Commit d9a4c376 authored by oshima@chromium.org's avatar oshima@chromium.org

Do not set the last mouse location from synthesized event.

 The last mouse location should be the updated only by real event because it should point to the real mouse point and synthesized enter/leave may not contain the valid point.

minor: remove unnecessary cast.

BUG=None
TEST=TBD.

Review URL: https://codereview.chromium.org/143303006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251291 0039d316-1c4b-4281-b951-d872f2087c98
parent 4204077d
......@@ -398,6 +398,11 @@ void RootWindow::MoveCursorToInternal(const gfx::Point& root_location,
ui::EventDispatchDetails RootWindow::DispatchMouseEnterOrExit(
const ui::MouseEvent& event,
ui::EventType type) {
if (event.type() != ui::ET_MOUSE_CAPTURE_CHANGED &&
!(event.flags() & ui::EF_IS_SYNTHESIZED)) {
SetLastMouseLocation(window(), event.root_location());
}
if (!mouse_moved_handler_ || !mouse_moved_handler_->delegate())
return DispatchDetails();
......@@ -793,7 +798,6 @@ ui::EventDispatchDetails RootWindow::SynthesizeMouseMoveEvent() {
return details;
gfx::Point host_mouse_location = root_mouse_location;
host()->ConvertPointToHost(&host_mouse_location);
ui::MouseEvent event(ui::ET_MOUSE_MOVED,
host_mouse_location,
host_mouse_location,
......@@ -810,10 +814,10 @@ void RootWindow::PreDispatchLocatedEvent(Window* target,
event->set_flags(flags);
if (!dispatching_held_event_ &&
(event->IsMouseEvent() || event->IsScrollEvent())) {
(event->IsMouseEvent() || event->IsScrollEvent()) &&
!(event->flags() & ui::EF_IS_SYNTHESIZED)) {
if (event->type() != ui::ET_MOUSE_CAPTURE_CHANGED)
SetLastMouseLocation(window(), event->root_location());
if (!(event->flags() & ui::EF_IS_SYNTHESIZED))
synthesize_mouse_move_ = false;
}
}
......
......@@ -1731,4 +1731,54 @@ TEST_F(RootWindowTestInHighDPI, TouchMovesHeldOnScroll) {
filter->touch_locations()[1].ToString());
}
class SelfDestructDelegate : public test::TestWindowDelegate {
public:
SelfDestructDelegate() {}
virtual ~SelfDestructDelegate() {}
virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
window_.reset();
}
void set_window(scoped_ptr<aura::Window> window) {
window_ = window.Pass();
}
bool has_window() const { return !!window_.get(); }
private:
scoped_ptr<aura::Window> window_;
DISALLOW_COPY_AND_ASSIGN(SelfDestructDelegate);
};
TEST_F(RootWindowTest, SynthesizedLocatedEvent) {
test::EventGenerator generator(root_window());
generator.MoveMouseTo(10, 10);
EXPECT_EQ("10,10",
Env::GetInstance()->last_mouse_location().ToString());
// Synthesized event should not update the mouse location.
ui::MouseEvent mouseev(ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(),
ui::EF_IS_SYNTHESIZED, 0);
generator.Dispatch(&mouseev);
EXPECT_EQ("10,10",
Env::GetInstance()->last_mouse_location().ToString());
generator.MoveMouseTo(0, 0);
EXPECT_EQ("0,0",
Env::GetInstance()->last_mouse_location().ToString());
// Make sure the location gets updated when a syntheiszed enter
// event destroyed the window.
SelfDestructDelegate delegate;
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
&delegate, 1, gfx::Rect(50, 50, 100, 100), root_window()));
delegate.set_window(window.Pass());
EXPECT_TRUE(delegate.has_window());
generator.MoveMouseTo(100, 100);
EXPECT_FALSE(delegate.has_window());
EXPECT_EQ("100,100",
Env::GetInstance()->last_mouse_location().ToString());
}
} // namespace aura
......@@ -608,7 +608,7 @@ void EventGenerator::DoDispatchEvent(ui::Event* event, bool async) {
pending_events_.push_back(pending_event);
} else {
ui::EventDispatchDetails details = current_root_window_->OnEventFromSource(
static_cast<ui::KeyEvent*>(event));
event);
CHECK(!details.dispatcher_destroyed);
}
}
......
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