| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ash/touch/touch_hud_projection.h" |
| 6 | 6 |
| 7 #include "ash/root_window_controller.h" | 7 #include "ash/root_window_controller.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/wm/property_util.h" | 9 #include "ash/wm/property_util.h" |
| 10 #include "third_party/skia/include/effects/SkGradientShader.h" | 10 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 11 #include "ui/base/animation/animation_delegate.h" | |
| 12 #include "ui/base/animation/linear_animation.h" | |
| 13 #include "ui/base/events/event.h" | 11 #include "ui/base/events/event.h" |
| 12 #include "ui/gfx/animation/animation_delegate.h" |
| 13 #include "ui/gfx/animation/linear_animation.h" |
| 14 #include "ui/gfx/canvas.h" | 14 #include "ui/gfx/canvas.h" |
| 15 #include "ui/gfx/size.h" | 15 #include "ui/gfx/size.h" |
| 16 #include "ui/views/widget/widget.h" | 16 #include "ui/views/widget/widget.h" |
| 17 | 17 |
| 18 namespace ash { | 18 namespace ash { |
| 19 namespace internal { | 19 namespace internal { |
| 20 | 20 |
| 21 const int kPointRadius = 20; | 21 const int kPointRadius = 20; |
| 22 const SkColor kProjectionFillColor = SkColorSetRGB(0xF5, 0xF5, 0xDC); | 22 const SkColor kProjectionFillColor = SkColorSetRGB(0xF5, 0xF5, 0xDC); |
| 23 const SkColor kProjectionStrokeColor = SK_ColorGRAY; | 23 const SkColor kProjectionStrokeColor = SK_ColorGRAY; |
| 24 const int kProjectionAlpha = 0xB0; | 24 const int kProjectionAlpha = 0xB0; |
| 25 const int kFadeoutDurationInMs = 250; | 25 const int kFadeoutDurationInMs = 250; |
| 26 const int kFadeoutFrameRate = 60; | 26 const int kFadeoutFrameRate = 60; |
| 27 | 27 |
| 28 // TouchPointView draws a single touch point. This object manages its own | 28 // TouchPointView draws a single touch point. This object manages its own |
| 29 // lifetime and deletes itself upon fade-out completion or whenever |Remove()| | 29 // lifetime and deletes itself upon fade-out completion or whenever |Remove()| |
| 30 // is explicitly called. | 30 // is explicitly called. |
| 31 class TouchPointView : public views::View, | 31 class TouchPointView : public views::View, |
| 32 public ui::AnimationDelegate, | 32 public gfx::AnimationDelegate, |
| 33 public views::WidgetObserver { | 33 public views::WidgetObserver { |
| 34 public: | 34 public: |
| 35 explicit TouchPointView(views::Widget* parent_widget) | 35 explicit TouchPointView(views::Widget* parent_widget) |
| 36 : circle_center_(kPointRadius + 1, kPointRadius + 1), | 36 : circle_center_(kPointRadius + 1, kPointRadius + 1), |
| 37 gradient_center_(SkPoint::Make(kPointRadius + 1, | 37 gradient_center_(SkPoint::Make(kPointRadius + 1, |
| 38 kPointRadius + 1)) { | 38 kPointRadius + 1)) { |
| 39 SetPaintToLayer(true); | 39 SetPaintToLayer(true); |
| 40 SetFillsBoundsOpaquely(false); | 40 SetFillsBoundsOpaquely(false); |
| 41 | 41 |
| 42 SetSize(gfx::Size(2 * kPointRadius + 2, 2 * kPointRadius + 2)); | 42 SetSize(gfx::Size(2 * kPointRadius + 2, 2 * kPointRadius + 2)); |
| 43 | 43 |
| 44 stroke_paint_.setStyle(SkPaint::kStroke_Style); | 44 stroke_paint_.setStyle(SkPaint::kStroke_Style); |
| 45 stroke_paint_.setColor(kProjectionStrokeColor); | 45 stroke_paint_.setColor(kProjectionStrokeColor); |
| 46 | 46 |
| 47 gradient_colors_[0] = kProjectionFillColor; | 47 gradient_colors_[0] = kProjectionFillColor; |
| 48 gradient_colors_[1] = kProjectionStrokeColor; | 48 gradient_colors_[1] = kProjectionStrokeColor; |
| 49 | 49 |
| 50 gradient_pos_[0] = SkFloatToScalar(0.9f); | 50 gradient_pos_[0] = SkFloatToScalar(0.9f); |
| 51 gradient_pos_[1] = SkFloatToScalar(1.0f); | 51 gradient_pos_[1] = SkFloatToScalar(1.0f); |
| 52 | 52 |
| 53 parent_widget->GetContentsView()->AddChildView(this); | 53 parent_widget->GetContentsView()->AddChildView(this); |
| 54 | 54 |
| 55 parent_widget->AddObserver(this); | 55 parent_widget->AddObserver(this); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void UpdateTouch(const ui::TouchEvent& touch) { | 58 void UpdateTouch(const ui::TouchEvent& touch) { |
| 59 if (touch.type() == ui::ET_TOUCH_RELEASED || | 59 if (touch.type() == ui::ET_TOUCH_RELEASED || |
| 60 touch.type() == ui::ET_TOUCH_CANCELLED) { | 60 touch.type() == ui::ET_TOUCH_CANCELLED) { |
| 61 fadeout_.reset(new ui::LinearAnimation(kFadeoutDurationInMs, | 61 fadeout_.reset(new gfx::LinearAnimation(kFadeoutDurationInMs, |
| 62 kFadeoutFrameRate, | 62 kFadeoutFrameRate, |
| 63 this)); | 63 this)); |
| 64 fadeout_->Start(); | 64 fadeout_->Start(); |
| 65 } else { | 65 } else { |
| 66 SetX(parent()->GetMirroredXInView(touch.root_location().x()) - | 66 SetX(parent()->GetMirroredXInView(touch.root_location().x()) - |
| 67 kPointRadius - 1); | 67 kPointRadius - 1); |
| 68 SetY(touch.root_location().y() - kPointRadius - 1); | 68 SetY(touch.root_location().y() - kPointRadius - 1); |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 | 71 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 95 SkShader::kMirror_TileMode, | 95 SkShader::kMirror_TileMode, |
| 96 NULL); | 96 NULL); |
| 97 fill_paint_.setShader(shader); | 97 fill_paint_.setShader(shader); |
| 98 shader->unref(); | 98 shader->unref(); |
| 99 canvas->DrawCircle(circle_center_, SkIntToScalar(kPointRadius), | 99 canvas->DrawCircle(circle_center_, SkIntToScalar(kPointRadius), |
| 100 fill_paint_); | 100 fill_paint_); |
| 101 canvas->DrawCircle(circle_center_, SkIntToScalar(kPointRadius), | 101 canvas->DrawCircle(circle_center_, SkIntToScalar(kPointRadius), |
| 102 stroke_paint_); | 102 stroke_paint_); |
| 103 } | 103 } |
| 104 | 104 |
| 105 // Overridden from ui::AnimationDelegate. | 105 // Overridden from gfx::AnimationDelegate. |
| 106 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE { | 106 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE { |
| 107 DCHECK_EQ(fadeout_.get(), animation); | 107 DCHECK_EQ(fadeout_.get(), animation); |
| 108 delete this; | 108 delete this; |
| 109 } | 109 } |
| 110 | 110 |
| 111 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE { | 111 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE { |
| 112 DCHECK_EQ(fadeout_.get(), animation); | 112 DCHECK_EQ(fadeout_.get(), animation); |
| 113 SchedulePaint(); | 113 SchedulePaint(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 virtual void AnimationCanceled(const ui::Animation* animation) OVERRIDE { | 116 virtual void AnimationCanceled(const gfx::Animation* animation) OVERRIDE { |
| 117 AnimationEnded(animation); | 117 AnimationEnded(animation); |
| 118 } | 118 } |
| 119 | 119 |
| 120 // Overridden from views::WidgetObserver. | 120 // Overridden from views::WidgetObserver. |
| 121 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE { | 121 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE { |
| 122 fadeout_->Stop(); | 122 fadeout_->Stop(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 const gfx::Point circle_center_; | 125 const gfx::Point circle_center_; |
| 126 const SkPoint gradient_center_; | 126 const SkPoint gradient_center_; |
| 127 | 127 |
| 128 SkPaint fill_paint_; | 128 SkPaint fill_paint_; |
| 129 SkPaint stroke_paint_; | 129 SkPaint stroke_paint_; |
| 130 SkColor gradient_colors_[2]; | 130 SkColor gradient_colors_[2]; |
| 131 SkScalar gradient_pos_[2]; | 131 SkScalar gradient_pos_[2]; |
| 132 | 132 |
| 133 scoped_ptr<ui::Animation> fadeout_; | 133 scoped_ptr<gfx::Animation> fadeout_; |
| 134 | 134 |
| 135 DISALLOW_COPY_AND_ASSIGN(TouchPointView); | 135 DISALLOW_COPY_AND_ASSIGN(TouchPointView); |
| 136 }; | 136 }; |
| 137 | 137 |
| 138 TouchHudProjection::TouchHudProjection(aura::RootWindow* initial_root) | 138 TouchHudProjection::TouchHudProjection(aura::RootWindow* initial_root) |
| 139 : TouchObserverHUD(initial_root) { | 139 : TouchObserverHUD(initial_root) { |
| 140 } | 140 } |
| 141 | 141 |
| 142 TouchHudProjection::~TouchHudProjection() { | 142 TouchHudProjection::~TouchHudProjection() { |
| 143 } | 143 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 controller->set_touch_hud_projection(this); | 178 controller->set_touch_hud_projection(this); |
| 179 } | 179 } |
| 180 | 180 |
| 181 void TouchHudProjection::UnsetHudForRootWindowController( | 181 void TouchHudProjection::UnsetHudForRootWindowController( |
| 182 RootWindowController* controller) { | 182 RootWindowController* controller) { |
| 183 controller->set_touch_hud_projection(NULL); | 183 controller->set_touch_hud_projection(NULL); |
| 184 } | 184 } |
| 185 | 185 |
| 186 } // namespace internal | 186 } // namespace internal |
| 187 } // namespace ash | 187 } // namespace ash |
| OLD | NEW |