Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "chrome/browser/ui/cocoa/content_setting_bubble_cocoa.h" | 5 #import "chrome/browser/ui/cocoa/content_setting_bubble_cocoa.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 308 | 308 |
| 309 - (void)initializeGeoLists { | 309 - (void)initializeGeoLists { |
| 310 // Cocoa has its origin in the lower left corner. This means elements are | 310 // Cocoa has its origin in the lower left corner. This means elements are |
| 311 // added from bottom to top, which explains why loops run backwards and the | 311 // added from bottom to top, which explains why loops run backwards and the |
| 312 // order of operations is the other way than on Linux/Windows. | 312 // order of operations is the other way than on Linux/Windows. |
| 313 const ContentSettingBubbleModel::BubbleContent& content = | 313 const ContentSettingBubbleModel::BubbleContent& content = |
| 314 contentSettingBubbleModel_->bubble_content(); | 314 contentSettingBubbleModel_->bubble_content(); |
| 315 NSRect containerFrame = [contentsContainer_ frame]; | 315 NSRect containerFrame = [contentsContainer_ frame]; |
| 316 NSRect frame = NSMakeRect(0, 0, NSWidth(containerFrame), kGeoLabelHeight); | 316 NSRect frame = NSMakeRect(0, 0, NSWidth(containerFrame), kGeoLabelHeight); |
| 317 | 317 |
| 318 // "Clear" button. | 318 // "Clear" button / text field. |
| 319 if (!content.clear_link.empty()) { | 319 if (!content.custom_link.empty()) { |
| 320 NSRect buttonFrame = NSMakeRect(0, 0, | 320 NSControl* control = nil; |
| 321 NSWidth(containerFrame), | 321 if(content.custom_link_enabled) { |
| 322 kGeoClearButtonHeight); | 322 NSRect buttonFrame = NSMakeRect(0, 0, |
| 323 scoped_nsobject<NSButton> button([[NSButton alloc] | 323 NSWidth(containerFrame), |
| 324 initWithFrame:buttonFrame]); | 324 kGeoClearButtonHeight); |
| 325 [button setTitle:base::SysUTF8ToNSString(content.clear_link)]; | 325 scoped_nsobject<NSButton> button([[NSButton alloc] |
| 326 [button setTarget:self]; | 326 initWithFrame:buttonFrame]); |
| 327 [button setAction:@selector(clearGeolocationForCurrentHost:)]; | 327 [button setTitle:base::SysUTF8ToNSString(content.custom_link)]; |
| 328 [button setBezelStyle:NSRoundRectBezelStyle]; | 328 [button setTarget:self]; |
| 329 SetControlSize(button, NSSmallControlSize); | 329 [button setAction:@selector(clearGeolocationForCurrentHost:)]; |
| 330 [button sizeToFit]; | 330 [button setBezelStyle:NSRoundRectBezelStyle]; |
| 331 SetControlSize(button, NSSmallControlSize); | |
| 332 [button sizeToFit]; | |
| 333 control = button.release(); | |
|
Nico
2010/12/09 06:41:46
This is wrong – please read http://developer.apple
| |
| 334 } else { | |
| 335 // Add the notification that settings will be cleared on next reload. | |
| 336 scoped_nsobject<NSTextField> custom_text( | |
| 337 LabelWithFrame(base::SysUTF8ToNSString(content.custom_link), frame)); | |
|
Nico
2010/12/09 06:41:46
LabelWithFrame() returns an autoreleased object.
| |
| 338 SetControlSize(custom_text, NSSmallControlSize); | |
| 339 control = custom_text.release(); | |
| 340 } | |
| 331 | 341 |
| 332 // If the button is wider than the container, widen the window. | 342 // If the new control is wider than the container, widen the window. |
| 333 CGFloat buttonWidth = NSWidth([button frame]); | 343 CGFloat controlWidth = NSWidth([control frame]); |
| 334 if (buttonWidth > NSWidth(containerFrame)) { | 344 if (controlWidth > NSWidth(containerFrame)) { |
| 335 NSRect windowFrame = [[self window] frame]; | 345 NSRect windowFrame = [[self window] frame]; |
| 336 windowFrame.size.width += buttonWidth - NSWidth(containerFrame); | 346 windowFrame.size.width += controlWidth - NSWidth(containerFrame); |
| 337 [[self window] setFrame:windowFrame display:NO]; | 347 [[self window] setFrame:windowFrame display:NO]; |
| 338 // Fetch the updated sizes. | 348 // Fetch the updated sizes. |
| 339 containerFrame = [contentsContainer_ frame]; | 349 containerFrame = [contentsContainer_ frame]; |
| 340 frame = NSMakeRect(0, 0, NSWidth(containerFrame), kGeoLabelHeight); | 350 frame = NSMakeRect(0, 0, NSWidth(containerFrame), kGeoLabelHeight); |
| 341 } | 351 } |
| 342 | 352 |
| 343 // Add the button. | 353 DCHECK(control); |
| 344 [contentsContainer_ addSubview:button]; | 354 [contentsContainer_ addSubview:control]; |
| 345 | 355 frame.origin.y = NSMaxY([control frame]) + kGeoPadding; |
| 346 frame.origin.y = NSMaxY([button frame]) + kGeoPadding; | |
| 347 } | 356 } |
| 348 | 357 |
| 349 typedef | 358 typedef |
| 350 std::vector<ContentSettingBubbleModel::DomainList>::const_reverse_iterator | 359 std::vector<ContentSettingBubbleModel::DomainList>::const_reverse_iterator |
| 351 GeolocationGroupIterator; | 360 GeolocationGroupIterator; |
| 352 for (GeolocationGroupIterator i = content.domain_lists.rbegin(); | 361 for (GeolocationGroupIterator i = content.domain_lists.rbegin(); |
| 353 i != content.domain_lists.rend(); ++i) { | 362 i != content.domain_lists.rend(); ++i) { |
| 354 // Add all hosts in the current domain list. | 363 // Add all hosts in the current domain list. |
| 355 for (std::set<std::string>::const_reverse_iterator j = i->hosts.rbegin(); | 364 for (std::set<std::string>::const_reverse_iterator j = i->hosts.rbegin(); |
| 356 j != i->hosts.rend(); ++j) { | 365 j != i->hosts.rend(); ++j) { |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 383 NSRect windowFrame = [[self window] frame]; | 392 NSRect windowFrame = [[self window] frame]; |
| 384 windowFrame.size.height += containerHeight - NSHeight(containerFrame); | 393 windowFrame.size.height += containerHeight - NSHeight(containerFrame); |
| 385 [[self window] setFrame:windowFrame display:NO]; | 394 [[self window] setFrame:windowFrame display:NO]; |
| 386 containerFrame.size.height = containerHeight; | 395 containerFrame.size.height = containerHeight; |
| 387 [contentsContainer_ setFrame:containerFrame]; | 396 [contentsContainer_ setFrame:containerFrame]; |
| 388 } | 397 } |
| 389 | 398 |
| 390 - (void)sizeToFitLoadPluginsButton { | 399 - (void)sizeToFitLoadPluginsButton { |
| 391 const ContentSettingBubbleModel::BubbleContent& content = | 400 const ContentSettingBubbleModel::BubbleContent& content = |
| 392 contentSettingBubbleModel_->bubble_content(); | 401 contentSettingBubbleModel_->bubble_content(); |
| 393 [loadAllPluginsButton_ setEnabled:content.load_plugins_link_enabled]; | 402 [loadAllPluginsButton_ setEnabled:content.custom_link_enabled]; |
| 394 | 403 |
| 395 // Resize horizontally to fit button if necessary. | 404 // Resize horizontally to fit button if necessary. |
| 396 NSRect windowFrame = [[self window] frame]; | 405 NSRect windowFrame = [[self window] frame]; |
| 397 int widthNeeded = NSWidth([loadAllPluginsButton_ frame]) + | 406 int widthNeeded = NSWidth([loadAllPluginsButton_ frame]) + |
| 398 2 * NSMinX([loadAllPluginsButton_ frame]); | 407 2 * NSMinX([loadAllPluginsButton_ frame]); |
| 399 if (NSWidth(windowFrame) < widthNeeded) { | 408 if (NSWidth(windowFrame) < widthNeeded) { |
| 400 windowFrame.size.width = widthNeeded; | 409 windowFrame.size.width = widthNeeded; |
| 401 [[self window] setFrame:windowFrame display:NO]; | 410 [[self window] setFrame:windowFrame display:NO]; |
| 402 } | 411 } |
| 403 } | 412 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 444 | 453 |
| 445 /////////////////////////////////////////////////////////////////////////////// | 454 /////////////////////////////////////////////////////////////////////////////// |
| 446 // Actual application logic | 455 // Actual application logic |
| 447 | 456 |
| 448 - (IBAction)allowBlockToggled:(id)sender { | 457 - (IBAction)allowBlockToggled:(id)sender { |
| 449 NSButtonCell *selectedCell = [sender selectedCell]; | 458 NSButtonCell *selectedCell = [sender selectedCell]; |
| 450 contentSettingBubbleModel_->OnRadioClicked( | 459 contentSettingBubbleModel_->OnRadioClicked( |
| 451 [selectedCell tag] == kAllowTag ? 0 : 1); | 460 [selectedCell tag] == kAllowTag ? 0 : 1); |
| 452 } | 461 } |
| 453 | 462 |
| 454 - (IBAction)closeBubble:(id)sender { | |
| 455 [self close]; | |
| 456 } | |
| 457 | |
| 458 - (IBAction)manageBlocking:(id)sender { | |
| 459 contentSettingBubbleModel_->OnManageLinkClicked(); | |
| 460 } | |
| 461 | |
| 462 - (IBAction)showMoreInfo:(id)sender { | |
| 463 contentSettingBubbleModel_->OnInfoLinkClicked(); | |
| 464 [self close]; | |
| 465 } | |
| 466 | |
| 467 - (IBAction)loadAllPlugins:(id)sender { | |
| 468 contentSettingBubbleModel_->OnLoadPluginsLinkClicked(); | |
| 469 [self close]; | |
| 470 } | |
| 471 | |
| 472 - (void)popupLinkClicked:(id)sender { | 463 - (void)popupLinkClicked:(id)sender { |
| 473 content_setting_bubble::PopupLinks::iterator i(popupLinks_.find(sender)); | 464 content_setting_bubble::PopupLinks::iterator i(popupLinks_.find(sender)); |
| 474 DCHECK(i != popupLinks_.end()); | 465 DCHECK(i != popupLinks_.end()); |
| 475 contentSettingBubbleModel_->OnPopupClicked(i->second); | 466 contentSettingBubbleModel_->OnPopupClicked(i->second); |
| 476 } | 467 } |
| 477 | 468 |
| 478 - (void)clearGeolocationForCurrentHost:(id)sender { | 469 - (void)clearGeolocationForCurrentHost:(id)sender { |
| 479 contentSettingBubbleModel_->OnClearLinkClicked(); | 470 contentSettingBubbleModel_->OnCustomLinkClicked(); |
| 480 [self close]; | 471 [self close]; |
| 481 } | 472 } |
| 482 | 473 |
| 474 - (IBAction)showMoreInfo:(id)sender { | |
| 475 contentSettingBubbleModel_->OnCustomLinkClicked(); | |
| 476 [self close]; | |
| 477 } | |
| 478 | |
| 479 - (IBAction)loadAllPlugins:(id)sender { | |
| 480 contentSettingBubbleModel_->OnCustomLinkClicked(); | |
| 481 [self close]; | |
| 482 } | |
| 483 | |
| 484 - (IBAction)manageBlocking:(id)sender { | |
| 485 contentSettingBubbleModel_->OnManageLinkClicked(); | |
| 486 } | |
| 487 | |
| 488 - (IBAction)closeBubble:(id)sender { | |
| 489 [self close]; | |
| 490 } | |
| 491 | |
| 483 @end // ContentSettingBubbleController | 492 @end // ContentSettingBubbleController |
| OLD | NEW |