| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/media_picker/desktop_media_picker_controller.h" | 5 #import "chrome/browser/ui/cocoa/media_picker/desktop_media_picker_controller.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #import "base/mac/bundle_locations.h" | 8 #import "base/mac/bundle_locations.h" |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #import "chrome/browser/ui/cocoa/media_picker/desktop_media_picker_item.h" | 10 #import "chrome/browser/ui/cocoa/media_picker/desktop_media_picker_item.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 - (void)sharePressed:(id)sender; | 50 - (void)sharePressed:(id)sender; |
| 51 - (void)cancelPressed:(id)sender; | 51 - (void)cancelPressed:(id)sender; |
| 52 | 52 |
| 53 @end | 53 @end |
| 54 | 54 |
| 55 @implementation DesktopMediaPickerController | 55 @implementation DesktopMediaPickerController |
| 56 | 56 |
| 57 - (id)initWithMediaList:(scoped_ptr<DesktopMediaList>)media_list | 57 - (id)initWithMediaList:(scoped_ptr<DesktopMediaList>)media_list |
| 58 parent:(NSWindow*)parent | 58 parent:(NSWindow*)parent |
| 59 callback:(const DesktopMediaPicker::DoneCallback&)callback | 59 callback:(const DesktopMediaPicker::DoneCallback&)callback |
| 60 appName:(const base::string16&)appName { | 60 appName:(const base::string16&)appName |
| 61 targetName:(const base::string16&)targetName { |
| 61 const NSUInteger kStyleMask = | 62 const NSUInteger kStyleMask = |
| 62 NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask; | 63 NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask; |
| 63 base::scoped_nsobject<NSWindow> window( | 64 base::scoped_nsobject<NSWindow> window( |
| 64 [[NSWindow alloc] initWithContentRect:ui::kWindowSizeDeterminedLater | 65 [[NSWindow alloc] initWithContentRect:ui::kWindowSizeDeterminedLater |
| 65 styleMask:kStyleMask | 66 styleMask:kStyleMask |
| 66 backing:NSBackingStoreBuffered | 67 backing:NSBackingStoreBuffered |
| 67 defer:NO]); | 68 defer:NO]); |
| 68 | 69 |
| 69 if ((self = [super initWithWindow:window])) { | 70 if ((self = [super initWithWindow:window])) { |
| 70 [parent addChildWindow:window ordered:NSWindowAbove]; | 71 [parent addChildWindow:window ordered:NSWindowAbove]; |
| 71 [window setDelegate:self]; | 72 [window setDelegate:self]; |
| 72 [self initializeContentsWithAppName:appName]; | 73 [self initializeContentsWithAppName:appName targetName:targetName]; |
| 73 media_list_ = media_list.Pass(); | 74 media_list_ = media_list.Pass(); |
| 74 media_list_->SetViewDialogWindowId([window windowNumber]); | 75 media_list_->SetViewDialogWindowId([window windowNumber]); |
| 75 doneCallback_ = callback; | 76 doneCallback_ = callback; |
| 76 items_.reset([[NSMutableArray alloc] init]); | 77 items_.reset([[NSMutableArray alloc] init]); |
| 77 bridge_.reset(new DesktopMediaPickerBridge(self)); | 78 bridge_.reset(new DesktopMediaPickerBridge(self)); |
| 78 } | 79 } |
| 79 return self; | 80 return self; |
| 80 } | 81 } |
| 81 | 82 |
| 82 - (void)dealloc { | 83 - (void)dealloc { |
| 83 [sourceBrowser_ setDelegate:nil]; | 84 [sourceBrowser_ setDelegate:nil]; |
| 84 [sourceBrowser_ setDataSource:nil]; | 85 [sourceBrowser_ setDataSource:nil]; |
| 85 [super dealloc]; | 86 [super dealloc]; |
| 86 } | 87 } |
| 87 | 88 |
| 88 - (void)initializeContentsWithAppName:(const base::string16&)appName { | 89 - (void)initializeContentsWithAppName:(const base::string16&)appName |
| 90 targetName:(const base::string16&)targetName { |
| 89 // Use flipped coordinates to facilitate manual layout. | 91 // Use flipped coordinates to facilitate manual layout. |
| 90 const CGFloat kPaddedWidth = kInitialContentWidth - (kFramePadding * 2); | 92 const CGFloat kPaddedWidth = kInitialContentWidth - (kFramePadding * 2); |
| 91 base::scoped_nsobject<FlippedView> content( | 93 base::scoped_nsobject<FlippedView> content( |
| 92 [[FlippedView alloc] initWithFrame:NSZeroRect]); | 94 [[FlippedView alloc] initWithFrame:NSZeroRect]); |
| 93 [[self window] setContentView:content]; | 95 [[self window] setContentView:content]; |
| 94 NSPoint origin = NSMakePoint(kFramePadding, kFramePadding); | 96 NSPoint origin = NSMakePoint(kFramePadding, kFramePadding); |
| 95 | 97 |
| 96 // Set the dialog's title. | 98 // Set the dialog's title. |
| 97 NSString* titleText = l10n_util::GetNSStringF( | 99 NSString* titleText = l10n_util::GetNSStringF( |
| 98 IDS_DESKTOP_MEDIA_PICKER_TITLE, appName); | 100 IDS_DESKTOP_MEDIA_PICKER_TITLE, appName); |
| 99 [[self window] setTitle:titleText]; | 101 [[self window] setTitle:titleText]; |
| 100 | 102 |
| 101 // Set the dialog's description. | 103 // Set the dialog's description. |
| 102 NSString* descriptionText = l10n_util::GetNSStringF( | 104 NSString* descriptionText; |
| 103 IDS_DESKTOP_MEDIA_PICKER_TEXT, appName); | 105 if (appName == targetName) { |
| 106 descriptionText = l10n_util::GetNSStringF( |
| 107 IDS_DESKTOP_MEDIA_PICKER_TEXT, appName); |
| 108 } else { |
| 109 descriptionText = l10n_util::GetNSStringF( |
| 110 IDS_DESKTOP_MEDIA_PICKER_TEXT_DELEGATED, appName, targetName); |
| 111 } |
| 104 NSTextField* description = [self createTextFieldWithText:descriptionText | 112 NSTextField* description = [self createTextFieldWithText:descriptionText |
| 105 frameWidth:kPaddedWidth]; | 113 frameWidth:kPaddedWidth]; |
| 106 [description setFrameOrigin:origin]; | 114 [description setFrameOrigin:origin]; |
| 107 [content addSubview:description]; | 115 [content addSubview:description]; |
| 108 origin.y += NSHeight([description frame]) + kControlSpacing; | 116 origin.y += NSHeight([description frame]) + kControlSpacing; |
| 109 | 117 |
| 110 // Create the image browser. | 118 // Create the image browser. |
| 111 sourceBrowser_.reset([[IKImageBrowserView alloc] initWithFrame:NSZeroRect]); | 119 sourceBrowser_.reset([[IKImageBrowserView alloc] initWithFrame:NSZeroRect]); |
| 112 NSUInteger cellStyle = IKCellsStyleShadowed | IKCellsStyleTitled; | 120 NSUInteger cellStyle = IKCellsStyleShadowed | IKCellsStyleTitled; |
| 113 [sourceBrowser_ setDelegate:self]; | 121 [sourceBrowser_ setDelegate:self]; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 - (void)sourceThumbnailChangedAtIndex:(int)index { | 310 - (void)sourceThumbnailChangedAtIndex:(int)index { |
| 303 const DesktopMediaList::Source& source = media_list_->GetSource(index); | 311 const DesktopMediaList::Source& source = media_list_->GetSource(index); |
| 304 NSImage* image = gfx::NSImageFromImageSkia(source.thumbnail); | 312 NSImage* image = gfx::NSImageFromImageSkia(source.thumbnail); |
| 305 | 313 |
| 306 DesktopMediaPickerItem* item = [items_ objectAtIndex:index]; | 314 DesktopMediaPickerItem* item = [items_ objectAtIndex:index]; |
| 307 [item setImageRepresentation:image]; | 315 [item setImageRepresentation:image]; |
| 308 [sourceBrowser_ reloadData]; | 316 [sourceBrowser_ reloadData]; |
| 309 } | 317 } |
| 310 | 318 |
| 311 @end // @interface DesktopMediaPickerController | 319 @end // @interface DesktopMediaPickerController |
| OLD | NEW |