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

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

Issue 2283753003: Material page info (Mac, 1/3): Update section padding variables. (Closed)
Patch Set: Also move constant grouping comments into this CL. Created 4 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/website_settings_bubble_contro ller.h" 5 #import "chrome/browser/ui/cocoa/website_settings/website_settings_bubble_contro ller.h"
6 6
7 #import <AppKit/AppKit.h> 7 #import <AppKit/AppKit.h>
8 8
9 #include <cmath> 9 #include <cmath>
10 10
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" 51 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
52 #include "ui/resources/grit/ui_resources.h" 52 #include "ui/resources/grit/ui_resources.h"
53 53
54 using ChosenObjectInfoPtr = 54 using ChosenObjectInfoPtr =
55 std::unique_ptr<WebsiteSettingsUI::ChosenObjectInfo>; 55 std::unique_ptr<WebsiteSettingsUI::ChosenObjectInfo>;
56 using ChosenObjectDeleteCallback = 56 using ChosenObjectDeleteCallback =
57 base::Callback<void(const WebsiteSettingsUI::ChosenObjectInfo&)>; 57 base::Callback<void(const WebsiteSettingsUI::ChosenObjectInfo&)>;
58 58
59 namespace { 59 namespace {
60 60
61 /**************** General ****************/
62
61 // The default width of the window, in view coordinates. It may be larger to 63 // The default width of the window, in view coordinates. It may be larger to
62 // fit the content. 64 // fit the content.
63 const CGFloat kDefaultWindowWidth = 310; 65 const CGFloat kDefaultWindowWidth = 320;
64 66
65 // Padding between the window frame and content. 67 // Padding around each section
66 const CGFloat kFramePadding = 20; 68 const CGFloat kSectionVerticalPadding = 20;
67 69 const CGFloat kSectionHorizontalPadding = 16;
68 // Padding between the window frame and content.
69 const CGFloat kVerticalSectionMargin = 16;
70
71 // Padding between the window frame and content for the internal page bubble.
72 const CGFloat kInternalPageFramePadding = 10;
73 70
74 // Spacing between the identity field and the security summary. 71 // Spacing between the identity field and the security summary.
75 const CGFloat kSpacingBeforeSecuritySummary = 2; 72 const CGFloat kSpacingBeforeSecuritySummary = 2;
76 73
74 /**************** Security Section ****************/
75
77 // Spacing between the security summary and the reset decisions button. 76 // Spacing between the security summary and the reset decisions button.
78 const CGFloat kSpacingBeforeResetDecisionsButton = 8; 77 const CGFloat kSpacingBeforeResetDecisionsButton = 8;
79 78
79 /**************** Site Settings Section ****************/
80
80 // Spacing between parts of the site settings section. 81 // Spacing between parts of the site settings section.
81 const CGFloat kSiteSettingsSectionSpacing = 2; 82 const CGFloat kSiteSettingsSectionSpacing = 2;
82 83
83 // Spacing between the image and text for internal pages.
84 const CGFloat kInternalPageImageSpacing = 10;
85
86 // Square size of the permission images. 84 // Square size of the permission images.
87 const CGFloat kPermissionImageSize = 19; 85 const CGFloat kPermissionImageSize = 19;
88 86
89 // Square size of the permission delete button image. 87 // Square size of the permission delete button image.
90 const CGFloat kPermissionDeleteImageSize = 16; 88 const CGFloat kPermissionDeleteImageSize = 16;
91 89
92 // Vertical adjustment for the permission images. They have an extra pixel of 90 // Vertical adjustment for the permission images. They have an extra pixel of
93 // padding on the bottom edge. 91 // padding on the bottom edge.
94 const CGFloat kPermissionImageYAdjust = 1; 92 const CGFloat kPermissionImageYAdjust = 1;
95 93
96 // Spacing between a permission image and the text. 94 // Spacing between a permission image and the text.
97 const CGFloat kPermissionImageSpacing = 3; 95 const CGFloat kPermissionImageSpacing = 3;
98 96
99 // The spacing between individual items in the Permissions tab. 97 // The spacing between individual items in the Permissions tab.
100 const CGFloat kPermissionsTabSpacing = 12; 98 const CGFloat kPermissionsTabSpacing = 12;
101 99
102 // Extra spacing after a headline on the Permissions tab. 100 // Extra spacing after a headline on the Permissions tab.
103 const CGFloat kPermissionsHeadlineSpacing = 2; 101 const CGFloat kPermissionsHeadlineSpacing = 2;
104 102
105 // The amount of horizontal space between a permission label and the popup. 103 // The amount of horizontal space between a permission label and the popup.
106 const CGFloat kPermissionPopUpXSpacing = 3; 104 const CGFloat kPermissionPopUpXSpacing = 3;
107 105
108 // The amount of padding to *remove* when placing 106 // The amount of padding to *remove* when placing
109 // |IDS_WEBSITE_SETTINGS_{FIRST,THIRD}_PARTY_SITE_DATA| next to each other. 107 // |IDS_WEBSITE_SETTINGS_{FIRST,THIRD}_PARTY_SITE_DATA| next to each other.
110 const CGFloat kTextLabelXPadding = 5; 108 const CGFloat kTextLabelXPadding = 5;
111 109
110 /**************** Internal Page Bubble ****************/
111
112 // Padding between the window frame and content for the internal page bubble.
113 const CGFloat kInternalPageFramePadding = 10;
114
115 // Spacing between the image and text for internal pages.
116 const CGFloat kInternalPageImageSpacing = 10;
117
118 /********************************/
119
112 // NOTE: This assumes that there will never be more than one website settings 120 // NOTE: This assumes that there will never be more than one website settings
113 // popup shown, and that the one that is shown is associated with the current 121 // popup shown, and that the one that is shown is associated with the current
114 // window. This matches the behaviour in views: see WebsiteSettingsPopupView. 122 // window. This matches the behaviour in views: see WebsiteSettingsPopupView.
115 bool g_is_popup_showing = false; 123 bool g_is_popup_showing = false;
116 124
117 // Takes in the parent window, which should be a BrowserWindow, and gets the 125 // Takes in the parent window, which should be a BrowserWindow, and gets the
118 // proper anchor point for the bubble. The returned point is in screen 126 // proper anchor point for the bubble. The returned point is in screen
119 // coordinates. 127 // coordinates.
120 NSPoint AnchorPointForWindow(NSWindow* parent) { 128 NSPoint AnchorPointForWindow(NSWindow* parent) {
121 BrowserWindowController* controller = [parent windowController]; 129 BrowserWindowController* controller = [parent windowController];
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 317
310 // Create and return a subview for the security section and add it to the given 318 // Create and return a subview for the security section and add it to the given
311 // |superview|. |superview| retains the new view. 319 // |superview|. |superview| retains the new view.
312 - (NSView*)addSecuritySectionToView:(NSView*)superview { 320 - (NSView*)addSecuritySectionToView:(NSView*)superview {
313 base::scoped_nsobject<NSView> securitySectionView( 321 base::scoped_nsobject<NSView> securitySectionView(
314 [[FlippedView alloc] initWithFrame:[superview frame]]); 322 [[FlippedView alloc] initWithFrame:[superview frame]]);
315 [superview addSubview:securitySectionView]; 323 [superview addSubview:securitySectionView];
316 324
317 // Create a controlOrigin to place the text fields. The y value doesn't 325 // Create a controlOrigin to place the text fields. The y value doesn't
318 // matter, because the correct value is calculated in -performLayout. 326 // matter, because the correct value is calculated in -performLayout.
319 NSPoint controlOrigin = NSMakePoint(kFramePadding, 0); 327 NSPoint controlOrigin = NSMakePoint(kSectionHorizontalPadding, 0);
320 328
321 // Create a text field (empty for now) to show the site identity. 329 // Create a text field (empty for now) to show the site identity.
322 identityField_ = [self addText:base::string16() 330 identityField_ = [self addText:base::string16()
323 withSize:[NSFont systemFontSize] 331 withSize:[NSFont systemFontSize]
324 bold:YES 332 bold:YES
325 toView:securitySectionView 333 toView:securitySectionView
326 atPoint:controlOrigin]; 334 atPoint:controlOrigin];
327 335
328 // Create a text field for the security summary (private/not private/etc.). 336 // Create a text field for the security summary (private/not private/etc.).
329 securitySummaryField_ = [self addText:base::string16() 337 securitySummaryField_ = [self addText:base::string16()
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 // Make the content at least as wide as the permissions view. 460 // Make the content at least as wide as the permissions view.
453 CGFloat contentWidth = std::max([self defaultWindowWidth], 461 CGFloat contentWidth = std::max([self defaultWindowWidth],
454 NSWidth([permissionsView_ frame])); 462 NSWidth([permissionsView_ frame]));
455 463
456 // Set the width of the content view now, so that all the text fields will 464 // Set the width of the content view now, so that all the text fields will
457 // be sized to fit before their heights and vertical positions are adjusted. 465 // be sized to fit before their heights and vertical positions are adjusted.
458 [self setWidthOfView:contentView_ to:contentWidth]; 466 [self setWidthOfView:contentView_ to:contentWidth];
459 [self setWidthOfView:securitySectionView_ to:contentWidth]; 467 [self setWidthOfView:securitySectionView_ to:contentWidth];
460 [self setWidthOfView:siteSettingsSectionView_ to:contentWidth]; 468 [self setWidthOfView:siteSettingsSectionView_ to:contentWidth];
461 469
462 CGFloat yPos = info_bubble::kBubbleArrowHeight; 470 CGFloat yPos = 0;
463 471
464 [self layoutSecuritySection]; 472 [self layoutSecuritySection];
465 yPos = [self setYPositionOfView:securitySectionView_ to:yPos + kFramePadding]; 473 yPos = [self setYPositionOfView:securitySectionView_ to:yPos];
466 474
467 yPos = [self setYPositionOfView:separatorAfterSecuritySection_ 475 yPos = [self setYPositionOfView:separatorAfterSecuritySection_ to:yPos];
468 to:yPos + kVerticalSectionMargin];
469 476
470 [self layoutSiteSettingsSection]; 477 [self layoutSiteSettingsSection];
471 yPos = [self setYPositionOfView:siteSettingsSectionView_ 478 yPos = [self setYPositionOfView:siteSettingsSectionView_ to:yPos];
472 to:yPos + kVerticalSectionMargin];
473 479
474 [contentView_ setFrame:NSMakeRect(0, 0, NSWidth([contentView_ frame]), 480 [contentView_ setFrame:NSMakeRect(0, 0, NSWidth([contentView_ frame]), yPos)];
475 yPos + kFramePadding)];
476 481
477 [self sizeAndPositionWindow]; 482 [self sizeAndPositionWindow];
478 } 483 }
479 484
480 - (void)layoutSecuritySection { 485 - (void)layoutSecuritySection {
481 // Start the layout with the first element. Margins are handled by the caller. 486 // Start the layout with the first element. Margins are handled by the caller.
482 CGFloat yPos = 0; 487 CGFloat yPos = 0;
483 488
484 [self sizeTextFieldHeightToFit:identityField_]; 489 [self sizeTextFieldHeightToFit:identityField_];
485 yPos = [self setYPositionOfView:identityField_ to:yPos]; 490 yPos = [self setYPositionOfView:identityField_
491 to:yPos + kSectionVerticalPadding];
486 492
487 [self sizeTextFieldHeightToFit:securitySummaryField_]; 493 [self sizeTextFieldHeightToFit:securitySummaryField_];
488 yPos = [self setYPositionOfView:securitySummaryField_ 494 yPos = [self setYPositionOfView:securitySummaryField_
489 to:yPos + kSpacingBeforeSecuritySummary]; 495 to:yPos + kSpacingBeforeSecuritySummary];
490 496
491 if (isDevToolsDisabled_ && certificateId_ == 0) { 497 if (isDevToolsDisabled_ && certificateId_ == 0) {
492 // -removeFromSuperview is idempotent. 498 // -removeFromSuperview is idempotent.
493 [securityDetailsButton_ removeFromSuperview]; 499 [securityDetailsButton_ removeFromSuperview];
494 } else { 500 } else {
495 // -addSubview is idempotent. 501 // -addSubview is idempotent.
496 [securitySectionView_ addSubview:securityDetailsButton_]; 502 [securitySectionView_ addSubview:securityDetailsButton_];
497 yPos = [self setYPositionOfView:securityDetailsButton_ to:yPos]; 503 yPos = [self setYPositionOfView:securityDetailsButton_ to:yPos];
498 } 504 }
499 505
500 if (resetDecisionsButton_) { 506 if (resetDecisionsButton_) {
501 yPos = [self setYPositionOfView:resetDecisionsButton_ 507 yPos = [self setYPositionOfView:resetDecisionsButton_
502 to:yPos + kSpacingBeforeResetDecisionsButton]; 508 to:yPos + kSpacingBeforeResetDecisionsButton];
503 } 509 }
504 510
505 // Resize the height based on contents. 511 // Resize the height based on contents.
506 [self setHeightOfView:securitySectionView_ to:yPos]; 512 [self setHeightOfView:securitySectionView_ to:yPos + kSectionVerticalPadding];
507 } 513 }
508 514
509 - (void)layoutSiteSettingsSection { 515 - (void)layoutSiteSettingsSection {
510 // Start the layout with the first element. Margins are handled by the caller. 516 // Start the layout with the first element. Margins are handled by the caller.
511 CGFloat yPos = 0; 517 CGFloat yPos = 0;
512 518
513 yPos = [self setYPositionOfView:cookiesView_ to:yPos]; 519 yPos =
520 [self setYPositionOfView:cookiesView_ to:yPos + kSectionVerticalPadding];
514 521
515 if (permissionsPresent_) { 522 if (permissionsPresent_) {
516 // Put the permission info just below the link button. 523 // Put the permission info just below the link button.
517 yPos = [self setYPositionOfView:permissionsView_ 524 yPos = [self setYPositionOfView:permissionsView_
518 to:yPos + kSiteSettingsSectionSpacing]; 525 to:yPos + kSiteSettingsSectionSpacing];
519 } 526 }
520 527
521 // Put the link button for site settings just below the permissions. 528 // Put the link button for site settings just below the permissions.
522 // TODO(lgarron): set the position of this based on RTL/LTR. 529 // TODO(lgarron): set the position of this based on RTL/LTR.
523 // http://code.google.com/p/chromium/issues/detail?id=525304 530 // http://code.google.com/p/chromium/issues/detail?id=525304
524 yPos += kSiteSettingsSectionSpacing; 531 yPos += kSiteSettingsSectionSpacing;
525 [siteSettingsButton_ setFrameOrigin:NSMakePoint(kFramePadding, yPos)]; 532 [siteSettingsButton_
533 setFrameOrigin:NSMakePoint(kSectionHorizontalPadding, yPos)];
526 yPos = NSMaxY([siteSettingsButton_ frame]); 534 yPos = NSMaxY([siteSettingsButton_ frame]);
527 535
528 // Resize the height based on contents. 536 // Resize the height based on contents.
529 [self setHeightOfView:siteSettingsSectionView_ to:yPos]; 537 [self setHeightOfView:siteSettingsSectionView_
538 to:yPos + kSectionVerticalPadding];
530 } 539 }
531 540
532 // Adjust the size of the window to match the size of the content, and position 541 // Adjust the size of the window to match the size of the content, and position
533 // the bubble anchor appropriately. 542 // the bubble anchor appropriately.
534 - (void)sizeAndPositionWindow { 543 - (void)sizeAndPositionWindow {
535 NSRect windowFrame = [contentView_ frame]; 544 NSRect windowFrame = [contentView_ frame];
536 windowFrame.size = [[[self window] contentView] convertSize:windowFrame.size 545 windowFrame.size = [[[self window] contentView] convertSize:windowFrame.size
537 toView:nil]; 546 toView:nil];
538 // Adjust the origin by the difference in height. 547 // Adjust the origin by the difference in height.
539 windowFrame.origin = [[self window] frame].origin; 548 windowFrame.origin = [[self window] frame].origin;
(...skipping 30 matching lines...) Expand all
570 579
571 // Create a new text field and add it to the given array of subviews. 580 // Create a new text field and add it to the given array of subviews.
572 // The array will retain a reference to the object. 581 // The array will retain a reference to the object.
573 - (NSTextField*)addText:(const base::string16&)text 582 - (NSTextField*)addText:(const base::string16&)text
574 withSize:(CGFloat)fontSize 583 withSize:(CGFloat)fontSize
575 bold:(BOOL)bold 584 bold:(BOOL)bold
576 toView:(NSView*)view 585 toView:(NSView*)view
577 atPoint:(NSPoint)point { 586 atPoint:(NSPoint)point {
578 // Size the text to take up the full available width, with some padding. 587 // Size the text to take up the full available width, with some padding.
579 // The height is arbitrary as it will be adjusted later. 588 // The height is arbitrary as it will be adjusted later.
580 CGFloat width = NSWidth([view frame]) - point.x - kFramePadding; 589 CGFloat width = NSWidth([view frame]) - point.x - kSectionHorizontalPadding;
581 NSRect frame = NSMakeRect(point.x, point.y, width, 100); 590 NSRect frame = NSMakeRect(point.x, point.y, width, 100);
582 base::scoped_nsobject<NSTextField> textField( 591 base::scoped_nsobject<NSTextField> textField(
583 [[NSTextField alloc] initWithFrame:frame]); 592 [[NSTextField alloc] initWithFrame:frame]);
584 [self configureTextFieldAsLabel:textField.get()]; 593 [self configureTextFieldAsLabel:textField.get()];
585 [textField setStringValue:base::SysUTF16ToNSString(text)]; 594 [textField setStringValue:base::SysUTF16ToNSString(text)];
586 NSFont* font = bold ? [NSFont boldSystemFontOfSize:fontSize] 595 NSFont* font = bold ? [NSFont boldSystemFontOfSize:fontSize]
587 : [NSFont systemFontOfSize:fontSize]; 596 : [NSFont systemFontOfSize:fontSize];
588 [textField setFont:font]; 597 [textField setFont:font];
589 [self sizeTextFieldHeightToFit:textField]; 598 [self sizeTextFieldHeightToFit:textField];
590 [textField setAutoresizingMask:NSViewWidthSizable]; 599 [textField setAutoresizingMask:NSViewWidthSizable];
(...skipping 19 matching lines...) Expand all
610 // Use an arbitrary position; it will be adjusted in performLayout. 619 // Use an arbitrary position; it will be adjusted in performLayout.
611 NSBox* spacer = [self 620 NSBox* spacer = [self
612 horizontalSeparatorWithFrame:NSMakeRect(0, 0, NSWidth([view frame]), 0)]; 621 horizontalSeparatorWithFrame:NSMakeRect(0, 0, NSWidth([view frame]), 0)];
613 [view addSubview:spacer]; 622 [view addSubview:spacer];
614 return spacer; 623 return spacer;
615 } 624 }
616 625
617 // Add a link button with the given text to |view|. 626 // Add a link button with the given text to |view|.
618 - (NSButton*)addLinkButtonWithText:(NSString*)text toView:(NSView*)view { 627 - (NSButton*)addLinkButtonWithText:(NSString*)text toView:(NSView*)view {
619 // Frame size is arbitrary; it will be adjusted by the layout tweaker. 628 // Frame size is arbitrary; it will be adjusted by the layout tweaker.
620 NSRect frame = NSMakeRect(kFramePadding, 0, 100, 10); 629 NSRect frame = NSMakeRect(kSectionHorizontalPadding, 0, 100, 10);
621 base::scoped_nsobject<NSButton> button( 630 base::scoped_nsobject<NSButton> button(
622 [[NSButton alloc] initWithFrame:frame]); 631 [[NSButton alloc] initWithFrame:frame]);
623 base::scoped_nsobject<HyperlinkButtonCell> cell( 632 base::scoped_nsobject<HyperlinkButtonCell> cell(
624 [[HyperlinkButtonCell alloc] initTextCell:text]); 633 [[HyperlinkButtonCell alloc] initTextCell:text]);
625 [cell setControlSize:NSSmallControlSize]; 634 [cell setControlSize:NSSmallControlSize];
626 [button setCell:cell.get()]; 635 [button setCell:cell.get()];
627 [button setButtonType:NSMomentaryPushInButton]; 636 [button setButtonType:NSMomentaryPushInButton];
628 [button setBezelStyle:NSRegularSquareBezelStyle]; 637 [button setBezelStyle:NSRegularSquareBezelStyle];
629 [view addSubview:button.get()]; 638 [view addSubview:button.get()];
630 639
631 [GTMUILocalizerAndLayoutTweaker sizeToFitView:button.get()]; 640 [GTMUILocalizerAndLayoutTweaker sizeToFitView:button.get()];
632 return button.get(); 641 return button.get();
633 } 642 }
634 643
635 // Create and return a button with the specified text and add it to the given 644 // Create and return a button with the specified text and add it to the given
636 // |view|. |view| retains the new button. 645 // |view|. |view| retains the new button.
637 - (NSButton*)addButtonWithText:(NSString*)text toView:(NSView*)view { 646 - (NSButton*)addButtonWithText:(NSString*)text toView:(NSView*)view {
638 NSRect containerFrame = [view frame]; 647 NSRect containerFrame = [view frame];
639 // Frame size is arbitrary; it will be adjusted by the layout tweaker. 648 // Frame size is arbitrary; it will be adjusted by the layout tweaker.
640 NSRect frame = NSMakeRect(kFramePadding, 0, 100, 10); 649 NSRect frame = NSMakeRect(kSectionHorizontalPadding, 0, 100, 10);
641 base::scoped_nsobject<NSButton> button( 650 base::scoped_nsobject<NSButton> button(
642 [[NSButton alloc] initWithFrame:frame]); 651 [[NSButton alloc] initWithFrame:frame]);
643 652
644 // Determine the largest possible size for this button. The size is the width 653 // Determine the largest possible size for this button. The size is the width
645 // of the connection section minus the padding on both sides minus the 654 // of the connection section minus the padding on both sides minus the
646 // connection image size and spacing. 655 // connection image size and spacing.
647 // TODO(lgarron): handle this sizing in -performLayout. 656 // TODO(lgarron): handle this sizing in -performLayout.
648 CGFloat maxTitleWidth = containerFrame.size.width - kFramePadding * 2; 657 CGFloat maxTitleWidth =
658 containerFrame.size.width - kSectionHorizontalPadding * 2;
649 659
650 base::scoped_nsobject<NSButtonCell> cell( 660 base::scoped_nsobject<NSButtonCell> cell(
651 [[NSButtonCell alloc] initTextCell:text]); 661 [[NSButtonCell alloc] initTextCell:text]);
652 [button setCell:cell.get()]; 662 [button setCell:cell.get()];
653 [GTMUILocalizerAndLayoutTweaker sizeToFitView:button.get()]; 663 [GTMUILocalizerAndLayoutTweaker sizeToFitView:button.get()];
654 664
655 // Ensure the containing view is large enough to contain the button with its 665 // Ensure the containing view is large enough to contain the button with its
656 // widest possible title. 666 // widest possible title.
657 NSRect buttonFrame = [button frame]; 667 NSRect buttonFrame = [button frame];
658 buttonFrame.size.width = maxTitleWidth; 668 buttonFrame.size.width = maxTitleWidth;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 forURL:url 713 forURL:url
704 withCallback:callback]); 714 withCallback:callback]);
705 // Determine the largest possible size for this button. 715 // Determine the largest possible size for this button.
706 CGFloat maxTitleWidth = [button 716 CGFloat maxTitleWidth = [button
707 maxTitleWidthForContentSettingsType:permissionInfo.type 717 maxTitleWidthForContentSettingsType:permissionInfo.type
708 withDefaultSetting:permissionInfo.default_setting]; 718 withDefaultSetting:permissionInfo.default_setting];
709 719
710 // Ensure the containing view is large enough to contain the button with its 720 // Ensure the containing view is large enough to contain the button with its
711 // widest possible title. 721 // widest possible title.
712 NSRect containerFrame = [view frame]; 722 NSRect containerFrame = [view frame];
713 containerFrame.size.width = std::max( 723 containerFrame.size.width =
714 NSWidth(containerFrame), point.x + maxTitleWidth + kFramePadding); 724 std::max(NSWidth(containerFrame),
725 point.x + maxTitleWidth + kSectionHorizontalPadding);
715 [view setFrame:containerFrame]; 726 [view setFrame:containerFrame];
716 [view addSubview:button.get()]; 727 [view addSubview:button.get()];
717 return button.get(); 728 return button.get();
718 } 729 }
719 730
720 // Add a delete button for |objectInfo| to the given view. 731 // Add a delete button for |objectInfo| to the given view.
721 - (NSButton*)addDeleteButtonForChosenObject:(ChosenObjectInfoPtr)objectInfo 732 - (NSButton*)addDeleteButtonForChosenObject:(ChosenObjectInfoPtr)objectInfo
722 toView:(NSView*)view 733 toView:(NSView*)view
723 atPoint:(NSPoint)point { 734 atPoint:(NSPoint)point {
724 __block WebsiteSettingsBubbleController* weakSelf = self; 735 __block WebsiteSettingsBubbleController* weakSelf = self;
725 auto callback = 736 auto callback =
726 base::BindBlock(^(const WebsiteSettingsUI::ChosenObjectInfo& objectInfo) { 737 base::BindBlock(^(const WebsiteSettingsUI::ChosenObjectInfo& objectInfo) {
727 [weakSelf onChosenObjectDeleted:objectInfo]; 738 [weakSelf onChosenObjectDeleted:objectInfo];
728 }); 739 });
729 base::scoped_nsobject<ChosenObjectDeleteButton> button( 740 base::scoped_nsobject<ChosenObjectDeleteButton> button(
730 [[ChosenObjectDeleteButton alloc] 741 [[ChosenObjectDeleteButton alloc]
731 initWithChosenObject:std::move(objectInfo) 742 initWithChosenObject:std::move(objectInfo)
732 atPoint:point 743 atPoint:point
733 withCallback:callback]); 744 withCallback:callback]);
734 745
735 // Ensure the containing view is large enough to contain the button. 746 // Ensure the containing view is large enough to contain the button.
736 NSRect containerFrame = [view frame]; 747 NSRect containerFrame = [view frame];
737 containerFrame.size.width = 748 containerFrame.size.width =
738 std::max(NSWidth(containerFrame), 749 std::max(NSWidth(containerFrame), point.x + kPermissionDeleteImageSize +
739 point.x + kPermissionDeleteImageSize + kFramePadding); 750 kSectionHorizontalPadding);
740 [view setFrame:containerFrame]; 751 [view setFrame:containerFrame];
741 [view addSubview:button.get()]; 752 [view addSubview:button.get()];
742 return button.get(); 753 return button.get();
743 } 754 }
744 755
745 // Called when the user changes the setting of a permission. 756 // Called when the user changes the setting of a permission.
746 - (void)onPermissionChanged:(ContentSettingsType)permissionType 757 - (void)onPermissionChanged:(ContentSettingsType)permissionType
747 to:(ContentSetting)newSetting { 758 to:(ContentSetting)newSetting {
748 if (presenter_) 759 if (presenter_)
749 presenter_->OnSitePermissionChanged(permissionType, newSetting); 760 presenter_->OnSitePermissionChanged(permissionType, newSetting);
(...skipping 23 matching lines...) Expand all
773 784
774 NSPoint position; 785 NSPoint position;
775 NSImageView* imageView; 786 NSImageView* imageView;
776 NSPopUpButton* button; 787 NSPopUpButton* button;
777 NSTextField* label; 788 NSTextField* label;
778 789
779 CGFloat viewWidth = NSWidth([view frame]); 790 CGFloat viewWidth = NSWidth([view frame]);
780 791
781 if (isRTL) { 792 if (isRTL) {
782 point.x = NSWidth([view frame]) - kPermissionImageSize - 793 point.x = NSWidth([view frame]) - kPermissionImageSize -
783 kPermissionImageSpacing - kFramePadding; 794 kPermissionImageSpacing - kSectionHorizontalPadding;
784 imageView = [self addImageWithSize:[image size] toView:view atPoint:point]; 795 imageView = [self addImageWithSize:[image size] toView:view atPoint:point];
785 [imageView setImage:image]; 796 [imageView setImage:image];
786 point.x -= kPermissionImageSpacing; 797 point.x -= kPermissionImageSpacing;
787 798
788 label = [self addText:labelText 799 label = [self addText:labelText
789 withSize:[NSFont smallSystemFontSize] 800 withSize:[NSFont smallSystemFontSize]
790 bold:NO 801 bold:NO
791 toView:view 802 toView:view
792 atPoint:point]; 803 atPoint:point];
793 [label sizeToFit]; 804 [label sizeToFit];
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 874
864 NSPoint position; 875 NSPoint position;
865 NSImageView* imageView; 876 NSImageView* imageView;
866 NSButton* button; 877 NSButton* button;
867 NSTextField* label; 878 NSTextField* label;
868 879
869 CGFloat viewWidth = NSWidth([view frame]); 880 CGFloat viewWidth = NSWidth([view frame]);
870 881
871 if (isRTL) { 882 if (isRTL) {
872 point.x = NSWidth([view frame]) - kPermissionImageSize - 883 point.x = NSWidth([view frame]) - kPermissionImageSize -
873 kPermissionImageSpacing - kFramePadding; 884 kPermissionImageSpacing - kSectionHorizontalPadding;
874 imageView = [self addImageWithSize:[image size] toView:view atPoint:point]; 885 imageView = [self addImageWithSize:[image size] toView:view atPoint:point];
875 [imageView setImage:image]; 886 [imageView setImage:image];
876 point.x -= kPermissionImageSpacing; 887 point.x -= kPermissionImageSpacing;
877 888
878 label = [self addText:labelText 889 label = [self addText:labelText
879 withSize:[NSFont smallSystemFontSize] 890 withSize:[NSFont smallSystemFontSize]
880 bold:NO 891 bold:NO
881 toView:view 892 toView:view
882 atPoint:point]; 893 atPoint:point];
883 [label sizeToFit]; 894 [label sizeToFit];
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 IDS_WEBSITE_SETTINGS_THIRD_PARTY_SITE_DATA, i.allowed); 976 IDS_WEBSITE_SETTINGS_THIRD_PARTY_SITE_DATA, i.allowed);
966 } 977 }
967 } 978 }
968 979
969 base::string16 sectionTitle = 980 base::string16 sectionTitle =
970 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TITLE_SITE_DATA); 981 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TITLE_SITE_DATA);
971 bool isRTL = base::i18n::RIGHT_TO_LEFT == 982 bool isRTL = base::i18n::RIGHT_TO_LEFT ==
972 base::i18n::GetStringDirection(firstPartyLabelText); 983 base::i18n::GetStringDirection(firstPartyLabelText);
973 984
974 [cookiesView_ setSubviews:[NSArray array]]; 985 [cookiesView_ setSubviews:[NSArray array]];
975 NSPoint controlOrigin = NSMakePoint(kFramePadding, 0); 986 NSPoint controlOrigin = NSMakePoint(kSectionHorizontalPadding, 0);
976 987
977 NSTextField* label; 988 NSTextField* label;
978 989
979 CGFloat viewWidth = NSWidth([cookiesView_ frame]); 990 CGFloat viewWidth = NSWidth([cookiesView_ frame]);
980 991
981 NSTextField* header = [self addText:sectionTitle 992 NSTextField* header = [self addText:sectionTitle
982 withSize:[NSFont smallSystemFontSize] 993 withSize:[NSFont smallSystemFontSize]
983 bold:YES 994 bold:YES
984 toView:cookiesView_ 995 toView:cookiesView_
985 atPoint:controlOrigin]; 996 atPoint:controlOrigin];
986 [header sizeToFit]; 997 [header sizeToFit];
987 998
988 if (isRTL) { 999 if (isRTL) {
989 controlOrigin.x = viewWidth - kFramePadding - NSWidth([header frame]); 1000 controlOrigin.x =
1001 viewWidth - kSectionHorizontalPadding - NSWidth([header frame]);
990 [header setFrameOrigin:controlOrigin]; 1002 [header setFrameOrigin:controlOrigin];
991 } 1003 }
992 controlOrigin.y += NSHeight([header frame]) + kPermissionsHeadlineSpacing; 1004 controlOrigin.y += NSHeight([header frame]) + kPermissionsHeadlineSpacing;
993 controlOrigin.y += kPermissionsTabSpacing; 1005 controlOrigin.y += kPermissionsTabSpacing;
994 1006
995 // Reset X for the cookie image. 1007 // Reset X for the cookie image.
996 if (isRTL) { 1008 if (isRTL) {
997 controlOrigin.x = viewWidth - kPermissionImageSize - 1009 controlOrigin.x = viewWidth - kPermissionImageSize -
998 kPermissionImageSpacing - kFramePadding; 1010 kPermissionImageSpacing - kSectionHorizontalPadding;
999 } 1011 }
1000 1012
1001 WebsiteSettingsUI::PermissionInfo info; 1013 WebsiteSettingsUI::PermissionInfo info;
1002 info.type = CONTENT_SETTINGS_TYPE_COOKIES; 1014 info.type = CONTENT_SETTINGS_TYPE_COOKIES;
1003 info.setting = CONTENT_SETTING_ALLOW; 1015 info.setting = CONTENT_SETTING_ALLOW;
1004 // info.default_setting, info.source, and info.is_incognito have not been set, 1016 // info.default_setting, info.source, and info.is_incognito have not been set,
1005 // but GetPermissionIcon doesn't use any of those. 1017 // but GetPermissionIcon doesn't use any of those.
1006 NSImage* image = WebsiteSettingsUI::GetPermissionIcon(info).ToNSImage(); 1018 NSImage* image = WebsiteSettingsUI::GetPermissionIcon(info).ToNSImage();
1007 NSImageView* imageView = [self addImageWithSize:[image size] 1019 NSImageView* imageView = [self addImageWithSize:[image size]
1008 toView:cookiesView_ 1020 toView:cookiesView_
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 1066
1055 [cookiesView_ setFrameSize: 1067 [cookiesView_ setFrameSize:
1056 NSMakeSize(NSWidth([cookiesView_ frame]), controlOrigin.y)]; 1068 NSMakeSize(NSWidth([cookiesView_ frame]), controlOrigin.y)];
1057 1069
1058 [self performLayout]; 1070 [self performLayout];
1059 } 1071 }
1060 1072
1061 - (void)setPermissionInfo:(const PermissionInfoList&)permissionInfoList 1073 - (void)setPermissionInfo:(const PermissionInfoList&)permissionInfoList
1062 andChosenObjects:(const ChosenObjectInfoList&)chosenObjectInfoList { 1074 andChosenObjects:(const ChosenObjectInfoList&)chosenObjectInfoList {
1063 [permissionsView_ setSubviews:[NSArray array]]; 1075 [permissionsView_ setSubviews:[NSArray array]];
1064 NSPoint controlOrigin = NSMakePoint(kFramePadding, 0); 1076 NSPoint controlOrigin = NSMakePoint(kSectionHorizontalPadding, 0);
1065 1077
1066 permissionsPresent_ = YES; 1078 permissionsPresent_ = YES;
1067 1079
1068 if (permissionInfoList.size() > 0 || chosenObjectInfoList.size() > 0) { 1080 if (permissionInfoList.size() > 0 || chosenObjectInfoList.size() > 0) {
1069 base::string16 sectionTitle = l10n_util::GetStringUTF16( 1081 base::string16 sectionTitle = l10n_util::GetStringUTF16(
1070 IDS_WEBSITE_SETTINGS_TITLE_SITE_PERMISSIONS); 1082 IDS_WEBSITE_SETTINGS_TITLE_SITE_PERMISSIONS);
1071 bool isRTL = base::i18n::RIGHT_TO_LEFT == 1083 bool isRTL = base::i18n::RIGHT_TO_LEFT ==
1072 base::i18n::GetStringDirection(sectionTitle); 1084 base::i18n::GetStringDirection(sectionTitle);
1073 NSTextField* header = [self addText:sectionTitle 1085 NSTextField* header = [self addText:sectionTitle
1074 withSize:[NSFont smallSystemFontSize] 1086 withSize:[NSFont smallSystemFontSize]
1075 bold:YES 1087 bold:YES
1076 toView:permissionsView_ 1088 toView:permissionsView_
1077 atPoint:controlOrigin]; 1089 atPoint:controlOrigin];
1078 [header sizeToFit]; 1090 [header sizeToFit];
1079 if (isRTL) { 1091 if (isRTL) {
1080 controlOrigin.x = NSWidth([permissionsView_ frame]) - kFramePadding - 1092 controlOrigin.x = NSWidth([permissionsView_ frame]) -
1081 NSWidth([header frame]); 1093 kSectionHorizontalPadding - NSWidth([header frame]);
1082 [header setFrameOrigin:controlOrigin]; 1094 [header setFrameOrigin:controlOrigin];
1083 } 1095 }
1084 controlOrigin.y += NSHeight([header frame]) + kPermissionsHeadlineSpacing; 1096 controlOrigin.y += NSHeight([header frame]) + kPermissionsHeadlineSpacing;
1085 1097
1086 for (const auto& permission : permissionInfoList) { 1098 for (const auto& permission : permissionInfoList) {
1087 controlOrigin.y += kPermissionsTabSpacing; 1099 controlOrigin.y += kPermissionsTabSpacing;
1088 NSPoint rowBottomRight = [self addPermission:permission 1100 NSPoint rowBottomRight = [self addPermission:permission
1089 toView:permissionsView_ 1101 toView:permissionsView_
1090 atPoint:controlOrigin]; 1102 atPoint:controlOrigin];
1091 controlOrigin.y = rowBottomRight.y; 1103 controlOrigin.y = rowBottomRight.y;
1092 } 1104 }
1093 1105
1094 for (auto* object : chosenObjectInfoList) { 1106 for (auto* object : chosenObjectInfoList) {
1095 controlOrigin.y += kPermissionsTabSpacing; 1107 controlOrigin.y += kPermissionsTabSpacing;
1096 NSPoint rowBottomRight = [self addChosenObject:base::WrapUnique(object) 1108 NSPoint rowBottomRight = [self addChosenObject:base::WrapUnique(object)
1097 toView:permissionsView_ 1109 toView:permissionsView_
1098 atPoint:controlOrigin]; 1110 atPoint:controlOrigin];
1099 controlOrigin.y = rowBottomRight.y; 1111 controlOrigin.y = rowBottomRight.y;
1100 } 1112 }
1101 1113
1102 controlOrigin.y += kFramePadding; 1114 controlOrigin.y += kPermissionsTabSpacing;
1103 } 1115 }
1104 1116
1105 [permissionsView_ setFrameSize: 1117 [permissionsView_ setFrameSize:
1106 NSMakeSize(NSWidth([permissionsView_ frame]), controlOrigin.y)]; 1118 NSMakeSize(NSWidth([permissionsView_ frame]), controlOrigin.y)];
1107 [self performLayout]; 1119 [self performLayout];
1108 } 1120 }
1109 1121
1110 @end 1122 @end
1111 1123
1112 WebsiteSettingsUIBridge::WebsiteSettingsUIBridge( 1124 WebsiteSettingsUIBridge::WebsiteSettingsUIBridge(
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 void WebsiteSettingsUIBridge::SetPermissionInfo( 1208 void WebsiteSettingsUIBridge::SetPermissionInfo(
1197 const PermissionInfoList& permission_info_list, 1209 const PermissionInfoList& permission_info_list,
1198 const ChosenObjectInfoList& chosen_object_info_list) { 1210 const ChosenObjectInfoList& chosen_object_info_list) {
1199 [bubble_controller_ setPermissionInfo:permission_info_list 1211 [bubble_controller_ setPermissionInfo:permission_info_list
1200 andChosenObjects:chosen_object_info_list]; 1212 andChosenObjects:chosen_object_info_list];
1201 } 1213 }
1202 1214
1203 void WebsiteSettingsUIBridge::SetSelectedTab(TabId tab_id) { 1215 void WebsiteSettingsUIBridge::SetSelectedTab(TabId tab_id) {
1204 // TODO(lgarron): Remove this from the interface. (crbug.com/571533) 1216 // TODO(lgarron): Remove this from the interface. (crbug.com/571533)
1205 } 1217 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698