Bug 899931 - Part b: Introduce a nice nsListControlFrame::GetOption; r=dzbarsky
authorMs2ger <ms2ger@gmail.com>
Fri, 02 Aug 2013 09:07:04 +0200
changeset 153238 ad1c42bfcc98ce552a6282f6c42b2acfbed78de8
parent 153237 136f1614f09240b3e9bc9032d0fe8ca70570f2ca
child 153239 0fc75bf359ef700ac1e845af5e72310e24044fa2
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 b: Introduce a nice nsListControlFrame::GetOption; r=dzbarsky
layout/forms/nsListControlFrame.cpp
layout/forms/nsListControlFrame.h
--- a/layout/forms/nsListControlFrame.cpp
+++ b/layout/forms/nsListControlFrame.cpp
@@ -1051,16 +1051,26 @@ nsListControlFrame::GetOptions(nsIConten
   nsCOMPtr<nsIDOMHTMLSelectElement> selectElement = do_QueryInterface(aContent);
   if (selectElement) {
     selectElement->GetOptions(getter_AddRefs(options));
   }
 
   return options.forget();
 }
 
+dom::HTMLOptionElement*
+nsListControlFrame::GetOption(uint32_t aIndex) const
+{
+  dom::HTMLSelectElement* select =
+    dom::HTMLSelectElement::FromContentOrNull(mContent);
+  NS_ENSURE_TRUE(select, nullptr);
+
+  return select->Item(aIndex);
+}
+
 already_AddRefed<nsIDOMHTMLOptionElement>
 nsListControlFrame::GetOption(nsIDOMHTMLOptionsCollection* aCollection,
                               int32_t aIndex)
 {
   nsCOMPtr<nsIDOMNode> node;
   if (NS_SUCCEEDED(aCollection->Item(aIndex, getter_AddRefs(node)))) {
     NS_ASSERTION(node,
                  "Item was successful, but node from collection was null!");
--- a/layout/forms/nsListControlFrame.h
+++ b/layout/forms/nsListControlFrame.h
@@ -28,16 +28,22 @@
 class nsIContent;
 class nsIDOMHTMLSelectElement;
 class nsIDOMHTMLOptionsCollection;
 class nsIDOMHTMLOptionElement;
 class nsIComboboxControlFrame;
 class nsPresContext;
 class nsListEventListener;
 
+namespace mozilla {
+namespace dom {
+class HTMLOptionElement;
+} // namespace dom
+} // namespace mozilla
+
 /**
  * Frame-based listbox.
  */
 
 class nsListControlFrame : public nsHTMLScrollFrame,
                            public nsIFormControlFrame, 
                            public nsIListControlFrame,
                            public nsISelectControlFrame
@@ -163,16 +169,20 @@ public:
   nsresult KeyDown(nsIDOMEvent* aKeyEvent);     // might destroy |this|
   nsresult KeyPress(nsIDOMEvent* aKeyEvent);    // might destroy |this|
 
   /**
    * Returns the options collection for aContent, if any.
    */
   static already_AddRefed<nsIDOMHTMLOptionsCollection>
     GetOptions(nsIContent * aContent);
+  /**
+   * Returns the HTMLOptionElement for a given index in mContent's collection.
+   */
+  mozilla::dom::HTMLOptionElement* GetOption(uint32_t aIndex) const;
 
   /**
    * Returns the nsIDOMHTMLOptionElement for a given index 
    * in the select's collection.
    */
   static already_AddRefed<nsIDOMHTMLOptionElement>
     GetOption(nsIDOMHTMLOptionsCollection* aOptions, int32_t aIndex);