| 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 [cell setControlSize:controlSize]; | 103 [cell setControlSize:controlSize]; |
| 104 } | 104 } |
| 105 | 105 |
| 106 // Returns an autoreleased NSTextField that is configured to look like a Label | 106 // Returns an autoreleased NSTextField that is configured to look like a Label |
| 107 // looks in Interface Builder. | 107 // looks in Interface Builder. |
| 108 NSTextField* LabelWithFrame(NSString* text, const NSRect& frame) { | 108 NSTextField* LabelWithFrame(NSString* text, const NSRect& frame) { |
| 109 NSTextField* label = [[NSTextField alloc] initWithFrame:frame]; | 109 NSTextField* label = [[NSTextField alloc] initWithFrame:frame]; |
| 110 [label setStringValue:text]; | 110 [label setStringValue:text]; |
| 111 [label setSelectable:NO]; | 111 [label setSelectable:NO]; |
| 112 [label setBezeled:NO]; | 112 [label setBezeled:NO]; |
| 113 [label setAlignment:NSNaturalTextAlignment]; |
| 113 return [label autorelease]; | 114 return [label autorelease]; |
| 114 } | 115 } |
| 115 | 116 |
| 116 // Sets the title for the popup button. | 117 // Sets the title for the popup button. |
| 117 void SetTitleForPopUpButton(NSPopUpButton* button, NSString* title) { | 118 void SetTitleForPopUpButton(NSPopUpButton* button, NSString* title) { |
| 118 base::scoped_nsobject<NSMenuItem> titleItem([[NSMenuItem alloc] init]); | 119 base::scoped_nsobject<NSMenuItem> titleItem([[NSMenuItem alloc] init]); |
| 119 [titleItem setTitle:title]; | 120 [titleItem setTitle:title]; |
| 120 [[button cell] setUsesItemFromMenu:NO]; | 121 [[button cell] setUsesItemFromMenu:NO]; |
| 121 [[button cell] setMenuItem:titleItem.get()]; | 122 [[button cell] setMenuItem:titleItem.get()]; |
| 122 } | 123 } |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 | 384 |
| 384 // Layout title post-localization. | 385 // Layout title post-localization. |
| 385 CGFloat deltaY = [GTMUILocalizerAndLayoutTweaker | 386 CGFloat deltaY = [GTMUILocalizerAndLayoutTweaker |
| 386 sizeToFitFixedWidthTextField:titleLabel_]; | 387 sizeToFitFixedWidthTextField:titleLabel_]; |
| 387 NSRect windowFrame = [[self window] frame]; | 388 NSRect windowFrame = [[self window] frame]; |
| 388 windowFrame.size.height += deltaY; | 389 windowFrame.size.height += deltaY; |
| 389 [[self window] setFrame:windowFrame display:NO]; | 390 [[self window] setFrame:windowFrame display:NO]; |
| 390 NSRect titleFrame = [titleLabel_ frame]; | 391 NSRect titleFrame = [titleLabel_ frame]; |
| 391 titleFrame.origin.y -= deltaY; | 392 titleFrame.origin.y -= deltaY; |
| 392 [titleLabel_ setFrame:titleFrame]; | 393 [titleLabel_ setFrame:titleFrame]; |
| 394 [titleLabel_ setAlignment:NSNaturalTextAlignment]; |
| 393 } | 395 } |
| 394 | 396 |
| 395 - (void)initializeMessage { | 397 - (void)initializeMessage { |
| 396 if (!messageLabel_) | 398 if (!messageLabel_) |
| 397 return; | 399 return; |
| 398 | 400 |
| 399 NSString* label = base::SysUTF16ToNSString( | 401 NSString* label = base::SysUTF16ToNSString( |
| 400 contentSettingBubbleModel_->bubble_content().message); | 402 contentSettingBubbleModel_->bubble_content().message); |
| 401 [messageLabel_ setStringValue:label]; | 403 [messageLabel_ setStringValue:label]; |
| 402 | 404 |
| 403 CGFloat deltaY = [GTMUILocalizerAndLayoutTweaker | 405 CGFloat deltaY = [GTMUILocalizerAndLayoutTweaker |
| 404 sizeToFitFixedWidthTextField:messageLabel_]; | 406 sizeToFitFixedWidthTextField:messageLabel_]; |
| 405 NSRect windowFrame = [[self window] frame]; | 407 NSRect windowFrame = [[self window] frame]; |
| 406 windowFrame.size.height += deltaY; | 408 windowFrame.size.height += deltaY; |
| 407 [[self window] setFrame:windowFrame display:NO]; | 409 [[self window] setFrame:windowFrame display:NO]; |
| 408 NSRect messageFrame = [messageLabel_ frame]; | 410 NSRect messageFrame = [messageLabel_ frame]; |
| 409 messageFrame.origin.y -= deltaY; | 411 messageFrame.origin.y -= deltaY; |
| 410 [messageLabel_ setFrame:messageFrame]; | 412 [messageLabel_ setFrame:messageFrame]; |
| 413 [messageLabel_ setAlignment:NSNaturalTextAlignment]; |
| 411 } | 414 } |
| 412 | 415 |
| 413 - (void)initializeRadioGroup { | 416 - (void)initializeRadioGroup { |
| 414 // NOTE! Tags in the xib files must match the order of the radio buttons | 417 // NOTE! Tags in the xib files must match the order of the radio buttons |
| 415 // passed in the radio_group and be 1-based, not 0-based. | 418 // passed in the radio_group and be 1-based, not 0-based. |
| 416 const ContentSettingBubbleModel::BubbleContent& bubble_content = | 419 const ContentSettingBubbleModel::BubbleContent& bubble_content = |
| 417 contentSettingBubbleModel_->bubble_content(); | 420 contentSettingBubbleModel_->bubble_content(); |
| 418 const ContentSettingBubbleModel::RadioGroup& radio_group = | 421 const ContentSettingBubbleModel::RadioGroup& radio_group = |
| 419 bubble_content.radio_group; | 422 bubble_content.radio_group; |
| 420 | 423 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 443 } | 446 } |
| 444 | 447 |
| 445 // Layout radio group labels post-localization. | 448 // Layout radio group labels post-localization. |
| 446 [GTMUILocalizerAndLayoutTweaker | 449 [GTMUILocalizerAndLayoutTweaker |
| 447 wrapRadioGroupForWidth:allowBlockRadioGroup_]; | 450 wrapRadioGroupForWidth:allowBlockRadioGroup_]; |
| 448 CGFloat radioDeltaY = [GTMUILocalizerAndLayoutTweaker | 451 CGFloat radioDeltaY = [GTMUILocalizerAndLayoutTweaker |
| 449 sizeToFitView:allowBlockRadioGroup_].height; | 452 sizeToFitView:allowBlockRadioGroup_].height; |
| 450 NSRect windowFrame = [[self window] frame]; | 453 NSRect windowFrame = [[self window] frame]; |
| 451 windowFrame.size.height += radioDeltaY; | 454 windowFrame.size.height += radioDeltaY; |
| 452 [[self window] setFrame:windowFrame display:NO]; | 455 [[self window] setFrame:windowFrame display:NO]; |
| 456 |
| 457 // NSMatrix-based radio buttons don't get automatically flipped for |
| 458 // RTL. Setting the user interface layout direction explicitly |
| 459 // doesn't affect rendering, so set image position and text alignment |
| 460 // manually. |
| 461 if (cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) |
| 462 for (NSButtonCell* cell in [allowBlockRadioGroup_ cells]) { |
| 463 [cell setAlignment:NSNaturalTextAlignment]; |
| 464 [cell setImagePosition:cocoa_l10n_util::LeadingCellImagePosition()]; |
| 465 // Why not? |
| 466 [cell setUserInterfaceLayoutDirection: |
| 467 NSUserInterfaceLayoutDirectionRightToLeft]; |
| 468 } |
| 453 } | 469 } |
| 454 | 470 |
| 455 - (NSButton*)hyperlinkButtonWithFrame:(NSRect)frame | 471 - (NSButton*)hyperlinkButtonWithFrame:(NSRect)frame |
| 456 title:(NSString*)title | 472 title:(NSString*)title |
| 457 icon:(NSImage*)icon | 473 icon:(NSImage*)icon |
| 458 referenceFrame:(NSRect)referenceFrame { | 474 referenceFrame:(NSRect)referenceFrame { |
| 459 base::scoped_nsobject<HyperlinkButtonCell> cell( | 475 base::scoped_nsobject<HyperlinkButtonCell> cell( |
| 460 [[HyperlinkButtonCell alloc] initTextCell:title]); | 476 [[HyperlinkButtonCell alloc] initTextCell:title]); |
| 461 [cell.get() setAlignment:NSNaturalTextAlignment]; | 477 [cell.get() setAlignment:NSNaturalTextAlignment]; |
| 462 if (icon) { | 478 if (icon) { |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 975 [manageButton_ removeFromSuperview]; | 991 [manageButton_ removeFromSuperview]; |
| 976 | 992 |
| 977 NSRect frame = [[self window] frame]; | 993 NSRect frame = [[self window] frame]; |
| 978 frame.size.height -= delta; | 994 frame.size.height -= delta; |
| 979 [[self window] setFrame:frame display:NO]; | 995 [[self window] setFrame:frame display:NO]; |
| 980 } | 996 } |
| 981 } | 997 } |
| 982 | 998 |
| 983 if (contentSettingBubbleModel_->AsMediaStreamBubbleModel()) | 999 if (contentSettingBubbleModel_->AsMediaStreamBubbleModel()) |
| 984 [self initializeMediaMenus]; | 1000 [self initializeMediaMenus]; |
| 1001 |
| 1002 // RTL-ize NIBS: |
| 1003 if (cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) { |
| 1004 cocoa_l10n_util::FlipAllSubviewsIfNecessary([self bubble]); |
| 1005 |
| 1006 // Some NIBs have the manage/done buttons outside of the bubble. |
| 1007 cocoa_l10n_util::FlipAllSubviewsIfNecessary([[self bubble] superview]); |
| 1008 cocoa_l10n_util::FlipAllSubviewsIfNecessary(contentsContainer_); |
| 1009 |
| 1010 // These buttons are inside |GTMWidthBasedTweaker|s, so fix margins. |
| 1011 cocoa_l10n_util::FlipAllSubviewsIfNecessary([infoButton_ superview]); |
| 1012 cocoa_l10n_util::FlipAllSubviewsIfNecessary([doneButton_ superview]); |
| 1013 cocoa_l10n_util::FlipAllSubviewsIfNecessary([manageButton_ superview]); |
| 1014 } |
| 985 } | 1015 } |
| 986 | 1016 |
| 987 /////////////////////////////////////////////////////////////////////////////// | 1017 /////////////////////////////////////////////////////////////////////////////// |
| 988 // Actual application logic | 1018 // Actual application logic |
| 989 | 1019 |
| 990 - (IBAction)allowBlockToggled:(id)sender { | 1020 - (IBAction)allowBlockToggled:(id)sender { |
| 991 NSButtonCell *selectedCell = [sender selectedCell]; | 1021 NSButtonCell *selectedCell = [sender selectedCell]; |
| 992 contentSettingBubbleModel_->OnRadioClicked([selectedCell tag] - 1); | 1022 contentSettingBubbleModel_->OnRadioClicked([selectedCell tag] - 1); |
| 993 } | 1023 } |
| 994 | 1024 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1045 | 1075 |
| 1046 - (content_setting_bubble::MediaMenuPartsMap*)mediaMenus { | 1076 - (content_setting_bubble::MediaMenuPartsMap*)mediaMenus { |
| 1047 return &mediaMenus_; | 1077 return &mediaMenus_; |
| 1048 } | 1078 } |
| 1049 | 1079 |
| 1050 - (LocationBarDecoration*)decorationForBubble { | 1080 - (LocationBarDecoration*)decorationForBubble { |
| 1051 return decoration_; | 1081 return decoration_; |
| 1052 } | 1082 } |
| 1053 | 1083 |
| 1054 @end // ContentSettingBubbleController | 1084 @end // ContentSettingBubbleController |
| OLD | NEW |