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

Side by Side Diff: chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.mm

Issue 18004004: Web MIDI: Implement icon image and bubble (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: generated_resources.grd Created 7 years, 4 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 | Annotate | Revision Log
OLDNEW
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
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
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
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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 // Fetch the updated sizes. 457 // Fetch the updated sizes.
443 containerFrame = [contentsContainer_ frame]; 458 containerFrame = [contentsContainer_ frame];
444 frame = NSMakeRect(0, 0, NSWidth(containerFrame), kGeoLabelHeight); 459 frame = NSMakeRect(0, 0, NSWidth(containerFrame), kGeoLabelHeight);
445 } 460 }
446 461
447 DCHECK(control); 462 DCHECK(control);
448 [contentsContainer_ addSubview:control]; 463 [contentsContainer_ addSubview:control];
449 frame.origin.y = NSMaxY([control frame]) + kGeoPadding; 464 frame.origin.y = NSMaxY([control frame]) + kGeoPadding;
450 } 465 }
451 466
452 typedef 467 for (auto i = content.domain_lists.rbegin();
Robert Sesek 2013/08/08 14:37:50 Do you want const auto& for any of these?
Takashi Toyoshima 2013/08/08 14:52:32 If I didn't miss something, const auto& doesn't al
Robert Sesek 2013/08/08 14:53:51 Ah, you're right. You can't with the reverse itera
453 std::vector<ContentSettingBubbleModel::DomainList>::const_reverse_iterator
454 GeolocationGroupIterator;
455 for (GeolocationGroupIterator i = content.domain_lists.rbegin();
456 i != content.domain_lists.rend(); ++i) { 468 i != content.domain_lists.rend(); ++i) {
457 // Add all hosts in the current domain list. 469 // Add all hosts in the current domain list.
458 for (std::set<std::string>::const_reverse_iterator j = i->hosts.rbegin(); 470 for (auto j = i->hosts.rbegin(); j != i->hosts.rend(); ++j) {
459 j != i->hosts.rend(); ++j) {
460 NSTextField* title = LabelWithFrame(base::SysUTF8ToNSString(*j), frame); 471 NSTextField* title = LabelWithFrame(base::SysUTF8ToNSString(*j), frame);
461 SetControlSize(title, NSSmallControlSize); 472 SetControlSize(title, NSSmallControlSize);
462 [contentsContainer_ addSubview:title]; 473 [contentsContainer_ addSubview:title];
463 474
464 frame.origin.y = NSMaxY(frame) + kGeoHostPadding + 475 frame.origin.y = NSMaxY(frame) + kGeoHostPadding +
465 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:title]; 476 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:title];
466 } 477 }
467 if (!i->hosts.empty()) 478 if (!i->hosts.empty())
468 frame.origin.y += kGeoPadding - kGeoHostPadding; 479 frame.origin.y += kGeoPadding - kGeoHostPadding;
469 480
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 NSRect menuFrame = [i->first frame]; 583 NSRect menuFrame = [i->first frame];
573 menuFrame.origin.y = topMenuY; 584 menuFrame.origin.y = topMenuY;
574 menuFrame.origin.x = NSMinX(radioFrame) + maxLabelWidth; 585 menuFrame.origin.x = NSMinX(radioFrame) + maxLabelWidth;
575 menuFrame.size.width = maxMenuWidth; 586 menuFrame.size.width = maxMenuWidth;
576 menuFrame.size.height = maxMenuHeight; 587 menuFrame.size.height = maxMenuHeight;
577 [i->first setFrame:menuFrame]; 588 [i->first setFrame:menuFrame];
578 topMenuY -= (maxMenuHeight + kMediaMenuElementVerticalPadding); 589 topMenuY -= (maxMenuHeight + kMediaMenuElementVerticalPadding);
579 } 590 }
580 } 591 }
581 592
593 - (void)initializeMIDISysExLists {
594 const ContentSettingBubbleModel::BubbleContent& content =
595 contentSettingBubbleModel_->bubble_content();
596 NSRect containerFrame = [contentsContainer_ frame];
597 NSRect frame =
598 NSMakeRect(0, 0, NSWidth(containerFrame), kMIDISysExLabelHeight);
599
600 // "Clear" button / text field.
601 if (!content.custom_link.empty()) {
602 base::scoped_nsobject<NSControl> control;
603 if (content.custom_link_enabled) {
604 NSRect buttonFrame = NSMakeRect(0, 0,
605 NSWidth(containerFrame),
606 kMIDISysExClearButtonHeight);
607 NSButton* button = [[NSButton alloc] initWithFrame:buttonFrame];
608 control.reset(button);
609 [button setTitle:base::SysUTF8ToNSString(content.custom_link)];
610 [button setTarget:self];
611 [button setAction:@selector(clearMIDISysExForCurrentHost:)];
612 [button setBezelStyle:NSRoundRectBezelStyle];
613 SetControlSize(button, NSSmallControlSize);
614 [button sizeToFit];
615 } else {
616 // Add the notification that settings will be cleared on next reload.
617 control.reset([LabelWithFrame(
618 base::SysUTF8ToNSString(content.custom_link), frame) retain]);
619 SetControlSize(control.get(), NSSmallControlSize);
620 }
621
622 // If the new control is wider than the container, widen the window.
623 CGFloat controlWidth = NSWidth([control frame]);
624 if (controlWidth > NSWidth(containerFrame)) {
625 NSRect windowFrame = [[self window] frame];
626 windowFrame.size.width += controlWidth - NSWidth(containerFrame);
627 [[self window] setFrame:windowFrame display:NO];
628 // Fetch the updated sizes.
629 containerFrame = [contentsContainer_ frame];
630 frame = NSMakeRect(0, 0, NSWidth(containerFrame), kMIDISysExLabelHeight);
631 }
632
633 DCHECK(control);
634 [contentsContainer_ addSubview:control];
635 frame.origin.y = NSMaxY([control frame]) + kMIDISysExPadding;
636 }
637
638 for (auto i = content.domain_lists.rbegin();
639 i != content.domain_lists.rend(); ++i) {
640 // Add all hosts in the current domain list.
641 for (auto j = i->hosts.rbegin(); j != i->hosts.rend(); ++j) {
642 NSTextField* title = LabelWithFrame(base::SysUTF8ToNSString(*j), frame);
643 SetControlSize(title, NSSmallControlSize);
644 [contentsContainer_ addSubview:title];
645
646 frame.origin.y = NSMaxY(frame) + kMIDISysExHostPadding +
647 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:title];
648 }
649 if (!i->hosts.empty())
650 frame.origin.y += kMIDISysExPadding - kMIDISysExHostPadding;
651
652 // Add the domain list's title.
653 NSTextField* title =
654 LabelWithFrame(base::SysUTF8ToNSString(i->title), frame);
655 SetControlSize(title, NSSmallControlSize);
656 [contentsContainer_ addSubview:title];
657
658 frame.origin.y = NSMaxY(frame) + kMIDISysExPadding +
659 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:title];
660 }
661
662 CGFloat containerHeight = frame.origin.y;
663 // Undo last padding.
664 if (!content.domain_lists.empty())
665 containerHeight -= kMIDISysExPadding;
666
667 // Resize container to fit its subviews, and window to fit the container.
668 NSRect windowFrame = [[self window] frame];
669 windowFrame.size.height += containerHeight - NSHeight(containerFrame);
670 [[self window] setFrame:windowFrame display:NO];
671 containerFrame.size.height = containerHeight;
672 [contentsContainer_ setFrame:containerFrame];
673 }
674
582 - (void)sizeToFitLoadButton { 675 - (void)sizeToFitLoadButton {
583 const ContentSettingBubbleModel::BubbleContent& content = 676 const ContentSettingBubbleModel::BubbleContent& content =
584 contentSettingBubbleModel_->bubble_content(); 677 contentSettingBubbleModel_->bubble_content();
585 [loadButton_ setEnabled:content.custom_link_enabled]; 678 [loadButton_ setEnabled:content.custom_link_enabled];
586 679
587 // Resize horizontally to fit button if necessary. 680 // Resize horizontally to fit button if necessary.
588 NSRect windowFrame = [[self window] frame]; 681 NSRect windowFrame = [[self window] frame];
589 int widthNeeded = NSWidth([loadButton_ frame]) + 682 int widthNeeded = NSWidth([loadButton_ frame]) +
590 2 * NSMinX([loadButton_ frame]); 683 2 * NSMinX([loadButton_ frame]);
591 if (NSWidth(windowFrame) < widthNeeded) { 684 if (NSWidth(windowFrame) < widthNeeded) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 726
634 if (allowBlockRadioGroup_) // not bound in cookie bubble xib 727 if (allowBlockRadioGroup_) // not bound in cookie bubble xib
635 [self initializeRadioGroup]; 728 [self initializeRadioGroup];
636 729
637 if (type == CONTENT_SETTINGS_TYPE_POPUPS) 730 if (type == CONTENT_SETTINGS_TYPE_POPUPS)
638 [self initializePopupList]; 731 [self initializePopupList];
639 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION) 732 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION)
640 [self initializeGeoLists]; 733 [self initializeGeoLists];
641 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM) 734 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM)
642 [self initializeMediaMenus]; 735 [self initializeMediaMenus];
736 if (type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX)
737 [self initializeMIDISysExLists];
643 } 738 }
644 739
645 /////////////////////////////////////////////////////////////////////////////// 740 ///////////////////////////////////////////////////////////////////////////////
646 // Actual application logic 741 // Actual application logic
647 742
648 - (IBAction)allowBlockToggled:(id)sender { 743 - (IBAction)allowBlockToggled:(id)sender {
649 NSButtonCell *selectedCell = [sender selectedCell]; 744 NSButtonCell *selectedCell = [sender selectedCell];
650 contentSettingBubbleModel_->OnRadioClicked([selectedCell tag] - 1); 745 contentSettingBubbleModel_->OnRadioClicked([selectedCell tag] - 1);
651 } 746 }
652 747
653 - (void)popupLinkClicked:(id)sender { 748 - (void)popupLinkClicked:(id)sender {
654 content_setting_bubble::PopupLinks::iterator i(popupLinks_.find(sender)); 749 content_setting_bubble::PopupLinks::iterator i(popupLinks_.find(sender));
655 DCHECK(i != popupLinks_.end()); 750 DCHECK(i != popupLinks_.end());
656 contentSettingBubbleModel_->OnPopupClicked(i->second); 751 contentSettingBubbleModel_->OnPopupClicked(i->second);
657 } 752 }
658 753
659 - (void)clearGeolocationForCurrentHost:(id)sender { 754 - (void)clearGeolocationForCurrentHost:(id)sender {
660 contentSettingBubbleModel_->OnCustomLinkClicked(); 755 contentSettingBubbleModel_->OnCustomLinkClicked();
661 [self close]; 756 [self close];
662 } 757 }
663 758
759 - (void)clearMIDISysExForCurrentHost:(id)sender {
760 contentSettingBubbleModel_->OnCustomLinkClicked();
761 [self close];
762 }
763
664 - (IBAction)showMoreInfo:(id)sender { 764 - (IBAction)showMoreInfo:(id)sender {
665 contentSettingBubbleModel_->OnCustomLinkClicked(); 765 contentSettingBubbleModel_->OnCustomLinkClicked();
666 [self close]; 766 [self close];
667 } 767 }
668 768
669 - (IBAction)load:(id)sender { 769 - (IBAction)load:(id)sender {
670 contentSettingBubbleModel_->OnCustomLinkClicked(); 770 contentSettingBubbleModel_->OnCustomLinkClicked();
671 [self close]; 771 [self close];
672 } 772 }
673 773
(...skipping 21 matching lines...) Expand all
695 button, base::SysUTF16ToNSString(it->second->model->GetLabelAt(index))); 795 button, base::SysUTF16ToNSString(it->second->model->GetLabelAt(index)));
696 796
697 it->second->model->ExecuteCommand(index, 0); 797 it->second->model->ExecuteCommand(index, 0);
698 } 798 }
699 799
700 - (content_setting_bubble::MediaMenuPartsMap*)mediaMenus { 800 - (content_setting_bubble::MediaMenuPartsMap*)mediaMenus {
701 return &mediaMenus_; 801 return &mediaMenus_;
702 } 802 }
703 803
704 @end // ContentSettingBubbleController 804 @end // ContentSettingBubbleController
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698