| 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/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #import "ui/base/cocoa/controls/hyperlink_text_view.h" | 32 #import "ui/base/cocoa/controls/hyperlink_text_view.h" |
| 33 #import "ui/base/cocoa/menu_controller.h" | 33 #import "ui/base/cocoa/menu_controller.h" |
| 34 #include "ui/base/cocoa/window_size_constants.h" | 34 #include "ui/base/cocoa/window_size_constants.h" |
| 35 #include "ui/base/l10n/l10n_util_mac.h" | 35 #include "ui/base/l10n/l10n_util_mac.h" |
| 36 #include "ui/base/models/simple_menu_model.h" | 36 #include "ui/base/models/simple_menu_model.h" |
| 37 | 37 |
| 38 using base::UserMetricsAction; | 38 using base::UserMetricsAction; |
| 39 | 39 |
| 40 namespace { | 40 namespace { |
| 41 | 41 |
| 42 // Distance between permission icon and permission label. |
| 43 const CGFloat kHorizontalIconPadding = 8.0f; |
| 44 |
| 45 // Distance between two permission labels. |
| 46 const CGFloat kVerticalPermissionPadding = 2.0f; |
| 47 |
| 42 const CGFloat kHorizontalPadding = 13.0f; | 48 const CGFloat kHorizontalPadding = 13.0f; |
| 43 const CGFloat kVerticalPadding = 13.0f; | 49 const CGFloat kVerticalPadding = 15.0f; |
| 44 const CGFloat kBetweenButtonsPadding = 10.0f; | 50 const CGFloat kBetweenButtonsPadding = 10.0f; |
| 45 const CGFloat kButtonRightEdgePadding = 17.0f; | 51 const CGFloat kButtonRightEdgePadding = 17.0f; |
| 46 const CGFloat kTitlePaddingX = 50.0f; | 52 const CGFloat kTitlePaddingX = 50.0f; |
| 47 const CGFloat kBubbleMinWidth = 315.0f; | 53 const CGFloat kBubbleMinWidth = 315.0f; |
| 48 const NSSize kPermissionIconSize = {18, 18}; | 54 const NSSize kPermissionIconSize = {18, 18}; |
| 49 | 55 |
| 50 class MenuDelegate : public ui::SimpleMenuModel::Delegate { | 56 class MenuDelegate : public ui::SimpleMenuModel::Delegate { |
| 51 public: | 57 public: |
| 52 explicit MenuDelegate(PermissionBubbleController* bubble) | 58 explicit MenuDelegate(PermissionBubbleController* bubble) |
| 53 : bubble_controller_(bubble) {} | 59 : bubble_controller_(bubble) {} |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 action:@selector(onAllow:)] retain]); | 295 action:@selector(onAllow:)] retain]); |
| 290 } | 296 } |
| 291 CGFloat yOffset = 2 * kVerticalPadding + NSMaxY([allowOrOkButton frame]); | 297 CGFloat yOffset = 2 * kVerticalPadding + NSMaxY([allowOrOkButton frame]); |
| 292 BOOL singlePermission = requests.size() == 1; | 298 BOOL singlePermission = requests.size() == 1; |
| 293 | 299 |
| 294 base::scoped_nsobject<NSMutableArray> permissionMenus; | 300 base::scoped_nsobject<NSMutableArray> permissionMenus; |
| 295 if (customizationMode) | 301 if (customizationMode) |
| 296 permissionMenus.reset([[NSMutableArray alloc] init]); | 302 permissionMenus.reset([[NSMutableArray alloc] init]); |
| 297 | 303 |
| 298 CGFloat maxPermissionLineWidth = 0; | 304 CGFloat maxPermissionLineWidth = 0; |
| 305 CGFloat verticalPadding = 0.0f; |
| 299 for (auto it = requests.begin(); it != requests.end(); it++) { | 306 for (auto it = requests.begin(); it != requests.end(); it++) { |
| 300 base::scoped_nsobject<NSView> permissionView( | 307 base::scoped_nsobject<NSView> permissionView( |
| 301 [[self labelForRequest:(*it)] retain]); | 308 [[self labelForRequest:(*it)] retain]); |
| 302 NSPoint origin = [permissionView frame].origin; | 309 NSPoint origin = [permissionView frame].origin; |
| 303 origin.x += kHorizontalPadding; | 310 origin.x += kHorizontalPadding; |
| 304 origin.y += yOffset; | 311 origin.y += yOffset + verticalPadding; |
| 305 [permissionView setFrameOrigin:origin]; | 312 [permissionView setFrameOrigin:origin]; |
| 306 [contentView addSubview:permissionView]; | 313 [contentView addSubview:permissionView]; |
| 307 | 314 |
| 308 if (customizationMode) { | 315 if (customizationMode) { |
| 309 int index = it - requests.begin(); | 316 int index = it - requests.begin(); |
| 310 base::scoped_nsobject<NSView> menu( | 317 base::scoped_nsobject<NSView> menu( |
| 311 [[self menuForRequest:(*it) | 318 [[self menuForRequest:(*it) |
| 312 atIndex:index | 319 atIndex:index |
| 313 allow:acceptStates[index] ? YES : NO] retain]); | 320 allow:acceptStates[index] ? YES : NO] retain]); |
| 314 // Align vertically. Horizontal alignment will be adjusted once the | 321 // Align vertically. Horizontal alignment will be adjusted once the |
| 315 // widest permission is know. | 322 // widest permission is know. |
| 316 [PermissionBubbleController alignCenterOf:menu | 323 [PermissionBubbleController alignCenterOf:menu |
| 317 verticallyToCenterOf:permissionView]; | 324 verticallyToCenterOf:permissionView]; |
| 318 [permissionMenus addObject:menu]; | 325 [permissionMenus addObject:menu]; |
| 319 [contentView addSubview:menu]; | 326 [contentView addSubview:menu]; |
| 320 } | 327 } |
| 321 maxPermissionLineWidth = std::max( | 328 maxPermissionLineWidth = std::max( |
| 322 maxPermissionLineWidth, NSMaxX([permissionView frame])); | 329 maxPermissionLineWidth, NSMaxX([permissionView frame])); |
| 323 yOffset += NSHeight([permissionView frame]); | 330 yOffset += NSHeight([permissionView frame]); |
| 331 |
| 332 // Add extra padding for all but first permission. |
| 333 verticalPadding = kVerticalPermissionPadding; |
| 324 } | 334 } |
| 325 | 335 |
| 326 base::scoped_nsobject<NSView> titleView( | 336 base::scoped_nsobject<NSView> titleView( |
| 327 [[self titleWithHostname:requests[0]->GetRequestingHostname().host()] | 337 [[self titleWithHostname:requests[0]->GetRequestingHostname().host()] |
| 328 retain]); | 338 retain]); |
| 329 [contentView addSubview:titleView]; | 339 [contentView addSubview:titleView]; |
| 330 [titleView setFrameOrigin:NSMakePoint(kHorizontalPadding, | 340 [titleView setFrameOrigin:NSMakePoint(kHorizontalPadding, |
| 331 kVerticalPadding + yOffset)]; | 341 kVerticalPadding + yOffset)]; |
| 332 | 342 |
| 333 // 'x' button in the upper-right-hand corner. | 343 // 'x' button in the upper-right-hand corner. |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 base::string16 label = request->GetMessageTextFragment(); | 449 base::string16 label = request->GetMessageTextFragment(); |
| 440 [permissionLabel setDrawsBackground:NO]; | 450 [permissionLabel setDrawsBackground:NO]; |
| 441 [permissionLabel setBezeled:NO]; | 451 [permissionLabel setBezeled:NO]; |
| 442 [permissionLabel setEditable:NO]; | 452 [permissionLabel setEditable:NO]; |
| 443 [permissionLabel setSelectable:NO]; | 453 [permissionLabel setSelectable:NO]; |
| 444 [permissionLabel | 454 [permissionLabel |
| 445 setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; | 455 setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; |
| 446 [permissionLabel setStringValue:base::SysUTF16ToNSString(label)]; | 456 [permissionLabel setStringValue:base::SysUTF16ToNSString(label)]; |
| 447 [permissionLabel sizeToFit]; | 457 [permissionLabel sizeToFit]; |
| 448 [permissionLabel setFrameOrigin: | 458 [permissionLabel setFrameOrigin: |
| 449 NSMakePoint(NSWidth([permissionIcon frame]), 0)]; | 459 NSMakePoint(NSWidth([permissionIcon frame]) + kHorizontalIconPadding, 0)]; |
| 450 [permissionView addSubview:permissionLabel]; | 460 [permissionView addSubview:permissionLabel]; |
| 451 | 461 |
| 452 // Match the horizontal centers of the two subviews. Note that the label's | 462 // Match the horizontal centers of the two subviews. Note that the label's |
| 453 // center is rounded down, and the icon's center, up. It looks better that | 463 // center is rounded down, and the icon's center, up. It looks better that |
| 454 // way - with the text's center slightly lower than the icon's center - if the | 464 // way - with the text's center slightly lower than the icon's center - if the |
| 455 // height delta is not evenly split. | 465 // height delta is not evenly split. |
| 456 NSRect iconFrame = [permissionIcon frame]; | 466 NSRect iconFrame = [permissionIcon frame]; |
| 457 NSRect labelFrame = [permissionLabel frame]; | 467 NSRect labelFrame = [permissionLabel frame]; |
| 458 NSRect unionFrame = NSUnionRect(iconFrame, labelFrame); | 468 NSRect unionFrame = NSUnionRect(iconFrame, labelFrame); |
| 459 | 469 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 | 598 |
| 589 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB { | 599 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB { |
| 590 NSRect frameA = [viewA frame]; | 600 NSRect frameA = [viewA frame]; |
| 591 NSRect frameB = [viewB frame]; | 601 NSRect frameB = [viewB frame]; |
| 592 frameA.origin.y = | 602 frameA.origin.y = |
| 593 NSMinY(frameB) + std::floor((NSHeight(frameB) - NSHeight(frameA)) / 2); | 603 NSMinY(frameB) + std::floor((NSHeight(frameB) - NSHeight(frameA)) / 2); |
| 594 [viewA setFrameOrigin:frameA.origin]; | 604 [viewA setFrameOrigin:frameA.origin]; |
| 595 } | 605 } |
| 596 | 606 |
| 597 @end // implementation PermissionBubbleController | 607 @end // implementation PermissionBubbleController |
| OLD | NEW |