| 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 #include "webkit/tools/test_shell/test_webview_delegate.h" | 5 #include "webkit/tools/test_shell/test_webview_delegate.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
| 10 #include "webkit/api/public/WebCursorInfo.h" | 10 #include "webkit/api/public/WebCursorInfo.h" |
| 11 #include "webkit/api/public/WebPopupMenu.h" |
| 11 #include "webkit/glue/webcursor.h" | 12 #include "webkit/glue/webcursor.h" |
| 12 #include "webkit/glue/webview.h" | 13 #include "webkit/glue/webview.h" |
| 13 #include "webkit/glue/plugins/plugin_list.h" | 14 #include "webkit/glue/plugins/plugin_list.h" |
| 14 #include "webkit/glue/plugins/webplugin_delegate_impl.h" | 15 #include "webkit/glue/plugins/webplugin_delegate_impl.h" |
| 15 #include "webkit/glue/webmenurunner_mac.h" | 16 #include "webkit/glue/webmenurunner_mac.h" |
| 16 #include "webkit/tools/test_shell/test_shell.h" | 17 #include "webkit/tools/test_shell/test_shell.h" |
| 17 | 18 |
| 18 using WebKit::WebCursorInfo; | 19 using WebKit::WebCursorInfo; |
| 19 using WebKit::WebNavigationPolicy; | 20 using WebKit::WebNavigationPolicy; |
| 21 using WebKit::WebPopupMenu; |
| 20 using WebKit::WebPopupMenuInfo; | 22 using WebKit::WebPopupMenuInfo; |
| 21 using WebKit::WebRect; | 23 using WebKit::WebRect; |
| 22 using WebKit::WebWidget; | 24 using WebKit::WebWidget; |
| 23 | 25 |
| 24 // WebViewDelegate ------------------------------------------------------------ | 26 // WebViewClient -------------------------------------------------------------- |
| 25 | 27 |
| 26 WebWidget* TestWebViewDelegate::CreatePopupWidgetWithInfo( | 28 WebWidget* TestWebViewDelegate::createPopupMenu( |
| 27 WebView* webview, | |
| 28 const WebPopupMenuInfo& info) { | 29 const WebPopupMenuInfo& info) { |
| 29 WebWidget* webwidget = shell_->CreatePopupWidget(webview); | 30 WebWidget* webwidget = shell_->CreatePopupWidget(); |
| 30 popup_menu_info_.reset(new WebPopupMenuInfo(info)); | 31 popup_menu_info_.reset(new WebPopupMenuInfo(info)); |
| 31 return webwidget; | 32 return webwidget; |
| 32 } | 33 } |
| 33 | 34 |
| 34 void TestWebViewDelegate::ShowJavaScriptAlert(const std::wstring& message) { | |
| 35 NSString *text = | |
| 36 [NSString stringWithUTF8String:WideToUTF8(message).c_str()]; | |
| 37 NSAlert *alert = [NSAlert alertWithMessageText:@"JavaScript Alert" | |
| 38 defaultButton:@"OK" | |
| 39 alternateButton:nil | |
| 40 otherButton:nil | |
| 41 informativeTextWithFormat:text]; | |
| 42 [alert runModal]; | |
| 43 } | |
| 44 | |
| 45 // WebWidgetClient ------------------------------------------------------------ | 35 // WebWidgetClient ------------------------------------------------------------ |
| 46 | 36 |
| 47 void TestWebViewDelegate::show(WebNavigationPolicy policy) { | 37 void TestWebViewDelegate::show(WebNavigationPolicy policy) { |
| 48 if (!popup_menu_info_.get()) | 38 if (!popup_menu_info_.get()) |
| 49 return; | 39 return; |
| 50 if (this != shell_->popup_delegate()) | 40 if (this != shell_->popup_delegate()) |
| 51 return; | 41 return; |
| 52 // Display a HTML select menu. | 42 // Display a HTML select menu. |
| 53 | 43 |
| 54 std::vector<WebMenuItem> items; | 44 std::vector<WebMenuItem> items; |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 } | 198 } |
| 209 | 199 |
| 210 // Public methods ------------------------------------------------------------- | 200 // Public methods ------------------------------------------------------------- |
| 211 | 201 |
| 212 void TestWebViewDelegate::UpdateSelectionClipboard(bool is_empty_selection) { | 202 void TestWebViewDelegate::UpdateSelectionClipboard(bool is_empty_selection) { |
| 213 // No selection clipboard on mac, do nothing. | 203 // No selection clipboard on mac, do nothing. |
| 214 } | 204 } |
| 215 | 205 |
| 216 // Private methods ------------------------------------------------------------ | 206 // Private methods ------------------------------------------------------------ |
| 217 | 207 |
| 208 void TestWebViewDelegate::ShowJavaScriptAlert(const std::wstring& message) { |
| 209 NSString *text = |
| 210 [NSString stringWithUTF8String:WideToUTF8(message).c_str()]; |
| 211 NSAlert *alert = [NSAlert alertWithMessageText:@"JavaScript Alert" |
| 212 defaultButton:@"OK" |
| 213 alternateButton:nil |
| 214 otherButton:nil |
| 215 informativeTextWithFormat:text]; |
| 216 [alert runModal]; |
| 217 } |
| 218 |
| 218 void TestWebViewDelegate::SetPageTitle(const std::wstring& title) { | 219 void TestWebViewDelegate::SetPageTitle(const std::wstring& title) { |
| 219 [[shell_->webViewHost()->view_handle() window] | 220 [[shell_->webViewHost()->view_handle() window] |
| 220 setTitle:[NSString stringWithUTF8String:WideToUTF8(title).c_str()]]; | 221 setTitle:[NSString stringWithUTF8String:WideToUTF8(title).c_str()]]; |
| 221 } | 222 } |
| 222 | 223 |
| 223 void TestWebViewDelegate::SetAddressBarURL(const GURL& url) { | 224 void TestWebViewDelegate::SetAddressBarURL(const GURL& url) { |
| 224 const char* frameURL = url.spec().c_str(); | 225 const char* frameURL = url.spec().c_str(); |
| 225 NSString *address = [NSString stringWithUTF8String:frameURL]; | 226 NSString *address = [NSString stringWithUTF8String:frameURL]; |
| 226 [shell_->editWnd() setStringValue:address]; | 227 [shell_->editWnd() setStringValue:address]; |
| 227 } | 228 } |
| OLD | NEW |