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/cocoa/content_blocked_bubble_controller.h" | 5 #import "chrome/browser/cocoa/content_blocked_bubble_controller.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/mac_util.h" | 9 #include "base/mac_util.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 | 46 |
47 // Height of the "Clear" button in the geolocation bubble. | 47 // Height of the "Clear" button in the geolocation bubble. |
48 const int kGeoClearButtonHeight = 17; | 48 const int kGeoClearButtonHeight = 17; |
49 | 49 |
50 // General padding between elements in the geolocation bubble. | 50 // General padding between elements in the geolocation bubble. |
51 const int kGeoPadding = 8; | 51 const int kGeoPadding = 8; |
52 | 52 |
53 // Padding between host names in the geolocation bubble. | 53 // Padding between host names in the geolocation bubble. |
54 const int kGeoHostPadding = 4; | 54 const int kGeoHostPadding = 4; |
55 | 55 |
56 // Minimal padding between "Manage" and "Done" buttons. | |
57 const int kManageDonePadding = 8; | |
TVL
2010/04/06 12:02:09
rather then having padding constants, I usually tr
| |
56 | 58 |
57 // Like |ReplaceStringPlaceholders(const string16&, const string16&, size_t*)|, | 59 // Like |ReplaceStringPlaceholders(const string16&, const string16&, size_t*)|, |
58 // but for a NSString formatString. | 60 // but for a NSString formatString. |
59 NSString* ReplaceNSStringPlaceholders(NSString* formatString, | 61 NSString* ReplaceNSStringPlaceholders(NSString* formatString, |
60 const string16& a, | 62 const string16& a, |
61 size_t* offset) { | 63 size_t* offset) { |
62 return base::SysUTF16ToNSString( | 64 return base::SysUTF16ToNSString( |
63 ReplaceStringPlaceholders(base::SysNSStringToUTF16(formatString), | 65 ReplaceStringPlaceholders(base::SysNSStringToUTF16(formatString), |
64 a, | 66 a, |
65 offset)); | 67 offset)); |
(...skipping 24 matching lines...) Expand all Loading... | |
90 parentWindow:(NSWindow*)parentWindow | 92 parentWindow:(NSWindow*)parentWindow |
91 anchoredAt:(NSPoint)anchoredAt; | 93 anchoredAt:(NSPoint)anchoredAt; |
92 - (NSButton*)hyperlinkButtonWithFrame:(NSRect)frame | 94 - (NSButton*)hyperlinkButtonWithFrame:(NSRect)frame |
93 title:(NSString*)title | 95 title:(NSString*)title |
94 icon:(NSImage*)icon | 96 icon:(NSImage*)icon |
95 referenceFrame:(NSRect)referenceFrame; | 97 referenceFrame:(NSRect)referenceFrame; |
96 - (void)initializeTitle; | 98 - (void)initializeTitle; |
97 - (void)initializeRadioGroup; | 99 - (void)initializeRadioGroup; |
98 - (void)initializePopupList; | 100 - (void)initializePopupList; |
99 - (void)initializeGeoLists; | 101 - (void)initializeGeoLists; |
102 - (void)makeWideEnoughForManageDoneButtons; | |
100 - (void)popupLinkClicked:(id)sender; | 103 - (void)popupLinkClicked:(id)sender; |
101 - (void)clearGeolocationForCurrentHost:(id)sender; | 104 - (void)clearGeolocationForCurrentHost:(id)sender; |
102 @end | 105 @end |
103 | 106 |
104 @implementation ContentBlockedBubbleController | 107 @implementation ContentBlockedBubbleController |
105 | 108 |
106 + (ContentBlockedBubbleController*) | 109 + (ContentBlockedBubbleController*) |
107 showForModel:(ContentSettingBubbleModel*)contentSettingBubbleModel | 110 showForModel:(ContentSettingBubbleModel*)contentSettingBubbleModel |
108 parentWindow:(NSWindow*)parentWindow | 111 parentWindow:(NSWindow*)parentWindow |
109 anchoredAt:(NSPoint)anchor { | 112 anchoredAt:(NSPoint)anchor { |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
341 containerHeight -= kGeoPadding; | 344 containerHeight -= kGeoPadding; |
342 | 345 |
343 // Resize container to fit its subviews, and window to fit the container. | 346 // Resize container to fit its subviews, and window to fit the container. |
344 NSRect windowFrame = [[self window] frame]; | 347 NSRect windowFrame = [[self window] frame]; |
345 windowFrame.size.height += containerHeight - containerFrame.size.height; | 348 windowFrame.size.height += containerHeight - containerFrame.size.height; |
346 [[self window] setFrame:windowFrame display:NO]; | 349 [[self window] setFrame:windowFrame display:NO]; |
347 containerFrame.size.height = containerHeight; | 350 containerFrame.size.height = containerHeight; |
348 [contentsContainer_ setFrame:containerFrame]; | 351 [contentsContainer_ setFrame:containerFrame]; |
349 } | 352 } |
350 | 353 |
354 - (void)makeWideEnoughForManageDoneButtons { | |
355 CGFloat actualWidth = NSWidth([[[self window] contentView] frame]); | |
356 CGFloat requiredWidth = NSMaxX([manageButton_ frame]) + kManageDonePadding + | |
357 NSWidth([[doneButton_ superview] frame]) - NSMinX([doneButton_ frame]); | |
358 if (requiredWidth <= actualWidth || !doneButton_ || !manageButton_) | |
359 return; | |
360 | |
361 // Resize window, autoresizing takes care of the rest. | |
362 NSSize size = NSMakeSize(requiredWidth - actualWidth, 0); | |
363 size = [[[self window] contentView] convertSize:size toView:nil]; | |
364 NSRect frame = [[self window] frame]; | |
365 frame.origin.x -= size.width; | |
366 frame.size.width += size.width; | |
367 [[self window] setFrame:frame display:NO]; | |
368 } | |
369 | |
351 - (void)awakeFromNib { | 370 - (void)awakeFromNib { |
352 DCHECK([self window]); | 371 DCHECK([self window]); |
353 DCHECK_EQ(self, [[self window] delegate]); | 372 DCHECK_EQ(self, [[self window] delegate]); |
354 | 373 |
355 [bubble_ setBubbleType:kWhiteInfoBubble]; | 374 [bubble_ setBubbleType:kWhiteInfoBubble]; |
356 [bubble_ setArrowLocation:kTopRight]; | 375 [bubble_ setArrowLocation:kTopRight]; |
357 | 376 |
377 // Adapt window size to bottom buttons. Do this before all other layouting. | |
378 [self makeWideEnoughForManageDoneButtons]; | |
379 | |
358 [self initializeTitle]; | 380 [self initializeTitle]; |
359 if (allowBlockRadioGroup_) // not bound in cookie bubble xib | 381 if (allowBlockRadioGroup_) // not bound in cookie bubble xib |
360 [self initializeRadioGroup]; | 382 [self initializeRadioGroup]; |
361 if (contentSettingBubbleModel_->content_type() == | 383 if (contentSettingBubbleModel_->content_type() == |
362 CONTENT_SETTINGS_TYPE_POPUPS) | 384 CONTENT_SETTINGS_TYPE_POPUPS) |
363 [self initializePopupList]; | 385 [self initializePopupList]; |
364 if (contentSettingBubbleModel_->content_type() == | 386 if (contentSettingBubbleModel_->content_type() == |
365 CONTENT_SETTINGS_TYPE_GEOLOCATION) | 387 CONTENT_SETTINGS_TYPE_GEOLOCATION) |
366 [self initializeGeoLists]; | 388 [self initializeGeoLists]; |
367 } | 389 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
455 DCHECK(i != popupLinks_.end()); | 477 DCHECK(i != popupLinks_.end()); |
456 contentSettingBubbleModel_->OnPopupClicked(i->second); | 478 contentSettingBubbleModel_->OnPopupClicked(i->second); |
457 } | 479 } |
458 | 480 |
459 - (void)clearGeolocationForCurrentHost:(id)sender { | 481 - (void)clearGeolocationForCurrentHost:(id)sender { |
460 contentSettingBubbleModel_->OnClearLinkClicked(); | 482 contentSettingBubbleModel_->OnClearLinkClicked(); |
461 [self close]; | 483 [self close]; |
462 } | 484 } |
463 | 485 |
464 @end // ContentBlockedBubbleController | 486 @end // ContentBlockedBubbleController |
OLD | NEW |