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

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

Issue 1260453006: ui: events: Add a class to hold common touch and stylus properties (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address build problems, add accessor and unit tests. Created 5 years, 4 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/event_utils.h" 9 #include "ui/events/event_utils.h"
10 #include "ui/events/keycodes/keyboard_codes.h" 10 #include "ui/events/keycodes/keyboard_codes.h"
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 return false; 191 return false;
192 192
193 // Space sets button state to pushed. Enter clicks the button. This matches 193 // Space sets button state to pushed. Enter clicks the button. This matches
194 // the Windows native behavior of buttons, where Space clicks the button on 194 // the Windows native behavior of buttons, where Space clicks the button on
195 // KeyRelease and Enter clicks the button on KeyPressed. 195 // KeyRelease and Enter clicks the button on KeyPressed.
196 if (event.key_code() == ui::VKEY_SPACE) { 196 if (event.key_code() == ui::VKEY_SPACE) {
197 SetState(STATE_PRESSED); 197 SetState(STATE_PRESSED);
198 } else if (event.key_code() == ui::VKEY_RETURN) { 198 } else if (event.key_code() == ui::VKEY_RETURN) {
199 SetState(STATE_NORMAL); 199 SetState(STATE_NORMAL);
200 // TODO(beng): remove once NotifyClick takes ui::Event. 200 // TODO(beng): remove once NotifyClick takes ui::Event.
201 ui::MouseEvent synthetic_event(ui::ET_MOUSE_RELEASED, gfx::Point(), 201 ui::MouseEvent synthetic_event(
202 gfx::Point(), ui::EventTimeForNow(), 202 ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(),
203 ui::EF_LEFT_MOUSE_BUTTON, 203 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
204 ui::EF_LEFT_MOUSE_BUTTON); 204 ui::EF_LEFT_MOUSE_BUTTON,
205 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
205 NotifyClick(synthetic_event); 206 NotifyClick(synthetic_event);
206 } else { 207 } else {
207 return false; 208 return false;
208 } 209 }
209 return true; 210 return true;
210 } 211 }
211 212
212 bool CustomButton::OnKeyReleased(const ui::KeyEvent& event) { 213 bool CustomButton::OnKeyReleased(const ui::KeyEvent& event) {
213 if ((state_ == STATE_DISABLED) || (event.key_code() != ui::VKEY_SPACE)) 214 if ((state_ == STATE_DISABLED) || (event.key_code() != ui::VKEY_SPACE))
214 return false; 215 return false;
215 216
216 SetState(STATE_NORMAL); 217 SetState(STATE_NORMAL);
217 // TODO(beng): remove once NotifyClick takes ui::Event. 218 // TODO(beng): remove once NotifyClick takes ui::Event.
218 ui::MouseEvent synthetic_event( 219 ui::MouseEvent synthetic_event(
219 ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(), 220 ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(),
220 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); 221 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON,
222 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
221 NotifyClick(synthetic_event); 223 NotifyClick(synthetic_event);
222 return true; 224 return true;
223 } 225 }
224 226
225 void CustomButton::OnGestureEvent(ui::GestureEvent* event) { 227 void CustomButton::OnGestureEvent(ui::GestureEvent* event) {
226 if (state_ == STATE_DISABLED) { 228 if (state_ == STATE_DISABLED) {
227 Button::OnGestureEvent(event); 229 Button::OnGestureEvent(event);
228 return; 230 return;
229 } 231 }
230 232
(...skipping 18 matching lines...) Expand all
249 } 251 }
250 if (!event->handled()) 252 if (!event->handled())
251 Button::OnGestureEvent(event); 253 Button::OnGestureEvent(event);
252 } 254 }
253 255
254 bool CustomButton::AcceleratorPressed(const ui::Accelerator& accelerator) { 256 bool CustomButton::AcceleratorPressed(const ui::Accelerator& accelerator) {
255 SetState(STATE_NORMAL); 257 SetState(STATE_NORMAL);
256 // TODO(beng): remove once NotifyClick takes ui::Event. 258 // TODO(beng): remove once NotifyClick takes ui::Event.
257 ui::MouseEvent synthetic_event( 259 ui::MouseEvent synthetic_event(
258 ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(), 260 ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(),
259 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); 261 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON,
262 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
260 NotifyClick(synthetic_event); 263 NotifyClick(synthetic_event);
261 return true; 264 return true;
262 } 265 }
263 266
264 void CustomButton::ShowContextMenu(const gfx::Point& p, 267 void CustomButton::ShowContextMenu(const gfx::Point& p,
265 ui::MenuSourceType source_type) { 268 ui::MenuSourceType source_type) {
266 if (!context_menu_controller()) 269 if (!context_menu_controller())
267 return; 270 return;
268 271
269 // We're about to show the context menu. Showing the context menu likely means 272 // We're about to show the context menu. Showing the context menu likely means
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 if (!details.is_add && state_ != STATE_DISABLED) 352 if (!details.is_add && state_ != STATE_DISABLED)
350 SetState(STATE_NORMAL); 353 SetState(STATE_NORMAL);
351 } 354 }
352 355
353 void CustomButton::OnBlur() { 356 void CustomButton::OnBlur() {
354 if (IsHotTracked()) 357 if (IsHotTracked())
355 SetState(STATE_NORMAL); 358 SetState(STATE_NORMAL);
356 } 359 }
357 360
358 } // namespace views 361 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698