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

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 (simplify MenuButton) 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();
bruthig 2015/11/19 16:49:53 Would it make things easier if GetInkDropDelegate(
varkha 2015/11/19 23:34:35 Done. May remove InkDropAnimationControllerStub la
131 if (ink_drop_delegate)
132 ink_drop_delegate->OnAction(InkDropState::QUICK_ACTION);
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() {
149 if (listener_) {
150 listener_->OnMenuButtonClickCanceled(this);
151 }
152 }
153
154 void MenuButton::OnPaint(gfx::Canvas* canvas) { 152 void MenuButton::OnPaint(gfx::Canvas* canvas) {
155 LabelButton::OnPaint(canvas); 153 LabelButton::OnPaint(canvas);
156 154
157 if (show_menu_marker_) 155 if (show_menu_marker_)
158 PaintMenuMarker(canvas); 156 PaintMenuMarker(canvas);
159 } 157 }
160 158
161 //////////////////////////////////////////////////////////////////////////////// 159 ////////////////////////////////////////////////////////////////////////////////
162 // 160 //
163 // MenuButton - Events 161 // MenuButton - Events
164 // 162 //
165 //////////////////////////////////////////////////////////////////////////////// 163 ////////////////////////////////////////////////////////////////////////////////
166 164
167 gfx::Size MenuButton::GetPreferredSize() const { 165 gfx::Size MenuButton::GetPreferredSize() const {
168 gfx::Size prefsize = LabelButton::GetPreferredSize(); 166 gfx::Size prefsize = LabelButton::GetPreferredSize();
169 if (show_menu_marker_) { 167 if (show_menu_marker_) {
170 prefsize.Enlarge(menu_marker_->width() + kMenuMarkerPaddingLeft + 168 prefsize.Enlarge(menu_marker_->width() + kMenuMarkerPaddingLeft +
171 kMenuMarkerPaddingRight, 169 kMenuMarkerPaddingRight,
172 0); 170 0);
173 } 171 }
174 return prefsize; 172 return prefsize;
175 } 173 }
176 174
177 const char* MenuButton::GetClassName() const { 175 const char* MenuButton::GetClassName() const {
178 return kViewClassName; 176 return kViewClassName;
179 } 177 }
180 178
181 bool MenuButton::OnMousePressed(const ui::MouseEvent& event) { 179 bool MenuButton::OnMousePressed(const ui::MouseEvent& event) {
180 if (event.IsOnlyLeftMouseButton()) {
181 InkDropDelegate* ink_drop_delegate = GetInkDropDelegate();
182 if (ink_drop_delegate)
183 ink_drop_delegate->OnAction(InkDropState::ACTION_PENDING);
bruthig 2015/11/19 16:49:53 I don't think a MenuButton can know for certain th
varkha 2015/11/19 23:34:35 Done.
184 }
185
182 if (request_focus_on_press()) 186 if (request_focus_on_press())
183 RequestFocus(); 187 RequestFocus();
184 if (state() != STATE_DISABLED && ShouldEnterPushedState(event) && 188 if (state() != STATE_DISABLED && ShouldEnterPushedState(event) &&
185 HitTestPoint(event.location())) { 189 HitTestPoint(event.location())) {
186 TimeDelta delta = TimeTicks::Now() - menu_closed_time_; 190 TimeDelta delta = TimeTicks::Now() - menu_closed_time_;
187 if (delta.InMilliseconds() > kMinimumMsBetweenButtonClicks) 191 if (delta.InMilliseconds() > kMinimumMsBetweenButtonClicks) {
188 return Activate(); 192 return Activate();
193 }
189 } 194 }
190 return true; 195 return true;
191 } 196 }
192 197
193 void MenuButton::OnMouseReleased(const ui::MouseEvent& event) { 198 void MenuButton::OnMouseReleased(const ui::MouseEvent& event) {
194 if (state() != STATE_DISABLED && ShouldEnterPushedState(event) && 199 if (state() != STATE_DISABLED && ShouldEnterPushedState(event) &&
195 HitTestPoint(event.location()) && !InDrag()) { 200 HitTestPoint(event.location()) && !InDrag()) {
196 Activate(); 201 Activate();
197 } else { 202 } else {
198 WillNotActivate(); 203 InkDropDelegate* ink_drop_delegate = GetInkDropDelegate();
204 if (ink_drop_delegate)
205 ink_drop_delegate->OnAction(InkDropState::HIDDEN);
bruthig 2015/11/19 16:49:53 Somewhat similar concerns here to the ones in OnMo
varkha 2015/11/19 23:34:35 Will need to rethink what happens in asynchronous
199 LabelButton::OnMouseReleased(event); 206 LabelButton::OnMouseReleased(event);
200 } 207 }
201 } 208 }
202 209
203 void MenuButton::OnMouseEntered(const ui::MouseEvent& event) { 210 void MenuButton::OnMouseEntered(const ui::MouseEvent& event) {
204 if (pressed_lock_count_ == 0) // Ignore mouse movement if state is locked. 211 if (pressed_lock_count_ == 0) // Ignore mouse movement if state is locked.
205 LabelButton::OnMouseEntered(event); 212 LabelButton::OnMouseEntered(event);
206 } 213 }
207 214
208 void MenuButton::OnMouseExited(const ui::MouseEvent& event) { 215 void MenuButton::OnMouseExited(const ui::MouseEvent& event) {
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 if (!GetWidget()) { 369 if (!GetWidget()) {
363 NOTREACHED(); 370 NOTREACHED();
364 return 0; 371 return 0;
365 } 372 }
366 373
367 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen(); 374 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen();
368 return monitor_bounds.right() - 1; 375 return monitor_bounds.right() - 1;
369 } 376 }
370 377
371 } // namespace views 378 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698