Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/glue/webmenurunner_mac.h" | 5 #include "webkit/glue/webmenurunner_mac.h" |
| 6 | 6 |
| 7 #include "base/sys_string_conversions.h" | 7 #include "base/sys_string_conversions.h" |
| 8 | 8 |
| 9 namespace { | 9 namespace { |
| 10 | 10 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 keyEquivalent:@""]; | 85 keyEquivalent:@""]; |
| 86 [menuItem setEnabled:(item.enabled && item.type != WebMenuItem::GROUP)]; | 86 [menuItem setEnabled:(item.enabled && item.type != WebMenuItem::GROUP)]; |
| 87 [menuItem setTarget:self]; | 87 [menuItem setTarget:self]; |
| 88 if (attrs) { | 88 if (attrs) { |
| 89 scoped_nsobject<NSAttributedString> attrTitle( | 89 scoped_nsobject<NSAttributedString> attrTitle( |
| 90 [[NSAttributedString alloc] initWithString:title | 90 [[NSAttributedString alloc] initWithString:title |
| 91 attributes:attrs]); | 91 attributes:attrs]); |
| 92 [menuItem setAttributedTitle:attrTitle]; | 92 [menuItem setAttributedTitle:attrTitle]; |
| 93 } | 93 } |
| 94 if (gNewNSMenuAPI) | 94 if (gNewNSMenuAPI) |
| 95 [menuItem setTag:[menu_ numberOfItems] - 1]; | 95 [menuItem setTag:[menu_ numberOfItems] - 1]; |
|
Scott Hess - ex-Googler
2010/12/01 01:29:51
You can safely make this unconditional.
Jay Civelli
2010/12/01 02:07:13
Done.
| |
| 96 } | 96 } |
| 97 | 97 |
| 98 // Reflects the result of the user's interaction with the popup menu. If NO, the | 98 // Reflects the result of the user's interaction with the popup menu. If NO, the |
| 99 // menu was dismissed without the user choosing an item, which can happen if the | 99 // menu was dismissed without the user choosing an item, which can happen if the |
| 100 // user clicked outside the menu region or hit the escape key. If YES, the user | 100 // user clicked outside the menu region or hit the escape key. If YES, the user |
| 101 // selected an item from the menu. | 101 // selected an item from the menu. |
| 102 - (BOOL)menuItemWasChosen { | 102 - (BOOL)menuItemWasChosen { |
| 103 return menuItemWasChosen_; | 103 return menuItemWasChosen_; |
| 104 } | 104 } |
| 105 | 105 |
| 106 - (void)menuItemSelected:(id)sender { | 106 - (void)menuItemSelected:(id)sender { |
| 107 menuItemWasChosen_ = YES; | 107 menuItemWasChosen_ = YES; |
| 108 if (gNewNSMenuAPI) | 108 if (gNewNSMenuAPI) |
| 109 index_ = [sender tag]; | 109 index_ = [sender tag]; |
| 110 } | 110 } |
| 111 | 111 |
| 112 - (void)runMenuInView:(NSView*)view | 112 - (void)runMenuInView:(NSView*)view |
| 113 withBounds:(NSRect)bounds | 113 withBounds:(NSRect)bounds |
| 114 initialIndex:(int)index { | 114 initialIndex:(int)index { |
| 115 if (gNewNSMenuAPI) { | 115 if (gNewNSMenuAPI) { |
| 116 NSMenuItem* selectedItem = [menu_ itemAtIndex:index]; | 116 int actualIndex; |
| 117 [selectedItem setState:NSOnState]; | 117 if (index < 0 || index > [menu_ numberOfItems]) { |
| 118 actualIndex = 0; | |
| 119 } else { | |
| 120 actualIndex = index; | |
| 121 } | |
| 122 NSMenuItem* selectedItem = [menu_ itemAtIndex:actualIndex]; | |
| 123 if (actualIndex == index) | |
| 124 [selectedItem setState:NSOnState]; | |
|
Scott Hess - ex-Googler
2010/12/01 01:29:51
If I understand this correctly, what you want is t
Jay Civelli
2010/12/01 02:07:13
Good idea. Done.
| |
| 118 NSPoint anchor = NSMakePoint(NSMinX(bounds) + kPopupXOffset, | 125 NSPoint anchor = NSMakePoint(NSMinX(bounds) + kPopupXOffset, |
| 119 NSMaxY(bounds)); | 126 NSMaxY(bounds)); |
| 120 [menu_ popUpMenuPositioningItem:selectedItem | 127 [menu_ popUpMenuPositioningItem:selectedItem |
| 121 atLocation:anchor | 128 atLocation:anchor |
| 122 inView:view]; | 129 inView:view]; |
| 123 } else { | 130 } else { |
| 124 // Set up the button cell, converting to NSView coordinates. The menu is | 131 // Set up the button cell, converting to NSView coordinates. The menu is |
|
Jay Civelli
2010/12/01 01:08:52
I am not sure how to test that case? Should I just
Scott Hess - ex-Googler
2010/12/01 01:29:51
OMG.
I guess that's about your only option. Or r
Jay Civelli
2010/12/01 02:07:13
OK, I just hacked the value.
The API for NSPopUpBu
| |
| 125 // positioned such that the currently selected menu item appears over the | 132 // positioned such that the currently selected menu item appears over the |
| 126 // popup button, which is the expected Mac popup menu behavior. | 133 // popup button, which is the expected Mac popup menu behavior. |
| 127 NSPopUpButtonCell* button = [[NSPopUpButtonCell alloc] initTextCell:@"" | 134 NSPopUpButtonCell* button = [[NSPopUpButtonCell alloc] initTextCell:@"" |
| 128 pullsDown:NO]; | 135 pullsDown:NO]; |
| 129 [button autorelease]; | 136 [button autorelease]; |
| 130 [button setMenu:menu_]; | 137 [button setMenu:menu_]; |
| 131 [button selectItemAtIndex:index]; | 138 [button selectItemAtIndex:index]; |
| 132 [button setFont:[NSFont menuFontOfSize:fontSize_]]; | 139 [button setFont:[NSFont menuFontOfSize:fontSize_]]; |
| 133 | 140 |
| 134 // Create a dummy view to associate the popup with, since the OS will use | 141 // Create a dummy view to associate the popup with, since the OS will use |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 characters:@"" | 210 characters:@"" |
| 204 charactersIgnoringModifiers:escape_str | 211 charactersIgnoringModifiers:escape_str |
| 205 isARepeat:NO | 212 isARepeat:NO |
| 206 keyCode:0x1B]; | 213 keyCode:0x1B]; |
| 207 } | 214 } |
| 208 | 215 |
| 209 return event; | 216 return event; |
| 210 } | 217 } |
| 211 | 218 |
| 212 } // namespace webkit_glue | 219 } // namespace webkit_glue |
| OLD | NEW |