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

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: fix clang/win-aura 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
« no previous file with comments | « ash/touch/touch_observer_hud.h ('k') | chrome/app/generated_resources.grd » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 views::View* content = new views::View;
21 content->SetLayoutManager(new views::BoxLayout(
22 views::BoxLayout::kVertical, 0, 0, 0));
23
24 for (int i = 0; i < kMaxTouchPoints; ++i) {
25 touch_status_[i] = ui::ET_UNKNOWN;
26 touch_labels_[i] = new views::Label;
27 touch_labels_[i]->SetBackgroundColor(SkColorSetARGB(0, 255, 255, 255));
28 touch_labels_[i]->SetShadowColors(SK_ColorWHITE,
29 SK_ColorWHITE);
30 touch_labels_[i]->SetShadowOffset(1, 1);
31 touch_labels_[i]->SetVisible(false);
32 content->AddChildView(touch_labels_[i]);
33 }
34
35 widget_.reset(new views::Widget());
36 views::Widget::InitParams
37 params(views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
38 params.transparent = true;
39 params.can_activate = false;
40 params.bounds = gfx::Rect(content->GetPreferredSize());
41 params.parent = Shell::GetInstance()->GetContainer(
42 internal::kShellWindowId_OverlayContainer);
43 widget_->Init(params);
44 widget_->SetContentsView(content);
45 widget_->StackAtTop();
46 widget_->Show();
47 }
48
49 TouchObserverHUD::~TouchObserverHUD() {}
50
51 void TouchObserverHUD::UpdateTouchPointLabel(int index) {
52 const char* status = NULL;
53 switch (touch_status_[index]) {
54 case ui::ET_UNKNOWN:
55 status = " ";
56 break;
57 case ui::ET_TOUCH_PRESSED:
58 status = "P";
59 break;
60 case ui::ET_TOUCH_MOVED:
61 status = "M";
62 break;
63 case ui::ET_TOUCH_RELEASED:
64 status = "R";
65 break;
66 case ui::ET_TOUCH_CANCELLED:
67 status = "C";
68 break;
69 default:
70 status = "?";
71 break;
72 }
73 std::string string = base::StringPrintf("%2d: %s %s",
74 index, status, touch_positions_[index].ToString().c_str());
75 touch_labels_[index]->SetText(UTF8ToUTF16(string));
76 }
77
78 bool TouchObserverHUD::PreHandleKeyEvent(aura::Window* target,
79 aura::KeyEvent* event) {
80 return false;
81 }
82
83 bool TouchObserverHUD::PreHandleMouseEvent(aura::Window* target,
84 aura::MouseEvent* event) {
85 return false;
86 }
87
88 ui::TouchStatus TouchObserverHUD::PreHandleTouchEvent(
89 aura::Window* target,
90 aura::TouchEvent* event) {
91 if (event->touch_id() >= kMaxTouchPoints)
92 return ui::TOUCH_STATUS_UNKNOWN;
93
94 if (event->type() != ui::ET_TOUCH_CANCELLED)
95 touch_positions_[event->touch_id()] = event->root_location();
96 touch_status_[event->touch_id()] = event->type();
97 touch_labels_[event->touch_id()]->SetVisible(true);
98 UpdateTouchPointLabel(event->touch_id());
99
100 widget_->SetSize(widget_->GetContentsView()->GetPreferredSize());
101
102 return ui::TOUCH_STATUS_UNKNOWN;
103 }
104
105 ui::GestureStatus TouchObserverHUD::PreHandleGestureEvent(
106 aura::Window* target,
107 aura::GestureEvent* event) {
108 return ui::GESTURE_STATUS_UNKNOWN;
109 }
110
111 } // namespace internal
112 } // namespace ash
OLDNEW
« no previous file with comments | « ash/touch/touch_observer_hud.h ('k') | chrome/app/generated_resources.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698