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 = 200; | |
18 const int kAddStationaryPointsDelayMs = 5; | |
jdufault
2016/08/19 01:02:08
Should this be 10?
sammiequon
2016/08/19 20:28:46
I played around with the constants I think this lo
| |
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 // TODO(sammiequon): Remove check and set palette delegate to test delegate | |
49 // once test deleagte CL lands. | |
50 if (WmShell::Get()->palette_delegate()) | |
51 WmShell::Get()->palette_delegate()->OnLaserPointerEnabled(); | |
52 laser_pointer_view_->AddNewPoint(current_mouse_location_); | |
53 } | |
54 | |
55 void LaserPointerMode::OnDisable() { | |
56 CommonPaletteTool::OnDisable(); | |
57 | |
58 if (WmShell::Get()->palette_delegate()) | |
59 WmShell::Get()->palette_delegate()->OnLaserPointerDisabled(); | |
60 StopTimer(); | |
61 laser_pointer_view_->Stop(); | |
62 } | |
63 | |
64 gfx::VectorIconId LaserPointerMode::GetActiveTrayIcon() { | |
65 return gfx::VectorIconId::PALETTE_TRAY_ICON_LASER_POINTER; | |
66 } | |
67 | |
68 gfx::VectorIconId LaserPointerMode::GetPaletteIconId() { | |
69 return gfx::VectorIconId::PALETTE_MODE_LASER_POINTER; | |
70 } | |
71 | |
72 views::View* LaserPointerMode::CreateView() { | |
73 return CreateDefaultView( | |
74 l10n_util::GetStringUTF16(IDS_ASH_PALETTE_LASER_POINTER_MODE)); | |
75 } | |
76 | |
77 void LaserPointerMode::StopTimer() { | |
78 timer_repeat_count_ = 0; | |
79 timer_->Stop(); | |
80 } | |
81 | |
82 void LaserPointerMode::AddStationaryPoint() { | |
83 laser_pointer_view_->AddNewPoint(current_mouse_location_); | |
84 // We can stop repeating the timer once the mouse has been stationary for | |
85 // longer than the life of a point. | |
86 if (timer_repeat_count_++ * kAddStationaryPointsDelayMs >= | |
87 kPointLifeDurationMs) | |
jdufault
2016/08/19 01:02:08
Wrap with {} since if condition is >1 line
sammiequon
2016/08/19 20:28:46
Done.
| |
88 StopTimer(); | |
89 } | |
90 | |
91 void LaserPointerMode::OnPointerEventObserved( | |
92 const ui::PointerEvent& event, | |
93 const gfx::Point& location_in_screen, | |
94 views::Widget* target) { | |
95 if (event.type() == ui::ET_POINTER_MOVED && | |
96 event.pointer_details().pointer_type == | |
97 ui::EventPointerType::POINTER_TYPE_PEN) { | |
98 current_mouse_location_ = location_in_screen; | |
99 if (enabled()) { | |
100 // Add the new point and notify the queue. | |
101 laser_pointer_view_->AddNewPoint(current_mouse_location_); | |
102 timer_repeat_count_ = 0; | |
103 timer_->Reset(); | |
104 } | |
105 } | |
106 } | |
107 } // namespace ash | |
OLD | NEW |