summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/browser_frame_view.mm
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/cocoa/browser_frame_view.mm')
-rw-r--r--chrome/browser/cocoa/browser_frame_view.mm92
1 files changed, 69 insertions, 23 deletions
diff --git a/chrome/browser/cocoa/browser_frame_view.mm b/chrome/browser/cocoa/browser_frame_view.mm
index c4bcf53..bf999c6 100644
--- a/chrome/browser/cocoa/browser_frame_view.mm
+++ b/chrome/browser/cocoa/browser_frame_view.mm
@@ -9,8 +9,10 @@
#include "base/logging.h"
#include "base/scoped_nsautorelease_pool.h"
+#import "chrome/browser/browser_theme_provider.h"
#import "chrome/browser/cocoa/chrome_browser_window.h"
-#import "chrome/browser/cocoa/GTMTheme.h"
+#import "chrome/browser/cocoa/themed_window.h"
+#include "grit/theme_resources.h"
@interface NSView (Swizzles)
- (void)drawRectOriginal:(NSRect)rect;
@@ -87,14 +89,14 @@
// Here is our custom drawing for our frame.
- (void)drawRect:(NSRect)rect {
+ [self drawRectOriginal:rect];
// If this isn't the window class we expect, then pass it on to the
// original implementation.
- [self drawRectOriginal:rect];
if (![[self window] isKindOfClass:[ChromeBrowserWindow class]]) {
return;
}
- // Set up our clip
+ // Set up our clip.
NSWindow* window = [self window];
NSRect windowRect = [window frame];
windowRect.origin = NSMakePoint(0, 0);
@@ -103,15 +105,45 @@
yRadius:4] addClip];
[[NSBezierPath bezierPathWithRect:rect] addClip];
- // Draw our background color if we have one, otherwise fall back on
- // system drawing.
- GTMTheme* theme = [self gtm_theme];
- GTMThemeState state = [window isMainWindow] ? GTMThemeStateActiveWindow
- : GTMThemeStateInactiveWindow;
- NSColor* color = [theme backgroundPatternColorForStyle:GTMThemeStyleWindow
- state:state];
- if (color) {
- // If there is a theme pattern, draw it here.
+ // Do the theming.
+ [BrowserFrameView drawWindowThemeInDirtyRect:rect
+ forView:self
+ bounds:windowRect];
+}
+
++ (void)drawWindowThemeInDirtyRect:(NSRect)dirtyRect
+ forView:(NSView*)view
+ bounds:(NSRect)bounds {
+ ThemeProvider* themeProvider = [[view window] themeProvider];
+ if (!themeProvider)
+ return;
+
+ BOOL active = [[view window] isMainWindow];
+ BOOL incognito = [[view window] themeIsIncognito];
+
+ // Find a theme image.
+ NSImage* themeImage = nil;
+ int themeImageID;
+ if (active && incognito)
+ themeImageID = IDR_THEME_FRAME_INCOGNITO;
+ else if (active && !incognito)
+ themeImageID = IDR_THEME_FRAME;
+ else if (!active && incognito)
+ themeImageID = IDR_THEME_FRAME_INCOGNITO_INACTIVE;
+ else
+ themeImageID = IDR_THEME_FRAME_INACTIVE;
+ if (themeProvider->HasCustomImage(IDR_THEME_FRAME))
+ themeImage = themeProvider->GetNSImageNamed(themeImageID, true);
+
+ // If no theme image, use a gradient if incognito.
+ NSGradient* gradient = nil;
+ if (!themeImage && incognito)
+ gradient = themeProvider->GetNSGradient(
+ active ? BrowserThemeProvider::GRADIENT_FRAME_INCOGNITO :
+ BrowserThemeProvider::GRADIENT_FRAME_INCOGNITO_INACTIVE);
+
+ if (themeImage) {
+ NSColor* themeImageColor = [NSColor colorWithPatternImage:themeImage];
// The titlebar/tabstrip header on the mac is slightly smaller than on
// Windows. To keep the window background lined up with the tab and toolbar
@@ -122,27 +154,41 @@
// This will make the themes look slightly different than in Windows/Linux
// because of the differing heights between window top and tab top, but this
// has been approved by UI.
- static const NSPoint kBrowserFrameViewPatternPhaseOffset = { -5, 2 };
+ static const NSPoint kBrowserFrameViewPatternPhaseOffset = { -5, 3 };
NSPoint phase = kBrowserFrameViewPatternPhaseOffset;
- phase.y += NSHeight(windowRect);
+ phase.y += NSHeight(bounds);
+
+ phase = [view convertPoint:phase toView:nil];
+
[[NSGraphicsContext currentContext] setPatternPhase:phase];
- [color set];
- NSRectFill(rect);
+ [themeImageColor set];
+ NSRectFill(dirtyRect);
+ } else if (gradient) {
+ // Only paint the gradient at the top of the window. (This is at the maximum
+ // when fullscreening; before adjusting check this case.)
+ static const CGFloat kBrowserFrameViewGradientHeight = 52.0;
+ NSRect gradientRect = bounds;
+ gradientRect.origin.y = NSMaxY(gradientRect) -
+ kBrowserFrameViewGradientHeight;
+ gradientRect.size.height = kBrowserFrameViewGradientHeight;
+
+ [gradient drawInRect:gradientRect angle:270];
}
// Check to see if we have an overlay image.
- NSImage* overlayImage = [theme valueForAttribute:@"overlay"
- style:GTMThemeStyleWindow
- state:state];
+ NSImage* overlayImage =
+ themeProvider->GetNSImageNamed(active ? IDR_THEME_FRAME_OVERLAY :
+ IDR_THEME_FRAME_OVERLAY_INACTIVE,
+ false);
if (overlayImage) {
// Anchor to top-left and don't scale.
NSSize overlaySize = [overlayImage size];
NSRect imageFrame = NSMakeRect(0, 0, overlaySize.width, overlaySize.height);
- [overlayImage drawAtPoint:NSMakePoint(0, NSHeight(windowRect) -
- overlaySize.height)
+ [overlayImage drawAtPoint:NSMakePoint(0, NSHeight(bounds) -
+ overlaySize.height)
fromRect:imageFrame
- operation:NSCompositeSourceOver
- fraction:1.0];
+ operation:NSCompositeSourceOver
+ fraction:1.0];
}
}