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_debug.h" | 5 #include "ash/touch/touch_hud_debug.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include <X11/extensions/XInput2.h> | 32 #include <X11/extensions/XInput2.h> |
33 #include <X11/Xlib.h> | 33 #include <X11/Xlib.h> |
34 | 34 |
35 #include "ui/events/devices/x11/device_data_manager_x11.h" // nogncheck | 35 #include "ui/events/devices/x11/device_data_manager_x11.h" // nogncheck |
36 #endif | 36 #endif |
37 | 37 |
38 namespace ash { | 38 namespace ash { |
39 | 39 |
40 const int kPointRadius = 20; | 40 const int kPointRadius = 20; |
41 const SkColor kColors[] = { | 41 const SkColor kColors[] = { |
42 SK_ColorYELLOW, | 42 SK_ColorYELLOW, |
43 SK_ColorGREEN, | 43 SK_ColorGREEN, |
44 SK_ColorRED, | 44 SK_ColorRED, |
45 SK_ColorBLUE, | 45 SK_ColorBLUE, |
46 SK_ColorGRAY, | 46 SK_ColorGRAY, |
47 SK_ColorMAGENTA, | 47 SK_ColorMAGENTA, |
48 SK_ColorCYAN, | 48 SK_ColorCYAN, |
49 SK_ColorWHITE, | 49 SK_ColorWHITE, |
50 SK_ColorBLACK, | 50 SK_ColorBLACK, |
51 SkColorSetRGB(0xFF, 0x8C, 0x00), | 51 SkColorSetRGB(0xFF, 0x8C, 0x00), |
52 SkColorSetRGB(0x8B, 0x45, 0x13), | 52 SkColorSetRGB(0x8B, 0x45, 0x13), |
53 SkColorSetRGB(0xFF, 0xDE, 0xAD), | 53 SkColorSetRGB(0xFF, 0xDE, 0xAD), |
54 }; | 54 }; |
55 const int kAlpha = 0x60; | 55 const int kAlpha = 0x60; |
56 const int kMaxPaths = arraysize(kColors); | 56 const int kMaxPaths = arraysize(kColors); |
57 const int kReducedScale = 10; | 57 const int kReducedScale = 10; |
58 | 58 |
59 const char* GetTouchEventLabel(ui::EventType type) { | 59 const char* GetTouchEventLabel(ui::EventType type) { |
60 switch (type) { | 60 switch (type) { |
61 case ui::ET_UNKNOWN: | 61 case ui::ET_UNKNOWN: |
62 return " "; | 62 return " "; |
63 case ui::ET_TOUCH_PRESSED: | 63 case ui::ET_TOUCH_PRESSED: |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 // A TouchTrace keeps track of all the touch events of a single touch point | 135 // A TouchTrace keeps track of all the touch events of a single touch point |
136 // (starting from a touch-press and ending at a touch-release or touch-cancel). | 136 // (starting from a touch-press and ending at a touch-release or touch-cancel). |
137 class TouchTrace { | 137 class TouchTrace { |
138 public: | 138 public: |
139 typedef std::vector<TouchPointLog>::iterator iterator; | 139 typedef std::vector<TouchPointLog>::iterator iterator; |
140 typedef std::vector<TouchPointLog>::const_iterator const_iterator; | 140 typedef std::vector<TouchPointLog>::const_iterator const_iterator; |
141 typedef std::vector<TouchPointLog>::reverse_iterator reverse_iterator; | 141 typedef std::vector<TouchPointLog>::reverse_iterator reverse_iterator; |
142 typedef std::vector<TouchPointLog>::const_reverse_iterator | 142 typedef std::vector<TouchPointLog>::const_reverse_iterator |
143 const_reverse_iterator; | 143 const_reverse_iterator; |
144 | 144 |
145 TouchTrace() { | 145 TouchTrace() {} |
146 } | |
147 | 146 |
148 void AddTouchPoint(const ui::TouchEvent& touch) { | 147 void AddTouchPoint(const ui::TouchEvent& touch) { |
149 log_.push_back(TouchPointLog(touch)); | 148 log_.push_back(TouchPointLog(touch)); |
150 } | 149 } |
151 | 150 |
152 const std::vector<TouchPointLog>& log() const { return log_; } | 151 const std::vector<TouchPointLog>& log() const { return log_; } |
153 | 152 |
154 bool active() const { | 153 bool active() const { |
155 return !log_.empty() && log_.back().type != ui::ET_TOUCH_RELEASED && | 154 return !log_.empty() && log_.back().type != ui::ET_TOUCH_RELEASED && |
156 log_.back().type != ui::ET_TOUCH_CANCELLED; | 155 log_.back().type != ui::ET_TOUCH_CANCELLED; |
157 } | 156 } |
158 | 157 |
159 // Returns a list containing data from all events for the touch point. | 158 // Returns a list containing data from all events for the touch point. |
160 std::unique_ptr<base::ListValue> GetAsList() const { | 159 std::unique_ptr<base::ListValue> GetAsList() const { |
161 std::unique_ptr<base::ListValue> list(new base::ListValue()); | 160 std::unique_ptr<base::ListValue> list(new base::ListValue()); |
162 for (const_iterator i = log_.begin(); i != log_.end(); ++i) | 161 for (const_iterator i = log_.begin(); i != log_.end(); ++i) |
163 list->Append((*i).GetAsDictionary()); | 162 list->Append((*i).GetAsDictionary()); |
164 return list; | 163 return list; |
165 } | 164 } |
166 | 165 |
167 void Reset() { | 166 void Reset() { log_.clear(); } |
168 log_.clear(); | |
169 } | |
170 | 167 |
171 private: | 168 private: |
172 std::vector<TouchPointLog> log_; | 169 std::vector<TouchPointLog> log_; |
173 | 170 |
174 DISALLOW_COPY_AND_ASSIGN(TouchTrace); | 171 DISALLOW_COPY_AND_ASSIGN(TouchTrace); |
175 }; | 172 }; |
176 | 173 |
177 // A TouchLog keeps track of all touch events of all touch points. | 174 // A TouchLog keeps track of all touch events of all touch points. |
178 class TouchLog { | 175 class TouchLog { |
179 public: | 176 public: |
180 TouchLog() : next_trace_index_(0) { | 177 TouchLog() : next_trace_index_(0) {} |
181 } | |
182 | 178 |
183 void AddTouchPoint(const ui::TouchEvent& touch) { | 179 void AddTouchPoint(const ui::TouchEvent& touch) { |
184 if (touch.type() == ui::ET_TOUCH_PRESSED) | 180 if (touch.type() == ui::ET_TOUCH_PRESSED) |
185 StartTrace(touch); | 181 StartTrace(touch); |
186 AddToTrace(touch); | 182 AddToTrace(touch); |
187 } | 183 } |
188 | 184 |
189 void Reset() { | 185 void Reset() { |
190 next_trace_index_ = 0; | 186 next_trace_index_ = 0; |
191 for (int i = 0; i < kMaxPaths; ++i) | 187 for (int i = 0; i < kMaxPaths; ++i) |
192 traces_[i].Reset(); | 188 traces_[i].Reset(); |
193 } | 189 } |
194 | 190 |
195 std::unique_ptr<base::ListValue> GetAsList() const { | 191 std::unique_ptr<base::ListValue> GetAsList() const { |
196 std::unique_ptr<base::ListValue> list(new base::ListValue()); | 192 std::unique_ptr<base::ListValue> list(new base::ListValue()); |
197 for (int i = 0; i < kMaxPaths; ++i) { | 193 for (int i = 0; i < kMaxPaths; ++i) { |
198 if (!traces_[i].log().empty()) | 194 if (!traces_[i].log().empty()) |
199 list->Append(traces_[i].GetAsList()); | 195 list->Append(traces_[i].GetAsList()); |
200 } | 196 } |
201 return list; | 197 return list; |
202 } | 198 } |
203 | 199 |
204 int GetTraceIndex(int touch_id) const { | 200 int GetTraceIndex(int touch_id) const { |
205 return touch_id_to_trace_index_.at(touch_id); | 201 return touch_id_to_trace_index_.at(touch_id); |
206 } | 202 } |
207 | 203 |
208 const TouchTrace* traces() const { | 204 const TouchTrace* traces() const { return traces_; } |
209 return traces_; | |
210 } | |
211 | 205 |
212 private: | 206 private: |
213 void StartTrace(const ui::TouchEvent& touch) { | 207 void StartTrace(const ui::TouchEvent& touch) { |
214 // Find the first inactive spot; otherwise, overwrite the one | 208 // Find the first inactive spot; otherwise, overwrite the one |
215 // |next_trace_index_| is pointing to. | 209 // |next_trace_index_| is pointing to. |
216 int old_trace_index = next_trace_index_; | 210 int old_trace_index = next_trace_index_; |
217 do { | 211 do { |
218 if (!traces_[next_trace_index_].active()) | 212 if (!traces_[next_trace_index_].active()) |
219 break; | 213 break; |
220 next_trace_index_ = (next_trace_index_ + 1) % kMaxPaths; | 214 next_trace_index_ = (next_trace_index_ + 1) % kMaxPaths; |
(...skipping 15 matching lines...) Expand all Loading... |
236 | 230 |
237 std::map<int, int> touch_id_to_trace_index_; | 231 std::map<int, int> touch_id_to_trace_index_; |
238 | 232 |
239 DISALLOW_COPY_AND_ASSIGN(TouchLog); | 233 DISALLOW_COPY_AND_ASSIGN(TouchLog); |
240 }; | 234 }; |
241 | 235 |
242 // TouchHudCanvas draws touch traces in |FULLSCREEN| and |REDUCED_SCALE| modes. | 236 // TouchHudCanvas draws touch traces in |FULLSCREEN| and |REDUCED_SCALE| modes. |
243 class TouchHudCanvas : public views::View { | 237 class TouchHudCanvas : public views::View { |
244 public: | 238 public: |
245 explicit TouchHudCanvas(const TouchLog& touch_log) | 239 explicit TouchHudCanvas(const TouchLog& touch_log) |
246 : touch_log_(touch_log), | 240 : touch_log_(touch_log), scale_(1) { |
247 scale_(1) { | |
248 SetPaintToLayer(true); | 241 SetPaintToLayer(true); |
249 layer()->SetFillsBoundsOpaquely(false); | 242 layer()->SetFillsBoundsOpaquely(false); |
250 | 243 |
251 paint_.setStyle(SkPaint::kFill_Style); | 244 paint_.setStyle(SkPaint::kFill_Style); |
252 } | 245 } |
253 | 246 |
254 ~TouchHudCanvas() override {} | 247 ~TouchHudCanvas() override {} |
255 | 248 |
256 void SetScale(int scale) { | 249 void SetScale(int scale) { |
257 if (scale_ == scale) | 250 if (scale_ == scale) |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 | 326 |
334 views::View* content = widget()->GetContentsView(); | 327 views::View* content = widget()->GetContentsView(); |
335 | 328 |
336 canvas_ = new TouchHudCanvas(*touch_log_); | 329 canvas_ = new TouchHudCanvas(*touch_log_); |
337 content->AddChildView(canvas_); | 330 content->AddChildView(canvas_); |
338 | 331 |
339 const gfx::Size& display_size = display.size(); | 332 const gfx::Size& display_size = display.size(); |
340 canvas_->SetSize(display_size); | 333 canvas_->SetSize(display_size); |
341 | 334 |
342 label_container_ = new views::View; | 335 label_container_ = new views::View; |
343 label_container_->SetLayoutManager(new views::BoxLayout( | 336 label_container_->SetLayoutManager( |
344 views::BoxLayout::kVertical, 0, 0, 0)); | 337 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
345 | 338 |
346 for (int i = 0; i < kMaxTouchPoints; ++i) { | 339 for (int i = 0; i < kMaxTouchPoints; ++i) { |
347 touch_labels_[i] = new views::Label; | 340 touch_labels_[i] = new views::Label; |
348 touch_labels_[i]->SetBackgroundColor(SkColorSetARGB(0, 255, 255, 255)); | 341 touch_labels_[i]->SetBackgroundColor(SkColorSetARGB(0, 255, 255, 255)); |
349 touch_labels_[i]->SetShadows(gfx::ShadowValues( | 342 touch_labels_[i]->SetShadows(gfx::ShadowValues( |
350 1, gfx::ShadowValue(gfx::Vector2d(1, 1), 0, SK_ColorWHITE))); | 343 1, gfx::ShadowValue(gfx::Vector2d(1, 1), 0, SK_ColorWHITE))); |
351 label_container_->AddChildView(touch_labels_[i]); | 344 label_container_->AddChildView(touch_labels_[i]); |
352 } | 345 } |
353 label_container_->SetX(0); | 346 label_container_->SetX(0); |
354 label_container_->SetY(display_size.height() / kReducedScale); | 347 label_container_->SetY(display_size.height() / kReducedScale); |
355 label_container_->SetSize(label_container_->GetPreferredSize()); | 348 label_container_->SetSize(label_container_->GetPreferredSize()); |
356 label_container_->SetVisible(false); | 349 label_container_->SetVisible(false); |
357 content->AddChildView(label_container_); | 350 content->AddChildView(label_container_); |
358 } | 351 } |
359 | 352 |
360 TouchHudDebug::~TouchHudDebug() { | 353 TouchHudDebug::~TouchHudDebug() {} |
361 } | |
362 | 354 |
363 // static | 355 // static |
364 std::unique_ptr<base::DictionaryValue> TouchHudDebug::GetAllAsDictionary() { | 356 std::unique_ptr<base::DictionaryValue> TouchHudDebug::GetAllAsDictionary() { |
365 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 357 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
366 aura::Window::Windows roots = Shell::GetInstance()->GetAllRootWindows(); | 358 aura::Window::Windows roots = Shell::GetInstance()->GetAllRootWindows(); |
367 for (aura::Window::Windows::iterator iter = roots.begin(); | 359 for (aura::Window::Windows::iterator iter = roots.begin(); |
368 iter != roots.end(); ++iter) { | 360 iter != roots.end(); ++iter) { |
369 RootWindowController* controller = GetRootWindowController(*iter); | 361 RootWindowController* controller = GetRootWindowController(*iter); |
370 TouchHudDebug* hud = controller->touch_hud_debug(); | 362 TouchHudDebug* hud = controller->touch_hud_debug(); |
371 if (hud) { | 363 if (hud) { |
372 std::unique_ptr<base::ListValue> list = hud->GetLogAsList(); | 364 std::unique_ptr<base::ListValue> list = hud->GetLogAsList(); |
373 if (!list->empty()) | 365 if (!list->empty()) |
374 value->Set(base::Int64ToString(hud->display_id()), list.release()); | 366 value->Set(base::Int64ToString(hud->display_id()), list.release()); |
375 } | 367 } |
376 } | 368 } |
377 return value; | 369 return value; |
378 } | 370 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 int trace_index = touch_log_->GetTraceIndex(index); | 425 int trace_index = touch_log_->GetTraceIndex(index); |
434 const TouchTrace& trace = touch_log_->traces()[trace_index]; | 426 const TouchTrace& trace = touch_log_->traces()[trace_index]; |
435 TouchTrace::const_reverse_iterator point = trace.log().rbegin(); | 427 TouchTrace::const_reverse_iterator point = trace.log().rbegin(); |
436 ui::EventType touch_status = point->type; | 428 ui::EventType touch_status = point->type; |
437 float touch_radius = std::max(point->radius_x, point->radius_y); | 429 float touch_radius = std::max(point->radius_x, point->radius_y); |
438 while (point != trace.log().rend() && point->type == ui::ET_TOUCH_CANCELLED) | 430 while (point != trace.log().rend() && point->type == ui::ET_TOUCH_CANCELLED) |
439 point++; | 431 point++; |
440 DCHECK(point != trace.log().rend()); | 432 DCHECK(point != trace.log().rend()); |
441 gfx::Point touch_position = point->location; | 433 gfx::Point touch_position = point->location; |
442 | 434 |
443 std::string string = base::StringPrintf("%2d: %s %s (%.4f)", | 435 std::string string = base::StringPrintf( |
444 index, | 436 "%2d: %s %s (%.4f)", index, GetTouchEventLabel(touch_status), |
445 GetTouchEventLabel(touch_status), | 437 touch_position.ToString().c_str(), touch_radius); |
446 touch_position.ToString().c_str(), | |
447 touch_radius); | |
448 touch_labels_[index]->SetText(base::UTF8ToUTF16(string)); | 438 touch_labels_[index]->SetText(base::UTF8ToUTF16(string)); |
449 } | 439 } |
450 | 440 |
451 void TouchHudDebug::OnTouchEvent(ui::TouchEvent* event) { | 441 void TouchHudDebug::OnTouchEvent(ui::TouchEvent* event) { |
452 if (event->touch_id() >= kMaxTouchPoints) | 442 if (event->touch_id() >= kMaxTouchPoints) |
453 return; | 443 return; |
454 | 444 |
455 touch_log_->AddTouchPoint(*event); | 445 touch_log_->AddTouchPoint(*event); |
456 canvas_->TouchPointAdded(event->touch_id()); | 446 canvas_->TouchPointAdded(event->touch_id()); |
457 UpdateTouchPointLabel(event->touch_id()); | 447 UpdateTouchPointLabel(event->touch_id()); |
(...skipping 15 matching lines...) Expand all Loading... |
473 RootWindowController* controller) { | 463 RootWindowController* controller) { |
474 controller->set_touch_hud_debug(this); | 464 controller->set_touch_hud_debug(this); |
475 } | 465 } |
476 | 466 |
477 void TouchHudDebug::UnsetHudForRootWindowController( | 467 void TouchHudDebug::UnsetHudForRootWindowController( |
478 RootWindowController* controller) { | 468 RootWindowController* controller) { |
479 controller->set_touch_hud_debug(NULL); | 469 controller->set_touch_hud_debug(NULL); |
480 } | 470 } |
481 | 471 |
482 } // namespace ash | 472 } // namespace ash |
OLD | NEW |