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/system/chromeos/palette/tools/laser_pointer_view.h" | |
10 #include "ash/common/wm_shell.h" | |
11 #include "grit/ash_strings.h" | |
12 #include "ui/base/l10n/l10n_util.h" | |
13 #include "ui/wm/core/coordinate_conversion.h" | |
14 #include "ui/wm/core/cursor_manager.h" | |
15 | |
16 namespace ash { | |
17 namespace { | |
18 const int kPointLifeDurationMs = 200; | |
19 const int kAddStationaryPointsDelayMs = 5; | |
oshima
2016/08/24 23:01:03
please document these variables, and please keep a
sammiequon
2016/08/25 17:59:04
Done.
| |
20 } // namespace | |
21 | |
22 LaserPointerMode::LaserPointerMode(Delegate* delegate) | |
23 : CommonPaletteTool(delegate) { | |
24 laser_pointer_view_.reset(new LaserPointerView( | |
25 base::TimeDelta::FromMilliseconds(kPointLifeDurationMs))); | |
26 timer_.reset(new base::Timer( | |
27 FROM_HERE, base::TimeDelta::FromMilliseconds(kAddStationaryPointsDelayMs), | |
28 base::Bind(&LaserPointerMode::AddStationaryPoint, base::Unretained(this)), | |
29 true)); | |
30 WmShell::Get()->AddPointerWatcher(this, true); | |
31 } | |
32 | |
33 LaserPointerMode::~LaserPointerMode() { | |
34 StopTimer(); | |
35 WmShell::Get()->RemovePointerWatcher(this); | |
oshima
2016/08/24 23:01:03
q: No need to disable?
sammiequon
2016/08/25 17:59:04
Done.
| |
36 } | |
37 | |
38 PaletteGroup LaserPointerMode::GetGroup() const { | |
39 return PaletteGroup::MODE; | |
40 } | |
41 | |
42 PaletteToolId LaserPointerMode::GetToolId() const { | |
43 return PaletteToolId::LASER_POINTER; | |
44 } | |
45 | |
46 void LaserPointerMode::OnEnable() { | |
47 CommonPaletteTool::OnEnable(); | |
48 | |
49 // TODO(sammiequon): Remove check and set palette delegate to test delegate | |
oshima
2016/08/24 23:01:03
which check?
sammiequon
2016/08/25 17:59:04
Done.
| |
50 // once test delegate CL lands. | |
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 WmShell::Get()->palette_delegate()->OnLaserPointerDisabled(); | |
59 StopTimer(); | |
60 laser_pointer_view_->Stop(); | |
61 } | |
62 | |
63 gfx::VectorIconId LaserPointerMode::GetActiveTrayIcon() { | |
64 return gfx::VectorIconId::PALETTE_TRAY_ICON_LASER_POINTER; | |
65 } | |
66 | |
67 gfx::VectorIconId LaserPointerMode::GetPaletteIconId() { | |
68 return gfx::VectorIconId::PALETTE_MODE_LASER_POINTER; | |
69 } | |
70 | |
71 views::View* LaserPointerMode::CreateView() { | |
72 return CreateDefaultView( | |
73 l10n_util::GetStringUTF16(IDS_ASH_PALETTE_LASER_POINTER_MODE)); | |
74 } | |
75 | |
76 void LaserPointerMode::StopTimer() { | |
77 timer_repeat_count_ = 0; | |
78 timer_->Stop(); | |
79 } | |
80 | |
81 void LaserPointerMode::AddStationaryPoint() { | |
82 laser_pointer_view_->AddNewPoint(current_mouse_location_); | |
83 // We can stop repeating the timer once the mouse has been stationary for | |
84 // longer than the life of a point. | |
85 if (timer_repeat_count_++ * kAddStationaryPointsDelayMs >= | |
86 kPointLifeDurationMs) { | |
87 StopTimer(); | |
88 } | |
89 } | |
90 | |
91 void LaserPointerMode::OnPointerEventObserved( | |
92 const ui::PointerEvent& event, | |
93 const gfx::Point& location_in_screen, | |
94 views::Widget* target) { | |
95 // TODO(sammiequon): Add support for pointer drags. See crbug.com/640410. | |
96 if (event.type() == ui::ET_POINTER_MOVED && | |
97 event.pointer_details().pointer_type == | |
98 ui::EventPointerType::POINTER_TYPE_PEN) { | |
99 current_mouse_location_ = location_in_screen; | |
oshima
2016/08/24 23:01:03
am i correct that it always start recording when t
sammiequon
2016/08/25 17:59:04
Yes it constantly updates even while the laser is
| |
100 if (enabled()) { | |
101 laser_pointer_view_->AddNewPoint(current_mouse_location_); | |
102 timer_repeat_count_ = 0; | |
103 if (!timer_->IsRunning()) | |
104 timer_->Reset(); | |
105 } | |
106 } | |
107 } | |
108 } // namespace ash | |
OLD | NEW |