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