Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: webkit/tools/test_shell/mac/test_webview_delegate.mm

Issue 67018: Chrome side of the WebKit popup changes. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/glue/webwidget_impl.cc ('k') | webkit/tools/test_shell/test_webview_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/string_util.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/tools/test_shell/test_shell.h" 15 #include "webkit/tools/test_shell/test_shell.h"
16 16
17 using WebKit::WebRect; 17 using WebKit::WebRect;
18 18
19 // MenuDelegate ---------------------------------------------------------------- 19 // MenuDelegate ----------------------------------------------------------------
20 // A class for determining whether an item was selected from an HTML select 20 // A class for determining whether an item was selected from an HTML select
21 // control, or if the menu was dismissed without making a selection. If a menu 21 // control, or if the menu was dismissed without making a selection. If a menu
22 // item is selected, MenuDelegate is informed and sets a flag which can be 22 // item is selected, MenuDelegate is informed and sets a flag which can be
23 // queried after the menu has finished running. 23 // queried after the menu has finished running.
24 24
25 @interface MenuDelegate : NSObject { 25 @interface MenuDelegate : NSObject {
26 @private 26 @private
27 NSMenu* menu_; // Non-owning 27 NSMenu* menu_; // Non-owning
28 BOOL menuItemWasChosen_; 28 BOOL menuItemWasChosen_;
29 } 29 }
30 - (id)initWithItems:(const std::vector<MenuItem>&)items forMenu:(NSMenu*)menu; 30 - (id)initWithItems:(const std::vector<WebMenuItem>&)items
31 - (void)addItem:(const MenuItem&)item; 31 forMenu:(NSMenu*)menu;
32 - (void)addItem:(const WebMenuItem&)item;
32 - (BOOL)menuItemWasChosen; 33 - (BOOL)menuItemWasChosen;
33 - (void)menuItemSelected:(id)sender; 34 - (void)menuItemSelected:(id)sender;
34 @end 35 @end
35 36
36 @implementation MenuDelegate 37 @implementation MenuDelegate
37 38
38 - (id)initWithItems:(const std::vector<MenuItem>&)items forMenu:(NSMenu*)menu { 39 - (id)initWithItems:(const std::vector<WebMenuItem>&)items
40 forMenu:(NSMenu*)menu {
39 if ((self = [super init])) { 41 if ((self = [super init])) {
40 menu_ = menu; 42 menu_ = menu;
41 menuItemWasChosen_ = NO; 43 menuItemWasChosen_ = NO;
42 for (int i = 0; i < static_cast<int>(items.size()); ++i) 44 for (int i = 0; i < static_cast<int>(items.size()); ++i)
43 [self addItem:items[i]]; 45 [self addItem:items[i]];
44 } 46 }
45 return self; 47 return self;
46 } 48 }
47 49
48 - (void)addItem:(const MenuItem&)item { 50 - (void)addItem:(const WebMenuItem&)item {
49 if (item.type == MenuItem::SEPARATOR) { 51 if (item.type == WebMenuItem::SEPARATOR) {
50 [menu_ addItem:[NSMenuItem separatorItem]]; 52 [menu_ addItem:[NSMenuItem separatorItem]];
51 return; 53 return;
52 } 54 }
53 55
54 NSString* title = base::SysUTF16ToNSString(item.label); 56 NSString* title = base::SysUTF16ToNSString(item.label);
55 NSMenuItem* menu_item = [menu_ addItemWithTitle:title 57 NSMenuItem* menu_item = [menu_ addItemWithTitle:title
56 action:@selector(menuItemSelected:) 58 action:@selector(menuItemSelected:)
57 keyEquivalent:@""]; 59 keyEquivalent:@""];
58 [menu_item setEnabled:(item.enabled && item.type != MenuItem::GROUP)]; 60 [menu_item setEnabled:(item.enabled && item.type != WebMenuItem::GROUP)];
59 [menu_item setTarget:self]; 61 [menu_item setTarget:self];
60 } 62 }
61 63
62 // Reflects the result of the user's interaction with the popup menu. If NO, the 64 // Reflects the result of the user's interaction with the popup menu. If NO, the
63 // menu was dismissed without the user choosing an item, which can happen if the 65 // menu was dismissed without the user choosing an item, which can happen if the
64 // user clicked outside the menu region or hit the escape key. If YES, the user 66 // user clicked outside the menu region or hit the escape key. If YES, the user
65 // selected an item from the menu. 67 // selected an item from the menu.
66 - (BOOL)menuItemWasChosen { 68 - (BOOL)menuItemWasChosen {
67 return menuItemWasChosen_; 69 return menuItemWasChosen_;
68 } 70 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 } 117 }
116 118
117 119
118 // WebWidgetDelegate --------------------------------------------------------- 120 // WebWidgetDelegate ---------------------------------------------------------
119 121
120 void TestWebViewDelegate::Show(WebWidget* webview, 122 void TestWebViewDelegate::Show(WebWidget* webview,
121 WindowOpenDisposition disposition) { 123 WindowOpenDisposition disposition) {
122 } 124 }
123 125
124 // Display a HTML select menu. 126 // Display a HTML select menu.
125 void TestWebViewDelegate::ShowWithItems( 127 void TestWebViewDelegate::ShowAsPopupWithItems(
126 WebWidget* webview, 128 WebWidget* webview,
127 const WebRect& bounds, 129 const WebRect& bounds,
128 int item_height, 130 int item_height,
129 int selected_index, 131 int selected_index,
130 const std::vector<MenuItem>& items) { 132 const std::vector<WebMenuItem>& items) {
131 // Populate the menu. 133 // Populate the menu.
132 NSMenu* menu = [[[NSMenu alloc] initWithTitle:@""] autorelease]; 134 NSMenu* menu = [[[NSMenu alloc] initWithTitle:@""] autorelease];
133 [menu setAutoenablesItems:NO]; 135 [menu setAutoenablesItems:NO];
134 MenuDelegate* menu_delegate = 136 MenuDelegate* menu_delegate =
135 [[[MenuDelegate alloc] initWithItems:items forMenu:menu] autorelease]; 137 [[[MenuDelegate alloc] initWithItems:items forMenu:menu] autorelease];
136 138
137 // Set up the button cell, converting to NSView coordinates. The menu is 139 // Set up the button cell, converting to NSView coordinates. The menu is
138 // positioned such that the currently selected menu item appears over the 140 // positioned such that the currently selected menu item appears over the
139 // popup button, which is the expected Mac popup menu behavior. 141 // popup button, which is the expected Mac popup menu behavior.
140 NSPopUpButtonCell* button = [[NSPopUpButtonCell alloc] initTextCell:@"" 142 NSPopUpButtonCell* button = [[NSPopUpButtonCell alloc] initTextCell:@""
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 void TestWebViewDelegate::SetPageTitle(const std::wstring& title) { 306 void TestWebViewDelegate::SetPageTitle(const std::wstring& title) {
305 [[shell_->webViewHost()->view_handle() window] 307 [[shell_->webViewHost()->view_handle() window]
306 setTitle:[NSString stringWithUTF8String:WideToUTF8(title).c_str()]]; 308 setTitle:[NSString stringWithUTF8String:WideToUTF8(title).c_str()]];
307 } 309 }
308 310
309 void TestWebViewDelegate::SetAddressBarURL(const GURL& url) { 311 void TestWebViewDelegate::SetAddressBarURL(const GURL& url) {
310 const char* frameURL = url.spec().c_str(); 312 const char* frameURL = url.spec().c_str();
311 NSString *address = [NSString stringWithUTF8String:frameURL]; 313 NSString *address = [NSString stringWithUTF8String:frameURL];
312 [shell_->editWnd() setStringValue:address]; 314 [shell_->editWnd() setStringValue:address];
313 } 315 }
OLDNEW
« no previous file with comments | « webkit/glue/webwidget_impl.cc ('k') | webkit/tools/test_shell/test_webview_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698