Commit 27b62f45 authored by tkent's avatar tkent Committed by Commit bot

AX: Don't use listIndex in AXListBoxOption class.

* AXListBoxOption::isSelectedOptionActive()
  We don't need to compare indices. We can compare node pointers.

* AXListBoxOption::setSelected()
  We don't need to compute an optionIndex.  We can pass an HTMLOptionElement
  pointer directly by changing the argument type of accessKeySetSelectedIndex().
  This CL renames accessKeySetSelectedIndex() to selectOptionByAccessKey().

Now, we can remove AXListBoxOption::listBoxOptionIndex() and
HTMLSelectElement::listToOptionIndex().

Review-Url: https://codereview.chromium.org/2147963004
Cr-Commit-Position: refs/heads/master@{#405500}
parent 837ddb07
...@@ -171,7 +171,7 @@ void HTMLOptionElement::setText(const String &text, ExceptionState& exceptionSta ...@@ -171,7 +171,7 @@ void HTMLOptionElement::setText(const String &text, ExceptionState& exceptionSta
void HTMLOptionElement::accessKeyAction(bool) void HTMLOptionElement::accessKeyAction(bool)
{ {
if (HTMLSelectElement* select = ownerSelectElement()) if (HTMLSelectElement* select = ownerSelectElement())
select->accessKeySetSelectedIndex(index()); select->selectOptionByAccessKey(this);
} }
int HTMLOptionElement::index() const int HTMLOptionElement::index() const
......
...@@ -1064,22 +1064,6 @@ int HTMLSelectElement::optionToListIndex(int optionIndex) const ...@@ -1064,22 +1064,6 @@ int HTMLSelectElement::optionToListIndex(int optionIndex) const
return -1; return -1;
} }
int HTMLSelectElement::listToOptionIndex(int listIndex) const
{
const ListItems& items = listItems();
if (!optionAtListIndex(listIndex))
return -1;
// Actual index of option not counting OPTGROUP entries that may be in list.
int optionIndex = 0;
for (int i = 0; i < listIndex; ++i) {
if (isHTMLOptionElement(*items[i]))
++optionIndex;
}
return optionIndex;
}
void HTMLSelectElement::dispatchFocusEvent(Element* oldFocusedElement, WebFocusType type, InputDeviceCapabilities* sourceCapabilities) void HTMLSelectElement::dispatchFocusEvent(Element* oldFocusedElement, WebFocusType type, InputDeviceCapabilities* sourceCapabilities)
{ {
// Save the selection so it can be compared to the new selection when // Save the selection so it can be compared to the new selection when
...@@ -1717,14 +1701,13 @@ void HTMLSelectElement::typeAheadFind(KeyboardEvent* event) ...@@ -1717,14 +1701,13 @@ void HTMLSelectElement::typeAheadFind(KeyboardEvent* event)
listBoxOnChange(); listBoxOnChange();
} }
void HTMLSelectElement::accessKeySetSelectedIndex(int index) void HTMLSelectElement::selectOptionByAccessKey(HTMLOptionElement* option)
{ {
// First bring into focus the list box. // First bring into focus the list box.
if (!focused()) if (!focused())
accessKeyAction(false); accessKeyAction(false);
HTMLOptionElement* option = item(index); if (!option || option->ownerSelectElement() != this)
if (!option)
return; return;
EventQueueScope scope; EventQueueScope scope;
// If this index is already selected, unselect. otherwise update the // If this index is already selected, unselect. otherwise update the
......
...@@ -102,7 +102,7 @@ public: ...@@ -102,7 +102,7 @@ public:
const ListItems& listItems() const; const ListItems& listItems() const;
void accessKeyAction(bool sendMouseEvents) override; void accessKeyAction(bool sendMouseEvents) override;
void accessKeySetSelectedIndex(int); void selectOptionByAccessKey(HTMLOptionElement*);
void setOption(unsigned index, HTMLOptionElement*, ExceptionState&); void setOption(unsigned index, HTMLOptionElement*, ExceptionState&);
...@@ -114,7 +114,6 @@ public: ...@@ -114,7 +114,6 @@ public:
bool canSelectAll() const; bool canSelectAll() const;
void selectAll(); void selectAll();
int listToOptionIndex(int listIndex) const;
void listBoxOnChange(); void listBoxOnChange();
int optionToListIndex(int optionIndex) const; int optionToListIndex(int optionIndex) const;
int activeSelectionEndListIndex() const; int activeSelectionEndListIndex() const;
......
...@@ -108,7 +108,7 @@ bool AXListBoxOption::isSelectedOptionActive() const ...@@ -108,7 +108,7 @@ bool AXListBoxOption::isSelectedOptionActive() const
if (!listBoxParentNode) if (!listBoxParentNode)
return false; return false;
return listBoxParentNode->activeSelectionEndListIndex() == listBoxOptionIndex(); return listBoxParentNode->activeSelectionEnd() == getNode();
} }
bool AXListBoxOption::computeAccessibilityIsIgnored(IgnoredReasons* ignoredReasons) const bool AXListBoxOption::computeAccessibilityIsIgnored(IgnoredReasons* ignoredReasons) const
...@@ -176,9 +176,7 @@ void AXListBoxOption::setSelected(bool selected) ...@@ -176,9 +176,7 @@ void AXListBoxOption::setSelected(bool selected)
if ((isOptionSelected && selected) || (!isOptionSelected && !selected)) if ((isOptionSelected && selected) || (!isOptionSelected && !selected))
return; return;
// Convert from the entire list index to the option index. selectElement->selectOptionByAccessKey(toHTMLOptionElement(getNode()));
int optionIndex = selectElement->listToOptionIndex(listBoxOptionIndex());
selectElement->accessKeySetSelectedIndex(optionIndex);
} }
HTMLSelectElement* AXListBoxOption::listBoxOptionParentNode() const HTMLSelectElement* AXListBoxOption::listBoxOptionParentNode() const
...@@ -192,20 +190,4 @@ HTMLSelectElement* AXListBoxOption::listBoxOptionParentNode() const ...@@ -192,20 +190,4 @@ HTMLSelectElement* AXListBoxOption::listBoxOptionParentNode() const
return 0; return 0;
} }
int AXListBoxOption::listBoxOptionIndex() const
{
HTMLSelectElement* selectElement = listBoxOptionParentNode();
if (!selectElement)
return -1;
const HeapVector<Member<HTMLElement>>& listItems = selectElement->listItems();
unsigned length = listItems.size();
for (unsigned i = 0; i < length; i++) {
if (listItems[i] == getNode())
return i;
}
return -1;
}
} // namespace blink } // namespace blink
...@@ -62,7 +62,6 @@ private: ...@@ -62,7 +62,6 @@ private:
bool computeAccessibilityIsIgnored(IgnoredReasons* = nullptr) const override; bool computeAccessibilityIsIgnored(IgnoredReasons* = nullptr) const override;
HTMLSelectElement* listBoxOptionParentNode() const; HTMLSelectElement* listBoxOptionParentNode() const;
int listBoxOptionIndex() const;
bool isParentPresentationalRole() const; bool isParentPresentationalRole() const;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment