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

Side by Side Diff: ui/views/controls/button/menu_button.cc

Issue 873513002: [Views] Make MenuButton track its desired state while pressed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 // 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"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 MenuButtonListener* menu_button_listener, 65 MenuButtonListener* menu_button_listener,
66 bool show_menu_marker) 66 bool show_menu_marker)
67 : LabelButton(listener, text), 67 : LabelButton(listener, text),
68 menu_offset_(kDefaultMenuOffsetX, kDefaultMenuOffsetY), 68 menu_offset_(kDefaultMenuOffsetX, kDefaultMenuOffsetY),
69 listener_(menu_button_listener), 69 listener_(menu_button_listener),
70 show_menu_marker_(show_menu_marker), 70 show_menu_marker_(show_menu_marker),
71 menu_marker_(ui::ResourceBundle::GetSharedInstance().GetImageNamed( 71 menu_marker_(ui::ResourceBundle::GetSharedInstance().GetImageNamed(
72 IDR_MENU_DROPARROW).ToImageSkia()), 72 IDR_MENU_DROPARROW).ToImageSkia()),
73 destroyed_flag_(NULL), 73 destroyed_flag_(NULL),
74 pressed_lock_count_(0), 74 pressed_lock_count_(0),
75 should_disable_after_press_(false),
75 weak_factory_(this) { 76 weak_factory_(this) {
76 SetHorizontalAlignment(gfx::ALIGN_LEFT); 77 SetHorizontalAlignment(gfx::ALIGN_LEFT);
77 } 78 }
78 79
79 MenuButton::~MenuButton() { 80 MenuButton::~MenuButton() {
80 if (destroyed_flag_) 81 if (destroyed_flag_)
81 *destroyed_flag_ = true; 82 *destroyed_flag_ = true;
82 } 83 }
83 84
84 //////////////////////////////////////////////////////////////////////////////// 85 ////////////////////////////////////////////////////////////////////////////////
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 ui::EventType active_on = 302 ui::EventType active_on =
302 GetDragOperations(mouseev.location()) == ui::DragDropTypes::DRAG_NONE 303 GetDragOperations(mouseev.location()) == ui::DragDropTypes::DRAG_NONE
303 ? ui::ET_MOUSE_PRESSED 304 ? ui::ET_MOUSE_PRESSED
304 : ui::ET_MOUSE_RELEASED; 305 : ui::ET_MOUSE_RELEASED;
305 return event.type() == active_on; 306 return event.type() == active_on;
306 } 307 }
307 308
308 return event.type() == ui::ET_GESTURE_TAP; 309 return event.type() == ui::ET_GESTURE_TAP;
309 } 310 }
310 311
312 void MenuButton::StateChanged() {
313 if (pressed_lock_count_ != 0) {
314 // The button's state was changed while it was supposed to be locked in a
315 // pressed state. This shouldn't happen, but conceivably could if a caller
316 // tries to switch from enabled to disabled or vice versa while the button
317 // is pressed.
318 if (state() == STATE_NORMAL)
319 should_disable_after_press_ = false;
320 else if (state() == STATE_DISABLED)
321 should_disable_after_press_ = true;
322 }
323 }
324
311 void MenuButton::IncrementPressedLocked() { 325 void MenuButton::IncrementPressedLocked() {
312 ++pressed_lock_count_; 326 ++pressed_lock_count_;
327 should_disable_after_press_ = state() == STATE_DISABLED;
313 SetState(STATE_PRESSED); 328 SetState(STATE_PRESSED);
314 } 329 }
315 330
316 void MenuButton::DecrementPressedLocked() { 331 void MenuButton::DecrementPressedLocked() {
317 --pressed_lock_count_; 332 --pressed_lock_count_;
318 DCHECK_GE(pressed_lock_count_, 0); 333 DCHECK_GE(pressed_lock_count_, 0);
319 334
320 // If this was the last lock, manually reset state to "normal". We set 335 // If this was the last lock, manually reset state to the desired state.
321 // "normal" and not "hot" because the likelihood is that the mouse is now 336 if (pressed_lock_count_ == 0) {
322 // somewhere else (user clicked elsewhere on screen to close the menu or 337 ButtonState desired_state = STATE_NORMAL;
323 // selected an item) and we will inevitably refresh the hot state in the event 338 if (should_disable_after_press_) {
324 // the mouse _is_ over the view. 339 desired_state = STATE_DISABLED;
325 if (pressed_lock_count_ == 0) 340 should_disable_after_press_ = false;
326 SetState(STATE_NORMAL); 341 } else if (IsMouseHovered()) {
342 desired_state = STATE_HOVERED;
343 }
344 SetState(desired_state);
345 }
327 } 346 }
328 347
329 int MenuButton::GetMaximumScreenXCoordinate() { 348 int MenuButton::GetMaximumScreenXCoordinate() {
330 if (!GetWidget()) { 349 if (!GetWidget()) {
331 NOTREACHED(); 350 NOTREACHED();
332 return 0; 351 return 0;
333 } 352 }
334 353
335 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen(); 354 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen();
336 return monitor_bounds.right() - 1; 355 return monitor_bounds.right() - 1;
337 } 356 }
338 357
339 } // namespace views 358 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/button/menu_button.h ('k') | ui/views/controls/button/menu_button_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698