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

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

Issue 1411833006: Refactoring to make adding ink drop animations easier (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactor ink drop animations (moved ACTION_PENDING handling to toolbar_action_view for now) Created 5 years, 1 month 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"
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/base/ui_base_switches_util.h"
13 #include "ui/events/event.h" 13 #include "ui/events/event.h"
14 #include "ui/events/event_constants.h" 14 #include "ui/events/event_constants.h"
15 #include "ui/gfx/canvas.h" 15 #include "ui/gfx/canvas.h"
16 #include "ui/gfx/image/image.h" 16 #include "ui/gfx/image/image.h"
17 #include "ui/gfx/screen.h" 17 #include "ui/gfx/screen.h"
18 #include "ui/gfx/text_constants.h" 18 #include "ui/gfx/text_constants.h"
19 #include "ui/resources/grit/ui_resources.h" 19 #include "ui/resources/grit/ui_resources.h"
20 #include "ui/strings/grit/ui_strings.h" 20 #include "ui/strings/grit/ui_strings.h"
21 #include "ui/views/animation/ink_drop_delegate.h"
21 #include "ui/views/controls/button/button.h" 22 #include "ui/views/controls/button/button.h"
22 #include "ui/views/controls/button/menu_button_listener.h" 23 #include "ui/views/controls/button/menu_button_listener.h"
23 #include "ui/views/mouse_constants.h" 24 #include "ui/views/mouse_constants.h"
24 #include "ui/views/resources/grit/views_resources.h" 25 #include "ui/views/resources/grit/views_resources.h"
25 #include "ui/views/widget/root_view.h" 26 #include "ui/views/widget/root_view.h"
26 #include "ui/views/widget/widget.h" 27 #include "ui/views/widget/widget.h"
27 28
28 using base::TimeTicks; 29 using base::TimeTicks;
29 using base::TimeDelta; 30 using base::TimeDelta;
30 31
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // to NULL. 120 // to NULL.
120 static_cast<internal::RootView*>(GetWidget()->GetRootView())-> 121 static_cast<internal::RootView*>(GetWidget()->GetRootView())->
121 SetMouseHandler(NULL); 122 SetMouseHandler(NULL);
122 123
123 bool destroyed = false; 124 bool destroyed = false;
124 destroyed_flag_ = &destroyed; 125 destroyed_flag_ = &destroyed;
125 126
126 // We don't set our state here. It's handled in the MenuController code or 127 // We don't set our state here. It's handled in the MenuController code or
127 // by our click listener. 128 // by our click listener.
128 129
130 GetInkDropDelegate()->OnAction(InkDropState::QUICK_ACTION);
129 listener_->OnMenuButtonClicked(this, menu_position); 131 listener_->OnMenuButtonClicked(this, menu_position);
130 132
131 if (destroyed) { 133 if (destroyed) {
132 // The menu was deleted while showing. Don't attempt any processing. 134 // The menu was deleted while showing. Don't attempt any processing.
133 return false; 135 return false;
134 } 136 }
135 137
136 destroyed_flag_ = NULL; 138 destroyed_flag_ = NULL;
137 139
138 menu_closed_time_ = TimeTicks::Now(); 140 menu_closed_time_ = TimeTicks::Now();
139 141
140 // We must return false here so that the RootView does not get stuck 142 // We must return false here so that the RootView does not get stuck
141 // sending all mouse pressed events to us instead of the appropriate 143 // sending all mouse pressed events to us instead of the appropriate
142 // target. 144 // target.
143 return false; 145 return false;
144 } 146 }
145 return true; 147 return true;
146 } 148 }
147 149
148 void MenuButton::WillNotActivate() {
149 if (listener_) {
150 listener_->OnMenuButtonClickCanceled(this);
151 }
152 }
153
154 void MenuButton::OnPaint(gfx::Canvas* canvas) { 150 void MenuButton::OnPaint(gfx::Canvas* canvas) {
155 LabelButton::OnPaint(canvas); 151 LabelButton::OnPaint(canvas);
156 152
157 if (show_menu_marker_) 153 if (show_menu_marker_)
158 PaintMenuMarker(canvas); 154 PaintMenuMarker(canvas);
159 } 155 }
160 156
161 //////////////////////////////////////////////////////////////////////////////// 157 ////////////////////////////////////////////////////////////////////////////////
162 // 158 //
163 // MenuButton - Events 159 // MenuButton - Events
(...skipping 24 matching lines...) Expand all
188 return Activate(); 184 return Activate();
189 } 185 }
190 return true; 186 return true;
191 } 187 }
192 188
193 void MenuButton::OnMouseReleased(const ui::MouseEvent& event) { 189 void MenuButton::OnMouseReleased(const ui::MouseEvent& event) {
194 if (state() != STATE_DISABLED && ShouldEnterPushedState(event) && 190 if (state() != STATE_DISABLED && ShouldEnterPushedState(event) &&
195 HitTestPoint(event.location()) && !InDrag()) { 191 HitTestPoint(event.location()) && !InDrag()) {
196 Activate(); 192 Activate();
197 } else { 193 } else {
198 WillNotActivate(); 194 GetInkDropDelegate()->OnAction(InkDropState::HIDDEN);
199 LabelButton::OnMouseReleased(event); 195 LabelButton::OnMouseReleased(event);
200 } 196 }
201 } 197 }
202 198
203 void MenuButton::OnMouseEntered(const ui::MouseEvent& event) { 199 void MenuButton::OnMouseEntered(const ui::MouseEvent& event) {
204 if (pressed_lock_count_ == 0) // Ignore mouse movement if state is locked. 200 if (pressed_lock_count_ == 0) // Ignore mouse movement if state is locked.
205 LabelButton::OnMouseEntered(event); 201 LabelButton::OnMouseEntered(event);
206 } 202 }
207 203
208 void MenuButton::OnMouseExited(const ui::MouseEvent& event) { 204 void MenuButton::OnMouseExited(const ui::MouseEvent& event) {
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 if (!GetWidget()) { 358 if (!GetWidget()) {
363 NOTREACHED(); 359 NOTREACHED();
364 return 0; 360 return 0;
365 } 361 }
366 362
367 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen(); 363 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen();
368 return monitor_bounds.right() - 1; 364 return monitor_bounds.right() - 1;
369 } 365 }
370 366
371 } // namespace views 367 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698