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

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: Renamed TouchHudDebug and applied some more reviews 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
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.
349 class TouchPointView : public views::View,
350 public ui::AnimationDelegate,
351 public views::WidgetObserver {
352 public:
353 explicit TouchPointView(views::Widget* parent_widget)
354 : circle_center_(kPointRadius + 1, kPointRadius + 1),
355 gradient_center_(SkPoint::Make(kPointRadius + 1,
356 kPointRadius + 1)) {
357 SetPaintToLayer(true);
358 SetFillsBoundsOpaquely(false);
359
360 SetSize(gfx::Size(2 * kPointRadius + 2, 2 * kPointRadius + 2));
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), 335 mode_(FULLSCREEN),
459 touch_log_(new TouchLog()) { 336 touch_log_(new TouchLog()) {
sky 2013/06/26 21:07:44 Please member initialize all primitives/pointers (
mohsen 2013/06/27 00:44:31 Done. (Isn't it enough that they're initialized in
sky 2013/06/28 16:09:00 Your argument equally applies to whether you shoul
460 const gfx::Display& display = 337 const gfx::Display& display =
461 Shell::GetInstance()->display_manager()->GetDisplayForId(display_id_); 338 Shell::GetInstance()->display_manager()->GetDisplayForId(display_id());
462 339
463 views::View* content = new views::View; 340 views::View* content = widget()->GetContentsView();
464 341
465 canvas_ = new TouchHudCanvas(*touch_log_); 342 canvas_ = new TouchHudCanvas(*touch_log_);
466 content->AddChildView(canvas_); 343 content->AddChildView(canvas_);
467 344
468 const gfx::Size& display_size = display.size(); 345 const gfx::Size& display_size = display.size();
469 canvas_->SetSize(display_size); 346 canvas_->SetSize(display_size);
470 content->SetSize(display_size);
471 347
472 label_container_ = new views::View; 348 label_container_ = new views::View;
473 label_container_->SetLayoutManager(new views::BoxLayout( 349 label_container_->SetLayoutManager(new views::BoxLayout(
474 views::BoxLayout::kVertical, 0, 0, 0)); 350 views::BoxLayout::kVertical, 0, 0, 0));
475 351
476 for (int i = 0; i < kMaxTouchPoints; ++i) { 352 for (int i = 0; i < kMaxTouchPoints; ++i) {
477 touch_labels_[i] = new views::Label; 353 touch_labels_[i] = new views::Label;
478 touch_labels_[i]->SetBackgroundColor(SkColorSetARGB(0, 255, 255, 255)); 354 touch_labels_[i]->SetBackgroundColor(SkColorSetARGB(0, 255, 255, 255));
479 touch_labels_[i]->SetShadowColors(SK_ColorWHITE, 355 touch_labels_[i]->SetShadowColors(SK_ColorWHITE,
480 SK_ColorWHITE); 356 SK_ColorWHITE);
481 touch_labels_[i]->SetShadowOffset(1, 1); 357 touch_labels_[i]->SetShadowOffset(1, 1);
482 label_container_->AddChildView(touch_labels_[i]); 358 label_container_->AddChildView(touch_labels_[i]);
483 } 359 }
484 label_container_->SetX(0); 360 label_container_->SetX(0);
485 label_container_->SetY(display_size.height() / kReducedScale); 361 label_container_->SetY(display_size.height() / kReducedScale);
486 label_container_->SetSize(label_container_->GetPreferredSize()); 362 label_container_->SetSize(label_container_->GetPreferredSize());
487 label_container_->SetVisible(false); 363 label_container_->SetVisible(false);
488 content->AddChildView(label_container_); 364 content->AddChildView(label_container_);
489
490 widget_ = new views::Widget();
491 views::Widget::InitParams
492 params(views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
493 params.transparent = true;
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 } 365 }
516 366
517 TouchObserverHUD::~TouchObserverHUD() { 367 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 } 368 }
527 369
528 // static 370 // static
529 scoped_ptr<DictionaryValue> TouchObserverHUD::GetAllAsDictionary() { 371 scoped_ptr<DictionaryValue> TouchHudDebug::GetAllAsDictionary() {
530 scoped_ptr<DictionaryValue> value(new DictionaryValue()); 372 scoped_ptr<DictionaryValue> value(new DictionaryValue());
531 Shell::RootWindowList roots = Shell::GetInstance()->GetAllRootWindows(); 373 Shell::RootWindowList roots = Shell::GetInstance()->GetAllRootWindows();
532 for (Shell::RootWindowList::iterator iter = roots.begin(); 374 for (Shell::RootWindowList::iterator iter = roots.begin();
533 iter != roots.end(); ++iter) { 375 iter != roots.end(); ++iter) {
534 internal::RootWindowController* controller = GetRootWindowController(*iter); 376 internal::RootWindowController* controller = GetRootWindowController(*iter);
535 if (controller->touch_observer_hud()) { 377 internal::TouchHudDebug* hud = controller->touch_hud_debug();
536 int64 display_id = (*iter)->GetProperty(kDisplayIdKey); 378 if (hud) {
537 scoped_ptr<ListValue> list = 379 scoped_ptr<ListValue> list = hud->GetLogAsList();
538 controller->touch_observer_hud()->GetLogAsList();
539 if (!list->empty()) 380 if (!list->empty())
540 value->Set(base::Int64ToString(display_id), list.release()); 381 value->Set(base::Int64ToString(hud->display_id()), list.release());
541 } 382 }
542 } 383 }
543 return value.Pass(); 384 return value.Pass();
544 } 385 }
545 386
546 void TouchObserverHUD::ChangeToNextMode() { 387 void TouchHudDebug::ChangeToNextMode() {
547 switch (mode_) { 388 switch (mode_) {
548 case FULLSCREEN: 389 case FULLSCREEN:
549 SetMode(REDUCED_SCALE); 390 SetMode(REDUCED_SCALE);
550 break; 391 break;
551 case REDUCED_SCALE: 392 case REDUCED_SCALE:
552 SetMode(PROJECTION);
553 break;
554 case PROJECTION:
555 SetMode(INVISIBLE); 393 SetMode(INVISIBLE);
556 break; 394 break;
557 case INVISIBLE: 395 case INVISIBLE:
558 SetMode(FULLSCREEN); 396 SetMode(FULLSCREEN);
559 break; 397 break;
560 } 398 }
561 } 399 }
562 400
563 void TouchObserverHUD::Clear() { 401 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(); 402 return touch_log_->GetAsList();
573 } 403 }
574 404
575 void TouchObserverHUD::SetMode(Mode mode) { 405 void TouchHudDebug::Clear() {
406 if (widget()->IsVisible()) {
407 canvas_->Clear();
408 for (int i = 0; i < kMaxTouchPoints; ++i)
409 touch_labels_[i]->SetText(string16());
410 label_container_->SetSize(label_container_->GetPreferredSize());
411 }
412 }
413
414 void TouchHudDebug::SetMode(Mode mode) {
576 if (mode_ == mode) 415 if (mode_ == mode)
577 return; 416 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; 417 mode_ = mode;
586 switch (mode) { 418 switch (mode) {
587 case FULLSCREEN: 419 case FULLSCREEN:
588 label_container_->SetVisible(false); 420 label_container_->SetVisible(false);
589 canvas_->SetVisible(true); 421 canvas_->SetVisible(true);
590 canvas_->SetScale(1); 422 canvas_->SetScale(1);
591 canvas_->SchedulePaint(); 423 canvas_->SchedulePaint();
592 widget_->Show(); 424 widget()->Show();
593 break; 425 break;
594 case REDUCED_SCALE: 426 case REDUCED_SCALE:
595 label_container_->SetVisible(true); 427 label_container_->SetVisible(true);
596 canvas_->SetVisible(true); 428 canvas_->SetVisible(true);
597 canvas_->SetScale(kReducedScale); 429 canvas_->SetScale(kReducedScale);
598 canvas_->SchedulePaint(); 430 canvas_->SchedulePaint();
599 widget_->Show(); 431 widget()->Show();
600 break;
601 case PROJECTION:
602 label_container_->SetVisible(false);
603 canvas_->SetVisible(false);
604 widget_->Show();
605 break; 432 break;
606 case INVISIBLE: 433 case INVISIBLE:
607 widget_->Hide(); 434 widget()->Hide();
608 break; 435 break;
609 } 436 }
610 } 437 }
611 438
612 void TouchObserverHUD::UpdateTouchPointLabel(int index) { 439 void TouchHudDebug::UpdateTouchPointLabel(int index) {
613 int trace_index = touch_log_->GetTraceIndex(index); 440 int trace_index = touch_log_->GetTraceIndex(index);
614 const TouchTrace& trace = touch_log_->traces()[trace_index]; 441 const TouchTrace& trace = touch_log_->traces()[trace_index];
615 TouchTrace::const_reverse_iterator point = trace.log().rbegin(); 442 TouchTrace::const_reverse_iterator point = trace.log().rbegin();
616 ui::EventType touch_status = point->type; 443 ui::EventType touch_status = point->type;
617 float touch_radius = std::max(point->radius_x, point->radius_y); 444 float touch_radius = std::max(point->radius_x, point->radius_y);
618 while (point != trace.log().rend() && point->type == ui::ET_TOUCH_CANCELLED) 445 while (point != trace.log().rend() && point->type == ui::ET_TOUCH_CANCELLED)
619 point++; 446 point++;
620 DCHECK(point != trace.log().rend()); 447 DCHECK(point != trace.log().rend());
621 gfx::Point touch_position = point->location; 448 gfx::Point touch_position = point->location;
622 449
623 std::string string = base::StringPrintf("%2d: %s %s (%.4f)", 450 std::string string = base::StringPrintf("%2d: %s %s (%.4f)",
624 index, 451 index,
625 GetTouchEventLabel(touch_status), 452 GetTouchEventLabel(touch_status),
626 touch_position.ToString().c_str(), 453 touch_position.ToString().c_str(),
627 touch_radius); 454 touch_radius);
628 touch_labels_[index]->SetText(UTF8ToUTF16(string)); 455 touch_labels_[index]->SetText(UTF8ToUTF16(string));
629 } 456 }
630 457
631 void TouchObserverHUD::OnTouchEvent(ui::TouchEvent* event) { 458 void TouchHudDebug::OnTouchEvent(ui::TouchEvent* event) {
632 if (event->touch_id() >= kMaxTouchPoints) 459 if (event->touch_id() >= kMaxTouchPoints)
633 return; 460 return;
634 461
635 touch_log_->AddTouchPoint(*event); 462 touch_log_->AddTouchPoint(*event);
636 canvas_->TouchPointAdded(event->touch_id()); 463 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()); 464 UpdateTouchPointLabel(event->touch_id());
663 label_container_->SetSize(label_container_->GetPreferredSize()); 465 label_container_->SetSize(label_container_->GetPreferredSize());
664 } 466 }
665 467
666 void TouchObserverHUD::OnWidgetDestroying(views::Widget* widget) { 468 void TouchHudDebug::OnDisplayBoundsChanged(const gfx::Display& display) {
667 DCHECK_EQ(widget, widget_); 469 TouchObserverHUD::OnDisplayBoundsChanged(display);
668 delete this;
669 }
670 470
671 void TouchObserverHUD::OnDisplayBoundsChanged(const gfx::Display& display) { 471 if (display.id() != display_id())
672 if (display.id() != display_id_)
673 return; 472 return;
674 const gfx::Size& size = display.size(); 473 const gfx::Size& size = display.size();
675 widget_->SetSize(size);
676 canvas_->SetSize(size); 474 canvas_->SetSize(size);
677 label_container_->SetY(size.height() / kReducedScale); 475 label_container_->SetY(size.height() / kReducedScale);
678 } 476 }
679 477
680 void TouchObserverHUD::OnDisplayAdded(const gfx::Display& new_display) {} 478 void TouchHudDebug::SetHudForRootWindowController(
681 479 RootWindowController* controller) {
682 void TouchObserverHUD::OnDisplayRemoved(const gfx::Display& old_display) { 480 controller->set_touch_hud_debug(this);
683 if (old_display.id() != display_id_)
684 return;
685 widget_->CloseNow();
686 } 481 }
687 482
688 #if defined(OS_CHROMEOS) 483 void TouchHudDebug::UnsetHudForRootWindowController(
689 void TouchObserverHUD::OnDisplayModeChanged() { 484 RootWindowController* controller) {
690 // Clear touch HUD for any change in display mode (single, dual extended, dual 485 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 } 486 }
730 487
731 } // namespace internal 488 } // namespace internal
732 } // namespace ash 489 } // namespace ash
OLDNEW
« ash/shell.h ('K') | « 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