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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ui/base/test/event_generator_base.cc
diff --git a/ui/base/test/event_generator_base.cc b/ui/base/test/event_generator_base.cc
new file mode 100644
index 0000000000000000000000000000000000000000..08612f33bbb0935dac73bdd70be9f02ef41dc91d
--- /dev/null
+++ b/ui/base/test/event_generator_base.cc
@@ -0,0 +1,78 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/base/test/event_generator_base.h"
+
+namespace ui {
+namespace test {
+
+namespace {
+
+const int kAllButtonMask = EF_LEFT_MOUSE_BUTTON | EF_RIGHT_MOUSE_BUTTON;
+
+} // namespace
+
+EventGeneratorBase::EventGeneratorBase(const gfx::Point& initial_location)
+ : current_location_(initial_location),
+ flags_(0),
+ grab_(false) {
+}
+
+EventGeneratorBase::~EventGeneratorBase() {
+}
+
+void EventGeneratorBase::PressLeftButton() {
+ PressButton(EF_LEFT_MOUSE_BUTTON);
+}
+
+void EventGeneratorBase::ReleaseLeftButton() {
+ ReleaseButton(EF_LEFT_MOUSE_BUTTON);
+}
+
+void EventGeneratorBase::ClickLeftButton() {
+ PressLeftButton();
+ ReleaseLeftButton();
+}
+
+void EventGeneratorBase::DoubleClickLeftButton() {
+ flags_ |= EF_IS_DOUBLE_CLICK;
+ PressLeftButton();
+ flags_ ^= EF_IS_DOUBLE_CLICK;
+ ReleaseLeftButton();
+}
+
+void EventGeneratorBase::PressRightButton() {
+ PressButton(EF_RIGHT_MOUSE_BUTTON);
+}
+
+void EventGeneratorBase::ReleaseRightButton() {
+ ReleaseButton(EF_RIGHT_MOUSE_BUTTON);
+}
+
+void EventGeneratorBase::DragMouseTo(const gfx::Point& point) {
+ PressLeftButton();
+ MoveMouseTo(point);
+ ReleaseLeftButton();
+}
+
+void EventGeneratorBase::PressButton(int flag) {
+ if (!(flags_ & flag)) {
+ flags_ |= flag;
+ grab_ = flags_ & kAllButtonMask;
+ gfx::Point location = GetLocationInCurrentRoot();
+ DispatchMouseEvent(ET_MOUSE_PRESSED, location, flags_, flag);
+ }
+}
+
+void EventGeneratorBase::ReleaseButton(int flag) {
+ if (flags_ & flag) {
+ gfx::Point location = GetLocationInCurrentRoot();
+ DispatchMouseEvent(ET_MOUSE_RELEASED, location, flags_, flag);
+ flags_ ^= flag;
+ }
+ grab_ = flags_ & kAllButtonMask;
+}
+
+} // namespace test
+} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698