| 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 scoped_nsobject<NSControl> control; |
| 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 NSButton* button = [[NSButton alloc] initWithFrame:buttonFrame]; |
| 326 [button setTarget:self]; | 326 control.reset(button); |
| 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 } else { |
| 334 // Add the notification that settings will be cleared on next reload. |
| 335 control.reset([LabelWithFrame( |
| 336 base::SysUTF8ToNSString(content.custom_link), frame) retain]); |
| 337 SetControlSize(control.get(), NSSmallControlSize); |
| 338 } |
| 331 | 339 |
| 332 // If the button is wider than the container, widen the window. | 340 // If the new control is wider than the container, widen the window. |
| 333 CGFloat buttonWidth = NSWidth([button frame]); | 341 CGFloat controlWidth = NSWidth([control frame]); |
| 334 if (buttonWidth > NSWidth(containerFrame)) { | 342 if (controlWidth > NSWidth(containerFrame)) { |
| 335 NSRect windowFrame = [[self window] frame]; | 343 NSRect windowFrame = [[self window] frame]; |
| 336 windowFrame.size.width += buttonWidth - NSWidth(containerFrame); | 344 windowFrame.size.width += controlWidth - NSWidth(containerFrame); |
| 337 [[self window] setFrame:windowFrame display:NO]; | 345 [[self window] setFrame:windowFrame display:NO]; |
| 338 // Fetch the updated sizes. | 346 // Fetch the updated sizes. |
| 339 containerFrame = [contentsContainer_ frame]; | 347 containerFrame = [contentsContainer_ frame]; |
| 340 frame = NSMakeRect(0, 0, NSWidth(containerFrame), kGeoLabelHeight); | 348 frame = NSMakeRect(0, 0, NSWidth(containerFrame), kGeoLabelHeight); |
| 341 } | 349 } |
| 342 | 350 |
| 343 // Add the button. | 351 DCHECK(control); |
| 344 [contentsContainer_ addSubview:button]; | 352 [contentsContainer_ addSubview:control]; |
| 345 | 353 frame.origin.y = NSMaxY([control frame]) + kGeoPadding; |
| 346 frame.origin.y = NSMaxY([button frame]) + kGeoPadding; | |
| 347 } | 354 } |
| 348 | 355 |
| 349 typedef | 356 typedef |
| 350 std::vector<ContentSettingBubbleModel::DomainList>::const_reverse_iterator | 357 std::vector<ContentSettingBubbleModel::DomainList>::const_reverse_iterator |
| 351 GeolocationGroupIterator; | 358 GeolocationGroupIterator; |
| 352 for (GeolocationGroupIterator i = content.domain_lists.rbegin(); | 359 for (GeolocationGroupIterator i = content.domain_lists.rbegin(); |
| 353 i != content.domain_lists.rend(); ++i) { | 360 i != content.domain_lists.rend(); ++i) { |
| 354 // Add all hosts in the current domain list. | 361 // Add all hosts in the current domain list. |
| 355 for (std::set<std::string>::const_reverse_iterator j = i->hosts.rbegin(); | 362 for (std::set<std::string>::const_reverse_iterator j = i->hosts.rbegin(); |
| 356 j != i->hosts.rend(); ++j) { | 363 j != i->hosts.rend(); ++j) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 383 NSRect windowFrame = [[self window] frame]; | 390 NSRect windowFrame = [[self window] frame]; |
| 384 windowFrame.size.height += containerHeight - NSHeight(containerFrame); | 391 windowFrame.size.height += containerHeight - NSHeight(containerFrame); |
| 385 [[self window] setFrame:windowFrame display:NO]; | 392 [[self window] setFrame:windowFrame display:NO]; |
| 386 containerFrame.size.height = containerHeight; | 393 containerFrame.size.height = containerHeight; |
| 387 [contentsContainer_ setFrame:containerFrame]; | 394 [contentsContainer_ setFrame:containerFrame]; |
| 388 } | 395 } |
| 389 | 396 |
| 390 - (void)sizeToFitLoadPluginsButton { | 397 - (void)sizeToFitLoadPluginsButton { |
| 391 const ContentSettingBubbleModel::BubbleContent& content = | 398 const ContentSettingBubbleModel::BubbleContent& content = |
| 392 contentSettingBubbleModel_->bubble_content(); | 399 contentSettingBubbleModel_->bubble_content(); |
| 393 [loadAllPluginsButton_ setEnabled:content.load_plugins_link_enabled]; | 400 [loadAllPluginsButton_ setEnabled:content.custom_link_enabled]; |
| 394 | 401 |
| 395 // Resize horizontally to fit button if necessary. | 402 // Resize horizontally to fit button if necessary. |
| 396 NSRect windowFrame = [[self window] frame]; | 403 NSRect windowFrame = [[self window] frame]; |
| 397 int widthNeeded = NSWidth([loadAllPluginsButton_ frame]) + | 404 int widthNeeded = NSWidth([loadAllPluginsButton_ frame]) + |
| 398 2 * NSMinX([loadAllPluginsButton_ frame]); | 405 2 * NSMinX([loadAllPluginsButton_ frame]); |
| 399 if (NSWidth(windowFrame) < widthNeeded) { | 406 if (NSWidth(windowFrame) < widthNeeded) { |
| 400 windowFrame.size.width = widthNeeded; | 407 windowFrame.size.width = widthNeeded; |
| 401 [[self window] setFrame:windowFrame display:NO]; | 408 [[self window] setFrame:windowFrame display:NO]; |
| 402 } | 409 } |
| 403 } | 410 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 | 451 |
| 445 /////////////////////////////////////////////////////////////////////////////// | 452 /////////////////////////////////////////////////////////////////////////////// |
| 446 // Actual application logic | 453 // Actual application logic |
| 447 | 454 |
| 448 - (IBAction)allowBlockToggled:(id)sender { | 455 - (IBAction)allowBlockToggled:(id)sender { |
| 449 NSButtonCell *selectedCell = [sender selectedCell]; | 456 NSButtonCell *selectedCell = [sender selectedCell]; |
| 450 contentSettingBubbleModel_->OnRadioClicked( | 457 contentSettingBubbleModel_->OnRadioClicked( |
| 451 [selectedCell tag] == kAllowTag ? 0 : 1); | 458 [selectedCell tag] == kAllowTag ? 0 : 1); |
| 452 } | 459 } |
| 453 | 460 |
| 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 { | 461 - (void)popupLinkClicked:(id)sender { |
| 473 content_setting_bubble::PopupLinks::iterator i(popupLinks_.find(sender)); | 462 content_setting_bubble::PopupLinks::iterator i(popupLinks_.find(sender)); |
| 474 DCHECK(i != popupLinks_.end()); | 463 DCHECK(i != popupLinks_.end()); |
| 475 contentSettingBubbleModel_->OnPopupClicked(i->second); | 464 contentSettingBubbleModel_->OnPopupClicked(i->second); |
| 476 } | 465 } |
| 477 | 466 |
| 478 - (void)clearGeolocationForCurrentHost:(id)sender { | 467 - (void)clearGeolocationForCurrentHost:(id)sender { |
| 479 contentSettingBubbleModel_->OnClearLinkClicked(); | 468 contentSettingBubbleModel_->OnCustomLinkClicked(); |
| 480 [self close]; | 469 [self close]; |
| 481 } | 470 } |
| 482 | 471 |
| 472 - (IBAction)showMoreInfo:(id)sender { |
| 473 contentSettingBubbleModel_->OnCustomLinkClicked(); |
| 474 [self close]; |
| 475 } |
| 476 |
| 477 - (IBAction)loadAllPlugins:(id)sender { |
| 478 contentSettingBubbleModel_->OnCustomLinkClicked(); |
| 479 [self close]; |
| 480 } |
| 481 |
| 482 - (IBAction)manageBlocking:(id)sender { |
| 483 contentSettingBubbleModel_->OnManageLinkClicked(); |
| 484 } |
| 485 |
| 486 - (IBAction)closeBubble:(id)sender { |
| 487 [self close]; |
| 488 } |
| 489 |
| 483 @end // ContentSettingBubbleController | 490 @end // ContentSettingBubbleController |
| OLD | NEW |