Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/content_settings/content_setting_bubble_cocoa.h " | 5 #import "chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.h " |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 [cell setControlSize:controlSize]; | 92 [cell setControlSize:controlSize]; |
| 93 } | 93 } |
| 94 | 94 |
| 95 // Returns an autoreleased NSTextField that is configured to look like a Label | 95 // Returns an autoreleased NSTextField that is configured to look like a Label |
| 96 // looks in Interface Builder. | 96 // looks in Interface Builder. |
| 97 NSTextField* LabelWithFrame(NSString* text, const NSRect& frame) { | 97 NSTextField* LabelWithFrame(NSString* text, const NSRect& frame) { |
| 98 NSTextField* label = [[NSTextField alloc] initWithFrame:frame]; | 98 NSTextField* label = [[NSTextField alloc] initWithFrame:frame]; |
| 99 [label setStringValue:text]; | 99 [label setStringValue:text]; |
| 100 [label setSelectable:NO]; | 100 [label setSelectable:NO]; |
| 101 [label setBezeled:NO]; | 101 [label setBezeled:NO]; |
| 102 [label setAlignment:NSNaturalTextAlignment]; | |
| 102 return [label autorelease]; | 103 return [label autorelease]; |
| 103 } | 104 } |
| 104 | 105 |
| 105 // Sets the title for the popup button. | 106 // Sets the title for the popup button. |
| 106 void SetTitleForPopUpButton(NSPopUpButton* button, NSString* title) { | 107 void SetTitleForPopUpButton(NSPopUpButton* button, NSString* title) { |
| 107 base::scoped_nsobject<NSMenuItem> titleItem([[NSMenuItem alloc] init]); | 108 base::scoped_nsobject<NSMenuItem> titleItem([[NSMenuItem alloc] init]); |
| 108 [titleItem setTitle:title]; | 109 [titleItem setTitle:title]; |
| 109 [[button cell] setUsesItemFromMenu:NO]; | 110 [[button cell] setUsesItemFromMenu:NO]; |
| 110 [[button cell] setMenuItem:titleItem.get()]; | 111 [[button cell] setMenuItem:titleItem.get()]; |
| 111 } | 112 } |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 | 373 |
| 373 // Layout title post-localization. | 374 // Layout title post-localization. |
| 374 CGFloat deltaY = [GTMUILocalizerAndLayoutTweaker | 375 CGFloat deltaY = [GTMUILocalizerAndLayoutTweaker |
| 375 sizeToFitFixedWidthTextField:titleLabel_]; | 376 sizeToFitFixedWidthTextField:titleLabel_]; |
| 376 NSRect windowFrame = [[self window] frame]; | 377 NSRect windowFrame = [[self window] frame]; |
| 377 windowFrame.size.height += deltaY; | 378 windowFrame.size.height += deltaY; |
| 378 [[self window] setFrame:windowFrame display:NO]; | 379 [[self window] setFrame:windowFrame display:NO]; |
| 379 NSRect titleFrame = [titleLabel_ frame]; | 380 NSRect titleFrame = [titleLabel_ frame]; |
| 380 titleFrame.origin.y -= deltaY; | 381 titleFrame.origin.y -= deltaY; |
| 381 [titleLabel_ setFrame:titleFrame]; | 382 [titleLabel_ setFrame:titleFrame]; |
| 383 [titleLabel_ setAlignment:NSNaturalTextAlignment]; | |
| 382 } | 384 } |
| 383 | 385 |
| 384 - (void)initializeMessage { | 386 - (void)initializeMessage { |
| 385 if (!messageLabel_) | 387 if (!messageLabel_) |
| 386 return; | 388 return; |
| 387 | 389 |
| 388 NSString* label = base::SysUTF16ToNSString( | 390 NSString* label = base::SysUTF16ToNSString( |
| 389 contentSettingBubbleModel_->bubble_content().message); | 391 contentSettingBubbleModel_->bubble_content().message); |
| 390 [messageLabel_ setStringValue:label]; | 392 [messageLabel_ setStringValue:label]; |
| 391 | 393 |
| 392 CGFloat deltaY = [GTMUILocalizerAndLayoutTweaker | 394 CGFloat deltaY = [GTMUILocalizerAndLayoutTweaker |
| 393 sizeToFitFixedWidthTextField:messageLabel_]; | 395 sizeToFitFixedWidthTextField:messageLabel_]; |
| 394 NSRect windowFrame = [[self window] frame]; | 396 NSRect windowFrame = [[self window] frame]; |
| 395 windowFrame.size.height += deltaY; | 397 windowFrame.size.height += deltaY; |
| 396 [[self window] setFrame:windowFrame display:NO]; | 398 [[self window] setFrame:windowFrame display:NO]; |
| 397 NSRect messageFrame = [messageLabel_ frame]; | 399 NSRect messageFrame = [messageLabel_ frame]; |
| 398 messageFrame.origin.y -= deltaY; | 400 messageFrame.origin.y -= deltaY; |
| 399 [messageLabel_ setFrame:messageFrame]; | 401 [messageLabel_ setFrame:messageFrame]; |
| 402 [messageLabel_ setAlignment:NSNaturalTextAlignment]; | |
| 400 } | 403 } |
| 401 | 404 |
| 402 - (void)initializeRadioGroup { | 405 - (void)initializeRadioGroup { |
| 403 // NOTE! Tags in the xib files must match the order of the radio buttons | 406 // NOTE! Tags in the xib files must match the order of the radio buttons |
| 404 // passed in the radio_group and be 1-based, not 0-based. | 407 // passed in the radio_group and be 1-based, not 0-based. |
| 405 const ContentSettingBubbleModel::BubbleContent& bubble_content = | 408 const ContentSettingBubbleModel::BubbleContent& bubble_content = |
| 406 contentSettingBubbleModel_->bubble_content(); | 409 contentSettingBubbleModel_->bubble_content(); |
| 407 const ContentSettingBubbleModel::RadioGroup& radio_group = | 410 const ContentSettingBubbleModel::RadioGroup& radio_group = |
| 408 bubble_content.radio_group; | 411 bubble_content.radio_group; |
| 409 | 412 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 432 } | 435 } |
| 433 | 436 |
| 434 // Layout radio group labels post-localization. | 437 // Layout radio group labels post-localization. |
| 435 [GTMUILocalizerAndLayoutTweaker | 438 [GTMUILocalizerAndLayoutTweaker |
| 436 wrapRadioGroupForWidth:allowBlockRadioGroup_]; | 439 wrapRadioGroupForWidth:allowBlockRadioGroup_]; |
| 437 CGFloat radioDeltaY = [GTMUILocalizerAndLayoutTweaker | 440 CGFloat radioDeltaY = [GTMUILocalizerAndLayoutTweaker |
| 438 sizeToFitView:allowBlockRadioGroup_].height; | 441 sizeToFitView:allowBlockRadioGroup_].height; |
| 439 NSRect windowFrame = [[self window] frame]; | 442 NSRect windowFrame = [[self window] frame]; |
| 440 windowFrame.size.height += radioDeltaY; | 443 windowFrame.size.height += radioDeltaY; |
| 441 [[self window] setFrame:windowFrame display:NO]; | 444 [[self window] setFrame:windowFrame display:NO]; |
| 445 | |
| 446 // NSMatrix-based radio buttons don't get automatically flipped for | |
| 447 // RTL. Setting the user interface layout direction explicitly | |
| 448 // doesn't affect rendering, so set image position and text alignment | |
| 449 // manually. | |
| 450 if (cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) | |
| 451 for (NSButtonCell* cell in [allowBlockRadioGroup_ cells]) { | |
| 452 [cell setAlignment:NSNaturalTextAlignment]; | |
| 453 [cell setImagePosition:cocoa_l10n_util::LeadingCellImagePosition()]; | |
| 454 // Why not? | |
| 455 [cell setUserInterfaceLayoutDirection: | |
| 456 NSUserInterfaceLayoutDirectionRightToLeft]; | |
| 457 } | |
| 442 } | 458 } |
| 443 | 459 |
| 444 - (NSButton*)hyperlinkButtonWithFrame:(NSRect)frame | 460 - (NSButton*)hyperlinkButtonWithFrame:(NSRect)frame |
| 445 title:(NSString*)title | 461 title:(NSString*)title |
| 446 icon:(NSImage*)icon | 462 icon:(NSImage*)icon |
| 447 referenceFrame:(NSRect)referenceFrame { | 463 referenceFrame:(NSRect)referenceFrame { |
| 448 base::scoped_nsobject<HyperlinkButtonCell> cell( | 464 base::scoped_nsobject<HyperlinkButtonCell> cell( |
| 449 [[HyperlinkButtonCell alloc] initTextCell:title]); | 465 [[HyperlinkButtonCell alloc] initTextCell:title]); |
| 450 [cell.get() setAlignment:NSNaturalTextAlignment]; | 466 [cell.get() setAlignment:NSNaturalTextAlignment]; |
| 451 if (icon) { | 467 if (icon) { |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 912 [manageButton_ removeFromSuperview]; | 928 [manageButton_ removeFromSuperview]; |
| 913 | 929 |
| 914 NSRect frame = [[self window] frame]; | 930 NSRect frame = [[self window] frame]; |
| 915 frame.size.height -= delta; | 931 frame.size.height -= delta; |
| 916 [[self window] setFrame:frame display:NO]; | 932 [[self window] setFrame:frame display:NO]; |
| 917 } | 933 } |
| 918 } | 934 } |
| 919 | 935 |
| 920 if (contentSettingBubbleModel_->AsMediaStreamBubbleModel()) | 936 if (contentSettingBubbleModel_->AsMediaStreamBubbleModel()) |
| 921 [self initializeMediaMenus]; | 937 [self initializeMediaMenus]; |
| 938 // RTL-ize NIBS: | |
|
Avi (use Gerrit)
2017/06/09 17:41:05
blank line above this comment to separate it from
lgrey
2017/06/09 17:59:13
Done.
| |
| 939 if (cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) { | |
| 940 cocoa_l10n_util::FlipAllSubviewsIfNecessary([self bubble]); | |
| 941 // Some NIBs have the manage/done buttons outside of the bubble. | |
| 942 cocoa_l10n_util::FlipAllSubviewsIfNecessary([[self bubble] superview]); | |
| 943 cocoa_l10n_util::FlipAllSubviewsIfNecessary(contentsContainer_); | |
| 944 // These buttons are inside |GTMWidthBasedTweaker|s, so fix margins. | |
| 945 cocoa_l10n_util::FlipAllSubviewsIfNecessary([infoButton_ superview]); | |
| 946 cocoa_l10n_util::FlipAllSubviewsIfNecessary([doneButton_ superview]); | |
| 947 cocoa_l10n_util::FlipAllSubviewsIfNecessary([manageButton_ superview]); | |
|
Avi (use Gerrit)
2017/06/09 17:41:05
for both of these line comments (941, 944), since
lgrey
2017/06/09 17:59:13
Done.
| |
| 948 } | |
| 922 } | 949 } |
| 923 | 950 |
| 924 /////////////////////////////////////////////////////////////////////////////// | 951 /////////////////////////////////////////////////////////////////////////////// |
| 925 // Actual application logic | 952 // Actual application logic |
| 926 | 953 |
| 927 - (IBAction)allowBlockToggled:(id)sender { | 954 - (IBAction)allowBlockToggled:(id)sender { |
| 928 NSButtonCell *selectedCell = [sender selectedCell]; | 955 NSButtonCell *selectedCell = [sender selectedCell]; |
| 929 contentSettingBubbleModel_->OnRadioClicked([selectedCell tag] - 1); | 956 contentSettingBubbleModel_->OnRadioClicked([selectedCell tag] - 1); |
| 930 } | 957 } |
| 931 | 958 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 982 | 1009 |
| 983 - (content_setting_bubble::MediaMenuPartsMap*)mediaMenus { | 1010 - (content_setting_bubble::MediaMenuPartsMap*)mediaMenus { |
| 984 return &mediaMenus_; | 1011 return &mediaMenus_; |
| 985 } | 1012 } |
| 986 | 1013 |
| 987 - (LocationBarDecoration*)decorationForBubble { | 1014 - (LocationBarDecoration*)decorationForBubble { |
| 988 return decoration_; | 1015 return decoration_; |
| 989 } | 1016 } |
| 990 | 1017 |
| 991 @end // ContentSettingBubbleController | 1018 @end // ContentSettingBubbleController |
| OLD | NEW |