Bug 899931 - Part d: Cleanup nsListControlFrame::GetCurrentOption; r=dzbarsky
authorMs2ger <ms2ger@gmail.com>
Fri, 02 Aug 2013 09:07:22 +0200
changeset 153240 a38da0a3d6320361304565584fa7f63d30048920
parent 153239 0fc75bf359ef700ac1e845af5e72310e24044fa2
child 153241 fa76408d51da3434960c20bfebbfe61afdfe7410
push id2859
push userakeybl@mozilla.com
push dateMon, 16 Sep 2013 19:14:59 +0000
treeherdermozilla-beta@87d3c51cd2bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdzbarsky
bugs899931
milestone25.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 899931 - Part d: Cleanup nsListControlFrame::GetCurrentOption; r=dzbarsky
layout/forms/nsIListControlFrame.h
layout/forms/nsListControlFrame.cpp
layout/forms/nsListControlFrame.h
--- a/layout/forms/nsIListControlFrame.h
+++ b/layout/forms/nsIListControlFrame.h
@@ -7,16 +7,22 @@
 #define nsIListControlFrame_h___
 
 #include "nsQueryFrame.h"
 #include "nsFont.h"
 
 class nsAString;
 class nsIContent;
 
+namespace mozilla {
+namespace dom {
+class HTMLOptionElement;
+} // namespace dom
+} // namespace mozilla
+
 /** 
   * nsIListControlFrame is the interface for frame-based listboxes.
   */
 class nsIListControlFrame : public nsQueryFrame
 {
 public:
   NS_DECL_QUERYFRAME_TARGET(nsIListControlFrame)
 
@@ -36,17 +42,17 @@ public:
    *
    */
   virtual int32_t GetSelectedIndex() = 0;
 
   /**
    * Return current option. The current option is the option displaying
    * the focus ring when the listbox is focused.
    */
-  virtual already_AddRefed<nsIContent> GetCurrentOption() = 0;
+  virtual mozilla::dom::HTMLOptionElement* GetCurrentOption() = 0;
 
   /**
    * Initiates mouse capture for the listbox
    *
    */
   virtual void CaptureMouseEvents(bool aGrabMouseEvents) = 0;
 
   /**
--- a/layout/forms/nsListControlFrame.cpp
+++ b/layout/forms/nsListControlFrame.cpp
@@ -1172,62 +1172,43 @@ nsListControlFrame::GetSelectedIndex()
   int32_t aIndex;
   
   nsCOMPtr<nsIDOMHTMLSelectElement> selectElement(do_QueryInterface(mContent));
   selectElement->GetSelectedIndex(&aIndex);
   
   return aIndex;
 }
 
-already_AddRefed<nsIContent>
+dom::HTMLOptionElement*
 nsListControlFrame::GetCurrentOption()
 {
   // The mEndSelectionIndex is what is currently being selected. Use
   // the selected index if this is kNothingSelected.
   int32_t focusedIndex = (mEndSelectionIndex == kNothingSelected) ?
     GetSelectedIndex() : mEndSelectionIndex;
 
   if (focusedIndex != kNothingSelected) {
-    return GetOptionContent(focusedIndex);
+    return GetOption(SafeCast<uint32_t>(focusedIndex));
   }
 
+  // There is no selected item. Return the first non-disabled item.
   nsRefPtr<dom::HTMLSelectElement> selectElement =
     dom::HTMLSelectElement::FromContent(mContent);
-  NS_ASSERTION(selectElement, "Can't be null");
 
-  // There is no a selected item return the first non-disabled item and skip all
-  // the option group elements.
-  nsCOMPtr<nsIDOMNode> node;
-
-  uint32_t length;
-  selectElement->GetLength(&length);
-  if (length) {
-    bool isDisabled = true;
-    for (uint32_t i = 0; i < length && isDisabled; i++) {
-      if (NS_FAILED(selectElement->Item(i, getter_AddRefs(node))) || !node) {
-        break;
-      }
-      if (NS_FAILED(selectElement->IsOptionDisabled(i, &isDisabled))) {
-        break;
-      }
-      if (isDisabled) {
-        node = nullptr;
-      } else {
-        break;
-      }
-    }
+  for (uint32_t i = 0, length = selectElement->Length(); i < length; ++i) {
+    dom::HTMLOptionElement* node = selectElement->Item(i);
     if (!node) {
       return nullptr;
     }
+
+    if (!selectElement->IsOptionDisabled(node)) {
+      return node;
+    }
   }
 
-  if (node) {
-    nsCOMPtr<nsIContent> focusedOption = do_QueryInterface(node);
-    return focusedOption.forget();
-  }
   return nullptr;
 }
 
 bool 
 nsListControlFrame::IsInDropDownMode() const
 {
   return (mComboboxFrame != nullptr);
 }
--- a/layout/forms/nsListControlFrame.h
+++ b/layout/forms/nsListControlFrame.h
@@ -112,17 +112,17 @@ public:
     // for accessibility purposes
 #ifdef ACCESSIBILITY
   virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE;
 #endif
 
     // nsIListControlFrame
   virtual void SetComboboxFrame(nsIFrame* aComboboxFrame) MOZ_OVERRIDE;
   virtual int32_t GetSelectedIndex() MOZ_OVERRIDE;
-  virtual already_AddRefed<nsIContent> GetCurrentOption() MOZ_OVERRIDE;
+  virtual mozilla::dom::HTMLOptionElement* GetCurrentOption() MOZ_OVERRIDE;
 
   /**
    * Gets the text of the currently selected item.
    * If the there are zero items then an empty string is returned
    * If there is nothing selected, then the 0th item's text is returned.
    */
   virtual void GetOptionText(uint32_t aIndex, nsAString& aStr) MOZ_OVERRIDE;