OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #import "chrome/browser/ui/cocoa/menu_button.h" | 5 #import "chrome/browser/ui/cocoa/menu_button.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_nsobject.h" | 8 #include "base/memory/scoped_nsobject.h" |
9 #import "chrome/browser/ui/cocoa/clickhold_button_cell.h" | 9 #import "chrome/browser/ui/cocoa/clickhold_button_cell.h" |
| 10 #import "chrome/browser/ui/cocoa/nsview_additions.h" |
10 | 11 |
11 @interface MenuButton (Private) | 12 @interface MenuButton (Private) |
12 - (void)showMenu:(BOOL)isDragging; | 13 - (void)showMenu:(BOOL)isDragging; |
13 - (void)clickShowMenu:(id)sender; | 14 - (void)clickShowMenu:(id)sender; |
14 - (void)dragShowMenu:(id)sender; | 15 - (void)dragShowMenu:(id)sender; |
15 @end // @interface MenuButton (Private) | 16 @end // @interface MenuButton (Private) |
16 | 17 |
17 @implementation MenuButton | 18 @implementation MenuButton |
18 | 19 |
19 @synthesize openMenuOnClick = openMenuOnClick_; | 20 @synthesize openMenuOnClick = openMenuOnClick_; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 popUpCell_.reset([[NSPopUpButtonCell alloc] initTextCell:@"" | 131 popUpCell_.reset([[NSPopUpButtonCell alloc] initTextCell:@"" |
131 pullsDown:YES]); | 132 pullsDown:YES]); |
132 } | 133 } |
133 DCHECK(popUpCell_.get()); | 134 DCHECK(popUpCell_.get()); |
134 [popUpCell_ setMenu:[self attachedMenu]]; | 135 [popUpCell_ setMenu:[self attachedMenu]]; |
135 [popUpCell_ selectItem:nil]; | 136 [popUpCell_ selectItem:nil]; |
136 [popUpCell_ attachPopUpWithFrame:frame | 137 [popUpCell_ attachPopUpWithFrame:frame |
137 inView:self]; | 138 inView:self]; |
138 [popUpCell_ performClickWithFrame:frame | 139 [popUpCell_ performClickWithFrame:frame |
139 inView:self]; | 140 inView:self]; |
| 141 |
| 142 // Once the menu is dismissed send a mouseExited event if necessary. If the |
| 143 // menu action caused the super view to resize then we won't automatically |
| 144 // get a mouseExited event so we need to do this manually. |
| 145 // See http://crbug.com/82456 |
| 146 if (![self cr_isMouseInView]) { |
| 147 if ([[self cell] respondsToSelector:@selector(mouseExited:)]) |
| 148 [[self cell] mouseExited:nil]; |
| 149 } |
140 } | 150 } |
141 | 151 |
142 // Called when the button is clicked and released. (Shouldn't happen with | 152 // Called when the button is clicked and released. (Shouldn't happen with |
143 // timeout of 0, though there may be some strange pointing devices out there.) | 153 // timeout of 0, though there may be some strange pointing devices out there.) |
144 - (void)clickShowMenu:(id)sender { | 154 - (void)clickShowMenu:(id)sender { |
145 // This should only be called if openMenuOnClick has been set (which hooks | 155 // This should only be called if openMenuOnClick has been set (which hooks |
146 // up this target-action). | 156 // up this target-action). |
147 DCHECK(openMenuOnClick_); | 157 DCHECK(openMenuOnClick_); |
148 [self showMenu:NO]; | 158 [self showMenu:NO]; |
149 } | 159 } |
150 | 160 |
151 // Called when the button is clicked and dragged/held. | 161 // Called when the button is clicked and dragged/held. |
152 - (void)dragShowMenu:(id)sender { | 162 - (void)dragShowMenu:(id)sender { |
153 // We shouldn't get here unless the menu is enabled. | 163 // We shouldn't get here unless the menu is enabled. |
154 DCHECK([self attachedMenu]); | 164 DCHECK([self attachedMenu]); |
155 [self showMenu:YES]; | 165 [self showMenu:YES]; |
156 } | 166 } |
157 | 167 |
158 @end // @implementation MenuButton (Private) | 168 @end // @implementation MenuButton (Private) |
OLD | NEW |