Index: chrome/browser/ui/cocoa/extensions/media_galleries_scan_result_dialog_cocoa.mm |
diff --git a/chrome/browser/ui/cocoa/extensions/media_galleries_scan_result_dialog_cocoa.mm b/chrome/browser/ui/cocoa/extensions/media_galleries_scan_result_dialog_cocoa.mm |
index f87d0dee12b39cb8de8358f885def000b664a5a7..ae69b9c0714fd75483703b558b5120418e588877 100644 |
--- a/chrome/browser/ui/cocoa/extensions/media_galleries_scan_result_dialog_cocoa.mm |
+++ b/chrome/browser/ui/cocoa/extensions/media_galleries_scan_result_dialog_cocoa.mm |
@@ -7,20 +7,23 @@ |
#include "base/mac/foundation_util.h" |
#include "base/mac/scoped_nsobject.h" |
#include "base/strings/sys_string_conversions.h" |
-#include "chrome/browser/ui/chrome_style.h" |
#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_alert.h" |
#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_control_utils.h" |
#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sheet.h" |
#import "chrome/browser/ui/cocoa/key_equivalent_constants.h" |
#include "content/public/browser/web_contents.h" |
#include "grit/generated_resources.h" |
-#include "grit/theme_resources.h" |
#import "ui/base/cocoa/flipped_view.h" |
-#import "ui/base/cocoa/menu_controller.h" |
#import "ui/base/models/menu_model.h" |
#include "ui/base/l10n/l10n_util.h" |
-const CGFloat kDetailGray = 0.625; |
+namespace { |
groby-ooo-7-16
2014/04/23 21:57:58
const implies internal linkage - no need for anon
vandebo (ex-Chrome)
2014/04/25 20:10:56
Done.
|
+ |
+const CGFloat kCheckboxLeading = 10; |
+const CGFloat kCheckboxWidth = 440; |
+const CGFloat kScrollAreaHeight = 220; |
+ |
+} // namespace |
// Controller for UI events on items in the media galleries dialog. |
@interface MediaGalleriesScanResultCocoaController : NSObject { |
@@ -30,6 +33,9 @@ const CGFloat kDetailGray = 0.625; |
@property(assign, nonatomic) MediaGalleriesScanResultDialogCocoa* dialog; |
+- (void)onAcceptButton:(id)sender; |
+- (void)onCancelButton:(id)sender; |
+ |
@end |
@implementation MediaGalleriesScanResultCocoaController |
@@ -44,66 +50,9 @@ const CGFloat kDetailGray = 0.625; |
dialog_->OnCancelClicked(); |
} |
-- (void)onCheckboxToggled:(id)sender { |
- DCHECK(dialog_); |
- dialog_->OnCheckboxToggled(sender); |
-} |
- |
-- (void)onFolderViewClicked:(id)sender { |
- DCHECK(dialog_); |
- dialog_->OnFolderViewClicked(sender); |
-} |
- |
@end |
-@interface MediaGalleriesScanResultButton : NSButton { |
- @private |
- MediaGalleriesScanResultDialogCocoa* dialog_; // |dialog_| owns |this|. |
- MediaGalleryPrefId prefId_; |
- base::scoped_nsobject<MenuController> menuController_; |
-} |
- |
-@property(readonly, nonatomic) MediaGalleryPrefId prefId; |
- |
-- (id)initWithFrame:(NSRect)frameRect |
- dialog:(MediaGalleriesScanResultDialogCocoa*)dialog |
- prefId:(MediaGalleryPrefId)prefId; |
-- (NSMenu*)menuForEvent:(NSEvent*)theEvent; |
- |
-@end |
- |
-@implementation MediaGalleriesScanResultButton |
- |
-@synthesize prefId = prefId_; |
- |
-- (id)initWithFrame:(NSRect)frameRect |
- dialog:(MediaGalleriesScanResultDialogCocoa*)dialog |
- prefId:(MediaGalleryPrefId)prefId { |
- if ((self = [super initWithFrame:frameRect])) { |
- dialog_ = dialog; |
- prefId_ = prefId; |
- } |
- return self; |
-} |
- |
-- (NSMenu*)menuForEvent:(NSEvent*)theEvent { |
- menuController_.reset( |
- [[MenuController alloc] initWithModel:dialog_->GetContextMenu(prefId_) |
- useWithPopUpButtonCell:NO]); |
- return [menuController_ menu]; |
-} |
- |
-@end |
- |
-namespace { |
- |
-const CGFloat kCheckboxMargin = 10; |
-const CGFloat kCheckboxMaxWidth = 440; |
-const CGFloat kScrollAreaHeight = 220; |
- |
-} // namespace |
- |
MediaGalleriesScanResultDialogCocoa::MediaGalleriesScanResultDialogCocoa( |
MediaGalleriesScanResultDialogController* controller, |
MediaGalleriesScanResultCocoaController* cocoa_controller) |
@@ -160,7 +109,7 @@ void MediaGalleriesScanResultDialogCocoa::InitDialogControls() { |
base::scoped_nsobject<NSScrollView> scroll_view( |
[[NSScrollView alloc] initWithFrame: |
- NSMakeRect(0, 0, kCheckboxMaxWidth, kScrollAreaHeight)]); |
+ NSMakeRect(0, 0, kCheckboxWidth, kScrollAreaHeight)]); |
[scroll_view setHasVerticalScroller:YES]; |
[scroll_view setHasHorizontalScroller:NO]; |
[scroll_view setBorderType:NSNoBorder]; |
@@ -169,25 +118,28 @@ void MediaGalleriesScanResultDialogCocoa::InitDialogControls() { |
// Add scan results checkboxes inside the scrolling view. |
checkbox_container_.reset([[FlippedView alloc] initWithFrame:NSZeroRect]); |
- checkboxes_.reset([[NSMutableArray alloc] init]); |
+ CGFloat height = CreateCheckboxes(); |
+ // Give the container a reasonable initial size so that the scroll_view can |
+ // figure out the content size. |
+ [checkbox_container_ setFrame:NSMakeRect(0, 0, kCheckboxWidth, height)]; |
[scroll_view setDocumentView:checkbox_container_]; |
- CGFloat y_pos = 0; |
- |
- y_pos = CreateCheckboxes(y_pos, controller_->GetGalleryList()); |
- |
- [checkbox_container_ setFrame:NSMakeRect(0, 0, kCheckboxMaxWidth, y_pos + 2)]; |
+ NSRect checkboxes_frame = |
+ NSMakeRect(0, 0, [scroll_view contentSize].width, height); |
+ [checkbox_container_ setFrame:checkboxes_frame]; |
// Resize to pack the scroll view if possible. |
NSRect scroll_frame = [scroll_view frame]; |
- if (NSHeight(scroll_frame) > NSHeight([checkbox_container_ frame])) { |
- scroll_frame.size.height = NSHeight([checkbox_container_ frame]); |
+ if (NSHeight(scroll_frame) > NSHeight(checkboxes_frame)) { |
+ scroll_frame.size.height = NSHeight(checkboxes_frame); |
[scroll_view setFrame:scroll_frame]; |
} |
[main_container_ setFrameFromContentFrame:scroll_frame]; |
+ NSRect main_frame = [main_container_ frame]; |
groby-ooo-7-16
2014/04/23 21:57:58
setFrameOrigin:
vandebo (ex-Chrome)
2014/04/25 20:10:56
Done.
|
+ main_frame.origin = NSZeroPoint; |
+ [main_container_ setFrame:main_frame]; |
[alert_ setAccessoryView:main_container_]; |
- |
[alert_ layout]; |
} |
@@ -195,20 +147,32 @@ void MediaGalleriesScanResultDialogCocoa::AcceptDialogForTesting() { |
OnAcceptClicked(); |
} |
-CGFloat MediaGalleriesScanResultDialogCocoa::CreateCheckboxes( |
- CGFloat y_pos, |
- const MediaGalleriesScanResultDialogController::OrderedScanResults& |
- scan_results) { |
- y_pos += kCheckboxMargin; |
- |
+CGFloat MediaGalleriesScanResultDialogCocoa::CreateCheckboxes() { |
+ CGFloat y_pos = 0; |
+ MediaGalleriesScanResultDialogController::OrderedScanResults scan_results = |
+ controller_->GetGalleryList(); |
for (MediaGalleriesScanResultDialogController::OrderedScanResults:: |
const_iterator iter = scan_results.begin(); |
iter != scan_results.end(); iter++) { |
const MediaGalleriesScanResultDialogController::ScanResult& scan_result = |
*iter; |
- UpdateScanResultCheckbox(scan_result.pref_info, scan_result.selected, |
- y_pos); |
- y_pos = NSMaxY([[checkboxes_ lastObject] frame]) + kCheckboxMargin; |
+ base::scoped_nsobject<MediaGalleryListEntry> checkbox_entry( |
+ [[MediaGalleryListEntry alloc] |
+ initWithFrame:NSZeroRect |
+ controller:this |
+ prefId:scan_result.pref_info.pref_id |
+ galleryName:scan_result.pref_info.GetGalleryDisplayName() |
+ subscript:scan_result.pref_info.GetGalleryAdditionalDetails() |
+ tooltip:scan_result.pref_info.GetGalleryTooltip() |
+ showFolderViewer:scan_result.pref_info.IsGalleryAvailable()]); |
+ |
+ [checkbox_entry setState:scan_result.selected]; |
+ |
+ NSRect entry_rect = [checkbox_entry frame]; |
+ entry_rect.origin.y = y_pos; |
+ [checkbox_entry setFrame:entry_rect]; |
+ [checkbox_container_ addSubview:checkbox_entry]; |
+ y_pos = NSMaxY(entry_rect) + kCheckboxLeading; |
} |
return y_pos; |
@@ -226,125 +190,6 @@ void MediaGalleriesScanResultDialogCocoa::OnCancelClicked() { |
window_->CloseWebContentsModalDialog(); |
} |
-void MediaGalleriesScanResultDialogCocoa::OnCheckboxToggled( |
- NSButton* button) { |
- [[[alert_ buttons] objectAtIndex:0] setEnabled:YES]; |
- |
- MediaGalleriesScanResultButton* checkbox = |
- (MediaGalleriesScanResultButton*) button; |
- controller_->DidToggleGalleryId([checkbox prefId], |
- [checkbox state] == NSOnState); |
-} |
- |
-void MediaGalleriesScanResultDialogCocoa::OnFolderViewClicked( |
- NSButton* button) { |
- MediaGalleriesScanResultButton* checkbox = |
- base::mac::ObjCCastStrict<MediaGalleriesScanResultButton>(button); |
- controller_->DidClickOpenFolderViewer([checkbox prefId]); |
-} |
- |
-void MediaGalleriesScanResultDialogCocoa::UpdateScanResultCheckbox( |
- const MediaGalleryPrefInfo& gallery, |
- bool selected, |
- CGFloat y_pos) { |
- // Checkbox. |
- base::scoped_nsobject<MediaGalleriesScanResultButton> checkbox( |
- [[MediaGalleriesScanResultButton alloc] initWithFrame:NSZeroRect |
- dialog:this |
- prefId:gallery.pref_id]); |
- [[checkbox cell] setLineBreakMode:NSLineBreakByTruncatingMiddle]; |
- [checkbox setButtonType:NSSwitchButton]; |
- [checkbox setTarget:cocoa_controller_]; |
- [checkbox setAction:@selector(onCheckboxToggled:)]; |
- [checkboxes_ addObject:checkbox]; |
- |
- [checkbox setTitle:base::SysUTF16ToNSString( |
- gallery.GetGalleryDisplayName())]; |
- [checkbox setToolTip:base::SysUTF16ToNSString(gallery.GetGalleryTooltip())]; |
- [checkbox setState:selected ? NSOnState : NSOffState]; |
- [checkbox sizeToFit]; |
- NSRect checkbox_rect = [checkbox bounds]; |
- |
- // Folder viewer button. |
- NSRect folder_viewer_rect = NSZeroRect; |
- base::scoped_nsobject<MediaGalleriesScanResultButton> folder_viewer; |
- if (gallery.IsGalleryAvailable()) { |
- folder_viewer.reset( |
- [[MediaGalleriesScanResultButton alloc] initWithFrame:NSZeroRect |
- dialog:this |
- prefId:gallery.pref_id]); |
- [folder_viewer setButtonType:NSMomentaryChangeButton]; |
- [folder_viewer setTarget:cocoa_controller_]; |
- [folder_viewer setAction:@selector(onFolderViewClicked:)]; |
- |
- ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
- [folder_viewer setImage:rb.GetNativeImageNamed( |
- IDR_FILE_FOLDER).ToNSImage()]; |
- [folder_viewer setTitle:nil]; |
- [folder_viewer setBordered:false]; |
- [folder_viewer setToolTip: |
- base::SysUTF16ToNSString(gallery.GetGalleryTooltip())]; |
- [folder_viewer sizeToFit]; |
- folder_viewer_rect = [folder_viewer bounds]; |
- } else { |
- folder_viewer_rect.size.width = -kCheckboxMargin; |
- } |
- |
- // Additional details text. |
- base::scoped_nsobject<NSTextField> details( |
- [[NSTextField alloc] initWithFrame:NSZeroRect]); |
- [[details cell] setLineBreakMode:NSLineBreakByTruncatingHead]; |
- [details setEditable:NO]; |
- [details setSelectable:NO]; |
- [details setBezeled:NO]; |
- [details setAttributedStringValue: |
- constrained_window::GetAttributedLabelString( |
- base::SysUTF16ToNSString(gallery.GetGalleryAdditionalDetails()), |
- chrome_style::kTextFontStyle, |
- NSNaturalTextAlignment, |
- NSLineBreakByClipping |
- )]; |
- [details setTextColor:[NSColor colorWithCalibratedRed:kDetailGray |
- green:kDetailGray |
- blue:kDetailGray |
- alpha:1.0]]; |
- [details sizeToFit]; |
- NSRect details_rect = [details bounds]; |
- |
- // Size the views. If all the elements don't naturally fit, the checkbox |
- // should get squished and will elide in the middle. However, it shouldn't |
- // squish too much so it gets at least half of the max width and the details |
- // text should elide as well in that case. |
- int natural_width = NSWidth(checkbox_rect) + NSWidth(folder_viewer_rect) + |
- NSWidth(details_rect) + 5 * kCheckboxMargin; |
- if (natural_width > kCheckboxMaxWidth) { |
- int max_content = kCheckboxMaxWidth - 5 * kCheckboxMargin; |
- if (NSWidth(folder_viewer_rect) + NSWidth(details_rect) > max_content / 2) { |
- details_rect.size.width = std::max( |
- max_content / 2 - NSWidth(folder_viewer_rect), |
- max_content - NSWidth(checkbox_rect) - NSWidth(folder_viewer_rect)); |
- } |
- checkbox_rect.size.width = |
- max_content - NSWidth(folder_viewer_rect) - NSWidth(details_rect); |
- } |
- |
- checkbox_rect.origin = NSMakePoint(kCheckboxMargin, y_pos); |
- [checkbox setFrame:checkbox_rect]; |
- [checkbox_container_ addSubview:checkbox]; |
- |
- folder_viewer_rect.origin = |
- NSMakePoint(NSMaxX(checkbox_rect) + kCheckboxMargin, y_pos); |
- if (gallery.IsGalleryAvailable()) { |
- [folder_viewer setFrame:folder_viewer_rect]; |
- [checkbox_container_ addSubview:folder_viewer]; |
- } |
- |
- details_rect.origin = |
- NSMakePoint(NSMaxX(folder_viewer_rect) + kCheckboxMargin, y_pos - 1); |
- [details setFrame:details_rect]; |
- [checkbox_container_ addSubview:details]; |
-} |
- |
void MediaGalleriesScanResultDialogCocoa::UpdateResults() { |
InitDialogControls(); |
} |
@@ -354,9 +199,19 @@ void MediaGalleriesScanResultDialogCocoa::OnConstrainedWindowClosed( |
controller_->DialogFinished(accepted_); |
} |
+void MediaGalleriesScanResultDialogCocoa::OnCheckboxToggled( |
+ MediaGalleryPrefId prefId, bool checked) { |
+ controller_->DidToggleGalleryId(prefId, checked); |
+} |
+ |
+void MediaGalleriesScanResultDialogCocoa::OnFolderViewerClicked( |
+ MediaGalleryPrefId prefId) { |
+ controller_->DidClickOpenFolderViewer(prefId); |
+} |
+ |
ui::MenuModel* MediaGalleriesScanResultDialogCocoa::GetContextMenu( |
- MediaGalleryPrefId prefid) { |
- return controller_->GetContextMenu(prefid); |
+ MediaGalleryPrefId pref_id) { |
+ return controller_->GetContextMenu(pref_id); |
} |
// static |