Bug 677107 - Sprinkle IsHTML(nsIAtom*) pixie dust over select-option-optgroup code; r=bz
authorMs2ger <ms2ger@gmail.com>
Mon, 08 Aug 2011 17:14:33 +0200
changeset 74030 ac18ea6e0b37630c4e1ba0ceedae250e320dd639
parent 74029 9c7ab0a15292530bd8b908f1433e87545c60ff82
child 74031 e0ae0b46f4f546b0041f962cff9076c46d6d0901
push id1054
push usermbrubeck@mozilla.com
push dateMon, 08 Aug 2011 21:22:30 +0000
treeherdermozilla-inbound@f37a51e43d5a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs677107
milestone8.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 677107 - Sprinkle IsHTML(nsIAtom*) pixie dust over select-option-optgroup code; r=bz
content/html/content/src/nsHTMLSelectElement.cpp
layout/forms/nsListControlFrame.cpp
layout/forms/nsListControlFrame.h
layout/forms/nsSelectsAreaFrame.cpp
layout/forms/nsSelectsAreaFrame.h
--- a/content/html/content/src/nsHTMLSelectElement.cpp
+++ b/content/html/content/src/nsHTMLSelectElement.cpp
@@ -355,22 +355,16 @@ nsHTMLSelectElement::RemoveOptionsFromLi
 
       UpdateState(aNotify);
     }
   }
 
   return NS_OK;
 }
 
