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/sys_string_conversions.h" | 8 #include "base/sys_string_conversions.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "third_party/WebKit/WebKit/chromium/public/WebCursorInfo.h" | 10 #include "third_party/WebKit/WebKit/chromium/public/WebCursorInfo.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 return; | 41 return; |
42 // Display a HTML select menu. | 42 // Display a HTML select menu. |
43 | 43 |
44 std::vector<WebMenuItem> items; | 44 std::vector<WebMenuItem> items; |
45 for (size_t i = 0; i < popup_menu_info_->items.size(); ++i) | 45 for (size_t i = 0; i < popup_menu_info_->items.size(); ++i) |
46 items.push_back(popup_menu_info_->items[i]); | 46 items.push_back(popup_menu_info_->items[i]); |
47 | 47 |
48 int item_height = popup_menu_info_->itemHeight; | 48 int item_height = popup_menu_info_->itemHeight; |
49 double font_size = popup_menu_info_->itemFontSize; | 49 double font_size = popup_menu_info_->itemFontSize; |
50 int selected_index = popup_menu_info_->selectedIndex; | 50 int selected_index = popup_menu_info_->selectedIndex; |
| 51 bool right_aligned = popup_menu_info_->rightAligned; |
51 popup_menu_info_.reset(); // No longer needed. | 52 popup_menu_info_.reset(); // No longer needed. |
52 | 53 |
53 const WebRect& bounds = popup_bounds_; | 54 const WebRect& bounds = popup_bounds_; |
54 | 55 |
55 // Set up the menu position. | 56 // Set up the menu position. |
56 NSView* web_view = shell_->webViewWnd(); | 57 NSView* web_view = shell_->webViewWnd(); |
57 NSRect view_rect = [web_view bounds]; | 58 NSRect view_rect = [web_view bounds]; |
58 int y_offset = bounds.y + bounds.height; | 59 int y_offset = bounds.y + bounds.height; |
59 NSRect position = NSMakeRect(bounds.x, view_rect.size.height - y_offset, | 60 NSRect position = NSMakeRect(bounds.x, view_rect.size.height - y_offset, |
60 bounds.width, bounds.height); | 61 bounds.width, bounds.height); |
61 | 62 |
62 // Display the menu. | 63 // Display the menu. |
63 scoped_nsobject<WebMenuRunner> menu_runner; | 64 scoped_nsobject<WebMenuRunner> menu_runner; |
64 menu_runner.reset([[WebMenuRunner alloc] initWithItems:items | 65 menu_runner.reset([[WebMenuRunner alloc] initWithItems:items |
65 fontSize:font_size]); | 66 fontSize:font_size |
| 67 rightAligned:right_aligned]); |
66 | 68 |
67 [menu_runner runMenuInView:shell_->webViewWnd() | 69 [menu_runner runMenuInView:shell_->webViewWnd() |
68 withBounds:position | 70 withBounds:position |
69 initialIndex:selected_index]; | 71 initialIndex:selected_index]; |
70 | 72 |
71 // Get the selected item and forward to WebKit. WebKit expects an input event | 73 // Get the selected item and forward to WebKit. WebKit expects an input event |
72 // (mouse down, keyboard activity) for this, so we calculate the proper | 74 // (mouse down, keyboard activity) for this, so we calculate the proper |
73 // position based on the selected index and provided bounds. | 75 // position based on the selected index and provided bounds. |
74 WebWidgetHost* popup = shell_->popupHost(); | 76 WebWidgetHost* popup = shell_->popupHost(); |
75 int window_num = [shell_->mainWnd() windowNumber]; | 77 int window_num = [shell_->mainWnd() windowNumber]; |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 void TestWebViewDelegate::SetPageTitle(const std::wstring& title) { | 227 void TestWebViewDelegate::SetPageTitle(const std::wstring& title) { |
226 [[shell_->webViewHost()->view_handle() window] | 228 [[shell_->webViewHost()->view_handle() window] |
227 setTitle:[NSString stringWithUTF8String:WideToUTF8(title).c_str()]]; | 229 setTitle:[NSString stringWithUTF8String:WideToUTF8(title).c_str()]]; |
228 } | 230 } |
229 | 231 |
230 void TestWebViewDelegate::SetAddressBarURL(const GURL& url) { | 232 void TestWebViewDelegate::SetAddressBarURL(const GURL& url) { |
231 const char* frameURL = url.spec().c_str(); | 233 const char* frameURL = url.spec().c_str(); |
232 NSString *address = [NSString stringWithUTF8String:frameURL]; | 234 NSString *address = [NSString stringWithUTF8String:frameURL]; |
233 [shell_->editWnd() setStringValue:address]; | 235 [shell_->editWnd() setStringValue:address]; |
234 } | 236 } |
OLD | NEW |