OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/website_settings/permission_bubble_controller.h
" | 5 #import "chrome/browser/ui/cocoa/website_settings/permission_bubble_controller.h
" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/mac/bind_objc_block.h" | 9 #include "base/mac/bind_objc_block.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 CGFloat maxTitleWidth = 0; | 135 CGFloat maxTitleWidth = 0; |
136 for (NSMenuItem* item in [self itemArray]) { | 136 for (NSMenuItem* item in [self itemArray]) { |
137 NSSize size = SizeForWebsiteSettingsButtonTitle(self, [item title]); | 137 NSSize size = SizeForWebsiteSettingsButtonTitle(self, [item title]); |
138 maxTitleWidth = std::max(maxTitleWidth, size.width); | 138 maxTitleWidth = std::max(maxTitleWidth, size.width); |
139 } | 139 } |
140 return maxTitleWidth; | 140 return maxTitleWidth; |
141 } | 141 } |
142 | 142 |
143 @end | 143 @end |
144 | 144 |
145 // The window used for the permission bubble controller. | |
146 // Subclassed to allow browser-handled keyboard events to be passed from the | |
147 // permission bubble to its parent window, which is a browser window. | |
148 @interface PermissionBubbleWindow : InfoBubbleWindow | |
149 @end | |
150 | |
151 @implementation PermissionBubbleWindow | |
152 - (BOOL)performKeyEquivalent:(NSEvent*)event { | |
153 // Before forwarding to parent, handle locally. | |
154 if ([super performKeyEquivalent:event]) | |
155 return YES; | |
156 | |
157 // Only handle events if they should be forwarded to the parent window. | |
158 if ([self allowShareParentKeyState]) { | |
159 content::NativeWebKeyboardEvent wrappedEvent(event); | |
160 if ([BrowserWindowUtils shouldHandleKeyboardEvent:wrappedEvent]) { | |
161 // Turn off sharing of key window state while the keyboard event is | |
162 // processed. This avoids recursion - with the key window state shared, | |
163 // the parent window would just forward the event back to this class. | |
164 [self setAllowShareParentKeyState:NO]; | |
165 BOOL eventHandled = | |
166 [BrowserWindowUtils handleKeyboardEvent:event | |
167 inWindow:[self parentWindow]]; | |
168 [self setAllowShareParentKeyState:YES]; | |
169 return eventHandled; | |
170 } | |
171 } | |
172 return NO; | |
173 } | |
174 @end | |
175 | |
176 @interface PermissionBubbleController () | 145 @interface PermissionBubbleController () |
177 | 146 |
178 // Determines if the bubble has an anchor in a corner or no anchor at all. | 147 // Determines if the bubble has an anchor in a corner or no anchor at all. |
179 - (info_bubble::BubbleArrowLocation)getExpectedArrowLocation; | 148 - (info_bubble::BubbleArrowLocation)getExpectedArrowLocation; |
180 | 149 |
181 // Returns the expected parent for this bubble. | 150 // Returns the expected parent for this bubble. |
182 - (NSWindow*)getExpectedParentWindow; | 151 - (NSWindow*)getExpectedParentWindow; |
183 | 152 |
184 // Returns an autoreleased NSView displaying the icon and label for |request|. | 153 // Returns an autoreleased NSView displaying the icon and label for |request|. |
185 - (NSView*)labelForRequest:(PermissionRequest*)request; | 154 - (NSView*)labelForRequest:(PermissionRequest*)request; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 - (IBAction)cancel:(id)sender; | 201 - (IBAction)cancel:(id)sender; |
233 | 202 |
234 @end | 203 @end |
235 | 204 |
236 @implementation PermissionBubbleController | 205 @implementation PermissionBubbleController |
237 | 206 |
238 - (id)initWithBrowser:(Browser*)browser bridge:(PermissionBubbleCocoa*)bridge { | 207 - (id)initWithBrowser:(Browser*)browser bridge:(PermissionBubbleCocoa*)bridge { |
239 DCHECK(browser); | 208 DCHECK(browser); |
240 DCHECK(bridge); | 209 DCHECK(bridge); |
241 browser_ = browser; | 210 browser_ = browser; |
242 base::scoped_nsobject<PermissionBubbleWindow> window( | 211 base::scoped_nsobject<InfoBubbleWindow> window([[InfoBubbleWindow alloc] |
243 [[PermissionBubbleWindow alloc] | 212 initWithContentRect:ui::kWindowSizeDeterminedLater |
244 initWithContentRect:ui::kWindowSizeDeterminedLater | 213 styleMask:NSBorderlessWindowMask |
245 styleMask:NSBorderlessWindowMask | 214 backing:NSBackingStoreBuffered |
246 backing:NSBackingStoreBuffered | 215 defer:NO]); |
247 defer:NO]); | 216 |
248 [window setAllowedAnimations:info_bubble::kAnimateNone]; | 217 [window setAllowedAnimations:info_bubble::kAnimateNone]; |
249 [window setReleasedWhenClosed:NO]; | 218 [window setReleasedWhenClosed:NO]; |
250 if ((self = [super initWithWindow:window | 219 if ((self = [super initWithWindow:window |
251 parentWindow:[self getExpectedParentWindow] | 220 parentWindow:[self getExpectedParentWindow] |
252 anchoredAt:NSZeroPoint])) { | 221 anchoredAt:NSZeroPoint])) { |
253 [self setShouldCloseOnResignKey:NO]; | 222 [self setShouldCloseOnResignKey:NO]; |
254 [self setShouldOpenAsKeyWindow:YES]; | 223 [self setShouldOpenAsKeyWindow:YES]; |
255 [[self bubble] setArrowLocation:[self getExpectedArrowLocation]]; | 224 [[self bubble] setArrowLocation:[self getExpectedArrowLocation]]; |
256 bridge_ = bridge; | 225 bridge_ = bridge; |
257 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | 226 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 } | 646 } |
678 | 647 |
679 - (IBAction)cancel:(id)sender { | 648 - (IBAction)cancel:(id)sender { |
680 // This is triggered by ESC when the bubble has focus. | 649 // This is triggered by ESC when the bubble has focus. |
681 DCHECK(delegate_); | 650 DCHECK(delegate_); |
682 delegate_->Closing(); | 651 delegate_->Closing(); |
683 [super cancel:sender]; | 652 [super cancel:sender]; |
684 } | 653 } |
685 | 654 |
686 @end // implementation PermissionBubbleController | 655 @end // implementation PermissionBubbleController |
OLD | NEW |