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,
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;
if (Shell::Get()
->tablet_mode_controller()
......@@ -59,8 +62,7 @@ void RecordUMA(ui::EventPointerType type, views::Widget* target) {
DownEventSource input_type = DownEventSource::kUnknown;
switch (type) {
case ui::EventPointerType::POINTER_TYPE_UNKNOWN:
input_type = DownEventSource::kUnknown;
break;
return;
case ui::EventPointerType::POINTER_TYPE_MOUSE:
input_type = DownEventSource::kMouse;
break;
......@@ -84,20 +86,21 @@ void RecordUMA(ui::EventPointerType type, views::Widget* target) {
} // namespace
PointerMetricsRecorder::PointerMetricsRecorder() {
Shell::Get()->AddPointerWatcher(this, views::PointerWatcherEventTypes::BASIC);
Shell::Get()->AddPreTargetHandler(this);
}
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(
const ui::PointerEvent& event,
const gfx::Point& location_in_screen,
gfx::NativeView target) {
if (event.type() == ui::ET_POINTER_DOWN)
RecordUMA(event.pointer_details().pointer_type,
views::Widget::GetTopLevelWidgetForNativeView(target));
void PointerMetricsRecorder::OnTouchEvent(ui::TouchEvent* event) {
if (event->type() == ui::ET_TOUCH_PRESSED)
RecordUMA(event->pointer_details().pointer_type, event->target());
}
} // namespace ash
......@@ -7,15 +7,7 @@
#include "ash/ash_export.h"
#include "base/macros.h"
#include "ui/views/pointer_watcher.h"
namespace gfx {
class Point;
}
namespace ui {
class PointerEvent;
}
#include "ui/events/event_handler.h"
namespace ash {
......@@ -33,7 +25,7 @@ enum class DownEventFormFactor {
// This enum is used to control a UMA histogram buckets. If you change this
// enum, you should update DownEventMetric as well.
enum class DownEventSource {
kUnknown = 0,
kUnknown = 0, // Deprecated, never occurs in practice.
kMouse,
kStylus,
kTouch,
......@@ -44,6 +36,7 @@ enum class DownEventSource {
// This enum is used to back an UMA histogram and new values should
// be inserted immediately above kCombinationCount.
enum class DownEventMetric {
// All "Unknown" types are deprecated, never occur in practice.
kUnknownClamshellOthers = 0,
kUnknownClamshellBrowser,
kUnknownClamshellChromeApp,
......@@ -96,15 +89,14 @@ enum class DownEventMetric {
};
// A metrics recorder that records pointer related metrics.
class ASH_EXPORT PointerMetricsRecorder : public views::PointerWatcher {
class ASH_EXPORT PointerMetricsRecorder : public ui::EventHandler {
public:
PointerMetricsRecorder();
~PointerMetricsRecorder() override;
// views::PointerWatcher:
void OnPointerEventObserved(const ui::PointerEvent& event,
const gfx::Point& location_in_screen,
gfx::NativeView target) override;
// ui::EventHandler:
void OnMouseEvent(ui::MouseEvent* event) override;
void OnTouchEvent(ui::TouchEvent* event) override;
private:
DISALLOW_COPY_AND_ASSIGN(PointerMetricsRecorder);
......
......@@ -75,10 +75,6 @@ void PointerMetricsRecorderTest::CreateDownEvent(
ui::EventPointerType pointer_type,
DownEventFormFactor form_factor,
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();
CHECK(window);
window->SetProperty(aura::client::kAppType, static_cast<int>(destination));
......@@ -99,8 +95,19 @@ void PointerMetricsRecorderTest::CreateDownEvent(
test_api.SetDisplayRotation(rotation,
display::Display::RotationSource::ACTIVE);
}
pointer_metrics_recorder_->OnPointerEventObserved(pointer_event, gfx::Point(),
window);
if (pointer_type == ui::EventPointerType::POINTER_TYPE_MOUSE) {
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
......@@ -108,12 +115,9 @@ void PointerMetricsRecorderTest::CreateDownEvent(
// Verifies that histogram is not recorded when receiving events that are not
// down events.
TEST_F(PointerMetricsRecorderTest, NonDownEventsInAllPointerHistogram) {
const ui::PointerEvent pointer_event(
ui::ET_POINTER_UP, gfx::Point(), gfx::Point(), 0, 0,
ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE, 0),
base::TimeTicks());
pointer_metrics_recorder_->OnPointerEventObserved(pointer_event, gfx::Point(),
widget_->GetNativeView());
ui::MouseEvent mouse_up(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(),
base::TimeTicks(), 0, 0);
pointer_metrics_recorder_->OnMouseEvent(&mouse_up);
histogram_tester_->ExpectTotalCount(kCombinationHistogramName, 0);
}
......@@ -126,80 +130,6 @@ TEST_F(PointerMetricsRecorderTest, DownEventPerCombination) {
display::test::ScopedSetInternalDisplayId set_internal(display_manager,
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,
DownEventFormFactor::kClamshell, AppType::OTHERS);
histogram_tester_->ExpectBucketCount(
......@@ -422,9 +352,7 @@ TEST_F(PointerMetricsRecorderTest, DownEventPerCombination) {
kCombinationHistogramName,
static_cast<int>(DownEventMetric::kStylusTabletPortraitArcApp), 1);
histogram_tester_->ExpectTotalCount(
kCombinationHistogramName,
static_cast<int>(DownEventMetric::kCombinationCount));
histogram_tester_->ExpectTotalCount(kCombinationHistogramName, 36);
}
} // 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