Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(517)

Side by Side Diff: ui/views/controls/touch/touch_hud_drawer.cc

Issue 2092343002: Touch HUD app for mustash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change window manager connection unittest to original Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/controls/touch/touch_hud_drawer.h ('k') | ui/views/mus/native_widget_mus.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 = 40;
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, kPointRadius + 1)) { 35 gradient_center_(SkPoint::Make(kPointRadius + 1,
36 kPointRadius + 1)) {
36 SetPaintToLayer(true); 37 SetPaintToLayer(true);
37 layer()->SetFillsBoundsOpaquely(false); 38 layer()->SetFillsBoundsOpaquely(false);
38 39
39 SetSize(gfx::Size(2 * kPointRadius + 2, 2 * kPointRadius + 2)); 40 SetSize(gfx::Size(2 * kPointRadius + 2, 2 * kPointRadius + 2));
40 41
41 stroke_paint_.setStyle(SkPaint::kStroke_Style); 42 stroke_paint_.setStyle(SkPaint::kStroke_Style);
42 stroke_paint_.setColor(kProjectionStrokeColor); 43 stroke_paint_.setColor(kProjectionStrokeColor);
43 44
44 gradient_colors_[0] = kProjectionFillColor; 45 gradient_colors_[0] = kProjectionFillColor;
45 gradient_colors_[1] = kProjectionStrokeColor; 46 gradient_colors_[1] = kProjectionStrokeColor;
46 47
47 gradient_pos_[0] = SkFloatToScalar(0.9f); 48 gradient_pos_[0] = SkFloatToScalar(0.9f);
48 gradient_pos_[1] = SkFloatToScalar(1.0f); 49 gradient_pos_[1] = SkFloatToScalar(1.0f);
49 50
50 parent_widget->GetContentsView()->AddChildView(this); 51 parent_widget->GetContentsView()->AddChildView(this);
51 52
52 parent_widget->AddObserver(this); 53 parent_widget->AddObserver(this);
53 } 54 }
54 55
55 void UpdateTouch(const ui::TouchEvent& touch) { 56 void UpdateTouch(const ui::LocatedEvent& touch) {
56 if (touch.type() == ui::ET_TOUCH_RELEASED || 57 if (touch.type() == ui::ET_TOUCH_RELEASED ||
57 touch.type() == ui::ET_TOUCH_CANCELLED) { 58 touch.type() == ui::ET_TOUCH_CANCELLED ||
59 touch.type() == ui::ET_POINTER_UP ||
60 touch.type() == ui::ET_POINTER_CANCELLED) {
58 fadeout_.reset(new gfx::LinearAnimation(kFadeoutDurationInMs, 61 fadeout_.reset(new gfx::LinearAnimation(kFadeoutDurationInMs,
59 kFadeoutFrameRate, this)); 62 kFadeoutFrameRate,
63 this));
60 fadeout_->Start(); 64 fadeout_->Start();
61 } else { 65 } else {
62 SetX(parent()->GetMirroredXInView(touch.root_location().x()) - 66 SetX(parent()->GetMirroredXInView(touch.root_location().x()) -
63 kPointRadius - 1); 67 kPointRadius - 1);
64 SetY(touch.root_location().y() - kPointRadius - 1); 68 SetY(touch.root_location().y() - kPointRadius - 1);
65 } 69 }
66 } 70 }
67 71
68 void Remove() { delete this; } 72 void Remove() {
73 delete this;
74 }
69 75
70 private: 76 private:
71 ~TouchPointView() override { 77 ~TouchPointView() override {
72 GetWidget()->RemoveObserver(this); 78 GetWidget()->RemoveObserver(this);
73 parent()->RemoveChildView(this); 79 parent()->RemoveChildView(this);
74 } 80 }
75 81
76 // Overridden from views::View. 82 // Overridden from views::View.
77 void OnPaint(gfx::Canvas* canvas) override { 83 void OnPaint(gfx::Canvas* canvas) override {
78 int alpha = kProjectionAlpha; 84 int alpha = kProjectionAlpha;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 SkPaint fill_paint_; 125 SkPaint fill_paint_;
120 SkPaint stroke_paint_; 126 SkPaint stroke_paint_;
121 SkColor gradient_colors_[2]; 127 SkColor gradient_colors_[2];
122 SkScalar gradient_pos_[2]; 128 SkScalar gradient_pos_[2];
123 129
124 std::unique_ptr<gfx::Animation> fadeout_; 130 std::unique_ptr<gfx::Animation> fadeout_;
125 131
126 DISALLOW_COPY_AND_ASSIGN(TouchPointView); 132 DISALLOW_COPY_AND_ASSIGN(TouchPointView);
127 }; 133 };
128 134
129 TouchHudProjection::TouchHudProjection(aura::Window* initial_root) 135 TouchHudDrawer::TouchHudDrawer() {}
130 : TouchObserverHUD(initial_root) {}
131 136
132 TouchHudProjection::~TouchHudProjection() {} 137 TouchHudDrawer::~TouchHudDrawer() {}
133 138
134 void TouchHudProjection::Clear() { 139 void TouchHudDrawer::Clear() {
135 for (std::map<int, TouchPointView*>::iterator iter = points_.begin(); 140 for (std::map<int, TouchPointView*>::iterator iter = points_.begin();
136 iter != points_.end(); iter++) 141 iter != points_.end(); iter++)
137 iter->second->Remove(); 142 iter->second->Remove();
138 points_.clear(); 143 points_.clear();
139 } 144 }
140 145
141 void TouchHudProjection::OnTouchEvent(ui::TouchEvent* event) { 146 void TouchHudDrawer::HandleTouchEvent(const ui::LocatedEvent* event,
142 if (event->type() == ui::ET_TOUCH_PRESSED) { 147 Widget* parent_widget) {
143 TouchPointView* point = new TouchPointView(widget()); 148 int id = 0;
149 if (event->IsTouchEvent()) {
150 id = event->AsTouchEvent()->touch_id();
151 } else if (event->IsPointerEvent()) {
152 id = event->AsPointerEvent()->pointer_id();
153 }
154 if (event->type() == ui::ET_TOUCH_PRESSED ||
155 event->type() == ui::ET_POINTER_DOWN) {
156 TouchPointView* point = new TouchPointView(parent_widget);
144 point->UpdateTouch(*event); 157 point->UpdateTouch(*event);
145 std::pair<std::map<int, TouchPointView*>::iterator, bool> result = 158 std::pair<std::map<int, TouchPointView*>::iterator, bool> result =
146 points_.insert(std::make_pair(event->touch_id(), point)); 159 points_.insert(std::make_pair(id, point));
147 // If a |TouchPointView| is already mapped to the touch id, remove it and 160 // If a |TouchPointView| is already mapped to the touch id, remove it and
148 // replace it with the new one. 161 // replace it with the new one.
149 if (!result.second) { 162 if (!result.second) {
150 result.first->second->Remove(); 163 result.first->second->Remove();
151 result.first->second = point; 164 result.first->second = point;
152 } 165 }
153 } else { 166 } else {
154 std::map<int, TouchPointView*>::iterator iter = 167 std::map<int, TouchPointView*>::iterator iter = points_.find(id);
155 points_.find(event->touch_id());
156 if (iter != points_.end()) { 168 if (iter != points_.end()) {
157 iter->second->UpdateTouch(*event); 169 iter->second->UpdateTouch(*event);
158 if (event->type() == ui::ET_TOUCH_RELEASED || 170 if (event->type() == ui::ET_TOUCH_RELEASED ||
159 event->type() == ui::ET_TOUCH_CANCELLED) 171 event->type() == ui::ET_TOUCH_CANCELLED ||
172 event->type() == ui::ET_POINTER_UP ||
173 event->type() == ui::ET_POINTER_CANCELLED)
160 points_.erase(iter); 174 points_.erase(iter);
161 } 175 }
162 } 176 }
163 } 177 }
164 178
165 void TouchHudProjection::SetHudForRootWindowController( 179 } // namespace views
166 RootWindowController* controller) {
167 controller->set_touch_hud_projection(this);
168 }
169
170 void TouchHudProjection::UnsetHudForRootWindowController(
171 RootWindowController* controller) {
172 controller->set_touch_hud_projection(NULL);
173 }
174
175 } // namespace ash
OLDNEW
« no previous file with comments | « ui/views/controls/touch/touch_hud_drawer.h ('k') | ui/views/mus/native_widget_mus.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698