Bug 899931 - Part f: Cleanup nsListControlFrame::GetIndexFromDOMEvent; r=dzbarsky

This commit is contained in:
Ms2ger 2013-08-02 09:07:56 +02:00
parent aba0c83a1c
commit 12dfce76ee
2 changed files with 12 additions and 44 deletions

View File

@ -619,41 +619,6 @@ nsListControlFrame::GetContentInsertionFrame() {
return GetOptionsContainer()->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<nsIDOMHTMLOptionElement> option;
option = do_QueryInterface(aContent);
if (option) {
int32_t retval;
option->GetIndex(&retval);
if (retval >= 0) {
return retval;
}
}
return kNothingSelected;
}
//--------------------------------------------------------- //---------------------------------------------------------
bool bool
nsListControlFrame::ExtendedSelection(int32_t aStartIndex, nsListControlFrame::ExtendedSelection(int32_t aStartIndex,
@ -1802,12 +1767,17 @@ nsListControlFrame::GetIndexFromDOMEvent(nsIDOMEvent* aMouseEvent,
} }
} }
nsCOMPtr<nsIContent> content = PresContext()->EventStateManager()-> nsRefPtr<dom::HTMLOptionElement> option;
GetEventTargetContent(nullptr); for (nsCOMPtr<nsIContent> content =
PresContext()->EventStateManager()->GetEventTargetContent(nullptr);
content && !option;
content = content->GetParent()) {
option = dom::HTMLOptionElement::FromContent(content);
}
nsCOMPtr<nsIContent> optionContent = GetOptionFromContent(content); if (option) {
if (optionContent) { option->GetIndex(&aCurIndex);
aCurIndex = GetIndexFromContent(optionContent); MOZ_ASSERT(aCurIndex >= 0);
return NS_OK; return NS_OK;
} }
@ -1819,7 +1789,7 @@ nsListControlFrame::GetIndexFromDOMEvent(nsIDOMEvent* aMouseEvent,
// If the event coordinate is above the first option frame, then target the // If the event coordinate is above the first option frame, then target the
// first option frame // first option frame
nsCOMPtr<nsIContent> firstOption = GetOptionContent(0); nsRefPtr<dom::HTMLOptionElement> firstOption = GetOption(0);
NS_ASSERTION(firstOption, "Can't find first option that's supposed to be there"); NS_ASSERTION(firstOption, "Can't find first option that's supposed to be there");
nsIFrame* optionFrame = firstOption->GetPrimaryFrame(); nsIFrame* optionFrame = firstOption->GetPrimaryFrame();
if (optionFrame) { if (optionFrame) {
@ -1831,7 +1801,7 @@ nsListControlFrame::GetIndexFromDOMEvent(nsIDOMEvent* aMouseEvent,
} }
} }
nsCOMPtr<nsIContent> lastOption = GetOptionContent(numOptions - 1); nsRefPtr<dom::HTMLOptionElement> lastOption = GetOption(numOptions - 1);
// If the event coordinate is below the last option frame, then target the // If the event coordinate is below the last option frame, then target the
// last option frame // last option frame
NS_ASSERTION(lastOption, "Can't find last option that's supposed to be there"); NS_ASSERTION(lastOption, "Can't find last option that's supposed to be there");

View File

@ -321,7 +321,6 @@ protected:
// Utility methods // Utility methods
nsresult GetSizeAttribute(uint32_t *aSize); nsresult GetSizeAttribute(uint32_t *aSize);
nsIContent* GetOptionFromContent(nsIContent *aContent);
/** /**
* Sets the mSelectedIndex and mOldSelectedIndex from figuring out what * Sets the mSelectedIndex and mOldSelectedIndex from figuring out what
@ -338,7 +337,6 @@ protected:
already_AddRefed<nsIContent> GetOptionContent(int32_t aIndex) const; already_AddRefed<nsIContent> GetOptionContent(int32_t aIndex) const;
bool CheckIfAllFramesHere(); bool CheckIfAllFramesHere();
int32_t GetIndexFromContent(nsIContent *aContent);
bool IsLeftButton(nsIDOMEvent* aMouseEvent); bool IsLeftButton(nsIDOMEvent* aMouseEvent);
// guess at a row height based on our own style. // guess at a row height based on our own style.