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

Side by Side Diff: ash/touch/touch_hud_debug.cc

Issue 17063013: Separate projection mode from rest of touch HUD (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 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 | Annotate | Revision Log
« no previous file with comments | « ash/touch/touch_hud_debug.h ('k') | ash/touch/touch_hud_projection.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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_observer_hud.h" 5 #include "ash/touch/touch_hud_debug.h"
6 6
7 #include "ash/display/display_controller.h"
8 #include "ash/display/display_manager.h" 7 #include "ash/display/display_manager.h"
9 #include "ash/root_window_controller.h" 8 #include "ash/root_window_controller.h"
10 #include "ash/shell_window_ids.h" 9 #include "ash/shell.h"
11 #include "ash/wm/property_util.h" 10 #include "ash/wm/property_util.h"
12 #include "base/json/json_string_value_serializer.h" 11 #include "base/json/json_string_value_serializer.h"
13 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
15 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
16 #include "third_party/skia/include/core/SkPath.h" 15 #include "third_party/skia/include/core/SkPath.h"
17 #include "third_party/skia/include/core/SkXfermode.h"
18 #include "third_party/skia/include/effects/SkGradientShader.h"
19 #include "ui/aura/root_window.h" 16 #include "ui/aura/root_window.h"
20 #include "ui/aura/window.h"
21 #include "ui/base/animation/animation_delegate.h" 17 #include "ui/base/animation/animation_delegate.h"
22 #include "ui/base/animation/linear_animation.h"
23 #include "ui/base/events/event.h" 18 #include "ui/base/events/event.h"
24 #include "ui/gfx/canvas.h" 19 #include "ui/gfx/canvas.h"
25 #include "ui/gfx/display.h" 20 #include "ui/gfx/display.h"
26 #include "ui/gfx/rect.h"
27 #include "ui/gfx/screen.h"
28 #include "ui/gfx/size.h" 21 #include "ui/gfx/size.h"
29 #include "ui/gfx/transform.h" 22 #include "ui/gfx/transform.h"
30 #include "ui/views/background.h"
31 #include "ui/views/controls/label.h" 23 #include "ui/views/controls/label.h"
32 #include "ui/views/layout/box_layout.h" 24 #include "ui/views/layout/box_layout.h"
33 #include "ui/views/widget/widget.h" 25 #include "ui/views/widget/widget.h"
34 26
35 #if defined(USE_X11) 27 #if defined(USE_X11)
36 #include <X11/extensions/XInput2.h> 28 #include <X11/extensions/XInput2.h>
37 #include <X11/Xlib.h> 29 #include <X11/Xlib.h>
38 30
39 #include "ui/base/x/device_data_manager.h" 31 #include "ui/base/x/device_data_manager.h"
40 #endif 32 #endif
(...skipping 10 matching lines...) Expand all
51 SK_ColorGRAY, 43 SK_ColorGRAY,
52 SK_ColorMAGENTA, 44 SK_ColorMAGENTA,
53 SK_ColorCYAN, 45 SK_ColorCYAN,
54 SK_ColorWHITE, 46 SK_ColorWHITE,
55 SK_ColorBLACK, 47 SK_ColorBLACK,
56 SkColorSetRGB(0xFF, 0x8C, 0x00), 48 SkColorSetRGB(0xFF, 0x8C, 0x00),
57 SkColorSetRGB(0x8B, 0x45, 0x13), 49 SkColorSetRGB(0x8B, 0x45, 0x13),
58 SkColorSetRGB(0xFF, 0xDE, 0xAD), 50 SkColorSetRGB(0xFF, 0xDE, 0xAD),
59 }; 51 };
60 const int kAlpha = 0x60; 52 const int kAlpha = 0x60;
61 const SkColor kProjectionFillColor = SkColorSetRGB(0xF5, 0xF5, 0xDC);
62 const SkColor kProjectionStrokeColor = SK_ColorGRAY;
63 const int kProjectionAlpha = 0xB0;
64 const int kMaxPaths = arraysize(kColors); 53 const int kMaxPaths = arraysize(kColors);
65 const int kReducedScale = 10; 54 const int kReducedScale = 10;
66 const int kFadeoutDurationInMs = 250;
67 const int kFadeoutFrameRate = 60;
68 55
69 const char* GetTouchEventLabel(ui::EventType type) { 56 const char* GetTouchEventLabel(ui::EventType type) {
70 switch (type) { 57 switch (type) {
71 case ui::ET_UNKNOWN: 58 case ui::ET_UNKNOWN:
72 return " "; 59 return " ";
73 case ui::ET_TOUCH_PRESSED: 60 case ui::ET_TOUCH_PRESSED:
74 return "P"; 61 return "P";
75 case ui::ET_TOUCH_MOVED: 62 case ui::ET_TOUCH_MOVED:
76 return "M"; 63 return "M";
77 case ui::ET_TOUCH_RELEASED: 64 case ui::ET_TOUCH_RELEASED:
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 gfx::Point location; 134 gfx::Point location;
148 double timestamp; 135 double timestamp;
149 float radius_x; 136 float radius_x;
150 float radius_y; 137 float radius_y;
151 float pressure; 138 float pressure;
152 int tracking_id; 139 int tracking_id;
153 int source_device; 140 int source_device;
154 }; 141 };
155 142
156 // A TouchTrace keeps track of all the touch events of a single touch point 143 // A TouchTrace keeps track of all the touch events of a single touch point
157 // (starting from a touch-press and ending at touch-release). 144 // (starting from a touch-press and ending at a touch-release or touch-cancel).
158 class TouchTrace { 145 class TouchTrace {
159 public: 146 public:
160 typedef std::vector<TouchPointLog>::iterator iterator; 147 typedef std::vector<TouchPointLog>::iterator iterator;
161 typedef std::vector<TouchPointLog>::const_iterator const_iterator; 148 typedef std::vector<TouchPointLog>::const_iterator const_iterator;
162 typedef std::vector<TouchPointLog>::reverse_iterator reverse_iterator; 149 typedef std::vector<TouchPointLog>::reverse_iterator reverse_iterator;
163 typedef std::vector<TouchPointLog>::const_reverse_iterator 150 typedef std::vector<TouchPointLog>::const_reverse_iterator
164 const_reverse_iterator; 151 const_reverse_iterator;
165 152
166 TouchTrace() { 153 TouchTrace() {
167 } 154 }
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 323
337 const TouchLog& touch_log_; 324 const TouchLog& touch_log_;
338 SkPath paths_[kMaxPaths]; 325 SkPath paths_[kMaxPaths];
339 SkColor colors_[kMaxPaths]; 326 SkColor colors_[kMaxPaths];
340 327
341 int scale_; 328 int scale_;
342 329
343 DISALLOW_COPY_AND_ASSIGN(TouchHudCanvas); 330 DISALLOW_COPY_AND_ASSIGN(TouchHudCanvas);
344 }; 331 };
345 332
346 // TouchPointView draws a single touch point in |PROJECTION| mode. This object 333 TouchHudDebug::TouchHudDebug(aura::RootWindow* initial_root)
347 // manages its own lifetime and deletes itself upon fade-out completion or 334 : TouchObserverHUD(initial_root),
348 // whenever |Remove()| is explicitly called. 335 mode_(FULLSCREEN),
349 class TouchPointView : public views::View, 336 touch_log_(new TouchLog()),
350 public ui::AnimationDelegate, 337 canvas_(NULL),
351 public views::WidgetObserver { 338 label_container_(NULL) {
352 public: 339 const gfx::Display& display =
353 explicit TouchPointView(views::Widget* parent_widget) 340 Shell::GetInstance()->display_manager()->GetDisplayForId(display_id());
354 : circle_center_(kPointRadius + 1, kPointRadius + 1),
355 gradient_center_(SkPoint::Make(kPointRadius + 1,
356 kPointRadius + 1)) {
357 SetPaintToLayer(true);
358 SetFillsBoundsOpaquely(false);
359 341
360 SetSize(gfx::Size(2 * kPointRadius + 2, 2 * kPointRadius + 2)); 342 views::View* content = widget()->GetContentsView();
361
362 stroke_paint_.setStyle(SkPaint::kStroke_Style);
363 stroke_paint_.setColor(kProjectionStrokeColor);
364
365 gradient_colors_[0] = kProjectionFillColor;
366 gradient_colors_[1] = kProjectionStrokeColor;
367
368 gradient_pos_[0] = SkFloatToScalar(0.9f);
369 gradient_pos_[1] = SkFloatToScalar(1.0f);
370
371 parent_widget->GetContentsView()->AddChildView(this);
372
373 parent_widget->AddObserver(this);
374 }
375
376 void UpdateTouch(const ui::TouchEvent& touch) {
377 if (touch.type() == ui::ET_TOUCH_RELEASED ||
378 touch.type() == ui::ET_TOUCH_CANCELLED) {
379 fadeout_.reset(new ui::LinearAnimation(kFadeoutDurationInMs,
380 kFadeoutFrameRate,
381 this));
382 fadeout_->Start();
383 } else {
384 SetX(touch.root_location().x() - kPointRadius - 1);
385 SetY(touch.root_location().y() - kPointRadius - 1);
386 }
387 }
388
389 void Remove() {
390 delete this;
391 }
392
393 private:
394 virtual ~TouchPointView() {
395 GetWidget()->RemoveObserver(this);
396 parent()->RemoveChildView(this);
397 }
398
399 // Overridden from views::View.
400 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
401 int alpha = kProjectionAlpha;
402 if (fadeout_)
403 alpha = static_cast<int>(fadeout_->CurrentValueBetween(alpha, 0));
404 fill_paint_.setAlpha(alpha);
405 stroke_paint_.setAlpha(alpha);
406 SkShader* shader = SkGradientShader::CreateRadial(
407 gradient_center_,
408 SkIntToScalar(kPointRadius),
409 gradient_colors_,
410 gradient_pos_,
411 arraysize(gradient_colors_),
412 SkShader::kMirror_TileMode,
413 NULL);
414 fill_paint_.setShader(shader);
415 shader->unref();
416 canvas->DrawCircle(circle_center_, SkIntToScalar(kPointRadius),
417 fill_paint_);
418 canvas->DrawCircle(circle_center_, SkIntToScalar(kPointRadius),
419 stroke_paint_);
420 }
421
422 // Overridden from ui::AnimationDelegate.
423 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE {
424 DCHECK_EQ(fadeout_.get(), animation);
425 delete this;
426 }
427
428 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE {
429 DCHECK_EQ(fadeout_.get(), animation);
430 SchedulePaint();
431 }
432
433 virtual void AnimationCanceled(const ui::Animation* animation) OVERRIDE {
434 AnimationEnded(animation);
435 }
436
437 // Overridden from views::WidgetObserver.
438 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE {
439 fadeout_->Stop();
440 }
441
442 const gfx::Point circle_center_;
443 const SkPoint gradient_center_;
444
445 SkPaint fill_paint_;
446 SkPaint stroke_paint_;
447 SkColor gradient_colors_[2];
448 SkScalar gradient_pos_[2];
449
450 scoped_ptr<ui::Animation> fadeout_;
451
452 DISALLOW_COPY_AND_ASSIGN(TouchPointView);
453 };
454
455 TouchObserverHUD::TouchObserverHUD(aura::RootWindow* initial_root)
456 : display_id_(initial_root->GetProperty(kDisplayIdKey)),
457 root_window_(initial_root),
458 mode_(FULLSCREEN),
459 touch_log_(new TouchLog()) {
460 const gfx::Display& display =
461 Shell::GetInstance()->display_manager()->GetDisplayForId(display_id_);
462
463 views::View* content = new views::View;
464 343
465 canvas_ = new TouchHudCanvas(*touch_log_); 344 canvas_ = new TouchHudCanvas(*touch_log_);
466 content->AddChildView(canvas_); 345 content->AddChildView(canvas_);
467 346
468 const gfx::Size& display_size = display.size(); 347 const gfx::Size& display_size = display.size();
469 canvas_->SetSize(display_size); 348 canvas_->SetSize(display_size);
470 content->SetSize(display_size);
471 349
472 label_container_ = new views::View; 350 label_container_ = new views::View;
473 label_container_->SetLayoutManager(new views::BoxLayout( 351 label_container_->SetLayoutManager(new views::BoxLayout(
474 views::BoxLayout::kVertical, 0, 0, 0)); 352 views::BoxLayout::kVertical, 0, 0, 0));
475 353
476 for (int i = 0; i < kMaxTouchPoints; ++i) { 354 for (int i = 0; i < kMaxTouchPoints; ++i) {
477 touch_labels_[i] = new views::Label; 355 touch_labels_[i] = new views::Label;
478 touch_labels_[i]->SetBackgroundColor(SkColorSetARGB(0, 255, 255, 255)); 356 touch_labels_[i]->SetBackgroundColor(SkColorSetARGB(0, 255, 255, 255));
479 touch_labels_[i]->SetShadowColors(SK_ColorWHITE, 357 touch_labels_[i]->SetShadowColors(SK_ColorWHITE,
480 SK_ColorWHITE); 358 SK_ColorWHITE);
481 touch_labels_[i]->SetShadowOffset(1, 1); 359 touch_labels_[i]->SetShadowOffset(1, 1);
482 label_container_->AddChildView(touch_labels_[i]); 360 label_container_->AddChildView(touch_labels_[i]);
483 } 361 }
484 label_container_->SetX(0); 362 label_container_->SetX(0);
485 label_container_->SetY(display_size.height() / kReducedScale); 363 label_container_->SetY(display_size.height() / kReducedScale);
486 label_container_->SetSize(label_container_->GetPreferredSize()); 364 label_container_->SetSize(label_container_->GetPreferredSize());
487 label_container_->SetVisible(false); 365 label_container_->SetVisible(false);
488 content->AddChildView(label_container_); 366 content->AddChildView(label_container_);
489
490 widget_ = new views::Widget();
491 views::Widget::InitParams
492 params(views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
493 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
494 params.can_activate = false;
495 params.accept_events = false;
496 params.bounds = gfx::Rect(display_size);
497 params.parent = Shell::GetContainer(
498 root_window_,
499 internal::kShellWindowId_OverlayContainer);
500 widget_->Init(params);
501 widget_->SetContentsView(content);
502 widget_->StackAtTop();
503 widget_->Show();
504
505 widget_->AddObserver(this);
506
507 // Observe changes in display size and mode to update touch HUD.
508 Shell::GetScreen()->AddObserver(this);
509 #if defined(OS_CHROMEOS)
510 Shell::GetInstance()->output_configurator()->AddObserver(this);
511 #endif // defined(OS_CHROMEOS)
512
513 Shell::GetInstance()->display_controller()->AddObserver(this);
514 root_window_->AddPreTargetHandler(this);
515 } 367 }
516 368
517 TouchObserverHUD::~TouchObserverHUD() { 369 TouchHudDebug::~TouchHudDebug() {
518 Shell::GetInstance()->display_controller()->RemoveObserver(this);
519
520 #if defined(OS_CHROMEOS)
521 Shell::GetInstance()->output_configurator()->RemoveObserver(this);
522 #endif // defined(OS_CHROMEOS)
523 Shell::GetScreen()->RemoveObserver(this);
524
525 widget_->RemoveObserver(this);
526 } 370 }
527 371
528 // static 372 // static
529 scoped_ptr<DictionaryValue> TouchObserverHUD::GetAllAsDictionary() { 373 scoped_ptr<DictionaryValue> TouchHudDebug::GetAllAsDictionary() {
530 scoped_ptr<DictionaryValue> value(new DictionaryValue()); 374 scoped_ptr<DictionaryValue> value(new DictionaryValue());
531 Shell::RootWindowList roots = Shell::GetInstance()->GetAllRootWindows(); 375 Shell::RootWindowList roots = Shell::GetInstance()->GetAllRootWindows();
532 for (Shell::RootWindowList::iterator iter = roots.begin(); 376 for (Shell::RootWindowList::iterator iter = roots.begin();
533 iter != roots.end(); ++iter) { 377 iter != roots.end(); ++iter) {
534 internal::RootWindowController* controller = GetRootWindowController(*iter); 378 internal::RootWindowController* controller = GetRootWindowController(*iter);
535 if (controller->touch_observer_hud()) { 379 internal::TouchHudDebug* hud = controller->touch_hud_debug();
536 int64 display_id = (*iter)->GetProperty(kDisplayIdKey); 380 if (hud) {
537 scoped_ptr<ListValue> list = 381 scoped_ptr<ListValue> list = hud->GetLogAsList();
538 controller->touch_observer_hud()->GetLogAsList();
539 if (!list->empty()) 382 if (!list->empty())
540 value->Set(base::Int64ToString(display_id), list.release()); 383 value->Set(base::Int64ToString(hud->display_id()), list.release());
541 } 384 }
542 } 385 }
543 return value.Pass(); 386 return value.Pass();
544 } 387 }
545 388
546 void TouchObserverHUD::ChangeToNextMode() { 389 void TouchHudDebug::ChangeToNextMode() {
547 switch (mode_) { 390 switch (mode_) {
548 case FULLSCREEN: 391 case FULLSCREEN:
549 SetMode(REDUCED_SCALE); 392 SetMode(REDUCED_SCALE);
550 break; 393 break;
551 case REDUCED_SCALE: 394 case REDUCED_SCALE:
552 SetMode(PROJECTION);
553 break;
554 case PROJECTION:
555 SetMode(INVISIBLE); 395 SetMode(INVISIBLE);
556 break; 396 break;
557 case INVISIBLE: 397 case INVISIBLE:
558 SetMode(FULLSCREEN); 398 SetMode(FULLSCREEN);
559 break; 399 break;
560 } 400 }
561 } 401 }
562 402
563 void TouchObserverHUD::Clear() { 403 scoped_ptr<ListValue> TouchHudDebug::GetLogAsList() const {
564 if (widget_->IsVisible())
565 canvas_->Clear();
566 for (int i = 0; i < kMaxTouchPoints; ++i)
567 touch_labels_[i]->SetText(string16());
568 label_container_->SetSize(label_container_->GetPreferredSize());
569 }
570
571 scoped_ptr<ListValue> TouchObserverHUD::GetLogAsList() const {
572 return touch_log_->GetAsList(); 404 return touch_log_->GetAsList();
573 } 405 }
574 406
575 void TouchObserverHUD::SetMode(Mode mode) { 407 void TouchHudDebug::Clear() {
408 if (widget()->IsVisible()) {
409 canvas_->Clear();
410 for (int i = 0; i < kMaxTouchPoints; ++i)
411 touch_labels_[i]->SetText(string16());
412 label_container_->SetSize(label_container_->GetPreferredSize());
413 }
414 }
415
416 void TouchHudDebug::SetMode(Mode mode) {
576 if (mode_ == mode) 417 if (mode_ == mode)
577 return; 418 return;
578 // When going out of projection mode, hide all active touch points.
579 if (mode_ == PROJECTION) {
580 for (std::map<int, TouchPointView*>::iterator iter = points_.begin();
581 iter != points_.end(); ++iter)
582 iter->second->Remove();
583 points_.clear();
584 }
585 mode_ = mode; 419 mode_ = mode;
586 switch (mode) { 420 switch (mode) {
587 case FULLSCREEN: 421 case FULLSCREEN:
588 label_container_->SetVisible(false); 422 label_container_->SetVisible(false);
589 canvas_->SetVisible(true); 423 canvas_->SetVisible(true);
590 canvas_->SetScale(1); 424 canvas_->SetScale(1);
591 canvas_->SchedulePaint(); 425 canvas_->SchedulePaint();
592 widget_->Show(); 426 widget()->Show();
593 break; 427 break;
594 case REDUCED_SCALE: 428 case REDUCED_SCALE:
595 label_container_->SetVisible(true); 429 label_container_->SetVisible(true);
596 canvas_->SetVisible(true); 430 canvas_->SetVisible(true);
597 canvas_->SetScale(kReducedScale); 431 canvas_->SetScale(kReducedScale);
598 canvas_->SchedulePaint(); 432 canvas_->SchedulePaint();
599 widget_->Show(); 433 widget()->Show();
600 break;
601 case PROJECTION:
602 label_container_->SetVisible(false);
603 canvas_->SetVisible(false);
604 widget_->Show();
605 break; 434 break;
606 case INVISIBLE: 435 case INVISIBLE:
607 widget_->Hide(); 436 widget()->Hide();
608 break; 437 break;
609 } 438 }
610 } 439 }
611 440
612 void TouchObserverHUD::UpdateTouchPointLabel(int index) { 441 void TouchHudDebug::UpdateTouchPointLabel(int index) {
613 int trace_index = touch_log_->GetTraceIndex(index); 442 int trace_index = touch_log_->GetTraceIndex(index);
614 const TouchTrace& trace = touch_log_->traces()[trace_index]; 443 const TouchTrace& trace = touch_log_->traces()[trace_index];
615 TouchTrace::const_reverse_iterator point = trace.log().rbegin(); 444 TouchTrace::const_reverse_iterator point = trace.log().rbegin();
616 ui::EventType touch_status = point->type; 445 ui::EventType touch_status = point->type;
617 float touch_radius = std::max(point->radius_x, point->radius_y); 446 float touch_radius = std::max(point->radius_x, point->radius_y);
618 while (point != trace.log().rend() && point->type == ui::ET_TOUCH_CANCELLED) 447 while (point != trace.log().rend() && point->type == ui::ET_TOUCH_CANCELLED)
619 point++; 448 point++;
620 DCHECK(point != trace.log().rend()); 449 DCHECK(point != trace.log().rend());
621 gfx::Point touch_position = point->location; 450 gfx::Point touch_position = point->location;
622 451
623 std::string string = base::StringPrintf("%2d: %s %s (%.4f)", 452 std::string string = base::StringPrintf("%2d: %s %s (%.4f)",
624 index, 453 index,
625 GetTouchEventLabel(touch_status), 454 GetTouchEventLabel(touch_status),
626 touch_position.ToString().c_str(), 455 touch_position.ToString().c_str(),
627 touch_radius); 456 touch_radius);
628 touch_labels_[index]->SetText(UTF8ToUTF16(string)); 457 touch_labels_[index]->SetText(UTF8ToUTF16(string));
629 } 458 }
630 459
631 void TouchObserverHUD::OnTouchEvent(ui::TouchEvent* event) { 460 void TouchHudDebug::OnTouchEvent(ui::TouchEvent* event) {
632 if (event->touch_id() >= kMaxTouchPoints) 461 if (event->touch_id() >= kMaxTouchPoints)
633 return; 462 return;
634 463
635 touch_log_->AddTouchPoint(*event); 464 touch_log_->AddTouchPoint(*event);
636 canvas_->TouchPointAdded(event->touch_id()); 465 canvas_->TouchPointAdded(event->touch_id());
637
638 if (mode_ == PROJECTION) {
639 if (event->type() == ui::ET_TOUCH_PRESSED) {
640 TouchPointView* point = new TouchPointView(widget_);
641 point->UpdateTouch(*event);
642 std::pair<std::map<int, TouchPointView*>::iterator, bool> result =
643 points_.insert(std::make_pair(event->touch_id(), point));
644 // If a |TouchPointView| is already mapped to the touch id, remove it and
645 // replace it with the new one.
646 if (!result.second) {
647 result.first->second->Remove();
648 result.first->second = point;
649 }
650 } else {
651 std::map<int, TouchPointView*>::iterator iter =
652 points_.find(event->touch_id());
653 if (iter != points_.end()) {
654 iter->second->UpdateTouch(*event);
655 if (event->type() == ui::ET_TOUCH_RELEASED ||
656 event->type() == ui::ET_TOUCH_CANCELLED)
657 points_.erase(iter);
658 }
659 }
660 }
661
662 UpdateTouchPointLabel(event->touch_id()); 466 UpdateTouchPointLabel(event->touch_id());
663 label_container_->SetSize(label_container_->GetPreferredSize()); 467 label_container_->SetSize(label_container_->GetPreferredSize());
664 } 468 }
665 469
666 void TouchObserverHUD::OnWidgetDestroying(views::Widget* widget) { 470 void TouchHudDebug::OnDisplayBoundsChanged(const gfx::Display& display) {
667 DCHECK_EQ(widget, widget_); 471 TouchObserverHUD::OnDisplayBoundsChanged(display);
668 delete this;
669 }
670 472
671 void TouchObserverHUD::OnDisplayBoundsChanged(const gfx::Display& display) { 473 if (display.id() != display_id())
672 if (display.id() != display_id_)
673 return; 474 return;
674 const gfx::Size& size = display.size(); 475 const gfx::Size& size = display.size();
675 widget_->SetSize(size);
676 canvas_->SetSize(size); 476 canvas_->SetSize(size);
677 label_container_->SetY(size.height() / kReducedScale); 477 label_container_->SetY(size.height() / kReducedScale);
678 } 478 }
679 479
680 void TouchObserverHUD::OnDisplayAdded(const gfx::Display& new_display) {} 480 void TouchHudDebug::SetHudForRootWindowController(
681 481 RootWindowController* controller) {
682 void TouchObserverHUD::OnDisplayRemoved(const gfx::Display& old_display) { 482 controller->set_touch_hud_debug(this);
683 if (old_display.id() != display_id_)
684 return;
685 widget_->CloseNow();
686 } 483 }
687 484
688 #if defined(OS_CHROMEOS) 485 void TouchHudDebug::UnsetHudForRootWindowController(
689 void TouchObserverHUD::OnDisplayModeChanged() { 486 RootWindowController* controller) {
690 // Clear touch HUD for any change in display mode (single, dual extended, dual 487 controller->set_touch_hud_debug(NULL);
691 // mirrored, ...).
692 Clear();
693 }
694 #endif // defined(OS_CHROMEOS)
695
696 void TouchObserverHUD::OnDisplayConfigurationChanging() {
697 if (!root_window_)
698 return;
699
700 root_window_->RemovePreTargetHandler(this);
701
702 RootWindowController* controller = GetRootWindowController(root_window_);
703 controller->set_touch_observer_hud(NULL);
704
705 views::Widget::ReparentNativeView(
706 widget_->GetNativeView(),
707 Shell::GetContainer(root_window_,
708 internal::kShellWindowId_UnparentedControlContainer));
709
710 root_window_ = NULL;
711 }
712
713 void TouchObserverHUD::OnDisplayConfigurationChanged() {
714 if (root_window_)
715 return;
716
717 root_window_ = Shell::GetInstance()->display_controller()->
718 GetRootWindowForDisplayId(display_id_);
719
720 views::Widget::ReparentNativeView(
721 widget_->GetNativeView(),
722 Shell::GetContainer(root_window_,
723 internal::kShellWindowId_OverlayContainer));
724
725 RootWindowController* controller = GetRootWindowController(root_window_);
726 controller->set_touch_observer_hud(this);
727
728 root_window_->AddPreTargetHandler(this);
729 } 488 }
730 489
731 } // namespace internal 490 } // namespace internal
732 } // namespace ash 491 } // namespace ash
OLDNEW
« no previous file with comments | « ash/touch/touch_hud_debug.h ('k') | ash/touch/touch_hud_projection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698