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/utf_string_conversions.h" | 7 #include "base/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/base/accessibility/accessible_view_state.h" | 10 #include "ui/base/accessibility/accessible_view_state.h" |
11 #include "ui/base/dragdrop/drag_drop_types.h" | 11 #include "ui/base/dragdrop/drag_drop_types.h" |
12 #include "ui/base/events.h" | |
12 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
13 #include "ui/base/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
14 #include "ui/gfx/canvas.h" | 15 #include "ui/gfx/canvas.h" |
15 #include "ui/gfx/image/image.h" | 16 #include "ui/gfx/image/image.h" |
16 #include "ui/gfx/screen.h" | 17 #include "ui/gfx/screen.h" |
17 #include "ui/views/controls/button/button.h" | 18 #include "ui/views/controls/button/button.h" |
18 #include "ui/views/controls/button/menu_button_listener.h" | 19 #include "ui/views/controls/button/menu_button_listener.h" |
19 #include "ui/views/events/event.h" | 20 #include "ui/views/events/event.h" |
20 #include "ui/views/widget/root_view.h" | 21 #include "ui/views/widget/root_view.h" |
21 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 case ui::VKEY_DOWN: { | 231 case ui::VKEY_DOWN: { |
231 // WARNING: we may have been deleted by the time Activate returns. | 232 // WARNING: we may have been deleted by the time Activate returns. |
232 return Activate(); | 233 return Activate(); |
233 } | 234 } |
234 default: | 235 default: |
235 break; | 236 break; |
236 } | 237 } |
237 return false; | 238 return false; |
238 } | 239 } |
239 | 240 |
241 ui::GestureStatus MenuButton::OnGestureEvent(const GestureEvent& event) { | |
sadrul
2012/06/11 16:00:37
This should be before OnKeyPressed (order in cc fi
flackr
2012/06/11 19:34:45
Done.
| |
242 if (state() != BS_DISABLED && event.type() == ui::ET_GESTURE_TAP) { | |
243 if (Activate()) | |
244 return ui::GESTURE_STATUS_CONSUMED; | |
245 } | |
246 return TextButton::OnGestureEvent(event); | |
247 } | |
248 | |
240 bool MenuButton::OnKeyReleased(const KeyEvent& event) { | 249 bool MenuButton::OnKeyReleased(const KeyEvent& event) { |
241 // Override CustomButton's implementation, which presses the button when | 250 // Override CustomButton's implementation, which presses the button when |
242 // you press space and clicks it when you release space. For a MenuButton | 251 // you press space and clicks it when you release space. For a MenuButton |
243 // we always activate the menu on key press. | 252 // we always activate the menu on key press. |
244 return false; | 253 return false; |
245 } | 254 } |
246 | 255 |
247 void MenuButton::GetAccessibleState(ui::AccessibleViewState* state) { | 256 void MenuButton::GetAccessibleState(ui::AccessibleViewState* state) { |
248 CustomButton::GetAccessibleState(state); | 257 CustomButton::GetAccessibleState(state); |
249 state->role = ui::AccessibilityTypes::ROLE_BUTTONMENU; | 258 state->role = ui::AccessibilityTypes::ROLE_BUTTONMENU; |
250 state->default_action = l10n_util::GetStringUTF16(IDS_APP_ACCACTION_PRESS); | 259 state->default_action = l10n_util::GetStringUTF16(IDS_APP_ACCACTION_PRESS); |
251 state->state = ui::AccessibilityTypes::STATE_HASPOPUP; | 260 state->state = ui::AccessibilityTypes::STATE_HASPOPUP; |
252 } | 261 } |
253 | 262 |
254 int MenuButton::GetMaximumScreenXCoordinate() { | 263 int MenuButton::GetMaximumScreenXCoordinate() { |
255 if (!GetWidget()) { | 264 if (!GetWidget()) { |
256 NOTREACHED(); | 265 NOTREACHED(); |
257 return 0; | 266 return 0; |
258 } | 267 } |
259 | 268 |
260 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen(); | 269 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen(); |
261 return monitor_bounds.right() - 1; | 270 return monitor_bounds.right() - 1; |
262 } | 271 } |
263 | 272 |
264 } // namespace views | 273 } // namespace views |
OLD | NEW |