| 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/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
| 9 #include "base/string_util.h" | |
| 10 #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" | 10 #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" |
| 11 #include "webkit/glue/webcursor.h" | 11 #include "webkit/glue/webcursor.h" |
| 12 #include "webkit/glue/webview.h" | 12 #include "webkit/glue/webview.h" |
| 13 #include "webkit/glue/plugins/plugin_list.h" | 13 #include "webkit/glue/plugins/plugin_list.h" |
| 14 #include "webkit/glue/plugins/webplugin_delegate_impl.h" | 14 #include "webkit/glue/plugins/webplugin_delegate_impl.h" |
| 15 #include "webkit/glue/webmenurunner_mac.h" | 15 #include "webkit/glue/webmenurunner_mac.h" |
| 16 #include "webkit/tools/test_shell/test_shell.h" | 16 #include "webkit/tools/test_shell/test_shell.h" |
| 17 | 17 |
| 18 using WebKit::WebRect; | 18 using WebKit::WebRect; |
| 19 | 19 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 int selected_index, | 72 int selected_index, |
| 73 const std::vector<WebMenuItem>& items) { | 73 const std::vector<WebMenuItem>& items) { |
| 74 // Set up the menu position. | 74 // Set up the menu position. |
| 75 NSView* web_view = shell_->webViewWnd(); | 75 NSView* web_view = shell_->webViewWnd(); |
| 76 NSRect view_rect = [web_view bounds]; | 76 NSRect view_rect = [web_view bounds]; |
| 77 int y_offset = bounds.y + bounds.height; | 77 int y_offset = bounds.y + bounds.height; |
| 78 NSRect position = NSMakeRect(bounds.x, view_rect.size.height - y_offset, | 78 NSRect position = NSMakeRect(bounds.x, view_rect.size.height - y_offset, |
| 79 bounds.width, bounds.height); | 79 bounds.width, bounds.height); |
| 80 | 80 |
| 81 // Display the menu. | 81 // Display the menu. |
| 82 WebMenuRunner* menu_runner = | 82 scoped_nsobject<WebMenuRunner> menu_runner; |
| 83 [[[WebMenuRunner alloc] initWithItems:items] autorelease]; | 83 menu_runner.reset([[WebMenuRunner alloc] initWithItems:items]); |
| 84 | 84 |
| 85 [menu_runner runMenuInView:shell_->webViewWnd() | 85 [menu_runner runMenuInView:shell_->webViewWnd() |
| 86 withBounds:position | 86 withBounds:position |
| 87 initialIndex:selected_index]; | 87 initialIndex:selected_index]; |
| 88 | 88 |
| 89 // Get the selected item and forward to WebKit. WebKit expects an input event | 89 // Get the selected item and forward to WebKit. WebKit expects an input event |
| 90 // (mouse down, keyboard activity) for this, so we calculate the proper | 90 // (mouse down, keyboard activity) for this, so we calculate the proper |
| 91 // position based on the selected index and provided bounds. | 91 // position based on the selected index and provided bounds. |
| 92 WebWidgetHost* popup = shell_->popupHost(); | 92 WebWidgetHost* popup = shell_->popupHost(); |
| 93 int window_num = [shell_->mainWnd() windowNumber]; | 93 int window_num = [shell_->mainWnd() windowNumber]; |
| 94 NSEvent* event = |
| 95 webkit_glue::EventWithMenuAction([menu_runner menuItemWasChosen], |
| 96 window_num, item_height, |
| 97 [menu_runner indexOfSelectedItem], |
| 98 position, view_rect); |
| 94 | 99 |
| 95 NSEvent* event = CreateEventForMenuAction([menu_runner menuItemWasChosen], | |
| 96 window_num, item_height, | |
| 97 [menu_runner indexOfSelectedItem], | |
| 98 position, view_rect); | |
| 99 if ([menu_runner menuItemWasChosen]) { | 100 if ([menu_runner menuItemWasChosen]) { |
| 100 // Construct a mouse up event to simulate the selection of an appropriate | 101 // Construct a mouse up event to simulate the selection of an appropriate |
| 101 // menu item. | 102 // menu item. |
| 102 popup->MouseEvent(event); | 103 popup->MouseEvent(event); |
| 103 } else { | 104 } else { |
| 104 // Fake an ESC key event (keyCode = 0x1B, from webinputevent_mac.mm) and | 105 // Fake an ESC key event (keyCode = 0x1B, from webinputevent_mac.mm) and |
| 105 // forward that to WebKit. | 106 // forward that to WebKit. |
| 106 popup->KeyEvent(event); | 107 popup->KeyEvent(event); |
| 107 } | 108 } |
| 108 } | 109 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 void TestWebViewDelegate::SetPageTitle(const std::wstring& title) { | 204 void TestWebViewDelegate::SetPageTitle(const std::wstring& title) { |
| 204 [[shell_->webViewHost()->view_handle() window] | 205 [[shell_->webViewHost()->view_handle() window] |
| 205 setTitle:[NSString stringWithUTF8String:WideToUTF8(title).c_str()]]; | 206 setTitle:[NSString stringWithUTF8String:WideToUTF8(title).c_str()]]; |
| 206 } | 207 } |
| 207 | 208 |
| 208 void TestWebViewDelegate::SetAddressBarURL(const GURL& url) { | 209 void TestWebViewDelegate::SetAddressBarURL(const GURL& url) { |
| 209 const char* frameURL = url.spec().c_str(); | 210 const char* frameURL = url.spec().c_str(); |
| 210 NSString *address = [NSString stringWithUTF8String:frameURL]; | 211 NSString *address = [NSString stringWithUTF8String:frameURL]; |
| 211 [shell_->editWnd() setStringValue:address]; | 212 [shell_->editWnd() setStringValue:address]; |
| 212 } | 213 } |
| OLD | NEW |