| 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_de
precated.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #import "base/mac/bundle_locations.h" | 11 #import "base/mac/bundle_locations.h" |
| 12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
| 13 #include "chrome/browser/media/combined_desktop_media_list.h" | 13 #include "chrome/browser/media/combined_desktop_media_list.h" |
| 14 #import "chrome/browser/ui/cocoa/key_equivalent_constants.h" | 14 #import "chrome/browser/ui/cocoa/key_equivalent_constants.h" |
| 15 #import "chrome/browser/ui/cocoa/media_picker/desktop_media_picker_item.h" | 15 #import "chrome/browser/ui/cocoa/media_picker/desktop_media_picker_item.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 32 const int kMinimumContentWidth = 500; | 32 const int kMinimumContentWidth = 500; |
| 33 const int kMinimumContentHeight = 390; | 33 const int kMinimumContentHeight = 390; |
| 34 const int kThumbnailWidth = 150; | 34 const int kThumbnailWidth = 150; |
| 35 const int kThumbnailHeight = 150; | 35 const int kThumbnailHeight = 150; |
| 36 const int kFramePadding = 20; | 36 const int kFramePadding = 20; |
| 37 const int kControlSpacing = 10; | 37 const int kControlSpacing = 10; |
| 38 const int kExcessButtonPadding = 6; | 38 const int kExcessButtonPadding = 6; |
| 39 | 39 |
| 40 } // namespace | 40 } // namespace |
| 41 | 41 |
| 42 @interface DesktopMediaPickerController (Private) | 42 @interface DesktopMediaPickerControllerDeprecated (Private) |
| 43 | 43 |
| 44 // Populate the window with controls and views. | 44 // Populate the window with controls and views. |
| 45 - (void)initializeContentsWithAppName:(const base::string16&)appName; | 45 - (void)initializeContentsWithAppName:(const base::string16&)appName; |
| 46 | 46 |
| 47 // Create a |NSTextField| with label traits given |width|. Frame height is | 47 // Create a |NSTextField| with label traits given |width|. Frame height is |
| 48 // automatically adjusted to fit. | 48 // automatically adjusted to fit. |
| 49 - (NSTextField*)createTextFieldWithText:(NSString*)text | 49 - (NSTextField*)createTextFieldWithText:(NSString*)text |
| 50 frameWidth:(CGFloat)width; | 50 frameWidth:(CGFloat)width; |
| 51 | 51 |
| 52 // Create a button with |title|, with size adjusted to fit. | 52 // Create a button with |title|, with size adjusted to fit. |
| 53 - (NSButton*)createButtonWithTitle:(NSString*)title; | 53 - (NSButton*)createButtonWithTitle:(NSString*)title; |
| 54 | 54 |
| 55 // Report result by invoking |doneCallback_|. The callback is invoked only on | 55 // Report result by invoking |doneCallback_|. The callback is invoked only on |
| 56 // the first call to |reportResult:|. Subsequent calls will be no-ops. | 56 // the first call to |reportResult:|. Subsequent calls will be no-ops. |
| 57 - (void)reportResult:(content::DesktopMediaID)sourceID; | 57 - (void)reportResult:(content::DesktopMediaID)sourceID; |
| 58 | 58 |
| 59 // Action handlers. | 59 // Action handlers. |
| 60 - (void)sharePressed:(id)sender; | 60 - (void)sharePressed:(id)sender; |
| 61 - (void)cancelPressed:(id)sender; | 61 - (void)cancelPressed:(id)sender; |
| 62 | 62 |
| 63 @end | 63 @end |
| 64 | 64 |
| 65 @implementation DesktopMediaPickerController | 65 @implementation DesktopMediaPickerControllerDeprecated |
| 66 | 66 |
| 67 - (id)initWithScreenList:(std::unique_ptr<DesktopMediaList>)screen_list | 67 - (id)initWithScreenList:(std::unique_ptr<DesktopMediaList>)screen_list |
| 68 windowList:(std::unique_ptr<DesktopMediaList>)window_list | 68 windowList:(std::unique_ptr<DesktopMediaList>)window_list |
| 69 tabList:(std::unique_ptr<DesktopMediaList>)tab_list | 69 tabList:(std::unique_ptr<DesktopMediaList>)tab_list |
| 70 parent:(NSWindow*)parent | 70 parent:(NSWindow*)parent |
| 71 callback:(const DesktopMediaPicker::DoneCallback&)callback | 71 callback:(const DesktopMediaPicker::DoneCallback&)callback |
| 72 appName:(const base::string16&)appName | 72 appName:(const base::string16&)appName |
| 73 targetName:(const base::string16&)targetName | 73 targetName:(const base::string16&)targetName |
| 74 requestAudio:(bool)requestAudio { | 74 requestAudio:(bool)requestAudio { |
| 75 const NSUInteger kStyleMask = | 75 const NSUInteger kStyleMask = |
| 76 NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask; | 76 NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask; |
| 77 base::scoped_nsobject<NSWindow> window( | 77 base::scoped_nsobject<NSWindow> window([[NSWindow alloc] |
| 78 [[NSWindow alloc] initWithContentRect:ui::kWindowSizeDeterminedLater | 78 initWithContentRect:ui::kWindowSizeDeterminedLater |
| 79 styleMask:kStyleMask | 79 styleMask:kStyleMask |
| 80 backing:NSBackingStoreBuffered | 80 backing:NSBackingStoreBuffered |
| 81 defer:NO]); | 81 defer:NO]); |
| 82 | 82 |
| 83 if ((self = [super initWithWindow:window])) { | 83 if ((self = [super initWithWindow:window])) { |
| 84 [parent addChildWindow:window ordered:NSWindowAbove]; | 84 [parent addChildWindow:window ordered:NSWindowAbove]; |
| 85 [window setDelegate:self]; | 85 [window setDelegate:self]; |
| 86 [self initializeContentsWithAppName:appName | 86 [self initializeContentsWithAppName:appName |
| 87 targetName:targetName | 87 targetName:targetName |
| 88 requestAudio:requestAudio]; | 88 requestAudio:requestAudio]; |
| 89 std::vector<std::unique_ptr<DesktopMediaList>> media_lists; | 89 std::vector<std::unique_ptr<DesktopMediaList>> media_lists; |
| 90 if (screen_list) | 90 if (screen_list) |
| 91 media_lists.push_back(std::move(screen_list)); | 91 media_lists.push_back(std::move(screen_list)); |
| 92 | 92 |
| 93 if (window_list) | 93 if (window_list) |
| 94 media_lists.push_back(std::move(window_list)); | 94 media_lists.push_back(std::move(window_list)); |
| 95 | 95 |
| 96 if (tab_list) | 96 if (tab_list) |
| 97 media_lists.push_back(std::move(tab_list)); | 97 media_lists.push_back(std::move(tab_list)); |
| 98 | 98 |
| 99 if (media_lists.size() > 1) | 99 if (media_lists.size() > 1) |
| 100 media_list_.reset(new CombinedDesktopMediaList(media_lists)); | 100 media_list_.reset(new CombinedDesktopMediaList(media_lists)); |
| 101 else | 101 else |
| 102 media_list_ = std::move(media_lists[0]); | 102 media_list_ = std::move(media_lists[0]); |
| 103 media_list_->SetViewDialogWindowId(content::DesktopMediaID( | 103 media_list_->SetViewDialogWindowId(content::DesktopMediaID( |
| 104 content::DesktopMediaID::TYPE_WINDOW, [window windowNumber])); | 104 content::DesktopMediaID::TYPE_WINDOW, [window windowNumber])); |
| 105 doneCallback_ = callback; | 105 doneCallback_ = callback; |
| 106 items_.reset([[NSMutableArray alloc] init]); | 106 items_.reset([[NSMutableArray alloc] init]); |
| 107 bridge_.reset(new DesktopMediaPickerBridge(self)); | 107 bridge_.reset(new DesktopMediaPickerBridge(self)); |
| 108 } | 108 } |
| 109 return self; | 109 return self; |
| 110 } | 110 } |
| 111 | 111 |
| 112 - (void)dealloc { | 112 - (void)dealloc { |
| 113 [shareButton_ setTarget:nil]; | 113 [shareButton_ setTarget:nil]; |
| 114 [cancelButton_ setTarget:nil]; | 114 [cancelButton_ setTarget:nil]; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 129 NSPoint origin = NSMakePoint(kFramePadding, kFramePadding); | 129 NSPoint origin = NSMakePoint(kFramePadding, kFramePadding); |
| 130 | 130 |
| 131 // Set the dialog's title. | 131 // Set the dialog's title. |
| 132 NSString* titleText = l10n_util::GetNSStringF( | 132 NSString* titleText = l10n_util::GetNSStringF( |
| 133 IDS_DESKTOP_MEDIA_PICKER_TITLE_DEPRECATED, appName); | 133 IDS_DESKTOP_MEDIA_PICKER_TITLE_DEPRECATED, appName); |
| 134 [[self window] setTitle:titleText]; | 134 [[self window] setTitle:titleText]; |
| 135 | 135 |
| 136 // Set the dialog's description. | 136 // Set the dialog's description. |
| 137 NSString* descriptionText; | 137 NSString* descriptionText; |
| 138 if (appName == targetName) { | 138 if (appName == targetName) { |
| 139 descriptionText = l10n_util::GetNSStringF( | 139 descriptionText = |
| 140 IDS_DESKTOP_MEDIA_PICKER_TEXT, appName); | 140 l10n_util::GetNSStringF(IDS_DESKTOP_MEDIA_PICKER_TEXT, appName); |
| 141 } else { | 141 } else { |
| 142 descriptionText = l10n_util::GetNSStringF( | 142 descriptionText = l10n_util::GetNSStringF( |
| 143 IDS_DESKTOP_MEDIA_PICKER_TEXT_DELEGATED, appName, targetName); | 143 IDS_DESKTOP_MEDIA_PICKER_TEXT_DELEGATED, appName, targetName); |
| 144 } | 144 } |
| 145 NSTextField* description = [self createTextFieldWithText:descriptionText | 145 NSTextField* description = |
| 146 frameWidth:kPaddedWidth]; | 146 [self createTextFieldWithText:descriptionText frameWidth:kPaddedWidth]; |
| 147 [description setFrameOrigin:origin]; | 147 [description setFrameOrigin:origin]; |
| 148 [content addSubview:description]; | 148 [content addSubview:description]; |
| 149 origin.y += NSHeight([description frame]) + kControlSpacing; | 149 origin.y += NSHeight([description frame]) + kControlSpacing; |
| 150 | 150 |
| 151 // Create the image browser. | 151 // Create the image browser. |
| 152 sourceBrowser_.reset([[IKImageBrowserView alloc] initWithFrame:NSZeroRect]); | 152 sourceBrowser_.reset([[IKImageBrowserView alloc] initWithFrame:NSZeroRect]); |
| 153 NSUInteger cellStyle = IKCellsStyleShadowed | IKCellsStyleTitled; | 153 NSUInteger cellStyle = IKCellsStyleShadowed | IKCellsStyleTitled; |
| 154 [sourceBrowser_ setDelegate:self]; | 154 [sourceBrowser_ setDelegate:self]; |
| 155 [sourceBrowser_ setDataSource:self]; | 155 [sourceBrowser_ setDataSource:self]; |
| 156 [sourceBrowser_ setCellsStyleMask:cellStyle]; | 156 [sourceBrowser_ setCellsStyleMask:cellStyle]; |
| 157 [sourceBrowser_ setCellSize:NSMakeSize(kThumbnailWidth, kThumbnailHeight)]; | 157 [sourceBrowser_ setCellSize:NSMakeSize(kThumbnailWidth, kThumbnailHeight)]; |
| 158 [sourceBrowser_ setAllowsMultipleSelection:NO]; | 158 [sourceBrowser_ setAllowsMultipleSelection:NO]; |
| 159 | 159 |
| 160 // Create a scroll view to host the image browser. | 160 // Create a scroll view to host the image browser. |
| 161 NSRect imageBrowserScrollFrame = NSMakeRect( | 161 NSRect imageBrowserScrollFrame = |
| 162 origin.x, origin.y, kPaddedWidth, 350); | 162 NSMakeRect(origin.x, origin.y, kPaddedWidth, 350); |
| 163 base::scoped_nsobject<NSScrollView> imageBrowserScroll( | 163 base::scoped_nsobject<NSScrollView> imageBrowserScroll( |
| 164 [[NSScrollView alloc] initWithFrame:imageBrowserScrollFrame]); | 164 [[NSScrollView alloc] initWithFrame:imageBrowserScrollFrame]); |
| 165 [imageBrowserScroll setHasVerticalScroller:YES]; | 165 [imageBrowserScroll setHasVerticalScroller:YES]; |
| 166 [imageBrowserScroll setDocumentView:sourceBrowser_]; | 166 [imageBrowserScroll setDocumentView:sourceBrowser_]; |
| 167 [imageBrowserScroll setBorderType:NSBezelBorder]; | 167 [imageBrowserScroll setBorderType:NSBezelBorder]; |
| 168 [imageBrowserScroll setAutoresizingMask: | 168 [imageBrowserScroll |
| 169 NSViewWidthSizable | NSViewHeightSizable]; | 169 setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
| 170 [content addSubview:imageBrowserScroll]; | 170 [content addSubview:imageBrowserScroll]; |
| 171 origin.y += NSHeight(imageBrowserScrollFrame) + kControlSpacing; | 171 origin.y += NSHeight(imageBrowserScrollFrame) + kControlSpacing; |
| 172 | 172 |
| 173 // Create a checkbox for audio sharing. | 173 // Create a checkbox for audio sharing. |
| 174 if (requestAudio) { | 174 if (requestAudio) { |
| 175 audioShareCheckbox_.reset([[NSButton alloc] initWithFrame:NSZeroRect]); | 175 audioShareCheckbox_.reset([[NSButton alloc] initWithFrame:NSZeroRect]); |
| 176 [audioShareCheckbox_ setFrameOrigin:origin]; | 176 [audioShareCheckbox_ setFrameOrigin:origin]; |
| 177 [audioShareCheckbox_ | 177 [audioShareCheckbox_ |
| 178 setAutoresizingMask:NSViewMaxXMargin | NSViewMinYMargin]; | 178 setAutoresizingMask:NSViewMaxXMargin | NSViewMinYMargin]; |
| 179 [audioShareCheckbox_ setButtonType:NSSwitchButton]; | 179 [audioShareCheckbox_ setButtonType:NSSwitchButton]; |
| 180 audioShareState_ = NSOnState; | 180 audioShareState_ = NSOnState; |
| 181 [audioShareCheckbox_ | 181 [audioShareCheckbox_ |
| 182 setTitle:l10n_util::GetNSString(IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE)]; | 182 setTitle:l10n_util::GetNSString(IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE)]; |
| 183 [audioShareCheckbox_ sizeToFit]; | 183 [audioShareCheckbox_ sizeToFit]; |
| 184 [audioShareCheckbox_ setEnabled:NO]; | 184 [audioShareCheckbox_ setEnabled:NO]; |
| 185 [audioShareCheckbox_ | 185 [audioShareCheckbox_ |
| 186 setToolTip:l10n_util::GetNSString( | 186 setToolTip:l10n_util::GetNSString( |
| 187 IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE_TOOLTIP_MAC)]; | 187 IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE_TOOLTIP_MAC)]; |
| 188 [content addSubview:audioShareCheckbox_]; | 188 [content addSubview:audioShareCheckbox_]; |
| 189 origin.y += NSHeight([audioShareCheckbox_ frame]) + kControlSpacing; | 189 origin.y += NSHeight([audioShareCheckbox_ frame]) + kControlSpacing; |
| 190 } | 190 } |
| 191 | 191 |
| 192 // Create the share button. | 192 // Create the share button. |
| 193 shareButton_ = [self createButtonWithTitle:l10n_util::GetNSString( | 193 shareButton_ = |
| 194 IDS_DESKTOP_MEDIA_PICKER_SHARE)]; | 194 [self createButtonWithTitle:l10n_util::GetNSString( |
| 195 IDS_DESKTOP_MEDIA_PICKER_SHARE)]; |
| 195 origin.x = kInitialContentWidth - kFramePadding - | 196 origin.x = kInitialContentWidth - kFramePadding - |
| 196 (NSWidth([shareButton_ frame]) - kExcessButtonPadding); | 197 (NSWidth([shareButton_ frame]) - kExcessButtonPadding); |
| 197 [shareButton_ setEnabled:NO]; | 198 [shareButton_ setEnabled:NO]; |
| 198 [shareButton_ setFrameOrigin:origin]; | 199 [shareButton_ setFrameOrigin:origin]; |
| 199 [shareButton_ setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin]; | 200 [shareButton_ setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin]; |
| 200 [shareButton_ setTarget:self]; | 201 [shareButton_ setTarget:self]; |
| 201 [shareButton_ setKeyEquivalent:kKeyEquivalentReturn]; | 202 [shareButton_ setKeyEquivalent:kKeyEquivalentReturn]; |
| 202 [shareButton_ setAction:@selector(sharePressed:)]; | 203 [shareButton_ setAction:@selector(sharePressed:)]; |
| 203 [content addSubview:shareButton_]; | 204 [content addSubview:shareButton_]; |
| 204 | 205 |
| 205 // Create the cancel button. | 206 // Create the cancel button. |
| 206 cancelButton_ = | 207 cancelButton_ = |
| 207 [self createButtonWithTitle:l10n_util::GetNSString(IDS_CANCEL)]; | 208 [self createButtonWithTitle:l10n_util::GetNSString(IDS_CANCEL)]; |
| 208 origin.x -= kControlSpacing + | 209 origin.x -= kControlSpacing + |
| 209 (NSWidth([cancelButton_ frame]) - (kExcessButtonPadding * 2)); | 210 (NSWidth([cancelButton_ frame]) - (kExcessButtonPadding * 2)); |
| 210 [cancelButton_ setFrameOrigin:origin]; | 211 [cancelButton_ setFrameOrigin:origin]; |
| 211 [cancelButton_ setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin]; | 212 [cancelButton_ setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin]; |
| 212 [cancelButton_ setTarget:self]; | 213 [cancelButton_ setTarget:self]; |
| 213 [cancelButton_ setKeyEquivalent:kKeyEquivalentEscape]; | 214 [cancelButton_ setKeyEquivalent:kKeyEquivalentEscape]; |
| 214 [cancelButton_ setAction:@selector(cancelPressed:)]; | 215 [cancelButton_ setAction:@selector(cancelPressed:)]; |
| 215 [content addSubview:cancelButton_]; | 216 [content addSubview:cancelButton_]; |
| 216 origin.y += kFramePadding + | 217 origin.y += |
| 217 (NSHeight([cancelButton_ frame]) - kExcessButtonPadding); | 218 kFramePadding + (NSHeight([cancelButton_ frame]) - kExcessButtonPadding); |
| 218 | 219 |
| 219 // Resize window to fit. | 220 // Resize window to fit. |
| 220 [[[self window] contentView] setAutoresizesSubviews:NO]; | 221 [[[self window] contentView] setAutoresizesSubviews:NO]; |
| 221 [[self window] setContentSize:NSMakeSize(kInitialContentWidth, origin.y)]; | 222 [[self window] setContentSize:NSMakeSize(kInitialContentWidth, origin.y)]; |
| 222 [[self window] setContentMinSize: | 223 [[self window] setContentMinSize:NSMakeSize(kMinimumContentWidth, |
| 223 NSMakeSize(kMinimumContentWidth, kMinimumContentHeight)]; | 224 kMinimumContentHeight)]; |
| 224 [[[self window] contentView] setAutoresizesSubviews:YES]; | 225 [[[self window] contentView] setAutoresizesSubviews:YES]; |
| 225 | 226 |
| 226 // Make sourceBrowser_ get keyboard focus. | 227 // Make sourceBrowser_ get keyboard focus. |
| 227 [[self window] makeFirstResponder:sourceBrowser_]; | 228 [[self window] makeFirstResponder:sourceBrowser_]; |
| 228 } | 229 } |
| 229 | 230 |
| 230 - (void)showWindow:(id)sender { | 231 - (void)showWindow:(id)sender { |
| 231 // Signal the media_list to start sending thumbnails. |bridge_| is used as the | 232 // Signal the media_list to start sending thumbnails. |bridge_| is used as the |
| 232 // observer, and will forward notifications to this object. | 233 // observer, and will forward notifications to this object. |
| 233 media_list_->SetThumbnailSize(gfx::Size(kThumbnailWidth, kThumbnailHeight)); | 234 media_list_->SetThumbnailSize(gfx::Size(kThumbnailWidth, kThumbnailHeight)); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 250 content::WebContents* tab = content::WebContents::FromRenderFrameHost( | 251 content::WebContents* tab = content::WebContents::FromRenderFrameHost( |
| 251 content::RenderFrameHost::FromID( | 252 content::RenderFrameHost::FromID( |
| 252 sourceID.web_contents_id.render_process_id, | 253 sourceID.web_contents_id.render_process_id, |
| 253 sourceID.web_contents_id.main_render_frame_id)); | 254 sourceID.web_contents_id.main_render_frame_id)); |
| 254 if (tab) | 255 if (tab) |
| 255 tab->GetDelegate()->ActivateContents(tab); | 256 tab->GetDelegate()->ActivateContents(tab); |
| 256 } | 257 } |
| 257 | 258 |
| 258 // Notify the |callback_| asynchronously because it may release the | 259 // Notify the |callback_| asynchronously because it may release the |
| 259 // controller. | 260 // controller. |
| 260 content::BrowserThread::PostTask( | 261 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| 261 content::BrowserThread::UI, FROM_HERE, | 262 base::Bind(doneCallback_, sourceID)); |
| 262 base::Bind(doneCallback_, sourceID)); | |
| 263 doneCallback_.Reset(); | 263 doneCallback_.Reset(); |
| 264 } | 264 } |
| 265 | 265 |
| 266 - (void)sharePressed:(id)sender { | 266 - (void)sharePressed:(id)sender { |
| 267 NSIndexSet* indexes = [sourceBrowser_ selectionIndexes]; | 267 NSIndexSet* indexes = [sourceBrowser_ selectionIndexes]; |
| 268 NSUInteger selectedIndex = [indexes firstIndex]; | 268 NSUInteger selectedIndex = [indexes firstIndex]; |
| 269 DesktopMediaPickerItem* item = | 269 DesktopMediaPickerItem* item = [items_ objectAtIndex:selectedIndex]; |
| 270 [items_ objectAtIndex:selectedIndex]; | |
| 271 [self reportResult:[item sourceID]]; | 270 [self reportResult:[item sourceID]]; |
| 272 [self close]; | 271 [self close]; |
| 273 } | 272 } |
| 274 | 273 |
| 275 - (void)cancelPressed:(id)sender { | 274 - (void)cancelPressed:(id)sender { |
| 276 [self reportResult:content::DesktopMediaID()]; | 275 [self reportResult:content::DesktopMediaID()]; |
| 277 [self close]; | 276 [self close]; |
| 278 } | 277 } |
| 279 | 278 |
| 280 - (NSTextField*)createTextFieldWithText:(NSString*)text | 279 - (NSTextField*)createTextFieldWithText:(NSString*)text |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 NSWindow* window = [self window]; | 313 NSWindow* window = [self window]; |
| 315 [[window parentWindow] removeChildWindow:window]; | 314 [[window parentWindow] removeChildWindow:window]; |
| 316 } | 315 } |
| 317 | 316 |
| 318 #pragma mark IKImageBrowserDataSource | 317 #pragma mark IKImageBrowserDataSource |
| 319 | 318 |
| 320 - (NSUInteger)numberOfItemsInImageBrowser:(IKImageBrowserView*)browser { | 319 - (NSUInteger)numberOfItemsInImageBrowser:(IKImageBrowserView*)browser { |
| 321 return [items_ count]; | 320 return [items_ count]; |
| 322 } | 321 } |
| 323 | 322 |
| 324 - (id)imageBrowser:(IKImageBrowserView *)browser | 323 - (id)imageBrowser:(IKImageBrowserView*)browser itemAtIndex:(NSUInteger)index { |
| 325 itemAtIndex:(NSUInteger)index { | |
| 326 return [items_ objectAtIndex:index]; | 324 return [items_ objectAtIndex:index]; |
| 327 } | 325 } |
| 328 | 326 |
| 329 #pragma mark IKImageBrowserDelegate | 327 #pragma mark IKImageBrowserDelegate |
| 330 | 328 |
| 331 - (void)imageBrowser:(IKImageBrowserView *)browser | 329 - (void)imageBrowser:(IKImageBrowserView*)browser |
| 332 cellWasDoubleClickedAtIndex:(NSUInteger)index { | 330 cellWasDoubleClickedAtIndex:(NSUInteger)index { |
| 333 DesktopMediaPickerItem* item = [items_ objectAtIndex:index]; | 331 DesktopMediaPickerItem* item = [items_ objectAtIndex:index]; |
| 334 [self reportResult:[item sourceID]]; | 332 [self reportResult:[item sourceID]]; |
| 335 [self close]; | 333 [self close]; |
| 336 } | 334 } |
| 337 | 335 |
| 338 - (void)imageBrowserSelectionDidChange:(IKImageBrowserView*)browser { | 336 - (void)imageBrowserSelectionDidChange:(IKImageBrowserView*)browser { |
| 339 NSIndexSet* indexes = [sourceBrowser_ selectionIndexes]; | 337 NSIndexSet* indexes = [sourceBrowser_ selectionIndexes]; |
| 340 | 338 |
| 341 // Enable or disable the OK button based on whether we have a selection. | 339 // Enable or disable the OK button based on whether we have a selection. |
| 342 [shareButton_ setEnabled:([indexes count] > 0)]; | 340 [shareButton_ setEnabled:([indexes count] > 0)]; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 } | 376 } |
| 379 [audioShareCheckbox_ setToolTip:@""]; | 377 [audioShareCheckbox_ setToolTip:@""]; |
| 380 break; | 378 break; |
| 381 case content::DesktopMediaID::TYPE_NONE: | 379 case content::DesktopMediaID::TYPE_NONE: |
| 382 NOTREACHED(); | 380 NOTREACHED(); |
| 383 } | 381 } |
| 384 } | 382 } |
| 385 | 383 |
| 386 #pragma mark DesktopMediaPickerObserver | 384 #pragma mark DesktopMediaPickerObserver |
| 387 | 385 |
| 388 - (void)sourceAddedAtIndex:(int)index { | 386 - (void)sourceAddedForList:(DesktopMediaList*)list atIndex:(int)index { |
| 389 const DesktopMediaList::Source& source = media_list_->GetSource(index); | 387 const DesktopMediaList::Source& source = media_list_->GetSource(index); |
| 390 NSString* imageTitle = base::SysUTF16ToNSString(source.name); | 388 NSString* imageTitle = base::SysUTF16ToNSString(source.name); |
| 391 base::scoped_nsobject<DesktopMediaPickerItem> item( | 389 base::scoped_nsobject<DesktopMediaPickerItem> item( |
| 392 [[DesktopMediaPickerItem alloc] initWithSourceId:source.id | 390 [[DesktopMediaPickerItem alloc] initWithSourceId:source.id |
| 393 imageUID:++lastImageUID_ | 391 imageUID:++lastImageUID_ |
| 394 imageTitle:imageTitle]); | 392 imageTitle:imageTitle]); |
| 395 [items_ insertObject:item atIndex:index]; | 393 [items_ insertObject:item atIndex:index]; |
| 396 [sourceBrowser_ reloadData]; | 394 [sourceBrowser_ reloadData]; |
| 397 | 395 |
| 398 NSString* autoselectSource = base::SysUTF8ToNSString( | 396 NSString* autoselectSource = base::SysUTF8ToNSString( |
| 399 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 397 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 400 switches::kAutoSelectDesktopCaptureSource)); | 398 switches::kAutoSelectDesktopCaptureSource)); |
| 401 | 399 |
| 402 if ([autoselectSource isEqualToString:imageTitle]) { | 400 if ([autoselectSource isEqualToString:imageTitle]) { |
| 403 [self reportResult:[item sourceID]]; | 401 [self reportResult:[item sourceID]]; |
| 404 [self close]; | 402 [self close]; |
| 405 } | 403 } |
| 406 } | 404 } |
| 407 | 405 |
| 408 - (void)sourceRemovedAtIndex:(int)index { | 406 - (void)sourceRemovedForList:(DesktopMediaList*)list atIndex:(int)index { |
| 409 if ([[sourceBrowser_ selectionIndexes] containsIndex:index]) { | 407 if ([[sourceBrowser_ selectionIndexes] containsIndex:index]) { |
| 410 // Selected item was removed. Clear selection. | 408 // Selected item was removed. Clear selection. |
| 411 [sourceBrowser_ setSelectionIndexes:[NSIndexSet indexSet] | 409 [sourceBrowser_ setSelectionIndexes:[NSIndexSet indexSet] |
| 412 byExtendingSelection:FALSE]; | 410 byExtendingSelection:FALSE]; |
| 413 } | 411 } |
| 414 [items_ removeObjectAtIndex:index]; | 412 [items_ removeObjectAtIndex:index]; |
| 415 [sourceBrowser_ reloadData]; | 413 [sourceBrowser_ reloadData]; |
| 416 } | 414 } |
| 417 | 415 |
| 418 - (void)sourceMovedFrom:(int)oldIndex to:(int)newIndex { | 416 - (void)sourceMovedForList:(DesktopMediaList*)list |
| 417 from:(int)oldIndex |
| 418 to:(int)newIndex { |
| 419 base::scoped_nsobject<DesktopMediaPickerItem> item( | 419 base::scoped_nsobject<DesktopMediaPickerItem> item( |
| 420 [[items_ objectAtIndex:oldIndex] retain]); | 420 [[items_ objectAtIndex:oldIndex] retain]); |
| 421 [items_ removeObjectAtIndex:oldIndex]; | 421 [items_ removeObjectAtIndex:oldIndex]; |
| 422 [items_ insertObject:item atIndex:newIndex]; | 422 [items_ insertObject:item atIndex:newIndex]; |
| 423 [sourceBrowser_ reloadData]; | 423 [sourceBrowser_ reloadData]; |
| 424 } | 424 } |
| 425 | 425 |
| 426 - (void)sourceNameChangedAtIndex:(int)index { | 426 - (void)sourceNameChangedForList:(DesktopMediaList*)list atIndex:(int)index { |
| 427 DesktopMediaPickerItem* item = [items_ objectAtIndex:index]; | 427 DesktopMediaPickerItem* item = [items_ objectAtIndex:index]; |
| 428 const DesktopMediaList::Source& source = media_list_->GetSource(index); | 428 const DesktopMediaList::Source& source = media_list_->GetSource(index); |
| 429 [item setImageTitle:base::SysUTF16ToNSString(source.name)]; | 429 [item setImageTitle:base::SysUTF16ToNSString(source.name)]; |
| 430 [sourceBrowser_ reloadData]; | 430 [sourceBrowser_ reloadData]; |
| 431 } | 431 } |
| 432 | 432 |
| 433 - (void)sourceThumbnailChangedAtIndex:(int)index { | 433 - (void)sourceThumbnailChangedForList:(DesktopMediaList*)list |
| 434 atIndex:(int)index { |
| 434 const DesktopMediaList::Source& source = media_list_->GetSource(index); | 435 const DesktopMediaList::Source& source = media_list_->GetSource(index); |
| 435 NSImage* image = gfx::NSImageFromImageSkia(source.thumbnail); | 436 NSImage* image = gfx::NSImageFromImageSkia(source.thumbnail); |
| 436 | 437 |
| 437 DesktopMediaPickerItem* item = [items_ objectAtIndex:index]; | 438 DesktopMediaPickerItem* item = [items_ objectAtIndex:index]; |
| 438 [item setImageRepresentation:image]; | 439 [item setImageRepresentation:image]; |
| 439 [sourceBrowser_ reloadData]; | 440 [sourceBrowser_ reloadData]; |
| 440 } | 441 } |
| 441 | 442 |
| 442 @end // @interface DesktopMediaPickerController | 443 @end // @interface DesktopMediaPickerController |
| OLD | NEW |