diff --git a/layout/forms/nsIListControlFrame.h b/layout/forms/nsIListControlFrame.h index 5e164a8c5d99..46d3db2826ba 100644 --- a/layout/forms/nsIListControlFrame.h +++ b/layout/forms/nsIListControlFrame.h @@ -12,6 +12,12 @@ class nsAString; class nsIContent; +namespace mozilla { +namespace dom { +class HTMLOptionElement; +} // namespace dom +} // namespace mozilla + /** * nsIListControlFrame is the interface for frame-based listboxes. */ @@ -41,7 +47,7 @@ public: * Return current option. The current option is the option displaying * the focus ring when the listbox is focused. */ - virtual already_AddRefed GetCurrentOption() = 0; + virtual mozilla::dom::HTMLOptionElement* GetCurrentOption() = 0; /** * Initiates mouse capture for the listbox diff --git a/layout/forms/nsListControlFrame.cpp b/layout/forms/nsListControlFrame.cpp index 42cf68e23526..143b192efb83 100644 --- a/layout/forms/nsListControlFrame.cpp +++ b/layout/forms/nsListControlFrame.cpp @@ -1177,7 +1177,7 @@ nsListControlFrame::GetSelectedIndex() return aIndex; } -already_AddRefed +dom::HTMLOptionElement* nsListControlFrame::GetCurrentOption() { // The mEndSelectionIndex is what is currently being selected. Use @@ -1186,43 +1186,24 @@ nsListControlFrame::GetCurrentOption() GetSelectedIndex() : mEndSelectionIndex; if (focusedIndex != kNothingSelected) { - return GetOptionContent(focusedIndex); + return GetOption(SafeCast(focusedIndex)); } + // There is no selected item. Return the first non-disabled item. nsRefPtr 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 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 focusedOption = do_QueryInterface(node); - return focusedOption.forget(); - } return nullptr; } diff --git a/layout/forms/nsListControlFrame.h b/layout/forms/nsListControlFrame.h index d6c4dc767f00..024a25433873 100644 --- a/layout/forms/nsListControlFrame.h +++ b/layout/forms/nsListControlFrame.h @@ -117,7 +117,7 @@ public: // nsIListControlFrame virtual void SetComboboxFrame(nsIFrame* aComboboxFrame) MOZ_OVERRIDE; virtual int32_t GetSelectedIndex() MOZ_OVERRIDE; - virtual already_AddRefed GetCurrentOption() MOZ_OVERRIDE; + virtual mozilla::dom::HTMLOptionElement* GetCurrentOption() MOZ_OVERRIDE; /** * Gets the text of the currently selected item.