Commit 7307474f authored by sadrul@chromium.org's avatar sadrul@chromium.org

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
parent 96191d56
......@@ -177,6 +177,8 @@
'system/user/user_observer.h',
'tooltips/tooltip_controller.cc',
'tooltips/tooltip_controller.h',
'touch/touch_observer_hud.cc',
'touch/touch_observer_hud.h',
'volume_control_delegate.h',
'wm/app_list_controller.cc',
'wm/app_list_controller.h',
......
......@@ -13,6 +13,9 @@ const char kAshEnableOak[] = "ash-enable-oak";
// Use Ash notifications.
const char kAshNotify[] = "ash-notify";
// Enables the heads-up display for tracking touch points.
const char kAshTouchHud[] = "ash-touch-hud";
// Use Google-style dialog box frames.
const char kAuraGoogleDialogFrames[] = "aura-google-dialog-frames";
......
......@@ -18,6 +18,7 @@ namespace switches {
// Please keep alphabetized.
ASH_EXPORT extern const char kAshEnableOak[];
ASH_EXPORT extern const char kAshNotify[];
ASH_EXPORT extern const char kAshTouchHud[];
ASH_EXPORT extern const char kAuraGoogleDialogFrames[];
ASH_EXPORT extern const char kAuraLegacyPowerButton[];
ASH_EXPORT extern const char kAuraNoShadows[];
......
......@@ -27,6 +27,7 @@
#include "ash/system/tray/system_tray.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/tooltips/tooltip_controller.h"
#include "ash/touch/touch_observer_hud.h"
#include "ash/wm/activation_controller.h"
#include "ash/wm/app_list_controller.h"
#include "ash/wm/base_layout_manager.h"
......@@ -553,6 +554,8 @@ Shell::~Shell() {
#if !defined(OS_MACOSX)
RemoveRootWindowEventFilter(accelerator_filter_.get());
#endif
if (touch_observer_hud_.get())
RemoveRootWindowEventFilter(touch_observer_hud_.get());
// Close background widget now so that the focus manager of the
// widget gets deleted in the final message loop run.
......@@ -684,6 +687,13 @@ void Shell::Init() {
CreateSpecialContainers(root_window);
CommandLine* command_line = CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kAshTouchHud)) {
touch_observer_hud_.reset(new internal::TouchObserverHUD);
AddRootWindowEventFilter(touch_observer_hud_.get());
}
stacking_controller_.reset(new internal::StackingController);
root_window_layout_ = new internal::RootWindowLayoutManager(root_window);
......@@ -691,8 +701,6 @@ void Shell::Init() {
event_client_.reset(new internal::EventClientImpl(root_window));
CommandLine* command_line = CommandLine::ForCurrentProcess();
tray_.reset(new SystemTray());
if (delegate_.get())
tray_delegate_.reset(delegate_->CreateSystemTrayDelegate(tray_.get()));
......
......@@ -86,6 +86,7 @@ class ShellContextMenu;
class SystemGestureEventFilter;
class StackingController;
class TooltipController;
class TouchObserverHUD;
class VisibilityController;
class WindowModalityController;
class WorkspaceController;
......@@ -368,6 +369,10 @@ class ASH_EXPORT Shell {
// An event filter that pre-handles all key events to send them to an IME.
scoped_ptr<aura::shared::InputMethodEventFilter> input_method_filter_;
// An event filter that silently keeps track of all touch events and controls
// a heads-up display. This is enabled only if --ash-touch-hud flag is used.
scoped_ptr<internal::TouchObserverHUD> touch_observer_hud_;
// The shelf for managing the launcher and the status widget in non-compact
// mode. Shell does not own the shelf. Instead, it is owned by container of
// the status area.
......
// 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
// 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_
......@@ -5637,6 +5637,13 @@ Keep your key file in a safe place. You will need it to create new versions of y
Enables a menu that allows changing the side the launcher is aligned to.
</message>
<message name="IDS_FLAGS_SHOW_TOUCH_HUD_NAME" desc="Name for the flag to show a heads-up display for tracking touch-points.">
Show HUD for touch points
</message>
<message name="IDS_FLAGS_SHOW_TOUCH_HUD_DESCRIPTION" desc="Description for the flag to show a heads-up display for tracking touch-points.">
Enables a heads-up display at the top-left corner of the screen that lists information about the touch-points on the screen.
</message>
<message name="IDS_FLAGS_ALLOW_NACL_SOCKET_API_NAME" desc="Name for the NaCl Socket API feature.">
NaCl Socket API.
</message>
......
......@@ -717,6 +717,13 @@ const Experiment kExperiments[] = {
kOsAll,
SINGLE_VALUE_TYPE(switches::kShowLauncherAlignmentMenu)
},
{
"show-touch-hud",
IDS_FLAGS_SHOW_TOUCH_HUD_NAME,
IDS_FLAGS_SHOW_TOUCH_HUD_DESCRIPTION,
kOsAll,
SINGLE_VALUE_TYPE(ash::switches::kAshTouchHud)
},
{
"ash-notify",
IDS_FLAGS_ENABLE_ASH_NOTIFY_NAME,
......@@ -724,7 +731,7 @@ const Experiment kExperiments[] = {
kOsAll,
SINGLE_VALUE_TYPE(ash::switches::kAshNotify),
},
#endif
#endif // defined(USE_ASH)
};
const Experiment* experiments = kExperiments;
......
......@@ -1075,6 +1075,7 @@ std::string LoginUtilsImpl::GetOffTheRecordCommandLine(
::switches::kFlingTapSuppressMaxGap,
::switches::kTouchDevices,
::switches::kTouchOptimizedUI,
ash::switches::kAshTouchHud,
ash::switches::kAuraLegacyPowerButton,
ash::switches::kAuraNoShadows,
ash::switches::kAuraPanelManager,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment