| Index: views/controls/native_control_gtk.cc
|
| diff --git a/views/controls/native_control_gtk.cc b/views/controls/native_control_gtk.cc
|
| index 88035c1c510ae9a5661013dc951944add885d8c6..5a2bed16f014dd5f9d86c102b98aa98551672853 100644
|
| --- a/views/controls/native_control_gtk.cc
|
| +++ b/views/controls/native_control_gtk.cc
|
| @@ -1,4 +1,4 @@
|
| -// Copyright (c) 2010 The Chromium Authors. All rights reserved.
|
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| @@ -11,8 +11,135 @@
|
| #include "views/focus/focus_manager.h"
|
| #include "views/widget/widget.h"
|
|
|
| +#if defined(TOUCH_UI)
|
| +namespace {
|
| +
|
| +GdkEvent* MouseButtonEvent(const views::MouseEvent& mouseev,
|
| + const views::NativeViewHost* source) {
|
| + GdkEvent* event = NULL;
|
| + switch (mouseev.type()) {
|
| + case ui::ET_MOUSE_PRESSED:
|
| + event = gdk_event_new(GDK_BUTTON_PRESS);
|
| + break;
|
| + case ui::ET_MOUSE_RELEASED:
|
| + event = gdk_event_new(GDK_BUTTON_RELEASE);
|
| + break;
|
| + default:
|
| + NOTREACHED();
|
| + return NULL;
|
| + }
|
| + event->button.send_event = false;
|
| + event->button.time = GDK_CURRENT_TIME;
|
| +
|
| + // Ideally using native_view()->window should work, but it doesn't.
|
| + event->button.window = gdk_window_at_pointer(NULL, NULL);
|
| + g_object_ref(event->button.window);
|
| + event->button.x = mouseev.location().x();
|
| + event->button.y = mouseev.location().y();
|
| +
|
| + gfx::Point point = mouseev.location();
|
| + views::View::ConvertPointToScreen(source, &point);
|
| + event->button.x_root = point.x();
|
| + event->button.y_root = point.y();
|
| +
|
| + event->button.axes = NULL;
|
| +
|
| + // Ideally, this should reconstruct the state from mouseev.flags().
|
| + GdkModifierType modifier;
|
| + gdk_window_get_pointer(event->button.window, NULL, NULL, &modifier);
|
| + event->button.state = modifier;
|
| +
|
| + event->button.button = (mouseev.flags() & ui::EF_LEFT_BUTTON_DOWN) ? 1 :
|
| + (mouseev.flags() & ui::EF_RIGHT_BUTTON_DOWN) ? 3 :
|
| + 2;
|
| + event->button.device = gdk_device_get_core_pointer();
|
| + return event;
|
| +}
|
| +
|
| +GdkEvent* MouseMoveEvent(const views::MouseEvent& mouseev,
|
| + const views::NativeViewHost* source) {
|
| + GdkEvent* event = gdk_event_new(GDK_MOTION_NOTIFY);
|
| + event->motion.send_event = false;
|
| + event->motion.time = GDK_CURRENT_TIME;
|
| +
|
| + event->motion.window = source->native_view()->window;
|
| + g_object_ref(event->motion.window);
|
| + event->motion.x = mouseev.location().x();
|
| + event->motion.y = mouseev.location().y();
|
| +
|
| + gfx::Point point = mouseev.location();
|
| + views::View::ConvertPointToScreen(source, &point);
|
| + event->motion.x_root = point.x();
|
| + event->motion.y_root = point.y();
|
| +
|
| + event->motion.device = gdk_device_get_core_pointer();
|
| + return event;
|
| +}
|
| +
|
| +GdkEvent* MouseCrossEvent(const views::MouseEvent& mouseev,
|
| + const views::NativeViewHost* source) {
|
| + GdkEvent* event = NULL;
|
| + switch (mouseev.type()) {
|
| + case ui::ET_MOUSE_ENTERED:
|
| + event = gdk_event_new(GDK_ENTER_NOTIFY);
|
| + break;
|
| + case ui::ET_MOUSE_EXITED:
|
| + event = gdk_event_new(GDK_LEAVE_NOTIFY);
|
| + break;
|
| + default:
|
| + NOTREACHED();
|
| + return NULL;
|
| + }
|
| + event->crossing.send_event = false;
|
| + event->crossing.time = GDK_CURRENT_TIME;
|
| +
|
| + event->crossing.window = source->native_view()->window;
|
| + g_object_ref(event->crossing.window);
|
| +
|
| + event->crossing.x = event->crossing.y = 0;
|
| + event->crossing.x_root = event->crossing.y_root = 0;
|
| + event->crossing.mode = GDK_CROSSING_NORMAL;
|
| + event->crossing.detail = GDK_NOTIFY_VIRTUAL;
|
| + event->crossing.focus = false;
|
| + event->crossing.state = 0;
|
| +
|
| + return event;
|
| +}
|
| +
|
| +} // namespace
|
| +#endif // defined(TOUCH_UI)
|
| +
|
| namespace views {
|
|
|
| +#if defined(TOUCH_UI)
|
| +void NativeControlGtk::FakeNativeMouseEvent(const MouseEvent& mouseev) {
|
| + GdkEvent* event = NULL;
|
| + switch (mouseev.type()) {
|
| + case ui::ET_MOUSE_PRESSED:
|
| + case ui::ET_MOUSE_RELEASED:
|
| + event = MouseButtonEvent(mouseev, this);
|
| + break;
|
| + case ui::ET_MOUSE_MOVED:
|
| + event = MouseMoveEvent(mouseev, this);
|
| + break;
|
| + case ui::ET_MOUSE_ENTERED:
|
| + case ui::ET_MOUSE_EXITED:
|
| + event = MouseCrossEvent(mouseev, this);
|
| + break;
|
| + default:
|
| + NOTREACHED();
|
| + return;
|
| + }
|
| +
|
| + if (event) {
|
| + // Do not gdk_event_put, since that will end up going through the
|
| + // message-loop and turn into an infinite loop.
|
| + gtk_widget_event(native_view(), event);
|
| + gdk_event_free(event);
|
| + }
|
| +}
|
| +#endif // defined(TOUCH_UI)
|
| +
|
| NativeControlGtk::NativeControlGtk() {
|
| }
|
|
|
| @@ -72,6 +199,29 @@ void NativeControlGtk::OnFocus() {
|
| parent(), ui::AccessibilityTypes::EVENT_FOCUS, true);
|
| }
|
|
|
| +#if defined(TOUCH_UI)
|
| +bool NativeControlGtk::OnMousePressed(const MouseEvent& mouseev) {
|
| + FakeNativeMouseEvent(mouseev);
|
| + return true;
|
| +}
|
| +
|
| +void NativeControlGtk::OnMouseReleased(const MouseEvent& mouseev) {
|
| + FakeNativeMouseEvent(mouseev);
|
| +}
|
| +
|
| +void NativeControlGtk::OnMouseMoved(const MouseEvent& mouseev) {
|
| + FakeNativeMouseEvent(mouseev);
|
| +}
|
| +
|
| +void NativeControlGtk::OnMouseEntered(const MouseEvent& mouseev) {
|
| + FakeNativeMouseEvent(mouseev);
|
| +}
|
| +
|
| +void NativeControlGtk::OnMouseExited(const MouseEvent& mouseev) {
|
| + FakeNativeMouseEvent(mouseev);
|
| +}
|
| +#endif // defined(TOUCH_UI)
|
| +
|
| void NativeControlGtk::NativeControlCreated(GtkWidget* native_control) {
|
| Attach(native_control);
|
|
|
|
|