| 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" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "chrome/browser/plugins/plugin_finder.h" | 15 #include "chrome/browser/plugins/plugin_finder.h" |
| 16 #include "chrome/browser/plugins/plugin_metadata.h" | 16 #include "chrome/browser/plugins/plugin_metadata.h" |
| 17 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 17 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
| 18 #import "chrome/browser/ui/cocoa/l10n_util.h" | 18 #import "chrome/browser/ui/cocoa/l10n_util.h" |
| 19 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | 19 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" |
| 20 #include "chrome/browser/ui/content_settings/content_setting_media_menu_model.h" | 20 #include "chrome/browser/ui/content_settings/content_setting_media_menu_model.h" |
| 21 #include "chrome/grit/generated_resources.h" | 21 #include "chrome/grit/generated_resources.h" |
| 22 #include "components/content_settings/core/browser/host_content_settings_map.h" | 22 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 } | 299 } |
| 300 | 300 |
| 301 if (model->AsMediaStreamBubbleModel()) | 301 if (model->AsMediaStreamBubbleModel()) |
| 302 nibPath = @"ContentBlockedMedia"; | 302 nibPath = @"ContentBlockedMedia"; |
| 303 | 303 |
| 304 if (model->AsSubresourceFilterBubbleModel()) | 304 if (model->AsSubresourceFilterBubbleModel()) |
| 305 nibPath = @"ContentSubresourceFilter"; | 305 nibPath = @"ContentSubresourceFilter"; |
| 306 return nibPath; | 306 return nibPath; |
| 307 } | 307 } |
| 308 | 308 |
| 309 - (void)dealloc { | |
| 310 base::STLDeleteValues(&mediaMenus_); | |
| 311 [super dealloc]; | |
| 312 } | |
| 313 | |
| 314 - (void)initializeTitle { | 309 - (void)initializeTitle { |
| 315 if (!titleLabel_) | 310 if (!titleLabel_) |
| 316 return; | 311 return; |
| 317 | 312 |
| 318 NSString* label = base::SysUTF16ToNSString( | 313 NSString* label = base::SysUTF16ToNSString( |
| 319 contentSettingBubbleModel_->bubble_content().title); | 314 contentSettingBubbleModel_->bubble_content().title); |
| 320 [titleLabel_ setStringValue:label]; | 315 [titleLabel_ setStringValue:label]; |
| 321 | 316 |
| 322 // Layout title post-localization. | 317 // Layout title post-localization. |
| 323 CGFloat deltaY = [GTMUILocalizerAndLayoutTweaker | 318 CGFloat deltaY = [GTMUILocalizerAndLayoutTweaker |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 // MediaMenuPartsMap uses this value to order its elements. | 596 // MediaMenuPartsMap uses this value to order its elements. |
| 602 [button setTag:static_cast<NSInteger>(map_entry.first)]; | 597 [button setTag:static_cast<NSInteger>(map_entry.first)]; |
| 603 | 598 |
| 604 // Store the |label| and |button| into MediaMenuParts struct and build | 599 // Store the |label| and |button| into MediaMenuParts struct and build |
| 605 // the popup menu from the menu model. | 600 // the popup menu from the menu model. |
| 606 content_setting_bubble::MediaMenuParts* menuParts = | 601 content_setting_bubble::MediaMenuParts* menuParts = |
| 607 new content_setting_bubble::MediaMenuParts(map_entry.first, label); | 602 new content_setting_bubble::MediaMenuParts(map_entry.first, label); |
| 608 menuParts->model.reset(new ContentSettingMediaMenuModel( | 603 menuParts->model.reset(new ContentSettingMediaMenuModel( |
| 609 map_entry.first, contentSettingBubbleModel_.get(), | 604 map_entry.first, contentSettingBubbleModel_.get(), |
| 610 ContentSettingMediaMenuModel::MenuLabelChangedCallback())); | 605 ContentSettingMediaMenuModel::MenuLabelChangedCallback())); |
| 611 mediaMenus_[button] = menuParts; | 606 mediaMenus_[button] = base::WrapUnique(menuParts); |
| 612 CGFloat width = BuildPopUpMenuFromModel( | 607 CGFloat width = BuildPopUpMenuFromModel( |
| 613 button, menuParts->model.get(), map_entry.second.selected_device.name, | 608 button, menuParts->model.get(), map_entry.second.selected_device.name, |
| 614 map_entry.second.disabled); | 609 map_entry.second.disabled); |
| 615 maxMenuWidth = std::max(maxMenuWidth, width); | 610 maxMenuWidth = std::max(maxMenuWidth, width); |
| 616 | 611 |
| 617 [[self bubble] addSubview:button | 612 [[self bubble] addSubview:button |
| 618 positioned:NSWindowBelow | 613 positioned:NSWindowBelow |
| 619 relativeTo:nil]; | 614 relativeTo:nil]; |
| 620 | 615 |
| 621 maxMenuHeight = std::max(maxMenuHeight, [button frame].size.height); | 616 maxMenuHeight = std::max(maxMenuHeight, [button frame].size.height); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 636 windowFrame.size.width = widthNeeded; | 631 windowFrame.size.width = widthNeeded; |
| 637 [[self window] setFrame:windowFrame display:NO]; | 632 [[self window] setFrame:windowFrame display:NO]; |
| 638 | 633 |
| 639 // The radio group lies above the media menus, move the radio group up. | 634 // The radio group lies above the media menus, move the radio group up. |
| 640 radioFrame.origin.y += delta; | 635 radioFrame.origin.y += delta; |
| 641 [allowBlockRadioGroup_ setFrame:radioFrame]; | 636 [allowBlockRadioGroup_ setFrame:radioFrame]; |
| 642 | 637 |
| 643 // Resize and reposition the media menus layout. | 638 // Resize and reposition the media menus layout. |
| 644 CGFloat topMenuY = NSMinY(radioFrame) - kMediaMenuVerticalPadding; | 639 CGFloat topMenuY = NSMinY(radioFrame) - kMediaMenuVerticalPadding; |
| 645 maxMenuWidth = std::max(maxMenuWidth, kMinMediaMenuButtonWidth); | 640 maxMenuWidth = std::max(maxMenuWidth, kMinMediaMenuButtonWidth); |
| 646 for (const std::pair<NSPopUpButton*, content_setting_bubble::MediaMenuParts*>& | 641 for (const auto& map_entry : mediaMenus_) { |
| 647 map_entry : mediaMenus_) { | |
| 648 NSRect labelFrame = [map_entry.second->label frame]; | 642 NSRect labelFrame = [map_entry.second->label frame]; |
| 649 // Align the label text with the button text. | 643 // Align the label text with the button text. |
| 650 labelFrame.origin.y = | 644 labelFrame.origin.y = |
| 651 topMenuY + (maxMenuHeight - labelFrame.size.height) / 2 + 1; | 645 topMenuY + (maxMenuHeight - labelFrame.size.height) / 2 + 1; |
| 652 labelFrame.size.width = maxLabelWidth; | 646 labelFrame.size.width = maxLabelWidth; |
| 653 [map_entry.second->label setFrame:labelFrame]; | 647 [map_entry.second->label setFrame:labelFrame]; |
| 654 NSRect menuFrame = [map_entry.first frame]; | 648 NSRect menuFrame = [map_entry.first frame]; |
| 655 menuFrame.origin.y = topMenuY; | 649 menuFrame.origin.y = topMenuY; |
| 656 menuFrame.origin.x = NSMinX(radioFrame) + maxLabelWidth; | 650 menuFrame.origin.x = NSMinX(radioFrame) + maxLabelWidth; |
| 657 menuFrame.size.width = maxMenuWidth; | 651 menuFrame.size.width = maxMenuWidth; |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 contentSettingBubbleModel_->OnManageLinkClicked(); | 856 contentSettingBubbleModel_->OnManageLinkClicked(); |
| 863 } | 857 } |
| 864 | 858 |
| 865 - (IBAction)closeBubble:(id)sender { | 859 - (IBAction)closeBubble:(id)sender { |
| 866 contentSettingBubbleModel_->OnDoneClicked(); | 860 contentSettingBubbleModel_->OnDoneClicked(); |
| 867 [self close]; | 861 [self close]; |
| 868 } | 862 } |
| 869 | 863 |
| 870 - (IBAction)mediaMenuChanged:(id)sender { | 864 - (IBAction)mediaMenuChanged:(id)sender { |
| 871 NSPopUpButton* button = static_cast<NSPopUpButton*>(sender); | 865 NSPopUpButton* button = static_cast<NSPopUpButton*>(sender); |
| 872 content_setting_bubble::MediaMenuPartsMap::const_iterator it( | 866 auto it = mediaMenus_.find(sender); |
| 873 mediaMenus_.find(sender)); | |
| 874 DCHECK(it != mediaMenus_.end()); | 867 DCHECK(it != mediaMenus_.end()); |
| 875 NSInteger index = [[button selectedItem] tag]; | 868 NSInteger index = [[button selectedItem] tag]; |
| 876 | 869 |
| 877 SetTitleForPopUpButton( | 870 SetTitleForPopUpButton( |
| 878 button, base::SysUTF16ToNSString(it->second->model->GetLabelAt(index))); | 871 button, base::SysUTF16ToNSString(it->second->model->GetLabelAt(index))); |
| 879 | 872 |
| 880 it->second->model->ExecuteCommand(index, 0); | 873 it->second->model->ExecuteCommand(index, 0); |
| 881 } | 874 } |
| 882 | 875 |
| 883 - (content_setting_bubble::MediaMenuPartsMap*)mediaMenus { | 876 - (content_setting_bubble::MediaMenuPartsMap*)mediaMenus { |
| 884 return &mediaMenus_; | 877 return &mediaMenus_; |
| 885 } | 878 } |
| 886 | 879 |
| 887 @end // ContentSettingBubbleController | 880 @end // ContentSettingBubbleController |
| OLD | NEW |