| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-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 contains the implementation of TestWebViewDelegate, which serves | 5 // This file contains the implementation of TestWebViewDelegate, which serves |
| 6 // as the WebViewDelegate for the TestShellWebHost. The host is expected to | 6 // as the WebViewDelegate for the TestShellWebHost. The host is expected to |
| 7 // have initialized a MessageLoop before these methods are called. | 7 // have initialized a MessageLoop before these methods are called. |
| 8 | 8 |
| 9 #include "webkit/tools/test_shell/test_webview_delegate.h" | 9 #include "webkit/tools/test_shell/test_webview_delegate.h" |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "webkit/glue/webview.h" | 29 #include "webkit/glue/webview.h" |
| 30 #include "webkit/glue/plugins/plugin_list.h" | 30 #include "webkit/glue/plugins/plugin_list.h" |
| 31 #include "webkit/glue/plugins/webplugin_delegate_impl.h" | 31 #include "webkit/glue/plugins/webplugin_delegate_impl.h" |
| 32 #include "webkit/glue/window_open_disposition.h" | 32 #include "webkit/glue/window_open_disposition.h" |
| 33 #include "webkit/tools/test_shell/drag_delegate.h" | 33 #include "webkit/tools/test_shell/drag_delegate.h" |
| 34 #include "webkit/tools/test_shell/drop_delegate.h" | 34 #include "webkit/tools/test_shell/drop_delegate.h" |
| 35 #include "webkit/tools/test_shell/test_navigation_controller.h" | 35 #include "webkit/tools/test_shell/test_navigation_controller.h" |
| 36 #include "webkit/tools/test_shell/test_shell.h" | 36 #include "webkit/tools/test_shell/test_shell.h" |
| 37 | 37 |
| 38 using WebKit::WebCursorInfo; | 38 using WebKit::WebCursorInfo; |
| 39 using WebKit::WebNavigationPolicy; |
| 39 using WebKit::WebRect; | 40 using WebKit::WebRect; |
| 40 | 41 |
| 41 // WebViewDelegate ----------------------------------------------------------- | 42 // WebViewDelegate ----------------------------------------------------------- |
| 42 | 43 |
| 43 TestWebViewDelegate::~TestWebViewDelegate() { | 44 TestWebViewDelegate::~TestWebViewDelegate() { |
| 44 RevokeDragDrop(shell_->webViewWnd()); | 45 RevokeDragDrop(shell_->webViewWnd()); |
| 45 } | 46 } |
| 46 | 47 |
| 47 WebPluginDelegate* TestWebViewDelegate::CreatePluginDelegate( | 48 WebPluginDelegate* TestWebViewDelegate::CreatePluginDelegate( |
| 48 WebView* webview, | 49 WebView* webview, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 60 allow_wildcard, &info, | 61 allow_wildcard, &info, |
| 61 actual_mime_type)) | 62 actual_mime_type)) |
| 62 return NULL; | 63 return NULL; |
| 63 | 64 |
| 64 if (actual_mime_type && !actual_mime_type->empty()) | 65 if (actual_mime_type && !actual_mime_type->empty()) |
| 65 return WebPluginDelegateImpl::Create(info.path, *actual_mime_type, hwnd); | 66 return WebPluginDelegateImpl::Create(info.path, *actual_mime_type, hwnd); |
| 66 else | 67 else |
| 67 return WebPluginDelegateImpl::Create(info.path, mime_type, hwnd); | 68 return WebPluginDelegateImpl::Create(info.path, mime_type, hwnd); |
| 68 } | 69 } |
| 69 | 70 |
| 70 void TestWebViewDelegate::ShowJavaScriptAlert(const std::wstring& message) { | 71 void TestWebViewDelegate::DidMovePlugin(const WebPluginGeometry& move) { |
| 71 MessageBox(NULL, message.c_str(), L"JavaScript Alert", MB_OK); | |
| 72 } | |
| 73 | |
| 74 void TestWebViewDelegate::Show(WebWidget* webwidget, WindowOpenDisposition) { | |
| 75 if (webwidget == shell_->webView()) { | |
| 76 ShowWindow(shell_->mainWnd(), SW_SHOW); | |
| 77 UpdateWindow(shell_->mainWnd()); | |
| 78 } else if (webwidget == shell_->popup()) { | |
| 79 ShowWindow(shell_->popupWnd(), SW_SHOW); | |
| 80 UpdateWindow(shell_->popupWnd()); | |
| 81 } | |
| 82 } | |
| 83 | |
| 84 void TestWebViewDelegate::CloseWidgetSoon(WebWidget* webwidget) { | |
| 85 if (webwidget == shell_->webView()) { | |
| 86 PostMessage(shell_->mainWnd(), WM_CLOSE, 0, 0); | |
| 87 } else if (webwidget == shell_->popup()) { | |
| 88 shell_->ClosePopup(); | |
| 89 } | |
| 90 } | |
| 91 | |
| 92 void TestWebViewDelegate::SetCursor(WebWidget* webwidget, | |
| 93 const WebCursorInfo& cursor_info) { | |
| 94 if (WebWidgetHost* host = GetHostForWidget(webwidget)) { | |
| 95 current_cursor_.InitFromCursorInfo(cursor_info); | |
| 96 HINSTANCE mod_handle = GetModuleHandle(NULL); | |
| 97 host->SetCursor(current_cursor_.GetCursor(mod_handle)); | |
| 98 } | |
| 99 } | |
| 100 | |
| 101 void TestWebViewDelegate::GetWindowRect(WebWidget* webwidget, | |
| 102 WebRect* out_rect) { | |
| 103 if (WebWidgetHost* host = GetHostForWidget(webwidget)) { | |
| 104 RECT rect; | |
| 105 ::GetWindowRect(host->view_handle(), &rect); | |
| 106 *out_rect = gfx::Rect(rect); | |
| 107 } | |
| 108 } | |
| 109 | |
| 110 void TestWebViewDelegate::SetWindowRect(WebWidget* webwidget, | |
| 111 const WebRect& rect) { | |
| 112 if (webwidget == shell_->webView()) { | |
| 113 // ignored | |
| 114 } else if (webwidget == shell_->popup()) { | |
| 115 MoveWindow(shell_->popupWnd(), | |
| 116 rect.x, rect.y, rect.width, rect.height, FALSE); | |
| 117 } | |
| 118 } | |
| 119 | |
| 120 void TestWebViewDelegate::GetRootWindowRect(WebWidget* webwidget, | |
| 121 WebRect* out_rect) { | |
| 122 if (WebWidgetHost* host = GetHostForWidget(webwidget)) { | |
| 123 RECT rect; | |
| 124 HWND root_window = ::GetAncestor(host->view_handle(), GA_ROOT); | |
| 125 ::GetWindowRect(root_window, &rect); | |
| 126 *out_rect = gfx::Rect(rect); | |
| 127 } | |
| 128 } | |
| 129 | |
| 130 void TestWebViewDelegate::GetRootWindowResizerRect(WebWidget* webwidget, | |
| 131 WebRect* out_rect) { | |
| 132 // Not necessary on Windows. | |
| 133 *out_rect = gfx::Rect(); | |
| 134 } | |
| 135 | |
| 136 void TestWebViewDelegate::DidMove(WebWidget* webwidget, | |
| 137 const WebPluginGeometry& move) { | |
| 138 HRGN hrgn = ::CreateRectRgn(move.clip_rect.x(), | 72 HRGN hrgn = ::CreateRectRgn(move.clip_rect.x(), |
| 139 move.clip_rect.y(), | 73 move.clip_rect.y(), |
| 140 move.clip_rect.right(), | 74 move.clip_rect.right(), |
| 141 move.clip_rect.bottom()); | 75 move.clip_rect.bottom()); |
| 142 gfx::SubtractRectanglesFromRegion(hrgn, move.cutout_rects); | 76 gfx::SubtractRectanglesFromRegion(hrgn, move.cutout_rects); |
| 143 | 77 |
| 144 // Note: System will own the hrgn after we call SetWindowRgn, | 78 // Note: System will own the hrgn after we call SetWindowRgn, |
| 145 // so we don't need to call DeleteObject(hrgn) | 79 // so we don't need to call DeleteObject(hrgn) |
| 146 ::SetWindowRgn(move.window, hrgn, FALSE); | 80 ::SetWindowRgn(move.window, hrgn, FALSE); |
| 147 unsigned long flags = 0; | 81 unsigned long flags = 0; |
| 148 if (move.visible) | 82 if (move.visible) |
| 149 flags |= SWP_SHOWWINDOW; | 83 flags |= SWP_SHOWWINDOW; |
| 150 else | 84 else |
| 151 flags |= SWP_HIDEWINDOW; | 85 flags |= SWP_HIDEWINDOW; |
| 152 | 86 |
| 153 ::SetWindowPos(move.window, | 87 ::SetWindowPos(move.window, |
| 154 NULL, | 88 NULL, |
| 155 move.window_rect.x(), | 89 move.window_rect.x(), |
| 156 move.window_rect.y(), | 90 move.window_rect.y(), |
| 157 move.window_rect.width(), | 91 move.window_rect.width(), |
| 158 move.window_rect.height(), | 92 move.window_rect.height(), |
| 159 flags); | 93 flags); |
| 160 } | 94 } |
| 161 | 95 |
| 162 void TestWebViewDelegate::RunModal(WebWidget* webwidget) { | 96 void TestWebViewDelegate::ShowJavaScriptAlert(const std::wstring& message) { |
| 163 Show(webwidget, NEW_WINDOW); | 97 MessageBox(NULL, message.c_str(), L"JavaScript Alert", MB_OK); |
| 98 } |
| 99 |
| 100 void TestWebViewDelegate::show(WebNavigationPolicy) { |
| 101 if (WebWidgetHost* host = GetWidgetHost()) { |
| 102 HWND root = GetAncestor(host->view_handle(), GA_ROOT); |
| 103 ShowWindow(root, SW_SHOW); |
| 104 UpdateWindow(root); |
| 105 } |
| 106 } |
| 107 |
| 108 void TestWebViewDelegate::closeWidgetSoon() { |
| 109 if (this == shell_->delegate()) { |
| 110 PostMessage(shell_->mainWnd(), WM_CLOSE, 0, 0); |
| 111 } else if (this == shell_->popup_delegate()) { |
| 112 shell_->ClosePopup(); |
| 113 } |
| 114 } |
| 115 |
| 116 void TestWebViewDelegate::didChangeCursor(const WebCursorInfo& cursor_info) { |
| 117 if (WebWidgetHost* host = GetWidgetHost()) { |
| 118 current_cursor_.InitFromCursorInfo(cursor_info); |
| 119 HINSTANCE mod_handle = GetModuleHandle(NULL); |
| 120 host->SetCursor(current_cursor_.GetCursor(mod_handle)); |
| 121 } |
| 122 } |
| 123 |
| 124 WebRect TestWebViewDelegate::windowRect() { |
| 125 if (WebWidgetHost* host = GetWidgetHost()) { |
| 126 RECT rect; |
| 127 ::GetWindowRect(host->view_handle(), &rect); |
| 128 return gfx::Rect(rect); |
| 129 } |
| 130 return WebRect(); |
| 131 } |
| 132 |
| 133 void TestWebViewDelegate::setWindowRect(const WebRect& rect) { |
| 134 if (this == shell_->delegate()) { |
| 135 // ignored |
| 136 } else if (this == shell_->popup_delegate()) { |
| 137 MoveWindow(shell_->popupWnd(), |
| 138 rect.x, rect.y, rect.width, rect.height, FALSE); |
| 139 } |
| 140 } |
| 141 |
| 142 WebRect TestWebViewDelegate::rootWindowRect() { |
| 143 if (WebWidgetHost* host = GetWidgetHost()) { |
| 144 RECT rect; |
| 145 HWND root_window = ::GetAncestor(host->view_handle(), GA_ROOT); |
| 146 ::GetWindowRect(root_window, &rect); |
| 147 return gfx::Rect(rect); |
| 148 } |
| 149 return WebRect(); |
| 150 } |
| 151 |
| 152 WebRect TestWebViewDelegate::windowResizerRect() { |
| 153 // Not necessary on Windows. |
| 154 return WebRect(); |
| 155 } |
| 156 |
| 157 void TestWebViewDelegate::runModal() { |
| 158 WebWidgetHost* host = GetWidgetHost(); |
| 159 if (!host) |
| 160 return; |
| 161 |
| 162 show(WebNavigationPolicy() /*XXX NEW_WINDOW*/); |
| 164 | 163 |
| 165 WindowList* wl = TestShell::windowList(); | 164 WindowList* wl = TestShell::windowList(); |
| 166 for (WindowList::const_iterator i = wl->begin(); i != wl->end(); ++i) { | 165 for (WindowList::const_iterator i = wl->begin(); i != wl->end(); ++i) { |
| 167 if (*i != shell_->mainWnd()) | 166 if (*i != shell_->mainWnd()) |
| 168 EnableWindow(*i, FALSE); | 167 EnableWindow(*i, FALSE); |
| 169 } | 168 } |
| 170 | 169 |
| 171 shell_->set_is_modal(true); | 170 shell_->set_is_modal(true); |
| 172 MessageLoop::current()->Run(); | 171 MessageLoop::current()->Run(); |
| 173 | 172 |
| 174 for (WindowList::const_iterator i = wl->begin(); i != wl->end(); ++i) | 173 for (WindowList::const_iterator i = wl->begin(); i != wl->end(); ++i) |
| 175 EnableWindow(*i, TRUE); | 174 EnableWindow(*i, TRUE); |
| 176 } | 175 } |
| 177 | 176 |
| 178 void TestWebViewDelegate::UpdateSelectionClipboard(bool is_empty_selection) { | 177 void TestWebViewDelegate::UpdateSelectionClipboard(bool is_empty_selection) { |
| 179 // No selection clipboard on windows, do nothing. | 178 // No selection clipboard on windows, do nothing. |
| 180 } | 179 } |
| 181 | 180 |
| 182 // Private methods ----------------------------------------------------------- | 181 // Private methods ----------------------------------------------------------- |
| 183 | 182 |
| 184 void TestWebViewDelegate::SetPageTitle(const std::wstring& title) { | 183 void TestWebViewDelegate::SetPageTitle(const std::wstring& title) { |
| 185 // The Windows test shell, pre-refactoring, ignored this. *shrug* | 184 // The Windows test shell, pre-refactoring, ignored this. *shrug* |
| 186 } | 185 } |
| 187 | 186 |
| 188 void TestWebViewDelegate::SetAddressBarURL(const GURL& url) { | 187 void TestWebViewDelegate::SetAddressBarURL(const GURL& url) { |
| 189 std::wstring url_string = UTF8ToWide(url.spec()); | 188 std::wstring url_string = UTF8ToWide(url.spec()); |
| 190 SendMessage(shell_->editWnd(), WM_SETTEXT, 0, | 189 SendMessage(shell_->editWnd(), WM_SETTEXT, 0, |
| 191 reinterpret_cast<LPARAM>(url_string.c_str())); | 190 reinterpret_cast<LPARAM>(url_string.c_str())); |
| 192 } | 191 } |
| OLD | NEW |