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

Side by Side Diff: chrome/browser/ui/cocoa/website_settings/permission_selector_button.mm

Issue 819183002: Plugin Power Saver: Fix DETECT in WebsiteSettingsUI omnibox dropdown. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@0210-plugin-power-saver-fix-website-settings-plugin-ask-backportable
Patch Set: fix mac stuff Created 6 years 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/website_settings/permission_selector_button.h" 5 #import "chrome/browser/ui/cocoa/website_settings/permission_selector_button.h"
6 6
7 #include "base/strings/sys_string_conversions.h" 7 #include "base/strings/sys_string_conversions.h"
8 #include "chrome/browser/ui/cocoa/website_settings/website_settings_utils_cocoa. h" 8 #include "chrome/browser/ui/cocoa/website_settings/website_settings_utils_cocoa. h"
9 #include "chrome/browser/ui/website_settings/website_settings_ui.h" 9 #include "chrome/browser/ui/website_settings/website_settings_ui.h"
10 #include "chrome/browser/ui/website_settings/website_settings_utils.h" 10 #include "chrome/browser/ui/website_settings/website_settings_utils.h"
(...skipping 13 matching lines...) Expand all
24 menuModel_.reset(new PermissionMenuModel(url, permissionInfo, callback)); 24 menuModel_.reset(new PermissionMenuModel(url, permissionInfo, callback));
25 25
26 menuController_.reset([[MenuController alloc] initWithModel:menuModel_.get() 26 menuController_.reset([[MenuController alloc] initWithModel:menuModel_.get()
27 useWithPopUpButtonCell:NO]); 27 useWithPopUpButtonCell:NO]);
28 [self setMenu:[menuController_ menu]]; 28 [self setMenu:[menuController_ menu]];
29 [self selectItemWithTag:permissionInfo.setting]; 29 [self selectItemWithTag:permissionInfo.setting];
30 30
31 // Set the button title. 31 // Set the button title.
32 base::scoped_nsobject<NSMenuItem> titleItem([[NSMenuItem alloc] init]); 32 base::scoped_nsobject<NSMenuItem> titleItem([[NSMenuItem alloc] init]);
33 base::string16 buttonTitle = WebsiteSettingsUI::PermissionActionToUIString( 33 base::string16 buttonTitle = WebsiteSettingsUI::PermissionActionToUIString(
34 permissionInfo.setting, 34 permissionInfo.type, permissionInfo.setting,
35 permissionInfo.default_setting, 35 permissionInfo.default_setting, permissionInfo.source);
36 permissionInfo.source);
37 [titleItem setTitle:base::SysUTF16ToNSString(buttonTitle)]; 36 [titleItem setTitle:base::SysUTF16ToNSString(buttonTitle)];
38 [[self cell] setUsesItemFromMenu:NO]; 37 [[self cell] setUsesItemFromMenu:NO];
39 [[self cell] setMenuItem:titleItem.get()]; 38 [[self cell] setMenuItem:titleItem.get()];
40 // Although the frame is reset, below, this sizes the cell properly. 39 // Although the frame is reset, below, this sizes the cell properly.
41 [self sizeToFit]; 40 [self sizeToFit];
42 41
43 // Size the button to just fit the visible title - not all of its items. 42 // Size the button to just fit the visible title - not all of its items.
44 [self setFrameSize:SizeForWebsiteSettingsButtonTitle(self, [self title])]; 43 [self setFrameSize:SizeForWebsiteSettingsButtonTitle(self, [self title])];
45 } 44 }
46 return self; 45 return self;
47 } 46 }
48 47
49 - (CGFloat)maxTitleWidthWithDefaultSetting:(ContentSetting)defaultSetting { 48 - (CGFloat)maxTitleWidthForContentSettingsType:(ContentSettingsType)type
49 withDefaultSetting:(ContentSetting)defaultSetting {
50 // Determine the largest possible size for this button. 50 // Determine the largest possible size for this button.
51 CGFloat maxTitleWidth = 0; 51 CGFloat maxTitleWidth = 0;
52 for (NSMenuItem* item in [self itemArray]) { 52 for (NSMenuItem* item in [self itemArray]) {
53 NSString* title = 53 NSString* title =
54 base::SysUTF16ToNSString(WebsiteSettingsUI::PermissionActionToUIString( 54 base::SysUTF16ToNSString(WebsiteSettingsUI::PermissionActionToUIString(
55 static_cast<ContentSetting>([item tag]), 55 type, static_cast<ContentSetting>([item tag]), defaultSetting,
56 defaultSetting,
57 content_settings::SETTING_SOURCE_USER)); 56 content_settings::SETTING_SOURCE_USER));
58 NSSize size = SizeForWebsiteSettingsButtonTitle(self, title); 57 NSSize size = SizeForWebsiteSettingsButtonTitle(self, title);
59 maxTitleWidth = std::max(maxTitleWidth, size.width); 58 maxTitleWidth = std::max(maxTitleWidth, size.width);
60 } 59 }
61 return maxTitleWidth; 60 return maxTitleWidth;
62 } 61 }
63 62
64 // Accessor function for testing only. 63 // Accessor function for testing only.
65 - (NSMenu*)permissionMenu { 64 - (NSMenu*)permissionMenu {
66 return [menuController_ menu]; 65 return [menuController_ menu];
67 } 66 }
68 67
69 @end 68 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698