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/event.h" | 12 #include "ui/base/event.h" |
13 #include "ui/base/events.h" | 13 #include "ui/base/events.h" |
14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
15 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
16 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
17 #include "ui/gfx/image/image.h" | 17 #include "ui/gfx/image/image.h" |
18 #include "ui/gfx/screen.h" | 18 #include "ui/gfx/screen.h" |
19 #include "ui/views/controls/button/button.h" | 19 #include "ui/views/controls/button/button.h" |
20 #include "ui/views/controls/button/menu_button_listener.h" | 20 #include "ui/views/controls/button/menu_button_listener.h" |
21 #include "ui/views/events/event.h" | |
22 #include "ui/views/widget/root_view.h" | 21 #include "ui/views/widget/root_view.h" |
23 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
24 | 23 |
25 using base::Time; | 24 using base::Time; |
26 using base::TimeDelta; | 25 using base::TimeDelta; |
27 | 26 |
28 namespace views { | 27 namespace views { |
29 | 28 |
30 // The amount of time, in milliseconds, we wait before allowing another mouse | 29 // The amount of time, in milliseconds, we wait before allowing another mouse |
31 // pressed event to show the menu. | 30 // pressed event to show the menu. |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 // we display the menu. If we don't override this method then | 212 // we display the menu. If we don't override this method then |
214 // BaseButton::OnMouseExited will get the event and will set the button's state | 213 // BaseButton::OnMouseExited will get the event and will set the button's state |
215 // to BS_NORMAL instead of keeping the state BM_PUSHED. This, in turn, will | 214 // to BS_NORMAL instead of keeping the state BM_PUSHED. This, in turn, will |
216 // cause the button to appear depressed while the menu is displayed. | 215 // cause the button to appear depressed while the menu is displayed. |
217 void MenuButton::OnMouseExited(const ui::MouseEvent& event) { | 216 void MenuButton::OnMouseExited(const ui::MouseEvent& event) { |
218 if ((state_ != BS_DISABLED) && (!menu_visible_) && (!InDrag())) { | 217 if ((state_ != BS_DISABLED) && (!menu_visible_) && (!InDrag())) { |
219 SetState(BS_NORMAL); | 218 SetState(BS_NORMAL); |
220 } | 219 } |
221 } | 220 } |
222 | 221 |
223 ui::GestureStatus MenuButton::OnGestureEvent(const GestureEvent& event) { | 222 ui::GestureStatus MenuButton::OnGestureEvent(const ui::GestureEvent& event) { |
224 if (state() != BS_DISABLED && event.type() == ui::ET_GESTURE_TAP) { | 223 if (state() != BS_DISABLED && event.type() == ui::ET_GESTURE_TAP) { |
225 if (Activate()) | 224 if (Activate()) |
226 return ui::GESTURE_STATUS_CONSUMED; | 225 return ui::GESTURE_STATUS_CONSUMED; |
227 return ui::GESTURE_STATUS_UNKNOWN; | 226 return ui::GESTURE_STATUS_UNKNOWN; |
228 } | 227 } |
229 return TextButton::OnGestureEvent(event); | 228 return TextButton::OnGestureEvent(event); |
230 } | 229 } |
231 | 230 |
232 bool MenuButton::OnKeyPressed(const ui::KeyEvent& event) { | 231 bool MenuButton::OnKeyPressed(const ui::KeyEvent& event) { |
233 switch (event.key_code()) { | 232 switch (event.key_code()) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 if (!GetWidget()) { | 264 if (!GetWidget()) { |
266 NOTREACHED(); | 265 NOTREACHED(); |
267 return 0; | 266 return 0; |
268 } | 267 } |
269 | 268 |
270 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen(); | 269 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen(); |
271 return monitor_bounds.right() - 1; | 270 return monitor_bounds.right() - 1; |
272 } | 271 } |
273 | 272 |
274 } // namespace views | 273 } // namespace views |
OLD | NEW |