/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#ifndef mozilla_IMEStateManager_h_
#define mozilla_IMEStateManager_h_
#include "mozilla/EventForwards.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/dom/TabParent.h"
#include "nsIWidget.h"
class nsIContent;
class nsIDOMMouseEvent;
class nsIEditor;
class nsINode;
class nsPresContext;
class nsISelection;
namespace mozilla {
class EventDispatchingCallback;
class IMEContentObserver;
class TextCompositionArray;
class TextComposition;
/**
* 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.
*/
class IMEStateManager
{
typedef dom::TabParent TabParent;
typedef widget::IMEMessage IMEMessage;
typedef widget::IMENotification IMENotification;
typedef widget::IMEState IMEState;
typedef widget::InputContext InputContext;
typedef widget::InputContextAction InputContextAction;
public:
static void Init();
static void Shutdown();
/**
* GetActiveTabParent() returns a pointer to a TabParent instance which is
* managed by the focused content (sContent). If the focused content isn't
* managing another process, this returns nullptr.
*/
static TabParent* GetActiveTabParent()
{
// If menu has pseudo focus, we should ignore active child process.
if (sInstalledMenuKeyboardListener) {
return nullptr;
}
return sActiveTabParent.get();
}
/**
* OnTabParentDestroying() is called when aTabParent is being destroyed.
*/
static void OnTabParentDestroying(TabParent* aTabParent);
/**
* SetIMEContextForChildProcess() is called when aTabParent receives
* SetInputContext() from the remote process.
*/
static void SetInputContextForChildProcess(TabParent* aTabParent,
const InputContext& aInputContext,
const InputContextAction& aAction);
/**
* StopIMEStateManagement() is called when the process should stop managing
* IME state.
*/
static void StopIMEStateManagement();
static nsresult OnDestroyPresContext(nsPresContext* aPresContext);
static nsresult OnRemoveContent(nsPresContext* aPresContext,
nsIContent* aContent);
/**
* OnChangeFocus() should be called when focused content is changed or
* IME enabled state is changed. If nobody has focus, set both aPresContext
* and aContent nullptr. E.g., all windows are deactivated.
*/
static nsresult OnChangeFocus(nsPresContext* aPresContext,
nsIContent* aContent,
InputContextAction::Cause aCause);
static void OnInstalledMenuKeyboardListener(bool aInstalling);
// 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);
// 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.
static void UpdateIMEState(const IMEState &aNewIMEState,
nsIContent* aContent,
nsIEditor* aEditor);
// This method is called when user operates mouse button in focused editor
// and before the editor handles it.
// Returns true if IME consumes the event. Otherwise, false.
static bool OnMouseButtonEventInEditor(nsPresContext* aPresContext,
nsIContent* aContent,
nsIDOMMouseEvent* aMouseEvent);
// This method is called when user clicked in an editor.
// aContent must be:
// If the editor is for or