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

Side by Side Diff: ash/laser/laser_pointer_controller.cc

Issue 2362063002: cros: Laser pointer fades out on release, do not cover palette. (Closed)
Patch Set: Fixed patch set 5 errors. Created 4 years, 2 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/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
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
jdufault 2016/10/05 21:36:05 This comment is repeating the code without giving
sammiequon 2016/10/06 00:19:15 Done.
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 // Compute the event coordinate relative to the display it is currently on
85 // ET_MOUSE_PRESSED events. 86 // (and not the one the event was captured on).
86 SwitchTargetRootWindowIfNeeded(GetCurrentRootWindow()); 87 gfx::Point event_location = event->root_location();
88 aura::Window* target = static_cast<aura::Window*>(event->target());
89 aura::Window* event_root = target->GetRootWindow();
90 aura::Window::ConvertPointToTarget(event_root, current_window,
91 &event_location);
92
93 // If the stylus is pressed and the laser pointer view is currently active,
94 // create a new view.
95 if (event->type() == ui::ET_MOUSE_PRESSED) {
96 // Do not start a new laser session if the event is over the
97 // palette.
98 if (PaletteContainsPointInScreen(event_location))
99 return;
100
101 DestroyLaserPointerView();
102 }
103
104 SwitchTargetRootWindowIfNeeded(current_window);
jdufault 2016/10/05 21:36:05 Won't this start a laser session if I hold the las
sammiequon 2016/10/06 00:19:15 Yes this won't work properly. I went back to the o
87 105
88 if (laser_pointer_view_) { 106 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; 107 current_mouse_location_ = event_location;
97 laser_pointer_view_->AddNewPoint(current_mouse_location_); 108 // Signal the view to start fading away if the mouse has been released.
109 is_fading_away_ = event->type() == ui::ET_MOUSE_RELEASED;
110 if (is_fading_away_)
111 laser_pointer_view_->UpdateTime();
112 else
113 laser_pointer_view_->AddNewPoint(current_mouse_location_);
98 114
99 stationary_timer_repeat_count_ = 0; 115 stationary_timer_repeat_count_ = 0;
100 if (event->type() == ui::ET_MOUSE_DRAGGED) { 116 if (event->type() == ui::ET_MOUSE_DRAGGED ||
101 // Start the timer to add stationary points if dragged. 117 event->type() == ui::ET_MOUSE_RELEASED) {
118 // Start the timer to add stationary points if dragged, or to advance the
119 // internal collections timestamps if released.
102 if (!stationary_timer_->IsRunning()) 120 if (!stationary_timer_->IsRunning())
103 stationary_timer_->Reset(); 121 stationary_timer_->Reset();
104 } 122 }
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 } 123 }
124 event->StopPropagation();
111 } 125 }
112 126
113 void LaserPointerController::OnWindowDestroying(aura::Window* window) { 127 void LaserPointerController::OnWindowDestroying(aura::Window* window) {
114 SwitchTargetRootWindowIfNeeded(window); 128 SwitchTargetRootWindowIfNeeded(window);
115 } 129 }
116 130
117 void LaserPointerController::SwitchTargetRootWindowIfNeeded( 131 void LaserPointerController::SwitchTargetRootWindowIfNeeded(
118 aura::Window* root_window) { 132 aura::Window* root_window) {
119 if (!root_window) { 133 if (!root_window) {
120 stationary_timer_->Stop(); 134 DestroyLaserPointerView();
121 laser_pointer_view_.reset();
122 } else if (laser_pointer_view_) { 135 } else if (laser_pointer_view_) {
123 laser_pointer_view_->ReparentWidget(root_window); 136 laser_pointer_view_->ReparentWidget(root_window);
124 } else if (enabled_) { 137 } else if (enabled_) {
125 laser_pointer_view_.reset(new LaserPointerView( 138 laser_pointer_view_.reset(new LaserPointerView(
126 base::TimeDelta::FromMilliseconds(kPointLifeDurationMs), root_window)); 139 base::TimeDelta::FromMilliseconds(kPointLifeDurationMs), root_window));
127 } 140 }
128 } 141 }
129 142
143 void LaserPointerController::DestroyLaserPointerView() {
144 // |stationary_timer_| should also be stopped so that it does not attempt to
145 // add points when |laser_pointer_view_| is null.
146 stationary_timer_->Stop();
147 if (laser_pointer_view_) {
148 is_fading_away_ = false;
149 laser_pointer_view_.reset();
150 }
151 }
152
130 void LaserPointerController::AddStationaryPoint() { 153 void LaserPointerController::AddStationaryPoint() {
131 laser_pointer_view_->AddNewPoint(current_mouse_location_); 154 if (is_fading_away_)
155 laser_pointer_view_->UpdateTime();
156 else
157 laser_pointer_view_->AddNewPoint(current_mouse_location_);
158
132 // We can stop repeating the timer once the mouse has been stationary for 159 // We can stop repeating the timer once the mouse has been stationary for
133 // longer than the life of a point. 160 // longer than the life of a point.
134 if (stationary_timer_repeat_count_ * kAddStationaryPointsDelayMs >= 161 if (stationary_timer_repeat_count_ * kAddStationaryPointsDelayMs >=
135 kPointLifeDurationMs) { 162 kPointLifeDurationMs) {
136 stationary_timer_->Stop(); 163 stationary_timer_->Stop();
164 // Reset the view if the timer expires and the view was in process of fading
165 // away.
166 if (is_fading_away_)
167 DestroyLaserPointerView();
137 } 168 }
138 stationary_timer_repeat_count_++; 169 stationary_timer_repeat_count_++;
139 } 170 }
140 } // namespace ash 171 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698