diff options
author | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-09 19:22:09 +0000 |
---|---|---|
committer | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-09 19:22:09 +0000 |
commit | eb282f62d3465f6cbc050b4c5dd761f14479a838 (patch) | |
tree | a2c25d0b030be222a88a2b725697ed77faa0f05d | |
parent | 004b6c51c2f9105da946f3b2624472ba0aca8795 (diff) | |
download | chromium_src-eb282f62d3465f6cbc050b4c5dd761f14479a838.zip chromium_src-eb282f62d3465f6cbc050b4c5dd761f14479a838.tar.gz chromium_src-eb282f62d3465f6cbc050b4c5dd761f14479a838.tar.bz2 |
Modifies the growbox behavior to be more Mac-like.
Nib file changes:
- Set the min browser window size to 400x250.
BUG=http://crbug.com/11844
BUG=http://crbug.com/13015
BUG=http://crbug.com/13017
TEST=Verify that windows have a minimum size. Verify that (with a
single monitor) windows cannot be resized into the dock area, unless
their lower right corner started in the dock area. Verify that
windows can be resized across multiple monitors.
Review URL: http://codereview.chromium.org/118439
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17965 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/nibs/en.lproj/BrowserWindow.xib | 14 | ||||
-rw-r--r-- | chrome/browser/cocoa/browser_window_controller.mm | 13 | ||||
-rw-r--r-- | chrome/browser/cocoa/grow_box_view.h | 3 | ||||
-rw-r--r-- | chrome/browser/cocoa/grow_box_view.m | 71 |
4 files changed, 92 insertions, 9 deletions
diff --git a/chrome/app/nibs/en.lproj/BrowserWindow.xib b/chrome/app/nibs/en.lproj/BrowserWindow.xib index 2240ebf..a73b489 100644 --- a/chrome/app/nibs/en.lproj/BrowserWindow.xib +++ b/chrome/app/nibs/en.lproj/BrowserWindow.xib @@ -2,13 +2,14 @@ <archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.03"> <data> <int key="IBDocument.SystemTarget">1050</int> - <string key="IBDocument.SystemVersion">9G55</string> + <string key="IBDocument.SystemVersion">9J61</string> <string key="IBDocument.InterfaceBuilderVersion">677</string> - <string key="IBDocument.AppKitVersion">949.43</string> + <string key="IBDocument.AppKitVersion">949.46</string> <string key="IBDocument.HIToolboxVersion">353.00</string> <object class="NSMutableArray" key="IBDocument.EditedObjectIDs"> <bool key="EncodedWithXMLCoder">YES</bool> <integer value="56"/> + <integer value="1"/> </object> <object class="NSArray" key="IBDocument.PluginDependencies"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -43,8 +44,9 @@ <string key="NSWindowClass">NSWindow</string> <nil key="NSViewClass"/> <string key="NSWindowContentMaxSize">{3.40282e+38, 3.40282e+38}</string> + <string key="NSWindowContentMinSize">{400, 250}</string> <object class="NSView" key="NSWindowView" id="1006"> - <nil key="NSNextResponder"/> + <reference key="NSNextResponder"/> <int key="NSvFlags">256</int> <object class="NSMutableArray" key="NSSubviews"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -57,8 +59,10 @@ </object> </object> <string key="NSFrameSize">{750, 600}</string> + <reference key="NSSuperview"/> </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> </object> <object class="NSCustomView" id="1029219716"> @@ -228,6 +232,8 @@ <string>1.NSWindowTemplate.visibleAtLaunch</string> <string>1.WindowOrigin</string> <string>1.editorWindowContentRectSynchronizationRect</string> + <string>1.windowTemplate.hasMinSize</string> + <string>1.windowTemplate.minSize</string> <string>2.IBPluginDependency</string> <string>2.IBViewIntegration.shadowBlurRadius</string> <string>2.IBViewIntegration.shadowColor</string> @@ -250,6 +256,8 @@ <boolean value="NO"/> <string>{196, 240}</string> <string>{{357, 418}, {480, 270}}</string> + <boolean value="YES"/> + <string>{400, 250}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <real value="0.000000e+00"/> <object class="NSColor"> diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm index f8342d0..99a0737 100644 --- a/chrome/browser/cocoa/browser_window_controller.mm +++ b/chrome/browser/cocoa/browser_window_controller.mm @@ -110,9 +110,18 @@ willPositionSheet:(NSWindow *)sheet name:nil object:[self tabContentArea]]; - // Get the most appropriate size for the window. The window shim will handle - // flipping the coordinates for us so we can use it to save some code. + // Get the most appropriate size for the window, then enforce the + // minimum width and height. The window shim will handle flipping + // the coordinates for us so we can use it to save some code. + // Note that this may leave a significant portion of the window + // offscreen, but there will always be enough window onscreen to + // drag the whole window back into view. + NSSize minSize = [[self window] minSize]; gfx::Rect windowRect = browser_->GetSavedWindowBounds(); + if (windowRect.width() < minSize.width) + windowRect.set_width(minSize.width); + if (windowRect.height() < minSize.height) + windowRect.set_height(minSize.height); windowShim_->SetBounds(windowRect); // Create a controller for the tab strip, giving it the model object for diff --git a/chrome/browser/cocoa/grow_box_view.h b/chrome/browser/cocoa/grow_box_view.h index 60c51f0..04b6fd2 100644 --- a/chrome/browser/cocoa/grow_box_view.h +++ b/chrome/browser/cocoa/grow_box_view.h @@ -15,6 +15,9 @@ @interface GrowBoxView : NSView { @private NSImage* image_; // grow box image + NSPoint startPoint_; // location of the mouseDown event. + NSRect startFrame_; // original window frame. + NSRect clipRect_; // constrain the resized window to this frame. } @end diff --git a/chrome/browser/cocoa/grow_box_view.m b/chrome/browser/cocoa/grow_box_view.m index d7ace41..5f74b08 100644 --- a/chrome/browser/cocoa/grow_box_view.m +++ b/chrome/browser/cocoa/grow_box_view.m @@ -4,6 +4,20 @@ #import "chrome/browser/cocoa/grow_box_view.h" +@interface GrowBoxView (PrivateMethods) + +// Computes the area in which the resized window can grow. This is +// the union of the current window frame and the work area of each +// screen. +// NOTE: If the lower right corner of the window is on a screen but +// outside its work area, we use the full area of that screen instead. +// The net effect is to closely mimic the resize behavior of other +// apps: the window is prevented from growing outside the work area, +// unless it is outside the work area to begin with. +- (void)computeClipRect; + +@end + @implementation GrowBoxView - (void)awakeFromNib { @@ -21,14 +35,63 @@ operation:NSCompositeSourceOver fraction:1.0]; } +- (void)mouseDown:(NSEvent*)event { + startPoint_ = [NSEvent mouseLocation]; + startFrame_ = [[self window] frame]; + [self computeClipRect]; +} + // Called when the user clicks and drags within the bounds. Resize the window's // frame based on the delta of the drag. - (void)mouseDragged:(NSEvent*)event { - NSRect frame = [[self window] frame]; - frame.size.width += [event deltaX]; - frame.origin.y -= [event deltaY]; - frame.size.height += [event deltaY]; + NSPoint point = [NSEvent mouseLocation]; + const int deltaX = point.x - startPoint_.x; + const int deltaY = point.y - startPoint_.y; + + NSRect frame = startFrame_; + frame.size.width = frame.size.width + deltaX; + frame.origin.y = frame.origin.y + deltaY; + frame.size.height = frame.size.height - deltaY; + + // Enforce that the frame is entirely contained within the computed clipRect. + if (NSMaxX(frame) > NSMaxX(clipRect_)) + frame.size.width = NSMaxX(clipRect_) - frame.origin.x; + if (NSMinY(frame) < NSMinY(clipRect_)) { + int maxY = NSMaxY(frame); + frame.origin.y = NSMinY(clipRect_); + frame.size.height = maxY - frame.origin.y; + } + + // Enforce min window size. + NSSize minSize = [[self window] minSize]; + if (frame.size.width < minSize.width) + frame.size.width = minSize.width; + if (frame.size.height < minSize.height) { + frame.origin.y = NSMaxY(startFrame_) - minSize.height; + frame.size.height = minSize.height; + } + [[self window] setFrame:frame display:YES]; } @end + +@implementation GrowBoxView (PrivateMethods) +- (void)computeClipRect { + // Start with the current frame. It makes sense to allow users to + // resize up to this size. + clipRect_ = startFrame_; + + // Calculate the union of all the screen work areas. If the lower + // right corner of the window is outside a work area, that use that + // screen's frame instead. + NSPoint lowerRight = NSMakePoint(NSMaxX(startFrame_), NSMinY(startFrame_)); + for (NSScreen* screen in [NSScreen screens]) { + if (!NSPointInRect(lowerRight, [screen visibleFrame]) && + NSPointInRect(lowerRight, [screen frame])) + clipRect_ = NSUnionRect(clipRect_, [screen frame]); + else + clipRect_ = NSUnionRect(clipRect_, [screen visibleFrame]); + } +} +@end |