| 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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 bridge_ = bridge; | 256 bridge_ = bridge; |
| 257 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | 257 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
| 258 [center addObserver:self | 258 [center addObserver:self |
| 259 selector:@selector(parentWindowDidMove:) | 259 selector:@selector(parentWindowDidMove:) |
| 260 name:NSWindowDidMoveNotification | 260 name:NSWindowDidMoveNotification |
| 261 object:[self getExpectedParentWindow]]; | 261 object:[self getExpectedParentWindow]]; |
| 262 } | 262 } |
| 263 return self; | 263 return self; |
| 264 } | 264 } |
| 265 | 265 |
| 266 + (NSPoint)getAnchorPointForBrowser:(Browser*)browser { |
| 267 NSPoint anchor; |
| 268 NSWindow* parentWindow = browser->window()->GetNativeWindow(); |
| 269 if ([PermissionBubbleController hasVisibleLocationBarForBrowser:browser]) { |
| 270 LocationBarViewMac* location_bar = |
| 271 [[parentWindow windowController] locationBarBridge]; |
| 272 anchor = location_bar->GetPageInfoBubblePoint(); |
| 273 } else { |
| 274 // Center the bubble if there's no location bar. |
| 275 NSRect contentFrame = [[parentWindow contentView] frame]; |
| 276 anchor = NSMakePoint(NSMidX(contentFrame), NSMaxY(contentFrame)); |
| 277 } |
| 278 |
| 279 return ui::ConvertPointFromWindowToScreen(parentWindow, anchor); |
| 280 } |
| 281 |
| 282 + (bool)hasVisibleLocationBarForBrowser:(Browser*)browser { |
| 283 if (!browser->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)) |
| 284 return false; |
| 285 |
| 286 if (!browser->exclusive_access_manager()->context()->IsFullscreen()) |
| 287 return true; |
| 288 |
| 289 // If the browser is in browser-initiated full screen, a preference can cause |
| 290 // the toolbar to be hidden. |
| 291 if (browser->exclusive_access_manager() |
| 292 ->fullscreen_controller() |
| 293 ->IsFullscreenForBrowser()) { |
| 294 PrefService* prefs = browser->profile()->GetPrefs(); |
| 295 bool show_toolbar = prefs->GetBoolean(prefs::kShowFullscreenToolbar); |
| 296 return show_toolbar; |
| 297 } |
| 298 |
| 299 // Otherwise this is fullscreen without a toolbar, so there is no visible |
| 300 // location bar. |
| 301 return false; |
| 302 } |
| 303 |
| 266 - (void)windowWillClose:(NSNotification*)notification { | 304 - (void)windowWillClose:(NSNotification*)notification { |
| 267 [[NSNotificationCenter defaultCenter] | 305 [[NSNotificationCenter defaultCenter] |
| 268 removeObserver:self | 306 removeObserver:self |
| 269 name:NSWindowDidMoveNotification | 307 name:NSWindowDidMoveNotification |
| 270 object:nil]; | 308 object:nil]; |
| 271 bridge_->OnBubbleClosing(); | 309 bridge_->OnBubbleClosing(); |
| 272 [super windowWillClose:notification]; | 310 [super windowWillClose:notification]; |
| 273 } | 311 } |
| 274 | 312 |
| 275 - (void)parentWindowWillToggleFullScreen:(NSNotification*)notification { | 313 - (void)parentWindowWillToggleFullScreen:(NSNotification*)notification { |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 [[self window] setInitialFirstResponder:allowOrOkButton.get()]; | 482 [[self window] setInitialFirstResponder:allowOrOkButton.get()]; |
| 445 } | 483 } |
| 446 } | 484 } |
| 447 | 485 |
| 448 - (void)updateAnchorPosition { | 486 - (void)updateAnchorPosition { |
| 449 [self setParentWindow:[self getExpectedParentWindow]]; | 487 [self setParentWindow:[self getExpectedParentWindow]]; |
| 450 [self setAnchorPoint:[self getExpectedAnchorPoint]]; | 488 [self setAnchorPoint:[self getExpectedAnchorPoint]]; |
| 451 } | 489 } |
| 452 | 490 |
| 453 - (NSPoint)getExpectedAnchorPoint { | 491 - (NSPoint)getExpectedAnchorPoint { |
| 454 NSPoint anchor; | 492 return [PermissionBubbleController getAnchorPointForBrowser:browser_]; |
| 455 if ([self hasVisibleLocationBar]) { | |
| 456 LocationBarViewMac* location_bar = | |
| 457 [[[self getExpectedParentWindow] windowController] locationBarBridge]; | |
| 458 anchor = location_bar->GetPageInfoBubblePoint(); | |
| 459 } else { | |
| 460 // Center the bubble if there's no location bar. | |
| 461 NSRect contentFrame = [[[self getExpectedParentWindow] contentView] frame]; | |
| 462 anchor = NSMakePoint(NSMidX(contentFrame), NSMaxY(contentFrame)); | |
| 463 } | |
| 464 | |
| 465 return ui::ConvertPointFromWindowToScreen([self getExpectedParentWindow], | |
| 466 anchor); | |
| 467 } | 493 } |
| 468 | 494 |
| 469 - (bool)hasVisibleLocationBar { | 495 - (bool)hasVisibleLocationBar { |
| 470 if (!browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)) | 496 return [PermissionBubbleController hasVisibleLocationBarForBrowser:browser_]; |
| 471 return false; | |
| 472 | |
| 473 if (!browser_->exclusive_access_manager()->context()->IsFullscreen()) | |
| 474 return true; | |
| 475 | |
| 476 // If the browser is in browser-initiated full screen, a preference can cause | |
| 477 // the toolbar to be hidden. | |
| 478 if (browser_->exclusive_access_manager() | |
| 479 ->fullscreen_controller() | |
| 480 ->IsFullscreenForBrowser()) { | |
| 481 PrefService* prefs = browser_->profile()->GetPrefs(); | |
| 482 bool show_toolbar = prefs->GetBoolean(prefs::kShowFullscreenToolbar); | |
| 483 return show_toolbar; | |
| 484 } | |
| 485 | |
| 486 // Otherwise this is fullscreen without a toolbar, so there is no visible | |
| 487 // location bar. | |
| 488 return false; | |
| 489 } | 497 } |
| 490 | 498 |
| 491 - (info_bubble::BubbleArrowLocation)getExpectedArrowLocation { | 499 - (info_bubble::BubbleArrowLocation)getExpectedArrowLocation { |
| 492 return [self hasVisibleLocationBar] ? info_bubble::kTopLeft | 500 return [self hasVisibleLocationBar] ? info_bubble::kTopLeft |
| 493 : info_bubble::kNoArrow; | 501 : info_bubble::kNoArrow; |
| 494 } | 502 } |
| 495 | 503 |
| 496 - (NSWindow*)getExpectedParentWindow { | 504 - (NSWindow*)getExpectedParentWindow { |
| 497 DCHECK(browser_->window()); | 505 DCHECK(browser_->window()); |
| 498 return browser_->window()->GetNativeWindow(); | 506 return browser_->window()->GetNativeWindow(); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 | 652 |
| 645 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB { | 653 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB { |
| 646 NSRect frameA = [viewA frame]; | 654 NSRect frameA = [viewA frame]; |
| 647 NSRect frameB = [viewB frame]; | 655 NSRect frameB = [viewB frame]; |
| 648 frameA.origin.y = | 656 frameA.origin.y = |
| 649 NSMinY(frameB) + std::floor((NSHeight(frameB) - NSHeight(frameA)) / 2); | 657 NSMinY(frameB) + std::floor((NSHeight(frameB) - NSHeight(frameA)) / 2); |
| 650 [viewA setFrameOrigin:frameA.origin]; | 658 [viewA setFrameOrigin:frameA.origin]; |
| 651 } | 659 } |
| 652 | 660 |
| 653 @end // implementation PermissionBubbleController | 661 @end // implementation PermissionBubbleController |
| OLD | NEW |