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

Side by Side Diff: webkit/tools/test_shell/test_webview_delegate_gtk.cc

Issue 149620: Use WebWidget from the WebKit API. This change also makes... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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
OLDNEW
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2008 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 // This file was forked off the Mac port. 5 // This file was forked off the Mac port.
6 6
7 #include "webkit/tools/test_shell/test_webview_delegate.h" 7 #include "webkit/tools/test_shell/test_webview_delegate.h"
8 8
9 #include <gtk/gtk.h> 9 #include <gtk/gtk.h>
10 #include <gdk/gdkx.h> 10 #include <gdk/gdkx.h>
(...skipping 14 matching lines...) Expand all
25 #include "webkit/glue/webkit_glue.h" 25 #include "webkit/glue/webkit_glue.h"
26 #include "webkit/glue/webview.h" 26 #include "webkit/glue/webview.h"
27 #include "webkit/glue/plugins/gtk_plugin_container_manager.h" 27 #include "webkit/glue/plugins/gtk_plugin_container_manager.h"
28 #include "webkit/glue/plugins/plugin_list.h" 28 #include "webkit/glue/plugins/plugin_list.h"
29 #include "webkit/glue/window_open_disposition.h" 29 #include "webkit/glue/window_open_disposition.h"
30 #include "webkit/glue/plugins/webplugin_delegate_impl.h" 30 #include "webkit/glue/plugins/webplugin_delegate_impl.h"
31 #include "webkit/tools/test_shell/test_navigation_controller.h" 31 #include "webkit/tools/test_shell/test_navigation_controller.h"
32 #include "webkit/tools/test_shell/test_shell.h" 32 #include "webkit/tools/test_shell/test_shell.h"
33 33
34 using WebKit::WebCursorInfo; 34 using WebKit::WebCursorInfo;
35 using WebKit::WebNavigationPolicy;
35 using WebKit::WebRect; 36 using WebKit::WebRect;
36 37
37 namespace { 38 namespace {
38 39
39 enum SelectionClipboardType { 40 enum SelectionClipboardType {
40 TEXT_HTML, 41 TEXT_HTML,
41 PLAIN_TEXT, 42 PLAIN_TEXT,
42 }; 43 };
43 44
44 GdkAtom GetTextHtmlAtom() { 45 GdkAtom GetTextHtmlAtom() {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 113
113 void TestWebViewDelegate::ShowJavaScriptAlert(const std::wstring& message) { 114 void TestWebViewDelegate::ShowJavaScriptAlert(const std::wstring& message) {
114 GtkWidget* dialog = gtk_message_dialog_new( 115 GtkWidget* dialog = gtk_message_dialog_new(
115 shell_->mainWnd(), GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, 116 shell_->mainWnd(), GTK_DIALOG_MODAL, GTK_MESSAGE_INFO,
116 GTK_BUTTONS_OK, "%s", WideToUTF8(message).c_str()); 117 GTK_BUTTONS_OK, "%s", WideToUTF8(message).c_str());
117 gtk_window_set_title(GTK_WINDOW(dialog), "JavaScript Alert"); 118 gtk_window_set_title(GTK_WINDOW(dialog), "JavaScript Alert");
118 gtk_dialog_run(GTK_DIALOG(dialog)); // Runs a nested message loop. 119 gtk_dialog_run(GTK_DIALOG(dialog)); // Runs a nested message loop.
119 gtk_widget_destroy(dialog); 120 gtk_widget_destroy(dialog);
120 } 121 }
121 122
122 void TestWebViewDelegate::Show(WebWidget* webwidget, 123 void TestWebViewDelegate::show(WebNavigationPolicy policy) {
123 WindowOpenDisposition disposition) { 124 WebWidgetHost* host = GetWidgetHost();
124 WebWidgetHost* host = GetHostForWidget(webwidget);
125 GtkWidget* drawing_area = host->view_handle(); 125 GtkWidget* drawing_area = host->view_handle();
126 GtkWidget* window = 126 GtkWidget* window =
127 gtk_widget_get_parent(gtk_widget_get_parent(drawing_area)); 127 gtk_widget_get_parent(gtk_widget_get_parent(drawing_area));
128 gtk_widget_show_all(window); 128 gtk_widget_show_all(window);
129 } 129 }
130 130
131 void TestWebViewDelegate::CloseWidgetSoon(WebWidget* webwidget) { 131 void TestWebViewDelegate::closeWidgetSoon() {
132 if (webwidget == shell_->webView()) { 132 if (this == shell_->delegate()) {
133 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableFunction( 133 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableFunction(
134 &gtk_widget_destroy, GTK_WIDGET(shell_->mainWnd()))); 134 &gtk_widget_destroy, GTK_WIDGET(shell_->mainWnd())));
135 } else if (webwidget == shell_->popup()) { 135 } else if (this == shell_->popup_delegate()) {
136 shell_->ClosePopup(); 136 shell_->ClosePopup();
137 } 137 }
138 } 138 }
139 139
140 void TestWebViewDelegate::SetCursor(WebWidget* webwidget, 140 void TestWebViewDelegate::didChangeCursor(const WebCursorInfo& cursor_info) {
141 const WebCursorInfo& cursor_info) {
142 current_cursor_.InitFromCursorInfo(cursor_info); 141 current_cursor_.InitFromCursorInfo(cursor_info);
143 GdkCursorType cursor_type = current_cursor_.GetCursorType(); 142 GdkCursorType cursor_type = current_cursor_.GetCursorType();
144 GdkCursor* gdk_cursor; 143 GdkCursor* gdk_cursor;
145 if (cursor_type == GDK_CURSOR_IS_PIXMAP) { 144 if (cursor_type == GDK_CURSOR_IS_PIXMAP) {
146 // TODO(port): WebKit bug https://bugs.webkit.org/show_bug.cgi?id=16388 is 145 // TODO(port): WebKit bug https://bugs.webkit.org/show_bug.cgi?id=16388 is
147 // that calling gdk_window_set_cursor repeatedly is expensive. We should 146 // that calling gdk_window_set_cursor repeatedly is expensive. We should
148 // avoid it here where possible. 147 // avoid it here where possible.
149 gdk_cursor = current_cursor_.GetCustomCursor(); 148 gdk_cursor = current_cursor_.GetCustomCursor();
150 } else { 149 } else {
151 // Optimize the common case, where the cursor hasn't changed. 150 // Optimize the common case, where the cursor hasn't changed.
152 // However, we can switch between different pixmaps, so only on the 151 // However, we can switch between different pixmaps, so only on the
153 // non-pixmap branch. 152 // non-pixmap branch.
154 if (cursor_type_ == cursor_type) 153 if (cursor_type_ == cursor_type)
155 return; 154 return;
156 if (cursor_type_ == GDK_LAST_CURSOR) 155 if (cursor_type_ == GDK_LAST_CURSOR)
157 gdk_cursor = NULL; 156 gdk_cursor = NULL;
158 else 157 else
159 gdk_cursor = gdk_cursor_new(cursor_type); 158 gdk_cursor = gdk_cursor_new(cursor_type);
160 } 159 }
161 cursor_type_ = cursor_type; 160 cursor_type_ = cursor_type;
162 gdk_window_set_cursor(shell_->webViewWnd()->window, gdk_cursor); 161 gdk_window_set_cursor(shell_->webViewWnd()->window, gdk_cursor);
163 // The window now owns the cursor. 162 // The window now owns the cursor.
164 if (gdk_cursor) 163 if (gdk_cursor)
165 gdk_cursor_unref(gdk_cursor); 164 gdk_cursor_unref(gdk_cursor);
166 } 165 }
167 166
168 void TestWebViewDelegate::GetWindowRect(WebWidget* webwidget, 167 WebRect TestWebViewDelegate::windowRect() {
169 WebRect* out_rect) { 168 WebWidgetHost* host = GetWidgetHost();
170 DCHECK(out_rect);
171 WebWidgetHost* host = GetHostForWidget(webwidget);
172 GtkWidget* drawing_area = host->view_handle(); 169 GtkWidget* drawing_area = host->view_handle();
173 GtkWidget* vbox = gtk_widget_get_parent(drawing_area); 170 GtkWidget* vbox = gtk_widget_get_parent(drawing_area);
174 GtkWidget* window = gtk_widget_get_parent(vbox); 171 GtkWidget* window = gtk_widget_get_parent(vbox);
175 172
176 gint x, y; 173 gint x, y;
177 gtk_window_get_position(GTK_WINDOW(window), &x, &y); 174 gtk_window_get_position(GTK_WINDOW(window), &x, &y);
178 x += vbox->allocation.x + drawing_area->allocation.x; 175 x += vbox->allocation.x + drawing_area->allocation.x;
179 y += vbox->allocation.y + drawing_area->allocation.y; 176 y += vbox->allocation.y + drawing_area->allocation.y;
180 177
181 *out_rect = WebRect(x, y, 178 return WebRect(x, y,
182 drawing_area->allocation.width, 179 drawing_area->allocation.width,
183 drawing_area->allocation.height); 180 drawing_area->allocation.height);
184 } 181 }
185 182
186 void TestWebViewDelegate::SetWindowRect(WebWidget* webwidget, 183 void TestWebViewDelegate::setWindowRect(const WebRect& rect) {
187 const WebRect& rect) { 184 if (this == shell_->delegate()) {
188 if (webwidget == shell_->webView()) {
189 // ignored 185 // ignored
190 } else if (webwidget == shell_->popup()) { 186 } else if (this == shell_->popup_delegate()) {
191 WebWidgetHost* host = GetHostForWidget(webwidget); 187 WebWidgetHost* host = GetWidgetHost();
192 GtkWidget* drawing_area = host->view_handle(); 188 GtkWidget* drawing_area = host->view_handle();
193 GtkWidget* window = 189 GtkWidget* window =
194 gtk_widget_get_parent(gtk_widget_get_parent(drawing_area)); 190 gtk_widget_get_parent(gtk_widget_get_parent(drawing_area));
195 gtk_window_resize(GTK_WINDOW(window), rect.width, rect.height); 191 gtk_window_resize(GTK_WINDOW(window), rect.width, rect.height);
196 gtk_window_move(GTK_WINDOW(window), rect.x, rect.y); 192 gtk_window_move(GTK_WINDOW(window), rect.x, rect.y);
197 } 193 }
198 } 194 }
199 195
200 void TestWebViewDelegate::GetRootWindowRect(WebWidget* webwidget, 196 WebRect TestWebViewDelegate::rootWindowRect() {
201 WebRect* out_rect) { 197 if (WebWidgetHost* host = GetWidgetHost()) {
202 if (WebWidgetHost* host = GetHostForWidget(webwidget)) {
203 // We are being asked for the x/y and width/height of the entire browser 198 // We are being asked for the x/y and width/height of the entire browser
204 // window. This means the x/y is the distance from the corner of the 199 // window. This means the x/y is the distance from the corner of the
205 // screen, and the width/height is the size of the entire browser window. 200 // screen, and the width/height is the size of the entire browser window.
206 // For example, this is used to implement window.screenX and window.screenY. 201 // For example, this is used to implement window.screenX and window.screenY.
207 GtkWidget* drawing_area = host->view_handle(); 202 GtkWidget* drawing_area = host->view_handle();
208 GtkWidget* window = 203 GtkWidget* window =
209 gtk_widget_get_parent(gtk_widget_get_parent(drawing_area)); 204 gtk_widget_get_parent(gtk_widget_get_parent(drawing_area));
210 gint x, y, width, height; 205 gint x, y, width, height;
211 gtk_window_get_position(GTK_WINDOW(window), &x, &y); 206 gtk_window_get_position(GTK_WINDOW(window), &x, &y);
212 gtk_window_get_size(GTK_WINDOW(window), &width, &height); 207 gtk_window_get_size(GTK_WINDOW(window), &width, &height);
213 *out_rect = WebRect(x, y, width, height); 208 return WebRect(x, y, width, height);
214 } 209 }
210 return WebRect();
215 } 211 }
216 212
217 void TestWebViewDelegate::GetRootWindowResizerRect(WebWidget* webwidget, 213 WebRect TestWebViewDelegate::windowResizerRect() {
218 WebRect* out_rect) {
219 // Not necessary on Linux. 214 // Not necessary on Linux.
220 *out_rect = WebRect(); 215 return WebRect();
221 } 216 }
222 217
223 void TestWebViewDelegate::DidMove(WebWidget* webwidget, 218 void TestWebViewDelegate::DidMovePlugin(const WebPluginGeometry& move) {
224 const WebPluginGeometry& move) { 219 WebWidgetHost* host = GetWidgetHost();
225 WebWidgetHost* host = GetHostForWidget(webwidget);
226 GtkPluginContainerManager* plugin_container_manager = 220 GtkPluginContainerManager* plugin_container_manager =
227 static_cast<WebViewHost*>(host)->plugin_container_manager(); 221 static_cast<WebViewHost*>(host)->plugin_container_manager();
228 plugin_container_manager->MovePluginContainer(move); 222 plugin_container_manager->MovePluginContainer(move);
229 } 223 }
230 224
231 void TestWebViewDelegate::RunModal(WebWidget* webwidget) { 225 void TestWebViewDelegate::runModal() {
232 NOTIMPLEMENTED(); 226 NOTIMPLEMENTED();
233 } 227 }
234 228
235 void TestWebViewDelegate::UpdateSelectionClipboard(bool is_empty_selection) { 229 void TestWebViewDelegate::UpdateSelectionClipboard(bool is_empty_selection) {
236 if (is_empty_selection) 230 if (is_empty_selection)
237 return; 231 return;
238 232
239 GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); 233 GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
240 // Put data on the X clipboard. This doesn't actually grab the text from 234 // Put data on the X clipboard. This doesn't actually grab the text from
241 // the HTML, it just registers a callback for when someone tries to paste. 235 // the HTML, it just registers a callback for when someone tries to paste.
(...skipping 14 matching lines...) Expand all
256 // Private methods ----------------------------------------------------------- 250 // Private methods -----------------------------------------------------------
257 251
258 void TestWebViewDelegate::SetPageTitle(const std::wstring& title) { 252 void TestWebViewDelegate::SetPageTitle(const std::wstring& title) {
259 gtk_window_set_title(GTK_WINDOW(shell_->mainWnd()), 253 gtk_window_set_title(GTK_WINDOW(shell_->mainWnd()),
260 ("Test Shell - " + WideToUTF8(title)).c_str()); 254 ("Test Shell - " + WideToUTF8(title)).c_str());
261 } 255 }
262 256
263 void TestWebViewDelegate::SetAddressBarURL(const GURL& url) { 257 void TestWebViewDelegate::SetAddressBarURL(const GURL& url) {
264 gtk_entry_set_text(GTK_ENTRY(shell_->editWnd()), url.spec().c_str()); 258 gtk_entry_set_text(GTK_ENTRY(shell_->editWnd()), url.spec().c_str());
265 } 259 }
OLDNEW
« no previous file with comments | « webkit/tools/test_shell/test_webview_delegate.cc ('k') | webkit/tools/test_shell/test_webview_delegate_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698