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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 | 63 |
64 // Padding between media menu elements in the media bubble. | 64 // Padding between media menu elements in the media bubble. |
65 const int kMediaMenuElementVerticalPadding = 5; | 65 const int kMediaMenuElementVerticalPadding = 5; |
66 | 66 |
67 // The amount of horizontal space between the media menu title and the border. | 67 // The amount of horizontal space between the media menu title and the border. |
68 const int kMediaMenuTitleHorizontalPadding = 10; | 68 const int kMediaMenuTitleHorizontalPadding = 10; |
69 | 69 |
70 // The minimum width of the media menu buttons. | 70 // The minimum width of the media menu buttons. |
71 const CGFloat kMinMediaMenuButtonWidth = 100; | 71 const CGFloat kMinMediaMenuButtonWidth = 100; |
72 | 72 |
73 // Height of each of the labels in the MIDI bubble. | |
74 const int kMIDISysExLabelHeight = 14; | |
75 | |
76 // Height of the "Clear" button in the MIDI bubble. | |
77 const int kMIDISysExClearButtonHeight = 17; | |
78 | |
79 // General padding between elements in the MIDI bubble. | |
80 const int kMIDISysExPadding = 8; | |
81 | |
82 // Padding between host names in the MIDI bubble. | |
83 const int kMIDISysExHostPadding = 4; | |
84 | |
73 void SetControlSize(NSControl* control, NSControlSize controlSize) { | 85 void SetControlSize(NSControl* control, NSControlSize controlSize) { |
74 CGFloat fontSize = [NSFont systemFontSizeForControlSize:controlSize]; | 86 CGFloat fontSize = [NSFont systemFontSizeForControlSize:controlSize]; |
75 NSCell* cell = [control cell]; | 87 NSCell* cell = [control cell]; |
76 NSFont* font = [NSFont fontWithName:[[cell font] fontName] size:fontSize]; | 88 NSFont* font = [NSFont fontWithName:[[cell font] fontName] size:fontSize]; |
77 [cell setFont:font]; | 89 [cell setFont:font]; |
78 [cell setControlSize:controlSize]; | 90 [cell setControlSize:controlSize]; |
79 } | 91 } |
80 | 92 |
81 // Returns an autoreleased NSTextField that is configured to look like a Label | 93 // Returns an autoreleased NSTextField that is configured to look like a Label |
82 // looks in Interface Builder. | 94 // looks in Interface Builder. |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 - (NSButton*)hyperlinkButtonWithFrame:(NSRect)frame | 176 - (NSButton*)hyperlinkButtonWithFrame:(NSRect)frame |
165 title:(NSString*)title | 177 title:(NSString*)title |
166 icon:(NSImage*)icon | 178 icon:(NSImage*)icon |
167 referenceFrame:(NSRect)referenceFrame; | 179 referenceFrame:(NSRect)referenceFrame; |
168 - (void)initializeBlockedPluginsList; | 180 - (void)initializeBlockedPluginsList; |
169 - (void)initializeTitle; | 181 - (void)initializeTitle; |
170 - (void)initializeRadioGroup; | 182 - (void)initializeRadioGroup; |
171 - (void)initializePopupList; | 183 - (void)initializePopupList; |
172 - (void)initializeGeoLists; | 184 - (void)initializeGeoLists; |
173 - (void)initializeMediaMenus; | 185 - (void)initializeMediaMenus; |
186 - (void)initializeMIDISysExLists; | |
174 - (void)sizeToFitLoadButton; | 187 - (void)sizeToFitLoadButton; |
175 - (void)initManageDoneButtons; | 188 - (void)initManageDoneButtons; |
176 - (void)removeInfoButton; | 189 - (void)removeInfoButton; |
177 - (void)popupLinkClicked:(id)sender; | 190 - (void)popupLinkClicked:(id)sender; |
178 - (void)clearGeolocationForCurrentHost:(id)sender; | 191 - (void)clearGeolocationForCurrentHost:(id)sender; |
192 - (void)clearMIDISysExForCurrentHost:(id)sender; | |
179 @end | 193 @end |
180 | 194 |
181 @implementation ContentSettingBubbleController | 195 @implementation ContentSettingBubbleController |
182 | 196 |
183 + (ContentSettingBubbleController*) | 197 + (ContentSettingBubbleController*) |
184 showForModel:(ContentSettingBubbleModel*)contentSettingBubbleModel | 198 showForModel:(ContentSettingBubbleModel*)contentSettingBubbleModel |
185 parentWindow:(NSWindow*)parentWindow | 199 parentWindow:(NSWindow*)parentWindow |
186 anchoredAt:(NSPoint)anchor { | 200 anchoredAt:(NSPoint)anchor { |
187 // Autoreleases itself on bubble close. | 201 // Autoreleases itself on bubble close. |
188 return [[ContentSettingBubbleController alloc] | 202 return [[ContentSettingBubbleController alloc] |
(...skipping 25 matching lines...) Expand all Loading... | |
214 case CONTENT_SETTINGS_TYPE_GEOLOCATION: | 228 case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
215 nibPath = @"ContentBlockedGeolocation"; break; | 229 nibPath = @"ContentBlockedGeolocation"; break; |
216 case CONTENT_SETTINGS_TYPE_MIXEDSCRIPT: | 230 case CONTENT_SETTINGS_TYPE_MIXEDSCRIPT: |
217 nibPath = @"ContentBlockedMixedScript"; break; | 231 nibPath = @"ContentBlockedMixedScript"; break; |
218 case CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS: | 232 case CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS: |
219 nibPath = @"ContentProtocolHandlers"; break; | 233 nibPath = @"ContentProtocolHandlers"; break; |
220 case CONTENT_SETTINGS_TYPE_MEDIASTREAM: | 234 case CONTENT_SETTINGS_TYPE_MEDIASTREAM: |
221 nibPath = @"ContentBlockedMedia"; break; | 235 nibPath = @"ContentBlockedMedia"; break; |
222 case CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS: | 236 case CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS: |
223 nibPath = @"ContentBlockedDownloads"; break; | 237 nibPath = @"ContentBlockedDownloads"; break; |
238 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: | |
239 nibPath = @"ContentBlockedMIDISysEx"; break; | |
224 // These content types have no bubble: | 240 // These content types have no bubble: |
225 case CONTENT_SETTINGS_TYPE_DEFAULT: | 241 case CONTENT_SETTINGS_TYPE_DEFAULT: |
226 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: | 242 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: |
227 case CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE: | 243 case CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE: |
228 case CONTENT_SETTINGS_TYPE_FULLSCREEN: | 244 case CONTENT_SETTINGS_TYPE_FULLSCREEN: |
229 case CONTENT_SETTINGS_TYPE_MOUSELOCK: | 245 case CONTENT_SETTINGS_TYPE_MOUSELOCK: |
230 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC: | 246 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC: |
231 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA: | 247 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA: |
232 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: | |
233 case CONTENT_SETTINGS_NUM_TYPES: | 248 case CONTENT_SETTINGS_NUM_TYPES: |
234 NOTREACHED(); | 249 NOTREACHED(); |
235 } | 250 } |
236 if ((self = [super initWithWindowNibPath:nibPath | 251 if ((self = [super initWithWindowNibPath:nibPath |
237 parentWindow:parentWindow | 252 parentWindow:parentWindow |
238 anchoredAt:anchoredAt])) { | 253 anchoredAt:anchoredAt])) { |
239 contentSettingBubbleModel_.reset(model.release()); | 254 contentSettingBubbleModel_.reset(model.release()); |
240 [self showWindow:nil]; | 255 [self showWindow:nil]; |
241 } | 256 } |
242 return self; | 257 return self; |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
572 NSRect menuFrame = [i->first frame]; | 587 NSRect menuFrame = [i->first frame]; |
573 menuFrame.origin.y = topMenuY; | 588 menuFrame.origin.y = topMenuY; |
574 menuFrame.origin.x = NSMinX(radioFrame) + maxLabelWidth; | 589 menuFrame.origin.x = NSMinX(radioFrame) + maxLabelWidth; |
575 menuFrame.size.width = maxMenuWidth; | 590 menuFrame.size.width = maxMenuWidth; |
576 menuFrame.size.height = maxMenuHeight; | 591 menuFrame.size.height = maxMenuHeight; |
577 [i->first setFrame:menuFrame]; | 592 [i->first setFrame:menuFrame]; |
578 topMenuY -= (maxMenuHeight + kMediaMenuElementVerticalPadding); | 593 topMenuY -= (maxMenuHeight + kMediaMenuElementVerticalPadding); |
579 } | 594 } |
580 } | 595 } |
581 | 596 |
597 - (void)initializeMIDISysExLists { | |
598 const ContentSettingBubbleModel::BubbleContent& content = | |
599 contentSettingBubbleModel_->bubble_content(); | |
600 NSRect containerFrame = [contentsContainer_ frame]; | |
601 NSRect frame = | |
602 NSMakeRect(0, 0, NSWidth(containerFrame), kMIDISysExLabelHeight); | |
603 | |
604 // "Clear" button / text field. | |
605 if (!content.custom_link.empty()) { | |
606 base::scoped_nsobject<NSControl> control; | |
607 if(content.custom_link_enabled) { | |
Robert Sesek
2013/08/07 14:11:56
nit: space before (
Takashi Toyoshima
2013/08/08 06:44:34
Done.
| |
608 NSRect buttonFrame = NSMakeRect(0, 0, | |
609 NSWidth(containerFrame), | |
610 kMIDISysExClearButtonHeight); | |
611 NSButton* button = [[NSButton alloc] initWithFrame:buttonFrame]; | |
612 control.reset(button); | |
613 [button setTitle:base::SysUTF8ToNSString(content.custom_link)]; | |
614 [button setTarget:self]; | |
615 [button setAction:@selector(clearMIDISysExForCurrentHost:)]; | |
616 [button setBezelStyle:NSRoundRectBezelStyle]; | |
617 SetControlSize(button, NSSmallControlSize); | |
618 [button sizeToFit]; | |
619 } else { | |
620 // Add the notification that settings will be cleared on next reload. | |
621 control.reset([LabelWithFrame( | |
622 base::SysUTF8ToNSString(content.custom_link), frame) retain]); | |
623 SetControlSize(control.get(), NSSmallControlSize); | |
624 } | |
625 | |
626 // If the new control is wider than the container, widen the window. | |
627 CGFloat controlWidth = NSWidth([control frame]); | |
628 if (controlWidth > NSWidth(containerFrame)) { | |
629 NSRect windowFrame = [[self window] frame]; | |
630 windowFrame.size.width += controlWidth - NSWidth(containerFrame); | |
631 [[self window] setFrame:windowFrame display:NO]; | |
632 // Fetch the updated sizes. | |
633 containerFrame = [contentsContainer_ frame]; | |
634 frame = NSMakeRect(0, 0, NSWidth(containerFrame), kMIDISysExLabelHeight); | |
635 } | |
636 | |
637 DCHECK(control); | |
638 [contentsContainer_ addSubview:control]; | |
639 frame.origin.y = NSMaxY([control frame]) + kMIDISysExPadding; | |
640 } | |
641 | |
642 typedef | |
643 std::vector<ContentSettingBubbleModel::DomainList>::const_reverse_iterator | |
644 GroupIterator; | |
Bernhard Bauer
2013/08/07 13:16:31
Does the typedef here really simplify anything if
Robert Sesek
2013/08/07 14:11:56
Also, in Mac code, you can use C++11 auto.
Takashi Toyoshima
2013/08/08 06:44:34
Oh, I'm happy to use C++11 auto here :)
| |
645 for (GroupIterator i = content.domain_lists.rbegin(); | |
646 i != content.domain_lists.rend(); ++i) { | |
647 // Add all hosts in the current domain list. | |
648 for (std::set<std::string>::const_reverse_iterator j = i->hosts.rbegin(); | |
649 j != i->hosts.rend(); ++j) { | |
650 NSTextField* title = LabelWithFrame(base::SysUTF8ToNSString(*j), frame); | |
651 SetControlSize(title, NSSmallControlSize); | |
652 [contentsContainer_ addSubview:title]; | |
653 | |
654 frame.origin.y = NSMaxY(frame) + kMIDISysExHostPadding + | |
655 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:title]; | |
656 } | |
657 if (!i->hosts.empty()) | |
658 frame.origin.y += kMIDISysExPadding - kMIDISysExHostPadding; | |
659 | |
660 // Add the domain list's title. | |
661 NSTextField* title = | |
662 LabelWithFrame(base::SysUTF8ToNSString(i->title), frame); | |
663 SetControlSize(title, NSSmallControlSize); | |
664 [contentsContainer_ addSubview:title]; | |
665 | |
666 frame.origin.y = NSMaxY(frame) + kMIDISysExPadding + | |
667 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:title]; | |
668 } | |
669 | |
670 CGFloat containerHeight = frame.origin.y; | |
671 // Undo last padding. | |
672 if (!content.domain_lists.empty()) | |
673 containerHeight -= kMIDISysExPadding; | |
674 | |
675 // Resize container to fit its subviews, and window to fit the container. | |
676 NSRect windowFrame = [[self window] frame]; | |
677 windowFrame.size.height += containerHeight - NSHeight(containerFrame); | |
678 [[self window] setFrame:windowFrame display:NO]; | |
679 containerFrame.size.height = containerHeight; | |
680 [contentsContainer_ setFrame:containerFrame]; | |
681 } | |
682 | |
582 - (void)sizeToFitLoadButton { | 683 - (void)sizeToFitLoadButton { |
583 const ContentSettingBubbleModel::BubbleContent& content = | 684 const ContentSettingBubbleModel::BubbleContent& content = |
584 contentSettingBubbleModel_->bubble_content(); | 685 contentSettingBubbleModel_->bubble_content(); |
585 [loadButton_ setEnabled:content.custom_link_enabled]; | 686 [loadButton_ setEnabled:content.custom_link_enabled]; |
586 | 687 |
587 // Resize horizontally to fit button if necessary. | 688 // Resize horizontally to fit button if necessary. |
588 NSRect windowFrame = [[self window] frame]; | 689 NSRect windowFrame = [[self window] frame]; |
589 int widthNeeded = NSWidth([loadButton_ frame]) + | 690 int widthNeeded = NSWidth([loadButton_ frame]) + |
590 2 * NSMinX([loadButton_ frame]); | 691 2 * NSMinX([loadButton_ frame]); |
591 if (NSWidth(windowFrame) < widthNeeded) { | 692 if (NSWidth(windowFrame) < widthNeeded) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
633 | 734 |
634 if (allowBlockRadioGroup_) // not bound in cookie bubble xib | 735 if (allowBlockRadioGroup_) // not bound in cookie bubble xib |
635 [self initializeRadioGroup]; | 736 [self initializeRadioGroup]; |
636 | 737 |
637 if (type == CONTENT_SETTINGS_TYPE_POPUPS) | 738 if (type == CONTENT_SETTINGS_TYPE_POPUPS) |
638 [self initializePopupList]; | 739 [self initializePopupList]; |
639 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION) | 740 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION) |
640 [self initializeGeoLists]; | 741 [self initializeGeoLists]; |
641 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM) | 742 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM) |
642 [self initializeMediaMenus]; | 743 [self initializeMediaMenus]; |
744 if (type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX) | |
745 [self initializeMIDISysExLists]; | |
643 } | 746 } |
644 | 747 |
645 /////////////////////////////////////////////////////////////////////////////// | 748 /////////////////////////////////////////////////////////////////////////////// |
646 // Actual application logic | 749 // Actual application logic |
647 | 750 |
648 - (IBAction)allowBlockToggled:(id)sender { | 751 - (IBAction)allowBlockToggled:(id)sender { |
649 NSButtonCell *selectedCell = [sender selectedCell]; | 752 NSButtonCell *selectedCell = [sender selectedCell]; |
650 contentSettingBubbleModel_->OnRadioClicked([selectedCell tag] - 1); | 753 contentSettingBubbleModel_->OnRadioClicked([selectedCell tag] - 1); |
651 } | 754 } |
652 | 755 |
653 - (void)popupLinkClicked:(id)sender { | 756 - (void)popupLinkClicked:(id)sender { |
654 content_setting_bubble::PopupLinks::iterator i(popupLinks_.find(sender)); | 757 content_setting_bubble::PopupLinks::iterator i(popupLinks_.find(sender)); |
655 DCHECK(i != popupLinks_.end()); | 758 DCHECK(i != popupLinks_.end()); |
656 contentSettingBubbleModel_->OnPopupClicked(i->second); | 759 contentSettingBubbleModel_->OnPopupClicked(i->second); |
657 } | 760 } |
658 | 761 |
659 - (void)clearGeolocationForCurrentHost:(id)sender { | 762 - (void)clearGeolocationForCurrentHost:(id)sender { |
660 contentSettingBubbleModel_->OnCustomLinkClicked(); | 763 contentSettingBubbleModel_->OnCustomLinkClicked(); |
661 [self close]; | 764 [self close]; |
662 } | 765 } |
663 | 766 |
767 - (void)clearMIDISysExForCurrentHost:(id)sender { | |
768 contentSettingBubbleModel_->OnCustomLinkClicked(); | |
769 [self close]; | |
770 } | |
771 | |
664 - (IBAction)showMoreInfo:(id)sender { | 772 - (IBAction)showMoreInfo:(id)sender { |
665 contentSettingBubbleModel_->OnCustomLinkClicked(); | 773 contentSettingBubbleModel_->OnCustomLinkClicked(); |
666 [self close]; | 774 [self close]; |
667 } | 775 } |
668 | 776 |
669 - (IBAction)load:(id)sender { | 777 - (IBAction)load:(id)sender { |
670 contentSettingBubbleModel_->OnCustomLinkClicked(); | 778 contentSettingBubbleModel_->OnCustomLinkClicked(); |
671 [self close]; | 779 [self close]; |
672 } | 780 } |
673 | 781 |
(...skipping 21 matching lines...) Expand all Loading... | |
695 button, base::SysUTF16ToNSString(it->second->model->GetLabelAt(index))); | 803 button, base::SysUTF16ToNSString(it->second->model->GetLabelAt(index))); |
696 | 804 |
697 it->second->model->ExecuteCommand(index, 0); | 805 it->second->model->ExecuteCommand(index, 0); |
698 } | 806 } |
699 | 807 |
700 - (content_setting_bubble::MediaMenuPartsMap*)mediaMenus { | 808 - (content_setting_bubble::MediaMenuPartsMap*)mediaMenus { |
701 return &mediaMenus_; | 809 return &mediaMenus_; |
702 } | 810 } |
703 | 811 |
704 @end // ContentSettingBubbleController | 812 @end // ContentSettingBubbleController |
OLD | NEW |