diff --git a/layout/forms/nsListControlFrame.cpp b/layout/forms/nsListControlFrame.cpp index 76ad0ba402b..070b9c7eed6 100644 --- a/layout/forms/nsListControlFrame.cpp +++ b/layout/forms/nsListControlFrame.cpp @@ -619,41 +619,6 @@ nsListControlFrame::GetContentInsertionFrame() { return GetOptionsContainer()->GetContentInsertionFrame(); } -//--------------------------------------------------------- -// Starts at the passed in content object and walks up the -// parent heierarchy looking for the nsIDOMHTMLOptionElement -//--------------------------------------------------------- -nsIContent * -nsListControlFrame::GetOptionFromContent(nsIContent *aContent) -{ - for (nsIContent* content = aContent; content; content = content->GetParent()) { - if (content->IsHTML(nsGkAtoms::option)) { - return content; - } - } - - return nullptr; -} - -//--------------------------------------------------------- -// Finds the index of the hit frame's content in the list -// of option elements -//--------------------------------------------------------- -int32_t -nsListControlFrame::GetIndexFromContent(nsIContent *aContent) -{ - nsCOMPtr option; - option = do_QueryInterface(aContent); - if (option) { - int32_t retval; - option->GetIndex(&retval); - if (retval >= 0) { - return retval; - } - } - return kNothingSelected; -} - //--------------------------------------------------------- bool nsListControlFrame::ExtendedSelection(int32_t aStartIndex, @@ -1802,12 +1767,17 @@ nsListControlFrame::GetIndexFromDOMEvent(nsIDOMEvent* aMouseEvent, } } - nsCOMPtr content = PresContext()->EventStateManager()-> - GetEventTargetContent(nullptr); + nsRefPtr option; + for (nsCOMPtr content = + PresContext()->EventStateManager()->GetEventTargetContent(nullptr); + content && !option; + content = content->GetParent()) { + option = dom::HTMLOptionElement::FromContent(content); + } - nsCOMPtr optionContent = GetOptionFromContent(content); - if (optionContent) { - aCurIndex = GetIndexFromContent(optionContent); + if (option) { + option->GetIndex(&aCurIndex); + MOZ_ASSERT(aCurIndex >= 0); return NS_OK; } @@ -1819,7 +1789,7 @@ nsListControlFrame::GetIndexFromDOMEvent(nsIDOMEvent* aMouseEvent, // If the event coordinate is above the first option frame, then target the // first option frame - nsCOMPtr firstOption = GetOptionContent(0); + nsRefPtr firstOption = GetOption(0); NS_ASSERTION(firstOption, "Can't find first option that's supposed to be there"); nsIFrame* optionFrame = firstOption->GetPrimaryFrame(); if (optionFrame) { @@ -1831,7 +1801,7 @@ nsListControlFrame::GetIndexFromDOMEvent(nsIDOMEvent* aMouseEvent, } } - nsCOMPtr lastOption = GetOptionContent(numOptions - 1); + nsRefPtr lastOption = GetOption(numOptions - 1); // If the event coordinate is below the last option frame, then target the // last option frame NS_ASSERTION(lastOption, "Can't find last option that's supposed to be there"); diff --git a/layout/forms/nsListControlFrame.h b/layout/forms/nsListControlFrame.h index 024a2543387..cfdc2f940b4 100644 --- a/layout/forms/nsListControlFrame.h +++ b/layout/forms/nsListControlFrame.h @@ -321,7 +321,6 @@ protected: // Utility methods nsresult GetSizeAttribute(uint32_t *aSize); - nsIContent* GetOptionFromContent(nsIContent *aContent); /** * Sets the mSelectedIndex and mOldSelectedIndex from figuring out what @@ -338,7 +337,6 @@ protected: already_AddRefed GetOptionContent(int32_t aIndex) const; bool CheckIfAllFramesHere(); - int32_t GetIndexFromContent(nsIContent *aContent); bool IsLeftButton(nsIDOMEvent* aMouseEvent); // guess at a row height based on our own style.