diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-02 02:07:45 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-02 02:07:45 +0000 |
commit | 40c21bd2186610e63636f75912752b8b7982f67b (patch) | |
tree | 5078453a60fefce0243271aee7292be8cce61b58 /ash | |
parent | 110acecb930631867c825e70396c6364083fe553 (diff) | |
download | chromium_src-40c21bd2186610e63636f75912752b8b7982f67b.zip chromium_src-40c21bd2186610e63636f75912752b8b7982f67b.tar.gz chromium_src-40c21bd2186610e63636f75912752b8b7982f67b.tar.bz2 |
ash: Include the HUD log in the feedback reports.
BUG=173587
Review URL: https://codereview.chromium.org/12087127
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@180232 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/touch/touch_observer_hud.cc | 144 | ||||
-rw-r--r-- | ash/touch/touch_observer_hud.h | 7 |
2 files changed, 142 insertions, 9 deletions
diff --git a/ash/touch/touch_observer_hud.cc b/ash/touch/touch_observer_hud.cc index 51809b0..05d0d87 100644 --- a/ash/touch/touch_observer_hud.cc +++ b/ash/touch/touch_observer_hud.cc @@ -5,8 +5,10 @@ #include "ash/touch/touch_observer_hud.h" #include "ash/shell_window_ids.h" +#include "base/json/json_string_value_serializer.h" #include "base/stringprintf.h" #include "base/utf_string_conversions.h" +#include "base/values.h" #include "third_party/skia/include/core/SkPath.h" #include "third_party/skia/include/core/SkXfermode.h" #include "ui/aura/window.h" @@ -22,6 +24,13 @@ #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/valuators.h" +#endif + namespace ash { namespace internal { @@ -41,6 +50,103 @@ const int kAlpha = 0x60; const int kMaxPaths = arraysize(kColors); const int kReducedScale = 10; +int GetTrackingId(const ui::TouchEvent& event) { + if (!event.HasNativeEvent()) + return 0; +#if defined(USE_XI2_MT) + ui::ValuatorTracker* valuators = ui::ValuatorTracker::GetInstance(); + float tracking_id; + if (valuators->ExtractValuator(*event.native_event(), + ui::ValuatorTracker::VAL_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()), + tracking_id(GetTrackingId(touch)), + location(touch.root_location()), + radius_x(touch.radius_x()), + radius_y(touch.radius_y()), + pressure(touch.force()), + 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->SetInteger("tracking_id", tracking_id); + value->SetString("location", location.ToString()); + value->SetDouble("radius_x", radius_x); + value->SetDouble("radius_y", radius_y); + value->SetDouble("pressure", pressure); + value->SetInteger("source_device", source_device); + + return value.Pass(); + } + + int id; + int tracking_id; + gfx::Point location; + float radius_x; + float radius_y; + float pressure; + 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 touch-release). +class TouchTrace { + public: + TouchTrace() { + } + + void AddTouchPoint(const ui::TouchEvent& touch) { + log_.push_back(TouchPointLog(touch)); + } + + bool empty() const { return log_.empty(); } + + // Returns a list containing data from all events for the touch point. + scoped_ptr<ListValue> GetAsList() const { + scoped_ptr<ListValue> list(new ListValue()); + for (std::vector<TouchPointLog>::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); +}; + class TouchHudCanvas : public views::View { public: explicit TouchHudCanvas(TouchObserverHUD* owner) @@ -67,23 +173,29 @@ class TouchHudCanvas : public views::View { int scale() const { return scale_; } - void Start(int id, const gfx::Point& point) { + void Start(const ui::TouchEvent& touch) { + int id = touch.touch_id(); paths_[path_index_].reset(); + traces_[path_index_].Reset(); 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); + AddPoint(touch); SchedulePaint(); } - void AddPoint(int id, const gfx::Point& point) { - SkPoint last; + void AddPoint(const ui::TouchEvent& touch) { + int id = touch.touch_id(); + const gfx::Point& point = touch.root_location(); int path_id = touch_id_to_path_[id]; SkScalar x = SkIntToScalar(point.x()); SkScalar y = SkIntToScalar(point.y()); - if (!paths_[path_id].getLastPt(&last) || x != last.x() || y != last.y()) + SkPoint last; + if (!paths_[path_id].getLastPt(&last) || x != last.x() || y != last.y()) { paths_[path_id].addCircle(x, y, SkIntToScalar(kPointRadius)); + traces_[path_id].AddTouchPoint(touch); + } SchedulePaint(); } @@ -92,11 +204,21 @@ class TouchHudCanvas : public views::View { color_index_ = 0; for (size_t i = 0; i < arraysize(paths_); ++i) { paths_[i].reset(); + traces_[i].Reset(); } SchedulePaint(); } + scoped_ptr<ListValue> GetAsList() const { + scoped_ptr<ListValue> list(new ListValue()); + for (size_t i = 0; i < arraysize(traces_); ++i) { + if (!traces_[i].empty()) + list->Append(traces_[i].GetAsList().release()); + } + return list.Pass(); + } + private: // Overridden from views::View. virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { @@ -116,6 +238,7 @@ class TouchHudCanvas : public views::View { TouchObserverHUD* owner_; SkPath paths_[kMaxPaths]; SkColor colors_[kMaxPaths]; + TouchTrace traces_[kMaxPaths]; int path_index_; int color_index_; @@ -201,6 +324,13 @@ void TouchObserverHUD::Clear() { canvas_->Clear(); } +std::string TouchObserverHUD::GetLogAsString() const { + std::string string; + scoped_ptr<ListValue> list = canvas_->GetAsList(); + JSONStringValueSerializer json(&string); + return json.Serialize(*list) ? string : std::string(); +} + void TouchObserverHUD::UpdateTouchPointLabel(int index) { const char* status = NULL; switch (touch_status_[index]) { @@ -235,9 +365,9 @@ void TouchObserverHUD::OnTouchEvent(ui::TouchEvent* event) { if (event->type() != ui::ET_TOUCH_CANCELLED) touch_positions_[event->touch_id()] = event->root_location(); if (event->type() == ui::ET_TOUCH_PRESSED) - canvas_->Start(event->touch_id(), touch_positions_[event->touch_id()]); + canvas_->Start(*event); else - canvas_->AddPoint(event->touch_id(), touch_positions_[event->touch_id()]); + canvas_->AddPoint(*event); touch_status_[event->touch_id()] = event->type(); UpdateTouchPointLabel(event->touch_id()); diff --git a/ash/touch/touch_observer_hud.h b/ash/touch/touch_observer_hud.h index 3ae4e3d..c4f3aa3 100644 --- a/ash/touch/touch_observer_hud.h +++ b/ash/touch/touch_observer_hud.h @@ -5,6 +5,7 @@ #ifndef ASH_TOUCH_TOUCH_OBSERVER_HUD_H_ #define ASH_TOUCH_TOUCH_OBSERVER_HUD_H_ +#include "ash/ash_export.h" #include "ash/shell.h" #include "ui/base/events/event_handler.h" #include "ui/gfx/point.h" @@ -26,8 +27,8 @@ namespace internal { class TouchHudCanvas; // An event filter which handles system level gesture events. -class TouchObserverHUD : public ui::EventHandler, - public views::WidgetObserver { +class ASH_EXPORT TouchObserverHUD : public ui::EventHandler, + public views::WidgetObserver { public: TouchObserverHUD(); virtual ~TouchObserverHUD(); @@ -40,6 +41,8 @@ class TouchObserverHUD : public ui::EventHandler, // visible). void Clear(); + std::string GetLogAsString() const; + private: void UpdateTouchPointLabel(int index); |