| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 const CGFloat kVerticalPermissionPadding = 2.0f; | 58 const CGFloat kVerticalPermissionPadding = 2.0f; |
| 59 | 59 |
| 60 const CGFloat kHorizontalPadding = 13.0f; | 60 const CGFloat kHorizontalPadding = 13.0f; |
| 61 const CGFloat kVerticalPadding = 15.0f; | 61 const CGFloat kVerticalPadding = 15.0f; |
| 62 const CGFloat kBetweenButtonsPadding = 10.0f; | 62 const CGFloat kBetweenButtonsPadding = 10.0f; |
| 63 const CGFloat kButtonRightEdgePadding = 17.0f; | 63 const CGFloat kButtonRightEdgePadding = 17.0f; |
| 64 const CGFloat kTitlePaddingX = 50.0f; | 64 const CGFloat kTitlePaddingX = 50.0f; |
| 65 const CGFloat kBubbleMinWidth = 315.0f; | 65 const CGFloat kBubbleMinWidth = 315.0f; |
| 66 const NSSize kPermissionIconSize = {18, 18}; | 66 const NSSize kPermissionIconSize = {18, 18}; |
| 67 | 67 |
| 68 const NSInteger kFullscreenLeftOffset = 40; |
| 69 |
| 68 } // namespace | 70 } // namespace |
| 69 | 71 |
| 70 // NSPopUpButton with a menu containing two items: allow and block. | 72 // NSPopUpButton with a menu containing two items: allow and block. |
| 71 // One AllowBlockMenuButton is used for each requested permission when there are | 73 // One AllowBlockMenuButton is used for each requested permission when there are |
| 72 // multiple permissions in the bubble. | 74 // multiple permissions in the bubble. |
| 73 @interface AllowBlockMenuButton : NSPopUpButton { | 75 @interface AllowBlockMenuButton : NSPopUpButton { |
| 74 @private | 76 @private |
| 75 std::unique_ptr<PermissionMenuModel> menuModel_; | 77 std::unique_ptr<PermissionMenuModel> menuModel_; |
| 76 base::scoped_nsobject<MenuController> menuController_; | 78 base::scoped_nsobject<MenuController> menuController_; |
| 77 } | 79 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 | 203 |
| 202 // Called when the 'allow' button is pressed. | 204 // Called when the 'allow' button is pressed. |
| 203 - (void)onAllow:(id)sender; | 205 - (void)onAllow:(id)sender; |
| 204 | 206 |
| 205 // Called when the 'block' button is pressed. | 207 // Called when the 'block' button is pressed. |
| 206 - (void)onBlock:(id)sender; | 208 - (void)onBlock:(id)sender; |
| 207 | 209 |
| 208 // Called when the 'close' button is pressed. | 210 // Called when the 'close' button is pressed. |
| 209 - (void)onClose:(id)sender; | 211 - (void)onClose:(id)sender; |
| 210 | 212 |
| 213 // Returns the constant offset from the left to use for fullscreen permission |
| 214 // bubbles. Only used in tests. |
| 215 + (NSInteger)getFullscreenLeftOffset; |
| 216 |
| 211 // Sets the width of both |viewA| and |viewB| to be the larger of the | 217 // Sets the width of both |viewA| and |viewB| to be the larger of the |
| 212 // two views' widths. Does not change either view's origin or height. | 218 // two views' widths. Does not change either view's origin or height. |
| 213 + (CGFloat)matchWidthsOf:(NSView*)viewA andOf:(NSView*)viewB; | 219 + (CGFloat)matchWidthsOf:(NSView*)viewA andOf:(NSView*)viewB; |
| 214 | 220 |
| 215 // Sets the offset of |viewA| so that its vertical center is aligned with the | 221 // Sets the offset of |viewA| so that its vertical center is aligned with the |
| 216 // vertical center of |viewB|. | 222 // vertical center of |viewB|. |
| 217 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB; | 223 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB; |
| 218 | 224 |
| 219 @end | 225 @end |
| 220 | 226 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 249 } | 255 } |
| 250 | 256 |
| 251 + (NSPoint)getAnchorPointForBrowser:(Browser*)browser { | 257 + (NSPoint)getAnchorPointForBrowser:(Browser*)browser { |
| 252 NSPoint anchor; | 258 NSPoint anchor; |
| 253 NSWindow* parentWindow = browser->window()->GetNativeWindow(); | 259 NSWindow* parentWindow = browser->window()->GetNativeWindow(); |
| 254 if ([PermissionBubbleController hasVisibleLocationBarForBrowser:browser]) { | 260 if ([PermissionBubbleController hasVisibleLocationBarForBrowser:browser]) { |
| 255 LocationBarViewMac* location_bar = | 261 LocationBarViewMac* location_bar = |
| 256 [[parentWindow windowController] locationBarBridge]; | 262 [[parentWindow windowController] locationBarBridge]; |
| 257 anchor = location_bar->GetPageInfoBubblePoint(); | 263 anchor = location_bar->GetPageInfoBubblePoint(); |
| 258 } else { | 264 } else { |
| 259 // Center the bubble if there's no location bar. | 265 // Position the bubble on the left of the screen if there is no page info |
| 266 // button to point at. |
| 260 NSRect contentFrame = [[parentWindow contentView] frame]; | 267 NSRect contentFrame = [[parentWindow contentView] frame]; |
| 261 anchor = NSMakePoint(NSMidX(contentFrame), NSMaxY(contentFrame)); | 268 anchor = NSMakePoint(NSMinX(contentFrame) + kFullscreenLeftOffset, |
| 269 NSMaxY(contentFrame)); |
| 262 } | 270 } |
| 263 | 271 |
| 264 return ui::ConvertPointFromWindowToScreen(parentWindow, anchor); | 272 return ui::ConvertPointFromWindowToScreen(parentWindow, anchor); |
| 265 } | 273 } |
| 266 | 274 |
| 267 + (bool)hasVisibleLocationBarForBrowser:(Browser*)browser { | 275 + (bool)hasVisibleLocationBarForBrowser:(Browser*)browser { |
| 268 if (!browser->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)) | 276 if (!browser->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)) |
| 269 return false; | 277 return false; |
| 270 | 278 |
| 271 if (!browser->exclusive_access_manager()->context()->IsFullscreen()) | 279 if (!browser->exclusive_access_manager()->context()->IsFullscreen()) |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 | 485 |
| 478 - (NSPoint)getExpectedAnchorPoint { | 486 - (NSPoint)getExpectedAnchorPoint { |
| 479 return [PermissionBubbleController getAnchorPointForBrowser:browser_]; | 487 return [PermissionBubbleController getAnchorPointForBrowser:browser_]; |
| 480 } | 488 } |
| 481 | 489 |
| 482 - (bool)hasVisibleLocationBar { | 490 - (bool)hasVisibleLocationBar { |
| 483 return [PermissionBubbleController hasVisibleLocationBarForBrowser:browser_]; | 491 return [PermissionBubbleController hasVisibleLocationBarForBrowser:browser_]; |
| 484 } | 492 } |
| 485 | 493 |
| 486 - (info_bubble::BubbleArrowLocation)getExpectedArrowLocation { | 494 - (info_bubble::BubbleArrowLocation)getExpectedArrowLocation { |
| 487 return [self hasVisibleLocationBar] ? info_bubble::kTopLeft | 495 return info_bubble::kTopLeft; |
| 488 : info_bubble::kNoArrow; | |
| 489 } | 496 } |
| 490 | 497 |
| 491 - (NSWindow*)getExpectedParentWindow { | 498 - (NSWindow*)getExpectedParentWindow { |
| 492 DCHECK(browser_->window()); | 499 DCHECK(browser_->window()); |
| 493 return browser_->window()->GetNativeWindow(); | 500 return browser_->window()->GetNativeWindow(); |
| 494 } | 501 } |
| 495 | 502 |
| 496 - (NSView*)labelForRequest:(PermissionRequest*)request { | 503 - (NSView*)labelForRequest:(PermissionRequest*)request { |
| 497 DCHECK(request); | 504 DCHECK(request); |
| 498 base::scoped_nsobject<NSView> permissionView( | 505 base::scoped_nsobject<NSView> permissionView( |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 - (void)onBlock:(id)sender { | 620 - (void)onBlock:(id)sender { |
| 614 DCHECK(delegate_); | 621 DCHECK(delegate_); |
| 615 delegate_->Deny(); | 622 delegate_->Deny(); |
| 616 } | 623 } |
| 617 | 624 |
| 618 - (void)onClose:(id)sender { | 625 - (void)onClose:(id)sender { |
| 619 DCHECK(delegate_); | 626 DCHECK(delegate_); |
| 620 delegate_->Closing(); | 627 delegate_->Closing(); |
| 621 } | 628 } |
| 622 | 629 |
| 630 + (NSInteger)getFullscreenLeftOffset { |
| 631 return kFullscreenLeftOffset; |
| 632 } |
| 633 |
| 623 - (void)activateTabWithContents:(content::WebContents*)newContents | 634 - (void)activateTabWithContents:(content::WebContents*)newContents |
| 624 previousContents:(content::WebContents*)oldContents | 635 previousContents:(content::WebContents*)oldContents |
| 625 atIndex:(NSInteger)index | 636 atIndex:(NSInteger)index |
| 626 reason:(int)reason { | 637 reason:(int)reason { |
| 627 // The show/hide of this bubble is handled by the PermissionRequestManager. | 638 // The show/hide of this bubble is handled by the PermissionRequestManager. |
| 628 // So bypass the base class, which would close the bubble here. | 639 // So bypass the base class, which would close the bubble here. |
| 629 } | 640 } |
| 630 | 641 |
| 631 + (CGFloat)matchWidthsOf:(NSView*)viewA andOf:(NSView*)viewB { | 642 + (CGFloat)matchWidthsOf:(NSView*)viewA andOf:(NSView*)viewB { |
| 632 NSRect frameA = [viewA frame]; | 643 NSRect frameA = [viewA frame]; |
| 633 NSRect frameB = [viewB frame]; | 644 NSRect frameB = [viewB frame]; |
| 634 CGFloat width = std::max(NSWidth(frameA), NSWidth(frameB)); | 645 CGFloat width = std::max(NSWidth(frameA), NSWidth(frameB)); |
| 635 [viewA setFrameSize:NSMakeSize(width, NSHeight(frameA))]; | 646 [viewA setFrameSize:NSMakeSize(width, NSHeight(frameA))]; |
| 636 [viewB setFrameSize:NSMakeSize(width, NSHeight(frameB))]; | 647 [viewB setFrameSize:NSMakeSize(width, NSHeight(frameB))]; |
| 637 return width; | 648 return width; |
| 638 } | 649 } |
| 639 | 650 |
| 640 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB { | 651 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB { |
| 641 NSRect frameA = [viewA frame]; | 652 NSRect frameA = [viewA frame]; |
| 642 NSRect frameB = [viewB frame]; | 653 NSRect frameB = [viewB frame]; |
| 643 frameA.origin.y = | 654 frameA.origin.y = |
| 644 NSMinY(frameB) + std::floor((NSHeight(frameB) - NSHeight(frameA)) / 2); | 655 NSMinY(frameB) + std::floor((NSHeight(frameB) - NSHeight(frameA)) / 2); |
| 645 [viewA setFrameOrigin:frameA.origin]; | 656 [viewA setFrameOrigin:frameA.origin]; |
| 646 } | 657 } |
| 647 | 658 |
| 648 @end // implementation PermissionBubbleController | 659 @end // implementation PermissionBubbleController |
| OLD | NEW |