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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 - (void)reportResult:(content::DesktopMediaID)sourceID; | 47 - (void)reportResult:(content::DesktopMediaID)sourceID; |
48 | 48 |
49 // Action handlers. | 49 // Action handlers. |
50 - (void)okPressed:(id)sender; | 50 - (void)okPressed:(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)initWithModel:(scoped_ptr<DesktopMediaPickerModel>)model | 57 - (id)initWithMediaList:(scoped_ptr<DesktopMediaList>)media_list |
58 callback:(const DesktopMediaPicker::DoneCallback&)callback | 58 callback:(const DesktopMediaPicker::DoneCallback&)callback |
59 appName:(const string16&)appName { | 59 appName:(const string16&)appName { |
60 const NSUInteger kStyleMask = | 60 const NSUInteger kStyleMask = |
61 NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask; | 61 NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask; |
62 base::scoped_nsobject<NSWindow> window( | 62 base::scoped_nsobject<NSWindow> window( |
63 [[NSWindow alloc] initWithContentRect:ui::kWindowSizeDeterminedLater | 63 [[NSWindow alloc] initWithContentRect:ui::kWindowSizeDeterminedLater |
64 styleMask:kStyleMask | 64 styleMask:kStyleMask |
65 backing:NSBackingStoreBuffered | 65 backing:NSBackingStoreBuffered |
66 defer:NO]); | 66 defer:NO]); |
67 | 67 |
68 if ((self = [super initWithWindow:window])) { | 68 if ((self = [super initWithWindow:window])) { |
69 [window setDelegate:self]; | 69 [window setDelegate:self]; |
70 [self initializeContentsWithAppName:appName]; | 70 [self initializeContentsWithAppName:appName]; |
71 model_ = model.Pass(); | 71 media_list_ = media_list.Pass(); |
72 model_->SetViewDialogWindowId([window windowNumber]); | 72 media_list_->SetViewDialogWindowId([window windowNumber]); |
73 doneCallback_ = callback; | 73 doneCallback_ = callback; |
74 items_.reset([[NSMutableArray alloc] init]); | 74 items_.reset([[NSMutableArray alloc] init]); |
75 bridge_.reset(new DesktopMediaPickerBridge(self)); | 75 bridge_.reset(new DesktopMediaPickerBridge(self)); |
76 } | 76 } |
77 return self; | 77 return self; |
78 } | 78 } |
79 | 79 |
80 - (void)dealloc { | 80 - (void)dealloc { |
81 [sourceBrowser_ setDelegate:nil]; | 81 [sourceBrowser_ setDelegate:nil]; |
82 [sourceBrowser_ setDataSource:nil]; | 82 [sourceBrowser_ setDataSource:nil]; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 | 152 |
153 // Resize window to fit. | 153 // Resize window to fit. |
154 [[[self window] contentView] setAutoresizesSubviews:NO]; | 154 [[[self window] contentView] setAutoresizesSubviews:NO]; |
155 [[self window] setContentSize:NSMakeSize(kInitialContentWidth, origin.y)]; | 155 [[self window] setContentSize:NSMakeSize(kInitialContentWidth, origin.y)]; |
156 [[self window] setContentMinSize: | 156 [[self window] setContentMinSize: |
157 NSMakeSize(kMinimumContentWidth, kMinimumContentHeight)]; | 157 NSMakeSize(kMinimumContentWidth, kMinimumContentHeight)]; |
158 [[[self window] contentView] setAutoresizesSubviews:YES]; | 158 [[[self window] contentView] setAutoresizesSubviews:YES]; |
159 } | 159 } |
160 | 160 |
161 - (void)showWindow:(id)sender { | 161 - (void)showWindow:(id)sender { |
162 // Signal the model to start sending thumbnails. |bridge_| is used as the | 162 // Signal the media_list to start sending thumbnails. |bridge_| is used as the |
163 // observer, and will forward notifications to this object. | 163 // observer, and will forward notifications to this object. |
164 model_->SetThumbnailSize(gfx::Size(kThumbnailWidth, kThumbnailHeight)); | 164 media_list_->SetThumbnailSize(gfx::Size(kThumbnailWidth, kThumbnailHeight)); |
165 model_->StartUpdating(bridge_.get()); | 165 media_list_->StartUpdating(bridge_.get()); |
166 | 166 |
167 [self.window center]; | 167 [self.window center]; |
168 [super showWindow:sender]; | 168 [super showWindow:sender]; |
169 } | 169 } |
170 | 170 |
171 - (void)reportResult:(content::DesktopMediaID)sourceID { | 171 - (void)reportResult:(content::DesktopMediaID)sourceID { |
172 if (doneCallback_.is_null()) { | 172 if (doneCallback_.is_null()) { |
173 return; | 173 return; |
174 } | 174 } |
175 | 175 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 } | 250 } |
251 | 251 |
252 - (void)imageBrowserSelectionDidChange:(IKImageBrowserView*) aBrowser { | 252 - (void)imageBrowserSelectionDidChange:(IKImageBrowserView*) aBrowser { |
253 // Enable or disable the OK button based on whether we have a selection. | 253 // Enable or disable the OK button based on whether we have a selection. |
254 [okButton_ setEnabled:([[sourceBrowser_ selectionIndexes] count] > 0)]; | 254 [okButton_ setEnabled:([[sourceBrowser_ selectionIndexes] count] > 0)]; |
255 } | 255 } |
256 | 256 |
257 #pragma mark DesktopMediaPickerObserver | 257 #pragma mark DesktopMediaPickerObserver |
258 | 258 |
259 - (void)sourceAddedAtIndex:(int)index { | 259 - (void)sourceAddedAtIndex:(int)index { |
260 const DesktopMediaPickerModel::Source& source = model_->source(index); | 260 const DesktopMediaList::Source& source = media_list_->GetSource(index); |
261 NSString* imageTitle = base::SysUTF16ToNSString(source.name); | 261 NSString* imageTitle = base::SysUTF16ToNSString(source.name); |
262 base::scoped_nsobject<DesktopMediaPickerItem> item( | 262 base::scoped_nsobject<DesktopMediaPickerItem> item( |
263 [[DesktopMediaPickerItem alloc] initWithSourceId:source.id | 263 [[DesktopMediaPickerItem alloc] initWithSourceId:source.id |
264 imageUID:++lastImageUID_ | 264 imageUID:++lastImageUID_ |
265 imageTitle:imageTitle]); | 265 imageTitle:imageTitle]); |
266 [items_ insertObject:item atIndex:index]; | 266 [items_ insertObject:item atIndex:index]; |
267 [sourceBrowser_ reloadData]; | 267 [sourceBrowser_ reloadData]; |
268 } | 268 } |
269 | 269 |
270 - (void)sourceRemovedAtIndex:(int)index { | 270 - (void)sourceRemovedAtIndex:(int)index { |
271 if ([[sourceBrowser_ selectionIndexes] containsIndex:index]) { | 271 if ([[sourceBrowser_ selectionIndexes] containsIndex:index]) { |
272 // Selected item was removed. Clear selection. | 272 // Selected item was removed. Clear selection. |
273 [sourceBrowser_ setSelectionIndexes:[NSIndexSet indexSet] | 273 [sourceBrowser_ setSelectionIndexes:[NSIndexSet indexSet] |
274 byExtendingSelection:FALSE]; | 274 byExtendingSelection:FALSE]; |
275 } | 275 } |
276 [items_ removeObjectAtIndex:index]; | 276 [items_ removeObjectAtIndex:index]; |
277 [sourceBrowser_ reloadData]; | 277 [sourceBrowser_ reloadData]; |
278 } | 278 } |
279 | 279 |
280 - (void)sourceNameChangedAtIndex:(int)index { | 280 - (void)sourceNameChangedAtIndex:(int)index { |
281 DesktopMediaPickerItem* item = [items_ objectAtIndex:index]; | 281 DesktopMediaPickerItem* item = [items_ objectAtIndex:index]; |
282 const DesktopMediaPickerModel::Source& source = model_->source(index); | 282 const DesktopMediaList::Source& source = media_list_->GetSource(index); |
283 [item setImageTitle:base::SysUTF16ToNSString(source.name)]; | 283 [item setImageTitle:base::SysUTF16ToNSString(source.name)]; |
284 [sourceBrowser_ reloadData]; | 284 [sourceBrowser_ reloadData]; |
285 } | 285 } |
286 | 286 |
287 - (void)sourceThumbnailChangedAtIndex:(int)index { | 287 - (void)sourceThumbnailChangedAtIndex:(int)index { |
288 const DesktopMediaPickerModel::Source& source = model_->source(index); | 288 const DesktopMediaList::Source& source = media_list_->GetSource(index); |
289 NSImage* image = gfx::NSImageFromImageSkia(source.thumbnail); | 289 NSImage* image = gfx::NSImageFromImageSkia(source.thumbnail); |
290 | 290 |
291 DesktopMediaPickerItem* item = [items_ objectAtIndex:index]; | 291 DesktopMediaPickerItem* item = [items_ objectAtIndex:index]; |
292 [item setImageRepresentation:image]; | 292 [item setImageRepresentation:image]; |
293 [sourceBrowser_ reloadData]; | 293 [sourceBrowser_ reloadData]; |
294 } | 294 } |
295 | 295 |
296 @end // @interface DesktopMediaPickerController | 296 @end // @interface DesktopMediaPickerController |
OLD | NEW |