Chromium Code Reviews| 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 81% |
| rename from ash/common/system/chromeos/palette/tools/laser_pointer_view.cc |
| rename to ash/laser/laser_pointer_view.cc |
| index 3a826baa33c0b31110a7fe95b6921f9e9b5e04c9..e30fb8b1c5c084ed44f0ec4af18c975045d48248 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. |
|
jdufault
2016/09/12 21:10:12
Specify units of the radius variables
sammiequon
2016/09/13 01:09:56
Done.
|
| 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; |
| 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,12 @@ 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. |
|
jdufault
2016/09/12 21:10:12
offset of what?
sammiequon
2016/09/13 01:09:56
Done.
|
| + gfx::Point root_window_bounds = |
| + widget_->GetNativeView()->GetRootWindow()->GetBoundsInScreen().origin(); |
| + gfx::Point widget_bounds = widget_->GetWindowBoundsInScreen().origin(); |
| + gfx::Point offset = gfx::Point(widget_bounds.x() - root_window_bounds.x(), |
| + widget_bounds.y() - root_window_bounds.y()); |
| int num_points_ = laser_points_.GetNumberOfPoints(); |
| int point_count = 0; |
| for (const LaserPointerPoints::LaserPoint& point : |
| @@ -110,7 +123,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 +145,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); |