• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #import <Cocoa/Cocoa.h>
6 
7 // BrowserFrameView is a class whose methods we swizzle into NSGrayFrame
8 // (an AppKit framework class) so that we can support custom frame drawing.
9 // This class is never to be instantiated on its own.
10 // We explored a variety of ways to support custom frame drawing and custom
11 // window widgets.
12 // Our requirements were:
13 // a) that we could fall back on standard system drawing at any time for the
14 //    "default theme"
15 // b) We needed to be able to draw both a background pattern, and an overlay
16 //    graphic, and we need to be able to set the pattern phase of our background
17 //    window.
18 // c) We had to be able to support "transparent" themes, so that you could see
19 //    through to the underlying windows in places without the system theme
20 //    getting in the way.
21 //
22 // Since we want "A" we couldn't just do a transparent borderless window. At
23 // least I couldn't find the right combination of HITheme calls to make it draw
24 // nicely, and I don't trust that the HITheme calls are going to exist in future
25 // system versions.
26 // "C" precluded us from inserting a view between the system frame and the
27 // the content frame in Z order. To get the transparency we actually need to
28 // replace the drawing of the system frame.
29 // "B" precluded us from just setting a background color on the window.
30 //
31 // Originally we tried overriding the private API +frameViewForStyleMask: to
32 // add our own subclass of NSGrayView to our window. Turns out that if you
33 // subclass NSGrayView it does not draw correctly when you call NSGrayView's
34 // drawRect. It appears that NSGrayView's drawRect: method (and that of its
35 // superclasses) do lots of "isMemberOfClass/isKindOfClass" calls, and if your
36 // class is NOT an instance of NSGrayView (as opposed to a subclass of
37 // NSGrayView) then the system drawing will not work correctly.
38 //
39 // Given all of the above, we found swizzling drawRect in _load to be the
40 // easiest and safest method of achieving our goals. We do the best we can to
41 // check that everything is safe, and attempt to fallback gracefully if it is
42 // not.
43 @interface BrowserFrameView : NSView
44 
45 // Draws the window theme into the specified rect. Returns whether a theme was
46 // drawn (whether incognito or full pattern theme; an overlay image doesn't
47 // count).
48 + (BOOL)drawWindowThemeInDirtyRect:(NSRect)dirtyRect
49                            forView:(NSView*)view
50                             bounds:(NSRect)bounds
51                             offset:(NSPoint)offset
52               forceBlackBackground:(BOOL)forceBlackBackground;
53 
54 // Gets the color to draw title text.
55 + (NSColor*)titleColorForThemeView:(NSView*)view;
56 
57 @end
58