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/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" |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 // Override the base class implementation, which sets the anchor point. But | 274 // Override the base class implementation, which sets the anchor point. But |
275 // it's not necessary since BrowserWindowController will notify the | 275 // it's not necessary since BrowserWindowController will notify the |
276 // PermissionRequestManager to update the anchor position on a resize. | 276 // PermissionRequestManager to update the anchor position on a resize. |
277 } | 277 } |
278 | 278 |
279 - (void)parentWindowDidMove:(NSNotification*)notification { | 279 - (void)parentWindowDidMove:(NSNotification*)notification { |
280 DCHECK(bridge_); | 280 DCHECK(bridge_); |
281 [self setAnchorPoint:[self getExpectedAnchorPoint]]; | 281 [self setAnchorPoint:[self getExpectedAnchorPoint]]; |
282 } | 282 } |
283 | 283 |
284 - (void)showWithDelegate:(PermissionPrompt::Delegate*)delegate | 284 - (void)showWithDelegate:(PermissionPrompt::Delegate*)delegate { |
285 forRequests:(const std::vector<PermissionRequest*>&)requests | 285 const std::vector<PermissionRequest*>& requests = delegate->Requests(); |
raymes
2017/05/11 01:17:54
nit: move this below the 3 lines below?
Timothy Loh
2017/05/11 04:42:08
I re-arranged it a bit.
| |
286 acceptStates:(const std::vector<bool>&)acceptStates { | |
287 DCHECK(!requests.empty()); | 286 DCHECK(!requests.empty()); |
288 DCHECK(delegate); | 287 DCHECK(delegate); |
289 delegate_ = delegate; | 288 delegate_ = delegate; |
290 | 289 |
291 NSView* contentView = [[self window] contentView]; | 290 NSView* contentView = [[self window] contentView]; |
292 [contentView setSubviews:@[]]; | 291 [contentView setSubviews:@[]]; |
293 | 292 |
294 BOOL singlePermission = requests.size() == 1; | 293 BOOL singlePermission = requests.size() == 1; |
295 | 294 |
296 // Create one button to use as a guide for the permissions' y-offsets. | 295 // Create one button to use as a guide for the permissions' y-offsets. |
(...skipping 19 matching lines...) Expand all Loading... | |
316 base::scoped_nsobject<NSView> permissionView( | 315 base::scoped_nsobject<NSView> permissionView( |
317 [[self labelForRequest:(*it)] retain]); | 316 [[self labelForRequest:(*it)] retain]); |
318 NSPoint origin = [permissionView frame].origin; | 317 NSPoint origin = [permissionView frame].origin; |
319 origin.x += kHorizontalPadding; | 318 origin.x += kHorizontalPadding; |
320 origin.y += yOffset + verticalPadding; | 319 origin.y += yOffset + verticalPadding; |
321 [permissionView setFrameOrigin:origin]; | 320 [permissionView setFrameOrigin:origin]; |
322 [contentView addSubview:permissionView]; | 321 [contentView addSubview:permissionView]; |
323 | 322 |
324 if (!singlePermission) { | 323 if (!singlePermission) { |
325 int index = it - requests.begin(); | 324 int index = it - requests.begin(); |
326 base::scoped_nsobject<NSView> menu( | 325 base::scoped_nsobject<NSView> menu([[self |
327 [[self menuForRequest:(*it) | 326 menuForRequest:(*it)atIndex:index |
328 atIndex:index | 327 allow:delegate->AcceptStates()[index] ? YES : NO] retain]); |
329 allow:acceptStates[index] ? YES : NO] retain]); | |
330 // Align vertically. Horizontal alignment will be adjusted once the | 328 // Align vertically. Horizontal alignment will be adjusted once the |
331 // widest permission is know. | 329 // widest permission is know. |
332 [PermissionBubbleController alignCenterOf:menu | 330 [PermissionBubbleController alignCenterOf:menu |
333 verticallyToCenterOf:permissionView]; | 331 verticallyToCenterOf:permissionView]; |
334 [permissionMenus addObject:menu]; | 332 [permissionMenus addObject:menu]; |
335 [contentView addSubview:menu]; | 333 [contentView addSubview:menu]; |
336 } | 334 } |
337 maxPermissionLineWidth = std::max( | 335 maxPermissionLineWidth = std::max( |
338 maxPermissionLineWidth, NSMaxX([permissionView frame])); | 336 maxPermissionLineWidth, NSMaxX([permissionView frame])); |
339 yOffset += NSHeight([permissionView frame]); | 337 yOffset += NSHeight([permissionView frame]); |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
621 } | 619 } |
622 | 620 |
623 - (IBAction)cancel:(id)sender { | 621 - (IBAction)cancel:(id)sender { |
624 // This is triggered by ESC when the bubble has focus. | 622 // This is triggered by ESC when the bubble has focus. |
625 if (delegate_) | 623 if (delegate_) |
626 delegate_->Closing(); | 624 delegate_->Closing(); |
627 [super cancel:sender]; | 625 [super cancel:sender]; |
628 } | 626 } |
629 | 627 |
630 @end // implementation PermissionBubbleController | 628 @end // implementation PermissionBubbleController |
OLD | NEW |