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/website_settings_bubble_controller.h" | 5 #import "chrome/browser/ui/cocoa/website_settings_bubble_controller.h" |
6 | 6 |
7 #import <AppKit/NSCell.h> | |
Robert Sesek
2012/07/26 02:49:28
Is this necessary? You import Cocoa.h in the .h, w
Patrick Dubroy
2012/07/28 02:15:02
You're right. I could have sworn I added this only
| |
8 #import <QuartzCore/QuartzCore.h> | |
9 | |
7 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
8 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 11 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
9 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 12 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
10 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 13 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
11 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 14 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
12 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 15 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
13 #include "content/public/browser/cert_store.h" | 16 #include "content/public/browser/cert_store.h" |
14 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
18 #include "grit/theme_resources.h" | |
15 #include "grit/ui_resources.h" | 19 #include "grit/ui_resources.h" |
16 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" | 20 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" |
17 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
18 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
19 | 23 |
20 namespace { | 24 namespace { |
21 | 25 |
22 // The width of the window, in view coordinates. The height will be determined | 26 // The width of the window, in view coordinates. The height will be determined |
23 // by the content. | 27 // by the content. |
24 const CGFloat kWindowWidth = 380; | 28 const CGFloat kWindowWidth = 380; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 // A simple container to hold all the contents of the website settings bubble. | 70 // A simple container to hold all the contents of the website settings bubble. |
67 // It uses a flipped coordinate system to make text layout easier. | 71 // It uses a flipped coordinate system to make text layout easier. |
68 @interface WebsiteSettingsContentView : NSView | 72 @interface WebsiteSettingsContentView : NSView |
69 @end | 73 @end |
70 @implementation WebsiteSettingsContentView | 74 @implementation WebsiteSettingsContentView |
71 - (BOOL)isFlipped { | 75 - (BOOL)isFlipped { |
72 return YES; | 76 return YES; |
73 } | 77 } |
74 @end | 78 @end |
75 | 79 |
80 @interface CustomTabbedSegmentedCell : NSSegmentedCell { | |
Robert Sesek
2012/07/26 02:49:28
naming: call this WebsiteSettingsTabSegmentedCell
Patrick Dubroy
2012/07/28 02:15:02
Done.
| |
81 @private | |
82 scoped_nsobject<NSImage> tabBackgroundImage_; | |
83 scoped_nsobject<NSImage> tabCenterImage_; | |
84 scoped_nsobject<NSImage> tabLeftImage_; | |
85 scoped_nsobject<NSImage> tabRightImage_; | |
86 } | |
87 @end | |
88 @implementation CustomTabbedSegmentedCell | |
89 - (id)init { | |
90 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
Robert Sesek
2012/07/26 02:49:28
This should be in an if ((self = [super init])) bl
Patrick Dubroy
2012/07/28 02:15:02
Done.
| |
91 tabBackgroundImage_.reset( | |
92 [rb.GetNativeImageNamed(IDR_WEBSITE_SETTINGS_TAB_BACKGROUND) retain]); | |
93 tabCenterImage_.reset( | |
94 [rb.GetNativeImageNamed(IDR_WEBSITE_SETTINGS_TAB_CENTER) retain]); | |
95 tabLeftImage_.reset( | |
96 [rb.GetNativeImageNamed(IDR_WEBSITE_SETTINGS_TAB_LEFT) retain]); | |
97 tabRightImage_.reset( | |
98 [rb.GetNativeImageNamed(IDR_WEBSITE_SETTINGS_TAB_RIGHT) retain]); | |
99 | |
100 return [super init]; | |
101 } | |
102 | |
103 // Fill the given rect with a tiled pattern using the given image. | |
104 - (void)fillRect:(NSRect)rect | |
105 withTiledImage:(NSImage*)image | |
106 inView:(NSView*)view{ | |
107 NSGraphicsContext* context = [NSGraphicsContext currentContext]; | |
108 [context saveGraphicsState]; | |
Robert Sesek
2012/07/26 02:49:28
There's a scoper in ui/gfx for this.
Patrick Dubroy
2012/07/28 02:15:02
Not relevant anymore.
| |
109 NSPoint patternStart = [view convertPoint:rect.origin toView:nil]; | |
110 [context setPatternPhase:patternStart]; | |
111 [[NSColor colorWithPatternImage:image] set]; | |
112 NSRectFill(rect); | |
113 [context restoreGraphicsState]; | |
114 } | |
115 | |
116 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { | |
117 // Draw the background for the tab strip. | |
118 [self fillRect:cellFrame | |
119 withTiledImage:tabBackgroundImage_.get() | |
Robert Sesek
2012/07/26 02:49:28
nit: if aligning the colons mean that the next lin
Patrick Dubroy
2012/07/28 02:15:02
Not relevant anymore.
| |
120 inView:controlView]; | |
121 | |
122 // Draw the individual tabs. | |
123 [self drawInteriorWithFrame:cellFrame inView:controlView]; | |
124 } | |
125 | |
126 - (void)drawSegment:(NSInteger)segment | |
127 inFrame:(NSRect)frame | |
128 withView:(NSView*)controlView { | |
129 if ([self isSelectedForSegment:segment]) { | |
130 NSDrawThreePartImage(frame, | |
131 tabLeftImage_, | |
132 tabCenterImage_, | |
133 tabRightImage_, | |
134 NO, | |
Robert Sesek
2012/07/26 02:49:28
For these BOOL params, can you do /*param_name=*/
Patrick Dubroy
2012/07/28 02:15:02
Done.
| |
135 NSCompositeSourceOver, | |
136 1, | |
137 YES); | |
138 } | |
139 frame.origin.y += 20; | |
140 frame.size.height -= 20; | |
141 | |
142 // Call the superclass to draw the label. | |
143 [super drawSegment:segment inFrame:frame withView:controlView]; | |
144 } | |
145 @end | |
146 | |
76 @implementation WebsiteSettingsBubbleController | 147 @implementation WebsiteSettingsBubbleController |
77 | 148 |
78 - (id)initWithParentWindow:(NSWindow*)parentWindow | 149 - (id)initWithParentWindow:(NSWindow*)parentWindow |
79 websiteSettingsUIBridge:(WebsiteSettingsUIBridge*)bridge { | 150 websiteSettingsUIBridge:(WebsiteSettingsUIBridge*)bridge { |
80 DCHECK(parentWindow); | 151 DCHECK(parentWindow); |
81 | 152 |
82 // Use an arbitrary height; it will be changed in performLayout. | 153 // Use an arbitrary height; it will be changed in performLayout. |
83 NSRect contentRect = NSMakeRect(0, 0, kWindowWidth, 1); | 154 NSRect contentRect = NSMakeRect(0, 0, kWindowWidth, 1); |
84 // Create an empty window into which content is placed. | 155 // Create an empty window into which content is placed. |
85 scoped_nsobject<InfoBubbleWindow> window( | 156 scoped_nsobject<InfoBubbleWindow> window( |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 | 197 |
127 // Create a text field to identity status (e.g. verified, not verified). | 198 // Create a text field to identity status (e.g. verified, not verified). |
128 identityStatusField_ = [self addText:string16() | 199 identityStatusField_ = [self addText:string16() |
129 withSize:[NSFont smallSystemFontSize] | 200 withSize:[NSFont smallSystemFontSize] |
130 bold:NO | 201 bold:NO |
131 toView:contentView_ | 202 toView:contentView_ |
132 atPoint:controlOrigin]; | 203 atPoint:controlOrigin]; |
133 | 204 |
134 // Create the tab view and its two tabs. | 205 // Create the tab view and its two tabs. |
135 | 206 |
207 NSRect initialFrame = NSMakeRect(0, 0, kWindowWidth, 44); | |
208 segmentedControl_.reset( | |
209 [[NSSegmentedControl alloc] initWithFrame:initialFrame]); | |
210 [segmentedControl_ setCell:[[CustomTabbedSegmentedCell alloc] init]]; | |
211 [segmentedControl_ setSegmentCount:2]; | |
212 [segmentedControl_ setTarget:self]; | |
213 [segmentedControl_ setAction:@selector(tabSelected:)]; | |
214 NSFont* smallSystemFont = | |
215 [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; | |
216 NSDictionary* textAttributes = | |
217 [NSDictionary dictionaryWithObject:smallSystemFont | |
218 forKey:NSFontAttributeName]; | |
219 | |
220 NSString* label = l10n_util::GetNSString( | |
221 IDS_WEBSITE_SETTINGS_TAB_LABEL_PERMISSIONS); | |
222 NSSize textSize = [label sizeWithAttributes:textAttributes]; | |
223 | |
224 [segmentedControl_ setLabel:label forSegment:0]; | |
225 [segmentedControl_ setWidth:textSize.width + 2 * 28 forSegment:0]; | |
Robert Sesek
2012/07/26 02:49:28
Where's 28 come from?
Patrick Dubroy
2012/07/28 02:15:02
Fixed.
| |
226 | |
227 label = l10n_util::GetNSString(IDS_WEBSITE_SETTINGS_TAB_LABEL_CONNECTION); | |
228 textSize = [label sizeWithAttributes:textAttributes]; | |
229 [segmentedControl_ setLabel:label forSegment:1]; | |
230 [segmentedControl_ setWidth:textSize.width + 2 * 28 forSegment:1]; | |
231 | |
232 [segmentedControl_ setFont:smallSystemFont]; | |
233 [contentView_ addSubview:segmentedControl_]; | |
234 | |
136 NSRect tabFrame = NSMakeRect(0, 0, kWindowWidth, 300); | 235 NSRect tabFrame = NSMakeRect(0, 0, kWindowWidth, 300); |
137 tabView_.reset([[NSTabView alloc] initWithFrame:tabFrame]); | 236 tabView_.reset([[NSTabView alloc] initWithFrame:tabFrame]); |
138 [tabView_ setTabViewType:NSTopTabsBezelBorder]; | 237 [tabView_ setTabViewType:NSNoTabsNoBorder]; |
238 [tabView_ setDrawsBackground:NO]; | |
139 [tabView_ setControlSize:NSSmallControlSize]; | 239 [tabView_ setControlSize:NSSmallControlSize]; |
140 [tabView_ setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; | |
141 [contentView_ addSubview:tabView_.get()]; | 240 [contentView_ addSubview:tabView_.get()]; |
142 | 241 |
143 permissionsContentView_ = [self addPermissionsTabToTabView:tabView_]; | 242 permissionsContentView_ = [self addPermissionsTabToTabView:tabView_]; |
144 [self addConnectionTabToTabView:tabView_]; | 243 [self addConnectionTabToTabView:tabView_]; |
145 | 244 |
146 // Replace the window's content. | 245 // Replace the window's content. |
147 [[[self window] contentView] setSubviews: | 246 [[[self window] contentView] setSubviews: |
148 [NSArray arrayWithObject:contentView_.get()]]; | 247 [NSArray arrayWithObject:contentView_.get()]]; |
149 | 248 |
150 [self performLayout]; | 249 [self performLayout]; |
151 } | 250 } |
152 | 251 |
153 // Create the contents of the Permissions tab and add it to the given tab view. | 252 // Create the contents of the Permissions tab and add it to the given tab view. |
154 // Returns a weak reference to the tab view item's view. | 253 // Returns a weak reference to the tab view item's view. |
155 - (NSView*)addPermissionsTabToTabView:(NSTabView*)tabView { | 254 - (NSView*)addPermissionsTabToTabView:(NSTabView*)tabView { |
156 scoped_nsobject<NSTabViewItem> item([[NSTabViewItem alloc] init]); | 255 scoped_nsobject<NSTabViewItem> item([[NSTabViewItem alloc] init]); |
157 [item setLabel: | |
158 l10n_util::GetNSString(IDS_WEBSITE_SETTINGS_TAB_LABEL_PERMISSIONS)]; | |
159 [tabView_ addTabViewItem:item.get()]; | 256 [tabView_ addTabViewItem:item.get()]; |
160 scoped_nsobject<NSView> contentView([[WebsiteSettingsContentView alloc] | 257 scoped_nsobject<NSView> contentView([[WebsiteSettingsContentView alloc] |
161 initWithFrame:[tabView_ contentRect]]); | 258 initWithFrame:[tabView_ contentRect]]); |
162 [item setView:contentView.get()]; | 259 [item setView:contentView.get()]; |
163 return contentView.get(); | 260 return contentView.get(); |
164 } | 261 } |
165 | 262 |
166 // Create the contents of the Connection tab and add it to the given tab view. | 263 // Create the contents of the Connection tab and add it to the given tab view. |
167 // Returns a weak reference to the tab view item's view. | 264 // Returns a weak reference to the tab view item's view. |
168 - (NSView*)addConnectionTabToTabView:(NSTabView*)tabView { | 265 - (NSView*)addConnectionTabToTabView:(NSTabView*)tabView { |
169 scoped_nsobject<NSTabViewItem> item([[NSTabViewItem alloc] init]); | 266 scoped_nsobject<NSTabViewItem> item([[NSTabViewItem alloc] init]); |
170 [item setLabel: | |
171 l10n_util::GetNSString(IDS_WEBSITE_SETTINGS_TAB_LABEL_CONNECTION)]; | |
172 | |
173 scoped_nsobject<NSView> contentView([[WebsiteSettingsContentView alloc] | 267 scoped_nsobject<NSView> contentView([[WebsiteSettingsContentView alloc] |
174 initWithFrame:[tabView_ contentRect]]); | 268 initWithFrame:[tabView_ contentRect]]); |
175 | 269 |
176 // Place all the text at the same position. It will be adjusted in | 270 // Place all the text at the same position. It will be adjusted in |
177 // performLayout. | 271 // performLayout. |
178 NSPoint textPosition = NSMakePoint( | 272 NSPoint textPosition = NSMakePoint( |
179 kTabViewContentsPadding + kImageSize + kImageSpacing, | 273 kTabViewContentsPadding + kImageSize + kImageSpacing, |
180 kTabViewContentsPadding); | 274 kTabViewContentsPadding); |
181 | 275 |
182 identityStatusIcon_ = | 276 identityStatusIcon_ = |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 | 354 |
261 // Lay out the last visit section. | 355 // Lay out the last visit section. |
262 [self setYPositionOfView:firstVisitIcon_ to:yPos]; | 356 [self setYPositionOfView:firstVisitIcon_ to:yPos]; |
263 [self sizeTextFieldHeightToFit:firstVisitHeaderField_]; | 357 [self sizeTextFieldHeightToFit:firstVisitHeaderField_]; |
264 yPos = [self setYPositionOfView:firstVisitHeaderField_ to:yPos]; | 358 yPos = [self setYPositionOfView:firstVisitHeaderField_ to:yPos]; |
265 yPos += kHeadlineSpacing; | 359 yPos += kHeadlineSpacing; |
266 [self sizeTextFieldHeightToFit:firstVisitDescriptionField_]; | 360 [self sizeTextFieldHeightToFit:firstVisitDescriptionField_]; |
267 [self setYPositionOfView:firstVisitDescriptionField_ to:yPos]; | 361 [self setYPositionOfView:firstVisitDescriptionField_ to:yPos]; |
268 | 362 |
269 // Adjust the tab view size and place it below the identity status. | 363 // Adjust the tab view size and place it below the identity status. |
364 | |
365 NSRect segmentedControlFrame = [segmentedControl_ frame]; | |
366 segmentedControlFrame.origin.y = | |
367 NSMaxY([identityStatusField_ frame]); | |
368 [segmentedControl_ setFrame:segmentedControlFrame]; | |
369 | |
270 NSRect tabViewFrame = [tabView_ frame]; | 370 NSRect tabViewFrame = [tabView_ frame]; |
271 tabViewFrame.origin.y = | 371 tabViewFrame.origin.y = NSMaxY(segmentedControlFrame); |
272 NSMaxY([identityStatusField_ frame]) + kVerticalSpacing; | |
273 | 372 |
274 CGFloat connectionTabHeight = std::max( | 373 CGFloat connectionTabHeight = std::max( |
275 NSMaxY([firstVisitDescriptionField_ frame]), | 374 NSMaxY([firstVisitDescriptionField_ frame]), |
276 NSMaxY([firstVisitIcon_ frame ])); | 375 NSMaxY([firstVisitIcon_ frame ])); |
277 connectionTabHeight += kVerticalSpacing; | 376 connectionTabHeight += kVerticalSpacing; |
278 | 377 |
279 CGFloat tabContentHeight = std::max(connectionTabHeight, | 378 CGFloat tabContentHeight = std::max(connectionTabHeight, |
280 permissionsTabHeight_); | 379 permissionsTabHeight_); |
281 tabViewFrame.size.height = tabContentHeight + | 380 tabViewFrame.size.height = tabContentHeight + |
282 NSHeight(tabViewFrame) - NSHeight([tabView_ contentRect]); | 381 NSHeight(tabViewFrame) - NSHeight([tabView_ contentRect]); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
462 | 561 |
463 [button setAction:@selector(permissionValueChanged:)]; | 562 [button setAction:@selector(permissionValueChanged:)]; |
464 [button setTarget:self]; | 563 [button setTarget:self]; |
465 | 564 |
466 [self setTitleOfButton:button]; | 565 [self setTitleOfButton:button]; |
467 | 566 |
468 [view addSubview:button.get()]; | 567 [view addSubview:button.get()]; |
469 return button.get(); | 568 return button.get(); |
470 } | 569 } |
471 | 570 |
571 - (void)tabSelected:(id)sender { | |
572 [tabView_ selectTabViewItemAtIndex: [segmentedControl_ selectedSegment]]; | |
Robert Sesek
2012/07/26 02:49:28
nit: no space after :
Patrick Dubroy
2012/07/28 02:15:02
Done.
| |
573 } | |
574 | |
472 // Handler for the permission-changing menus. | 575 // Handler for the permission-changing menus. |
473 - (void)permissionValueChanged:(id)sender { | 576 - (void)permissionValueChanged:(id)sender { |
474 DCHECK([sender isKindOfClass:[NSPopUpButton class]]); | 577 DCHECK([sender isKindOfClass:[NSPopUpButton class]]); |
475 NSPopUpButton* button = static_cast<NSPopUpButton*>(sender); | 578 NSPopUpButton* button = static_cast<NSPopUpButton*>(sender); |
476 ContentSettingsType type = static_cast<ContentSettingsType>([button tag]); | 579 ContentSettingsType type = static_cast<ContentSettingsType>([button tag]); |
477 ContentSetting newSetting = [self contentSettingForButton:button]; | 580 ContentSetting newSetting = [self contentSettingForButton:button]; |
478 | 581 |
479 [self setTitleOfButton:button]; | 582 [self setTitleOfButton:button]; |
480 if (presenter_.get()) | 583 if (presenter_.get()) |
481 presenter_->OnSitePermissionChanged(type, newSetting); | 584 presenter_->OnSitePermissionChanged(type, newSetting); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
610 } | 713 } |
611 | 714 |
612 void WebsiteSettingsUIBridge::SetIdentityInfo( | 715 void WebsiteSettingsUIBridge::SetIdentityInfo( |
613 const WebsiteSettingsUI::IdentityInfo& identity_info) { | 716 const WebsiteSettingsUI::IdentityInfo& identity_info) { |
614 [bubble_controller_ setIdentityInfo:identity_info]; | 717 [bubble_controller_ setIdentityInfo:identity_info]; |
615 } | 718 } |
616 | 719 |
617 void WebsiteSettingsUIBridge::SetFirstVisit(const string16& first_visit) { | 720 void WebsiteSettingsUIBridge::SetFirstVisit(const string16& first_visit) { |
618 [bubble_controller_ setFirstVisit:first_visit]; | 721 [bubble_controller_ setFirstVisit:first_visit]; |
619 } | 722 } |
OLD | NEW |