Index: ash/laser/laser_pointer_view.cc |
diff --git a/ash/common/system/chromeos/palette/tools/laser_pointer_view.cc b/ash/laser/laser_pointer_view.cc |
similarity index 86% |
rename from ash/common/system/chromeos/palette/tools/laser_pointer_view.cc |
rename to ash/laser/laser_pointer_view.cc |
index 3a826baa33c0b31110a7fe95b6921f9e9b5e04c9..f6a381957a838574477052d3f22a8e2ef7cda3f8 100644 |
--- a/ash/common/system/chromeos/palette/tools/laser_pointer_view.cc |
+++ b/ash/laser/laser_pointer_view.cc |
@@ -2,21 +2,24 @@ |
// 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_view.h" |
+#include "ash/laser/laser_pointer_view.h" |
#include <memory> |
#include "ash/common/shell_window_ids.h" |
-#include "ash/common/wm_root_window_controller.h" |
-#include "ash/common/wm_shell.h" |
-#include "ash/common/wm_window.h" |
+#include "ash/laser/laser_pointer_points.h" |
+#include "base/timer/timer.h" |
#include "third_party/skia/include/core/SkColor.h" |
#include "third_party/skia/include/core/SkPaint.h" |
+#include "ui/aura/window.h" |
+#include "ui/events/event.h" |
#include "ui/gfx/canvas.h" |
+#include "ui/views/widget/widget.h" |
namespace ash { |
namespace { |
+// Variables for rendering the laser. Radius in DIP. |
const double kPointInitialRadius = 5; |
const double kPointFinalRadius = 0.25; |
const int kPointInitialOpacity = 200; |
@@ -39,21 +42,19 @@ double LinearInterpolate(double initial_value, |
//////////////////////////////////////////////////////////////////////////////// |
// LaserPointerView |
-LaserPointerView::LaserPointerView(base::TimeDelta life_duration) |
+LaserPointerView::LaserPointerView(base::TimeDelta life_duration, |
+ aura::Window* root_window) |
: laser_points_(life_duration) { |
widget_.reset(new views::Widget); |
views::Widget::InitParams params; |
params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS; |
- params.name = "LaserOverlay"; |
+ params.name = "Laser Overlay"; |
params.accept_events = false; |
params.activatable = views::Widget::InitParams::ACTIVATABLE_NO; |
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
- WmShell::Get() |
- ->GetRootWindowForNewWindows() |
- ->GetRootWindowController() |
- ->ConfigureWidgetInitParamsForContainer( |
- widget_.get(), kShellWindowId_OverlayContainer, ¶ms); |
+ params.parent = root_window; |
James Cook
2016/09/14 22:53:38
I think this is wrong. I didn't notice before beca
sammiequon
2016/09/16 17:35:26
Done.
|
+ |
widget_->Init(params); |
widget_->Show(); |
widget_->SetContentsView(this); |
@@ -67,6 +68,10 @@ void LaserPointerView::Stop() { |
SchedulePaint(); |
} |
+aura::Window* LaserPointerView::GetRootWindow() { |
+ return widget_->GetNativeView()->GetRootWindow(); |
+} |
+ |
void LaserPointerView::AddNewPoint(const gfx::Point& new_point) { |
laser_points_.AddPoint(new_point); |
// Expand the bounding box so that it includes the radius of the points on the |
@@ -93,7 +98,10 @@ void LaserPointerView::OnPaint(gfx::Canvas* canvas) { |
base::Time newest = laser_points_.GetNewest().creation_time; |
gfx::Point previous_point = laser_points_.GetOldest().location; |
gfx::Point current_point; |
- gfx::Rect widget_bounds = widget_->GetWindowBoundsInScreen(); |
+ |
+ // Compute the offset of the current widget. |
+ gfx::Point offset = |
James Cook
2016/09/14 22:53:38
how about |widget_offset| or |widget_origin| ?
sammiequon
2016/09/16 17:35:26
Done.
|
+ widget_->GetNativeView()->GetBoundsInRootWindow().origin(); |
int num_points_ = laser_points_.GetNumberOfPoints(); |
int point_count = 0; |
for (const LaserPointerPoints::LaserPoint& point : |
@@ -110,7 +118,7 @@ void LaserPointerView::OnPaint(gfx::Canvas* canvas) { |
double radius = LinearInterpolate(kPointInitialRadius, kPointFinalRadius, |
relative_time); |
- gfx::Vector2d center = point.location - widget_bounds.origin(); |
+ gfx::Vector2d center = point.location - offset; |
current_point = gfx::Point(center.x(), center.y()); |
// If we draw laser_points_ that are within a stroke width of each other, |
@@ -132,6 +140,7 @@ void LaserPointerView::OnPaint(gfx::Canvas* canvas) { |
canvas->DrawLine(previous_point, current_point, paint); |
previous_point = current_point; |
} |
+ // Draw the last point as a circle. |
paint.setColor(SkColorSetA(kPointColor, kPointInitialOpacity)); |
paint.setStyle(SkPaint::kFill_Style); |
canvas->DrawCircle(current_point, kPointInitialRadius, paint); |