| 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 #import "base/mac/sdk_forward_declarations.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 13 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 15 #include "chrome/browser/plugins/plugin_finder.h" | 16 #include "chrome/browser/plugins/plugin_finder.h" |
| 16 #include "chrome/browser/plugins/plugin_metadata.h" | 17 #include "chrome/browser/plugins/plugin_metadata.h" |
| 17 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 18 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
| 18 #import "chrome/browser/ui/cocoa/l10n_util.h" | 19 #import "chrome/browser/ui/cocoa/l10n_util.h" |
| 19 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h" | 20 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h" |
| 20 #import "chrome/browser/ui/cocoa/subresource_filter/subresource_filter_bubble_co
ntroller.h" | 21 #import "chrome/browser/ui/cocoa/subresource_filter/subresource_filter_bubble_co
ntroller.h" |
| 21 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | 22 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" |
| 22 #include "chrome/browser/ui/content_settings/content_setting_media_menu_model.h" | 23 #include "chrome/browser/ui/content_settings/content_setting_media_menu_model.h" |
| 24 #include "chrome/common/chrome_features.h" |
| 23 #include "chrome/grit/generated_resources.h" | 25 #include "chrome/grit/generated_resources.h" |
| 24 #include "components/content_settings/core/browser/host_content_settings_map.h" | 26 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 27 #include "components/strings/grit/components_strings.h" |
| 25 #include "content/public/browser/navigation_handle.h" | 28 #include "content/public/browser/navigation_handle.h" |
| 26 #include "content/public/browser/plugin_service.h" | 29 #include "content/public/browser/plugin_service.h" |
| 27 #include "content/public/browser/web_contents_observer.h" | 30 #include "content/public/browser/web_contents_observer.h" |
| 28 #include "skia/ext/skia_utils_mac.h" | 31 #include "skia/ext/skia_utils_mac.h" |
| 29 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw
eaker.h" | 32 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw
eaker.h" |
| 30 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" | 33 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" |
| 34 #import "ui/base/cocoa/touch_bar_util.h" |
| 31 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
| 32 | 36 |
| 33 using content::PluginService; | 37 using content::PluginService; |
| 34 | 38 |
| 35 namespace { | 39 namespace { |
| 36 | 40 |
| 37 // Height of one link in the popup list. | 41 // Height of one link in the popup list. |
| 38 const int kLinkHeight = 16; | 42 const int kLinkHeight = 16; |
| 39 | 43 |
| 40 // Space between two popup links. | 44 // Space between two popup links. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 | 82 |
| 79 // Height of the "Clear" button in the MIDI bubble. | 83 // Height of the "Clear" button in the MIDI bubble. |
| 80 const int kMIDISysExClearButtonHeight = 17; | 84 const int kMIDISysExClearButtonHeight = 17; |
| 81 | 85 |
| 82 // General padding between elements in the MIDI bubble. | 86 // General padding between elements in the MIDI bubble. |
| 83 const int kMIDISysExPadding = 8; | 87 const int kMIDISysExPadding = 8; |
| 84 | 88 |
| 85 // Padding between host names in the MIDI bubble. | 89 // Padding between host names in the MIDI bubble. |
| 86 const int kMIDISysExHostPadding = 4; | 90 const int kMIDISysExHostPadding = 4; |
| 87 | 91 |
| 92 // Touch bar identifier. |
| 93 NSString* const kContentSettingsBubbleTouchBarId = @"content-settings-bubble"; |
| 94 |
| 95 // Touch bar item identifiers. |
| 96 NSString* const kManageTouchBarId = @"MANAGE"; |
| 97 NSString* const kDoneTouchBarId = @"DONE"; |
| 98 |
| 88 void SetControlSize(NSControl* control, NSControlSize controlSize) { | 99 void SetControlSize(NSControl* control, NSControlSize controlSize) { |
| 89 CGFloat fontSize = [NSFont systemFontSizeForControlSize:controlSize]; | 100 CGFloat fontSize = [NSFont systemFontSizeForControlSize:controlSize]; |
| 90 NSCell* cell = [control cell]; | 101 NSCell* cell = [control cell]; |
| 91 [cell setFont:[NSFont systemFontOfSize:fontSize]]; | 102 [cell setFont:[NSFont systemFontOfSize:fontSize]]; |
| 92 [cell setControlSize:controlSize]; | 103 [cell setControlSize:controlSize]; |
| 93 } | 104 } |
| 94 | 105 |
| 95 // 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 |
| 96 // looks in Interface Builder. | 107 // looks in Interface Builder. |
| 97 NSTextField* LabelWithFrame(NSString* text, const NSRect& frame) { | 108 NSTextField* LabelWithFrame(NSString* text, const NSRect& frame) { |
| (...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 frame.origin.x -= size.width; | 857 frame.origin.x -= size.width; |
| 847 frame.size.width += size.width; | 858 frame.size.width += size.width; |
| 848 [[self window] setFrame:frame display:NO]; | 859 [[self window] setFrame:frame display:NO]; |
| 849 } | 860 } |
| 850 | 861 |
| 851 - (void)awakeFromNib { | 862 - (void)awakeFromNib { |
| 852 [super awakeFromNib]; | 863 [super awakeFromNib]; |
| 853 [self layoutView]; | 864 [self layoutView]; |
| 854 } | 865 } |
| 855 | 866 |
| 867 - (NSTouchBar*)makeTouchBar { |
| 868 if (!base::FeatureList::IsEnabled(features::kBrowserTouchBar)) |
| 869 return nil; |
| 870 |
| 871 if (!manageButton_ && !doneButton_) |
| 872 return nil; |
| 873 |
| 874 base::scoped_nsobject<NSTouchBar> touchBar([[ui::NSTouchBar() alloc] init]); |
| 875 [touchBar setCustomizationIdentifier:ui::GetTouchBarId( |
| 876 kContentSettingsBubbleTouchBarId)]; |
| 877 [touchBar setDelegate:self]; |
| 878 |
| 879 NSMutableArray* dialogItems = [NSMutableArray array]; |
| 880 if (manageButton_) { |
| 881 [dialogItems |
| 882 addObject:ui::GetTouchBarItemId(kContentSettingsBubbleTouchBarId, |
| 883 kManageTouchBarId)]; |
| 884 } |
| 885 |
| 886 if (doneButton_) { |
| 887 [dialogItems |
| 888 addObject:ui::GetTouchBarItemId(kContentSettingsBubbleTouchBarId, |
| 889 kDoneTouchBarId)]; |
| 890 } |
| 891 |
| 892 [touchBar setDefaultItemIdentifiers:dialogItems]; |
| 893 [touchBar setCustomizationAllowedItemIdentifiers:dialogItems]; |
| 894 return touchBar.autorelease(); |
| 895 } |
| 896 |
| 897 - (NSTouchBarItem*)touchBar:(NSTouchBar*)touchBar |
| 898 makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier { |
| 899 NSButton* button = nil; |
| 900 if ([identifier hasSuffix:kManageTouchBarId]) { |
| 901 NSString* title = base::SysUTF16ToNSString( |
| 902 contentSettingBubbleModel_->bubble_content().manage_text); |
| 903 button = [NSButton buttonWithTitle:title |
| 904 target:self |
| 905 action:@selector(manageBlocking:)]; |
| 906 } else if ([identifier hasSuffix:kDoneTouchBarId]) { |
| 907 button = ui::GetBlueTouchBarButton(l10n_util::GetNSString(IDS_DONE), self, |
| 908 @selector(closeBubble:)); |
| 909 } else { |
| 910 return nil; |
| 911 } |
| 912 |
| 913 base::scoped_nsobject<NSCustomTouchBarItem> item( |
| 914 [[ui::NSCustomTouchBarItem() alloc] initWithIdentifier:identifier]); |
| 915 [item setView:button]; |
| 916 return item.autorelease(); |
| 917 } |
| 918 |
| 856 - (void)layoutView { | 919 - (void)layoutView { |
| 857 ContentSettingSimpleBubbleModel* simple_bubble = | 920 ContentSettingSimpleBubbleModel* simple_bubble = |
| 858 contentSettingBubbleModel_->AsSimpleBubbleModel(); | 921 contentSettingBubbleModel_->AsSimpleBubbleModel(); |
| 859 | 922 |
| 860 [[self bubble] setArrowLocation:info_bubble::kTopTrailing]; | 923 [[self bubble] setArrowLocation:info_bubble::kTopTrailing]; |
| 861 | 924 |
| 862 // Adapt window size to bottom buttons. Do this before all other layouting. | 925 // Adapt window size to bottom buttons. Do this before all other layouting. |
| 863 if ((simple_bubble && !simple_bubble->bubble_content().manage_text.empty()) || | 926 if ((simple_bubble && !simple_bubble->bubble_content().manage_text.empty()) || |
| 864 contentSettingBubbleModel_->AsDownloadsBubbleModel() || | 927 contentSettingBubbleModel_->AsDownloadsBubbleModel() || |
| 865 contentSettingBubbleModel_->AsSubresourceFilterBubbleModel()) { | 928 contentSettingBubbleModel_->AsSubresourceFilterBubbleModel()) { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 982 | 1045 |
| 983 - (content_setting_bubble::MediaMenuPartsMap*)mediaMenus { | 1046 - (content_setting_bubble::MediaMenuPartsMap*)mediaMenus { |
| 984 return &mediaMenus_; | 1047 return &mediaMenus_; |
| 985 } | 1048 } |
| 986 | 1049 |
| 987 - (LocationBarDecoration*)decorationForBubble { | 1050 - (LocationBarDecoration*)decorationForBubble { |
| 988 return decoration_; | 1051 return decoration_; |
| 989 } | 1052 } |
| 990 | 1053 |
| 991 @end // ContentSettingBubbleController | 1054 @end // ContentSettingBubbleController |
| OLD | NEW |