Chromium Code Reviews| 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 <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" |
| (...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 590 | 590 |
| 591 - (NSUInteger)numberOfItemsInImageBrowser:(IKImageBrowserView*)browser { | 591 - (NSUInteger)numberOfItemsInImageBrowser:(IKImageBrowserView*)browser { |
| 592 DesktopMediaID::Type sourceType = [self sourceTypeForBrowser:browser]; | 592 DesktopMediaID::Type sourceType = [self sourceTypeForBrowser:browser]; |
| 593 NSMutableArray* items = [self itemSetForType:sourceType]; | 593 NSMutableArray* items = [self itemSetForType:sourceType]; |
| 594 return [items count]; | 594 return [items count]; |
| 595 } | 595 } |
| 596 | 596 |
| 597 - (id)imageBrowser:(IKImageBrowserView*)browser itemAtIndex:(NSUInteger)index { | 597 - (id)imageBrowser:(IKImageBrowserView*)browser itemAtIndex:(NSUInteger)index { |
| 598 DesktopMediaID::Type sourceType = [self sourceTypeForBrowser:browser]; | 598 DesktopMediaID::Type sourceType = [self sourceTypeForBrowser:browser]; |
| 599 NSMutableArray* items = [self itemSetForType:sourceType]; | 599 NSMutableArray* items = [self itemSetForType:sourceType]; |
| 600 return [items objectAtIndex:index]; | 600 id item = [items objectAtIndex:index]; |
|
tapted
2016/07/22 03:43:36
id -> DesktopMediaPickerItem* (it's usually best t
qiangchen
2016/07/22 18:33:54
Done.
| |
| 601 [item setTitleHidden:browser == screenBrowser_ && [items count] == 1]; | |
|
tapted
2016/07/22 03:43:36
this should have a comment - it's pretty subtle
qiangchen
2016/07/22 18:33:54
Done.
| |
| 602 | |
| 603 return item; | |
| 601 } | 604 } |
| 602 | 605 |
| 603 #pragma mark IKImageBrowserDelegate | 606 #pragma mark IKImageBrowserDelegate |
| 604 | 607 |
| 605 - (void)imageBrowser:(IKImageBrowserView*)browser | 608 - (void)imageBrowser:(IKImageBrowserView*)browser |
| 606 cellWasDoubleClickedAtIndex:(NSUInteger)index { | 609 cellWasDoubleClickedAtIndex:(NSUInteger)index { |
| 607 DesktopMediaPickerItem* item; | 610 DesktopMediaPickerItem* item; |
| 608 if (browser == screenBrowser_) | 611 if (browser == screenBrowser_) |
| 609 item = [screenItems_ objectAtIndex:index]; | 612 item = [screenItems_ objectAtIndex:index]; |
| 610 else | 613 else |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 674 NSInteger selectedIndex = [self selectedIndexForType:sourceType]; | 677 NSInteger selectedIndex = [self selectedIndexForType:sourceType]; |
| 675 if (selectedIndex >= index) | 678 if (selectedIndex >= index) |
| 676 ++selectedIndex; | 679 ++selectedIndex; |
| 677 | 680 |
| 678 const DesktopMediaList::Source& source = list->GetSource(index); | 681 const DesktopMediaList::Source& source = list->GetSource(index); |
| 679 NSString* imageTitle = base::SysUTF16ToNSString(source.name); | 682 NSString* imageTitle = base::SysUTF16ToNSString(source.name); |
| 680 base::scoped_nsobject<DesktopMediaPickerItem> item( | 683 base::scoped_nsobject<DesktopMediaPickerItem> item( |
| 681 [[DesktopMediaPickerItem alloc] initWithSourceId:source.id | 684 [[DesktopMediaPickerItem alloc] initWithSourceId:source.id |
| 682 imageUID:++lastImageUID_ | 685 imageUID:++lastImageUID_ |
| 683 imageTitle:imageTitle]); | 686 imageTitle:imageTitle]); |
| 687 | |
| 684 [items insertObject:item atIndex:index]; | 688 [items insertObject:item atIndex:index]; |
| 685 [browser reloadData]; | 689 [browser reloadData]; |
| 686 if (sourceType == DesktopMediaID::TYPE_WEB_CONTENTS) | 690 if (sourceType == DesktopMediaID::TYPE_WEB_CONTENTS) { |
| 691 // Memorizing selection. | |
| 687 [self setTabBrowserIndex:selectedIndex]; | 692 [self setTabBrowserIndex:selectedIndex]; |
| 693 } else if (sourceType == DesktopMediaID::TYPE_SCREEN && [items count] == 1) { | |
| 694 // Preselect the first screen source. | |
| 695 [browser setSelectionIndexes:[NSIndexSet indexSetWithIndex:0] | |
| 696 byExtendingSelection:NO]; | |
| 697 } | |
| 688 | 698 |
| 689 NSString* autoselectSource = base::SysUTF8ToNSString( | 699 NSString* autoselectSource = base::SysUTF8ToNSString( |
| 690 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 700 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 691 switches::kAutoSelectDesktopCaptureSource)); | 701 switches::kAutoSelectDesktopCaptureSource)); |
| 692 | 702 |
| 693 if ([autoselectSource isEqualToString:imageTitle]) { | 703 if ([autoselectSource isEqualToString:imageTitle]) { |
| 694 [self reportResult:[item sourceID]]; | 704 [self reportResult:[item sourceID]]; |
| 695 [self close]; | 705 [self close]; |
| 696 } | 706 } |
| 697 } | 707 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 771 | 781 |
| 772 DesktopMediaPickerItem* item = [items objectAtIndex:index]; | 782 DesktopMediaPickerItem* item = [items objectAtIndex:index]; |
| 773 [item setImageRepresentation:image]; | 783 [item setImageRepresentation:image]; |
| 774 [browser reloadData]; | 784 [browser reloadData]; |
| 775 | 785 |
| 776 if (sourceType == DesktopMediaID::TYPE_WEB_CONTENTS) | 786 if (sourceType == DesktopMediaID::TYPE_WEB_CONTENTS) |
| 777 [self setTabBrowserIndex:selectedIndex]; | 787 [self setTabBrowserIndex:selectedIndex]; |
| 778 } | 788 } |
| 779 | 789 |
| 780 @end // @interface DesktopMediaPickerController | 790 @end // @interface DesktopMediaPickerController |
| OLD | NEW |