Chromium Code Reviews| 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/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 // Adjust the size to fit the current title. Using only -sizeToFit leaves | 120 // Adjust the size to fit the current title. Using only -sizeToFit leaves |
| 121 // an ugly amount of whitespace between the title and the arrows because it | 121 // an ugly amount of whitespace between the title and the arrows because it |
| 122 // will fit to the largest element in the menu, not just the selected item. | 122 // will fit to the largest element in the menu, not just the selected item. |
| 123 [self setFrameSize:SizeForWebsiteSettingsButtonTitle(self, [self title])]; | 123 [self setFrameSize:SizeForWebsiteSettingsButtonTitle(self, [self title])]; |
| 124 } | 124 } |
| 125 return self; | 125 return self; |
| 126 } | 126 } |
| 127 | 127 |
| 128 @end | 128 @end |
| 129 | 129 |
| 130 // The window used for the permission bubble controller. | |
| 131 // Subclassed to allow browser-handled keyboard events to be passed from the | |
| 132 // permission bubble to its parent window, which is a browser window. | |
|
groby-ooo-7-16
2014/05/02 01:43:25
If the parent window is a browser window, I believ
leng
2014/05/02 16:24:58
Thanks, done.
| |
| 133 @interface PermissionBubbleWindow : InfoBubbleWindow | |
| 134 @end | |
| 135 | |
| 136 @implementation PermissionBubbleWindow | |
| 137 - (BOOL)performKeyEquivalent:(NSEvent*)event { | |
| 138 ChromeEventProcessingWindow* eventWindow = | |
| 139 base::mac::ObjCCastStrict<ChromeEventProcessingWindow>( | |
| 140 [self parentWindow]); | |
| 141 return [eventWindow performKeyEquivalent:event]; | |
| 142 } | |
| 143 @end | |
| 144 | |
| 130 @interface PermissionBubbleController () | 145 @interface PermissionBubbleController () |
| 131 | 146 |
| 132 // Returns an autoreleased NSView displaying the icon and label for |request|. | 147 // Returns an autoreleased NSView displaying the icon and label for |request|. |
| 133 - (NSView*)labelForRequest:(PermissionBubbleRequest*)request; | 148 - (NSView*)labelForRequest:(PermissionBubbleRequest*)request; |
| 134 | 149 |
| 135 // Returns an autoreleased NSView displaying the title for the bubble | 150 // Returns an autoreleased NSView displaying the title for the bubble |
| 136 // requesting settings for |host|. | 151 // requesting settings for |host|. |
| 137 - (NSView*)titleWithHostname:(const std::string&)host; | 152 - (NSView*)titleWithHostname:(const std::string&)host; |
| 138 | 153 |
| 139 // Returns an autoreleased NSView displaying a menu for |request|. The | 154 // Returns an autoreleased NSView displaying a menu for |request|. The |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB; | 198 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB; |
| 184 | 199 |
| 185 @end | 200 @end |
| 186 | 201 |
| 187 @implementation PermissionBubbleController | 202 @implementation PermissionBubbleController |
| 188 | 203 |
| 189 - (id)initWithParentWindow:(NSWindow*)parentWindow | 204 - (id)initWithParentWindow:(NSWindow*)parentWindow |
| 190 bridge:(PermissionBubbleCocoa*)bridge { | 205 bridge:(PermissionBubbleCocoa*)bridge { |
| 191 DCHECK(parentWindow); | 206 DCHECK(parentWindow); |
| 192 DCHECK(bridge); | 207 DCHECK(bridge); |
| 193 base::scoped_nsobject<InfoBubbleWindow> window([[InfoBubbleWindow alloc] | 208 base::scoped_nsobject<PermissionBubbleWindow> window( |
| 194 initWithContentRect:ui::kWindowSizeDeterminedLater | 209 [[PermissionBubbleWindow alloc] |
| 195 styleMask:NSBorderlessWindowMask | 210 initWithContentRect:ui::kWindowSizeDeterminedLater |
| 196 backing:NSBackingStoreBuffered | 211 styleMask:NSBorderlessWindowMask |
| 197 defer:NO]); | 212 backing:NSBackingStoreBuffered |
| 213 defer:NO]); | |
| 198 [window setAllowedAnimations:info_bubble::kAnimateNone]; | 214 [window setAllowedAnimations:info_bubble::kAnimateNone]; |
| 199 if ((self = [super initWithWindow:window | 215 if ((self = [super initWithWindow:window |
| 200 parentWindow:parentWindow | 216 parentWindow:parentWindow |
| 201 anchoredAt:NSZeroPoint])) { | 217 anchoredAt:NSZeroPoint])) { |
| 202 [self setShouldCloseOnResignKey:NO]; | 218 [self setShouldCloseOnResignKey:NO]; |
| 203 [[self bubble] setArrowLocation:info_bubble::kTopLeft]; | 219 [[self bubble] setArrowLocation:info_bubble::kTopLeft]; |
| 204 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; | 220 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; |
| 205 [nc addObserver:self | 221 [nc addObserver:self |
| 206 selector:@selector(parentWindowDidResize:) | 222 selector:@selector(parentWindowDidResize:) |
| 207 name:NSWindowDidResizeNotification | 223 name:NSWindowDidResizeNotification |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 535 | 551 |
| 536 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB { | 552 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB { |
| 537 NSRect frameA = [viewA frame]; | 553 NSRect frameA = [viewA frame]; |
| 538 NSRect frameB = [viewB frame]; | 554 NSRect frameB = [viewB frame]; |
| 539 frameA.origin.y = | 555 frameA.origin.y = |
| 540 NSMinY(frameB) + std::floor((NSHeight(frameB) - NSHeight(frameA)) / 2); | 556 NSMinY(frameB) + std::floor((NSHeight(frameB) - NSHeight(frameA)) / 2); |
| 541 [viewA setFrameOrigin:frameA.origin]; | 557 [viewA setFrameOrigin:frameA.origin]; |
| 542 } | 558 } |
| 543 | 559 |
| 544 @end // implementation PermissionBubbleController | 560 @end // implementation PermissionBubbleController |
| OLD | NEW |