1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 
6 #ifndef EditorEventListener_h
7 #define EditorEventListener_h
8 
9 #include "nsCOMPtr.h"
10 #include "nsError.h"
11 #include "nsIDOMEventListener.h"
12 #include "nsISupportsImpl.h"
13 #include "nscore.h"
14 
15 class nsCaret;
16 class nsIContent;
17 class nsIDOMDragEvent;
18 class nsIDOMEvent;
19 class nsIDOMKeyEvent;
20 class nsIDOMMouseEvent;
21 class nsIPresShell;
22 class nsPresContext;
23 
24 // X.h defines KeyPress
25 #ifdef KeyPress
26 #undef KeyPress
27 #endif
28 
29 #ifdef XP_WIN
30 // On Windows, we support switching the text direction by pressing Ctrl+Shift
31 #define HANDLE_NATIVE_TEXT_DIRECTION_SWITCH
32 #endif
33 
34 namespace mozilla {
35 
36 class EditorBase;
37 
38 class EditorEventListener : public nsIDOMEventListener
39 {
40 public:
41   EditorEventListener();
42 
43   virtual nsresult Connect(EditorBase* aEditorBase);
44 
45   void Disconnect();
46 
47   NS_DECL_ISUPPORTS
48   NS_DECL_NSIDOMEVENTLISTENER
49 
50   void SpellCheckIfNeeded();
51 
52 protected:
53   virtual ~EditorEventListener();
54 
55   nsresult InstallToEditor();
56   void UninstallFromEditor();
57 
58 #ifdef HANDLE_NATIVE_TEXT_DIRECTION_SWITCH
59   nsresult KeyDown(nsIDOMKeyEvent* aKeyEvent);
60   nsresult KeyUp(nsIDOMKeyEvent* aKeyEvent);
61 #endif
62   nsresult KeyPress(nsIDOMKeyEvent* aKeyEvent);
63   nsresult HandleText(nsIDOMEvent* aTextEvent);
64   nsresult HandleStartComposition(nsIDOMEvent* aCompositionEvent);
65   void HandleEndComposition(nsIDOMEvent* aCompositionEvent);
66   virtual nsresult MouseDown(nsIDOMMouseEvent* aMouseEvent);
MouseUp(nsIDOMMouseEvent * aMouseEvent)67   virtual nsresult MouseUp(nsIDOMMouseEvent* aMouseEvent) { return NS_OK; }
68   virtual nsresult MouseClick(nsIDOMMouseEvent* aMouseEvent);
69   nsresult Focus(nsIDOMEvent* aEvent);
70   nsresult Blur(nsIDOMEvent* aEvent);
71   nsresult DragEnter(nsIDOMDragEvent* aDragEvent);
72   nsresult DragOver(nsIDOMDragEvent* aDragEvent);
73   nsresult DragExit(nsIDOMDragEvent* aDragEvent);
74   nsresult Drop(nsIDOMDragEvent* aDragEvent);
75 
76   bool CanDrop(nsIDOMDragEvent* aEvent);
77   void CleanupDragDropCaret();
78   already_AddRefed<nsIPresShell> GetPresShell();
79   nsPresContext* GetPresContext();
80   nsIContent* GetFocusedRootContent();
81   // Returns true if IME consumes the mouse event.
82   bool NotifyIMEOfMouseButtonEvent(nsIDOMMouseEvent* aMouseEvent);
83   bool EditorHasFocus();
84   bool IsFileControlTextBox();
85   bool ShouldHandleNativeKeyBindings(nsIDOMKeyEvent* aKeyEvent);
86   nsresult HandleMiddleClickPaste(nsIDOMMouseEvent* aMouseEvent);
87 
88   EditorBase* mEditorBase; // weak
89   RefPtr<nsCaret> mCaret;
90   bool mCommitText;
91   bool mInTransaction;
92   bool mMouseDownOrUpConsumedByIME;
93 #ifdef HANDLE_NATIVE_TEXT_DIRECTION_SWITCH
94   bool mHaveBidiKeyboards;
95   bool mShouldSwitchTextDirection;
96   bool mSwitchToRTL;
97 #endif
98 };
99 
100 } // namespace mozilla
101 
102 #endif // #ifndef EditorEventListener_h
103