2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-03-07 17:20:07 -08:00
|
|
|
#ifndef mozilla_IMEStateManager_h_
|
|
|
|
#define mozilla_IMEStateManager_h_
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-09-24 03:04:14 -07:00
|
|
|
#include "mozilla/EventForwards.h"
|
2011-11-27 03:51:52 -08:00
|
|
|
#include "nsIWidget.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class nsIContent;
|
2011-11-27 03:51:53 -08:00
|
|
|
class nsIDOMMouseEvent;
|
2012-09-25 22:47:45 -07:00
|
|
|
class nsINode;
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsPIDOMWindow;
|
|
|
|
class nsPresContext;
|
2009-02-10 12:56:51 -08:00
|
|
|
class nsISelection;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-09-25 22:47:45 -07:00
|
|
|
namespace mozilla {
|
2014-03-07 17:20:07 -08:00
|
|
|
|
2014-03-17 21:48:20 -07:00
|
|
|
class EventDispatchingCallback;
|
2014-03-07 17:20:07 -08:00
|
|
|
class IMEContentObserver;
|
2012-09-25 22:47:45 -07:00
|
|
|
class TextCompositionArray;
|
2013-11-06 16:11:11 -08:00
|
|
|
class TextComposition;
|
2012-09-25 22:47:45 -07:00
|
|
|
|
2014-03-07 17:20:07 -08:00
|
|
|
/**
|
|
|
|
* IMEStateManager manages InputContext (e.g., active editor type, IME enabled
|
|
|
|
* state and IME open state) of nsIWidget instances, manages IMEContentObserver
|
|
|
|
* and provides useful API for IME.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
|
2014-03-07 17:20:07 -08:00
|
|
|
class IMEStateManager
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-03-07 17:20:07 -08:00
|
|
|
typedef widget::IMEMessage IMEMessage;
|
|
|
|
typedef widget::IMEState IMEState;
|
|
|
|
typedef widget::InputContext InputContext;
|
|
|
|
typedef widget::InputContextAction InputContextAction;
|
2011-11-27 03:51:52 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
2014-07-15 22:13:28 -07:00
|
|
|
static void Init();
|
2012-09-25 22:47:45 -07:00
|
|
|
static void Shutdown();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static nsresult OnDestroyPresContext(nsPresContext* aPresContext);
|
|
|
|
static nsresult OnRemoveContent(nsPresContext* aPresContext,
|
|
|
|
nsIContent* aContent);
|
2011-11-27 03:51:52 -08:00
|
|
|
/**
|
|
|
|
* OnChangeFocus() should be called when focused content is changed or
|
2012-10-25 17:49:13 -07:00
|
|
|
* IME enabled state is changed. If nobody has focus, set both aPresContext
|
|
|
|
* and aContent nullptr. E.g., all windows are deactivated.
|
2011-11-27 03:51:52 -08:00
|
|
|
*/
|
2007-03-22 10:30:00 -07:00
|
|
|
static nsresult OnChangeFocus(nsPresContext* aPresContext,
|
2011-04-20 05:47:40 -07:00
|
|
|
nsIContent* aContent,
|
2011-11-27 03:51:52 -08:00
|
|
|
InputContextAction::Cause aCause);
|
2011-09-28 23:19:26 -07:00
|
|
|
static void OnInstalledMenuKeyboardListener(bool aInstalling);
|
2009-02-10 12:56:51 -08:00
|
|
|
|
|
|
|
// These two methods manage focus and selection/text observers.
|
|
|
|
// They are separate from OnChangeFocus above because this offers finer
|
|
|
|
// control compared to having the two methods incorporated into OnChangeFocus
|
|
|
|
|
|
|
|
// Get the focused editor's selection and root
|
|
|
|
static nsresult GetFocusSelectionAndRoot(nsISelection** aSel,
|
|
|
|
nsIContent** aRoot);
|
2010-05-26 19:04:14 -07:00
|
|
|
// This method updates the current IME state. However, if the enabled state
|
|
|
|
// isn't changed by the new state, this method does nothing.
|
|
|
|
// Note that this method changes the IME state of the active element in the
|
|
|
|
// widget. So, the caller must have focus.
|
2011-11-27 03:51:53 -08:00
|
|
|
static void UpdateIMEState(const IMEState &aNewIMEState,
|
|
|
|
nsIContent* aContent);
|
2010-05-26 19:04:14 -07:00
|
|
|
|
2011-11-27 03:51:53 -08:00
|
|
|
// This method is called when user clicked in an editor.
|
|
|
|
// aContent must be:
|
|
|
|
// If the editor is for <input> or <textarea>, the element.
|
|
|
|
// If the editor is for contenteditable, the active editinghost.
|
2013-04-02 18:14:24 -07:00
|
|
|
// If the editor is for designMode, nullptr.
|
2011-11-27 03:51:53 -08:00
|
|
|
static void OnClickInEditor(nsPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIDOMMouseEvent* aMouseEvent);
|
|
|
|
|
2012-10-25 17:49:13 -07:00
|
|
|
// This method is called when editor actually gets focus.
|
|
|
|
// aContent must be:
|
|
|
|
// If the editor is for <input> or <textarea>, the element.
|
|
|
|
// If the editor is for contenteditable, the active editinghost.
|
2013-04-02 18:14:24 -07:00
|
|
|
// If the editor is for designMode, nullptr.
|
2012-10-25 17:49:13 -07:00
|
|
|
static void OnFocusInEditor(nsPresContext* aPresContext,
|
|
|
|
nsIContent* aContent);
|
|
|
|
|
2012-09-25 22:47:45 -07:00
|
|
|
/**
|
|
|
|
* All DOM composition events and DOM text events must be dispatched via
|
|
|
|
* DispatchCompositionEvent() for storing the composition target
|
|
|
|
* and ensuring a set of composition events must be fired the stored target.
|
|
|
|
* If the stored composition event target is destroying, this removes the
|
|
|
|
* stored composition automatically.
|
|
|
|
*/
|
|
|
|
static void DispatchCompositionEvent(nsINode* aEventTargetNode,
|
|
|
|
nsPresContext* aPresContext,
|
2014-03-07 17:20:07 -08:00
|
|
|
WidgetEvent* aEvent,
|
2012-09-25 22:47:45 -07:00
|
|
|
nsEventStatus* aStatus,
|
2014-03-17 21:48:20 -07:00
|
|
|
EventDispatchingCallback* aCallBack);
|
2012-09-25 22:47:45 -07:00
|
|
|
|
2013-11-06 16:11:11 -08:00
|
|
|
/**
|
|
|
|
* Get TextComposition from widget.
|
|
|
|
*/
|
2014-03-07 17:20:07 -08:00
|
|
|
static already_AddRefed<TextComposition>
|
2014-02-12 05:02:55 -08:00
|
|
|
GetTextCompositionFor(nsIWidget* aWidget);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns TextComposition instance for the event.
|
|
|
|
*
|
|
|
|
* @param aEvent Should be a composition event or a text event which is
|
|
|
|
* being dispatched.
|
|
|
|
*/
|
2014-03-07 17:20:07 -08:00
|
|
|
static already_AddRefed<TextComposition>
|
|
|
|
GetTextCompositionFor(WidgetGUIEvent* aEvent);
|
2013-11-06 16:11:11 -08:00
|
|
|
|
2012-09-25 22:47:51 -07:00
|
|
|
/**
|
|
|
|
* Send a notification to IME. It depends on the IME or platform spec what
|
|
|
|
* will occur (or not occur).
|
|
|
|
*/
|
2014-02-17 16:00:15 -08:00
|
|
|
static nsresult NotifyIME(IMEMessage aMessage, nsIWidget* aWidget);
|
|
|
|
static nsresult NotifyIME(IMEMessage aMessage, nsPresContext* aPresContext);
|
2012-09-25 22:47:51 -07:00
|
|
|
|
2014-03-07 17:20:07 -08:00
|
|
|
static nsINode* GetRootEditableNode(nsPresContext* aPresContext,
|
|
|
|
nsIContent* aContent);
|
|
|
|
static bool IsTestingIME() { return sIsTestingIME; }
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
2011-11-27 03:51:52 -08:00
|
|
|
static nsresult OnChangeFocusInternal(nsPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
InputContextAction aAction);
|
2011-11-27 03:51:53 -08:00
|
|
|
static void SetIMEState(const IMEState &aState,
|
|
|
|
nsIContent* aContent,
|
2011-11-27 03:51:52 -08:00
|
|
|
nsIWidget* aWidget,
|
|
|
|
InputContextAction aAction);
|
2011-11-27 03:51:53 -08:00
|
|
|
static IMEState GetNewIMEState(nsPresContext* aPresContext,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIContent* aContent);
|
|
|
|
|
2012-09-25 22:47:45 -07:00
|
|
|
static void EnsureTextCompositionArray();
|
2014-03-07 17:20:07 -08:00
|
|
|
static void CreateIMEContentObserver();
|
2014-07-15 22:13:28 -07:00
|
|
|
static void DestroyIMEContentObserver();
|
2012-10-25 17:49:13 -07:00
|
|
|
|
|
|
|
static bool IsEditable(nsINode* node);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-10-30 16:22:22 -07:00
|
|
|
static bool IsEditableIMEState(nsIWidget* aWidget);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static nsIContent* sContent;
|
|
|
|
static nsPresContext* sPresContext;
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool sInstalledMenuKeyboardListener;
|
2012-11-09 00:40:40 -08:00
|
|
|
static bool sIsTestingIME;
|
2014-07-16 22:08:44 -07:00
|
|
|
static bool sIsGettingNewIMEState;
|
|
|
|
|
|
|
|
class MOZ_STACK_CLASS GettingNewIMEStateBlocker MOZ_FINAL
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GettingNewIMEStateBlocker()
|
|
|
|
: mOldValue(IMEStateManager::sIsGettingNewIMEState)
|
|
|
|
{
|
|
|
|
IMEStateManager::sIsGettingNewIMEState = true;
|
|
|
|
}
|
|
|
|
~GettingNewIMEStateBlocker()
|
|
|
|
{
|
|
|
|
IMEStateManager::sIsGettingNewIMEState = mOldValue;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
bool mOldValue;
|
|
|
|
};
|
2009-02-10 12:56:51 -08:00
|
|
|
|
2014-03-07 17:20:07 -08:00
|
|
|
static IMEContentObserver* sActiveIMEContentObserver;
|
2012-09-25 22:47:45 -07:00
|
|
|
|
|
|
|
// All active compositions in the process are stored by this array.
|
|
|
|
// When you get an item of this array and use it, please be careful.
|
|
|
|
// The instances in this array can be destroyed automatically if you do
|
|
|
|
// something to cause committing or canceling the composition.
|
2014-03-07 17:20:07 -08:00
|
|
|
static TextCompositionArray* sTextCompositions;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2014-03-07 17:20:07 -08:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_IMEStateManager_h_
|