| 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 1268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1279 // valueChanged, which gets called after the user makes a selection from the | 1279 // valueChanged, which gets called after the user makes a selection from the |
| 1280 // menu. | 1280 // menu. |
| 1281 saveLastSelection(); | 1281 saveLastSelection(); |
| 1282 showPopup(); | 1282 showPopup(); |
| 1283 event->setDefaultHandled(); | 1283 event->setDefaultHandled(); |
| 1284 return; | 1284 return; |
| 1285 } | 1285 } |
| 1286 | 1286 |
| 1287 bool HTMLSelectElement::shouldOpenPopupForKeyDownEvent(KeyboardEvent* keyEvent) | 1287 bool HTMLSelectElement::shouldOpenPopupForKeyDownEvent(KeyboardEvent* keyEvent) |
| 1288 { | 1288 { |
| 1289 const String& keyIdentifier = keyEvent->keyIdentifier(); | 1289 const String& key = keyEvent->key(); |
| 1290 LayoutTheme& layoutTheme = LayoutTheme::theme(); | 1290 LayoutTheme& layoutTheme = LayoutTheme::theme(); |
| 1291 | 1291 |
| 1292 if (isSpatialNavigationEnabled(document().frame())) | 1292 if (isSpatialNavigationEnabled(document().frame())) |
| 1293 return false; | 1293 return false; |
| 1294 | 1294 |
| 1295 return ((layoutTheme.popsMenuByArrowKeys() && (keyIdentifier == "Down" || k
eyIdentifier == "Up")) | 1295 return ((layoutTheme.popsMenuByArrowKeys() && (key == "ArrowDown" || key ==
"ArrowUp")) |
| 1296 || (layoutTheme.popsMenuByAltDownUpOrF4Key() && (keyIdentifier == "Down"
|| keyIdentifier == "Up") && keyEvent->altKey()) | 1296 || (layoutTheme.popsMenuByAltDownUpOrF4Key() && (key == "ArrowDown" || k
ey == "ArrowUp") && keyEvent->altKey()) |
| 1297 || (layoutTheme.popsMenuByAltDownUpOrF4Key() && (!keyEvent->altKey() &&
!keyEvent->ctrlKey() && keyIdentifier == "F4"))); | 1297 || (layoutTheme.popsMenuByAltDownUpOrF4Key() && (!keyEvent->altKey() &&
!keyEvent->ctrlKey() && key == "F4"))); |
| 1298 } | 1298 } |
| 1299 | 1299 |
| 1300 bool HTMLSelectElement::shouldOpenPopupForKeyPressEvent(KeyboardEvent *event) | 1300 bool HTMLSelectElement::shouldOpenPopupForKeyPressEvent(KeyboardEvent *event) |
| 1301 { | 1301 { |
| 1302 LayoutTheme& layoutTheme = LayoutTheme::theme(); | 1302 LayoutTheme& layoutTheme = LayoutTheme::theme(); |
| 1303 int keyCode = event->keyCode(); | 1303 int keyCode = event->keyCode(); |
| 1304 | 1304 |
| 1305 return ((layoutTheme.popsMenuBySpaceKey() && event->keyCode() == ' ' && !m_t
ypeAhead.hasActiveSession(event)) | 1305 return ((layoutTheme.popsMenuBySpaceKey() && event->keyCode() == ' ' && !m_t
ypeAhead.hasActiveSession(event)) |
| 1306 || (layoutTheme.popsMenuByReturnKey() && keyCode == '\r')); | 1306 || (layoutTheme.popsMenuByReturnKey() && keyCode == '\r')); |
| 1307 } | 1307 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1324 if (isSpatialNavigationEnabled(document().frame())) { | 1324 if (isSpatialNavigationEnabled(document().frame())) { |
| 1325 if (!m_activeSelectionState) | 1325 if (!m_activeSelectionState) |
| 1326 return; | 1326 return; |
| 1327 } | 1327 } |
| 1328 | 1328 |
| 1329 // The key handling below shouldn't be used for non spatial navigation | 1329 // The key handling below shouldn't be used for non spatial navigation |
| 1330 // mode Mac | 1330 // mode Mac |
| 1331 if (LayoutTheme::theme().popsMenuByArrowKeys() && !isSpatialNavigationEn
abled(document().frame())) | 1331 if (LayoutTheme::theme().popsMenuByArrowKeys() && !isSpatialNavigationEn
abled(document().frame())) |
| 1332 return; | 1332 return; |
| 1333 | 1333 |
| 1334 const String& keyIdentifier = keyEvent->keyIdentifier(); | 1334 const String& key = keyEvent->key(); |
| 1335 bool handled = true; | 1335 bool handled = true; |
| 1336 const ListItems& listItems = this->listItems(); | 1336 const ListItems& listItems = this->listItems(); |
| 1337 HTMLOptionElement* option = selectedOption(); | 1337 HTMLOptionElement* option = selectedOption(); |
| 1338 int listIndex = option ? option->listIndex() : -1; | 1338 int listIndex = option ? option->listIndex() : -1; |
| 1339 | 1339 |
| 1340 if (keyIdentifier == "Down" || keyIdentifier == "Right") | 1340 if (key == "ArrowDown" || key == "ArrowRight") |
| 1341 option = nextValidOption(listIndex, SkipForwards, 1); | 1341 option = nextValidOption(listIndex, SkipForwards, 1); |
| 1342 else if (keyIdentifier == "Up" || keyIdentifier == "Left") | 1342 else if (key == "ArrowUp" || key == "ArrowLeft") |
| 1343 option = nextValidOption(listIndex, SkipBackwards, 1); | 1343 option = nextValidOption(listIndex, SkipBackwards, 1); |
| 1344 else if (keyIdentifier == "PageDown") | 1344 else if (key == "PageDown") |
| 1345 option = nextValidOption(listIndex, SkipForwards, 3); | 1345 option = nextValidOption(listIndex, SkipForwards, 3); |
| 1346 else if (keyIdentifier == "PageUp") | 1346 else if (key == "PageUp") |
| 1347 option = nextValidOption(listIndex, SkipBackwards, 3); | 1347 option = nextValidOption(listIndex, SkipBackwards, 3); |
| 1348 else if (keyIdentifier == "Home") | 1348 else if (key == "Home") |
| 1349 option = nextValidOption(-1, SkipForwards, 1); | 1349 option = nextValidOption(-1, SkipForwards, 1); |
| 1350 else if (keyIdentifier == "End") | 1350 else if (key == "End") |
| 1351 option = nextValidOption(listItems.size(), SkipBackwards, 1); | 1351 option = nextValidOption(listItems.size(), SkipBackwards, 1); |
| 1352 else | 1352 else |
| 1353 handled = false; | 1353 handled = false; |
| 1354 | 1354 |
| 1355 if (handled && option) | 1355 if (handled && option) |
| 1356 selectOption(option, DeselectOtherOptions | MakeOptionDirty | Dispat
chInputAndChangeEvent); | 1356 selectOption(option, DeselectOtherOptions | MakeOptionDirty | Dispat
chInputAndChangeEvent); |
| 1357 | 1357 |
| 1358 if (handled) | 1358 if (handled) |
| 1359 event->setDefaultHandled(); | 1359 event->setDefaultHandled(); |
| 1360 } | 1360 } |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1567 | 1567 |
| 1568 } else if (event->type() == EventTypeNames::mouseup && event->isMouseEvent()
&& toMouseEvent(event)->button() == LeftButton && layoutObject()) { | 1568 } else if (event->type() == EventTypeNames::mouseup && event->isMouseEvent()
&& toMouseEvent(event)->button() == LeftButton && layoutObject()) { |
| 1569 if (document().page() && document().page()->autoscrollController().autos
crollInProgress(toLayoutBox(layoutObject()))) | 1569 if (document().page() && document().page()->autoscrollController().autos
crollInProgress(toLayoutBox(layoutObject()))) |
| 1570 document().page()->autoscrollController().stopAutoscroll(); | 1570 document().page()->autoscrollController().stopAutoscroll(); |
| 1571 else | 1571 else |
| 1572 handleMouseRelease(); | 1572 handleMouseRelease(); |
| 1573 | 1573 |
| 1574 } else if (event->type() == EventTypeNames::keydown) { | 1574 } else if (event->type() == EventTypeNames::keydown) { |
| 1575 if (!event->isKeyboardEvent()) | 1575 if (!event->isKeyboardEvent()) |
| 1576 return; | 1576 return; |
| 1577 const String& keyIdentifier = toKeyboardEvent(event)->keyIdentifier(); | 1577 const String& key = toKeyboardEvent(event)->key(); |
| 1578 | 1578 |
| 1579 bool handled = false; | 1579 bool handled = false; |
| 1580 HTMLOptionElement* endOption = nullptr; | 1580 HTMLOptionElement* endOption = nullptr; |
| 1581 if (!m_activeSelectionEnd) { | 1581 if (!m_activeSelectionEnd) { |
| 1582 // Initialize the end index | 1582 // Initialize the end index |
| 1583 if (keyIdentifier == "Down" || keyIdentifier == "PageDown") { | 1583 if (key == "ArrowDown" || key == "PageDown") { |
| 1584 HTMLOptionElement* startOption = lastSelectedOption(); | 1584 HTMLOptionElement* startOption = lastSelectedOption(); |
| 1585 handled = true; | 1585 handled = true; |
| 1586 if (keyIdentifier == "Down") | 1586 if (key == "ArrowDown") |
| 1587 endOption = nextSelectableOption(startOption); | 1587 endOption = nextSelectableOption(startOption); |
| 1588 else | 1588 else |
| 1589 endOption = nextSelectableOptionPageAway(startOption, SkipFo
rwards); | 1589 endOption = nextSelectableOptionPageAway(startOption, SkipFo
rwards); |
| 1590 } else if (keyIdentifier == "Up" || keyIdentifier == "PageUp") { | 1590 } else if (key == "ArrowUp" || key == "PageUp") { |
| 1591 HTMLOptionElement* startOption = selectedOption(); | 1591 HTMLOptionElement* startOption = selectedOption(); |
| 1592 handled = true; | 1592 handled = true; |
| 1593 if (keyIdentifier == "Up") | 1593 if (key == "ArrowUp") |
| 1594 endOption = previousSelectableOption(startOption); | 1594 endOption = previousSelectableOption(startOption); |
| 1595 else | 1595 else |
| 1596 endOption = nextSelectableOptionPageAway(startOption, SkipBa
ckwards); | 1596 endOption = nextSelectableOptionPageAway(startOption, SkipBa
ckwards); |
| 1597 } | 1597 } |
| 1598 } else { | 1598 } else { |
| 1599 // Set the end index based on the current end index. | 1599 // Set the end index based on the current end index. |
| 1600 if (keyIdentifier == "Down") { | 1600 if (key == "ArrowDown") { |
| 1601 endOption = nextSelectableOption(m_activeSelectionEnd.get()); | 1601 endOption = nextSelectableOption(m_activeSelectionEnd.get()); |
| 1602 handled = true; | 1602 handled = true; |
| 1603 } else if (keyIdentifier == "Up") { | 1603 } else if (key == "ArrowUp") { |
| 1604 endOption = previousSelectableOption(m_activeSelectionEnd.get())
; | 1604 endOption = previousSelectableOption(m_activeSelectionEnd.get())
; |
| 1605 handled = true; | 1605 handled = true; |
| 1606 } else if (keyIdentifier == "PageDown") { | 1606 } else if (key == "PageDown") { |
| 1607 endOption = nextSelectableOptionPageAway(m_activeSelectionEnd.ge
t(), SkipForwards); | 1607 endOption = nextSelectableOptionPageAway(m_activeSelectionEnd.ge
t(), SkipForwards); |
| 1608 handled = true; | 1608 handled = true; |
| 1609 } else if (keyIdentifier == "PageUp") { | 1609 } else if (key == "PageUp") { |
| 1610 endOption = nextSelectableOptionPageAway(m_activeSelectionEnd.ge
t(), SkipBackwards); | 1610 endOption = nextSelectableOptionPageAway(m_activeSelectionEnd.ge
t(), SkipBackwards); |
| 1611 handled = true; | 1611 handled = true; |
| 1612 } | 1612 } |
| 1613 } | 1613 } |
| 1614 if (keyIdentifier == "Home") { | 1614 if (key == "Home") { |
| 1615 endOption = firstSelectableOption(); | 1615 endOption = firstSelectableOption(); |
| 1616 handled = true; | 1616 handled = true; |
| 1617 } else if (keyIdentifier == "End") { | 1617 } else if (key == "End") { |
| 1618 endOption = lastSelectableOption(); | 1618 endOption = lastSelectableOption(); |
| 1619 handled = true; | 1619 handled = true; |
| 1620 } | 1620 } |
| 1621 | 1621 |
| 1622 if (isSpatialNavigationEnabled(document().frame())) { | 1622 if (isSpatialNavigationEnabled(document().frame())) { |
| 1623 // Check if the selection moves to the boundary. | 1623 // Check if the selection moves to the boundary. |
| 1624 if (keyIdentifier == "Left" || keyIdentifier == "Right" || ((keyIden
tifier == "Down" || keyIdentifier == "Up") && endOption == m_activeSelectionEnd)
) | 1624 if (key == "ArrowLeft" || key == "ArrowRight" || ((key == "ArrowDown
" || key == "ArrowUp") && endOption == m_activeSelectionEnd)) |
| 1625 return; | 1625 return; |
| 1626 } | 1626 } |
| 1627 | 1627 |
| 1628 if (endOption && handled) { | 1628 if (endOption && handled) { |
| 1629 // Save the selection so it can be compared to the new selection | 1629 // Save the selection so it can be compared to the new selection |
| 1630 // when dispatching change events immediately after making the new | 1630 // when dispatching change events immediately after making the new |
| 1631 // selection. | 1631 // selection. |
| 1632 saveLastSelection(); | 1632 saveLastSelection(); |
| 1633 | 1633 |
| 1634 setActiveSelectionEnd(endOption); | 1634 setActiveSelectionEnd(endOption); |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2073 } | 2073 } |
| 2074 | 2074 |
| 2075 void HTMLSelectElement::didMutateSubtree() | 2075 void HTMLSelectElement::didMutateSubtree() |
| 2076 { | 2076 { |
| 2077 DCHECK(popupIsVisible()); | 2077 DCHECK(popupIsVisible()); |
| 2078 DCHECK(m_popup); | 2078 DCHECK(m_popup); |
| 2079 m_popup->updateFromElement(PopupMenu::ByDOMChange); | 2079 m_popup->updateFromElement(PopupMenu::ByDOMChange); |
| 2080 } | 2080 } |
| 2081 | 2081 |
| 2082 } // namespace blink | 2082 } // namespace blink |
| OLD | NEW |