-static PRBool IsOptGroup(nsIContent *aContent)
-{
-  return (aContent->NodeInfo()->Equals(nsGkAtoms::optgroup) &&
-          aContent->IsHTML());
-}
-
 // If the document is such that recursing over these options gets us
 // deeper than four levels, there is something terribly wrong with the
 // world.
 nsresult
 nsHTMLSelectElement::InsertOptionsIntoListRecurse(nsIContent* aOptions,
                                                   PRInt32* aInsertIndex,
                                                   PRInt32 aDepth)
 {
@@ -389,17 +383,17 @@ nsHTMLSelectElement::InsertOptionsIntoLi
 
   // If it's at the top level, then we just found out there are non-options
   // at the top level, which will throw off the insert count
   if (aDepth == 0) {
     mNonOptionChildren++;
   }
 
   // Recurse down into optgroups
-  if (IsOptGroup(aOptions)) {
+  if (aOptions->IsHTML(nsGkAtoms::optgroup)) {
     mOptGroupCount++;
 
     PRUint32 numChildren = aOptions->GetChildCount();
     for (PRUint32 i = 0; i < numChildren; ++i) {
       nsresult rv = InsertOptionsIntoListRecurse(aOptions->GetChildAt(i),
                                                  aInsertIndex, aDepth+1);
       NS_ENSURE_SUCCESS(rv, rv);
     }
@@ -433,17 +427,17 @@ nsHTMLSelectElement::RemoveOptionsFromLi
   }
 
   // Yay, one less artifact at the top level.
   if (aDepth == 0) {
     mNonOptionChildren--;
   }
 
   // Recurse down deeper for options
-  if (mOptGroupCount && IsOptGroup(aOptions)) {
+  if (mOptGroupCount && aOptions->IsHTML(nsGkAtoms::optgroup)) {
     mOptGroupCount--;
 
     PRUint32 numChildren = aOptions->GetChildCount();
     for (PRUint32 i = 0; i < numChildren; ++i) {
       nsresult rv = RemoveOptionsFromListRecurse(aOptions->GetChildAt(i),
                                                  aRemoveIndex,
                                                  aNumRemoved,
                                                  aDepth + 1);
@@ -1868,25 +1862,25 @@ void nsHTMLSelectElement::DispatchConten
       }
     }
   }
 }
 
 static void
 AddOptionsRecurse(nsIContent* aRoot, nsHTMLOptionCollection* aArray)
 {
-  nsIContent* child;
-  for(PRUint32 i = 0; (child = aRoot->GetChildAt(i)); ++i) {
-    nsHTMLOptionElement *opt = nsHTMLOptionElement::FromContent(child);
+  for (nsIContent* cur = aRoot->GetFirstChild();
+       cur;
+       cur = cur->GetNextSibling()) {
+    nsHTMLOptionElement* opt = nsHTMLOptionElement::FromContent(cur);
     if (opt) {
       // If we fail here, then at least we've tried our best
       aArray->AppendOption(opt);
-    }
-    else if (IsOptGroup(child)) {
-      AddOptionsRecurse(child, aArray);
+    } else if (cur->IsHTML(nsGkAtoms::optgroup)) {
+      AddOptionsRecurse(cur, aArray);
     }
   }
 }
 
 void
 nsHTMLSelectElement::RebuildOptionsArray(PRBool aNotify)
 {
   mOptions->Clear();
@@ -1964,25 +1958,25 @@ nsHTMLSelectElement::GetValidationMessag
 }
 
 #ifdef DEBUG
 
 static void
 VerifyOptionsRecurse(nsIContent* aRoot, PRInt32& aIndex,
                      nsHTMLOptionCollection* aArray)
 {
-  nsIContent* child;
-  for(PRUint32 i = 0; (child = aRoot->GetChildAt(i)); ++i) {
-    nsCOMPtr<nsIDOMHTMLOptionElement> opt = do_QueryInterface(child);
+  for (nsIContent* cur = aRoot->GetFirstChild();
+       cur;
+       cur = cur->GetNextSibling()) {
+    nsCOMPtr<nsIDOMHTMLOptionElement> opt = do_QueryInterface(cur);
     if (opt) {
       NS_ASSERTION(opt == aArray->ItemAsOption(aIndex++),
                    "Options collection broken");
-    }
-    else if (IsOptGroup(child)) {
-      VerifyOptionsRecurse(child, aIndex, aArray);
+    } else if (cur->IsHTML(nsGkAtoms::optgroup)) {
+      VerifyOptionsRecurse(cur, aIndex, aArray);
     }
   }
 }
 
 void
 nsHTMLSelectElement::VerifyOptionsArray()
 {
   PRInt32 aIndex = 0;
--- a/layout/forms/nsListControlFrame.cpp
+++ b/layout/forms/nsListControlFrame.cpp
@@ -398,42 +398,31 @@ GetMaxOptionHeight(nsIFrame* aContainer)
       optionHeight = option->GetSize().height;
     }
     if (result < optionHeight)
       result = optionHeight;
   }
   return result;
 }
 
-static inline PRBool
-IsOptGroup(nsIContent *aContent)
-{
-  return (aContent->NodeInfo()->Equals(nsGkAtoms::optgroup) &&
-          aContent->IsHTML());
-}
-
-static inline PRBool
-IsOption(nsIContent *aContent)
-{
-  return (aContent->NodeInfo()->Equals(nsGkAtoms::option) &&
-          aContent->IsHTML());
-}
-
 static PRUint32
 GetNumberOfOptionsRecursive(nsIContent* aContent)
 {
+  if (!aContent) {
+    return 0;
+  }
+
   PRUint32 optionCount = 0;
-  const PRUint32 childCount = aContent ? aContent->GetChildCount() : 0;
-  for (PRUint32 index = 0; index < childCount; ++index) {
-    nsIContent* child = aContent->GetChildAt(index);
-    if (::IsOption(child)) {
+  for (nsIContent* cur = aContent->GetFirstChild();
+       cur;
+       cur = cur->GetNextSibling()) {
+    if (cur->IsHTML(nsGkAtoms::option)) {
       ++optionCount;
-    }
-    else if (::IsOptGroup(child)) {
-      optionCount += ::GetNumberOfOptionsRecursive(child);
+    } else if (cur->IsHTML(nsGkAtoms::optgroup)) {
+      optionCount += GetNumberOfOptionsRecursive(cur);
     }
   }
   return optionCount;
 }
 
 //-----------------------------------------------------------------
 // Main Reflow for ListBox/Dropdown
 //-----------------------------------------------------------------
@@ -757,45 +746,30 @@ nsListControlFrame::GetScrollbarStyles()
 
 PRBool
 nsListControlFrame::ShouldPropagateComputedHeightToScrolledContent() const
 {
   return !IsInDropDownMode();
 }
 
 //---------------------------------------------------------
-PRBool 
-nsListControlFrame::IsOptionElement(nsIContent* aContent)
-{
-  PRBool result = PR_FALSE;
- 
-  nsCOMPtr<nsIDOMHTMLOptionElement> optElem;
-  if (NS_SUCCEEDED(aContent->QueryInterface(NS_GET_IID(nsIDOMHTMLOptionElement),(void**) getter_AddRefs(optElem)))) {      
-    if (optElem != nsnull) {
-      result = PR_TRUE;
-    }
-  }
- 
-  return result;
-}
-
 nsIFrame*
 nsListControlFrame::GetContentInsertionFrame() {
   return GetOptionsContainer()->GetContentInsertionFrame();
 }
 
 //---------------------------------------------------------
 // Starts at the passed in content object and walks up the 
 // parent heierarchy looking for the nsIDOMHTMLOptionElement
 //---------------------------------------------------------
 nsIContent *
 nsListControlFrame::GetOptionFromContent(nsIContent *aContent) 
 {
   for (nsIContent* content = aContent; content; content = content->GetParent()) {
-    if (IsOptionElement(content)) {
+    if (content->IsHTML(nsGkAtoms::option)) {
       return content;
     }
   }
 
   return nsnull;
 }
 
 //---------------------------------------------------------
--- a/layout/forms/nsListControlFrame.h
+++ b/layout/forms/nsListControlFrame.h
@@ -364,17 +364,16 @@ protected:
    */
   PRBool   IsContentSelected(nsIContent* aContent) const;
 
   /**
    * For a given index is return whether the content is selected.
    */
   PRBool   IsContentSelectedByIndex(PRInt32 aIndex) const;
 
-  PRBool   IsOptionElement(nsIContent* aContent);
   PRBool   CheckIfAllFramesHere();
   PRInt32  GetIndexFromContent(nsIContent *aContent);
   PRBool   IsLeftButton(nsIDOMEvent* aMouseEvent);
 
   // guess at a row height based on our own style.
   nscoord  CalcFallbackRowHeight();
 
   // CalcIntrinsicHeight computes our intrinsic height (taking the "size"
--- a/layout/forms/nsSelectsAreaFrame.cpp
+++ b/layout/forms/nsSelectsAreaFrame.cpp
@@ -54,42 +54,16 @@ NS_NewSelectsAreaFrame(nsIPresShell* aSh
   }
 
   return it;
 }
 
 NS_IMPL_FRAMEARENA_HELPERS(nsSelectsAreaFrame)
 
 //---------------------------------------------------------
-PRBool 
-nsSelectsAreaFrame::IsOptionElement(nsIContent* aContent)
-{
-  PRBool result = PR_FALSE;
- 
-  nsCOMPtr<nsIDOMHTMLOptionElement> optElem;
-  if (NS_SUCCEEDED(aContent->QueryInterface(NS_GET_IID(nsIDOMHTMLOptionElement),(void**) getter_AddRefs(optElem)))) {      
-    if (optElem != nsnull) {
-      result = PR_TRUE;
-    }
-  }
- 
-  return result;
-}
-
-//---------------------------------------------------------
-PRBool 
-nsSelectsAreaFrame::IsOptionElementFrame(nsIFrame *aFrame)
-{
-  nsIContent *content = aFrame->GetContent();
-  if (content) {
-    return IsOptionElement(content);
-  }
-  return PR_FALSE;
-}
-
 /**
  * This wrapper class lets us redirect mouse hits from the child frame of
  * an option element to the element's own frame.
  * REVIEW: This is what nsSelectsAreaFrame::GetFrameForPoint used to do
  */
 class nsDisplayOptionEventGrabber : public nsDisplayWrapList {
 public:
   nsDisplayOptionEventGrabber(nsDisplayListBuilder* aBuilder,
@@ -110,17 +84,18 @@ void nsDisplayOptionEventGrabber::HitTes
     const nsRect& aRect, HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames)
 {
   nsTArray<nsIFrame*> outFrames;
   mList.HitTest(aBuilder, aRect, aState, &outFrames);
 
   for (PRUint32 i = 0; i < outFrames.Length(); i++) {
     nsIFrame* selectedFrame = outFrames.ElementAt(i);
     while (selectedFrame &&
-           !nsSelectsAreaFrame::IsOptionElementFrame(selectedFrame)) {
+           !(selectedFrame->GetContent() &&
+             selectedFrame->GetContent()->IsHTML(nsGkAtoms::option))) {
       selectedFrame = selectedFrame->GetParent();
     }
     if (selectedFrame) {
       aOutFrames->AppendElement(selectedFrame);
     } else {
       // keep the original result, which could be this frame
       aOutFrames->AppendElement(outFrames.ElementAt(i));
     }
--- a/layout/forms/nsSelectsAreaFrame.h
+++ b/layout/forms/nsSelectsAreaFrame.h
@@ -33,17 +33,16 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 #ifndef nsSelectsAreaFrame_h___
 #define nsSelectsAreaFrame_h___
 
 #include "nsBlockFrame.h"
-class nsIContent;
 
 class nsSelectsAreaFrame : public nsBlockFrame
 {
 public:
   NS_DECL_FRAMEARENA_HELPERS
 
   friend nsIFrame* NS_NewSelectsAreaFrame(nsIPresShell* aShell, nsStyleContext* aContext, PRUint32 aFlags);
 
@@ -55,19 +54,16 @@ public:
                                     const nsRect&           aDirtyRect,
                                     const nsDisplayListSet& aLists);
 
   NS_IMETHOD Reflow(nsPresContext*          aCX,
                     nsHTMLReflowMetrics&     aDesiredSize,
                     const nsHTMLReflowState& aReflowState,
                     nsReflowStatus&          aStatus);
 
-  static PRBool IsOptionElement(nsIContent* aContent);
-  static PRBool IsOptionElementFrame(nsIFrame *aFrame);
-  
   nscoord HeightOfARow() const { return mHeightOfARow; }
   
 protected:
   nsSelectsAreaFrame(nsStyleContext* aContext) :
     nsBlockFrame(aContext),
     mHeightOfARow(0)
   {}