Bug 899931 - Part c: Cleanup nsListControlFrame::GetOptionText; r=dzbarsky
authorMs2ger <ms2ger@gmail.com>
Fri, 02 Aug 2013 09:07:08 +0200
changeset 148533 0fc75bf359ef700ac1e845af5e72310e24044fa2
parent 148532 ad1c42bfcc98ce552a6282f6c42b2acfbed78de8
child 148534 a38da0a3d6320361304565584fa7f63d30048920
push id4085
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 20:29:25 +0000
treeherdermozilla-aurora@ede8780a15bc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdzbarsky
bugs899931
milestone25.0a1
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|.