michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0:
michael@0: #ifndef mozilla_IMEStateManager_h_
michael@0: #define mozilla_IMEStateManager_h_
michael@0:
michael@0: #include "mozilla/EventForwards.h"
michael@0: #include "nsIWidget.h"
michael@0:
michael@0: class nsIContent;
michael@0: class nsIDOMMouseEvent;
michael@0: class nsINode;
michael@0: class nsPIDOMWindow;
michael@0: class nsPresContext;
michael@0: class nsISelection;
michael@0:
michael@0: namespace mozilla {
michael@0:
michael@0: class EventDispatchingCallback;
michael@0: class IMEContentObserver;
michael@0: class TextCompositionArray;
michael@0: class TextComposition;
michael@0:
michael@0: /**
michael@0: * IMEStateManager manages InputContext (e.g., active editor type, IME enabled
michael@0: * state and IME open state) of nsIWidget instances, manages IMEContentObserver
michael@0: * and provides useful API for IME.
michael@0: */
michael@0:
michael@0: class IMEStateManager
michael@0: {
michael@0: typedef widget::IMEMessage IMEMessage;
michael@0: typedef widget::IMEState IMEState;
michael@0: typedef widget::InputContext InputContext;
michael@0: typedef widget::InputContextAction InputContextAction;
michael@0:
michael@0: public:
michael@0: static void Shutdown();
michael@0:
michael@0: static nsresult OnDestroyPresContext(nsPresContext* aPresContext);
michael@0: static nsresult OnRemoveContent(nsPresContext* aPresContext,
michael@0: nsIContent* aContent);
michael@0: /**
michael@0: * OnChangeFocus() should be called when focused content is changed or
michael@0: * IME enabled state is changed. If nobody has focus, set both aPresContext
michael@0: * and aContent nullptr. E.g., all windows are deactivated.
michael@0: */
michael@0: static nsresult OnChangeFocus(nsPresContext* aPresContext,
michael@0: nsIContent* aContent,
michael@0: InputContextAction::Cause aCause);
michael@0: static void OnInstalledMenuKeyboardListener(bool aInstalling);
michael@0:
michael@0: // These two methods manage focus and selection/text observers.
michael@0: // They are separate from OnChangeFocus above because this offers finer
michael@0: // control compared to having the two methods incorporated into OnChangeFocus
michael@0:
michael@0: // Get the focused editor's selection and root
michael@0: static nsresult GetFocusSelectionAndRoot(nsISelection** aSel,
michael@0: nsIContent** aRoot);
michael@0: // This method updates the current IME state. However, if the enabled state
michael@0: // isn't changed by the new state, this method does nothing.
michael@0: // Note that this method changes the IME state of the active element in the
michael@0: // widget. So, the caller must have focus.
michael@0: static void UpdateIMEState(const IMEState &aNewIMEState,
michael@0: nsIContent* aContent);
michael@0:
michael@0: // This method is called when user clicked in an editor.
michael@0: // aContent must be:
michael@0: // If the editor is for or