Commit 536445df authored by miletus@chromium.org's avatar miletus@chromium.org

Correct scale for touch radius & scroll offset ordinal

In https://codereview.chromium.org/12983010/

reversed_root_transform is passed into event::UpdateForRootTransform.

Then for TouchEvent::UpdateForRootTransform(), the radius_x/y now
should times the inverted device scale factor instead of being
divided by it. The same in ScrollEvent::UpdateForRootTransform() for
scroll offset ordinal.

BUG=chromium:226169
TEST=On Link, visit http://www.rbyers.net/paint.html, make sure
     touch radius has normal range.

Review URL: https://chromiumcodereview.appspot.com/13594009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@192490 0039d316-1c4b-4281-b951-d872f2087c98
parent 8039b2ed
......@@ -25,6 +25,8 @@ namespace ash {
namespace test {
namespace {
const char kDesktopBackgroundView[] = "DesktopBackgroundView";
class TestObserver : public DisplayController::Observer {
public:
TestObserver() : changing_count_(0), changed_count_(0) {
......@@ -98,20 +100,53 @@ class DisplayControllerShutdownTest : public test::AshTestBase {
class TestEventHandler : public ui::EventHandler {
public:
TestEventHandler() : target_root_(NULL) {}
TestEventHandler() : target_root_(NULL),
touch_radius_x_(0.0),
touch_radius_y_(0.0),
scroll_x_offset_(0.0),
scroll_y_offset_(0.0),
scroll_x_offset_ordinal_(0.0),
scroll_y_offset_ordinal_(0.0) {}
virtual ~TestEventHandler() {}
virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
aura::Window* target = static_cast<aura::Window*>(event->target());
// Only record when the target is the background which covers
// entire root window.
if (target->name() != "DesktopBackgroundView")
if (target->name() != kDesktopBackgroundView)
return;
mouse_location_ = event->location();
target_root_ = target->GetRootWindow();
event->StopPropagation();
}
virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE {
aura::Window* target = static_cast<aura::Window*>(event->target());
// Only record when the target is the background which covers
// entire root window.
if (target->name() != kDesktopBackgroundView)
return;
touch_radius_x_ = event->radius_x();
touch_radius_y_ = event->radius_y();
event->StopPropagation();
}
virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE {
aura::Window* target = static_cast<aura::Window*>(event->target());
// Only record when the target is the background which covers
// entire root window.
if (target->name() != kDesktopBackgroundView)
return;
if (event->type() == ui::ET_SCROLL) {
scroll_x_offset_ = event->x_offset();
scroll_y_offset_ = event->y_offset();
scroll_x_offset_ordinal_ = event->x_offset_ordinal();
scroll_y_offset_ordinal_ = event->y_offset_ordinal();
}
event->StopPropagation();
}
std::string GetLocationAndReset() {
std::string result = mouse_location_.ToString();
mouse_location_.SetPoint(0, 0);
......@@ -119,10 +154,24 @@ class TestEventHandler : public ui::EventHandler {
return result;
}
float touch_radius_x() { return touch_radius_x_; }
float touch_radius_y() { return touch_radius_y_; }
float scroll_x_offset() { return scroll_x_offset_; }
float scroll_y_offset() { return scroll_y_offset_; }
float scroll_x_offset_ordinal() { return scroll_x_offset_ordinal_; }
float scroll_y_offset_ordinal() { return scroll_y_offset_ordinal_; }
private:
gfx::Point mouse_location_;
aura::RootWindow* target_root_;
float touch_radius_x_;
float touch_radius_y_;
float scroll_x_offset_;
float scroll_y_offset_;
float scroll_x_offset_ordinal_;
float scroll_y_offset_ordinal_;
DISALLOW_COPY_AND_ASSIGN(TestEventHandler);
};
......@@ -791,5 +840,44 @@ TEST_F(DisplayControllerTest, MAYBE_ScaleRootWindow) {
Shell::GetInstance()->RemovePreTargetHandler(&event_handler);
}
#if defined(OS_WIN)
// On Win8 bots, the host window can't be resized and
// SetTransform updates the window using the orignal host window
// size.
#define MAYBE_TouchScale DISABLED_TouchScale
#else
#define MAYBE_TouchScale TouchScale
#endif
TEST_F(DisplayControllerTest, MAYBE_TouchScale) {
TestEventHandler event_handler;
Shell::GetInstance()->AddPreTargetHandler(&event_handler);
UpdateDisplay("200x200*2");
gfx::Display display = Shell::GetScreen()->GetPrimaryDisplay();
Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
aura::RootWindow* root_window = root_windows[0];
aura::test::EventGenerator generator(root_window);
generator.PressMoveAndReleaseTouchTo(50, 50);
// Default test touches have radius_x/y = 1.0, with device scale
// factor = 2, the scaled radius_x/y should be 0.5.
EXPECT_EQ(0.5, event_handler.touch_radius_x());
EXPECT_EQ(0.5, event_handler.touch_radius_y());
generator.ScrollSequence(gfx::Point(0,0),
base::TimeDelta::FromMilliseconds(100),
10.0, 1.0, 5, 1);
// With device scale factor = 2, ordinal_offset * 2 = offset.
EXPECT_EQ(event_handler.scroll_x_offset(),
event_handler.scroll_x_offset_ordinal() * 2);
EXPECT_EQ(event_handler.scroll_y_offset(),
event_handler.scroll_y_offset_ordinal() * 2);
Shell::GetInstance()->RemovePreTargetHandler(&event_handler);
}
} // namespace test
} // namespace ash
......@@ -61,8 +61,8 @@ class TestTouchEvent : public ui::TouchEvent {
TestTouchEvent(ui::EventType type,
const gfx::Point& root_location,
int flags)
: TouchEvent(type, root_location, 0, ui::EventTimeForNow()) {
set_flags(flags);
: TouchEvent(type, root_location, flags, 0, ui::EventTimeForNow(),
1.0f, 1.0f, 1.0f, 1.0f) {
}
private:
......
......@@ -462,15 +462,16 @@ void TouchEvent::Relocate(const gfx::Point& origin) {
root_location_ -= origin.OffsetFromOrigin();
}
void TouchEvent::UpdateForRootTransform(const gfx::Transform& root_transform) {
LocatedEvent::UpdateForRootTransform(root_transform);
void TouchEvent::UpdateForRootTransform(
const gfx::Transform& inverted_root_transform) {
LocatedEvent::UpdateForRootTransform(inverted_root_transform);
gfx::DecomposedTransform decomp;
bool success = gfx::DecomposeTransform(&decomp, root_transform);
bool success = gfx::DecomposeTransform(&decomp, inverted_root_transform);
DCHECK(success);
if (decomp.scale[0])
radius_x_ /= decomp.scale[0];
radius_x_ *= decomp.scale[0];
if (decomp.scale[1])
radius_y_ /= decomp.scale[1];
radius_y_ *= decomp.scale[1];
}
////////////////////////////////////////////////////////////////////////////////
......@@ -690,15 +691,16 @@ void ScrollEvent::Scale(const float factor) {
y_offset_ordinal_ *= factor;
}
void ScrollEvent::UpdateForRootTransform(const gfx::Transform& root_transform) {
LocatedEvent::UpdateForRootTransform(root_transform);
void ScrollEvent::UpdateForRootTransform(
const gfx::Transform& inverted_root_transform) {
LocatedEvent::UpdateForRootTransform(inverted_root_transform);
gfx::DecomposedTransform decomp;
bool success = gfx::DecomposeTransform(&decomp, root_transform);
bool success = gfx::DecomposeTransform(&decomp, inverted_root_transform);
DCHECK(success);
if (decomp.scale[0])
x_offset_ordinal_ /= decomp.scale[0];
x_offset_ordinal_ *= decomp.scale[0];
if (decomp.scale[1])
y_offset_ordinal_ /= decomp.scale[1];
y_offset_ordinal_ *= decomp.scale[1];
}
////////////////////////////////////////////////////////////////////////////////
......
......@@ -495,7 +495,7 @@ class UI_EXPORT TouchEvent : public LocatedEvent {
// Overridden from LocatedEvent.
virtual void UpdateForRootTransform(
const gfx::Transform& root_transform) OVERRIDE;
const gfx::Transform& inverted_root_transform) OVERRIDE;
protected:
void set_radius(float radius_x, float radius_y) {
......@@ -661,7 +661,7 @@ class UI_EXPORT ScrollEvent : public MouseEvent {
// Overridden from LocatedEvent.
virtual void UpdateForRootTransform(
const gfx::Transform& root_transform) OVERRIDE;
const gfx::Transform& inverted_root_transform) OVERRIDE;
private:
// Potential accelerated offsets.
......
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