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

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

Issue 2890233003: Dynamically Adjust Screen Item Size According To Item Count (Closed)
Patch Set: Move size detection to list observer Created 3 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.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 22 matching lines...) Expand all
33 33
34 namespace { 34 namespace {
35 35
36 const CGFloat kInitialContentWidth = 620; 36 const CGFloat kInitialContentWidth = 620;
37 const CGFloat kMinimumContentWidth = 500; 37 const CGFloat kMinimumContentWidth = 500;
38 const CGFloat kMinimumContentHeight = 390; 38 const CGFloat kMinimumContentHeight = 390;
39 const CGFloat kThumbnailWidth = 150; 39 const CGFloat kThumbnailWidth = 150;
40 const CGFloat kThumbnailHeight = 150; 40 const CGFloat kThumbnailHeight = 150;
41 const CGFloat kSingleScreenWidth = 300; 41 const CGFloat kSingleScreenWidth = 300;
42 const CGFloat kSingleScreenHeight = 300; 42 const CGFloat kSingleScreenHeight = 300;
43 const CGFloat kMultipleScreenWidth = 220;
44 const CGFloat kMultipleScreenHeight = 220;
43 const CGFloat kFramePadding = 20; 45 const CGFloat kFramePadding = 20;
44 const CGFloat kControlSpacing = 10; 46 const CGFloat kControlSpacing = 10;
45 const CGFloat kExcessButtonPadding = 6; 47 const CGFloat kExcessButtonPadding = 6;
46 const CGFloat kRowHeight = 20; 48 const CGFloat kRowHeight = 20;
47 const CGFloat kRowWidth = 500; 49 const CGFloat kRowWidth = 500;
48 const CGFloat kIconWidth = 20; 50 const CGFloat kIconWidth = 20;
49 const CGFloat kPaddedWidth = kInitialContentWidth - (kFramePadding * 2); 51 const CGFloat kPaddedWidth = kInitialContentWidth - (kFramePadding * 2);
50 const CGFloat kFontSize = 13; 52 const CGFloat kFontSize = 13;
51 53
52 NSString* const kIconId = @"icon"; 54 NSString* const kIconId = @"icon";
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 CGFloat controlWidth = NSWidth([sourceTypeControl_ frame]); 274 CGFloat controlWidth = NSWidth([sourceTypeControl_ frame]);
273 CGFloat controlHeight = NSHeight([sourceTypeControl_ frame]); 275 CGFloat controlHeight = NSHeight([sourceTypeControl_ frame]);
274 NSRect centerFrame = NSMakeRect((kInitialContentWidth - controlWidth) / 2, 276 NSRect centerFrame = NSMakeRect((kInitialContentWidth - controlWidth) / 2,
275 origin.y, controlWidth, controlHeight); 277 origin.y, controlWidth, controlHeight);
276 278
277 [sourceTypeControl_ setFrame:NSIntegralRect(centerFrame)]; 279 [sourceTypeControl_ setFrame:NSIntegralRect(centerFrame)];
278 } 280 }
279 281
280 - (void)createSourceViewsAtOrigin:(NSPoint)origin { 282 - (void)createSourceViewsAtOrigin:(NSPoint)origin {
281 if (screenList_) { 283 if (screenList_) {
282 screenBrowser_.reset([[self 284 const bool is_single = screenList_->GetSourceCount() <= 1;
283 createImageBrowserWithSize:NSMakeSize(kSingleScreenWidth, 285 const CGFloat width = is_single ? kSingleScreenWidth : kMultipleScreenWidth;
284 kSingleScreenHeight)] retain]); 286 const CGFloat height =
287 is_single ? kSingleScreenHeight : kMultipleScreenHeight;
288 screenBrowser_.reset(
289 [[self createImageBrowserWithSize:NSMakeSize(width, height)] retain]);
285 } 290 }
286 291
287 if (windowList_) { 292 if (windowList_) {
288 windowBrowser_.reset([ 293 windowBrowser_.reset([
289 [self createImageBrowserWithSize:NSMakeSize(kThumbnailWidth, 294 [self createImageBrowserWithSize:NSMakeSize(kThumbnailWidth,
290 kThumbnailHeight)] retain]); 295 kThumbnailHeight)] retain]);
291 } 296 }
292 297
293 if (tabList_) { 298 if (tabList_) {
294 tabBrowser_.reset([[NSTableView alloc] initWithFrame:NSZeroRect]); 299 tabBrowser_.reset([[NSTableView alloc] initWithFrame:NSZeroRect]);
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 600
596 - (id)imageBrowser:(IKImageBrowserView*)browser itemAtIndex:(NSUInteger)index { 601 - (id)imageBrowser:(IKImageBrowserView*)browser itemAtIndex:(NSUInteger)index {
597 DesktopMediaID::Type sourceType = [self sourceTypeForBrowser:browser]; 602 DesktopMediaID::Type sourceType = [self sourceTypeForBrowser:browser];
598 NSMutableArray* items = [self itemSetForType:sourceType]; 603 NSMutableArray* items = [self itemSetForType:sourceType];
599 DesktopMediaPickerItem* item = [items objectAtIndex:index]; 604 DesktopMediaPickerItem* item = [items objectAtIndex:index];
600 605
601 // For screen source, if there is only one source, we can omit the label 606 // For screen source, if there is only one source, we can omit the label
602 // "Entire Screen", because it is redundant with tab label "Your Entire 607 // "Entire Screen", because it is redundant with tab label "Your Entire
603 // Screen". 608 // Screen".
604 [item setTitleHidden:browser == screenBrowser_ && [items count] == 1]; 609 [item setTitleHidden:browser == screenBrowser_ && [items count] == 1];
605
606 return item; 610 return item;
607 } 611 }
608 612
609 #pragma mark IKImageBrowserDelegate 613 #pragma mark IKImageBrowserDelegate
610 614
611 - (void)imageBrowser:(IKImageBrowserView*)browser 615 - (void)imageBrowser:(IKImageBrowserView*)browser
612 cellWasDoubleClickedAtIndex:(NSUInteger)index { 616 cellWasDoubleClickedAtIndex:(NSUInteger)index {
613 DesktopMediaPickerItem* item; 617 DesktopMediaPickerItem* item;
614 if (browser == screenBrowser_) 618 if (browser == screenBrowser_)
615 item = [screenItems_ objectAtIndex:index]; 619 item = [screenItems_ objectAtIndex:index];
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 base::scoped_nsobject<DesktopMediaPickerItem> item( 690 base::scoped_nsobject<DesktopMediaPickerItem> item(
687 [[DesktopMediaPickerItem alloc] initWithSourceId:source.id 691 [[DesktopMediaPickerItem alloc] initWithSourceId:source.id
688 imageUID:++lastImageUID_ 692 imageUID:++lastImageUID_
689 imageTitle:imageTitle]); 693 imageTitle:imageTitle]);
690 694
691 [items insertObject:item atIndex:index]; 695 [items insertObject:item atIndex:index];
692 [browser reloadData]; 696 [browser reloadData];
693 if (sourceType == DesktopMediaID::TYPE_WEB_CONTENTS) { 697 if (sourceType == DesktopMediaID::TYPE_WEB_CONTENTS) {
694 // Memorizing selection. 698 // Memorizing selection.
695 [self setTabBrowserIndex:selectedIndex]; 699 [self setTabBrowserIndex:selectedIndex];
696 } else if (sourceType == DesktopMediaID::TYPE_SCREEN && [items count] == 1) { 700 } else if (sourceType == DesktopMediaID::TYPE_SCREEN) {
697 // Preselect the first screen source. 701 if ([items count] == 1) {
698 [browser setSelectionIndexes:[NSIndexSet indexSetWithIndex:0] 702 // Preselect the first screen source.
699 byExtendingSelection:NO]; 703 [browser setSelectionIndexes:[NSIndexSet indexSetWithIndex:0]
704 byExtendingSelection:NO];
705 } else if ([items count] == 2) {
706 // Switch to multiple sources mode
tapted 2017/05/23 20:36:11 nit: full stop at end
qiangchen 2017/05/23 21:33:17 Done.
707 [browser
708 setCellSize:NSMakeSize(kMultipleScreenWidth, kMultipleScreenHeight)];
709 }
700 } 710 }
701 711
702 NSString* autoselectSource = base::SysUTF8ToNSString( 712 NSString* autoselectSource = base::SysUTF8ToNSString(
703 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 713 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
704 switches::kAutoSelectDesktopCaptureSource)); 714 switches::kAutoSelectDesktopCaptureSource));
705 715
706 if ([autoselectSource isEqualToString:imageTitle]) { 716 if ([autoselectSource isEqualToString:imageTitle]) {
707 [self reportResult:[item sourceID]]; 717 [self reportResult:[item sourceID]];
708 [self close]; 718 [self close];
709 } 719 }
(...skipping 14 matching lines...) Expand all
724 [tabBrowser_ reloadData]; 734 [tabBrowser_ reloadData];
725 [self setTabBrowserIndex:selectedIndex]; 735 [self setTabBrowserIndex:selectedIndex];
726 return; 736 return;
727 } 737 }
728 738
729 if ([[browser selectionIndexes] containsIndex:index]) { 739 if ([[browser selectionIndexes] containsIndex:index]) {
730 // Selected item was removed. Clear selection. 740 // Selected item was removed. Clear selection.
731 [browser setSelectionIndexes:[NSIndexSet indexSet] byExtendingSelection:NO]; 741 [browser setSelectionIndexes:[NSIndexSet indexSet] byExtendingSelection:NO];
732 } 742 }
733 [items removeObjectAtIndex:index]; 743 [items removeObjectAtIndex:index];
734 [browser reloadData]; 744 [browser reloadData];
tapted 2017/05/23 20:36:11 move this after the setCellSize call?
qiangchen 2017/05/23 21:33:17 Done.
745 if (sourceType == DesktopMediaID::TYPE_SCREEN && [items count] == 1) {
746 [browser setCellSize:NSMakeSize(kSingleScreenWidth, kSingleScreenHeight)];
747 }
tapted 2017/05/23 20:36:11 nit: curlies not needed
qiangchen 2017/05/23 21:33:17 Done.
735 } 748 }
736 749
737 - (void)sourceMovedForList:(DesktopMediaList*)list 750 - (void)sourceMovedForList:(DesktopMediaList*)list
738 from:(int)oldIndex 751 from:(int)oldIndex
739 to:(int)newIndex { 752 to:(int)newIndex {
740 DesktopMediaID::Type sourceType = [self sourceTypeForList:list]; 753 DesktopMediaID::Type sourceType = [self sourceTypeForList:list];
741 NSMutableArray* items = [self itemSetForType:sourceType]; 754 NSMutableArray* items = [self itemSetForType:sourceType];
742 id browser = [self browserViewForType:sourceType]; 755 id browser = [self browserViewForType:sourceType];
743 NSInteger selectedIndex = [self selectedIndexForType:sourceType]; 756 NSInteger selectedIndex = [self selectedIndexForType:sourceType];
744 if (selectedIndex > oldIndex && selectedIndex <= newIndex) 757 if (selectedIndex > oldIndex && selectedIndex <= newIndex)
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 797
785 DesktopMediaPickerItem* item = [items objectAtIndex:index]; 798 DesktopMediaPickerItem* item = [items objectAtIndex:index];
786 [item setImageRepresentation:image]; 799 [item setImageRepresentation:image];
787 [browser reloadData]; 800 [browser reloadData];
788 801
789 if (sourceType == DesktopMediaID::TYPE_WEB_CONTENTS) 802 if (sourceType == DesktopMediaID::TYPE_WEB_CONTENTS)
790 [self setTabBrowserIndex:selectedIndex]; 803 [self setTabBrowserIndex:selectedIndex];
791 } 804 }
792 805
793 @end // @interface DesktopMediaPickerController 806 @end // @interface DesktopMediaPickerController
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698