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

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

Issue 2233293003: Position Mac permission bubbles on the left when in fullscreen. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix MacViews bubbles Created 4 years, 4 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 - (void)ok:(id)sender; 202 - (void)ok:(id)sender;
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
tapted 2016/08/12 04:25:39 (j.e. here)
211 // Sets the width of both |viewA| and |viewB| to be the larger of the 213 // 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. 214 // two views' widths. Does not change either view's origin or height.
213 + (CGFloat)matchWidthsOf:(NSView*)viewA andOf:(NSView*)viewB; 215 + (CGFloat)matchWidthsOf:(NSView*)viewA andOf:(NSView*)viewB;
214 216
215 // Sets the offset of |viewA| so that its vertical center is aligned with the 217 // Sets the offset of |viewA| so that its vertical center is aligned with the
216 // vertical center of |viewB|. 218 // vertical center of |viewB|.
217 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB; 219 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB;
218 220
219 @end 221 @end
220 222
(...skipping 28 matching lines...) Expand all
249 } 251 }
250 252
251 + (NSPoint)getAnchorPointForBrowser:(Browser*)browser { 253 + (NSPoint)getAnchorPointForBrowser:(Browser*)browser {
252 NSPoint anchor; 254 NSPoint anchor;
253 NSWindow* parentWindow = browser->window()->GetNativeWindow(); 255 NSWindow* parentWindow = browser->window()->GetNativeWindow();
254 if ([PermissionBubbleController hasVisibleLocationBarForBrowser:browser]) { 256 if ([PermissionBubbleController hasVisibleLocationBarForBrowser:browser]) {
255 LocationBarViewMac* location_bar = 257 LocationBarViewMac* location_bar =
256 [[parentWindow windowController] locationBarBridge]; 258 [[parentWindow windowController] locationBarBridge];
257 anchor = location_bar->GetPageInfoBubblePoint(); 259 anchor = location_bar->GetPageInfoBubblePoint();
258 } else { 260 } else {
259 // Center the bubble if there's no location bar. 261 // Position the bubble on the left of the screen if there is no page info
262 // button to point at.
260 NSRect contentFrame = [[parentWindow contentView] frame]; 263 NSRect contentFrame = [[parentWindow contentView] frame];
261 anchor = NSMakePoint(NSMidX(contentFrame), NSMaxY(contentFrame)); 264 anchor = NSMakePoint(NSMinX(contentFrame) + kFullscreenLeftOffset,
265 NSMaxY(contentFrame));
262 } 266 }
263 267
264 return ui::ConvertPointFromWindowToScreen(parentWindow, anchor); 268 return ui::ConvertPointFromWindowToScreen(parentWindow, anchor);
265 } 269 }
266 270
267 + (bool)hasVisibleLocationBarForBrowser:(Browser*)browser { 271 + (bool)hasVisibleLocationBarForBrowser:(Browser*)browser {
268 if (!browser->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)) 272 if (!browser->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR))
269 return false; 273 return false;
270 274
271 if (!browser->exclusive_access_manager()->context()->IsFullscreen()) 275 if (!browser->exclusive_access_manager()->context()->IsFullscreen())
272 return true; 276 return true;
273 277
274 // If the browser is in browser-initiated full screen, a preference can cause 278 // If the browser is in browser-initiated full screen, a preference can cause
275 // the toolbar to be hidden. 279 // the toolbar to be hidden.
276 if (browser->exclusive_access_manager() 280 if (browser->exclusive_access_manager()
277 ->fullscreen_controller() 281 ->fullscreen_controller()
278 ->IsFullscreenForBrowser()) { 282 ->IsFullscreenForBrowser()) {
279 PrefService* prefs = browser->profile()->GetPrefs(); 283 PrefService* prefs = browser->profile()->GetPrefs();
280 bool show_toolbar = prefs->GetBoolean(prefs::kShowFullscreenToolbar); 284 bool show_toolbar = prefs->GetBoolean(prefs::kShowFullscreenToolbar);
281 return show_toolbar; 285 return show_toolbar;
282 } 286 }
283 287
284 // Otherwise this is fullscreen without a toolbar, so there is no visible 288 // Otherwise this is fullscreen without a toolbar, so there is no visible
285 // location bar. 289 // location bar.
286 return false; 290 return false;
287 } 291 }
288 292
293 + (NSInteger)getFullscreenLeftOffset {
tapted 2016/08/12 04:25:39 nit: move to after onClose
benwells 2016/08/12 06:29:44 Done.
294 return kFullscreenLeftOffset;
295 }
296
289 - (void)windowWillClose:(NSNotification*)notification { 297 - (void)windowWillClose:(NSNotification*)notification {
290 [[NSNotificationCenter defaultCenter] 298 [[NSNotificationCenter defaultCenter]
291 removeObserver:self 299 removeObserver:self
292 name:NSWindowDidMoveNotification 300 name:NSWindowDidMoveNotification
293 object:nil]; 301 object:nil];
294 bridge_->OnBubbleClosing(); 302 bridge_->OnBubbleClosing();
295 [super windowWillClose:notification]; 303 [super windowWillClose:notification];
296 } 304 }
297 305
298 - (void)parentWindowWillToggleFullScreen:(NSNotification*)notification { 306 - (void)parentWindowWillToggleFullScreen:(NSNotification*)notification {
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 646
640 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB { 647 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB {
641 NSRect frameA = [viewA frame]; 648 NSRect frameA = [viewA frame];
642 NSRect frameB = [viewB frame]; 649 NSRect frameB = [viewB frame];
643 frameA.origin.y = 650 frameA.origin.y =
644 NSMinY(frameB) + std::floor((NSHeight(frameB) - NSHeight(frameA)) / 2); 651 NSMinY(frameB) + std::floor((NSHeight(frameB) - NSHeight(frameA)) / 2);
645 [viewA setFrameOrigin:frameA.origin]; 652 [viewA setFrameOrigin:frameA.origin];
646 } 653 }
647 654
648 @end // implementation PermissionBubbleController 655 @end // implementation PermissionBubbleController
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698