blob: b4f705439ffd50ac8a779c7019bb7de759d781e0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
// Copyright (c) 2010 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/floating_bar_backing_view.h"
#import "third_party/GTM/AppKit/GTMTheme.h"
@implementation FloatingBarBackingView
- (void)drawRect:(NSRect)rect {
NSWindow* window = [self window];
BOOL isMainWindow = [window isMainWindow];
if (isMainWindow)
[[NSColor windowFrameColor] set];
else
[[NSColor windowBackgroundColor] set];
NSRectFill(rect);
// The code here mirrors the code in browser_frame_view.mm, with modifications
// to not use window rect and not draw rounded corners.
NSRect bounds = [self bounds];
// Draw our background image or theme pattern, if one exists.
GTMTheme* theme = [self gtm_theme];
GTMThemeState state = isMainWindow ? GTMThemeStateActiveWindow
: GTMThemeStateInactiveWindow;
NSColor* color = [theme backgroundPatternColorForStyle:GTMThemeStyleWindow
state:state];
if (color) {
// 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
// patterns, we have to shift the pattern slightly, rather than simply
// drawing it from the top left corner. The offset below was empirically
// determined in order to line these patterns up.
//
// 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 };
NSPoint offsetTopLeft = kBrowserFrameViewPatternPhaseOffset;
offsetTopLeft.y += NSHeight(bounds);
// We want the pattern to start at the upper left corner of the floating
// bar, but the phase needs to be in the coordinate system of
// |windowChromeView|.
NSView* windowChromeView = [[[self window] contentView] superview];
NSPoint phase = [self convertPoint:offsetTopLeft toView:windowChromeView];
// Apply the offset.
[[NSGraphicsContext currentContext] setPatternPhase:phase];
[color set];
NSRectFill(rect);
}
// Check to see if we have an overlay image.
NSImage* overlayImage = [theme valueForAttribute:@"overlay"
style:GTMThemeStyleWindow
state:state];
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(bounds) -
overlaySize.height)
fromRect:imageFrame
operation:NSCompositeSourceOver
fraction:1.0];
}
}
@end // @implementation FloatingBarBackingView
|