Chromium Code Reviews| 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 // 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 over the palette icon or widget do not display the laser, | |
|
jdufault
2016/10/05 18:08:51
I would say something like
// Do not start active
sammiequon
2016/10/05 21:15:22
Done.
| |
| 94 // unless it is in the process of being faded away. | |
| 95 if ((!laser_pointer_view_ || is_fading_away_) && | |
|
jdufault
2016/10/05 18:08:50
This logic is only applicable for ui::ET_MOUSE_PRE
sammiequon
2016/10/05 21:15:21
If SwitchTargetRootWindowIfNeeded is not outside t
| |
| 96 PaletteContainsPointInScreen(event_location)) { | |
| 97 return; | |
| 98 } | |
| 99 | |
| 100 // If the stylus is pressed and the laser pointer view is currently active, | |
| 101 // create a new view and stop the timer. | |
| 102 if (event->type() == ui::ET_MOUSE_PRESSED) | |
| 103 DestroyLaserPointerView(); | |
| 104 | |
| 105 SwitchTargetRootWindowIfNeeded(current_window); | |
| 87 | 106 |
| 88 if (laser_pointer_view_) { | 107 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; | 108 current_mouse_location_ = event_location; |
| 97 laser_pointer_view_->AddNewPoint(current_mouse_location_); | 109 // Signal the view to start fading away if the mouse has been released. |
| 110 is_fading_away_ = event->type() == ui::ET_MOUSE_RELEASED; | |
| 111 laser_pointer_view_->AddNewPoint(current_mouse_location_, is_fading_away_); | |
| 98 | 112 |
| 99 stationary_timer_repeat_count_ = 0; | 113 stationary_timer_repeat_count_ = 0; |
| 100 if (event->type() == ui::ET_MOUSE_DRAGGED) { | 114 if (event->type() == ui::ET_MOUSE_DRAGGED || |
| 101 // Start the timer to add stationary points if dragged. | 115 event->type() == ui::ET_MOUSE_RELEASED) { |
| 116 // Start the timer to add stationary points if dragged, or to advance the | |
| 117 // internal collections timestamps if released. | |
| 102 if (!stationary_timer_->IsRunning()) | 118 if (!stationary_timer_->IsRunning()) |
| 103 stationary_timer_->Reset(); | 119 stationary_timer_->Reset(); |
| 104 } | 120 } |
| 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 } | 121 } |
| 122 event->StopPropagation(); | |
| 111 } | 123 } |
| 112 | 124 |
| 113 void LaserPointerController::OnWindowDestroying(aura::Window* window) { | 125 void LaserPointerController::OnWindowDestroying(aura::Window* window) { |
| 114 SwitchTargetRootWindowIfNeeded(window); | 126 SwitchTargetRootWindowIfNeeded(window); |
| 115 } | 127 } |
| 116 | 128 |
| 117 void LaserPointerController::SwitchTargetRootWindowIfNeeded( | 129 void LaserPointerController::SwitchTargetRootWindowIfNeeded( |
| 118 aura::Window* root_window) { | 130 aura::Window* root_window) { |
| 119 if (!root_window) { | 131 if (!root_window) { |
| 120 stationary_timer_->Stop(); | 132 DestroyLaserPointerView(); |
| 121 laser_pointer_view_.reset(); | |
| 122 } else if (laser_pointer_view_) { | 133 } else if (laser_pointer_view_) { |
| 123 laser_pointer_view_->ReparentWidget(root_window); | 134 laser_pointer_view_->ReparentWidget(root_window); |
| 124 } else if (enabled_) { | 135 } else if (enabled_) { |
| 125 laser_pointer_view_.reset(new LaserPointerView( | 136 laser_pointer_view_.reset(new LaserPointerView( |
| 126 base::TimeDelta::FromMilliseconds(kPointLifeDurationMs), root_window)); | 137 base::TimeDelta::FromMilliseconds(kPointLifeDurationMs), root_window)); |
| 127 } | 138 } |
| 128 } | 139 } |
| 129 | 140 |
| 141 void LaserPointerController::DestroyLaserPointerView() { | |
| 142 // |stationary_timer_| should also be stopped so that it does not attempt to | |
| 143 // add points when |laser_pointer_view_| is null. | |
| 144 stationary_timer_->Stop(); | |
| 145 if (laser_pointer_view_) { | |
| 146 is_fading_away_ = false; | |
| 147 laser_pointer_view_.reset(); | |
| 148 } | |
| 149 } | |
| 150 | |
| 130 void LaserPointerController::AddStationaryPoint() { | 151 void LaserPointerController::AddStationaryPoint() { |
| 131 laser_pointer_view_->AddNewPoint(current_mouse_location_); | 152 laser_pointer_view_->AddNewPoint(current_mouse_location_, is_fading_away_); |
| 132 // We can stop repeating the timer once the mouse has been stationary for | 153 // We can stop repeating the timer once the mouse has been stationary for |
| 133 // longer than the life of a point. | 154 // longer than the life of a point. |
| 134 if (stationary_timer_repeat_count_ * kAddStationaryPointsDelayMs >= | 155 if (stationary_timer_repeat_count_ * kAddStationaryPointsDelayMs >= |
| 135 kPointLifeDurationMs) { | 156 kPointLifeDurationMs) { |
| 136 stationary_timer_->Stop(); | 157 stationary_timer_->Stop(); |
| 158 // Reset the view if the timer expires and the view was in process of fading | |
| 159 // away. | |
| 160 if (is_fading_away_) | |
| 161 DestroyLaserPointerView(); | |
| 137 } | 162 } |
| 138 stationary_timer_repeat_count_++; | 163 stationary_timer_repeat_count_++; |
| 139 } | 164 } |
| 140 } // namespace ash | 165 } // namespace ash |
| OLD | NEW |