Commit 5b0bdfc4 authored by ccameron@chromium.org's avatar ccameron@chromium.org

Remove --disable-core-animation flag

This doesn't do anything effective anymore.

BUG=245900

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

Cr-Commit-Position: refs/heads/master@{#289998}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289998 0039d316-1c4b-4281-b951-d872f2087c98
parent 259eb8bd
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#import "chrome/browser/ui/cocoa/custom_frame_view.h" #import "chrome/browser/ui/cocoa/custom_frame_view.h"
#include "chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa.h" #include "chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa.h"
#include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h"
#import "chrome/browser/ui/cocoa/nsview_additions.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "content/public/browser/native_web_keyboard_event.h" #include "content/public/browser/native_web_keyboard_event.h"
#include "content/public/browser/render_widget_host_view.h" #include "content/public/browser/render_widget_host_view.h"
...@@ -366,7 +365,7 @@ NativeAppWindowCocoa::NativeAppWindowCocoa( ...@@ -366,7 +365,7 @@ NativeAppWindowCocoa::NativeAppWindowCocoa(
if (extension) if (extension)
name = extension->name(); name = extension->name();
[window setTitle:base::SysUTF8ToNSString(name)]; [window setTitle:base::SysUTF8ToNSString(name)];
[[window contentView] cr_setWantsLayer:YES]; [[window contentView] setWantsLayer:YES];
if (has_frame_ && has_frame_color_) { if (has_frame_ && has_frame_color_) {
[base::mac::ObjCCastStrict<ShellCustomFrameNSWindow>(window) [base::mac::ObjCCastStrict<ShellCustomFrameNSWindow>(window)
setColor:gfx::SkColorToSRGBNSColor(active_frame_color_) setColor:gfx::SkColorToSRGBNSColor(active_frame_color_)
......
...@@ -253,7 +253,7 @@ using content::WebContents; ...@@ -253,7 +253,7 @@ using content::WebContents;
// Make the content view for the window have a layer. This will make all // Make the content view for the window have a layer. This will make all
// sub-views have layers. This is necessary to ensure correct layer // sub-views have layers. This is necessary to ensure correct layer
// ordering of all child views and their layers. // ordering of all child views and their layers.
[[window contentView] cr_setWantsLayer:YES]; [[window contentView] setWantsLayer:YES];
windowShim_.reset(new BrowserWindowCocoa(browser, self)); windowShim_.reset(new BrowserWindowCocoa(browser, self));
// Set different minimum sizes on tabbed windows vs non-tabbed, e.g. popups. // Set different minimum sizes on tabbed windows vs non-tabbed, e.g. popups.
...@@ -1014,10 +1014,6 @@ using content::WebContents; ...@@ -1014,10 +1014,6 @@ using content::WebContents;
} }
} }
- (void)setAnimationInProgress:(BOOL)inProgress {
[[self tabContentArea] setFastResizeMode:inProgress];
}
// Update a toggle state for an NSMenuItem if modified. // Update a toggle state for an NSMenuItem if modified.
// Take care to ensure |item| looks like a NSMenuItem. // Take care to ensure |item| looks like a NSMenuItem.
// Called by validateUserInterfaceItem:. // Called by validateUserInterfaceItem:.
......
...@@ -9,16 +9,11 @@ ...@@ -9,16 +9,11 @@
@class CAShapeLayer; @class CAShapeLayer;
// A Cocoa view that supports an alternate resizing mode, normally used when // A Cocoa view originally created to support fast re-painting to white on
// animations are in progress. In normal resizing mode, subviews are sized to // resize. This is done by CoreAnimation now, so this view remains only as the
// completely fill this view's bounds. In fast resizing mode, the subviews' // first opaque ancestor of accelerated web contents views.
// size is not changed and the subview is clipped to fit, if necessary. Fast
// resize mode is useful when animating a view that normally takes a significant
// amount of time to relayout and redraw when its size is changed.
@interface FastResizeView : NSView { @interface FastResizeView : NSView {
@private @private
BOOL fastResizeMode_;
// Whether the bottom corners should be rounded. // Whether the bottom corners should be rounded.
BOOL roundedBottomCorners_; BOOL roundedBottomCorners_;
...@@ -26,12 +21,6 @@ ...@@ -26,12 +21,6 @@
CAShapeLayer* layerMask_; CAShapeLayer* layerMask_;
} }
// Turns fast resizing mode on or off, which determines how this view resizes
// its subviews. Turning fast resizing mode off has the effect of immediately
// resizing subviews to fit; callers do not need to explictly call |setFrame:|
// to trigger a resize.
- (void)setFastResizeMode:(BOOL)fastResizeMode;
// Changes whether the bottom two corners are rounded. // Changes whether the bottom two corners are rounded.
- (void)setRoundedBottomCorners:(BOOL)roundedBottomCorners; - (void)setRoundedBottomCorners:(BOOL)roundedBottomCorners;
......
...@@ -7,10 +7,8 @@ ...@@ -7,10 +7,8 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#include "base/logging.h" #include "base/logging.h"
#include "base/command_line.h"
#include "base/mac/scoped_nsobject.h" #include "base/mac/scoped_nsobject.h"
#include "ui/base/cocoa/animation_utils.h" #include "ui/base/cocoa/animation_utils.h"
#include "ui/base/ui_base_switches.h"
namespace { namespace {
...@@ -20,17 +18,12 @@ const CGFloat kRoundedCornerRadius = 4; ...@@ -20,17 +18,12 @@ const CGFloat kRoundedCornerRadius = 4;
} // namespace } // namespace
@interface FastResizeView (PrivateMethods) @interface FastResizeView (PrivateMethods)
// Lays out this views subviews. If fast resize mode is on, does not resize any
// subviews and instead pegs them to the top left. If fast resize mode is off,
// sets the subviews' frame to be equal to this view's bounds.
- (void)layoutSubviews;
// Creates a path whose bottom two corners are rounded. // Creates a path whose bottom two corners are rounded.
// Caller takes ownership of the path. // Caller takes ownership of the path.
- (CGPathRef)createRoundedBottomCornersPath:(NSSize)size; - (CGPathRef)createRoundedBottomCornersPath:(NSSize)size;
// Updates the path of the layer mask to reflect the current value of // Updates the path of the layer mask to reflect the current value of
// roundedBottomCorners_ and fastResizeMode_. // roundedBottomCorners_.
- (void)updateLayerMask; - (void)updateLayerMask;
@end @end
...@@ -38,17 +31,14 @@ const CGFloat kRoundedCornerRadius = 4; ...@@ -38,17 +31,14 @@ const CGFloat kRoundedCornerRadius = 4;
- (id)initWithFrame:(NSRect)frameRect { - (id)initWithFrame:(NSRect)frameRect {
if ((self = [super initWithFrame:frameRect])) { if ((self = [super initWithFrame:frameRect])) {
if (!CommandLine::ForCurrentProcess()->HasSwitch( ScopedCAActionDisabler disabler;
switches::kDisableCoreAnimation)) { base::scoped_nsobject<CALayer> layer([[CALayer alloc] init]);
ScopedCAActionDisabler disabler; [layer setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)];
base::scoped_nsobject<CALayer> layer([[CALayer alloc] init]); [self setLayer:layer];
[layer setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)]; [self setWantsLayer:YES];
[self setLayer:layer];
[self setWantsLayer:YES]; roundedBottomCorners_ = YES;
[self updateLayerMask];
roundedBottomCorners_ = YES;
[self updateLayerMask];
}
} }
return self; return self;
} }
...@@ -57,20 +47,6 @@ const CGFloat kRoundedCornerRadius = 4; ...@@ -57,20 +47,6 @@ const CGFloat kRoundedCornerRadius = 4;
return YES; return YES;
} }
- (void)setFastResizeMode:(BOOL)fastResizeMode {
if (fastResizeMode_ == fastResizeMode)
return;
fastResizeMode_ = fastResizeMode;
[self updateLayerMask];
// Force a relayout when coming out of fast resize mode.
if (!fastResizeMode_)
[self layoutSubviews];
[self setNeedsDisplay:YES];
}
- (void)setRoundedBottomCorners:(BOOL)roundedBottomCorners { - (void)setRoundedBottomCorners:(BOOL)roundedBottomCorners {
if (roundedBottomCorners == roundedBottomCorners_) if (roundedBottomCorners == roundedBottomCorners_)
return; return;
...@@ -79,21 +55,6 @@ const CGFloat kRoundedCornerRadius = 4; ...@@ -79,21 +55,6 @@ const CGFloat kRoundedCornerRadius = 4;
[self updateLayerMask]; [self updateLayerMask];
} }
- (void)resizeSubviewsWithOldSize:(NSSize)oldSize {
[self layoutSubviews];
}
- (void)drawRect:(NSRect)dirtyRect {
// If we are in fast resize mode, our subviews may not completely cover our
// bounds, so we fill with white. If we are not in fast resize mode, we do
// not need to draw anything.
if (!fastResizeMode_)
return;
[[NSColor whiteColor] set];
NSRectFill(dirtyRect);
}
// Every time the frame's size changes, the layer mask needs to be updated. // Every time the frame's size changes, the layer mask needs to be updated.
- (void)setFrameSize:(NSSize)newSize { - (void)setFrameSize:(NSSize)newSize {
[super setFrameSize:newSize]; [super setFrameSize:newSize];
...@@ -104,28 +65,6 @@ const CGFloat kRoundedCornerRadius = 4; ...@@ -104,28 +65,6 @@ const CGFloat kRoundedCornerRadius = 4;
@implementation FastResizeView (PrivateMethods) @implementation FastResizeView (PrivateMethods)
- (void)layoutSubviews {
// There should never be more than one subview. There can be zero, if we are
// in the process of switching tabs or closing the window. In those cases, no
// layout is needed.
NSArray* subviews = [self subviews];
DCHECK([subviews count] <= 1);
if ([subviews count] < 1)
return;
NSView* subview = [subviews objectAtIndex:0];
NSRect bounds = [self bounds];
if (fastResizeMode_) {
NSRect frame = [subview frame];
frame.origin.x = 0;
frame.origin.y = NSHeight(bounds) - NSHeight(frame);
[subview setFrame:frame];
} else {
[subview setFrame:bounds];
}
}
- (CGPathRef)createRoundedBottomCornersPath:(NSSize)size { - (CGPathRef)createRoundedBottomCornersPath:(NSSize)size {
CGMutablePathRef path = CGPathCreateMutable(); CGMutablePathRef path = CGPathCreateMutable();
CGFloat width = size.width; CGFloat width = size.width;
...@@ -165,7 +104,7 @@ const CGFloat kRoundedCornerRadius = 4; ...@@ -165,7 +104,7 @@ const CGFloat kRoundedCornerRadius = 4;
} }
- (void)updateLayerMask { - (void)updateLayerMask {
if (fastResizeMode_ || !roundedBottomCorners_) { if (!roundedBottomCorners_) {
[self layer].mask = nil; [self layer].mask = nil;
layerMask_ = nil; layerMask_ = nil;
return; return;
......
// Copyright (c) 2011 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 "base/mac/scoped_nsobject.h"
#import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
#import "chrome/browser/ui/cocoa/fast_resize_view.h"
namespace {
class FastResizeViewTest : public CocoaTest {
public:
FastResizeViewTest() {
NSRect frame = NSMakeRect(0, 0, 100, 30);
base::scoped_nsobject<FastResizeView> view(
[[FastResizeView alloc] initWithFrame:frame]);
view_ = view.get();
[[test_window() contentView] addSubview:view_];
base::scoped_nsobject<NSView> childView(
[[NSView alloc] initWithFrame:frame]);
childView_ = childView.get();
[view_ addSubview:childView_];
}
FastResizeView* view_;
NSView* childView_;
};
TEST_VIEW(FastResizeViewTest, view_);
TEST_F(FastResizeViewTest, TestResizingOfChildren) {
NSRect squareFrame = NSMakeRect(0, 0, 200, 200);
NSRect rectFrame = NSMakeRect(1, 1, 150, 300);
// Test that changing the view's frame also changes the child's frame.
[view_ setFrame:squareFrame];
EXPECT_TRUE(NSEqualRects([view_ bounds], [childView_ frame]));
// Turn fast resize mode on and change the view's frame. This time, the child
// should not resize, but it should be anchored to the top left.
[view_ setFastResizeMode:YES];
[view_ setFrame:NSMakeRect(15, 30, 250, 250)];
EXPECT_TRUE(NSEqualSizes([childView_ frame].size, squareFrame.size));
EXPECT_EQ(NSMinX([view_ bounds]), NSMinX([childView_ frame]));
EXPECT_EQ(NSMaxY([view_ bounds]), NSMaxY([childView_ frame]));
// Another resize with fast resize mode on.
[view_ setFrame:rectFrame];
EXPECT_TRUE(NSEqualSizes([childView_ frame].size, squareFrame.size));
EXPECT_EQ(NSMinX([view_ bounds]), NSMinX([childView_ frame]));
EXPECT_EQ(NSMaxY([view_ bounds]), NSMaxY([childView_ frame]));
// Turn fast resize mode off. This should initiate an immediate resize, even
// though we haven't called setFrame directly.
[view_ setFastResizeMode:NO];
EXPECT_TRUE(NSEqualRects([view_ frame], rectFrame));
EXPECT_TRUE(NSEqualRects([view_ bounds], [childView_ frame]));
}
} // namespace
...@@ -20,9 +20,9 @@ CGFloat kCurveSize = 8; ...@@ -20,9 +20,9 @@ CGFloat kCurveSize = 8;
- (id)initWithFrame:(NSRect)frame { - (id)initWithFrame:(NSRect)frame {
if ((self = [super initWithFrame:frame])) { if ((self = [super initWithFrame:frame])) {
// Give this view its own layer so that it can appear over the web contents // Give this view its own layer so that it can appear over the web contents
// view's layer. Layer squashing is not necessary for this view because // view's layer. Layer squashing is not helpful for this view because
// NSTextField will correctly anti-alias text on 10.8 and beyond. // NSTextField will correctly anti-alias text on 10.8 and beyond.
[self cr_setWantsLayer:YES]; [self setWantsLayer:YES];
} }
return self; return self;
} }
......
...@@ -139,10 +139,6 @@ const CGFloat kTrackingAreaMaxYEpsilon = 15; ...@@ -139,10 +139,6 @@ const CGFloat kTrackingAreaMaxYEpsilon = 15;
destinationState_ = state; destinationState_ = state;
// Turn on fast resize mode to ensure a smooth web contents animation.
// TODO(rsesek): This makes the animation jump at the end.
[[controller_ tabContentArea] setFastResizeMode:YES];
animation_.reset([[FullscreenModeDropDownAnimation alloc] animation_.reset([[FullscreenModeDropDownAnimation alloc]
initWithFullscreenModeController:self]); initWithFullscreenModeController:self]);
[animation_ startAnimation]; [animation_ startAnimation];
...@@ -172,8 +168,6 @@ const CGFloat kTrackingAreaMaxYEpsilon = 15; ...@@ -172,8 +168,6 @@ const CGFloat kTrackingAreaMaxYEpsilon = 15;
[animation_ setDelegate:nil]; [animation_ setDelegate:nil];
animation_.reset(); animation_.reset();
[[controller_ tabContentArea] setFastResizeMode:NO];
} }
@end @end
...@@ -32,10 +32,6 @@ ...@@ -32,10 +32,6 @@
// Set needsDisplay for this view and all descendants. // Set needsDisplay for this view and all descendants.
- (void)cr_recursivelySetNeedsDisplay:(BOOL)flag; - (void)cr_recursivelySetNeedsDisplay:(BOOL)flag;
// Set the specified view to have a CoreAnimation layer if CoreAnimation is
// enabled at the command line.
- (void)cr_setWantsLayer:(BOOL)wantsLayer;
// Draw using ancestorView's drawRect function into this view's rect. Do any // Draw using ancestorView's drawRect function into this view's rect. Do any
// required translating or flipping to transform between the two coordinate // required translating or flipping to transform between the two coordinate
// systems. // systems.
......
...@@ -2,12 +2,10 @@ ...@@ -2,12 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "base/command_line.h"
#include "base/mac/mac_util.h" #include "base/mac/mac_util.h"
#include "base/mac/sdk_forward_declarations.h" #include "base/mac/sdk_forward_declarations.h"
#import "chrome/browser/ui/cocoa/nsview_additions.h" #import "chrome/browser/ui/cocoa/nsview_additions.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "ui/base/ui_base_switches.h"
#include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
#include "base/logging.h" #include "base/logging.h"
...@@ -70,20 +68,6 @@ ...@@ -70,20 +68,6 @@
[child cr_recursivelySetNeedsDisplay:flag]; [child cr_recursivelySetNeedsDisplay:flag];
} }
- (void)cr_setWantsLayer:(BOOL)wantsLayer {
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableCoreAnimation))
return;
// Dynamically removing layers on SnowLeopard will sometimes result in
// crashes. Once a view has a layer on SnowLeopard, it is stuck with it.
// http://crbug.com/348328
if (!wantsLayer && base::mac::IsOSSnowLeopard())
return;
[self setWantsLayer:wantsLayer];
}
static NSView* g_ancestorBeingDrawnFrom = nil; static NSView* g_ancestorBeingDrawnFrom = nil;
static NSView* g_childBeingDrawnTo = nil; static NSView* g_childBeingDrawnTo = nil;
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#import "chrome/browser/ui/cocoa/browser_window_controller.h" #import "chrome/browser/ui/cocoa/browser_window_controller.h"
#import "chrome/browser/ui/cocoa/nsview_additions.h"
#import "chrome/browser/ui/cocoa/profiles/avatar_label_button.h" #import "chrome/browser/ui/cocoa/profiles/avatar_label_button.h"
#include "grit/generated_resources.h" #include "grit/generated_resources.h"
#include "grit/theme_resources.h" #include "grit/theme_resources.h"
...@@ -60,7 +59,7 @@ const CGFloat kAvatarLabelRightSpacing = 2; ...@@ -60,7 +59,7 @@ const CGFloat kAvatarLabelRightSpacing = 2;
base::scoped_nsobject<NSView> container( base::scoped_nsobject<NSView> container(
[[NSView alloc] initWithFrame:NSMakeRect( [[NSView alloc] initWithFrame:NSMakeRect(
0, 0, profiles::kAvatarIconWidth, profiles::kAvatarIconHeight)]); 0, 0, profiles::kAvatarIconWidth, profiles::kAvatarIconHeight)]);
[container cr_setWantsLayer:YES]; [container setWantsLayer:YES];
[self setView:container]; [self setView:container];
button_.reset([[NSButton alloc] initWithFrame:NSMakeRect( button_.reset([[NSButton alloc] initWithFrame:NSMakeRect(
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include <utility> #include <utility>
#include "base/command_line.h"
#include "base/mac/scoped_cftyperef.h" #include "base/mac/scoped_cftyperef.h"
#include "base/mac/scoped_nsobject.h" #include "base/mac/scoped_nsobject.h"
#include "chrome/browser/devtools/devtools_window.h" #include "chrome/browser/devtools/devtools_window.h"
...@@ -18,7 +17,6 @@ ...@@ -18,7 +17,6 @@
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "ui/base/cocoa/animation_utils.h" #include "ui/base/cocoa/animation_utils.h"
#include "ui/base/ui_base_switches.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
using content::WebContents; using content::WebContents;
...@@ -86,16 +84,11 @@ class FullscreenObserver : public WebContentsObserver { ...@@ -86,16 +84,11 @@ class FullscreenObserver : public WebContentsObserver {
- (id)initWithDelegate:(TabContentsController*)delegate { - (id)initWithDelegate:(TabContentsController*)delegate {
if ((self = [super initWithFrame:NSZeroRect])) { if ((self = [super initWithFrame:NSZeroRect])) {
delegate_ = delegate; delegate_ = delegate;
if (!CommandLine::ForCurrentProcess()->HasSwitch( ScopedCAActionDisabler disabler;
switches::kDisableCoreAnimation)) { base::scoped_nsobject<CALayer> layer([[CALayer alloc] init]);
// TODO(ccameron): Remove the -drawRect: method once the [layer setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)];
// kDisableCoreAnimation switch is removed. [self setLayer:layer];
ScopedCAActionDisabler disabler; [self setWantsLayer:YES];
base::scoped_nsobject<CALayer> layer([[CALayer alloc] init]);
[layer setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)];
[self setLayer:layer];
[self setWantsLayer:YES];
}
} }
return self; return self;
} }
......
...@@ -1591,7 +1591,6 @@ ...@@ -1591,7 +1591,6 @@
'browser/ui/cocoa/extensions/extension_install_view_controller_unittest.mm', 'browser/ui/cocoa/extensions/extension_install_view_controller_unittest.mm',
'browser/ui/cocoa/extensions/extension_installed_bubble_controller_unittest.mm', 'browser/ui/cocoa/extensions/extension_installed_bubble_controller_unittest.mm',
'browser/ui/cocoa/extensions/media_galleries_dialog_cocoa_unittest.mm', 'browser/ui/cocoa/extensions/media_galleries_dialog_cocoa_unittest.mm',
'browser/ui/cocoa/fast_resize_view_unittest.mm',
'browser/ui/cocoa/find_bar/find_bar_bridge_unittest.mm', 'browser/ui/cocoa/find_bar/find_bar_bridge_unittest.mm',
'browser/ui/cocoa/find_bar/find_bar_cocoa_controller_unittest.mm', 'browser/ui/cocoa/find_bar/find_bar_cocoa_controller_unittest.mm',
'browser/ui/cocoa/find_bar/find_bar_text_field_cell_unittest.mm', 'browser/ui/cocoa/find_bar/find_bar_text_field_cell_unittest.mm',
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
#include "ui/base/ui_base_export.h" #include "ui/base/ui_base_export.h"
// Common base class for windows that host a OpenGL surface that renders under // Common base class for windows that host a OpenGL surface that renders under
// the window. Contains methods relating to hole punching so that the OpenGL // the window. Previously contained methods related to hole punching, now just
// surface is visible through the window. // contains common asserts.
UI_BASE_EXPORT UI_BASE_EXPORT
@interface UnderlayOpenGLHostingWindow : NSWindow @interface UnderlayOpenGLHostingWindow : NSWindow
@end @end
......
...@@ -4,89 +4,7 @@ ...@@ -4,89 +4,7 @@
#import "ui/base/cocoa/underlay_opengl_hosting_window.h" #import "ui/base/cocoa/underlay_opengl_hosting_window.h"
#import <objc/runtime.h>
#include "base/command_line.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/mac_util.h"
#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/mac/scoped_nsobject.h"
#include "ui/base/ui_base_switches.h"
@interface NSWindow (UndocumentedAPI)
// Normally, punching a hole in a window by painting a subview with a
// transparent color causes the shadow for that area to also not be present.
// That feature is "content has shadow", which means that shadows are effective
// even in the content area of the window. If, however, "content has shadow" is
// turned off, then the transparent area of the content casts a shadow. The one
// tricky part is that even if "content has shadow" is turned off, "the content"
// is defined as being the scanline from the leftmost opaque part to the
// rightmost opaque part. Therefore, to force the entire window to have a
// shadow, make sure that for the entire content region, there is an opaque area
// on the right and left edge of the window.
- (void)_setContentHasShadow:(BOOL)shadow;
@end
@interface OpaqueView : NSView
@end
namespace {
bool CoreAnimationIsEnabled() {
static bool is_enabled = !CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableCoreAnimation);
return is_enabled;
}
NSComparisonResult OpaqueViewsOnTop(id view1, id view2, void* context) {
BOOL view_1_is_opaque_view = [view1 isKindOfClass:[OpaqueView class]];
BOOL view_2_is_opaque_view = [view2 isKindOfClass:[OpaqueView class]];
if (view_1_is_opaque_view && view_2_is_opaque_view)
return NSOrderedSame;
if (view_1_is_opaque_view)
return NSOrderedDescending;
if (view_2_is_opaque_view)
return NSOrderedAscending;
return NSOrderedSame;
}
} // namespace
@implementation OpaqueView
- (void)drawRect:(NSRect)r {
[[NSColor blackColor] set];
NSRectFill(r);
}
- (void)resetCursorRects {
// When a view is moved relative to its peers, its cursor rects are reset.
// (This is an undocumented side-effect.) At that time, verify that any
// OpaqueViews are z-ordered in the front, and enforce it if need be.
NSView* rootView = [self superview];
DCHECK_EQ((NSView*)nil, [rootView superview]);
NSArray* subviews = [rootView subviews];
// If a window has any opaques, it will have exactly two.
DCHECK_EQ(2U, [[subviews indexesOfObjectsPassingTest:
^(id el, NSUInteger i, BOOL *stop) {
return [el isKindOfClass:[OpaqueView class]];
}] count]);
NSUInteger count = [subviews count];
if (count < 2)
return;
if (![[subviews objectAtIndex:count - 1] isKindOfClass:[OpaqueView class]] ||
![[subviews objectAtIndex:count - 2] isKindOfClass:[OpaqueView class]]) {
// Do not sort the subviews array here and call -[NSView setSubviews:] as
// that causes a crash on 10.6.
[rootView sortSubviewsUsingFunction:OpaqueViewsOnTop context:NULL];
}
}
@end
@implementation UnderlayOpenGLHostingWindow @implementation UnderlayOpenGLHostingWindow
...@@ -107,58 +25,10 @@ NSComparisonResult OpaqueViewsOnTop(id view1, id view2, void* context) { ...@@ -107,58 +25,10 @@ NSComparisonResult OpaqueViewsOnTop(id view1, id view2, void* context) {
// (This is checked here because UnderlayOpenGLHostingWindow is the base of // (This is checked here because UnderlayOpenGLHostingWindow is the base of
// most Chromium windows, not because this is related to its functionality.) // most Chromium windows, not because this is related to its functionality.)
DCHECK(!NSIsEmptyRect(contentRect)); DCHECK(!NSIsEmptyRect(contentRect));
if ((self = [super initWithContentRect:contentRect self = [super initWithContentRect:contentRect
styleMask:windowStyle styleMask:windowStyle
backing:bufferingType backing:bufferingType
defer:deferCreation])) { defer:deferCreation];
if (CoreAnimationIsEnabled()) {
// If CoreAnimation is used, then the hole punching technique won't be
// used. Bail now and don't play any special games with the shadow.
// TODO(avi): Rip all this shadow code out once CoreAnimation can't be
// turned off. http://crbug.com/336554
return self;
}
// OpenGL-accelerated content works by punching holes in windows. Therefore
// all windows hosting OpenGL content must not be opaque.
[self setOpaque:NO];
if (windowStyle & NSTitledWindowMask) {
// Only fiddle with shadows if the window is a proper window with a
// title bar and all.
[self _setContentHasShadow:NO];
NSView* rootView = [[self contentView] superview];
const NSRect rootBounds = [rootView bounds];
// On 10.7/8, the bottom corners of the window are rounded by magic at a
// deeper level than the NSThemeFrame, so it is OK to have the opaques
// go all the way to the bottom.
const CGFloat kTopEdgeInset = 16;
const CGFloat kAlphaValueJustOpaqueEnough = 0.005;
base::scoped_nsobject<NSView> leftOpaque([[OpaqueView alloc]
initWithFrame:NSMakeRect(NSMinX(rootBounds),
NSMinY(rootBounds),
1,
NSHeight(rootBounds) - kTopEdgeInset)]);
[leftOpaque setAutoresizingMask:NSViewMaxXMargin |
NSViewHeightSizable];
[leftOpaque setAlphaValue:kAlphaValueJustOpaqueEnough];
[rootView addSubview:leftOpaque];
base::scoped_nsobject<NSView> rightOpaque([[OpaqueView alloc]
initWithFrame:NSMakeRect(NSMaxX(rootBounds) - 1,
NSMinY(rootBounds),
1,
NSHeight(rootBounds) - kTopEdgeInset)]);
[rightOpaque setAutoresizingMask:NSViewMinXMargin |
NSViewHeightSizable];
[rightOpaque setAlphaValue:kAlphaValueJustOpaqueEnough];
[rootView addSubview:rightOpaque];
}
}
return self; return self;
} }
......
...@@ -7,9 +7,6 @@ ...@@ -7,9 +7,6 @@
namespace switches { namespace switches {
#if defined(OS_MACOSX) && !defined(OS_IOS) #if defined(OS_MACOSX) && !defined(OS_IOS)
// Disable use of CoreAnimation to draw on the Mac.
const char kDisableCoreAnimation[] = "disable-core-animation";
// Enable use of cross-process CALayers to display content directly from the // Enable use of cross-process CALayers to display content directly from the
// GPU process on Mac. // GPU process on Mac.
const char kEnableRemoteCoreAnimation[] = "enable-remote-core-animation"; const char kEnableRemoteCoreAnimation[] = "enable-remote-core-animation";
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
namespace switches { namespace switches {
#if defined(OS_MACOSX) && !defined(OS_IOS) #if defined(OS_MACOSX) && !defined(OS_IOS)
UI_BASE_EXPORT extern const char kDisableCoreAnimation[];
UI_BASE_EXPORT extern const char kEnableRemoteCoreAnimation[]; UI_BASE_EXPORT extern const char kEnableRemoteCoreAnimation[];
#endif #endif
......
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