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

Unified 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 side-by-side diff with in-line comments
Download patch
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..d595229d405dcdcd3d495043393e372b873ee469 100644
--- a/ash/laser/laser_pointer_controller.cc
+++ b/ash/laser/laser_pointer_controller.cc
@@ -73,41 +73,55 @@ 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();
+
+ // 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.
+ // not.
+ if (!current_window) {
+ DestroyLaserPointerView();
return;
}
- // This will handle creating the initial laser pointer view on
- // ET_MOUSE_PRESSED events.
- SwitchTargetRootWindowIfNeeded(GetCurrentRootWindow());
+ // 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);
+
+ // If the stylus is pressed and the laser pointer view is currently active,
+ // create a new view.
+ if (event->type() == ui::ET_MOUSE_PRESSED) {
+ // Do not start a new laser session if the event is over the
+ // palette.
+ if (PaletteContainsPointInScreen(event_location))
+ return;
+
+ 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/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
+ 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 +131,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 +140,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_++;
}

Powered by Google App Engine
This is Rietveld 408576698