Chromium Code Reviews| 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" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 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 ui::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 parent_(parent_widget->GetContentsView()) { | |
| 39 SetPaintToLayer(true); | 40 SetPaintToLayer(true); |
| 40 SetFillsBoundsOpaquely(false); | 41 SetFillsBoundsOpaquely(false); |
| 41 | 42 |
| 42 SetSize(gfx::Size(2 * kPointRadius + 2, 2 * kPointRadius + 2)); | 43 SetSize(gfx::Size(2 * kPointRadius + 2, 2 * kPointRadius + 2)); |
| 43 | 44 |
| 44 stroke_paint_.setStyle(SkPaint::kStroke_Style); | 45 stroke_paint_.setStyle(SkPaint::kStroke_Style); |
| 45 stroke_paint_.setColor(kProjectionStrokeColor); | 46 stroke_paint_.setColor(kProjectionStrokeColor); |
| 46 | 47 |
| 47 gradient_colors_[0] = kProjectionFillColor; | 48 gradient_colors_[0] = kProjectionFillColor; |
| 48 gradient_colors_[1] = kProjectionStrokeColor; | 49 gradient_colors_[1] = kProjectionStrokeColor; |
| 49 | 50 |
| 50 gradient_pos_[0] = SkFloatToScalar(0.9f); | 51 gradient_pos_[0] = SkFloatToScalar(0.9f); |
| 51 gradient_pos_[1] = SkFloatToScalar(1.0f); | 52 gradient_pos_[1] = SkFloatToScalar(1.0f); |
| 52 | 53 |
| 53 parent_widget->GetContentsView()->AddChildView(this); | 54 parent_->AddChildView(this); |
| 54 | 55 |
| 55 parent_widget->AddObserver(this); | 56 parent_widget->AddObserver(this); |
| 56 } | 57 } |
| 57 | 58 |
| 58 void UpdateTouch(const ui::TouchEvent& touch) { | 59 void UpdateTouch(const ui::TouchEvent& touch) { |
| 59 if (touch.type() == ui::ET_TOUCH_RELEASED || | 60 if (touch.type() == ui::ET_TOUCH_RELEASED || |
| 60 touch.type() == ui::ET_TOUCH_CANCELLED) { | 61 touch.type() == ui::ET_TOUCH_CANCELLED) { |
| 61 fadeout_.reset(new ui::LinearAnimation(kFadeoutDurationInMs, | 62 fadeout_.reset(new ui::LinearAnimation(kFadeoutDurationInMs, |
| 62 kFadeoutFrameRate, | 63 kFadeoutFrameRate, |
| 63 this)); | 64 this)); |
| 64 fadeout_->Start(); | 65 fadeout_->Start(); |
| 65 } else { | 66 } else { |
| 66 SetX(touch.root_location().x() - kPointRadius - 1); | 67 gfx::Point position(touch.root_location().x() - kPointRadius - 1, |
|
sadrul
2013/07/15 21:44:06
Can you use:
SetX(parent()->GetMirroredXInView(t
mohsen
2013/07/15 22:10:52
Yes, much better. Done.
| |
| 67 SetY(touch.root_location().y() - kPointRadius - 1); | 68 touch.root_location().y() - kPointRadius - 1); |
| 69 if (base::i18n::IsRTL()) | |
| 70 position.set_x(parent_->width() - position.x() - width()); | |
| 71 SetPosition(position); | |
| 68 } | 72 } |
| 69 } | 73 } |
| 70 | 74 |
| 71 void Remove() { | 75 void Remove() { |
| 72 delete this; | 76 delete this; |
| 73 } | 77 } |
| 74 | 78 |
| 75 private: | 79 private: |
| 76 virtual ~TouchPointView() { | 80 virtual ~TouchPointView() { |
| 77 GetWidget()->RemoveObserver(this); | 81 GetWidget()->RemoveObserver(this); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 } | 121 } |
| 118 | 122 |
| 119 // Overridden from views::WidgetObserver. | 123 // Overridden from views::WidgetObserver. |
| 120 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE { | 124 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE { |
| 121 fadeout_->Stop(); | 125 fadeout_->Stop(); |
| 122 } | 126 } |
| 123 | 127 |
| 124 const gfx::Point circle_center_; | 128 const gfx::Point circle_center_; |
| 125 const SkPoint gradient_center_; | 129 const SkPoint gradient_center_; |
| 126 | 130 |
| 131 View* parent_; | |
| 132 | |
| 127 SkPaint fill_paint_; | 133 SkPaint fill_paint_; |
| 128 SkPaint stroke_paint_; | 134 SkPaint stroke_paint_; |
| 129 SkColor gradient_colors_[2]; | 135 SkColor gradient_colors_[2]; |
| 130 SkScalar gradient_pos_[2]; | 136 SkScalar gradient_pos_[2]; |
| 131 | 137 |
| 132 scoped_ptr<ui::Animation> fadeout_; | 138 scoped_ptr<ui::Animation> fadeout_; |
| 133 | 139 |
| 134 DISALLOW_COPY_AND_ASSIGN(TouchPointView); | 140 DISALLOW_COPY_AND_ASSIGN(TouchPointView); |
| 135 }; | 141 }; |
| 136 | 142 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 controller->set_touch_hud_projection(this); | 183 controller->set_touch_hud_projection(this); |
| 178 } | 184 } |
| 179 | 185 |
| 180 void TouchHudProjection::UnsetHudForRootWindowController( | 186 void TouchHudProjection::UnsetHudForRootWindowController( |
| 181 RootWindowController* controller) { | 187 RootWindowController* controller) { |
| 182 controller->set_touch_hud_projection(NULL); | 188 controller->set_touch_hud_projection(NULL); |
| 183 } | 189 } |
| 184 | 190 |
| 185 } // namespace internal | 191 } // namespace internal |
| 186 } // namespace ash | 192 } // namespace ash |
| OLD | NEW |