| 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/WebCString.h" |
| 18 #include "webkit/api/public/WebCursorInfo.h" | 19 #include "webkit/api/public/WebCursorInfo.h" |
| 20 #include "webkit/api/public/WebFrame.h" |
| 19 #include "webkit/api/public/WebRect.h" | 21 #include "webkit/api/public/WebRect.h" |
| 22 #include "webkit/api/public/WebString.h" |
| 20 #include "webkit/glue/webcursor.h" | 23 #include "webkit/glue/webcursor.h" |
| 21 #include "webkit/glue/webdropdata.h" | 24 #include "webkit/glue/webdropdata.h" |
| 22 #include "webkit/glue/webframe.h" | |
| 23 #include "webkit/glue/webpreferences.h" | 25 #include "webkit/glue/webpreferences.h" |
| 24 #include "webkit/glue/webplugin.h" | 26 #include "webkit/glue/webplugin.h" |
| 25 #include "webkit/glue/webkit_glue.h" | 27 #include "webkit/glue/webkit_glue.h" |
| 26 #include "webkit/glue/webview.h" | 28 #include "webkit/glue/webview.h" |
| 27 #include "webkit/glue/plugins/gtk_plugin_container_manager.h" | 29 #include "webkit/glue/plugins/gtk_plugin_container_manager.h" |
| 28 #include "webkit/glue/plugins/plugin_list.h" | 30 #include "webkit/glue/plugins/plugin_list.h" |
| 29 #include "webkit/glue/window_open_disposition.h" | 31 #include "webkit/glue/window_open_disposition.h" |
| 30 #include "webkit/glue/plugins/webplugin_delegate_impl.h" | 32 #include "webkit/glue/plugins/webplugin_delegate_impl.h" |
| 31 #include "webkit/tools/test_shell/test_navigation_controller.h" | 33 #include "webkit/tools/test_shell/test_navigation_controller.h" |
| 32 #include "webkit/tools/test_shell/test_shell.h" | 34 #include "webkit/tools/test_shell/test_shell.h" |
| 33 | 35 |
| 34 using WebKit::WebCursorInfo; | 36 using WebKit::WebCursorInfo; |
| 37 using WebKit::WebFrame; |
| 35 using WebKit::WebNavigationPolicy; | 38 using WebKit::WebNavigationPolicy; |
| 36 using WebKit::WebRect; | 39 using WebKit::WebRect; |
| 37 | 40 |
| 38 namespace { | 41 namespace { |
| 39 | 42 |
| 40 enum SelectionClipboardType { | 43 enum SelectionClipboardType { |
| 41 TEXT_HTML, | 44 TEXT_HTML, |
| 42 PLAIN_TEXT, | 45 PLAIN_TEXT, |
| 43 }; | 46 }; |
| 44 | 47 |
| 45 GdkAtom GetTextHtmlAtom() { | 48 GdkAtom GetTextHtmlAtom() { |
| 46 GdkAtom kTextHtmlGdkAtom = gdk_atom_intern_static_string("text/html"); | 49 GdkAtom kTextHtmlGdkAtom = gdk_atom_intern_static_string("text/html"); |
| 47 return kTextHtmlGdkAtom; | 50 return kTextHtmlGdkAtom; |
| 48 } | 51 } |
| 49 | 52 |
| 50 void SelectionClipboardGetContents(GtkClipboard* clipboard, | 53 void SelectionClipboardGetContents(GtkClipboard* clipboard, |
| 51 GtkSelectionData* selection_data, guint info, gpointer data) { | 54 GtkSelectionData* selection_data, guint info, gpointer data) { |
| 52 // Ignore formats that we don't know about. | 55 // Ignore formats that we don't know about. |
| 53 if (info != TEXT_HTML && info != PLAIN_TEXT) | 56 if (info != TEXT_HTML && info != PLAIN_TEXT) |
| 54 return; | 57 return; |
| 55 | 58 |
| 56 WebView* webview = static_cast<WebView*>(data); | 59 WebView* webview = static_cast<WebView*>(data); |
| 57 WebFrame* frame = webview->GetFocusedFrame(); | 60 WebFrame* frame = webview->GetFocusedFrame(); |
| 58 if (!frame) | 61 if (!frame) |
| 59 frame = webview->GetMainFrame(); | 62 frame = webview->GetMainFrame(); |
| 60 DCHECK(frame); | 63 DCHECK(frame); |
| 61 | 64 |
| 62 std::string selection = frame->GetSelection(TEXT_HTML == info); | 65 std::string selection; |
| 66 if (TEXT_HTML == info) { |
| 67 selection = frame->selectionAsMarkup().utf8(); |
| 68 } else { |
| 69 selection = frame->selectionAsText().utf8(); |
| 70 } |
| 63 if (TEXT_HTML == info) { | 71 if (TEXT_HTML == info) { |
| 64 gtk_selection_data_set(selection_data, | 72 gtk_selection_data_set(selection_data, |
| 65 GetTextHtmlAtom(), | 73 GetTextHtmlAtom(), |
| 66 8 /* bits per data unit, ie, char */, | 74 8 /* bits per data unit, ie, char */, |
| 67 reinterpret_cast<const guchar*>(selection.data()), | 75 reinterpret_cast<const guchar*>(selection.data()), |
| 68 selection.length()); | 76 selection.length()); |
| 69 } else { | 77 } else { |
| 70 gtk_selection_data_set_text(selection_data, selection.data(), | 78 gtk_selection_data_set_text(selection_data, selection.data(), |
| 71 selection.length()); | 79 selection.length()); |
| 72 } | 80 } |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 // Private methods ----------------------------------------------------------- | 258 // Private methods ----------------------------------------------------------- |
| 251 | 259 |
| 252 void TestWebViewDelegate::SetPageTitle(const std::wstring& title) { | 260 void TestWebViewDelegate::SetPageTitle(const std::wstring& title) { |
| 253 gtk_window_set_title(GTK_WINDOW(shell_->mainWnd()), | 261 gtk_window_set_title(GTK_WINDOW(shell_->mainWnd()), |
| 254 ("Test Shell - " + WideToUTF8(title)).c_str()); | 262 ("Test Shell - " + WideToUTF8(title)).c_str()); |
| 255 } | 263 } |
| 256 | 264 |
| 257 void TestWebViewDelegate::SetAddressBarURL(const GURL& url) { | 265 void TestWebViewDelegate::SetAddressBarURL(const GURL& url) { |
| 258 gtk_entry_set_text(GTK_ENTRY(shell_->editWnd()), url.spec().c_str()); | 266 gtk_entry_set_text(GTK_ENTRY(shell_->editWnd()), url.spec().c_str()); |
| 259 } | 267 } |
| OLD | NEW |