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

Side by Side Diff: chrome/browser/ui/cocoa/subresource_filter/subresource_filter_bubble_controller.mm

Issue 2826233002: [subresource_filter] Mac UI updated and xib replaced with code based layout. (Closed)
Patch Set: csharrison feedback addressed Created 3 years, 7 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
« no previous file with comments | « chrome/browser/ui/cocoa/subresource_filter/subresource_filter_bubble_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 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/subresource_filter/subresource_filter_bubble_co ntroller.h"
6
7 #include "base/strings/sys_string_conversions.h"
8 #import "chrome/browser/ui/cocoa/info_bubble_window.h"
9 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
10 #include "components/strings/grit/components_strings.h"
11 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h"
12 #include "ui/base/l10n/l10n_util_mac.h"
13
14 @interface SubresourceFilterBubbleController () {
15 NSButton* manageCheckbox_;
16 }
17 @end
18
19 @implementation SubresourceFilterBubbleController
20
21 - (id)initWithModel:(ContentSettingBubbleModel*)contentSettingBubbleModel
22 webContents:(content::WebContents*)webContents
23 parentWindow:(NSWindow*)parentWindow
24 decoration:(ContentSettingDecoration*)decoration
25 anchoredAt:(NSPoint)anchoredAt {
26 NSRect contentRect = NSMakeRect(196, 376, 316, 154);
27 base::scoped_nsobject<InfoBubbleWindow> window([[InfoBubbleWindow alloc]
28 initWithContentRect:contentRect
29 styleMask:NSBorderlessWindowMask
30 backing:NSBackingStoreBuffered
31 defer:NO]);
32
33 // Disable animations - otherwise, the window/controller will outlive the web
34 // contents it's associated with.
35 [window setAllowedAnimations:info_bubble::kAnimateNone];
36
37 [super initWithModel:contentSettingBubbleModel
38 webContents:webContents
39 window:window
40 parentWindow:parentWindow
41 decoration:decoration
42 anchoredAt:anchoredAt];
43 return self;
44 }
45
46 - (void)awakeFromNib {
47 [self loadView];
48 [super awakeFromNib];
49 }
50
51 - (void)layoutView {
52 [super layoutView];
53 [self initializeManageCheckbox];
54 }
55
56 - (void)loadView {
57 titleLabel_ =
58 [[NSTextField alloc] initWithFrame:NSMakeRect(18, 120, 282, 14)];
59 [titleLabel_ setEditable:NO];
60 [titleLabel_ setBordered:NO];
61 [self.window.contentView addSubview:titleLabel_];
62 [titleLabel_ release];
63
64 messageLabel_ =
65 [[NSTextField alloc] initWithFrame:NSMakeRect(18, 85, 282, 28)];
66 [messageLabel_ setEditable:NO];
67 [messageLabel_ setBordered:NO];
68 [self.window.contentView addSubview:messageLabel_];
69 [messageLabel_ release];
70
71 manageCheckbox_ =
72 [[NSButton alloc] initWithFrame:NSMakeRect(18, 35, 282, 28)];
73 [manageCheckbox_ setButtonType:NSSwitchButton];
74 [manageCheckbox_ setState:NSOffState];
75 [self.window.contentView addSubview:manageCheckbox_];
76 [manageCheckbox_ setAction:@selector(manageCheckboxChecked:)];
77 [manageCheckbox_ release];
78
79 doneButton_ = [[NSButton alloc] initWithFrame:NSMakeRect(210, 10, 90, 28)];
80 [doneButton_ setBezelStyle:NSRoundedBezelStyle];
81 [doneButton_ highlight:YES];
82 [doneButton_ setTitle:l10n_util::GetNSString(IDS_OK)];
83 [self.window.contentView addSubview:doneButton_];
84 [doneButton_ setAction:@selector(closeBubble:)];
85 [doneButton_ release];
86 }
87
88 - (void)initializeManageCheckbox {
89 if (!manageCheckbox_)
90 return;
91
92 NSString* label = base::SysUTF16ToNSString(
93 contentSettingBubbleModel_->bubble_content().manage_text);
94 [manageCheckbox_ setTitle:label];
95
96 CGFloat deltaY =
97 [GTMUILocalizerAndLayoutTweaker sizeToFitView:manageCheckbox_].height;
98 NSRect windowFrame = [[self window] frame];
99 windowFrame.size.height += deltaY;
100 [[self window] setFrame:windowFrame display:NO];
101 NSRect manageCheckboxFrame = [manageCheckbox_ frame];
102 manageCheckboxFrame.origin.y -= deltaY;
103 [manageCheckbox_ setFrame:manageCheckboxFrame];
104 }
105
106 // Callback for "manage" checkbox button.
107 - (void)manageCheckboxChecked:(id)sender {
108 bool isChecked = [sender state] == NSOnState;
109 contentSettingBubbleModel_->OnManageCheckboxChecked(isChecked);
110 [self layoutView];
111 }
112
113 // For testing.
114
115 - (id)titleLabel {
116 return titleLabel_;
117 }
118
119 - (id)messageLabel {
120 return messageLabel_;
121 }
122
123 - (id)manageCheckbox {
124 return manageCheckbox_;
125 }
126
127 - (id)doneButton {
128 return doneButton_;
129 }
130 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/subresource_filter/subresource_filter_bubble_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698