Bug 802896 nsIMEStateManager should use nsPresContext::GetNearestWidget() instead of its GetWidget() r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 17 Oct 2012 16:50:24 +0900
changeset 110861 3a9b5deb064355a7628b0b129ecd0f621b402cdd
parent 110860 49606de3e007de2ac18bec51d563690c06dddb4c
child 110862 73976ead8d6c60384840e962e98ab62f965f15c9
push id23717
push userryanvm@gmail.com
push dateSat, 20 Oct 2012 16:43:11 +0000
treeherdermozilla-central@5d03feda2300 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs802896
milestone19.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 802896 nsIMEStateManager should use nsPresContext::GetNearestWidget() instead of its GetWidget() r=smaug
content/events/src/nsIMEStateManager.cpp
content/events/src/nsIMEStateManager.h
--- a/content/events/src/nsIMEStateManager.cpp
+++ b/content/events/src/nsIMEStateManager.cpp
@@ -74,17 +74,17 @@ nsIMEStateManager::OnDestroyPresContext(
       sTextCompositions->RemoveElementAt(i);
       MOZ_ASSERT(sTextCompositions->IndexOf(aPresContext) ==
                    TextCompositionArray::NoIndex);
     }
   }
 
   if (aPresContext != sPresContext)
     return NS_OK;
-  nsCOMPtr<nsIWidget> widget = GetWidget(sPresContext);
+  nsCOMPtr<nsIWidget> widget = sPresContext->GetNearestWidget();
   if (widget) {
     IMEState newState = GetNewIMEState(sPresContext, nullptr);
     InputContextAction action(InputContextAction::CAUSE_UNKNOWN,
                               InputContextAction::LOST_FOCUS);
     SetIMEState(newState, nullptr, widget, action);
   }
   NS_IF_RELEASE(sContent);
   sPresContext = nullptr;
@@ -133,17 +133,17 @@ nsIMEStateManager::OnRemoveContent(nsPre
   }
 
   if (!sPresContext || !sContent ||
       !nsContentUtils::ContentIsDescendantOf(sContent, aContent)) {
     return NS_OK;
   }
 
   // Current IME transaction should commit
-  nsCOMPtr<nsIWidget> widget = GetWidget(sPresContext);
+  nsCOMPtr<nsIWidget> widget = sPresContext->GetNearestWidget();
   if (widget) {
     IMEState newState = GetNewIMEState(sPresContext, nullptr);
     InputContextAction action(InputContextAction::CAUSE_UNKNOWN,
                               InputContextAction::LOST_FOCUS);
     SetIMEState(newState, nullptr, widget, action);
   }
 
   NS_IF_RELEASE(sContent);
