dom/events/IMEStateManager.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/events/IMEStateManager.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,160 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef mozilla_IMEStateManager_h_
    1.10 +#define mozilla_IMEStateManager_h_
    1.11 +
    1.12 +#include "mozilla/EventForwards.h"
    1.13 +#include "nsIWidget.h"
    1.14 +
    1.15 +class nsIContent;
    1.16 +class nsIDOMMouseEvent;
    1.17 +class nsINode;
    1.18 +class nsPIDOMWindow;
    1.19 +class nsPresContext;
    1.20 +class nsISelection;
    1.21 +
    1.22 +namespace mozilla {
    1.23 +
    1.24 +class EventDispatchingCallback;
    1.25 +class IMEContentObserver;
    1.26 +class TextCompositionArray;
    1.27 +class TextComposition;
    1.28 +
    1.29 +/**
    1.30 + * IMEStateManager manages InputContext (e.g., active editor type, IME enabled
    1.31 + * state and IME open state) of nsIWidget instances, manages IMEContentObserver
    1.32 + * and provides useful API for IME.
    1.33 + */
    1.34 +
    1.35 +class IMEStateManager
    1.36 +{
    1.37 +  typedef widget::IMEMessage IMEMessage;
    1.38 +  typedef widget::IMEState IMEState;
    1.39 +  typedef widget::InputContext InputContext;
    1.40 +  typedef widget::InputContextAction InputContextAction;
    1.41 +
    1.42 +public:
    1.43 +  static void Shutdown();
    1.44 +
    1.45 +  static nsresult OnDestroyPresContext(nsPresContext* aPresContext);
    1.46 +  static nsresult OnRemoveContent(nsPresContext* aPresContext,
    1.47 +                                  nsIContent* aContent);
    1.48 +  /**
    1.49 +   * OnChangeFocus() should be called when focused content is changed or
    1.50 +   * IME enabled state is changed.  If nobody has focus, set both aPresContext
    1.51 +   * and aContent nullptr.  E.g., all windows are deactivated.
    1.52 +   */
    1.53 +  static nsresult OnChangeFocus(nsPresContext* aPresContext,
    1.54 +                                nsIContent* aContent,
    1.55 +                                InputContextAction::Cause aCause);
    1.56 +  static void OnInstalledMenuKeyboardListener(bool aInstalling);
    1.57 +
    1.58 +  // These two methods manage focus and selection/text observers.
    1.59 +  // They are separate from OnChangeFocus above because this offers finer
    1.60 +  // control compared to having the two methods incorporated into OnChangeFocus
    1.61 +
    1.62 +  // Get the focused editor's selection and root
    1.63 +  static nsresult GetFocusSelectionAndRoot(nsISelection** aSel,
    1.64 +                                           nsIContent** aRoot);
    1.65 +  // This method updates the current IME state.  However, if the enabled state
    1.66 +  // isn't changed by the new state, this method does nothing.
    1.67 +  // Note that this method changes the IME state of the active element in the
    1.68 +  // widget.  So, the caller must have focus.
    1.69 +  static void UpdateIMEState(const IMEState &aNewIMEState,
    1.70 +                             nsIContent* aContent);
    1.71 +
    1.72 +  // This method is called when user clicked in an editor.
    1.73 +  // aContent must be:
    1.74 +  //   If the editor is for <input> or <textarea>, the element.
    1.75 +  //   If the editor is for contenteditable, the active editinghost.
    1.76 +  //   If the editor is for designMode, nullptr.
    1.77 +  static void OnClickInEditor(nsPresContext* aPresContext,
    1.78 +                              nsIContent* aContent,
    1.79 +                              nsIDOMMouseEvent* aMouseEvent);
    1.80 +
    1.81 +  // This method is called when editor actually gets focus.
    1.82 +  // aContent must be:
    1.83 +  //   If the editor is for <input> or <textarea>, the element.
    1.84 +  //   If the editor is for contenteditable, the active editinghost.
    1.85 +  //   If the editor is for designMode, nullptr.
    1.86 +  static void OnFocusInEditor(nsPresContext* aPresContext,
    1.87 +                              nsIContent* aContent);
    1.88 +
    1.89 +  /**
    1.90 +   * All DOM composition events and DOM text events must be dispatched via
    1.91 +   * DispatchCompositionEvent() for storing the composition target
    1.92 +   * and ensuring a set of composition events must be fired the stored target.
    1.93 +   * If the stored composition event target is destroying, this removes the
    1.94 +   * stored composition automatically.
    1.95 +   */
    1.96 +  static void DispatchCompositionEvent(nsINode* aEventTargetNode,
    1.97 +                                       nsPresContext* aPresContext,
    1.98 +                                       WidgetEvent* aEvent,
    1.99 +                                       nsEventStatus* aStatus,
   1.100 +                                       EventDispatchingCallback* aCallBack);
   1.101 +
   1.102 +  /**
   1.103 +   * Get TextComposition from widget.
   1.104 +   */
   1.105 +  static already_AddRefed<TextComposition>
   1.106 +    GetTextCompositionFor(nsIWidget* aWidget);
   1.107 +
   1.108 +  /**
   1.109 +   * Returns TextComposition instance for the event.
   1.110 +   *
   1.111 +   * @param aEvent      Should be a composition event or a text event which is
   1.112 +   *                    being dispatched.
   1.113 +   */
   1.114 +  static already_AddRefed<TextComposition>
   1.115 +    GetTextCompositionFor(WidgetGUIEvent* aEvent);
   1.116 +
   1.117 +  /**
   1.118 +   * Send a notification to IME.  It depends on the IME or platform spec what
   1.119 +   * will occur (or not occur).
   1.120 +   */
   1.121 +  static nsresult NotifyIME(IMEMessage aMessage, nsIWidget* aWidget);
   1.122 +  static nsresult NotifyIME(IMEMessage aMessage, nsPresContext* aPresContext);
   1.123 +
   1.124 +  static nsINode* GetRootEditableNode(nsPresContext* aPresContext,
   1.125 +                                      nsIContent* aContent);
   1.126 +  static bool IsTestingIME() { return sIsTestingIME; }
   1.127 +
   1.128 +protected:
   1.129 +  static nsresult OnChangeFocusInternal(nsPresContext* aPresContext,
   1.130 +                                        nsIContent* aContent,
   1.131 +                                        InputContextAction aAction);
   1.132 +  static void SetIMEState(const IMEState &aState,
   1.133 +                          nsIContent* aContent,
   1.134 +                          nsIWidget* aWidget,
   1.135 +                          InputContextAction aAction);
   1.136 +  static IMEState GetNewIMEState(nsPresContext* aPresContext,
   1.137 +                                 nsIContent* aContent);
   1.138 +
   1.139 +  static void EnsureTextCompositionArray();
   1.140 +  static void CreateIMEContentObserver();
   1.141 +  static void DestroyTextStateManager();
   1.142 +
   1.143 +  static bool IsEditable(nsINode* node);
   1.144 +
   1.145 +  static bool IsEditableIMEState(nsIWidget* aWidget);
   1.146 +
   1.147 +  static nsIContent*    sContent;
   1.148 +  static nsPresContext* sPresContext;
   1.149 +  static bool           sInstalledMenuKeyboardListener;
   1.150 +  static bool           sIsTestingIME;
   1.151 +
   1.152 +  static IMEContentObserver* sActiveIMEContentObserver;
   1.153 +
   1.154 +  // All active compositions in the process are stored by this array.
   1.155 +  // When you get an item of this array and use it, please be careful.
   1.156 +  // The instances in this array can be destroyed automatically if you do
   1.157 +  // something to cause committing or canceling the composition.
   1.158 +  static TextCompositionArray* sTextCompositions;
   1.159 +};
   1.160 +
   1.161 +} // namespace mozilla
   1.162 +
   1.163 +#endif // mozilla_IMEStateManager_h_

mercurial