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

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

Issue 10386178: ash: Add a heads-up display to track touch-point states and positions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 7 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
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ash/touch/touch_observer_hud.h"
6
7 #include "ash/shell_window_ids.h"
8 #include "base/stringprintf.h"
9 #include "base/utf_string_conversions.h"
10 #include "ui/aura/event.h"
11 #include "ui/views/background.h"
12 #include "ui/views/controls/label.h"
13 #include "ui/views/layout/box_layout.h"
14 #include "ui/views/widget/widget.h"
15
16 namespace ash {
17 namespace internal {
18
19 TouchObserverHUD::TouchObserverHUD() {}
20
21 TouchObserverHUD::~TouchObserverHUD() {}
22
23 void TouchObserverHUD::Initialize() {
24 views::View* content = new views::View;
25 content->SetLayoutManager(new views::BoxLayout(
26 views::BoxLayout::kVertical, 0, 0, 0));
27
28 for (int i = 0; i < kMaxTouchPoints; ++i) {
29 touch_status_[i] = ui::ET_UNKNOWN;
30 touch_labels_[i] = new views::Label;
31 touch_labels_[i]->SetBackgroundColor(SkColorSetARGB(0, 255, 255, 255));
32 touch_labels_[i]->SetShadowColors(SK_ColorWHITE,
33 SK_ColorWHITE);
34 touch_labels_[i]->SetShadowOffset(1, 1);
35 touch_labels_[i]->SetVisible(false);
36 content->AddChildView(touch_labels_[i]);
37 }
38
39 widget_.reset(new views::Widget());
40 views::Widget::InitParams
41 params(views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
42 params.transparent = true;
43 params.can_activate = false;
44 params.bounds = gfx::Rect(content->GetPreferredSize());
45 params.parent = Shell::GetInstance()->GetContainer(
46 internal::kShellWindowId_OverlayContainer);
47 widget_->Init(params);
48 widget_->SetContentsView(content);
49 widget_->StackAtTop();
50 widget_->Show();
51 }
52
53 void TouchObserverHUD::UpdateTouchPointLabel(int index) {
54 const char* status = NULL;
55 switch (touch_status_[index]) {
56 case ui::ET_UNKNOWN:
57 status = " ";
58 break;
59 case ui::ET_TOUCH_PRESSED:
60 status = "P";
61 break;
62 case ui::ET_TOUCH_MOVED:
63 status = "M";
64 break;
65 case ui::ET_TOUCH_RELEASED:
66 status = "R";
67 break;
68 case ui::ET_TOUCH_CANCELLED:
69 status = "C";
70 break;
71 default:
72 status = "?";
73 break;
74 }
75 std::string string = base::StringPrintf("%2d: %s %s",
76 index, status, touch_positions_[index].ToString().c_str());
77 touch_labels_[index]->SetText(UTF8ToUTF16(string));
78 }
79
80 bool TouchObserverHUD::PreHandleKeyEvent(aura::Window* target,
81 aura::KeyEvent* event) OVERRIDE {
82 return false;
83 }
84
85 bool TouchObserverHUD::PreHandleMouseEvent(aura::Window* target,
86 aura::MouseEvent* event) OVERRIDE {
87 return false;
88 }
89
90 ui::TouchStatus TouchObserverHUD::PreHandleTouchEvent(
91 aura::Window* target,
92 aura::TouchEvent* event) OVERRIDE {
93 if (event->touch_id() >= kMaxTouchPoints)
94 return ui::TOUCH_STATUS_UNKNOWN;
95
96 if (event->type() != ui::ET_TOUCH_CANCELLED)
97 touch_positions_[event->touch_id()] = event->root_location();
98 touch_status_[event->touch_id()] = event->type();
99 touch_labels_[event->touch_id()]->SetVisible(true);
100 UpdateTouchPointLabel(event->touch_id());
101
102 widget_->SetSize(widget_->GetContentsView()->GetPreferredSize());
103
104 return ui::TOUCH_STATUS_UNKNOWN;
105 }
106
107 ui::GestureStatus TouchObserverHUD::PreHandleGestureEvent(
108 aura::Window* target,
109 aura::GestureEvent* event) OVERRIDE {
110 return ui::GESTURE_STATUS_UNKNOWN;
111 }
112
113 } // namespace internal
114 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698