Commit 455fc184 authored by James Cook's avatar James Cook Committed by Commit Bot

chromeos: Convert PointerMetricsRecorder to ui::EventHandler

PointerWatchers aren't necessary in ash anymore. ui::EventHandler does
everything that PointerWatcher can do, plus can mutate events. Once
we eliminate PointerWatcher from ash we can delete some glue code I
added to make them work.

Also drop support for ui::EventPointerType::POINTER_TYPE_UNKNOWN,
which is never recorded in practice. (I don't think we ever generate
events with this type.)

Bug: 872450, 786214
Test: ash_unittests
Change-Id: I08f781dd6e26b34870e7947c3a14e42edaf91080
Reviewed-on: https://chromium-review.googlesource.com/1239455Reviewed-by: default avatarXiaoyin Hu <xiaoyinh@chromium.org>
Commit-Queue: James Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593631}
parent 47be7815
...@@ -41,7 +41,10 @@ DownEventMetric FindCombination(DownEventSource input_type, ...@@ -41,7 +41,10 @@ DownEventMetric FindCombination(DownEventSource input_type,
return static_cast<DownEventMetric>(result); return static_cast<DownEventMetric>(result);
} }
void RecordUMA(ui::EventPointerType type, views::Widget* target) { void RecordUMA(ui::EventPointerType type, ui::EventTarget* event_target) {
DCHECK_NE(type, ui::EventPointerType::POINTER_TYPE_UNKNOWN);
views::Widget* target = views::Widget::GetTopLevelWidgetForNativeView(
static_cast<aura::Window*>(event_target));
DownEventFormFactor form_factor = DownEventFormFactor::kClamshell; DownEventFormFactor form_factor = DownEventFormFactor::kClamshell;
if (Shell::Get() if (Shell::Get()
->tablet_mode_controller() ->tablet_mode_controller()
...@@ -59,8 +62,7 @@ void RecordUMA(ui::EventPointerType type, views::Widget* target) { ...@@ -59,8 +62,7 @@ void RecordUMA(ui::EventPointerType type, views::Widget* target) {
DownEventSource input_type = DownEventSource::kUnknown; DownEventSource input_type = DownEventSource::kUnknown;
switch (type) { switch (type) {
case ui::EventPointerType::POINTER_TYPE_UNKNOWN: case ui::EventPointerType::POINTER_TYPE_UNKNOWN:
input_type = DownEventSource::kUnknown; return;
break;
case ui::EventPointerType::POINTER_TYPE_MOUSE: case ui::EventPointerType::POINTER_TYPE_MOUSE:
input_type = DownEventSource::kMouse; input_type = DownEventSource::kMouse;
break; break;
...@@ -84,20 +86,21 @@ void RecordUMA(ui::EventPointerType type, views::Widget* target) { ...@@ -84,20 +86,21 @@ void RecordUMA(ui::EventPointerType type, views::Widget* target) {
} // namespace } // namespace
PointerMetricsRecorder::PointerMetricsRecorder() { PointerMetricsRecorder::PointerMetricsRecorder() {
Shell::Get()->AddPointerWatcher(this, views::PointerWatcherEventTypes::BASIC); Shell::Get()->AddPreTargetHandler(this);
} }
PointerMetricsRecorder::~PointerMetricsRecorder() { PointerMetricsRecorder::~PointerMetricsRecorder() {
Shell::Get()->RemovePointerWatcher(this); Shell::Get()->RemovePreTargetHandler(this);
}
void PointerMetricsRecorder::OnMouseEvent(ui::MouseEvent* event) {
if (event->type() == ui::ET_MOUSE_PRESSED)
RecordUMA(event->pointer_details().pointer_type, event->target());
} }
void PointerMetricsRecorder::OnPointerEventObserved( void PointerMetricsRecorder::OnTouchEvent(ui::TouchEvent* event) {
const ui::PointerEvent& event, if (event->type() == ui::ET_TOUCH_PRESSED)
const gfx::Point& location_in_screen, RecordUMA(event->pointer_details().pointer_type, event->target());
gfx::NativeView target) {
if (event.type() == ui::ET_POINTER_DOWN)
RecordUMA(event.pointer_details().pointer_type,
views::Widget::GetTopLevelWidgetForNativeView(target));
} }
} // namespace ash } // namespace ash
...@@ -7,15 +7,7 @@ ...@@ -7,15 +7,7 @@
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "base/macros.h" #include "base/macros.h"
#include "ui/views/pointer_watcher.h" #include "ui/events/event_handler.h"
namespace gfx {
class Point;
}
namespace ui {
class PointerEvent;
}
namespace ash { namespace ash {
...@@ -33,7 +25,7 @@ enum class DownEventFormFactor { ...@@ -33,7 +25,7 @@ enum class DownEventFormFactor {
// This enum is used to control a UMA histogram buckets. If you change this // This enum is used to control a UMA histogram buckets. If you change this
// enum, you should update DownEventMetric as well. // enum, you should update DownEventMetric as well.
enum class DownEventSource { enum class DownEventSource {
kUnknown = 0, kUnknown = 0, // Deprecated, never occurs in practice.
kMouse, kMouse,
kStylus, kStylus,
kTouch, kTouch,
...@@ -44,6 +36,7 @@ enum class DownEventSource { ...@@ -44,6 +36,7 @@ enum class DownEventSource {
// This enum is used to back an UMA histogram and new values should // This enum is used to back an UMA histogram and new values should
// be inserted immediately above kCombinationCount. // be inserted immediately above kCombinationCount.
enum class DownEventMetric { enum class DownEventMetric {
// All "Unknown" types are deprecated, never occur in practice.
kUnknownClamshellOthers = 0, kUnknownClamshellOthers = 0,
kUnknownClamshellBrowser, kUnknownClamshellBrowser,
kUnknownClamshellChromeApp, kUnknownClamshellChromeApp,
...@@ -96,15 +89,14 @@ enum class DownEventMetric { ...@@ -96,15 +89,14 @@ enum class DownEventMetric {
}; };
// A metrics recorder that records pointer related metrics. // A metrics recorder that records pointer related metrics.
class ASH_EXPORT PointerMetricsRecorder : public views::PointerWatcher { class ASH_EXPORT PointerMetricsRecorder : public ui::EventHandler {
public: public:
PointerMetricsRecorder(); PointerMetricsRecorder();
~PointerMetricsRecorder() override; ~PointerMetricsRecorder() override;
// views::PointerWatcher: // ui::EventHandler:
void OnPointerEventObserved(const ui::PointerEvent& event, void OnMouseEvent(ui::MouseEvent* event) override;
const gfx::Point& location_in_screen, void OnTouchEvent(ui::TouchEvent* event) override;
gfx::NativeView target) override;
private: private:
DISALLOW_COPY_AND_ASSIGN(PointerMetricsRecorder); DISALLOW_COPY_AND_ASSIGN(PointerMetricsRecorder);
......
...@@ -75,10 +75,6 @@ void PointerMetricsRecorderTest::CreateDownEvent( ...@@ -75,10 +75,6 @@ void PointerMetricsRecorderTest::CreateDownEvent(
ui::EventPointerType pointer_type, ui::EventPointerType pointer_type,
DownEventFormFactor form_factor, DownEventFormFactor form_factor,
AppType destination) { AppType destination) {
const ui::PointerEvent pointer_event(
ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), 0, 0,
ui::PointerDetails(pointer_type, 0), base::TimeTicks());
aura::Window* window = widget_->GetNativeWindow(); aura::Window* window = widget_->GetNativeWindow();
CHECK(window); CHECK(window);
window->SetProperty(aura::client::kAppType, static_cast<int>(destination)); window->SetProperty(aura::client::kAppType, static_cast<int>(destination));
...@@ -99,8 +95,19 @@ void PointerMetricsRecorderTest::CreateDownEvent( ...@@ -99,8 +95,19 @@ void PointerMetricsRecorderTest::CreateDownEvent(
test_api.SetDisplayRotation(rotation, test_api.SetDisplayRotation(rotation,
display::Display::RotationSource::ACTIVE); display::Display::RotationSource::ACTIVE);
} }
pointer_metrics_recorder_->OnPointerEventObserved(pointer_event, gfx::Point(), if (pointer_type == ui::EventPointerType::POINTER_TYPE_MOUSE) {
window); ui::MouseEvent mouse_down(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
base::TimeTicks(), 0, 0);
ui::Event::DispatcherApi(&mouse_down).set_target(window);
pointer_metrics_recorder_->OnMouseEvent(&mouse_down);
} else {
// Pen and eraser events are touch events.
ui::TouchEvent touch_down(ui::ET_TOUCH_PRESSED, gfx::Point(),
base::TimeTicks(),
ui::PointerDetails(pointer_type, 0));
ui::Event::DispatcherApi(&touch_down).set_target(window);
pointer_metrics_recorder_->OnTouchEvent(&touch_down);
}
} }
} // namespace } // namespace
...@@ -108,12 +115,9 @@ void PointerMetricsRecorderTest::CreateDownEvent( ...@@ -108,12 +115,9 @@ void PointerMetricsRecorderTest::CreateDownEvent(
// Verifies that histogram is not recorded when receiving events that are not // Verifies that histogram is not recorded when receiving events that are not
// down events. // down events.
TEST_F(PointerMetricsRecorderTest, NonDownEventsInAllPointerHistogram) { TEST_F(PointerMetricsRecorderTest, NonDownEventsInAllPointerHistogram) {
const ui::PointerEvent pointer_event( ui::MouseEvent mouse_up(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(),
ui::ET_POINTER_UP, gfx::Point(), gfx::Point(), 0, 0, base::TimeTicks(), 0, 0);
ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE, 0), pointer_metrics_recorder_->OnMouseEvent(&mouse_up);
base::TimeTicks());
pointer_metrics_recorder_->OnPointerEventObserved(pointer_event, gfx::Point(),
widget_->GetNativeView());
histogram_tester_->ExpectTotalCount(kCombinationHistogramName, 0); histogram_tester_->ExpectTotalCount(kCombinationHistogramName, 0);
} }
...@@ -126,80 +130,6 @@ TEST_F(PointerMetricsRecorderTest, DownEventPerCombination) { ...@@ -126,80 +130,6 @@ TEST_F(PointerMetricsRecorderTest, DownEventPerCombination) {
display::test::ScopedSetInternalDisplayId set_internal(display_manager, display::test::ScopedSetInternalDisplayId set_internal(display_manager,
display_id); display_id);
CreateDownEvent(ui::EventPointerType::POINTER_TYPE_UNKNOWN,
DownEventFormFactor::kClamshell, AppType::OTHERS);
histogram_tester_->ExpectBucketCount(
kCombinationHistogramName,
static_cast<int>(DownEventMetric::kUnknownClamshellOthers), 1);
CreateDownEvent(ui::EventPointerType::POINTER_TYPE_UNKNOWN,
DownEventFormFactor::kClamshell, AppType::BROWSER);
histogram_tester_->ExpectBucketCount(
kCombinationHistogramName,
static_cast<int>(DownEventMetric::kUnknownClamshellBrowser), 1);
CreateDownEvent(ui::EventPointerType::POINTER_TYPE_UNKNOWN,
DownEventFormFactor::kClamshell, AppType::CHROME_APP);
histogram_tester_->ExpectBucketCount(
kCombinationHistogramName,
static_cast<int>(DownEventMetric::kUnknownClamshellChromeApp), 1);
CreateDownEvent(ui::EventPointerType::POINTER_TYPE_UNKNOWN,
DownEventFormFactor::kClamshell, AppType::ARC_APP);
histogram_tester_->ExpectBucketCount(
kCombinationHistogramName,
static_cast<int>(DownEventMetric::kUnknownClamshellArcApp), 1);
CreateDownEvent(ui::EventPointerType::POINTER_TYPE_UNKNOWN,
DownEventFormFactor::kTabletModeLandscape, AppType::OTHERS);
histogram_tester_->ExpectBucketCount(
kCombinationHistogramName,
static_cast<int>(DownEventMetric::kUnknownTabletLandscapeOthers), 1);
CreateDownEvent(ui::EventPointerType::POINTER_TYPE_UNKNOWN,
DownEventFormFactor::kTabletModeLandscape, AppType::BROWSER);
histogram_tester_->ExpectBucketCount(
kCombinationHistogramName,
static_cast<int>(DownEventMetric::kUnknownTabletLandscapeBrowser), 1);
CreateDownEvent(ui::EventPointerType::POINTER_TYPE_UNKNOWN,
DownEventFormFactor::kTabletModeLandscape,
AppType::CHROME_APP);
histogram_tester_->ExpectBucketCount(
kCombinationHistogramName,
static_cast<int>(DownEventMetric::kUnknownTabletLandscapeChromeApp), 1);
CreateDownEvent(ui::EventPointerType::POINTER_TYPE_UNKNOWN,
DownEventFormFactor::kTabletModeLandscape, AppType::ARC_APP);
histogram_tester_->ExpectBucketCount(
kCombinationHistogramName,
static_cast<int>(DownEventMetric::kUnknownTabletLandscapeArcApp), 1);
CreateDownEvent(ui::EventPointerType::POINTER_TYPE_UNKNOWN,
DownEventFormFactor::kTabletModePortrait, AppType::OTHERS);
histogram_tester_->ExpectBucketCount(
kCombinationHistogramName,
static_cast<int>(DownEventMetric::kUnknownTabletPortraitOthers), 1);
CreateDownEvent(ui::EventPointerType::POINTER_TYPE_UNKNOWN,
DownEventFormFactor::kTabletModePortrait, AppType::BROWSER);
histogram_tester_->ExpectBucketCount(
kCombinationHistogramName,
static_cast<int>(DownEventMetric::kUnknownTabletPortraitBrowser), 1);
CreateDownEvent(ui::EventPointerType::POINTER_TYPE_UNKNOWN,
DownEventFormFactor::kTabletModePortrait,
AppType::CHROME_APP);
histogram_tester_->ExpectBucketCount(
kCombinationHistogramName,
static_cast<int>(DownEventMetric::kUnknownTabletPortraitChromeApp), 1);
CreateDownEvent(ui::EventPointerType::POINTER_TYPE_UNKNOWN,
DownEventFormFactor::kTabletModePortrait, AppType::ARC_APP);
histogram_tester_->ExpectBucketCount(
kCombinationHistogramName,
static_cast<int>(DownEventMetric::kUnknownTabletPortraitArcApp), 1);
CreateDownEvent(ui::EventPointerType::POINTER_TYPE_MOUSE, CreateDownEvent(ui::EventPointerType::POINTER_TYPE_MOUSE,
DownEventFormFactor::kClamshell, AppType::OTHERS); DownEventFormFactor::kClamshell, AppType::OTHERS);
histogram_tester_->ExpectBucketCount( histogram_tester_->ExpectBucketCount(
...@@ -422,9 +352,7 @@ TEST_F(PointerMetricsRecorderTest, DownEventPerCombination) { ...@@ -422,9 +352,7 @@ TEST_F(PointerMetricsRecorderTest, DownEventPerCombination) {
kCombinationHistogramName, kCombinationHistogramName,
static_cast<int>(DownEventMetric::kStylusTabletPortraitArcApp), 1); static_cast<int>(DownEventMetric::kStylusTabletPortraitArcApp), 1);
histogram_tester_->ExpectTotalCount( histogram_tester_->ExpectTotalCount(kCombinationHistogramName, 36);
kCombinationHistogramName,
static_cast<int>(DownEventMetric::kCombinationCount));
} }
} // namespace ash } // namespace ash
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