Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). | 2 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
| 3 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 3 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 4 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 4 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 5 * (C) 2001 Dirk Mueller (mueller@kde.org) | 5 * (C) 2001 Dirk Mueller (mueller@kde.org) |
| 6 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 2011 Apple Inc. All rights reserved. | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 2011 Apple Inc. All rights reserved. |
| 7 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) | 7 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) |
| 8 * Copyright (C) 2010 Google Inc. All rights reserved. | 8 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 9 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) | 9 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) |
| 10 * | 10 * |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 return firstSelectionIndex < 0 || (!firstSelectionIndex && hasPlaceholderLab elOption()); | 201 return firstSelectionIndex < 0 || (!firstSelectionIndex && hasPlaceholderLab elOption()); |
| 202 } | 202 } |
| 203 | 203 |
| 204 String HTMLSelectElement::defaultToolTip() const | 204 String HTMLSelectElement::defaultToolTip() const |
| 205 { | 205 { |
| 206 if (form() && form()->noValidate()) | 206 if (form() && form()->noValidate()) |
| 207 return String(); | 207 return String(); |
| 208 return validationMessage(); | 208 return validationMessage(); |
| 209 } | 209 } |
| 210 | 210 |
| 211 void HTMLSelectElement::listBoxSelectItem(int listIndex, bool allowMultiplySelec tions, bool fireOnChangeNow) | 211 void HTMLSelectElement::selectMultipleOptionsByPopup(const Vector<int>& listIndi ces) |
| 212 { | 212 { |
| 213 if (!multiple()) { | 213 DCHECK(usesMenuList()); |
| 214 optionSelectedByUser(listToOptionIndex(listIndex), fireOnChangeNow); | 214 DCHECK(!multiple()); |
|
wychen
2016/09/29 02:42:57
Should this line be DCHECK(multiple())? I'm a bit
tkent
2016/09/29 03:14:55
I think so :)
| |
| 215 } else { | 215 for (size_t i = 0; i < listIndices.size(); ++i) { |
| 216 HTMLElement* element = listItems()[listIndex]; | 216 bool addSelectionIfNotFirst = i > 0; |
| 217 HTMLElement* element = listItems()[listIndices[i]]; | |
| 217 if (isHTMLOptionElement(element)) | 218 if (isHTMLOptionElement(element)) |
| 218 updateSelectedState(toHTMLOptionElement(element), allowMultiplySelec tions, false); | 219 updateSelectedState(toHTMLOptionElement(element), addSelectionIfNotF irst, false); |
| 219 setNeedsValidityCheck(); | |
| 220 if (fireOnChangeNow) | |
| 221 listBoxOnChange(); | |
| 222 } | 220 } |
| 221 setNeedsValidityCheck(); | |
| 222 // TODO(tkent): Using listBoxOnChange() is very confusing. | |
| 223 listBoxOnChange(); | |
| 223 } | 224 } |
| 224 | 225 |
| 225 bool HTMLSelectElement::usesMenuList() const | 226 bool HTMLSelectElement::usesMenuList() const |
| 226 { | 227 { |
| 227 if (LayoutTheme::theme().delegatesMenuListRendering()) | 228 if (LayoutTheme::theme().delegatesMenuListRendering()) |
| 228 return true; | 229 return true; |
| 229 | 230 |
| 230 return !m_multiple && m_size <= 1; | 231 return !m_multiple && m_size <= 1; |
| 231 } | 232 } |
| 232 | 233 |
| (...skipping 1027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1260 void HTMLSelectElement::handlePopupOpenKeyboardEvent(Event* event) | 1261 void HTMLSelectElement::handlePopupOpenKeyboardEvent(Event* event) |
| 1261 { | 1262 { |
| 1262 focus(); | 1263 focus(); |
| 1263 // Calling focus() may cause us to lose our layoutObject. Return true so | 1264 // Calling focus() may cause us to lose our layoutObject. Return true so |
| 1264 // that our caller doesn't process the event further, but don't set | 1265 // that our caller doesn't process the event further, but don't set |
| 1265 // the event as handled. | 1266 // the event as handled. |
| 1266 if (!layoutObject() || !layoutObject()->isMenuList() || isDisabledFormContro l()) | 1267 if (!layoutObject() || !layoutObject()->isMenuList() || isDisabledFormContro l()) |
| 1267 return; | 1268 return; |
| 1268 // Save the selection so it can be compared to the new selection when | 1269 // Save the selection so it can be compared to the new selection when |
| 1269 // dispatching change events during selectOption, which gets called from | 1270 // dispatching change events during selectOption, which gets called from |
| 1270 // valueChanged, which gets called after the user makes a selection from the | 1271 // selectOptionByPopup, which gets called after the user makes a selection |
| 1271 // menu. | 1272 // from the menu. |
| 1272 saveLastSelection(); | 1273 saveLastSelection(); |
| 1273 showPopup(); | 1274 showPopup(); |
| 1274 event->setDefaultHandled(); | 1275 event->setDefaultHandled(); |
| 1275 return; | 1276 return; |
| 1276 } | 1277 } |
| 1277 | 1278 |
| 1278 bool HTMLSelectElement::shouldOpenPopupForKeyDownEvent(KeyboardEvent* keyEvent) | 1279 bool HTMLSelectElement::shouldOpenPopupForKeyDownEvent(KeyboardEvent* keyEvent) |
| 1279 { | 1280 { |
| 1280 const String& key = keyEvent->key(); | 1281 const String& key = keyEvent->key(); |
| 1281 LayoutTheme& layoutTheme = LayoutTheme::theme(); | 1282 LayoutTheme& layoutTheme = LayoutTheme::theme(); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1379 | 1380 |
| 1380 if (event->type() == EventTypeNames::mousedown && event->isMouseEvent() && t oMouseEvent(event)->button() == LeftButton) { | 1381 if (event->type() == EventTypeNames::mousedown && event->isMouseEvent() && t oMouseEvent(event)->button() == LeftButton) { |
| 1381 InputDeviceCapabilities* sourceCapabilities = toMouseEvent(event)->fromT ouch() ? InputDeviceCapabilities::firesTouchEventsSourceCapabilities() : InputDe viceCapabilities::doesntFireTouchEventsSourceCapabilities(); | 1382 InputDeviceCapabilities* sourceCapabilities = toMouseEvent(event)->fromT ouch() ? InputDeviceCapabilities::firesTouchEventsSourceCapabilities() : InputDe viceCapabilities::doesntFireTouchEventsSourceCapabilities(); |
| 1382 focus(FocusParams(SelectionBehaviorOnFocus::Restore, WebFocusTypeNone, s ourceCapabilities)); | 1383 focus(FocusParams(SelectionBehaviorOnFocus::Restore, WebFocusTypeNone, s ourceCapabilities)); |
| 1383 if (layoutObject() && layoutObject()->isMenuList() && !isDisabledFormCon trol()) { | 1384 if (layoutObject() && layoutObject()->isMenuList() && !isDisabledFormCon trol()) { |
| 1384 if (popupIsVisible()) { | 1385 if (popupIsVisible()) { |
| 1385 hidePopup(); | 1386 hidePopup(); |
| 1386 } else { | 1387 } else { |
| 1387 // Save the selection so it can be compared to the new selection | 1388 // Save the selection so it can be compared to the new selection |
| 1388 // when we call onChange during selectOption, which gets called | 1389 // when we call onChange during selectOption, which gets called |
| 1389 // from valueChanged, which gets called after the user makes a | 1390 // from selectOptionByPopup, which gets called after the user |
| 1390 // selection from the menu. | 1391 // makes a selection from the menu. |
| 1391 saveLastSelection(); | 1392 saveLastSelection(); |
| 1392 // TODO(lanwei): Will check if we need to add | 1393 // TODO(lanwei): Will check if we need to add |
| 1393 // InputDeviceCapabilities here when select menu list gets | 1394 // InputDeviceCapabilities here when select menu list gets |
| 1394 // focus, see https://crbug.com/476530. | 1395 // focus, see https://crbug.com/476530. |
| 1395 showPopup(); | 1396 showPopup(); |
| 1396 } | 1397 } |
| 1397 } | 1398 } |
| 1398 event->setDefaultHandled(); | 1399 event->setDefaultHandled(); |
| 1399 } | 1400 } |
| 1400 | 1401 |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1916 return toHTMLOptionElement(listItems()[m_indexToSelectOnCancel]); | 1917 return toHTMLOptionElement(listItems()[m_indexToSelectOnCancel]); |
| 1917 if (m_suggestedOption) | 1918 if (m_suggestedOption) |
| 1918 return m_suggestedOption; | 1919 return m_suggestedOption; |
| 1919 // TODO(tkent): We should not call optionToBeShown() in multiple() case. | 1920 // TODO(tkent): We should not call optionToBeShown() in multiple() case. |
| 1920 if (multiple()) | 1921 if (multiple()) |
| 1921 return selectedOption(); | 1922 return selectedOption(); |
| 1922 DCHECK_EQ(selectedOption(), m_lastOnChangeOption); | 1923 DCHECK_EQ(selectedOption(), m_lastOnChangeOption); |
| 1923 return m_lastOnChangeOption; | 1924 return m_lastOnChangeOption; |
| 1924 } | 1925 } |
| 1925 | 1926 |
| 1926 void HTMLSelectElement::valueChanged(unsigned listIndex) | 1927 void HTMLSelectElement::selectOptionByPopup(int listIndex) |
| 1927 { | 1928 { |
| 1929 DCHECK(usesMenuList()); | |
| 1928 // Check to ensure a page navigation has not occurred while the popup was | 1930 // Check to ensure a page navigation has not occurred while the popup was |
| 1929 // up. | 1931 // up. |
| 1930 Document& doc = document(); | 1932 Document& doc = document(); |
| 1931 if (&doc != doc.frame()->document()) | 1933 if (&doc != doc.frame()->document()) |
| 1932 return; | 1934 return; |
| 1933 | 1935 |
| 1934 setIndexToSelectOnCancel(-1); | 1936 setIndexToSelectOnCancel(-1); |
| 1935 optionSelectedByUser(listToOptionIndex(listIndex), true); | 1937 optionSelectedByUser(listToOptionIndex(listIndex), true); |
| 1936 } | 1938 } |
| 1937 | 1939 |
| 1938 void HTMLSelectElement::popupDidCancel() | 1940 void HTMLSelectElement::popupDidCancel() |
| 1939 { | 1941 { |
| 1940 if (m_indexToSelectOnCancel >= 0) | 1942 if (m_indexToSelectOnCancel >= 0) |
| 1941 valueChanged(m_indexToSelectOnCancel); | 1943 selectOptionByPopup(m_indexToSelectOnCancel); |
| 1942 } | 1944 } |
| 1943 | 1945 |
| 1944 void HTMLSelectElement::provisionalSelectionChanged(unsigned listIndex) | 1946 void HTMLSelectElement::provisionalSelectionChanged(unsigned listIndex) |
| 1945 { | 1947 { |
| 1946 setIndexToSelectOnCancel(listIndex); | 1948 setIndexToSelectOnCancel(listIndex); |
| 1947 } | 1949 } |
| 1948 | 1950 |
| 1949 void HTMLSelectElement::showPopup() | 1951 void HTMLSelectElement::showPopup() |
| 1950 { | 1952 { |
| 1951 if (popupIsVisible()) | 1953 if (popupIsVisible()) |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2069 } | 2071 } |
| 2070 | 2072 |
| 2071 void HTMLSelectElement::didMutateSubtree() | 2073 void HTMLSelectElement::didMutateSubtree() |
| 2072 { | 2074 { |
| 2073 DCHECK(popupIsVisible()); | 2075 DCHECK(popupIsVisible()); |
| 2074 DCHECK(m_popup); | 2076 DCHECK(m_popup); |
| 2075 m_popup->updateFromElement(PopupMenu::ByDOMChange); | 2077 m_popup->updateFromElement(PopupMenu::ByDOMChange); |
| 2076 } | 2078 } |
| 2077 | 2079 |
| 2078 } // namespace blink | 2080 } // namespace blink |
| OLD | NEW |