2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 sw=2 et tw=80: */
|
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
|
|
|
|
|
|
|
#include "nsIMEStateManager.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
#include "nsIEditorDocShell.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsIDOMWindow.h"
|
2011-11-27 03:51:53 -08:00
|
|
|
#include "nsIDOMMouseEvent.h"
|
2007-04-15 06:43:55 -07:00
|
|
|
#include "nsContentUtils.h"
|
2009-02-10 12:56:51 -08:00
|
|
|
#include "nsINode.h"
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsRange.h"
|
|
|
|
#include "nsIDOMRange.h"
|
|
|
|
#include "nsISelection.h"
|
|
|
|
#include "nsISelectionPrivate.h"
|
|
|
|
#include "nsISelectionListener.h"
|
|
|
|
#include "nsISelectionController.h"
|
|
|
|
#include "nsIMutationObserver.h"
|
|
|
|
#include "nsContentEventHandler.h"
|
2010-10-18 09:37:00 -07:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "mozilla/Services.h"
|
2011-01-31 06:23:58 -08:00
|
|
|
#include "nsIFormControl.h"
|
|
|
|
#include "nsIForm.h"
|
|
|
|
#include "nsHTMLFormElement.h"
|
2012-06-18 19:30:09 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-11-27 03:51:52 -08:00
|
|
|
using namespace mozilla::widget;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/******************************************************************/
|
|
|
|
/* nsIMEStateManager */
|
|
|
|
/******************************************************************/
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIContent* nsIMEStateManager::sContent = nullptr;
|
|
|
|
nsPresContext* nsIMEStateManager::sPresContext = nullptr;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsIMEStateManager::sInstalledMenuKeyboardListener = false;
|
|
|
|
bool nsIMEStateManager::sInSecureInputMode = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
nsTextStateManager* nsIMEStateManager::sTextStateObserver = nullptr;
|
2009-02-10 12:56:51 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
|
|
|
nsIMEStateManager::OnDestroyPresContext(nsPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aPresContext);
|
|
|
|
if (aPresContext != sPresContext)
|
|
|
|
return NS_OK;
|
2009-12-04 00:03:27 -08:00
|
|
|
nsCOMPtr<nsIWidget> widget = GetWidget(sPresContext);
|
|
|
|
if (widget) {
|
2012-07-30 07:20:58 -07:00
|
|
|
IMEState newState = GetNewIMEState(sPresContext, nullptr);
|
2011-11-27 03:51:52 -08:00
|
|
|
InputContextAction action(InputContextAction::CAUSE_UNKNOWN,
|
|
|
|
InputContextAction::LOST_FOCUS);
|
2012-07-30 07:20:58 -07:00
|
|
|
SetIMEState(newState, nullptr, widget, action);
|
2009-12-04 00:03:27 -08:00
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
sContent = nullptr;
|
|
|
|
sPresContext = nullptr;
|
|
|
|
OnTextStateBlur(nullptr, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsIMEStateManager::OnRemoveContent(nsPresContext* aPresContext,
|
|
|
|
nsIContent* aContent)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aPresContext);
|
|
|
|
if (!sPresContext || !sContent ||
|
|
|
|
aPresContext != sPresContext ||
|
|
|
|
aContent != sContent)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// Current IME transaction should commit
|
2008-07-13 19:56:18 -07:00
|
|
|
nsCOMPtr<nsIWidget> widget = GetWidget(sPresContext);
|
|
|
|
if (widget) {
|
|
|
|
nsresult rv = widget->CancelIMEComposition();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv))
|
2008-07-13 19:56:18 -07:00
|
|
|
widget->ResetInputState();
|
2012-07-30 07:20:58 -07:00
|
|
|
IMEState newState = GetNewIMEState(sPresContext, nullptr);
|
2011-11-27 03:51:52 -08:00
|
|
|
InputContextAction action(InputContextAction::CAUSE_UNKNOWN,
|
|
|
|
InputContextAction::LOST_FOCUS);
|
2012-07-30 07:20:58 -07:00
|
|
|
SetIMEState(newState, nullptr, widget, action);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
sContent = nullptr;
|
|
|
|
sPresContext = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsIMEStateManager::OnChangeFocus(nsPresContext* aPresContext,
|
2011-04-20 05:47:40 -07:00
|
|
|
nsIContent* aContent,
|
2011-11-27 03:51:52 -08:00
|
|
|
InputContextAction::Cause aCause)
|
|
|
|
{
|
|
|
|
InputContextAction action(aCause);
|
|
|
|
return OnChangeFocusInternal(aPresContext, aContent, action);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsIMEStateManager::OnChangeFocusInternal(nsPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
InputContextAction aAction)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aPresContext);
|
|
|
|
|
2008-07-13 19:56:18 -07:00
|
|
|
nsCOMPtr<nsIWidget> widget = GetWidget(aPresContext);
|
|
|
|
if (!widget) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-02-09 11:00:58 -08:00
|
|
|
// Handle secure input mode for password field input.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool contentIsPassword = false;
|
2011-02-09 11:00:58 -08:00
|
|
|
if (aContent && aContent->GetNameSpaceID() == kNameSpaceID_XHTML) {
|
|
|
|
if (aContent->Tag() == nsGkAtoms::input) {
|
|
|
|
nsAutoString type;
|
|
|
|
aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::type, type);
|
|
|
|
contentIsPassword = type.LowerCaseEqualsLiteral("password");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sInSecureInputMode) {
|
|
|
|
if (!contentIsPassword) {
|
|
|
|
if (NS_SUCCEEDED(widget->EndSecureKeyboardInput())) {
|
2011-10-17 07:59:28 -07:00
|
|
|
sInSecureInputMode = false;
|
2011-02-09 11:00:58 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (contentIsPassword) {
|
|
|
|
if (NS_SUCCEEDED(widget->BeginSecureKeyboardInput())) {
|
2011-10-17 07:59:28 -07:00
|
|
|
sInSecureInputMode = true;
|
2011-02-09 11:00:58 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-27 03:51:53 -08:00
|
|
|
IMEState newState = GetNewIMEState(aPresContext, aContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aPresContext == sPresContext && aContent == sContent) {
|
|
|
|
// actual focus isn't changing, but if IME enabled state is changing,
|
|
|
|
// we should do it.
|
2011-11-27 03:51:52 -08:00
|
|
|
InputContext context = widget->GetInputContext();
|
2011-11-27 03:51:53 -08:00
|
|
|
if (context.mIMEState.mEnabled == newState.mEnabled) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// the enabled state isn't changing.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-11-27 03:51:52 -08:00
|
|
|
aAction.mFocusChange = InputContextAction::FOCUS_NOT_CHANGED;
|
|
|
|
} else if (aAction.mFocusChange == InputContextAction::FOCUS_NOT_CHANGED) {
|
|
|
|
// If aContent isn't null or aContent is null but editable, somebody gets
|
|
|
|
// focus.
|
2011-11-27 03:51:53 -08:00
|
|
|
bool gotFocus = aContent || (newState.mEnabled == IMEState::ENABLED);
|
2011-11-27 03:51:52 -08:00
|
|
|
aAction.mFocusChange =
|
|
|
|
gotFocus ? InputContextAction::GOT_FOCUS : InputContextAction::LOST_FOCUS;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Current IME transaction should commit
|
|
|
|
if (sPresContext) {
|
2008-07-13 19:56:18 -07:00
|
|
|
nsCOMPtr<nsIWidget> oldWidget;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (sPresContext == aPresContext)
|
2008-07-13 19:56:18 -07:00
|
|
|
oldWidget = widget;
|
2007-03-22 10:30:00 -07:00
|
|
|
else
|
2008-07-13 19:56:18 -07:00
|
|
|
oldWidget = GetWidget(sPresContext);
|
|
|
|
if (oldWidget)
|
|
|
|
oldWidget->ResetInputState();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-11-27 03:51:53 -08:00
|
|
|
// Update IME state for new focus widget
|
|
|
|
SetIMEState(newState, aContent, widget, aAction);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
sPresContext = aPresContext;
|
|
|
|
sContent = aContent;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-05-02 08:34:35 -07:00
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsIMEStateManager::OnInstalledMenuKeyboardListener(bool aInstalling)
|
2007-05-02 08:34:35 -07:00
|
|
|
{
|
|
|
|
sInstalledMenuKeyboardListener = aInstalling;
|
2011-04-20 05:47:40 -07:00
|
|
|
|
2011-11-27 03:51:52 -08:00
|
|
|
InputContextAction action(InputContextAction::CAUSE_UNKNOWN,
|
|
|
|
aInstalling ? InputContextAction::MENU_GOT_PSEUDO_FOCUS :
|
|
|
|
InputContextAction::MENU_LOST_PSEUDO_FOCUS);
|
|
|
|
OnChangeFocusInternal(sPresContext, sContent, action);
|
2007-05-02 08:34:35 -07:00
|
|
|
}
|
|
|
|
|
2011-11-27 03:51:53 -08:00
|
|
|
void
|
|
|
|
nsIMEStateManager::OnClickInEditor(nsPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIDOMMouseEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
if (sPresContext != aPresContext || sContent != aContent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWidget> widget = GetWidget(aPresContext);
|
2012-09-14 03:00:31 -07:00
|
|
|
NS_ENSURE_TRUE_VOID(widget);
|
2011-11-27 03:51:53 -08:00
|
|
|
|
|
|
|
bool isTrusted;
|
2012-08-04 00:44:00 -07:00
|
|
|
nsresult rv = aMouseEvent->GetIsTrusted(&isTrusted);
|
2012-09-14 03:00:31 -07:00
|
|
|
NS_ENSURE_SUCCESS_VOID(rv);
|
2011-11-27 03:51:53 -08:00
|
|
|
if (!isTrusted) {
|
|
|
|
return; // ignore untrusted event.
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t button;
|
2011-11-27 03:51:53 -08:00
|
|
|
rv = aMouseEvent->GetButton(&button);
|
2012-09-14 03:00:31 -07:00
|
|
|
NS_ENSURE_SUCCESS_VOID(rv);
|
2011-11-27 03:51:53 -08:00
|
|
|
if (button != 0) {
|
|
|
|
return; // not a left click event.
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t clickCount;
|
2011-11-27 03:51:53 -08:00
|
|
|
rv = aMouseEvent->GetDetail(&clickCount);
|
2012-09-14 03:00:31 -07:00
|
|
|
NS_ENSURE_SUCCESS_VOID(rv);
|
2011-11-27 03:51:53 -08:00
|
|
|
if (clickCount != 1) {
|
|
|
|
return; // should notify only first click event.
|
|
|
|
}
|
|
|
|
|
|
|
|
InputContextAction action(InputContextAction::CAUSE_MOUSE,
|
|
|
|
InputContextAction::FOCUS_NOT_CHANGED);
|
|
|
|
IMEState newState = GetNewIMEState(aPresContext, aContent);
|
|
|
|
SetIMEState(newState, aContent, widget, action);
|
|
|
|
}
|
|
|
|
|
2010-05-04 10:40:39 -07:00
|
|
|
void
|
2011-11-27 03:51:53 -08:00
|
|
|
nsIMEStateManager::UpdateIMEState(const IMEState &aNewIMEState,
|
|
|
|
nsIContent* aContent)
|
2010-05-04 10:40:39 -07:00
|
|
|
{
|
|
|
|
if (!sPresContext) {
|
|
|
|
NS_WARNING("ISM doesn't know which editor has focus");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIWidget> widget = GetWidget(sPresContext);
|
|
|
|
if (!widget) {
|
|
|
|
NS_WARNING("focused widget is not found");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-05-26 19:04:14 -07:00
|
|
|
// Don't update IME state when enabled state isn't actually changed.
|
2011-11-27 03:51:52 -08:00
|
|
|
InputContext context = widget->GetInputContext();
|
2011-11-27 03:51:53 -08:00
|
|
|
if (context.mIMEState.mEnabled == aNewIMEState.mEnabled) {
|
2010-05-26 19:04:14 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-05-04 10:40:39 -07:00
|
|
|
// commit current composition
|
|
|
|
widget->ResetInputState();
|
|
|
|
|
2011-11-27 03:51:52 -08:00
|
|
|
InputContextAction action(InputContextAction::CAUSE_UNKNOWN,
|
|
|
|
InputContextAction::FOCUS_NOT_CHANGED);
|
|
|
|
SetIMEState(aNewIMEState, aContent, widget, action);
|
2010-05-04 10:40:39 -07:00
|
|
|
}
|
|
|
|
|
2011-11-27 03:51:53 -08:00
|
|
|
IMEState
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIMEStateManager::GetNewIMEState(nsPresContext* aPresContext,
|
|
|
|
nsIContent* aContent)
|
|
|
|
{
|
|
|
|
// On Printing or Print Preview, we don't need IME.
|
|
|
|
if (aPresContext->Type() == nsPresContext::eContext_PrintPreview ||
|
|
|
|
aPresContext->Type() == nsPresContext::eContext_Print) {
|
2011-11-27 03:51:53 -08:00
|
|
|
return IMEState(IMEState::DISABLED);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-11-27 03:51:53 -08:00
|
|
|
if (sInstalledMenuKeyboardListener) {
|
|
|
|
return IMEState(IMEState::DISABLED);
|
|
|
|
}
|
2007-05-02 08:34:35 -07:00
|
|
|
|
2008-02-13 04:51:00 -08:00
|
|
|
if (!aContent) {
|
|
|
|
// Even if there are no focused content, the focused document might be
|
|
|
|
// editable, such case is design mode.
|
|
|
|
nsIDocument* doc = aPresContext->Document();
|
2011-11-27 03:51:53 -08:00
|
|
|
if (doc && doc->HasFlag(NODE_IS_EDITABLE)) {
|
|
|
|
return IMEState(IMEState::ENABLED);
|
|
|
|
}
|
|
|
|
return IMEState(IMEState::DISABLED);
|
2008-02-13 04:51:00 -08:00
|
|
|
}
|
|
|
|
|
2008-02-08 09:58:09 -08:00
|
|
|
return aContent->GetDesiredIMEState();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-10-18 09:37:00 -07:00
|
|
|
// Helper class, used for IME enabled state change notification
|
|
|
|
class IMEEnabledStateChangedEvent : public nsRunnable {
|
|
|
|
public:
|
2012-08-22 08:56:38 -07:00
|
|
|
IMEEnabledStateChangedEvent(uint32_t aState)
|
2010-10-18 09:37:00 -07:00
|
|
|
: mState(aState)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run() {
|
|
|
|
nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
|
|
|
|
if (observerService) {
|
|
|
|
nsAutoString state;
|
|
|
|
state.AppendInt(mState);
|
2012-07-30 07:20:58 -07:00
|
|
|
observerService->NotifyObservers(nullptr, "ime-enabled-state-changed", state.get());
|
2010-10-18 09:37:00 -07:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mState;
|
2010-10-18 09:37:00 -07:00
|
|
|
};
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
2011-11-27 03:51:53 -08:00
|
|
|
nsIMEStateManager::SetIMEState(const IMEState &aState,
|
2010-11-22 22:48:03 -08:00
|
|
|
nsIContent* aContent,
|
2011-04-20 05:47:40 -07:00
|
|
|
nsIWidget* aWidget,
|
2011-11-27 03:51:52 -08:00
|
|
|
InputContextAction aAction)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-09-14 03:00:31 -07:00
|
|
|
NS_ENSURE_TRUE_VOID(aWidget);
|
2011-11-27 03:51:53 -08:00
|
|
|
|
2011-11-27 03:51:53 -08:00
|
|
|
InputContext oldContext = aWidget->GetInputContext();
|
|
|
|
|
2011-11-27 03:51:53 -08:00
|
|
|
InputContext context;
|
2011-11-27 03:51:53 -08:00
|
|
|
context.mIMEState = aState;
|
2011-11-27 03:51:53 -08:00
|
|
|
|
|
|
|
if (aContent && aContent->GetNameSpaceID() == kNameSpaceID_XHTML &&
|
|
|
|
(aContent->Tag() == nsGkAtoms::input ||
|
|
|
|
aContent->Tag() == nsGkAtoms::textarea)) {
|
|
|
|
aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::type,
|
|
|
|
context.mHTMLInputType);
|
2012-08-26 19:16:22 -07:00
|
|
|
aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::inputmode,
|
|
|
|
context.mHTMLInputInputmode);
|
2011-11-27 03:51:53 -08:00
|
|
|
aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::moz_action_hint,
|
|
|
|
context.mActionHint);
|
|
|
|
|
|
|
|
// if we don't have an action hint and return won't submit the form use "next"
|
|
|
|
if (context.mActionHint.IsEmpty() && aContent->Tag() == nsGkAtoms::input) {
|
|
|
|
bool willSubmit = false;
|
|
|
|
nsCOMPtr<nsIFormControl> control(do_QueryInterface(aContent));
|
|
|
|
mozilla::dom::Element* formElement = control->GetFormElement();
|
|
|
|
nsCOMPtr<nsIForm> form;
|
|
|
|
if (control) {
|
|
|
|
// is this a form and does it have a default submit element?
|
|
|
|
if ((form = do_QueryInterface(formElement)) && form->GetDefaultSubmitElement()) {
|
|
|
|
willSubmit = true;
|
|
|
|
// is this an html form and does it only have a single text input element?
|
|
|
|
} else if (formElement && formElement->Tag() == nsGkAtoms::form && formElement->IsHTML() &&
|
|
|
|
static_cast<nsHTMLFormElement*>(formElement)->HasSingleTextControl()) {
|
|
|
|
willSubmit = true;
|
2011-01-31 06:23:58 -08:00
|
|
|
}
|
|
|
|
}
|
2011-11-27 03:51:53 -08:00
|
|
|
context.mActionHint.Assign(willSubmit ? control->GetType() == NS_FORM_INPUT_SEARCH
|
|
|
|
? NS_LITERAL_STRING("search")
|
|
|
|
: NS_LITERAL_STRING("go")
|
|
|
|
: formElement
|
|
|
|
? NS_LITERAL_STRING("next")
|
|
|
|
: EmptyString());
|
2010-11-22 22:48:03 -08:00
|
|
|
}
|
2011-11-27 03:51:53 -08:00
|
|
|
}
|
2010-11-22 22:48:03 -08:00
|
|
|
|
2011-11-27 03:51:53 -08:00
|
|
|
// XXX I think that we should use nsContentUtils::IsCallerChrome() instead
|
|
|
|
// of the process type.
|
|
|
|
if (aAction.mCause == InputContextAction::CAUSE_UNKNOWN &&
|
|
|
|
XRE_GetProcessType() != GeckoProcessType_Content) {
|
|
|
|
aAction.mCause = InputContextAction::CAUSE_UNKNOWN_CHROME;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-11-27 03:51:53 -08:00
|
|
|
|
|
|
|
aWidget->SetInputContext(context, aAction);
|
2011-11-27 03:51:53 -08:00
|
|
|
if (oldContext.mIMEState.mEnabled != context.mIMEState.mEnabled) {
|
2011-11-27 03:51:53 -08:00
|
|
|
nsContentUtils::AddScriptRunner(
|
|
|
|
new IMEEnabledStateChangedEvent(context.mIMEState.mEnabled));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-13 19:56:18 -07:00
|
|
|
nsIWidget*
|
|
|
|
nsIMEStateManager::GetWidget(nsPresContext* aPresContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-03-11 08:43:08 -07:00
|
|
|
nsIPresShell* shell = aPresContext->GetPresShell();
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ENSURE_TRUE(shell, nullptr);
|
2009-03-11 08:43:08 -07:00
|
|
|
|
|
|
|
nsIViewManager* vm = shell->GetViewManager();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!vm)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
|
|
|
nsCOMPtr<nsIWidget> widget = nullptr;
|
2009-07-21 17:45:05 -07:00
|
|
|
nsresult rv = vm->GetRootWidget(getter_AddRefs(widget));
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
2008-07-13 19:56:18 -07:00
|
|
|
return widget;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
|
|
|
|
// nsTextStateManager notifies widget of any text and selection changes
|
|
|
|
// in the currently focused editor
|
|
|
|
// sTextStateObserver points to the currently active nsTextStateManager
|
|
|
|
// sTextStateObserver is null if there is no focused editor
|
|
|
|
|
2012-06-18 19:30:09 -07:00
|
|
|
class nsTextStateManager MOZ_FINAL : public nsISelectionListener,
|
|
|
|
public nsStubMutationObserver
|
2009-02-10 12:56:51 -08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsTextStateManager();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSISELECTIONLISTENER
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
|
|
|
|
|
|
|
|
nsresult Init(nsIWidget* aWidget,
|
|
|
|
nsPresContext* aPresContext,
|
2010-09-23 20:28:15 -07:00
|
|
|
nsINode* aNode,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aWantUpdates);
|
2009-02-10 12:56:51 -08:00
|
|
|
void Destroy(void);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWidget> mWidget;
|
|
|
|
nsCOMPtr<nsISelection> mSel;
|
|
|
|
nsCOMPtr<nsIContent> mRootContent;
|
|
|
|
nsCOMPtr<nsINode> mEditableNode;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mDestroying;
|
2009-02-10 12:56:51 -08:00
|
|
|
|
|
|
|
private:
|
2012-08-22 08:56:38 -07:00
|
|
|
void NotifyContentAdded(nsINode* aContainer, int32_t aStart, int32_t aEnd);
|
2009-02-10 12:56:51 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
nsTextStateManager::nsTextStateManager()
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
mDestroying = false;
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextStateManager::Init(nsIWidget* aWidget,
|
|
|
|
nsPresContext* aPresContext,
|
2010-09-23 20:28:15 -07:00
|
|
|
nsINode* aNode,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aWantUpdates)
|
2009-02-10 12:56:51 -08:00
|
|
|
{
|
|
|
|
mWidget = aWidget;
|
2011-08-09 16:05:00 -07:00
|
|
|
MOZ_ASSERT(mWidget);
|
2010-09-23 20:28:15 -07:00
|
|
|
if (!aWantUpdates) {
|
|
|
|
mEditableNode = aNode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
nsIPresShell* presShell = aPresContext->PresShell();
|
|
|
|
|
|
|
|
// get selection and root content
|
|
|
|
nsCOMPtr<nsISelectionController> selCon;
|
|
|
|
if (aNode->IsNodeOfType(nsINode::eCONTENT)) {
|
2009-12-24 13:20:05 -08:00
|
|
|
nsIFrame* frame = static_cast<nsIContent*>(aNode)->GetPrimaryFrame();
|
2009-02-10 12:56:51 -08:00
|
|
|
NS_ENSURE_TRUE(frame, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
frame->GetSelectionController(aPresContext,
|
|
|
|
getter_AddRefs(selCon));
|
|
|
|
} else {
|
|
|
|
// aNode is a document
|
|
|
|
selCon = do_QueryInterface(presShell);
|
|
|
|
}
|
|
|
|
NS_ENSURE_TRUE(selCon, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsISelection> sel;
|
|
|
|
nsresult rv = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
|
|
|
|
getter_AddRefs(sel));
|
|
|
|
NS_ENSURE_TRUE(sel, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMRange> selDomRange;
|
|
|
|
rv = sel->GetRangeAt(0, getter_AddRefs(selDomRange));
|
|
|
|
|
2010-09-23 20:34:28 -07:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-01-10 06:19:54 -08:00
|
|
|
nsRange* selRange = static_cast<nsRange*>(selDomRange.get());
|
2010-09-23 20:34:28 -07:00
|
|
|
NS_ENSURE_TRUE(selRange && selRange->GetStartParent(),
|
|
|
|
NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
mRootContent = selRange->GetStartParent()->
|
2009-02-10 12:56:51 -08:00
|
|
|
GetSelectionRootContent(presShell);
|
2010-09-23 20:34:28 -07:00
|
|
|
} else {
|
|
|
|
mRootContent = aNode->GetSelectionRootContent(presShell);
|
|
|
|
}
|
2009-04-16 22:01:23 -07:00
|
|
|
if (!mRootContent && aNode->IsNodeOfType(nsINode::eDOCUMENT)) {
|
|
|
|
// The document node is editable, but there are no contents, this document
|
|
|
|
// is not editable.
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
NS_ENSURE_TRUE(mRootContent, NS_ERROR_UNEXPECTED);
|
2009-02-10 12:56:51 -08:00
|
|
|
|
|
|
|
// add text change observer
|
|
|
|
mRootContent->AddMutationObserver(this);
|
|
|
|
|
|
|
|
// add selection change listener
|
|
|
|
nsCOMPtr<nsISelectionPrivate> selPrivate(do_QueryInterface(sel));
|
|
|
|
NS_ENSURE_TRUE(selPrivate, NS_ERROR_UNEXPECTED);
|
|
|
|
rv = selPrivate->AddSelectionListener(this);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
mSel = sel;
|
|
|
|
|
|
|
|
mEditableNode = aNode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTextStateManager::Destroy(void)
|
|
|
|
{
|
|
|
|
if (mSel) {
|
|
|
|
nsCOMPtr<nsISelectionPrivate> selPrivate(do_QueryInterface(mSel));
|
|
|
|
if (selPrivate)
|
|
|
|
selPrivate->RemoveSelectionListener(this);
|
2012-07-30 07:20:58 -07:00
|
|
|
mSel = nullptr;
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
if (mRootContent) {
|
|
|
|
mRootContent->RemoveMutationObserver(this);
|
2012-07-30 07:20:58 -07:00
|
|
|
mRootContent = nullptr;
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
mEditableNode = nullptr;
|
|
|
|
mWidget = nullptr;
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS2(nsTextStateManager,
|
|
|
|
nsIMutationObserver,
|
|
|
|
nsISelectionListener)
|
|
|
|
|
2010-08-04 12:22:50 -07:00
|
|
|
// Helper class, used for selection change notification
|
|
|
|
class SelectionChangeEvent : public nsRunnable {
|
|
|
|
public:
|
|
|
|
SelectionChangeEvent(nsIWidget *widget)
|
|
|
|
: mWidget(widget)
|
|
|
|
{
|
2011-08-09 16:05:00 -07:00
|
|
|
MOZ_ASSERT(mWidget);
|
2010-08-04 12:22:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run() {
|
2011-08-09 16:05:00 -07:00
|
|
|
if(mWidget) {
|
|
|
|
mWidget->OnIMESelectionChange();
|
|
|
|
}
|
2010-08-04 12:22:50 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIWidget> mWidget;
|
|
|
|
};
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
nsresult
|
|
|
|
nsTextStateManager::NotifySelectionChanged(nsIDOMDocument* aDoc,
|
|
|
|
nsISelection* aSel,
|
2012-08-22 08:56:38 -07:00
|
|
|
int16_t aReason)
|
2009-02-10 12:56:51 -08:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t count = 0;
|
2009-02-10 12:56:51 -08:00
|
|
|
nsresult rv = aSel->GetRangeCount(&count);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-08-09 16:05:00 -07:00
|
|
|
if (count > 0 && mWidget) {
|
2010-08-04 12:22:50 -07:00
|
|
|
nsContentUtils::AddScriptRunner(new SelectionChangeEvent(mWidget));
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-08-04 12:22:50 -07:00
|
|
|
// Helper class, used for text change notification
|
|
|
|
class TextChangeEvent : public nsRunnable {
|
|
|
|
public:
|
|
|
|
TextChangeEvent(nsIWidget *widget,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t start, uint32_t oldEnd, uint32_t newEnd)
|
2010-08-04 12:22:50 -07:00
|
|
|
: mWidget(widget)
|
|
|
|
, mStart(start)
|
|
|
|
, mOldEnd(oldEnd)
|
|
|
|
, mNewEnd(newEnd)
|
|
|
|
{
|
2011-08-09 16:05:00 -07:00
|
|
|
MOZ_ASSERT(mWidget);
|
2010-08-04 12:22:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run() {
|
2011-08-09 16:05:00 -07:00
|
|
|
if(mWidget) {
|
|
|
|
mWidget->OnIMETextChange(mStart, mOldEnd, mNewEnd);
|
|
|
|
}
|
2010-08-04 12:22:50 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIWidget> mWidget;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mStart, mOldEnd, mNewEnd;
|
2010-08-04 12:22:50 -07:00
|
|
|
};
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
void
|
|
|
|
nsTextStateManager::CharacterDataChanged(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContent,
|
|
|
|
CharacterDataChangeInfo* aInfo)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aContent->IsNodeOfType(nsINode::eTEXT),
|
|
|
|
"character data changed for non-text node");
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t offset = 0;
|
2009-02-10 12:56:51 -08:00
|
|
|
// get offsets of change and fire notification
|
|
|
|
if (NS_FAILED(nsContentEventHandler::GetFlatTextOffsetOfRange(
|
|
|
|
mRootContent, aContent, aInfo->mChangeStart, &offset)))
|
|
|
|
return;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t oldEnd = offset + aInfo->mChangeEnd - aInfo->mChangeStart;
|
|
|
|
uint32_t newEnd = offset + aInfo->mReplaceLength;
|
2010-08-04 12:22:50 -07:00
|
|
|
|
|
|
|
nsContentUtils::AddScriptRunner(
|
|
|
|
new TextChangeEvent(mWidget, offset, oldEnd, newEnd));
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTextStateManager::NotifyContentAdded(nsINode* aContainer,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aStartIndex,
|
|
|
|
int32_t aEndIndex)
|
2009-02-10 12:56:51 -08:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t offset = 0, newOffset = 0;
|
2009-02-10 12:56:51 -08:00
|
|
|
if (NS_FAILED(nsContentEventHandler::GetFlatTextOffsetOfRange(
|
|
|
|
mRootContent, aContainer, aStartIndex, &offset)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// get offset at the end of the last added node
|
|
|
|
if (NS_FAILED(nsContentEventHandler::GetFlatTextOffsetOfRange(
|
|
|
|
aContainer->GetChildAt(aStartIndex),
|
|
|
|
aContainer, aEndIndex, &newOffset)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// fire notification
|
|
|
|
if (newOffset)
|
2010-08-04 12:22:50 -07:00
|
|
|
nsContentUtils::AddScriptRunner(
|
|
|
|
new TextChangeEvent(mWidget, offset, offset, offset + newOffset));
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTextStateManager::ContentAppended(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
2010-05-10 18:12:34 -07:00
|
|
|
nsIContent* aFirstNewContent,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aNewIndexInContainer)
|
2009-02-10 12:56:51 -08:00
|
|
|
{
|
|
|
|
NotifyContentAdded(aContainer, aNewIndexInContainer,
|
|
|
|
aContainer->GetChildCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTextStateManager::ContentInserted(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aIndexInContainer)
|
2009-02-10 12:56:51 -08:00
|
|
|
{
|
|
|
|
NotifyContentAdded(NODE_FROM(aContainer, aDocument),
|
|
|
|
aIndexInContainer, aIndexInContainer + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTextStateManager::ContentRemoved(nsIDocument* aDocument,
|
2010-07-21 15:05:17 -07:00
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aIndexInContainer,
|
2010-07-21 15:05:17 -07:00
|
|
|
nsIContent* aPreviousSibling)
|
2009-02-10 12:56:51 -08:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t offset = 0, childOffset = 1;
|
2009-02-10 12:56:51 -08:00
|
|
|
if (NS_FAILED(nsContentEventHandler::GetFlatTextOffsetOfRange(
|
|
|
|
mRootContent, NODE_FROM(aContainer, aDocument),
|
|
|
|
aIndexInContainer, &offset)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// get offset at the end of the deleted node
|
|
|
|
if (aChild->IsNodeOfType(nsINode::eTEXT))
|
|
|
|
childOffset = aChild->TextLength();
|
|
|
|
else if (0 < aChild->GetChildCount())
|
|
|
|
childOffset = aChild->GetChildCount();
|
|
|
|
|
|
|
|
if (NS_FAILED(nsContentEventHandler::GetFlatTextOffsetOfRange(
|
|
|
|
aChild, aChild, childOffset, &childOffset)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// fire notification
|
|
|
|
if (childOffset)
|
2010-08-04 12:22:50 -07:00
|
|
|
nsContentUtils::AddScriptRunner(
|
|
|
|
new TextChangeEvent(mWidget, offset, offset + childOffset, offset));
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
|
2012-05-24 14:49:44 -07:00
|
|
|
static bool IsEditable(nsINode* node) {
|
|
|
|
if (node->IsEditable()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// |node| might be readwrite (for example, a text control)
|
|
|
|
if (node->IsElement() && node->AsElement()->State().HasState(NS_EVENT_STATE_MOZ_READWRITE)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
static nsINode* GetRootEditableNode(nsPresContext* aPresContext,
|
|
|
|
nsIContent* aContent)
|
|
|
|
{
|
|
|
|
if (aContent) {
|
2012-07-30 07:20:58 -07:00
|
|
|
nsINode* root = nullptr;
|
2011-03-23 07:45:21 -07:00
|
|
|
nsINode* node = aContent;
|
2012-05-24 14:49:44 -07:00
|
|
|
while (node && IsEditable(node)) {
|
2011-03-23 07:45:21 -07:00
|
|
|
root = node;
|
|
|
|
node = node->GetNodeParent();
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
return root;
|
|
|
|
}
|
|
|
|
if (aPresContext) {
|
|
|
|
nsIDocument* document = aPresContext->Document();
|
|
|
|
if (document && document->IsEditable())
|
|
|
|
return document;
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsIMEStateManager::OnTextStateBlur(nsPresContext* aPresContext,
|
|
|
|
nsIContent* aContent)
|
|
|
|
{
|
|
|
|
if (!sTextStateObserver || sTextStateObserver->mDestroying ||
|
|
|
|
sTextStateObserver->mEditableNode ==
|
|
|
|
GetRootEditableNode(aPresContext, aContent))
|
|
|
|
return NS_OK;
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
sTextStateObserver->mDestroying = true;
|
|
|
|
sTextStateObserver->mWidget->OnIMEFocusChange(false);
|
2009-02-10 12:56:51 -08:00
|
|
|
sTextStateObserver->Destroy();
|
|
|
|
NS_RELEASE(sTextStateObserver);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsIMEStateManager::OnTextStateFocus(nsPresContext* aPresContext,
|
|
|
|
nsIContent* aContent)
|
|
|
|
{
|
|
|
|
if (sTextStateObserver) return NS_OK;
|
|
|
|
|
|
|
|
nsINode *editableNode = GetRootEditableNode(aPresContext, aContent);
|
|
|
|
if (!editableNode) return NS_OK;
|
|
|
|
|
2009-03-11 08:43:08 -07:00
|
|
|
nsIPresShell* shell = aPresContext->GetPresShell();
|
|
|
|
NS_ENSURE_TRUE(shell, NS_ERROR_NOT_AVAILABLE);
|
|
|
|
|
|
|
|
nsIViewManager* vm = shell->GetViewManager();
|
2009-02-10 12:56:51 -08:00
|
|
|
NS_ENSURE_TRUE(vm, NS_ERROR_NOT_AVAILABLE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWidget> widget;
|
2009-07-21 17:45:05 -07:00
|
|
|
nsresult rv = vm->GetRootWidget(getter_AddRefs(widget));
|
2009-02-10 12:56:51 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_NOT_AVAILABLE);
|
2009-11-17 04:40:59 -08:00
|
|
|
if (!widget) {
|
|
|
|
return NS_OK; // Sometimes, there are no widgets.
|
|
|
|
}
|
2009-02-10 12:56:51 -08:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
rv = widget->OnIMEFocusChange(true);
|
2009-04-16 22:01:23 -07:00
|
|
|
if (rv == NS_ERROR_NOT_IMPLEMENTED)
|
|
|
|
return NS_OK;
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-02-10 12:56:51 -08:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool wantUpdates = rv != NS_SUCCESS_IME_NO_UPDATES;
|
2010-09-23 20:28:15 -07:00
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
// OnIMEFocusChange may cause focus and sTextStateObserver to change
|
|
|
|
// In that case return and keep the current sTextStateObserver
|
|
|
|
NS_ENSURE_TRUE(!sTextStateObserver, NS_OK);
|
|
|
|
|
|
|
|
sTextStateObserver = new nsTextStateManager();
|
|
|
|
NS_ENSURE_TRUE(sTextStateObserver, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
NS_ADDREF(sTextStateObserver);
|
2010-09-23 20:28:15 -07:00
|
|
|
rv = sTextStateObserver->Init(widget, aPresContext,
|
|
|
|
editableNode, wantUpdates);
|
2009-02-10 12:56:51 -08:00
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
sTextStateObserver->mDestroying = true;
|
2009-02-10 12:56:51 -08:00
|
|
|
sTextStateObserver->Destroy();
|
|
|
|
NS_RELEASE(sTextStateObserver);
|
2011-10-17 07:59:28 -07:00
|
|
|
widget->OnIMEFocusChange(false);
|
2009-02-10 12:56:51 -08:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsIMEStateManager::GetFocusSelectionAndRoot(nsISelection** aSel,
|
|
|
|
nsIContent** aRoot)
|
|
|
|
{
|
2010-12-10 09:31:23 -08:00
|
|
|
if (!sTextStateObserver || !sTextStateObserver->mEditableNode ||
|
|
|
|
!sTextStateObserver->mSel)
|
2009-02-10 12:56:51 -08:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
NS_ASSERTION(sTextStateObserver->mSel && sTextStateObserver->mRootContent,
|
|
|
|
"uninitialized text state observer");
|
|
|
|
NS_ADDREF(*aSel = sTextStateObserver->mSel);
|
|
|
|
NS_ADDREF(*aRoot = sTextStateObserver->mRootContent);
|
|
|
|
return NS_OK;
|
|
|
|
}
|