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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 if (view != label) { | 213 if (view != label) { |
214 origin.y += nonLabelShift; | 214 origin.y += nonLabelShift; |
215 } | 215 } |
216 [view setFrameOrigin:origin]; | 216 [view setFrameOrigin:origin]; |
217 } | 217 } |
218 | 218 |
219 // Return how much the group grew. | 219 // Return how much the group grew. |
220 return localVerticalShift + nonLabelShift; | 220 return localVerticalShift + nonLabelShift; |
221 } | 221 } |
222 | 222 |
223 // Compare function for -[NSArray sortedArrayUsingFunction:context:] that | |
224 // sorts the views in Y order bottom up. | |
225 NSInteger CompareFrameY(id view1, id view2, void* context) { | |
226 CGFloat y1 = NSMinY([view1 frame]); | |
227 CGFloat y2 = NSMinY([view2 frame]); | |
228 if (y1 < y2) | |
229 return NSOrderedAscending; | |
230 else if (y1 > y2) | |
231 return NSOrderedDescending; | |
232 else | |
233 return NSOrderedSame; | |
234 } | |
235 | |
236 // Helper to tweak the layout of the "Under the Hood" content by autosizing all | |
237 // the views and moving things up vertically. Special case the two controls for | |
238 // download location as they are horizontal, and should fill the row. | |
239 CGFloat AutoSizeUnderTheHoodContent(NSView* view, | |
240 NSPathControl* downloadLocationControl, | |
241 NSButton* downloadLocationButton) { | |
242 CGFloat verticalShift = 0.0; | |
243 | |
244 // Loop bottom up through the views sizing and shifting. | |
245 NSArray* views = [view subviews]; | |
246 views = [views sortedArrayUsingFunction:CompareFrameY context:NULL]; | |
Mark Mentovai
2009/11/03 17:35:44
Rather than assigning the same crap into the same
| |
247 for (NSView* view in views) { | |
248 NSSize delta = WrapOrSizeToFit(view); | |
249 DCHECK_GE(delta.height, 0.0) << "Should NOT shrink in height"; | |
250 if (verticalShift) { | |
251 NSPoint origin = [view frame].origin; | |
252 origin.y += verticalShift; | |
253 [view setFrameOrigin:origin]; | |
254 } | |
255 verticalShift += delta.height; | |
256 // The Download Location controls go in a row with the button aligned to the | |
Mark Mentovai
2009/11/03 17:35:44
blank before?
| |
257 // right edge and the path control using all the rest of the space. | |
258 if (view == downloadLocationButton) { | |
259 NSPoint origin = [downloadLocationButton frame].origin; | |
260 origin.x -= delta.width; | |
261 [downloadLocationButton setFrameOrigin:origin]; | |
262 NSSize controlSize = [downloadLocationControl frame].size; | |
263 controlSize.width -= delta.width; | |
264 [downloadLocationControl setFrameSize:controlSize]; | |
265 } | |
266 } | |
267 | |
268 return verticalShift; | |
269 } | |
270 | |
223 } // namespace | 271 } // namespace |
224 | 272 |
225 //------------------------------------------------------------------------- | 273 //------------------------------------------------------------------------- |
226 | 274 |
227 @interface PreferencesWindowController(Private) | 275 @interface PreferencesWindowController(Private) |
228 // Callback when preferences are changed. |prefName| is the name of the | 276 // Callback when preferences are changed. |prefName| is the name of the |
229 // pref that has changed. | 277 // pref that has changed. |
230 - (void)prefChanged:(std::wstring*)prefName; | 278 - (void)prefChanged:(std::wstring*)prefName; |
231 // Record the user performed a certain action and save the preferences. | 279 // Record the user performed a certain action and save the preferences. |
232 - (void)recordUserAction:(const wchar_t*)action; | 280 - (void)recordUserAction:(const wchar_t*)action; |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
383 widest = std::max(widest, NSWidth(underTheHoodFrame)); | 431 widest = std::max(widest, NSWidth(underTheHoodFrame)); |
384 NSWindow* prefsWindow = [self window]; | 432 NSWindow* prefsWindow = [self window]; |
385 NSRect frame = [prefsWindow frame]; | 433 NSRect frame = [prefsWindow frame]; |
386 frame.size.width = widest; | 434 frame.size.width = widest; |
387 [prefsWindow setFrame:frame display:NO]; | 435 [prefsWindow setFrame:frame display:NO]; |
388 | 436 |
389 // The Under the Hood prefs is a scroller, it shouldn't get any border, so it | 437 // The Under the Hood prefs is a scroller, it shouldn't get any border, so it |
390 // gets resized to the as wide as the window ends up. | 438 // gets resized to the as wide as the window ends up. |
391 underTheHoodFrame.size.width = widest; | 439 underTheHoodFrame.size.width = widest; |
392 [underTheHoodView_ setFrame:underTheHoodFrame]; | 440 [underTheHoodView_ setFrame:underTheHoodFrame]; |
393 // Widen the Under the Hood content so things can rewrap | 441 |
394 NSSize advancedContentSize = [advancedView_ frame].size; | 442 // Widen the Under the Hood content so things can rewrap to the full width |
395 advancedContentSize.width = [advancedScroller_ contentSize].width; | 443 NSSize underTheHoodContentSize = [underTheHoodContentView_ frame].size; |
396 [advancedView_ setFrameSize:advancedContentSize]; | 444 underTheHoodContentSize.width = [underTheHoodScroller_ contentSize].width; |
445 [underTheHoodContentView_ setFrameSize:underTheHoodContentSize]; | |
446 | |
447 // Now that Under the Hood is the right wide, spin through auto sizing things | |
Mark Mentovai
2009/11/03 17:35:44
hahaha
Now that Under the Hood is the right width
| |
448 // to that new width to get teh final height. | |
449 verticalShift = AutoSizeUnderTheHoodContent(underTheHoodContentView_, | |
450 downloadLocationControl_, | |
451 downloadLocationButton_); | |
452 [GTMUILocalizerAndLayoutTweaker | |
453 resizeViewWithoutAutoResizingSubViews:underTheHoodContentView_ | |
454 delta:NSMakeSize(0.0, verticalShift)]; | |
455 underTheHoodContentSize = [underTheHoodContentView_ frame].size; | |
397 | 456 |
398 // Adjust the view origins so they show up centered. | 457 // Adjust the view origins so they show up centered. |
399 CenterViewForWidth(basicsView_, widest); | 458 CenterViewForWidth(basicsView_, widest); |
400 CenterViewForWidth(personalStuffView_, widest); | 459 CenterViewForWidth(personalStuffView_, widest); |
401 CenterViewForWidth(underTheHoodView_, widest); | 460 CenterViewForWidth(underTheHoodView_, widest); |
402 | 461 |
403 // Put the advanced view into the scroller and scroll it to the top. | 462 // Put the Under the Hood content view into the scroller and scroll it to the |
404 [advancedScroller_ setDocumentView:advancedView_]; | 463 // top. |
405 [advancedView_ scrollPoint:NSMakePoint(0, advancedContentSize.height)]; | 464 [underTheHoodScroller_ setDocumentView:underTheHoodContentView_]; |
465 [underTheHoodContentView_ scrollPoint: | |
466 NSMakePoint(0, underTheHoodContentSize.height)]; | |
406 | 467 |
407 // Get the last visited page from local state. | 468 // Get the last visited page from local state. |
408 OptionsPage page = static_cast<OptionsPage>(lastSelectedPage_.GetValue()); | 469 OptionsPage page = static_cast<OptionsPage>(lastSelectedPage_.GetValue()); |
409 if (page == OPTIONS_PAGE_DEFAULT) | 470 if (page == OPTIONS_PAGE_DEFAULT) |
410 page = OPTIONS_PAGE_GENERAL; | 471 page = OPTIONS_PAGE_GENERAL; |
411 | 472 |
412 NSUInteger pageIndex = (NSUInteger)page; | 473 NSUInteger pageIndex = (NSUInteger)page; |
413 if (pageIndex >= [[toolbar_ items] count]) | 474 if (pageIndex >= [[toolbar_ items] count]) |
414 pageIndex = 0; | 475 pageIndex = 0; |
415 NSToolbarItem* firstItem = [[toolbar_ items] objectAtIndex:pageIndex]; | 476 NSToolbarItem* firstItem = [[toolbar_ items] objectAtIndex:pageIndex]; |
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1354 [[NSNotificationCenter defaultCenter] | 1415 [[NSNotificationCenter defaultCenter] |
1355 postNotificationName:kUserDoneEditingPrefsNotification | 1416 postNotificationName:kUserDoneEditingPrefsNotification |
1356 object:self]; | 1417 object:self]; |
1357 } | 1418 } |
1358 | 1419 |
1359 - (void)controlTextDidEndEditing:(NSNotification*)notification { | 1420 - (void)controlTextDidEndEditing:(NSNotification*)notification { |
1360 [customPagesSource_ validateURLs]; | 1421 [customPagesSource_ validateURLs]; |
1361 } | 1422 } |
1362 | 1423 |
1363 @end | 1424 @end |
OLD | NEW |