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 80% |
rename from ash/common/system/chromeos/palette/tools/laser_pointer_view.cc |
rename to ash/laser/laser_pointer_view.cc |
index 3a826baa33c0b31110a7fe95b6921f9e9b5e04c9..722220e1000e5e938763507e2c15bd35b4e69764 100644 |
--- a/ash/common/system/chromeos/palette/tools/laser_pointer_view.cc |
+++ b/ash/laser/laser_pointer_view.cc |
@@ -2,27 +2,33 @@ |
// 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. |
James Cook
2016/09/14 17:52:28
Thanks for specifying dip.
sammiequon
2016/09/14 21:44:10
Jacob caught that.
|
const double kPointInitialRadius = 5; |
const double kPointFinalRadius = 0.25; |
const int kPointInitialOpacity = 200; |
const int kPointFinalOpacity = 0; |
const SkColor kPointColor = SkColorSetRGB(255, 0, 0); |
+// Name of the laser overlay. |
+const char kPartialMagniferWindowName[] = "LaserOverlay"; |
+ |
float DistanceBetweenPoints(const gfx::Point& point1, |
const gfx::Point& point2) { |
return (point1 - point2).Length(); |
@@ -39,21 +45,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 = kPartialMagniferWindowName; |
James Cook
2016/09/14 17:52:28
optional: I'm OK with these names being inlined in
sammiequon
2016/09/14 21:44:10
Done.
|
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; |
+ |
widget_->Init(params); |
widget_->Show(); |
widget_->SetContentsView(this); |
@@ -67,6 +71,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 +101,13 @@ 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 root_window_bounds = |
James Cook
2016/09/14 17:52:29
A point is not a bounds. Do you mean origin?
sammiequon
2016/09/14 21:44:10
Done.
|
+ widget_->GetNativeView()->GetRootWindow()->GetBoundsInScreen().origin(); |
+ gfx::Point widget_bounds = widget_->GetWindowBoundsInScreen().origin(); |
+ gfx::Point offset = gfx::Point(widget_bounds.x() - root_window_bounds.x(), |
James Cook
2016/09/14 17:52:28
Are you trying to compute the widget's position in
sammiequon
2016/09/14 21:44:10
Yes, thanks! This makes it so much simpler.
|
+ widget_bounds.y() - root_window_bounds.y()); |
int num_points_ = laser_points_.GetNumberOfPoints(); |
int point_count = 0; |
for (const LaserPointerPoints::LaserPoint& point : |
@@ -110,7 +124,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 +146,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); |