@@ -163,17 +163,17 @@ nsIMEStateManager::OnChangeFocus(nsPresC
 
 nsresult
 nsIMEStateManager::OnChangeFocusInternal(nsPresContext* aPresContext,
                                          nsIContent* aContent,
                                          InputContextAction aAction)
 {
   NS_ENSURE_ARG_POINTER(aPresContext);
 
-  nsCOMPtr<nsIWidget> widget = GetWidget(aPresContext);
+  nsCOMPtr<nsIWidget> widget = aPresContext->GetNearestWidget();
   if (!widget) {
     return NS_OK;
   }
 
   // Handle secure input mode for password field input.
   bool contentIsPassword = false;
   if (aContent && aContent->GetNameSpaceID() == kNameSpaceID_XHTML) {
     if (aContent->Tag() == nsGkAtoms::input) {
@@ -215,17 +215,17 @@ nsIMEStateManager::OnChangeFocusInternal
   }
 
   // Current IME transaction should commit
   if (sPresContext) {
     nsCOMPtr<nsIWidget> oldWidget;
     if (sPresContext == aPresContext)
       oldWidget = widget;
     else
-      oldWidget = GetWidget(sPresContext);
+      oldWidget = sPresContext->GetNearestWidget();
     if (oldWidget) {
       NotifyIME(REQUEST_TO_COMMIT_COMPOSITION, oldWidget);
     }
   }
 
   // Update IME state for new focus widget
   SetIMEState(newState, aContent, widget, aAction);
 
@@ -253,17 +253,17 @@ void
 nsIMEStateManager::OnClickInEditor(nsPresContext* aPresContext,
                                    nsIContent* aContent,
                                    nsIDOMMouseEvent* aMouseEvent)
 {
   if (sPresContext != aPresContext || sContent != aContent) {
     return;
   }
 
-  nsCOMPtr<nsIWidget> widget = GetWidget(aPresContext);
+  nsCOMPtr<nsIWidget> widget = aPresContext->GetNearestWidget();
   NS_ENSURE_TRUE_VOID(widget);
 
   bool isTrusted;
   nsresult rv = aMouseEvent->GetIsTrusted(&isTrusted);
   NS_ENSURE_SUCCESS_VOID(rv);
   if (!isTrusted) {
     return; // ignore untrusted event.
   }
@@ -291,17 +291,17 @@ nsIMEStateManager::OnClickInEditor(nsPre
 void
 nsIMEStateManager::UpdateIMEState(const IMEState &aNewIMEState,
                                   nsIContent* aContent)
 {
   if (!sPresContext) {
     NS_WARNING("ISM doesn't know which editor has focus");
     return;
   }
-  nsCOMPtr<nsIWidget> widget = GetWidget(sPresContext);
+  nsCOMPtr<nsIWidget> widget = sPresContext->GetNearestWidget();
   if (!widget) {
     NS_WARNING("focused widget is not found");
     return;
   }
 
   // Don't update IME state when enabled state isn't actually changed.
   InputContext context = widget->GetInputContext();
   if (context.mIMEState.mEnabled == aNewIMEState.mEnabled) {
@@ -422,31 +422,16 @@ nsIMEStateManager::SetIMEState(const IME
 
   aWidget->SetInputContext(context, aAction);
   if (oldContext.mIMEState.mEnabled != context.mIMEState.mEnabled) {
     nsContentUtils::AddScriptRunner(
       new IMEEnabledStateChangedEvent(context.mIMEState.mEnabled));
   }
 }
 
-nsIWidget*
-nsIMEStateManager::GetWidget(nsPresContext* aPresContext)
-{
-  nsIPresShell* shell = aPresContext->GetPresShell();
-  NS_ENSURE_TRUE(shell, nullptr);
-
-  nsIViewManager* vm = shell->GetViewManager();
-  if (!vm)
-    return nullptr;
-  nsCOMPtr<nsIWidget> widget = nullptr;
-  nsresult rv = vm->GetRootWidget(getter_AddRefs(widget));
-  NS_ENSURE_SUCCESS(rv, nullptr);
-  return widget;
-}
-
 void
 nsIMEStateManager::EnsureTextCompositionArray()
 {
   if (sTextCompositions) {
     return;
   }
   sTextCompositions = new TextCompositionArray();
 }
--- a/content/events/src/nsIMEStateManager.h
+++ b/content/events/src/nsIMEStateManager.h
@@ -112,17 +112,16 @@ protected:
                                         InputContextAction aAction);
   static void SetIMEState(const IMEState &aState,
                           nsIContent* aContent,
                           nsIWidget* aWidget,
                           InputContextAction aAction);
   static IMEState GetNewIMEState(nsPresContext* aPresContext,
                                  nsIContent* aContent);
 
-  static nsIWidget* GetWidget(nsPresContext* aPresContext);
   static void EnsureTextCompositionArray();
 
   static nsIContent*    sContent;
   static nsPresContext* sPresContext;
   static bool           sInstalledMenuKeyboardListener;
   static bool           sInSecureInputMode;
 
   static nsTextStateManager* sTextStateObserver;