| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef CHROME_BROWSER_UI_COCOA_VERSION_INDEPENDENT_WINDOW_H_ | 5 #ifndef CHROME_BROWSER_UI_COCOA_VERSION_INDEPENDENT_WINDOW_H_ |
| 6 #define CHROME_BROWSER_UI_COCOA_VERSION_INDEPENDENT_WINDOW_H_ | 6 #define CHROME_BROWSER_UI_COCOA_VERSION_INDEPENDENT_WINDOW_H_ |
| 7 | 7 |
| 8 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" | 8 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" |
| 9 | 9 |
| 10 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
| 11 | 11 |
| 12 @interface NSWindow (VersionIndependentWindow) | 12 @interface NSWindow (VersionIndependentWindow) |
| 13 | 13 |
| 14 // Returns the NSView closest to the root of the NSView hierarchy that is | 14 // Returns the NSView closest to the root of the NSView hierarchy that is |
| 15 // eligible for adding subviews. | 15 // eligible for adding subviews. |
| 16 // The frame of the view in screen coordinates is coincident with the window's | 16 // The frame of the view in screen coordinates is coincident with the window's |
| 17 // frame in screen coordinates. | 17 // frame in screen coordinates. |
| 18 - (NSView*)cr_windowView; | 18 - (NSView*)cr_windowView; |
| 19 | 19 |
| 20 @end | 20 @end |
| 21 | 21 |
| 22 // In OSX 10.10, adding subviews to the root view for the NSView hierarchy | 22 // By default, the contentView does not occupy the full size of a framed |
| 23 // produces warnings. To eliminate the warnings, we resize the contentView to | 23 // window. Chrome still wants to draw in the title bar. Historically, Chrome |
| 24 // fill the window, and add subviews to that. When this class is used on OSX | 24 // has done this by adding subviews directly to the root view. This causes |
| 25 // 10.9 and lower, subviews are added directly to the root view, and the | 25 // several problems. The most egregious is related to layer ordering when the |
| 26 // contentView is not resized. | 26 // root view does not have a layer. By giving the contentView the same size as |
| 27 // http://crbug.com/380412 | 27 // the window, there is no longer any need to add subviews to the root view. |
| 28 // | 28 // |
| 29 // For code to be 10.9 and 10.10 compatible, views should be added to [window | 29 // No views should be manually added to [[window contentView] superview]. |
| 30 // cr_windowView] instead of [[window contentView] superview]. | 30 // Instead, they should be added to [window cr_windowView]. |
| 31 // | 31 // |
| 32 // If the window does not have a titlebar, then its contentView already has the | 32 // If the window does not have a titlebar, then its contentView already has the |
| 33 // same size as the window. In this case, this class has no effect. | 33 // same size as the window. In this case, this class has no effect. |
| 34 // | 34 // |
| 35 // This class currently does not support changing the window's style after the | 35 // This class currently does not support changing the window's style after the |
| 36 // window has been initialized. | 36 // window has been initialized. |
| 37 // | |
| 38 // Since the contentView's size varies between OSes, several NSWindow methods | |
| 39 // are no longer well defined. | |
| 40 // - setContentSize: | |
| 41 // - setContentMinSize: | |
| 42 // - setContentMaxSize: | |
| 43 // - setContentAspectRatio: | |
| 44 // The implementation of this class on OSX 10.10 uses a hacked subclass of | |
| 45 // NSView. It currently does not support the above 4 methods. | |
| 46 @interface VersionIndependentWindow : ChromeEventProcessingWindow { | 37 @interface VersionIndependentWindow : ChromeEventProcessingWindow { |
| 47 @private | 38 @private |
| 48 // Holds the view that replaces [window contentView]. This view's size is the | 39 // Holds the view that replaces [window contentView]. This view has the same |
| 49 // same as the window's size. | 40 // size as the window. Empty if there is no titlebar. |
| 50 // Empty on 10.9 and lower, or if there is no titlebar. | |
| 51 base::scoped_nsobject<NSView> chromeWindowView_; | 41 base::scoped_nsobject<NSView> chromeWindowView_; |
| 52 } | 42 } |
| 53 | 43 |
| 54 // Designated initializer. | 44 // Designated initializer. |
| 55 - (instancetype)initWithContentRect:(NSRect)contentRect | 45 - (instancetype)initWithContentRect:(NSRect)contentRect |
| 56 styleMask:(NSUInteger)windowStyle | 46 styleMask:(NSUInteger)windowStyle |
| 57 backing:(NSBackingStoreType)bufferingType | 47 backing:(NSBackingStoreType)bufferingType |
| 58 defer:(BOOL)deferCreation; | 48 defer:(BOOL)deferCreation |
| 49 wantsViewsOverTitlebar:(BOOL)wantsViewsOverTitlebar; |
| 59 | 50 |
| 60 @end | 51 @end |
| 61 | 52 |
| 62 #endif // CHROME_BROWSER_UI_COCOA_VERSION_INDEPENDENT_WINDOW_H_ | 53 #endif // CHROME_BROWSER_UI_COCOA_VERSION_INDEPENDENT_WINDOW_H_ |
| OLD | NEW |