Bug 1190608, part 2 - Tuck elses in nsXULElement.cpp. r=poiru
authorAndrew McCreight <continuation@gmail.com>
Tue, 04 Aug 2015 13:06:14 -0700
changeset 287848 99a5c0692c09f351c949f2fe6b0d30dc80dac8b6
parent 287847 9f3ba882cb9c9334a2eba8760d7f10aa22dce00b
child 287849 f1579da7f21e0e2fa602061092d2f82ecc3a7dcc
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspoiru
bugs1190608
milestone42.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 1190608, part 2 - Tuck elses in nsXULElement.cpp. r=poiru
dom/xul/nsXULElement.cpp
--- a/dom/xul/nsXULElement.cpp
+++ b/dom/xul/nsXULElement.cpp
@@ -281,18 +281,17 @@ nsXULElement::Create(nsXULPrototypeEleme
         return NS_ERROR_NULL_POINTER;
 
     nsRefPtr<mozilla::dom::NodeInfo> nodeInfo;
     if (aDocument) {
         mozilla::dom::NodeInfo* ni = aPrototype->mNodeInfo;
         nodeInfo = aDocument->NodeInfoManager()->
           GetNodeInfo(ni->NameAtom(), ni->GetPrefixAtom(), ni->NamespaceID(),
                       nsIDOMNode::ELEMENT_NODE);
-    }
-    else {
+    } else {
         nodeInfo = aPrototype->mNodeInfo;
     }
 
     nsRefPtr<nsXULElement> element = Create(aPrototype, nodeInfo,
                                             aIsScriptable, aIsRoot);
     if (!element) {
         return NS_ERROR_OUT_OF_MEMORY;
     }
@@ -592,18 +591,17 @@ nsXULElement::IsFocusableInternal(int32_
     if (xulControl) {
       if (HasAttr(kNameSpaceID_None, nsGkAtoms::tabindex)) {
         // if either the aTabIndex argument or a specified tabindex is non-negative,
         // the element becomes focusable.
         int32_t tabIndex = 0;
         xulControl->GetTabIndex(&tabIndex);
         shouldFocus = *aTabIndex >= 0 || tabIndex >= 0;
         *aTabIndex = tabIndex;
-      }
-      else {
+      } else {
         // otherwise, if there is no tabindex attribute, just use the value of
         // *aTabIndex to indicate focusability. Reset any supplied tabindex to 0.
         shouldFocus = *aTabIndex >= 0;
         if (shouldFocus)
           *aTabIndex = 0;
       }
 
       if (shouldFocus && sTabFocusModelAppliesToXUL &&
@@ -613,18 +611,17 @@ nsXULElement::IsFocusableInternal(int32_
         // "Full Keyboard Access" system setting (see mac/nsILookAndFeel).
         // both textboxes and list elements (i.e. trees and list) should always be focusable
         // (textboxes are handled as html:input)
         // For compatibility, we only do this for controls, otherwise elements like <browser>
         // cannot take this focus.
         if (IsNonList(mNodeInfo))
           *aTabIndex = -1;
       }
-    }
-    else {
+    } else {
       shouldFocus = *aTabIndex >= 0;
     }
   }
 
   return shouldFocus;
 }
 
 void
@@ -672,30 +669,28 @@ nsXULElement::PerformAccesskey(bool aKey
                 bool disabled;
                 controlItem->GetDisabled(&disabled);
                 if (!disabled) {
                   nsCOMPtr<nsIDOMXULSelectControlElement> selectControl;
                   controlItem->GetControl(getter_AddRefs(selectControl));
                   element = do_QueryInterface(selectControl);
                 }
               }
-            }
-            else {
+            } else {
               element = do_QueryInterface(content);
             }
             if (element)
               fm->SetFocus(element, nsIFocusManager::FLAG_BYKEY);
           }
         }
         if (aKeyCausesActivation &&
             !content->IsAnyOfXULElements(nsGkAtoms::textbox, nsGkAtoms::menulist)) {
           elm->ClickWithInputSource(nsIDOMMouseEvent::MOZ_SOURCE_KEYBOARD);
         }
-    }
-    else {
+    } else {
         content->PerformAccesskey(aKeyCausesActivation, aIsTrustedEvent);
     }
 }
 
 //----------------------------------------------------------------------
 
 void
 nsXULElement::AddListenerFor(const nsAttrName& aName,
@@ -983,19 +978,19 @@ nsXULElement::RemoveChildAt(uint32_t aIn
             if (newCurrentIndex == -1)
               newCurrentIndex = -2;
         }
       }
     }
 
     nsStyledElement::RemoveChildAt(aIndex, aNotify);
 
