Chromium Code Reviews| OLD | NEW |
|---|---|
| (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" | |
|
Robert Sesek
2017/05/03 22:05:11
nit: blank line after
shivanisha
2017/05/04 20:20:57
done
| |
| 6 #include "base/strings/sys_string_conversions.h" | |
| 7 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | |
| 8 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | |
| 9 #include "components/strings/grit/components_strings.h" | |
| 10 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h" | |
| 11 #include "ui/base/l10n/l10n_util_mac.h" | |
| 12 | |
| 13 @interface SubresourceFilterBubbleController (Private) | |
| 14 - (void)loadView; | |
| 15 @end | |
| 16 | |
| 17 @implementation SubresourceFilterBubbleController | |
| 18 | |
| 19 - (void)awakeFromNib { | |
| 20 [self loadView]; | |
| 21 [super awakeFromNib]; | |
| 22 } | |
| 23 | |
| 24 - (void)layoutView { | |
| 25 [super layoutView]; | |
| 26 [self initializeManageCheckbox]; | |
| 27 } | |
| 28 | |
| 29 - (void)initializeManageCheckbox { | |
| 30 if (!manageCheckbox_) | |
| 31 return; | |
| 32 | |
| 33 NSString* label = base::SysUTF16ToNSString( | |
| 34 contentSettingBubbleModel_->bubble_content().manage_text); | |
| 35 [manageCheckbox_ setTitle:label]; | |
| 36 | |
| 37 CGFloat deltaY = | |
| 38 [GTMUILocalizerAndLayoutTweaker sizeToFitView:manageCheckbox_].height; | |
| 39 NSRect windowFrame = [[self window] frame]; | |
| 40 windowFrame.size.height += deltaY; | |
| 41 [[self window] setFrame:windowFrame display:NO]; | |
| 42 NSRect manageCheckboxFrame = [manageCheckbox_ frame]; | |
| 43 manageCheckboxFrame.origin.y -= deltaY; | |
| 44 [manageCheckbox_ setFrame:manageCheckboxFrame]; | |
| 45 } | |
| 46 | |
| 47 - (void)loadView { | |
|
Robert Sesek
2017/05/03 22:05:11
method ordering: Move this above initializeManageC
shivanisha
2017/05/04 20:20:57
done
| |
| 48 titleLabel_ = | |
| 49 [[NSTextField alloc] initWithFrame:NSMakeRect(18, 120, 282, 14)]; | |
| 50 [titleLabel_ setEditable:NO]; | |
| 51 [titleLabel_ setBordered:NO]; | |
| 52 [self.window.contentView addSubview:titleLabel_]; | |
| 53 [titleLabel_ autorelease]; | |
|
Robert Sesek
2017/05/03 22:05:11
You can switch the |autorelease| calls to direct |
shivanisha
2017/05/04 20:20:58
Done. So it will be released when subview goes out
| |
| 54 | |
| 55 messageLabel_ = | |
| 56 [[NSTextField alloc] initWithFrame:NSMakeRect(18, 85, 282, 28)]; | |
| 57 [messageLabel_ setEditable:NO]; | |
| 58 [messageLabel_ setBordered:NO]; | |
| 59 [self.window.contentView addSubview:messageLabel_]; | |
| 60 [messageLabel_ autorelease]; | |
| 61 | |
| 62 manageCheckbox_ = | |
| 63 [[NSButton alloc] initWithFrame:NSMakeRect(18, 35, 282, 28)]; | |
| 64 [manageCheckbox_ setButtonType:NSSwitchButton]; | |
| 65 [manageCheckbox_ setState:NSOffState]; | |
| 66 [self.window.contentView addSubview:manageCheckbox_]; | |
| 67 [manageCheckbox_ setAction:@selector(manageCheckboxChecked:)]; | |
| 68 [manageCheckbox_ autorelease]; | |
| 69 | |
| 70 doneButton_ = [[NSButton alloc] initWithFrame:NSMakeRect(210, 10, 90, 28)]; | |
| 71 [doneButton_ setBezelStyle:NSRoundedBezelStyle]; | |
| 72 [doneButton_ highlight:YES]; | |
| 73 [doneButton_ setTitle:l10n_util::GetNSString(IDS_OK)]; | |
| 74 [self.window.contentView addSubview:doneButton_]; | |
| 75 [doneButton_ setAction:@selector(closeBubble:)]; | |
| 76 [doneButton_ autorelease]; | |
| 77 } | |
| 78 | |
| 79 - (id)initWithModel:(ContentSettingBubbleModel*)contentSettingBubbleModel | |
|
Robert Sesek
2017/05/03 22:05:11
method ordering: Move this to be the first method
shivanisha
2017/05/04 20:20:58
done
| |
| 80 webContents:(content::WebContents*)webContents | |
| 81 parentWindow:(NSWindow*)parentWindow | |
| 82 decoration:(ContentSettingDecoration*)decoration | |
| 83 anchoredAt:(NSPoint)anchoredAt { | |
| 84 NSRect contentRect = NSMakeRect(196, 376, 316, 154); | |
| 85 base::scoped_nsobject<InfoBubbleWindow> window([[InfoBubbleWindow alloc] | |
| 86 initWithContentRect:contentRect | |
| 87 styleMask:NSBorderlessWindowMask | |
| 88 backing:NSBackingStoreBuffered | |
| 89 defer:NO]); | |
| 90 | |
| 91 // Disable animations - otherwise, the window/controller will outlive the web | |
| 92 // contents it's associated with. | |
| 93 [window setAllowedAnimations:info_bubble::kAnimateNone]; | |
| 94 | |
| 95 [super initWithModel:contentSettingBubbleModel | |
| 96 webContents:webContents | |
| 97 window:window | |
| 98 parentWindow:parentWindow | |
| 99 decoration:decoration | |
| 100 anchoredAt:anchoredAt]; | |
| 101 return self; | |
| 102 } | |
| 103 | |
| 104 // Callback for "manage" checkbox button. | |
| 105 - (IBAction)manageCheckboxChecked:(id)sender { | |
|
Robert Sesek
2017/05/03 22:05:11
Similar to |IBOutlet|, you can drop the |IBAction|
shivanisha
2017/05/04 20:20:57
done
| |
| 106 bool isChecked = [sender state] == NSOnState; | |
| 107 contentSettingBubbleModel_->OnManageCheckboxChecked(isChecked); | |
| 108 [self layoutView]; | |
| 109 } | |
| 110 | |
| 111 @end | |
| OLD | NEW |