summaryrefslogtreecommitdiffstats
path: root/ash/touch
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-17 01:44:41 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-17 01:44:41 +0000
commit7307474f771ee48241f2769edd19e3aea62c4031 (patch)
treec24d283dd099e568269a53885b939d099e071d8d /ash/touch
parent96191d56d125050904d21a4a7e5585ad1bbaee05 (diff)
downloadchromium_src-7307474f771ee48241f2769edd19e3aea62c4031.zip
chromium_src-7307474f771ee48241f2769edd19e3aea62c4031.tar.gz
chromium_src-7307474f771ee48241f2769edd19e3aea62c4031.tar.bz2
ash: Add a heads-up display to track touch-point states and positions.
The command-line flag to turn on the HUD is --ash-touch-hud. It can also be turned on from about:flags BUG=none TEST=manually Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=137549 Review URL: https://chromiumcodereview.appspot.com/10386178 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137605 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/touch')
-rw-r--r--ash/touch/touch_observer_hud.cc112
-rw-r--r--ash/touch/touch_observer_hud.h59
2 files changed, 171 insertions, 0 deletions
diff --git a/ash/touch/touch_observer_hud.cc b/ash/touch/touch_observer_hud.cc
new file mode 100644
index 0000000..d383c60
--- /dev/null
+++ b/ash/touch/touch_observer_hud.cc
@@ -0,0 +1,112 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/touch/touch_observer_hud.h"
+
+#include "ash/shell_window_ids.h"
+#include "base/stringprintf.h"
+#include "base/utf_string_conversions.h"
+#include "ui/aura/event.h"
+#include "ui/views/background.h"
+#include "ui/views/controls/label.h"
+#include "ui/views/layout/box_layout.h"
+#include "ui/views/widget/widget.h"
+
+namespace ash {
+namespace internal {
+
+TouchObserverHUD::TouchObserverHUD() {
+ views::View* content = new views::View;
+ content->SetLayoutManager(new views::BoxLayout(
+ views::BoxLayout::kVertical, 0, 0, 0));
+
+ for (int i = 0; i < kMaxTouchPoints; ++i) {
+ touch_status_[i] = ui::ET_UNKNOWN;
+ touch_labels_[i] = new views::Label;
+ touch_labels_[i]->SetBackgroundColor(SkColorSetARGB(0, 255, 255, 255));
+ touch_labels_[i]->SetShadowColors(SK_ColorWHITE,
+ SK_ColorWHITE);
+ touch_labels_[i]->SetShadowOffset(1, 1);
+ touch_labels_[i]->SetVisible(false);
+ content->AddChildView(touch_labels_[i]);
+ }
+
+ widget_.reset(new views::Widget());
+ views::Widget::InitParams
+ params(views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
+ params.transparent = true;
+ params.can_activate = false;
+ params.bounds = gfx::Rect(content->GetPreferredSize());
+ params.parent = Shell::GetInstance()->GetContainer(
+ internal::kShellWindowId_OverlayContainer);
+ widget_->Init(params);
+ widget_->SetContentsView(content);
+ widget_->StackAtTop();
+ widget_->Show();
+}
+
+TouchObserverHUD::~TouchObserverHUD() {}
+
+void TouchObserverHUD::UpdateTouchPointLabel(int index) {
+ const char* status = NULL;
+ switch (touch_status_[index]) {
+ case ui::ET_UNKNOWN:
+ status = " ";
+ break;
+ case ui::ET_TOUCH_PRESSED:
+ status = "P";
+ break;
+ case ui::ET_TOUCH_MOVED:
+ status = "M";
+ break;
+ case ui::ET_TOUCH_RELEASED:
+ status = "R";
+ break;
+ case ui::ET_TOUCH_CANCELLED:
+ status = "C";
+ break;
+ default:
+ status = "?";
+ break;
+ }
+ std::string string = base::StringPrintf("%2d: %s %s",
+ index, status, touch_positions_[index].ToString().c_str());
+ touch_labels_[index]->SetText(UTF8ToUTF16(string));
+}
+
+bool TouchObserverHUD::PreHandleKeyEvent(aura::Window* target,
+ aura::KeyEvent* event) {
+ return false;
+}
+
+bool TouchObserverHUD::PreHandleMouseEvent(aura::Window* target,
+ aura::MouseEvent* event) {
+ return false;
+}
+
+ui::TouchStatus TouchObserverHUD::PreHandleTouchEvent(
+ aura::Window* target,
+ aura::TouchEvent* event) {
+ if (event->touch_id() >= kMaxTouchPoints)
+ return ui::TOUCH_STATUS_UNKNOWN;
+
+ if (event->type() != ui::ET_TOUCH_CANCELLED)
+ touch_positions_[event->touch_id()] = event->root_location();
+ touch_status_[event->touch_id()] = event->type();
+ touch_labels_[event->touch_id()]->SetVisible(true);
+ UpdateTouchPointLabel(event->touch_id());
+
+ widget_->SetSize(widget_->GetContentsView()->GetPreferredSize());
+
+ return ui::TOUCH_STATUS_UNKNOWN;
+}
+
+ui::GestureStatus TouchObserverHUD::PreHandleGestureEvent(
+ aura::Window* target,
+ aura::GestureEvent* event) {
+ return ui::GESTURE_STATUS_UNKNOWN;
+}
+
+} // namespace internal
+} // namespace ash
diff --git a/ash/touch/touch_observer_hud.h b/ash/touch/touch_observer_hud.h
new file mode 100644
index 0000000..3da6a56
--- /dev/null
+++ b/ash/touch/touch_observer_hud.h
@@ -0,0 +1,59 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ASH_TOUCH_TOUCH_OBSERVER_HUD_H_
+#define ASH_TOUCH_TOUCH_OBSERVER_HUD_H_
+#pragma once
+
+#include "ash/shell.h"
+#include "ui/aura/event_filter.h"
+#include "ui/gfx/point.h"
+
+namespace aura {
+class MouseEvent;
+class KeyEvent;
+class Window;
+}
+
+namespace views {
+class Label;
+class Widget;
+}
+
+namespace ash {
+namespace internal {
+
+// An event filter which handles system level gesture events.
+class TouchObserverHUD : public aura::EventFilter {
+ public:
+ TouchObserverHUD();
+ virtual ~TouchObserverHUD();
+
+ private:
+ void UpdateTouchPointLabel(int index);
+
+ // Overriden from aura::EventFilter:
+ virtual bool PreHandleKeyEvent(aura::Window* target,
+ aura::KeyEvent* event) OVERRIDE;
+ virtual bool PreHandleMouseEvent(aura::Window* target,
+ aura::MouseEvent* event) OVERRIDE;
+ virtual ui::TouchStatus PreHandleTouchEvent(aura::Window* target,
+ aura::TouchEvent* event) OVERRIDE;
+ virtual ui::GestureStatus PreHandleGestureEvent(
+ aura::Window* target,
+ aura::GestureEvent* event) OVERRIDE;
+
+ static const int kMaxTouchPoints = 32;
+ scoped_ptr<views::Widget> widget_;
+ views::Label* touch_labels_[kMaxTouchPoints];
+ gfx::Point touch_positions_[kMaxTouchPoints];
+ ui::EventType touch_status_[kMaxTouchPoints];
+
+ DISALLOW_COPY_AND_ASSIGN(TouchObserverHUD);
+};
+
+} // namespace internal
+} // namespace ash
+
+#endif // ASH_TOUCH_TOUCH_OBSERVER_HUD_H_