-    if (newCurrentIndex == -2)
+    if (newCurrentIndex == -2) {
         controlElement->SetCurrentItem(nullptr);
-    else if (newCurrentIndex > -1) {
+    } else if (newCurrentIndex > -1) {
         // Make sure the index is still valid
         int32_t treeRows;
         listBox->GetRowCount(&treeRows);
         if (treeRows > 0) {
             newCurrentIndex = std::min((treeRows - 1), newCurrentIndex);
             nsCOMPtr<nsIDOMElement> newCurrentItem;
             listBox->GetItemAtIndex(newCurrentIndex, getter_AddRefs(newCurrentItem));
             nsCOMPtr<nsIDOMXULSelectControlItemElement> xulCurItem = do_QueryInterface(newCurrentItem);
@@ -1049,34 +1044,33 @@ nsXULElement::BeforeSetAttr(int32_t aNam
                             nsAttrValueOrString* aValue, bool aNotify)
 {
     if (aNamespaceID == kNameSpaceID_None && aName == nsGkAtoms::accesskey &&
         IsInDoc()) {
         nsAutoString oldValue;
         if (GetAttr(aNamespaceID, aName, oldValue)) {
             UnregisterAccessKey(oldValue);
         }
-    }
-    else if (aNamespaceID == kNameSpaceID_None && (aName ==
-             nsGkAtoms::command || aName == nsGkAtoms::observes) && IsInDoc()) {
+    } else if (aNamespaceID == kNameSpaceID_None &&
+               (aName == nsGkAtoms::command || aName == nsGkAtoms::observes) &&
+               IsInDoc()) {
 //         XXX sXBL/XBL2 issue! Owner or current document?
         nsAutoString oldValue;
         GetAttr(kNameSpaceID_None, nsGkAtoms::observes, oldValue);
         if (oldValue.IsEmpty()) {
           GetAttr(kNameSpaceID_None, nsGkAtoms::command, oldValue);
         }
 
         if (!oldValue.IsEmpty()) {
           RemoveBroadcaster(oldValue);
         }
-    }
-    else if (aNamespaceID == kNameSpaceID_None &&
-             aValue &&
-             mNodeInfo->Equals(nsGkAtoms::window) &&
-             aName == nsGkAtoms::chromemargin) {
+    } else if (aNamespaceID == kNameSpaceID_None &&
+               aValue &&
+               mNodeInfo->Equals(nsGkAtoms::window) &&
+               aName == nsGkAtoms::chromemargin) {
       nsAttrValue attrValue;
       // Make sure the margin format is valid first
       if (!attrValue.ParseIntMarginValue(aValue->String())) {
         return NS_ERROR_INVALID_ARG;
       }
     }
 
     return nsStyledElement::BeforeSetAttr(aNamespaceID, aName,
@@ -1104,118 +1098,103 @@ nsXULElement::AfterSetAttr(int32_t aName
 
             nsIDocument* document = GetUncomposedDoc();
 
             // Hide chrome if needed
             if (mNodeInfo->Equals(nsGkAtoms::window)) {
                 if (aName == nsGkAtoms::hidechrome) {
                     HideWindowChrome(
                       aValue->Equals(NS_LITERAL_STRING("true"), eCaseMatters));
-                }
-                else if (aName == nsGkAtoms::chromemargin) {
+                } else if (aName == nsGkAtoms::chromemargin) {
                     SetChromeMargins(aValue);
-                }
-
-                else if (aName == nsGkAtoms::windowtype &&
-                         document && document->GetRootElement() == this) {
+                } else if (aName == nsGkAtoms::windowtype &&
+                           document && document->GetRootElement() == this) {
                     MaybeUpdatePrivateLifetime();
                 }
             }
             // title, (in)activetitlebarcolor and drawintitlebar are settable on
             // any root node (windows, dialogs, etc)
             if (document && document->GetRootElement() == this) {
                 if (aName == nsGkAtoms::title) {
                     document->NotifyPossibleTitleChange(false);
-                }
-                else if ((aName == nsGkAtoms::activetitlebarcolor ||
-                          aName == nsGkAtoms::inactivetitlebarcolor)) {
+                } else if ((aName == nsGkAtoms::activetitlebarcolor ||
+                            aName == nsGkAtoms::inactivetitlebarcolor)) {
                     nscolor color = NS_RGBA(0, 0, 0, 0);
                     if (aValue->Type() == nsAttrValue::eColor) {
                         aValue->GetColorValue(color);
                     } else {
                         nsAutoString tmp;
                         nsAttrValue attrValue;
                         aValue->ToString(tmp);
                         attrValue.ParseColor(tmp);
                         attrValue.GetColorValue(color);
                     }
                     SetTitlebarColor(color, aName == nsGkAtoms::activetitlebarcolor);
-                }
-                else if (aName == nsGkAtoms::drawintitlebar) {
+                } else if (aName == nsGkAtoms::drawintitlebar) {
                     SetDrawsInTitlebar(
                         aValue->Equals(NS_LITERAL_STRING("true"), eCaseMatters));
-                }
-                else if (aName == nsGkAtoms::drawtitle) {
+                } else if (aName == nsGkAtoms::drawtitle) {
                     SetDrawsTitle(
                         aValue->Equals(NS_LITERAL_STRING("true"), eCaseMatters));
-                }
-                else if (aName == nsGkAtoms::localedir) {
+                } else if (aName == nsGkAtoms::localedir) {
                     // if the localedir changed on the root element, reset the document direction
                     nsCOMPtr<nsIXULDocument> xuldoc = do_QueryInterface(document);
                     if (xuldoc) {
                         xuldoc->ResetDocumentDirection();
                     }
-                }
-                else if (aName == nsGkAtoms::lwtheme ||
+                } else if (aName == nsGkAtoms::lwtheme ||
                          aName == nsGkAtoms::lwthemetextcolor) {
                     // if the lwtheme changed, make sure to reset the document lwtheme cache
                     nsCOMPtr<nsIXULDocument> xuldoc = do_QueryInterface(document);
                     if (xuldoc) {
                         xuldoc->ResetDocumentLWTheme();
                         UpdateBrightTitlebarForeground(document);
                     }
-                }
-                else if (aName == nsGkAtoms::brighttitlebarforeground) {
+                } else if (aName == nsGkAtoms::brighttitlebarforeground) {
                     UpdateBrightTitlebarForeground(document);
                 }
             }
 
             if (aName == nsGkAtoms::src && document) {
                 LoadSrc();
             }
-        } else  {
+        } else {
             if (mNodeInfo->Equals(nsGkAtoms::window)) {
                 if (aName == nsGkAtoms::hidechrome) {
                     HideWindowChrome(false);
-                }
-                else if (aName == nsGkAtoms::chromemargin) {
+                } else if (aName == nsGkAtoms::chromemargin) {
                     ResetChromeMargins();
                 }
             }
 
             nsIDocument* doc = GetUncomposedDoc();
             if (doc && doc->GetRootElement() == this) {
                 if ((aName == nsGkAtoms::activetitlebarcolor ||
                      aName == nsGkAtoms::inactivetitlebarcolor)) {
                     // Use 0, 0, 0, 0 as the "none" color.
                     SetTitlebarColor(NS_RGBA(0, 0, 0, 0), aName == nsGkAtoms::activetitlebarcolor);
-                }
-                else if (aName == nsGkAtoms::localedir) {
+                } else if (aName == nsGkAtoms::localedir) {
                     // if the localedir changed on the root element, reset the document direction
                     nsCOMPtr<nsIXULDocument> xuldoc = do_QueryInterface(doc);
                     if (xuldoc) {
                         xuldoc->ResetDocumentDirection();
                     }
-                }
-                else if ((aName == nsGkAtoms::lwtheme ||
-                          aName == nsGkAtoms::lwthemetextcolor)) {
+                } else if ((aName == nsGkAtoms::lwtheme ||
+                            aName == nsGkAtoms::lwthemetextcolor)) {
                     // if the lwtheme changed, make sure to restyle appropriately
                     nsCOMPtr<nsIXULDocument> xuldoc = do_QueryInterface(doc);
                     if (xuldoc) {
                         xuldoc->ResetDocumentLWTheme();
                         UpdateBrightTitlebarForeground(doc);
                     }
-                }
-                else if (aName == nsGkAtoms::brighttitlebarforeground) {
+                } else if (aName == nsGkAtoms::brighttitlebarforeground) {
                     UpdateBrightTitlebarForeground(doc);
-                }
-                else if (aName == nsGkAtoms::drawintitlebar) {
+                } else if (aName == nsGkAtoms::drawintitlebar) {
                     SetDrawsInTitlebar(false);
-                }
-                else if (aName == nsGkAtoms::drawtitle) {
+                } else if (aName == nsGkAtoms::drawtitle) {
                     SetDrawsTitle(false);
                 }
             }
         }
 
         // XXX need to check if they're changing an event handler: if
         // so, then we need to unhook the old one.  Or something.
     }
@@ -1884,26 +1863,24 @@ nsXULElement::MakeHeavyweight(nsXULProto
             nsRefPtr<css::Rule> ruleClone =
                 protoattr->mValue.GetCSSStyleRuleValue()->Clone();
 
             nsString stringValue;
             protoattr->mValue.ToString(stringValue);
 
             nsRefPtr<css::StyleRule> styleRule = do_QueryObject(ruleClone);
             attrValue.SetTo(styleRule, &stringValue);
-        }
-        else {
+        } else {
             attrValue.SetTo(protoattr->mValue);
         }
 
         // XXX we might wanna have a SetAndTakeAttr that takes an nsAttrName
         if (protoattr->mName.IsAtom()) {
             rv = mAttrsAndChildren.SetAndSwapAttr(protoattr->mName.Atom(), attrValue);
-        }
-        else {
+        } else {
             rv = mAttrsAndChildren.SetAndSwapAttr(protoattr->mName.NodeInfo(),
                                                   attrValue);
         }
         NS_ENSURE_SUCCESS(rv, rv);
     }
     return NS_OK;
 }
 
@@ -2126,18 +2103,17 @@ nsXULElement::WrapNode(JSContext *aCx, J
     return dom::XULElementBinding::Wrap(aCx, this, aGivenProto);
 }
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULPrototypeNode)
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsXULPrototypeNode)
     if (tmp->mType == nsXULPrototypeNode::eType_Element) {
         static_cast<nsXULPrototypeElement*>(tmp)->Unlink();
-    }
-    else if (tmp->mType == nsXULPrototypeNode::eType_Script) {
+    } else if (tmp->mType == nsXULPrototypeNode::eType_Script) {
         static_cast<nsXULPrototypeScript*>(tmp)->UnlinkJSObjects();
     }
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXULPrototypeNode)
     if (tmp->mType == nsXULPrototypeNode::eType_Element) {
         nsXULPrototypeElement *elem =
             static_cast<nsXULPrototypeElement*>(tmp);
         NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mNodeInfo");
@@ -2213,18 +2189,17 @@ nsXULPrototypeElement::Serialize(nsIObje
     for (i = 0; i < mNumAttributes; ++i) {
         nsRefPtr<mozilla::dom::NodeInfo> ni;
         if (mAttributes[i].mName.IsAtom()) {
             ni = mNodeInfo->NodeInfoManager()->
                 GetNodeInfo(mAttributes[i].mName.Atom(), nullptr,
                             kNameSpaceID_None,
                             nsIDOMNode::ATTRIBUTE_NODE);
             NS_ASSERTION(ni, "the nodeinfo should already exist");
-        }
-        else {
+        } else {
             ni = mAttributes[i].mName.NodeInfo();
         }
 
         index = aNodeInfos->IndexOf(ni);
         NS_ASSERTION(index >= 0, "unknown mozilla::dom::NodeInfo index");
         tmp = aStream->Write32(index);
         if (NS_FAILED(tmp)) {
           rv = tmp;
@@ -2480,25 +2455,23 @@ nsXULPrototypeElement::SetAttrAt(uint32_
         !aValue.IsEmpty()) {
         mHasIdAttribute = true;
         // Store id as atom.
         // id="" means that the element has no id. Not that it has
         // emptystring as id.
         mAttributes[aPos].mValue.ParseAtom(aValue);
 
         return NS_OK;
-    }
-    else if (mAttributes[aPos].mName.Equals(nsGkAtoms::_class)) {
+    } else if (mAttributes[aPos].mName.Equals(nsGkAtoms::_class)) {
         mHasClassAttribute = true;
         // Compute the element's class list
         mAttributes[aPos].mValue.ParseAtomArray(aValue);
 
         return NS_OK;
-    }
-    else if (mAttributes[aPos].mName.Equals(nsGkAtoms::style)) {
+    } else if (mAttributes[aPos].mName.Equals(nsGkAtoms::style)) {
         mHasStyleAttribute = true;
         // Parse the element's 'style' attribute
         nsRefPtr<css::StyleRule> rule;
 
         nsCSSParser parser;
 
         // XXX Get correct Base URI (need GetBaseURI on *prototype* element)
         // TODO: If we implement Content Security Policy for chrome documents