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 "ui/accessibility/ax_view_state.h" | 8 #include "ui/accessibility/ax_view_state.h" |
9 #include "ui/base/dragdrop/drag_drop_types.h" | 9 #include "ui/base/dragdrop/drag_drop_types.h" |
10 #include "ui/base/l10n/l10n_util.h" | 10 #include "ui/base/l10n/l10n_util.h" |
11 #include "ui/base/resource/resource_bundle.h" | 11 #include "ui/base/resource/resource_bundle.h" |
12 #include "ui/base/ui_base_switches_util.h" | |
12 #include "ui/events/event.h" | 13 #include "ui/events/event.h" |
13 #include "ui/events/event_constants.h" | 14 #include "ui/events/event_constants.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/gfx/text_constants.h" | 18 #include "ui/gfx/text_constants.h" |
18 #include "ui/resources/grit/ui_resources.h" | 19 #include "ui/resources/grit/ui_resources.h" |
19 #include "ui/strings/grit/ui_strings.h" | 20 #include "ui/strings/grit/ui_strings.h" |
20 #include "ui/views/controls/button/button.h" | 21 #include "ui/views/controls/button/button.h" |
21 #include "ui/views/controls/button/menu_button_listener.h" | 22 #include "ui/views/controls/button/menu_button_listener.h" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 if (pressed_lock_count_ == 0) // Ignore mouse movement if state is locked. | 199 if (pressed_lock_count_ == 0) // Ignore mouse movement if state is locked. |
199 LabelButton::OnMouseExited(event); | 200 LabelButton::OnMouseExited(event); |
200 } | 201 } |
201 | 202 |
202 void MenuButton::OnMouseMoved(const ui::MouseEvent& event) { | 203 void MenuButton::OnMouseMoved(const ui::MouseEvent& event) { |
203 if (pressed_lock_count_ == 0) // Ignore mouse movement if state is locked. | 204 if (pressed_lock_count_ == 0) // Ignore mouse movement if state is locked. |
204 LabelButton::OnMouseMoved(event); | 205 LabelButton::OnMouseMoved(event); |
205 } | 206 } |
206 | 207 |
207 void MenuButton::OnGestureEvent(ui::GestureEvent* event) { | 208 void MenuButton::OnGestureEvent(ui::GestureEvent* event) { |
208 if (state() != STATE_DISABLED && ShouldEnterPushedState(*event) && | 209 if (state() != STATE_DISABLED) { |
209 !Activate()) { | 210 if (switches::IsTouchFeedbackEnabled()) { |
flackr
2014/10/27 17:51:27
Should this be done after line 220 so that the men
jonross
2014/10/27 18:51:39
Good call, that way any classes extending get the
| |
210 // When |Activate()| returns |false|, it means that a menu is shown and | 211 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { |
211 // has handled the gesture event. So, there is no need to further process | 212 event->SetHandled(); |
flackr
2014/10/27 17:51:27
This doesn't prevent context menu generation, does
jonross
2014/10/27 18:51:39
No it does not, it just keeps this view as the eve
| |
212 // the gesture event here. | 213 SetState(Button::STATE_HOVERED); |
213 return; | 214 } else if (state() == Button::STATE_HOVERED && |
215 (event->type() == ui::ET_GESTURE_TAP_CANCEL || | |
216 event->type() == ui::ET_GESTURE_END)) { | |
217 SetState(Button::STATE_NORMAL); | |
218 } | |
219 } | |
220 if (ShouldEnterPushedState(*event) && !Activate()) { | |
221 // When |Activate()| returns |false|, it means that a menu is shown and | |
222 // has handled the gesture event. So, there is no need to further process | |
223 // the gesture event here. | |
224 return; | |
225 } | |
214 } | 226 } |
215 LabelButton::OnGestureEvent(event); | 227 LabelButton::OnGestureEvent(event); |
216 } | 228 } |
217 | 229 |
218 bool MenuButton::OnKeyPressed(const ui::KeyEvent& event) { | 230 bool MenuButton::OnKeyPressed(const ui::KeyEvent& event) { |
219 switch (event.key_code()) { | 231 switch (event.key_code()) { |
220 case ui::VKEY_SPACE: | 232 case ui::VKEY_SPACE: |
221 // Alt-space on windows should show the window menu. | 233 // Alt-space on windows should show the window menu. |
222 if (event.IsAltDown()) | 234 if (event.IsAltDown()) |
223 break; | 235 break; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
318 if (!GetWidget()) { | 330 if (!GetWidget()) { |
319 NOTREACHED(); | 331 NOTREACHED(); |
320 return 0; | 332 return 0; |
321 } | 333 } |
322 | 334 |
323 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen(); | 335 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen(); |
324 return monitor_bounds.right() - 1; | 336 return monitor_bounds.right() - 1; |
325 } | 337 } |
326 | 338 |
327 } // namespace views | 339 } // namespace views |
OLD | NEW |