Bug 978023 part.4 Clean up IMEStateManager r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Sat, 08 Mar 2014 10:20:08 +0900
changeset 190852 062114c06fee2f09d18a758f3a322fdbeb0d3b2e
parent 190851 f9ff47c2057310858e571e259971205a457c8928
child 190853 0f472b5d1d7af7c62c9ba88fdf420a96a8781a5b
push id474
push userasasaki@mozilla.com
push dateMon, 02 Jun 2014 21:01:02 +0000
treeherdermozilla-release@967f4cf1b31c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs978023
milestone30.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 978023 part.4 Clean up IMEStateManager r=smaug
dom/events/IMEStateManager.cpp
--- a/dom/events/IMEStateManager.cpp
+++ b/dom/events/IMEStateManager.cpp
@@ -1,37 +1,39 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=2 sw=2 et 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/. */
 
 #include "mozilla/IMEStateManager.h"
 
+#include "mozilla/Attributes.h"
+#include "mozilla/Preferences.h"
+#include "mozilla/Services.h"
+#include "mozilla/TextEvents.h"
+#include "mozilla/dom/HTMLFormElement.h"
+
+#include "HTMLInputElement.h"
 #include "IMEContentObserver.h"
-#include "HTMLInputElement.h"
+#include "TextComposition.h"
+
 #include "nsCOMPtr.h"
-#include "nsIPresShell.h"
-#include "nsISupports.h"
+#include "nsContentUtils.h"
 #include "nsIContent.h"
 #include "nsIDocument.h"
-#include "nsPresContext.h"
 #include "nsIDOMMouseEvent.h"
-#include "nsContentUtils.h"
+#include "nsIForm.h"
+#include "nsIFormControl.h"
 #include "nsINode.h"
-#include "nsISelection.h"
 #include "nsIObserverService.h"
-#include "mozilla/Services.h"
-#include "nsIFormControl.h"
-#include "nsIForm.h"
-#include "mozilla/dom/HTMLFormElement.h"
-#include "mozilla/Attributes.h"
-#include "mozilla/TextEvents.h"
-#include "TextComposition.h"
-#include "mozilla/Preferences.h"
+#include "nsIPresShell.h"
+#include "nsISelection.h"
+#include "nsISupports.h"
+#include "nsPresContext.h"
 
 namespace mozilla {
 
 using namespace dom;
 using namespace widget;
 
 nsIContent* IMEStateManager::sContent = nullptr;
 nsPresContext* IMEStateManager::sPresContext = nullptr;
@@ -64,18 +66,19 @@ IMEStateManager::OnDestroyPresContext(ns
       // there should be only one composition per presContext object.
       sTextCompositions->ElementAt(i)->Destroy();
       sTextCompositions->RemoveElementAt(i);
       MOZ_ASSERT(sTextCompositions->IndexOf(aPresContext) ==
                    TextCompositionArray::NoIndex);
     }
   }
 
-  if (aPresContext != sPresContext)
+  if (aPresContext != sPresContext) {
     return NS_OK;
+  }
 
   DestroyTextStateManager();
 
   nsCOMPtr<nsIWidget> widget = sPresContext->GetRootWidget();
   if (widget) {
     IMEState newState = GetNewIMEState(sPresContext, nullptr);
     InputContextAction action(InputContextAction::CAUSE_UNKNOWN,
                               InputContextAction::LOST_FOCUS);
@@ -373,23 +376,25 @@ IMEStateManager::GetNewIMEState(nsPresCo
 // Helper class, used for IME enabled state change notification
 class IMEEnabledStateChangedEvent : public nsRunnable {
 public:
   IMEEnabledStateChangedEvent(uint32_t aState)
     : mState(aState)
   {
   }
 
-  NS_IMETHOD Run() {
+  NS_IMETHOD Run()
+  {
     nsCOMPtr<nsIObserverService> observerService =
       services::GetObserverService();
     if (observerService) {
       nsAutoString state;
       state.AppendInt(mState);
-      observerService->NotifyObservers(nullptr, "ime-enabled-state-changed", state.get());
+      observerService->NotifyObservers(nullptr, "ime-enabled-state-changed",
+                                       state.get());
     }
     return NS_OK;
   }
 
 private:
   uint32_t mState;
 };
 
@@ -441,45 +446,49 @@ IMEStateManager::SetIMEState(const IMESt
     // 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()) {
+        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<dom::HTMLFormElement*>(formElement)->ImplicitSubmissionIsDisabled()) {
+        } else if (formElement && formElement->Tag() == nsGkAtoms::form &&
+                   formElement->IsHTML() &&
+                   !static_cast<dom::HTMLFormElement*>(formElement)->
+                     ImplicitSubmissionIsDisabled()) {
           willSubmit = true;
         }
       }
-      context.mActionHint.Assign(willSubmit ? control->GetType() == NS_FORM_INPUT_SEARCH
-                                                ? NS_LITERAL_STRING("search")
-                                                : NS_LITERAL_STRING("go")
-                                            : formElement
-                                                ? NS_LITERAL_STRING("next")
-                                                : EmptyString());
+      context.mActionHint.Assign(
+        willSubmit ? (control->GetType() == NS_FORM_INPUT_SEARCH ?
+                       NS_LITERAL_STRING("search") : NS_LITERAL_STRING("go")) :
+                     (formElement ?
+                       NS_LITERAL_STRING("next") : EmptyString()));
     }
   }
 
   // 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;
   }
 
   aWidget->SetInputContext(context, aAction);
-  if (oldContext.mIMEState.mEnabled != context.mIMEState.mEnabled) {
-    nsContentUtils::AddScriptRunner(
-      new IMEEnabledStateChangedEvent(context.mIMEState.mEnabled));
+  if (oldContext.mIMEState.mEnabled == context.mIMEState.mEnabled) {
+    return;
   }
+
+  nsContentUtils::AddScriptRunner(
+    new IMEEnabledStateChangedEvent(context.mIMEState.mEnabled));
 }
 
 void
 IMEStateManager::EnsureTextCompositionArray()
 {
   if (sTextCompositions) {
     return;
   }
@@ -635,17 +644,18 @@ IMEStateManager::NotifyIME(IMEMessage aM
 
 bool
 IMEStateManager::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)) {
+  if (node->IsElement() &&
+      node->AsElement()->State().HasState(NS_EVENT_STATE_MOZ_READWRITE)) {
     return true;
   }
   return false;
 }
 
 nsINode*
 IMEStateManager::GetRootEditableNode(nsPresContext* aPresContext,
                                      nsIContent* aContent)
@@ -656,18 +666,19 @@ IMEStateManager::GetRootEditableNode(nsP
     while (node && IsEditable(node)) {
       root = node;
       node = node->GetParentNode();
     }
     return root;
   }
   if (aPresContext) {
     nsIDocument* document = aPresContext->Document();
-    if (document && document->IsEditable())
+    if (document && document->IsEditable()) {
       return document;
+    }
   }
   return nullptr;
 }
 
 bool
 IMEStateManager::IsEditableIMEState(nsIWidget* aWidget)
 {
   switch (aWidget->GetInputContext().mIMEState.mEnabled) {