OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ash/autoclick/autoclick_controller.h" | 5 #include "ash/autoclick/autoclick_controller.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/wm/coordinate_conversion.h" | 8 #include "ash/wm/coordinate_conversion.h" |
9 #include "base/timer/timer.h" | 9 #include "base/timer/timer.h" |
10 #include "ui/aura/env.h" | 10 #include "ui/aura/env.h" |
11 #include "ui/aura/root_window.h" | 11 #include "ui/aura/root_window.h" |
12 #include "ui/events/event.h" | 12 #include "ui/events/event.h" |
13 #include "ui/events/event_constants.h" | 13 #include "ui/events/event_constants.h" |
14 #include "ui/events/event_handler.h" | 14 #include "ui/events/event_handler.h" |
15 #include "ui/gfx/point.h" | 15 #include "ui/gfx/point.h" |
16 | 16 |
17 namespace ash { | 17 namespace ash { |
18 | 18 |
19 namespace { | |
20 | |
21 // The default wait time between last mouse movement and sending the autoclick. | |
22 int kDefaultClickWaitTimeMs = 500; | |
23 | |
24 } // namespace | |
25 | |
26 class AutoclickControllerImpl : public AutoclickController, | 19 class AutoclickControllerImpl : public AutoclickController, |
27 public ui::EventHandler { | 20 public ui::EventHandler { |
28 public: | 21 public: |
29 AutoclickControllerImpl(); | 22 AutoclickControllerImpl(); |
30 virtual ~AutoclickControllerImpl(); | 23 virtual ~AutoclickControllerImpl(); |
31 | 24 |
32 private: | 25 private: |
33 // AutoclickController overrides: | 26 // AutoclickController overrides: |
34 virtual void SetEnabled(bool enabled) OVERRIDE; | 27 virtual void SetEnabled(bool enabled) OVERRIDE; |
35 virtual bool IsEnabled() const OVERRIDE; | 28 virtual bool IsEnabled() const OVERRIDE; |
36 virtual void SetClickWaitTime(int wait_time_ms) OVERRIDE; | 29 virtual void SetAutoclickDelay(int delay_ms) OVERRIDE; |
37 virtual int GetClickWaitTime() const OVERRIDE; | 30 virtual int GetAutoclickDelay() const OVERRIDE; |
38 | 31 |
39 // ui::EventHandler overrides: | 32 // ui::EventHandler overrides: |
40 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; | 33 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; |
41 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; | 34 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; |
42 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE; | 35 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE; |
43 | 36 |
44 void InitClickTimer(); | 37 void InitClickTimer(); |
45 | 38 |
46 void DoAutoclick(); | 39 void DoAutoclick(); |
47 | 40 |
48 bool enabled_; | 41 bool enabled_; |
49 int wait_time_ms_; | 42 int delay_ms_; |
50 int mouse_event_flags_; | 43 int mouse_event_flags_; |
51 scoped_ptr<base::Timer> autoclick_timer_; | 44 scoped_ptr<base::Timer> autoclick_timer_; |
52 | 45 |
53 DISALLOW_COPY_AND_ASSIGN(AutoclickControllerImpl); | 46 DISALLOW_COPY_AND_ASSIGN(AutoclickControllerImpl); |
54 }; | 47 }; |
55 | 48 |
56 | 49 |
57 AutoclickControllerImpl::AutoclickControllerImpl() | 50 AutoclickControllerImpl::AutoclickControllerImpl() |
58 : enabled_(false), | 51 : enabled_(false), |
59 wait_time_ms_(kDefaultClickWaitTimeMs), | 52 delay_ms_(kDefaultAutoclickDelayMs), |
60 mouse_event_flags_(ui::EF_NONE) { | 53 mouse_event_flags_(ui::EF_NONE) { |
61 InitClickTimer(); | 54 InitClickTimer(); |
62 } | 55 } |
63 | 56 |
64 AutoclickControllerImpl::~AutoclickControllerImpl() { | 57 AutoclickControllerImpl::~AutoclickControllerImpl() { |
65 } | 58 } |
66 | 59 |
67 void AutoclickControllerImpl::SetEnabled(bool enabled) { | 60 void AutoclickControllerImpl::SetEnabled(bool enabled) { |
68 if (enabled_ == enabled) | 61 if (enabled_ == enabled) |
69 return; | 62 return; |
70 enabled_ = enabled; | 63 enabled_ = enabled; |
71 | 64 |
72 if (enabled_) { | 65 if (enabled_) { |
73 Shell::GetInstance()->AddPreTargetHandler(this); | 66 Shell::GetInstance()->AddPreTargetHandler(this); |
74 autoclick_timer_->Stop(); | 67 autoclick_timer_->Stop(); |
75 } else { | 68 } else { |
76 Shell::GetInstance()->RemovePreTargetHandler(this); | 69 Shell::GetInstance()->RemovePreTargetHandler(this); |
77 } | 70 } |
78 } | 71 } |
79 | 72 |
80 bool AutoclickControllerImpl::IsEnabled() const { | 73 bool AutoclickControllerImpl::IsEnabled() const { |
81 return enabled_; | 74 return enabled_; |
82 } | 75 } |
83 | 76 |
84 void AutoclickControllerImpl::SetClickWaitTime(int wait_time_ms) { | 77 void AutoclickControllerImpl::SetAutoclickDelay(int delay_ms) { |
85 wait_time_ms_ = wait_time_ms; | 78 delay_ms_ = delay_ms; |
86 InitClickTimer(); | 79 InitClickTimer(); |
87 } | 80 } |
88 | 81 |
89 int AutoclickControllerImpl::GetClickWaitTime() const { | 82 int AutoclickControllerImpl::GetAutoclickDelay() const { |
90 return wait_time_ms_; | 83 return delay_ms_; |
91 } | 84 } |
92 | 85 |
93 void AutoclickControllerImpl::InitClickTimer() { | 86 void AutoclickControllerImpl::InitClickTimer() { |
94 autoclick_timer_.reset(new base::Timer( | 87 autoclick_timer_.reset(new base::Timer( |
95 FROM_HERE, | 88 FROM_HERE, |
96 base::TimeDelta::FromMilliseconds(wait_time_ms_), | 89 base::TimeDelta::FromMilliseconds(delay_ms_), |
97 base::Bind(&AutoclickControllerImpl::DoAutoclick, | 90 base::Bind(&AutoclickControllerImpl::DoAutoclick, |
98 base::Unretained(this)), | 91 base::Unretained(this)), |
99 false)); | 92 false)); |
100 } | 93 } |
101 | 94 |
102 void AutoclickControllerImpl::OnMouseEvent(ui::MouseEvent* event) { | 95 void AutoclickControllerImpl::OnMouseEvent(ui::MouseEvent* event) { |
103 if (event->type() == ui::ET_MOUSE_MOVED) { | 96 if (event->type() == ui::ET_MOUSE_MOVED) { |
104 mouse_event_flags_ = event->flags(); | 97 mouse_event_flags_ = event->flags(); |
105 autoclick_timer_->Reset(); | 98 autoclick_timer_->Reset(); |
106 } else if (event->type() == ui::ET_MOUSE_PRESSED) { | 99 } else if (event->type() == ui::ET_MOUSE_PRESSED) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&press_event); | 141 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&press_event); |
149 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&release_event); | 142 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&release_event); |
150 } | 143 } |
151 | 144 |
152 // static. | 145 // static. |
153 AutoclickController* AutoclickController::CreateInstance() { | 146 AutoclickController* AutoclickController::CreateInstance() { |
154 return new AutoclickControllerImpl(); | 147 return new AutoclickControllerImpl(); |
155 } | 148 } |
156 | 149 |
157 } // namespace ash | 150 } // namespace ash |
OLD | NEW |