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" |
| 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 #import "chrome/browser/ui/cocoa/key_equivalent_constants.h" | 14 #import "chrome/browser/ui/cocoa/key_equivalent_constants.h" |
| 15 #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" |
| 16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/grit/chromium_strings.h" | |
| 17 #include "chrome/grit/generated_resources.h" | 18 #include "chrome/grit/generated_resources.h" |
| 19 #include "chrome/grit/google_chrome_strings.h" | |
| 18 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/render_frame_host.h" | 21 #include "content/public/browser/render_frame_host.h" |
| 20 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 21 #include "content/public/browser/web_contents_delegate.h" | 23 #include "content/public/browser/web_contents_delegate.h" |
| 22 #include "grit/components_strings.h" | 24 #include "grit/components_strings.h" |
| 23 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h" | 25 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h" |
| 24 #import "ui/base/cocoa/flipped_view.h" | 26 #import "ui/base/cocoa/flipped_view.h" |
| 25 #import "ui/base/cocoa/window_size_constants.h" | 27 #import "ui/base/cocoa/window_size_constants.h" |
| 26 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
| 27 #include "ui/gfx/image/image_skia_util_mac.h" | 29 #include "ui/gfx/image/image_skia_util_mac.h" |
| 28 | 30 |
| 29 namespace { | 31 namespace { |
| 30 | 32 |
| 31 const int kInitialContentWidth = 620; | 33 const int kInitialContentWidth = 620; |
|
tapted
2016/06/20 12:18:34
UI geometry constants in Cocoa should all be CGFlo
qiangchen
2016/06/21 23:31:27
Done.
| |
| 32 const int kMinimumContentWidth = 500; | 34 const int kMinimumContentWidth = 500; |
| 33 const int kMinimumContentHeight = 390; | 35 const int kMinimumContentHeight = 390; |
| 34 const int kThumbnailWidth = 150; | 36 const int kThumbnailWidth = 150; |
| 35 const int kThumbnailHeight = 150; | 37 const int kThumbnailHeight = 150; |
| 38 const int kSingleScreenWidth = 300; | |
| 39 const int kSingleScreenHeight = 300; | |
| 36 const int kFramePadding = 20; | 40 const int kFramePadding = 20; |
| 37 const int kControlSpacing = 10; | 41 const int kControlSpacing = 10; |
| 38 const int kExcessButtonPadding = 6; | 42 const int kExcessButtonPadding = 6; |
| 43 const int kRowHeight = 20; | |
| 44 const int kRowWidth = 500; | |
| 45 const int kIconWidth = 20; | |
| 39 | 46 |
| 40 } // namespace | 47 } // namespace |
| 41 | 48 |
| 42 @interface DesktopMediaPickerController (Private) | 49 @interface DesktopMediaPickerController (Private) |
| 43 | 50 |
| 44 // Populate the window with controls and views. | 51 // Populate the window with controls and views. |
| 45 - (void)initializeContentsWithAppName:(const base::string16&)appName; | 52 - (void)initializeContentsWithAppName:(const base::string16&)appName; |
| 46 | 53 |
| 47 // Create a |NSTextField| with label traits given |width|. Frame height is | 54 // Create a |NSTextField| with label traits given |width|. Frame height is |
| 48 // automatically adjusted to fit. | 55 // automatically adjusted to fit. |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 76 NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask; | 83 NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask; |
| 77 base::scoped_nsobject<NSWindow> window( | 84 base::scoped_nsobject<NSWindow> window( |
| 78 [[NSWindow alloc] initWithContentRect:ui::kWindowSizeDeterminedLater | 85 [[NSWindow alloc] initWithContentRect:ui::kWindowSizeDeterminedLater |
| 79 styleMask:kStyleMask | 86 styleMask:kStyleMask |
| 80 backing:NSBackingStoreBuffered | 87 backing:NSBackingStoreBuffered |
| 81 defer:NO]); | 88 defer:NO]); |
| 82 | 89 |
| 83 if ((self = [super initWithWindow:window])) { | 90 if ((self = [super initWithWindow:window])) { |
| 84 [parent addChildWindow:window ordered:NSWindowAbove]; | 91 [parent addChildWindow:window ordered:NSWindowAbove]; |
| 85 [window setDelegate:self]; | 92 [window setDelegate:self]; |
| 93 if (screen_list) { | |
| 94 screen_list_ = std::move(screen_list); | |
| 95 screen_items_.reset([[NSMutableArray alloc] init]); | |
| 96 } | |
| 97 | |
| 98 if (window_list) { | |
| 99 window_list_ = std::move(window_list); | |
| 100 window_list_->SetViewDialogWindowId(content::DesktopMediaID( | |
| 101 content::DesktopMediaID::TYPE_WINDOW, [window windowNumber])); | |
| 102 window_items_.reset([[NSMutableArray alloc] init]); | |
| 103 } | |
| 104 | |
| 105 if (tab_list) { | |
| 106 tab_list_ = std::move(tab_list); | |
| 107 tab_items_.reset([[NSMutableArray alloc] init]); | |
| 108 } | |
| 109 | |
| 86 [self initializeContentsWithAppName:appName | 110 [self initializeContentsWithAppName:appName |
| 87 targetName:targetName | 111 targetName:targetName |
| 88 requestAudio:requestAudio]; | 112 requestAudio:requestAudio]; |
| 89 std::vector<std::unique_ptr<DesktopMediaList>> media_lists; | 113 doneCallback_ = callback; |
| 90 if (screen_list) | |
| 91 media_lists.push_back(std::move(screen_list)); | |
| 92 | 114 |
| 93 if (window_list) | |
| 94 media_lists.push_back(std::move(window_list)); | |
| 95 | |
| 96 if (tab_list) | |
| 97 media_lists.push_back(std::move(tab_list)); | |
| 98 | |
| 99 if (media_lists.size() > 1) | |
| 100 media_list_.reset(new CombinedDesktopMediaList(media_lists)); | |
| 101 else | |
| 102 media_list_ = std::move(media_lists[0]); | |
| 103 media_list_->SetViewDialogWindowId(content::DesktopMediaID( | |
| 104 content::DesktopMediaID::TYPE_WINDOW, [window windowNumber])); | |
| 105 doneCallback_ = callback; | |
| 106 items_.reset([[NSMutableArray alloc] init]); | |
| 107 bridge_.reset(new DesktopMediaPickerBridge(self)); | 115 bridge_.reset(new DesktopMediaPickerBridge(self)); |
| 108 } | 116 } |
| 109 return self; | 117 return self; |
| 110 } | 118 } |
| 111 | 119 |
| 112 - (void)dealloc { | 120 - (void)dealloc { |
| 113 [shareButton_ setTarget:nil]; | 121 [shareButton_ setTarget:nil]; |
| 114 [cancelButton_ setTarget:nil]; | 122 [cancelButton_ setTarget:nil]; |
| 115 [sourceBrowser_ setDelegate:nil]; | 123 [screenBrowser_ setDelegate:nil]; |
| 116 [sourceBrowser_ setDataSource:nil]; | 124 [screenBrowser_ setDataSource:nil]; |
| 125 [windowBrowser_ setDelegate:nil]; | |
| 126 [windowBrowser_ setDataSource:nil]; | |
| 127 [tabBrowser_ setDataSource:nil]; | |
| 128 [tabBrowser_ setDelegate:nil]; | |
| 117 [[self window] close]; | 129 [[self window] close]; |
| 118 [super dealloc]; | 130 [super dealloc]; |
| 119 } | 131 } |
| 120 | 132 |
| 121 - (void)initializeContentsWithAppName:(const base::string16&)appName | 133 - (void)initializeContentsWithAppName:(const base::string16&)appName |
| 122 targetName:(const base::string16&)targetName | 134 targetName:(const base::string16&)targetName |
| 123 requestAudio:(bool)requestAudio { | 135 requestAudio:(bool)requestAudio { |
| 124 // Use flipped coordinates to facilitate manual layout. | 136 // Use flipped coordinates to facilitate manual layout. |
| 125 const CGFloat kPaddedWidth = kInitialContentWidth - (kFramePadding * 2); | 137 const CGFloat kPaddedWidth = kInitialContentWidth - (kFramePadding * 2); |
| 126 base::scoped_nsobject<FlippedView> content( | 138 base::scoped_nsobject<FlippedView> content( |
| 127 [[FlippedView alloc] initWithFrame:NSZeroRect]); | 139 [[FlippedView alloc] initWithFrame:NSZeroRect]); |
| 128 [[self window] setContentView:content]; | 140 [[self window] setContentView:content]; |
| 129 NSPoint origin = NSMakePoint(kFramePadding, kFramePadding); | 141 NSPoint origin = NSMakePoint(kFramePadding, kFramePadding); |
| 130 | 142 |
| 131 // Set the dialog's title. | 143 // Set the dialog's title. |
| 132 NSString* titleText = l10n_util::GetNSStringF( | 144 NSString* titleText = l10n_util::GetNSString(IDS_DESKTOP_MEDIA_PICKER_TITLE); |
| 133 IDS_DESKTOP_MEDIA_PICKER_TITLE_DEPRECATED, appName); | |
| 134 [[self window] setTitle:titleText]; | 145 [[self window] setTitle:titleText]; |
| 135 | 146 |
| 136 // Set the dialog's description. | 147 // Set the dialog's description. |
| 137 NSString* descriptionText; | 148 NSString* descriptionText; |
| 138 if (appName == targetName) { | 149 if (appName == targetName) { |
| 139 descriptionText = l10n_util::GetNSStringF( | 150 descriptionText = l10n_util::GetNSStringF( |
| 140 IDS_DESKTOP_MEDIA_PICKER_TEXT, appName); | 151 IDS_DESKTOP_MEDIA_PICKER_TEXT, appName); |
| 141 } else { | 152 } else { |
| 142 descriptionText = l10n_util::GetNSStringF( | 153 descriptionText = l10n_util::GetNSStringF( |
| 143 IDS_DESKTOP_MEDIA_PICKER_TEXT_DELEGATED, appName, targetName); | 154 IDS_DESKTOP_MEDIA_PICKER_TEXT_DELEGATED, appName, targetName); |
| 144 } | 155 } |
| 145 NSTextField* description = [self createTextFieldWithText:descriptionText | 156 NSTextField* description = [self createTextFieldWithText:descriptionText |
| 146 frameWidth:kPaddedWidth]; | 157 frameWidth:kPaddedWidth]; |
| 147 [description setFrameOrigin:origin]; | 158 [description setFrameOrigin:origin]; |
| 148 [content addSubview:description]; | 159 [content addSubview:description]; |
| 149 origin.y += NSHeight([description frame]) + kControlSpacing; | 160 origin.y += NSHeight([description frame]) + kControlSpacing; |
| 150 | 161 |
| 162 // Create segmented button | |
|
tapted
2016/06/20 12:18:35
nit: full stop
qiangchen
2016/06/21 23:31:28
Done.
| |
| 163 sourceTypeControl_.reset([[NSSegmentedControl alloc] init]); | |
| 164 | |
| 165 NSInteger segment_count = | |
|
tapted
2016/06/20 12:18:35
segmentCount - more below
qiangchen
2016/06/21 23:31:28
Done.
| |
| 166 (screen_list_ ? 1 : 0) + (window_list_ ? 1 : 0) + (tab_list_ ? 1 : 0); | |
| 167 [sourceTypeControl_ setSegmentCount:segment_count]; | |
| 168 NSInteger segment_index = 0; | |
| 169 | |
| 170 if (screen_list_) { | |
| 171 [sourceTypeControl_ | |
| 172 setLabel:l10n_util::GetNSString( | |
| 173 IDS_DESKTOP_MEDIA_PICKER_SOURCE_TYPE_SCREEN) | |
| 174 forSegment:segment_index]; | |
| 175 | |
| 176 [[sourceTypeControl_ cell] setTag:content::DesktopMediaID::TYPE_SCREEN | |
| 177 forSegment:segment_index]; | |
| 178 ++segment_index; | |
| 179 } | |
| 180 | |
| 181 if (window_list_) { | |
| 182 [sourceTypeControl_ | |
| 183 setLabel:l10n_util::GetNSString( | |
| 184 IDS_DESKTOP_MEDIA_PICKER_SOURCE_TYPE_WINDOW) | |
| 185 forSegment:segment_index]; | |
| 186 [[sourceTypeControl_ cell] setTag:content::DesktopMediaID::TYPE_WINDOW | |
| 187 forSegment:segment_index]; | |
| 188 ++segment_index; | |
| 189 } | |
| 190 | |
| 191 if (tab_list_) { | |
| 192 [sourceTypeControl_ setLabel:l10n_util::GetNSString( | |
| 193 IDS_DESKTOP_MEDIA_PICKER_SOURCE_TYPE_TAB) | |
| 194 forSegment:segment_index]; | |
| 195 [[sourceTypeControl_ cell] setTag:content::DesktopMediaID::TYPE_WEB_CONTENTS | |
| 196 forSegment:segment_index]; | |
| 197 ++segment_index; | |
| 198 } | |
| 199 [sourceTypeControl_ setAction:@selector(typeButtonPressed:)]; | |
| 200 | |
| 201 [[sourceTypeControl_ cell] setTrackingMode:NSSegmentSwitchTrackingSelectOne]; | |
| 202 | |
| 203 [content addSubview:sourceTypeControl_]; | |
| 204 | |
| 205 [sourceTypeControl_ sizeToFit]; | |
| 206 [sourceTypeControl_ setAutoresizingMask:NSViewMaxXMargin | NSViewMinXMargin]; | |
| 207 CGFloat control_width = NSWidth([sourceTypeControl_ frame]); | |
| 208 | |
| 209 [sourceTypeControl_ | |
| 210 setFrameOrigin:NSMakePoint((kInitialContentWidth - control_width) / 2, | |
|
tapted
2016/06/20 12:18:35
controlWidth can be an odd number, so dividing by
qiangchen
2016/06/21 23:31:28
Done.
| |
| 211 origin.y)]; | |
| 212 origin.y += NSHeight([sourceTypeControl_ frame]) + kControlSpacing; | |
| 213 | |
| 214 NSUInteger cellStyle = IKCellsStyleShadowed | IKCellsStyleTitled; | |
| 151 // Create the image browser. | 215 // Create the image browser. |
| 152 sourceBrowser_.reset([[IKImageBrowserView alloc] initWithFrame:NSZeroRect]); | 216 if (screen_list_) { |
| 153 NSUInteger cellStyle = IKCellsStyleShadowed | IKCellsStyleTitled; | 217 screenBrowser_.reset([[IKImageBrowserView alloc] initWithFrame:NSZeroRect]); |
|
tapted
2016/06/20 12:18:35
This is too much boilerplate - can you make a help
qiangchen
2016/06/21 23:31:27
Done.
| |
| 154 [sourceBrowser_ setDelegate:self]; | 218 [screenBrowser_ setDelegate:self]; |
| 155 [sourceBrowser_ setDataSource:self]; | 219 [screenBrowser_ setDataSource:self]; |
| 156 [sourceBrowser_ setCellsStyleMask:cellStyle]; | 220 [screenBrowser_ setCellsStyleMask:cellStyle]; |
| 157 [sourceBrowser_ setCellSize:NSMakeSize(kThumbnailWidth, kThumbnailHeight)]; | 221 [screenBrowser_ |
| 158 [sourceBrowser_ setAllowsMultipleSelection:NO]; | 222 setCellSize:NSMakeSize(kSingleScreenWidth, kSingleScreenHeight)]; |
| 223 [screenBrowser_ setAllowsMultipleSelection:NO]; | |
| 224 } | |
| 225 | |
| 226 if (window_list_) { | |
| 227 windowBrowser_.reset([[IKImageBrowserView alloc] initWithFrame:NSZeroRect]); | |
| 228 [windowBrowser_ setDelegate:self]; | |
| 229 [windowBrowser_ setDataSource:self]; | |
| 230 [windowBrowser_ setCellsStyleMask:cellStyle]; | |
| 231 [windowBrowser_ setCellSize:NSMakeSize(kThumbnailWidth, kThumbnailHeight)]; | |
| 232 [windowBrowser_ setAllowsMultipleSelection:NO]; | |
| 233 } | |
| 234 | |
| 235 if (tab_list_) { | |
| 236 tabBrowser_.reset([[NSTableView alloc] initWithFrame:NSZeroRect]); | |
| 237 [tabBrowser_ setDelegate:self]; | |
| 238 [tabBrowser_ setDataSource:self]; | |
| 239 [tabBrowser_ setAllowsMultipleSelection:NO]; | |
| 240 [tabBrowser_ setRowHeight:kRowHeight]; | |
| 241 [tabBrowser_ setDoubleAction:@selector(tableDoubleClick:)]; | |
| 242 NSTableColumn* icon_column = | |
|
tapted
2016/06/20 12:18:35
this should be scoped_nsobject - currently it's a
qiangchen
2016/06/21 23:31:27
Done.
| |
| 243 [[NSTableColumn alloc] initWithIdentifier:@"icon"]; | |
|
tapted
2016/06/20 12:18:34
@"icon" and @"title" should be constants
qiangchen
2016/06/21 23:31:27
Done.
| |
| 244 [icon_column setEditable:NO]; | |
| 245 [icon_column setWidth:kIconWidth]; | |
| 246 [tabBrowser_ addTableColumn:icon_column]; | |
| 247 NSTableColumn* title_column = | |
| 248 [[NSTableColumn alloc] initWithIdentifier:@"title"]; | |
| 249 [title_column setEditable:NO]; | |
| 250 [title_column setWidth:kRowWidth]; | |
| 251 [tabBrowser_ addTableColumn:title_column]; | |
| 252 [tabBrowser_ setHeaderView:nil]; | |
| 253 } | |
| 159 | 254 |
| 160 // Create a scroll view to host the image browser. | 255 // Create a scroll view to host the image browser. |
| 161 NSRect imageBrowserScrollFrame = NSMakeRect( | 256 NSRect imageBrowserScrollFrame = NSMakeRect( |
| 162 origin.x, origin.y, kPaddedWidth, 350); | 257 origin.x, origin.y, kPaddedWidth, 350); |
| 163 base::scoped_nsobject<NSScrollView> imageBrowserScroll( | 258 imageBrowserScroll_.reset( |
| 164 [[NSScrollView alloc] initWithFrame:imageBrowserScrollFrame]); | 259 [[NSScrollView alloc] initWithFrame:imageBrowserScrollFrame]); |
| 165 [imageBrowserScroll setHasVerticalScroller:YES]; | 260 [imageBrowserScroll_ setHasVerticalScroller:YES]; |
| 166 [imageBrowserScroll setDocumentView:sourceBrowser_]; | 261 [imageBrowserScroll_ setBorderType:NSBezelBorder]; |
| 167 [imageBrowserScroll setBorderType:NSBezelBorder]; | 262 [imageBrowserScroll_ |
| 168 [imageBrowserScroll setAutoresizingMask: | 263 setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
| 169 NSViewWidthSizable | NSViewHeightSizable]; | 264 [content addSubview:imageBrowserScroll_]; |
| 170 [content addSubview:imageBrowserScroll]; | 265 |
| 171 origin.y += NSHeight(imageBrowserScrollFrame) + kControlSpacing; | 266 origin.y += NSHeight(imageBrowserScrollFrame) + kControlSpacing; |
| 172 | 267 |
| 173 // Create a checkbox for audio sharing. | 268 // Create a checkbox for audio sharing. |
| 174 if (requestAudio) { | 269 if (requestAudio) { |
| 175 audioShareCheckbox_.reset([[NSButton alloc] initWithFrame:NSZeroRect]); | 270 audioShareCheckbox_.reset([[NSButton alloc] initWithFrame:NSZeroRect]); |
| 176 [audioShareCheckbox_ setFrameOrigin:origin]; | 271 [audioShareCheckbox_ setFrameOrigin:origin]; |
| 177 [audioShareCheckbox_ | 272 [audioShareCheckbox_ |
| 178 setAutoresizingMask:NSViewMaxXMargin | NSViewMinYMargin]; | 273 setAutoresizingMask:NSViewMaxXMargin | NSViewMinYMargin]; |
| 179 [audioShareCheckbox_ setButtonType:NSSwitchButton]; | 274 [audioShareCheckbox_ setButtonType:NSSwitchButton]; |
| 180 audioShareState_ = NSOnState; | 275 audioShareState_ = NSOnState; |
| 181 [audioShareCheckbox_ | 276 [audioShareCheckbox_ |
| 182 setTitle:l10n_util::GetNSString(IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE)]; | 277 setTitle:l10n_util::GetNSString(IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE)]; |
| 183 [audioShareCheckbox_ sizeToFit]; | 278 [audioShareCheckbox_ sizeToFit]; |
| 184 [audioShareCheckbox_ setEnabled:NO]; | |
| 185 [audioShareCheckbox_ | 279 [audioShareCheckbox_ |
| 186 setToolTip:l10n_util::GetNSString( | 280 setToolTip:l10n_util::GetNSString( |
| 187 IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE_TOOLTIP_MAC)]; | 281 IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE_TOOLTIP_MAC)]; |
| 188 [content addSubview:audioShareCheckbox_]; | 282 [content addSubview:audioShareCheckbox_]; |
| 189 origin.y += NSHeight([audioShareCheckbox_ frame]) + kControlSpacing; | 283 origin.y += NSHeight([audioShareCheckbox_ frame]) + kControlSpacing; |
| 190 } | 284 } |
| 191 | 285 |
| 192 // Create the share button. | 286 // Create the share button. |
| 193 shareButton_ = [self createButtonWithTitle:l10n_util::GetNSString( | 287 shareButton_ = [self createButtonWithTitle:l10n_util::GetNSString( |
| 194 IDS_DESKTOP_MEDIA_PICKER_SHARE)]; | 288 IDS_DESKTOP_MEDIA_PICKER_SHARE)]; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 216 origin.y += kFramePadding + | 310 origin.y += kFramePadding + |
| 217 (NSHeight([cancelButton_ frame]) - kExcessButtonPadding); | 311 (NSHeight([cancelButton_ frame]) - kExcessButtonPadding); |
| 218 | 312 |
| 219 // Resize window to fit. | 313 // Resize window to fit. |
| 220 [[[self window] contentView] setAutoresizesSubviews:NO]; | 314 [[[self window] contentView] setAutoresizesSubviews:NO]; |
| 221 [[self window] setContentSize:NSMakeSize(kInitialContentWidth, origin.y)]; | 315 [[self window] setContentSize:NSMakeSize(kInitialContentWidth, origin.y)]; |
| 222 [[self window] setContentMinSize: | 316 [[self window] setContentMinSize: |
| 223 NSMakeSize(kMinimumContentWidth, kMinimumContentHeight)]; | 317 NSMakeSize(kMinimumContentWidth, kMinimumContentHeight)]; |
| 224 [[[self window] contentView] setAutoresizesSubviews:YES]; | 318 [[[self window] contentView] setAutoresizesSubviews:YES]; |
| 225 | 319 |
| 226 // Make sourceBrowser_ get keyboard focus. | 320 // Make source browser get keyboard focus. |
| 227 [[self window] makeFirstResponder:sourceBrowser_]; | 321 if (segment_index == 1) |
|
tapted
2016/06/20 12:18:34
segmentIndex should end up in a separate method. s
qiangchen
2016/06/21 23:31:27
N/A now.
And I found this logic is actually incor
| |
| 322 [[self window] makeFirstResponder:screenBrowser_]; | |
| 323 else if (segment_index == 2) | |
| 324 [[self window] makeFirstResponder:windowBrowser_]; | |
| 325 else | |
| 326 [[self window] makeFirstResponder:tabBrowser_]; | |
| 327 | |
| 328 // Initialize the type selection at the first segment. | |
| 329 [sourceTypeControl_ setSelected:YES forSegment:0]; | |
| 330 [self typeButtonPressed:sourceTypeControl_]; | |
| 228 } | 331 } |
|
tapted
2016/06/20 12:18:35
200 lines is too much for one function - please sp
qiangchen
2016/06/21 23:31:28
Acknowledged.
| |
| 229 | 332 |
| 230 - (void)showWindow:(id)sender { | 333 - (void)showWindow:(id)sender { |
| 231 // Signal the media_list to start sending thumbnails. |bridge_| is used as the | 334 // Signal the media_list to start sending thumbnails. |bridge_| is used as the |
|
tapted
2016/06/20 12:18:36
update comment
qiangchen
2016/06/21 23:31:27
Done.
| |
| 232 // observer, and will forward notifications to this object. | 335 // observer, and will forward notifications to this object. |
| 233 media_list_->SetThumbnailSize(gfx::Size(kThumbnailWidth, kThumbnailHeight)); | 336 if (screen_list_) { |
| 234 media_list_->StartUpdating(bridge_.get()); | 337 screen_list_->SetThumbnailSize( |
| 338 gfx::Size(kSingleScreenWidth, kSingleScreenHeight)); | |
| 339 screen_list_->StartUpdating(bridge_.get()); | |
| 340 } | |
| 341 | |
| 342 if (window_list_) { | |
| 343 window_list_->SetThumbnailSize( | |
| 344 gfx::Size(kThumbnailWidth, kThumbnailHeight)); | |
| 345 window_list_->StartUpdating(bridge_.get()); | |
| 346 } | |
| 347 | |
| 348 if (tab_list_) { | |
| 349 tab_list_->SetThumbnailSize(gfx::Size(kIconWidth, kRowHeight)); | |
| 350 tab_list_->StartUpdating(bridge_.get()); | |
| 351 } | |
| 235 | 352 |
| 236 [self.window center]; | 353 [self.window center]; |
| 237 [super showWindow:sender]; | 354 [super showWindow:sender]; |
| 238 } | 355 } |
| 239 | 356 |
| 240 - (void)reportResult:(content::DesktopMediaID)sourceID { | 357 - (void)reportResult:(content::DesktopMediaID)sourceID { |
| 241 if (doneCallback_.is_null()) { | 358 if (doneCallback_.is_null()) { |
| 242 return; | 359 return; |
| 243 } | 360 } |
| 244 | 361 |
| 245 sourceID.audio_share = [audioShareCheckbox_ isEnabled] && | 362 sourceID.audio_share = ![audioShareCheckbox_ isHidden] && |
| 246 [audioShareCheckbox_ state] == NSOnState; | 363 [audioShareCheckbox_ state] == NSOnState; |
| 247 | 364 |
| 248 // If the media source is an tab, activate it. | 365 // If the media source is an tab, activate it. |
| 249 if (sourceID.type == content::DesktopMediaID::TYPE_WEB_CONTENTS) { | 366 if (sourceID.type == content::DesktopMediaID::TYPE_WEB_CONTENTS) { |
| 250 content::WebContents* tab = content::WebContents::FromRenderFrameHost( | 367 content::WebContents* tab = content::WebContents::FromRenderFrameHost( |
| 251 content::RenderFrameHost::FromID( | 368 content::RenderFrameHost::FromID( |
| 252 sourceID.web_contents_id.render_process_id, | 369 sourceID.web_contents_id.render_process_id, |
| 253 sourceID.web_contents_id.main_render_frame_id)); | 370 sourceID.web_contents_id.main_render_frame_id)); |
| 254 if (tab) | 371 if (tab) |
| 255 tab->GetDelegate()->ActivateContents(tab); | 372 tab->GetDelegate()->ActivateContents(tab); |
| 256 } | 373 } |
| 257 | 374 |
| 258 // Notify the |callback_| asynchronously because it may release the | 375 // Notify the |callback_| asynchronously because it may release the |
| 259 // controller. | 376 // controller. |
| 260 content::BrowserThread::PostTask( | 377 content::BrowserThread::PostTask( |
| 261 content::BrowserThread::UI, FROM_HERE, | 378 content::BrowserThread::UI, FROM_HERE, |
| 262 base::Bind(doneCallback_, sourceID)); | 379 base::Bind(doneCallback_, sourceID)); |
| 263 doneCallback_.Reset(); | 380 doneCallback_.Reset(); |
| 264 } | 381 } |
| 265 | 382 |
| 266 - (void)sharePressed:(id)sender { | 383 - (void)sharePressed:(id)sender { |
| 267 NSIndexSet* indexes = [sourceBrowser_ selectionIndexes]; | 384 int segment = [sourceTypeControl_ selectedSegment]; |
|
tapted
2016/06/20 12:18:35
nit: int -> NSInteger
qiangchen
2016/06/21 23:31:28
Done.
| |
| 385 content::DesktopMediaID::Type selected_type = | |
|
tapted
2016/06/20 12:18:35
selectedType
qiangchen
2016/06/21 23:31:26
Done.
| |
| 386 static_cast<content::DesktopMediaID::Type>( | |
| 387 [[sourceTypeControl_ cell] tagForSegment:segment]); | |
| 388 | |
| 389 if (selected_type == content::DesktopMediaID::TYPE_WEB_CONTENTS) { | |
| 390 NSIndexSet* indexes = [tabBrowser_ selectedRowIndexes]; | |
|
tapted
2016/06/20 12:18:34
This logic should be in a helper function which is
qiangchen
2016/06/21 23:31:27
Done.
| |
| 391 NSUInteger selectedIndex = [indexes firstIndex]; | |
| 392 DesktopMediaPickerItem* item = [tab_items_ objectAtIndex:selectedIndex]; | |
| 393 [self reportResult:[item sourceID]]; | |
| 394 [self close]; | |
| 395 return; | |
| 396 } | |
| 397 | |
| 398 NSMutableArray* items; | |
| 399 IKImageBrowserView* browser; | |
| 400 | |
| 401 if (selected_type == content::DesktopMediaID::TYPE_SCREEN) { | |
| 402 items = screen_items_; | |
| 403 browser = screenBrowser_; | |
| 404 } else { | |
| 405 items = window_items_; | |
| 406 browser = windowBrowser_; | |
| 407 } | |
| 408 NSIndexSet* indexes = [browser selectionIndexes]; | |
| 268 NSUInteger selectedIndex = [indexes firstIndex]; | 409 NSUInteger selectedIndex = [indexes firstIndex]; |
| 269 DesktopMediaPickerItem* item = | 410 DesktopMediaPickerItem* item = [items objectAtIndex:selectedIndex]; |
| 270 [items_ objectAtIndex:selectedIndex]; | |
| 271 [self reportResult:[item sourceID]]; | 411 [self reportResult:[item sourceID]]; |
| 272 [self close]; | 412 [self close]; |
| 273 } | 413 } |
| 274 | 414 |
| 275 - (void)cancelPressed:(id)sender { | 415 - (void)cancelPressed:(id)sender { |
| 276 [self reportResult:content::DesktopMediaID()]; | 416 [self reportResult:content::DesktopMediaID()]; |
| 277 [self close]; | 417 [self close]; |
| 278 } | 418 } |
| 279 | 419 |
| 420 - (void)typeButtonPressed:(id)sender { | |
| 421 int segment = [sender selectedSegment]; | |
| 422 content::DesktopMediaID::Type selected_type = | |
| 423 static_cast<content::DesktopMediaID::Type>( | |
| 424 [[sourceTypeControl_ cell] tagForSegment:segment]); | |
|
tapted
2016/06/20 12:18:34
This should be a helper function. E.g.
- (content
qiangchen
2016/06/21 23:31:27
Done.
| |
| 425 if (selected_type == content::DesktopMediaID::TYPE_SCREEN) { | |
|
tapted
2016/06/20 12:18:36
this should be a switch statement
qiangchen
2016/06/21 23:31:26
Done.
| |
| 426 [imageBrowserScroll_ setDocumentView:screenBrowser_]; | |
| 427 [screenBrowser_ reloadData]; | |
| 428 [self imageBrowserSelectionDidChange:screenBrowser_]; | |
| 429 [audioShareCheckbox_ setHidden:YES]; | |
| 430 } else if (selected_type == content::DesktopMediaID::TYPE_WINDOW) { | |
| 431 [imageBrowserScroll_ setDocumentView:windowBrowser_]; | |
| 432 [windowBrowser_ reloadData]; | |
| 433 [self imageBrowserSelectionDidChange:windowBrowser_]; | |
| 434 | |
| 435 [audioShareCheckbox_ setHidden:YES]; | |
| 436 } else { | |
| 437 [imageBrowserScroll_ setDocumentView:tabBrowser_]; | |
| 438 [tabBrowser_ reloadData]; | |
| 439 [self | |
| 440 tableViewSelectionDidChange:[NSNotification | |
| 441 notificationWithName:@"selectionChange" | |
|
tapted
2016/06/20 12:18:35
pass nil - the notification isn't used
qiangchen
2016/06/21 23:31:27
Done.
| |
| 442 object:tabBrowser_]]; | |
| 443 | |
| 444 [audioShareCheckbox_ setHidden:NO]; | |
| 445 } | |
| 446 } | |
|
tapted
2016/06/20 12:18:35
I suspect you need to do something like
[sharebut
qiangchen
2016/06/21 23:31:28
In XXXDidChange(), Share button status will be upd
| |
| 447 | |
| 448 - (void)tableDoubleClick:(id)sender { | |
|
tapted
2016/06/20 12:18:35
declare this in the private interface
qiangchen
2016/06/21 23:31:27
Done.
| |
| 449 NSIndexSet* indexes = [tabBrowser_ selectedRowIndexes]; | |
| 450 NSUInteger selectedIndex = [indexes firstIndex]; | |
| 451 DesktopMediaPickerItem* item = [tab_items_ objectAtIndex:selectedIndex]; | |
| 452 [self reportResult:[item sourceID]]; | |
| 453 [self close]; | |
| 454 } | |
| 455 | |
| 280 - (NSTextField*)createTextFieldWithText:(NSString*)text | 456 - (NSTextField*)createTextFieldWithText:(NSString*)text |
| 281 frameWidth:(CGFloat)width { | 457 frameWidth:(CGFloat)width { |
| 282 NSRect frame = NSMakeRect(0, 0, width, 1); | 458 NSRect frame = NSMakeRect(0, 0, width, 1); |
| 283 base::scoped_nsobject<NSTextField> textField( | 459 base::scoped_nsobject<NSTextField> textField( |
| 284 [[NSTextField alloc] initWithFrame:frame]); | 460 [[NSTextField alloc] initWithFrame:frame]); |
| 285 [textField setEditable:NO]; | 461 [textField setEditable:NO]; |
| 286 [textField setSelectable:YES]; | 462 [textField setSelectable:YES]; |
| 287 [textField setDrawsBackground:NO]; | 463 [textField setDrawsBackground:NO]; |
| 288 [textField setBezeled:NO]; | 464 [textField setBezeled:NO]; |
| 289 [textField setStringValue:text]; | 465 [textField setStringValue:text]; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 311 [self reportResult:content::DesktopMediaID()]; | 487 [self reportResult:content::DesktopMediaID()]; |
| 312 | 488 |
| 313 // Remove self from the parent. | 489 // Remove self from the parent. |
| 314 NSWindow* window = [self window]; | 490 NSWindow* window = [self window]; |
| 315 [[window parentWindow] removeChildWindow:window]; | 491 [[window parentWindow] removeChildWindow:window]; |
| 316 } | 492 } |
| 317 | 493 |
| 318 #pragma mark IKImageBrowserDataSource | 494 #pragma mark IKImageBrowserDataSource |
| 319 | 495 |
| 320 - (NSUInteger)numberOfItemsInImageBrowser:(IKImageBrowserView*)browser { | 496 - (NSUInteger)numberOfItemsInImageBrowser:(IKImageBrowserView*)browser { |
| 321 return [items_ count]; | 497 if (browser == screenBrowser_) |
| 498 return [screen_items_ count]; | |
| 499 else // if (browser == windowBrowser_) | |
|
tapted
2016/06/20 12:18:35
remove comment
qiangchen
2016/06/21 23:31:27
Done.
| |
| 500 return [window_items_ count]; | |
|
tapted
2016/06/20 12:18:35
no else after return
qiangchen
2016/06/21 23:31:28
Done.
| |
| 322 } | 501 } |
| 323 | 502 |
| 324 - (id)imageBrowser:(IKImageBrowserView *)browser | 503 - (id)imageBrowser:(IKImageBrowserView *)browser |
|
tapted
2016/06/20 12:18:35
remove space before * - more below
qiangchen
2016/06/21 23:31:28
Done.
| |
| 325 itemAtIndex:(NSUInteger)index { | 504 itemAtIndex:(NSUInteger)index { |
| 326 return [items_ objectAtIndex:index]; | 505 if (browser == screenBrowser_) |
|
tapted
2016/06/20 12:18:34
Looks like another good case for a helper function
qiangchen
2016/06/21 23:31:28
Done.
| |
| 506 return [screen_items_ objectAtIndex:index]; | |
| 507 else // if (browser == windowBrowser_) | |
| 508 return [window_items_ objectAtIndex:index]; | |
| 327 } | 509 } |
| 328 | 510 |
| 329 #pragma mark IKImageBrowserDelegate | 511 #pragma mark IKImageBrowserDelegate |
| 330 | 512 |
| 331 - (void)imageBrowser:(IKImageBrowserView *)browser | 513 - (void)imageBrowser:(IKImageBrowserView *)browser |
| 332 cellWasDoubleClickedAtIndex:(NSUInteger)index { | 514 cellWasDoubleClickedAtIndex:(NSUInteger)index { |
| 333 DesktopMediaPickerItem* item = [items_ objectAtIndex:index]; | 515 DesktopMediaPickerItem* item; |
| 516 if (browser == screenBrowser_) | |
| 517 item = [screen_items_ objectAtIndex:index]; | |
| 518 else // if (browser == windowBrowser_) | |
| 519 item = [window_items_ objectAtIndex:index]; | |
| 334 [self reportResult:[item sourceID]]; | 520 [self reportResult:[item sourceID]]; |
| 335 [self close]; | 521 [self close]; |
| 336 } | 522 } |
| 337 | 523 |
| 338 - (void)imageBrowserSelectionDidChange:(IKImageBrowserView*)browser { | 524 - (void)imageBrowserSelectionDidChange:(IKImageBrowserView*)browser { |
| 339 NSIndexSet* indexes = [sourceBrowser_ selectionIndexes]; | 525 int segment = [sourceTypeControl_ selectedSegment]; |
| 526 content::DesktopMediaID::Type selected_type = | |
| 527 static_cast<content::DesktopMediaID::Type>( | |
| 528 [[sourceTypeControl_ cell] tagForSegment:segment]); | |
| 529 if (selected_type != content::DesktopMediaID::TYPE_SCREEN && | |
| 530 browser == screenBrowser_) | |
| 531 return; | |
| 532 if (selected_type != content::DesktopMediaID::TYPE_WINDOW && | |
| 533 browser == windowBrowser_) | |
| 534 return; | |
| 535 NSIndexSet* indexes = [browser selectionIndexes]; | |
| 340 | 536 |
| 341 // Enable or disable the OK button based on whether we have a selection. | 537 // Enable or disable the OK button based on whether we have a selection. |
| 342 [shareButton_ setEnabled:([indexes count] > 0)]; | 538 [shareButton_ setEnabled:([indexes count] > 0)]; |
| 539 } | |
| 343 | 540 |
| 344 // Enable or disable the checkbox based on whether we can support audio for | 541 #pragma mark NSTableViewDataSource |
| 345 // the selected source. | 542 - (NSInteger)numberOfRowsInTableView:(NSTableView*)table { |
| 346 // On Mac, the checkbox will enabled for tab sharing, namely | 543 return [tab_items_ count]; |
| 347 // TYPE_WEB_CONTENTS. | 544 } |
| 348 if ([indexes count] == 0) { | 545 |
| 349 if ([audioShareCheckbox_ isEnabled]) { | 546 #pragma mark NSTableViewDelegate |
| 350 [audioShareCheckbox_ setEnabled:NO]; | 547 - (NSView*)tableView:(NSTableView*)table |
| 351 audioShareState_ = [audioShareCheckbox_ state]; | 548 viewForTableColumn:(NSTableColumn*)column |
| 352 [audioShareCheckbox_ setState:NSOffState]; | 549 row:(NSInteger)rowIndex { |
| 550 if ([[column identifier] isEqualToString:@"icon"]) { | |
| 551 NSImage* image = [[tab_items_ objectAtIndex:rowIndex] imageRepresentation]; | |
| 552 NSImageView* cell = [table makeViewWithIdentifier:@"icon" owner:self]; | |
| 553 if (cell == nil) { | |
|
tapted
2016/06/20 12:18:35
nit: !cell. more below
qiangchen
2016/06/21 23:31:27
Done.
| |
| 554 cell = [[NSImageView alloc] | |
|
tapted
2016/06/20 12:18:35
this is leaked
qiangchen
2016/06/21 23:31:28
Used scoped_nsobject now.
But I found I have to r
tapted
2016/06/22 07:08:41
see comment on the latest patchset
qiangchen
2016/06/22 23:54:23
Acknowledged.
| |
| 555 initWithFrame:NSMakeRect(0, 0, kIconWidth, kRowWidth)]; | |
| 556 cell.identifier = @"icon"; | |
|
tapted
2016/06/20 12:18:34
don't use dot notation
qiangchen
2016/06/21 23:31:27
Done.
| |
| 353 } | 557 } |
| 354 [audioShareCheckbox_ | 558 [cell setImage:image]; |
| 355 setToolTip:l10n_util::GetNSString( | 559 return cell; |
| 356 IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE_TOOLTIP_MAC)]; | |
| 357 return; | |
| 358 } | 560 } |
| 359 | 561 |
| 360 NSUInteger selectedIndex = [indexes firstIndex]; | 562 NSString* string = [[tab_items_ objectAtIndex:rowIndex] imageTitle]; |
| 361 DesktopMediaPickerItem* item = [items_ objectAtIndex:selectedIndex]; | 563 |
| 362 switch ([item sourceID].type) { | 564 NSTextField* cell = [table makeViewWithIdentifier:@"title" owner:self]; |
| 363 case content::DesktopMediaID::TYPE_SCREEN: | 565 if (cell == nil) { |
| 364 case content::DesktopMediaID::TYPE_WINDOW: | 566 cell = |
| 365 if ([audioShareCheckbox_ isEnabled]) { | 567 [self createTextFieldWithText:string frameWidth:kMinimumContentWidth]; |
| 366 [audioShareCheckbox_ setEnabled:NO]; | 568 cell.identifier = @"title"; |
| 367 audioShareState_ = [audioShareCheckbox_ state]; | 569 } else { |
| 368 [audioShareCheckbox_ setState:NSOffState]; | 570 [cell setStringValue:string]; |
| 369 } | |
| 370 [audioShareCheckbox_ | |
| 371 setToolTip:l10n_util::GetNSString( | |
| 372 IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE_TOOLTIP_MAC)]; | |
| 373 break; | |
| 374 case content::DesktopMediaID::TYPE_WEB_CONTENTS: | |
| 375 if (![audioShareCheckbox_ isEnabled]) { | |
| 376 [audioShareCheckbox_ setEnabled:YES]; | |
| 377 [audioShareCheckbox_ setState:audioShareState_]; | |
| 378 } | |
| 379 [audioShareCheckbox_ setToolTip:@""]; | |
| 380 break; | |
| 381 case content::DesktopMediaID::TYPE_NONE: | |
| 382 NOTREACHED(); | |
| 383 } | 571 } |
| 572 return cell; | |
| 573 } | |
| 574 | |
| 575 - (void)tableViewSelectionDidChange:(NSNotification*)notification { | |
| 576 int segment = [sourceTypeControl_ selectedSegment]; | |
| 577 if ([[sourceTypeControl_ cell] tagForSegment:segment] != | |
|
tapted
2016/06/20 12:18:35
can this happen? DCHECK?
qiangchen
2016/06/21 23:31:28
Done.
| |
| 578 content::DesktopMediaID::TYPE_WEB_CONTENTS) | |
| 579 return; | |
| 580 NSIndexSet* indexes = [tabBrowser_ selectedRowIndexes]; | |
| 581 | |
| 582 // Enable or disable the OK button based on whether we have a selection. | |
| 583 [shareButton_ setEnabled:([indexes count] > 0)]; | |
| 584 if ([indexes count] == 0) | |
|
tapted
2016/06/20 12:18:35
remove
qiangchen
2016/06/21 23:31:27
Done.
| |
| 585 return; | |
| 384 } | 586 } |
| 385 | 587 |
| 386 #pragma mark DesktopMediaPickerObserver | 588 #pragma mark DesktopMediaPickerObserver |
| 387 | 589 |
| 388 - (void)sourceAddedAtIndex:(int)index { | 590 - (void)sourceAddedForList:(DesktopMediaList*)list AtIndex:(int)index { |
| 389 const DesktopMediaList::Source& source = media_list_->GetSource(index); | 591 NSMutableArray* items; |
| 592 id browser; | |
| 593 | |
| 594 if (list == screen_list_.get()) { | |
|
tapted
2016/06/20 12:18:34
this should be a helper function e.g.
id browserF
qiangchen
2016/06/21 23:31:27
Done.
| |
| 595 items = screen_items_; | |
| 596 browser = screenBrowser_; | |
| 597 } else if (list == window_list_.get()) { | |
| 598 items = window_items_; | |
| 599 browser = windowBrowser_; | |
| 600 } else { | |
| 601 items = tab_items_; | |
| 602 browser = tabBrowser_; | |
| 603 } | |
| 604 | |
| 605 const DesktopMediaList::Source& source = list->GetSource(index); | |
| 390 NSString* imageTitle = base::SysUTF16ToNSString(source.name); | 606 NSString* imageTitle = base::SysUTF16ToNSString(source.name); |
| 391 base::scoped_nsobject<DesktopMediaPickerItem> item( | 607 base::scoped_nsobject<DesktopMediaPickerItem> item( |
| 392 [[DesktopMediaPickerItem alloc] initWithSourceId:source.id | 608 [[DesktopMediaPickerItem alloc] initWithSourceId:source.id |
| 393 imageUID:++lastImageUID_ | 609 imageUID:++lastImageUID_ |
| 394 imageTitle:imageTitle]); | 610 imageTitle:imageTitle]); |
| 395 [items_ insertObject:item atIndex:index]; | 611 [items insertObject:item atIndex:index]; |
| 396 [sourceBrowser_ reloadData]; | 612 [browser reloadData]; |
| 397 | 613 |
| 398 NSString* autoselectSource = base::SysUTF8ToNSString( | 614 NSString* autoselectSource = base::SysUTF8ToNSString( |
| 399 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 615 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 400 switches::kAutoSelectDesktopCaptureSource)); | 616 switches::kAutoSelectDesktopCaptureSource)); |
| 401 | 617 |
| 402 if ([autoselectSource isEqualToString:imageTitle]) { | 618 if ([autoselectSource isEqualToString:imageTitle]) { |
| 403 [self reportResult:[item sourceID]]; | 619 [self reportResult:[item sourceID]]; |
| 404 [self close]; | 620 [self close]; |
| 405 } | 621 } |
| 406 } | 622 } |
| 407 | 623 |
| 408 - (void)sourceRemovedAtIndex:(int)index { | 624 - (void)sourceRemovedForList:(DesktopMediaList*)list AtIndex:(int)index { |
| 409 if ([[sourceBrowser_ selectionIndexes] containsIndex:index]) { | 625 NSMutableArray* items; |
| 626 IKImageBrowserView* browser; | |
| 627 | |
| 628 if (list == tab_list_.get()) { | |
| 629 [tab_items_ removeObjectAtIndex:index]; | |
| 630 [tabBrowser_ reloadData]; | |
| 631 return; | |
| 632 } | |
| 633 | |
| 634 if (list == screen_list_.get()) { | |
| 635 items = screen_items_; | |
| 636 browser = screenBrowser_.get(); | |
| 637 } else { // if (list == window_list_.get()) | |
|
tapted
2016/06/20 12:18:35
remove comment
qiangchen
2016/06/21 23:31:27
Done.
| |
| 638 items = window_items_; | |
| 639 browser = windowBrowser_.get(); | |
| 640 } | |
| 641 if ([[browser selectionIndexes] containsIndex:index]) { | |
| 410 // Selected item was removed. Clear selection. | 642 // Selected item was removed. Clear selection. |
| 411 [sourceBrowser_ setSelectionIndexes:[NSIndexSet indexSet] | 643 [browser setSelectionIndexes:[NSIndexSet indexSet] |
| 412 byExtendingSelection:FALSE]; | 644 byExtendingSelection:FALSE]; |
|
tapted
2016/06/20 12:18:34
FALSE -> NO
qiangchen
2016/06/21 23:31:28
Done.
| |
| 413 } | 645 } |
| 414 [items_ removeObjectAtIndex:index]; | 646 [items removeObjectAtIndex:index]; |
| 415 [sourceBrowser_ reloadData]; | 647 [browser reloadData]; |
| 416 } | 648 } |
| 417 | 649 |
| 418 - (void)sourceMovedFrom:(int)oldIndex to:(int)newIndex { | 650 - (void)sourceMovedForList:(DesktopMediaList*)list |
| 651 From:(int)oldIndex | |
| 652 to:(int)newIndex { | |
| 653 NSMutableArray* items; | |
| 654 id browser; | |
| 655 | |
| 656 if (list == screen_list_.get()) { | |
| 657 items = screen_items_; | |
| 658 browser = screenBrowser_; | |
| 659 } else if (list == window_list_.get()) { | |
| 660 items = window_items_; | |
| 661 browser = windowBrowser_; | |
| 662 } else { | |
| 663 items = tab_items_; | |
| 664 browser = tabBrowser_; | |
| 665 } | |
| 666 | |
| 419 base::scoped_nsobject<DesktopMediaPickerItem> item( | 667 base::scoped_nsobject<DesktopMediaPickerItem> item( |
| 420 [[items_ objectAtIndex:oldIndex] retain]); | 668 [[items objectAtIndex:oldIndex] retain]); |
| 421 [items_ removeObjectAtIndex:oldIndex]; | 669 [items removeObjectAtIndex:oldIndex]; |
| 422 [items_ insertObject:item atIndex:newIndex]; | 670 [items insertObject:item atIndex:newIndex]; |
| 423 [sourceBrowser_ reloadData]; | 671 [browser reloadData]; |
| 424 } | 672 } |
| 425 | 673 |
| 426 - (void)sourceNameChangedAtIndex:(int)index { | 674 - (void)sourceNameChangedForList:(DesktopMediaList*)list AtIndex:(int)index { |
| 427 DesktopMediaPickerItem* item = [items_ objectAtIndex:index]; | 675 NSMutableArray* items; |
| 428 const DesktopMediaList::Source& source = media_list_->GetSource(index); | 676 id browser; |
| 677 | |
| 678 if (list == screen_list_.get()) { | |
| 679 items = screen_items_; | |
| 680 browser = screenBrowser_; | |
| 681 } else if (list == window_list_.get()) { | |
| 682 items = window_items_; | |
| 683 browser = windowBrowser_; | |
| 684 } else { | |
| 685 items = tab_items_; | |
| 686 browser = tabBrowser_; | |
| 687 } | |
| 688 | |
| 689 DesktopMediaPickerItem* item = [items objectAtIndex:index]; | |
| 690 const DesktopMediaList::Source& source = list->GetSource(index); | |
| 429 [item setImageTitle:base::SysUTF16ToNSString(source.name)]; | 691 [item setImageTitle:base::SysUTF16ToNSString(source.name)]; |
| 430 [sourceBrowser_ reloadData]; | 692 [browser reloadData]; |
| 431 } | 693 } |
| 432 | 694 |
| 433 - (void)sourceThumbnailChangedAtIndex:(int)index { | 695 - (void)sourceThumbnailChangedForList:(DesktopMediaList*)list |
| 434 const DesktopMediaList::Source& source = media_list_->GetSource(index); | 696 AtIndex:(int)index { |
| 697 NSMutableArray* items; | |
| 698 id browser; | |
| 699 | |
| 700 if (list == screen_list_.get()) { | |
| 701 items = screen_items_; | |
| 702 browser = screenBrowser_; | |
| 703 } else if (list == window_list_.get()) { | |
| 704 items = window_items_; | |
| 705 browser = windowBrowser_; | |
| 706 } else { | |
| 707 items = tab_items_; | |
| 708 browser = tabBrowser_; | |
| 709 } | |
| 710 | |
| 711 const DesktopMediaList::Source& source = list->GetSource(index); | |
| 435 NSImage* image = gfx::NSImageFromImageSkia(source.thumbnail); | 712 NSImage* image = gfx::NSImageFromImageSkia(source.thumbnail); |
| 436 | 713 |
| 437 DesktopMediaPickerItem* item = [items_ objectAtIndex:index]; | 714 DesktopMediaPickerItem* item = [items objectAtIndex:index]; |
| 438 [item setImageRepresentation:image]; | 715 [item setImageRepresentation:image]; |
| 439 [sourceBrowser_ reloadData]; | 716 [browser reloadData]; |
| 440 } | 717 } |
| 441 | 718 |
| 442 @end // @interface DesktopMediaPickerController | 719 @end // @interface DesktopMediaPickerController |
| OLD | NEW |