OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "chrome/browser/ui/cocoa/browser_frame_view.h" | 5 #import "chrome/browser/ui/cocoa/browser_frame_view.h" |
6 | 6 |
7 #import <objc/runtime.h> | 7 #import <objc/runtime.h> |
8 #import <Carbon/Carbon.h> | 8 #import <Carbon/Carbon.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/mac/mac_util.h" |
11 #include "base/mac/scoped_nsautorelease_pool.h" | 12 #include "base/mac/scoped_nsautorelease_pool.h" |
12 #import "chrome/browser/themes/theme_service.h" | 13 #import "chrome/browser/themes/theme_service.h" |
13 #import "chrome/browser/ui/cocoa/framed_browser_window.h" | 14 #import "chrome/browser/ui/cocoa/framed_browser_window.h" |
14 #import "chrome/browser/ui/cocoa/themed_window.h" | 15 #import "chrome/browser/ui/cocoa/themed_window.h" |
15 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
16 #include "grit/theme_resources_standard.h" | 17 #include "grit/theme_resources_standard.h" |
17 | 18 |
18 static const CGFloat kBrowserFrameViewPaintHeight = 60.0; | 19 static const CGFloat kBrowserFrameViewPaintHeight = 60.0; |
19 static const NSPoint kBrowserFrameViewPatternPhaseOffset = { -5, 3 }; | 20 static const NSPoint kBrowserFrameViewPatternPhaseOffset = { -5, 3 }; |
20 | 21 |
(...skipping 18 matching lines...) Expand all Loading... |
39 | 40 |
40 @implementation BrowserFrameView | 41 @implementation BrowserFrameView |
41 | 42 |
42 + (void)load { | 43 + (void)load { |
43 // This is where we swizzle drawRect, and add in two methods that we | 44 // This is where we swizzle drawRect, and add in two methods that we |
44 // need. If any of these fail it shouldn't affect the functionality of the | 45 // need. If any of these fail it shouldn't affect the functionality of the |
45 // others. If they all fail, we will lose window frame theming and | 46 // others. If they all fail, we will lose window frame theming and |
46 // roll overs for our close widgets, but things should still function | 47 // roll overs for our close widgets, but things should still function |
47 // correctly. | 48 // correctly. |
48 base::mac::ScopedNSAutoreleasePool pool; | 49 base::mac::ScopedNSAutoreleasePool pool; |
49 Class grayFrameClass = NSClassFromString(@"NSGrayFrame"); | 50 |
50 DCHECK(grayFrameClass); | 51 // On 10.8+ the background for textured windows are no longer drawn by |
51 if (!grayFrameClass) return; | 52 // NSGrayFrame, and NSThemeFrame is used instead <http://crbug.com/114745>. |
| 53 Class borderViewClass = NSClassFromString( |
| 54 base::mac::IsOSMountainLionOrLater() ? @"NSThemeFrame" : @"NSGrayFrame"); |
| 55 DCHECK(borderViewClass); |
| 56 if (!borderViewClass) return; |
52 | 57 |
53 // Exchange draw rect. | 58 // Exchange draw rect. |
54 Method m0 = class_getInstanceMethod([self class], @selector(drawRect:)); | 59 Method m0 = class_getInstanceMethod([self class], @selector(drawRect:)); |
55 DCHECK(m0); | 60 DCHECK(m0); |
56 if (m0) { | 61 if (m0) { |
57 BOOL didAdd = class_addMethod(grayFrameClass, | 62 BOOL didAdd = class_addMethod(borderViewClass, |
58 @selector(drawRectOriginal:), | 63 @selector(drawRectOriginal:), |
59 method_getImplementation(m0), | 64 method_getImplementation(m0), |
60 method_getTypeEncoding(m0)); | 65 method_getTypeEncoding(m0)); |
61 DCHECK(didAdd); | 66 DCHECK(didAdd); |
62 if (didAdd) { | 67 if (didAdd) { |
63 Method m1 = class_getInstanceMethod(grayFrameClass, @selector(drawRect:)); | 68 Method m1 = class_getInstanceMethod(borderViewClass, |
64 Method m2 = class_getInstanceMethod(grayFrameClass, | 69 @selector(drawRect:)); |
| 70 Method m2 = class_getInstanceMethod(borderViewClass, |
65 @selector(drawRectOriginal:)); | 71 @selector(drawRectOriginal:)); |
66 DCHECK(m1 && m2); | 72 DCHECK(m1 && m2); |
67 if (m1 && m2) { | 73 if (m1 && m2) { |
68 method_exchangeImplementations(m1, m2); | 74 method_exchangeImplementations(m1, m2); |
69 } | 75 } |
70 } | 76 } |
71 } | 77 } |
72 | 78 |
73 gCanDrawTitle = | 79 gCanDrawTitle = |
74 [grayFrameClass | 80 [borderViewClass |
75 instancesRespondToSelector:@selector(_titlebarTitleRect)] && | 81 instancesRespondToSelector:@selector(_titlebarTitleRect)] && |
76 [grayFrameClass | 82 [borderViewClass |
77 instancesRespondToSelector:@selector(_drawTitleStringIn:withColor:)]; | 83 instancesRespondToSelector:@selector(_drawTitleStringIn:withColor:)]; |
78 gCanGetCornerRadius = | 84 gCanGetCornerRadius = |
79 [grayFrameClass | 85 [borderViewClass |
80 instancesRespondToSelector:@selector(roundedCornerRadius)]; | 86 instancesRespondToSelector:@selector(roundedCornerRadius)]; |
81 | 87 |
82 // Add _shadowFlags. This is a method on NSThemeFrame, not on NSGrayFrame. | 88 // Add _shadowFlags. This is a method on NSThemeFrame, not on NSGrayFrame. |
83 // NSThemeFrame is NSGrayFrame's superclass. | 89 // NSThemeFrame is NSGrayFrame's superclass. |
84 Class themeFrameClass = NSClassFromString(@"NSThemeFrame"); | 90 Class themeFrameClass = NSClassFromString(@"NSThemeFrame"); |
85 DCHECK(themeFrameClass); | 91 DCHECK(themeFrameClass); |
86 if (!themeFrameClass) return; | 92 if (!themeFrameClass) return; |
87 m0 = class_getInstanceMethod([self class], @selector(_shadowFlags)); | 93 m0 = class_getInstanceMethod([self class], @selector(_shadowFlags)); |
88 DCHECK(m0); | 94 DCHECK(m0); |
89 if (m0) { | 95 if (m0) { |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 | 352 |
347 // If this isn't the window class we expect, then pass it on to the | 353 // If this isn't the window class we expect, then pass it on to the |
348 // original implementation. | 354 // original implementation. |
349 if (![[self window] isKindOfClass:[FramedBrowserWindow class]]) | 355 if (![[self window] isKindOfClass:[FramedBrowserWindow class]]) |
350 return [self _shadowFlagsOriginal]; | 356 return [self _shadowFlagsOriginal]; |
351 | 357 |
352 return [self _shadowFlagsOriginal] | 128; | 358 return [self _shadowFlagsOriginal] | 128; |
353 } | 359 } |
354 | 360 |
355 @end | 361 @end |
OLD | NEW |