#include "ui/aura/window_event_dispatcher.h"
#include "ui/events/event.h"
#include "ui/events/event_utils.h"
+#include "ui/wm/core/default_activation_client.h"
#include "ui/wm/public/activation_client.h"
namespace {
-#if defined(OS_CHROMEOS)
+#if defined(OS_CHROMEOS) || defined(OS_WIN)
base::TimeDelta GetTime() {
return ui::EventTimeForNow();
}
-#endif // defined(OS_CHROMEOS)
+#endif // defined(OS_CHROMEOS) || defined(OS_WIN)
}
DispatchEventUsingWindowDispatcher(&move);
EXPECT_FALSE(cursor_client.IsCursorVisible());
+ // A real mouse event should show the cursor.
ui::MouseEvent real_move(ui::ET_MOUSE_MOVED, gfx::Point(10, 10),
gfx::Point(10, 10), 0, 0);
DispatchEventUsingWindowDispatcher(&real_move);
EXPECT_TRUE(cursor_client.IsCursorVisible());
- // Send key event to hide the cursor again.
+ // Disallow hiding the cursor on keypress.
+ cursor_client.set_should_hide_cursor_on_key_event(false);
+ key = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_A, 0, true);
+ DispatchEventUsingWindowDispatcher(&key);
+ EXPECT_TRUE(cursor_client.IsCursorVisible());
+
+ // Allow hiding the cursor on keypress.
+ cursor_client.set_should_hide_cursor_on_key_event(true);
+ key = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_A, 0, true);
DispatchEventUsingWindowDispatcher(&key);
EXPECT_FALSE(cursor_client.IsCursorVisible());
exit.set_flags(enter.flags() | ui::EF_IS_SYNTHESIZED);
DispatchEventUsingWindowDispatcher(&exit);
EXPECT_FALSE(cursor_client.IsCursorVisible());
+
aura::Env::GetInstance()->RemovePreTargetHandler(compound_filter.get());
}
+#endif // defined(OS_CHROMEOS)
-// Touch visually hides the cursor on ChromeOS and Windows, but we only update
-// our internal tracking of the cursor state on ChromeOS (crbug.com/333952).
+#if defined(OS_CHROMEOS) || defined(OS_WIN)
+// Touch visually hides the cursor on ChromeOS and Windows.
TEST_F(CompoundEventFilterTest, TouchHidesCursor) {
+ new wm::DefaultActivationClient(root_window());
scoped_ptr<CompoundEventFilter> compound_filter(new CompoundEventFilter);
aura::Env::GetInstance()->AddPreTargetHandler(compound_filter.get());
aura::test::TestWindowDelegate delegate;
EXPECT_FALSE(cursor_client.IsMouseEventsEnabled());
aura::Env::GetInstance()->RemovePreTargetHandler(compound_filter.get());
}
-#endif // defined(OS_CHROMEOS)
+#endif // defined(OS_CHROMEOS) || defined(OS_WIN)
// Tests that if an event filter consumes a gesture, then it doesn't focus the
// window.
aura::Env::GetInstance()->RemovePreTargetHandler(compound_filter.get());
}
+#if defined(OS_WIN)
+// Windows synthesizes mouse messages for touch events. We should not be
+// showing the cursor when we receive such messages.
+TEST_F(CompoundEventFilterTest, DontShowCursorOnMouseMovesFromTouch) {
+ scoped_ptr<CompoundEventFilter> compound_filter(new CompoundEventFilter);
+ aura::Env::GetInstance()->AddPreTargetHandler(compound_filter.get());
+ aura::test::TestWindowDelegate delegate;
+ scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(&delegate, 1234,
+ gfx::Rect(5, 5, 100, 100), root_window()));
+ window->Show();
+ window->SetCapture();
+
+ aura::test::TestCursorClient cursor_client(root_window());
+ cursor_client.DisableMouseEvents();
+ EXPECT_FALSE(cursor_client.IsMouseEventsEnabled());
+
+ ui::MouseEvent mouse0(ui::ET_MOUSE_MOVED, gfx::Point(10, 10),
+ gfx::Point(10, 10), 0, 0);
+ mouse0.set_flags(mouse0.flags() | ui::EF_FROM_TOUCH);
+
+ DispatchEventUsingWindowDispatcher(&mouse0);
+ EXPECT_FALSE(cursor_client.IsMouseEventsEnabled());
+
+ mouse0.set_flags(mouse0.flags() & ~ui::EF_FROM_TOUCH);
+ DispatchEventUsingWindowDispatcher(&mouse0);
+ EXPECT_TRUE(cursor_client.IsMouseEventsEnabled());
+
+ aura::Env::GetInstance()->RemovePreTargetHandler(compound_filter.get());
+}
+#endif
+
} // namespace wm