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

Side by Side Diff: chrome/browser/ui/views/desktop_capture/desktop_media_picker_views.cc

Issue 1932413002: Desktop Capture Picker New UI: Non Mac Structure Change (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Flag Created 4 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
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 #include "chrome/browser/ui/views/desktop_media_picker_views.h" 5 #include "chrome/browser/ui/views/desktop_capture/desktop_media_picker_views.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "chrome/browser/media/combined_desktop_media_list.h" 14 #include "chrome/browser/media/combined_desktop_media_list.h"
15 #include "chrome/browser/media/desktop_media_list.h" 15 #include "chrome/browser/media/desktop_media_list.h"
16 #include "chrome/browser/ui/ash/ash_util.h" 16 #include "chrome/browser/ui/ash/ash_util.h"
17 #include "chrome/browser/ui/views/desktop_media_picker_views.h"
17 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
19 #include "chrome/grit/chromium_strings.h"
18 #include "chrome/grit/generated_resources.h" 20 #include "chrome/grit/generated_resources.h"
21 #include "chrome/grit/google_chrome_strings.h"
19 #include "components/constrained_window/constrained_window_views.h" 22 #include "components/constrained_window/constrained_window_views.h"
20 #include "components/web_modal/web_contents_modal_dialog_manager.h" 23 #include "components/web_modal/web_contents_modal_dialog_manager.h"
21 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/render_frame_host.h" 25 #include "content/public/browser/render_frame_host.h"
23 #include "content/public/browser/web_contents_delegate.h" 26 #include "content/public/browser/web_contents_delegate.h"
27 #include "extensions/common/switches.h"
24 #include "grit/components_strings.h" 28 #include "grit/components_strings.h"
25 #include "ui/aura/window_tree_host.h" 29 #include "ui/aura/window_tree_host.h"
26 #include "ui/base/l10n/l10n_util.h" 30 #include "ui/base/l10n/l10n_util.h"
27 #include "ui/events/event_constants.h" 31 #include "ui/events/event_constants.h"
28 #include "ui/events/keycodes/keyboard_codes.h" 32 #include "ui/events/keycodes/keyboard_codes.h"
29 #include "ui/gfx/canvas.h" 33 #include "ui/gfx/canvas.h"
30 #include "ui/native_theme/native_theme.h" 34 #include "ui/native_theme/native_theme.h"
31 #include "ui/views/background.h" 35 #include "ui/views/background.h"
32 #include "ui/views/bubble/bubble_frame_view.h" 36 #include "ui/views/bubble/bubble_frame_view.h"
33 #include "ui/views/controls/button/checkbox.h" 37 #include "ui/views/controls/button/checkbox.h"
38 #include "ui/views/controls/button/label_button.h"
39 #include "ui/views/controls/button/label_button_border.h"
34 #include "ui/views/controls/image_view.h" 40 #include "ui/views/controls/image_view.h"
35 #include "ui/views/controls/label.h" 41 #include "ui/views/controls/label.h"
36 #include "ui/views/controls/scroll_view.h" 42 #include "ui/views/controls/scroll_view.h"
43 #include "ui/views/controls/tabbed_pane/tabbed_pane.h"
37 #include "ui/views/layout/box_layout.h" 44 #include "ui/views/layout/box_layout.h"
38 #include "ui/views/layout/layout_constants.h" 45 #include "ui/views/layout/layout_constants.h"
39 #include "ui/views/widget/widget.h" 46 #include "ui/views/widget/widget.h"
40 #include "ui/views/window/dialog_client_view.h" 47 #include "ui/views/window/dialog_client_view.h"
41 #include "ui/wm/core/shadow_types.h" 48 #include "ui/wm/core/shadow_types.h"
42 49
43 using content::DesktopMediaID; 50 using content::DesktopMediaID;
44 51
45 namespace { 52 namespace {
46 53
(...skipping 20 matching lines...) Expand all
67 return static_cast<DesktopMediaID::Id>(accelerated_widget); 74 return static_cast<DesktopMediaID::Id>(accelerated_widget);
68 #endif 75 #endif
69 } 76 }
70 77
71 int GetMediaListViewHeightForRows(size_t rows) { 78 int GetMediaListViewHeightForRows(size_t rows) {
72 return kListItemHeight * rows; 79 return kListItemHeight * rows;
73 } 80 }
74 81
75 } // namespace 82 } // namespace
76 83
77 DesktopMediaSourceView::DesktopMediaSourceView( 84 DesktopMediaSourceView::DesktopMediaSourceView(DesktopMediaListView* parent,
78 DesktopMediaListView* parent, 85 DesktopMediaID source_id)
79 DesktopMediaID source_id)
80 : parent_(parent), 86 : parent_(parent),
81 source_id_(source_id), 87 source_id_(source_id),
82 image_view_(new views::ImageView()), 88 image_view_(new views::ImageView()),
83 label_(new views::Label()), 89 label_(new views::Label()),
84 selected_(false) { 90 selected_(false) {
85 AddChildView(image_view_); 91 AddChildView(image_view_);
86 AddChildView(label_); 92 AddChildView(label_);
87 SetFocusable(true); 93 SetFocusable(true);
88 } 94 }
89 95
90 DesktopMediaSourceView::~DesktopMediaSourceView() {} 96 DesktopMediaSourceView::~DesktopMediaSourceView() {}
91 97
92 void DesktopMediaSourceView::SetName(const base::string16& name) { 98 void DesktopMediaSourceView::SetName(const base::string16& name) {
93 label_->SetText(name); 99 label_->SetText(name);
94 } 100 }
(...skipping 30 matching lines...) Expand all
125 } 131 }
126 132
127 SchedulePaint(); 133 SchedulePaint();
128 } 134 }
129 135
130 const char* DesktopMediaSourceView::GetClassName() const { 136 const char* DesktopMediaSourceView::GetClassName() const {
131 return kDesktopMediaSourceViewClassName; 137 return kDesktopMediaSourceViewClassName;
132 } 138 }
133 139
134 void DesktopMediaSourceView::Layout() { 140 void DesktopMediaSourceView::Layout() {
135 image_view_->SetBounds(kThumbnailMargin, kThumbnailMargin, 141 image_view_->SetBounds(kThumbnailMargin, kThumbnailMargin, kThumbnailWidth,
136 kThumbnailWidth, kThumbnailHeight); 142 kThumbnailHeight);
137 label_->SetBounds(kThumbnailMargin, kThumbnailHeight + kThumbnailMargin, 143 label_->SetBounds(kThumbnailMargin, kThumbnailHeight + kThumbnailMargin,
138 kThumbnailWidth, kLabelHeight); 144 kThumbnailWidth, kLabelHeight);
139 } 145 }
140 146
141 views::View* DesktopMediaSourceView::GetSelectedViewForGroup(int group) { 147 views::View* DesktopMediaSourceView::GetSelectedViewForGroup(int group) {
142 Views neighbours; 148 Views neighbours;
143 parent()->GetViewsInGroup(group, &neighbours); 149 parent()->GetViewsInGroup(group, &neighbours);
144 if (neighbours.empty()) 150 if (neighbours.empty())
145 return NULL; 151 return NULL;
146 152
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 static_cast<DesktopMediaSourceView*>(child_at(i)); 243 static_cast<DesktopMediaSourceView*>(child_at(i));
238 DCHECK_EQ(source_view->GetClassName(), kDesktopMediaSourceViewClassName); 244 DCHECK_EQ(source_view->GetClassName(), kDesktopMediaSourceViewClassName);
239 if (source_view->is_selected()) 245 if (source_view->is_selected())
240 return source_view; 246 return source_view;
241 } 247 }
242 return NULL; 248 return NULL;
243 } 249 }
244 250
245 gfx::Size DesktopMediaListView::GetPreferredSize() const { 251 gfx::Size DesktopMediaListView::GetPreferredSize() const {
246 int total_rows = (child_count() + kListColumns - 1) / kListColumns; 252 int total_rows = (child_count() + kListColumns - 1) / kListColumns;
247 return gfx::Size(kTotalListWidth, GetMediaListViewHeightForRows(total_rows)); 253 return gfx::Size(kTotalListWidth + views::kPanelHorizMargin * 4,
254 GetMediaListViewHeightForRows(total_rows));
248 } 255 }
249 256
250 void DesktopMediaListView::Layout() { 257 void DesktopMediaListView::Layout() {
251 int x = 0; 258 int x = views::kPanelHorizMargin * 2;
252 int y = 0; 259 int y = 0;
253 260
254 for (int i = 0; i < child_count(); ++i) { 261 for (int i = 0; i < child_count(); ++i) {
255 if (x + kListItemWidth > kTotalListWidth) { 262 if (x + kListItemWidth > kTotalListWidth + views::kPanelHorizMargin * 2) {
256 x = 0; 263 x = views::kPanelHorizMargin * 2;
257 y += kListItemHeight; 264 y += kListItemHeight;
258 } 265 }
259 266
260 View* source_view = child_at(i); 267 View* source_view = child_at(i);
261 source_view->SetBounds(x, y, kListItemWidth, kListItemHeight); 268 source_view->SetBounds(x, y, kListItemWidth, kListItemHeight);
262 269
263 x += kListItemWidth; 270 x += kListItemWidth;
264 } 271 }
265 272
266 y += kListItemHeight; 273 y += kListItemHeight;
267 SetSize(gfx::Size(kTotalListWidth, y)); 274 SetSize(gfx::Size(kTotalListWidth + views::kPanelHorizMargin * 2, y));
268 } 275 }
269 276
270 bool DesktopMediaListView::OnKeyPressed(const ui::KeyEvent& event) { 277 bool DesktopMediaListView::OnKeyPressed(const ui::KeyEvent& event) {
271 int position_increment = 0; 278 int position_increment = 0;
272 switch (event.key_code()) { 279 switch (event.key_code()) {
273 case ui::VKEY_UP: 280 case ui::VKEY_UP:
274 position_increment = -kListColumns; 281 position_increment = -kListColumns;
275 break; 282 break;
276 case ui::VKEY_DOWN: 283 case ui::VKEY_DOWN:
277 position_increment = kListColumns; 284 position_increment = kListColumns;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 new DesktopMediaSourceView(this, source.id); 328 new DesktopMediaSourceView(this, source.id);
322 source_view->SetName(source.name); 329 source_view->SetName(source.name);
323 source_view->SetGroup(kDesktopMediaSourceViewGroupId); 330 source_view->SetGroup(kDesktopMediaSourceViewGroupId);
324 AddChildViewAt(source_view, index); 331 AddChildViewAt(source_view, index);
325 332
326 PreferredSizeChanged(); 333 PreferredSizeChanged();
327 334
328 if (child_count() % kListColumns == 1) 335 if (child_count() % kListColumns == 1)
329 parent_->OnMediaListRowsChanged(); 336 parent_->OnMediaListRowsChanged();
330 337
338 // Auto select the first screen.
339 if (index == 0 && source.id.type == DesktopMediaID::TYPE_SCREEN) {
340 source_view->OnFocus();
341 }
342
331 std::string autoselect_source = 343 std::string autoselect_source =
332 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 344 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
333 switches::kAutoSelectDesktopCaptureSource); 345 switches::kAutoSelectDesktopCaptureSource);
334 if (!autoselect_source.empty() && 346 if (!autoselect_source.empty() &&
335 base::ASCIIToUTF16(autoselect_source) == source.name) { 347 base::ASCIIToUTF16(autoselect_source) == source.name) {
336 // Select, then accept and close the dialog when we're done adding sources. 348 // Select, then accept and close the dialog when we're done adding sources.
337 source_view->OnFocus(); 349 source_view->OnFocus();
338 content::BrowserThread::PostTask( 350 content::BrowserThread::PostTask(
339 content::BrowserThread::UI, FROM_HERE, 351 content::BrowserThread::UI, FROM_HERE,
340 base::Bind(&DesktopMediaListView::AcceptSelection, 352 base::Bind(&DesktopMediaListView::AcceptSelection,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 const base::string16& app_name, 409 const base::string16& app_name,
398 const base::string16& target_name, 410 const base::string16& target_name,
399 std::unique_ptr<DesktopMediaList> screen_list, 411 std::unique_ptr<DesktopMediaList> screen_list,
400 std::unique_ptr<DesktopMediaList> window_list, 412 std::unique_ptr<DesktopMediaList> window_list,
401 std::unique_ptr<DesktopMediaList> tab_list, 413 std::unique_ptr<DesktopMediaList> tab_list,
402 bool request_audio) 414 bool request_audio)
403 : parent_(parent), 415 : parent_(parent),
404 app_name_(app_name), 416 app_name_(app_name),
405 description_label_(new views::Label()), 417 description_label_(new views::Label()),
406 audio_share_checkbox_(nullptr), 418 audio_share_checkbox_(nullptr),
407 audio_share_checked_(true), 419 pane_(new views::TabbedPane()) {
408 sources_scroll_view_(views::ScrollView::CreateScrollViewWithBorder()) { 420 if (screen_list) {
409 std::vector<std::unique_ptr<DesktopMediaList>> media_lists; 421 source_types_.push_back(DesktopMediaID::TYPE_SCREEN);
410 if (screen_list) 422 scroll_views_.push_back(views::ScrollView::CreateScrollViewWithBorder());
411 media_lists.push_back(std::move(screen_list)); 423 list_views_.push_back(
412 if (window_list) 424 new DesktopMediaListView(this, std::move(screen_list)));
413 media_lists.push_back(std::move(window_list));
414 if (tab_list)
415 media_lists.push_back(std::move(tab_list));
416 425
417 std::unique_ptr<DesktopMediaList> media_list; 426 pane_->AddTab(
418 if (media_lists.size() > 1) 427 l10n_util::GetStringUTF16(IDS_DESKTOP_MEDIA_PICKER_SOURCE_TYPE_SCREEN),
419 media_list.reset(new CombinedDesktopMediaList(media_lists)); 428 scroll_views_.back());
420 else 429 pane_->set_listener(this);
421 media_list = std::move(media_lists[0]); 430 }
422 431
423 DCHECK(media_list != nullptr); 432 if (window_list) {
424 sources_list_view_ = new DesktopMediaListView(this, std::move(media_list)); 433 source_types_.push_back(DesktopMediaID::TYPE_WINDOW);
434 scroll_views_.push_back(views::ScrollView::CreateScrollViewWithBorder());
435 list_views_.push_back(
436 new DesktopMediaListView(this, std::move(window_list)));
425 437
426 // TODO(estade): we should be getting the inside-border spacing by default as 438 pane_->AddTab(
427 // a DialogDelegateView subclass, via default BubbleFrameView content margins. 439 l10n_util::GetStringUTF16(IDS_DESKTOP_MEDIA_PICKER_SOURCE_TYPE_WINDOW),
428 SetLayoutManager(new views::BoxLayout( 440 scroll_views_.back());
429 views::BoxLayout::kVertical, views::kButtonHEdgeMarginNew, 441 pane_->set_listener(this);
430 views::kPanelVertMargin, views::kLabelToControlVerticalSpacing)); 442 }
443
444 if (tab_list) {
445 source_types_.push_back(DesktopMediaID::TYPE_WEB_CONTENTS);
446 scroll_views_.push_back(views::ScrollView::CreateScrollViewWithBorder());
447 list_views_.push_back(new DesktopMediaListView(this, std::move(tab_list)));
448
449 pane_->AddTab(
450 l10n_util::GetStringUTF16(IDS_DESKTOP_MEDIA_PICKER_SOURCE_TYPE_TAB),
451 scroll_views_.back());
452 pane_->set_listener(this);
453 }
431 454
432 if (app_name == target_name) { 455 if (app_name == target_name) {
433 description_label_->SetText( 456 description_label_->SetText(
434 l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TEXT, app_name)); 457 l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TEXT, app_name));
435 } else { 458 } else {
436 description_label_->SetText(l10n_util::GetStringFUTF16( 459 description_label_->SetText(l10n_util::GetStringFUTF16(
437 IDS_DESKTOP_MEDIA_PICKER_TEXT_DELEGATED, app_name, target_name)); 460 IDS_DESKTOP_MEDIA_PICKER_TEXT_DELEGATED, app_name, target_name));
438 } 461 }
439 description_label_->SetMultiLine(true); 462 description_label_->SetMultiLine(true);
440 description_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 463 description_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
441 AddChildView(description_label_); 464 AddChildView(description_label_);
442 465
443 sources_scroll_view_->SetContents(sources_list_view_); 466 for (size_t i = 0; i < source_types_.size(); i++) {
444 sources_scroll_view_->ClipHeightTo(GetMediaListViewHeightForRows(1), 467 scroll_views_[i]->SetContents(list_views_[i]);
445 GetMediaListViewHeightForRows(2)); 468 scroll_views_[i]->ClipHeightTo(GetMediaListViewHeightForRows(1),
446 AddChildView(sources_scroll_view_); 469 GetMediaListViewHeightForRows(2));
470 }
471 AddChildView(pane_);
447 472
448 if (request_audio) { 473 if (request_audio) {
449 audio_share_checkbox_ = new views::Checkbox( 474 audio_share_checkbox_ = new views::Checkbox(
450 l10n_util::GetStringUTF16(IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE)); 475 l10n_util::GetStringUTF16(IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE));
476 audio_share_checkbox_->SetChecked(true);
451 AddChildView(audio_share_checkbox_); 477 AddChildView(audio_share_checkbox_);
452 audio_share_checkbox_->SetEnabled(false);
453 audio_share_checkbox_->SetTooltipText(l10n_util::GetStringUTF16(
454 IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE_TOOLTIP_NONE));
455 } 478 }
456 479
480 // Focus on the first non-null media_list
481 SwitchSourceType(0);
482
457 // If |parent_web_contents| is set and it's not a background page then the 483 // If |parent_web_contents| is set and it's not a background page then the
458 // picker will be shown modal to the web contents. Otherwise the picker is 484 // picker will be shown modal to the web contents. Otherwise the picker is
459 // shown in a separate window. 485 // shown in a separate window.
460 views::Widget* widget = NULL; 486 views::Widget* widget = NULL;
461 bool modal_dialog = 487 bool modal_dialog =
462 parent_web_contents && 488 parent_web_contents &&
463 !parent_web_contents->GetDelegate()->IsNeverVisible(parent_web_contents); 489 !parent_web_contents->GetDelegate()->IsNeverVisible(parent_web_contents);
464 if (modal_dialog) { 490 if (modal_dialog) {
465 widget = constrained_window::ShowWebModalDialogViews(this, 491 widget =
466 parent_web_contents); 492 constrained_window::ShowWebModalDialogViews(this, parent_web_contents);
467 } else { 493 } else {
468 widget = DialogDelegate::CreateDialogWidget(this, context, NULL); 494 widget = DialogDelegate::CreateDialogWidget(this, context, NULL);
469 widget->Show(); 495 widget->Show();
470 } 496 }
471 497
472 // If the picker is not modal to the calling web contents then it is displayed 498 // If the picker is not modal to the calling web contents then it is displayed
473 // in its own top-level window, so in that case it needs to be filtered out of 499 // in its own top-level window, so in that case it needs to be filtered out of
474 // the list of top-level windows available for capture, and to achieve that 500 // the list of top-level windows available for capture, and to achieve that
475 // the Id is passed to DesktopMediaList. 501 // the Id is passed to DesktopMediaList.
476 DesktopMediaID dialog_window_id; 502 DesktopMediaID dialog_window_id;
477 if (!modal_dialog) { 503 if (!modal_dialog) {
478 dialog_window_id = DesktopMediaID::RegisterAuraWindow( 504 dialog_window_id = DesktopMediaID::RegisterAuraWindow(
479 DesktopMediaID::TYPE_WINDOW, widget->GetNativeWindow()); 505 DesktopMediaID::TYPE_WINDOW, widget->GetNativeWindow());
480 506
481 bool is_ash_window = false; 507 bool is_ash_window = false;
482 #if defined(USE_ASH) 508 #if defined(USE_ASH)
483 is_ash_window = chrome::IsNativeWindowInAsh(widget->GetNativeWindow()); 509 is_ash_window = chrome::IsNativeWindowInAsh(widget->GetNativeWindow());
484 #endif 510 #endif
485 511
486 // Set native window ID if the windows is outside Ash. 512 // Set native window ID if the windows is outside Ash.
487 if (!is_ash_window) { 513 if (!is_ash_window) {
488 dialog_window_id.id = AcceleratedWidgetToDesktopMediaId( 514 dialog_window_id.id = AcceleratedWidgetToDesktopMediaId(
489 widget->GetNativeWindow()->GetHost()->GetAcceleratedWidget()); 515 widget->GetNativeWindow()->GetHost()->GetAcceleratedWidget());
490 } 516 }
491 } 517 }
492 518
493 sources_list_view_->StartUpdating(dialog_window_id); 519 for (auto& list_view : list_views_) {
520 list_view->StartUpdating(dialog_window_id);
521 }
494 } 522 }
495 523
496 DesktopMediaPickerDialogView::~DesktopMediaPickerDialogView() {} 524 DesktopMediaPickerDialogView::~DesktopMediaPickerDialogView() {}
497 525
526 void DesktopMediaPickerDialogView::TabSelectedAt(int index) {
527 SwitchSourceType(index);
528 GetDialogClientView()->UpdateDialogButtons();
529 }
530
531 void DesktopMediaPickerDialogView::SwitchSourceType(int index) {
532 // Set whether the checkbox is visible based on the source type
533 if (audio_share_checkbox_) {
534 switch (source_types_[index]) {
535 case DesktopMediaID::TYPE_SCREEN:
536 #if defined(USE_CRAS) || defined(OS_WIN)
537 audio_share_checkbox_->SetVisible(true);
538 #else
539 audio_share_checkbox_->SetVisible(false);
540 #endif
541 break;
542 case DesktopMediaID::TYPE_WINDOW:
543 audio_share_checkbox_->SetVisible(false);
544 break;
545 case DesktopMediaID::TYPE_WEB_CONTENTS:
546 audio_share_checkbox_->SetVisible(true);
547 break;
548 case DesktopMediaID::TYPE_NONE:
549 NOTREACHED();
550 break;
551 }
552 }
553 }
554
498 void DesktopMediaPickerDialogView::DetachParent() { 555 void DesktopMediaPickerDialogView::DetachParent() {
499 parent_ = NULL; 556 parent_ = NULL;
500 } 557 }
501 558
502 gfx::Size DesktopMediaPickerDialogView::GetPreferredSize() const { 559 gfx::Size DesktopMediaPickerDialogView::GetPreferredSize() const {
503 static const size_t kDialogViewWidth = 600; 560 static const size_t kDialogViewWidth = 600;
504 return gfx::Size(kDialogViewWidth, GetHeightForWidth(kDialogViewWidth)); 561 const size_t kInnerWidth = kDialogViewWidth - views::kPanelHorizMargin * 4;
562
563 int related_spacing_num = 0;
564 int unrelated_spacing_num = 0;
565
566 size_t label_height = description_label_->GetHeightForWidth(kInnerWidth);
567 unrelated_spacing_num++;
568
569 size_t checkbox_height = 0;
570 if (audio_share_checkbox_) {
571 checkbox_height = audio_share_checkbox_->GetHeightForWidth(kInnerWidth);
572 related_spacing_num++;
573 }
574
575 size_t pane_height = pane_->GetHeightForWidth(kInnerWidth);
576 related_spacing_num++;
577
578 return gfx::Size(
579 kDialogViewWidth,
580 views::kPanelVertMargin * 2 + label_height + checkbox_height +
581 pane_height +
582 views::kRelatedControlVerticalSpacing * related_spacing_num +
583 views::kUnrelatedControlVerticalSpacing * unrelated_spacing_num);
584 }
585
586 void DesktopMediaPickerDialogView::Layout() {
587 // DialogDelegate uses the bubble style frame.
588 gfx::Rect rect = GetLocalBounds();
589
590 // |left|, |top|, |right|, |bottom| describes the available area.
591 rect.Inset(views::kPanelHorizMargin * 2, views::kPanelVertMargin);
592 int left = rect.x();
593 int top = rect.y();
594 int right = rect.x() + rect.width();
595 int bottom = rect.y() + rect.height();
596
597 // Put on Label
598 gfx::Rect label_rect(left, top, right - left,
599 description_label_->GetHeightForWidth(right - left));
600 description_label_->SetBoundsRect(label_rect);
601 top += label_rect.height() + views::kUnrelatedControlVerticalSpacing;
602
603 // Put on Checkbox
604 int checkbox_height = 0;
605 if (audio_share_checkbox_) {
606 checkbox_height = audio_share_checkbox_->GetHeightForWidth(right - left);
607 bottom -= checkbox_height;
608 gfx::Rect checkbox_rect(left, bottom, right - left, checkbox_height);
609 audio_share_checkbox_->SetBoundsRect(checkbox_rect);
610 }
611
612 // Put on scroll view
613 int pane_height = bottom - top - views::kRelatedControlVerticalSpacing;
614 gfx::Rect pane_rect(0, top, right - left + views::kPanelHorizMargin * 4,
615 pane_height);
616
617 pane_->SetBoundsRect(pane_rect);
505 } 618 }
506 619
507 ui::ModalType DesktopMediaPickerDialogView::GetModalType() const { 620 ui::ModalType DesktopMediaPickerDialogView::GetModalType() const {
508 return ui::MODAL_TYPE_CHILD; 621 return ui::MODAL_TYPE_CHILD;
509 } 622 }
510 623
511 base::string16 DesktopMediaPickerDialogView::GetWindowTitle() const { 624 base::string16 DesktopMediaPickerDialogView::GetWindowTitle() const {
512 return l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TITLE, app_name_); 625 return l10n_util::GetStringUTF16(IDS_DESKTOP_MEDIA_PICKER_TITLE);
513 } 626 }
514 627
515 bool DesktopMediaPickerDialogView::IsDialogButtonEnabled( 628 bool DesktopMediaPickerDialogView::IsDialogButtonEnabled(
516 ui::DialogButton button) const { 629 ui::DialogButton button) const {
517 if (button == ui::DIALOG_BUTTON_OK) 630 if (button == ui::DIALOG_BUTTON_OK) {
518 return sources_list_view_->GetSelection() != NULL; 631 return list_views_[pane_->selected_tab_index()]->GetSelection() != NULL;
632 }
519 return true; 633 return true;
520 } 634 }
521 635
522 views::View* DesktopMediaPickerDialogView::GetInitiallyFocusedView() { 636 views::View* DesktopMediaPickerDialogView::GetInitiallyFocusedView() {
523 return sources_list_view_; 637 return list_views_[0];
524 } 638 }
525 639
526 base::string16 DesktopMediaPickerDialogView::GetDialogButtonLabel( 640 base::string16 DesktopMediaPickerDialogView::GetDialogButtonLabel(
527 ui::DialogButton button) const { 641 ui::DialogButton button) const {
528 return l10n_util::GetStringUTF16(button == ui::DIALOG_BUTTON_OK ? 642 return l10n_util::GetStringUTF16(button == ui::DIALOG_BUTTON_OK
529 IDS_DESKTOP_MEDIA_PICKER_SHARE : IDS_CANCEL); 643 ? IDS_DESKTOP_MEDIA_PICKER_SHARE
644 : IDS_CANCEL);
645 }
646
647 bool DesktopMediaPickerDialogView::ShouldDefaultButtonBeBlue() const {
648 return true;
530 } 649 }
531 650
532 bool DesktopMediaPickerDialogView::Accept() { 651 bool DesktopMediaPickerDialogView::Accept() {
533 DesktopMediaSourceView* selection = sources_list_view_->GetSelection(); 652 DesktopMediaSourceView* selection =
653 list_views_[pane_->selected_tab_index()]->GetSelection();
534 654
535 // Ok button should only be enabled when a source is selected. 655 // Ok button should only be enabled when a source is selected.
536 DCHECK(selection); 656 DCHECK(selection);
537 DesktopMediaID source = selection->source_id(); 657 DesktopMediaID source = selection->source_id();
538 source.audio_share = audio_share_checkbox_ && 658 source.audio_share = audio_share_checkbox_ &&
539 audio_share_checkbox_->enabled() && 659 audio_share_checkbox_->visible() &&
540 audio_share_checkbox_->checked(); 660 audio_share_checkbox_->checked();
541 661
542 // If the media source is an tab, activate it. 662 // If the media source is an tab, activate it.
543 if (source.type == DesktopMediaID::TYPE_WEB_CONTENTS) { 663 if (source.type == DesktopMediaID::TYPE_WEB_CONTENTS) {
544 content::WebContents* tab = content::WebContents::FromRenderFrameHost( 664 content::WebContents* tab = content::WebContents::FromRenderFrameHost(
545 content::RenderFrameHost::FromID( 665 content::RenderFrameHost::FromID(
546 source.web_contents_id.render_process_id, 666 source.web_contents_id.render_process_id,
547 source.web_contents_id.main_render_frame_id)); 667 source.web_contents_id.main_render_frame_id));
548 if (tab) 668 if (tab)
549 tab->GetDelegate()->ActivateContents(tab); 669 tab->GetDelegate()->ActivateContents(tab);
550 } 670 }
551 671
552 if (parent_) 672 if (parent_)
553 parent_->NotifyDialogResult(source); 673 parent_->NotifyDialogResult(source);
554 674
555 // Return true to close the window. 675 // Return true to close the window.
556 return true; 676 return true;
557 } 677 }
558 678
559 void DesktopMediaPickerDialogView::DeleteDelegate() { 679 void DesktopMediaPickerDialogView::DeleteDelegate() {
560 // If the dialog is being closed then notify the parent about it. 680 // If the dialog is being closed then notify the parent about it.
561 if (parent_) 681 if (parent_)
562 parent_->NotifyDialogResult(DesktopMediaID()); 682 parent_->NotifyDialogResult(DesktopMediaID());
563 delete this; 683 delete this;
564 } 684 }
565 685
566 void DesktopMediaPickerDialogView::OnSelectionChanged() { 686 void DesktopMediaPickerDialogView::OnSelectionChanged() {
567 GetDialogClientView()->UpdateDialogButtons(); 687 GetDialogClientView()->UpdateDialogButtons();
568
569 // Disable the checkbox if we cannot support audio for the selected source.
570 if (audio_share_checkbox_) {
571 DesktopMediaSourceView* selection = sources_list_view_->GetSelection();
572
573 DesktopMediaID source;
574 if (selection)
575 source = selection->source_id();
576
577 if (source.type == DesktopMediaID::TYPE_SCREEN ||
578 source.type == DesktopMediaID::TYPE_WEB_CONTENTS) {
579 if (!audio_share_checkbox_->enabled()) {
580 audio_share_checkbox_->SetEnabled(true);
581 audio_share_checkbox_->SetChecked(audio_share_checked_);
582 }
583 audio_share_checkbox_->SetTooltipText(base::string16());
584 } else if (source.type == DesktopMediaID::TYPE_WINDOW) {
585 if (audio_share_checkbox_->enabled()) {
586 audio_share_checkbox_->SetEnabled(false);
587 audio_share_checked_ = audio_share_checkbox_->checked();
588 audio_share_checkbox_->SetChecked(false);
589 }
590 audio_share_checkbox_->SetTooltipText(l10n_util::GetStringUTF16(
591 IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE_TOOLTIP_WINDOW));
592 } else {
593 NOTREACHED();
594 }
595 }
596 } 688 }
597 689
598 void DesktopMediaPickerDialogView::OnDoubleClick() { 690 void DesktopMediaPickerDialogView::OnDoubleClick() {
599 // This will call Accept() and close the dialog. 691 // This will call Accept() and close the dialog.
600 GetDialogClientView()->AcceptWindow(); 692 GetDialogClientView()->AcceptWindow();
601 } 693 }
602 694
603 void DesktopMediaPickerDialogView::OnMediaListRowsChanged() { 695 void DesktopMediaPickerDialogView::OnMediaListRowsChanged() {
604 gfx::Rect widget_bound = GetWidget()->GetWindowBoundsInScreen(); 696 gfx::Rect widget_bound = GetWidget()->GetWindowBoundsInScreen();
605 697
606 int new_height = widget_bound.height() - sources_scroll_view_->height() + 698 int new_height = widget_bound.height() - pane_->height() +
607 sources_scroll_view_->GetPreferredSize().height(); 699 pane_->GetPreferredSize().height();
608 700
609 GetWidget()->CenterWindow(gfx::Size(widget_bound.width(), new_height)); 701 GetWidget()->CenterWindow(gfx::Size(widget_bound.width(), new_height));
610 } 702 }
611 703
612 DesktopMediaListView* DesktopMediaPickerDialogView::GetMediaListViewForTesting() 704 DesktopMediaListView* DesktopMediaPickerDialogView::GetMediaListViewForTesting()
613 const { 705 const {
614 return sources_list_view_; 706 return list_views_[pane_->selected_tab_index()];
615 } 707 }
616 708
617 DesktopMediaSourceView* 709 DesktopMediaSourceView*
618 DesktopMediaPickerDialogView::GetMediaSourceViewForTesting(int index) const { 710 DesktopMediaPickerDialogView::GetMediaSourceViewForTesting(int index) const {
619 if (sources_list_view_->child_count() <= index) 711 if (list_views_[pane_->selected_tab_index()]->child_count() <= index)
620 return NULL; 712 return NULL;
621 713
622 return reinterpret_cast<DesktopMediaSourceView*>( 714 return reinterpret_cast<DesktopMediaSourceView*>(
623 sources_list_view_->child_at(index)); 715 list_views_[pane_->selected_tab_index()]->child_at(index));
624 } 716 }
625 717
626 DesktopMediaPickerViews::DesktopMediaPickerViews() : dialog_(NULL) { 718 views::Checkbox* DesktopMediaPickerDialogView::GetCheckboxForTesting() const {
719 return audio_share_checkbox_;
627 } 720 }
628 721
722 int DesktopMediaPickerDialogView::GetIndexOfSourceTypeForTesting(
723 DesktopMediaID::Type source_type) const {
724 for (size_t i = 0; i < source_types_.size(); i++) {
725 if (source_types_[i] == source_type)
726 return i;
727 }
728 return -1;
729 }
730
731 views::TabbedPane* DesktopMediaPickerDialogView::GetPaneForTesting() const {
732 return pane_;
733 }
734
735 DesktopMediaPickerViews::DesktopMediaPickerViews() : dialog_(NULL) {}
736
629 DesktopMediaPickerViews::~DesktopMediaPickerViews() { 737 DesktopMediaPickerViews::~DesktopMediaPickerViews() {
630 if (dialog_) { 738 if (dialog_) {
631 dialog_->DetachParent(); 739 dialog_->DetachParent();
632 dialog_->GetWidget()->Close(); 740 dialog_->GetWidget()->Close();
633 } 741 }
634 } 742 }
635 743
636 void DesktopMediaPickerViews::Show( 744 void DesktopMediaPickerViews::Show(
637 content::WebContents* web_contents, 745 content::WebContents* web_contents,
638 gfx::NativeWindow context, 746 gfx::NativeWindow context,
(...skipping 14 matching lines...) Expand all
653 761
654 void DesktopMediaPickerViews::NotifyDialogResult(DesktopMediaID source) { 762 void DesktopMediaPickerViews::NotifyDialogResult(DesktopMediaID source) {
655 // Once this method is called the |dialog_| will close and destroy itself. 763 // Once this method is called the |dialog_| will close and destroy itself.
656 dialog_->DetachParent(); 764 dialog_->DetachParent();
657 dialog_ = NULL; 765 dialog_ = NULL;
658 766
659 DCHECK(!callback_.is_null()); 767 DCHECK(!callback_.is_null());
660 768
661 // Notify the |callback_| asynchronously because it may need to destroy 769 // Notify the |callback_| asynchronously because it may need to destroy
662 // DesktopMediaPicker. 770 // DesktopMediaPicker.
663 content::BrowserThread::PostTask( 771 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
664 content::BrowserThread::UI, FROM_HERE, 772 base::Bind(callback_, source));
665 base::Bind(callback_, source));
666 callback_.Reset(); 773 callback_.Reset();
667 } 774 }
668 775
669 // static 776 // static
670 std::unique_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() { 777 std::unique_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() {
778 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
779 extensions::switches::kDisableDesktopPickerNewUI)) {
780 return std::unique_ptr<DesktopMediaPicker>(
781 new deprecated::DesktopMediaPickerViews());
782 }
671 return std::unique_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews()); 783 return std::unique_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews());
672 } 784 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698