Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "base/string_number_conversions.h" | |
| 7 #include "base/sys_string_conversions.h" | 8 #include "base/sys_string_conversions.h" |
| 8 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 9 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 9 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 10 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
| 10 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 11 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
| 11 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 12 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| 12 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 13 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 13 #include "content/public/browser/cert_store.h" | 14 #include "content/public/browser/cert_store.h" |
| 14 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
| 15 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
| 16 #include "grit/ui_resources.h" | 17 #include "grit/ui_resources.h" |
| 17 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" | 18 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" |
| 18 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 19 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 // The width of the window, in view coordinates. The height will be determined | 24 // The width of the window, in view coordinates. The height will be determined |
| 24 // by the content. | 25 // by the content. |
| 25 const CGFloat kWindowWidth = 380; | 26 const CGFloat kWindowWidth = 380; |
| 26 | 27 |
| 27 // Spacing in between sections. | 28 // Spacing in between sections. |
| 28 const CGFloat kVerticalSpacing = 10; | 29 const CGFloat kVerticalSpacing = 10; |
| 29 | 30 |
| 30 // Padding between the window frame and content. | 31 // Padding between the window frame and content. |
| 31 const CGFloat kFramePadding = 10; | 32 const CGFloat kFramePadding = 10; |
| 32 | 33 |
| 33 // Spacing between the optional headline and description text views. | 34 // Spacing between the optional headline and description text views. |
| 34 const CGFloat kHeadlineSpacing = 2; | 35 const CGFloat kHeadlineSpacing = 2; |
| 35 | 36 |
| 36 // Spacing between the image and the text. | 37 // Spacing between images on the Connection tab and the text. |
| 37 const CGFloat kImageSpacing = 10; | 38 const CGFloat kConnectionImageSpacing = 10; |
| 38 | 39 |
| 39 // Square size of the image. | 40 // Square size of the images on the Connections tab. |
| 40 const CGFloat kImageSize = 30; | 41 const CGFloat kConnectionImageSize = 30; |
| 41 | 42 |
| 42 // The X position of the text fields. Variants for with and without an image. | 43 // Square size of the permission images. |
| 43 const CGFloat kTextXPositionNoImage = kFramePadding; | 44 const CGFloat kPermissionImageSize = 19; |
| 44 const CGFloat kTextXPosition = kTextXPositionNoImage + kImageSize + | |
| 45 kImageSpacing; | |
| 46 | 45 |
| 47 // Width of the text fields. | 46 // Vertical adjustment for the permission images. |
| 48 const CGFloat kTextWidth = kWindowWidth - (kImageSize + kImageSpacing + | 47 // They have an extra pixel of padding on the bottom edge. |
| 49 kFramePadding * 2); | 48 const CGFloat kPermissionImageYAdjust = 1; |
| 49 | |
| 50 // Spacing between a permission image and the text. | |
| 51 const CGFloat kPermissionImageSpacing = 3; | |
| 50 | 52 |
| 51 // The amount of padding given to tab view contents. | 53 // The amount of padding given to tab view contents. |
| 52 const CGFloat kTabViewContentsPadding = kFramePadding; | 54 const CGFloat kTabViewContentsPadding = kFramePadding; |
| 53 | 55 |
| 54 // The spacing between individual items in the Permissions tab. | 56 // The spacing between individual items in the Permissions tab. |
| 55 const CGFloat kPermissionsTabSpacing = 8; | 57 const CGFloat kPermissionsTabSpacing = 8; |
| 56 | 58 |
| 57 // The extra space to the left of the first tab in the tab strip. | 59 // The extra space to the left of the first tab in the tab strip. |
| 58 const CGFloat kTabStripXPadding = 19; | 60 const CGFloat kTabStripXPadding = 19; |
| 59 | 61 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 76 const CGFloat kTabLabelXPadding = 12; | 78 const CGFloat kTabLabelXPadding = 12; |
| 77 | 79 |
| 78 // In the permission changing menu, the order of the menu items (which | 80 // In the permission changing menu, the order of the menu items (which |
| 79 // correspond to different content settings). | 81 // correspond to different content settings). |
| 80 const ContentSetting kPermissionsMenuSettings[] = { | 82 const ContentSetting kPermissionsMenuSettings[] = { |
| 81 CONTENT_SETTING_ALLOW, | 83 CONTENT_SETTING_ALLOW, |
| 82 CONTENT_SETTING_BLOCK, | 84 CONTENT_SETTING_BLOCK, |
| 83 CONTENT_SETTING_DEFAULT | 85 CONTENT_SETTING_DEFAULT |
| 84 }; | 86 }; |
| 85 | 87 |
| 88 // Return the text color to use for the indentity status when the site's | |
| 89 // identity has been verified. | |
| 90 NSColor* IdentityVerifiedTextColor() { | |
| 91 // RGB components are specified using integer RGB [0-255] values for easy | |
| 92 // comparison to other platforms. | |
| 93 return [NSColor colorWithCalibratedRed:0x07/255.0 | |
| 94 green:0x95/255.0 | |
| 95 blue:0 | |
| 96 alpha:1.0]; | |
| 97 } | |
| 98 | |
| 86 } // namespace | 99 } // namespace |
| 87 | 100 |
| 88 // A simple container to hold all the contents of the website settings bubble. | 101 // A simple container to hold all the contents of the website settings bubble. |
| 89 // It uses a flipped coordinate system to make text layout easier. | 102 // It uses a flipped coordinate system to make text layout easier. |
| 90 @interface WebsiteSettingsContentView : NSView | 103 @interface WebsiteSettingsContentView : NSView |
| 91 @end | 104 @end |
| 92 @implementation WebsiteSettingsContentView | 105 @implementation WebsiteSettingsContentView |
| 93 - (BOOL)isFlipped { | 106 - (BOOL)isFlipped { |
| 94 return YES; | 107 return YES; |
| 95 } | 108 } |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 } | 255 } |
| 243 | 256 |
| 244 - (void)setPresenter:(WebsiteSettings*)presenter { | 257 - (void)setPresenter:(WebsiteSettings*)presenter { |
| 245 presenter_.reset(presenter); | 258 presenter_.reset(presenter); |
| 246 } | 259 } |
| 247 | 260 |
| 248 // Create the subviews for the website settings bubble. | 261 // Create the subviews for the website settings bubble. |
| 249 - (void)initializeContents { | 262 - (void)initializeContents { |
| 250 // Keeps track of the position that the next control should be drawn at. | 263 // Keeps track of the position that the next control should be drawn at. |
| 251 NSPoint controlOrigin = NSMakePoint( | 264 NSPoint controlOrigin = NSMakePoint( |
| 252 kTextXPositionNoImage, | 265 kFramePadding, |
| 253 kFramePadding + info_bubble::kBubbleArrowHeight); | 266 kFramePadding + info_bubble::kBubbleArrowHeight); |
| 254 | 267 |
| 255 // Create the container view that uses flipped coordinates. | 268 // Create the container view that uses flipped coordinates. |
| 256 NSRect contentFrame = NSMakeRect(0, 0, kWindowWidth, 300); | 269 NSRect contentFrame = NSMakeRect(0, 0, kWindowWidth, 300); |
| 257 contentView_.reset( | 270 contentView_.reset( |
| 258 [[WebsiteSettingsContentView alloc] initWithFrame:contentFrame]); | 271 [[WebsiteSettingsContentView alloc] initWithFrame:contentFrame]); |
| 259 | 272 |
| 260 // Create a text field (empty for now) to show the site identity. | 273 // Create a text field (empty for now) to show the site identity. |
| 261 identityField_ = [self addText:string16() | 274 identityField_ = [self addText:string16() |
| 262 withSize:[NSFont systemFontSize] | 275 withSize:[NSFont systemFontSize] |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 [segmentedControl_ setSelectedSegment:0]; | 327 [segmentedControl_ setSelectedSegment:0]; |
| 315 [contentView_ addSubview:segmentedControl_]; | 328 [contentView_ addSubview:segmentedControl_]; |
| 316 | 329 |
| 317 NSRect tabFrame = NSMakeRect(0, 0, kWindowWidth, 300); | 330 NSRect tabFrame = NSMakeRect(0, 0, kWindowWidth, 300); |
| 318 tabView_.reset([[NSTabView alloc] initWithFrame:tabFrame]); | 331 tabView_.reset([[NSTabView alloc] initWithFrame:tabFrame]); |
| 319 [tabView_ setTabViewType:NSNoTabsNoBorder]; | 332 [tabView_ setTabViewType:NSNoTabsNoBorder]; |
| 320 [tabView_ setDrawsBackground:NO]; | 333 [tabView_ setDrawsBackground:NO]; |
| 321 [tabView_ setControlSize:NSSmallControlSize]; | 334 [tabView_ setControlSize:NSSmallControlSize]; |
| 322 [contentView_ addSubview:tabView_.get()]; | 335 [contentView_ addSubview:tabView_.get()]; |
| 323 | 336 |
| 324 permissionsContentView_ = [self addPermissionsTabToTabView:tabView_]; | 337 permissionsTabContentView_ = [self addPermissionsTabToTabView:tabView_]; |
| 325 [self addConnectionTabToTabView:tabView_]; | 338 [self addConnectionTabToTabView:tabView_]; |
| 326 | 339 |
| 327 // Replace the window's content. | 340 // Replace the window's content. |
| 328 [[[self window] contentView] setSubviews: | 341 [[[self window] contentView] setSubviews: |
| 329 [NSArray arrayWithObject:contentView_.get()]]; | 342 [NSArray arrayWithObject:contentView_.get()]]; |
| 330 | 343 |
| 331 [self performLayout]; | 344 [self performLayout]; |
| 332 } | 345 } |
| 333 | 346 |
| 334 // Create the contents of the Permissions tab and add it to the given tab view. | 347 // Create the contents of the Permissions tab and add it to the given tab view. |
| 335 // Returns a weak reference to the tab view item's view. | 348 // Returns a weak reference to the tab view item's view. |
| 336 - (NSView*)addPermissionsTabToTabView:(NSTabView*)tabView { | 349 - (NSView*)addPermissionsTabToTabView:(NSTabView*)tabView { |
| 337 scoped_nsobject<NSTabViewItem> item([[NSTabViewItem alloc] init]); | 350 scoped_nsobject<NSTabViewItem> item([[NSTabViewItem alloc] init]); |
| 338 [tabView_ addTabViewItem:item.get()]; | 351 [tabView_ addTabViewItem:item.get()]; |
| 339 scoped_nsobject<NSView> contentView([[WebsiteSettingsContentView alloc] | 352 scoped_nsobject<NSView> contentView([[WebsiteSettingsContentView alloc] |
| 340 initWithFrame:[tabView_ contentRect]]); | 353 initWithFrame:[tabView_ contentRect]]); |
| 341 [item setView:contentView.get()]; | 354 [item setView:contentView.get()]; |
| 355 | |
| 356 // Initialize the two containers that hold the controls. The initial frames | |
| 357 // are arbitrary, and will be adjusted after the controls are laid out. | |
| 358 cookiesView_ = [[WebsiteSettingsContentView alloc] | |
|
Robert Sesek
2012/08/13 17:44:57
These are leaked.
| |
| 359 initWithFrame:[tabView_ contentRect]]; | |
| 360 permissionsView_ = [[WebsiteSettingsContentView alloc] | |
| 361 initWithFrame:[tabView_ contentRect]]; | |
| 362 | |
| 363 [contentView addSubview:cookiesView_]; | |
| 364 [contentView addSubview:permissionsView_]; | |
| 365 | |
| 342 return contentView.get(); | 366 return contentView.get(); |
| 343 } | 367 } |
| 344 | 368 |
| 345 // Create the contents of the Connection tab and add it to the given tab view. | 369 // Create the contents of the Connection tab and add it to the given tab view. |
| 346 // Returns a weak reference to the tab view item's view. | 370 // Returns a weak reference to the tab view item's view. |
| 347 - (NSView*)addConnectionTabToTabView:(NSTabView*)tabView { | 371 - (NSView*)addConnectionTabToTabView:(NSTabView*)tabView { |
| 348 scoped_nsobject<NSTabViewItem> item([[NSTabViewItem alloc] init]); | 372 scoped_nsobject<NSTabViewItem> item([[NSTabViewItem alloc] init]); |
| 349 scoped_nsobject<NSView> contentView([[WebsiteSettingsContentView alloc] | 373 scoped_nsobject<NSView> contentView([[WebsiteSettingsContentView alloc] |
| 350 initWithFrame:[tabView_ contentRect]]); | 374 initWithFrame:[tabView_ contentRect]]); |
| 351 | 375 |
| 352 // Place all the text at the same position. It will be adjusted in | 376 // Place all the text at the same position. It will be adjusted in |
| 353 // performLayout. | 377 // performLayout. |
| 354 NSPoint textPosition = NSMakePoint( | 378 NSPoint textPosition = NSMakePoint( |
| 355 kTabViewContentsPadding + kImageSize + kImageSpacing, | 379 kTabViewContentsPadding + kConnectionImageSize + kConnectionImageSpacing, |
| 356 kTabViewContentsPadding); | 380 kTabViewContentsPadding); |
| 381 NSSize imageSize = NSMakeSize(kConnectionImageSize, kConnectionImageSize); | |
| 357 | 382 |
| 358 identityStatusIcon_ = | 383 identityStatusIcon_ = [self addImageWithSize:imageSize |
| 359 [self addImageToView:contentView atOffset:kTabViewContentsPadding]; | 384 toView:contentView |
| 385 atOffset:kTabViewContentsPadding]; | |
| 360 identityStatusDescriptionField_ = | 386 identityStatusDescriptionField_ = |
| 361 [self addText:string16() | 387 [self addText:string16() |
| 362 withSize:[NSFont smallSystemFontSize] | 388 withSize:[NSFont smallSystemFontSize] |
| 363 bold:NO | 389 bold:NO |
| 364 toView:contentView.get() | 390 toView:contentView.get() |
| 365 atPoint:textPosition]; | 391 atPoint:textPosition]; |
| 366 separatorAfterIdentity_ = [self addSeparatorToView:contentView]; | 392 separatorAfterIdentity_ = [self addSeparatorToView:contentView]; |
| 367 | 393 |
| 368 connectionStatusIcon_ = | 394 connectionStatusIcon_ = [self addImageWithSize:imageSize |
| 369 [self addImageToView:contentView atOffset:kTabViewContentsPadding]; | 395 toView:contentView |
| 396 atOffset:kTabViewContentsPadding]; | |
| 370 connectionStatusDescriptionField_ = | 397 connectionStatusDescriptionField_ = |
| 371 [self addText:string16() | 398 [self addText:string16() |
| 372 withSize:[NSFont smallSystemFontSize] | 399 withSize:[NSFont smallSystemFontSize] |
| 373 bold:NO | 400 bold:NO |
| 374 toView:contentView.get() | 401 toView:contentView.get() |
| 375 atPoint:textPosition]; | 402 atPoint:textPosition]; |
| 376 separatorAfterConnection_ = [self addSeparatorToView:contentView]; | 403 separatorAfterConnection_ = [self addSeparatorToView:contentView]; |
| 377 | 404 |
| 378 firstVisitIcon_ = | 405 firstVisitIcon_ = [self addImageWithSize:imageSize |
| 379 [self addImageToView:contentView atOffset:kTabViewContentsPadding]; | 406 toView:contentView |
| 407 atOffset:kTabViewContentsPadding]; | |
| 380 firstVisitHeaderField_ = | 408 firstVisitHeaderField_ = |
| 381 [self addText:l10n_util::GetStringUTF16(IDS_PAGE_INFO_SITE_INFO_TITLE) | 409 [self addText:l10n_util::GetStringUTF16(IDS_PAGE_INFO_SITE_INFO_TITLE) |
| 382 withSize:[NSFont smallSystemFontSize] | 410 withSize:[NSFont smallSystemFontSize] |
| 383 bold:YES | 411 bold:YES |
| 384 toView:contentView.get() | 412 toView:contentView.get() |
| 385 atPoint:textPosition]; | 413 atPoint:textPosition]; |
| 386 firstVisitDescriptionField_ = | 414 firstVisitDescriptionField_ = |
| 387 [self addText:string16() | 415 [self addText:string16() |
| 388 withSize:[NSFont smallSystemFontSize] | 416 withSize:[NSFont smallSystemFontSize] |
| 389 bold:NO | 417 bold:NO |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 407 | 435 |
| 408 // Layout all of the controls in the window. This should be called whenever | 436 // Layout all of the controls in the window. This should be called whenever |
| 409 // the content has changed. | 437 // the content has changed. |
| 410 - (void)performLayout { | 438 - (void)performLayout { |
| 411 // Place the identity status immediately below the identity. | 439 // Place the identity status immediately below the identity. |
| 412 [self sizeTextFieldHeightToFit:identityField_]; | 440 [self sizeTextFieldHeightToFit:identityField_]; |
| 413 [self sizeTextFieldHeightToFit:identityStatusField_]; | 441 [self sizeTextFieldHeightToFit:identityStatusField_]; |
| 414 CGFloat yPos = NSMaxY([identityField_ frame]) + kHeadlineSpacing; | 442 CGFloat yPos = NSMaxY([identityField_ frame]) + kHeadlineSpacing; |
| 415 yPos = [self setYPositionOfView:identityStatusField_ to:yPos]; | 443 yPos = [self setYPositionOfView:identityStatusField_ to:yPos]; |
| 416 | 444 |
| 417 // Lay out the connection tab. | 445 // Lay out the Permissions tab. |
| 446 NSRect permissionsViewFrame = [permissionsView_ frame]; | |
| 447 permissionsViewFrame.origin.y = NSMaxY([cookiesView_ frame]); | |
| 448 [permissionsView_ setFrame:permissionsViewFrame]; | |
| 449 | |
| 450 // Lay out the Connection tab. | |
| 418 | 451 |
| 419 // Lay out the identity status section. | 452 // Lay out the identity status section. |
| 420 [self sizeTextFieldHeightToFit:identityStatusDescriptionField_]; | 453 [self sizeTextFieldHeightToFit:identityStatusDescriptionField_]; |
| 421 yPos = std::max(NSMaxY([identityStatusDescriptionField_ frame]), | 454 yPos = std::max(NSMaxY([identityStatusDescriptionField_ frame]), |
| 422 NSMaxY([identityStatusIcon_ frame])); | 455 NSMaxY([identityStatusIcon_ frame])); |
| 423 yPos = [self setYPositionOfView:separatorAfterIdentity_ | 456 yPos = [self setYPositionOfView:separatorAfterIdentity_ |
| 424 to:yPos + kVerticalSpacing]; | 457 to:yPos + kVerticalSpacing]; |
| 425 yPos += kVerticalSpacing; | 458 yPos += kVerticalSpacing; |
| 426 | 459 |
| 427 // Lay out the connection status section. | 460 // Lay out the connection status section. |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 445 // Adjust the tab view size and place it below the identity status. | 478 // Adjust the tab view size and place it below the identity status. |
| 446 | 479 |
| 447 NSRect segmentedControlFrame = [segmentedControl_ frame]; | 480 NSRect segmentedControlFrame = [segmentedControl_ frame]; |
| 448 segmentedControlFrame.origin.y = | 481 segmentedControlFrame.origin.y = |
| 449 NSMaxY([identityStatusField_ frame]); | 482 NSMaxY([identityStatusField_ frame]); |
| 450 [segmentedControl_ setFrame:segmentedControlFrame]; | 483 [segmentedControl_ setFrame:segmentedControlFrame]; |
| 451 | 484 |
| 452 NSRect tabViewFrame = [tabView_ frame]; | 485 NSRect tabViewFrame = [tabView_ frame]; |
| 453 tabViewFrame.origin.y = NSMaxY(segmentedControlFrame); | 486 tabViewFrame.origin.y = NSMaxY(segmentedControlFrame); |
| 454 | 487 |
| 488 // Determine the height of the tab contents. | |
| 489 | |
| 455 CGFloat connectionTabHeight = std::max( | 490 CGFloat connectionTabHeight = std::max( |
| 456 NSMaxY([firstVisitDescriptionField_ frame]), | 491 NSMaxY([firstVisitDescriptionField_ frame]), |
| 457 NSMaxY([firstVisitIcon_ frame ])); | 492 NSMaxY([firstVisitIcon_ frame ])); |
| 458 connectionTabHeight += kVerticalSpacing; | 493 connectionTabHeight += kVerticalSpacing; |
| 459 | 494 |
| 495 CGFloat permissionsTabHeight = | |
| 496 NSHeight([cookiesView_ frame]) + NSHeight([permissionsView_ frame]); | |
| 497 | |
| 460 CGFloat tabContentHeight = std::max(connectionTabHeight, | 498 CGFloat tabContentHeight = std::max(connectionTabHeight, |
| 461 permissionsTabHeight_); | 499 permissionsTabHeight); |
| 462 tabViewFrame.size.height = tabContentHeight + | 500 tabViewFrame.size.height = tabContentHeight + |
| 463 NSHeight(tabViewFrame) - NSHeight([tabView_ contentRect]); | 501 NSHeight(tabViewFrame) - NSHeight([tabView_ contentRect]); |
| 464 [tabView_ setFrame:tabViewFrame]; | 502 [tabView_ setFrame:tabViewFrame]; |
| 465 | 503 |
| 466 // Adjust the contentView to fit everything. | 504 // Adjust the contentView to fit everything. |
| 467 [contentView_ setFrame:NSMakeRect( | 505 [contentView_ setFrame:NSMakeRect( |
| 468 0, 0, kWindowWidth, NSMaxY([tabView_ frame]))]; | 506 0, 0, kWindowWidth, NSMaxY([tabView_ frame]))]; |
| 469 | 507 |
| 470 // Now adjust and position the window. | 508 // Now adjust and position the window. |
| 471 | 509 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 529 // Create a new text field and add it to the given array of subviews. | 567 // Create a new text field and add it to the given array of subviews. |
| 530 // The array will retain a reference to the object. | 568 // The array will retain a reference to the object. |
| 531 - (NSTextField*)addText:(const string16&)text | 569 - (NSTextField*)addText:(const string16&)text |
| 532 withSize:(CGFloat)fontSize | 570 withSize:(CGFloat)fontSize |
| 533 bold:(BOOL)bold | 571 bold:(BOOL)bold |
| 534 toView:(NSView*)view | 572 toView:(NSView*)view |
| 535 atPoint:(NSPoint)point { | 573 atPoint:(NSPoint)point { |
| 536 // Size the text to take up the full available width, with some padding. | 574 // Size the text to take up the full available width, with some padding. |
| 537 // The height is arbitrary as it will be adjusted later. | 575 // The height is arbitrary as it will be adjusted later. |
| 538 CGFloat width = NSWidth([view frame]) - point.x - kFramePadding; | 576 CGFloat width = NSWidth([view frame]) - point.x - kFramePadding; |
| 539 NSRect frame = NSMakeRect(point.x, point.y, width, kImageSize); | 577 NSRect frame = NSMakeRect(point.x, point.y, width, 100); |
| 540 scoped_nsobject<NSTextField> textField( | 578 scoped_nsobject<NSTextField> textField( |
| 541 [[NSTextField alloc] initWithFrame:frame]); | 579 [[NSTextField alloc] initWithFrame:frame]); |
| 542 [self configureTextFieldAsLabel:textField.get()]; | 580 [self configureTextFieldAsLabel:textField.get()]; |
| 543 [textField setStringValue:base::SysUTF16ToNSString(text)]; | 581 [textField setStringValue:base::SysUTF16ToNSString(text)]; |
| 544 NSFont* font = bold ? [NSFont boldSystemFontOfSize:fontSize] | 582 NSFont* font = bold ? [NSFont boldSystemFontOfSize:fontSize] |
| 545 : [NSFont systemFontOfSize:fontSize]; | 583 : [NSFont systemFontOfSize:fontSize]; |
| 546 [textField setFont:font]; | 584 [textField setFont:font]; |
| 547 [self sizeTextFieldHeightToFit:textField]; | 585 [self sizeTextFieldHeightToFit:textField]; |
| 548 [view addSubview:textField.get()]; | 586 [view addSubview:textField.get()]; |
| 549 return textField.get(); | 587 return textField.get(); |
| 550 } | 588 } |
| 551 | 589 |
| 552 // Add an image as a subview of the given view, placed at a pre-determined x | 590 // Add an image as a subview of the given view, placed at a pre-determined x |
| 553 // position and the given y position. Return the new NSImageView. | 591 // position and the given y position. Return the new NSImageView. |
| 554 - (NSImageView*)addImageToView:(NSView*)view | 592 - (NSImageView*)addImageWithSize:(NSSize)size |
| 555 atOffset:(CGFloat)offset { | 593 toView:(NSView*)view |
| 556 NSRect frame = NSMakeRect(kFramePadding, offset, kImageSize, kImageSize); | 594 atOffset:(CGFloat)offset { |
| 595 NSRect frame = NSMakeRect(kFramePadding, offset, size.width, size.height); | |
| 557 scoped_nsobject<NSImageView> imageView( | 596 scoped_nsobject<NSImageView> imageView( |
| 558 [[NSImageView alloc] initWithFrame:frame]); | 597 [[NSImageView alloc] initWithFrame:frame]); |
| 559 [imageView setImageFrameStyle:NSImageFrameNone]; | 598 [imageView setImageFrameStyle:NSImageFrameNone]; |
| 560 [view addSubview:imageView.get()]; | 599 [view addSubview:imageView.get()]; |
| 561 return imageView.get(); | 600 return imageView.get(); |
| 562 } | 601 } |
| 563 | 602 |
| 564 // Add a separator as a subview of the given view. Return the new view. | 603 // Add a separator as a subview of the given view. Return the new view. |
| 565 - (NSView*)addSeparatorToView:(NSView*)view { | 604 - (NSView*)addSeparatorToView:(NSView*)view { |
| 566 // Take up almost the full width of the container's frame. | 605 // Take up almost the full width of the container's frame. |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 665 if (presenter_.get()) | 704 if (presenter_.get()) |
| 666 presenter_->OnSitePermissionChanged(type, newSetting); | 705 presenter_->OnSitePermissionChanged(type, newSetting); |
| 667 } | 706 } |
| 668 | 707 |
| 669 // Adds a new row to the UI listing the permissions. Returns the amount of | 708 // Adds a new row to the UI listing the permissions. Returns the amount of |
| 670 // vertical space that was taken up by the row. | 709 // vertical space that was taken up by the row. |
| 671 - (CGFloat)addPermission: | 710 - (CGFloat)addPermission: |
| 672 (const WebsiteSettingsUI::PermissionInfo&)permissionInfo | 711 (const WebsiteSettingsUI::PermissionInfo&)permissionInfo |
| 673 toView:(NSView*)view | 712 toView:(NSView*)view |
| 674 atPoint:(NSPoint)point { | 713 atPoint:(NSPoint)point { |
| 714 // TODO(dubroy): Remove this check by refactoring GetPermissionIcon to take | |
| 715 // the PermissionInfo object as its argument. | |
| 716 ContentSetting setting = permissionInfo.setting == CONTENT_SETTING_DEFAULT ? | |
| 717 permissionInfo.default_setting : permissionInfo.setting; | |
| 718 NSImage* image = WebsiteSettingsUI::GetPermissionIcon( | |
| 719 permissionInfo.type, setting).ToNSImage(); | |
| 720 NSImageView* imageView = [self addImageWithSize:[image size] | |
| 721 toView:view | |
| 722 atOffset:point.y]; | |
| 723 [imageView setImage:image]; | |
| 724 point.x += kPermissionImageSize + kPermissionImageSpacing; | |
| 725 | |
| 675 string16 labelText = | 726 string16 labelText = |
| 676 WebsiteSettingsUI::PermissionTypeToUIString(permissionInfo.type) + | 727 WebsiteSettingsUI::PermissionTypeToUIString(permissionInfo.type) + |
| 677 ASCIIToUTF16(":"); | 728 ASCIIToUTF16(":"); |
| 678 | 729 |
| 679 NSTextField* label = [self addText:labelText | 730 NSTextField* label = [self addText:labelText |
| 680 withSize:[NSFont smallSystemFontSize] | 731 withSize:[NSFont smallSystemFontSize] |
| 681 bold:NO | 732 bold:NO |
| 682 toView:view | 733 toView:view |
| 683 atPoint:point]; | 734 atPoint:point]; |
| 684 | 735 |
| 685 // Shrink the label to fit the text width. | 736 // Shrink the label to fit the text width. |
| 686 NSSize requiredSize = [[label cell] cellSizeForBounds:[label frame]]; | 737 NSSize requiredSize = [[label cell] cellSizeForBounds:[label frame]]; |
| 687 [label setFrameSize:requiredSize]; | 738 [label setFrameSize:requiredSize]; |
| 688 | 739 |
| 689 NSPoint popUpPosition = NSMakePoint(NSMaxX([label frame]), point.y); | 740 NSPoint popUpPosition = NSMakePoint(NSMaxX([label frame]), point.y); |
| 690 NSPopUpButton* button = [self addPopUpButtonForPermission:permissionInfo | 741 NSPopUpButton* button = [self addPopUpButtonForPermission:permissionInfo |
| 691 toView:view | 742 toView:view |
| 692 atPoint:popUpPosition]; | 743 atPoint:popUpPosition]; |
| 693 | 744 |
| 694 // Adjust the vertical position of the button so that its title text is | 745 // Adjust the vertical position of the button so that its title text is |
| 695 // aligned with the label. Assumes that the text is the same size in both. | 746 // aligned with the label. Assumes that the text is the same size in both. |
| 696 NSRect titleRect = [[button cell] titleRectForBounds:[button bounds]]; | 747 NSRect titleRect = [[button cell] titleRectForBounds:[button bounds]]; |
| 697 popUpPosition.y -= titleRect.origin.y; | 748 popUpPosition.y -= titleRect.origin.y; |
| 698 [button setFrameOrigin:popUpPosition]; | 749 [button setFrameOrigin:popUpPosition]; |
| 699 | 750 |
| 751 // Align the icon with the text. | |
| 752 [self alignPermissionIcon:imageView withTextField:label]; | |
| 753 | |
| 700 return std::max(NSHeight([label frame]), NSHeight([button frame])); | 754 return std::max(NSHeight([label frame]), NSHeight([button frame])); |
| 701 } | 755 } |
| 702 | 756 |
| 757 // Align an image with a text field by vertically centering the image on | |
| 758 // the cap height of the first line of text. | |
| 759 - (void)alignPermissionIcon:(NSImageView*)imageView | |
| 760 withTextField:(NSTextField*)textField { | |
| 761 NSFont* font = [textField font]; | |
| 762 | |
| 763 // Calculate the offset from the top of the text field. | |
| 764 CGFloat capHeight = [font capHeight]; | |
| 765 CGFloat offset = (kPermissionImageSize - capHeight) / 2 - | |
| 766 ([font ascender] - capHeight) - kPermissionImageYAdjust; | |
| 767 | |
| 768 NSRect frame = [imageView frame]; | |
| 769 frame.origin.y -= offset; | |
| 770 [imageView setFrame:frame]; | |
| 771 } | |
| 772 | |
| 773 - (CGFloat)addCookieInfo: | |
| 774 (const WebsiteSettingsUI::CookieInfo&)cookieInfo | |
| 775 toView:(NSView*)view | |
| 776 atPoint:(NSPoint)point { | |
| 777 NSImage* image = WebsiteSettingsUI::GetPermissionIcon( | |
| 778 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_ALLOW).ToNSImage(); | |
| 779 NSImageView* imageView = [self addImageWithSize:[image size] | |
| 780 toView:view | |
| 781 atOffset:point.y]; | |
| 782 [imageView setImage:image]; | |
| 783 point.x += kPermissionImageSize + kPermissionImageSpacing; | |
| 784 | |
| 785 string16 labelText = l10n_util::GetStringFUTF16( | |
| 786 IDS_WEBSITE_SETTINGS_SITE_DATA_STATS_LINE, | |
| 787 UTF8ToUTF16(cookieInfo.cookie_source), | |
| 788 base::IntToString16(cookieInfo.allowed), | |
| 789 base::IntToString16(cookieInfo.blocked)); | |
| 790 | |
| 791 NSTextField* label = [self addText:labelText | |
| 792 withSize:[NSFont smallSystemFontSize] | |
| 793 bold:NO | |
| 794 toView:view | |
| 795 atPoint:point]; | |
| 796 | |
| 797 // Shrink the label to fit the text width. | |
| 798 NSSize requiredSize = [[label cell] cellSizeForBounds:[label frame]]; | |
| 799 [label setFrameSize:requiredSize]; | |
| 800 | |
| 801 // Align the icon with the text. | |
| 802 [self alignPermissionIcon:imageView withTextField:label]; | |
| 803 | |
| 804 return NSHeight([label frame]); | |
| 805 } | |
| 806 | |
| 703 // Set the content of the identity and identity status fields. | 807 // Set the content of the identity and identity status fields. |
| 704 - (void)setIdentityInfo:(const WebsiteSettingsUI::IdentityInfo&)identityInfo { | 808 - (void)setIdentityInfo:(const WebsiteSettingsUI::IdentityInfo&)identityInfo { |
| 705 [identityField_ setStringValue: | 809 [identityField_ setStringValue: |
| 706 base::SysUTF8ToNSString(identityInfo.site_identity)]; | 810 base::SysUTF8ToNSString(identityInfo.site_identity)]; |
| 707 [identityStatusField_ setStringValue: | 811 [identityStatusField_ setStringValue: |
| 708 base::SysUTF16ToNSString(identityInfo.GetIdentityStatusText())]; | 812 base::SysUTF16ToNSString(identityInfo.GetIdentityStatusText())]; |
| 709 | 813 |
| 814 WebsiteSettings::SiteIdentityStatus status = identityInfo.identity_status; | |
| 815 if (status == WebsiteSettings::SITE_IDENTITY_STATUS_CERT || | |
| 816 status == WebsiteSettings::SITE_IDENTITY_STATUS_DNSSEC_CERT || | |
| 817 status == WebsiteSettings::SITE_IDENTITY_STATUS_EV_CERT) { | |
| 818 [identityStatusField_ setTextColor:IdentityVerifiedTextColor()]; | |
| 819 } | |
| 820 | |
| 710 [identityStatusIcon_ setImage:WebsiteSettingsUI::GetIdentityIcon( | 821 [identityStatusIcon_ setImage:WebsiteSettingsUI::GetIdentityIcon( |
| 711 identityInfo.identity_status).ToNSImage()]; | 822 identityInfo.identity_status).ToNSImage()]; |
| 712 [identityStatusDescriptionField_ setStringValue: | 823 [identityStatusDescriptionField_ setStringValue: |
| 713 base::SysUTF8ToNSString(identityInfo.identity_status_description)]; | 824 base::SysUTF8ToNSString(identityInfo.identity_status_description)]; |
| 714 | 825 |
| 715 [connectionStatusIcon_ setImage:WebsiteSettingsUI::GetConnectionIcon( | 826 [connectionStatusIcon_ setImage:WebsiteSettingsUI::GetConnectionIcon( |
| 716 identityInfo.connection_status).ToNSImage()]; | 827 identityInfo.connection_status).ToNSImage()]; |
| 717 [connectionStatusDescriptionField_ setStringValue: | 828 [connectionStatusDescriptionField_ setStringValue: |
| 718 base::SysUTF8ToNSString(identityInfo.connection_status_description)]; | 829 base::SysUTF8ToNSString(identityInfo.connection_status_description)]; |
| 719 | 830 |
| 720 [self performLayout]; | 831 [self performLayout]; |
| 721 } | 832 } |
| 722 | 833 |
| 834 - (void)setCookieInfo:(const CookieInfoList&)cookieInfoList { | |
| 835 [cookiesView_ setSubviews:[NSArray array]]; | |
| 836 NSPoint controlOrigin = NSMakePoint(kFramePadding, kFramePadding); | |
| 837 | |
| 838 NSTextField* header = [self addText:ASCIIToUTF16("Cookies") | |
| 839 withSize:[NSFont smallSystemFontSize] | |
| 840 bold:YES | |
| 841 toView:cookiesView_ | |
| 842 atPoint:controlOrigin]; | |
| 843 [self sizeTextFieldHeightToFit:header]; | |
| 844 controlOrigin.y += NSHeight([header frame]) + kPermissionsTabSpacing; | |
| 845 | |
| 846 for (CookieInfoList::const_iterator it = cookieInfoList.begin(); | |
| 847 it != cookieInfoList.end(); | |
| 848 ++it) { | |
| 849 CGFloat rowHeight = [self addCookieInfo:*it | |
| 850 toView:cookiesView_ | |
| 851 atPoint:controlOrigin]; | |
| 852 controlOrigin.y += rowHeight + kPermissionsTabSpacing; | |
| 853 } | |
| 854 [cookiesView_ setFrameSize:NSMakeSize(kWindowWidth, controlOrigin.y)]; | |
| 855 } | |
| 856 | |
| 857 - (void)setPermissionInfo:(const PermissionInfoList&)permissionInfoList { | |
| 858 [permissionsView_ setSubviews:[NSArray array]]; | |
| 859 NSPoint controlOrigin = NSMakePoint(kFramePadding, kFramePadding); | |
| 860 | |
| 861 NSTextField* header = [self addText:ASCIIToUTF16("Permissions") | |
| 862 withSize:[NSFont smallSystemFontSize] | |
| 863 bold:YES | |
| 864 toView:permissionsView_ | |
| 865 atPoint:controlOrigin]; | |
| 866 [self sizeTextFieldHeightToFit:header]; | |
| 867 controlOrigin.y += NSHeight([header frame]) + kPermissionsTabSpacing; | |
| 868 | |
| 869 for (PermissionInfoList::const_iterator permission = | |
| 870 permissionInfoList.begin(); | |
| 871 permission != permissionInfoList.end(); | |
| 872 ++permission) { | |
| 873 CGFloat rowHeight = [self addPermission:*permission | |
| 874 toView:permissionsView_ | |
| 875 atPoint:controlOrigin]; | |
| 876 controlOrigin.y += rowHeight + kPermissionsTabSpacing; | |
| 877 } | |
| 878 [permissionsView_ setFrameSize:NSMakeSize(kWindowWidth, controlOrigin.y)]; | |
| 879 } | |
| 880 | |
| 723 - (void)setFirstVisit:(const string16&)firstVisit { | 881 - (void)setFirstVisit:(const string16&)firstVisit { |
| 724 [firstVisitIcon_ setImage: | 882 [firstVisitIcon_ setImage: |
| 725 WebsiteSettingsUI::GetFirstVisitIcon(firstVisit).ToNSImage()]; | 883 WebsiteSettingsUI::GetFirstVisitIcon(firstVisit).ToNSImage()]; |
| 726 [firstVisitDescriptionField_ setStringValue: | 884 [firstVisitDescriptionField_ setStringValue: |
| 727 base::SysUTF16ToNSString(firstVisit)]; | 885 base::SysUTF16ToNSString(firstVisit)]; |
| 728 [self performLayout]; | 886 [self performLayout]; |
| 729 } | 887 } |
| 730 | 888 |
| 731 - (void)setPermissionInfo:(const PermissionInfoList&)permissionInfoList { | |
| 732 [permissionsContentView_ setSubviews:[NSArray array]]; | |
| 733 NSPoint controlOrigin = NSMakePoint(kFramePadding, kFramePadding); | |
| 734 | |
| 735 for (PermissionInfoList::const_iterator permission = | |
| 736 permissionInfoList.begin(); | |
| 737 permission != permissionInfoList.end(); | |
| 738 ++permission) { | |
| 739 CGFloat rowHeight = [self addPermission:*permission | |
| 740 toView:permissionsContentView_ | |
| 741 atPoint:controlOrigin]; | |
| 742 controlOrigin.y += rowHeight + kPermissionsTabSpacing; | |
| 743 } | |
| 744 permissionsTabHeight_ = controlOrigin.y; | |
| 745 } | |
| 746 | |
| 747 @end | 889 @end |
| 748 | 890 |
| 749 WebsiteSettingsUIBridge::WebsiteSettingsUIBridge() | 891 WebsiteSettingsUIBridge::WebsiteSettingsUIBridge() |
| 750 : bubble_controller_(nil) { | 892 : bubble_controller_(nil) { |
| 751 } | 893 } |
| 752 | 894 |
| 753 WebsiteSettingsUIBridge::~WebsiteSettingsUIBridge() { | 895 WebsiteSettingsUIBridge::~WebsiteSettingsUIBridge() { |
| 754 } | 896 } |
| 755 | 897 |
| 756 void WebsiteSettingsUIBridge::set_bubble_controller( | 898 void WebsiteSettingsUIBridge::set_bubble_controller( |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 779 tab_contents->content_settings(), | 921 tab_contents->content_settings(), |
| 780 tab_contents->infobar_tab_helper(), | 922 tab_contents->infobar_tab_helper(), |
| 781 url, | 923 url, |
| 782 ssl, | 924 ssl, |
| 783 content::CertStore::GetInstance()); | 925 content::CertStore::GetInstance()); |
| 784 [bubble_controller setPresenter:presenter]; | 926 [bubble_controller setPresenter:presenter]; |
| 785 | 927 |
| 786 [bubble_controller showWindow:nil]; | 928 [bubble_controller showWindow:nil]; |
| 787 } | 929 } |
| 788 | 930 |
| 931 void WebsiteSettingsUIBridge::SetIdentityInfo( | |
| 932 const WebsiteSettingsUI::IdentityInfo& identity_info) { | |
| 933 [bubble_controller_ setIdentityInfo:identity_info]; | |
| 934 } | |
| 935 | |
| 789 void WebsiteSettingsUIBridge::SetCookieInfo( | 936 void WebsiteSettingsUIBridge::SetCookieInfo( |
| 790 const CookieInfoList& cookie_info_list) { | 937 const CookieInfoList& cookie_info_list) { |
| 938 [bubble_controller_ setCookieInfo:cookie_info_list]; | |
| 791 } | 939 } |
| 792 | 940 |
| 793 void WebsiteSettingsUIBridge::SetPermissionInfo( | 941 void WebsiteSettingsUIBridge::SetPermissionInfo( |
| 794 const PermissionInfoList& permission_info_list) { | 942 const PermissionInfoList& permission_info_list) { |
| 795 [bubble_controller_ setPermissionInfo:permission_info_list]; | 943 [bubble_controller_ setPermissionInfo:permission_info_list]; |
| 796 } | 944 } |
| 797 | 945 |
| 798 void WebsiteSettingsUIBridge::SetIdentityInfo( | |
| 799 const WebsiteSettingsUI::IdentityInfo& identity_info) { | |
| 800 [bubble_controller_ setIdentityInfo:identity_info]; | |
| 801 } | |
| 802 | |
| 803 void WebsiteSettingsUIBridge::SetFirstVisit(const string16& first_visit) { | 946 void WebsiteSettingsUIBridge::SetFirstVisit(const string16& first_visit) { |
| 804 [bubble_controller_ setFirstVisit:first_visit]; | 947 [bubble_controller_ setFirstVisit:first_visit]; |
| 805 } | 948 } |
| OLD | NEW |