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

Side by Side Diff: views/controls/link.cc

Issue 6685069: Disambiguate OnMouseCaptureLost from OnMouseReleased, etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments, fix tests, cleanup, etc. Created 9 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « views/controls/link.h ('k') | views/controls/menu/menu_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/link.h" 5 #include "views/controls/link.h"
6 6
7 #if defined(OS_LINUX) 7 #if defined(OS_LINUX)
8 #include <gdk/gdk.h> 8 #include <gdk/gdk.h>
9 #endif 9 #endif
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 } 90 }
91 91
92 void Link::SetController(LinkController* controller) { 92 void Link::SetController(LinkController* controller) {
93 controller_ = controller; 93 controller_ = controller;
94 } 94 }
95 95
96 const LinkController* Link::GetController() { 96 const LinkController* Link::GetController() {
97 return controller_; 97 return controller_;
98 } 98 }
99 99
100 bool Link::OnMousePressed(const MouseEvent& e) { 100 bool Link::OnMousePressed(const MouseEvent& event) {
101 if (!enabled_ || (!e.IsLeftMouseButton() && !e.IsMiddleMouseButton())) 101 if (!enabled_ || (!event.IsLeftMouseButton() && !event.IsMiddleMouseButton()))
102 return false; 102 return false;
103 SetHighlighted(true); 103 SetHighlighted(true);
104 return true; 104 return true;
105 } 105 }
106 106
107 bool Link::OnMouseDragged(const MouseEvent& e) { 107 bool Link::OnMouseDragged(const MouseEvent& event) {
108 SetHighlighted(enabled_ && 108 SetHighlighted(enabled_ &&
109 (e.IsLeftMouseButton() || e.IsMiddleMouseButton()) && 109 (event.IsLeftMouseButton() || event.IsMiddleMouseButton()) &&
110 HitTest(e.location())); 110 HitTest(event.location()));
111 return true; 111 return true;
112 } 112 }
113 113
114 void Link::OnMouseReleased(const MouseEvent& e, bool canceled) { 114 void Link::OnMouseReleased(const MouseEvent& event) {
115 // Change the highlight first just in case this instance is deleted 115 // Change the highlight first just in case this instance is deleted
116 // while calling the controller 116 // while calling the controller
117 SetHighlighted(false); 117 OnMouseCaptureLost();
118 if (enabled_ && !canceled && 118 if (enabled_ && (event.IsLeftMouseButton() || event.IsMiddleMouseButton()) &&
119 (e.IsLeftMouseButton() || e.IsMiddleMouseButton()) && 119 HitTest(event.location())) {
120 HitTest(e.location())) {
121 // Focus the link on click. 120 // Focus the link on click.
122 RequestFocus(); 121 RequestFocus();
123 122
124 if (controller_) 123 if (controller_)
125 controller_->LinkActivated(this, e.flags()); 124 controller_->LinkActivated(this, event.flags());
126 } 125 }
127 } 126 }
128 127
129 bool Link::OnKeyPressed(const KeyEvent& e) { 128 void Link::OnMouseCaptureLost() {
130 bool activate = ((e.key_code() == ui::VKEY_SPACE) || 129 SetHighlighted(false);
131 (e.key_code() == ui::VKEY_RETURN)); 130 }
131
132 bool Link::OnKeyPressed(const KeyEvent& event) {
133 bool activate = ((event.key_code() == ui::VKEY_SPACE) ||
134 (event.key_code() == ui::VKEY_RETURN));
132 if (!activate) 135 if (!activate)
133 return false; 136 return false;
134 137
135 SetHighlighted(false); 138 SetHighlighted(false);
136 139
137 // Focus the link on key pressed. 140 // Focus the link on key pressed.
138 RequestFocus(); 141 RequestFocus();
139 142
140 if (controller_) 143 if (controller_)
141 controller_->LinkActivated(this, e.flags()); 144 controller_->LinkActivated(this, event.flags());
142 145
143 return true; 146 return true;
144 } 147 }
145 148
146 bool Link::SkipDefaultKeyEventProcessing(const KeyEvent& e) { 149 bool Link::SkipDefaultKeyEventProcessing(const KeyEvent& event) {
147 // Make sure we don't process space or enter as accelerators. 150 // Make sure we don't process space or enter as accelerators.
148 return (e.key_code() == ui::VKEY_SPACE) || 151 return (event.key_code() == ui::VKEY_SPACE) ||
149 (e.key_code() == ui::VKEY_RETURN); 152 (event.key_code() == ui::VKEY_RETURN);
150 } 153 }
151 154
152 void Link::GetAccessibleState(ui::AccessibleViewState* state) { 155 void Link::GetAccessibleState(ui::AccessibleViewState* state) {
153 Label::GetAccessibleState(state); 156 Label::GetAccessibleState(state);
154 state->role = ui::AccessibilityTypes::ROLE_LINK; 157 state->role = ui::AccessibilityTypes::ROLE_LINK;
155 } 158 }
156 159
157 void Link::SetFont(const gfx::Font& font) { 160 void Link::SetFont(const gfx::Font& font) {
158 Label::SetFont(font); 161 Label::SetFont(font);
159 ValidateStyle(); 162 ValidateStyle();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 } else { 225 } else {
223 if (font().GetStyle() & gfx::Font::UNDERLINED) { 226 if (font().GetStyle() & gfx::Font::UNDERLINED) {
224 Label::SetFont( 227 Label::SetFont(
225 font().DeriveFont(0, font().GetStyle() & ~gfx::Font::UNDERLINED)); 228 font().DeriveFont(0, font().GetStyle() & ~gfx::Font::UNDERLINED));
226 } 229 }
227 Label::SetColor(disabled_color_); 230 Label::SetColor(disabled_color_);
228 } 231 }
229 } 232 }
230 233
231 } // namespace views 234 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/link.h ('k') | views/controls/menu/menu_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698