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

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

Issue 2853143003: MacViews: Allows the toolkit-views Device Chooser bubble to be used (Closed)
Patch Set: MacViews: Allows the toolkit-views Device Chooser bubble to be used (nits) Created 3 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/permission_bubble/permission_bubble_controller. h" 5 #import "chrome/browser/ui/cocoa/permission_bubble/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"
11 #include "base/strings/sys_string_conversions.h" 11 #include "base/strings/sys_string_conversions.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/browser/permissions/permission_request.h" 13 #include "chrome/browser/permissions/permission_request.h"
14 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_finder.h" 15 #include "chrome/browser/ui/browser_finder.h"
16 #include "chrome/browser/ui/browser_window.h" 16 #include "chrome/browser/ui/browser_window.h"
17 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 17 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
18 #import "chrome/browser/ui/cocoa/browser_window_utils.h" 18 #import "chrome/browser/ui/cocoa/browser_window_utils.h"
19 #import "chrome/browser/ui/cocoa/bubble_anchor_helper.h"
19 #import "chrome/browser/ui/cocoa/chrome_style.h" 20 #import "chrome/browser/ui/cocoa/chrome_style.h"
20 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" 21 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h"
21 #import "chrome/browser/ui/cocoa/hover_close_button.h" 22 #import "chrome/browser/ui/cocoa/hover_close_button.h"
22 #import "chrome/browser/ui/cocoa/info_bubble_view.h" 23 #import "chrome/browser/ui/cocoa/info_bubble_view.h"
23 #import "chrome/browser/ui/cocoa/info_bubble_window.h" 24 #import "chrome/browser/ui/cocoa/info_bubble_window.h"
24 #import "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h" 25 #import "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h"
25 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" 26 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
26 #include "chrome/browser/ui/cocoa/page_info/page_info_utils_cocoa.h" 27 #include "chrome/browser/ui/cocoa/page_info/page_info_utils_cocoa.h"
27 #include "chrome/browser/ui/cocoa/page_info/permission_selector_button.h" 28 #include "chrome/browser/ui/cocoa/page_info/permission_selector_button.h"
28 #include "chrome/browser/ui/cocoa/page_info/split_block_button.h" 29 #include "chrome/browser/ui/cocoa/page_info/split_block_button.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 const CGFloat kVerticalPermissionPadding = 2.0f; 63 const CGFloat kVerticalPermissionPadding = 2.0f;
63 64
64 const CGFloat kHorizontalPadding = 13.0f; 65 const CGFloat kHorizontalPadding = 13.0f;
65 const CGFloat kVerticalPadding = 15.0f; 66 const CGFloat kVerticalPadding = 15.0f;
66 const CGFloat kBetweenButtonsPadding = 10.0f; 67 const CGFloat kBetweenButtonsPadding = 10.0f;
67 const CGFloat kButtonRightEdgePadding = 17.0f; 68 const CGFloat kButtonRightEdgePadding = 17.0f;
68 const CGFloat kTitlePaddingX = 50.0f; 69 const CGFloat kTitlePaddingX = 50.0f;
69 const CGFloat kBubbleMinWidth = 315.0f; 70 const CGFloat kBubbleMinWidth = 315.0f;
70 const NSSize kPermissionIconSize = {18, 18}; 71 const NSSize kPermissionIconSize = {18, 18};
71 72
72 const NSInteger kFullscreenLeftOffset = 40;
73
74 } // namespace 73 } // namespace
75 74
76 // NSPopUpButton with a menu containing two items: allow and block. 75 // NSPopUpButton with a menu containing two items: allow and block.
77 // One AllowBlockMenuButton is used for each requested permission when there are 76 // One AllowBlockMenuButton is used for each requested permission when there are
78 // multiple permissions in the bubble. 77 // multiple permissions in the bubble.
79 @interface AllowBlockMenuButton : NSPopUpButton { 78 @interface AllowBlockMenuButton : NSPopUpButton {
80 @private 79 @private
81 std::unique_ptr<PermissionMenuModel> menuModel_; 80 std::unique_ptr<PermissionMenuModel> menuModel_;
82 base::scoped_nsobject<MenuController> menuController_; 81 base::scoped_nsobject<MenuController> menuController_;
83 } 82 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 177
179 // Called when the 'allow' button is pressed. 178 // Called when the 'allow' button is pressed.
180 - (void)onAllow:(id)sender; 179 - (void)onAllow:(id)sender;
181 180
182 // Called when the 'block' button is pressed. 181 // Called when the 'block' button is pressed.
183 - (void)onBlock:(id)sender; 182 - (void)onBlock:(id)sender;
184 183
185 // Called when the 'close' button is pressed. 184 // Called when the 'close' button is pressed.
186 - (void)onClose:(id)sender; 185 - (void)onClose:(id)sender;
187 186
188 // Returns the constant offset from the left to use for fullscreen permission
189 // bubbles. Only used in tests.
190 + (NSInteger)getFullscreenLeftOffset;
191
192 // Sets the width of both |viewA| and |viewB| to be the larger of the 187 // Sets the width of both |viewA| and |viewB| to be the larger of the
193 // two views' widths. Does not change either view's origin or height. 188 // two views' widths. Does not change either view's origin or height.
194 + (CGFloat)matchWidthsOf:(NSView*)viewA andOf:(NSView*)viewB; 189 + (CGFloat)matchWidthsOf:(NSView*)viewA andOf:(NSView*)viewB;
195 190
196 // Sets the offset of |viewA| so that its vertical center is aligned with the 191 // Sets the offset of |viewA| so that its vertical center is aligned with the
197 // vertical center of |viewB|. 192 // vertical center of |viewB|.
198 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB; 193 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB;
199 194
200 // BaseBubbleController override. 195 // BaseBubbleController override.
201 - (IBAction)cancel:(id)sender; 196 - (IBAction)cancel:(id)sender;
(...skipping 24 matching lines...) Expand all
226 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; 221 NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
227 [center addObserver:self 222 [center addObserver:self
228 selector:@selector(parentWindowDidMove:) 223 selector:@selector(parentWindowDidMove:)
229 name:NSWindowDidMoveNotification 224 name:NSWindowDidMoveNotification
230 object:[self getExpectedParentWindow]]; 225 object:[self getExpectedParentWindow]];
231 } 226 }
232 return self; 227 return self;
233 } 228 }
234 229
235 + (NSPoint)getAnchorPointForBrowser:(Browser*)browser { 230 + (NSPoint)getAnchorPointForBrowser:(Browser*)browser {
236 NSPoint anchor; 231 return GetPermissionBubbleAnchorPointForBrowser(
237 NSWindow* parentWindow = browser->window()->GetNativeWindow(); 232 browser,
238 if ([PermissionBubbleController hasVisibleLocationBarForBrowser:browser]) { 233 [PermissionBubbleController hasVisibleLocationBarForBrowser:browser]);
239 LocationBarViewMac* location_bar =
240 [[parentWindow windowController] locationBarBridge];
241 anchor = location_bar->GetPageInfoBubblePoint();
242 } else {
243 // Position the bubble on the left of the screen if there is no page info
244 // button to point at.
245 NSRect contentFrame = [[parentWindow contentView] frame];
246 anchor = NSMakePoint(NSMinX(contentFrame) + kFullscreenLeftOffset,
247 NSMaxY(contentFrame));
248 }
249
250 return ui::ConvertPointFromWindowToScreen(parentWindow, anchor);
251 } 234 }
252 235
253 + (bool)hasVisibleLocationBarForBrowser:(Browser*)browser { 236 + (bool)hasVisibleLocationBarForBrowser:(Browser*)browser {
254 if (!browser->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)) 237 return HasVisibleLocationBarForBrowser(browser);
255 return false;
256
257 if (!browser->exclusive_access_manager()->context()->IsFullscreen())
258 return true;
259
260 // If the browser is in browser-initiated full screen, a preference can cause
261 // the toolbar to be hidden.
262 if (browser->exclusive_access_manager()
263 ->fullscreen_controller()
264 ->IsFullscreenForBrowser()) {
265 PrefService* prefs = browser->profile()->GetPrefs();
266 bool show_toolbar = prefs->GetBoolean(prefs::kShowFullscreenToolbar);
267 return show_toolbar;
268 }
269
270 // Otherwise this is fullscreen without a toolbar, so there is no visible
271 // location bar.
272 return false;
273 } 238 }
274 239
275 - (void)windowWillClose:(NSNotification*)notification { 240 - (void)windowWillClose:(NSNotification*)notification {
276 [[NSNotificationCenter defaultCenter] 241 [[NSNotificationCenter defaultCenter]
277 removeObserver:self 242 removeObserver:self
278 name:NSWindowDidMoveNotification 243 name:NSWindowDidMoveNotification
279 object:nil]; 244 object:nil];
280 bridge_->OnBubbleClosing(); 245 bridge_->OnBubbleClosing();
281 [super windowWillClose:notification]; 246 [super windowWillClose:notification];
282 } 247 }
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 - (void)onBlock:(id)sender { 588 - (void)onBlock:(id)sender {
624 if (delegate_) 589 if (delegate_)
625 delegate_->Deny(); 590 delegate_->Deny();
626 } 591 }
627 592
628 - (void)onClose:(id)sender { 593 - (void)onClose:(id)sender {
629 if (delegate_) 594 if (delegate_)
630 delegate_->Closing(); 595 delegate_->Closing();
631 } 596 }
632 597
633 + (NSInteger)getFullscreenLeftOffset {
634 return kFullscreenLeftOffset;
635 }
636
637 - (void)activateTabWithContents:(content::WebContents*)newContents 598 - (void)activateTabWithContents:(content::WebContents*)newContents
638 previousContents:(content::WebContents*)oldContents 599 previousContents:(content::WebContents*)oldContents
639 atIndex:(NSInteger)index 600 atIndex:(NSInteger)index
640 reason:(int)reason { 601 reason:(int)reason {
641 // The show/hide of this bubble is handled by the PermissionRequestManager. 602 // The show/hide of this bubble is handled by the PermissionRequestManager.
642 // So bypass the base class, which would close the bubble here. 603 // So bypass the base class, which would close the bubble here.
643 } 604 }
644 605
645 + (CGFloat)matchWidthsOf:(NSView*)viewA andOf:(NSView*)viewB { 606 + (CGFloat)matchWidthsOf:(NSView*)viewA andOf:(NSView*)viewB {
646 NSRect frameA = [viewA frame]; 607 NSRect frameA = [viewA frame];
(...skipping 13 matching lines...) Expand all
660 } 621 }
661 622
662 - (IBAction)cancel:(id)sender { 623 - (IBAction)cancel:(id)sender {
663 // This is triggered by ESC when the bubble has focus. 624 // This is triggered by ESC when the bubble has focus.
664 if (delegate_) 625 if (delegate_)
665 delegate_->Closing(); 626 delegate_->Closing();
666 [super cancel:sender]; 627 [super cancel:sender];
667 } 628 }
668 629
669 @end // implementation PermissionBubbleController 630 @end // implementation PermissionBubbleController
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698