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

Side by Side Diff: ui/base/test/event_generator_base.cc

Issue 322893005: MacViews: Add WidgetEventGenerator to abstract platform-specific event generation for tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase at r282511 Created 6 years, 5 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
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/base/test/event_generator_base.h"
6
7 namespace ui {
8 namespace test {
9
10 namespace {
11
12 const int kAllButtonMask = EF_LEFT_MOUSE_BUTTON | EF_RIGHT_MOUSE_BUTTON;
13
14 } // namespace
15
16 EventGeneratorBase::EventGeneratorBase(const gfx::Point& initial_location)
17 : current_location_(initial_location),
18 flags_(0),
19 grab_(false) {
20 }
21
22 EventGeneratorBase::~EventGeneratorBase() {
23 }
24
25 void EventGeneratorBase::PressLeftButton() {
26 PressButton(EF_LEFT_MOUSE_BUTTON);
27 }
28
29 void EventGeneratorBase::ReleaseLeftButton() {
30 ReleaseButton(EF_LEFT_MOUSE_BUTTON);
31 }
32
33 void EventGeneratorBase::ClickLeftButton() {
34 PressLeftButton();
35 ReleaseLeftButton();
36 }
37
38 void EventGeneratorBase::DoubleClickLeftButton() {
39 flags_ |= EF_IS_DOUBLE_CLICK;
40 PressLeftButton();
41 flags_ ^= EF_IS_DOUBLE_CLICK;
42 ReleaseLeftButton();
43 }
44
45 void EventGeneratorBase::PressRightButton() {
46 PressButton(EF_RIGHT_MOUSE_BUTTON);
47 }
48
49 void EventGeneratorBase::ReleaseRightButton() {
50 ReleaseButton(EF_RIGHT_MOUSE_BUTTON);
51 }
52
53 void EventGeneratorBase::DragMouseTo(const gfx::Point& point) {
54 PressLeftButton();
55 MoveMouseTo(point);
56 ReleaseLeftButton();
57 }
58
59 void EventGeneratorBase::PressButton(int flag) {
60 if (!(flags_ & flag)) {
61 flags_ |= flag;
62 grab_ = flags_ & kAllButtonMask;
63 gfx::Point location = GetLocationInCurrentRoot();
64 DispatchMouseEvent(ET_MOUSE_PRESSED, location, flags_, flag);
65 }
66 }
67
68 void EventGeneratorBase::ReleaseButton(int flag) {
69 if (flags_ & flag) {
70 gfx::Point location = GetLocationInCurrentRoot();
71 DispatchMouseEvent(ET_MOUSE_RELEASED, location, flags_, flag);
72 flags_ ^= flag;
73 }
74 grab_ = flags_ & kAllButtonMask;
75 }
76
77 } // namespace test
78 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698