OLD | NEW |
---|---|
(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 "grit/ash_strings.h" | |
11 #include "ui/base/l10n/l10n_util.h" | |
12 #include "ui/wm/core/coordinate_conversion.h" | |
13 #include "ui/wm/core/cursor_manager.h" | |
14 | |
15 namespace ash { | |
16 namespace { | |
17 const int kPointLifeDurationMs = 300; | |
18 const int kAddStationaryPointsDelayMs = 10; | |
19 } // namespace | |
20 | |
21 LaserPointerMode::LaserPointerMode(Delegate* delegate) | |
22 : CommonPaletteTool(delegate) { | |
23 laser_pointer_view_.reset(new LaserPointerView( | |
24 base::TimeDelta::FromMilliseconds(kPointLifeDurationMs))); | |
25 timer_.reset(new base::Timer( | |
26 FROM_HERE, base::TimeDelta::FromMilliseconds(kAddStationaryPointsDelayMs), | |
27 base::Bind(&LaserPointerMode::AddStationaryPoint, base::Unretained(this)), | |
28 true)); | |
29 WmShell::Get()->AddPointerWatcher(this, true); | |
30 } | |
31 | |
32 LaserPointerMode::~LaserPointerMode() { | |
33 StopTimer(); | |
34 WmShell::Get()->RemovePointerWatcher(this); | |
35 } | |
36 | |
37 PaletteGroup LaserPointerMode::GetGroup() const { | |
38 return PaletteGroup::MODE; | |
39 } | |
40 | |
41 PaletteToolId LaserPointerMode::GetToolId() const { | |
42 return PaletteToolId::LASER_POINTER; | |
43 } | |
44 | |
45 void LaserPointerMode::OnEnable() { | |
46 CommonPaletteTool::OnEnable(); | |
47 | |
48 if (WmShell::Get()->palette_delegate()) | |
49 WmShell::Get()->palette_delegate()->OnLaserPointerEnabled(); | |
50 laser_pointer_view_->AddNewPoint(current_mouse_location_); | |
51 } | |
52 | |
53 void LaserPointerMode::OnDisable() { | |
54 CommonPaletteTool::OnDisable(); | |
55 | |
56 if (WmShell::Get()->palette_delegate()) | |
jdufault
2016/08/17 21:41:07
https://codereview.chromium.org/2235063002/ adds a
sammiequon
2016/08/18 00:52:07
Done.
| |
57 WmShell::Get()->palette_delegate()->OnLaserPointerDisabled(); | |
58 StopTimer(); | |
59 laser_pointer_view_->Stop(); | |
60 } | |
61 | |
62 gfx::VectorIconId LaserPointerMode::GetActiveTrayIcon() { | |
63 return gfx::VectorIconId::PALETTE_TRAY_ICON_LASER_POINTER; | |
64 } | |
65 | |
66 gfx::VectorIconId LaserPointerMode::GetPaletteIconId() { | |
67 return gfx::VectorIconId::PALETTE_MODE_LASER_POINTER; | |
68 } | |
69 | |
70 views::View* LaserPointerMode::CreateView() { | |
71 return CreateDefaultView( | |
72 l10n_util::GetStringUTF16(IDS_ASH_PALETTE_LASER_POINTER_MODE)); | |
73 } | |
74 | |
75 void LaserPointerMode::StopTimer() { | |
76 timer_repeat_count_ = 0; | |
77 timer_->Stop(); | |
78 } | |
79 | |
80 void LaserPointerMode::AddStationaryPoint() { | |
81 DCHECK(thread_checker_.CalledOnValidThread()); | |
82 laser_pointer_view_->AddNewPoint(current_mouse_location_); | |
83 int count = timer_repeat_count_; | |
jdufault
2016/08/17 21:41:07
Let's always add to timer_repeat_count_ so the if
sammiequon
2016/08/18 00:52:07
Done.
| |
84 // We can stop repeating the timer once the mouse has been stationary for | |
85 // longer than the life of a point. | |
86 if (count * kAddStationaryPointsDelayMs < kPointLifeDurationMs) { | |
87 timer_repeat_count_++; | |
88 } else { | |
89 StopTimer(); | |
90 } | |
91 } | |
92 | |
93 void LaserPointerMode::OnPointerEventObserved( | |
94 const ui::PointerEvent& event, | |
95 const gfx::Point& location_in_screen, | |
96 views::Widget* target) { | |
97 if (event.type() == ui::ET_POINTER_MOVED && | |
98 event.pointer_details().pointer_type == | |
99 ui::EventPointerType::POINTER_TYPE_PEN) { | |
100 current_mouse_location_ = location_in_screen; | |
101 if (enabled()) { | |
102 // Add the new point and notify the queue. | |
103 laser_pointer_view_->AddNewPoint(current_mouse_location_); | |
104 timer_repeat_count_ = 0; | |
105 timer_->Reset(); | |
106 } | |
107 } | |
108 } | |
109 } // namespace ash | |
OLD | NEW |