OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/views/controls/button/menu_button.h" | 5 #include "ui/views/controls/button/menu_button.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "grit/ui_resources.h" | 8 #include "grit/ui_resources.h" |
9 #include "grit/ui_strings.h" | 9 #include "grit/ui_strings.h" |
10 #include "ui/accessibility/ax_view_state.h" | 10 #include "ui/accessibility/ax_view_state.h" |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 bool MenuButton::OnKeyPressed(const ui::KeyEvent& event) { | 213 bool MenuButton::OnKeyPressed(const ui::KeyEvent& event) { |
214 switch (event.key_code()) { | 214 switch (event.key_code()) { |
215 case ui::VKEY_SPACE: | 215 case ui::VKEY_SPACE: |
216 // Alt-space on windows should show the window menu. | 216 // Alt-space on windows should show the window menu. |
217 if (event.IsAltDown()) | 217 if (event.IsAltDown()) |
218 break; | 218 break; |
219 case ui::VKEY_RETURN: | 219 case ui::VKEY_RETURN: |
220 case ui::VKEY_UP: | 220 case ui::VKEY_UP: |
221 case ui::VKEY_DOWN: { | 221 case ui::VKEY_DOWN: { |
222 // WARNING: we may have been deleted by the time Activate returns. | 222 // WARNING: we may have been deleted by the time Activate returns. |
223 bool ret = Activate(); | 223 Activate(); |
224 #if defined(USE_AURA) | 224 // This is to prevent the keyboard event from being dispatched twice. If |
225 // This is to prevent the keyboard event from being dispatched twice. | 225 // the keyboard event is not handled, we pass it to the default handler |
226 // The Activate function returns false in most cases. In AURA if the | 226 // which dispatches the event back to us causing the menu to get displayed |
227 // keyboard event is not handled, we pass it to the default handler | 227 // again. Return true to prevent this. |
228 // which dispatches the event back to us causing the menu to get | 228 return true; |
229 // displayed again. | |
230 ret = true; | |
231 #endif | |
232 return ret; | |
233 } | 229 } |
234 default: | 230 default: |
235 break; | 231 break; |
236 } | 232 } |
237 return false; | 233 return false; |
238 } | 234 } |
239 | 235 |
240 bool MenuButton::OnKeyReleased(const ui::KeyEvent& event) { | 236 bool MenuButton::OnKeyReleased(const ui::KeyEvent& event) { |
241 // Override CustomButton's implementation, which presses the button when | 237 // Override CustomButton's implementation, which presses the button when |
242 // you press space and clicks it when you release space. For a MenuButton | 238 // you press space and clicks it when you release space. For a MenuButton |
(...skipping 28 matching lines...) Expand all Loading... |
271 if (!GetWidget()) { | 267 if (!GetWidget()) { |
272 NOTREACHED(); | 268 NOTREACHED(); |
273 return 0; | 269 return 0; |
274 } | 270 } |
275 | 271 |
276 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen(); | 272 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen(); |
277 return monitor_bounds.right() - 1; | 273 return monitor_bounds.right() - 1; |
278 } | 274 } |
279 | 275 |
280 } // namespace views | 276 } // namespace views |
OLD | NEW |