Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Unified Diff: ui/aura/event.cc

Issue 8763020: aura: Detect double clicks and set ui::EF_IS_DOUBLE_CLICK appropriately. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/renderer_host/web_input_event_aurax11.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/aura/event.cc
diff --git a/ui/aura/event.cc b/ui/aura/event.cc
index 91e15bafa91a1f3f4ef68b706bb28477384a5708..670bb8a7810f4927802e2fab5d3da50d5762cb5f 100644
--- a/ui/aura/event.cc
+++ b/ui/aura/event.cc
@@ -17,6 +17,41 @@
#include "ui/base/keycodes/keyboard_code_conversion_x.h"
#endif
+#if !defined(OS_WIN)
+namespace {
+
+// On non-windows systems, double-click events aren't reported by the system.
+// So aura has to detect double-clicks itself.
+double g_last_click_time = 0.0;
+int g_last_click_x = 0;
+int g_last_click_y = 0;
+int g_flags = 0;
+
+void RememberClickForDoubleClickDetection(const aura::MouseEvent& event) {
+ g_last_click_time = event.time_stamp().ToDoubleT();
+ g_last_click_x = event.location().x();
+ g_last_click_y = event.location().y();
+ g_flags = event.flags();
+}
+
+bool IsDoubleClick(const aura::MouseEvent& event) {
+ // The flags must be the same
+ if ((g_flags & event.flags()) != g_flags)
+ return false;
+
+ const int double_click_distance = 5;
+ const double double_click_time = 0.250; // in seconds
+ return std::abs(event.location().x() - g_last_click_x) <=
+ double_click_distance &&
+ std::abs(event.location().y() - g_last_click_y) <=
+ double_click_distance &&
+ event.time_stamp().ToDoubleT() - g_last_click_time <=
+ double_click_time;
+}
+
+} // namespace
+#endif // !defined(OS_WIN)
+
namespace aura {
Event::Event(ui::EventType type, int flags)
@@ -81,6 +116,14 @@ void LocatedEvent::UpdateForTransform(const ui::Transform& transform) {
MouseEvent::MouseEvent(const base::NativeEvent& native_event)
: LocatedEvent(native_event) {
+#if !defined(OS_WIN)
+ if (type() == ui::ET_MOUSE_PRESSED) {
+ if (IsDoubleClick(*this))
+ set_flags(flags() | ui::EF_IS_DOUBLE_CLICK);
+ else
+ RememberClickForDoubleClickDetection(*this);
+ }
+#endif
}
MouseEvent::MouseEvent(const MouseEvent& model, Window* source, Window* target)
« no previous file with comments | « content/browser/renderer_host/web_input_event_aurax11.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698