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

Side by Side 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 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/renderer_host/web_input_event_aurax11.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/aura/event.h" 5 #include "ui/aura/event.h"
6 6
7 #if defined(USE_X11) 7 #if defined(USE_X11)
8 #include <X11/Xlib.h> 8 #include <X11/Xlib.h>
9 #endif 9 #endif
10 10
11 #include "ui/aura/window.h" 11 #include "ui/aura/window.h"
12 #include "ui/base/keycodes/keyboard_code_conversion.h" 12 #include "ui/base/keycodes/keyboard_code_conversion.h"
13 #include "ui/gfx/point3.h" 13 #include "ui/gfx/point3.h"
14 #include "ui/gfx/transform.h" 14 #include "ui/gfx/transform.h"
15 15
16 #if defined(USE_X11) 16 #if defined(USE_X11)
17 #include "ui/base/keycodes/keyboard_code_conversion_x.h" 17 #include "ui/base/keycodes/keyboard_code_conversion_x.h"
18 #endif 18 #endif
19 19
20 #if !defined(OS_WIN)
21 namespace {
22
23 // On non-windows systems, double-click events aren't reported by the system.
24 // So aura has to detect double-clicks itself.
25 double g_last_click_time = 0.0;
26 int g_last_click_x = 0;
27 int g_last_click_y = 0;
28 int g_flags = 0;
29
30 void RememberClickForDoubleClickDetection(const aura::MouseEvent& event) {
31 g_last_click_time = event.time_stamp().ToDoubleT();
32 g_last_click_x = event.location().x();
33 g_last_click_y = event.location().y();
34 g_flags = event.flags();
35 }
36
37 bool IsDoubleClick(const aura::MouseEvent& event) {
38 // The flags must be the same
39 if ((g_flags & event.flags()) != g_flags)
40 return false;
41
42 const int double_click_distance = 5;
43 const double double_click_time = 0.250; // in seconds
44 return std::abs(event.location().x() - g_last_click_x) <=
45 double_click_distance &&
46 std::abs(event.location().y() - g_last_click_y) <=
47 double_click_distance &&
48 event.time_stamp().ToDoubleT() - g_last_click_time <=
49 double_click_time;
50 }
51
52 } // namespace
53 #endif // !defined(OS_WIN)
54
20 namespace aura { 55 namespace aura {
21 56
22 Event::Event(ui::EventType type, int flags) 57 Event::Event(ui::EventType type, int flags)
23 : type_(type), 58 : type_(type),
24 time_stamp_(base::Time::NowFromSystemTime()), 59 time_stamp_(base::Time::NowFromSystemTime()),
25 flags_(flags) { 60 flags_(flags) {
26 Init(); 61 Init();
27 } 62 }
28 63
29 Event::Event(const base::NativeEvent& native_event, 64 Event::Event(const base::NativeEvent& native_event,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 } 109 }
75 110
76 void LocatedEvent::UpdateForTransform(const ui::Transform& transform) { 111 void LocatedEvent::UpdateForTransform(const ui::Transform& transform) {
77 gfx::Point3f p(location_); 112 gfx::Point3f p(location_);
78 transform.TransformPointReverse(p); 113 transform.TransformPointReverse(p);
79 location_ = p.AsPoint(); 114 location_ = p.AsPoint();
80 } 115 }
81 116
82 MouseEvent::MouseEvent(const base::NativeEvent& native_event) 117 MouseEvent::MouseEvent(const base::NativeEvent& native_event)
83 : LocatedEvent(native_event) { 118 : LocatedEvent(native_event) {
119 #if !defined(OS_WIN)
120 if (type() == ui::ET_MOUSE_PRESSED) {
121 if (IsDoubleClick(*this))
122 set_flags(flags() | ui::EF_IS_DOUBLE_CLICK);
123 else
124 RememberClickForDoubleClickDetection(*this);
125 }
126 #endif
84 } 127 }
85 128
86 MouseEvent::MouseEvent(const MouseEvent& model, Window* source, Window* target) 129 MouseEvent::MouseEvent(const MouseEvent& model, Window* source, Window* target)
87 : LocatedEvent(model, source, target) { 130 : LocatedEvent(model, source, target) {
88 } 131 }
89 132
90 MouseEvent::MouseEvent(const MouseEvent& model, 133 MouseEvent::MouseEvent(const MouseEvent& model,
91 Window* source, 134 Window* source,
92 Window* target, 135 Window* target,
93 ui::EventType type, 136 ui::EventType type,
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 uint16 ch = ui::DefaultSymbolFromXEvent(native_event()); 245 uint16 ch = ui::DefaultSymbolFromXEvent(native_event());
203 return ch ? ch : 246 return ch ? ch :
204 ui::GetCharacterFromKeyCode(key_code_, flags() & ui::EF_SHIFT_DOWN); 247 ui::GetCharacterFromKeyCode(key_code_, flags() & ui::EF_SHIFT_DOWN);
205 #else 248 #else
206 NOTIMPLEMENTED(); 249 NOTIMPLEMENTED();
207 return 0; 250 return 0;
208 #endif 251 #endif
209 } 252 }
210 253
211 } // namespace aura 254 } // namespace aura
OLDNEW
« 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