From 9435c4c6cd6ef245fd9b5a66dd990400e638ae46 Mon Sep 17 00:00:00 2001 From: "bauerb@chromium.org" Date: Fri, 30 Apr 2010 08:37:22 +0000 Subject: [Mac] Make exceptions dialog a sheet. XIB changes (applying to ContentExceptionsWindow.xib and GeolocationExceptionsWindow.xib): The window is now drawn in Aqua style, with window margins, Aqua buttons and text labels for them. At the bottom right of the window there is an additional button for closing the sheet, hooked up to the |doneButton_| outlet in the file's owner and with action |closeSheet:|. The lefthand side buttons are inside a |GTMWidthBasedTweaker|, as is the done button. The actual tweaking is done by a newly added |GTMUILocalizerAndLayoutTweaker|. BUG=38021 TEST=Preferences > Under the Hood > Content Settings > Exceptions should be a sheet. Review URL: http://codereview.chromium.org/1760001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46049 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/app/nibs/ContentExceptionsWindow.xib | 490 ++++++++++++++------- chrome/app/nibs/GeolocationExceptionsWindow.xib | 303 ++++++++++--- .../cocoa/content_exceptions_window_controller.h | 15 +- .../cocoa/content_exceptions_window_controller.mm | 49 ++- .../cocoa/content_settings_dialog_controller.h | 3 + .../cocoa/content_settings_dialog_controller.mm | 16 +- .../geolocation_exceptions_window_controller.h | 9 +- .../geolocation_exceptions_window_controller.mm | 48 +- 8 files changed, 675 insertions(+), 258 deletions(-) diff --git a/chrome/app/nibs/ContentExceptionsWindow.xib b/chrome/app/nibs/ContentExceptionsWindow.xib index 1ccb4c4..9e2b30f 100644 --- a/chrome/app/nibs/ContentExceptionsWindow.xib +++ b/chrome/app/nibs/ContentExceptionsWindow.xib @@ -37,13 +37,13 @@ 15 2 - {{477, 301}, {480, 285}} + {{477, 138}, {533, 448}} 536870912 Title set by controller NSWindow {3.40282e+38, 3.40282e+38} - {200, 100} + {425, 131} 256 @@ -62,13 +62,13 @@ 256 - {480, 233} + {491, 351} YES 256 - {480, 17} + {491, 17} @@ -82,7 +82,7 @@ YES pattern - 3.020000e+02 + 3.120000e+02 4.000000e+01 1.000000e+03 @@ -141,7 +141,7 @@ action - 1.720000e+02 + 1.730000e+02 4.000000e+01 1.000000e+03 @@ -223,7 +223,7 @@ YES - {{1, 17}, {480, 233}} + {{1, 17}, {491, 351}} @@ -233,22 +233,21 @@ -2147483392 - {{466, 17}, {15, 218}} + {{368, 17}, {15, 327}} _doScroller: - 1.000000e+00 - 9.356223e-01 + 9.941860e-01 -2147483392 - {{1, 235}, {465, 15}} + {{1, 344}, {367, 15}} 1 _doScroller: - 9.979210e-01 + 9.973890e-01 @@ -257,7 +256,7 @@ YES - {{1, 0}, {480, 17}} + {{1, 0}, {491, 17}} @@ -266,7 +265,7 @@ - {{-1, 35}, {482, 251}} + {{20, 59}, {493, 369}} 562 @@ -277,85 +276,124 @@ QSAAAEEgAABBmAAAQZgAAA - + 292 - {{7, 5}, {25, 25}} - - YES - - -2080244224 - 134217728 - - - - -2033958657 - 163 - - NSImage - NSAddTemplate + + YES + + + 292 + {{14, 12}, {79, 32}} + + YES + + 67239424 + 134217728 + ^IDS_EXCEPTIONS_ADD_BUTTON + + + -2038021889 + 129 + + + + 400 + 75 + + + + + 292 + {{93, 12}, {90, 32}} + + YES + + -2080244224 + 134217728 + ^IDS_EXCEPTIONS_REMOVE_BUTTON + + + -2038021889 + 129 + + + + 400 + 75 + + + + + 292 + {{183, 12}, {124, 32}} + + YES + + -2080244224 + 134217728 + ^IDS_EXCEPTIONS_REMOVEALL_BUTTON + + + -2038021889 + 129 + + + + 400 + 75 + - - - 400 - 75 + {307, 51} + + GTMWidthBasedTweaker - + - 292 - {{40, 5}, {25, 25}} - - YES - - -2080244224 - 134217728 - - - - -2033958657 - 163 - - NSImage - NSRemoveTemplate + 289 + + YES + + + 289 + {{0, 12}, {73, 32}} + + YES + + -2080244224 + 134217728 + ^IDS_DONE + + + -2038021889 + 129 + + + + 400 + 75 + - - - 400 - 75 - - - - 292 - {{73, 5}, {96, 25}} + {{446, 0}, {87, 51}} - YES - - -2080244224 - 134217728 - ^IDS_EXCEPTIONS_PAGE_VIEW_REMOVE_ALL_BUTTON - - - -2038152961 - 163 - - - 400 - 75 - + GTMWidthBasedTweaker - {480, 285} + {533, 448} {{0, 0}, {1440, 878}} - {200, 122} + {425, 153} {3.40282e+38, 3.40282e+38} ChromeUILocalizer + + GTMUILocalizerAndLayoutTweaker + @@ -386,30 +424,6 @@ - addButton_ - - - - 22 - - - - removeButton_ - - - - 23 - - - - removeAllButton_ - - - - 24 - - - tableView_ @@ -434,27 +448,91 @@ + closeSheet: + + + + 55 + + + + removeAllExceptions: + + + + 56 + + + addException: - + - 28 + 57 removeException: - + - 29 + 58 - - removeAllExceptions: + + addButton_ + + + + 59 + + + + removeButton_ + + + + 61 + + + + removeAllButton_ + + + + 62 + + + + initialFirstResponder + + + + 63 + + + + localizer_ + + + + 65 + + + + uiObject_ + + + + 66 + + + + doneButton_ - + - 30 + 67 @@ -501,9 +579,8 @@ YES - - - + + @@ -568,74 +645,113 @@ - 14 - + 20 + + + + + 31 + YES - + - + + + + 32 + + + YES + + + - 15 - - + 33 + + - 16 - + 39 + YES - + + + - 17 - - + 44 + + + YES + + + - 18 - + 45 + YES - + - + + + + 46 + + + YES + + + - 19 - - + 47 + + - 20 - - + 48 + + - 31 - + 49 + + + + + 50 + YES - + - + - 32 - + 53 + YES - + - + - 33 - - + 54 + + + + + 64 + + @@ -648,6 +764,7 @@ -3.IBPluginDependency 1.IBEditorWindowLastContentRect 1.IBPluginDependency + 1.IBViewEditorWindowController.showingLayoutRectangles 1.IBWindowTemplateEditedContentRect 1.NSWindowTemplate.visibleAtLaunch 1.WindowOrigin @@ -657,20 +774,23 @@ 10.IBPluginDependency 11.IBPluginDependency 13.IBPluginDependency - 14.IBPluginDependency - 15.IBPluginDependency - 16.IBPluginDependency - 17.IBPluginDependency - 18.IBPluginDependency - 19.IBPluginDependency 2.IBPluginDependency 20.IBPluginDependency 31.IBPluginDependency 32.IBEditorWindowLastContentRect 32.IBPluginDependency 33.IBPluginDependency + 44.IBPluginDependency + 45.IBPluginDependency + 46.IBPluginDependency + 47.IBPluginDependency + 48.IBPluginDependency + 49.IBPluginDependency 5.IBPluginDependency + 53.IBPluginDependency + 54.IBPluginDependency 6.IBPluginDependency + 64.IBPluginDependency 7.IBPluginDependency 8.IBPluginDependency 9.IBPluginDependency @@ -680,19 +800,24 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{128, 406}, {480, 285}} + {{507, 468}, {533, 448}} com.apple.InterfaceBuilder.CocoaPlugin - {{128, 406}, {480, 285}} - + + {{507, 468}, {533, 448}} + {196, 240} {{357, 418}, {480, 270}} - - {200, 100} + + {425, 131} + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + {{13, 491}, {480, 20}} + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -700,7 +825,6 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{13, 491}, {480, 20}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -730,7 +854,7 @@ - 33 + 67 @@ -752,6 +876,7 @@ YES addException: cancel: + closeSheet: removeAllExceptions: removeException: @@ -761,6 +886,7 @@ id id id + id @@ -768,6 +894,7 @@ YES addButton_ + doneButton_ removeAllButton_ removeButton_ tableView_ @@ -777,6 +904,7 @@ NSButton NSButton NSButton + NSButton NSTableView @@ -809,6 +937,49 @@ + GTMUILocalizerAndLayoutTweaker + NSObject + + YES + + YES + localizerOwner_ + localizer_ + uiObject_ + + + YES + id + GTMUILocalizer + id + + + + IBProjectSource + ../third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h + + + + GTMWidthBasedTweaker + NSView + + YES + + YES + viewToResize_ + viewToSlideAndResize_ + viewToSlide_ + + + YES + id + NSView + NSView + + + + + NSMenuItem IBProjectSource @@ -819,6 +990,13 @@ NSObject IBProjectSource + ../third_party/GTM/Foundation/GTMNSObject+KeyValueObserving.h + + + + NSObject + + IBProjectSource browser/cocoa/status_bubble_mac.h diff --git a/chrome/app/nibs/GeolocationExceptionsWindow.xib b/chrome/app/nibs/GeolocationExceptionsWindow.xib index ed6cea4..f3c57aa 100644 --- a/chrome/app/nibs/GeolocationExceptionsWindow.xib +++ b/chrome/app/nibs/GeolocationExceptionsWindow.xib @@ -3,12 +3,12 @@ 1050 9L31a - 677 + 680 949.54 353.00 YES - + YES @@ -37,7 +37,7 @@ 15 2 - {{477, 301}, {480, 285}} + {{477, 202}, {474, 384}} 536870912 ^IDS_GEOLOCATION_EXCEPTION_TITLE NSWindow @@ -62,13 +62,13 @@ 256 - {480, 233} + {432, 287} YES 256 - {480, 17} + {432, 17} @@ -82,7 +82,7 @@ YES hostname - 3.020000e+02 + 2.750000e+02 4.000000e+01 1.000000e+03 @@ -141,7 +141,7 @@ action - 1.720000e+02 + 1.510000e+02 4.000000e+01 1.000000e+03 @@ -195,7 +195,7 @@ YES - {{1, 17}, {480, 233}} + {{1, 17}, {432, 287}} @@ -205,22 +205,21 @@ -2147483392 - {{466, 17}, {15, 218}} + {{509, 17}, {15, 270}} _doScroller: - 1.000000e+00 9.356223e-01 -2147483392 - {{1, 235}, {465, 15}} + {{1, 287}, {508, 15}} 1 _doScroller: - 9.979210e-01 + 9.980916e-01 @@ -229,7 +228,7 @@ YES - {{1, 0}, {480, 17}} + {{1, 0}, {432, 17}} @@ -238,7 +237,7 @@ - {{-1, 35}, {482, 251}} + {{20, 59}, {434, 305}} 562 @@ -249,52 +248,91 @@ QSAAAEEgAABBmAAAQZgAAA - + 292 - {{7, 5}, {25, 25}} - - YES - - -2080244224 - 134217728 - - - - -2033958657 - 163 - - NSImage - NSRemoveTemplate + + YES + + + 292 + {{106, 12}, {96, 32}} + + YES + + -2080244224 + 134217728 + ^IDS_EXCEPTIONS_REMOVEALL_BUTTON + + + -2038021889 + 129 + + + + 400 + 75 + + + + + 292 + {{14, 12}, {92, 32}} + + YES + + -2080244224 + 134217728 + ^IDS_EXCEPTIONS_REMOVE_BUTTON + + + -2038021889 + 129 + + + + 400 + 75 + - - - 400 - 75 + {202, 60} + + GTMWidthBasedTweaker - + - 292 - {{40, 5}, {96, 25}} - - YES - - -2080244224 - 134217728 - ^IDS_EXCEPTIONS_REMOVEALL_BUTTON - - - -2038152961 - 163 - - - 400 - 75 + 289 + + YES + + + 289 + {{0, 12}, {96, 32}} + + YES + + -2080244224 + 134217728 + ^IDS_DONE + + + -2038021889 + 129 + + + + 400 + 75 + + + {{364, 0}, {110, 60}} + + GTMWidthBasedTweaker - {480, 285} + {474, 384} {{0, 0}, {1440, 878}} @@ -304,6 +342,9 @@ ChromeUILocalizer + + GTMUILocalizerAndLayoutTweaker + @@ -388,6 +429,38 @@ 37 + + + closeSheet: + + + + 41 + + + + localizer_ + + + + 45 + + + + uiObject_ + + + + 46 + + + + doneButton_ + + + + 47 + @@ -432,9 +505,9 @@ YES + + - - @@ -499,13 +572,33 @@ + 20 + + + + + 38 + + + + + 42 + + + YES + + + + + + 16 YES - + 17 @@ -513,13 +606,36 @@ + 43 + + + YES + + + + + + 39 + + + YES + + + + + + 40 + + + + 18 YES - + 19 @@ -527,15 +643,10 @@ - 20 - + 44 + - - 38 - - - @@ -563,6 +674,9 @@ 2.IBPluginDependency 20.IBPluginDependency 38.IBPluginDependency + 39.IBPluginDependency + 40.IBPluginDependency + 44.IBPluginDependency 5.IBPluginDependency 6.IBPluginDependency 7.IBPluginDependency @@ -574,10 +688,10 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{128, 406}, {480, 285}} + {{125, 434}, {474, 384}} com.apple.InterfaceBuilder.CocoaPlugin - {{128, 406}, {480, 285}} - + {{125, 434}, {474, 384}} + {196, 240} {{357, 418}, {480, 270}} @@ -597,6 +711,9 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin @@ -619,7 +736,7 @@ - 38 + 47 @@ -656,12 +773,56 @@ + GTMUILocalizerAndLayoutTweaker + NSObject + + YES + + YES + localizerOwner_ + localizer_ + uiObject_ + + + YES + id + GTMUILocalizer + id + + + + IBProjectSource + ../third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h + + + + GTMWidthBasedTweaker + NSView + + YES + + YES + viewToResize_ + viewToSlideAndResize_ + viewToSlide_ + + + YES + id + NSView + NSView + + + + + GeolocationExceptionsWindowController NSWindowController YES YES + closeSheet: removeAllExceptions: removeException: @@ -669,12 +830,14 @@ YES id id + id YES YES + doneButton_ removeAllButton_ removeButton_ tableView_ @@ -683,6 +846,7 @@ YES NSButton NSButton + NSButton NSTableView @@ -695,6 +859,13 @@ NSObject IBProjectSource + ../third_party/GTM/Foundation/GTMNSObject+KeyValueObserving.h + + + + NSObject + + IBProjectSource browser/cocoa/status_bubble_mac.h diff --git a/chrome/browser/cocoa/content_exceptions_window_controller.h b/chrome/browser/cocoa/content_exceptions_window_controller.h index 91a5b33..1d1bc2a 100644 --- a/chrome/browser/cocoa/content_exceptions_window_controller.h +++ b/chrome/browser/cocoa/content_exceptions_window_controller.h @@ -24,6 +24,7 @@ class UpdatingContentSettingsObserver; IBOutlet NSButton* addButton_; IBOutlet NSButton* removeButton_; IBOutlet NSButton* removeAllButton_; + IBOutlet NSButton* doneButton_; ContentSettingsType settingsType_; HostContentSettingsMap* settingsMap_; // weak @@ -45,14 +46,22 @@ class UpdatingContentSettingsObserver; scoped_ptr newException_; } -// Shows or makes frontmost the content exceptions window for |settingsType|. +// Returns the content exceptions window controller for |settingsType|. // Changes made by the user in the window are persisted in |settingsMap|. -+ (id)showForType:(ContentSettingsType)settingsType - settingsMap:(HostContentSettingsMap*)settingsMap; ++ (id)controllerForType:(ContentSettingsType)settingsType + settingsMap:(HostContentSettingsMap*)settingsMap; + +// Shows the exceptions dialog as a modal sheet attached to |window|. +- (void)attachSheetTo:(NSWindow*)window; + +// Sets the minimum width of the sheet and resizes it if necessary. +- (void)setMinWidth:(CGFloat)minWidth; - (IBAction)addException:(id)sender; - (IBAction)removeException:(id)sender; - (IBAction)removeAllExceptions:(id)sender; +// Closes the sheet and ends the modal loop. +- (IBAction)closeSheet:(id)sender; @end diff --git a/chrome/browser/cocoa/content_exceptions_window_controller.mm b/chrome/browser/cocoa/content_exceptions_window_controller.mm index de51985..0ebcb8e 100644 --- a/chrome/browser/cocoa/content_exceptions_window_controller.mm +++ b/chrome/browser/cocoa/content_exceptions_window_controller.mm @@ -140,14 +140,13 @@ static ContentExceptionsWindowController* @implementation ContentExceptionsWindowController -+ (id)showForType:(ContentSettingsType)settingsType - settingsMap:(HostContentSettingsMap*)settingsMap { ++ (id)controllerForType:(ContentSettingsType)settingsType + settingsMap:(HostContentSettingsMap*)settingsMap { if (!g_exceptionWindows[settingsType]) { g_exceptionWindows[settingsType] = [[ContentExceptionsWindowController alloc] initWithType:settingsType settingsMap:settingsMap]; } - [g_exceptionWindows[settingsType] showWindow:nil]; return g_exceptionWindows[settingsType]; } @@ -179,12 +178,9 @@ static ContentExceptionsWindowController* [[self window] setTitle:GetWindowTitle(settingsType_)]; - // Make sure the button fits its label, but keep it the same height as the - // other two buttons. - [GTMUILocalizerAndLayoutTweaker sizeToFitView:removeAllButton_]; - NSSize size = [removeAllButton_ frame].size; - size.height = NSHeight([addButton_ frame]); - [removeAllButton_ setFrameSize:size]; + CGFloat minWidth = [[addButton_ superview] bounds].size.width + + [[doneButton_ superview] bounds].size.width; + [self setMinWidth:minWidth]; [self adjustEditingButtons]; @@ -203,12 +199,16 @@ static ContentExceptionsWindowController* NSCell* patternCell = [[tableView_ tableColumnWithIdentifier:@"pattern"] dataCell]; [patternCell setFormatter:[[[PatternFormatter alloc] init] autorelease]]; +} - // Give the button bar on the bottom of the window the "iTunes/iChat" look. - [[self window] setAutorecalculatesContentBorderThickness:NO - forEdge:NSMinYEdge]; - [[self window] setContentBorderThickness:kButtonBarHeight - forEdge:NSMinYEdge]; +- (void)setMinWidth:(CGFloat)minWidth { + NSWindow* window = [self window]; + [window setMinSize:NSMakeSize(minWidth, [window minSize].height)]; + if ([window frame].size.width < minWidth) { + NSRect frame = [window frame]; + frame.size.width = minWidth; + [window setFrame:frame display:NO]; + } } - (void)windowWillClose:(NSNotification*)notification { @@ -235,7 +235,7 @@ static ContentExceptionsWindowController* [self removeException:self]; } } else { - [self close]; + [self closeSheet:self]; } } @@ -264,6 +264,21 @@ static ContentExceptionsWindowController* [super keyDown:event]; } +- (void)attachSheetTo:(NSWindow*)window { + [NSApp beginSheet:[self window] + modalForWindow:window + modalDelegate:self + didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) + contextInfo:nil]; +} + +- (void)sheetDidEnd:(NSWindow*)sheet + returnCode:(NSInteger)returnCode + contextInfo:(void*)context { + [sheet close]; + [sheet orderOut:self]; +} + - (IBAction)addException:(id)sender { if (newException_.get()) { // The invariant is that |newException_| is non-NULL exactly if the pattern @@ -310,6 +325,10 @@ static ContentExceptionsWindowController* [self modelDidChange]; } +- (IBAction)closeSheet:(id)sender { + [NSApp endSheet:[self window]]; +} + // Table View Data Source ----------------------------------------------------- - (NSInteger)numberOfRowsInTableView:(NSTableView*)table { diff --git a/chrome/browser/cocoa/content_settings_dialog_controller.h b/chrome/browser/cocoa/content_settings_dialog_controller.h index 5f6127a..187f7f8 100644 --- a/chrome/browser/cocoa/content_settings_dialog_controller.h +++ b/chrome/browser/cocoa/content_settings_dialog_controller.h @@ -35,6 +35,9 @@ class Profile; +(id)showContentSettingsForType:(ContentSettingsType)settingsType profile:(Profile*)profile; +// Closes an exceptions sheet, if one is attached. +- (void)closeExceptionsSheet; + - (IBAction)showCookies:(id)sender; - (IBAction)openFlashPlayerSettings:(id)sender; - (IBAction)openPluginsPage:(id)sender; diff --git a/chrome/browser/cocoa/content_settings_dialog_controller.mm b/chrome/browser/cocoa/content_settings_dialog_controller.mm index 88034ff..fcca282 100644 --- a/chrome/browser/cocoa/content_settings_dialog_controller.mm +++ b/chrome/browser/cocoa/content_settings_dialog_controller.mm @@ -135,6 +135,7 @@ class PrefObserverBridge : public NotificationObserver { [g_instance selectTab:settingsType]; [g_instance showWindow:nil]; + [g_instance closeExceptionsSheet]; return g_instance; } @@ -158,6 +159,13 @@ class PrefObserverBridge : public NotificationObserver { return self; } +- (void)closeExceptionsSheet { + NSWindow* attachedSheet = [[self window] attachedSheet]; + if (attachedSheet) { + [NSApp endSheet:attachedSheet]; + } +} + - (void)awakeFromNib { DCHECK([self window]); DCHECK_EQ(self, [[self window] delegate]); @@ -304,13 +312,15 @@ class PrefObserverBridge : public NotificationObserver { - (IBAction)showGeolocationExceptions:(id)sender { GeolocationContentSettingsMap* settingsMap = profile_->GetGeolocationContentSettingsMap(); - [GeolocationExceptionsWindowController showWindowWithSettingsMap:settingsMap]; + [[GeolocationExceptionsWindowController controllerWithSettingsMap:settingsMap] + attachSheetTo:[self window]]; } - (void)showExceptionsForType:(ContentSettingsType)settingsType { HostContentSettingsMap* settingsMap = profile_->GetHostContentSettingsMap(); - [ContentExceptionsWindowController showForType:settingsType - settingsMap:settingsMap]; + [[ContentExceptionsWindowController controllerForType:settingsType + settingsMap:settingsMap] + attachSheetTo:[self window]]; } - (void)setImagesEnabledIndex:(NSInteger)value { diff --git a/chrome/browser/cocoa/geolocation_exceptions_window_controller.h b/chrome/browser/cocoa/geolocation_exceptions_window_controller.h index 9de67a1..f93b9af 100644 --- a/chrome/browser/cocoa/geolocation_exceptions_window_controller.h +++ b/chrome/browser/cocoa/geolocation_exceptions_window_controller.h @@ -20,6 +20,7 @@ class GeolocationObserverBridge; IBOutlet NSTableView* tableView_; IBOutlet NSButton* removeButton_; IBOutlet NSButton* removeAllButton_; + IBOutlet NSButton* doneButton_; GeolocationContentSettingsMap* settingsMap_; // weak scoped_ptr model_; @@ -28,7 +29,13 @@ class GeolocationObserverBridge; // Shows or makes frontmost the geolocation exceptions window. // Changes made by the user in the window are persisted in |settingsMap|. -+ (id)showWindowWithSettingsMap:(GeolocationContentSettingsMap*)settingsMap; ++ (id)controllerWithSettingsMap:(GeolocationContentSettingsMap*)settingsMap; + +// Sets the minimum width of the sheet and resizes it if necessary. +- (void)setMinWidth:(CGFloat)minWidth; + +- (void)attachSheetTo:(NSWindow*)window; +- (IBAction)closeSheet:(id)sender; - (IBAction)removeException:(id)sender; - (IBAction)removeAllExceptions:(id)sender; diff --git a/chrome/browser/cocoa/geolocation_exceptions_window_controller.mm b/chrome/browser/cocoa/geolocation_exceptions_window_controller.mm index 02715bb..7c7bee4 100644 --- a/chrome/browser/cocoa/geolocation_exceptions_window_controller.mm +++ b/chrome/browser/cocoa/geolocation_exceptions_window_controller.mm @@ -57,12 +57,11 @@ GeolocationExceptionsWindowController* g_exceptionWindow = nil; @implementation GeolocationExceptionsWindowController -+ (id)showWindowWithSettingsMap:(GeolocationContentSettingsMap*)settingsMap { ++ (id)controllerWithSettingsMap:(GeolocationContentSettingsMap*)settingsMap { if (!g_exceptionWindow) { g_exceptionWindow = [[GeolocationExceptionsWindowController alloc] initWithSettingsMap:settingsMap]; } - [g_exceptionWindow showWindow:nil]; return g_exceptionWindow; } @@ -89,20 +88,22 @@ GeolocationExceptionsWindowController* g_exceptionWindow = nil; DCHECK_EQ(self, [tableView_ dataSource]); DCHECK_EQ(self, [tableView_ delegate]); - // Make sure the button fits its label, but keep it the same height as the - // other two buttons. - [GTMUILocalizerAndLayoutTweaker sizeToFitView:removeAllButton_]; - NSSize size = [removeAllButton_ frame].size; - size.height = NSHeight([removeButton_ frame]); - [removeAllButton_ setFrameSize:size]; + CGFloat minWidth = [[removeButton_ superview] bounds].size.width + + [[doneButton_ superview] bounds].size.width; + [[self window] setMinSize:NSMakeSize(minWidth, + [[self window] minSize].height)]; [self adjustEditingButtons]; +} - // Give the button bar on the bottom of the window the "iTunes/iChat" look. - [[self window] setAutorecalculatesContentBorderThickness:NO - forEdge:NSMinYEdge]; - [[self window] setContentBorderThickness:kButtonBarHeight - forEdge:NSMinYEdge]; +- (void)setMinWidth:(CGFloat)minWidth { + NSWindow* window = [self window]; + [window setMinSize:NSMakeSize(minWidth, [window minSize].height)]; + if ([window frame].size.width < minWidth) { + NSRect frame = [window frame]; + frame.size.width = minWidth; + [window setFrame:frame display:NO]; + } } - (void)windowWillClose:(NSNotification*)notification { @@ -115,7 +116,7 @@ GeolocationExceptionsWindowController* g_exceptionWindow = nil; // Let esc close the window. - (void)cancel:(id)sender { - [self close]; + [self closeSheet:self]; } - (void)keyDown:(NSEvent*)event { @@ -133,6 +134,25 @@ GeolocationExceptionsWindowController* g_exceptionWindow = nil; [super keyDown:event]; } +- (void)attachSheetTo:(NSWindow*)window { + [NSApp beginSheet:[self window] + modalForWindow:window + modalDelegate:self + didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) + contextInfo:nil]; +} + +- (void)sheetDidEnd:(NSWindow*)sheet + returnCode:(NSInteger)returnCode + contextInfo:(void*)context { + [sheet close]; + [sheet orderOut:self]; +} + +- (IBAction)closeSheet:(id)sender { + [NSApp endSheet:[self window]]; +} + - (IBAction)removeException:(id)sender { GeolocationContentSettingsTableModel::Rows rows; [self selectedRows:&rows]; -- cgit v1.1