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

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

Issue 2298963002: Material Page Info (Mac, 3/3): Update site settings section. (Closed)
Patch Set: Update WSBC tests to compensate for removing the Permissions label. 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 | chrome/browser/ui/cocoa/website_settings/website_settings_bubble_controller_unittest.mm » ('j') | 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 // align with other text. 72 // align with other text.
73 const CGFloat kLinkButtonXAdjustment = 1; 73 const CGFloat kLinkButtonXAdjustment = 1;
74 74
75 /**************** Security Section ****************/ 75 /**************** Security Section ****************/
76 76
77 // Spacing between security summary, security details, and cert decisions text. 77 // Spacing between security summary, security details, and cert decisions text.
78 const CGFloat kSecurityParagraphSpacing = 12; 78 const CGFloat kSecurityParagraphSpacing = 12;
79 79
80 /**************** Site Settings Section ****************/ 80 /**************** Site Settings Section ****************/
81 81
82 // Spacing between parts of the site settings section. 82 // Square size of the permission images.
83 const CGFloat kSiteSettingsSectionSpacing = 2; 83 const CGFloat kPermissionImageSize = 16;
84 84
85 // Square size of the permission images. 85 // Spacing between a permission image and the text.
86 const CGFloat kPermissionImageSize = 19; 86 const CGFloat kPermissionImageSpacing = 6;
87 87
88 // Square size of the permission delete button image. 88 // Square size of the permission delete button image.
89 const CGFloat kPermissionDeleteImageSize = 16; 89 const CGFloat kPermissionDeleteImageSize = 16;
90 90
91 // Vertical adjustment for the permission images. They have an extra pixel of 91 // The spacing between individual permissions.
92 // padding on the bottom edge. 92 const CGFloat kPermissionsVerticalSpacing = 16;
93 const CGFloat kPermissionImageYAdjust = 1;
94 93
95 // Spacing between a permission image and the text. 94 // Amount to lower each permission icon to align the icon baseline with the
96 const CGFloat kPermissionImageSpacing = 3; 95 // label text.
96 const CGFloat kPermissionIconYAdjustment = 1;
97 97
98 // The spacing between individual items in the Permissions tab. 98 // Amount to lower each permission popup button to make its text align with the
99 const CGFloat kPermissionsTabSpacing = 12; 99 // permission label.
100 100 const CGFloat kPermissionPopupButtonYAdjustment = 3;
101 // Extra spacing after a headline on the Permissions tab.
102 const CGFloat kPermissionsHeadlineSpacing = 2;
103
104 // The amount of horizontal space between a permission label and the popup.
105 const CGFloat kPermissionPopUpXSpacing = 3;
106
107 // The amount of padding to *remove* when placing
108 // |IDS_WEBSITE_SETTINGS_{FIRST,THIRD}_PARTY_SITE_DATA| next to each other.
109 const CGFloat kTextLabelXPadding = 5;
110 101
111 /**************** Internal Page Bubble ****************/ 102 /**************** Internal Page Bubble ****************/
112 103
113 // Padding between the window frame and content for the internal page bubble. 104 // Padding between the window frame and content for the internal page bubble.
114 const CGFloat kInternalPageFramePadding = 10; 105 const CGFloat kInternalPageFramePadding = 10;
115 106
116 // Spacing between the image and text for internal pages. 107 // Spacing between the image and text for internal pages.
117 const CGFloat kInternalPageImageSpacing = 10; 108 const CGFloat kInternalPageImageSpacing = 10;
118 109
119 /********************************/ 110 /********************************/
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 [siteSettingsSectionView addSubview:cookiesView_]; 362 [siteSettingsSectionView addSubview:cookiesView_];
372 363
373 permissionsView_ = 364 permissionsView_ =
374 [[[FlippedView alloc] initWithFrame:[superview frame]] autorelease]; 365 [[[FlippedView alloc] initWithFrame:[superview frame]] autorelease];
375 [siteSettingsSectionView addSubview:permissionsView_]; 366 [siteSettingsSectionView addSubview:permissionsView_];
376 367
377 // Create the link button to view site settings. Its position will be set in 368 // Create the link button to view site settings. Its position will be set in
378 // performLayout. 369 // performLayout.
379 NSString* siteSettingsButtonText = 370 NSString* siteSettingsButtonText =
380 l10n_util::GetNSString(IDS_PAGE_INFO_SITE_SETTINGS_LINK); 371 l10n_util::GetNSString(IDS_PAGE_INFO_SITE_SETTINGS_LINK);
381 siteSettingsButton_ = [self addLinkButtonWithText:siteSettingsButtonText 372 siteSettingsButton_ = [self addButtonWithText:siteSettingsButtonText
382 toView:siteSettingsSectionView]; 373 toView:siteSettingsSectionView];
374 [GTMUILocalizerAndLayoutTweaker sizeToFitView:siteSettingsButton_];
375
383 [siteSettingsButton_ setTarget:self]; 376 [siteSettingsButton_ setTarget:self];
384 [siteSettingsButton_ setAction:@selector(showSiteSettingsData:)]; 377 [siteSettingsButton_ setAction:@selector(showSiteSettingsData:)];
385 378
386 return siteSettingsSectionView.get(); 379 return siteSettingsSectionView.get();
387 } 380 }
388 381
389 // Handler for the link button below the list of cookies. 382 // Handler for the link button below the list of cookies.
390 - (void)showCookiesAndSiteData:(id)sender { 383 - (void)showCookiesAndSiteData:(id)sender {
391 DCHECK(webContents_); 384 DCHECK(webContents_);
392 DCHECK(presenter_); 385 DCHECK(presenter_);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 ShowCertificateViewer(webContents_, [self parentWindow], certificate_.get()); 426 ShowCertificateViewer(webContents_, [self parentWindow], certificate_.get());
434 } 427 }
435 428
436 // Handler for the link button to revoke user certificate decisions. 429 // Handler for the link button to revoke user certificate decisions.
437 - (void)resetCertificateDecisions:(id)sender { 430 - (void)resetCertificateDecisions:(id)sender {
438 DCHECK(resetDecisionsButton_); 431 DCHECK(resetDecisionsButton_);
439 presenter_->OnRevokeSSLErrorBypassButtonPressed(); 432 presenter_->OnRevokeSSLErrorBypassButtonPressed();
440 [self close]; 433 [self close];
441 } 434 }
442 435
436 - (CGFloat)layoutViewAtRTLStart:(NSView*)view withYPosition:(CGFloat)yPos {
437 CGFloat xPos;
438 if (base::i18n::IsRTL()) {
439 xPos =
440 kDefaultWindowWidth - kSectionHorizontalPadding - NSWidth([view frame]);
441 } else {
442 xPos = kSectionHorizontalPadding;
443 }
444 [view setFrameOrigin:NSMakePoint(xPos, yPos)];
445 return yPos + NSHeight([view frame]);
446 }
447
443 // Set the Y position of |view| to the given position, and return the position 448 // Set the Y position of |view| to the given position, and return the position
444 // of its bottom edge. 449 // of its bottom edge.
445 - (CGFloat)setYPositionOfView:(NSView*)view to:(CGFloat)position { 450 - (CGFloat)setYPositionOfView:(NSView*)view to:(CGFloat)position {
446 NSRect frame = [view frame]; 451 NSRect frame = [view frame];
447 frame.origin.y = position; 452 frame.origin.y = position;
448 [view setFrame:frame]; 453 [view setFrame:frame];
449 return position + NSHeight(frame); 454 return position + NSHeight(frame);
450 } 455 }
451 456
452 - (void)setWidthOfView:(NSView*)view to:(CGFloat)width { 457 - (void)setWidthOfView:(NSView*)view to:(CGFloat)width {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 532
528 - (void)layoutSiteSettingsSection { 533 - (void)layoutSiteSettingsSection {
529 // Start the layout with the first element. Margins are handled by the caller. 534 // Start the layout with the first element. Margins are handled by the caller.
530 CGFloat yPos = 0; 535 CGFloat yPos = 0;
531 536
532 yPos = 537 yPos =
533 [self setYPositionOfView:cookiesView_ to:yPos + kSectionVerticalPadding]; 538 [self setYPositionOfView:cookiesView_ to:yPos + kSectionVerticalPadding];
534 539
535 if (permissionsPresent_) { 540 if (permissionsPresent_) {
536 // Put the permission info just below the link button. 541 // Put the permission info just below the link button.
537 yPos = [self setYPositionOfView:permissionsView_ 542 yPos = [self setYPositionOfView:permissionsView_ to:yPos];
538 to:yPos + kSiteSettingsSectionSpacing];
539 } 543 }
540 544
541 // Put the link button for site settings just below the permissions. 545 yPos = [self layoutViewAtRTLStart:siteSettingsButton_ withYPosition:yPos];
542 // TODO(lgarron): set the position of this based on RTL/LTR.
543 // http://code.google.com/p/chromium/issues/detail?id=525304
544 yPos += kSiteSettingsSectionSpacing;
545 [siteSettingsButton_
546 setFrameOrigin:NSMakePoint(kSectionHorizontalPadding, yPos)];
547 yPos = NSMaxY([siteSettingsButton_ frame]);
548 546
549 // Resize the height based on contents. 547 // Resize the height based on contents.
550 [self setHeightOfView:siteSettingsSectionView_ 548 [self setHeightOfView:siteSettingsSectionView_
551 to:yPos + kSectionVerticalPadding]; 549 to:yPos + kSectionVerticalPadding];
552 } 550 }
553 551
554 // Adjust the size of the window to match the size of the content, and position 552 // Adjust the size of the window to match the size of the content, and position
555 // the bubble anchor appropriately. 553 // the bubble anchor appropriately.
556 - (void)sizeAndPositionWindow { 554 - (void)sizeAndPositionWindow {
557 NSRect windowFrame = [contentView_ frame]; 555 NSRect windowFrame = [contentView_ frame];
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 GURL url = webContents_ ? webContents_->GetURL() : GURL(); 731 GURL url = webContents_ ? webContents_->GetURL() : GURL();
734 __block WebsiteSettingsBubbleController* weakSelf = self; 732 __block WebsiteSettingsBubbleController* weakSelf = self;
735 PermissionMenuModel::ChangeCallback callback = 733 PermissionMenuModel::ChangeCallback callback =
736 base::BindBlock(^(const WebsiteSettingsUI::PermissionInfo& permission) { 734 base::BindBlock(^(const WebsiteSettingsUI::PermissionInfo& permission) {
737 [weakSelf onPermissionChanged:permission.type to:permission.setting]; 735 [weakSelf onPermissionChanged:permission.type to:permission.setting];
738 }); 736 });
739 base::scoped_nsobject<PermissionSelectorButton> button( 737 base::scoped_nsobject<PermissionSelectorButton> button(
740 [[PermissionSelectorButton alloc] initWithPermissionInfo:permissionInfo 738 [[PermissionSelectorButton alloc] initWithPermissionInfo:permissionInfo
741 forURL:url 739 forURL:url
742 withCallback:callback]); 740 withCallback:callback]);
741
743 // Determine the largest possible size for this button. 742 // Determine the largest possible size for this button.
744 CGFloat maxTitleWidth = [button 743 CGFloat maxTitleWidth = [button
745 maxTitleWidthForContentSettingsType:permissionInfo.type 744 maxTitleWidthForContentSettingsType:permissionInfo.type
746 withDefaultSetting:permissionInfo.default_setting]; 745 withDefaultSetting:permissionInfo.default_setting];
747 746
748 // Ensure the containing view is large enough to contain the button with its 747 // Ensure the containing view is large enough to contain the button with its
749 // widest possible title. 748 // widest possible title.
750 NSRect containerFrame = [view frame]; 749 NSRect containerFrame = [view frame];
751 containerFrame.size.width = 750 containerFrame.size.width =
752 std::max(NSWidth(containerFrame), 751 std::max(NSWidth(containerFrame),
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 } 794 }
796 795
797 // Adds a new row to the UI listing the permissions. Returns the NSPoint of the 796 // Adds a new row to the UI listing the permissions. Returns the NSPoint of the
798 // last UI element added (either the permission button, in LTR, or the text 797 // last UI element added (either the permission button, in LTR, or the text
799 // label, in RTL). 798 // label, in RTL).
800 - (NSPoint)addPermission: 799 - (NSPoint)addPermission:
801 (const WebsiteSettingsUI::PermissionInfo&)permissionInfo 800 (const WebsiteSettingsUI::PermissionInfo&)permissionInfo
802 toView:(NSView*)view 801 toView:(NSView*)view
803 atPoint:(NSPoint)point { 802 atPoint:(NSPoint)point {
804 base::string16 labelText = 803 base::string16 labelText =
805 WebsiteSettingsUI::PermissionTypeToUIString(permissionInfo.type) + 804 WebsiteSettingsUI::PermissionTypeToUIString(permissionInfo.type);
806 base::ASCIIToUTF16(":"); 805 bool isRTL = base::i18n::IsRTL();
807 bool isRTL =
808 base::i18n::RIGHT_TO_LEFT == base::i18n::GetStringDirection(labelText);
809 base::scoped_nsobject<NSImage> image( 806 base::scoped_nsobject<NSImage> image(
810 [WebsiteSettingsUI::GetPermissionIcon(permissionInfo).ToNSImage() 807 [WebsiteSettingsUI::GetPermissionIcon(permissionInfo).ToNSImage()
811 retain]); 808 retain]);
812 809
813 NSPoint position; 810 NSPoint position;
814 NSImageView* imageView; 811 NSImageView* imageView;
815 NSPopUpButton* button; 812 NSPopUpButton* button;
816 NSTextField* label; 813 NSTextField* label;
817 814
818 CGFloat viewWidth = NSWidth([view frame]); 815 CGFloat viewWidth = NSWidth([view frame]);
819 816
820 if (isRTL) { 817 if (isRTL) {
821 point.x = NSWidth([view frame]) - kPermissionImageSize - 818 point.x = NSWidth([view frame]) - kPermissionImageSize -
822 kPermissionImageSpacing - kSectionHorizontalPadding; 819 kSectionHorizontalPadding;
823 imageView = [self addImageWithSize:[image size] toView:view atPoint:point]; 820 imageView = [self addImageWithSize:[image size] toView:view atPoint:point];
824 [imageView setImage:image]; 821 [imageView setImage:image];
825 point.x -= kPermissionImageSpacing; 822 point.x -= kPermissionImageSpacing;
826 823
827 label = [self addText:labelText 824 label = [self addText:labelText
828 withSize:[NSFont smallSystemFontSize] 825 withSize:[NSFont systemFontSize]
829 bold:NO 826 bold:NO
830 toView:view 827 toView:view
831 atPoint:point]; 828 atPoint:point];
832 [label sizeToFit]; 829 [label sizeToFit];
833 point.x -= NSWidth([label frame]); 830 point.x -= NSWidth([label frame]);
834 [label setFrameOrigin:point]; 831 [label setFrameOrigin:point];
835 832
836 position = NSMakePoint(point.x, point.y); 833 position =
834 NSMakePoint(point.x, point.y + kPermissionPopupButtonYAdjustment);
837 button = [self addPopUpButtonForPermission:permissionInfo 835 button = [self addPopUpButtonForPermission:permissionInfo
838 toView:view 836 toView:view
839 atPoint:position]; 837 atPoint:position];
840 position.x -= NSWidth([button frame]); 838 position.x -= NSWidth([button frame]);
841 [button setFrameOrigin:position]; 839 [button setFrameOrigin:position];
842 } else { 840 } else {
843 imageView = [self addImageWithSize:[image size] toView:view atPoint:point]; 841 imageView = [self addImageWithSize:[image size] toView:view atPoint:point];
844 [imageView setImage:image]; 842 [imageView setImage:image];
845 point.x += kPermissionImageSize + kPermissionImageSpacing; 843 point.x += kPermissionImageSize + kPermissionImageSpacing;
846 844
847 label = [self addText:labelText 845 label = [self addText:labelText
848 withSize:[NSFont smallSystemFontSize] 846 withSize:[NSFont systemFontSize]
849 bold:NO 847 bold:NO
850 toView:view 848 toView:view
851 atPoint:point]; 849 atPoint:point];
852 [label sizeToFit]; 850 [label sizeToFit];
853 851
854 position = NSMakePoint(NSMaxX([label frame]), point.y); 852 position = NSMakePoint(NSMaxX([label frame]),
853 point.y + kPermissionPopupButtonYAdjustment);
854
855 button = [self addPopUpButtonForPermission:permissionInfo 855 button = [self addPopUpButtonForPermission:permissionInfo
856 toView:view 856 toView:view
857 atPoint:position]; 857 atPoint:position];
858 } 858 }
859 859
860 [view setFrameSize:NSMakeSize(viewWidth, NSHeight([view frame]))]; 860 [view setFrameSize:NSMakeSize(viewWidth, NSHeight([view frame]))];
861 861
862 // Adjust the vertical position of the button so that its title text is 862 // Adjust the vertical position of the button so that its title text is
863 // aligned with the label. Assumes that the text is the same size in both. 863 // aligned with the label. Assumes that the text is the same size in both.
864 // Also adjust the horizontal position to remove excess space due to the 864 // Also adjust the horizontal position to remove excess space due to the
865 // invisible bezel. 865 // invisible bezel.
866 NSRect titleRect = [[button cell] titleRectForBounds:[button bounds]]; 866 NSRect titleRect = [[button cell] titleRectForBounds:[button bounds]];
867 if (isRTL) { 867 if (isRTL) {
868 position.x += kPermissionPopUpXSpacing; 868 position.x = kSectionHorizontalPadding;
869 } else { 869 } else {
870 position.x -= titleRect.origin.x - kPermissionPopUpXSpacing; 870 position.x = kDefaultWindowWidth - kSectionHorizontalPadding -
871 [button frame].size.width;
871 } 872 }
872 position.y -= titleRect.origin.y; 873 position.y -= titleRect.origin.y;
873 [button setFrameOrigin:position]; 874 [button setFrameOrigin:position];
874 875
875 // Align the icon with the text. 876 // Align the icon with the text.
876 [self alignPermissionIcon:imageView withTextField:label]; 877 [self alignPermissionIcon:imageView withTextField:label];
877 878
878 // Permissions specified by policy or an extension cannot be changed. 879 // Permissions specified by policy or an extension cannot be changed.
879 if (permissionInfo.source == content_settings::SETTING_SOURCE_EXTENSION || 880 if (permissionInfo.source == content_settings::SETTING_SOURCE_EXTENSION ||
880 permissionInfo.source == content_settings::SETTING_SOURCE_POLICY) { 881 permissionInfo.source == content_settings::SETTING_SOURCE_POLICY) {
881 [button setEnabled:NO]; 882 [button setEnabled:NO];
882 } 883 }
883 884
884 NSRect buttonFrame = [button frame]; 885 NSRect buttonFrame = [button frame];
885 return NSMakePoint(NSMaxX(buttonFrame), NSMaxY(buttonFrame)); 886 return NSMakePoint(NSMaxX(buttonFrame), NSMaxY(buttonFrame));
886 } 887 }
887 888
888 // Adds a new row to the UI listing the permissions. Returns the NSPoint of the 889 // Adds a new row to the UI listing the permissions. Returns the NSPoint of the
889 // last UI element added (either the permission button, in LTR, or the text 890 // last UI element added (either the permission button, in LTR, or the text
890 // label, in RTL). 891 // label, in RTL).
891 - (NSPoint)addChosenObject:(ChosenObjectInfoPtr)objectInfo 892 - (NSPoint)addChosenObject:(ChosenObjectInfoPtr)objectInfo
892 toView:(NSView*)view 893 toView:(NSView*)view
893 atPoint:(NSPoint)point { 894 atPoint:(NSPoint)point {
894 base::string16 labelText = l10n_util::GetStringFUTF16( 895 base::string16 labelText = l10n_util::GetStringFUTF16(
895 objectInfo->ui_info.label_string_id, 896 objectInfo->ui_info.label_string_id,
896 WebsiteSettingsUI::ChosenObjectToUIString(*objectInfo)); 897 WebsiteSettingsUI::ChosenObjectToUIString(*objectInfo));
897 bool isRTL = 898 bool isRTL = base::i18n::IsRTL();
898 base::i18n::RIGHT_TO_LEFT == base::i18n::GetStringDirection(labelText);
899 base::scoped_nsobject<NSImage> image( 899 base::scoped_nsobject<NSImage> image(
900 [WebsiteSettingsUI::GetChosenObjectIcon(*objectInfo, false) 900 [WebsiteSettingsUI::GetChosenObjectIcon(*objectInfo, false)
901 .ToNSImage() retain]); 901 .ToNSImage() retain]);
902 902
903 NSPoint position; 903 NSPoint position;
904 NSImageView* imageView; 904 NSImageView* imageView;
905 NSButton* button; 905 NSButton* button;
906 NSTextField* label; 906 NSTextField* label;
907 907
908 CGFloat viewWidth = NSWidth([view frame]); 908 CGFloat viewWidth = NSWidth([view frame]);
909 909
910 if (isRTL) { 910 if (isRTL) {
911 point.x = NSWidth([view frame]) - kPermissionImageSize - 911 point.x = NSWidth([view frame]) - kPermissionImageSize -
912 kPermissionImageSpacing - kSectionHorizontalPadding; 912 kPermissionImageSpacing - kSectionHorizontalPadding;
913 imageView = [self addImageWithSize:[image size] toView:view atPoint:point]; 913 imageView = [self addImageWithSize:[image size] toView:view atPoint:point];
914 [imageView setImage:image]; 914 [imageView setImage:image];
915 point.x -= kPermissionImageSpacing; 915 point.x -= kPermissionImageSpacing;
916 916
917 label = [self addText:labelText 917 label = [self addText:labelText
918 withSize:[NSFont smallSystemFontSize] 918 withSize:[NSFont systemFontSize]
919 bold:NO 919 bold:NO
920 toView:view 920 toView:view
921 atPoint:point]; 921 atPoint:point];
922 [label sizeToFit]; 922 [label sizeToFit];
923 point.x -= NSWidth([label frame]); 923 point.x -= NSWidth([label frame]);
924 [label setFrameOrigin:point]; 924 [label setFrameOrigin:point];
925 925
926 position = NSMakePoint(point.x, point.y); 926 position = NSMakePoint(point.x, point.y);
927 button = [self addDeleteButtonForChosenObject:std::move(objectInfo) 927 button = [self addDeleteButtonForChosenObject:std::move(objectInfo)
928 toView:view 928 toView:view
929 atPoint:position]; 929 atPoint:position];
930 position.x -= NSWidth([button frame]); 930 position.x -= NSWidth([button frame]);
931 [button setFrameOrigin:position]; 931 [button setFrameOrigin:position];
932 } else { 932 } else {
933 imageView = [self addImageWithSize:[image size] toView:view atPoint:point]; 933 imageView = [self addImageWithSize:[image size] toView:view atPoint:point];
934 [imageView setImage:image]; 934 [imageView setImage:image];
935 point.x += kPermissionImageSize + kPermissionImageSpacing; 935 point.x += kPermissionImageSize + kPermissionImageSpacing;
936 936
937 label = [self addText:labelText 937 label = [self addText:labelText
938 withSize:[NSFont smallSystemFontSize] 938 withSize:[NSFont systemFontSize]
939 bold:NO 939 bold:NO
940 toView:view 940 toView:view
941 atPoint:point]; 941 atPoint:point];
942 [label sizeToFit]; 942 [label sizeToFit];
943 943
944 position = NSMakePoint(NSMaxX([label frame]), point.y); 944 position = NSMakePoint(NSMaxX([label frame]), point.y);
945 button = [self addDeleteButtonForChosenObject:std::move(objectInfo) 945 button = [self addDeleteButtonForChosenObject:std::move(objectInfo)
946 toView:view 946 toView:view
947 atPoint:position]; 947 atPoint:position];
948 } 948 }
949 949
950 [view setFrameSize:NSMakeSize(viewWidth, NSHeight([view frame]))]; 950 [view setFrameSize:NSMakeSize(viewWidth, NSHeight([view frame]))];
951 951
952 // Adjust the vertical position of the button so that its title text is 952 // Adjust the vertical position of the button so that its title text is
953 // aligned with the label. Assumes that the text is the same size in both. 953 // aligned with the label. Assumes that the text is the same size in both.
954 // Also adjust the horizontal position to remove excess space due to the 954 // Also adjust the horizontal position to remove excess space due to the
955 // invisible bezel. 955 // invisible bezel.
956 NSRect titleRect = [[button cell] titleRectForBounds:[button bounds]]; 956 NSRect titleRect = [[button cell] titleRectForBounds:[button bounds]];
957 if (isRTL) {
958 position.x += kPermissionPopUpXSpacing;
959 } else {
960 position.x -= titleRect.origin.x - kPermissionPopUpXSpacing;
961 }
962 position.y -= titleRect.origin.y; 957 position.y -= titleRect.origin.y;
963 [button setFrameOrigin:position]; 958 [button setFrameOrigin:position];
964 959
965 // Align the icon with the text. 960 // Align the icon with the text.
966 [self alignPermissionIcon:imageView withTextField:label]; 961 [self alignPermissionIcon:imageView withTextField:label];
967 962
968 NSRect buttonFrame = [button frame]; 963 NSRect buttonFrame = [button frame];
969 return NSMakePoint(NSMaxX(buttonFrame), NSMaxY(buttonFrame)); 964 return NSMakePoint(NSMaxX(buttonFrame), NSMaxY(buttonFrame));
970 } 965 }
971 966
972 // Align an image with a text field by vertically centering the image on 967 // Align an image with a text field by vertically centering the image on
973 // the cap height of the first line of text. 968 // the cap height of the first line of text.
974 - (void)alignPermissionIcon:(NSImageView*)imageView 969 - (void)alignPermissionIcon:(NSImageView*)imageView
975 withTextField:(NSTextField*)textField { 970 withTextField:(NSTextField*)textField {
976 NSFont* font = [textField font];
977
978 // Calculate the offset from the top of the text field.
979 CGFloat capHeight = [font capHeight];
980 CGFloat offset = (kPermissionImageSize - capHeight) / 2 -
981 ([font ascender] - capHeight) - kPermissionImageYAdjust;
982 971
983 NSRect frame = [imageView frame]; 972 NSRect frame = [imageView frame];
984 frame.origin.y -= offset; 973 frame.origin.y += kPermissionIconYAdjustment;
985 [imageView setFrame:frame]; 974 [imageView setFrame:frame];
986 } 975 }
987 976
988 - (void)setCookieInfo:(const CookieInfoList&)cookieInfoList { 977 - (void)setCookieInfo:(const CookieInfoList&)cookieInfoList {
989 // A result of re-ordering of the permissions (crbug.com/444244) is 978 // A result of re-ordering of the permissions (crbug.com/444244) is
990 // that sometimes permissions may not be displayed at all, so it's 979 // that sometimes permissions may not be displayed at all, so it's
991 // incorrect to check they are set before the cookie info. 980 // incorrect to check they are set before the cookie info.
992 981
993 // |cookieInfoList| should only ever have 2 items: first- and third-party 982 // |cookieInfoList| should only ever have 2 items: first- and third-party
994 // cookies. 983 // cookies.
995 DCHECK_EQ(cookieInfoList.size(), 2u); 984 DCHECK_EQ(cookieInfoList.size(), 2u);
996 base::string16 firstPartyLabelText; 985
997 base::string16 thirdPartyLabelText; 986 int totalAllowed = 0;
998 for (const auto& i : cookieInfoList) { 987 for (const auto& i : cookieInfoList) {
999 if (i.is_first_party) { 988 totalAllowed += i.allowed;
1000 firstPartyLabelText = l10n_util::GetPluralStringFUTF16(
1001 IDS_WEBSITE_SETTINGS_FIRST_PARTY_SITE_DATA, i.allowed);
1002 } else {
1003 thirdPartyLabelText = l10n_util::GetPluralStringFUTF16(
1004 IDS_WEBSITE_SETTINGS_THIRD_PARTY_SITE_DATA, i.allowed);
1005 }
1006 } 989 }
990 base::string16 label_text = l10n_util::GetPluralStringFUTF16(
991 IDS_WEBSITE_SETTINGS_NUM_COOKIES, totalAllowed);
1007 992
1008 base::string16 sectionTitle = 993 base::string16 sectionTitle =
1009 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TITLE_SITE_DATA); 994 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TITLE_SITE_DATA);
1010 bool isRTL = base::i18n::RIGHT_TO_LEFT == 995 bool isRTL = base::i18n::IsRTL();
1011 base::i18n::GetStringDirection(firstPartyLabelText);
1012 996
1013 [cookiesView_ setSubviews:[NSArray array]]; 997 [cookiesView_ setSubviews:[NSArray array]];
1014 NSPoint controlOrigin = NSMakePoint(kSectionHorizontalPadding, 0); 998 NSPoint controlOrigin = NSMakePoint(kSectionHorizontalPadding, 0);
1015 999
1016 NSTextField* label;
1017
1018 CGFloat viewWidth = NSWidth([cookiesView_ frame]); 1000 CGFloat viewWidth = NSWidth([cookiesView_ frame]);
1019 1001
1020 NSTextField* header = [self addText:sectionTitle
1021 withSize:[NSFont smallSystemFontSize]
1022 bold:YES
1023 toView:cookiesView_
1024 atPoint:controlOrigin];
1025 [header sizeToFit];
1026
1027 if (isRTL) {
1028 controlOrigin.x =
1029 viewWidth - kSectionHorizontalPadding - NSWidth([header frame]);
1030 [header setFrameOrigin:controlOrigin];
1031 }
1032 controlOrigin.y += NSHeight([header frame]) + kPermissionsHeadlineSpacing;
1033 controlOrigin.y += kPermissionsTabSpacing;
1034
1035 // Reset X for the cookie image. 1002 // Reset X for the cookie image.
1036 if (isRTL) { 1003 if (isRTL) {
1037 controlOrigin.x = viewWidth - kPermissionImageSize - 1004 controlOrigin.x = viewWidth - kPermissionImageSize -
1038 kPermissionImageSpacing - kSectionHorizontalPadding; 1005 kPermissionImageSpacing - kSectionHorizontalPadding;
1039 } 1006 }
1040 1007
1041 WebsiteSettingsUI::PermissionInfo info; 1008 WebsiteSettingsUI::PermissionInfo info;
1042 info.type = CONTENT_SETTINGS_TYPE_COOKIES; 1009 info.type = CONTENT_SETTINGS_TYPE_COOKIES;
1043 info.setting = CONTENT_SETTING_ALLOW; 1010 info.setting = CONTENT_SETTING_ALLOW;
1044 // info.default_setting, info.source, and info.is_incognito have not been set, 1011 // info.default_setting, info.source, and info.is_incognito have not been set,
1045 // but GetPermissionIcon doesn't use any of those. 1012 // but GetPermissionIcon doesn't use any of those.
1046 NSImage* image = WebsiteSettingsUI::GetPermissionIcon(info).ToNSImage(); 1013 NSImage* image = WebsiteSettingsUI::GetPermissionIcon(info).ToNSImage();
1047 NSImageView* imageView = [self addImageWithSize:[image size] 1014 NSImageView* imageView = [self addImageWithSize:[image size]
1048 toView:cookiesView_ 1015 toView:cookiesView_
1049 atPoint:controlOrigin]; 1016 atPoint:controlOrigin];
1050 [imageView setImage:image]; 1017 [imageView setImage:image];
1051 1018
1052 base::string16 comma = base::ASCIIToUTF16(", "); 1019 NSButton* cookiesButton =
1053 NSString* cookieButtonText = base::SysUTF16ToNSString(firstPartyLabelText); 1020 [self addLinkButtonWithText:base::SysUTF16ToNSString(label_text)
1021 toView:cookiesView_];
1022 [cookiesButton setTarget:self];
1023 [cookiesButton setAction:@selector(showCookiesAndSiteData:)];
1054 1024
1055 if (isRTL) { 1025 if (isRTL) {
1056 NSButton* cookiesButton = 1026 controlOrigin.x -= kPermissionImageSpacing;
1057 [self addLinkButtonWithText:cookieButtonText toView:cookiesView_]; 1027 NSTextField* cookiesLabel =
1058 [cookiesButton setTarget:self]; 1028 [self addText:l10n_util::GetStringUTF16(IDS_PAGE_INFO_COOKIES)
1059 [cookiesButton setAction:@selector(showCookiesAndSiteData:)]; 1029 withSize:[NSFont systemFontSize]
1060 controlOrigin.x -= NSWidth([cookiesButton frame]); 1030 bold:NO
1031 toView:cookiesView_
1032 atPoint:controlOrigin];
1033 [cookiesLabel sizeToFit];
1034
1035 NSPoint cookiesLabelOrigin = [cookiesLabel frame].origin;
1036 cookiesLabelOrigin.x -= NSWidth([cookiesLabel frame]);
1037 [cookiesLabel setFrameOrigin:cookiesLabelOrigin];
1038
1039 // Align the icon with the text.
1040 [self alignPermissionIcon:imageView withTextField:cookiesLabel];
1041
1042 controlOrigin.y += NSHeight([cookiesLabel frame]);
1043 controlOrigin.x -= NSWidth([cookiesButton frame]) - kLinkButtonXAdjustment;
1044 [cookiesButton setFrameOrigin:controlOrigin];
1045 } else {
1046 controlOrigin.x += kPermissionImageSize + kPermissionImageSpacing;
1047 NSTextField* cookiesLabel =
1048 [self addText:l10n_util::GetStringUTF16(IDS_PAGE_INFO_COOKIES)
1049 withSize:[NSFont systemFontSize]
1050 bold:NO
1051 toView:cookiesView_
1052 atPoint:controlOrigin];
1053 [cookiesLabel sizeToFit];
1054
1055 controlOrigin.y += NSHeight([cookiesLabel frame]);
1056 controlOrigin.x -= kLinkButtonXAdjustment;
1061 [cookiesButton setFrameOrigin:controlOrigin]; 1057 [cookiesButton setFrameOrigin:controlOrigin];
1062 1058
1063 label = [self addText:comma + thirdPartyLabelText 1059 // Align the icon with the text.
1064 withSize:[NSFont smallSystemFontSize] 1060 [self alignPermissionIcon:imageView withTextField:cookiesLabel];
1065 bold:NO
1066 toView:cookiesView_
1067 atPoint:controlOrigin];
1068 [label sizeToFit];
1069 controlOrigin.x -= NSWidth([label frame]) - kTextLabelXPadding;
1070 [label setFrameOrigin:controlOrigin];
1071 } else {
1072 controlOrigin.x += kPermissionImageSize + kPermissionImageSpacing;
1073
1074 NSButton* cookiesButton =
1075 [self addLinkButtonWithText:cookieButtonText toView:cookiesView_];
1076 [cookiesButton setTarget:self];
1077 [cookiesButton setAction:@selector(showCookiesAndSiteData:)];
1078 [cookiesButton setFrameOrigin:controlOrigin];
1079
1080 controlOrigin.x += NSWidth([cookiesButton frame]) - kTextLabelXPadding;
1081
1082 label = [self addText:comma + thirdPartyLabelText
1083 withSize:[NSFont smallSystemFontSize]
1084 bold:NO
1085 toView:cookiesView_
1086 atPoint:controlOrigin];
1087 [label sizeToFit];
1088 } 1061 }
1089 1062
1090 // Align the icon with the text. 1063 controlOrigin.y += NSHeight([cookiesButton frame]);
1091 [self alignPermissionIcon:imageView withTextField:label]; 1064 [cookiesView_
1092 1065 setFrameSize:NSMakeSize(NSWidth([cookiesView_ frame]), controlOrigin.y)];
1093 controlOrigin.y += NSHeight([label frame]) + kPermissionsTabSpacing;
1094
1095 [cookiesView_ setFrameSize:
1096 NSMakeSize(NSWidth([cookiesView_ frame]), controlOrigin.y)];
1097 1066
1098 [self performLayout]; 1067 [self performLayout];
1099 } 1068 }
1100 1069
1101 - (void)setPermissionInfo:(const PermissionInfoList&)permissionInfoList 1070 - (void)setPermissionInfo:(const PermissionInfoList&)permissionInfoList
1102 andChosenObjects:(const ChosenObjectInfoList&)chosenObjectInfoList { 1071 andChosenObjects:(const ChosenObjectInfoList&)chosenObjectInfoList {
1103 [permissionsView_ setSubviews:[NSArray array]]; 1072 [permissionsView_ setSubviews:[NSArray array]];
1104 NSPoint controlOrigin = NSMakePoint(kSectionHorizontalPadding, 0); 1073 NSPoint controlOrigin = NSMakePoint(kSectionHorizontalPadding, 0);
1105 1074
1106 permissionsPresent_ = YES; 1075 permissionsPresent_ = YES;
1107 1076
1108 if (permissionInfoList.size() > 0 || chosenObjectInfoList.size() > 0) { 1077 if (permissionInfoList.size() > 0 || chosenObjectInfoList.size() > 0) {
1109 base::string16 sectionTitle = l10n_util::GetStringUTF16( 1078 base::string16 sectionTitle = l10n_util::GetStringUTF16(
1110 IDS_WEBSITE_SETTINGS_TITLE_SITE_PERMISSIONS); 1079 IDS_WEBSITE_SETTINGS_TITLE_SITE_PERMISSIONS);
1111 bool isRTL = base::i18n::RIGHT_TO_LEFT ==
1112 base::i18n::GetStringDirection(sectionTitle);
1113 NSTextField* header = [self addText:sectionTitle
1114 withSize:[NSFont smallSystemFontSize]
1115 bold:YES
1116 toView:permissionsView_
1117 atPoint:controlOrigin];
1118 [header sizeToFit];
1119 if (isRTL) {
1120 controlOrigin.x = NSWidth([permissionsView_ frame]) -
1121 kSectionHorizontalPadding - NSWidth([header frame]);
1122 [header setFrameOrigin:controlOrigin];
1123 }
1124 controlOrigin.y += NSHeight([header frame]) + kPermissionsHeadlineSpacing;
1125 1080
1126 for (const auto& permission : permissionInfoList) { 1081 for (const auto& permission : permissionInfoList) {
1127 controlOrigin.y += kPermissionsTabSpacing; 1082 controlOrigin.y += kPermissionsVerticalSpacing;
1128 NSPoint rowBottomRight = [self addPermission:permission 1083 NSPoint rowBottomRight = [self addPermission:permission
1129 toView:permissionsView_ 1084 toView:permissionsView_
1130 atPoint:controlOrigin]; 1085 atPoint:controlOrigin];
1131 controlOrigin.y = rowBottomRight.y; 1086 controlOrigin.y = rowBottomRight.y;
1132 } 1087 }
1133 1088
1134 for (auto* object : chosenObjectInfoList) { 1089 for (auto* object : chosenObjectInfoList) {
1135 controlOrigin.y += kPermissionsTabSpacing; 1090 controlOrigin.y += kPermissionsVerticalSpacing;
1136 NSPoint rowBottomRight = [self addChosenObject:base::WrapUnique(object) 1091 NSPoint rowBottomRight = [self addChosenObject:base::WrapUnique(object)
1137 toView:permissionsView_ 1092 toView:permissionsView_
1138 atPoint:controlOrigin]; 1093 atPoint:controlOrigin];
1139 controlOrigin.y = rowBottomRight.y; 1094 controlOrigin.y = rowBottomRight.y;
1140 } 1095 }
1141 1096
1142 controlOrigin.y += kPermissionsTabSpacing; 1097 controlOrigin.y += kPermissionsVerticalSpacing;
1143 } 1098 }
1144 1099
1145 [permissionsView_ setFrameSize: 1100 [permissionsView_ setFrameSize:
1146 NSMakeSize(NSWidth([permissionsView_ frame]), controlOrigin.y)]; 1101 NSMakeSize(NSWidth([permissionsView_ frame]), controlOrigin.y)];
1147 [self performLayout]; 1102 [self performLayout];
1148 } 1103 }
1149 1104
1150 @end 1105 @end
1151 1106
1152 WebsiteSettingsUIBridge::WebsiteSettingsUIBridge( 1107 WebsiteSettingsUIBridge::WebsiteSettingsUIBridge(
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 void WebsiteSettingsUIBridge::SetPermissionInfo( 1191 void WebsiteSettingsUIBridge::SetPermissionInfo(
1237 const PermissionInfoList& permission_info_list, 1192 const PermissionInfoList& permission_info_list,
1238 const ChosenObjectInfoList& chosen_object_info_list) { 1193 const ChosenObjectInfoList& chosen_object_info_list) {
1239 [bubble_controller_ setPermissionInfo:permission_info_list 1194 [bubble_controller_ setPermissionInfo:permission_info_list
1240 andChosenObjects:chosen_object_info_list]; 1195 andChosenObjects:chosen_object_info_list];
1241 } 1196 }
1242 1197
1243 void WebsiteSettingsUIBridge::SetSelectedTab(TabId tab_id) { 1198 void WebsiteSettingsUIBridge::SetSelectedTab(TabId tab_id) {
1244 // TODO(lgarron): Remove this from the interface. (crbug.com/571533) 1199 // TODO(lgarron): Remove this from the interface. (crbug.com/571533)
1245 } 1200 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/website_settings/website_settings_bubble_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698