| 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 DesktopMediaPickerItem* item = [items objectAtIndex:index]; |
| 601 |
| 602 // For screen source, if there is only one source, we can omit the label |
| 603 // "Entire Screen", because it is redundant with tab label "Your Entire |
| 604 // Screen". |
| 605 [item setTitleHidden:browser == screenBrowser_ && [items count] == 1]; |
| 606 |
| 607 return item; |
| 601 } | 608 } |
| 602 | 609 |
| 603 #pragma mark IKImageBrowserDelegate | 610 #pragma mark IKImageBrowserDelegate |
| 604 | 611 |
| 605 - (void)imageBrowser:(IKImageBrowserView*)browser | 612 - (void)imageBrowser:(IKImageBrowserView*)browser |
| 606 cellWasDoubleClickedAtIndex:(NSUInteger)index { | 613 cellWasDoubleClickedAtIndex:(NSUInteger)index { |
| 607 DesktopMediaPickerItem* item; | 614 DesktopMediaPickerItem* item; |
| 608 if (browser == screenBrowser_) | 615 if (browser == screenBrowser_) |
| 609 item = [screenItems_ objectAtIndex:index]; | 616 item = [screenItems_ objectAtIndex:index]; |
| 610 else | 617 else |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 NSInteger selectedIndex = [self selectedIndexForType:sourceType]; | 681 NSInteger selectedIndex = [self selectedIndexForType:sourceType]; |
| 675 if (selectedIndex >= index) | 682 if (selectedIndex >= index) |
| 676 ++selectedIndex; | 683 ++selectedIndex; |
| 677 | 684 |
| 678 const DesktopMediaList::Source& source = list->GetSource(index); | 685 const DesktopMediaList::Source& source = list->GetSource(index); |
| 679 NSString* imageTitle = base::SysUTF16ToNSString(source.name); | 686 NSString* imageTitle = base::SysUTF16ToNSString(source.name); |
| 680 base::scoped_nsobject<DesktopMediaPickerItem> item( | 687 base::scoped_nsobject<DesktopMediaPickerItem> item( |
| 681 [[DesktopMediaPickerItem alloc] initWithSourceId:source.id | 688 [[DesktopMediaPickerItem alloc] initWithSourceId:source.id |
| 682 imageUID:++lastImageUID_ | 689 imageUID:++lastImageUID_ |
| 683 imageTitle:imageTitle]); | 690 imageTitle:imageTitle]); |
| 691 |
| 684 [items insertObject:item atIndex:index]; | 692 [items insertObject:item atIndex:index]; |
| 685 [browser reloadData]; | 693 [browser reloadData]; |
| 686 if (sourceType == DesktopMediaID::TYPE_WEB_CONTENTS) | 694 if (sourceType == DesktopMediaID::TYPE_WEB_CONTENTS) { |
| 695 // Memorizing selection. |
| 687 [self setTabBrowserIndex:selectedIndex]; | 696 [self setTabBrowserIndex:selectedIndex]; |
| 697 } else if (sourceType == DesktopMediaID::TYPE_SCREEN && [items count] == 1) { |
| 698 // Preselect the first screen source. |
| 699 [browser setSelectionIndexes:[NSIndexSet indexSetWithIndex:0] |
| 700 byExtendingSelection:NO]; |
| 701 } |
| 688 | 702 |
| 689 NSString* autoselectSource = base::SysUTF8ToNSString( | 703 NSString* autoselectSource = base::SysUTF8ToNSString( |
| 690 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 704 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 691 switches::kAutoSelectDesktopCaptureSource)); | 705 switches::kAutoSelectDesktopCaptureSource)); |
| 692 | 706 |
| 693 if ([autoselectSource isEqualToString:imageTitle]) { | 707 if ([autoselectSource isEqualToString:imageTitle]) { |
| 694 [self reportResult:[item sourceID]]; | 708 [self reportResult:[item sourceID]]; |
| 695 [self close]; | 709 [self close]; |
| 696 } | 710 } |
| 697 } | 711 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 | 785 |
| 772 DesktopMediaPickerItem* item = [items objectAtIndex:index]; | 786 DesktopMediaPickerItem* item = [items objectAtIndex:index]; |
| 773 [item setImageRepresentation:image]; | 787 [item setImageRepresentation:image]; |
| 774 [browser reloadData]; | 788 [browser reloadData]; |
| 775 | 789 |
| 776 if (sourceType == DesktopMediaID::TYPE_WEB_CONTENTS) | 790 if (sourceType == DesktopMediaID::TYPE_WEB_CONTENTS) |
| 777 [self setTabBrowserIndex:selectedIndex]; | 791 [self setTabBrowserIndex:selectedIndex]; |
| 778 } | 792 } |
| 779 | 793 |
| 780 @end // @interface DesktopMediaPickerController | 794 @end // @interface DesktopMediaPickerController |
| OLD | NEW |