14e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
24e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
34e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// found in the LICENSE file.
44e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
54e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ash/autoclick/autoclick_controller.h"
64e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
74e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ash/shell.h"
84e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ash/wm/coordinate_conversion.h"
94e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "base/timer/timer.h"
104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ui/aura/env.h"
1123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)#include "ui/aura/window_tree_host.h"
124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ui/events/event.h"
134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ui/events/event_constants.h"
144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ui/events/event_handler.h"
1523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)#include "ui/events/event_processor.h"
164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ui/gfx/point.h"
171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ui/gfx/vector2d.h"
184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)namespace ash {
204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)namespace {
221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// The threshold of mouse movement measured in DIP that will
241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// initiate a new autoclick.
251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)const int kMovementThreshold = 20;
261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)bool IsModifierKey(ui::KeyboardCode key_code) {
281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  return key_code == ui::VKEY_SHIFT ||
291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      key_code == ui::VKEY_LSHIFT ||
301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      key_code == ui::VKEY_CONTROL ||
311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      key_code == ui::VKEY_LCONTROL ||
321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      key_code == ui::VKEY_RCONTROL ||
331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      key_code == ui::VKEY_MENU ||
341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      key_code == ui::VKEY_LMENU ||
351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      key_code == ui::VKEY_RMENU;
361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}  // namespace
391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
408bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// static.
418bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)const int AutoclickController::kDefaultAutoclickDelayMs = 400;
424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
434e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)class AutoclickControllerImpl : public AutoclickController,
444e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                                public ui::EventHandler {
454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) public:
464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  AutoclickControllerImpl();
474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  virtual ~AutoclickControllerImpl();
484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) private:
504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // AutoclickController overrides:
514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  virtual void SetEnabled(bool enabled) OVERRIDE;
524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  virtual bool IsEnabled() const OVERRIDE;
538bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual void SetAutoclickDelay(int delay_ms) OVERRIDE;
548bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual int GetAutoclickDelay() const OVERRIDE;
554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // ui::EventHandler overrides:
574e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE;
594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE;
601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE;
624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void InitClickTimer();
644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
654e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void DoAutoclick();
664e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
674e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  bool enabled_;
688bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  int delay_ms_;
694e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  int mouse_event_flags_;
704e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  scoped_ptr<base::Timer> autoclick_timer_;
711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // The position in screen coordinates used to determine
721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // the distance the mouse has moved.
731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  gfx::Point anchor_location_;
744e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
754e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(AutoclickControllerImpl);
764e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)};
774e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
784e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
794e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)AutoclickControllerImpl::AutoclickControllerImpl()
804e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    : enabled_(false),
818bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      delay_ms_(kDefaultAutoclickDelayMs),
821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      mouse_event_flags_(ui::EF_NONE),
831e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      anchor_location_(-kMovementThreshold, -kMovementThreshold) {
844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  InitClickTimer();
854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
864e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
874e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)AutoclickControllerImpl::~AutoclickControllerImpl() {
884e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
904e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)void AutoclickControllerImpl::SetEnabled(bool enabled) {
914e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  if (enabled_ == enabled)
924e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    return;
934e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  enabled_ = enabled;
944e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
954e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  if (enabled_) {
964e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    Shell::GetInstance()->AddPreTargetHandler(this);
974e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    autoclick_timer_->Stop();
984e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  } else {
994e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    Shell::GetInstance()->RemovePreTargetHandler(this);
1004e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  }
1014e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
1024e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1034e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)bool AutoclickControllerImpl::IsEnabled() const {
1044e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  return enabled_;
1054e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
1064e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1078bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)void AutoclickControllerImpl::SetAutoclickDelay(int delay_ms) {
1088bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  delay_ms_ = delay_ms;
1094e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  InitClickTimer();
1104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
1114e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1128bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)int AutoclickControllerImpl::GetAutoclickDelay() const {
1138bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  return delay_ms_;
1144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
1154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)void AutoclickControllerImpl::InitClickTimer() {
1174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  autoclick_timer_.reset(new base::Timer(
1184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      FROM_HERE,
1198bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      base::TimeDelta::FromMilliseconds(delay_ms_),
1204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      base::Bind(&AutoclickControllerImpl::DoAutoclick,
1214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                 base::Unretained(this)),
1224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      false));
1234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
1244e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)void AutoclickControllerImpl::OnMouseEvent(ui::MouseEvent* event) {
1265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (event->type() == ui::ET_MOUSE_MOVED &&
1275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      !(event->flags() & ui::EF_IS_SYNTHESIZED)) {
1284e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    mouse_event_flags_ = event->flags();
1291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    gfx::Point mouse_location = event->root_location();
1311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    ash::wm::ConvertPointToScreen(
1321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        wm::GetRootWindowAt(mouse_location),
1331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        &mouse_location);
1341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    // The distance between the mouse location and the anchor location
1361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    // must exceed a certain threshold to initiate a new autoclick countdown.
1371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    // This ensures that mouse jitter caused by poor motor control does not
1381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    // 1. initiate an unwanted autoclick from rest
1391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    // 2. prevent the autoclick from ever occuring when the mouse
1401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    //    arrives at the target.
1411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    gfx::Vector2d delta = mouse_location - anchor_location_;
1421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    if (delta.LengthSquared() >= kMovementThreshold * kMovementThreshold) {
1431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      anchor_location_ = event->root_location();
1441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      autoclick_timer_->Reset();
1451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    }
1464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  } else if (event->type() == ui::ET_MOUSE_PRESSED) {
1474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    autoclick_timer_->Stop();
1484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  } else if (event->type() == ui::ET_MOUSEWHEEL &&
1494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)             autoclick_timer_->IsRunning()) {
1504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    autoclick_timer_->Reset();
1514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  }
1524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
1534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1544e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)void AutoclickControllerImpl::OnKeyEvent(ui::KeyEvent* event) {
1554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  int modifier_mask =
1564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      ui::EF_SHIFT_DOWN |
1574e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      ui::EF_CONTROL_DOWN |
1584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      ui::EF_ALT_DOWN |
1594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      ui::EF_COMMAND_DOWN |
1604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      ui::EF_EXTENDED;
1614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  int new_modifiers = event->flags() & modifier_mask;
1624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  mouse_event_flags_ = (mouse_event_flags_ & ~modifier_mask) | new_modifiers;
1631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  if (!IsModifierKey(event->key_code()))
1651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    autoclick_timer_->Stop();
1664e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
1674e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1684e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)void AutoclickControllerImpl::OnTouchEvent(ui::TouchEvent* event) {
1694e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  autoclick_timer_->Stop();
1704e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
1714e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)void AutoclickControllerImpl::OnGestureEvent(ui::GestureEvent* event) {
1731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  autoclick_timer_->Stop();
1741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
1751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)void AutoclickControllerImpl::OnScrollEvent(ui::ScrollEvent* event) {
1771e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  autoclick_timer_->Stop();
1781e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
1791e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1804e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)void AutoclickControllerImpl::DoAutoclick() {
1814e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  gfx::Point screen_location =
1824e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      aura::Env::GetInstance()->last_mouse_location();
1831e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  aura::Window* root_window = wm::GetRootWindowAt(screen_location);
1844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  DCHECK(root_window) << "Root window not found while attempting autoclick.";
1854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1864e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  gfx::Point click_location(screen_location);
1871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  anchor_location_ = click_location;
1884e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  wm::ConvertPointFromScreen(root_window, &click_location);
1891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
190a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  aura::WindowTreeHost* host = root_window->GetHost();
191a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  host->ConvertPointToHost(&click_location);
1924e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1934e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED,
1944e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                             click_location,
1954e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                             click_location,
1965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                             mouse_event_flags_ | ui::EF_LEFT_MOUSE_BUTTON,
1975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                             ui::EF_LEFT_MOUSE_BUTTON);
1984e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED,
1994e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                               click_location,
2004e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                               click_location,
2015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                               mouse_event_flags_ | ui::EF_LEFT_MOUSE_BUTTON,
2025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                               ui::EF_LEFT_MOUSE_BUTTON);
2035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ui::EventDispatchDetails details =
20523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)      host->event_processor()->OnEventFromSource(&press_event);
2065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!details.dispatcher_destroyed)
20723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)    details = host->event_processor()->OnEventFromSource(&release_event);
2085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (details.dispatcher_destroyed)
2095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
2104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
2114e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
2124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// static.
2134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)AutoclickController* AutoclickController::CreateInstance() {
2144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  return new AutoclickControllerImpl();
2154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
2164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
2174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}  // namespace ash
218