Commit 6f7b4e45 authored by erikchen@chromium.org's avatar erikchen@chromium.org

mac: Fix tab dragging visual bug in Yosemite. (reland 2)

-----------------Reland 2 Description------------------
Turned on layers for the test for fullscreen windows.

-----------------Reland 1 Description------------------
Reland 1 link: https://codereview.chromium.org/393933003/
Core animation was turned on in M35. The fullscreen window was not layer
backed, but should have been. This original CL exposed this bug.

-----------------Original Description------------------
Original CL link: https://codereview.chromium.org/379293003/

In OSX 10.10+, all views must be added to the NSWindow's contentView. Some
views (like the tab strip and the profile icon) are placed on top of the title
bar and require special treatment. All other views are added as subviews of
'chromeContentView' in TabWindowController. This allows tab dragging and
fullscreen logic to easily move the views that don't need special treatment.

This CL also removes the instances where a VersionIndependentWindow's
contentView gets replaced by setContentView:. Instead, the 'chromeContentView'
gets passed around as a subview. This allows VersionIndependentWindow to remove
another of its internal hacks.

BUG=392239

Review URL: https://codereview.chromium.org/399803002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283650 0039d316-1c4b-4281-b951-d872f2087c98
parent 6249d66e
...@@ -1557,7 +1557,7 @@ using content::WebContents; ...@@ -1557,7 +1557,7 @@ using content::WebContents;
if (!downloadShelfController_.get()) { if (!downloadShelfController_.get()) {
downloadShelfController_.reset([[DownloadShelfController alloc] downloadShelfController_.reset([[DownloadShelfController alloc]
initWithBrowser:browser_.get() resizeDelegate:self]); initWithBrowser:browser_.get() resizeDelegate:self]);
[[[self window] contentView] addSubview:[downloadShelfController_ view]]; [self.chromeContentView addSubview:[downloadShelfController_ view]];
} }
return downloadShelfController_; return downloadShelfController_;
} }
......
...@@ -566,13 +566,10 @@ willPositionSheet:(NSWindow*)sheet ...@@ -566,13 +566,10 @@ willPositionSheet:(NSWindow*)sheet
[tabStripView removeFromSuperview]; [tabStripView removeFromSuperview];
} }
// Ditto for the content view.
base::scoped_nsobject<NSView> contentView(
[[sourceWindow contentView] retain]);
// Disable autoresizing of subviews while we move views around. This prevents // Disable autoresizing of subviews while we move views around. This prevents
// spurious renderer resizes. // spurious renderer resizes.
[contentView setAutoresizesSubviews:NO]; [self.chromeContentView setAutoresizesSubviews:NO];
[contentView removeFromSuperview]; [self.chromeContentView removeFromSuperview];
// Have to do this here, otherwise later calls can crash because the window // Have to do this here, otherwise later calls can crash because the window
// has no delegate. // has no delegate.
...@@ -584,8 +581,11 @@ willPositionSheet:(NSWindow*)sheet ...@@ -584,8 +581,11 @@ willPositionSheet:(NSWindow*)sheet
// drawOverlayRect:]. I'm pretty convinced this is an Apple bug, but there is // drawOverlayRect:]. I'm pretty convinced this is an Apple bug, but there is
// no visual impact. I have been unable to tickle it away with other window // no visual impact. I have been unable to tickle it away with other window
// or view manipulation Cocoa calls. Stack added to suppressions_mac.txt. // or view manipulation Cocoa calls. Stack added to suppressions_mac.txt.
[contentView setAutoresizesSubviews:YES]; [self.chromeContentView setAutoresizesSubviews:YES];
[destWindow setContentView:contentView]; [[destWindow contentView] addSubview:self.chromeContentView
positioned:NSWindowBelow
relativeTo:nil];
self.chromeContentView.frame = [[destWindow contentView] bounds];
// Move the incognito badge if present. // Move the incognito badge if present.
if ([self shouldShowAvatar]) { if ([self shouldShowAvatar]) {
...@@ -852,7 +852,7 @@ willPositionSheet:(NSWindow*)sheet ...@@ -852,7 +852,7 @@ willPositionSheet:(NSWindow*)sheet
for (NSWindow* window in [[NSApplication sharedApplication] windows]) { for (NSWindow* window in [[NSApplication sharedApplication] windows]) {
if ([window if ([window
isKindOfClass:NSClassFromString(@"NSToolbarFullScreenWindow")]) { isKindOfClass:NSClassFromString(@"NSToolbarFullScreenWindow")]) {
[window.contentView setHidden:YES]; [[window contentView] setHidden:YES];
} }
} }
} }
...@@ -930,7 +930,7 @@ willPositionSheet:(NSWindow*)sheet ...@@ -930,7 +930,7 @@ willPositionSheet:(NSWindow*)sheet
} }
- (void)updateSubviewZOrder:(BOOL)inPresentationMode { - (void)updateSubviewZOrder:(BOOL)inPresentationMode {
NSView* contentView = [[self window] contentView]; NSView* contentView = self.chromeContentView;
NSView* toolbarView = [toolbarController_ view]; NSView* toolbarView = [toolbarController_ view];
if (inPresentationMode) { if (inPresentationMode) {
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/cocoa/cocoa_profile_test.h" #include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
#include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" #include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h"
#import "chrome/browser/ui/cocoa/nsview_additions.h"
#include "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" #include "chrome/browser/ui/cocoa/tabs/tab_strip_view.h"
#import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
#include "chrome/browser/ui/host_desktop.h" #include "chrome/browser/ui/host_desktop.h"
...@@ -615,7 +616,7 @@ TEST_F(BrowserWindowControllerTest, TestFindBarOnTop) { ...@@ -615,7 +616,7 @@ TEST_F(BrowserWindowControllerTest, TestFindBarOnTop) {
[controller_ addFindBar:bridge.find_bar_cocoa_controller()]; [controller_ addFindBar:bridge.find_bar_cocoa_controller()];
// Test that the Z-order of the find bar is on top of everything. // Test that the Z-order of the find bar is on top of everything.
NSArray* subviews = [[[controller_ window] contentView] subviews]; NSArray* subviews = [controller_.chromeContentView subviews];
NSUInteger findBar_index = NSUInteger findBar_index =
[subviews indexOfObject:[controller_ findBarView]]; [subviews indexOfObject:[controller_ findBarView]];
EXPECT_NE(NSNotFound, findBar_index); EXPECT_NE(NSNotFound, findBar_index);
...@@ -881,6 +882,7 @@ TEST_F(BrowserWindowFullScreenControllerTest, TestActivate) { ...@@ -881,6 +882,7 @@ TEST_F(BrowserWindowFullScreenControllerTest, TestActivate) {
styleMask:NSBorderlessWindowMask styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered backing:NSBackingStoreBuffered
defer:NO]); defer:NO]);
[[testFullscreenWindow_ contentView] cr_setWantsLayer:YES];
return testFullscreenWindow_.get(); return testFullscreenWindow_.get();
} }
@end @end
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#import "chrome/browser/ui/cocoa/fullscreen_window.h" #import "chrome/browser/ui/cocoa/fullscreen_window.h"
#import "chrome/browser/ui/cocoa/nsview_additions.h"
#import "chrome/browser/ui/cocoa/themed_window.h" #import "chrome/browser/ui/cocoa/themed_window.h"
@implementation FullscreenWindow @implementation FullscreenWindow
...@@ -27,6 +28,7 @@ ...@@ -27,6 +28,7 @@
// Borderless windows don't usually show up in the Windows menu so whine at // Borderless windows don't usually show up in the Windows menu so whine at
// Cocoa until it complies. See -dealloc and -setTitle: as well. // Cocoa until it complies. See -dealloc and -setTitle: as well.
[NSApp addWindowsItem:self title:@"" filename:NO]; [NSApp addWindowsItem:self title:@"" filename:NO];
[[self contentView] cr_setWantsLayer:YES];
} }
return self; return self;
} }
......
...@@ -23,9 +23,19 @@ ...@@ -23,9 +23,19 @@
@interface TabWindowController : NSWindowController<NSWindowDelegate> { @interface TabWindowController : NSWindowController<NSWindowDelegate> {
@private @private
// Wrapper view around web content, and the developer tools view.
base::scoped_nsobject<FastResizeView> tabContentArea_; base::scoped_nsobject<FastResizeView> tabContentArea_;
// The tab strip overlaps the titlebar of the window.
base::scoped_nsobject<TabStripView> tabStripView_; base::scoped_nsobject<TabStripView> tabStripView_;
// In OSX 10.10+, all views must be added to the NSWindow's contentView. Some
// views (like the tab strip and the profile icon) are placed on top of the
// title bar and require special treatment. All other views should be added
// as subviews of chromeContentView_. This allows tab dragging and fullscreen
// logic to easily move the views that don't need special treatment.
base::scoped_nsobject<NSView> chromeContentView_;
// The child window used during dragging to achieve the opacity tricks. // The child window used during dragging to achieve the opacity tricks.
NSWindow* overlayWindow_; NSWindow* overlayWindow_;
...@@ -38,6 +48,7 @@ ...@@ -38,6 +48,7 @@
} }
@property(readonly, nonatomic) TabStripView* tabStripView; @property(readonly, nonatomic) TabStripView* tabStripView;
@property(readonly, nonatomic) FastResizeView* tabContentArea; @property(readonly, nonatomic) FastResizeView* tabContentArea;
@property(readonly, nonatomic) NSView* chromeContentView;
// This is the designated initializer for this class. // This is the designated initializer for this class.
- (id)initTabWindowControllerWithTabStrip:(BOOL)hasTabStrip; - (id)initTabWindowControllerWithTabStrip:(BOOL)hasTabStrip;
......
...@@ -47,7 +47,10 @@ ...@@ -47,7 +47,10 @@
@implementation TabWindowController @implementation TabWindowController
- (id)initTabWindowControllerWithTabStrip:(BOOL)hasTabStrip { - (id)initTabWindowControllerWithTabStrip:(BOOL)hasTabStrip {
NSRect contentRect = NSMakeRect(60, 229, 750, 600); const CGFloat kDefaultWidth = 750;
const CGFloat kDefaultHeight = 600;
NSRect contentRect = NSMakeRect(60, 229, kDefaultWidth, kDefaultHeight);
base::scoped_nsobject<FramedBrowserWindow> window( base::scoped_nsobject<FramedBrowserWindow> window(
[[FramedBrowserWindow alloc] initWithContentRect:contentRect [[FramedBrowserWindow alloc] initWithContentRect:contentRect
hasTabStrip:hasTabStrip]); hasTabStrip:hasTabStrip]);
...@@ -57,14 +60,20 @@ ...@@ -57,14 +60,20 @@
if ((self = [super initWithWindow:window])) { if ((self = [super initWithWindow:window])) {
[[self window] setDelegate:self]; [[self window] setDelegate:self];
tabContentArea_.reset([[FastResizeView alloc] initWithFrame: chromeContentView_.reset([[NSView alloc]
NSMakeRect(0, 0, 750, 600)]); initWithFrame:NSMakeRect(0, 0, kDefaultWidth, kDefaultHeight)]);
[chromeContentView_
setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[[[self window] contentView] addSubview:chromeContentView_];
tabContentArea_.reset(
[[FastResizeView alloc] initWithFrame:[chromeContentView_ bounds]]);
[tabContentArea_ setAutoresizingMask:NSViewWidthSizable | [tabContentArea_ setAutoresizingMask:NSViewWidthSizable |
NSViewHeightSizable]; NSViewHeightSizable];
[[[self window] contentView] addSubview:tabContentArea_]; [chromeContentView_ addSubview:tabContentArea_];
tabStripView_.reset([[TabStripView alloc] initWithFrame: tabStripView_.reset([[TabStripView alloc]
NSMakeRect(0, 0, 750, 37)]); initWithFrame:NSMakeRect(0, 0, kDefaultWidth, 37)]);
[tabStripView_ setAutoresizingMask:NSViewWidthSizable | [tabStripView_ setAutoresizingMask:NSViewWidthSizable |
NSViewMinYMargin]; NSViewMinYMargin];
if (hasTabStrip) if (hasTabStrip)
...@@ -81,6 +90,10 @@ ...@@ -81,6 +90,10 @@
return tabContentArea_; return tabContentArea_;
} }
- (NSView*)chromeContentView {
return chromeContentView_;
}
// Add the top tab strop to the window, above the content box and add it to the // Add the top tab strop to the window, above the content box and add it to the
// view hierarchy as a sibling of the content view so it can overlap with the // view hierarchy as a sibling of the content view so it can overlap with the
// window frame. // window frame.
...@@ -127,7 +140,7 @@ ...@@ -127,7 +140,7 @@
[overlayWindow_ setOpaque:NO]; [overlayWindow_ setOpaque:NO];
[overlayWindow_ setDelegate:self]; [overlayWindow_ setDelegate:self];
originalContentView_ = [window contentView]; originalContentView_ = self.chromeContentView;
[window addChildWindow:overlayWindow_ ordered:NSWindowAbove]; [window addChildWindow:overlayWindow_ ordered:NSWindowAbove];
// Explicitly set the responder to be nil here (for restoring later). // Explicitly set the responder to be nil here (for restoring later).
...@@ -153,7 +166,10 @@ ...@@ -153,7 +166,10 @@
// places. The TabStripView always needs to be in front of the window's // places. The TabStripView always needs to be in front of the window's
// content view and therefore it should always be added after the content // content view and therefore it should always be added after the content
// view is set. // view is set.
[window setContentView:originalContentView_]; [[window contentView] addSubview:originalContentView_
positioned:NSWindowBelow
relativeTo:nil];
originalContentView_.frame = [[window contentView] bounds];
[[window cr_windowView] addSubview:[self tabStripView]]; [[window cr_windowView] addSubview:[self tabStripView]];
[[window cr_windowView] updateTrackingAreas]; [[window cr_windowView] updateTrackingAreas];
......
...@@ -32,12 +32,6 @@ ...@@ -32,12 +32,6 @@
[super setFrameSize:size]; [super setFrameSize:size];
} }
// The contentView gets moved around during certain full-screen operations.
// This is less than ideal, and should eventually be removed.
- (void)viewDidMoveToSuperview {
[self setFrame:[[self superview] bounds]];
}
@end @end
@implementation NSWindow (VersionIndependentWindow) @implementation NSWindow (VersionIndependentWindow)
...@@ -79,8 +73,8 @@ ...@@ -79,8 +73,8 @@
chromeWindowView_.reset([[FullSizeContentView alloc] init]); chromeWindowView_.reset([[FullSizeContentView alloc] init]);
[chromeWindowView_ [chromeWindowView_
setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[chromeWindowView_ setFrame:[[[self contentView] superview] bounds]];
[self setContentView:chromeWindowView_]; [self setContentView:chromeWindowView_];
[chromeWindowView_ setFrame:[[[self contentView] superview] bounds]];
} }
} }
return self; return self;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment