Bug 1025824 - Fix mHwcLayerMap handling r=sushil
[gecko.git] / dom / events / IMEStateManager.h
blob86f642dc8ee072bb90e02f6eaa84ebc773f93468
1 /* -*- Mode: C++; tab-width: 2; 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/. */
6 #ifndef mozilla_IMEStateManager_h_
7 #define mozilla_IMEStateManager_h_
9 #include "mozilla/EventForwards.h"
10 #include "nsIWidget.h"
12 class nsIContent;
13 class nsIDOMMouseEvent;
14 class nsINode;
15 class nsPIDOMWindow;
16 class nsPresContext;
17 class nsISelection;
19 namespace mozilla {
21 class EventDispatchingCallback;
22 class IMEContentObserver;
23 class TextCompositionArray;
24 class TextComposition;
26 /**
27 * IMEStateManager manages InputContext (e.g., active editor type, IME enabled
28 * state and IME open state) of nsIWidget instances, manages IMEContentObserver
29 * and provides useful API for IME.
32 class IMEStateManager
34 typedef widget::IMEMessage IMEMessage;
35 typedef widget::IMEState IMEState;
36 typedef widget::InputContext InputContext;
37 typedef widget::InputContextAction InputContextAction;
39 public:
40 static void Shutdown();
42 static nsresult OnDestroyPresContext(nsPresContext* aPresContext);
43 static nsresult OnRemoveContent(nsPresContext* aPresContext,
44 nsIContent* aContent);
45 /**
46 * OnChangeFocus() should be called when focused content is changed or
47 * IME enabled state is changed. If nobody has focus, set both aPresContext
48 * and aContent nullptr. E.g., all windows are deactivated.
50 static nsresult OnChangeFocus(nsPresContext* aPresContext,
51 nsIContent* aContent,
52 InputContextAction::Cause aCause);
53 static void OnInstalledMenuKeyboardListener(bool aInstalling);
55 // These two methods manage focus and selection/text observers.
56 // They are separate from OnChangeFocus above because this offers finer
57 // control compared to having the two methods incorporated into OnChangeFocus
59 // Get the focused editor's selection and root
60 static nsresult GetFocusSelectionAndRoot(nsISelection** aSel,
61 nsIContent** aRoot);
62 // This method updates the current IME state. However, if the enabled state
63 // isn't changed by the new state, this method does nothing.
64 // Note that this method changes the IME state of the active element in the
65 // widget. So, the caller must have focus.
66 static void UpdateIMEState(const IMEState &aNewIMEState,
67 nsIContent* aContent);
69 // This method is called when user clicked in an editor.
70 // aContent must be:
71 // If the editor is for <input> or <textarea>, the element.
72 // If the editor is for contenteditable, the active editinghost.
73 // If the editor is for designMode, nullptr.
74 static void OnClickInEditor(nsPresContext* aPresContext,
75 nsIContent* aContent,
76 nsIDOMMouseEvent* aMouseEvent);
78 // This method is called when editor actually gets focus.
79 // aContent must be:
80 // If the editor is for <input> or <textarea>, the element.
81 // If the editor is for contenteditable, the active editinghost.
82 // If the editor is for designMode, nullptr.
83 static void OnFocusInEditor(nsPresContext* aPresContext,
84 nsIContent* aContent);
86 /**
87 * All DOM composition events and DOM text events must be dispatched via
88 * DispatchCompositionEvent() for storing the composition target
89 * and ensuring a set of composition events must be fired the stored target.
90 * If the stored composition event target is destroying, this removes the
91 * stored composition automatically.
93 static void DispatchCompositionEvent(nsINode* aEventTargetNode,
94 nsPresContext* aPresContext,
95 WidgetEvent* aEvent,
96 nsEventStatus* aStatus,
97 EventDispatchingCallback* aCallBack);
99 /**
100 * Get TextComposition from widget.
102 static already_AddRefed<TextComposition>
103 GetTextCompositionFor(nsIWidget* aWidget);
106 * Returns TextComposition instance for the event.
108 * @param aEvent Should be a composition event or a text event which is
109 * being dispatched.
111 static already_AddRefed<TextComposition>
112 GetTextCompositionFor(WidgetGUIEvent* aEvent);
115 * Send a notification to IME. It depends on the IME or platform spec what
116 * will occur (or not occur).
118 static nsresult NotifyIME(IMEMessage aMessage, nsIWidget* aWidget);
119 static nsresult NotifyIME(IMEMessage aMessage, nsPresContext* aPresContext);
121 static nsINode* GetRootEditableNode(nsPresContext* aPresContext,
122 nsIContent* aContent);
123 static bool IsTestingIME() { return sIsTestingIME; }
125 protected:
126 static nsresult OnChangeFocusInternal(nsPresContext* aPresContext,
127 nsIContent* aContent,
128 InputContextAction aAction);
129 static void SetIMEState(const IMEState &aState,
130 nsIContent* aContent,
131 nsIWidget* aWidget,
132 InputContextAction aAction);
133 static IMEState GetNewIMEState(nsPresContext* aPresContext,
134 nsIContent* aContent);
136 static void EnsureTextCompositionArray();
137 static void CreateIMEContentObserver();
138 static void DestroyTextStateManager();
140 static bool IsEditable(nsINode* node);
142 static bool IsEditableIMEState(nsIWidget* aWidget);
144 static nsIContent* sContent;
145 static nsPresContext* sPresContext;
146 static bool sInstalledMenuKeyboardListener;
147 static bool sIsTestingIME;
149 static IMEContentObserver* sActiveIMEContentObserver;
151 // All active compositions in the process are stored by this array.
152 // When you get an item of this array and use it, please be careful.
153 // The instances in this array can be destroyed automatically if you do
154 // something to cause committing or canceling the composition.
155 static TextCompositionArray* sTextCompositions;
158 } // namespace mozilla
160 #endif // mozilla_IMEStateManager_h_