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

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

Issue 2239743004: Palette tool laser prototype. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@patch
Patch Set: Refactored drawing code. 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..20f4d9ab03c4846a23910e62a7584e13f2ad765e
--- /dev/null
+++ b/ash/common/system/chromeos/palette/tools/laser_pointer_mode.cc
@@ -0,0 +1,108 @@
+// 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/palette_delegate.h"
+#include "ash/common/system/chromeos/palette/palette_ids.h"
+#include "ash/common/system/chromeos/palette/tools/laser_pointer_view.h"
+#include "ash/common/wm_shell.h"
+#include "grit/ash_strings.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/wm/core/coordinate_conversion.h"
+#include "ui/wm/core/cursor_manager.h"
+
+namespace ash {
+namespace {
+const int kPointLifeDurationMs = 200;
+const int kAddStationaryPointsDelayMs = 5;
oshima 2016/08/24 23:01:03 please document these variables, and please keep a
sammiequon 2016/08/25 17:59:04 Done.
+} // namespace
+
+LaserPointerMode::LaserPointerMode(Delegate* delegate)
+ : CommonPaletteTool(delegate) {
+ laser_pointer_view_.reset(new LaserPointerView(
+ base::TimeDelta::FromMilliseconds(kPointLifeDurationMs)));
+ timer_.reset(new base::Timer(
+ FROM_HERE, base::TimeDelta::FromMilliseconds(kAddStationaryPointsDelayMs),
+ base::Bind(&LaserPointerMode::AddStationaryPoint, base::Unretained(this)),
+ true));
+ WmShell::Get()->AddPointerWatcher(this, true);
+}
+
+LaserPointerMode::~LaserPointerMode() {
+ StopTimer();
+ WmShell::Get()->RemovePointerWatcher(this);
oshima 2016/08/24 23:01:03 q: No need to disable?
sammiequon 2016/08/25 17:59:04 Done.
+}
+
+PaletteGroup LaserPointerMode::GetGroup() const {
+ return PaletteGroup::MODE;
+}
+
+PaletteToolId LaserPointerMode::GetToolId() const {
+ return PaletteToolId::LASER_POINTER;
+}
+
+void LaserPointerMode::OnEnable() {
+ CommonPaletteTool::OnEnable();
+
+ // TODO(sammiequon): Remove check and set palette delegate to test delegate
oshima 2016/08/24 23:01:03 which check?
sammiequon 2016/08/25 17:59:04 Done.
+ // once test delegate CL lands.
+ WmShell::Get()->palette_delegate()->OnLaserPointerEnabled();
+ laser_pointer_view_->AddNewPoint(current_mouse_location_);
+}
+
+void LaserPointerMode::OnDisable() {
+ CommonPaletteTool::OnDisable();
+
+ WmShell::Get()->palette_delegate()->OnLaserPointerDisabled();
+ StopTimer();
+ 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;
+}
+
+views::View* LaserPointerMode::CreateView() {
+ return CreateDefaultView(
+ l10n_util::GetStringUTF16(IDS_ASH_PALETTE_LASER_POINTER_MODE));
+}
+
+void LaserPointerMode::StopTimer() {
+ timer_repeat_count_ = 0;
+ timer_->Stop();
+}
+
+void LaserPointerMode::AddStationaryPoint() {
+ 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 (timer_repeat_count_++ * kAddStationaryPointsDelayMs >=
+ kPointLifeDurationMs) {
+ StopTimer();
+ }
+}
+
+void LaserPointerMode::OnPointerEventObserved(
+ const ui::PointerEvent& event,
+ const gfx::Point& location_in_screen,
+ views::Widget* target) {
+ // TODO(sammiequon): Add support for pointer drags. See crbug.com/640410.
+ if (event.type() == ui::ET_POINTER_MOVED &&
+ event.pointer_details().pointer_type ==
+ ui::EventPointerType::POINTER_TYPE_PEN) {
+ current_mouse_location_ = location_in_screen;
oshima 2016/08/24 23:01:03 am i correct that it always start recording when t
sammiequon 2016/08/25 17:59:04 Yes it constantly updates even while the laser is
+ if (enabled()) {
+ laser_pointer_view_->AddNewPoint(current_mouse_location_);
+ timer_repeat_count_ = 0;
+ if (!timer_->IsRunning())
+ timer_->Reset();
+ }
+ }
+}
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698