Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(748)

Side by Side Diff: Source/core/html/HTMLSelectElement.cpp

Issue 368023003: Popup open and hide using Alt+KeyDown (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed mac tests Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1096 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 } 1107 }
1108 1108
1109 if (!selectedOption && firstOption && !m_multiple && m_size <= 1) 1109 if (!selectedOption && firstOption && !m_multiple && m_size <= 1)
1110 firstOption->setSelectedState(true); 1110 firstOption->setSelectedState(true);
1111 1111
1112 setOptionsChangedOnRenderer(); 1112 setOptionsChangedOnRenderer();
1113 setNeedsStyleRecalc(SubtreeStyleChange); 1113 setNeedsStyleRecalc(SubtreeStyleChange);
1114 setNeedsValidityCheck(); 1114 setNeedsValidityCheck();
1115 } 1115 }
1116 1116
1117 #if !OS(WIN) 1117 bool HTMLSelectElement::handlePopupOpenKeyboardEvent(Event* event)
keishi 2014/07/09 03:38:21 HTMLSelectElement::handlePopupOpenKeyboardEvent ha
Habib Virji 2014/07/09 09:49:39 Done.
1118 bool HTMLSelectElement::platformHandleKeydownEvent(KeyboardEvent* event)
1119 { 1118 {
1120 if (!RenderTheme::theme().popsMenuByArrowKeys()) 1119 bool shouldOpenPopup = false;
1121 return false; 1120 const KeyboardEvent* keyEvent = toKeyboardEvent(event);
1121 const String& keyIdentifier = keyEvent->keyIdentifier();
1122 RenderTheme& renderTheme = RenderTheme::theme();
1123 int keyCode = toKeyboardEvent(event)->keyCode();
keishi 2014/07/09 03:38:21 keyEvent
Habib Virji 2014/07/09 09:49:39 Done.
1122 1124
1123 if (!isSpatialNavigationEnabled(document().frame())) { 1125 if (event->type() == EventTypeNames::keypress) {
1124 if (event->keyIdentifier() == "Down" || event->keyIdentifier() == "Up") { 1126 if (keyCode == ' ' && isSpatialNavigationEnabled(document().frame())) {
1125 focus(); 1127 // Use space to toggle arrow key handling for selection change or sp atial navigation.
1126 // Calling focus() may cause us to lose our renderer. Return true so 1128 m_activeSelectionState = !m_activeSelectionState;
1127 // that our caller doesn't process the event further, but don't set 1129 event->setDefaultHandled();
1128 // the event as handled. 1130 return true;
1129 if (!renderer() || !renderer()->isMenuList() || isDisabledFormContro l()) 1131 }
1130 return true; 1132 // space works for all platforms
1133 // enter works for only linux and windows.
1134 shouldOpenPopup |= ((renderTheme.popsMenuBySpaceKey() && keyCode == ' ')
1135 || (!renderTheme.popsMenuByArrowKeys() && renderTheme.popsMenuByRetu rnKey() && keyCode == '\r')); // popsMenuByArrowKeys() is true only for mac
keishi 2014/07/09 03:38:21 popsMenuByReturnKey() should be false on mac so yo
Habib Virji 2014/07/09 09:49:39 Done.
1136 }
1131 1137
1132 // Save the selection so it can be compared to the new selection 1138 if (event->type() == EventTypeNames::keydown) {
1133 // when dispatching change events during selectOption, which 1139 // When using spatial navigation, we want to be able to navigate away
1134 // gets called from RenderMenuList::valueChanged, which gets called 1140 // from the select element when the user hits any of the arrow keys,
1135 // after the user makes a selection from the menu. 1141 // instead of changing the selection.
1136 saveLastSelection(); 1142 if (isSpatialNavigationEnabled(document().frame())) {
1137 if (RenderMenuList* menuList = toRenderMenuList(renderer())) 1143 return !m_activeSelectionState ? true : false; // false since we wan t it to continue
1138 menuList->showPopup(); 1144 }
1145 // down/Up works for mac.
1146 // down/up+alt & f4 works for linux and windows
keishi 2014/07/09 03:38:21 I don't think we need this comment because we aren
Habib Virji 2014/07/09 09:49:39 Done.
1147 shouldOpenPopup |= (renderTheme.popsMenuByArrowKeys() && (keyIdentifier == "Down" || keyIdentifier == "Up"))
1148 || (renderTheme.popsMenuByAltDownUpOrF4Key() && (keyIdentifier == "D own" || keyIdentifier == "Up") && (keyEvent->altKey() || keyEvent->altGraphKey() ))
1149 || (renderTheme.popsMenuByAltDownUpOrF4Key() && (!keyEvent->altKey() && !keyEvent->ctrlKey() && keyIdentifier == "F4"));
1150 }
1151
1152 if (shouldOpenPopup) {
1153 focus();
1154 // Calling focus() may cause us to lose our renderer. Return true so
1155 // that our caller doesn't process the event further, but don't set
1156 // the event as handled.
1157 if (!renderer() || !renderer()->isMenuList() || isDisabledFormControl())
1158 return true;
1159 // Save the selection so it can be compared to the new selection
1160 // when dispatching change events during selectOption, which
1161 // gets called from RenderMenuList::valueChanged, which gets called
1162 // after the user makes a selection from the menu.
1163 saveLastSelection();
1164 if (RenderMenuList* menuList = toRenderMenuList(renderer()))
1165 menuList->showPopup();
1166 int index = selectedIndex();
1167 ASSERT(index >= 0);
1168 ASSERT_WITH_SECURITY_IMPLICATION(index < static_cast<int>(listItems().si ze()));
1169 setSelectedIndex(index);
1170 event->setDefaultHandled();
1171 return true;
1172 }
1173
1174 // This is mac specific handling
1175 if (renderTheme.popsMenuByArrowKeys() && !isSpatialNavigationEnabled(documen t().frame())) {
1176 // Use key press event here since sending simulated mouse events
1177 // on key down blocks the proper sending of the out key press event.
1178 if (event->type() == EventTypeNames::keypress && renderTheme.popsMenuByR eturnKey() && keyCode == '\r') {
1179 if (form())
1180 form()->submitImplicitly(event, false);
1181 dispatchInputAndChangeEventForMenuList();
1139 event->setDefaultHandled(); 1182 event->setDefaultHandled();
1140 } 1183 }
1184 // In mac scenario, we do not want to handle any other key handling.
1185 // return true here for early return
1141 return true; 1186 return true;
1142 } 1187 }
1143 1188
1144 return false; 1189 return false;
1145 } 1190 }
1146 #endif
1147 1191
1148 void HTMLSelectElement::menuListDefaultEventHandler(Event* event) 1192 void HTMLSelectElement::menuListDefaultEventHandler(Event* event)
1149 { 1193 {
1150 RenderTheme& renderTheme = RenderTheme::theme(); 1194 if (renderer() && event->isKeyboardEvent() && handlePopupOpenKeyboardEvent(e vent))
1195 return;
1151 1196
1152 if (event->type() == EventTypeNames::keydown) { 1197 if (event->type() == EventTypeNames::keydown) {
1153 if (!renderer() || !event->isKeyboardEvent()) 1198 if (!renderer() || !event->isKeyboardEvent())
1154 return; 1199 return;
1155 1200
1156 if (platformHandleKeydownEvent(toKeyboardEvent(event)))
1157 return;
1158
1159 // When using spatial navigation, we want to be able to navigate away 1201 // When using spatial navigation, we want to be able to navigate away
1160 // from the select element when the user hits any of the arrow keys, 1202 // from the select element when the user hits any of the arrow keys,
1161 // instead of changing the selection. 1203 // instead of changing the selection.
1162 if (isSpatialNavigationEnabled(document().frame())) { 1204 if (isSpatialNavigationEnabled(document().frame())) {
1163 if (!m_activeSelectionState) 1205 if (!m_activeSelectionState)
1164 return; 1206 return;
1165 } 1207 }
1166 1208
1167 const String& keyIdentifier = toKeyboardEvent(event)->keyIdentifier(); 1209 const String& keyIdentifier = toKeyboardEvent(event)->keyIdentifier();
1168 bool handled = true; 1210 bool handled = true;
(...skipping 15 matching lines...) Expand all
1184 else 1226 else
1185 handled = false; 1227 handled = false;
1186 1228
1187 if (handled && static_cast<size_t>(listIndex) < listItems.size()) 1229 if (handled && static_cast<size_t>(listIndex) < listItems.size())
1188 selectOption(listToOptionIndex(listIndex), DeselectOtherOptions | Di spatchInputAndChangeEvent | UserDriven); 1230 selectOption(listToOptionIndex(listIndex), DeselectOtherOptions | Di spatchInputAndChangeEvent | UserDriven);
1189 1231
1190 if (handled) 1232 if (handled)
1191 event->setDefaultHandled(); 1233 event->setDefaultHandled();
1192 } 1234 }
1193 1235
1194 // Use key press event here since sending simulated mouse events
1195 // on key down blocks the proper sending of the key press event.
1196 if (event->type() == EventTypeNames::keypress) {
1197 if (!renderer() || !event->isKeyboardEvent())
1198 return;
1199
1200 int keyCode = toKeyboardEvent(event)->keyCode();
1201 bool handled = false;
1202
1203 if (keyCode == ' ' && isSpatialNavigationEnabled(document().frame())) {
1204 // Use space to toggle arrow key handling for selection change or sp atial navigation.
1205 m_activeSelectionState = !m_activeSelectionState;
1206 event->setDefaultHandled();
1207 return;
1208 }
1209
1210 if (renderTheme.popsMenuBySpaceOrReturn()) {
1211 if (keyCode == ' ' || keyCode == '\r') {
1212 focus();
1213
1214 // Calling focus() may remove the renderer or change the
1215 // renderer type.
1216 if (!renderer() || !renderer()->isMenuList() || isDisabledFormCo ntrol())
1217 return;
1218
1219 // Save the selection so it can be compared to the new selection
1220 // when dispatching change events during selectOption, which
1221 // gets called from RenderMenuList::valueChanged, which gets cal led
1222 // after the user makes a selection from the menu.
1223 saveLastSelection();
1224 if (RenderMenuList* menuList = toRenderMenuList(renderer()))
1225 menuList->showPopup();
1226 handled = true;
1227 }
1228 } else if (renderTheme.popsMenuByArrowKeys()) {
1229 if (keyCode == ' ') {
1230 focus();
1231
1232 // Calling focus() may remove the renderer or change the
1233 // renderer type.
1234 if (!renderer() || !renderer()->isMenuList() || isDisabledFormCo ntrol())
1235 return;
1236
1237 // Save the selection so it can be compared to the new selection
1238 // when dispatching change events during selectOption, which
1239 // gets called from RenderMenuList::valueChanged, which gets cal led
1240 // after the user makes a selection from the menu.
1241 saveLastSelection();
1242 if (RenderMenuList* menuList = toRenderMenuList(renderer()))
1243 menuList->showPopup();
1244 handled = true;
1245 } else if (keyCode == '\r') {
1246 if (form())
1247 form()->submitImplicitly(event, false);
1248 dispatchInputAndChangeEventForMenuList();
1249 handled = true;
1250 }
1251 }
1252
1253 if (handled)
1254 event->setDefaultHandled();
1255 }
1256
1257 if (event->type() == EventTypeNames::mousedown && event->isMouseEvent() && t oMouseEvent(event)->button() == LeftButton) { 1236 if (event->type() == EventTypeNames::mousedown && event->isMouseEvent() && t oMouseEvent(event)->button() == LeftButton) {
1258 focus(); 1237 focus();
1259 if (renderer() && renderer()->isMenuList() && !isDisabledFormControl()) { 1238 if (renderer() && renderer()->isMenuList() && !isDisabledFormControl()) {
1260 if (RenderMenuList* menuList = toRenderMenuList(renderer())) { 1239 if (RenderMenuList* menuList = toRenderMenuList(renderer())) {
1261 if (menuList->popupIsVisible()) 1240 if (menuList->popupIsVisible())
1262 menuList->hidePopup(); 1241 menuList->hidePopup();
1263 else { 1242 else {
1264 // Save the selection so it can be compared to the new 1243 // Save the selection so it can be compared to the new
1265 // selection when we call onChange during selectOption, 1244 // selection when we call onChange during selectOption,
1266 // which gets called from RenderMenuList::valueChanged, 1245 // which gets called from RenderMenuList::valueChanged,
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
1658 1637
1659 void HTMLSelectElement::trace(Visitor* visitor) 1638 void HTMLSelectElement::trace(Visitor* visitor)
1660 { 1639 {
1661 #if ENABLE(OILPAN) 1640 #if ENABLE(OILPAN)
1662 visitor->trace(m_listItems); 1641 visitor->trace(m_listItems);
1663 #endif 1642 #endif
1664 HTMLFormControlElementWithState::trace(visitor); 1643 HTMLFormControlElementWithState::trace(visitor);
1665 } 1644 }
1666 1645
1667 } // namespace 1646 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698