Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef mozilla_IMEStateManager_h_ |
michael@0 | 7 | #define mozilla_IMEStateManager_h_ |
michael@0 | 8 | |
michael@0 | 9 | #include "mozilla/EventForwards.h" |
michael@0 | 10 | #include "nsIWidget.h" |
michael@0 | 11 | |
michael@0 | 12 | class nsIContent; |
michael@0 | 13 | class nsIDOMMouseEvent; |
michael@0 | 14 | class nsINode; |
michael@0 | 15 | class nsPIDOMWindow; |
michael@0 | 16 | class nsPresContext; |
michael@0 | 17 | class nsISelection; |
michael@0 | 18 | |
michael@0 | 19 | namespace mozilla { |
michael@0 | 20 | |
michael@0 | 21 | class EventDispatchingCallback; |
michael@0 | 22 | class IMEContentObserver; |
michael@0 | 23 | class TextCompositionArray; |
michael@0 | 24 | class TextComposition; |
michael@0 | 25 | |
michael@0 | 26 | /** |
michael@0 | 27 | * IMEStateManager manages InputContext (e.g., active editor type, IME enabled |
michael@0 | 28 | * state and IME open state) of nsIWidget instances, manages IMEContentObserver |
michael@0 | 29 | * and provides useful API for IME. |
michael@0 | 30 | */ |
michael@0 | 31 | |
michael@0 | 32 | class IMEStateManager |
michael@0 | 33 | { |
michael@0 | 34 | typedef widget::IMEMessage IMEMessage; |
michael@0 | 35 | typedef widget::IMEState IMEState; |
michael@0 | 36 | typedef widget::InputContext InputContext; |
michael@0 | 37 | typedef widget::InputContextAction InputContextAction; |
michael@0 | 38 | |
michael@0 | 39 | public: |
michael@0 | 40 | static void Shutdown(); |
michael@0 | 41 | |
michael@0 | 42 | static nsresult OnDestroyPresContext(nsPresContext* aPresContext); |
michael@0 | 43 | static nsresult OnRemoveContent(nsPresContext* aPresContext, |
michael@0 | 44 | nsIContent* aContent); |
michael@0 | 45 | /** |
michael@0 | 46 | * OnChangeFocus() should be called when focused content is changed or |
michael@0 | 47 | * IME enabled state is changed. If nobody has focus, set both aPresContext |
michael@0 | 48 | * and aContent nullptr. E.g., all windows are deactivated. |
michael@0 | 49 | */ |
michael@0 | 50 | static nsresult OnChangeFocus(nsPresContext* aPresContext, |
michael@0 | 51 | nsIContent* aContent, |
michael@0 | 52 | InputContextAction::Cause aCause); |
michael@0 | 53 | static void OnInstalledMenuKeyboardListener(bool aInstalling); |
michael@0 | 54 | |
michael@0 | 55 | // These two methods manage focus and selection/text observers. |
michael@0 | 56 | // They are separate from OnChangeFocus above because this offers finer |
michael@0 | 57 | // control compared to having the two methods incorporated into OnChangeFocus |
michael@0 | 58 | |
michael@0 | 59 | // Get the focused editor's selection and root |
michael@0 | 60 | static nsresult GetFocusSelectionAndRoot(nsISelection** aSel, |
michael@0 | 61 | nsIContent** aRoot); |
michael@0 | 62 | // This method updates the current IME state. However, if the enabled state |
michael@0 | 63 | // isn't changed by the new state, this method does nothing. |
michael@0 | 64 | // Note that this method changes the IME state of the active element in the |
michael@0 | 65 | // widget. So, the caller must have focus. |
michael@0 | 66 | static void UpdateIMEState(const IMEState &aNewIMEState, |
michael@0 | 67 | nsIContent* aContent); |
michael@0 | 68 | |
michael@0 | 69 | // This method is called when user clicked in an editor. |
michael@0 | 70 | // aContent must be: |
michael@0 | 71 | // If the editor is for <input> or <textarea>, the element. |
michael@0 | 72 | // If the editor is for contenteditable, the active editinghost. |
michael@0 | 73 | // If the editor is for designMode, nullptr. |
michael@0 | 74 | static void OnClickInEditor(nsPresContext* aPresContext, |
michael@0 | 75 | nsIContent* aContent, |
michael@0 | 76 | nsIDOMMouseEvent* aMouseEvent); |
michael@0 | 77 | |
michael@0 | 78 | // This method is called when editor actually gets focus. |
michael@0 | 79 | // aContent must be: |
michael@0 | 80 | // If the editor is for <input> or <textarea>, the element. |
michael@0 | 81 | // If the editor is for contenteditable, the active editinghost. |
michael@0 | 82 | // If the editor is for designMode, nullptr. |
michael@0 | 83 | static void OnFocusInEditor(nsPresContext* aPresContext, |
michael@0 | 84 | nsIContent* aContent); |
michael@0 | 85 | |
michael@0 | 86 | /** |
michael@0 | 87 | * All DOM composition events and DOM text events must be dispatched via |
michael@0 | 88 | * DispatchCompositionEvent() for storing the composition target |
michael@0 | 89 | * and ensuring a set of composition events must be fired the stored target. |
michael@0 | 90 | * If the stored composition event target is destroying, this removes the |
michael@0 | 91 | * stored composition automatically. |
michael@0 | 92 | */ |
michael@0 | 93 | static void DispatchCompositionEvent(nsINode* aEventTargetNode, |
michael@0 | 94 | nsPresContext* aPresContext, |
michael@0 | 95 | WidgetEvent* aEvent, |
michael@0 | 96 | nsEventStatus* aStatus, |
michael@0 | 97 | EventDispatchingCallback* aCallBack); |
michael@0 | 98 | |
michael@0 | 99 | /** |
michael@0 | 100 | * Get TextComposition from widget. |
michael@0 | 101 | */ |
michael@0 | 102 | static already_AddRefed<TextComposition> |
michael@0 | 103 | GetTextCompositionFor(nsIWidget* aWidget); |
michael@0 | 104 | |
michael@0 | 105 | /** |
michael@0 | 106 | * Returns TextComposition instance for the event. |
michael@0 | 107 | * |
michael@0 | 108 | * @param aEvent Should be a composition event or a text event which is |
michael@0 | 109 | * being dispatched. |
michael@0 | 110 | */ |
michael@0 | 111 | static already_AddRefed<TextComposition> |
michael@0 | 112 | GetTextCompositionFor(WidgetGUIEvent* aEvent); |
michael@0 | 113 | |
michael@0 | 114 | /** |
michael@0 | 115 | * Send a notification to IME. It depends on the IME or platform spec what |
michael@0 | 116 | * will occur (or not occur). |
michael@0 | 117 | */ |
michael@0 | 118 | static nsresult NotifyIME(IMEMessage aMessage, nsIWidget* aWidget); |
michael@0 | 119 | static nsresult NotifyIME(IMEMessage aMessage, nsPresContext* aPresContext); |
michael@0 | 120 | |
michael@0 | 121 | static nsINode* GetRootEditableNode(nsPresContext* aPresContext, |
michael@0 | 122 | nsIContent* aContent); |
michael@0 | 123 | static bool IsTestingIME() { return sIsTestingIME; } |
michael@0 | 124 | |
michael@0 | 125 | protected: |
michael@0 | 126 | static nsresult OnChangeFocusInternal(nsPresContext* aPresContext, |
michael@0 | 127 | nsIContent* aContent, |
michael@0 | 128 | InputContextAction aAction); |
michael@0 | 129 | static void SetIMEState(const IMEState &aState, |
michael@0 | 130 | nsIContent* aContent, |
michael@0 | 131 | nsIWidget* aWidget, |
michael@0 | 132 | InputContextAction aAction); |
michael@0 | 133 | static IMEState GetNewIMEState(nsPresContext* aPresContext, |
michael@0 | 134 | nsIContent* aContent); |
michael@0 | 135 | |
michael@0 | 136 | static void EnsureTextCompositionArray(); |
michael@0 | 137 | static void CreateIMEContentObserver(); |
michael@0 | 138 | static void DestroyTextStateManager(); |
michael@0 | 139 | |
michael@0 | 140 | static bool IsEditable(nsINode* node); |
michael@0 | 141 | |
michael@0 | 142 | static bool IsEditableIMEState(nsIWidget* aWidget); |
michael@0 | 143 | |
michael@0 | 144 | static nsIContent* sContent; |
michael@0 | 145 | static nsPresContext* sPresContext; |
michael@0 | 146 | static bool sInstalledMenuKeyboardListener; |
michael@0 | 147 | static bool sIsTestingIME; |
michael@0 | 148 | |
michael@0 | 149 | static IMEContentObserver* sActiveIMEContentObserver; |
michael@0 | 150 | |
michael@0 | 151 | // All active compositions in the process are stored by this array. |
michael@0 | 152 | // When you get an item of this array and use it, please be careful. |
michael@0 | 153 | // The instances in this array can be destroyed automatically if you do |
michael@0 | 154 | // something to cause committing or canceling the composition. |
michael@0 | 155 | static TextCompositionArray* sTextCompositions; |
michael@0 | 156 | }; |
michael@0 | 157 | |
michael@0 | 158 | } // namespace mozilla |
michael@0 | 159 | |
michael@0 | 160 | #endif // mozilla_IMEStateManager_h_ |