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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 webContents:(content::WebContents*)webContents | 203 webContents:(content::WebContents*)webContents |
204 parentWindow:(NSWindow*)parentWindow | 204 parentWindow:(NSWindow*)parentWindow |
205 anchoredAt:(NSPoint)anchoredAt; | 205 anchoredAt:(NSPoint)anchoredAt; |
206 - (NSButton*)hyperlinkButtonWithFrame:(NSRect)frame | 206 - (NSButton*)hyperlinkButtonWithFrame:(NSRect)frame |
207 title:(NSString*)title | 207 title:(NSString*)title |
208 icon:(NSImage*)icon | 208 icon:(NSImage*)icon |
209 referenceFrame:(NSRect)referenceFrame; | 209 referenceFrame:(NSRect)referenceFrame; |
210 - (void)initializeBlockedPluginsList; | 210 - (void)initializeBlockedPluginsList; |
211 - (void)initializeTitle; | 211 - (void)initializeTitle; |
212 - (void)initializeRadioGroup; | 212 - (void)initializeRadioGroup; |
213 - (void)initializePopupList; | 213 - (void)initializeItemList; |
214 - (void)initializeGeoLists; | 214 - (void)initializeGeoLists; |
215 - (void)initializeMediaMenus; | 215 - (void)initializeMediaMenus; |
216 - (void)initializeMIDISysExLists; | 216 - (void)initializeMIDISysExLists; |
217 - (void)sizeToFitLoadButton; | 217 - (void)sizeToFitLoadButton; |
218 - (void)initManageDoneButtons; | 218 - (void)initManageDoneButtons; |
219 - (void)removeInfoButton; | 219 - (void)removeInfoButton; |
220 - (void)popupLinkClicked:(id)sender; | 220 - (void)popupLinkClicked:(id)sender; |
221 - (void)clearGeolocationForCurrentHost:(id)sender; | 221 - (void)clearGeolocationForCurrentHost:(id)sender; |
222 - (void)clearMIDISysExForCurrentHost:(id)sender; | 222 - (void)clearMIDISysExForCurrentHost:(id)sender; |
223 @end | 223 @end |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
377 if (NSWidth(buttonFrame) > maxWidth) | 377 if (NSWidth(buttonFrame) > maxWidth) |
378 buttonFrame.size.width = maxWidth; | 378 buttonFrame.size.width = maxWidth; |
379 | 379 |
380 [button setFrame:buttonFrame]; | 380 [button setFrame:buttonFrame]; |
381 [button setTarget:self]; | 381 [button setTarget:self]; |
382 [button setAction:@selector(popupLinkClicked:)]; | 382 [button setAction:@selector(popupLinkClicked:)]; |
383 return button; | 383 return button; |
384 } | 384 } |
385 | 385 |
386 - (void)initializeBlockedPluginsList { | 386 - (void)initializeBlockedPluginsList { |
387 NSString* label = base::SysUTF16ToNSString( | 387 // Hide the empty label at the top of the dialog. |
388 contentSettingBubbleModel_->bubble_content().plugin_names); | 388 int delta = |
389 [blockedResourcesField_ setStringValue:label]; | 389 NSMinY([titleLabel_ frame]) - NSMinY([blockedResourcesField_ frame]); |
390 [blockedResourcesField_ removeFromSuperview]; | |
391 NSRect frame = [[self window] frame]; | |
392 frame.size.height -= delta; | |
393 [[self window] setFrame:frame display:NO]; | |
390 } | 394 } |
391 | 395 |
392 - (void)initializePopupList { | 396 - (void)initializeItemList { |
393 // I didn't put the buttons into a NSMatrix because then they are only one | 397 // I didn't put the buttons into a NSMatrix because then they are only one |
394 // entity in the key view loop. This way, one can tab through all of them. | 398 // entity in the key view loop. This way, one can tab through all of them. |
395 const ContentSettingBubbleModel::PopupItems& popupItems = | 399 const ContentSettingBubbleModel::ListItems& listItems = |
396 contentSettingBubbleModel_->bubble_content().popup_items; | 400 contentSettingBubbleModel_->bubble_content().list_items; |
397 | 401 |
398 // Get the pre-resize frame of the radio group. Its origin is where the | 402 // Get the pre-resize frame of the radio group. Its origin is where the |
399 // popup list should go. | 403 // popup list should go. |
400 NSRect radioFrame = [allowBlockRadioGroup_ frame]; | 404 NSRect radioFrame = [allowBlockRadioGroup_ frame]; |
401 | 405 |
402 // Make room for the popup list. The bubble view and its subviews autosize | 406 // Make room for the popup list. The bubble view and its subviews autosize |
403 // themselves when the window is enlarged. | 407 // themselves when the window is enlarged. |
404 // Heading and radio box are already 1 * kLinkOuterPadding apart in the nib, | 408 // Heading and radio box are already 1 * kLinkOuterPadding apart in the nib, |
405 // so only 1 * kLinkOuterPadding more is needed. | 409 // so only 1 * kLinkOuterPadding more is needed. |
406 int delta = popupItems.size() * kLinkLineHeight - kLinkPadding + | 410 int delta = |
407 kLinkOuterPadding; | 411 listItems.size() * kLinkLineHeight - kLinkPadding + kLinkOuterPadding; |
408 NSSize deltaSize = NSMakeSize(0, delta); | 412 NSSize deltaSize = NSMakeSize(0, delta); |
409 deltaSize = [[[self window] contentView] convertSize:deltaSize toView:nil]; | 413 deltaSize = [[[self window] contentView] convertSize:deltaSize toView:nil]; |
410 NSRect windowFrame = [[self window] frame]; | 414 NSRect windowFrame = [[self window] frame]; |
411 windowFrame.size.height += deltaSize.height; | 415 windowFrame.size.height += deltaSize.height; |
412 [[self window] setFrame:windowFrame display:NO]; | 416 [[self window] setFrame:windowFrame display:NO]; |
413 | 417 |
414 // Create popup list. | 418 // Create item list. |
415 int topLinkY = NSMaxY(radioFrame) + delta - kLinkHeight; | 419 int topLinkY = NSMaxY(radioFrame) + delta - kLinkHeight; |
416 int row = 0; | 420 int row = 0; |
417 for (std::vector<ContentSettingBubbleModel::PopupItem>::const_iterator | 421 for (const auto& listItem : listItems) { |
Bernhard Bauer
2015/03/24 14:36:53
Would you mind using the actual type instead of au
meacer
2015/03/25 19:23:12
Done.
| |
418 it(popupItems.begin()); it != popupItems.end(); ++it, ++row) { | 422 NSImage* image = listItem.image.AsNSImage(); |
419 NSImage* image = it->image.AsNSImage(); | 423 NSRect frame = NSMakeRect( |
420 | 424 NSMinX(radioFrame), topLinkY - kLinkLineHeight * row, 200, kLinkHeight); |
421 std::string title(it->title); | 425 if (listItem.has_link) { |
422 // The popup may not have committed a load yet, in which case it won't | 426 NSButton* button = |
423 // have a URL or title. | 427 [self hyperlinkButtonWithFrame:frame |
424 if (title.empty()) | 428 title:base::SysUTF8ToNSString(listItem.title) |
425 title = l10n_util::GetStringUTF8(IDS_TAB_LOADING_TITLE); | 429 icon:image |
426 | 430 referenceFrame:radioFrame]; |
427 NSRect linkFrame = | 431 [[self bubble] addSubview:button]; |
428 NSMakeRect(NSMinX(radioFrame), topLinkY - kLinkLineHeight * row, | 432 popupLinks_[button] = row++; |
429 200, kLinkHeight); | 433 } else { |
430 NSButton* button = [self | 434 NSTextField* label = |
431 hyperlinkButtonWithFrame:linkFrame | 435 LabelWithFrame(base::SysUTF8ToNSString(listItem.title), frame); |
432 title:base::SysUTF8ToNSString(title) | 436 SetControlSize(label, NSSmallControlSize); |
433 icon:image | 437 [[self bubble] addSubview:label]; |
434 referenceFrame:radioFrame]; | 438 row++; |
435 [[self bubble] addSubview:button]; | 439 } |
436 popupLinks_[button] = row; | |
437 } | 440 } |
438 } | 441 } |
439 | 442 |
440 - (void)initializeGeoLists { | 443 - (void)initializeGeoLists { |
441 // Cocoa has its origin in the lower left corner. This means elements are | 444 // Cocoa has its origin in the lower left corner. This means elements are |
442 // added from bottom to top, which explains why loops run backwards and the | 445 // added from bottom to top, which explains why loops run backwards and the |
443 // order of operations is the other way than on Linux/Windows. | 446 // order of operations is the other way than on Linux/Windows. |
444 const ContentSettingBubbleModel::BubbleContent& content = | 447 const ContentSettingBubbleModel::BubbleContent& content = |
445 contentSettingBubbleModel_->bubble_content(); | 448 contentSettingBubbleModel_->bubble_content(); |
446 NSRect containerFrame = [contentsContainer_ frame]; | 449 NSRect containerFrame = [contentsContainer_ frame]; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
524 - (void)initializeMediaMenus { | 527 - (void)initializeMediaMenus { |
525 const ContentSettingBubbleModel::MediaMenuMap& media_menus = | 528 const ContentSettingBubbleModel::MediaMenuMap& media_menus = |
526 contentSettingBubbleModel_->bubble_content().media_menus; | 529 contentSettingBubbleModel_->bubble_content().media_menus; |
527 | 530 |
528 // Calculate the longest width of the labels and menus menus to avoid | 531 // Calculate the longest width of the labels and menus menus to avoid |
529 // truncation by the window's edge. | 532 // truncation by the window's edge. |
530 CGFloat maxLabelWidth = 0; | 533 CGFloat maxLabelWidth = 0; |
531 CGFloat maxMenuWidth = 0; | 534 CGFloat maxMenuWidth = 0; |
532 CGFloat maxMenuHeight = 0; | 535 CGFloat maxMenuHeight = 0; |
533 NSRect radioFrame = [allowBlockRadioGroup_ frame]; | 536 NSRect radioFrame = [allowBlockRadioGroup_ frame]; |
534 for (ContentSettingBubbleModel::MediaMenuMap::const_iterator it( | 537 for (const auto& map_entry : media_menus) { |
535 media_menus.begin()); it != media_menus.end(); ++it) { | |
536 // |labelFrame| will be resized later on in this function. | 538 // |labelFrame| will be resized later on in this function. |
537 NSRect labelFrame = NSMakeRect(NSMinX(radioFrame), 0, 0, 0); | 539 NSRect labelFrame = NSMakeRect(NSMinX(radioFrame), 0, 0, 0); |
538 NSTextField* label = | 540 NSTextField* label = LabelWithFrame( |
539 LabelWithFrame(base::SysUTF8ToNSString(it->second.label), labelFrame); | 541 base::SysUTF8ToNSString(map_entry.second.label), labelFrame); |
540 SetControlSize(label, NSSmallControlSize); | 542 SetControlSize(label, NSSmallControlSize); |
541 NSCell* cell = [label cell]; | 543 NSCell* cell = [label cell]; |
542 [cell setAlignment:NSRightTextAlignment]; | 544 [cell setAlignment:NSRightTextAlignment]; |
543 [GTMUILocalizerAndLayoutTweaker sizeToFitView:label]; | 545 [GTMUILocalizerAndLayoutTweaker sizeToFitView:label]; |
544 maxLabelWidth = std::max(maxLabelWidth, [label frame].size.width); | 546 maxLabelWidth = std::max(maxLabelWidth, [label frame].size.width); |
545 [[self bubble] addSubview:label]; | 547 [[self bubble] addSubview:label]; |
546 | 548 |
547 // |buttonFrame| will be resized and repositioned later on. | 549 // |buttonFrame| will be resized and repositioned later on. |
548 NSRect buttonFrame = NSMakeRect(NSMinX(radioFrame), 0, 0, 0); | 550 NSRect buttonFrame = NSMakeRect(NSMinX(radioFrame), 0, 0, 0); |
549 base::scoped_nsobject<NSPopUpButton> button( | 551 base::scoped_nsobject<NSPopUpButton> button( |
550 [[NSPopUpButton alloc] initWithFrame:buttonFrame]); | 552 [[NSPopUpButton alloc] initWithFrame:buttonFrame]); |
551 [button setTarget:self]; | 553 [button setTarget:self]; |
552 | 554 |
553 // Store the |label| and |button| into MediaMenuParts struct and build | 555 // Store the |label| and |button| into MediaMenuParts struct and build |
554 // the popup menu from the menu model. | 556 // the popup menu from the menu model. |
555 content_setting_bubble::MediaMenuParts* menuParts = | 557 content_setting_bubble::MediaMenuParts* menuParts = |
556 new content_setting_bubble::MediaMenuParts(it->first, label); | 558 new content_setting_bubble::MediaMenuParts(map_entry.first, label); |
557 menuParts->model.reset(new ContentSettingMediaMenuModel( | 559 menuParts->model.reset(new ContentSettingMediaMenuModel( |
558 it->first, contentSettingBubbleModel_.get(), | 560 map_entry.first, contentSettingBubbleModel_.get(), |
559 ContentSettingMediaMenuModel::MenuLabelChangedCallback())); | 561 ContentSettingMediaMenuModel::MenuLabelChangedCallback())); |
560 mediaMenus_[button] = menuParts; | 562 mediaMenus_[button] = menuParts; |
561 CGFloat width = BuildPopUpMenuFromModel(button, | 563 CGFloat width = BuildPopUpMenuFromModel( |
562 menuParts->model.get(), | 564 button, menuParts->model.get(), map_entry.second.selected_device.name, |
563 it->second.selected_device.name, | 565 map_entry.second.disabled); |
564 it->second.disabled); | |
565 maxMenuWidth = std::max(maxMenuWidth, width); | 566 maxMenuWidth = std::max(maxMenuWidth, width); |
566 | 567 |
567 [[self bubble] addSubview:button | 568 [[self bubble] addSubview:button |
568 positioned:NSWindowBelow | 569 positioned:NSWindowBelow |
569 relativeTo:nil]; | 570 relativeTo:nil]; |
570 | 571 |
571 maxMenuHeight = std::max(maxMenuHeight, [button frame].size.height); | 572 maxMenuHeight = std::max(maxMenuHeight, [button frame].size.height); |
572 } | 573 } |
573 | 574 |
574 // Make room for the media menu(s) and enlarge the windows to fit the views. | 575 // Make room for the media menu(s) and enlarge the windows to fit the views. |
(...skipping 11 matching lines...) Expand all Loading... | |
586 windowFrame.size.width = widthNeeded; | 587 windowFrame.size.width = widthNeeded; |
587 [[self window] setFrame:windowFrame display:NO]; | 588 [[self window] setFrame:windowFrame display:NO]; |
588 | 589 |
589 // The radio group lies above the media menus, move the radio group up. | 590 // The radio group lies above the media menus, move the radio group up. |
590 radioFrame.origin.y += delta; | 591 radioFrame.origin.y += delta; |
591 [allowBlockRadioGroup_ setFrame:radioFrame]; | 592 [allowBlockRadioGroup_ setFrame:radioFrame]; |
592 | 593 |
593 // Resize and reposition the media menus layout. | 594 // Resize and reposition the media menus layout. |
594 CGFloat topMenuY = NSMinY(radioFrame) - kMediaMenuVerticalPadding; | 595 CGFloat topMenuY = NSMinY(radioFrame) - kMediaMenuVerticalPadding; |
595 maxMenuWidth = std::max(maxMenuWidth, kMinMediaMenuButtonWidth); | 596 maxMenuWidth = std::max(maxMenuWidth, kMinMediaMenuButtonWidth); |
596 for (content_setting_bubble::MediaMenuPartsMap::const_iterator i = | 597 for (const auto& map_entry : mediaMenus_) { |
597 mediaMenus_.begin(); i != mediaMenus_.end(); ++i) { | 598 NSRect labelFrame = [map_entry.second->label frame]; |
598 NSRect labelFrame = [i->second->label frame]; | |
599 // Align the label text with the button text. | 599 // Align the label text with the button text. |
600 labelFrame.origin.y = | 600 labelFrame.origin.y = |
601 topMenuY + (maxMenuHeight - labelFrame.size.height) / 2 + 1; | 601 topMenuY + (maxMenuHeight - labelFrame.size.height) / 2 + 1; |
602 labelFrame.size.width = maxLabelWidth; | 602 labelFrame.size.width = maxLabelWidth; |
603 [i->second->label setFrame:labelFrame]; | 603 [map_entry.second->label setFrame:labelFrame]; |
604 NSRect menuFrame = [i->first frame]; | 604 NSRect menuFrame = [map_entry.first frame]; |
605 menuFrame.origin.y = topMenuY; | 605 menuFrame.origin.y = topMenuY; |
606 menuFrame.origin.x = NSMinX(radioFrame) + maxLabelWidth; | 606 menuFrame.origin.x = NSMinX(radioFrame) + maxLabelWidth; |
607 menuFrame.size.width = maxMenuWidth; | 607 menuFrame.size.width = maxMenuWidth; |
608 menuFrame.size.height = maxMenuHeight; | 608 menuFrame.size.height = maxMenuHeight; |
609 [i->first setFrame:menuFrame]; | 609 [map_entry.first setFrame:menuFrame]; |
610 topMenuY -= (maxMenuHeight + kMediaMenuElementVerticalPadding); | 610 topMenuY -= (maxMenuHeight + kMediaMenuElementVerticalPadding); |
611 } | 611 } |
612 } | 612 } |
613 | 613 |
614 - (void)initializeMIDISysExLists { | 614 - (void)initializeMIDISysExLists { |
615 const ContentSettingBubbleModel::BubbleContent& content = | 615 const ContentSettingBubbleModel::BubbleContent& content = |
616 contentSettingBubbleModel_->bubble_content(); | 616 contentSettingBubbleModel_->bubble_content(); |
617 NSRect containerFrame = [contentsContainer_ frame]; | 617 NSRect containerFrame = [contentsContainer_ frame]; |
618 NSRect frame = | 618 NSRect frame = |
619 NSMakeRect(0, 0, NSWidth(containerFrame), kMIDISysExLabelHeight); | 619 NSMakeRect(0, 0, NSWidth(containerFrame), kMIDISysExLabelHeight); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
741 | 741 |
742 ContentSettingsType type = contentSettingBubbleModel_->content_type(); | 742 ContentSettingsType type = contentSettingBubbleModel_->content_type(); |
743 if (type == CONTENT_SETTINGS_TYPE_PLUGINS) { | 743 if (type == CONTENT_SETTINGS_TYPE_PLUGINS) { |
744 [self sizeToFitLoadButton]; | 744 [self sizeToFitLoadButton]; |
745 [self initializeBlockedPluginsList]; | 745 [self initializeBlockedPluginsList]; |
746 } | 746 } |
747 | 747 |
748 if (allowBlockRadioGroup_) // not bound in cookie bubble xib | 748 if (allowBlockRadioGroup_) // not bound in cookie bubble xib |
749 [self initializeRadioGroup]; | 749 [self initializeRadioGroup]; |
750 | 750 |
751 if (type == CONTENT_SETTINGS_TYPE_POPUPS) | 751 if (type == CONTENT_SETTINGS_TYPE_POPUPS || |
752 [self initializePopupList]; | 752 type == CONTENT_SETTINGS_TYPE_PLUGINS) |
753 [self initializeItemList]; | |
753 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION) | 754 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION) |
754 [self initializeGeoLists]; | 755 [self initializeGeoLists]; |
755 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM) | 756 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM) |
756 [self initializeMediaMenus]; | 757 [self initializeMediaMenus]; |
757 if (type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX) | 758 if (type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX) |
758 [self initializeMIDISysExLists]; | 759 [self initializeMIDISysExLists]; |
759 } | 760 } |
760 | 761 |
761 /////////////////////////////////////////////////////////////////////////////// | 762 /////////////////////////////////////////////////////////////////////////////// |
762 // Actual application logic | 763 // Actual application logic |
763 | 764 |
764 - (IBAction)allowBlockToggled:(id)sender { | 765 - (IBAction)allowBlockToggled:(id)sender { |
765 NSButtonCell *selectedCell = [sender selectedCell]; | 766 NSButtonCell *selectedCell = [sender selectedCell]; |
766 contentSettingBubbleModel_->OnRadioClicked([selectedCell tag] - 1); | 767 contentSettingBubbleModel_->OnRadioClicked([selectedCell tag] - 1); |
767 } | 768 } |
768 | 769 |
769 - (void)popupLinkClicked:(id)sender { | 770 - (void)popupLinkClicked:(id)sender { |
770 content_setting_bubble::PopupLinks::iterator i(popupLinks_.find(sender)); | 771 content_setting_bubble::PopupLinks::iterator i(popupLinks_.find(sender)); |
771 DCHECK(i != popupLinks_.end()); | 772 DCHECK(i != popupLinks_.end()); |
772 contentSettingBubbleModel_->OnPopupClicked(i->second); | 773 contentSettingBubbleModel_->OnListItemClicked(i->second); |
773 } | 774 } |
774 | 775 |
775 - (void)clearGeolocationForCurrentHost:(id)sender { | 776 - (void)clearGeolocationForCurrentHost:(id)sender { |
776 contentSettingBubbleModel_->OnCustomLinkClicked(); | 777 contentSettingBubbleModel_->OnCustomLinkClicked(); |
777 [self close]; | 778 [self close]; |
778 } | 779 } |
779 | 780 |
780 - (void)clearMIDISysExForCurrentHost:(id)sender { | 781 - (void)clearMIDISysExForCurrentHost:(id)sender { |
781 contentSettingBubbleModel_->OnCustomLinkClicked(); | 782 contentSettingBubbleModel_->OnCustomLinkClicked(); |
782 [self close]; | 783 [self close]; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
816 button, base::SysUTF16ToNSString(it->second->model->GetLabelAt(index))); | 817 button, base::SysUTF16ToNSString(it->second->model->GetLabelAt(index))); |
817 | 818 |
818 it->second->model->ExecuteCommand(index, 0); | 819 it->second->model->ExecuteCommand(index, 0); |
819 } | 820 } |
820 | 821 |
821 - (content_setting_bubble::MediaMenuPartsMap*)mediaMenus { | 822 - (content_setting_bubble::MediaMenuPartsMap*)mediaMenus { |
822 return &mediaMenus_; | 823 return &mediaMenus_; |
823 } | 824 } |
824 | 825 |
825 @end // ContentSettingBubbleController | 826 @end // ContentSettingBubbleController |
OLD | NEW |