| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "chrome/browser/cocoa/content_settings_dialog_controller.h" | 5 #import "chrome/browser/cocoa/content_settings_dialog_controller.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "base/mac_util.h" | 10 #include "base/mac_util.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "chrome/common/notification_service.h" | 21 #include "chrome/common/notification_service.h" |
| 22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 23 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
| 24 #include "grit/locale_settings.h" | 24 #include "grit/locale_settings.h" |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 // Stores the currently visible content settings dialog, if any. | 28 // Stores the currently visible content settings dialog, if any. |
| 29 ContentSettingsDialogController* g_instance = nil; | 29 ContentSettingsDialogController* g_instance = nil; |
| 30 | 30 |
| 31 // Walks views in top-down order, wraps each to their current width, and moves | |
| 32 // the latter ones down to prevent overlaps. | |
| 33 CGFloat VerticallyReflowGroup(NSArray* views) { | |
| 34 views = [views sortedArrayUsingFunction:cocoa_l10n_util::CompareFrameY | |
| 35 context:NULL]; | |
| 36 CGFloat localVerticalShift = 0; | |
| 37 for (NSInteger index = [views count] - 1; index >= 0; --index) { | |
| 38 NSView* view = [views objectAtIndex:index]; | |
| 39 | |
| 40 // Since the tab pane is in a horizontal resizer in IB, it's convenient | |
| 41 // to give all the subviews flexible width so that their sizes are | |
| 42 // autoupdated in IB. However, in chrome, the subviews shouldn't have | |
| 43 // flexible widths as this looks weird. | |
| 44 [view setAutoresizingMask:NSViewMaxXMargin | NSViewMinYMargin]; | |
| 45 | |
| 46 NSSize delta = cocoa_l10n_util::WrapOrSizeToFit(view); | |
| 47 localVerticalShift += delta.height; | |
| 48 if (localVerticalShift) { | |
| 49 NSPoint origin = [view frame].origin; | |
| 50 origin.y -= localVerticalShift; | |
| 51 [view setFrameOrigin:origin]; | |
| 52 } | |
| 53 } | |
| 54 return localVerticalShift; | |
| 55 } | |
| 56 | |
| 57 } // namespace | 31 } // namespace |
| 58 | 32 |
| 59 | 33 |
| 60 @interface ContentSettingsDialogController(Private) | 34 @interface ContentSettingsDialogController(Private) |
| 61 - (id)initWithProfile:(Profile*)profile; | 35 - (id)initWithProfile:(Profile*)profile; |
| 62 - (void)selectTab:(ContentSettingsType)settingsType; | 36 - (void)selectTab:(ContentSettingsType)settingsType; |
| 63 - (void)showExceptionsForType:(ContentSettingsType)settingsType; | 37 - (void)showExceptionsForType:(ContentSettingsType)settingsType; |
| 64 | 38 |
| 65 // Callback when preferences are changed. |prefName| is the name of the | 39 // Callback when preferences are changed. |prefName| is the name of the |
| 66 // pref that has changed. | 40 // pref that has changed. |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 } | 163 } |
| 190 } | 164 } |
| 191 | 165 |
| 192 - (void)awakeFromNib { | 166 - (void)awakeFromNib { |
| 193 DCHECK([self window]); | 167 DCHECK([self window]); |
| 194 DCHECK_EQ(self, [[self window] delegate]); | 168 DCHECK_EQ(self, [[self window] delegate]); |
| 195 | 169 |
| 196 // Adapt views to potentially long localized strings. | 170 // Adapt views to potentially long localized strings. |
| 197 CGFloat windowDelta = 0; | 171 CGFloat windowDelta = 0; |
| 198 for (NSTabViewItem* tab in [tabView_ tabViewItems]) { | 172 for (NSTabViewItem* tab in [tabView_ tabViewItems]) { |
| 173 NSArray* subviews = [[tab view] subviews]; |
| 199 windowDelta = MAX(windowDelta, | 174 windowDelta = MAX(windowDelta, |
| 200 VerticallyReflowGroup([[tab view] subviews])); | 175 cocoa_l10n_util::VerticallyReflowGroup(subviews)); |
| 176 |
| 177 for (NSView* view in subviews) { |
| 178 // Since the tab pane is in a horizontal resizer in IB, it's convenient |
| 179 // to give all the subviews flexible width so that their sizes are |
| 180 // autoupdated in IB. However, in chrome, the subviews shouldn't have |
| 181 // flexible widths as this looks weird. |
| 182 [view setAutoresizingMask:NSViewMaxXMargin | NSViewMinYMargin]; |
| 183 } |
| 201 } | 184 } |
| 202 | 185 |
| 203 NSRect frame = [[self window] frame]; | 186 NSRect frame = [[self window] frame]; |
| 204 frame.origin.y -= windowDelta; | 187 frame.origin.y -= windowDelta; |
| 205 frame.size.height += windowDelta; | 188 frame.size.height += windowDelta; |
| 206 [[self window] setFrame:frame display:NO]; | 189 [[self window] setFrame:frame display:NO]; |
| 207 } | 190 } |
| 208 | 191 |
| 209 // NSWindowDelegate method. | 192 // NSWindowDelegate method. |
| 210 - (void)windowWillClose:(NSNotification*)notification { | 193 - (void)windowWillClose:(NSNotification*)notification { |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 [self willChangeValueForKey:@"popupsEnabledIndex"]; | 459 [self willChangeValueForKey:@"popupsEnabledIndex"]; |
| 477 [self didChangeValueForKey:@"popupsEnabledIndex"]; | 460 [self didChangeValueForKey:@"popupsEnabledIndex"]; |
| 478 } | 461 } |
| 479 if (*prefName == prefs::kGeolocationDefaultContentSetting) { | 462 if (*prefName == prefs::kGeolocationDefaultContentSetting) { |
| 480 [self willChangeValueForKey:@"geolocationSettingIndex"]; | 463 [self willChangeValueForKey:@"geolocationSettingIndex"]; |
| 481 [self didChangeValueForKey:@"geolocationSettingIndex"]; | 464 [self didChangeValueForKey:@"geolocationSettingIndex"]; |
| 482 } | 465 } |
| 483 } | 466 } |
| 484 | 467 |
| 485 @end | 468 @end |
| OLD | NEW |