| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/preferences_window_controller.h" | 5 #import "chrome/browser/cocoa/preferences_window_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
| 9 #include "base/mac_util.h" | 9 #include "base/mac_util.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 NSString* const kUserDoneEditingPrefsNotification = | 43 NSString* const kUserDoneEditingPrefsNotification = |
| 44 @"kUserDoneEditingPrefsNotification"; | 44 @"kUserDoneEditingPrefsNotification"; |
| 45 | 45 |
| 46 namespace { | 46 namespace { |
| 47 | 47 |
| 48 std::wstring GetNewTabUIURLString() { | 48 std::wstring GetNewTabUIURLString() { |
| 49 std::wstring temp = UTF8ToWide(chrome::kChromeUINewTabURL); | 49 std::wstring temp = UTF8ToWide(chrome::kChromeUINewTabURL); |
| 50 return URLFixerUpper::FixupURL(temp, std::wstring()); | 50 return URLFixerUpper::FixupURL(temp, std::wstring()); |
| 51 } | 51 } |
| 52 | 52 |
| 53 // Adjusts the views origin so it will be centered if in a given width parent. | |
| 54 void CenterViewForWidth(NSView* view, CGFloat width) { | |
| 55 NSRect frame = [view frame]; | |
| 56 frame.origin.x = (width - NSWidth(frame)) / 2.0; | |
| 57 [view setFrame:frame]; | |
| 58 } | |
| 59 | |
| 60 // Helper to remove all but the last view from the view heirarchy. | 53 // Helper to remove all but the last view from the view heirarchy. |
| 61 void RemoveAllButLastView(NSArray* views) { | 54 void RemoveAllButLastView(NSArray* views) { |
| 62 NSArray* toRemove = [views subarrayWithRange:NSMakeRange(0, [views count]-1)]; | 55 NSArray* toRemove = [views subarrayWithRange:NSMakeRange(0, [views count]-1)]; |
| 63 for (NSView* view in toRemove) { | 56 for (NSView* view in toRemove) { |
| 64 [view removeFromSuperviewWithoutNeedingDisplay]; | 57 [view removeFromSuperviewWithoutNeedingDisplay]; |
| 65 } | 58 } |
| 66 } | 59 } |
| 67 | 60 |
| 68 // Helper for tweaking the prefs window, if view is a: | 61 // Helper for tweaking the prefs window, if view is a: |
| 69 // checkbox, radio group or label: it gets a forced wrap at current size | 62 // checkbox, radio group or label: it gets a forced wrap at current size |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 verticalShift += AutoSizeGroup(personalStuffGroupAutofill_, | 411 verticalShift += AutoSizeGroup(personalStuffGroupAutofill_, |
| 419 kAutoSizeGroupBehaviorVerticalToFit, | 412 kAutoSizeGroupBehaviorVerticalToFit, |
| 420 verticalShift); | 413 verticalShift); |
| 421 verticalShift += AutoSizeGroup(personalStuffGroupPasswords_, | 414 verticalShift += AutoSizeGroup(personalStuffGroupPasswords_, |
| 422 kAutoSizeGroupBehaviorVerticalFirstToFit, | 415 kAutoSizeGroupBehaviorVerticalFirstToFit, |
| 423 verticalShift); | 416 verticalShift); |
| 424 [GTMUILocalizerAndLayoutTweaker | 417 [GTMUILocalizerAndLayoutTweaker |
| 425 resizeViewWithoutAutoResizingSubViews:personalStuffView_ | 418 resizeViewWithoutAutoResizingSubViews:personalStuffView_ |
| 426 delta:NSMakeSize(0.0, verticalShift)]; | 419 delta:NSMakeSize(0.0, verticalShift)]; |
| 427 | 420 |
| 428 // Make sure the window is wide enough to fit the the widest view | 421 #ifndef NDEBUG |
| 429 NSRect underTheHoodFrame = [underTheHoodView_ frame]; | 422 // Validate some assumptions in debug builds. |
| 430 CGFloat widest = std::max(NSWidth([basicsView_ frame]), | 423 |
| 431 NSWidth([personalStuffView_ frame])); | 424 // "Basics", "Personal Stuff", and "Under the Hood" views should be the same |
| 432 widest = std::max(widest, NSWidth(underTheHoodFrame)); | 425 // width. They should be the same width, so they are laid out to look as good |
| 426 // as possible at that width with controls just having to wrap if their text |
| 427 // is too long. |
| 428 DCHECK_EQ(NSWidth([basicsView_ frame]), NSWidth([personalStuffView_ frame])) |
| 429 << "Basics and Personal Stuff should be the same widths"; |
| 430 DCHECK_EQ(NSWidth([basicsView_ frame]), NSWidth([underTheHoodView_ frame])) |
| 431 << "Basics and Under the Hood should be the same widths"; |
| 432 // "Under the Hood" content should always be skinnier than the scroller it |
| 433 // goes into (we resize it). |
| 434 DCHECK_LE(NSWidth([underTheHoodContentView_ frame]), |
| 435 [underTheHoodScroller_ contentSize].width) |
| 436 << "The Under the Hood content should be narrower than the content " |
| 437 "of the scroller it goes into"; |
| 438 #endif // NDEBUG |
| 439 |
| 440 // Make the window as wide as the views |
| 433 NSWindow* prefsWindow = [self window]; | 441 NSWindow* prefsWindow = [self window]; |
| 434 NSRect frame = [prefsWindow frame]; | 442 NSRect frame = [prefsWindow frame]; |
| 435 frame.size.width = widest; | 443 frame.size.width = NSWidth([basicsView_ frame]); |
| 436 [prefsWindow setFrame:frame display:NO]; | 444 [prefsWindow setFrame:frame display:NO]; |
| 437 | 445 |
| 438 // The Under the Hood prefs is a scroller, it shouldn't get any border, so it | 446 // Widen the Under the Hood content so things can rewrap to the full width. |
| 439 // gets resized to the as wide as the window ends up. | |
| 440 underTheHoodFrame.size.width = widest; | |
| 441 [underTheHoodView_ setFrame:underTheHoodFrame]; | |
| 442 | |
| 443 // Widen the Under the Hood content so things can rewrap to the full width | |
| 444 NSSize underTheHoodContentSize = [underTheHoodContentView_ frame].size; | 447 NSSize underTheHoodContentSize = [underTheHoodContentView_ frame].size; |
| 445 underTheHoodContentSize.width = [underTheHoodScroller_ contentSize].width; | 448 underTheHoodContentSize.width = [underTheHoodScroller_ contentSize].width; |
| 446 [underTheHoodContentView_ setFrameSize:underTheHoodContentSize]; | 449 [underTheHoodContentView_ setFrameSize:underTheHoodContentSize]; |
| 447 | 450 |
| 448 // Now that Under the Hood is the right width, auto-size to the new width to | 451 // Now that Under the Hood is the right width, auto-size to the new width to |
| 449 // get the final height. | 452 // get the final height. |
| 450 verticalShift = AutoSizeUnderTheHoodContent(underTheHoodContentView_, | 453 verticalShift = AutoSizeUnderTheHoodContent(underTheHoodContentView_, |
| 451 downloadLocationControl_, | 454 downloadLocationControl_, |
| 452 downloadLocationButton_); | 455 downloadLocationButton_); |
| 453 [GTMUILocalizerAndLayoutTweaker | 456 [GTMUILocalizerAndLayoutTweaker |
| 454 resizeViewWithoutAutoResizingSubViews:underTheHoodContentView_ | 457 resizeViewWithoutAutoResizingSubViews:underTheHoodContentView_ |
| 455 delta:NSMakeSize(0.0, verticalShift)]; | 458 delta:NSMakeSize(0.0, verticalShift)]; |
| 456 underTheHoodContentSize = [underTheHoodContentView_ frame].size; | 459 underTheHoodContentSize = [underTheHoodContentView_ frame].size; |
| 457 | 460 |
| 458 // Adjust the view origins so they show up centered. | |
| 459 CenterViewForWidth(basicsView_, widest); | |
| 460 CenterViewForWidth(personalStuffView_, widest); | |
| 461 CenterViewForWidth(underTheHoodView_, widest); | |
| 462 | |
| 463 // Put the Under the Hood content view into the scroller and scroll it to the | 461 // Put the Under the Hood content view into the scroller and scroll it to the |
| 464 // top. | 462 // top. |
| 465 [underTheHoodScroller_ setDocumentView:underTheHoodContentView_]; | 463 [underTheHoodScroller_ setDocumentView:underTheHoodContentView_]; |
| 466 [underTheHoodContentView_ scrollPoint: | 464 [underTheHoodContentView_ scrollPoint: |
| 467 NSMakePoint(0, underTheHoodContentSize.height)]; | 465 NSMakePoint(0, underTheHoodContentSize.height)]; |
| 468 | 466 |
| 469 // Get the last visited page from local state. | 467 // Get the last visited page from local state. |
| 470 OptionsPage page = static_cast<OptionsPage>(lastSelectedPage_.GetValue()); | 468 OptionsPage page = static_cast<OptionsPage>(lastSelectedPage_.GetValue()); |
| 471 if (page == OPTIONS_PAGE_DEFAULT) | 469 if (page == OPTIONS_PAGE_DEFAULT) |
| 472 page = OPTIONS_PAGE_GENERAL; | 470 page = OPTIONS_PAGE_GENERAL; |
| (...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1416 [[NSNotificationCenter defaultCenter] | 1414 [[NSNotificationCenter defaultCenter] |
| 1417 postNotificationName:kUserDoneEditingPrefsNotification | 1415 postNotificationName:kUserDoneEditingPrefsNotification |
| 1418 object:self]; | 1416 object:self]; |
| 1419 } | 1417 } |
| 1420 | 1418 |
| 1421 - (void)controlTextDidEndEditing:(NSNotification*)notification { | 1419 - (void)controlTextDidEndEditing:(NSNotification*)notification { |
| 1422 [customPagesSource_ validateURLs]; | 1420 [customPagesSource_ validateURLs]; |
| 1423 } | 1421 } |
| 1424 | 1422 |
| 1425 @end | 1423 @end |
| OLD | NEW |