summaryrefslogtreecommitdiffstats
path: root/ash/touch
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-18 18:20:21 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-18 18:20:21 +0000
commitbb2e756f8636761fb4b66b7554138cbfc7f1f0b0 (patch)
tree4d214cb258b45827e85202b3c2be1a72aa5627e0 /ash/touch
parentd7fc83f78f47de82da3b67449cf7c742b45d3a00 (diff)
downloadchromium_src-bb2e756f8636761fb4b66b7554138cbfc7f1f0b0.zip
chromium_src-bb2e756f8636761fb4b66b7554138cbfc7f1f0b0.tar.gz
chromium_src-bb2e756f8636761fb4b66b7554138cbfc7f1f0b0.tar.bz2
ash: Make the touch HUD fullscreen.
Show the touch HUD fullscreen by default. Allow it to be changed to 10% scale, or invisible, using alt-ctrl-i accelerators. BUG=170758 Review URL: https://codereview.chromium.org/11867018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@177710 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/touch')
-rw-r--r--ash/touch/touch_observer_hud.cc104
-rw-r--r--ash/touch/touch_observer_hud.h6
2 files changed, 73 insertions, 37 deletions
diff --git a/ash/touch/touch_observer_hud.cc b/ash/touch/touch_observer_hud.cc
index 176e52f..d6408c0 100644
--- a/ash/touch/touch_observer_hud.cc
+++ b/ash/touch/touch_observer_hud.cc
@@ -9,12 +9,14 @@
#include "base/utf_string_conversions.h"
#include "third_party/skia/include/core/SkPath.h"
#include "third_party/skia/include/core/SkXfermode.h"
+#include "ui/aura/window.h"
#include "ui/base/events/event.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/display.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/screen.h"
#include "ui/gfx/size.h"
+#include "ui/gfx/transform.h"
#include "ui/views/background.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h"
@@ -23,78 +25,81 @@
namespace ash {
namespace internal {
-const int kMaxPaths = 15;
-const int kScale = 10;
+const int kPointRadius = 20;
const int kColors[] = {
static_cast<int>(SK_ColorYELLOW),
static_cast<int>(SK_ColorGREEN),
static_cast<int>(SK_ColorRED),
static_cast<int>(SK_ColorBLUE),
+ static_cast<int>(SK_ColorGRAY),
static_cast<int>(SK_ColorMAGENTA),
static_cast<int>(SK_ColorCYAN),
static_cast<int>(SK_ColorWHITE),
static_cast<int>(SK_ColorBLACK)
};
+const int kAlpha = 0x60;
+const int kMaxPaths = arraysize(kColors);
+const int kReducedScale = 10;
class TouchHudCanvas : public views::View {
public:
explicit TouchHudCanvas(TouchObserverHUD* owner)
: owner_(owner),
path_index_(0),
- color_index_(0) {
+ color_index_(0),
+ scale_(1) {
gfx::Display display = Shell::GetScreen()->GetPrimaryDisplay();
gfx::Rect bounds = display.bounds();
- size_.set_width(bounds.width() / kScale);
- size_.set_height(bounds.height() / kScale);
+ SetPaintToLayer(true);
+ SetFillsBoundsOpaquely(false);
}
virtual ~TouchHudCanvas() {}
+ void SetScale(int scale) {
+ if (scale_ == scale)
+ return;
+ scale_ = scale;
+ gfx::Transform transform;
+ transform.Scale(1. / scale_, 1. / scale_);
+ layer()->SetTransform(transform);
+ }
+
+ int scale() const { return scale_; }
+
void Start(int id, const gfx::Point& point) {
paths_[path_index_].reset();
- paths_[path_index_].moveTo(SkIntToScalar(point.x() / kScale),
- SkIntToScalar(point.y() / kScale));
- colors_[path_index_] = kColors[color_index_];
+ colors_[path_index_] = SkColorSetA(kColors[color_index_], kAlpha);
color_index_ = (color_index_ + 1) % arraysize(kColors);
-
touch_id_to_path_[id] = path_index_;
path_index_ = (path_index_ + 1) % kMaxPaths;
+ AddPoint(id, point);
SchedulePaint();
}
- void Update(int id, gfx::Point& to) {
+ void AddPoint(int id, const gfx::Point& point) {
SkPoint last;
int path_id = touch_id_to_path_[id];
- SkScalar x = SkIntToScalar(to.x() / kScale);
- SkScalar y = SkIntToScalar(to.y() / kScale);
+ SkScalar x = SkIntToScalar(point.x());
+ SkScalar y = SkIntToScalar(point.y());
if (!paths_[path_id].getLastPt(&last) || x != last.x() || y != last.y())
- paths_[path_id].lineTo(x, y);
+ paths_[path_id].addCircle(x, y, SkIntToScalar(kPointRadius));
SchedulePaint();
}
private:
// Overridden from views::View.
- virtual gfx::Size GetPreferredSize() OVERRIDE {
- return size_;
- }
-
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
canvas->DrawColor(SK_ColorBLACK, SkXfermode::kClear_Mode);
- canvas->DrawColor(SkColorSetARGB(25, 0, 0, 0));
+ canvas->DrawColor(SkColorSetARGB(0, 0, 0, 0));
SkPaint paint;
- paint.setStrokeWidth(SkIntToScalar(2));
- paint.setStyle(SkPaint::kStroke_Style);
+ paint.setStyle(SkPaint::kFill_Style);
for (size_t i = 0; i < arraysize(paths_); ++i) {
if (paths_[i].countPoints() == 0)
continue;
paint.setColor(colors_[i]);
- if (paths_[i].countPoints() == 1) {
- SkPoint point = paths_[i].getPoint(0);
- canvas->sk_canvas()->drawPoint(point.x(), point.y(), paint);
- } else {
- canvas->DrawPath(paths_[i], paint);
- }
+ canvas->DrawPath(paths_[i], paint);
}
}
@@ -104,21 +109,28 @@ class TouchHudCanvas : public views::View {
int path_index_;
int color_index_;
+ int scale_;
std::map<int, int> touch_id_to_path_;
- gfx::Size size_;
-
DISALLOW_COPY_AND_ASSIGN(TouchHudCanvas);
};
TouchObserverHUD::TouchObserverHUD() {
views::View* content = new views::View;
- content->SetLayoutManager(new views::BoxLayout(
- views::BoxLayout::kVertical, 0, 0, 0));
canvas_ = new TouchHudCanvas(this);
content->AddChildView(canvas_);
+
+ gfx::Display display = Shell::GetScreen()->GetPrimaryDisplay();
+ gfx::Rect display_bounds = display.bounds();
+ canvas_->SetBoundsRect(display_bounds);
+ content->SetBoundsRect(display_bounds);
+
+ label_container_ = new views::View;
+ label_container_->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;
@@ -126,9 +138,13 @@ TouchObserverHUD::TouchObserverHUD() {
touch_labels_[i]->SetShadowColors(SK_ColorWHITE,
SK_ColorWHITE);
touch_labels_[i]->SetShadowOffset(1, 1);
- touch_labels_[i]->SetVisible(false);
- content->AddChildView(touch_labels_[i]);
+ label_container_->AddChildView(touch_labels_[i]);
}
+ label_container_->SetX(0);
+ label_container_->SetY(display_bounds.height() / kReducedScale);
+ label_container_->SetSize(label_container_->GetPreferredSize());
+ label_container_->SetVisible(false);
+ content->AddChildView(label_container_);
widget_ = new views::Widget();
views::Widget::InitParams
@@ -136,7 +152,7 @@ TouchObserverHUD::TouchObserverHUD() {
params.transparent = true;
params.can_activate = false;
params.accept_events = false;
- params.bounds = gfx::Rect(content->GetPreferredSize());
+ params.bounds = display_bounds;
params.parent = Shell::GetContainer(
Shell::GetPrimaryRootWindow(),
internal::kShellWindowId_OverlayContainer);
@@ -155,6 +171,21 @@ TouchObserverHUD::~TouchObserverHUD() {
DCHECK(!widget_);
}
+void TouchObserverHUD::ChangeToNextMode() {
+ if (widget_->IsVisible()) {
+ if (canvas_->scale() == kReducedScale) {
+ widget_->Hide();
+ } else {
+ label_container_->SetVisible(true);
+ canvas_->SetScale(kReducedScale);
+ }
+ } else {
+ canvas_->SetScale(1);
+ label_container_->SetVisible(false);
+ widget_->Show();
+ }
+}
+
void TouchObserverHUD::UpdateTouchPointLabel(int index) {
const char* status = NULL;
switch (touch_status_[index]) {
@@ -191,12 +222,11 @@ void TouchObserverHUD::OnTouchEvent(ui::TouchEvent* event) {
if (event->type() == ui::ET_TOUCH_PRESSED)
canvas_->Start(event->touch_id(), touch_positions_[event->touch_id()]);
else
- canvas_->Update(event->touch_id(), touch_positions_[event->touch_id()]);
+ canvas_->AddPoint(event->touch_id(), touch_positions_[event->touch_id()]);
touch_status_[event->touch_id()] = event->type();
- touch_labels_[event->touch_id()]->SetVisible(true);
- UpdateTouchPointLabel(event->touch_id());
- widget_->SetSize(widget_->GetContentsView()->GetPreferredSize());
+ UpdateTouchPointLabel(event->touch_id());
+ label_container_->SetSize(label_container_->GetPreferredSize());
}
void TouchObserverHUD::OnWidgetClosing(views::Widget* widget) {
diff --git a/ash/touch/touch_observer_hud.h b/ash/touch/touch_observer_hud.h
index acee910..12dbe2b 100644
--- a/ash/touch/touch_observer_hud.h
+++ b/ash/touch/touch_observer_hud.h
@@ -16,6 +16,7 @@ class Window;
namespace views {
class Label;
+class View;
class Widget;
}
@@ -31,6 +32,10 @@ class TouchObserverHUD : public ui::EventHandler,
TouchObserverHUD();
virtual ~TouchObserverHUD();
+ // Changes the display mode (e.g. scale, visibility). Calling this repeatedly
+ // cycles between a fixed number of display modes.
+ void ChangeToNextMode();
+
private:
void UpdateTouchPointLabel(int index);
@@ -44,6 +49,7 @@ class TouchObserverHUD : public ui::EventHandler,
views::Widget* widget_;
TouchHudCanvas* canvas_;
+ views::View* label_container_;
views::Label* touch_labels_[kMaxTouchPoints];
gfx::Point touch_positions_[kMaxTouchPoints];
ui::EventType touch_status_[kMaxTouchPoints];