OLD | NEW |
---|---|
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/laser/laser_pointer_controller.h" | 5 #include "ash/laser/laser_pointer_controller.h" |
6 | 6 |
7 #include "ash/common/system/chromeos/palette/palette_utils.h" | 7 #include "ash/common/system/chromeos/palette/palette_utils.h" |
8 #include "ash/laser/laser_pointer_view.h" | 8 #include "ash/laser/laser_pointer_view.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ui/aura/window_event_dispatcher.h" | 10 #include "ui/aura/window_event_dispatcher.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 | 66 |
67 if (event->pointer_details().pointer_type != | 67 if (event->pointer_details().pointer_type != |
68 ui::EventPointerType::POINTER_TYPE_PEN) | 68 ui::EventPointerType::POINTER_TYPE_PEN) |
69 return; | 69 return; |
70 | 70 |
71 if (event->type() != ui::ET_MOUSE_DRAGGED && | 71 if (event->type() != ui::ET_MOUSE_DRAGGED && |
72 event->type() != ui::ET_MOUSE_PRESSED && | 72 event->type() != ui::ET_MOUSE_PRESSED && |
73 event->type() != ui::ET_MOUSE_RELEASED) | 73 event->type() != ui::ET_MOUSE_RELEASED) |
74 return; | 74 return; |
75 | 75 |
76 // Delete the LaserPointerView instance if mouse is released. | 76 aura::Window* current_window = GetCurrentRootWindow(); |
77 if (event->type() == ui::ET_MOUSE_RELEASED) { | 77 |
78 stationary_timer_->Stop(); | 78 // Check if the current window is valid. Destroy the laser pointer view if |
79 laser_pointer_view_->Stop(); | 79 // not. |
80 laser_pointer_view_.reset(); | 80 if (!current_window) { |
81 DestroyLaserPointerView(); | |
81 return; | 82 return; |
82 } | 83 } |
83 | 84 |
84 // This will handle creating the initial laser pointer view on | 85 gfx::Point event_location = event->root_location(); |
85 // ET_MOUSE_PRESSED events. | 86 aura::Window* target = static_cast<aura::Window*>(event->target()); |
86 SwitchTargetRootWindowIfNeeded(GetCurrentRootWindow()); | 87 aura::Window* event_root = target->GetRootWindow(); |
88 // Remap point from where it was captured to the display it is actually on. | |
jdufault
2016/10/04 22:04:12
Above line 85, what about this comment instead:
/
sammiequon
2016/10/05 17:42:22
Done.
| |
89 aura::Window::ConvertPointToTarget(event_root, current_window, | |
90 &event_location); | |
91 | |
92 // If the stylus is over the palette icon or widget do not display the laser. | |
jdufault
2016/10/04 22:04:12
This comment seems misleading because the laser po
sammiequon
2016/10/05 17:42:22
Done.
| |
93 if ((!laser_pointer_view_ || is_fading_away_) && | |
94 PaletteContainsPointInScreen(event_location)) { | |
95 return; | |
96 } | |
97 | |
98 // If the stylus is pressed and the laser pointer view is currently active, | |
99 // create a new one and stop the timer. | |
jdufault
2016/10/04 22:04:12
nit: replace `one` with `view`
Why the comment ab
sammiequon
2016/10/05 17:42:22
Done.
| |
100 if (event->type() == ui::ET_MOUSE_PRESSED) | |
101 DestroyLaserPointerView(); | |
102 | |
103 SwitchTargetRootWindowIfNeeded(current_window); | |
87 | 104 |
88 if (laser_pointer_view_) { | 105 if (laser_pointer_view_) { |
89 // Remap point from where it was captured to the display it is actually on. | |
90 gfx::Point event_location = event->root_location(); | |
91 aura::Window* target = static_cast<aura::Window*>(event->target()); | |
92 aura::Window* event_root = target->GetRootWindow(); | |
93 aura::Window::ConvertPointToTarget( | |
94 event_root, laser_pointer_view_->GetRootWindow(), &event_location); | |
95 | |
96 current_mouse_location_ = event_location; | 106 current_mouse_location_ = event_location; |
97 laser_pointer_view_->AddNewPoint(current_mouse_location_); | 107 laser_pointer_view_->AddNewPoint(current_mouse_location_, is_fading_away_); |
98 | 108 |
99 stationary_timer_repeat_count_ = 0; | 109 stationary_timer_repeat_count_ = 0; |
100 if (event->type() == ui::ET_MOUSE_DRAGGED) { | 110 if (event->type() == ui::ET_MOUSE_DRAGGED || |
101 // Start the timer to add stationary points if dragged. | 111 event->type() == ui::ET_MOUSE_RELEASED) { |
112 // Signal the view to start fading away if the mouse has been released. | |
113 is_fading_away_ = event->type() == ui::ET_MOUSE_RELEASED; | |
jdufault
2016/10/04 22:04:12
Shouldn't this check happen before we add the poin
sammiequon
2016/10/05 17:42:22
Done.
| |
114 // Start the timer to add stationary points if dragged, or too advance the | |
jdufault
2016/10/04 22:04:12
too => to
sammiequon
2016/10/05 17:42:22
Done.
| |
115 // internal collections timestamps if released. | |
102 if (!stationary_timer_->IsRunning()) | 116 if (!stationary_timer_->IsRunning()) |
103 stationary_timer_->Reset(); | 117 stationary_timer_->Reset(); |
104 } | 118 } |
105 | |
106 // If the stylus is over the palette icon or widget, do not consume the | |
107 // event. | |
108 if (!PaletteContainsPointInScreen(current_mouse_location_)) | |
109 event->StopPropagation(); | |
110 } | 119 } |
120 event->StopPropagation(); | |
111 } | 121 } |
112 | 122 |
113 void LaserPointerController::OnWindowDestroying(aura::Window* window) { | 123 void LaserPointerController::OnWindowDestroying(aura::Window* window) { |
114 SwitchTargetRootWindowIfNeeded(window); | 124 SwitchTargetRootWindowIfNeeded(window); |
115 } | 125 } |
116 | 126 |
117 void LaserPointerController::SwitchTargetRootWindowIfNeeded( | 127 void LaserPointerController::SwitchTargetRootWindowIfNeeded( |
118 aura::Window* root_window) { | 128 aura::Window* root_window) { |
119 if (!root_window) { | 129 if (!root_window) { |
120 stationary_timer_->Stop(); | 130 DestroyLaserPointerView(); |
121 laser_pointer_view_.reset(); | |
122 } else if (laser_pointer_view_) { | 131 } else if (laser_pointer_view_) { |
123 laser_pointer_view_->ReparentWidget(root_window); | 132 laser_pointer_view_->ReparentWidget(root_window); |
124 } else if (enabled_) { | 133 } else if (enabled_) { |
125 laser_pointer_view_.reset(new LaserPointerView( | 134 laser_pointer_view_.reset(new LaserPointerView( |
126 base::TimeDelta::FromMilliseconds(kPointLifeDurationMs), root_window)); | 135 base::TimeDelta::FromMilliseconds(kPointLifeDurationMs), root_window)); |
127 } | 136 } |
128 } | 137 } |
129 | 138 |
139 void LaserPointerController::DestroyLaserPointerView() { | |
140 // |stationary_timer_| should also be stopped so that it does not attempt to | |
141 // add points when |laser_pointer_view_| is nullptr. | |
jdufault
2016/10/04 22:04:12
nit: nullptr => null
sammiequon
2016/10/05 17:42:23
Done.
| |
142 stationary_timer_->Stop(); | |
143 if (laser_pointer_view_) { | |
144 is_fading_away_ = false; | |
145 laser_pointer_view_->Stop(); | |
jdufault
2016/10/04 22:04:12
If we are destroying the view, why do we need to c
sammiequon
2016/10/05 17:42:22
Done.
| |
146 laser_pointer_view_.reset(); | |
147 } | |
148 } | |
149 | |
130 void LaserPointerController::AddStationaryPoint() { | 150 void LaserPointerController::AddStationaryPoint() { |
131 laser_pointer_view_->AddNewPoint(current_mouse_location_); | 151 laser_pointer_view_->AddNewPoint(current_mouse_location_, is_fading_away_); |
132 // We can stop repeating the timer once the mouse has been stationary for | 152 // We can stop repeating the timer once the mouse has been stationary for |
133 // longer than the life of a point. | 153 // longer than the life of a point. |
134 if (stationary_timer_repeat_count_ * kAddStationaryPointsDelayMs >= | 154 if (stationary_timer_repeat_count_ * kAddStationaryPointsDelayMs >= |
135 kPointLifeDurationMs) { | 155 kPointLifeDurationMs) { |
136 stationary_timer_->Stop(); | 156 stationary_timer_->Stop(); |
157 // Reset the view if the timer expires and the view was in process of fading | |
158 // away. | |
159 if (is_fading_away_) | |
160 DestroyLaserPointerView(); | |
137 } | 161 } |
138 stationary_timer_repeat_count_++; | 162 stationary_timer_repeat_count_++; |
139 } | 163 } |
140 } // namespace ash | 164 } // namespace ash |
OLD | NEW |