diff options
Diffstat (limited to 'chrome/browser/cocoa')
-rw-r--r-- | chrome/browser/cocoa/tab_bar_view.h | 16 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_bar_view.mm | 36 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_cell.h | 17 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_cell.mm | 134 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_contents_controller.h | 31 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_contents_controller.mm | 28 | ||||
-rw-r--r-- | chrome/browser/cocoa/toolbar_button_cell.h | 17 | ||||
-rw-r--r-- | chrome/browser/cocoa/toolbar_button_cell.mm | 82 | ||||
-rw-r--r-- | chrome/browser/cocoa/toolbar_view.h | 17 | ||||
-rw-r--r-- | chrome/browser/cocoa/toolbar_view.mm | 27 |
10 files changed, 405 insertions, 0 deletions
diff --git a/chrome/browser/cocoa/tab_bar_view.h b/chrome/browser/cocoa/tab_bar_view.h new file mode 100644 index 0000000..eb15708 --- /dev/null +++ b/chrome/browser/cocoa/tab_bar_view.h @@ -0,0 +1,16 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_COCOA_TAB_BAR_VIEW_H_ +#define CHROME_BROWSER_COCOA_TAB_BAR_VIEW_H_ + +#import <Cocoa/Cocoa.h> + +// A view class that handles rendering the tab bar + +@interface TabBarView : NSView { +} +@end + +#endif // CHROME_BROWSER_COCOA_TAB_BAR_VIEW_H_ diff --git a/chrome/browser/cocoa/tab_bar_view.mm b/chrome/browser/cocoa/tab_bar_view.mm new file mode 100644 index 0000000..31deaba --- /dev/null +++ b/chrome/browser/cocoa/tab_bar_view.mm @@ -0,0 +1,36 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/cocoa/tab_bar_view.h" + +@implementation TabBarView + +- (id)initWithFrame:(NSRect)frame { + self = [super initWithFrame:frame]; + if (self) { + // Nothing yet to do here... + } + return self; +} + +- (void)drawRect:(NSRect)rect { + rect = [self bounds]; + BOOL isKey = [[self window] isKeyWindow]; + if (isKey) { + NSGradient *gradient = + [[[NSGradient alloc] initWithStartingColor: + [NSColor colorWithCalibratedWhite:0.0 alpha:0.0] + endingColor: + [NSColor colorWithCalibratedWhite:0.0 alpha:0.05]] autorelease]; + [gradient drawInRect:[self bounds] angle:270.0]; + } + + NSRect borderRect, contentRect; + NSDivideRect(rect, &borderRect, &contentRect, 1, NSMinYEdge); + [[NSColor colorWithCalibratedWhite:0.0 alpha:0.2] set]; + + NSRectFillUsingOperation(borderRect, NSCompositeSourceOver); +} + +@end diff --git a/chrome/browser/cocoa/tab_cell.h b/chrome/browser/cocoa/tab_cell.h new file mode 100644 index 0000000..a3ad120 --- /dev/null +++ b/chrome/browser/cocoa/tab_cell.h @@ -0,0 +1,17 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_COCOA_TAB_CELL_H_ +#define CHROME_BROWSER_COCOA_TAB_CELL_H_ + +#import <Cocoa/Cocoa.h> + +// A button cell that handles drawing/highlighting of tabs in the +// tab bar. + +@interface TabCell : NSButtonCell { +} +@end + +#endif // CHROME_BROWSER_COCOA_TAB_CELL_H_ diff --git a/chrome/browser/cocoa/tab_cell.mm b/chrome/browser/cocoa/tab_cell.mm new file mode 100644 index 0000000..a8e9276 --- /dev/null +++ b/chrome/browser/cocoa/tab_cell.mm @@ -0,0 +1,134 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/cocoa/tab_cell.h" + +#define INSET_MULTIPLIER 2.0/3.0 +#define CP1_MULTIPLIER 1.0/3.0 +#define CP2_MULTIPLIER 3.0/8.0 + +@implementation TabCell + +// Override drawing the button so that it looks like a Chromium tab instead +// of just a normal MacOS button. +// TODO(pinkerton/alcor): Clearly this is a work in progress. Comments need +// to be added to the flow once we get a better idea of exactly what we +// want and the kinks worked out of the visual appearance/tracking. +// TODO(pinkerton/alcor): Document what most of these constants are. +- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { + [[NSGraphicsContext currentContext] saveGraphicsState]; + + // create a rounded rect path with which we'll stroke the outine of the + // tab. + NSRect rect = cellFrame; + // rect.origin.y += 20; + NSBezierPath *path = + [NSBezierPath bezierPathWithRoundedRect:NSInsetRect(rect, 0.5, 0.5) + xRadius:10.0 + yRadius:10.0]; + + [[NSColor lightGrayColor] setStroke]; + BOOL isKey = [[controlView window] isKeyWindow]; + if (1) { //[self state] || [self isHighlighted]) { + [[NSColor colorWithCalibratedHue:218.0 / 360.0 + saturation:0.05 + brightness:1.0 + alpha:1.0] setFill]; + // [[NSColor colorWithCalibratedHue:210.0/360.0 saturation:0.36 + // brightness:0.73 alpha:1.0] setStroke]; + path = [NSBezierPath bezierPath]; + rect = NSInsetRect(rect, 0.5, 0.5); + float radius = 4.0; + if (radius > 0.0) { + // Clamp radius to be no larger than half the rect's width or height. + radius = MIN(radius, 0.5 * MIN(rect.size.width, rect.size.height)); + + NSPoint bottomLeft = NSMakePoint(NSMinX(rect), NSMaxY(rect)); + NSPoint bottomRight = NSMakePoint(NSMaxX(rect), NSMaxY(rect)); + NSPoint topRight = + NSMakePoint(NSMaxX(rect) - INSET_MULTIPLIER * NSHeight(rect), + NSMinY(rect)); + NSPoint topLeft = + NSMakePoint(NSMinX(rect) + INSET_MULTIPLIER * NSHeight(rect), + NSMinY(rect)); + + float baseControlPointOutset = NSHeight(rect) * CP1_MULTIPLIER; + float bottomControlPointInset = NSHeight(rect) * CP2_MULTIPLIER; + + [path moveToPoint:NSMakePoint(bottomLeft.x - 2, bottomLeft.y + 2)]; + [path lineToPoint:NSMakePoint(bottomLeft.x - 2, bottomLeft.y)]; + [path lineToPoint:bottomLeft]; + + [path curveToPoint:topLeft + controlPoint1:NSMakePoint(bottomLeft.x + baseControlPointOutset, + bottomLeft.y) + controlPoint2:NSMakePoint(topLeft.x - bottomControlPointInset, + topLeft.y)]; + + [path lineToPoint:topRight]; + + [path curveToPoint:bottomRight + controlPoint1:NSMakePoint(topRight.x + bottomControlPointInset, + topRight.y) + controlPoint2:NSMakePoint(bottomRight.x - baseControlPointOutset, + bottomRight.y)]; + + [path lineToPoint:NSMakePoint(bottomRight.x + 1, bottomRight.y)]; + [path lineToPoint:NSMakePoint(bottomRight.x + 1, bottomRight.y + 1)]; + } + BOOL selected = [(NSButton *)controlView state]; + + NSGradient *gradient = nil; + + if (!selected) + [[NSBezierPath bezierPathWithRect:NSOffsetRect(cellFrame, 0, -1)] + addClip]; + if (selected) { + NSColor* startingColor = [NSColor colorWithCalibratedWhite:1.0 alpha:1.0]; + NSColor* endingColor = + [NSColor colorWithCalibratedWhite:isKey ? 0.95 : 0.98 alpha:1.0]; + gradient = + [[[NSGradient alloc] + initWithStartingColor:startingColor endingColor:endingColor] + autorelease]; + [[NSColor colorWithCalibratedWhite:0.0 alpha:isKey ? 0.5 : 0.3] set]; + } else { + NSColor* startingColor = [NSColor colorWithCalibratedWhite:1.0 alpha:0.5]; + NSColor* endingColor = [NSColor colorWithCalibratedWhite:0.95 alpha:0.5]; + gradient = + [[[NSGradient alloc] + initWithStartingColor:startingColor endingColor:endingColor] + autorelease]; + [[NSColor colorWithCalibratedWhite:0.0 alpha:isKey ? 0.3 : 0.1] set]; + } + + if (isKey || selected) + [gradient drawInBezierPath:path angle:90.0]; + + [path stroke]; + } + + [[NSGraphicsContext currentContext] restoreGraphicsState]; + [self drawInteriorWithFrame:NSInsetRect(cellFrame, 12.0, 0) + inView:controlView]; +} + +- (void)drawImage:(NSImage*)image withFrame:(NSRect)frame + inView:(NSView*)controlView { + NSSize size = [image size]; + [image setFlipped: YES]; + + float opacity = [self isEnabled] ? 1.0 : 0.25; + + [image drawInRect:NSMakeRect(frame.origin.x, frame.origin.y, 16.0, 16.0) + fromRect:NSMakeRect(0, 0, size.width, size.height) + operation:NSCompositeSourceOver fraction:opacity]; +} + +- (void)highlight:(BOOL)flag withFrame:(NSRect)cellFrame + inView:(NSView *)controlView { + // Don't do normal highlighting +} + +@end diff --git a/chrome/browser/cocoa/tab_contents_controller.h b/chrome/browser/cocoa/tab_contents_controller.h new file mode 100644 index 0000000..903b020 --- /dev/null +++ b/chrome/browser/cocoa/tab_contents_controller.h @@ -0,0 +1,31 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_COCOA_TAB_COTNENTS_CONTROLLER_H_ +#define CHROME_BROWSER_COCOA_TAB_COTNENTS_CONTROLLER_H_ + +#include <Cocoa/Cocoa.h> + +// A class that controls the contents of a tab, including the toolbar and +// web area. + +// TODO(pinkerton): Cole and I went back and forth about whether or not each +// tab should have its own copy of the toolbar. Right now, we decided to leave +// it like this as he expects it will make it easier for him to implement +// tab dragging and tear-off into new windows. It's also not very expensive. +// As we hook things up, we'll see if this imposes other restrictions (such +// as command-handling or dispatch) that will require us to change the view +// layout. + +@interface TabContentsController : NSViewController { + @private + IBOutlet NSTextField* locationBar_; +} + +// take this view (toolbar and web contents) full screen +- (IBAction)fullScreen:(id)sender; + +@end + +#endif // CHROME_BROWSER_COCOA_TAB_COTNENTS_CONTROLLER_H_ diff --git a/chrome/browser/cocoa/tab_contents_controller.mm b/chrome/browser/cocoa/tab_contents_controller.mm new file mode 100644 index 0000000..b19dcb1 --- /dev/null +++ b/chrome/browser/cocoa/tab_contents_controller.mm @@ -0,0 +1,28 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/cocoa/tab_contents_controller.h" + +@implementation TabContentsController + +- (id)initWithNibName:(NSString*)name bundle:(NSBundle*)bundle { + if ((self = [super initWithNibName:name bundle:bundle])) { + // nothing to do + } + return self; +} + +- (void)awakeFromNib { + [locationBar_ setStringValue:@"http://dev.chromium.org"]; +} + +- (IBAction)fullScreen:(id)sender { + if ([[self view] isInFullScreenMode]) { + [[self view] exitFullScreenModeWithOptions:nil]; + } else { + [[self view] enterFullScreenMode:[NSScreen mainScreen] withOptions:nil]; + } +} + +@end diff --git a/chrome/browser/cocoa/toolbar_button_cell.h b/chrome/browser/cocoa/toolbar_button_cell.h new file mode 100644 index 0000000..cb7c6f4 --- /dev/null +++ b/chrome/browser/cocoa/toolbar_button_cell.h @@ -0,0 +1,17 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_COCOA_TOOLBAR_BUTTON_CELL_H_ +#define CHROME_BROWSER_COCOA_TOOLBAR_BUTTON_CELL_H_ + +#import <Cocoa/Cocoa.h> + +// A button cell that handles drawing/highlighting of buttons in the +// toolbar bar. + +@interface ToolbarButtonCell : NSButtonCell { +} +@end + +#endif // CHROME_BROWSER_COCOA_TOOLBAR_BUTTON_CELL_H_ diff --git a/chrome/browser/cocoa/toolbar_button_cell.mm b/chrome/browser/cocoa/toolbar_button_cell.mm new file mode 100644 index 0000000..d8b0baf --- /dev/null +++ b/chrome/browser/cocoa/toolbar_button_cell.mm @@ -0,0 +1,82 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/cocoa/toolbar_button_cell.h" + +enum { + kLeftButtonType = -1, + kLeftButtonWithShadowType = -2, + kStandardButtonType = 0, + kRightButtonType = 1, +}; +typedef NSInteger ButtonType; + +@implementation ToolbarButtonCell + +- (NSBackgroundStyle)interiorBackgroundStyle { + return [self isHighlighted] ? + NSBackgroundStyleLowered : NSBackgroundStyleRaised; +} + +- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView{ + NSRect drawFrame = NSInsetRect(cellFrame, 1.5, 1.5); + ButtonType type = [controlView tag]; + switch (type) { + case kRightButtonType: + drawFrame.origin.x -= 20; + case kLeftButtonType: + case kLeftButtonWithShadowType: + drawFrame.size.width += 20; + default: + break; + } + + float radius = 3.5; + BOOL highlighted = [self isHighlighted]; + + NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:drawFrame + xRadius:radius + yRadius:radius]; + NSBezierPath *outerPath = + [NSBezierPath bezierPathWithRoundedRect:NSInsetRect(drawFrame, -1, -1) + xRadius:radius + 1 + yRadius:radius + 1]; + NSGradient *gradient = nil; + + if (highlighted) { + NSColor* start = [NSColor colorWithCalibratedHue:0.6 + saturation:1.0 + brightness:0.6 + alpha:1.0]; + NSColor* end = [NSColor colorWithCalibratedHue:0.6 + saturation:1.0 + brightness:0.8 + alpha:1.0]; + gradient = [[[NSGradient alloc] initWithStartingColor:start + endingColor:end] autorelease]; + } else { + NSColor* start = [NSColor colorWithCalibratedWhite:1.0 alpha:1.0]; + NSColor* end = [NSColor colorWithCalibratedWhite:0.90 alpha:1.0]; + gradient = [[[NSGradient alloc] initWithStartingColor:start + endingColor:end] autorelease]; + } + + [[NSColor colorWithCalibratedWhite:1.0 alpha:0.25] set]; + [outerPath stroke]; + [gradient drawInBezierPath:path angle:90.0]; + [[NSColor colorWithCalibratedWhite:0.0 alpha:0.15] set]; + [path stroke]; + + if (type == kLeftButtonWithShadowType) { + NSRect borderRect, contentRect; + NSDivideRect(cellFrame, &borderRect, &contentRect, 1.0, NSMaxXEdge); + [[NSColor colorWithCalibratedWhite:0.0 alpha:0.15] set]; + NSRectFillUsingOperation(NSInsetRect(borderRect, 0, 2), + NSCompositeSourceOver); + } + + [self drawInteriorWithFrame:NSOffsetRect(cellFrame, 0, 1) inView:controlView]; +} + +@end diff --git a/chrome/browser/cocoa/toolbar_view.h b/chrome/browser/cocoa/toolbar_view.h new file mode 100644 index 0000000..761b3db --- /dev/null +++ b/chrome/browser/cocoa/toolbar_view.h @@ -0,0 +1,17 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_COCOA_TOOLBAR_VIEW_H_ +#define CHROME_BROWSER_COCOA_TOOLBAR_VIEW_H_ + +#import <Cocoa/Cocoa.h> + +// A view that handles any special rendering the toolbar, mostly just painting +// a gradient. + +@interface ToolbarView : NSView { +} +@end + +#endif // CHROME_BROWSER_COCOA_TOOLBAR_VIEW_H_ diff --git a/chrome/browser/cocoa/toolbar_view.mm b/chrome/browser/cocoa/toolbar_view.mm new file mode 100644 index 0000000..87d16e3 --- /dev/null +++ b/chrome/browser/cocoa/toolbar_view.mm @@ -0,0 +1,27 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/cocoa/toolbar_view.h" + +@implementation ToolbarView + +- (void)drawRect:(NSRect)rect { + BOOL isKey = [[self window] isKeyWindow]; + rect = [self bounds]; + + NSColor* start = + [NSColor colorWithCalibratedWhite: isKey ? 0.95 : 0.98 alpha:1.0]; + NSColor* end = [NSColor colorWithCalibratedWhite:0.90 alpha:1.0]; + NSGradient *gradient = + [[[NSGradient alloc] initWithStartingColor:start endingColor:end] + autorelease]; + [gradient drawInRect:[self bounds] angle:270.0]; + NSRect borderRect, contentRect; + NSDivideRect(rect, &borderRect, &contentRect, 1, NSMinYEdge); + + [[NSColor colorWithDeviceWhite:0.0 alpha:0.3] set]; + NSRectFillUsingOperation(borderRect, NSCompositeSourceOver); +} + +@end |