| 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
|
|
|