Chromium Code Reviews| Index: ui/views/controls/touch/touch_hud_drawer.cc |
| diff --git a/ash/touch/touch_hud_projection.cc b/ui/views/controls/touch/touch_hud_drawer.cc |
| similarity index 69% |
| copy from ash/touch/touch_hud_projection.cc |
| copy to ui/views/controls/touch/touch_hud_drawer.cc |
| index 02f604ef8d72543e6bb78242274de5c29a37161a..0779e1060e2d6606816908eac680435f0de3d565 100644 |
| --- a/ash/touch/touch_hud_projection.cc |
| +++ b/ui/views/controls/touch/touch_hud_drawer.cc |
| @@ -1,22 +1,22 @@ |
| -// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// 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/touch/touch_hud_projection.h" |
| +#include "ui/views/controls/touch/touch_hud_drawer.h" |
| -#include "ash/root_window_controller.h" |
| -#include "ash/shell.h" |
| #include "third_party/skia/include/effects/SkGradientShader.h" |
| #include "ui/events/event.h" |
| #include "ui/gfx/animation/animation_delegate.h" |
| #include "ui/gfx/animation/linear_animation.h" |
| #include "ui/gfx/canvas.h" |
| #include "ui/gfx/geometry/size.h" |
| +#include "ui/views/view.h" |
| #include "ui/views/widget/widget.h" |
| +#include "ui/views/widget/widget_observer.h" |
| -namespace ash { |
| +namespace views { |
| -const int kPointRadius = 20; |
| +const int kPointRadius = 40; |
| const SkColor kProjectionFillColor = SkColorSetRGB(0xF5, 0xF5, 0xDC); |
| const SkColor kProjectionStrokeColor = SK_ColorGRAY; |
| const int kProjectionAlpha = 0xB0; |
| @@ -26,13 +26,14 @@ const int kFadeoutFrameRate = 60; |
| // TouchPointView draws a single touch point. This object manages its own |
| // lifetime and deletes itself upon fade-out completion or whenever |Remove()| |
| // is explicitly called. |
| -class TouchPointView : public views::View, |
| +class TouchPointView : public View, |
| public gfx::AnimationDelegate, |
| - public views::WidgetObserver { |
| + public WidgetObserver { |
| public: |
| - explicit TouchPointView(views::Widget* parent_widget) |
| + explicit TouchPointView(Widget* parent_widget) |
| : circle_center_(kPointRadius + 1, kPointRadius + 1), |
| - gradient_center_(SkPoint::Make(kPointRadius + 1, kPointRadius + 1)) { |
| + gradient_center_(SkPoint::Make(kPointRadius + 1, |
| + kPointRadius + 1)) { |
| SetPaintToLayer(true); |
| layer()->SetFillsBoundsOpaquely(false); |
| @@ -52,20 +53,25 @@ class TouchPointView : public views::View, |
| parent_widget->AddObserver(this); |
| } |
| - void UpdateTouch(const ui::TouchEvent& touch) { |
| + void UpdateTouch(const ui::LocatedEvent& touch) { |
| if (touch.type() == ui::ET_TOUCH_RELEASED || |
| - touch.type() == ui::ET_TOUCH_CANCELLED) { |
| + touch.type() == ui::ET_TOUCH_CANCELLED || |
| + touch.type() == ui::ET_POINTER_UP || |
| + touch.type() == ui::ET_POINTER_CANCELLED) { |
| fadeout_.reset(new gfx::LinearAnimation(kFadeoutDurationInMs, |
| - kFadeoutFrameRate, this)); |
| + kFadeoutFrameRate, |
| + this)); |
| fadeout_->Start(); |
| } else { |
| SetX(parent()->GetMirroredXInView(touch.root_location().x()) - |
| - kPointRadius - 1); |
| + kPointRadius - 1); |
| SetY(touch.root_location().y() - kPointRadius - 1); |
| } |
| } |
| - void Remove() { delete this; } |
| + void Remove() { |
|
sky
2016/07/06 16:31:30
nit: Remove() is rather confusing given this funct
riajiang
2016/07/06 20:30:43
Done.
|
| + delete this; |
| + } |
| private: |
| ~TouchPointView() override { |
| @@ -126,24 +132,31 @@ class TouchPointView : public views::View, |
| DISALLOW_COPY_AND_ASSIGN(TouchPointView); |
| }; |
| -TouchHudProjection::TouchHudProjection(aura::Window* initial_root) |
| - : TouchObserverHUD(initial_root) {} |
| +TouchHudDrawer::TouchHudDrawer() {} |
| -TouchHudProjection::~TouchHudProjection() {} |
| +TouchHudDrawer::~TouchHudDrawer() {} |
| -void TouchHudProjection::Clear() { |
| +void TouchHudDrawer::Clear() { |
| for (std::map<int, TouchPointView*>::iterator iter = points_.begin(); |
| - iter != points_.end(); iter++) |
| + iter != points_.end(); iter++) |
| iter->second->Remove(); |
| points_.clear(); |
| } |
| -void TouchHudProjection::OnTouchEvent(ui::TouchEvent* event) { |
| - if (event->type() == ui::ET_TOUCH_PRESSED) { |
| - TouchPointView* point = new TouchPointView(widget()); |
| +void TouchHudDrawer::HandleTouchEvent(const ui::LocatedEvent* event, |
| + Widget* parent_widget) { |
| + int id = 0; |
| + if (event->IsTouchEvent()) { |
| + id = event->AsTouchEvent()->touch_id(); |
| + } else if (event->IsPointerEvent()) { |
| + id = event->AsPointerEvent()->pointer_id(); |
| + } |
| + if (event->type() == ui::ET_TOUCH_PRESSED || |
| + event->type() == ui::ET_POINTER_DOWN) { |
| + TouchPointView* point = new TouchPointView(parent_widget); |
| point->UpdateTouch(*event); |
| std::pair<std::map<int, TouchPointView*>::iterator, bool> result = |
| - points_.insert(std::make_pair(event->touch_id(), point)); |
| + points_.insert(std::make_pair(id, point)); |
| // If a |TouchPointView| is already mapped to the touch id, remove it and |
| // replace it with the new one. |
| if (!result.second) { |
| @@ -151,25 +164,16 @@ void TouchHudProjection::OnTouchEvent(ui::TouchEvent* event) { |
| result.first->second = point; |
| } |
| } else { |
| - std::map<int, TouchPointView*>::iterator iter = |
| - points_.find(event->touch_id()); |
| + std::map<int, TouchPointView*>::iterator iter = points_.find(id); |
| if (iter != points_.end()) { |
| iter->second->UpdateTouch(*event); |
| if (event->type() == ui::ET_TOUCH_RELEASED || |
| - event->type() == ui::ET_TOUCH_CANCELLED) |
| + event->type() == ui::ET_TOUCH_CANCELLED || |
| + event->type() == ui::ET_POINTER_UP || |
| + event->type() == ui::ET_POINTER_CANCELLED) |
| points_.erase(iter); |
| } |
| } |
| } |
| -void TouchHudProjection::SetHudForRootWindowController( |
| - RootWindowController* controller) { |
| - controller->set_touch_hud_projection(this); |
| -} |
| - |
| -void TouchHudProjection::UnsetHudForRootWindowController( |
| - RootWindowController* controller) { |
| - controller->set_touch_hud_projection(NULL); |
| -} |
| - |
| -} // namespace ash |
| +} // namespace views |