Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(469)

Side by Side Diff: chrome/browser/ui/cocoa/website_settings_bubble_controller.mm

Issue 11417082: [Mac] Website settings: Enlarge window when permission strings are too long. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add unit test. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/cocoa/website_settings_bubble_controller.h" 5 #import "chrome/browser/ui/cocoa/website_settings_bubble_controller.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #import <AppKit/AppKit.h> 9 #import <AppKit/AppKit.h>
10 10
(...skipping 19 matching lines...) Expand all
30 #include "grit/generated_resources.h" 30 #include "grit/generated_resources.h"
31 #include "grit/theme_resources.h" 31 #include "grit/theme_resources.h"
32 #include "grit/ui_resources.h" 32 #include "grit/ui_resources.h"
33 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" 33 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h"
34 #include "ui/base/l10n/l10n_util.h" 34 #include "ui/base/l10n/l10n_util.h"
35 #include "ui/base/resource/resource_bundle.h" 35 #include "ui/base/resource/resource_bundle.h"
36 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" 36 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
37 37
38 namespace { 38 namespace {
39 39
40 // The width of the window, in view coordinates. The height will be determined 40 // The default width of the window, in view coordinates. It may be larger to
41 // by the content. 41 // fit the content.
42 const CGFloat kWindowWidth = 310; 42 const CGFloat kDefaultWindowWidth = 310;
43 43
44 // Spacing in between sections. 44 // Spacing in between sections.
45 const CGFloat kVerticalSpacing = 10; 45 const CGFloat kVerticalSpacing = 10;
46 46
47 // Padding between the window frame and content. 47 // Padding between the window frame and content.
48 const CGFloat kFramePadding = 20; 48 const CGFloat kFramePadding = 20;
49 49
50 // Padding between the window frame and content for the internal page bubble. 50 // Padding between the window frame and content for the internal page bubble.
51 const CGFloat kInternalPageFramePadding = 10; 51 const CGFloat kInternalPageFramePadding = 10;
52 52
(...skipping 24 matching lines...) Expand all
77 77
78 // The spacing between individual items in the Permissions tab. 78 // The spacing between individual items in the Permissions tab.
79 const CGFloat kPermissionsTabSpacing = 12; 79 const CGFloat kPermissionsTabSpacing = 12;
80 80
81 // Extra spacing after a headline on the Permissions tab. 81 // Extra spacing after a headline on the Permissions tab.
82 const CGFloat kPermissionsHeadlineSpacing = 2; 82 const CGFloat kPermissionsHeadlineSpacing = 2;
83 83
84 // The amount of horizontal space between a permission label and the popup. 84 // The amount of horizontal space between a permission label and the popup.
85 const CGFloat kPermissionPopUpXSpacing = 3; 85 const CGFloat kPermissionPopUpXSpacing = 3;
86 86
87 // The amount of horizontal space between the permission popup title and the
88 // arrow icon.
89 const CGFloat kPermissionButtonTitleRightPadding = 4;
90
87 // The extra space to the left of the first tab in the tab strip. 91 // The extra space to the left of the first tab in the tab strip.
88 const CGFloat kTabStripXPadding = kFramePadding; 92 const CGFloat kTabStripXPadding = kFramePadding;
89 93
90 // The amount of space between the visual borders of adjacent tabs. 94 // The amount of space between the visual borders of adjacent tabs.
91 const CGFloat kTabSpacing = 4; 95 const CGFloat kTabSpacing = 4;
92 96
93 // The amount of space above the tab strip. 97 // The amount of space above the tab strip.
94 const CGFloat kTabStripTopSpacing = 14; 98 const CGFloat kTabStripTopSpacing = 14;
95 99
96 // The height of the clickable area of the tab. 100 // The height of the clickable area of the tab.
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 nil, 197 nil,
194 tabstripCenterImage_, 198 tabstripCenterImage_,
195 tabstripLeftImage_, 199 tabstripLeftImage_,
196 /*vertical=*/ NO, 200 /*vertical=*/ NO,
197 NSCompositeSourceOver, 201 NSCompositeSourceOver,
198 1, 202 1,
199 /*flipped=*/ YES); 203 /*flipped=*/ YES);
200 204
201 // Draw the background to the right of the selected tab. 205 // Draw the background to the right of the selected tab.
202 backgroundRect.origin.x = NSMaxX(tabRect); 206 backgroundRect.origin.x = NSMaxX(tabRect);
203 backgroundRect.size.width = kWindowWidth - NSMaxX(tabRect); 207 backgroundRect.size.width = NSMaxX(cellFrame) - NSMaxX(tabRect);
204 NSDrawThreePartImage(backgroundRect, 208 NSDrawThreePartImage(backgroundRect,
205 tabstripRightImage_, 209 tabstripRightImage_,
206 tabstripCenterImage_, 210 tabstripCenterImage_,
207 nil, 211 nil,
208 /*vertical=*/ NO, 212 /*vertical=*/ NO,
209 NSCompositeSourceOver, 213 NSCompositeSourceOver,
210 1, 214 1,
211 /*flipped=*/ YES); 215 /*flipped=*/ YES);
212 216
213 // Call the superclass method to trigger drawing of the tab labels. 217 // Call the superclass method to trigger drawing of the tab labels.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 // Returns the minimum size required to display this cell. 282 // Returns the minimum size required to display this cell.
279 // It should always be exactly as tall as the tabstrip background image. 283 // It should always be exactly as tall as the tabstrip background image.
280 - (NSSize)cellSize { 284 - (NSSize)cellSize {
281 return NSMakeSize([super cellSize].width, 285 return NSMakeSize([super cellSize].width,
282 [tabstripCenterImage_ size].height); 286 [tabstripCenterImage_ size].height);
283 } 287 }
284 @end 288 @end
285 289
286 @implementation WebsiteSettingsBubbleController 290 @implementation WebsiteSettingsBubbleController
287 291
292 // Return the default width of the window. It may be wider to fit the content.
Robert Sesek 2012/11/26 17:06:56 Move this to the .h since it's a public member.
Patrick Dubroy 2012/11/27 12:11:30 Done.
293 // This may be overriden by a subclass for testing purposes.
294 - (CGFloat)defaultWindowWidth {
295 return kDefaultWindowWidth;
296 }
297
288 - (id)initWithParentWindow:(NSWindow*)parentWindow 298 - (id)initWithParentWindow:(NSWindow*)parentWindow
289 websiteSettingsUIBridge:(WebsiteSettingsUIBridge*)bridge 299 websiteSettingsUIBridge:(WebsiteSettingsUIBridge*)bridge
290 tabContents:(TabContents*)tabContents 300 tabContents:(TabContents*)tabContents
291 isInternalPage:(BOOL)isInternalPage { 301 isInternalPage:(BOOL)isInternalPage {
292 DCHECK(parentWindow); 302 DCHECK(parentWindow);
293 303
294 tabContents_ = tabContents; 304 tabContents_ = tabContents;
295 305
296 // Use an arbitrary height; it will be changed in performLayout. 306 // Use an arbitrary height; it will be changed in performLayout.
297 NSRect contentRect = NSMakeRect(0, 0, kWindowWidth, 1); 307 NSRect contentRect = NSMakeRect(0, 0, [self defaultWindowWidth], 1);
298 // Create an empty window into which content is placed. 308 // Create an empty window into which content is placed.
299 scoped_nsobject<InfoBubbleWindow> window( 309 scoped_nsobject<InfoBubbleWindow> window(
300 [[InfoBubbleWindow alloc] initWithContentRect:contentRect 310 [[InfoBubbleWindow alloc] initWithContentRect:contentRect
301 styleMask:NSBorderlessWindowMask 311 styleMask:NSBorderlessWindowMask
302 backing:NSBackingStoreBuffered 312 backing:NSBackingStoreBuffered
303 defer:NO]); 313 defer:NO]);
304 314
305 if ((self = [super initWithWindow:window.get() 315 if ((self = [super initWithWindow:window.get()
306 parentWindow:parentWindow 316 parentWindow:parentWindow
307 anchoredAt:NSZeroPoint])) { 317 anchoredAt:NSZeroPoint])) {
308 [[self bubble] setArrowLocation:info_bubble::kTopLeft]; 318 [[self bubble] setArrowLocation:info_bubble::kTopLeft];
309 319
310 // Create the container view that uses flipped coordinates. 320 // Create the container view that uses flipped coordinates.
311 NSRect contentFrame = NSMakeRect(0, 0, kWindowWidth, 300); 321 NSRect contentFrame = NSMakeRect(0, 0, [self defaultWindowWidth], 300);
312 contentView_.reset( 322 contentView_.reset(
313 [[FlippedView alloc] initWithFrame:contentFrame]); 323 [[FlippedView alloc] initWithFrame:contentFrame]);
314 324
315 // Replace the window's content. 325 // Replace the window's content.
316 [[[self window] contentView] setSubviews: 326 [[[self window] contentView] setSubviews:
317 [NSArray arrayWithObject:contentView_.get()]]; 327 [NSArray arrayWithObject:contentView_.get()]];
318 328
319 if (isInternalPage) 329 if (isInternalPage)
320 [self initializeContentsForInternalPage]; 330 [self initializeContentsForInternalPage];
321 else 331 else
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 toView:contentView_ 369 toView:contentView_
360 atPoint:controlOrigin]; 370 atPoint:controlOrigin];
361 // Center the text vertically with the image. 371 // Center the text vertically with the image.
362 NSRect textFrame = [textField frame]; 372 NSRect textFrame = [textField frame];
363 textFrame.origin.y += (imageSize.height - NSHeight(textFrame)) / 2; 373 textFrame.origin.y += (imageSize.height - NSHeight(textFrame)) / 2;
364 [textField setFrame:textFrame]; 374 [textField setFrame:textFrame];
365 375
366 // Adjust the contentView to fit everything. 376 // Adjust the contentView to fit everything.
367 CGFloat maxY = std::max(NSMaxY([imageView frame]), NSMaxY(textFrame)); 377 CGFloat maxY = std::max(NSMaxY([imageView frame]), NSMaxY(textFrame));
368 [contentView_ setFrame:NSMakeRect( 378 [contentView_ setFrame:NSMakeRect(
369 0, 0, kWindowWidth, maxY + kInternalPageFramePadding)]; 379 0, 0, [self defaultWindowWidth], maxY + kInternalPageFramePadding)];
370 380
371 [self sizeAndPositionWindow]; 381 [self sizeAndPositionWindow];
372 } 382 }
373 383
374 // Create the subviews for the website settings bubble. 384 // Create the subviews for the website settings bubble.
375 - (void)initializeContents { 385 - (void)initializeContents {
376 // Keeps track of the position that the next control should be drawn at. 386 // Keeps track of the position that the next control should be drawn at.
377 NSPoint controlOrigin = NSMakePoint( 387 NSPoint controlOrigin = NSMakePoint(
378 kFramePadding, 388 kFramePadding,
379 kFramePadding + info_bubble::kBubbleArrowHeight); 389 kFramePadding + info_bubble::kBubbleArrowHeight);
(...skipping 12 matching lines...) Expand all
392 withSize:[NSFont smallSystemFontSize] 402 withSize:[NSFont smallSystemFontSize]
393 bold:NO 403 bold:NO
394 toView:contentView_ 404 toView:contentView_
395 atPoint:controlOrigin]; 405 atPoint:controlOrigin];
396 406
397 // Create the tab view and its two tabs. 407 // Create the tab view and its two tabs.
398 408
399 scoped_nsobject<WebsiteSettingsTabSegmentedCell> cell( 409 scoped_nsobject<WebsiteSettingsTabSegmentedCell> cell(
400 [[WebsiteSettingsTabSegmentedCell alloc] init]); 410 [[WebsiteSettingsTabSegmentedCell alloc] init]);
401 CGFloat tabstripHeight = [cell cellSize].height; 411 CGFloat tabstripHeight = [cell cellSize].height;
402 NSRect tabstripFrame = NSMakeRect(0, 0, kWindowWidth, tabstripHeight); 412 NSRect tabstripFrame = NSMakeRect(
413 0, 0, [self defaultWindowWidth], tabstripHeight);
403 segmentedControl_.reset( 414 segmentedControl_.reset(
404 [[NSSegmentedControl alloc] initWithFrame:tabstripFrame]); 415 [[NSSegmentedControl alloc] initWithFrame:tabstripFrame]);
405 [segmentedControl_ setCell:cell]; 416 [segmentedControl_ setCell:cell];
406 [segmentedControl_ setSegmentCount:WebsiteSettingsUI::NUM_TAB_IDS]; 417 [segmentedControl_ setSegmentCount:WebsiteSettingsUI::NUM_TAB_IDS];
407 [segmentedControl_ setTarget:self]; 418 [segmentedControl_ setTarget:self];
408 [segmentedControl_ setAction:@selector(tabSelected:)]; 419 [segmentedControl_ setAction:@selector(tabSelected:)];
420 [segmentedControl_ setAutoresizingMask:NSViewWidthSizable];
409 421
410 NSFont* smallSystemFont = 422 NSFont* smallSystemFont =
411 [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; 423 [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
412 NSDictionary* textAttributes = 424 NSDictionary* textAttributes =
413 [NSDictionary dictionaryWithObject:smallSystemFont 425 [NSDictionary dictionaryWithObject:smallSystemFont
414 forKey:NSFontAttributeName]; 426 forKey:NSFontAttributeName];
415 427
416 // Create the "Permissions" tab. 428 // Create the "Permissions" tab.
417 NSString* label = l10n_util::GetNSString( 429 NSString* label = l10n_util::GetNSString(
418 IDS_WEBSITE_SETTINGS_TAB_LABEL_PERMISSIONS); 430 IDS_WEBSITE_SETTINGS_TAB_LABEL_PERMISSIONS);
(...skipping 18 matching lines...) Expand all
437 tabWidth = std::max(tabWidth, 449 tabWidth = std::max(tabWidth,
438 textSize.width + 2 * kTabLabelXPadding); 450 textSize.width + 2 * kTabLabelXPadding);
439 [segmentedControl_ setWidth:tabWidth + kTabStripXPadding 451 [segmentedControl_ setWidth:tabWidth + kTabStripXPadding
440 forSegment:WebsiteSettingsUI::TAB_ID_PERMISSIONS]; 452 forSegment:WebsiteSettingsUI::TAB_ID_PERMISSIONS];
441 [segmentedControl_ setWidth:tabWidth 453 [segmentedControl_ setWidth:tabWidth
442 forSegment:WebsiteSettingsUI::TAB_ID_CONNECTION]; 454 forSegment:WebsiteSettingsUI::TAB_ID_CONNECTION];
443 455
444 [segmentedControl_ setFont:smallSystemFont]; 456 [segmentedControl_ setFont:smallSystemFont];
445 [contentView_ addSubview:segmentedControl_]; 457 [contentView_ addSubview:segmentedControl_];
446 458
447 NSRect tabFrame = NSMakeRect(0, 0, kWindowWidth, 300); 459 NSRect tabFrame = NSMakeRect(0, 0, [self defaultWindowWidth], 300);
448 tabView_.reset([[NSTabView alloc] initWithFrame:tabFrame]); 460 tabView_.reset([[NSTabView alloc] initWithFrame:tabFrame]);
449 [tabView_ setTabViewType:NSNoTabsNoBorder]; 461 [tabView_ setTabViewType:NSNoTabsNoBorder];
450 [tabView_ setDrawsBackground:NO]; 462 [tabView_ setDrawsBackground:NO];
451 [tabView_ setControlSize:NSSmallControlSize]; 463 [tabView_ setControlSize:NSSmallControlSize];
452 [contentView_ addSubview:tabView_.get()]; 464 [contentView_ addSubview:tabView_.get()];
453 465
454 permissionsTabContentView_ = [self addPermissionsTabToTabView:tabView_]; 466 permissionsTabContentView_ = [self addPermissionsTabToTabView:tabView_];
455 connectionTabContentView_ = [self addConnectionTabToTabView:tabView_]; 467 connectionTabContentView_ = [self addConnectionTabToTabView:tabView_];
456 [self setSelectedTab:WebsiteSettingsUI::TAB_ID_PERMISSIONS]; 468 [self setSelectedTab:WebsiteSettingsUI::TAB_ID_PERMISSIONS];
457 469
458 [self performLayout]; 470 [self performLayout];
459 } 471 }
460 472
461 // Create the contents of the Permissions tab and add it to the given tab view. 473 // Create the contents of the Permissions tab and add it to the given tab view.
462 // Returns a weak reference to the tab view item's view. 474 // Returns a weak reference to the tab view item's view.
463 - (NSView*)addPermissionsTabToTabView:(NSTabView*)tabView { 475 - (NSView*)addPermissionsTabToTabView:(NSTabView*)tabView {
464 scoped_nsobject<NSTabViewItem> item([[NSTabViewItem alloc] init]); 476 scoped_nsobject<NSTabViewItem> item([[NSTabViewItem alloc] init]);
465 [tabView_ insertTabViewItem:item.get() 477 [tabView_ insertTabViewItem:item.get()
466 atIndex:WebsiteSettingsUI::TAB_ID_PERMISSIONS]; 478 atIndex:WebsiteSettingsUI::TAB_ID_PERMISSIONS];
467 scoped_nsobject<NSView> contentView([[FlippedView alloc] 479 scoped_nsobject<NSView> contentView([[FlippedView alloc]
468 initWithFrame:[tabView_ contentRect]]); 480 initWithFrame:[tabView_ contentRect]]);
481 [contentView setAutoresizingMask:NSViewWidthSizable];
469 [item setView:contentView.get()]; 482 [item setView:contentView.get()];
470 483
471 // Initialize the two containers that hold the controls. The initial frames 484 // Initialize the two containers that hold the controls. The initial frames
472 // are arbitrary, and will be adjusted after the controls are laid out. 485 // are arbitrary, and will be adjusted after the controls are laid out.
473 cookiesView_ = [[[FlippedView alloc] 486 cookiesView_ = [[[FlippedView alloc]
474 initWithFrame:[tabView_ contentRect]] autorelease]; 487 initWithFrame:[tabView_ contentRect]] autorelease];
488 [cookiesView_ setAutoresizingMask:NSViewWidthSizable];
489
475 permissionsView_ = [[[FlippedView alloc] 490 permissionsView_ = [[[FlippedView alloc]
476 initWithFrame:[tabView_ contentRect]] autorelease]; 491 initWithFrame:[tabView_ contentRect]] autorelease];
477 492
478 [contentView addSubview:cookiesView_]; 493 [contentView addSubview:cookiesView_];
479 [contentView addSubview:permissionsView_]; 494 [contentView addSubview:permissionsView_];
480 495
481 // Create the link button to view cookies and site data. 496 // Create the link button to view cookies and site data.
482 // Its position will be set in performLayout. 497 // Its position will be set in performLayout.
483 NSString* cookieButtonText = l10n_util::GetNSString( 498 NSString* cookieButtonText = l10n_util::GetNSString(
484 IDS_WEBSITE_SETTINGS_SHOW_SITE_DATA); 499 IDS_WEBSITE_SETTINGS_SHOW_SITE_DATA);
(...skipping 30 matching lines...) Expand all
515 content::PAGE_TRANSITION_LINK, 530 content::PAGE_TRANSITION_LINK,
516 false)); 531 false));
517 } 532 }
518 533
519 // Create the contents of the Connection tab and add it to the given tab view. 534 // Create the contents of the Connection tab and add it to the given tab view.
520 // Returns a weak reference to the tab view item's view. 535 // Returns a weak reference to the tab view item's view.
521 - (NSView*)addConnectionTabToTabView:(NSTabView*)tabView { 536 - (NSView*)addConnectionTabToTabView:(NSTabView*)tabView {
522 scoped_nsobject<NSTabViewItem> item([[NSTabViewItem alloc] init]); 537 scoped_nsobject<NSTabViewItem> item([[NSTabViewItem alloc] init]);
523 scoped_nsobject<NSView> contentView([[FlippedView alloc] 538 scoped_nsobject<NSView> contentView([[FlippedView alloc]
524 initWithFrame:[tabView_ contentRect]]); 539 initWithFrame:[tabView_ contentRect]]);
540 [contentView setAutoresizingMask:NSViewWidthSizable];
525 541
526 // Place all the text and images at the same position. The positions will be 542 // Place all the text and images at the same position. The positions will be
527 // adjusted in performLayout. 543 // adjusted in performLayout.
528 NSPoint textPosition = NSMakePoint( 544 NSPoint textPosition = NSMakePoint(
529 kFramePadding + kConnectionImageSize + kConnectionImageSpacing, 545 kFramePadding + kConnectionImageSize + kConnectionImageSpacing,
530 kFramePadding); 546 kFramePadding);
531 NSPoint imagePosition = NSMakePoint(kFramePadding, kFramePadding); 547 NSPoint imagePosition = NSMakePoint(kFramePadding, kFramePadding);
532 NSSize imageSize = NSMakeSize(kConnectionImageSize, kConnectionImageSize); 548 NSSize imageSize = NSMakeSize(kConnectionImageSize, kConnectionImageSize);
533 549
534 identityStatusIcon_ = [self addImageWithSize:imageSize 550 identityStatusIcon_ = [self addImageWithSize:imageSize
535 toView:contentView 551 toView:contentView
536 atPoint:imagePosition]; 552 atPoint:imagePosition];
537 identityStatusDescriptionField_ = 553 identityStatusDescriptionField_ =
538 [self addText:string16() 554 [self addText:string16()
539 withSize:[NSFont smallSystemFontSize] 555 withSize:[NSFont smallSystemFontSize]
540 bold:NO 556 bold:NO
541 toView:contentView.get() 557 toView:contentView.get()
542 atPoint:textPosition]; 558 atPoint:textPosition];
559
543 separatorAfterIdentity_ = [self addSeparatorToView:contentView]; 560 separatorAfterIdentity_ = [self addSeparatorToView:contentView];
561 [separatorAfterIdentity_ setAutoresizingMask:NSViewWidthSizable];
544 562
545 connectionStatusIcon_ = [self addImageWithSize:imageSize 563 connectionStatusIcon_ = [self addImageWithSize:imageSize
546 toView:contentView 564 toView:contentView
547 atPoint:imagePosition]; 565 atPoint:imagePosition];
548 connectionStatusDescriptionField_ = 566 connectionStatusDescriptionField_ =
549 [self addText:string16() 567 [self addText:string16()
550 withSize:[NSFont smallSystemFontSize] 568 withSize:[NSFont smallSystemFontSize]
551 bold:NO 569 bold:NO
552 toView:contentView.get() 570 toView:contentView.get()
553 atPoint:textPosition]; 571 atPoint:textPosition];
554 certificateInfoButton_ = nil; // This will be created only if necessary. 572 certificateInfoButton_ = nil; // This will be created only if necessary.
555 separatorAfterConnection_ = [self addSeparatorToView:contentView]; 573 separatorAfterConnection_ = [self addSeparatorToView:contentView];
574 [separatorAfterConnection_ setAutoresizingMask:NSViewWidthSizable];
556 575
557 firstVisitIcon_ = [self addImageWithSize:imageSize 576 firstVisitIcon_ = [self addImageWithSize:imageSize
558 toView:contentView 577 toView:contentView
559 atPoint:imagePosition]; 578 atPoint:imagePosition];
560 firstVisitHeaderField_ = 579 firstVisitHeaderField_ =
561 [self addText:l10n_util::GetStringUTF16(IDS_PAGE_INFO_SITE_INFO_TITLE) 580 [self addText:l10n_util::GetStringUTF16(IDS_PAGE_INFO_SITE_INFO_TITLE)
562 withSize:[NSFont smallSystemFontSize] 581 withSize:[NSFont smallSystemFontSize]
563 bold:YES 582 bold:YES
564 toView:contentView.get() 583 toView:contentView.get()
565 atPoint:textPosition]; 584 atPoint:textPosition];
566 firstVisitDescriptionField_ = 585 firstVisitDescriptionField_ =
567 [self addText:string16() 586 [self addText:string16()
568 withSize:[NSFont smallSystemFontSize] 587 withSize:[NSFont smallSystemFontSize]
569 bold:NO 588 bold:NO
570 toView:contentView.get() 589 toView:contentView.get()
571 atPoint:textPosition]; 590 atPoint:textPosition];
572 591
573 separatorAfterFirstVisit_ = [self addSeparatorToView:contentView]; 592 separatorAfterFirstVisit_ = [self addSeparatorToView:contentView];
593 [separatorAfterFirstVisit_ setAutoresizingMask:NSViewWidthSizable];
594
574 NSString* helpButtonText = l10n_util::GetNSString( 595 NSString* helpButtonText = l10n_util::GetNSString(
575 IDS_PAGE_INFO_HELP_CENTER_LINK); 596 IDS_PAGE_INFO_HELP_CENTER_LINK);
576 helpButton_ = [self addLinkButtonWithText:helpButtonText 597 helpButton_ = [self addLinkButtonWithText:helpButtonText
577 toView:contentView]; 598 toView:contentView];
578 [helpButton_ setTarget:self]; 599 [helpButton_ setTarget:self];
579 [helpButton_ setAction:@selector(showHelpPage:)]; 600 [helpButton_ setAction:@selector(showHelpPage:)];
580 601
581 [item setView:contentView.get()]; 602 [item setView:contentView.get()];
582 [tabView_ insertTabViewItem:item.get() 603 [tabView_ insertTabViewItem:item.get()
583 atIndex:WebsiteSettingsUI::TAB_ID_CONNECTION]; 604 atIndex:WebsiteSettingsUI::TAB_ID_CONNECTION];
584 605
585 return contentView.get(); 606 return contentView.get();
586 } 607 }
587 608
588 // Set the Y position of |view| to the given position, and return the position 609 // Set the Y position of |view| to the given position, and return the position
589 // of its bottom edge. 610 // of its bottom edge.
590 - (CGFloat)setYPositionOfView:(NSView*)view to:(CGFloat)position { 611 - (CGFloat)setYPositionOfView:(NSView*)view to:(CGFloat)position {
591 NSRect frame = [view frame]; 612 NSRect frame = [view frame];
592 frame.origin.y = position; 613 frame.origin.y = position;
593 [view setFrame:frame]; 614 [view setFrame:frame];
594 return position + NSHeight(frame); 615 return position + NSHeight(frame);
595 } 616 }
596 617
618 - (void)setWidthOfView:(NSView*)view to:(CGFloat)width {
619 [view setFrameSize:NSMakeSize(width, NSHeight([view frame]))];
620 }
621
597 // Layout all of the controls in the window. This should be called whenever 622 // Layout all of the controls in the window. This should be called whenever
598 // the content has changed. 623 // the content has changed.
599 - (void)performLayout { 624 - (void)performLayout {
625 // Make the content at least as wide as the permissions view.
626 CGFloat contentWidth = std::max([self defaultWindowWidth],
627 NSWidth([permissionsView_ frame]));
628
629 // Set the width of the content view now, so that all the text fields will
630 // be sized to fit before their heights and vertical positions are adjusted.
631 // The tab view will only resize the currently selected tab, so resize both
632 // tab content views manually.
633 [self setWidthOfView:contentView_ to:contentWidth];
634 [self setWidthOfView:permissionsTabContentView_ to:contentWidth];
635 [self setWidthOfView:connectionTabContentView_ to:contentWidth];
636
600 // Place the identity status immediately below the identity. 637 // Place the identity status immediately below the identity.
601 [self sizeTextFieldHeightToFit:identityField_]; 638 [self sizeTextFieldHeightToFit:identityField_];
602 [self sizeTextFieldHeightToFit:identityStatusField_]; 639 [self sizeTextFieldHeightToFit:identityStatusField_];
603 CGFloat yPos = NSMaxY([identityField_ frame]) + kConnectionHeadlineSpacing; 640 CGFloat yPos = NSMaxY([identityField_ frame]) + kConnectionHeadlineSpacing;
604 yPos = [self setYPositionOfView:identityStatusField_ to:yPos]; 641 yPos = [self setYPositionOfView:identityStatusField_ to:yPos];
605 642
606 // Lay out the Permissions tab. 643 // Lay out the Permissions tab.
644
607 yPos = [self setYPositionOfView:cookiesView_ to:kFramePadding]; 645 yPos = [self setYPositionOfView:cookiesView_ to:kFramePadding];
608 646
609 // Put the link button for cookies and site data just below the cookie info. 647 // Put the link button for cookies and site data just below the cookie info.
610 NSRect cookiesButtonFrame = [cookiesButton_ frame]; 648 NSRect cookiesButtonFrame = [cookiesButton_ frame];
611 cookiesButtonFrame.origin.y = yPos; 649 cookiesButtonFrame.origin.y = yPos;
612 cookiesButtonFrame.origin.x = kFramePadding; 650 cookiesButtonFrame.origin.x = kFramePadding;
613 [cookiesButton_ setFrame:cookiesButtonFrame]; 651 [cookiesButton_ setFrame:cookiesButtonFrame];
614 652
615 // Put the permission info just below the link button. 653 // Put the permission info just below the link button.
616 [self setYPositionOfView:permissionsView_ 654 [self setYPositionOfView:permissionsView_
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 yPos = [self setYPositionOfView:separatorAfterFirstVisit_ 692 yPos = [self setYPositionOfView:separatorAfterFirstVisit_
655 to:yPos + kVerticalSpacing]; 693 to:yPos + kVerticalSpacing];
656 yPos += kVerticalSpacing; 694 yPos += kVerticalSpacing;
657 [self setYPositionOfView:helpButton_ to:yPos]; 695 [self setYPositionOfView:helpButton_ to:yPos];
658 696
659 // Adjust the tab view size and place it below the identity status. 697 // Adjust the tab view size and place it below the identity status.
660 698
661 yPos = NSMaxY([identityStatusField_ frame]) + kTabStripTopSpacing; 699 yPos = NSMaxY([identityStatusField_ frame]) + kTabStripTopSpacing;
662 yPos = [self setYPositionOfView:segmentedControl_ to:yPos]; 700 yPos = [self setYPositionOfView:segmentedControl_ to:yPos];
663 701
702 CGFloat connectionTabHeight = NSMaxY([helpButton_ frame]) + kVerticalSpacing;
703
664 NSRect tabViewFrame = [tabView_ frame]; 704 NSRect tabViewFrame = [tabView_ frame];
665 tabViewFrame.origin.y = yPos; 705 tabViewFrame.origin.y = yPos;
666 706 tabViewFrame.size.height =
667 // Determine the height of the tab contents. 707 std::max(connectionTabHeight, NSMaxY([permissionsView_ frame]));
668 708 tabViewFrame.size.width = contentWidth;
669 CGFloat connectionTabHeight = std::max(
670 NSMaxY([firstVisitDescriptionField_ frame]),
671 NSMaxY([firstVisitIcon_ frame ]));
672 connectionTabHeight += kVerticalSpacing;
673
674 CGFloat permissionsTabHeight = NSMaxY([permissionsView_ frame]);
675 CGFloat tabContentHeight = std::max(connectionTabHeight,
676 permissionsTabHeight);
677 tabViewFrame.size.height = tabContentHeight +
678 NSHeight(tabViewFrame) - NSHeight([tabView_ contentRect]);
679 [tabView_ setFrame:tabViewFrame]; 709 [tabView_ setFrame:tabViewFrame];
680 710
681 // Adjust the contentView to fit everything. 711 // Adjust the contentView to fit everything.
682 [contentView_ setFrame:NSMakeRect( 712 [contentView_ setFrame:NSMakeRect(
683 0, 0, kWindowWidth, NSMaxY([tabView_ frame]))]; 713 0, 0, NSWidth(tabViewFrame), NSMaxY(tabViewFrame))];
684 714
685 [self sizeAndPositionWindow]; 715 [self sizeAndPositionWindow];
686 } 716 }
687 717
688 // Adjust the size of the window to match the size of the content, and position 718 // Adjust the size of the window to match the size of the content, and position
689 // the bubble anchor appropriately. 719 // the bubble anchor appropriately.
690 - (void)sizeAndPositionWindow { 720 - (void)sizeAndPositionWindow {
691 NSRect windowFrame = 721 NSRect windowFrame = [contentView_ frame];
692 NSMakeRect(0, 0, kWindowWidth, NSHeight([contentView_ frame]));
693 windowFrame.size = [[[self window] contentView] convertSize:windowFrame.size 722 windowFrame.size = [[[self window] contentView] convertSize:windowFrame.size
694 toView:nil]; 723 toView:nil];
695 // Adjust the origin by the difference in height. 724 // Adjust the origin by the difference in height.
696 windowFrame.origin = [[self window] frame].origin; 725 windowFrame.origin = [[self window] frame].origin;
697 windowFrame.origin.y -= NSHeight(windowFrame) - 726 windowFrame.origin.y -= NSHeight(windowFrame) -
698 NSHeight([[self window] frame]); 727 NSHeight([[self window] frame]);
699 728
700 // Resize the window. Only animate if the window is visible, otherwise it 729 // Resize the window. Only animate if the window is visible, otherwise it
701 // could be "growing" while it's opening, looking awkward. 730 // could be "growing" while it's opening, looking awkward.
702 [[self window] setFrame:windowFrame 731 [[self window] setFrame:windowFrame
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 CGFloat width = NSWidth([view frame]) - point.x - kFramePadding; 786 CGFloat width = NSWidth([view frame]) - point.x - kFramePadding;
758 NSRect frame = NSMakeRect(point.x, point.y, width, 100); 787 NSRect frame = NSMakeRect(point.x, point.y, width, 100);
759 scoped_nsobject<NSTextField> textField( 788 scoped_nsobject<NSTextField> textField(
760 [[NSTextField alloc] initWithFrame:frame]); 789 [[NSTextField alloc] initWithFrame:frame]);
761 [self configureTextFieldAsLabel:textField.get()]; 790 [self configureTextFieldAsLabel:textField.get()];
762 [textField setStringValue:base::SysUTF16ToNSString(text)]; 791 [textField setStringValue:base::SysUTF16ToNSString(text)];
763 NSFont* font = bold ? [NSFont boldSystemFontOfSize:fontSize] 792 NSFont* font = bold ? [NSFont boldSystemFontOfSize:fontSize]
764 : [NSFont systemFontOfSize:fontSize]; 793 : [NSFont systemFontOfSize:fontSize];
765 [textField setFont:font]; 794 [textField setFont:font];
766 [self sizeTextFieldHeightToFit:textField]; 795 [self sizeTextFieldHeightToFit:textField];
796 [textField setAutoresizingMask:NSViewWidthSizable];
767 [view addSubview:textField.get()]; 797 [view addSubview:textField.get()];
768 return textField.get(); 798 return textField.get();
769 } 799 }
770 800
771 // Add an image as a subview of the given view, placed at a pre-determined x 801 // Add an image as a subview of the given view, placed at a pre-determined x
772 // position and the given y position. Return the new NSImageView. 802 // position and the given y position. Return the new NSImageView.
773 - (NSImageView*)addImageWithSize:(NSSize)size 803 - (NSImageView*)addImageWithSize:(NSSize)size
774 toView:(NSView*)view 804 toView:(NSView*)view
775 atPoint:(NSPoint)point { 805 atPoint:(NSPoint)point {
776 NSRect frame = NSMakeRect(point.x, point.y, size.width, size.height); 806 NSRect frame = NSMakeRect(point.x, point.y, size.width, size.height);
(...skipping 22 matching lines...) Expand all
799 NSRect frame = NSMakeRect(kFramePadding, 0, 100, 10); 829 NSRect frame = NSMakeRect(kFramePadding, 0, 100, 10);
800 scoped_nsobject<NSButton> button([[NSButton alloc] initWithFrame:frame]); 830 scoped_nsobject<NSButton> button([[NSButton alloc] initWithFrame:frame]);
801 scoped_nsobject<HyperlinkButtonCell> cell( 831 scoped_nsobject<HyperlinkButtonCell> cell(
802 [[HyperlinkButtonCell alloc] initTextCell:text]); 832 [[HyperlinkButtonCell alloc] initTextCell:text]);
803 [cell setControlSize:NSSmallControlSize]; 833 [cell setControlSize:NSSmallControlSize];
804 [button setCell:cell.get()]; 834 [button setCell:cell.get()];
805 [button setButtonType:NSMomentaryPushInButton]; 835 [button setButtonType:NSMomentaryPushInButton];
806 [button setBezelStyle:NSRegularSquareBezelStyle]; 836 [button setBezelStyle:NSRegularSquareBezelStyle];
807 [view addSubview:button.get()]; 837 [view addSubview:button.get()];
808 838
809 // Call size-to-fit to fixup for the localized string.
810 [GTMUILocalizerAndLayoutTweaker sizeToFitView:button.get()]; 839 [GTMUILocalizerAndLayoutTweaker sizeToFitView:button.get()];
811 return button.get(); 840 return button.get();
812 } 841 }
813 842
843 // Determine the size of a popup button with the given title.
844 - (NSSize)sizeForPopUpButton:(NSPopUpButton*)button
845 withTitle:(NSString*)title {
846 NSDictionary* textAttributes =
847 [NSDictionary dictionaryWithObject:[button font]
848 forKey:NSFontAttributeName];
849 NSSize titleSize = [title sizeWithAttributes:textAttributes];
850
851 NSRect buttonFrame = [button frame];
852 NSRect titleRect = [[button cell] titleRectForBounds:buttonFrame];
853 CGFloat width = titleSize.width + NSWidth(buttonFrame) - NSWidth(titleRect);
854
855 return NSMakeSize(width + kPermissionButtonTitleRightPadding,
856 NSHeight(buttonFrame));
857 }
858
814 // Add a pop-up button for |permissionInfo| to the given view. 859 // Add a pop-up button for |permissionInfo| to the given view.
815 - (NSPopUpButton*)addPopUpButtonForPermission: 860 - (NSPopUpButton*)addPopUpButtonForPermission:
816 (const WebsiteSettingsUI::PermissionInfo&)permissionInfo 861 (const WebsiteSettingsUI::PermissionInfo&)permissionInfo
817 toView:(NSView*)view 862 toView:(NSView*)view
818 atPoint:(NSPoint)point { 863 atPoint:(NSPoint)point {
819 // Use an arbitrary width and height; it will be sized to fit. 864 // Use an arbitrary width and height; it will be sized to fit.
820 NSRect frame = NSMakeRect(point.x, point.y, 1, 1); 865 NSRect frame = NSMakeRect(point.x, point.y, 1, 1);
821 scoped_nsobject<NSPopUpButton> button( 866 scoped_nsobject<NSPopUpButton> button(
822 [[NSPopUpButton alloc] initWithFrame:frame pullsDown:NO]); 867 [[NSPopUpButton alloc] initWithFrame:frame pullsDown:NO]);
823 [button setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; 868 [button setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 scoped_nsobject<NSMenuItem> titleItem([[NSMenuItem alloc] init]); 902 scoped_nsobject<NSMenuItem> titleItem([[NSMenuItem alloc] init]);
858 string16 buttonTitle = WebsiteSettingsUI::PermissionActionToUIString( 903 string16 buttonTitle = WebsiteSettingsUI::PermissionActionToUIString(
859 permissionInfo.setting, 904 permissionInfo.setting,
860 permissionInfo.default_setting, 905 permissionInfo.default_setting,
861 permissionInfo.source); 906 permissionInfo.source);
862 [titleItem setTitle:base::SysUTF16ToNSString(buttonTitle)]; 907 [titleItem setTitle:base::SysUTF16ToNSString(buttonTitle)];
863 [[button cell] setUsesItemFromMenu:NO]; 908 [[button cell] setUsesItemFromMenu:NO];
864 [[button cell] setMenuItem:titleItem.get()]; 909 [[button cell] setMenuItem:titleItem.get()];
865 [button sizeToFit]; 910 [button sizeToFit];
866 911
867 // Determine the size of the title, and size the control accordingly. 912 // Determine the largest possible size for this button.
868 // Using |sizeToFit| results in way too much extra space after the text. 913 CGFloat maxTitleWidth = 0;
869 NSDictionary* textAttributes = 914 for (NSInteger i = 0; i < [button numberOfItems]; i++) {
Robert Sesek 2012/11/26 17:06:56 nit: use prefix operator: ++i
Patrick Dubroy 2012/11/27 12:11:30 Done.
870 [NSDictionary dictionaryWithObject:[button font] 915 string16 title = WebsiteSettingsUI::PermissionActionToUIString(
871 forKey:NSFontAttributeName]; 916 static_cast<ContentSetting>([[button itemAtIndex:i] tag]),
872 NSSize titleSize = [[button title] sizeWithAttributes:textAttributes]; 917 permissionInfo.default_setting,
918 content_settings::SETTING_SOURCE_USER);
919 NSSize size = [self sizeForPopUpButton:button
920 withTitle:base::SysUTF16ToNSString(title)];
921 maxTitleWidth = std::max(maxTitleWidth, size.width);
922 }
923 // Ensure the containing view is large enough to contain the button with its
924 // widest possible title.
925 NSRect containerFrame = [view frame];
926 containerFrame.size.width = std::max(
927 NSWidth(containerFrame), point.x + maxTitleWidth + kFramePadding);
928 [view setFrame:containerFrame];
873 929
874 // Adjust the button frame to have a titleRect that exactly fits the title. 930 // Size the button to just fit the title.
875 NSRect buttonFrame = [button frame]; 931 [button setFrameSize:[self sizeForPopUpButton:button
876 NSRect titleRect = [[button cell] titleRectForBounds:buttonFrame]; 932 withTitle:[button title]]];
877 buttonFrame.size.width =
878 titleSize.width + NSWidth(buttonFrame) - NSWidth(titleRect);
879 [button setFrame:buttonFrame];
880 DCHECK_EQ(NSWidth([[button cell] titleRectForBounds:buttonFrame]),
881 titleSize.width);
882 933
883 [view addSubview:button.get()]; 934 [view addSubview:button.get()];
884 return button.get(); 935 return button.get();
885 } 936 }
886 937
887 // Called when the user changes the selected segment in the segmented control. 938 // Called when the user changes the selected segment in the segmented control.
888 - (void)tabSelected:(id)sender { 939 - (void)tabSelected:(id)sender {
889 [tabView_ selectTabViewItemAtIndex:[segmentedControl_ selectedSegment]]; 940 [tabView_ selectTabViewItemAtIndex:[segmentedControl_ selectedSegment]];
890 } 941 }
891 942
892 // Handler for the permission-changing menus. 943 // Handler for the permission-changing menus.
893 - (void)permissionValueChanged:(id)sender { 944 - (void)permissionValueChanged:(id)sender {
894 DCHECK([sender isKindOfClass:[NSPopUpButton class]]); 945 DCHECK([sender isKindOfClass:[NSPopUpButton class]]);
895 NSPopUpButton* button = static_cast<NSPopUpButton*>(sender); 946 NSPopUpButton* button = static_cast<NSPopUpButton*>(sender);
896 ContentSettingsType type = static_cast<ContentSettingsType>([button tag]); 947 ContentSettingsType type = static_cast<ContentSettingsType>([button tag]);
897 ContentSetting newSetting = static_cast<ContentSetting>( 948 ContentSetting newSetting = static_cast<ContentSetting>(
898 [[button selectedItem] tag]); 949 [[button selectedItem] tag]);
899 if (presenter_.get()) 950 if (presenter_.get())
900 presenter_->OnSitePermissionChanged(type, newSetting); 951 presenter_->OnSitePermissionChanged(type, newSetting);
901 } 952 }
902 953
903 // Adds a new row to the UI listing the permissions. Returns the amount of 954 // Adds a new row to the UI listing the permissions. Returns the amount of
904 // vertical space that was taken up by the row. 955 // vertical space that was taken up by the row.
905 - (CGFloat)addPermission: 956 - (NSPoint)addPermission:
906 (const WebsiteSettingsUI::PermissionInfo&)permissionInfo 957 (const WebsiteSettingsUI::PermissionInfo&)permissionInfo
907 toView:(NSView*)view 958 toView:(NSView*)view
908 atPoint:(NSPoint)point { 959 atPoint:(NSPoint)point {
909 // TODO(dubroy): Remove this check by refactoring GetPermissionIcon to take 960 // TODO(dubroy): Remove this check by refactoring GetPermissionIcon to take
910 // the PermissionInfo object as its argument. 961 // the PermissionInfo object as its argument.
911 ContentSetting setting = permissionInfo.setting == CONTENT_SETTING_DEFAULT ? 962 ContentSetting setting = permissionInfo.setting == CONTENT_SETTING_DEFAULT ?
912 permissionInfo.default_setting : permissionInfo.setting; 963 permissionInfo.default_setting : permissionInfo.setting;
913 NSImage* image = WebsiteSettingsUI::GetPermissionIcon( 964 NSImage* image = WebsiteSettingsUI::GetPermissionIcon(
914 permissionInfo.type, setting).ToNSImage(); 965 permissionInfo.type, setting).ToNSImage();
915 NSImageView* imageView = [self addImageWithSize:[image size] 966 NSImageView* imageView = [self addImageWithSize:[image size]
(...skipping 28 matching lines...) Expand all
944 995
945 // Align the icon with the text. 996 // Align the icon with the text.
946 [self alignPermissionIcon:imageView withTextField:label]; 997 [self alignPermissionIcon:imageView withTextField:label];
947 998
948 // Permissions specified by policy or an extension cannot be changed. 999 // Permissions specified by policy or an extension cannot be changed.
949 if (permissionInfo.source == content_settings::SETTING_SOURCE_EXTENSION || 1000 if (permissionInfo.source == content_settings::SETTING_SOURCE_EXTENSION ||
950 permissionInfo.source == content_settings::SETTING_SOURCE_POLICY) { 1001 permissionInfo.source == content_settings::SETTING_SOURCE_POLICY) {
951 [button setEnabled:NO]; 1002 [button setEnabled:NO];
952 } 1003 }
953 1004
954 return NSHeight([label frame]); 1005 NSRect buttonFrame = [button frame];
1006 return NSMakePoint(NSMaxX(buttonFrame), NSMaxY(buttonFrame));
955 } 1007 }
956 1008
957 // Align an image with a text field by vertically centering the image on 1009 // Align an image with a text field by vertically centering the image on
958 // the cap height of the first line of text. 1010 // the cap height of the first line of text.
959 - (void)alignPermissionIcon:(NSImageView*)imageView 1011 - (void)alignPermissionIcon:(NSImageView*)imageView
960 withTextField:(NSTextField*)textField { 1012 withTextField:(NSTextField*)textField {
961 NSFont* font = [textField font]; 1013 NSFont* font = [textField font];
962 1014
963 // Calculate the offset from the top of the text field. 1015 // Calculate the offset from the top of the text field.
964 CGFloat capHeight = [font capHeight]; 1016 CGFloat capHeight = [font capHeight];
(...skipping 22 matching lines...) Expand all
987 UTF8ToUTF16(cookieInfo.cookie_source), 1039 UTF8ToUTF16(cookieInfo.cookie_source),
988 base::IntToString16(cookieInfo.allowed), 1040 base::IntToString16(cookieInfo.allowed),
989 base::IntToString16(cookieInfo.blocked)); 1041 base::IntToString16(cookieInfo.blocked));
990 1042
991 NSTextField* label = [self addText:labelText 1043 NSTextField* label = [self addText:labelText
992 withSize:[NSFont smallSystemFontSize] 1044 withSize:[NSFont smallSystemFontSize]
993 bold:NO 1045 bold:NO
994 toView:view 1046 toView:view
995 atPoint:point]; 1047 atPoint:point];
996 1048
997 // Shrink the label to fit the text width.
998 NSSize requiredSize = [[label cell] cellSizeForBounds:[label frame]];
999 [label setFrameSize:requiredSize];
1000
1001 // Align the icon with the text. 1049 // Align the icon with the text.
1002 [self alignPermissionIcon:imageView withTextField:label]; 1050 [self alignPermissionIcon:imageView withTextField:label];
1003 1051
1004 return NSHeight([label frame]); 1052 return NSHeight([label frame]);
1005 } 1053 }
1006 1054
1007 // Set the content of the identity and identity status fields. 1055 // Set the content of the identity and identity status fields.
1008 - (void)setIdentityInfo:(const WebsiteSettingsUI::IdentityInfo&)identityInfo { 1056 - (void)setIdentityInfo:(const WebsiteSettingsUI::IdentityInfo&)identityInfo {
1009 [identityField_ setStringValue: 1057 [identityField_ setStringValue:
1010 base::SysUTF8ToNSString(identityInfo.site_identity)]; 1058 base::SysUTF8ToNSString(identityInfo.site_identity)];
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 [cookiesView_ setSubviews:[NSArray array]]; 1096 [cookiesView_ setSubviews:[NSArray array]];
1049 NSPoint controlOrigin = NSMakePoint(kFramePadding, 0); 1097 NSPoint controlOrigin = NSMakePoint(kFramePadding, 0);
1050 1098
1051 string16 sectionTitle = l10n_util::GetStringUTF16( 1099 string16 sectionTitle = l10n_util::GetStringUTF16(
1052 IDS_WEBSITE_SETTINGS_TITLE_SITE_DATA); 1100 IDS_WEBSITE_SETTINGS_TITLE_SITE_DATA);
1053 NSTextField* header = [self addText:sectionTitle 1101 NSTextField* header = [self addText:sectionTitle
1054 withSize:[NSFont smallSystemFontSize] 1102 withSize:[NSFont smallSystemFontSize]
1055 bold:YES 1103 bold:YES
1056 toView:cookiesView_ 1104 toView:cookiesView_
1057 atPoint:controlOrigin]; 1105 atPoint:controlOrigin];
1058 [self sizeTextFieldHeightToFit:header];
1059 controlOrigin.y += NSHeight([header frame]) + kPermissionsHeadlineSpacing; 1106 controlOrigin.y += NSHeight([header frame]) + kPermissionsHeadlineSpacing;
1060 1107
1061 for (CookieInfoList::const_iterator it = cookieInfoList.begin(); 1108 for (CookieInfoList::const_iterator it = cookieInfoList.begin();
1062 it != cookieInfoList.end(); 1109 it != cookieInfoList.end();
1063 ++it) { 1110 ++it) {
1064 controlOrigin.y += kPermissionsTabSpacing; 1111 controlOrigin.y += kPermissionsTabSpacing;
1065 CGFloat rowHeight = [self addCookieInfo:*it 1112 CGFloat rowHeight = [self addCookieInfo:*it
1066 toView:cookiesView_ 1113 toView:cookiesView_
1067 atPoint:controlOrigin]; 1114 atPoint:controlOrigin];
1068 controlOrigin.y += rowHeight; 1115 controlOrigin.y += rowHeight;
1069 } 1116 }
1070 1117
1071 controlOrigin.y += kPermissionsTabSpacing; 1118 controlOrigin.y += kPermissionsTabSpacing;
1072 [cookiesView_ setFrameSize:NSMakeSize(kWindowWidth, controlOrigin.y)]; 1119 [cookiesView_ setFrameSize:
1120 NSMakeSize(NSWidth([cookiesView_ frame]), controlOrigin.y)];
1121
1073 [self performLayout]; 1122 [self performLayout];
1074 } 1123 }
1075 1124
1076 - (void)setPermissionInfo:(const PermissionInfoList&)permissionInfoList { 1125 - (void)setPermissionInfo:(const PermissionInfoList&)permissionInfoList {
1126 // The contents of the permissions view can cause the whole window to get
1127 // bigger, but currently permissions are always set before cookie info.
1128 // Check to make sure that's still the case.
1129 DCHECK_EQ(0U, [[cookiesView_ subviews] count]);
1130
1077 [permissionsView_ setSubviews:[NSArray array]]; 1131 [permissionsView_ setSubviews:[NSArray array]];
1078 NSPoint controlOrigin = NSMakePoint(kFramePadding, 0); 1132 NSPoint controlOrigin = NSMakePoint(kFramePadding, 0);
1079 1133
1080 string16 sectionTitle = l10n_util::GetStringUTF16( 1134 string16 sectionTitle = l10n_util::GetStringUTF16(
1081 IDS_WEBSITE_SETTINGS_TITLE_SITE_PERMISSIONS); 1135 IDS_WEBSITE_SETTINGS_TITLE_SITE_PERMISSIONS);
1082 NSTextField* header = [self addText:sectionTitle 1136 NSTextField* header = [self addText:sectionTitle
1083 withSize:[NSFont smallSystemFontSize] 1137 withSize:[NSFont smallSystemFontSize]
1084 bold:YES 1138 bold:YES
1085 toView:permissionsView_ 1139 toView:permissionsView_
1086 atPoint:controlOrigin]; 1140 atPoint:controlOrigin];
1087 [self sizeTextFieldHeightToFit:header]; 1141 [self sizeTextFieldHeightToFit:header];
1088 controlOrigin.y += NSHeight([header frame]) + kPermissionsHeadlineSpacing; 1142 controlOrigin.y += NSHeight([header frame]) + kPermissionsHeadlineSpacing;
1089 1143
1090 for (PermissionInfoList::const_iterator permission = 1144 for (PermissionInfoList::const_iterator permission =
1091 permissionInfoList.begin(); 1145 permissionInfoList.begin();
1092 permission != permissionInfoList.end(); 1146 permission != permissionInfoList.end();
1093 ++permission) { 1147 ++permission) {
1094 controlOrigin.y += kPermissionsTabSpacing; 1148 controlOrigin.y += kPermissionsTabSpacing;
1095 CGFloat rowHeight = [self addPermission:*permission 1149 NSPoint rowBottomRight = [self addPermission:*permission
1096 toView:permissionsView_ 1150 toView:permissionsView_
1097 atPoint:controlOrigin]; 1151 atPoint:controlOrigin];
1098 controlOrigin.y += rowHeight; 1152 controlOrigin.y = rowBottomRight.y;
1099 } 1153 }
1100 controlOrigin.y += kFramePadding; 1154 controlOrigin.y += kFramePadding;
1101 [permissionsView_ setFrameSize:NSMakeSize(kWindowWidth, controlOrigin.y)]; 1155 [permissionsView_ setFrameSize:
1156 NSMakeSize(NSWidth([permissionsView_ frame]), controlOrigin.y)];
1157 [self performLayout];
1102 } 1158 }
1103 1159
1104 - (void)setFirstVisit:(const string16&)firstVisit { 1160 - (void)setFirstVisit:(const string16&)firstVisit {
1105 [firstVisitIcon_ setImage: 1161 [firstVisitIcon_ setImage:
1106 WebsiteSettingsUI::GetFirstVisitIcon(firstVisit).ToNSImage()]; 1162 WebsiteSettingsUI::GetFirstVisitIcon(firstVisit).ToNSImage()];
1107 [firstVisitDescriptionField_ setStringValue: 1163 [firstVisitDescriptionField_ setStringValue:
1108 base::SysUTF16ToNSString(firstVisit)]; 1164 base::SysUTF16ToNSString(firstVisit)];
1109 [self performLayout]; 1165 [self performLayout];
1110 } 1166 }
1111 1167
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 [bubble_controller_ setPermissionInfo:permission_info_list]; 1235 [bubble_controller_ setPermissionInfo:permission_info_list];
1180 } 1236 }
1181 1237
1182 void WebsiteSettingsUIBridge::SetFirstVisit(const string16& first_visit) { 1238 void WebsiteSettingsUIBridge::SetFirstVisit(const string16& first_visit) {
1183 [bubble_controller_ setFirstVisit:first_visit]; 1239 [bubble_controller_ setFirstVisit:first_visit];
1184 } 1240 }
1185 1241
1186 void WebsiteSettingsUIBridge::SetSelectedTab(TabId tab_id) { 1242 void WebsiteSettingsUIBridge::SetSelectedTab(TabId tab_id) {
1187 [bubble_controller_ setSelectedTab:tab_id]; 1243 [bubble_controller_ setSelectedTab:tab_id];
1188 } 1244 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698