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

Side by Side Diff: Tools/TestWebKitAPI/gtk/PlatformWebViewGtk.cpp

Issue 13602008: Remove non-chromium code from TestWebKitAPI (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 8 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 | « Tools/TestWebKitAPI/gtk/PlatformUtilitiesGtk.cpp ('k') | Tools/TestWebKitAPI/gtk/main.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2012 Igalia S.L.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #include "config.h"
27 #include "PlatformWebView.h"
28
29 #include <WebCore/GOwnPtrGtk.h>
30 #include <gtk/gtk.h>
31 #include <wtf/gobject/GOwnPtr.h>
32
33 namespace TestWebKitAPI {
34
35 PlatformWebView::PlatformWebView(WKContextRef contextRef, WKPageGroupRef pageGro upRef)
36 {
37 m_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
38 m_view = WKViewCreate(contextRef, pageGroupRef);
39 gtk_container_add(GTK_CONTAINER(m_window), GTK_WIDGET(m_view));
40 gtk_widget_show(GTK_WIDGET(m_view));
41 gtk_widget_show(m_window);
42 }
43
44 PlatformWebView::~PlatformWebView()
45 {
46 gtk_widget_destroy(m_window);
47 }
48
49 WKPageRef PlatformWebView::page() const
50 {
51 return WKViewGetPage(m_view);
52 }
53
54 void PlatformWebView::resizeTo(unsigned width, unsigned height)
55 {
56 gtk_window_resize(GTK_WINDOW(m_window), width, height);
57 }
58
59 static void doKeyStroke(GtkWidget* viewWidget, unsigned int keyVal)
60 {
61 GOwnPtr<GdkEvent> event(gdk_event_new(GDK_KEY_PRESS));
62 event->key.keyval = keyVal;
63 event->key.time = GDK_CURRENT_TIME;
64 event->key.state = 0;
65 event->key.window = gtk_widget_get_window(viewWidget);
66 g_object_ref(event->key.window);
67 gdk_event_set_device(event.get(), gdk_device_manager_get_client_pointer(gdk_ display_get_device_manager(gtk_widget_get_display(viewWidget))));
68
69 // When synthesizing an event, an invalid hardware_keycode value can cause i t to be badly processed by GTK+.
70 GOwnPtr<GdkKeymapKey> keys;
71 int keysCount;
72 if (gdk_keymap_get_entries_for_keyval(gdk_keymap_get_default(), keyVal, &key s.outPtr(), &keysCount))
73 event->key.hardware_keycode = keys.get()[0].keycode;
74
75 gtk_main_do_event(event.get());
76 event->key.type = GDK_KEY_RELEASE;
77 gtk_main_do_event(event.get());
78 }
79
80 void PlatformWebView::simulateSpacebarKeyPress()
81 {
82 GtkWidget* viewWidget = GTK_WIDGET(m_view);
83 if (!gtk_widget_get_realized(viewWidget))
84 gtk_widget_show(m_window);
85 doKeyStroke(viewWidget, GDK_KEY_KP_Space);
86 }
87
88 void PlatformWebView::simulateAltKeyPress()
89 {
90 GtkWidget* viewWidget = GTK_WIDGET(m_view);
91 if (!gtk_widget_get_realized(viewWidget))
92 gtk_widget_show(m_window);
93 doKeyStroke(viewWidget, GDK_KEY_Alt_L);
94 }
95
96 static void doMouseButtonEvent(GtkWidget* viewWidget, GdkEventType eventType, in t x, int y, unsigned int button)
97 {
98 GOwnPtr<GdkEvent> event(gdk_event_new(eventType));
99 event->button.x = x;
100 event->button.y = y;
101 event->button.button = button;
102 event->button.time = GDK_CURRENT_TIME;
103 event->button.axes = 0;
104 event->button.state = 0;
105 event->button.window = gtk_widget_get_window(viewWidget);
106 g_object_ref(event->button.window);
107 event->button.device = gdk_device_manager_get_client_pointer(gdk_display_get _device_manager(gtk_widget_get_display(viewWidget)));
108
109 int xRoot, yRoot;
110 gdk_window_get_root_coords(gtk_widget_get_window(viewWidget), x, y, &xRoot, &yRoot);
111 event->button.x_root = xRoot;
112 event->button.y_root = yRoot;
113 gtk_main_do_event(event.get());
114 }
115
116 void PlatformWebView::simulateRightClick(unsigned x, unsigned y)
117 {
118 GtkWidget* viewWidget = GTK_WIDGET(m_view);
119 if (!gtk_widget_get_realized(viewWidget))
120 gtk_widget_show(m_window);
121 doMouseButtonEvent(viewWidget, GDK_BUTTON_PRESS, x, y, 3);
122 doMouseButtonEvent(viewWidget, GDK_BUTTON_RELEASE, x, y, 3);
123 }
124
125 void PlatformWebView::simulateMouseMove(unsigned x, unsigned y)
126 {
127 GOwnPtr<GdkEvent> event(gdk_event_new(GDK_MOTION_NOTIFY));
128 event->motion.x = x;
129 event->motion.y = y;
130 event->motion.time = GDK_CURRENT_TIME;
131 event->motion.state = 0;
132 event->motion.axes = 0;
133
134 GtkWidget* viewWidget = GTK_WIDGET(m_view);
135 if (!gtk_widget_get_realized(viewWidget))
136 gtk_widget_show(m_window);
137 event->motion.window = gtk_widget_get_window(viewWidget);
138 g_object_ref(event->motion.window);
139 event->motion.device = gdk_device_manager_get_client_pointer(gdk_display_get _device_manager(gtk_widget_get_display(viewWidget)));
140
141 int xRoot, yRoot;
142 gdk_window_get_root_coords(gtk_widget_get_window(viewWidget), x, y, &xRoot, &yRoot);
143 event->motion.x_root = xRoot;
144 event->motion.y_root = yRoot;
145 gtk_main_do_event(event.get());
146 }
147
148 } // namespace TestWebKitAPI
OLDNEW
« no previous file with comments | « Tools/TestWebKitAPI/gtk/PlatformUtilitiesGtk.cpp ('k') | Tools/TestWebKitAPI/gtk/main.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698