+2006-10-16 Adam Roben <aroben@apple.com>
+
+ Reviewed by John.
+
+ More menulist cleanup/tweaking.
+
+ * html/HTMLSelectElement.cpp:
+ (WebCore::HTMLSelectElement::setSelectedIndex): Renamed 'index'
+ parameter to 'optionIndex' for clarity.
+ (WebCore::HTMLSelectElement::menuListDefaultEventHandler): Skip over
+ items that are not enabled <option> elements when using arrow keys, and
+ make sure we pass an option index to setSelectedIndex.
+ * platform/PopupMenu.h:
+ (WebCore::PopupMenu::setWasClicked): Specify default argument.
+ * rendering/RenderMenuList.cpp:
+ (WebCore::RenderMenuList::setTextFromOption): Strip whitespace from
+ option text before setting the control text so that options within
+ <optgroup>s don't appear indented in the actual control.
+
2006-10-16 Sam Weinig <sam.weinig@gmail.com>
Reviewed by Adam.
}
}
-void HTMLSelectElement::setSelectedIndex(int index, bool deselect, bool fireOnChange)
+void HTMLSelectElement::setSelectedIndex(int optionIndex, bool deselect, bool fireOnChange)
{
const Vector<HTMLElement*>& items = listItems();
- int listIndex = optionToListIndex(index);
+ int listIndex = optionToListIndex(optionIndex);
HTMLOptionElement* element = 0;
if (listIndex >= 0) {
element = static_cast<HTMLOptionElement*>(items[listIndex]);
if (deselect)
deselectItems(element);
if (fireOnChange) {
- m_lastOnChangeIndex = index;
+ m_lastOnChangeIndex = optionIndex;
onChange();
}
}
handled = true;
}
#else
- int index = optionToListIndex(selectedIndex());
+ int listIndex = optionToListIndex(selectedIndex());
if (keyIdentifier == "Down" || keyIdentifier == "Right") {
- if (index < listItems().size() - 1)
- setSelectedIndex(++index);
+ size_t size = listItems().size();
+ for (listIndex += 1;
+ listIndex >= 0 && listIndex < size && (listItems()[listIndex]->disabled() || !listItems()[listIndex]->hasTagName(optionTag));
+ ++listIndex);
+
+ if (listIndex >= 0 && listIndex < size)
+ setSelectedIndex(listToOptionIndex(listIndex));
handled = true;
} else if (keyIdentifier == "Up" || keyIdentifier == "Left") {
- if (index > 0)
- setSelectedIndex(--index);
+ size_t size = listItems().size();
+ for (listIndex -= 1;
+ listIndex >= 0 && listIndex < size && (listItems()[listIndex]->disabled() || !listItems()[listIndex]->hasTagName(optionTag));
+ --listIndex);
+
+ if (listIndex >= 0 && listIndex < size)
+ setSelectedIndex(listToOptionIndex(listIndex));
handled = true;
- } else if (keyIdentifier == "Enter" && index != m_lastOnChangeIndex) {
- setSelectedIndex(index, true, true);
+ } else if (keyIdentifier == "Enter" && listIndex != m_lastOnChangeIndex) {
+ setSelectedIndex(listToOptionIndex(listIndex), true, true);
}
#endif
#endif
#elif PLATFORM(WIN)
typedef struct HWND__* HWND;
+typedef struct tagDRAWITEMSTRUCT* LPDRAWITEMSTRUCT;
#endif
namespace WebCore {
bool down();
bool wasClicked() const { return m_wasClicked; }
- void setWasClicked(bool b) { m_wasClicked = b; }
+ void setWasClicked(bool b = true) { m_wasClicked = b; }
int focusedIndex() const;
#if PLATFORM(WIN)
HWND popupHandle() const { return m_popup; }
+ void drawItem(LPDRAWITEMSTRUCT);
#endif
protected: