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

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

Issue 2741933003: Move Cocoa Page Info UI code to its own folder. (Closed)
Patch Set: Fixin' more unit tests BUILD paths (does mass_rename.py just not pick those up? => crbug.com/701529) Created 3 years, 9 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "chrome/browser/ui/cocoa/website_settings/permission_selector_button.h"
6
7 #include "base/strings/sys_string_conversions.h"
8 #include "chrome/browser/ui/cocoa/website_settings/website_settings_utils_cocoa. h"
9 #include "chrome/browser/ui/page_info/website_settings_ui.h"
10 #import "ui/base/cocoa/menu_controller.h"
11
12 @implementation PermissionSelectorButton
13
14 - (id)initWithPermissionInfo:
15 (const WebsiteSettingsUI::PermissionInfo&)permissionInfo
16 forURL:(const GURL&)url
17 withCallback:(PermissionMenuModel::ChangeCallback)callback
18 profile:(Profile*)profile {
19 if (self = [super initWithFrame:NSMakeRect(0, 0, 1, 1) pullsDown:NO]) {
20 [self setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
21 [self setBordered:NO];
22 [[self cell] setControlSize:NSSmallControlSize];
23
24 menuModel_.reset(
25 new PermissionMenuModel(profile, url, permissionInfo, callback));
26
27 menuController_.reset([[MenuController alloc] initWithModel:menuModel_.get()
28 useWithPopUpButtonCell:NO]);
29 [self setMenu:[menuController_ menu]];
30 [self selectItemWithTag:permissionInfo.setting];
31
32 // Set the button title.
33 base::scoped_nsobject<NSMenuItem> titleItem([[NSMenuItem alloc] init]);
34 base::string16 buttonTitle = WebsiteSettingsUI::PermissionActionToUIString(
35 profile, permissionInfo.type, permissionInfo.setting,
36 permissionInfo.default_setting, permissionInfo.source);
37 [titleItem setTitle:base::SysUTF16ToNSString(buttonTitle)];
38 [[self cell] setUsesItemFromMenu:NO];
39 [[self cell] setMenuItem:titleItem.get()];
40 // Although the frame is reset, below, this sizes the cell properly.
41 [self sizeToFit];
42
43 // Size the button to just fit the visible title - not all of its items.
44 [self setFrameSize:SizeForWebsiteSettingsButtonTitle(self, [self title])];
45 }
46 return self;
47 }
48
49 - (CGFloat)maxTitleWidthForContentSettingsType:(ContentSettingsType)type
50 withDefaultSetting:(ContentSetting)defaultSetting
51 profile:(Profile*)profile {
52 // Determine the largest possible size for this button.
53 CGFloat maxTitleWidth = 0;
54 for (NSMenuItem* item in [self itemArray]) {
55 NSString* title =
56 base::SysUTF16ToNSString(WebsiteSettingsUI::PermissionActionToUIString(
57 profile, type, static_cast<ContentSetting>([item tag]),
58 defaultSetting, content_settings::SETTING_SOURCE_USER));
59 NSSize size = SizeForWebsiteSettingsButtonTitle(self, title);
60 maxTitleWidth = std::max(maxTitleWidth, size.width);
61 }
62 return maxTitleWidth;
63 }
64
65 // Accessor function for testing only.
66 - (NSMenu*)permissionMenu {
67 return [menuController_ menu];
68 }
69
70 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698