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

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

Issue 2311393004: Laser tool blocks events from propagating. (Closed)
Patch Set: Fixed patch set 4 errors. Created 4 years, 3 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/common/system/chromeos/palette/tools/laser_pointer_mode.h" 5 #include "ash/common/system/chromeos/palette/tools/laser_pointer_mode.h"
6 6
7 #include "ash/common/palette_delegate.h" 7 #include "ash/common/palette_delegate.h"
8 #include "ash/common/system/chromeos/palette/palette_ids.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" 9 #include "ash/common/wm_shell.h"
11 #include "ash/resources/vector_icons/vector_icons.h" 10 #include "ash/resources/vector_icons/vector_icons.h"
12 #include "grit/ash_strings.h" 11 #include "grit/ash_strings.h"
13 #include "ui/base/l10n/l10n_util.h" 12 #include "ui/base/l10n/l10n_util.h"
14 #include "ui/wm/core/coordinate_conversion.h"
15 #include "ui/wm/core/cursor_manager.h"
16 13
17 namespace ash { 14 namespace ash {
18 namespace {
19
20 // A point gets removed from the collection if it is older than
21 // |kPointLifeDurationMs|.
22 const int kPointLifeDurationMs = 200;
23
24 // When no move events are being recieved we add a new point every
25 // |kAddStationaryPointsDelayMs| so that points older than
26 // |kPointLifeDurationMs| can get removed.
27 const int kAddStationaryPointsDelayMs = 5;
28
29 } // namespace
30 15
31 LaserPointerMode::LaserPointerMode(Delegate* delegate) 16 LaserPointerMode::LaserPointerMode(Delegate* delegate)
32 : CommonPaletteTool(delegate) { 17 : CommonPaletteTool(delegate) {
33 laser_pointer_view_.reset(new LaserPointerView(
34 base::TimeDelta::FromMilliseconds(kPointLifeDurationMs)));
35 timer_.reset(new base::Timer(
36 FROM_HERE, base::TimeDelta::FromMilliseconds(kAddStationaryPointsDelayMs),
37 base::Bind(&LaserPointerMode::AddStationaryPoint, base::Unretained(this)),
38 true));
39 WmShell::Get()->AddPointerWatcher(this,
40 views::PointerWatcherEventTypes::DRAGS);
41 } 18 }
42 19
43 LaserPointerMode::~LaserPointerMode() { 20 LaserPointerMode::~LaserPointerMode() {}
44 OnDisable();
45 WmShell::Get()->RemovePointerWatcher(this);
46 }
47 21
48 PaletteGroup LaserPointerMode::GetGroup() const { 22 PaletteGroup LaserPointerMode::GetGroup() const {
49 return PaletteGroup::MODE; 23 return PaletteGroup::MODE;
50 } 24 }
51 25
52 PaletteToolId LaserPointerMode::GetToolId() const { 26 PaletteToolId LaserPointerMode::GetToolId() const {
53 return PaletteToolId::LASER_POINTER; 27 return PaletteToolId::LASER_POINTER;
54 } 28 }
55 29
56 void LaserPointerMode::OnEnable() { 30 void LaserPointerMode::OnEnable() {
57 CommonPaletteTool::OnEnable(); 31 CommonPaletteTool::OnEnable();
58 32
59 WmShell::Get()->palette_delegate()->OnLaserPointerEnabled(); 33 WmShell::Get()->SetLaserPointerEnabled(true);
60 laser_pointer_view_->AddNewPoint(current_mouse_location_);
61 } 34 }
62 35
63 void LaserPointerMode::OnDisable() { 36 void LaserPointerMode::OnDisable() {
64 CommonPaletteTool::OnDisable(); 37 CommonPaletteTool::OnDisable();
65 38
66 WmShell::Get()->palette_delegate()->OnLaserPointerDisabled(); 39 WmShell::Get()->SetLaserPointerEnabled(false);
67 StopTimer();
68 laser_pointer_view_->Stop();
69 } 40 }
70 41
71 const gfx::VectorIcon& LaserPointerMode::GetActiveTrayIcon() const { 42 const gfx::VectorIcon& LaserPointerMode::GetActiveTrayIcon() const {
72 return kPaletteTrayIconLaserPointerIcon; 43 return kPaletteTrayIconLaserPointerIcon;
73 } 44 }
74 45
75 const gfx::VectorIcon& LaserPointerMode::GetPaletteIcon() const { 46 const gfx::VectorIcon& LaserPointerMode::GetPaletteIcon() const {
76 return kPaletteModeLaserPointerIcon; 47 return kPaletteModeLaserPointerIcon;
77 } 48 }
78 49
79 views::View* LaserPointerMode::CreateView() { 50 views::View* LaserPointerMode::CreateView() {
80 return CreateDefaultView( 51 return CreateDefaultView(
81 l10n_util::GetStringUTF16(IDS_ASH_STYLUS_TOOLS_LASER_POINTER_MODE)); 52 l10n_util::GetStringUTF16(IDS_ASH_STYLUS_TOOLS_LASER_POINTER_MODE));
82 } 53 }
83
84 void LaserPointerMode::StopTimer() {
85 timer_repeat_count_ = 0;
86 timer_->Stop();
87 }
88
89 void LaserPointerMode::AddStationaryPoint() {
90 laser_pointer_view_->AddNewPoint(current_mouse_location_);
91 // We can stop repeating the timer once the mouse has been stationary for
92 // longer than the life of a point.
93 if (timer_repeat_count_++ * kAddStationaryPointsDelayMs >=
94 kPointLifeDurationMs) {
95 StopTimer();
96 }
97 }
98
99 void LaserPointerMode::OnPointerEventObserved(
100 const ui::PointerEvent& event,
101 const gfx::Point& location_in_screen,
102 views::Widget* target) {
103 // TODO(sammiequon): Add support for pointer drags. See crbug.com/640410.
104 if (event.type() == ui::ET_POINTER_MOVED &&
105 event.pointer_details().pointer_type ==
106 ui::EventPointerType::POINTER_TYPE_PEN) {
107 current_mouse_location_ = location_in_screen;
108 if (enabled()) {
109 laser_pointer_view_->AddNewPoint(current_mouse_location_);
110 timer_repeat_count_ = 0;
111 if (!timer_->IsRunning())
112 timer_->Reset();
113 }
114 }
115 }
116 } // namespace ash 54 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698