Bug 899931 - Part c: Cleanup nsListControlFrame::GetOptionText; r=dzbarsky
authorMs2ger <ms2ger@gmail.com>
Fri, 02 Aug 2013 09:07:08 +0200
changeset 153239 0fc75bf359ef700ac1e845af5e72310e24044fa2
parent 153238 ad1c42bfcc98ce552a6282f6c42b2acfbed78de8
child 153240 a38da0a3d6320361304565584fa7f63d30048920
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 c: Cleanup nsListControlFrame::GetOptionText; r=dzbarsky
layout/forms/nsIListControlFrame.h
layout/forms/nsListControlFrame.cpp
layout/forms/nsListControlFrame.h
--- a/layout/forms/nsIListControlFrame.h
+++ b/layout/forms/nsIListControlFrame.h
@@ -24,17 +24,17 @@ public:
    * Sets the ComboBoxFrame
    *
    */
   virtual void SetComboboxFrame(nsIFrame* aComboboxFrame) = 0;
 
   /**
    * Get the display string for an item
    */
-  virtual void GetOptionText(int32_t aIndex, nsAString & aStr) = 0;
+  virtual void GetOptionText(uint32_t aIndex, nsAString& aStr) = 0;
 
   /**
    * Get the Selected Item's index
    *
    */
   virtual int32_t GetSelectedIndex() = 0;
 
   /**
--- a/layout/forms/nsListControlFrame.cpp
+++ b/layout/forms/nsListControlFrame.cpp
@@ -1153,53 +1153,21 @@ void
 nsListControlFrame::SetComboboxFrame(nsIFrame* aComboboxFrame)
 {
   if (nullptr != aComboboxFrame) {
     mComboboxFrame = do_QueryFrame(aComboboxFrame);
   }
 }
 
 void
-nsListControlFrame::GetOptionText(int32_t aIndex, nsAString & aStr)
+nsListControlFrame::GetOptionText(uint32_t aIndex, nsAString& aStr)
 {
-  aStr.SetLength(0);
-  nsCOMPtr<nsIDOMHTMLOptionsCollection> options = GetOptions(mContent);
-
-  if (options) {
-    uint32_t numOptions;
-    options->GetLength(&numOptions);
-
-    if (numOptions != 0) {
-      nsCOMPtr<nsIDOMHTMLOptionElement> optionElement =
-        GetOption(options, aIndex);
-      if (optionElement) {
-#if 0 // This is for turning off labels Bug 4050
-        nsAutoString text;
-        optionElement->GetLabel(text);
-        // the return value is always NS_OK from DOMElements
-        // it is meaningless to check for it
-        if (!text.IsEmpty()) { 
-          nsAutoString compressText = text;
-          compressText.CompressWhitespace(true, true);
-          if (!compressText.IsEmpty()) {
-            text = compressText;
-          }
-        }
-
-        if (text.IsEmpty()) {
-          // the return value is always NS_OK from DOMElements
-          // it is meaningless to check for it
-          optionElement->GetText(text);
-        }          
-        aStr = text;
-#else
-        optionElement->GetText(aStr);
-#endif
-      }
-    }
+  aStr.Truncate();
+  if (dom::HTMLOptionElement* optionElement = GetOption(aIndex)) {
+    optionElement->GetText(aStr);
   }
 }
 
 int32_t
 nsListControlFrame::GetSelectedIndex()
 {
   int32_t aIndex;
   
--- a/layout/forms/nsListControlFrame.h
+++ b/layout/forms/nsListControlFrame.h
@@ -119,17 +119,17 @@ public:
   virtual int32_t GetSelectedIndex() MOZ_OVERRIDE;
   virtual already_AddRefed<nsIContent> 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(int32_t aIndex, nsAString & aStr) MOZ_OVERRIDE;
+  virtual void GetOptionText(uint32_t aIndex, nsAString& aStr) MOZ_OVERRIDE;
 
   virtual void CaptureMouseEvents(bool aGrabMouseEvents) MOZ_OVERRIDE;
   virtual nscoord GetHeightOfARow() MOZ_OVERRIDE;
   virtual uint32_t GetNumberOfOptions() MOZ_OVERRIDE;
   virtual void AboutToDropDown() MOZ_OVERRIDE;
 
   /**
    * @note This method might destroy |this|.