Chromium Code Reviews| Index: ash/laser/laser_pointer_controller.cc |
| diff --git a/ash/laser/laser_pointer_controller.cc b/ash/laser/laser_pointer_controller.cc |
| index 35a15d04f6954179b5db5f0c8f19cf5bb1a7cb5f..f53c78aff922255dd2b970f20895b2cb8c9506dd 100644 |
| --- a/ash/laser/laser_pointer_controller.cc |
| +++ b/ash/laser/laser_pointer_controller.cc |
| @@ -73,41 +73,54 @@ void LaserPointerController::OnMouseEvent(ui::MouseEvent* event) { |
| event->type() != ui::ET_MOUSE_RELEASED) |
| return; |
| - // Delete the LaserPointerView instance if mouse is released. |
| - if (event->type() == ui::ET_MOUSE_RELEASED) { |
| - stationary_timer_->Stop(); |
| - laser_pointer_view_->Stop(); |
| - laser_pointer_view_.reset(); |
| + aura::Window* current_window = GetCurrentRootWindow(); |
| + |
| + if (!current_window) { |
| + DestroyLaserPointerView(); |
| + return; |
| + } |
| + |
| + // Compute the event coordinate relative to the display it is currently on |
| + // (and not the one the event was captured on). |
| + gfx::Point event_location = event->root_location(); |
| + aura::Window* target = static_cast<aura::Window*>(event->target()); |
| + aura::Window* event_root = target->GetRootWindow(); |
| + aura::Window::ConvertPointToTarget(event_root, current_window, |
| + &event_location); |
| + |
| + // Do not start a new laser session if the event is over the palette, or is in |
| + // process of fading away. |
| + if (!laser_pointer_view_ && |
| + (is_fading_away_ || PaletteContainsPointInScreen(event_location))) { |
|
jdufault
2016/10/13 00:12:30
We should allow a new session even if the laser is
sammiequon
2016/10/14 18:48:50
Yeah that expression never happens, so it was work
|
| return; |
| } |
| - // This will handle creating the initial laser pointer view on |
| - // ET_MOUSE_PRESSED events. |
| - SwitchTargetRootWindowIfNeeded(GetCurrentRootWindow()); |
| + // If the stylus is pressed and the laser pointer view is currently active, |
| + // create a new view. |
| + if (event->type() == ui::ET_MOUSE_PRESSED) |
| + DestroyLaserPointerView(); |
| - if (laser_pointer_view_) { |
| - // Remap point from where it was captured to the display it is actually on. |
| - gfx::Point event_location = event->root_location(); |
| - aura::Window* target = static_cast<aura::Window*>(event->target()); |
| - aura::Window* event_root = target->GetRootWindow(); |
| - aura::Window::ConvertPointToTarget( |
| - event_root, laser_pointer_view_->GetRootWindow(), &event_location); |
| + SwitchTargetRootWindowIfNeeded(current_window); |
|
jdufault
2016/10/13 00:12:30
I think this code would be much easier if the impl
sammiequon
2016/10/14 18:48:50
Done.
|
| + if (laser_pointer_view_) { |
| current_mouse_location_ = event_location; |
| - laser_pointer_view_->AddNewPoint(current_mouse_location_); |
| + // Signal the view to start fading away if the mouse has been released. |
| + is_fading_away_ = event->type() == ui::ET_MOUSE_RELEASED; |
| + if (is_fading_away_) |
| + laser_pointer_view_->UpdateTime(); |
| + else |
| + laser_pointer_view_->AddNewPoint(current_mouse_location_); |
| stationary_timer_repeat_count_ = 0; |
| - if (event->type() == ui::ET_MOUSE_DRAGGED) { |
| - // Start the timer to add stationary points if dragged. |
| + if (event->type() == ui::ET_MOUSE_DRAGGED || |
| + event->type() == ui::ET_MOUSE_RELEASED) { |
| + // Start the timer to add stationary points if dragged, or to advance the |
| + // internal collections timestamps if released. |
| if (!stationary_timer_->IsRunning()) |
| stationary_timer_->Reset(); |
| } |
| - |
| - // If the stylus is over the palette icon or widget, do not consume the |
| - // event. |
| - if (!PaletteContainsPointInScreen(current_mouse_location_)) |
| - event->StopPropagation(); |
| } |
| + event->StopPropagation(); |
| } |
| void LaserPointerController::OnWindowDestroying(aura::Window* window) { |
| @@ -117,8 +130,7 @@ void LaserPointerController::OnWindowDestroying(aura::Window* window) { |
| void LaserPointerController::SwitchTargetRootWindowIfNeeded( |
| aura::Window* root_window) { |
| if (!root_window) { |
| - stationary_timer_->Stop(); |
| - laser_pointer_view_.reset(); |
| + DestroyLaserPointerView(); |
| } else if (laser_pointer_view_) { |
| laser_pointer_view_->ReparentWidget(root_window); |
| } else if (enabled_) { |
| @@ -127,13 +139,31 @@ void LaserPointerController::SwitchTargetRootWindowIfNeeded( |
| } |
| } |
| +void LaserPointerController::DestroyLaserPointerView() { |
| + // |stationary_timer_| should also be stopped so that it does not attempt to |
| + // add points when |laser_pointer_view_| is null. |
| + stationary_timer_->Stop(); |
| + if (laser_pointer_view_) { |
| + is_fading_away_ = false; |
| + laser_pointer_view_.reset(); |
| + } |
| +} |
| + |
| void LaserPointerController::AddStationaryPoint() { |
| - laser_pointer_view_->AddNewPoint(current_mouse_location_); |
| + if (is_fading_away_) |
| + laser_pointer_view_->UpdateTime(); |
| + else |
| + laser_pointer_view_->AddNewPoint(current_mouse_location_); |
| + |
| // We can stop repeating the timer once the mouse has been stationary for |
| // longer than the life of a point. |
| if (stationary_timer_repeat_count_ * kAddStationaryPointsDelayMs >= |
| kPointLifeDurationMs) { |
| stationary_timer_->Stop(); |
| + // Reset the view if the timer expires and the view was in process of fading |
| + // away. |
| + if (is_fading_away_) |
| + DestroyLaserPointerView(); |
| } |
| stationary_timer_repeat_count_++; |
| } |