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

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: Attempt to refactor ink drop animations (wired up chained EventHandler) 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 InkDropDelegate* ink_drop_delegate = GetInkDropDelegate();
131 if (ink_drop_delegate)
132 ink_drop_delegate->OnActionQuick();
129 listener_->OnMenuButtonClicked(this, menu_position); 133 listener_->OnMenuButtonClicked(this, menu_position);
130 134
131 if (destroyed) { 135 if (destroyed) {
132 // The menu was deleted while showing. Don't attempt any processing. 136 // The menu was deleted while showing. Don't attempt any processing.
133 return false; 137 return false;
134 } 138 }
135 139
136 destroyed_flag_ = NULL; 140 destroyed_flag_ = NULL;
137 141
138 menu_closed_time_ = TimeTicks::Now(); 142 menu_closed_time_ = TimeTicks::Now();
139 143
140 // We must return false here so that the RootView does not get stuck 144 // 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 145 // sending all mouse pressed events to us instead of the appropriate
142 // target. 146 // target.
143 return false; 147 return false;
144 } 148 }
145 return true; 149 return true;
146 } 150 }
147 151
148 void MenuButton::WillNotActivate() { 152 void MenuButton::WillNotActivate() {
149 if (listener_) { 153 if (listener_) {
150 listener_->OnMenuButtonClickCanceled(this); 154 listener_->OnMenuButtonClickCanceled(this);
155 InkDropDelegate* ink_drop_delegate = GetInkDropDelegate();
156 if (ink_drop_delegate)
157 ink_drop_delegate->OnActionComplete();
151 } 158 }
152 } 159 }
153 160
154 void MenuButton::OnPaint(gfx::Canvas* canvas) { 161 void MenuButton::OnPaint(gfx::Canvas* canvas) {
155 LabelButton::OnPaint(canvas); 162 LabelButton::OnPaint(canvas);
156 163
157 if (show_menu_marker_) 164 if (show_menu_marker_)
158 PaintMenuMarker(canvas); 165 PaintMenuMarker(canvas);
159 } 166 }
160 167
(...skipping 11 matching lines...) Expand all
172 0); 179 0);
173 } 180 }
174 return prefsize; 181 return prefsize;
175 } 182 }
176 183
177 const char* MenuButton::GetClassName() const { 184 const char* MenuButton::GetClassName() const {
178 return kViewClassName; 185 return kViewClassName;
179 } 186 }
180 187
181 bool MenuButton::OnMousePressed(const ui::MouseEvent& event) { 188 bool MenuButton::OnMousePressed(const ui::MouseEvent& event) {
189 if (event.IsOnlyLeftMouseButton()) {
190 InkDropDelegate* ink_drop_delegate = GetInkDropDelegate();
191 if (ink_drop_delegate)
192 ink_drop_delegate->OnActionPending();
193 }
194
182 if (request_focus_on_press()) 195 if (request_focus_on_press())
183 RequestFocus(); 196 RequestFocus();
184 if (state() != STATE_DISABLED && ShouldEnterPushedState(event) && 197 if (state() != STATE_DISABLED && ShouldEnterPushedState(event) &&
185 HitTestPoint(event.location())) { 198 HitTestPoint(event.location())) {
186 TimeDelta delta = TimeTicks::Now() - menu_closed_time_; 199 TimeDelta delta = TimeTicks::Now() - menu_closed_time_;
187 if (delta.InMilliseconds() > kMinimumMsBetweenButtonClicks) 200 if (delta.InMilliseconds() > kMinimumMsBetweenButtonClicks) {
188 return Activate(); 201 return Activate();
202 }
189 } 203 }
190 return true; 204 return true;
191 } 205 }
192 206
193 void MenuButton::OnMouseReleased(const ui::MouseEvent& event) { 207 void MenuButton::OnMouseReleased(const ui::MouseEvent& event) {
194 if (state() != STATE_DISABLED && ShouldEnterPushedState(event) && 208 if (state() != STATE_DISABLED && ShouldEnterPushedState(event) &&
195 HitTestPoint(event.location()) && !InDrag()) { 209 HitTestPoint(event.location()) && !InDrag()) {
196 Activate(); 210 Activate();
197 } else { 211 } else {
198 WillNotActivate(); 212 WillNotActivate();
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 if (!GetWidget()) { 376 if (!GetWidget()) {
363 NOTREACHED(); 377 NOTREACHED();
364 return 0; 378 return 0;
365 } 379 }
366 380
367 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen(); 381 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen();
368 return monitor_bounds.right() - 1; 382 return monitor_bounds.right() - 1;
369 } 383 }
370 384
371 } // namespace views 385 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698