| 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/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/browser_finder.h" | 13 #include "chrome/browser/ui/browser_finder.h" |
| 14 #include "chrome/browser/ui/browser_window.h" |
| 14 #import "chrome/browser/ui/chrome_style.h" | 15 #import "chrome/browser/ui/chrome_style.h" |
| 15 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 16 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 16 #import "chrome/browser/ui/cocoa/browser_window_utils.h" | 17 #import "chrome/browser/ui/cocoa/browser_window_utils.h" |
| 17 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" | 18 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" |
| 18 #import "chrome/browser/ui/cocoa/hover_close_button.h" | 19 #import "chrome/browser/ui/cocoa/hover_close_button.h" |
| 19 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 20 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
| 20 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 21 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
| 22 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| 21 #include "chrome/browser/ui/cocoa/website_settings/permission_bubble_cocoa.h" | 23 #include "chrome/browser/ui/cocoa/website_settings/permission_bubble_cocoa.h" |
| 22 #include "chrome/browser/ui/cocoa/website_settings/permission_selector_button.h" | 24 #include "chrome/browser/ui/cocoa/website_settings/permission_selector_button.h" |
| 23 #include "chrome/browser/ui/cocoa/website_settings/split_block_button.h" | 25 #include "chrome/browser/ui/cocoa/website_settings/split_block_button.h" |
| 24 #include "chrome/browser/ui/cocoa/website_settings/website_settings_utils_cocoa.
h" | 26 #include "chrome/browser/ui/cocoa/website_settings/website_settings_utils_cocoa.
h" |
| 27 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" |
| 25 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" | 28 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" |
| 26 #include "chrome/browser/ui/website_settings/permission_bubble_view.h" | |
| 27 #include "chrome/browser/ui/website_settings/permission_menu_model.h" | 29 #include "chrome/browser/ui/website_settings/permission_menu_model.h" |
| 28 #include "chrome/grit/generated_resources.h" | 30 #include "chrome/grit/generated_resources.h" |
| 29 #include "content/public/browser/native_web_keyboard_event.h" | 31 #include "content/public/browser/native_web_keyboard_event.h" |
| 30 #include "content/public/browser/user_metrics.h" | 32 #include "content/public/browser/user_metrics.h" |
| 31 #include "skia/ext/skia_utils_mac.h" | 33 #include "skia/ext/skia_utils_mac.h" |
| 32 #import "ui/base/cocoa/controls/hyperlink_text_view.h" | 34 #import "ui/base/cocoa/controls/hyperlink_text_view.h" |
| 33 #import "ui/base/cocoa/menu_controller.h" | 35 #import "ui/base/cocoa/menu_controller.h" |
| 34 #include "ui/base/cocoa/window_size_constants.h" | 36 #include "ui/base/cocoa/window_size_constants.h" |
| 35 #include "ui/base/l10n/l10n_util_mac.h" | 37 #include "ui/base/l10n/l10n_util_mac.h" |
| 36 #include "ui/base/models/simple_menu_model.h" | 38 #include "ui/base/models/simple_menu_model.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 // multiple permissions in the bubble. | 77 // multiple permissions in the bubble. |
| 76 @interface AllowBlockMenuButton : NSPopUpButton { | 78 @interface AllowBlockMenuButton : NSPopUpButton { |
| 77 @private | 79 @private |
| 78 scoped_ptr<PermissionMenuModel> menuModel_; | 80 scoped_ptr<PermissionMenuModel> menuModel_; |
| 79 base::scoped_nsobject<MenuController> menuController_; | 81 base::scoped_nsobject<MenuController> menuController_; |
| 80 } | 82 } |
| 81 | 83 |
| 82 - (id)initForURL:(const GURL&)url | 84 - (id)initForURL:(const GURL&)url |
| 83 allowed:(BOOL)allow | 85 allowed:(BOOL)allow |
| 84 index:(int)index | 86 index:(int)index |
| 85 delegate:(PermissionBubbleView::Delegate*)delegate; | 87 manager:(PermissionBubbleManager*)manager; |
| 86 | 88 |
| 87 // Returns the maximum width of its possible titles. | 89 // Returns the maximum width of its possible titles. |
| 88 - (CGFloat)maximumTitleWidth; | 90 - (CGFloat)maximumTitleWidth; |
| 89 @end | 91 @end |
| 90 | 92 |
| 91 @implementation AllowBlockMenuButton | 93 @implementation AllowBlockMenuButton |
| 92 | 94 |
| 93 - (id)initForURL:(const GURL&)url | 95 - (id)initForURL:(const GURL&)url |
| 94 allowed:(BOOL)allow | 96 allowed:(BOOL)allow |
| 95 index:(int)index | 97 index:(int)index |
| 96 delegate:(PermissionBubbleView::Delegate*)delegate { | 98 manager:(PermissionBubbleManager*)manager { |
| 97 if (self = [super initWithFrame:NSZeroRect pullsDown:NO]) { | 99 if (self = [super initWithFrame:NSZeroRect pullsDown:NO]) { |
| 98 ContentSetting setting = | 100 ContentSetting setting = |
| 99 allow ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 101 allow ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
| 100 [self setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; | 102 [self setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; |
| 101 [self setBordered:NO]; | 103 [self setBordered:NO]; |
| 102 | 104 |
| 103 __block PermissionBubbleView::Delegate* blockDelegate = delegate; | 105 __block PermissionBubbleManager* blockManager = manager; |
| 104 __block AllowBlockMenuButton* blockSelf = self; | 106 __block AllowBlockMenuButton* blockSelf = self; |
| 105 PermissionMenuModel::ChangeCallback changeCallback = | 107 PermissionMenuModel::ChangeCallback changeCallback = |
| 106 base::BindBlock(^(const WebsiteSettingsUI::PermissionInfo& permission) { | 108 base::BindBlock(^(const WebsiteSettingsUI::PermissionInfo& permission) { |
| 107 blockDelegate->ToggleAccept( | 109 blockManager->ToggleAccept( |
| 108 index, permission.setting == CONTENT_SETTING_ALLOW); | 110 index, permission.setting == CONTENT_SETTING_ALLOW); |
| 109 [blockSelf setFrameSize: | 111 [blockSelf setFrameSize:SizeForWebsiteSettingsButtonTitle( |
| 110 SizeForWebsiteSettingsButtonTitle(blockSelf, | 112 blockSelf, [blockSelf title])]; |
| 111 [blockSelf title])]; | |
| 112 }); | 113 }); |
| 113 | 114 |
| 114 menuModel_.reset(new PermissionMenuModel(url, setting, changeCallback)); | 115 menuModel_.reset(new PermissionMenuModel(url, setting, changeCallback)); |
| 115 menuController_.reset([[MenuController alloc] initWithModel:menuModel_.get() | 116 menuController_.reset([[MenuController alloc] initWithModel:menuModel_.get() |
| 116 useWithPopUpButtonCell:NO]); | 117 useWithPopUpButtonCell:NO]); |
| 117 [self setMenu:[menuController_ menu]]; | 118 [self setMenu:[menuController_ menu]]; |
| 118 [self selectItemAtIndex:menuModel_->GetIndexOfCommandId(setting)]; | 119 [self selectItemAtIndex:menuModel_->GetIndexOfCommandId(setting)]; |
| 119 // Although the frame is reset, below, this sizes the cell properly. | 120 // Although the frame is reset, below, this sizes the cell properly. |
| 120 [self sizeToFit]; | 121 [self sizeToFit]; |
| 121 // Adjust the size to fit the current title. Using only -sizeToFit leaves | 122 // Adjust the size to fit the current title. Using only -sizeToFit leaves |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 + (CGFloat)matchWidthsOf:(NSView*)viewA andOf:(NSView*)viewB; | 211 + (CGFloat)matchWidthsOf:(NSView*)viewA andOf:(NSView*)viewB; |
| 211 | 212 |
| 212 // Sets the offset of |viewA| so that its vertical center is aligned with the | 213 // Sets the offset of |viewA| so that its vertical center is aligned with the |
| 213 // vertical center of |viewB|. | 214 // vertical center of |viewB|. |
| 214 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB; | 215 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB; |
| 215 | 216 |
| 216 @end | 217 @end |
| 217 | 218 |
| 218 @implementation PermissionBubbleController | 219 @implementation PermissionBubbleController |
| 219 | 220 |
| 220 - (id)initWithParentWindow:(NSWindow*)parentWindow | 221 - (id)initWithBrowser:(Browser*)browser bridge:(PermissionBubbleCocoa*)bridge { |
| 221 bridge:(PermissionBubbleCocoa*)bridge { | 222 DCHECK(browser); |
| 222 DCHECK(parentWindow); | |
| 223 DCHECK(bridge); | 223 DCHECK(bridge); |
| 224 browser_ = browser; |
| 224 base::scoped_nsobject<PermissionBubbleWindow> window( | 225 base::scoped_nsobject<PermissionBubbleWindow> window( |
| 225 [[PermissionBubbleWindow alloc] | 226 [[PermissionBubbleWindow alloc] |
| 226 initWithContentRect:ui::kWindowSizeDeterminedLater | 227 initWithContentRect:ui::kWindowSizeDeterminedLater |
| 227 styleMask:NSBorderlessWindowMask | 228 styleMask:NSBorderlessWindowMask |
| 228 backing:NSBackingStoreBuffered | 229 backing:NSBackingStoreBuffered |
| 229 defer:NO]); | 230 defer:NO]); |
| 230 [window setAllowedAnimations:info_bubble::kAnimateNone]; | 231 [window setAllowedAnimations:info_bubble::kAnimateNone]; |
| 231 [window setReleasedWhenClosed:NO]; | 232 [window setReleasedWhenClosed:NO]; |
| 232 if ((self = [super initWithWindow:window | 233 if ((self = [super initWithWindow:window |
| 233 parentWindow:parentWindow | 234 parentWindow:[self getExpectedParentWindow] |
| 234 anchoredAt:NSZeroPoint])) { | 235 anchoredAt:NSZeroPoint])) { |
| 235 [self setShouldCloseOnResignKey:NO]; | 236 [self setShouldCloseOnResignKey:NO]; |
| 236 [self setShouldOpenAsKeyWindow:YES]; | 237 [self setShouldOpenAsKeyWindow:YES]; |
| 237 [[self bubble] setArrowLocation:bridge->GetArrowLocation()]; | 238 [[self bubble] setArrowLocation:[self getExpectedArrowLocation]]; |
| 238 bridge_ = bridge; | 239 bridge_ = bridge; |
| 239 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | 240 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
| 240 [center addObserver:self | 241 [center addObserver:self |
| 241 selector:@selector(parentWindowDidMove:) | 242 selector:@selector(parentWindowDidMove:) |
| 242 name:NSWindowDidMoveNotification | 243 name:NSWindowDidMoveNotification |
| 243 object:parentWindow]; | 244 object:[self getExpectedParentWindow]]; |
| 244 } | 245 } |
| 245 return self; | 246 return self; |
| 246 } | 247 } |
| 247 | 248 |
| 248 - (void)windowWillClose:(NSNotification*)notification { | 249 - (void)windowWillClose:(NSNotification*)notification { |
| 249 bridge_->OnBubbleClosing(); | 250 bridge_->OnBubbleClosing(); |
| 250 [super windowWillClose:notification]; | 251 [super windowWillClose:notification]; |
| 251 } | 252 } |
| 252 | 253 |
| 253 - (void)parentWindowWillToggleFullScreen:(NSNotification*)notification { | 254 - (void)parentWindowWillToggleFullScreen:(NSNotification*)notification { |
| 254 // Override the base class implementation, which would have closed the bubble. | 255 // Override the base class implementation, which would have closed the bubble. |
| 255 } | 256 } |
| 256 | 257 |
| 257 - (void)parentWindowDidResize:(NSNotification*)notification { | 258 - (void)parentWindowDidResize:(NSNotification*)notification { |
| 258 DCHECK(bridge_); | 259 DCHECK(bridge_); |
| 259 [self setAnchorPoint:bridge_->GetAnchorPoint()]; | 260 [self setAnchorPoint:[self getExpectedAnchorPoint]]; |
| 260 } | 261 } |
| 261 | 262 |
| 262 - (void)parentWindowDidMove:(NSNotification*)notification { | 263 - (void)parentWindowDidMove:(NSNotification*)notification { |
| 263 DCHECK(bridge_); | 264 DCHECK(bridge_); |
| 264 [self setAnchorPoint:bridge_->GetAnchorPoint()]; | 265 [self setAnchorPoint:[self getExpectedAnchorPoint]]; |
| 265 } | 266 } |
| 266 | 267 |
| 267 - (void)showAtAnchor:(NSPoint)anchorPoint | 268 - (void)showWithManager:(PermissionBubbleManager*)manager |
| 268 withDelegate:(PermissionBubbleView::Delegate*)delegate | 269 forRequests:(const std::vector<PermissionBubbleRequest*>&)requests |
| 269 forRequests:(const std::vector<PermissionBubbleRequest*>&)requests | 270 acceptStates:(const std::vector<bool>&)acceptStates { |
| 270 acceptStates:(const std::vector<bool>&)acceptStates { | |
| 271 DCHECK(!requests.empty()); | 271 DCHECK(!requests.empty()); |
| 272 DCHECK(delegate); | 272 DCHECK(manager); |
| 273 delegate_ = delegate; | 273 manager_ = manager; |
| 274 | 274 |
| 275 NSView* contentView = [[self window] contentView]; | 275 NSView* contentView = [[self window] contentView]; |
| 276 [contentView setSubviews:@[]]; | 276 [contentView setSubviews:@[]]; |
| 277 | 277 |
| 278 BOOL singlePermission = requests.size() == 1; | 278 BOOL singlePermission = requests.size() == 1; |
| 279 | 279 |
| 280 // Create one button to use as a guide for the permissions' y-offsets. | 280 // Create one button to use as a guide for the permissions' y-offsets. |
| 281 base::scoped_nsobject<NSView> allowOrOkButton; | 281 base::scoped_nsobject<NSView> allowOrOkButton; |
| 282 if (singlePermission) { | 282 if (singlePermission) { |
| 283 NSString* allowTitle = l10n_util::GetNSString(IDS_PERMISSION_ALLOW); | 283 NSString* allowTitle = l10n_util::GetNSString(IDS_PERMISSION_ALLOW); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 // within -setAnchorPoint) causes flickering. Avoid the flickering by | 411 // within -setAnchorPoint) causes flickering. Avoid the flickering by |
| 412 // manually adjusting the new frame's origin so that the top left stays the | 412 // manually adjusting the new frame's origin so that the top left stays the |
| 413 // same, and only calling -setFrame. | 413 // same, and only calling -setFrame. |
| 414 NSRect currentWindowFrame = [[self window] frame]; | 414 NSRect currentWindowFrame = [[self window] frame]; |
| 415 bubbleFrame.origin = currentWindowFrame.origin; | 415 bubbleFrame.origin = currentWindowFrame.origin; |
| 416 bubbleFrame.origin.y = bubbleFrame.origin.y + | 416 bubbleFrame.origin.y = bubbleFrame.origin.y + |
| 417 currentWindowFrame.size.height - bubbleFrame.size.height; | 417 currentWindowFrame.size.height - bubbleFrame.size.height; |
| 418 [[self window] setFrame:bubbleFrame display:YES]; | 418 [[self window] setFrame:bubbleFrame display:YES]; |
| 419 } else { | 419 } else { |
| 420 [[self window] setFrame:bubbleFrame display:NO]; | 420 [[self window] setFrame:bubbleFrame display:NO]; |
| 421 [self setAnchorPoint:anchorPoint]; | 421 [self setAnchorPoint:[self getExpectedAnchorPoint]]; |
| 422 [self showWindow:nil]; | 422 [self showWindow:nil]; |
| 423 [[self window] makeFirstResponder:nil]; | 423 [[self window] makeFirstResponder:nil]; |
| 424 [[self window] setInitialFirstResponder:allowOrOkButton.get()]; | 424 [[self window] setInitialFirstResponder:allowOrOkButton.get()]; |
| 425 } | 425 } |
| 426 } | 426 } |
| 427 | 427 |
| 428 - (void)updateAnchorPosition { |
| 429 [self setParentWindow:[self getExpectedParentWindow]]; |
| 430 [self setAnchorPoint:[self getExpectedAnchorPoint]]; |
| 431 } |
| 432 |
| 433 - (NSPoint)getExpectedAnchorPoint { |
| 434 NSPoint anchor; |
| 435 if ([self hasLocationBar]) { |
| 436 LocationBarViewMac* location_bar = |
| 437 [[[self getExpectedParentWindow] windowController] locationBarBridge]; |
| 438 anchor = location_bar->GetPageInfoBubblePoint(); |
| 439 } else { |
| 440 // Center the bubble if there's no location bar. |
| 441 NSView* content_view = [[self getExpectedParentWindow] contentView]; |
| 442 anchor.y = NSMaxY(content_view.frame); |
| 443 anchor.x = NSMidX(content_view.frame); |
| 444 } |
| 445 |
| 446 return [[self getExpectedParentWindow] convertBaseToScreen:anchor]; |
| 447 } |
| 448 |
| 449 - (BOOL)hasLocationBar { |
| 450 return browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR); |
| 451 } |
| 452 |
| 453 - (info_bubble::BubbleArrowLocation)getExpectedArrowLocation { |
| 454 return [self hasLocationBar] ? info_bubble::kTopLeft : info_bubble::kNoArrow; |
| 455 } |
| 456 |
| 457 - (NSWindow*)getExpectedParentWindow { |
| 458 return browser_->window()->GetNativeWindow(); |
| 459 } |
| 460 |
| 428 - (NSView*)labelForRequest:(PermissionBubbleRequest*)request { | 461 - (NSView*)labelForRequest:(PermissionBubbleRequest*)request { |
| 429 DCHECK(request); | 462 DCHECK(request); |
| 430 base::scoped_nsobject<NSView> permissionView( | 463 base::scoped_nsobject<NSView> permissionView( |
| 431 [[NSView alloc] initWithFrame:NSZeroRect]); | 464 [[NSView alloc] initWithFrame:NSZeroRect]); |
| 432 base::scoped_nsobject<NSImageView> permissionIcon( | 465 base::scoped_nsobject<NSImageView> permissionIcon( |
| 433 [[NSImageView alloc] initWithFrame:NSZeroRect]); | 466 [[NSImageView alloc] initWithFrame:NSZeroRect]); |
| 434 [permissionIcon setImage:ui::ResourceBundle::GetSharedInstance(). | 467 [permissionIcon setImage:ui::ResourceBundle::GetSharedInstance(). |
| 435 GetNativeImageNamed(request->GetIconID()).ToNSImage()]; | 468 GetNativeImageNamed(request->GetIconID()).ToNSImage()]; |
| 436 [permissionIcon setFrameSize:kPermissionIconSize]; | 469 [permissionIcon setFrameSize:kPermissionIconSize]; |
| 437 [permissionView addSubview:permissionIcon]; | 470 [permissionView addSubview:permissionIcon]; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 NSRect titleFrame = [titleView frame]; | 519 NSRect titleFrame = [titleView frame]; |
| 487 [titleView setFrameSize:NSMakeSize(NSWidth(titleFrame) + kTitlePaddingX, | 520 [titleView setFrameSize:NSMakeSize(NSWidth(titleFrame) + kTitlePaddingX, |
| 488 NSHeight(titleFrame))]; | 521 NSHeight(titleFrame))]; |
| 489 return titleView.autorelease(); | 522 return titleView.autorelease(); |
| 490 } | 523 } |
| 491 | 524 |
| 492 - (NSView*)menuForRequest:(PermissionBubbleRequest*)request | 525 - (NSView*)menuForRequest:(PermissionBubbleRequest*)request |
| 493 atIndex:(int)index | 526 atIndex:(int)index |
| 494 allow:(BOOL)allow { | 527 allow:(BOOL)allow { |
| 495 DCHECK(request); | 528 DCHECK(request); |
| 496 DCHECK(delegate_); | 529 DCHECK(manager_); |
| 497 base::scoped_nsobject<AllowBlockMenuButton> button( | 530 base::scoped_nsobject<AllowBlockMenuButton> button( |
| 498 [[AllowBlockMenuButton alloc] initForURL:request->GetRequestingHostname() | 531 [[AllowBlockMenuButton alloc] initForURL:request->GetRequestingHostname() |
| 499 allowed:allow | 532 allowed:allow |
| 500 index:index | 533 index:index |
| 501 delegate:delegate_]); | 534 manager:manager_]); |
| 502 return button.autorelease(); | 535 return button.autorelease(); |
| 503 } | 536 } |
| 504 | 537 |
| 505 - (NSView*)buttonWithTitle:(NSString*)title | 538 - (NSView*)buttonWithTitle:(NSString*)title |
| 506 action:(SEL)action { | 539 action:(SEL)action { |
| 507 base::scoped_nsobject<NSButton> button( | 540 base::scoped_nsobject<NSButton> button( |
| 508 [[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]); | 541 [[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]); |
| 509 [button setButtonType:NSMomentaryPushInButton]; | 542 [button setButtonType:NSMomentaryPushInButton]; |
| 510 [button setTitle:title]; | 543 [button setTitle:title]; |
| 511 [button setTarget:self]; | 544 [button setTarget:self]; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 524 int dimension = chrome_style::GetCloseButtonSize(); | 557 int dimension = chrome_style::GetCloseButtonSize(); |
| 525 NSRect frame = NSMakeRect(0, 0, dimension, dimension); | 558 NSRect frame = NSMakeRect(0, 0, dimension, dimension); |
| 526 base::scoped_nsobject<NSButton> button( | 559 base::scoped_nsobject<NSButton> button( |
| 527 [[WebUIHoverCloseButton alloc] initWithFrame:frame]); | 560 [[WebUIHoverCloseButton alloc] initWithFrame:frame]); |
| 528 [button setAction:@selector(onClose:)]; | 561 [button setAction:@selector(onClose:)]; |
| 529 [button setTarget:self]; | 562 [button setTarget:self]; |
| 530 return button.autorelease(); | 563 return button.autorelease(); |
| 531 } | 564 } |
| 532 | 565 |
| 533 - (void)ok:(id)sender { | 566 - (void)ok:(id)sender { |
| 534 DCHECK(delegate_); | 567 DCHECK(manager_); |
| 535 delegate_->Accept(); | 568 manager_->Accept(); |
| 536 } | 569 } |
| 537 | 570 |
| 538 - (void)onAllow:(id)sender { | 571 - (void)onAllow:(id)sender { |
| 539 DCHECK(delegate_); | 572 DCHECK(manager_); |
| 540 delegate_->Accept(); | 573 manager_->Accept(); |
| 541 } | 574 } |
| 542 | 575 |
| 543 - (void)onBlock:(id)sender { | 576 - (void)onBlock:(id)sender { |
| 544 DCHECK(delegate_); | 577 DCHECK(manager_); |
| 545 delegate_->Deny(); | 578 manager_->Deny(); |
| 546 } | 579 } |
| 547 | 580 |
| 548 - (void)onClose:(id)sender { | 581 - (void)onClose:(id)sender { |
| 549 DCHECK(delegate_); | 582 DCHECK(manager_); |
| 550 delegate_->Closing(); | 583 manager_->Closing(); |
| 551 } | 584 } |
| 552 | 585 |
| 553 - (void)activateTabWithContents:(content::WebContents*)newContents | 586 - (void)activateTabWithContents:(content::WebContents*)newContents |
| 554 previousContents:(content::WebContents*)oldContents | 587 previousContents:(content::WebContents*)oldContents |
| 555 atIndex:(NSInteger)index | 588 atIndex:(NSInteger)index |
| 556 reason:(int)reason { | 589 reason:(int)reason { |
| 557 // The show/hide of this bubble is handled by the PermissionBubbleManager. | 590 // The show/hide of this bubble is handled by the PermissionBubbleManager. |
| 558 // So bypass the base class, which would close the bubble here. | 591 // So bypass the base class, which would close the bubble here. |
| 559 } | 592 } |
| 560 | 593 |
| 561 + (CGFloat)matchWidthsOf:(NSView*)viewA andOf:(NSView*)viewB { | 594 + (CGFloat)matchWidthsOf:(NSView*)viewA andOf:(NSView*)viewB { |
| 562 NSRect frameA = [viewA frame]; | 595 NSRect frameA = [viewA frame]; |
| 563 NSRect frameB = [viewB frame]; | 596 NSRect frameB = [viewB frame]; |
| 564 CGFloat width = std::max(NSWidth(frameA), NSWidth(frameB)); | 597 CGFloat width = std::max(NSWidth(frameA), NSWidth(frameB)); |
| 565 [viewA setFrameSize:NSMakeSize(width, NSHeight(frameA))]; | 598 [viewA setFrameSize:NSMakeSize(width, NSHeight(frameA))]; |
| 566 [viewB setFrameSize:NSMakeSize(width, NSHeight(frameB))]; | 599 [viewB setFrameSize:NSMakeSize(width, NSHeight(frameB))]; |
| 567 return width; | 600 return width; |
| 568 } | 601 } |
| 569 | 602 |
| 570 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB { | 603 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB { |
| 571 NSRect frameA = [viewA frame]; | 604 NSRect frameA = [viewA frame]; |
| 572 NSRect frameB = [viewB frame]; | 605 NSRect frameB = [viewB frame]; |
| 573 frameA.origin.y = | 606 frameA.origin.y = |
| 574 NSMinY(frameB) + std::floor((NSHeight(frameB) - NSHeight(frameA)) / 2); | 607 NSMinY(frameB) + std::floor((NSHeight(frameB) - NSHeight(frameA)) / 2); |
| 575 [viewA setFrameOrigin:frameA.origin]; | 608 [viewA setFrameOrigin:frameA.origin]; |
| 576 } | 609 } |
| 577 | 610 |
| 578 @end // implementation PermissionBubbleController | 611 @end // implementation PermissionBubbleController |
| OLD | NEW |