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 "third_party/skia/include/effects/SkGradientShader.h" | 9 #include "third_party/skia/include/effects/SkGradientShader.h" |
10 #include "ui/events/event.h" | 10 #include "ui/events/event.h" |
(...skipping 14 matching lines...) Expand all Loading... |
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 views::View, |
30 public gfx::AnimationDelegate, | 30 public gfx::AnimationDelegate, |
31 public views::WidgetObserver { | 31 public views::WidgetObserver { |
32 public: | 32 public: |
33 explicit TouchPointView(views::Widget* parent_widget) | 33 explicit TouchPointView(views::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, kPointRadius + 1)) { |
36 kPointRadius + 1)) { | |
37 SetPaintToLayer(true); | 36 SetPaintToLayer(true); |
38 layer()->SetFillsBoundsOpaquely(false); | 37 layer()->SetFillsBoundsOpaquely(false); |
39 | 38 |
40 SetSize(gfx::Size(2 * kPointRadius + 2, 2 * kPointRadius + 2)); | 39 SetSize(gfx::Size(2 * kPointRadius + 2, 2 * kPointRadius + 2)); |
41 | 40 |
42 stroke_paint_.setStyle(SkPaint::kStroke_Style); | 41 stroke_paint_.setStyle(SkPaint::kStroke_Style); |
43 stroke_paint_.setColor(kProjectionStrokeColor); | 42 stroke_paint_.setColor(kProjectionStrokeColor); |
44 | 43 |
45 gradient_colors_[0] = kProjectionFillColor; | 44 gradient_colors_[0] = kProjectionFillColor; |
46 gradient_colors_[1] = kProjectionStrokeColor; | 45 gradient_colors_[1] = kProjectionStrokeColor; |
47 | 46 |
48 gradient_pos_[0] = SkFloatToScalar(0.9f); | 47 gradient_pos_[0] = SkFloatToScalar(0.9f); |
49 gradient_pos_[1] = SkFloatToScalar(1.0f); | 48 gradient_pos_[1] = SkFloatToScalar(1.0f); |
50 | 49 |
51 parent_widget->GetContentsView()->AddChildView(this); | 50 parent_widget->GetContentsView()->AddChildView(this); |
52 | 51 |
53 parent_widget->AddObserver(this); | 52 parent_widget->AddObserver(this); |
54 } | 53 } |
55 | 54 |
56 void UpdateTouch(const ui::TouchEvent& touch) { | 55 void UpdateTouch(const ui::TouchEvent& touch) { |
57 if (touch.type() == ui::ET_TOUCH_RELEASED || | 56 if (touch.type() == ui::ET_TOUCH_RELEASED || |
58 touch.type() == ui::ET_TOUCH_CANCELLED) { | 57 touch.type() == ui::ET_TOUCH_CANCELLED) { |
59 fadeout_.reset(new gfx::LinearAnimation(kFadeoutDurationInMs, | 58 fadeout_.reset(new gfx::LinearAnimation(kFadeoutDurationInMs, |
60 kFadeoutFrameRate, | 59 kFadeoutFrameRate, this)); |
61 this)); | |
62 fadeout_->Start(); | 60 fadeout_->Start(); |
63 } else { | 61 } else { |
64 SetX(parent()->GetMirroredXInView(touch.root_location().x()) - | 62 SetX(parent()->GetMirroredXInView(touch.root_location().x()) - |
65 kPointRadius - 1); | 63 kPointRadius - 1); |
66 SetY(touch.root_location().y() - kPointRadius - 1); | 64 SetY(touch.root_location().y() - kPointRadius - 1); |
67 } | 65 } |
68 } | 66 } |
69 | 67 |
70 void Remove() { | 68 void Remove() { delete this; } |
71 delete this; | |
72 } | |
73 | 69 |
74 private: | 70 private: |
75 ~TouchPointView() override { | 71 ~TouchPointView() override { |
76 GetWidget()->RemoveObserver(this); | 72 GetWidget()->RemoveObserver(this); |
77 parent()->RemoveChildView(this); | 73 parent()->RemoveChildView(this); |
78 } | 74 } |
79 | 75 |
80 // Overridden from views::View. | 76 // Overridden from views::View. |
81 void OnPaint(gfx::Canvas* canvas) override { | 77 void OnPaint(gfx::Canvas* canvas) override { |
82 int alpha = kProjectionAlpha; | 78 int alpha = kProjectionAlpha; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 SkPaint stroke_paint_; | 120 SkPaint stroke_paint_; |
125 SkColor gradient_colors_[2]; | 121 SkColor gradient_colors_[2]; |
126 SkScalar gradient_pos_[2]; | 122 SkScalar gradient_pos_[2]; |
127 | 123 |
128 std::unique_ptr<gfx::Animation> fadeout_; | 124 std::unique_ptr<gfx::Animation> fadeout_; |
129 | 125 |
130 DISALLOW_COPY_AND_ASSIGN(TouchPointView); | 126 DISALLOW_COPY_AND_ASSIGN(TouchPointView); |
131 }; | 127 }; |
132 | 128 |
133 TouchHudProjection::TouchHudProjection(aura::Window* initial_root) | 129 TouchHudProjection::TouchHudProjection(aura::Window* initial_root) |
134 : TouchObserverHUD(initial_root) { | 130 : TouchObserverHUD(initial_root) {} |
135 } | |
136 | 131 |
137 TouchHudProjection::~TouchHudProjection() { | 132 TouchHudProjection::~TouchHudProjection() {} |
138 } | |
139 | 133 |
140 void TouchHudProjection::Clear() { | 134 void TouchHudProjection::Clear() { |
141 for (std::map<int, TouchPointView*>::iterator iter = points_.begin(); | 135 for (std::map<int, TouchPointView*>::iterator iter = points_.begin(); |
142 iter != points_.end(); iter++) | 136 iter != points_.end(); iter++) |
143 iter->second->Remove(); | 137 iter->second->Remove(); |
144 points_.clear(); | 138 points_.clear(); |
145 } | 139 } |
146 | 140 |
147 void TouchHudProjection::OnTouchEvent(ui::TouchEvent* event) { | 141 void TouchHudProjection::OnTouchEvent(ui::TouchEvent* event) { |
148 if (event->type() == ui::ET_TOUCH_PRESSED) { | 142 if (event->type() == ui::ET_TOUCH_PRESSED) { |
149 TouchPointView* point = new TouchPointView(widget()); | 143 TouchPointView* point = new TouchPointView(widget()); |
150 point->UpdateTouch(*event); | 144 point->UpdateTouch(*event); |
151 std::pair<std::map<int, TouchPointView*>::iterator, bool> result = | 145 std::pair<std::map<int, TouchPointView*>::iterator, bool> result = |
152 points_.insert(std::make_pair(event->touch_id(), point)); | 146 points_.insert(std::make_pair(event->touch_id(), point)); |
(...skipping 19 matching lines...) Expand all Loading... |
172 RootWindowController* controller) { | 166 RootWindowController* controller) { |
173 controller->set_touch_hud_projection(this); | 167 controller->set_touch_hud_projection(this); |
174 } | 168 } |
175 | 169 |
176 void TouchHudProjection::UnsetHudForRootWindowController( | 170 void TouchHudProjection::UnsetHudForRootWindowController( |
177 RootWindowController* controller) { | 171 RootWindowController* controller) { |
178 controller->set_touch_hud_projection(NULL); | 172 controller->set_touch_hud_projection(NULL); |
179 } | 173 } |
180 | 174 |
181 } // namespace ash | 175 } // namespace ash |
OLD | NEW |