diff options
author | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-09 21:01:37 +0000 |
---|---|---|
committer | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-09 21:01:37 +0000 |
commit | 8c340d04ee3e18a1e5fb26d0c484adbb3d4e8955 (patch) | |
tree | 2ec1581ddcafb43a45d53bd5998ec57a94dea060 | |
parent | a4480e975f2d03a43b06166c3d10305d346768da (diff) | |
download | chromium_src-8c340d04ee3e18a1e5fb26d0c484adbb3d4e8955.zip chromium_src-8c340d04ee3e18a1e5fb26d0c484adbb3d4e8955.tar.gz chromium_src-8c340d04ee3e18a1e5fb26d0c484adbb3d4e8955.tar.bz2 |
[Mac] Adds a "fast resize mode" in which the RenderWidgetHostViewCocoa is clipped rather than resized. Useful for when animations are running.
BUG=http://crbug.com/26857
TEST=Animations should still work. Infobar animations should be smoother. The web contents will clip or fill with white at the bottom while the animation is running, but should resize and draw correctly when the animation finishes.
Review URL: http://codereview.chromium.org/372056
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31472 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/nibs/BrowserWindow.xib | 69 | ||||
-rw-r--r-- | chrome/browser/cocoa/animatable_view.mm | 6 | ||||
-rw-r--r-- | chrome/browser/cocoa/browser_window_controller.mm | 5 | ||||
-rw-r--r-- | chrome/browser/cocoa/fast_resize_view.h | 28 | ||||
-rw-r--r-- | chrome/browser/cocoa/fast_resize_view.mm | 65 | ||||
-rw-r--r-- | chrome/browser/cocoa/fast_resize_view_unittest.mm | 60 | ||||
-rw-r--r-- | chrome/browser/cocoa/infobar_container_controller.mm | 5 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_window_controller.h | 5 | ||||
-rw-r--r-- | chrome/browser/cocoa/view_resizer.h | 6 | ||||
-rwxr-xr-x | chrome/chrome.gyp | 3 |
10 files changed, 219 insertions, 33 deletions
diff --git a/chrome/app/nibs/BrowserWindow.xib b/chrome/app/nibs/BrowserWindow.xib index 245e044..884819e 100644 --- a/chrome/app/nibs/BrowserWindow.xib +++ b/chrome/app/nibs/BrowserWindow.xib @@ -1,15 +1,19 @@ <?xml version="1.0" encoding="UTF-8"?> -<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.03"> +<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.10"> <data> <int key="IBDocument.SystemTarget">1050</int> - <string key="IBDocument.SystemVersion">9L31a</string> - <string key="IBDocument.InterfaceBuilderVersion">677</string> - <string key="IBDocument.AppKitVersion">949.54</string> - <string key="IBDocument.HIToolboxVersion">353.00</string> + <string key="IBDocument.SystemVersion">10B504</string> + <string key="IBDocument.InterfaceBuilderVersion">740</string> + <string key="IBDocument.AppKitVersion">1038.2</string> + <string key="IBDocument.HIToolboxVersion">437.00</string> + <object class="NSMutableDictionary" key="IBDocument.PluginVersions"> + <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string> + <string key="NS.object.0">740</string> + </object> <object class="NSMutableArray" key="IBDocument.EditedObjectIDs"> <bool key="EncodedWithXMLCoder">YES</bool> - <integer value="56"/> <integer value="1"/> + <integer value="56"/> </object> <object class="NSArray" key="IBDocument.PluginDependencies"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -17,7 +21,7 @@ </object> <object class="NSMutableDictionary" key="IBDocument.Metadata"> <bool key="EncodedWithXMLCoder">YES</bool> - <object class="NSArray" key="dict.sortedKeys"> + <object class="NSArray" key="dict.sortedKeys" id="0"> <bool key="EncodedWithXMLCoder">YES</bool> </object> <object class="NSMutableArray" key="dict.values"> @@ -43,7 +47,7 @@ <string key="NSWindowTitle"/> <string key="NSWindowClass">ChromeBrowserWindow</string> <nil key="NSViewClass"/> - <string key="NSWindowContentMaxSize">{3.40282e+38, 3.40282e+38}</string> + <string key="NSWindowContentMaxSize">{1.79769e+308, 1.79769e+308}</string> <string key="NSWindowContentMinSize">{400, 250}</string> <object class="NSView" key="NSWindowView" id="1006"> <reference key="NSNextResponder"/> @@ -55,7 +59,7 @@ <int key="NSvFlags">274</int> <string key="NSFrameSize">{750, 586}</string> <reference key="NSSuperview" ref="1006"/> - <string key="NSClassName">NSView</string> + <string key="NSClassName">FastResizeView</string> </object> </object> <string key="NSFrameSize">{750, 600}</string> @@ -63,7 +67,7 @@ </object> <string key="NSScreenRect">{{0, 0}, {1440, 878}}</string> <string key="NSMinSize">{400, 272}</string> - <string key="NSMaxSize">{3.40282e+38, 3.40282e+38}</string> + <string key="NSMaxSize">{1.79769e+308, 1.79769e+308}</string> </object> <object class="NSCustomView" id="1029219716"> <reference key="NSNextResponder"/> @@ -82,7 +86,7 @@ <string key="NSContents"/> <object class="NSFont" key="NSSupport"> <string key="NSName">LucidaGrande</string> - <double key="NSSize">1.300000e+01</double> + <double key="NSSize">13</double> <int key="NSfFlags">1044</int> </object> <reference key="NSControlView" ref="131944810"/> @@ -149,28 +153,26 @@ <bool key="EncodedWithXMLCoder">YES</bool> <object class="IBObjectRecord"> <int key="objectID">0</int> - <object class="NSArray" key="object" id="1002"> - <bool key="EncodedWithXMLCoder">YES</bool> - </object> + <reference key="object" ref="0"/> <reference key="children" ref="1000"/> <nil key="parent"/> </object> <object class="IBObjectRecord"> <int key="objectID">-2</int> <reference key="object" ref="1001"/> - <reference key="parent" ref="1002"/> - <string type="base64-UTF8" key="objectName">RmlsZSdzIE93bmVyA</string> + <reference key="parent" ref="0"/> + <string key="objectName">File's Owner</string> </object> <object class="IBObjectRecord"> <int key="objectID">-1</int> <reference key="object" ref="1003"/> - <reference key="parent" ref="1002"/> + <reference key="parent" ref="0"/> <string key="objectName">First Responder</string> </object> <object class="IBObjectRecord"> <int key="objectID">-3</int> <reference key="object" ref="1004"/> - <reference key="parent" ref="1002"/> + <reference key="parent" ref="0"/> <string key="objectName">Application</string> </object> <object class="IBObjectRecord"> @@ -180,7 +182,7 @@ <bool key="EncodedWithXMLCoder">YES</bool> <reference ref="1006"/> </object> - <reference key="parent" ref="1002"/> + <reference key="parent" ref="0"/> <string key="objectName">Browser</string> </object> <object class="IBObjectRecord"> @@ -199,7 +201,7 @@ <bool key="EncodedWithXMLCoder">YES</bool> <reference ref="131944810"/> </object> - <reference key="parent" ref="1002"/> + <reference key="parent" ref="0"/> <string key="objectName">TabBar</string> </object> <object class="IBObjectRecord"> @@ -225,7 +227,7 @@ </object> <object class="NSMutableDictionary" key="flattenedProperties"> <bool key="EncodedWithXMLCoder">YES</bool> - <object class="NSMutableArray" key="dict.sortedKeys"> + <object class="NSArray" key="dict.sortedKeys"> <bool key="EncodedWithXMLCoder">YES</bool> <string>-1.IBPluginDependency</string> <string>-2.IBPluginDependency</string> @@ -263,13 +265,13 @@ <boolean value="YES"/> <string>{400, 250}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <real value="0.000000e+00"/> + <real value="0.0"/> <object class="NSColor"> <int key="NSColorSpace">3</int> <bytes key="NSWhite">MAA</bytes> </object> - <real value="0.000000e+00"/> - <real value="0.000000e+00"/> + <real value="0.0"/> + <real value="0.0"/> <string>{{138, 199}, {483, 36}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> @@ -279,9 +281,7 @@ </object> <object class="NSMutableDictionary" key="unlocalizedProperties"> <bool key="EncodedWithXMLCoder">YES</bool> - <object class="NSArray" key="dict.sortedKeys"> - <bool key="EncodedWithXMLCoder">YES</bool> - </object> + <reference key="dict.sortedKeys" ref="0"/> <object class="NSMutableArray" key="dict.values"> <bool key="EncodedWithXMLCoder">YES</bool> </object> @@ -289,9 +289,7 @@ <nil key="activeLocalization"/> <object class="NSMutableDictionary" key="localizations"> <bool key="EncodedWithXMLCoder">YES</bool> - <object class="NSArray" key="dict.sortedKeys"> - <bool key="EncodedWithXMLCoder">YES</bool> - </object> + <reference key="dict.sortedKeys" ref="0"/> <object class="NSMutableArray" key="dict.values"> <bool key="EncodedWithXMLCoder">YES</bool> </object> @@ -372,7 +370,7 @@ <string key="superclassName">NSWindowController</string> <object class="NSMutableDictionary" key="outlets"> <bool key="EncodedWithXMLCoder">YES</bool> - <object class="NSMutableArray" key="dict.sortedKeys"> + <object class="NSArray" key="dict.sortedKeys"> <bool key="EncodedWithXMLCoder">YES</bool> <string>tabContentArea_</string> <string>tabStripView_</string> @@ -391,6 +389,15 @@ </object> </object> <int key="IBDocument.localizationMode">0</int> + <object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencies"> + <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin.macosx</string> + <integer value="1050" key="NS.object.0"/> + </object> + <object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies"> + <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3</string> + <integer value="3000" key="NS.object.0"/> + </object> + <bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool> <string key="IBDocument.LastKnownRelativeProjectPath">../../chrome.xcodeproj</string> <int key="IBDocument.defaultPropertyAccessControl">3</int> </data> diff --git a/chrome/browser/cocoa/animatable_view.mm b/chrome/browser/cocoa/animatable_view.mm index 06d039b..7098e37 100644 --- a/chrome/browser/cocoa/animatable_view.mm +++ b/chrome/browser/cocoa/animatable_view.mm @@ -74,6 +74,8 @@ currentAnimation_.reset([[NSHeightAnimation alloc] initWithView:self finalHeight:newHeight duration:duration]); + if ([resizeDelegate_ respondsToSelector:@selector(setAnimationInProgress:)]) + [resizeDelegate_ setAnimationInProgress:YES]; [currentAnimation_ startAnimation]; } @@ -86,12 +88,16 @@ } - (void)animationDidStop:(NSAnimation*)animation { + if ([resizeDelegate_ respondsToSelector:@selector(setAnimationInProgress:)]) + [resizeDelegate_ setAnimationInProgress:NO]; if ([delegate_ respondsToSelector:@selector(animationDidStop:)]) [delegate_ animationDidStop:animation]; currentAnimation_.reset(nil); } - (void)animationDidEnd:(NSAnimation*)animation { + if ([resizeDelegate_ respondsToSelector:@selector(setAnimationInProgress:)]) + [resizeDelegate_ setAnimationInProgress:NO]; if ([delegate_ respondsToSelector:@selector(animationDidEnd:)]) [delegate_ animationDidEnd:animation]; currentAnimation_.reset(nil); diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm index 758a60d..b9f6026 100644 --- a/chrome/browser/cocoa/browser_window_controller.mm +++ b/chrome/browser/cocoa/browser_window_controller.mm @@ -29,6 +29,7 @@ #import "chrome/browser/cocoa/download_shelf_controller.h" #import "chrome/browser/cocoa/event_utils.h" #import "chrome/browser/cocoa/extension_shelf_controller.h" +#import "chrome/browser/cocoa/fast_resize_view.h" #import "chrome/browser/cocoa/find_bar_cocoa_controller.h" #include "chrome/browser/cocoa/find_bar_bridge.h" #import "chrome/browser/cocoa/fullscreen_window.h" @@ -488,6 +489,10 @@ willPositionSheet:(NSWindow*)sheet [self layoutSubviews]; } +- (void)setAnimationInProgress:(BOOL)inProgress { + [[self tabContentArea] setFastResizeMode:inProgress]; +} + // Update a toggle state for an NSMenuItem if modified. // Take care to insure |item| looks like a NSMenuItem. // Called by validateUserInterfaceItem:. diff --git a/chrome/browser/cocoa/fast_resize_view.h b/chrome/browser/cocoa/fast_resize_view.h new file mode 100644 index 0000000..d87b9b8f --- /dev/null +++ b/chrome/browser/cocoa/fast_resize_view.h @@ -0,0 +1,28 @@ +// Copyright (c) 2009 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. + +#ifndef CHROME_BROWSER_COCOA_FAST_RESIZE_VIEW_H_ +#define CHROME_BROWSER_COCOA_FAST_RESIZE_VIEW_H_ + +#import <Cocoa/Cocoa.h> + +// A Cocoa view that supports an alternate resizing mode, normally used when +// animations are in progress. In normal resizing mode, subviews are sized to +// completely fill this view's bounds. In fast resizing mode, the subviews' +// 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 { + @private + BOOL fastResizeMode_; +} + +// 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; +@end + +#endif // CHROME_BROWSER_COCOA_FAST_RESIZE_VIEW_H_ diff --git a/chrome/browser/cocoa/fast_resize_view.mm b/chrome/browser/cocoa/fast_resize_view.mm new file mode 100644 index 0000000..97c1d82 --- /dev/null +++ b/chrome/browser/cocoa/fast_resize_view.mm @@ -0,0 +1,65 @@ +// Copyright (c) 2009 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. + +#import <Cocoa/Cocoa.h> +#import "chrome/browser/cocoa/fast_resize_view.h" + +#include "base/logging.h" + +@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; +@end + +@implementation FastResizeView +- (void)setFastResizeMode:(BOOL)fastResizeMode { + fastResizeMode_ = fastResizeMode; + + // Force a relayout when coming out of fast resize mode. + if (!fastResizeMode_) + [self layoutSubviews]; +} + +- (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_) { + [[NSColor whiteColor] set]; + NSRectFill(dirtyRect); + } +} + + +@end + +@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]; + } +} +@end diff --git a/chrome/browser/cocoa/fast_resize_view_unittest.mm b/chrome/browser/cocoa/fast_resize_view_unittest.mm new file mode 100644 index 0000000..ee6f34d --- /dev/null +++ b/chrome/browser/cocoa/fast_resize_view_unittest.mm @@ -0,0 +1,60 @@ +// Copyright (c) 2009 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/scoped_nsobject.h" +#import "chrome/browser/cocoa/fast_resize_view.h" +#import "chrome/browser/cocoa/cocoa_test_helper.h" + +namespace { + +class FastResizeViewTest : public CocoaTest { + public: + FastResizeViewTest() { + NSRect frame = NSMakeRect(0, 0, 100, 30); + scoped_nsobject<FastResizeView> view( + [[FastResizeView alloc] initWithFrame:frame]); + view_ = view.get(); + [[test_window() contentView] addSubview:view_]; + + 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 diff --git a/chrome/browser/cocoa/infobar_container_controller.mm b/chrome/browser/cocoa/infobar_container_controller.mm index b09c580..bd18be5 100644 --- a/chrome/browser/cocoa/infobar_container_controller.mm +++ b/chrome/browser/cocoa/infobar_container_controller.mm @@ -130,6 +130,11 @@ class InfoBarNotificationObserver : public NotificationObserver { [self positionInfoBarsAndRedraw]; } +- (void)setAnimationInProgress:(BOOL)inProgress { + if ([resizeDelegate_ respondsToSelector:@selector(setAnimationInProgress:)]) + [resizeDelegate_ setAnimationInProgress:inProgress]; +} + @end @implementation InfoBarContainerController (PrivateMethods) diff --git a/chrome/browser/cocoa/tab_window_controller.h b/chrome/browser/cocoa/tab_window_controller.h index ba11bb9..04346e5 100644 --- a/chrome/browser/cocoa/tab_window_controller.h +++ b/chrome/browser/cocoa/tab_window_controller.h @@ -23,12 +23,13 @@ #import "base/cocoa_protocols_mac.h" #include "base/scoped_nsobject.h" +@class FastResizeView; @class TabStripView; @class TabView; @interface TabWindowController : NSWindowController<NSWindowDelegate> { @private - IBOutlet NSView* tabContentArea_; + IBOutlet FastResizeView* tabContentArea_; IBOutlet TabStripView* tabStripView_; NSWindow* overlayWindow_; // Used during dragging for window opacity tricks NSView* cachedContentView_; // Used during dragging for identifying which @@ -38,7 +39,7 @@ BOOL closeDeferred_; // If YES, call performClose: in removeOverlay:. } @property(readonly, nonatomic) TabStripView* tabStripView; -@property(readonly, nonatomic) NSView* tabContentArea; +@property(readonly, nonatomic) FastResizeView* tabContentArea; // Used during tab dragging to turn on/off the overlay window when a tab // is torn off. If -deferPerformClose (below) is used, -removeOverlay will diff --git a/chrome/browser/cocoa/view_resizer.h b/chrome/browser/cocoa/view_resizer.h index 091222d..209f2e4 100644 --- a/chrome/browser/cocoa/view_resizer.h +++ b/chrome/browser/cocoa/view_resizer.h @@ -16,6 +16,12 @@ // become necessary due to the resize. @protocol ViewResizer <NSObject> - (void)resizeView:(NSView*)view newHeight:(float)height; + +@optional +// Optional method called when an animation is beginning or ending. Resize +// delegates can implement this method if they need to modify their behavior +// while an animation is running. +- (void)setAnimationInProgress:(BOOL)inProgress; @end #endif // CHROME_BROWSER_COCOA_VIEW_RESIZER_H_ diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index ff99cb9..691927b 100755 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -1141,6 +1141,8 @@ 'browser/cocoa/extension_view_mac.mm', 'browser/cocoa/external_protocol_dialog.h', 'browser/cocoa/external_protocol_dialog.mm', + 'browser/cocoa/fast_resize_view.h', + 'browser/cocoa/fast_resize_view.mm', 'browser/cocoa/file_metadata.h', 'browser/cocoa/file_metadata.mm', 'browser/cocoa/find_bar_bridge.h', @@ -4561,6 +4563,7 @@ 'browser/cocoa/edit_search_engine_cocoa_controller_unittest.mm', 'browser/cocoa/extension_shelf_controller_unittest.mm', 'browser/cocoa/event_utils_unittest.mm', + 'browser/cocoa/fast_resize_view_unittest.mm', 'browser/cocoa/find_bar_bridge_unittest.mm', 'browser/cocoa/find_bar_cocoa_controller_unittest.mm', 'browser/cocoa/find_bar_text_field_unittest.mm', |