Bug 1056545 part.3 ns*EditorEventListener should conform to current coding rules r=ehsan
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 26 Aug 2014 09:57:46 +0900
changeset 201606 c43e2df984a603ad888a14676e57f3bfe0f49a76
parent 201605 c2c4c70d0be36493b7736d4981b47e3c3fb9bac4
child 201607 8b7c34d6dec5a22760138da5aefb3dba2a0a9241
push id27375
push userryanvm@gmail.com
push dateTue, 26 Aug 2014 19:56:59 +0000
treeherdermozilla-central@f9bfe115fee5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1056545
milestone34.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 1056545 part.3 ns*EditorEventListener should conform to current coding rules r=ehsan
editor/libeditor/nsEditorEventListener.cpp
editor/libeditor/nsHTMLEditorEventListener.cpp
--- a/editor/libeditor/nsEditorEventListener.cpp
+++ b/editor/libeditor/nsEditorEventListener.cpp
@@ -86,19 +86,20 @@ DoCommandCallback(Command aCommand, void
   bool commandEnabled;
   nsresult rv = controller->IsCommandEnabled(commandStr, &commandEnabled);
   NS_ENSURE_SUCCESS_VOID(rv);
   if (commandEnabled) {
     controller->DoCommand(commandStr);
   }
 }
 
-nsEditorEventListener::nsEditorEventListener() :
-  mEditor(nullptr), mCommitText(false),
-  mInTransaction(false)
+nsEditorEventListener::nsEditorEventListener()
+  : mEditor(nullptr)
+  , mCommitText(false)
+  , mInTransaction(false)
 #ifdef HANDLE_NATIVE_TEXT_DIRECTION_SWITCH
   , mHaveBidiKeyboards(false)
   , mShouldSwitchTextDirection(false)
   , mSwitchToRTL(false)
 #endif
 {
 }
 
@@ -442,18 +443,19 @@ bool IsCtrlShiftPressed(bool& isRTL)
   // (or a left-shift key), we use the steps below:
   // 1. Check if a user is pressing a control key and a right-shift key (or
   //    a left-shift key).
   // 2. If the condition 1 is true, we should check if there are any other
   //    keys pressed at the same time.
   //    To ignore the keys checked in 1, we set their status to 0 before
   //    checking the key status.
   const int kKeyDownMask = 0x80;
-  if ((keystate[VK_CONTROL] & kKeyDownMask) == 0)
+  if ((keystate[VK_CONTROL] & kKeyDownMask) == 0) {
     return false;
+  }
 
   if (keystate[VK_RSHIFT] & kKeyDownMask) {
     keystate[VK_RSHIFT] = 0;
     isRTL = true;
   } else if (keystate[VK_LSHIFT] & kKeyDownMask) {
     keystate[VK_LSHIFT] = 0;
     isRTL = false;
   } else {
@@ -466,18 +468,19 @@ bool IsCtrlShiftPressed(bool& isRTL)
   // right-shift key (or a left-shift key), i.e. we should ignore the status of
   // the keys: VK_SHIFT, VK_CONTROL, VK_RCONTROL, and VK_LCONTROL.
   // So, we reset their status to 0 and ignore them.
   keystate[VK_SHIFT] = 0;
   keystate[VK_CONTROL] = 0;
   keystate[VK_RCONTROL] = 0;
   keystate[VK_LCONTROL] = 0;
   for (int i = 0; i <= VK_PACKET; ++i) {
-    if (keystate[i] & kKeyDownMask)
+    if (keystate[i] & kKeyDownMask) {
       return false;
+    }
   }
   return true;
 }
 
 }
 
 // This logic is mostly borrowed from Chromium's
 // RenderWidgetHostViewWin::OnKeyEvent.
