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

Side by Side Diff: views/controls/native_control_gtk.cc

Issue 6990060: Make clicks work on views_examples with touchui. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 7 months 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 | « views/controls/native_control_gtk.h ('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) 2010 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 "views/controls/native_control_gtk.h" 5 #include "views/controls/native_control_gtk.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "ui/base/accessibility/accessibility_types.h" 10 #include "ui/base/accessibility/accessibility_types.h"
11 #include "views/focus/focus_manager.h" 11 #include "views/focus/focus_manager.h"
12 #include "views/widget/widget.h" 12 #include "views/widget/widget.h"
13 13
14 #if defined(TOUCH_UI)
15 namespace {
16
17 GdkEvent* MouseButtonEvent(const views::MouseEvent& mouseev,
18 const views::NativeViewHost* source) {
19 GdkEvent* event = NULL;
20 switch (mouseev.type()) {
21 case ui::ET_MOUSE_PRESSED:
22 event = gdk_event_new(GDK_BUTTON_PRESS);
23 break;
24 case ui::ET_MOUSE_RELEASED:
25 event = gdk_event_new(GDK_BUTTON_RELEASE);
26 break;
27 default:
28 NOTREACHED();
29 return NULL;
30 }
31 event->button.send_event = false;
32 event->button.time = GDK_CURRENT_TIME;
33
34 // Ideally using native_view()->window should work, but it doesn't.
35 event->button.window = gdk_window_at_pointer(NULL, NULL);
36 g_object_ref(event->button.window);
37 event->button.x = mouseev.location().x();
38 event->button.y = mouseev.location().y();
39
40 gfx::Point point = mouseev.location();
41 views::View::ConvertPointToScreen(source, &point);
42 event->button.x_root = point.x();
43 event->button.y_root = point.y();
44
45 event->button.axes = NULL;
46
47 // Ideally, this should reconstruct the state from mouseev.flags().
48 GdkModifierType modifier;
49 gdk_window_get_pointer(event->button.window, NULL, NULL, &modifier);
50 event->button.state = modifier;
51
52 event->button.button = (mouseev.flags() & ui::EF_LEFT_BUTTON_DOWN) ? 1 :
53 (mouseev.flags() & ui::EF_RIGHT_BUTTON_DOWN) ? 3 :
54 2;
55 event->button.device = gdk_device_get_core_pointer();
56 return event;
57 }
58
59 GdkEvent* MouseMoveEvent(const views::MouseEvent& mouseev,
60 const views::NativeViewHost* source) {
61 GdkEvent* event = gdk_event_new(GDK_MOTION_NOTIFY);
62 event->motion.send_event = false;
63 event->motion.time = GDK_CURRENT_TIME;
64
65 event->motion.window = source->native_view()->window;
66 g_object_ref(event->motion.window);
67 event->motion.x = mouseev.location().x();
68 event->motion.y = mouseev.location().y();
69
70 gfx::Point point = mouseev.location();
71 views::View::ConvertPointToScreen(source, &point);
72 event->motion.x_root = point.x();
73 event->motion.y_root = point.y();
74
75 event->motion.device = gdk_device_get_core_pointer();
76 return event;
77 }
78
79 GdkEvent* MouseCrossEvent(const views::MouseEvent& mouseev,
80 const views::NativeViewHost* source) {
81 GdkEvent* event = NULL;
82 switch (mouseev.type()) {
83 case ui::ET_MOUSE_ENTERED:
84 event = gdk_event_new(GDK_ENTER_NOTIFY);
85 break;
86 case ui::ET_MOUSE_EXITED:
87 event = gdk_event_new(GDK_LEAVE_NOTIFY);
88 break;
89 default:
90 NOTREACHED();
91 return NULL;
92 }
93 event->crossing.send_event = false;
94 event->crossing.time = GDK_CURRENT_TIME;
95
96 event->crossing.window = source->native_view()->window;
97 g_object_ref(event->crossing.window);
98
99 event->crossing.x = event->crossing.y = 0;
100 event->crossing.x_root = event->crossing.y_root = 0;
101 event->crossing.mode = GDK_CROSSING_NORMAL;
102 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
103 event->crossing.focus = false;
104 event->crossing.state = 0;
105
106 return event;
107 }
108
109 } // namespace
110 #endif // defined(TOUCH_UI)
111
14 namespace views { 112 namespace views {
15 113
114 #if defined(TOUCH_UI)
115 void NativeControlGtk::FakeNativeMouseEvent(const MouseEvent& mouseev) {
116 GdkEvent* event = NULL;
117 switch (mouseev.type()) {
118 case ui::ET_MOUSE_PRESSED:
119 case ui::ET_MOUSE_RELEASED:
120 event = MouseButtonEvent(mouseev, this);
121 break;
122 case ui::ET_MOUSE_MOVED:
123 event = MouseMoveEvent(mouseev, this);
124 break;
125 case ui::ET_MOUSE_ENTERED:
126 case ui::ET_MOUSE_EXITED:
127 event = MouseCrossEvent(mouseev, this);
128 break;
129 default:
130 NOTREACHED();
131 return;
132 }
133
134 if (event) {
135 // Do not gdk_event_put, since that will end up going through the
136 // message-loop and turn into an infinite loop.
137 gtk_widget_event(native_view(), event);
138 gdk_event_free(event);
139 }
140 }
141 #endif // defined(TOUCH_UI)
142
16 NativeControlGtk::NativeControlGtk() { 143 NativeControlGtk::NativeControlGtk() {
17 } 144 }
18 145
19 NativeControlGtk::~NativeControlGtk() { 146 NativeControlGtk::~NativeControlGtk() {
20 if (native_view()) 147 if (native_view())
21 gtk_widget_destroy(native_view()); 148 gtk_widget_destroy(native_view());
22 } 149 }
23 150
24 //////////////////////////////////////////////////////////////////////////////// 151 ////////////////////////////////////////////////////////////////////////////////
25 // NativeControlGtk, View overrides: 152 // NativeControlGtk, View overrides:
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 } 192 }
66 } 193 }
67 194
68 void NativeControlGtk::OnFocus() { 195 void NativeControlGtk::OnFocus() {
69 DCHECK(native_view()); 196 DCHECK(native_view());
70 gtk_widget_grab_focus(native_view()); 197 gtk_widget_grab_focus(native_view());
71 GetWidget()->NotifyAccessibilityEvent( 198 GetWidget()->NotifyAccessibilityEvent(
72 parent(), ui::AccessibilityTypes::EVENT_FOCUS, true); 199 parent(), ui::AccessibilityTypes::EVENT_FOCUS, true);
73 } 200 }
74 201
202 #if defined(TOUCH_UI)
203 bool NativeControlGtk::OnMousePressed(const MouseEvent& mouseev) {
204 FakeNativeMouseEvent(mouseev);
205 return true;
206 }
207
208 void NativeControlGtk::OnMouseReleased(const MouseEvent& mouseev) {
209 FakeNativeMouseEvent(mouseev);
210 }
211
212 void NativeControlGtk::OnMouseMoved(const MouseEvent& mouseev) {
213 FakeNativeMouseEvent(mouseev);
214 }
215
216 void NativeControlGtk::OnMouseEntered(const MouseEvent& mouseev) {
217 FakeNativeMouseEvent(mouseev);
218 }
219
220 void NativeControlGtk::OnMouseExited(const MouseEvent& mouseev) {
221 FakeNativeMouseEvent(mouseev);
222 }
223 #endif // defined(TOUCH_UI)
224
75 void NativeControlGtk::NativeControlCreated(GtkWidget* native_control) { 225 void NativeControlGtk::NativeControlCreated(GtkWidget* native_control) {
76 Attach(native_control); 226 Attach(native_control);
77 227
78 // Update the newly created GtkWidget with any resident enabled state. 228 // Update the newly created GtkWidget with any resident enabled state.
79 gtk_widget_set_sensitive(native_view(), IsEnabled()); 229 gtk_widget_set_sensitive(native_view(), IsEnabled());
80 230
81 // Listen for focus change event to update the FocusManager focused view. 231 // Listen for focus change event to update the FocusManager focused view.
82 g_signal_connect(native_control, "focus-in-event", 232 g_signal_connect(native_control, "focus-in-event",
83 G_CALLBACK(CallFocusIn), this); 233 G_CALLBACK(CallFocusIn), this);
84 } 234 }
85 235
86 // static 236 // static
87 gboolean NativeControlGtk::CallFocusIn(GtkWidget* widget, 237 gboolean NativeControlGtk::CallFocusIn(GtkWidget* widget,
88 GdkEventFocus* event, 238 GdkEventFocus* event,
89 NativeControlGtk* control) { 239 NativeControlGtk* control) {
90 FocusManager* focus_manager = 240 FocusManager* focus_manager =
91 FocusManager::GetFocusManagerForNativeView(widget); 241 FocusManager::GetFocusManagerForNativeView(widget);
92 if (!focus_manager) { 242 if (!focus_manager) {
93 // TODO(jcampan): http://crbug.com/21378 Reenable this NOTREACHED() when the 243 // TODO(jcampan): http://crbug.com/21378 Reenable this NOTREACHED() when the
94 // options page is only based on views. 244 // options page is only based on views.
95 // NOTREACHED(); 245 // NOTREACHED();
96 NOTIMPLEMENTED(); 246 NOTIMPLEMENTED();
97 return false; 247 return false;
98 } 248 }
99 focus_manager->SetFocusedView(control->focus_view()); 249 focus_manager->SetFocusedView(control->focus_view());
100 return false; 250 return false;
101 } 251 }
102 252
103 } // namespace views 253 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/native_control_gtk.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698