TEST_F(HTMLSelectElementTest, ActiveSelectionEndAfterOptionRemoval) { document().documentElement()->setInnerHTML("<select><optgroup><option selected>o1</option></optgroup></select>", ASSERT_NO_EXCEPTION); document().view()->updateAllLifecyclePhases(); HTMLSelectElement* select = toHTMLSelectElement(document().body()->firstChild()); HTMLOptionElement* option = toHTMLOptionElement(select->firstChild()->firstChild()); EXPECT_EQ(1, select->activeSelectionEndListIndex()); select->firstChild()->removeChild(option, ASSERT_NO_EXCEPTION); EXPECT_EQ(-1, select->activeSelectionEndListIndex()); select->appendChild(option, ASSERT_NO_EXCEPTION); EXPECT_EQ(1, select->activeSelectionEndListIndex()); }
void RenderListBox::addFocusRingRects(Vector<LayoutRect>& rects, const LayoutPoint& additionalOffset) { if (!isSpatialNavigationEnabled(frame())) return RenderBlock::addFocusRingRects(rects, additionalOffset); HTMLSelectElement* select = toHTMLSelectElement(node()); // Focus the last selected item. int selectedItem = select->activeSelectionEndListIndex(); if (selectedItem >= 0) { rects.append(itemBoundingBoxRect(additionalOffset, selectedItem)); return; } // No selected items, find the first non-disabled item. int size = numItems(); const Vector<HTMLElement*>& listItems = select->listItems(); for (int i = 0; i < size; ++i) { HTMLElement* element = listItems[i]; if (element->hasTagName(optionTag) && !toHTMLOptionElement(element)->disabled()) { rects.append(itemBoundingBoxRect(additionalOffset, i)); return; } } }
bool AccessibilityListBoxOption::isSelectedOptionActive() const { HTMLSelectElement* listBoxParentNode = listBoxOptionParentNode(); if (!listBoxParentNode) return false; return listBoxParentNode->activeSelectionEndListIndex() == listBoxOptionIndex(); }
void RenderListBox::scrollToRevealSelection() { HTMLSelectElement* select = toHTMLSelectElement(node()); m_scrollToRevealSelectionAfterLayout = false; int firstIndex = select->activeSelectionStartListIndex(); if (firstIndex >= 0 && !listIndexIsVisible(select->activeSelectionEndListIndex())) scrollToRevealElementAtListIndex(firstIndex); }