@@ -619,58 +622,59 @@ nsEditorEventListener::MouseClick(nsIDOM
 
   // If we got a mouse down inside the editing area, we should force the 
   // IME to commit before we change the cursor position
   mEditor->ForceCompositionEnd();
 
   int16_t button = -1;
   aMouseEvent->GetButton(&button);
   // middle-mouse click (paste);
-  if (button == 1)
-  {
-    if (Preferences::GetBool("middlemouse.paste", false))
-    {
+  if (button == 1) {
+    if (Preferences::GetBool("middlemouse.paste", false)) {
       // Set the selection to the point under the mouse cursor:
       nsCOMPtr<nsIDOMNode> parent;
       if (NS_FAILED(aMouseEvent->GetRangeParent(getter_AddRefs(parent)))) {
         return NS_ERROR_NULL_POINTER;
       }
       int32_t offset = 0;
       if (NS_FAILED(aMouseEvent->GetRangeOffset(&offset))) {
         return NS_ERROR_NULL_POINTER;
       }
 
       nsCOMPtr<nsISelection> selection;
-      if (NS_SUCCEEDED(mEditor->GetSelection(getter_AddRefs(selection))))
-        (void)selection->Collapse(parent, offset);
+      if (NS_SUCCEEDED(mEditor->GetSelection(getter_AddRefs(selection)))) {
+        selection->Collapse(parent, offset);
+      }
 
       // If the ctrl key is pressed, we'll do paste as quotation.
       // Would've used the alt key, but the kde wmgr treats alt-middle specially. 
       bool ctrlKey = false;
       aMouseEvent->GetCtrlKey(&ctrlKey);
 
       nsCOMPtr<nsIEditorMailSupport> mailEditor;
-      if (ctrlKey)
+      if (ctrlKey) {
         mailEditor = do_QueryObject(mEditor);
+      }
 
       int32_t clipboard = nsIClipboard::kGlobalClipboard;
       nsCOMPtr<nsIClipboard> clipboardService =
         do_GetService("@mozilla.org/widget/clipboard;1", &rv);
       if (NS_SUCCEEDED(rv)) {
         bool selectionSupported;
         rv = clipboardService->SupportsSelectionClipboard(&selectionSupported);
         if (NS_SUCCEEDED(rv) && selectionSupported) {
           clipboard = nsIClipboard::kSelectionClipboard;
         }
       }
 
-      if (mailEditor)
+      if (mailEditor) {
         mailEditor->PasteAsQuotation(clipboard);
-      else
+      } else {
         mEditor->Paste(clipboard);
+      }
 
       // Prevent the event from propagating up to be possibly handled
       // again by the containing window:
       aMouseEvent->StopPropagation();
       aMouseEvent->PreventDefault();
 
       // We processed the event, whether drop/paste succeeded or not
       return NS_OK;
@@ -748,44 +752,39 @@ nsEditorEventListener::DragOver(nsIDOMDr
     if (mCaret) {
       int32_t offset = 0;
       nsresult rv = aDragEvent->GetRangeOffset(&offset);
       NS_ENSURE_SUCCESS(rv, rv);
 
       mCaret->SetVisible(true);
       mCaret->SetCaretPosition(parent, offset);
     }
-  }
-  else
-  {
+  } else {
     if (!IsFileControlTextBox()) {
       // This is needed when dropping on an input, to prevent the editor for
       // the editable parent from receiving the event.
       aDragEvent->StopPropagation();
     }
 
-    if (mCaret)
-    {
+    if (mCaret) {
       mCaret->SetVisible(false);
     }
   }
 
   return NS_OK;
 }
 
 void
 nsEditorEventListener::CleanupDragDropCaret()
 {
-  if (mCaret)
-  {
+  if (mCaret) {
     mCaret->SetVisible(false);    // hide it, so that it turns off its timer
 
     nsCOMPtr<nsIPresShell> presShell = GetPresShell();
-    if (presShell)
-    {
+    if (presShell) {
       nsCOMPtr<nsISelectionController> selCon(do_QueryInterface(presShell));
       if (selCon) {
         selCon->SetCaretEnabled(false);
       }
       presShell->RestoreCaret();
     }
 
     mCaret->Terminate();
@@ -864,60 +863,68 @@ nsEditorEventListener::CanDrop(nsIDOMDra
     return false;
   }
 
   // If there is no source node, this is probably an external drag and the
   // drop is allowed. The later checks rely on checking if the drag target
   // is the same as the drag source.
   nsCOMPtr<nsIDOMNode> sourceNode;
   dataTransfer->GetMozSourceNode(getter_AddRefs(sourceNode));
-  if (!sourceNode)
+  if (!sourceNode) {
     return true;
+  }
 
   // There is a source node, so compare the source documents and this document.
   // Disallow drops on the same document.
 
   nsCOMPtr<nsIDOMDocument> domdoc = mEditor->GetDOMDocument();
   NS_ENSURE_TRUE(domdoc, false);
 
   nsCOMPtr<nsIDOMDocument> sourceDoc;
   nsresult rv = sourceNode->GetOwnerDocument(getter_AddRefs(sourceDoc));
   NS_ENSURE_SUCCESS(rv, false);
-  if (domdoc == sourceDoc)      // source and dest are the same document; disallow drops within the selection
-  {
+
+  // source and dest are the same document; disallow drops within the selection
+  if (domdoc == sourceDoc) {
     nsCOMPtr<nsISelection> selection;
     rv = mEditor->GetSelection(getter_AddRefs(selection));
-    if (NS_FAILED(rv) || !selection)
+    if (NS_FAILED(rv) || !selection) {
       return false;
-    
+    }
+
     // Don't bother if collapsed - can always drop
     if (!selection->Collapsed()) {
       nsCOMPtr<nsIDOMNode> parent;
       rv = aEvent->GetRangeParent(getter_AddRefs(parent));
-      if (NS_FAILED(rv) || !parent) return false;
+      if (NS_FAILED(rv) || !parent) {
+        return false;
+      }
 
       int32_t offset = 0;
       rv = aEvent->GetRangeOffset(&offset);
       NS_ENSURE_SUCCESS(rv, false);
 
       int32_t rangeCount;
       rv = selection->GetRangeCount(&rangeCount);
       NS_ENSURE_SUCCESS(rv, false);
 
-      for (int32_t i = 0; i < rangeCount; i++)
-      {
+      for (int32_t i = 0; i < rangeCount; i++) {
         nsCOMPtr<nsIDOMRange> range;
         rv = selection->GetRangeAt(i, getter_AddRefs(range));
-        if (NS_FAILED(rv) || !range) 
-          continue; //don't bail yet, iterate through them all
+        if (NS_FAILED(rv) || !range) {
+          // Don't bail yet, iterate through them all
+          continue;
+        }
 
         bool inRange = true;
-        (void)range->IsPointInRange(parent, offset, &inRange);
-        if (inRange)
-          return false;  //okay, now you can bail, we are over the orginal selection
+        range->IsPointInRange(parent, offset, &inRange);
+        if (inRange) {
+          // Okay, now you can bail, we are over the orginal selection
+          return false;
+        }
       }
     }
   }
   
   return true;
 }
 
 nsresult
@@ -978,18 +985,19 @@ nsEditorEventListener::Focus(nsIDOMEvent
     // make sure that the element is really focused in case an earlier
     // listener in the chain changed the focus.
     if (editableRoot) {
       nsIFocusManager* fm = nsFocusManager::GetFocusManager();
       NS_ENSURE_TRUE(fm, NS_OK);
 
       nsCOMPtr<nsIDOMElement> element;
       fm->GetFocusedElement(getter_AddRefs(element));
-      if (!SameCOMIdentity(element, target))
+      if (!SameCOMIdentity(element, target)) {
         return NS_OK;
+      }
     }
   }
 
   mEditor->OnFocus(target);
 
   nsCOMPtr<nsIPresShell> ps = GetPresShell();
   NS_ENSURE_TRUE(ps, NS_OK);
   nsCOMPtr<nsIContent> focusedContent = mEditor->GetFocusedContentForIME();
@@ -1005,31 +1013,32 @@ nsEditorEventListener::Blur(nsIDOMEvent*
 
   // check if something else is focused. If another element is focused, then
   // we should not change the selection.
   nsIFocusManager* fm = nsFocusManager::GetFocusManager();
   NS_ENSURE_TRUE(fm, NS_OK);
 
   nsCOMPtr<nsIDOMElement> element;
   fm->GetFocusedElement(getter_AddRefs(element));
-  if (element)
+  if (element) {
     return NS_OK;
+  }
 
   mEditor->FinalizeSelection();
   return NS_OK;
 }
 
 void
-nsEditorEventListener::SpellCheckIfNeeded() {
+nsEditorEventListener::SpellCheckIfNeeded()
+{
   // If the spell check skip flag is still enabled from creation time,
   // disable it because focused editors are allowed to spell check.
   uint32_t currentFlags = 0;
   mEditor->GetFlags(&currentFlags);
-  if(currentFlags & nsIPlaintextEditor::eEditorSkipSpellCheck)
-  {
+  if(currentFlags & nsIPlaintextEditor::eEditorSkipSpellCheck) {
     currentFlags ^= nsIPlaintextEditor::eEditorSkipSpellCheck;
     mEditor->SetFlags(currentFlags);
   }
 }
 
 bool
 nsEditorEventListener::IsFileControlTextBox()
 {
--- a/editor/libeditor/nsHTMLEditorEventListener.cpp
+++ b/editor/libeditor/nsHTMLEditorEventListener.cpp
@@ -29,17 +29,18 @@
  *
  */
 
 #ifdef DEBUG
 nsresult
 nsHTMLEditorEventListener::Connect(nsEditor* aEditor)
 {
   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryObject(aEditor);
-  nsCOMPtr<nsIHTMLInlineTableEditor> htmlInlineTableEditor = do_QueryObject(aEditor);
+  nsCOMPtr<nsIHTMLInlineTableEditor> htmlInlineTableEditor =
+    do_QueryObject(aEditor);
   NS_PRECONDITION(htmlEditor && htmlInlineTableEditor,
                   "Set nsHTMLEditor or its sub class");
   return nsEditorEventListener::Connect(aEditor);
 }
 #endif
 
 nsHTMLEditor*
 nsHTMLEditorEventListener::GetHTMLEditor()
@@ -51,18 +52,18 @@ nsHTMLEditorEventListener::GetHTMLEditor
 nsresult
 nsHTMLEditorEventListener::MouseUp(nsIDOMMouseEvent* aMouseEvent)
 {
   NS_ENSURE_TRUE(aMouseEvent, NS_OK);
 
   nsHTMLEditor* htmlEditor = GetHTMLEditor();
 
   nsCOMPtr<nsIDOMEventTarget> target;
-  nsresult res = aMouseEvent->GetTarget(getter_AddRefs(target));
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = aMouseEvent->GetTarget(getter_AddRefs(target));
+  NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_TRUE(target, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsIDOMElement> element = do_QueryInterface(target);
 
   int32_t clientX, clientY;
   aMouseEvent->GetClientX(&clientX);
   aMouseEvent->GetClientY(&clientY);
   htmlEditor->MouseUp(clientX, clientY, element);
 
@@ -72,154 +73,146 @@ nsHTMLEditorEventListener::MouseUp(nsIDO
 nsresult
 nsHTMLEditorEventListener::MouseDown(nsIDOMMouseEvent* aMouseEvent)
 {
   NS_ENSURE_TRUE(aMouseEvent, NS_OK);
 
   nsHTMLEditor* htmlEditor = GetHTMLEditor();
 
   // Detect only "context menu" click
-  //XXX This should be easier to do!
-  // But eDOMEvents_contextmenu and NS_CONTEXTMENU is not exposed in any event interface :-(
+  // XXX This should be easier to do!
+  // But eDOMEvents_contextmenu and NS_CONTEXTMENU is not exposed in any event
+  // interface :-(
   int16_t buttonNumber;
-  nsresult res = aMouseEvent->GetButton(&buttonNumber);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = aMouseEvent->GetButton(&buttonNumber);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   bool isContextClick = buttonNumber == 2;
 
   int32_t clickCount;
-  res = aMouseEvent->GetDetail(&clickCount);
-  NS_ENSURE_SUCCESS(res, res);
+  rv = aMouseEvent->GetDetail(&clickCount);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIDOMEventTarget> target;
-  res = aMouseEvent->GetExplicitOriginalTarget(getter_AddRefs(target));
-  NS_ENSURE_SUCCESS(res, res);
+  rv = aMouseEvent->GetExplicitOriginalTarget(getter_AddRefs(target));
+  NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_TRUE(target, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsIDOMElement> element = do_QueryInterface(target);
 
   // Contenteditable should disregard mousedowns outside it
   if (element && !htmlEditor->IsDescendantOfEditorRoot(element)) {
     return NS_OK;
   }
 
-  if (isContextClick || (buttonNumber == 0 && clickCount == 2))
-  {
+  if (isContextClick || (buttonNumber == 0 && clickCount == 2)) {
     nsCOMPtr<nsISelection> selection;
     mEditor->GetSelection(getter_AddRefs(selection));
     NS_ENSURE_TRUE(selection, NS_OK);
 
     // Get location of mouse within target node
     nsCOMPtr<nsIDOMNode> parent;
-    res = aMouseEvent->GetRangeParent(getter_AddRefs(parent));
-    NS_ENSURE_SUCCESS(res, res);
+    rv = aMouseEvent->GetRangeParent(getter_AddRefs(parent));
+    NS_ENSURE_SUCCESS(rv, rv);
     NS_ENSURE_TRUE(parent, NS_ERROR_FAILURE);
 
     int32_t offset = 0;
-    res = aMouseEvent->GetRangeOffset(&offset);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = aMouseEvent->GetRangeOffset(&offset);
+    NS_ENSURE_SUCCESS(rv, rv);
 
     // Detect if mouse point is within current selection for context click
     bool nodeIsInSelection = false;
     if (isContextClick && !selection->Collapsed()) {
       int32_t rangeCount;
-      res = selection->GetRangeCount(&rangeCount);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = selection->GetRangeCount(&rangeCount);
+      NS_ENSURE_SUCCESS(rv, rv);
 
       for (int32_t i = 0; i < rangeCount; i++) {
         nsCOMPtr<nsIDOMRange> range;
 
-        res = selection->GetRangeAt(i, getter_AddRefs(range));
-        if (NS_FAILED(res) || !range)
-          continue;//don't bail yet, iterate through them all
+        rv = selection->GetRangeAt(i, getter_AddRefs(range));
+        if (NS_FAILED(rv) || !range) {
+          // Don't bail yet, iterate through them all
+          continue;
+        }
 
-        res = range->IsPointInRange(parent, offset, &nodeIsInSelection);
+        range->IsPointInRange(parent, offset, &nodeIsInSelection);
 
         // Done when we find a range that we are in
-        if (nodeIsInSelection)
+        if (nodeIsInSelection) {
           break;
+        }
       }
     }
     nsCOMPtr<nsIDOMNode> node = do_QueryInterface(target);
-    if (node && !nodeIsInSelection)
-    {
-      if (!element)
-      {
-        if (isContextClick)
-        {
+    if (node && !nodeIsInSelection) {
+      if (!element) {
+        if (isContextClick) {
           // Set the selection to the point under the mouse cursor:
           selection->Collapse(parent, offset);
-        }
-        else
-        {
+        } else {
           // Get enclosing link if in text so we can select the link
           nsCOMPtr<nsIDOMElement> linkElement;
-          res = htmlEditor->GetElementOrParentByTagName(NS_LITERAL_STRING("href"), node, getter_AddRefs(linkElement));
-          NS_ENSURE_SUCCESS(res, res);
-          if (linkElement)
+          rv = htmlEditor->GetElementOrParentByTagName(
+                             NS_LITERAL_STRING("href"), node,
+                             getter_AddRefs(linkElement));
+          NS_ENSURE_SUCCESS(rv, rv);
+          if (linkElement) {
             element = linkElement;
+          }
         }
       }
       // Select entire element clicked on if NOT within an existing selection
       //   and not the entire body, or table-related elements
-      if (element)
-      {
+      if (element) {
         nsCOMPtr<nsIDOMNode> selectAllNode =
           htmlEditor->FindUserSelectAllNode(element);
 
-        if (selectAllNode)
-        {
+        if (selectAllNode) {
           nsCOMPtr<nsIDOMElement> newElement = do_QueryInterface(selectAllNode);
-          if (newElement)
-          {
+          if (newElement) {
             node = selectAllNode;
             element = newElement;
           }
         }
 
-        if (isContextClick && !nsHTMLEditUtils::IsImage(node))
-        {
+        if (isContextClick && !nsHTMLEditUtils::IsImage(node)) {
           selection->Collapse(parent, offset);
-        }
-        else
-        {
+        } else {
           htmlEditor->SelectElement(element);
         }
       }
     }
     // HACK !!! Context click places the caret but the context menu consumes
     // the event; so we need to check resizing state ourselves
     htmlEditor->CheckSelectionStateForAnonymousButtons(selection);
 
     // Prevent bubbling if we changed selection or 
     //   for all context clicks
-    if (element || isContextClick)
-    {
+    if (element || isContextClick) {
       aMouseEvent->PreventDefault();
       return NS_OK;
     }
-  }
-  else if (!isContextClick && buttonNumber == 0 && clickCount == 1)
-  {
+  } else if (!isContextClick && buttonNumber == 0 && clickCount == 1) {
     // if the target element is an image, we have to display resizers
     int32_t clientX, clientY;
     aMouseEvent->GetClientX(&clientX);
     aMouseEvent->GetClientY(&clientY);
     htmlEditor->MouseDown(clientX, clientY, element, aMouseEvent);
   }
 
   return nsEditorEventListener::MouseDown(aMouseEvent);
 }
 
 nsresult
 nsHTMLEditorEventListener::MouseClick(nsIDOMMouseEvent* aMouseEvent)
 {
   NS_ENSURE_TRUE(aMouseEvent, NS_OK);
 
   nsCOMPtr<nsIDOMEventTarget> target;
-  nsresult res = aMouseEvent->GetTarget(getter_AddRefs(target));
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = aMouseEvent->GetTarget(getter_AddRefs(target));
+  NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_TRUE(target, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsIDOMElement> element = do_QueryInterface(target);
 
   GetHTMLEditor()->DoInlineTableEditingAction(element);
 
   return nsEditorEventListener::MouseClick(aMouseEvent);
 }