Line data Source code
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 "mozilla/Attributes.h"
10 : #include "mozilla/EventForwards.h"
11 : #include "nsCOMPtr.h"
12 : #include "nsError.h"
13 : #include "nsIDOMEventListener.h"
14 : #include "nsISupportsImpl.h"
15 : #include "nscore.h"
16 :
17 : class nsCaret;
18 : class nsIContent;
19 : class nsIDOMDragEvent;
20 : class nsIDOMEvent;
21 : class nsIDOMKeyEvent;
22 : class nsIDOMMouseEvent;
23 : class nsIPresShell;
24 : class nsPresContext;
25 :
26 : // X.h defines KeyPress
27 : #ifdef KeyPress
28 : #undef KeyPress
29 : #endif
30 :
31 : #ifdef XP_WIN
32 : // On Windows, we support switching the text direction by pressing Ctrl+Shift
33 : #define HANDLE_NATIVE_TEXT_DIRECTION_SWITCH
34 : #endif
35 :
36 : namespace mozilla {
37 :
38 : class EditorBase;
39 :
40 : class EditorEventListener : public nsIDOMEventListener
41 : {
42 : public:
43 : EditorEventListener();
44 :
45 : virtual nsresult Connect(EditorBase* aEditorBase);
46 :
47 : void Disconnect();
48 :
49 : NS_DECL_ISUPPORTS
50 : NS_DECL_NSIDOMEVENTLISTENER
51 :
52 : void SpellCheckIfNeeded();
53 :
54 : protected:
55 : virtual ~EditorEventListener();
56 :
57 : nsresult InstallToEditor();
58 : void UninstallFromEditor();
59 :
60 : #ifdef HANDLE_NATIVE_TEXT_DIRECTION_SWITCH
61 : nsresult KeyDown(const WidgetKeyboardEvent* aKeyboardEvent);
62 : nsresult KeyUp(const WidgetKeyboardEvent* aKeyboardEvent);
63 : #endif
64 : nsresult KeyPress(WidgetKeyboardEvent* aKeyboardEvent);
65 : nsresult HandleChangeComposition(WidgetCompositionEvent* aCompositionEvent);
66 : nsresult HandleStartComposition(WidgetCompositionEvent* aCompositionEvent);
67 : void HandleEndComposition(WidgetCompositionEvent* aCompositionEvent);
68 : virtual nsresult MouseDown(nsIDOMMouseEvent* aMouseEvent);
69 0 : virtual nsresult MouseUp(nsIDOMMouseEvent* aMouseEvent) { return NS_OK; }
70 : virtual nsresult MouseClick(nsIDOMMouseEvent* aMouseEvent);
71 : nsresult Focus(InternalFocusEvent* aFocusEvent);
72 : nsresult Blur(InternalFocusEvent* aBlurEvent);
73 : nsresult DragEnter(nsIDOMDragEvent* aDragEvent);
74 : nsresult DragOver(nsIDOMDragEvent* aDragEvent);
75 : nsresult DragExit(nsIDOMDragEvent* aDragEvent);
76 : nsresult Drop(nsIDOMDragEvent* aDragEvent);
77 :
78 : bool CanDrop(nsIDOMDragEvent* aEvent);
79 : void CleanupDragDropCaret();
80 : already_AddRefed<nsIPresShell> GetPresShell();
81 : nsPresContext* GetPresContext();
82 : nsIContent* GetFocusedRootContent();
83 : // Returns true if IME consumes the mouse event.
84 : bool NotifyIMEOfMouseButtonEvent(WidgetMouseEvent* aMouseEvent);
85 : bool EditorHasFocus();
86 : bool IsFileControlTextBox();
87 : bool ShouldHandleNativeKeyBindings(WidgetKeyboardEvent* aKeyboardEvent);
88 : nsresult HandleMiddleClickPaste(nsIDOMMouseEvent* aMouseEvent);
89 :
90 : /**
91 : * DetachedFromEditor() returns true if editor was detached.
92 : * Otherwise, false.
93 : */
94 : bool DetachedFromEditor() const;
95 :
96 : /**
97 : * DetachedFromEditorOrDefaultPrevented() returns true if editor was detached
98 : * and/or the event was consumed. Otherwise, i.e., attached editor can
99 : * handle the event, returns true.
100 : */
101 : bool DetachedFromEditorOrDefaultPrevented(WidgetEvent* aEvent) const;
102 :
103 : /**
104 : * EnsureCommitComposition() requests to commit composition if there is.
105 : * Returns false if the editor is detached from the listener, i.e.,
106 : * impossible to continue to handle the event. Otherwise, true.
107 : */
108 : MOZ_MUST_USE bool EnsureCommitCompoisition();
109 :
110 : EditorBase* mEditorBase; // weak
111 : RefPtr<nsCaret> mCaret;
112 : bool mCommitText;
113 : bool mInTransaction;
114 : bool mMouseDownOrUpConsumedByIME;
115 : #ifdef HANDLE_NATIVE_TEXT_DIRECTION_SWITCH
116 : bool mHaveBidiKeyboards;
117 : bool mShouldSwitchTextDirection;
118 : bool mSwitchToRTL;
119 : #endif
120 : };
121 :
122 : } // namespace mozilla
123 :
124 : #endif // #ifndef EditorEventListener_h
|