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 gfx::Point event_location = event->root_location(); |
77 if (event->type() == ui::ET_MOUSE_RELEASED) { | 77 aura::Window* target = static_cast<aura::Window*>(event->target()); |
78 stationary_timer_->Stop(); | 78 aura::Window* event_root = target->GetRootWindow(); |
79 laser_pointer_view_->Stop(); | 79 aura::Window* current_window = GetCurrentRootWindow(); |
80 laser_pointer_view_.reset(); | 80 |
81 if (!current_window) { | |
82 SwitchTargetRootWindowIfNeeded(current_window); | |
jdufault
2016/09/23 23:59:19
What is the purpose of this?
sammiequon
2016/09/26 19:30:38
Done.
| |
81 return; | 83 return; |
82 } | 84 } |
83 | 85 |
84 // This will handle creating the initial laser pointer view on | 86 // Remap point from where it was captured to the display it is actually on. |
85 // ET_MOUSE_PRESSED events. | 87 aura::Window::ConvertPointToTarget(event_root, current_window, |
jdufault
2016/09/23 23:59:19
Keep all of the point remapping logic together.
sammiequon
2016/09/26 19:30:38
Done.
| |
86 SwitchTargetRootWindowIfNeeded(GetCurrentRootWindow()); | 88 &event_location); |
89 | |
90 // If the stylus is over the palette icon or widget do not display the laser. | |
91 if (PaletteContainsPointInScreen(event_location)) { | |
92 DestroyLaserPointerView(); | |
jdufault
2016/09/23 23:59:19
I think we should continuing showing the laser poi
sammiequon
2016/09/26 19:30:38
Done.
| |
93 return; | |
jdufault
2016/09/23 23:59:19
We should not be creating the view in the first pl
sammiequon
2016/09/26 19:30:38
Done.
| |
94 } | |
95 | |
96 // If the stylus is pressed and the laser pointer view is currently active, | |
97 // create a new one and stop the timer. | |
98 if (event->type() == ui::ET_MOUSE_PRESSED) | |
99 DestroyLaserPointerView(); | |
100 | |
101 SwitchTargetRootWindowIfNeeded(current_window); | |
87 | 102 |
88 if (laser_pointer_view_) { | 103 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; | 104 current_mouse_location_ = event_location; |
97 laser_pointer_view_->AddNewPoint(current_mouse_location_); | 105 laser_pointer_view_->AddNewPoint(current_mouse_location_); |
98 | 106 |
99 stationary_timer_repeat_count_ = 0; | 107 stationary_timer_repeat_count_ = 0; |
100 if (event->type() == ui::ET_MOUSE_DRAGGED) { | 108 if (event->type() == ui::ET_MOUSE_DRAGGED || |
101 // Start the timer to add stationary points if dragged. | 109 event->type() == ui::ET_MOUSE_RELEASED) { |
110 // Signal the view to start fading away if the mouse has been released. | |
111 if (event->type() == ui::ET_MOUSE_RELEASED) | |
112 laser_pointer_view_->SetIsFadingAway(true); | |
113 // Start the timer to add stationary points if dragged, or too advance the | |
114 // interal collections timestamps if released. | |
jdufault
2016/09/23 23:59:19
interal -> internal
sammiequon
2016/09/26 19:30:38
Done.
| |
102 if (!stationary_timer_->IsRunning()) | 115 if (!stationary_timer_->IsRunning()) |
103 stationary_timer_->Reset(); | 116 stationary_timer_->Reset(); |
104 } | 117 } |
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 } | 118 } |
119 event->StopPropagation(); | |
111 } | 120 } |
112 | 121 |
113 void LaserPointerController::OnWindowDestroying(aura::Window* window) { | 122 void LaserPointerController::OnWindowDestroying(aura::Window* window) { |
114 SwitchTargetRootWindowIfNeeded(window); | 123 SwitchTargetRootWindowIfNeeded(window); |
115 } | 124 } |
116 | 125 |
117 void LaserPointerController::SwitchTargetRootWindowIfNeeded( | 126 void LaserPointerController::SwitchTargetRootWindowIfNeeded( |
118 aura::Window* root_window) { | 127 aura::Window* root_window) { |
119 if (!root_window) { | 128 if (!root_window) { |
120 stationary_timer_->Stop(); | 129 DestroyLaserPointerView(); |
121 laser_pointer_view_.reset(); | |
122 } else if (laser_pointer_view_) { | 130 } else if (laser_pointer_view_) { |
123 laser_pointer_view_->ReparentWidget(root_window); | 131 laser_pointer_view_->ReparentWidget(root_window); |
124 } else if (enabled_) { | 132 } else if (enabled_) { |
125 laser_pointer_view_.reset(new LaserPointerView( | 133 laser_pointer_view_.reset(new LaserPointerView( |
126 base::TimeDelta::FromMilliseconds(kPointLifeDurationMs), root_window)); | 134 base::TimeDelta::FromMilliseconds(kPointLifeDurationMs), root_window)); |
127 } | 135 } |
128 } | 136 } |
129 | 137 |
138 void LaserPointerController::DestroyLaserPointerView() { | |
139 // |stationary_timer_| should also be stopped so that it does not attempt to | |
140 // add points when |laser_pointer_view_| is nullptr. | |
141 stationary_timer_->Stop(); | |
142 if (laser_pointer_view_) { | |
143 laser_pointer_view_->Stop(); | |
144 laser_pointer_view_.reset(); | |
145 } | |
146 } | |
147 | |
130 void LaserPointerController::AddStationaryPoint() { | 148 void LaserPointerController::AddStationaryPoint() { |
131 laser_pointer_view_->AddNewPoint(current_mouse_location_); | 149 laser_pointer_view_->AddNewPoint(current_mouse_location_); |
132 // We can stop repeating the timer once the mouse has been stationary for | 150 // We can stop repeating the timer once the mouse has been stationary for |
133 // longer than the life of a point. | 151 // longer than the life of a point. |
134 if (stationary_timer_repeat_count_ * kAddStationaryPointsDelayMs >= | 152 if (stationary_timer_repeat_count_ * kAddStationaryPointsDelayMs >= |
135 kPointLifeDurationMs) { | 153 kPointLifeDurationMs) { |
136 stationary_timer_->Stop(); | 154 stationary_timer_->Stop(); |
155 // Reset the view if the timer expires and the view was in process of fading | |
156 // away. | |
157 if (laser_pointer_view_->GetIsFadingAway()) | |
158 DestroyLaserPointerView(); | |
137 } | 159 } |
138 stationary_timer_repeat_count_++; | 160 stationary_timer_repeat_count_++; |
139 } | 161 } |
140 } // namespace ash | 162 } // namespace ash |
OLD | NEW |