Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(661)

Side by Side Diff: chrome/browser/ui/cocoa/website_settings/permission_bubble_controller.mm

Issue 1935993004: MacViews: support Views permission bubble (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix typo in chrome_browser_ui.gypi Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 bridge_ = bridge; 241 bridge_ = bridge;
242 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; 242 NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
243 [center addObserver:self 243 [center addObserver:self
244 selector:@selector(parentWindowDidMove:) 244 selector:@selector(parentWindowDidMove:)
245 name:NSWindowDidMoveNotification 245 name:NSWindowDidMoveNotification
246 object:[self getExpectedParentWindow]]; 246 object:[self getExpectedParentWindow]];
247 } 247 }
248 return self; 248 return self;
249 } 249 }
250 250
251 + (NSPoint)getAnchorPointForBrowser:(Browser*)browser {
252 NSPoint anchor;
253 NSWindow* parentWindow = browser->window()->GetNativeWindow();
254 if ([PermissionBubbleController hasVisibleLocationBarForBrowser:browser]) {
255 LocationBarViewMac* location_bar =
256 [[parentWindow windowController] locationBarBridge];
257 anchor = location_bar->GetPageInfoBubblePoint();
258 } else {
259 // Center the bubble if there's no location bar.
260 NSRect contentFrame = [[parentWindow contentView] frame];
261 anchor = NSMakePoint(NSMidX(contentFrame), NSMaxY(contentFrame));
262 }
263
264 return ui::ConvertPointFromWindowToScreen(parentWindow, anchor);
265 }
266
267 + (bool)hasVisibleLocationBarForBrowser:(Browser*)browser {
268 if (!browser->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR))
269 return false;
270
271 if (!browser->exclusive_access_manager()->context()->IsFullscreen())
272 return true;
273
274 // If the browser is in browser-initiated full screen, a preference can cause
275 // the toolbar to be hidden.
276 if (browser->exclusive_access_manager()
277 ->fullscreen_controller()
278 ->IsFullscreenForBrowser()) {
279 PrefService* prefs = browser->profile()->GetPrefs();
280 bool show_toolbar = prefs->GetBoolean(prefs::kShowFullscreenToolbar);
281 return show_toolbar;
282 }
283
284 // Otherwise this is fullscreen without a toolbar, so there is no visible
285 // location bar.
286 return false;
287 }
288
251 - (void)windowWillClose:(NSNotification*)notification { 289 - (void)windowWillClose:(NSNotification*)notification {
252 [[NSNotificationCenter defaultCenter] 290 [[NSNotificationCenter defaultCenter]
253 removeObserver:self 291 removeObserver:self
254 name:NSWindowDidMoveNotification 292 name:NSWindowDidMoveNotification
255 object:nil]; 293 object:nil];
256 bridge_->OnBubbleClosing(); 294 bridge_->OnBubbleClosing();
257 [super windowWillClose:notification]; 295 [super windowWillClose:notification];
258 } 296 }
259 297
260 - (void)parentWindowWillToggleFullScreen:(NSNotification*)notification { 298 - (void)parentWindowWillToggleFullScreen:(NSNotification*)notification {
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 [[self window] setInitialFirstResponder:allowOrOkButton.get()]; 467 [[self window] setInitialFirstResponder:allowOrOkButton.get()];
430 } 468 }
431 } 469 }
432 470
433 - (void)updateAnchorPosition { 471 - (void)updateAnchorPosition {
434 [self setParentWindow:[self getExpectedParentWindow]]; 472 [self setParentWindow:[self getExpectedParentWindow]];
435 [self setAnchorPoint:[self getExpectedAnchorPoint]]; 473 [self setAnchorPoint:[self getExpectedAnchorPoint]];
436 } 474 }
437 475
438 - (NSPoint)getExpectedAnchorPoint { 476 - (NSPoint)getExpectedAnchorPoint {
439 NSPoint anchor; 477 return [PermissionBubbleController getAnchorPointForBrowser:browser_];
440 if ([self hasVisibleLocationBar]) {
441 LocationBarViewMac* location_bar =
442 [[[self getExpectedParentWindow] windowController] locationBarBridge];
443 anchor = location_bar->GetPageInfoBubblePoint();
444 } else {
445 // Center the bubble if there's no location bar.
446 NSRect contentFrame = [[[self getExpectedParentWindow] contentView] frame];
447 anchor = NSMakePoint(NSMidX(contentFrame), NSMaxY(contentFrame));
448 }
449
450 return ui::ConvertPointFromWindowToScreen([self getExpectedParentWindow],
451 anchor);
452 } 478 }
453 479
454 - (bool)hasVisibleLocationBar { 480 - (bool)hasVisibleLocationBar {
455 if (!browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)) 481 return [PermissionBubbleController hasVisibleLocationBarForBrowser:browser_];
456 return false;
457
458 if (!browser_->exclusive_access_manager()->context()->IsFullscreen())
459 return true;
460
461 // If the browser is in browser-initiated full screen, a preference can cause
462 // the toolbar to be hidden.
463 if (browser_->exclusive_access_manager()
464 ->fullscreen_controller()
465 ->IsFullscreenForBrowser()) {
466 PrefService* prefs = browser_->profile()->GetPrefs();
467 bool show_toolbar = prefs->GetBoolean(prefs::kShowFullscreenToolbar);
468 return show_toolbar;
469 }
470
471 // Otherwise this is fullscreen without a toolbar, so there is no visible
472 // location bar.
473 return false;
474 } 482 }
475 483
476 - (info_bubble::BubbleArrowLocation)getExpectedArrowLocation { 484 - (info_bubble::BubbleArrowLocation)getExpectedArrowLocation {
477 return [self hasVisibleLocationBar] ? info_bubble::kTopLeft 485 return [self hasVisibleLocationBar] ? info_bubble::kTopLeft
478 : info_bubble::kNoArrow; 486 : info_bubble::kNoArrow;
479 } 487 }
480 488
481 - (NSWindow*)getExpectedParentWindow { 489 - (NSWindow*)getExpectedParentWindow {
482 DCHECK(browser_->window()); 490 DCHECK(browser_->window());
483 return browser_->window()->GetNativeWindow(); 491 return browser_->window()->GetNativeWindow();
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 637
630 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB { 638 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB {
631 NSRect frameA = [viewA frame]; 639 NSRect frameA = [viewA frame];
632 NSRect frameB = [viewB frame]; 640 NSRect frameB = [viewB frame];
633 frameA.origin.y = 641 frameA.origin.y =
634 NSMinY(frameB) + std::floor((NSHeight(frameB) - NSHeight(frameA)) / 2); 642 NSMinY(frameB) + std::floor((NSHeight(frameB) - NSHeight(frameA)) / 2);
635 [viewA setFrameOrigin:frameA.origin]; 643 [viewA setFrameOrigin:frameA.origin];
636 } 644 }
637 645
638 @end // implementation PermissionBubbleController 646 @end // implementation PermissionBubbleController
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698