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

Side by Side Diff: ash/common/system/chromeos/palette/tools/laser_pointer_mode.cc

Issue 2231533004: Pointer watcher modifications to support laser pointer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Initial patch. Created 4 years, 4 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
OLDNEW
(Empty)
1 // Copyright 2016 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 "ash/common/system/chromeos/palette/tools/laser_pointer_mode.h"
6
7 #include "ash/common/palette_delegate.h"
8 #include "ash/common/system/chromeos/palette/palette_ids.h"
9 #include "ash/common/wm_shell.h"
10 #include "ui/wm/core/coordinate_conversion.h"
11 #include "ui/wm/core/cursor_manager.h"
12
13 namespace ash {
14
15 const int LaserPointerMode::kPointLifeDurationMs = 300;
16 const int LaserPointerMode::kAddStationaryPointsDelayMs = 10;
17
18 LaserPointerMode::LaserPointerMode(Delegate* delegate)
19 : CommonPaletteTool(delegate),
20 timer_repeat_count_(0),
jdufault 2016/08/11 23:41:54 Initialize in header.
21 laser_points_(
22 base::TimeDelta::FromMilliseconds(int{kPointLifeDurationMs})) {
jdufault 2016/08/11 23:41:54 Remove the int{} cast.
23 laser_pointer_view_ = new LaserPointerView();
jdufault 2016/08/11 23:41:54 Use std::unique_ptr
24 InitializeTimer();
25 WmShell::Get()->AddPointerWatcher(this, true);
26 }
27
28 LaserPointerMode::~LaserPointerMode() {
29 WmShell::Get()->RemovePointerWatcher(this);
30 }
31
32 PaletteGroup LaserPointerMode::GetGroup() const {
33 return PaletteGroup::MODE;
34 }
35
36 PaletteToolId LaserPointerMode::GetToolId() const {
37 return PaletteToolId::LASER_POINTER;
38 }
39
40 void LaserPointerMode::OnEnable() {
41 CommonPaletteTool::OnEnable();
42 if (WmShell::Get()->palette_delegate())
43 WmShell::Get()->palette_delegate()->OnLaserModeEnabled();
44 laser_points_.AddPoint(current_mouse_location_);
45 laser_pointer_view_->SetNewPoints(laser_points_);
46 }
47
48 void LaserPointerMode::OnDisable() {
49 CommonPaletteTool::OnDisable();
50 if (WmShell::Get()->palette_delegate())
51 WmShell::Get()->palette_delegate()->OnLaserModeDisabled();
52 StopTimer();
53 // Clear the points and then notify the view that there is nothing to be
54 // rendered.
55 laser_points_.Clear();
56 laser_pointer_view_->Stop();
57 }
58
59 gfx::VectorIconId LaserPointerMode::GetActiveTrayIcon() {
60 return gfx::VectorIconId::PALETTE_TRAY_ICON_LASER_POINTER;
61 }
62
63 gfx::VectorIconId LaserPointerMode::GetPaletteIconId() {
64 return gfx::VectorIconId::PALETTE_MODE_LASER_POINTER;
65 }
66
67 void LaserPointerMode::InitializeTimer() {
68 timer_.reset(new base::Timer(
jdufault 2016/08/11 23:41:54 Is this the output from git cl format?
69 FROM_HERE, base::TimeDelta::FromMilliseconds(kAddStationaryPointsDelayMs),
70 base::Bind(&LaserPointerMode::AddStationaryPoint, base::Unretained(this)),
71 false));
72 }
73
74 void LaserPointerMode::StartTimer() {
75 timer_->Reset();
76 }
77
78 void LaserPointerMode::StopTimer() {
79 points_lock_.Acquire();
80 timer_repeat_count_ = 0;
81 points_lock_.Release();
82 timer_->Stop();
83 }
84
85 void LaserPointerMode::AddStationaryPoint() {
86 points_lock_.Acquire();
87 laser_points_.AddPoint(current_mouse_location_);
88 laser_pointer_view_->SetNewPoints(laser_points_);
89 int count = timer_repeat_count_;
90 points_lock_.Release();
91 // We can stop repeating the timer once the mouse has been stationary for
92 // longer than the life of a point.
93 if (count * kAddStationaryPointsDelayMs < kPointLifeDurationMs) {
94 timer_repeat_count_++;
95 timer_->Reset();
96 } else {
97 StopTimer();
98 }
99 }
100
101 void LaserPointerMode::OnPointerEventObserved(
102 const ui::PointerEvent& event,
103 const gfx::Point& location_in_screen,
104 views::Widget* target) {
105 if (event.type() == ui::ET_POINTER_MOVED) {
jdufault 2016/08/11 23:41:54 We want to only run this logic for pen pointer eve
106 current_mouse_location_ = location_in_screen;
107 if (enabled()) {
jdufault 2016/08/11 23:41:54 Do we want to always capture the mouse location? C
108 points_lock_.Acquire();
109 // Add the new point and notify the queue.
110 laser_points_.AddPoint(current_mouse_location_);
111 laser_pointer_view_->SetNewPoints(laser_points_);
112 timer_repeat_count_ = 0;
113 points_lock_.Release();
114 StartTimer();
115 }
116 }
117 }
118 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698