| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/touch/touch_hud_projection.h" | 5 #include "ui/views/controls/touch/touch_hud_drawer.h" |
| 6 | 6 |
| 7 #include "ash/root_window_controller.h" | |
| 8 #include "ash/shell.h" | |
| 9 #include "third_party/skia/include/effects/SkGradientShader.h" | 7 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 10 #include "ui/events/event.h" | 8 #include "ui/events/event.h" |
| 11 #include "ui/gfx/animation/animation_delegate.h" | 9 #include "ui/gfx/animation/animation_delegate.h" |
| 12 #include "ui/gfx/animation/linear_animation.h" | 10 #include "ui/gfx/animation/linear_animation.h" |
| 13 #include "ui/gfx/canvas.h" | 11 #include "ui/gfx/canvas.h" |
| 14 #include "ui/gfx/geometry/size.h" | 12 #include "ui/gfx/geometry/size.h" |
| 13 #include "ui/views/view.h" |
| 15 #include "ui/views/widget/widget.h" | 14 #include "ui/views/widget/widget.h" |
| 15 #include "ui/views/widget/widget_observer.h" |
| 16 | 16 |
| 17 namespace ash { | 17 namespace views { |
| 18 | 18 |
| 19 const int kPointRadius = 20; | 19 const int kPointRadius = 20; |
| 20 const SkColor kProjectionFillColor = SkColorSetRGB(0xF5, 0xF5, 0xDC); | 20 const SkColor kProjectionFillColor = SkColorSetRGB(0xF5, 0xF5, 0xDC); |
| 21 const SkColor kProjectionStrokeColor = SK_ColorGRAY; | 21 const SkColor kProjectionStrokeColor = SK_ColorGRAY; |
| 22 const int kProjectionAlpha = 0xB0; | 22 const int kProjectionAlpha = 0xB0; |
| 23 const int kFadeoutDurationInMs = 250; | 23 const int kFadeoutDurationInMs = 250; |
| 24 const int kFadeoutFrameRate = 60; | 24 const int kFadeoutFrameRate = 60; |
| 25 | 25 |
| 26 // TouchPointView draws a single touch point. This object manages its own | 26 // TouchPointView draws a single touch point. This object manages its own |
| 27 // lifetime and deletes itself upon fade-out completion or whenever |Remove()| | 27 // lifetime and deletes itself upon fade-out completion or whenever |Remove()| |
| 28 // is explicitly called. | 28 // is explicitly called. |
| 29 class TouchPointView : public views::View, | 29 class TouchPointView : public View, |
| 30 public gfx::AnimationDelegate, | 30 public gfx::AnimationDelegate, |
| 31 public views::WidgetObserver { | 31 public WidgetObserver { |
| 32 public: | 32 public: |
| 33 explicit TouchPointView(views::Widget* parent_widget) | 33 explicit TouchPointView(Widget* parent_widget) |
| 34 : circle_center_(kPointRadius + 1, kPointRadius + 1), | 34 : circle_center_(kPointRadius + 1, kPointRadius + 1), |
| 35 gradient_center_(SkPoint::Make(kPointRadius + 1, | 35 gradient_center_(SkPoint::Make(kPointRadius + 1, |
| 36 kPointRadius + 1)) { | 36 kPointRadius + 1)) { |
| 37 SetPaintToLayer(true); | 37 SetPaintToLayer(true); |
| 38 layer()->SetFillsBoundsOpaquely(false); | 38 layer()->SetFillsBoundsOpaquely(false); |
| 39 | 39 |
| 40 SetSize(gfx::Size(2 * kPointRadius + 2, 2 * kPointRadius + 2)); | 40 SetSize(gfx::Size(2 * kPointRadius + 2, 2 * kPointRadius + 2)); |
| 41 | 41 |
| 42 stroke_paint_.setStyle(SkPaint::kStroke_Style); | 42 stroke_paint_.setStyle(SkPaint::kStroke_Style); |
| 43 stroke_paint_.setColor(kProjectionStrokeColor); | 43 stroke_paint_.setColor(kProjectionStrokeColor); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 SkPaint fill_paint_; | 123 SkPaint fill_paint_; |
| 124 SkPaint stroke_paint_; | 124 SkPaint stroke_paint_; |
| 125 SkColor gradient_colors_[2]; | 125 SkColor gradient_colors_[2]; |
| 126 SkScalar gradient_pos_[2]; | 126 SkScalar gradient_pos_[2]; |
| 127 | 127 |
| 128 std::unique_ptr<gfx::Animation> fadeout_; | 128 std::unique_ptr<gfx::Animation> fadeout_; |
| 129 | 129 |
| 130 DISALLOW_COPY_AND_ASSIGN(TouchPointView); | 130 DISALLOW_COPY_AND_ASSIGN(TouchPointView); |
| 131 }; | 131 }; |
| 132 | 132 |
| 133 TouchHudProjection::TouchHudProjection(aura::Window* initial_root) | 133 TouchHudDrawer::TouchHudDrawer() {} |
| 134 : TouchObserverHUD(initial_root) { | |
| 135 } | |
| 136 | 134 |
| 137 TouchHudProjection::~TouchHudProjection() { | 135 TouchHudDrawer::~TouchHudDrawer() {} |
| 138 } | |
| 139 | 136 |
| 140 void TouchHudProjection::Clear() { | 137 void TouchHudDrawer::Clear() { |
| 141 for (std::map<int, TouchPointView*>::iterator iter = points_.begin(); | 138 for (std::map<int, TouchPointView*>::iterator iter = points_.begin(); |
| 142 iter != points_.end(); iter++) | 139 iter != points_.end(); iter++) |
| 143 iter->second->Remove(); | 140 iter->second->Remove(); |
| 144 points_.clear(); | 141 points_.clear(); |
| 145 } | 142 } |
| 146 | 143 |
| 147 void TouchHudProjection::OnTouchEvent(ui::TouchEvent* event) { | 144 void TouchHudDrawer::HandleTouchEvent(const ui::TouchEvent* event, |
| 145 Widget* parent_widget) { |
| 148 if (event->type() == ui::ET_TOUCH_PRESSED) { | 146 if (event->type() == ui::ET_TOUCH_PRESSED) { |
| 149 TouchPointView* point = new TouchPointView(widget()); | 147 TouchPointView* point = new TouchPointView(parent_widget); |
| 150 point->UpdateTouch(*event); | 148 point->UpdateTouch(*event); |
| 151 std::pair<std::map<int, TouchPointView*>::iterator, bool> result = | 149 std::pair<std::map<int, TouchPointView*>::iterator, bool> result = |
| 152 points_.insert(std::make_pair(event->touch_id(), point)); | 150 points_.insert(std::make_pair(event->touch_id(), point)); |
| 153 // If a |TouchPointView| is already mapped to the touch id, remove it and | 151 // If a |TouchPointView| is already mapped to the touch id, remove it and |
| 154 // replace it with the new one. | 152 // replace it with the new one. |
| 155 if (!result.second) { | 153 if (!result.second) { |
| 156 result.first->second->Remove(); | 154 result.first->second->Remove(); |
| 157 result.first->second = point; | 155 result.first->second = point; |
| 158 } | 156 } |
| 159 } else { | 157 } else { |
| 160 std::map<int, TouchPointView*>::iterator iter = | 158 std::map<int, TouchPointView*>::iterator iter = |
| 161 points_.find(event->touch_id()); | 159 points_.find(event->touch_id()); |
| 162 if (iter != points_.end()) { | 160 if (iter != points_.end()) { |
| 163 iter->second->UpdateTouch(*event); | 161 iter->second->UpdateTouch(*event); |
| 164 if (event->type() == ui::ET_TOUCH_RELEASED || | 162 if (event->type() == ui::ET_TOUCH_RELEASED || |
| 165 event->type() == ui::ET_TOUCH_CANCELLED) | 163 event->type() == ui::ET_TOUCH_CANCELLED) |
| 166 points_.erase(iter); | 164 points_.erase(iter); |
| 167 } | 165 } |
| 168 } | 166 } |
| 169 } | 167 } |
| 170 | 168 |
| 171 void TouchHudProjection::SetHudForRootWindowController( | 169 } // namespace views |
| 172 RootWindowController* controller) { | |
| 173 controller->set_touch_hud_projection(this); | |
| 174 } | |
| 175 | |
| 176 void TouchHudProjection::UnsetHudForRootWindowController( | |
| 177 RootWindowController* controller) { | |
| 178 controller->set_touch_hud_projection(NULL); | |
| 179 } | |
| 180 | |
| 181 } // namespace ash | |
| OLD | NEW |