Index: chrome/browser/ui/cocoa/website_settings_bubble_controller.mm |
diff --git a/chrome/browser/ui/cocoa/website_settings_bubble_controller.mm b/chrome/browser/ui/cocoa/website_settings_bubble_controller.mm |
index 22cf074cb3d6a17f6b32f6f2d11bb5634dbdb491..b6307d83fee14495dd13bb1b67d9cc842d823800 100644 |
--- a/chrome/browser/ui/cocoa/website_settings_bubble_controller.mm |
+++ b/chrome/browser/ui/cocoa/website_settings_bubble_controller.mm |
@@ -4,6 +4,9 @@ |
#import "chrome/browser/ui/cocoa/website_settings_bubble_controller.h" |
+#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
|
+#import <QuartzCore/QuartzCore.h> |
+ |
#include "base/sys_string_conversions.h" |
#import "chrome/browser/ui/cocoa/browser_window_controller.h" |
#import "chrome/browser/ui/cocoa/info_bubble_view.h" |
@@ -12,6 +15,7 @@ |
#include "chrome/browser/ui/tab_contents/tab_contents.h" |
#include "content/public/browser/cert_store.h" |
#include "grit/generated_resources.h" |
+#include "grit/theme_resources.h" |
#include "grit/ui_resources.h" |
#import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" |
#include "ui/base/l10n/l10n_util.h" |
@@ -73,6 +77,73 @@ const ContentSetting kPermissionsMenuSettings[] = { |
} |
@end |
+@interface CustomTabbedSegmentedCell : NSSegmentedCell { |
Robert Sesek
2012/07/26 02:49:28
naming: call this WebsiteSettingsTabSegmentedCell
Patrick Dubroy
2012/07/28 02:15:02
Done.
|
+ @private |
+ scoped_nsobject<NSImage> tabBackgroundImage_; |
+ scoped_nsobject<NSImage> tabCenterImage_; |
+ scoped_nsobject<NSImage> tabLeftImage_; |
+ scoped_nsobject<NSImage> tabRightImage_; |
+} |
+@end |
+@implementation CustomTabbedSegmentedCell |
+- (id)init { |
+ 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.
|
+ tabBackgroundImage_.reset( |
+ [rb.GetNativeImageNamed(IDR_WEBSITE_SETTINGS_TAB_BACKGROUND) retain]); |
+ tabCenterImage_.reset( |
+ [rb.GetNativeImageNamed(IDR_WEBSITE_SETTINGS_TAB_CENTER) retain]); |
+ tabLeftImage_.reset( |
+ [rb.GetNativeImageNamed(IDR_WEBSITE_SETTINGS_TAB_LEFT) retain]); |
+ tabRightImage_.reset( |
+ [rb.GetNativeImageNamed(IDR_WEBSITE_SETTINGS_TAB_RIGHT) retain]); |
+ |
+ return [super init]; |
+} |
+ |
+// Fill the given rect with a tiled pattern using the given image. |
+- (void)fillRect:(NSRect)rect |
+ withTiledImage:(NSImage*)image |
+ inView:(NSView*)view{ |
+ NSGraphicsContext* context = [NSGraphicsContext currentContext]; |
+ [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.
|
+ NSPoint patternStart = [view convertPoint:rect.origin toView:nil]; |
+ [context setPatternPhase:patternStart]; |
+ [[NSColor colorWithPatternImage:image] set]; |
+ NSRectFill(rect); |
+ [context restoreGraphicsState]; |
+} |
+ |
+- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { |
+ // Draw the background for the tab strip. |
+ [self fillRect:cellFrame |
+ 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.
|
+ inView:controlView]; |
+ |
+ // Draw the individual tabs. |
+ [self drawInteriorWithFrame:cellFrame inView:controlView]; |
+} |
+ |
+- (void)drawSegment:(NSInteger)segment |
+ inFrame:(NSRect)frame |
+ withView:(NSView*)controlView { |
+ if ([self isSelectedForSegment:segment]) { |
+ NSDrawThreePartImage(frame, |
+ tabLeftImage_, |
+ tabCenterImage_, |
+ tabRightImage_, |
+ 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.
|
+ NSCompositeSourceOver, |
+ 1, |
+ YES); |
+ } |
+ frame.origin.y += 20; |
+ frame.size.height -= 20; |
+ |
+ // Call the superclass to draw the label. |
+ [super drawSegment:segment inFrame:frame withView:controlView]; |
+} |
+@end |
+ |
@implementation WebsiteSettingsBubbleController |
- (id)initWithParentWindow:(NSWindow*)parentWindow |
@@ -133,11 +204,39 @@ const ContentSetting kPermissionsMenuSettings[] = { |
// Create the tab view and its two tabs. |
+ NSRect initialFrame = NSMakeRect(0, 0, kWindowWidth, 44); |
+ segmentedControl_.reset( |
+ [[NSSegmentedControl alloc] initWithFrame:initialFrame]); |
+ [segmentedControl_ setCell:[[CustomTabbedSegmentedCell alloc] init]]; |
+ [segmentedControl_ setSegmentCount:2]; |
+ [segmentedControl_ setTarget:self]; |
+ [segmentedControl_ setAction:@selector(tabSelected:)]; |
+ NSFont* smallSystemFont = |
+ [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; |
+ NSDictionary* textAttributes = |
+ [NSDictionary dictionaryWithObject:smallSystemFont |
+ forKey:NSFontAttributeName]; |
+ |
+ NSString* label = l10n_util::GetNSString( |
+ IDS_WEBSITE_SETTINGS_TAB_LABEL_PERMISSIONS); |
+ NSSize textSize = [label sizeWithAttributes:textAttributes]; |
+ |
+ [segmentedControl_ setLabel:label forSegment:0]; |
+ [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.
|
+ |
+ label = l10n_util::GetNSString(IDS_WEBSITE_SETTINGS_TAB_LABEL_CONNECTION); |
+ textSize = [label sizeWithAttributes:textAttributes]; |
+ [segmentedControl_ setLabel:label forSegment:1]; |
+ [segmentedControl_ setWidth:textSize.width + 2 * 28 forSegment:1]; |
+ |
+ [segmentedControl_ setFont:smallSystemFont]; |
+ [contentView_ addSubview:segmentedControl_]; |
+ |
NSRect tabFrame = NSMakeRect(0, 0, kWindowWidth, 300); |
tabView_.reset([[NSTabView alloc] initWithFrame:tabFrame]); |
- [tabView_ setTabViewType:NSTopTabsBezelBorder]; |
+ [tabView_ setTabViewType:NSNoTabsNoBorder]; |
+ [tabView_ setDrawsBackground:NO]; |
[tabView_ setControlSize:NSSmallControlSize]; |
- [tabView_ setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; |
[contentView_ addSubview:tabView_.get()]; |
permissionsContentView_ = [self addPermissionsTabToTabView:tabView_]; |
@@ -154,8 +253,6 @@ const ContentSetting kPermissionsMenuSettings[] = { |
// Returns a weak reference to the tab view item's view. |
- (NSView*)addPermissionsTabToTabView:(NSTabView*)tabView { |
scoped_nsobject<NSTabViewItem> item([[NSTabViewItem alloc] init]); |
- [item setLabel: |
- l10n_util::GetNSString(IDS_WEBSITE_SETTINGS_TAB_LABEL_PERMISSIONS)]; |
[tabView_ addTabViewItem:item.get()]; |
scoped_nsobject<NSView> contentView([[WebsiteSettingsContentView alloc] |
initWithFrame:[tabView_ contentRect]]); |
@@ -167,9 +264,6 @@ const ContentSetting kPermissionsMenuSettings[] = { |
// Returns a weak reference to the tab view item's view. |
- (NSView*)addConnectionTabToTabView:(NSTabView*)tabView { |
scoped_nsobject<NSTabViewItem> item([[NSTabViewItem alloc] init]); |
- [item setLabel: |
- l10n_util::GetNSString(IDS_WEBSITE_SETTINGS_TAB_LABEL_CONNECTION)]; |
- |
scoped_nsobject<NSView> contentView([[WebsiteSettingsContentView alloc] |
initWithFrame:[tabView_ contentRect]]); |
@@ -267,9 +361,14 @@ const ContentSetting kPermissionsMenuSettings[] = { |
[self setYPositionOfView:firstVisitDescriptionField_ to:yPos]; |
// Adjust the tab view size and place it below the identity status. |
+ |
+ NSRect segmentedControlFrame = [segmentedControl_ frame]; |
+ segmentedControlFrame.origin.y = |
+ NSMaxY([identityStatusField_ frame]); |
+ [segmentedControl_ setFrame:segmentedControlFrame]; |
+ |
NSRect tabViewFrame = [tabView_ frame]; |
- tabViewFrame.origin.y = |
- NSMaxY([identityStatusField_ frame]) + kVerticalSpacing; |
+ tabViewFrame.origin.y = NSMaxY(segmentedControlFrame); |
CGFloat connectionTabHeight = std::max( |
NSMaxY([firstVisitDescriptionField_ frame]), |
@@ -469,6 +568,10 @@ const ContentSetting kPermissionsMenuSettings[] = { |
return button.get(); |
} |
+- (void)tabSelected:(id)sender { |
+ [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.
|
+} |
+ |
// Handler for the permission-changing menus. |
- (void)permissionValueChanged:(id)sender { |
DCHECK([sender isKindOfClass:[NSPopUpButton class]]); |