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

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

Issue 2239743004: Palette tool laser prototype. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@patch
Patch Set: Fixed patch set 8 errors. 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/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;
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);
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
50 // once test delegate CL lands.
51 if (WmShell::Get()->palette_delegate())
jdufault 2016/08/23 21:52:05 TestPaletteDelegate should be available now.
sammiequon 2016/08/24 00:04:04 Done.
52 WmShell::Get()->palette_delegate()->OnLaserPointerEnabled();
53 laser_pointer_view_->AddNewPoint(current_mouse_location_);
54 }
55
56 void LaserPointerMode::OnDisable() {
57 CommonPaletteTool::OnDisable();
58
59 if (WmShell::Get()->palette_delegate())
60 WmShell::Get()->palette_delegate()->OnLaserPointerDisabled();
61 StopTimer();
62 laser_pointer_view_->Stop();
63 }
64
65 gfx::VectorIconId LaserPointerMode::GetActiveTrayIcon() {
66 return gfx::VectorIconId::PALETTE_TRAY_ICON_LASER_POINTER;
67 }
68
69 gfx::VectorIconId LaserPointerMode::GetPaletteIconId() {
70 return gfx::VectorIconId::PALETTE_MODE_LASER_POINTER;
71 }
72
73 views::View* LaserPointerMode::CreateView() {
74 return CreateDefaultView(
75 l10n_util::GetStringUTF16(IDS_ASH_PALETTE_LASER_POINTER_MODE));
76 }
77
78 void LaserPointerMode::StopTimer() {
79 timer_repeat_count_ = 0;
80 timer_->Stop();
81 }
82
83 void LaserPointerMode::AddStationaryPoint() {
84 laser_pointer_view_->AddNewPoint(current_mouse_location_);
85 // We can stop repeating the timer once the mouse has been stationary for
86 // longer than the life of a point.
87 if (timer_repeat_count_++ * kAddStationaryPointsDelayMs >=
88 kPointLifeDurationMs) {
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 laser_pointer_view_->AddNewPoint(current_mouse_location_);
103 timer_repeat_count_ = 0;
104 timer_->Reset();
105 }
106 }
107 }
108 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698