diff options
Diffstat (limited to 'chromium/ash/touch')
-rw-r--r-- | chromium/ash/touch/touch_hud_debug.cc | 491 | ||||
-rw-r--r-- | chromium/ash/touch/touch_hud_debug.h | 87 | ||||
-rw-r--r-- | chromium/ash/touch/touch_hud_projection.cc | 187 | ||||
-rw-r--r-- | chromium/ash/touch/touch_hud_projection.h | 44 | ||||
-rw-r--r-- | chromium/ash/touch/touch_observer_hud.cc | 150 | ||||
-rw-r--r-- | chromium/ash/touch/touch_observer_hud.h | 91 | ||||
-rw-r--r-- | chromium/ash/touch/touch_observer_hud_unittest.cc | 420 | ||||
-rw-r--r-- | chromium/ash/touch/touch_uma.cc | 437 | ||||
-rw-r--r-- | chromium/ash/touch/touch_uma.h | 83 |
9 files changed, 0 insertions, 1990 deletions
diff --git a/chromium/ash/touch/touch_hud_debug.cc b/chromium/ash/touch/touch_hud_debug.cc deleted file mode 100644 index 5b7c120d5cd..00000000000 --- a/chromium/ash/touch/touch_hud_debug.cc +++ /dev/null @@ -1,491 +0,0 @@ -// Copyright 2013 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_hud_debug.h" - -#include "ash/display/display_manager.h" -#include "ash/root_window_controller.h" -#include "ash/shell.h" -#include "ash/wm/property_util.h" -#include "base/json/json_string_value_serializer.h" -#include "base/strings/string_number_conversions.h" -#include "base/strings/stringprintf.h" -#include "base/strings/utf_string_conversions.h" -#include "third_party/skia/include/core/SkPath.h" -#include "ui/aura/root_window.h" -#include "ui/base/animation/animation_delegate.h" -#include "ui/base/events/event.h" -#include "ui/gfx/canvas.h" -#include "ui/gfx/display.h" -#include "ui/gfx/size.h" -#include "ui/gfx/transform.h" -#include "ui/views/controls/label.h" -#include "ui/views/layout/box_layout.h" -#include "ui/views/widget/widget.h" - -#if defined(USE_X11) -#include <X11/extensions/XInput2.h> -#include <X11/Xlib.h> - -#include "ui/base/x/device_data_manager.h" -#endif - -namespace ash { -namespace internal { - -const int kPointRadius = 20; -const SkColor kColors[] = { - SK_ColorYELLOW, - SK_ColorGREEN, - SK_ColorRED, - SK_ColorBLUE, - SK_ColorGRAY, - SK_ColorMAGENTA, - SK_ColorCYAN, - SK_ColorWHITE, - SK_ColorBLACK, - SkColorSetRGB(0xFF, 0x8C, 0x00), - SkColorSetRGB(0x8B, 0x45, 0x13), - SkColorSetRGB(0xFF, 0xDE, 0xAD), -}; -const int kAlpha = 0x60; -const int kMaxPaths = arraysize(kColors); -const int kReducedScale = 10; - -const char* GetTouchEventLabel(ui::EventType type) { - switch (type) { - case ui::ET_UNKNOWN: - return " "; - case ui::ET_TOUCH_PRESSED: - return "P"; - case ui::ET_TOUCH_MOVED: - return "M"; - case ui::ET_TOUCH_RELEASED: - return "R"; - case ui::ET_TOUCH_CANCELLED: - return "C"; - default: - break; - } - return "?"; -} - -int GetTrackingId(const ui::TouchEvent& event) { - if (!event.HasNativeEvent()) - return 0; -#if defined(USE_XI2_MT) - ui::DeviceDataManager* manager = ui::DeviceDataManager::GetInstance(); - double tracking_id; - if (manager->GetEventData(*event.native_event(), - ui::DeviceDataManager::DT_TOUCH_TRACKING_ID, - &tracking_id)) { - return static_cast<int>(tracking_id); - } -#endif - return 0; -} - -int GetSourceDeviceId(const ui::TouchEvent& event) { - if (!event.HasNativeEvent()) - return 0; -#if defined(USE_X11) - XEvent* xev = event.native_event(); - return static_cast<XIDeviceEvent*>(xev->xcookie.data)->sourceid; -#endif - return 0; -} - -// A TouchPointLog represents a single touch-event of a touch point. -struct TouchPointLog { - public: - explicit TouchPointLog(const ui::TouchEvent& touch) - : id(touch.touch_id()), - type(touch.type()), - location(touch.root_location()), - timestamp(touch.time_stamp().InMillisecondsF()), - radius_x(touch.radius_x()), - radius_y(touch.radius_y()), - pressure(touch.force()), - tracking_id(GetTrackingId(touch)), - source_device(GetSourceDeviceId(touch)) { - } - - // Populates a dictionary value with all the information about the touch - // point. - scoped_ptr<DictionaryValue> GetAsDictionary() const { - scoped_ptr<DictionaryValue> value(new DictionaryValue()); - - value->SetInteger("id", id); - value->SetString("type", std::string(GetTouchEventLabel(type))); - value->SetString("location", location.ToString()); - value->SetDouble("timestamp", timestamp); - value->SetDouble("radius_x", radius_x); - value->SetDouble("radius_y", radius_y); - value->SetDouble("pressure", pressure); - value->SetInteger("tracking_id", tracking_id); - value->SetInteger("source_device", source_device); - - return value.Pass(); - } - - int id; - ui::EventType type; - gfx::Point location; - double timestamp; - float radius_x; - float radius_y; - float pressure; - int tracking_id; - int source_device; -}; - -// A TouchTrace keeps track of all the touch events of a single touch point -// (starting from a touch-press and ending at a touch-release or touch-cancel). -class TouchTrace { - public: - typedef std::vector<TouchPointLog>::iterator iterator; - typedef std::vector<TouchPointLog>::const_iterator const_iterator; - typedef std::vector<TouchPointLog>::reverse_iterator reverse_iterator; - typedef std::vector<TouchPointLog>::const_reverse_iterator - const_reverse_iterator; - - TouchTrace() { - } - - void AddTouchPoint(const ui::TouchEvent& touch) { - log_.push_back(TouchPointLog(touch)); - } - - const std::vector<TouchPointLog>& log() const { return log_; } - - bool active() const { - return !log_.empty() && log_.back().type != ui::ET_TOUCH_RELEASED && - log_.back().type != ui::ET_TOUCH_CANCELLED; - } - - // Returns a list containing data from all events for the touch point. - scoped_ptr<ListValue> GetAsList() const { - scoped_ptr<ListValue> list(new ListValue()); - for (const_iterator i = log_.begin(); i != log_.end(); ++i) - list->Append((*i).GetAsDictionary().release()); - return list.Pass(); - } - - void Reset() { - log_.clear(); - } - - private: - std::vector<TouchPointLog> log_; - - DISALLOW_COPY_AND_ASSIGN(TouchTrace); -}; - -// A TouchLog keeps track of all touch events of all touch points. -class TouchLog { - public: - TouchLog() : next_trace_index_(0) { - } - - void AddTouchPoint(const ui::TouchEvent& touch) { - if (touch.type() == ui::ET_TOUCH_PRESSED) - StartTrace(touch); - AddToTrace(touch); - } - - void Reset() { - next_trace_index_ = 0; - for (int i = 0; i < kMaxPaths; ++i) - traces_[i].Reset(); - } - - scoped_ptr<ListValue> GetAsList() const { - scoped_ptr<ListValue> list(new ListValue()); - for (int i = 0; i < kMaxPaths; ++i) { - if (!traces_[i].log().empty()) - list->Append(traces_[i].GetAsList().release()); - } - return list.Pass(); - } - - int GetTraceIndex(int touch_id) const { - return touch_id_to_trace_index_.at(touch_id); - } - - const TouchTrace* traces() const { - return traces_; - } - - private: - void StartTrace(const ui::TouchEvent& touch) { - // Find the first inactive spot; otherwise, overwrite the one - // |next_trace_index_| is pointing to. - int old_trace_index = next_trace_index_; - do { - if (!traces_[next_trace_index_].active()) - break; - next_trace_index_ = (next_trace_index_ + 1) % kMaxPaths; - } while (next_trace_index_ != old_trace_index); - int touch_id = touch.touch_id(); - traces_[next_trace_index_].Reset(); - touch_id_to_trace_index_[touch_id] = next_trace_index_; - next_trace_index_ = (next_trace_index_ + 1) % kMaxPaths; - } - - void AddToTrace(const ui::TouchEvent& touch) { - int touch_id = touch.touch_id(); - int trace_index = touch_id_to_trace_index_[touch_id]; - traces_[trace_index].AddTouchPoint(touch); - } - - TouchTrace traces_[kMaxPaths]; - int next_trace_index_; - - std::map<int, int> touch_id_to_trace_index_; - - DISALLOW_COPY_AND_ASSIGN(TouchLog); -}; - -// TouchHudCanvas draws touch traces in |FULLSCREEN| and |REDUCED_SCALE| modes. -class TouchHudCanvas : public views::View { - public: - explicit TouchHudCanvas(const TouchLog& touch_log) - : touch_log_(touch_log), - scale_(1) { - SetPaintToLayer(true); - SetFillsBoundsOpaquely(false); - - paint_.setStyle(SkPaint::kFill_Style); - } - - 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 TouchPointAdded(int touch_id) { - int trace_index = touch_log_.GetTraceIndex(touch_id); - const TouchTrace& trace = touch_log_.traces()[trace_index]; - const TouchPointLog& point = trace.log().back(); - if (point.type == ui::ET_TOUCH_PRESSED) - StartedTrace(trace_index); - if (point.type != ui::ET_TOUCH_CANCELLED) - AddedPointToTrace(trace_index); - } - - void Clear() { - for (int i = 0; i < kMaxPaths; ++i) - paths_[i].reset(); - - SchedulePaint(); - } - - private: - void StartedTrace(int trace_index) { - paths_[trace_index].reset(); - colors_[trace_index] = SkColorSetA(kColors[trace_index], kAlpha); - } - - void AddedPointToTrace(int trace_index) { - const TouchTrace& trace = touch_log_.traces()[trace_index]; - const TouchPointLog& point = trace.log().back(); - const gfx::Point& location = point.location; - SkScalar x = SkIntToScalar(location.x()); - SkScalar y = SkIntToScalar(location.y()); - SkPoint last; - if (!paths_[trace_index].getLastPt(&last) || x != last.x() || - y != last.y()) { - paths_[trace_index].addCircle(x, y, SkIntToScalar(kPointRadius)); - SchedulePaint(); - } - } - - // Overridden from views::View. - virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { - for (int i = 0; i < kMaxPaths; ++i) { - if (paths_[i].countPoints() == 0) - continue; - paint_.setColor(colors_[i]); - canvas->DrawPath(paths_[i], paint_); - } - } - - SkPaint paint_; - - const TouchLog& touch_log_; - SkPath paths_[kMaxPaths]; - SkColor colors_[kMaxPaths]; - - int scale_; - - DISALLOW_COPY_AND_ASSIGN(TouchHudCanvas); -}; - -TouchHudDebug::TouchHudDebug(aura::RootWindow* initial_root) - : TouchObserverHUD(initial_root), - mode_(FULLSCREEN), - touch_log_(new TouchLog()), - canvas_(NULL), - label_container_(NULL) { - const gfx::Display& display = - Shell::GetInstance()->display_manager()->GetDisplayForId(display_id()); - - views::View* content = widget()->GetContentsView(); - - canvas_ = new TouchHudCanvas(*touch_log_); - content->AddChildView(canvas_); - - const gfx::Size& display_size = display.size(); - canvas_->SetSize(display_size); - - 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_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); - label_container_->AddChildView(touch_labels_[i]); - } - label_container_->SetX(0); - label_container_->SetY(display_size.height() / kReducedScale); - label_container_->SetSize(label_container_->GetPreferredSize()); - label_container_->SetVisible(false); - content->AddChildView(label_container_); -} - -TouchHudDebug::~TouchHudDebug() { -} - -// static -scoped_ptr<DictionaryValue> TouchHudDebug::GetAllAsDictionary() { - scoped_ptr<DictionaryValue> value(new DictionaryValue()); - Shell::RootWindowList roots = Shell::GetInstance()->GetAllRootWindows(); - for (Shell::RootWindowList::iterator iter = roots.begin(); - iter != roots.end(); ++iter) { - internal::RootWindowController* controller = GetRootWindowController(*iter); - internal::TouchHudDebug* hud = controller->touch_hud_debug(); - if (hud) { - scoped_ptr<ListValue> list = hud->GetLogAsList(); - if (!list->empty()) - value->Set(base::Int64ToString(hud->display_id()), list.release()); - } - } - return value.Pass(); -} - -void TouchHudDebug::ChangeToNextMode() { - switch (mode_) { - case FULLSCREEN: - SetMode(REDUCED_SCALE); - break; - case REDUCED_SCALE: - SetMode(INVISIBLE); - break; - case INVISIBLE: - SetMode(FULLSCREEN); - break; - } -} - -scoped_ptr<ListValue> TouchHudDebug::GetLogAsList() const { - return touch_log_->GetAsList(); -} - -void TouchHudDebug::Clear() { - if (widget()->IsVisible()) { - canvas_->Clear(); - for (int i = 0; i < kMaxTouchPoints; ++i) - touch_labels_[i]->SetText(string16()); - label_container_->SetSize(label_container_->GetPreferredSize()); - } -} - -void TouchHudDebug::SetMode(Mode mode) { - if (mode_ == mode) - return; - mode_ = mode; - switch (mode) { - case FULLSCREEN: - label_container_->SetVisible(false); - canvas_->SetVisible(true); - canvas_->SetScale(1); - canvas_->SchedulePaint(); - widget()->Show(); - break; - case REDUCED_SCALE: - label_container_->SetVisible(true); - canvas_->SetVisible(true); - canvas_->SetScale(kReducedScale); - canvas_->SchedulePaint(); - widget()->Show(); - break; - case INVISIBLE: - widget()->Hide(); - break; - } -} - -void TouchHudDebug::UpdateTouchPointLabel(int index) { - int trace_index = touch_log_->GetTraceIndex(index); - const TouchTrace& trace = touch_log_->traces()[trace_index]; - TouchTrace::const_reverse_iterator point = trace.log().rbegin(); - ui::EventType touch_status = point->type; - float touch_radius = std::max(point->radius_x, point->radius_y); - while (point != trace.log().rend() && point->type == ui::ET_TOUCH_CANCELLED) - point++; - DCHECK(point != trace.log().rend()); - gfx::Point touch_position = point->location; - - std::string string = base::StringPrintf("%2d: %s %s (%.4f)", - index, - GetTouchEventLabel(touch_status), - touch_position.ToString().c_str(), - touch_radius); - touch_labels_[index]->SetText(UTF8ToUTF16(string)); -} - -void TouchHudDebug::OnTouchEvent(ui::TouchEvent* event) { - if (event->touch_id() >= kMaxTouchPoints) - return; - - touch_log_->AddTouchPoint(*event); - canvas_->TouchPointAdded(event->touch_id()); - UpdateTouchPointLabel(event->touch_id()); - label_container_->SetSize(label_container_->GetPreferredSize()); -} - -void TouchHudDebug::OnDisplayBoundsChanged(const gfx::Display& display) { - TouchObserverHUD::OnDisplayBoundsChanged(display); - - if (display.id() != display_id()) - return; - const gfx::Size& size = display.size(); - canvas_->SetSize(size); - label_container_->SetY(size.height() / kReducedScale); -} - -void TouchHudDebug::SetHudForRootWindowController( - RootWindowController* controller) { - controller->set_touch_hud_debug(this); -} - -void TouchHudDebug::UnsetHudForRootWindowController( - RootWindowController* controller) { - controller->set_touch_hud_debug(NULL); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/touch/touch_hud_debug.h b/chromium/ash/touch/touch_hud_debug.h deleted file mode 100644 index a02a888db6b..00000000000 --- a/chromium/ash/touch/touch_hud_debug.h +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2013 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_HUD_DEBUG_H_ -#define ASH_TOUCH_TOUCH_HUD_DEBUG_H_ - -#include <map> - -#include "ash/ash_export.h" -#include "ash/touch/touch_observer_hud.h" -#include "base/memory/scoped_ptr.h" -#include "base/values.h" - -namespace views { -class Label; -class View; -} - -namespace ash { -namespace internal { - -class TouchHudCanvas; -class TouchLog; - -// A heads-up display to show touch traces on the screen and log touch events. -// As a derivative of TouchObserverHUD, objects of this class manage their own -// lifetime. -class ASH_EXPORT TouchHudDebug : public TouchObserverHUD { - public: - enum Mode { - FULLSCREEN, - REDUCED_SCALE, - INVISIBLE, - }; - - explicit TouchHudDebug(aura::RootWindow* initial_root); - - // Returns the log of touch events for all displays as a dictionary mapping id - // of each display to its touch log. - static scoped_ptr<DictionaryValue> GetAllAsDictionary(); - - // Changes the display mode (e.g. scale, visibility). Calling this repeatedly - // cycles between a fixed number of display modes. - void ChangeToNextMode(); - - // Returns log of touch events as a list value. Each item in the list is a - // trace of one touch point. - scoped_ptr<ListValue> GetLogAsList() const; - - Mode mode() const { return mode_; } - - // Overriden from TouchObserverHUD. - virtual void Clear() OVERRIDE; - - private: - virtual ~TouchHudDebug(); - - void SetMode(Mode mode); - - void UpdateTouchPointLabel(int index); - - // Overriden from TouchObserverHUD. - virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE; - virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE; - virtual void SetHudForRootWindowController( - RootWindowController* controller) OVERRIDE; - virtual void UnsetHudForRootWindowController( - RootWindowController* controller) OVERRIDE; - - static const int kMaxTouchPoints = 32; - - Mode mode_; - - scoped_ptr<TouchLog> touch_log_; - - TouchHudCanvas* canvas_; - views::View* label_container_; - views::Label* touch_labels_[kMaxTouchPoints]; - - DISALLOW_COPY_AND_ASSIGN(TouchHudDebug); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_TOUCH_TOUCH_HUD_DEBUG_H_ diff --git a/chromium/ash/touch/touch_hud_projection.cc b/chromium/ash/touch/touch_hud_projection.cc deleted file mode 100644 index 00d619336ef..00000000000 --- a/chromium/ash/touch/touch_hud_projection.cc +++ /dev/null @@ -1,187 +0,0 @@ -// Copyright 2013 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_hud_projection.h" - -#include "ash/root_window_controller.h" -#include "ash/shell.h" -#include "ash/wm/property_util.h" -#include "third_party/skia/include/effects/SkGradientShader.h" -#include "ui/base/animation/animation_delegate.h" -#include "ui/base/animation/linear_animation.h" -#include "ui/base/events/event.h" -#include "ui/gfx/canvas.h" -#include "ui/gfx/size.h" -#include "ui/views/widget/widget.h" - -namespace ash { -namespace internal { - -const int kPointRadius = 20; -const SkColor kProjectionFillColor = SkColorSetRGB(0xF5, 0xF5, 0xDC); -const SkColor kProjectionStrokeColor = SK_ColorGRAY; -const int kProjectionAlpha = 0xB0; -const int kFadeoutDurationInMs = 250; -const int kFadeoutFrameRate = 60; - -// TouchPointView draws a single touch point. This object manages its own -// lifetime and deletes itself upon fade-out completion or whenever |Remove()| -// is explicitly called. -class TouchPointView : public views::View, - public ui::AnimationDelegate, - public views::WidgetObserver { - public: - explicit TouchPointView(views::Widget* parent_widget) - : circle_center_(kPointRadius + 1, kPointRadius + 1), - gradient_center_(SkPoint::Make(kPointRadius + 1, - kPointRadius + 1)) { - SetPaintToLayer(true); - SetFillsBoundsOpaquely(false); - - SetSize(gfx::Size(2 * kPointRadius + 2, 2 * kPointRadius + 2)); - - stroke_paint_.setStyle(SkPaint::kStroke_Style); - stroke_paint_.setColor(kProjectionStrokeColor); - - gradient_colors_[0] = kProjectionFillColor; - gradient_colors_[1] = kProjectionStrokeColor; - - gradient_pos_[0] = SkFloatToScalar(0.9f); - gradient_pos_[1] = SkFloatToScalar(1.0f); - - parent_widget->GetContentsView()->AddChildView(this); - - parent_widget->AddObserver(this); - } - - void UpdateTouch(const ui::TouchEvent& touch) { - if (touch.type() == ui::ET_TOUCH_RELEASED || - touch.type() == ui::ET_TOUCH_CANCELLED) { - fadeout_.reset(new ui::LinearAnimation(kFadeoutDurationInMs, - kFadeoutFrameRate, - this)); - fadeout_->Start(); - } else { - SetX(parent()->GetMirroredXInView(touch.root_location().x()) - - kPointRadius - 1); - SetY(touch.root_location().y() - kPointRadius - 1); - } - } - - void Remove() { - delete this; - } - - private: - virtual ~TouchPointView() { - GetWidget()->RemoveObserver(this); - parent()->RemoveChildView(this); - } - - // Overridden from views::View. - virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { - int alpha = kProjectionAlpha; - if (fadeout_) - alpha = static_cast<int>(fadeout_->CurrentValueBetween(alpha, 0)); - fill_paint_.setAlpha(alpha); - stroke_paint_.setAlpha(alpha); - SkShader* shader = SkGradientShader::CreateRadial( - gradient_center_, - SkIntToScalar(kPointRadius), - gradient_colors_, - gradient_pos_, - arraysize(gradient_colors_), - SkShader::kMirror_TileMode, - NULL); - fill_paint_.setShader(shader); - shader->unref(); - canvas->DrawCircle(circle_center_, SkIntToScalar(kPointRadius), - fill_paint_); - canvas->DrawCircle(circle_center_, SkIntToScalar(kPointRadius), - stroke_paint_); - } - - // Overridden from ui::AnimationDelegate. - virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE { - DCHECK_EQ(fadeout_.get(), animation); - delete this; - } - - virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE { - DCHECK_EQ(fadeout_.get(), animation); - SchedulePaint(); - } - - virtual void AnimationCanceled(const ui::Animation* animation) OVERRIDE { - AnimationEnded(animation); - } - - // Overridden from views::WidgetObserver. - virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE { - fadeout_->Stop(); - } - - const gfx::Point circle_center_; - const SkPoint gradient_center_; - - SkPaint fill_paint_; - SkPaint stroke_paint_; - SkColor gradient_colors_[2]; - SkScalar gradient_pos_[2]; - - scoped_ptr<ui::Animation> fadeout_; - - DISALLOW_COPY_AND_ASSIGN(TouchPointView); -}; - -TouchHudProjection::TouchHudProjection(aura::RootWindow* initial_root) - : TouchObserverHUD(initial_root) { -} - -TouchHudProjection::~TouchHudProjection() { -} - -void TouchHudProjection::Clear() { - for (std::map<int, TouchPointView*>::iterator iter = points_.begin(); - iter != points_.end(); iter++) - iter->second->Remove(); - points_.clear(); -} - -void TouchHudProjection::OnTouchEvent(ui::TouchEvent* event) { - if (event->type() == ui::ET_TOUCH_PRESSED) { - TouchPointView* point = new TouchPointView(widget()); - point->UpdateTouch(*event); - std::pair<std::map<int, TouchPointView*>::iterator, bool> result = - points_.insert(std::make_pair(event->touch_id(), point)); - // If a |TouchPointView| is already mapped to the touch id, remove it and - // replace it with the new one. - if (!result.second) { - result.first->second->Remove(); - result.first->second = point; - } - } else { - std::map<int, TouchPointView*>::iterator iter = - points_.find(event->touch_id()); - if (iter != points_.end()) { - iter->second->UpdateTouch(*event); - if (event->type() == ui::ET_TOUCH_RELEASED || - event->type() == ui::ET_TOUCH_CANCELLED) - points_.erase(iter); - } - } -} - -void TouchHudProjection::SetHudForRootWindowController( - RootWindowController* controller) { - controller->set_touch_hud_projection(this); -} - -void TouchHudProjection::UnsetHudForRootWindowController( - RootWindowController* controller) { - controller->set_touch_hud_projection(NULL); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/touch/touch_hud_projection.h b/chromium/ash/touch/touch_hud_projection.h deleted file mode 100644 index 29fddc39837..00000000000 --- a/chromium/ash/touch/touch_hud_projection.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2013 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_HUD_PROJECTION_H_ -#define ASH_TOUCH_TOUCH_HUD_PROJECTION_H_ - -#include <map> - -#include "ash/touch/touch_observer_hud.h" - -namespace ash { -namespace internal { - -class TouchPointView; - -// A heads-up display to show active touch points on the screen. As a derivative -// of TouchObserverHUD, objects of this class manage their own lifetime. -class TouchHudProjection : public TouchObserverHUD { - public: - explicit TouchHudProjection(aura::RootWindow* initial_root); - - // Overriden from TouchObserverHUD. - virtual void Clear() OVERRIDE; - - private: - virtual ~TouchHudProjection(); - - // Overriden from TouchObserverHUD. - virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE; - virtual void SetHudForRootWindowController( - RootWindowController* controller) OVERRIDE; - virtual void UnsetHudForRootWindowController( - RootWindowController* controller) OVERRIDE; - - std::map<int, TouchPointView*> points_; - - DISALLOW_COPY_AND_ASSIGN(TouchHudProjection); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_TOUCH_TOUCH_HUD_PROJECTION_H_ diff --git a/chromium/ash/touch/touch_observer_hud.cc b/chromium/ash/touch/touch_observer_hud.cc deleted file mode 100644 index 3daeba65707..00000000000 --- a/chromium/ash/touch/touch_observer_hud.cc +++ /dev/null @@ -1,150 +0,0 @@ -// 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/root_window_controller.h" -#include "ash/shell.h" -#include "ash/shell_window_ids.h" -#include "ash/wm/property_util.h" -#include "ash/wm/window_properties.h" -#include "ui/aura/root_window.h" -#include "ui/gfx/display.h" -#include "ui/gfx/rect.h" -#include "ui/gfx/screen.h" -#include "ui/gfx/size.h" -#include "ui/views/widget/widget.h" - -namespace ash { -namespace internal { - -TouchObserverHUD::TouchObserverHUD(aura::RootWindow* initial_root) - : display_id_(initial_root->GetProperty(kDisplayIdKey)), - root_window_(initial_root), - widget_(NULL) { - const gfx::Display& display = - Shell::GetInstance()->display_manager()->GetDisplayForId(display_id_); - - views::View* content = new views::View; - - const gfx::Size& display_size = display.size(); - content->SetSize(display_size); - - widget_ = new views::Widget(); - views::Widget::InitParams - params(views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); - params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; - params.can_activate = false; - params.accept_events = false; - params.bounds = display.bounds(); - params.parent = Shell::GetContainer( - root_window_, - internal::kShellWindowId_OverlayContainer); - widget_->Init(params); - widget_->SetContentsView(content); - widget_->StackAtTop(); - widget_->Show(); - - widget_->AddObserver(this); - - // Observe changes in display size and mode to update touch HUD. - Shell::GetScreen()->AddObserver(this); -#if defined(OS_CHROMEOS) - Shell::GetInstance()->output_configurator()->AddObserver(this); -#endif // defined(OS_CHROMEOS) - - Shell::GetInstance()->display_controller()->AddObserver(this); - root_window_->AddPreTargetHandler(this); -} - -TouchObserverHUD::~TouchObserverHUD() { - Shell::GetInstance()->display_controller()->RemoveObserver(this); - -#if defined(OS_CHROMEOS) - Shell::GetInstance()->output_configurator()->RemoveObserver(this); -#endif // defined(OS_CHROMEOS) - Shell::GetScreen()->RemoveObserver(this); - - widget_->RemoveObserver(this); -} - -void TouchObserverHUD::Clear() { -} - -void TouchObserverHUD::Remove() { - root_window_->RemovePreTargetHandler(this); - - RootWindowController* controller = GetRootWindowController(root_window_); - UnsetHudForRootWindowController(controller); - - widget_->CloseNow(); -} - -void TouchObserverHUD::OnTouchEvent(ui::TouchEvent* /*event*/) { -} - -void TouchObserverHUD::OnWidgetDestroying(views::Widget* widget) { - DCHECK_EQ(widget, widget_); - delete this; -} - -void TouchObserverHUD::OnDisplayBoundsChanged(const gfx::Display& display) { - if (display.id() != display_id_) - return; - widget_->SetSize(display.size()); -} - -void TouchObserverHUD::OnDisplayAdded(const gfx::Display& new_display) {} - -void TouchObserverHUD::OnDisplayRemoved(const gfx::Display& old_display) { - if (old_display.id() != display_id_) - return; - widget_->CloseNow(); -} - -#if defined(OS_CHROMEOS) -void TouchObserverHUD::OnDisplayModeChanged() { - // Clear touch HUD for any change in display mode (single, dual extended, dual - // mirrored, ...). - Clear(); -} -#endif // defined(OS_CHROMEOS) - -void TouchObserverHUD::OnDisplayConfigurationChanging() { - if (!root_window_) - return; - - root_window_->RemovePreTargetHandler(this); - - RootWindowController* controller = GetRootWindowController(root_window_); - UnsetHudForRootWindowController(controller); - - views::Widget::ReparentNativeView( - widget_->GetNativeView(), - Shell::GetContainer(root_window_, - internal::kShellWindowId_UnparentedControlContainer)); - - root_window_ = NULL; -} - -void TouchObserverHUD::OnDisplayConfigurationChanged() { - if (root_window_) - return; - - root_window_ = Shell::GetInstance()->display_controller()-> - GetRootWindowForDisplayId(display_id_); - - views::Widget::ReparentNativeView( - widget_->GetNativeView(), - Shell::GetContainer(root_window_, - internal::kShellWindowId_OverlayContainer)); - - RootWindowController* controller = GetRootWindowController(root_window_); - SetHudForRootWindowController(controller); - - root_window_->AddPreTargetHandler(this); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/touch/touch_observer_hud.h b/chromium/ash/touch/touch_observer_hud.h deleted file mode 100644 index 850bc5e9202..00000000000 --- a/chromium/ash/touch/touch_observer_hud.h +++ /dev/null @@ -1,91 +0,0 @@ -// 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_ - -#include "ash/ash_export.h" -#include "ash/display/display_controller.h" -#include "ui/base/events/event_handler.h" -#include "ui/gfx/display_observer.h" -#include "ui/views/widget/widget_observer.h" - -#if defined(OS_CHROMEOS) -#include "chromeos/display/output_configurator.h" -#endif // defined(OS_CHROMEOS) - -namespace views { -class Widget; -} - -namespace ash { -namespace internal { - -// An event filter which handles system level gesture events. Objects of this -// class manage their own lifetime. -class ASH_EXPORT TouchObserverHUD - : public ui::EventHandler, - public views::WidgetObserver, - public gfx::DisplayObserver, -#if defined(OS_CHROMEOS) - public chromeos::OutputConfigurator::Observer, -#endif // defined(OS_CHROMEOS) - public DisplayController::Observer { - public: - // Called to clear touch points and traces from the screen. Default - // implementation does nothing. Sub-classes should implement appropriately. - virtual void Clear(); - - // Removes the HUD from the screen. - void Remove(); - - int64 display_id() const { return display_id_; } - - protected: - explicit TouchObserverHUD(aura::RootWindow* initial_root); - - virtual ~TouchObserverHUD(); - - virtual void SetHudForRootWindowController( - RootWindowController* controller) = 0; - virtual void UnsetHudForRootWindowController( - RootWindowController* controller) = 0; - - views::Widget* widget() { return widget_; } - - // Overriden from ui::EventHandler. - virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE; - - // Overridden from views::WidgetObserver. - virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE; - - // Overridden from gfx::DisplayObserver. - virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE; - virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE; - virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE; - -#if defined(OS_CHROMEOS) - // Overriden from chromeos::OutputConfigurator::Observer. - virtual void OnDisplayModeChanged() OVERRIDE; -#endif // defined(OS_CHROMEOS) - - // Overriden form DisplayController::Observer. - virtual void OnDisplayConfigurationChanging() OVERRIDE; - virtual void OnDisplayConfigurationChanged() OVERRIDE; - - private: - friend class TouchHudTest; - - const int64 display_id_; - aura::RootWindow* root_window_; - - views::Widget* widget_; - - DISALLOW_COPY_AND_ASSIGN(TouchObserverHUD); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_TOUCH_TOUCH_OBSERVER_HUD_H_ diff --git a/chromium/ash/touch/touch_observer_hud_unittest.cc b/chromium/ash/touch/touch_observer_hud_unittest.cc deleted file mode 100644 index 4d74982ae58..00000000000 --- a/chromium/ash/touch/touch_observer_hud_unittest.cc +++ /dev/null @@ -1,420 +0,0 @@ -// Copyright (c) 2013 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/ash_switches.h" -#include "ash/display/display_manager.h" -#include "ash/root_window_controller.h" -#include "ash/screen_ash.h" -#include "ash/shell.h" -#include "ash/test/ash_test_base.h" -#include "ash/test/display_manager_test_api.h" -#include "ash/touch/touch_hud_debug.h" -#include "ash/wm/property_util.h" -#include "base/command_line.h" -#include "base/format_macros.h" -#include "base/strings/stringprintf.h" -#include "ui/aura/window.h" - -namespace ash { -namespace internal { - -class TouchHudTest : public test::AshTestBase { - public: - TouchHudTest() {} - virtual ~TouchHudTest() {} - - virtual void SetUp() OVERRIDE { - // Add ash-touch-hud flag to enable touch HUD. This flag should be set - // before Ash environment is set up, i.e., before - // test::AshTestBase::SetUp(). - CommandLine::ForCurrentProcess()->AppendSwitch( - ash::switches::kAshTouchHud); - - test::AshTestBase::SetUp(); - - // Initialize display infos. They should be initialized after Ash - // environment is set up, i.e., after test::AshTestBase::SetUp(). - internal_display_id_ = test::DisplayManagerTestApi(GetDisplayManager()). - SetFirstDisplayAsInternalDisplay(); - external_display_id_ = 10; - mirrored_display_id_ = 11; - - internal_display_info_ = - CreateDisplayInfo(internal_display_id_, gfx::Rect(0, 0, 500, 500)); - external_display_info_ = - CreateDisplayInfo(external_display_id_, gfx::Rect(1, 1, 100, 100)); - mirrored_display_info_ = - CreateDisplayInfo(mirrored_display_id_, gfx::Rect(0, 0, 100, 100)); - } - - gfx::Display GetPrimaryDisplay() { - return Shell::GetScreen()->GetPrimaryDisplay(); - } - - const gfx::Display& GetSecondaryDisplay() { - return ScreenAsh::GetSecondaryDisplay(); - } - - void SetupSingleDisplay() { - display_info_list_.clear(); - display_info_list_.push_back(internal_display_info_); - GetDisplayManager()->OnNativeDisplaysChanged(display_info_list_); - } - - void SetupDualDisplays() { - display_info_list_.clear(); - display_info_list_.push_back(internal_display_info_); - display_info_list_.push_back(external_display_info_); - GetDisplayManager()->OnNativeDisplaysChanged(display_info_list_); - } - - void SetInternalAsPrimary() { - const gfx::Display& internal_display = - GetDisplayManager()->GetDisplayForId(internal_display_id_); - GetDisplayController()->SetPrimaryDisplay(internal_display); - } - - void SetExternalAsPrimary() { - const gfx::Display& external_display = - GetDisplayManager()->GetDisplayForId(external_display_id_); - GetDisplayController()->SetPrimaryDisplay(external_display); - } - - void MirrorDisplays() { - DCHECK_EQ(2U, display_info_list_.size()); - DCHECK_EQ(internal_display_id_, display_info_list_[0].id()); - DCHECK_EQ(external_display_id_, display_info_list_[1].id()); - display_info_list_[1] = mirrored_display_info_; - GetDisplayManager()->OnNativeDisplaysChanged(display_info_list_); - } - - void UnmirrorDisplays() { - DCHECK_EQ(2U, display_info_list_.size()); - DCHECK_EQ(internal_display_id_, display_info_list_[0].id()); - DCHECK_EQ(mirrored_display_id_, display_info_list_[1].id()); - display_info_list_[1] = external_display_info_; - GetDisplayManager()->OnNativeDisplaysChanged(display_info_list_); - } - - void RemoveInternalDisplay() { - DCHECK_LT(0U, display_info_list_.size()); - DCHECK_EQ(internal_display_id_, display_info_list_[0].id()); - display_info_list_.erase(display_info_list_.begin()); - GetDisplayManager()->OnNativeDisplaysChanged(display_info_list_); - } - - void RemoveExternalDisplay() { - DCHECK_EQ(2U, display_info_list_.size()); - display_info_list_.pop_back(); - GetDisplayManager()->OnNativeDisplaysChanged(display_info_list_); - } - - void AddInternalDisplay() { - DCHECK_EQ(0U, display_info_list_.size()); - display_info_list_.push_back(internal_display_info_); - GetDisplayManager()->OnNativeDisplaysChanged(display_info_list_); - } - - void AddExternalDisplay() { - DCHECK_EQ(1U, display_info_list_.size()); - display_info_list_.push_back(external_display_info_); - GetDisplayManager()->OnNativeDisplaysChanged(display_info_list_); - } - - int64 internal_display_id() const { - return internal_display_id_; - } - - int64 external_display_id() const { - return external_display_id_; - } - - void CheckInternalDisplay() { - EXPECT_NE(static_cast<internal::TouchObserverHUD*>(NULL), - GetInternalTouchHud()); - EXPECT_EQ(internal_display_id(), GetInternalTouchHud()->display_id_); - EXPECT_EQ(GetInternalRootWindow(), GetInternalTouchHud()->root_window_); - EXPECT_EQ(GetInternalRootWindow(), - GetInternalTouchHud()->widget_->GetNativeView()->GetRootWindow()); - EXPECT_EQ(GetInternalDisplay().size(), - GetInternalTouchHud()->widget_->GetWindowBoundsInScreen().size()); - } - - void CheckExternalDisplay() { - EXPECT_NE(static_cast<internal::TouchObserverHUD*>(NULL), - GetExternalTouchHud()); - EXPECT_EQ(external_display_id(), GetExternalTouchHud()->display_id_); - EXPECT_EQ(GetExternalRootWindow(), GetExternalTouchHud()->root_window_); - EXPECT_EQ(GetExternalRootWindow(), - GetExternalTouchHud()->widget_->GetNativeView()->GetRootWindow()); - EXPECT_EQ(GetExternalDisplay().size(), - GetExternalTouchHud()->widget_->GetWindowBoundsInScreen().size()); - } - - private: - DisplayManager* GetDisplayManager() { - return Shell::GetInstance()->display_manager(); - } - - DisplayController* GetDisplayController() { - return Shell::GetInstance()->display_controller(); - } - - const gfx::Display& GetInternalDisplay() { - return GetDisplayManager()->GetDisplayForId(internal_display_id_); - } - - const gfx::Display& GetExternalDisplay() { - return GetDisplayManager()->GetDisplayForId(external_display_id_); - } - - aura::RootWindow* GetInternalRootWindow() { - return GetDisplayController()->GetRootWindowForDisplayId( - internal_display_id_); - } - - aura::RootWindow* GetExternalRootWindow() { - return GetDisplayController()->GetRootWindowForDisplayId( - external_display_id_); - } - - aura::RootWindow* GetPrimaryRootWindow() { - const gfx::Display& display = GetPrimaryDisplay(); - return GetDisplayController()->GetRootWindowForDisplayId(display.id()); - } - - aura::RootWindow* GetSecondaryRootWindow() { - const gfx::Display& display = GetSecondaryDisplay(); - return GetDisplayController()->GetRootWindowForDisplayId(display.id()); - } - - internal::RootWindowController* GetInternalRootController() { - aura::RootWindow* root = GetInternalRootWindow(); - return GetRootWindowController(root); - } - - internal::RootWindowController* GetExternalRootController() { - aura::RootWindow* root = GetExternalRootWindow(); - return GetRootWindowController(root); - } - - internal::RootWindowController* GetPrimaryRootController() { - aura::RootWindow* root = GetPrimaryRootWindow(); - return GetRootWindowController(root); - } - - internal::RootWindowController* GetSecondaryRootController() { - aura::RootWindow* root = GetSecondaryRootWindow(); - return GetRootWindowController(root); - } - - internal::TouchObserverHUD* GetInternalTouchHud() { - return GetInternalRootController()->touch_hud_debug(); - } - - internal::TouchObserverHUD* GetExternalTouchHud() { - return GetExternalRootController()->touch_hud_debug(); - } - - internal::TouchObserverHUD* GetPrimaryTouchHud() { - return GetPrimaryRootController()->touch_hud_debug(); - } - - internal::TouchObserverHUD* GetSecondaryTouchHud() { - return GetSecondaryRootController()->touch_hud_debug(); - } - - DisplayInfo CreateDisplayInfo(int64 id, const gfx::Rect& bounds) { - DisplayInfo info(id, base::StringPrintf("x-%" PRId64, id), false); - info.SetBounds(bounds); - return info; - } - - int64 internal_display_id_; - int64 external_display_id_; - int64 mirrored_display_id_; - DisplayInfo internal_display_info_; - DisplayInfo external_display_info_; - DisplayInfo mirrored_display_info_; - - std::vector<DisplayInfo> display_info_list_; - - DISALLOW_COPY_AND_ASSIGN(TouchHudTest); -}; - -// Checks if touch HUDs are correctly initialized for displays. -TEST_F(TouchHudTest, Basic) { - if (!SupportsMultipleDisplays()) - return; - - // Setup a dual display setting. - SetupDualDisplays(); - - // Check if touch HUDs are set correctly and associated with appropriate - // displays. - CheckInternalDisplay(); - CheckExternalDisplay(); -} - -// Checks if touch HUDs are correctly handled when primary display is changed. -TEST_F(TouchHudTest, SwapPrimaryDisplay) { - if (!SupportsMultipleDisplays()) - return; - - // Setup a dual display setting. - SetupDualDisplays(); - - // Set the primary display to the external one. - SetExternalAsPrimary(); - - // Check if displays' touch HUDs are not swapped as root windows are. - EXPECT_EQ(external_display_id(), GetPrimaryDisplay().id()); - EXPECT_EQ(internal_display_id(), GetSecondaryDisplay().id()); - CheckInternalDisplay(); - CheckExternalDisplay(); - - // Set the primary display back to the internal one. - SetInternalAsPrimary(); - - // Check if displays' touch HUDs are not swapped back as root windows are. - EXPECT_EQ(internal_display_id(), GetPrimaryDisplay().id()); - EXPECT_EQ(external_display_id(), GetSecondaryDisplay().id()); - CheckInternalDisplay(); - CheckExternalDisplay(); -} - -// Checks if touch HUDs are correctly handled when displays are mirrored. -TEST_F(TouchHudTest, MirrorDisplays) { - if (!SupportsMultipleDisplays()) - return; - - // Setup a dual display setting. - SetupDualDisplays(); - - // Mirror displays. - MirrorDisplays(); - - // Check if the internal display is intact. - EXPECT_EQ(internal_display_id(), GetPrimaryDisplay().id()); - CheckInternalDisplay(); - - // Unmirror displays. - UnmirrorDisplays(); - - // Check if external display is added back correctly. - EXPECT_EQ(internal_display_id(), GetPrimaryDisplay().id()); - EXPECT_EQ(external_display_id(), GetSecondaryDisplay().id()); - CheckInternalDisplay(); - CheckExternalDisplay(); -} - -// Checks if touch HUDs are correctly handled when displays are mirrored after -// setting the external display as the primary one. -TEST_F(TouchHudTest, SwapPrimaryThenMirrorDisplays) { - if (!SupportsMultipleDisplays()) - return; - - // Setup a dual display setting. - SetupDualDisplays(); - - // Set the primary display to the external one. - SetExternalAsPrimary(); - - // Mirror displays. - MirrorDisplays(); - - // Check if the internal display is set as the primary one. - EXPECT_EQ(internal_display_id(), GetPrimaryDisplay().id()); - CheckInternalDisplay(); - - // Unmirror displays. - UnmirrorDisplays(); - - // Check if the external display is added back as the primary display and - // touch HUDs are set correctly. - EXPECT_EQ(external_display_id(), GetPrimaryDisplay().id()); - EXPECT_EQ(internal_display_id(), GetSecondaryDisplay().id()); - CheckInternalDisplay(); - CheckExternalDisplay(); -} - -// Checks if touch HUDs are correctly handled when the external display, which -// is the secondary one, is removed. -TEST_F(TouchHudTest, RemoveSecondaryDisplay) { - if (!SupportsMultipleDisplays()) - return; - - // Setup a dual display setting. - SetupDualDisplays(); - - // Remove external display which is the secondary one. - RemoveExternalDisplay(); - - // Check if the internal display is intact. - EXPECT_EQ(internal_display_id(), GetPrimaryDisplay().id()); - CheckInternalDisplay(); - - // Add external display back. - AddExternalDisplay(); - - // Check if displays' touch HUDs are set correctly. - EXPECT_EQ(internal_display_id(), GetPrimaryDisplay().id()); - EXPECT_EQ(external_display_id(), GetSecondaryDisplay().id()); - CheckInternalDisplay(); - CheckExternalDisplay(); -} - -// Checks if touch HUDs are correctly handled when the external display, which -// is set as the primary display, is removed. -TEST_F(TouchHudTest, RemovePrimaryDisplay) { - if (!SupportsMultipleDisplays()) - return; - - // Setup a dual display setting. - SetupDualDisplays(); - - // Set the primary display to the external one. - SetExternalAsPrimary(); - - // Remove the external display which is the primary display. - RemoveExternalDisplay(); - - // Check if the internal display is set as the primary one. - EXPECT_EQ(internal_display_id(), GetPrimaryDisplay().id()); - CheckInternalDisplay(); - - // Add the external display back. - AddExternalDisplay(); - - // Check if the external display is set as primary and touch HUDs are set - // correctly. - EXPECT_EQ(external_display_id(), GetPrimaryDisplay().id()); - EXPECT_EQ(internal_display_id(), GetSecondaryDisplay().id()); - CheckInternalDisplay(); - CheckExternalDisplay(); -} - -// Checks if touch HUDs are correctly handled when all displays are removed. -TEST_F(TouchHudTest, Headless) { - if (!SupportsMultipleDisplays()) - return; - - // Setup a single display setting. - SetupSingleDisplay(); - - // Remove the only display which is the internal one. - RemoveInternalDisplay(); - - // Add the internal display back. - AddInternalDisplay(); - - // Check if the display's touch HUD is set correctly. - EXPECT_EQ(internal_display_id(), GetPrimaryDisplay().id()); - CheckInternalDisplay(); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/touch/touch_uma.cc b/chromium/ash/touch/touch_uma.cc deleted file mode 100644 index f8ab0f17d66..00000000000 --- a/chromium/ash/touch/touch_uma.cc +++ /dev/null @@ -1,437 +0,0 @@ -// 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_uma.h" - -#include "ash/shell_delegate.h" -#include "base/metrics/histogram.h" -#include "base/strings/stringprintf.h" -#include "ui/aura/env.h" -#include "ui/aura/root_window.h" -#include "ui/aura/window.h" -#include "ui/aura/window_property.h" -#include "ui/base/events/event.h" -#include "ui/base/events/event_utils.h" -#include "ui/gfx/point_conversions.h" - -#if defined(USE_XI2_MT) -#include <X11/extensions/XInput2.h> -#include <X11/Xlib.h> -#endif - -namespace { - -enum UMAEventType { - UMA_ET_UNKNOWN, - UMA_ET_TOUCH_RELEASED, - UMA_ET_TOUCH_PRESSED, - UMA_ET_TOUCH_MOVED, - UMA_ET_TOUCH_STATIONARY, - UMA_ET_TOUCH_CANCELLED, - UMA_ET_GESTURE_SCROLL_BEGIN, - UMA_ET_GESTURE_SCROLL_END, - UMA_ET_GESTURE_SCROLL_UPDATE, - UMA_ET_GESTURE_TAP, - UMA_ET_GESTURE_TAP_DOWN, - UMA_ET_GESTURE_BEGIN, - UMA_ET_GESTURE_END, - UMA_ET_GESTURE_DOUBLE_TAP, - UMA_ET_GESTURE_TRIPLE_TAP, - UMA_ET_GESTURE_TWO_FINGER_TAP, - UMA_ET_GESTURE_PINCH_BEGIN, - UMA_ET_GESTURE_PINCH_END, - UMA_ET_GESTURE_PINCH_UPDATE, - UMA_ET_GESTURE_LONG_PRESS, - UMA_ET_GESTURE_MULTIFINGER_SWIPE, - UMA_ET_SCROLL, - UMA_ET_SCROLL_FLING_START, - UMA_ET_SCROLL_FLING_CANCEL, - UMA_ET_GESTURE_MULTIFINGER_SWIPE_3, - UMA_ET_GESTURE_MULTIFINGER_SWIPE_4P, // 4+ fingers - UMA_ET_GESTURE_SCROLL_UPDATE_2, - UMA_ET_GESTURE_SCROLL_UPDATE_3, - UMA_ET_GESTURE_SCROLL_UPDATE_4P, - UMA_ET_GESTURE_PINCH_UPDATE_3, - UMA_ET_GESTURE_PINCH_UPDATE_4P, - UMA_ET_GESTURE_LONG_TAP, - // NOTE: Add new event types only immediately above this line. Make sure to - // update the enum list in tools/histogram/histograms.xml accordingly. - UMA_ET_COUNT -}; - -struct WindowTouchDetails { - // Move and start times of the touch points. The key is the touch-id. - std::map<int, base::TimeDelta> last_move_time_; - std::map<int, base::TimeDelta> last_start_time_; - - // The first and last positions of the touch points. - std::map<int, gfx::Point> start_touch_position_; - std::map<int, gfx::Point> last_touch_position_; - - // Last time-stamp of the last touch-end event. - base::TimeDelta last_release_time_; - - // Stores the time of the last touch released on this window (if there was a - // multi-touch gesture on the window, then this is the release-time of the - // last touch on the window). - base::TimeDelta last_mt_time_; -}; - -DEFINE_OWNED_WINDOW_PROPERTY_KEY(WindowTouchDetails, - kWindowTouchDetails, - NULL); - - -UMAEventType UMAEventTypeFromEvent(const ui::Event& event) { - switch (event.type()) { - case ui::ET_TOUCH_RELEASED: - return UMA_ET_TOUCH_RELEASED; - case ui::ET_TOUCH_PRESSED: - return UMA_ET_TOUCH_PRESSED; - case ui::ET_TOUCH_MOVED: - return UMA_ET_TOUCH_MOVED; - case ui::ET_TOUCH_STATIONARY: - return UMA_ET_TOUCH_STATIONARY; - case ui::ET_TOUCH_CANCELLED: - return UMA_ET_TOUCH_CANCELLED; - case ui::ET_GESTURE_SCROLL_BEGIN: - return UMA_ET_GESTURE_SCROLL_BEGIN; - case ui::ET_GESTURE_SCROLL_END: - return UMA_ET_GESTURE_SCROLL_END; - case ui::ET_GESTURE_SCROLL_UPDATE: { - const ui::GestureEvent& gesture = - static_cast<const ui::GestureEvent&>(event); - if (gesture.details().touch_points() >= 4) - return UMA_ET_GESTURE_SCROLL_UPDATE_4P; - else if (gesture.details().touch_points() == 3) - return UMA_ET_GESTURE_SCROLL_UPDATE_3; - else if (gesture.details().touch_points() == 2) - return UMA_ET_GESTURE_SCROLL_UPDATE_2; - return UMA_ET_GESTURE_SCROLL_UPDATE; - } - case ui::ET_GESTURE_TAP: { - const ui::GestureEvent& gesture = - static_cast<const ui::GestureEvent&>(event); - int tap_count = gesture.details().tap_count(); - if (tap_count == 1) - return UMA_ET_GESTURE_TAP; - if (tap_count == 2) - return UMA_ET_GESTURE_DOUBLE_TAP; - if (tap_count == 3) - return UMA_ET_GESTURE_TRIPLE_TAP; - NOTREACHED() << "Received tap with tapcount " << tap_count; - return UMA_ET_UNKNOWN; - } - case ui::ET_GESTURE_TAP_DOWN: - return UMA_ET_GESTURE_TAP_DOWN; - case ui::ET_GESTURE_BEGIN: - return UMA_ET_GESTURE_BEGIN; - case ui::ET_GESTURE_END: - return UMA_ET_GESTURE_END; - case ui::ET_GESTURE_TWO_FINGER_TAP: - return UMA_ET_GESTURE_TWO_FINGER_TAP; - case ui::ET_GESTURE_PINCH_BEGIN: - return UMA_ET_GESTURE_PINCH_BEGIN; - case ui::ET_GESTURE_PINCH_END: - return UMA_ET_GESTURE_PINCH_END; - case ui::ET_GESTURE_PINCH_UPDATE: { - const ui::GestureEvent& gesture = - static_cast<const ui::GestureEvent&>(event); - if (gesture.details().touch_points() >= 4) - return UMA_ET_GESTURE_PINCH_UPDATE_4P; - else if (gesture.details().touch_points() == 3) - return UMA_ET_GESTURE_PINCH_UPDATE_3; - return UMA_ET_GESTURE_PINCH_UPDATE; - } - case ui::ET_GESTURE_LONG_PRESS: - return UMA_ET_GESTURE_LONG_PRESS; - case ui::ET_GESTURE_LONG_TAP: - return UMA_ET_GESTURE_LONG_TAP; - case ui::ET_GESTURE_MULTIFINGER_SWIPE: { - const ui::GestureEvent& gesture = - static_cast<const ui::GestureEvent&>(event); - if (gesture.details().touch_points() >= 4) - return UMA_ET_GESTURE_MULTIFINGER_SWIPE_4P; - else if (gesture.details().touch_points() == 3) - return UMA_ET_GESTURE_MULTIFINGER_SWIPE_3; - return UMA_ET_GESTURE_MULTIFINGER_SWIPE; - } - case ui::ET_SCROLL: - return UMA_ET_SCROLL; - case ui::ET_SCROLL_FLING_START: - return UMA_ET_SCROLL_FLING_START; - case ui::ET_SCROLL_FLING_CANCEL: - return UMA_ET_SCROLL_FLING_CANCEL; - default: - return UMA_ET_UNKNOWN; - } -} - -} - -namespace ash { - -// static -TouchUMA* TouchUMA::GetInstance() { - return Singleton<TouchUMA>::get(); -} - -void TouchUMA::RecordGestureEvent(aura::Window* target, - const ui::GestureEvent& event) { - UMA_HISTOGRAM_ENUMERATION("Ash.GestureCreated", - UMAEventTypeFromEvent(event), - UMA_ET_COUNT); - - GestureActionType action = FindGestureActionType(target, event); - RecordGestureAction(action); - - if (event.type() == ui::ET_GESTURE_END && - event.details().touch_points() == 2) { - WindowTouchDetails* details = target->GetProperty(kWindowTouchDetails); - if (!details) { - LOG(ERROR) << "Window received gesture events without receiving any touch" - " events"; - return; - } - details->last_mt_time_ = event.time_stamp(); - } -} - -void TouchUMA::RecordGestureAction(GestureActionType action) { - if (action == GESTURE_UNKNOWN || action >= GESTURE_ACTION_COUNT) - return; - UMA_HISTOGRAM_ENUMERATION("Ash.GestureTarget", action, - GESTURE_ACTION_COUNT); -} - -void TouchUMA::RecordTouchEvent(aura::Window* target, - const ui::TouchEvent& event) { - UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchRadius", - static_cast<int>(std::max(event.radius_x(), event.radius_y())), - 1, 500, 100); - - UpdateBurstData(event); - - WindowTouchDetails* details = target->GetProperty(kWindowTouchDetails); - if (!details) { - details = new WindowTouchDetails; - target->SetProperty(kWindowTouchDetails, details); - } - - // Record the location of the touch points. - const int kBucketCountForLocation = 100; - const gfx::Rect bounds = target->GetRootWindow()->bounds(); - const int bucket_size_x = std::max(1, - bounds.width() / kBucketCountForLocation); - const int bucket_size_y = std::max(1, - bounds.height() / kBucketCountForLocation); - - gfx::Point position = event.root_location(); - - // Prefer raw event location (when available) over calibrated location. - if (event.HasNativeEvent()) { -#if defined(USE_XI2_MT) - XEvent* xevent = event.native_event(); - CHECK_EQ(GenericEvent, xevent->type); - XIEvent* xievent = static_cast<XIEvent*>(xevent->xcookie.data); - if (xievent->evtype == XI_TouchBegin || - xievent->evtype == XI_TouchUpdate || - xievent->evtype == XI_TouchEnd) { - XIDeviceEvent* device_event = - static_cast<XIDeviceEvent*>(xevent->xcookie.data); - position.SetPoint(static_cast<int>(device_event->event_x), - static_cast<int>(device_event->event_y)); - } else { - position = ui::EventLocationFromNative(event.native_event()); - } -#else - position = ui::EventLocationFromNative(event.native_event()); -#endif - position = gfx::ToFlooredPoint( - gfx::ScalePoint(position, 1. / target->layer()->device_scale_factor())); - } - - position.set_x(std::min(bounds.width() - 1, std::max(0, position.x()))); - position.set_y(std::min(bounds.height() - 1, std::max(0, position.y()))); - - UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchPositionX", - position.x() / bucket_size_x, - 0, kBucketCountForLocation, kBucketCountForLocation + 1); - UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchPositionY", - position.y() / bucket_size_y, - 0, kBucketCountForLocation, kBucketCountForLocation + 1); - - if (event.type() == ui::ET_TOUCH_PRESSED) { - Shell::GetInstance()->delegate()->RecordUserMetricsAction( - UMA_TOUCHSCREEN_TAP_DOWN); - - details->last_start_time_[event.touch_id()] = event.time_stamp(); - details->start_touch_position_[event.touch_id()] = event.root_location(); - details->last_touch_position_[event.touch_id()] = event.location(); - - if (details->last_release_time_.ToInternalValue()) { - // Measuring the interval between a touch-release and the next - // touch-start is probably less useful when doing multi-touch (e.g. - // gestures, or multi-touch friendly apps). So count this only if the user - // hasn't done any multi-touch during the last 30 seconds. - base::TimeDelta diff = event.time_stamp() - details->last_mt_time_; - if (diff.InSeconds() > 30) { - base::TimeDelta gap = event.time_stamp() - details->last_release_time_; - UMA_HISTOGRAM_COUNTS_10000("Ash.TouchStartAfterEnd", - gap.InMilliseconds()); - } - } - - // Record the number of touch-points currently active for the window. - const int kMaxTouchPoints = 10; - UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.ActiveTouchPoints", - details->last_start_time_.size(), - 1, kMaxTouchPoints, kMaxTouchPoints + 1); - } else if (event.type() == ui::ET_TOUCH_RELEASED) { - if (details->last_start_time_.count(event.touch_id())) { - base::TimeDelta duration = event.time_stamp() - - details->last_start_time_[event.touch_id()]; - UMA_HISTOGRAM_COUNTS_100("Ash.TouchDuration", duration.InMilliseconds()); - - // Look for touches that were [almost] stationary for a long time. - const double kLongStationaryTouchDuration = 10; - const int kLongStationaryTouchDistanceSquared = 100; - if (duration.InSecondsF() > kLongStationaryTouchDuration) { - gfx::Vector2d distance = event.root_location() - - details->start_touch_position_[event.touch_id()]; - if (distance.LengthSquared() < kLongStationaryTouchDistanceSquared) { - UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.StationaryTouchDuration", - duration.InSeconds(), - kLongStationaryTouchDuration, - 1000, - 20); - } - } - } - details->last_start_time_.erase(event.touch_id()); - details->last_move_time_.erase(event.touch_id()); - details->start_touch_position_.erase(event.touch_id()); - details->last_touch_position_.erase(event.touch_id()); - details->last_release_time_ = event.time_stamp(); - } else if (event.type() == ui::ET_TOUCH_MOVED) { - int distance = 0; - if (details->last_touch_position_.count(event.touch_id())) { - gfx::Point lastpos = details->last_touch_position_[event.touch_id()]; - distance = abs(lastpos.x() - event.x()) + abs(lastpos.y() - event.y()); - } - - if (details->last_move_time_.count(event.touch_id())) { - base::TimeDelta move_delay = event.time_stamp() - - details->last_move_time_[event.touch_id()]; - UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchMoveInterval", - move_delay.InMilliseconds(), - 1, 50, 25); - } - - UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchMoveSteps", distance, 1, 1000, 50); - - details->last_move_time_[event.touch_id()] = event.time_stamp(); - details->last_touch_position_[event.touch_id()] = event.location(); - } -} - -TouchUMA::TouchUMA() - : touch_in_progress_(false), - burst_length_(0) { -} - -TouchUMA::~TouchUMA() { -} - -void TouchUMA::UpdateBurstData(const ui::TouchEvent& event) { - if (event.type() == ui::ET_TOUCH_PRESSED) { - if (!touch_in_progress_) { - base::TimeDelta difference = event.time_stamp() - last_touch_down_time_; - if (difference > base::TimeDelta::FromMilliseconds(250)) { - if (burst_length_) { - UMA_HISTOGRAM_COUNTS_100("Ash.TouchStartBurst", - std::min(burst_length_, 100)); - } - burst_length_ = 1; - } else { - ++burst_length_; - } - } - touch_in_progress_ = true; - last_touch_down_time_ = event.time_stamp(); - } else if (event.type() == ui::ET_TOUCH_RELEASED) { - if (!aura::Env::GetInstance()->is_touch_down()) - touch_in_progress_ = false; - } -} - -TouchUMA::GestureActionType TouchUMA::FindGestureActionType( - aura::Window* window, - const ui::GestureEvent& event) { - if (!window || window->GetRootWindow() == window) { - if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN) - return GESTURE_BEZEL_SCROLL; - if (event.type() == ui::ET_GESTURE_BEGIN) - return GESTURE_BEZEL_DOWN; - return GESTURE_UNKNOWN; - } - - std::string name = window ? window->name() : std::string(); - - const char kDesktopBackgroundView[] = "DesktopBackgroundView"; - if (name == kDesktopBackgroundView) { - if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN) - return GESTURE_DESKTOP_SCROLL; - if (event.type() == ui::ET_GESTURE_PINCH_BEGIN) - return GESTURE_DESKTOP_PINCH; - return GESTURE_UNKNOWN; - } - - const char kWebPage[] = "RenderWidgetHostViewAura"; - if (name == kWebPage) { - if (event.type() == ui::ET_GESTURE_PINCH_BEGIN) - return GESTURE_WEBPAGE_PINCH; - if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN) - return GESTURE_WEBPAGE_SCROLL; - if (event.type() == ui::ET_GESTURE_TAP) - return GESTURE_WEBPAGE_TAP; - return GESTURE_UNKNOWN; - } - - views::Widget* widget = views::Widget::GetWidgetForNativeView(window); - if (!widget) - return GESTURE_UNKNOWN; - - views::View* view = widget->GetRootView()-> - GetEventHandlerForPoint(event.location()); - if (!view) - return GESTURE_UNKNOWN; - - name = view->GetClassName(); - - const char kTabStrip[] = "TabStrip"; - const char kTab[] = "BrowserTab"; - if (name == kTabStrip || name == kTab) { - if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN) - return GESTURE_TABSTRIP_SCROLL; - if (event.type() == ui::ET_GESTURE_PINCH_BEGIN) - return GESTURE_TABSTRIP_PINCH; - if (event.type() == ui::ET_GESTURE_TAP) - return GESTURE_TABSTRIP_TAP; - return GESTURE_UNKNOWN; - } - - const char kOmnibox[] = "BrowserOmniboxViewViews"; - if (name == kOmnibox) { - if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN) - return GESTURE_OMNIBOX_SCROLL; - if (event.type() == ui::ET_GESTURE_PINCH_BEGIN) - return GESTURE_OMNIBOX_PINCH; - return GESTURE_UNKNOWN; - } - - return GESTURE_UNKNOWN; -} - -} // namespace ash diff --git a/chromium/ash/touch/touch_uma.h b/chromium/ash/touch/touch_uma.h deleted file mode 100644 index 3e2c7fda3ec..00000000000 --- a/chromium/ash/touch/touch_uma.h +++ /dev/null @@ -1,83 +0,0 @@ -// 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_UMA_H_ -#define ASH_TOUCH_TOUCH_OBSERVER_UMA_H_ - -#include <map> - -#include "ash/shell.h" -#include "base/memory/singleton.h" -#include "ui/gfx/point.h" -#include "ui/views/widget/widget.h" - -namespace aura { -class Window; -} - -namespace ash { - -// Records some touch/gesture event specific details (e.g. what gestures are -// targetted to which components etc.) -class ASH_EXPORT TouchUMA { - public: - enum GestureActionType { - GESTURE_UNKNOWN, - GESTURE_OMNIBOX_PINCH, - GESTURE_OMNIBOX_SCROLL, - GESTURE_TABSTRIP_PINCH, - GESTURE_TABSTRIP_SCROLL, - GESTURE_BEZEL_SCROLL, - GESTURE_DESKTOP_SCROLL, - GESTURE_DESKTOP_PINCH, - GESTURE_WEBPAGE_PINCH, - GESTURE_WEBPAGE_SCROLL, - GESTURE_WEBPAGE_TAP, - GESTURE_TABSTRIP_TAP, - GESTURE_BEZEL_DOWN, - GESTURE_TABSWITCH_TAP, - GESTURE_TABNOSWITCH_TAP, - GESTURE_TABCLOSE_TAP, - GESTURE_NEWTAB_TAP, - GESTURE_ROOTVIEWTOP_TAP, - GESTURE_FRAMEMAXIMIZE_TAP, - GESTURE_FRAMEVIEW_TAP, - GESTURE_MAXIMIZE_DOUBLETAP, - // NOTE: Add new action types only immediately above this line. Also, - // make sure the enum list in tools/histogram/histograms.xml is - // updated with any change in here. - GESTURE_ACTION_COUNT - }; - - // Returns the singleton instance. - static TouchUMA* GetInstance(); - - void RecordGestureEvent(aura::Window* target, - const ui::GestureEvent& event); - void RecordGestureAction(GestureActionType action); - void RecordTouchEvent(aura::Window* target, - const ui::TouchEvent& event); - - private: - friend struct DefaultSingletonTraits<TouchUMA>; - - TouchUMA(); - ~TouchUMA(); - - void UpdateBurstData(const ui::TouchEvent& event); - GestureActionType FindGestureActionType(aura::Window* window, - const ui::GestureEvent& event); - - // These are used to measure the number of touch-start events we receive in a - // quick succession, regardless of the target window. - bool touch_in_progress_; - int burst_length_; - base::TimeDelta last_touch_down_time_; - - DISALLOW_COPY_AND_ASSIGN(TouchUMA); -}; - -} // namespace ash - -#endif // ASH_TOUCH_TOUCH_OBSERVER_UMA_H_ |