Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(649)

Side by Side Diff: chrome/browser/ui/cocoa/media_picker/desktop_media_picker_controller_deprecated.mm

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

Powered by Google App Engine
This is Rietveld 408576698