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

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

Issue 2741004: Makes it so child views of menuitemview can be traversed with the (Closed)
Patch Set: Tweaks Created 10 years, 6 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "views/controls/button/custom_button.h" 5 #include "views/controls/button/custom_button.h"
6 6
7 #include "app/throb_animation.h" 7 #include "app/throb_animation.h"
8 #include "base/keyboard_codes.h" 8 #include "base/keyboard_codes.h"
9 9
10 namespace views { 10 namespace views {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 return (state_ != BS_DISABLED) && View::IsFocusable(); 67 return (state_ != BS_DISABLED) && View::IsFocusable();
68 } 68 }
69 69
70 //////////////////////////////////////////////////////////////////////////////// 70 ////////////////////////////////////////////////////////////////////////////////
71 // CustomButton, protected: 71 // CustomButton, protected:
72 72
73 CustomButton::CustomButton(ButtonListener* listener) 73 CustomButton::CustomButton(ButtonListener* listener)
74 : Button(listener), 74 : Button(listener),
75 state_(BS_NORMAL), 75 state_(BS_NORMAL),
76 animate_on_state_change_(true), 76 animate_on_state_change_(true),
77 triggerable_event_flags_(MouseEvent::EF_LEFT_BUTTON_DOWN) { 77 triggerable_event_flags_(MouseEvent::EF_LEFT_BUTTON_DOWN),
78 request_focus_on_press_(true) {
78 hover_animation_.reset(new ThrobAnimation(this)); 79 hover_animation_.reset(new ThrobAnimation(this));
79 hover_animation_->SetSlideDuration(kHoverFadeDurationMs); 80 hover_animation_->SetSlideDuration(kHoverFadeDurationMs);
80 } 81 }
81 82
82 bool CustomButton::IsTriggerableEvent(const MouseEvent& e) { 83 bool CustomButton::IsTriggerableEvent(const MouseEvent& e) {
83 return (triggerable_event_flags_ & e.GetFlags()) != 0; 84 return (triggerable_event_flags_ & e.GetFlags()) != 0;
84 } 85 }
85 86
86 //////////////////////////////////////////////////////////////////////////////// 87 ////////////////////////////////////////////////////////////////////////////////
87 // CustomButton, View overrides (protected): 88 // CustomButton, View overrides (protected):
88 89
89 bool CustomButton::AcceleratorPressed(const Accelerator& accelerator) { 90 bool CustomButton::AcceleratorPressed(const Accelerator& accelerator) {
90 if (enabled_) { 91 if (enabled_) {
91 SetState(BS_NORMAL); 92 SetState(BS_NORMAL);
92 KeyEvent key_event(Event::ET_KEY_RELEASED, accelerator.GetKeyCode(), 93 KeyEvent key_event(Event::ET_KEY_RELEASED, accelerator.GetKeyCode(),
93 accelerator.modifiers(), 0, 0); 94 accelerator.modifiers(), 0, 0);
94 NotifyClick(key_event); 95 NotifyClick(key_event);
95 return true; 96 return true;
96 } 97 }
97 return false; 98 return false;
98 } 99 }
99 100
100 bool CustomButton::OnMousePressed(const MouseEvent& e) { 101 bool CustomButton::OnMousePressed(const MouseEvent& e) {
101 if (state_ != BS_DISABLED) { 102 if (state_ != BS_DISABLED) {
102 if (ShouldEnterPushedState(e) && HitTest(e.location())) 103 if (ShouldEnterPushedState(e) && HitTest(e.location()))
103 SetState(BS_PUSHED); 104 SetState(BS_PUSHED);
104 RequestFocus(); 105 if (request_focus_on_press_)
106 RequestFocus();
105 } 107 }
106 return true; 108 return true;
107 } 109 }
108 110
109 bool CustomButton::OnMouseDragged(const MouseEvent& e) { 111 bool CustomButton::OnMouseDragged(const MouseEvent& e) {
110 if (state_ != BS_DISABLED) { 112 if (state_ != BS_DISABLED) {
111 if (!HitTest(e.location())) 113 if (!HitTest(e.location()))
112 SetState(BS_NORMAL); 114 SetState(BS_NORMAL);
113 else if (ShouldEnterPushedState(e)) 115 else if (ShouldEnterPushedState(e))
114 SetState(BS_PUSHED); 116 SetState(BS_PUSHED);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 249
248 bool CustomButton::IsHighlighted() const { 250 bool CustomButton::IsHighlighted() const {
249 return state_ == BS_HOT; 251 return state_ == BS_HOT;
250 } 252 }
251 253
252 bool CustomButton::IsPushed() const { 254 bool CustomButton::IsPushed() const {
253 return state_ == BS_PUSHED; 255 return state_ == BS_PUSHED;
254 } 256 }
255 257
256 } // namespace views 258 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698