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

Unified Diff: ash/common/system/chromeos/palette/tools/laser_pointer_mode.cc

Issue 2231533004: Pointer watcher modifications to support laser pointer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Created 4 years, 4 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/common/system/chromeos/palette/tools/laser_pointer_mode.cc
diff --git a/ash/common/system/chromeos/palette/tools/laser_pointer_mode.cc b/ash/common/system/chromeos/palette/tools/laser_pointer_mode.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ea2f6826f6929563bd3b7886a1df7040a946a35d
--- /dev/null
+++ b/ash/common/system/chromeos/palette/tools/laser_pointer_mode.cc
@@ -0,0 +1,137 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/common/system/chromeos/palette/tools/laser_pointer_mode.h"
+
+#include "ash/common/system/chromeos/palette/palette_ids.h"
+#include "ash/common/wm_shell.h"
+#include "ash/shell.h"
+#include "ui/wm/core/coordinate_conversion.h"
+#include "ui/wm/core/cursor_manager.h"
+
+namespace ash {
+
+const int LaserPointerMode::kPointLifeDurationMs = 300;
+const int LaserPointerMode::kAddStationaryPointsDelayMs = 10;
+
+LaserPointerMode::LaserPointerMode(Delegate* delegate)
+ : CommonPaletteTool(delegate),
+ timer_repeat_count_(0),
+ laser_points_(
+ base::TimeDelta::FromMilliseconds(int{kPointLifeDurationMs})) {
+ laser_pointer_view_ = new LaserPointerView();
+ InitializeTimer();
+ Shell::GetInstance()->AddPreTargetHandler(this);
+}
+
+LaserPointerMode::~LaserPointerMode() {
+ Shell::GetInstance()->RemovePreTargetHandler(this);
+}
+
+PaletteGroup LaserPointerMode::GetGroup() const {
+ return PaletteGroup::MODE;
+}
+
+PaletteToolId LaserPointerMode::GetToolId() const {
+ return PaletteToolId::LASER_POINTER;
+}
+
+void LaserPointerMode::OnEnable() {
+ CommonPaletteTool::OnEnable();
+ //WmShell::Get()->cursor_manager()->HideCursor();
+ // We lock the cursor after we hide it because it is always being updated by
+ // compound_event_filter.cc to be shown on every mouse movement.
+ //WmShell::Get()->cursor_manager()->LockCursor();
+ laser_points_.AddPoint(current_mouse_location_);
+ laser_pointer_view_->SetNewPoints(laser_points_);
+}
+
+void LaserPointerMode::OnDisable() {
+ CommonPaletteTool::OnDisable();
+ //WmShell::Get()->cursor_manager()->UnlockCursor();
+ //WmShell::Get()->cursor_manager()->ShowCursor();
+ StopTimer();
+ // Clear the points and then notify the view that there is nothing to be
+ // rendered.
+ laser_points_.Clear();
+ laser_pointer_view_->Stop();
+}
+
+gfx::VectorIconId LaserPointerMode::GetActiveTrayIcon() {
+ return gfx::VectorIconId::PALETTE_TRAY_ICON_LASER_POINTER;
+}
+
+gfx::VectorIconId LaserPointerMode::GetPaletteIconId() {
+ return gfx::VectorIconId::PALETTE_MODE_LASER_POINTER;
+}
+
+void LaserPointerMode::InitializeTimer() {
+ timer_.reset(new base::Timer(
+ FROM_HERE,
+ base::TimeDelta::FromMilliseconds(kAddStationaryPointsDelayMs),
+ base::Bind(&LaserPointerMode::AddStationaryPoint,
+ base::Unretained(this)),
+ false));
+}
+
+void LaserPointerMode::StartTimer() {
+ timer_->Reset();
+}
+
+void LaserPointerMode::StopTimer() {
+ points_lock_.Acquire();
+ timer_repeat_count_ = 0;
+ points_lock_.Release();
+ timer_->Stop();
+}
+
+void LaserPointerMode::AddStationaryPoint() {
+ points_lock_.Acquire();
+ laser_points_.AddPoint(current_mouse_location_);
+ laser_pointer_view_->SetNewPoints(laser_points_);
+ int count = timer_repeat_count_;
+ points_lock_.Release();
+ // We can stop repeating the timer once the mouse has been stationary for
+ // longer than the life of a point.
+ if (count * kAddStationaryPointsDelayMs < kPointLifeDurationMs) {
+ timer_repeat_count_++;
+ timer_->Reset();
+ } else {
+ StopTimer();
+ }
+}
+
+void LaserPointerMode::OnMouseEvent(ui::MouseEvent* event) {
+ if (event->type() == ui::ET_MOUSE_MOVED &&
+ !(event->flags() & ui::EF_IS_SYNTHESIZED)) {
+
+ gfx::Point mouse_location = event->location();
+ ::wm::ConvertPointToScreen(static_cast<aura::Window*>(event->target()),
+ &mouse_location);
+ current_mouse_location_ = mouse_location;
+ if (enabled()) {
+ points_lock_.Acquire();
+ // Add the new point and notify the queue.
+ laser_points_.AddPoint(mouse_location);
+ laser_pointer_view_->SetNewPoints(laser_points_);
+ timer_repeat_count_ = 0;
+ points_lock_.Release();
+ StartTimer();
+ }
+ }
+}
+
+void LaserPointerMode::OnKeyEvent(ui::KeyEvent* event) {
+}
+
+void LaserPointerMode::OnTouchEvent(ui::TouchEvent* event) {
+}
+
+void LaserPointerMode::OnGestureEvent(ui::GestureEvent* event) {
+}
+
+void LaserPointerMode::OnScrollEvent(ui::ScrollEvent* event) {
+}
+
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698