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

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

Issue 547303003: Keep reference view pressed while extension actions have a popup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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/custom_button.h" 5 #include "ui/views/controls/button/custom_button.h"
6 6
7 #include "ui/accessibility/ax_view_state.h" 7 #include "ui/accessibility/ax_view_state.h"
8 #include "ui/events/event.h" 8 #include "ui/events/event.h"
9 #include "ui/events/keycodes/keyboard_codes.h" 9 #include "ui/events/keycodes/keyboard_codes.h"
10 #include "ui/gfx/animation/throb_animation.h" 10 #include "ui/gfx/animation/throb_animation.h"
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 } 160 }
161 } 161 }
162 162
163 void CustomButton::OnMouseCaptureLost() { 163 void CustomButton::OnMouseCaptureLost() {
164 // Starting a drag results in a MouseCaptureLost, we need to ignore it. 164 // Starting a drag results in a MouseCaptureLost, we need to ignore it.
165 if (state_ != STATE_DISABLED && !InDrag()) 165 if (state_ != STATE_DISABLED && !InDrag())
166 SetState(STATE_NORMAL); 166 SetState(STATE_NORMAL);
167 } 167 }
168 168
169 void CustomButton::OnMouseEntered(const ui::MouseEvent& event) { 169 void CustomButton::OnMouseEntered(const ui::MouseEvent& event) {
170 if (state_ != STATE_DISABLED) 170 if (state_ != STATE_DISABLED && ShouldRespondToMouseMovement())
171 SetState(STATE_HOVERED); 171 SetState(STATE_HOVERED);
172 } 172 }
173 173
174 void CustomButton::OnMouseExited(const ui::MouseEvent& event) { 174 void CustomButton::OnMouseExited(const ui::MouseEvent& event) {
175 // Starting a drag results in a MouseExited, we need to ignore it. 175 // Starting a drag results in a MouseExited, we need to ignore it.
176 if (state_ != STATE_DISABLED && !InDrag()) 176 if (state_ != STATE_DISABLED && !InDrag() && ShouldRespondToMouseMovement())
177 SetState(STATE_NORMAL); 177 SetState(STATE_NORMAL);
178 } 178 }
179 179
180 void CustomButton::OnMouseMoved(const ui::MouseEvent& event) { 180 void CustomButton::OnMouseMoved(const ui::MouseEvent& event) {
181 if (state_ != STATE_DISABLED) 181 if (state_ != STATE_DISABLED && ShouldRespondToMouseMovement())
182 SetState(HitTestPoint(event.location()) ? STATE_HOVERED : STATE_NORMAL); 182 SetState(HitTestPoint(event.location()) ? STATE_HOVERED : STATE_NORMAL);
183 } 183 }
184 184
185 bool CustomButton::OnKeyPressed(const ui::KeyEvent& event) { 185 bool CustomButton::OnKeyPressed(const ui::KeyEvent& event) {
186 if (state_ == STATE_DISABLED) 186 if (state_ == STATE_DISABLED)
187 return false; 187 return false;
188 188
189 // Space sets button state to pushed. Enter clicks the button. This matches 189 // Space sets button state to pushed. Enter clicks the button. This matches
190 // the Windows native behavior of buttons, where Space clicks the button on 190 // the Windows native behavior of buttons, where Space clicks the button on
191 // KeyRelease and Enter clicks the button on KeyPressed. 191 // KeyRelease and Enter clicks the button on KeyPressed.
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 : Button(listener), 321 : Button(listener),
322 state_(STATE_NORMAL), 322 state_(STATE_NORMAL),
323 animate_on_state_change_(true), 323 animate_on_state_change_(true),
324 is_throbbing_(false), 324 is_throbbing_(false),
325 triggerable_event_flags_(ui::EF_LEFT_MOUSE_BUTTON), 325 triggerable_event_flags_(ui::EF_LEFT_MOUSE_BUTTON),
326 request_focus_on_press_(true) { 326 request_focus_on_press_(true) {
327 hover_animation_.reset(new gfx::ThrobAnimation(this)); 327 hover_animation_.reset(new gfx::ThrobAnimation(this));
328 hover_animation_->SetSlideDuration(kHoverFadeDurationMs); 328 hover_animation_->SetSlideDuration(kHoverFadeDurationMs);
329 } 329 }
330 330
331 bool CustomButton::ShouldRespondToMouseMovement() {
332 return true;
333 }
334
331 void CustomButton::StateChanged() { 335 void CustomButton::StateChanged() {
332 } 336 }
333 337
334 bool CustomButton::IsTriggerableEvent(const ui::Event& event) { 338 bool CustomButton::IsTriggerableEvent(const ui::Event& event) {
335 return event.type() == ui::ET_GESTURE_TAP_DOWN || 339 return event.type() == ui::ET_GESTURE_TAP_DOWN ||
336 event.type() == ui::ET_GESTURE_TAP || 340 event.type() == ui::ET_GESTURE_TAP ||
337 (event.IsMouseEvent() && 341 (event.IsMouseEvent() &&
338 (triggerable_event_flags_ & event.flags()) != 0); 342 (triggerable_event_flags_ & event.flags()) != 0);
339 } 343 }
340 344
341 bool CustomButton::ShouldEnterPushedState(const ui::Event& event) { 345 bool CustomButton::ShouldEnterPushedState(const ui::Event& event) {
342 return IsTriggerableEvent(event); 346 return IsTriggerableEvent(event);
343 } 347 }
344 348
345 //////////////////////////////////////////////////////////////////////////////// 349 ////////////////////////////////////////////////////////////////////////////////
346 // CustomButton, View overrides (protected): 350 // CustomButton, View overrides (protected):
347 351
348 void CustomButton::ViewHierarchyChanged( 352 void CustomButton::ViewHierarchyChanged(
349 const ViewHierarchyChangedDetails& details) { 353 const ViewHierarchyChangedDetails& details) {
350 if (!details.is_add && state_ != STATE_DISABLED) 354 if (!details.is_add && state_ != STATE_DISABLED)
351 SetState(STATE_NORMAL); 355 SetState(STATE_NORMAL);
352 } 356 }
353 357
354 void CustomButton::OnBlur() { 358 void CustomButton::OnBlur() {
355 if (IsHotTracked()) 359 if (IsHotTracked())
356 SetState(STATE_NORMAL); 360 SetState(STATE_NORMAL);
357 } 361 }
358 362
359 } // namespace views 363 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698