| OLD | NEW |
| 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> |
| 11 | 11 |
| 12 #include "base/gfx/gtk_util.h" | 12 #include "base/gfx/gtk_util.h" |
| 13 #include "base/gfx/point.h" | 13 #include "base/gfx/point.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 17 #include "chrome/common/page_transition_types.h" | 17 #include "chrome/common/page_transition_types.h" |
| 18 #include "webkit/api/public/WebRect.h" | 18 #include "webkit/api/public/WebRect.h" |
| 19 #include "webkit/glue/webcursor.h" | 19 #include "webkit/glue/webcursor.h" |
| 20 #include "webkit/glue/webdropdata.h" | 20 #include "webkit/glue/webdropdata.h" |
| 21 #include "webkit/glue/webframe.h" | 21 #include "webkit/glue/webframe.h" |
| 22 #include "webkit/glue/webpreferences.h" | 22 #include "webkit/glue/webpreferences.h" |
| 23 #include "webkit/glue/webplugin.h" | 23 #include "webkit/glue/webplugin.h" |
| 24 #include "webkit/glue/webkit_glue.h" | 24 #include "webkit/glue/webkit_glue.h" |
| 25 #include "webkit/glue/webview.h" | 25 #include "webkit/glue/webview.h" |
| 26 #include "webkit/glue/plugins/gtk_plugin_container.h" | 26 #include "webkit/glue/plugins/gtk_plugin_container_host.h" |
| 27 #include "webkit/glue/plugins/plugin_list.h" | 27 #include "webkit/glue/plugins/plugin_list.h" |
| 28 #include "webkit/glue/window_open_disposition.h" | 28 #include "webkit/glue/window_open_disposition.h" |
| 29 #include "webkit/glue/plugins/webplugin_delegate_impl.h" | 29 #include "webkit/glue/plugins/webplugin_delegate_impl.h" |
| 30 #include "webkit/tools/test_shell/test_navigation_controller.h" | 30 #include "webkit/tools/test_shell/test_navigation_controller.h" |
| 31 #include "webkit/tools/test_shell/test_shell.h" | 31 #include "webkit/tools/test_shell/test_shell.h" |
| 32 | 32 |
| 33 using WebKit::WebRect; | 33 using WebKit::WebRect; |
| 34 | 34 |
| 35 namespace { | 35 namespace { |
| 36 | 36 |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 | 223 |
| 224 void TestWebViewDelegate::GetRootWindowResizerRect(WebWidget* webwidget, | 224 void TestWebViewDelegate::GetRootWindowResizerRect(WebWidget* webwidget, |
| 225 WebRect* out_rect) { | 225 WebRect* out_rect) { |
| 226 // Not necessary on Linux. | 226 // Not necessary on Linux. |
| 227 *out_rect = WebRect(); | 227 *out_rect = WebRect(); |
| 228 } | 228 } |
| 229 | 229 |
| 230 void TestWebViewDelegate::DidMove(WebWidget* webwidget, | 230 void TestWebViewDelegate::DidMove(WebWidget* webwidget, |
| 231 const WebPluginGeometry& move) { | 231 const WebPluginGeometry& move) { |
| 232 WebWidgetHost* host = GetHostForWidget(webwidget); | 232 WebWidgetHost* host = GetHostForWidget(webwidget); |
| 233 | 233 GtkPluginContainerHost &plugin_container_host = |
| 234 // The "window" on WebPluginGeometry is actually the XEmbed parent | 234 static_cast<WebViewHost*>(host)->plugin_container_host(); |
| 235 // X window id. | 235 plugin_container_host.MovePluginContainer(move); |
| 236 GtkWidget* widget = ((WebViewHost*)host)->MapIDToWidget(move.window); | |
| 237 // If we don't know about this plugin (maybe we're shutting down the | |
| 238 // window?), ignore the message. | |
| 239 if (!widget) | |
| 240 return; | |
| 241 DCHECK(!GTK_WIDGET_NO_WINDOW(widget)); | |
| 242 DCHECK(GTK_WIDGET_REALIZED(widget)); | |
| 243 | |
| 244 if (!move.visible) { | |
| 245 gtk_widget_hide(widget); | |
| 246 return; | |
| 247 } else { | |
| 248 gtk_widget_show(widget); | |
| 249 } | |
| 250 | |
| 251 // Update the clipping region on the GdkWindow. | |
| 252 GdkRectangle clip_rect = move.clip_rect.ToGdkRectangle(); | |
| 253 GdkRegion* clip_region = gdk_region_rectangle(&clip_rect); | |
| 254 gfx::SubtractRectanglesFromRegion(clip_region, move.cutout_rects); | |
| 255 gdk_window_shape_combine_region(widget->window, clip_region, 0, 0); | |
| 256 gdk_region_destroy(clip_region); | |
| 257 | |
| 258 // Update the window position. Resizing is handled by WebPluginDelegate. | |
| 259 // TODO(deanm): Verify that we only need to move and not resize. | |
| 260 // TODO(evanm): we should cache the last shape and position and skip all | |
| 261 // of this business in the common case where nothing has changed. | |
| 262 int current_x, current_y; | |
| 263 | |
| 264 // Until the above TODO is resolved, we can grab the last position | |
| 265 // off of the GtkFixed with a bit of hackery. | |
| 266 GValue value = {0}; | |
| 267 g_value_init(&value, G_TYPE_INT); | |
| 268 gtk_container_child_get_property(GTK_CONTAINER(host->view_handle()), widget, | |
| 269 "x", &value); | |
| 270 current_x = g_value_get_int(&value); | |
| 271 gtk_container_child_get_property(GTK_CONTAINER(host->view_handle()), widget, | |
| 272 "y", &value); | |
| 273 current_y = g_value_get_int(&value); | |
| 274 g_value_unset(&value); | |
| 275 | |
| 276 if (move.window_rect.x() != current_x || move.window_rect.y() != current_y) { | |
| 277 // Calling gtk_fixed_move unnecessarily is a no-no, as it causes the parent | |
| 278 // window to repaint! | |
| 279 gtk_fixed_move(GTK_FIXED(host->view_handle()), | |
| 280 widget, | |
| 281 move.window_rect.x(), | |
| 282 move.window_rect.y()); | |
| 283 } | |
| 284 | |
| 285 gtk_plugin_container_set_size(widget, | |
| 286 move.window_rect.width(), | |
| 287 move.window_rect.height()); | |
| 288 } | 236 } |
| 289 | 237 |
| 290 void TestWebViewDelegate::RunModal(WebWidget* webwidget) { | 238 void TestWebViewDelegate::RunModal(WebWidget* webwidget) { |
| 291 NOTIMPLEMENTED(); | 239 NOTIMPLEMENTED(); |
| 292 } | 240 } |
| 293 | 241 |
| 294 void TestWebViewDelegate::UpdateSelectionClipboard(bool is_empty_selection) { | 242 void TestWebViewDelegate::UpdateSelectionClipboard(bool is_empty_selection) { |
| 295 if (is_empty_selection) | 243 if (is_empty_selection) |
| 296 return; | 244 return; |
| 297 | 245 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 315 // Private methods ----------------------------------------------------------- | 263 // Private methods ----------------------------------------------------------- |
| 316 | 264 |
| 317 void TestWebViewDelegate::SetPageTitle(const std::wstring& title) { | 265 void TestWebViewDelegate::SetPageTitle(const std::wstring& title) { |
| 318 gtk_window_set_title(GTK_WINDOW(shell_->mainWnd()), | 266 gtk_window_set_title(GTK_WINDOW(shell_->mainWnd()), |
| 319 ("Test Shell - " + WideToUTF8(title)).c_str()); | 267 ("Test Shell - " + WideToUTF8(title)).c_str()); |
| 320 } | 268 } |
| 321 | 269 |
| 322 void TestWebViewDelegate::SetAddressBarURL(const GURL& url) { | 270 void TestWebViewDelegate::SetAddressBarURL(const GURL& url) { |
| 323 gtk_entry_set_text(GTK_ENTRY(shell_->editWnd()), url.spec().c_str()); | 271 gtk_entry_set_text(GTK_ENTRY(shell_->editWnd()), url.spec().c_str()); |
| 324 } | 272 } |
| OLD | NEW |