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

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

Issue 1909663004: Desktop Capture Picker New UI: Non Mac Structure Change (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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_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"
(...skipping 13 matching lines...) Expand all
24 #include "grit/components_strings.h" 24 #include "grit/components_strings.h"
25 #include "ui/aura/window_tree_host.h" 25 #include "ui/aura/window_tree_host.h"
26 #include "ui/base/l10n/l10n_util.h" 26 #include "ui/base/l10n/l10n_util.h"
27 #include "ui/events/event_constants.h" 27 #include "ui/events/event_constants.h"
28 #include "ui/events/keycodes/keyboard_codes.h" 28 #include "ui/events/keycodes/keyboard_codes.h"
29 #include "ui/gfx/canvas.h" 29 #include "ui/gfx/canvas.h"
30 #include "ui/native_theme/native_theme.h" 30 #include "ui/native_theme/native_theme.h"
31 #include "ui/views/background.h" 31 #include "ui/views/background.h"
32 #include "ui/views/bubble/bubble_frame_view.h" 32 #include "ui/views/bubble/bubble_frame_view.h"
33 #include "ui/views/controls/button/checkbox.h" 33 #include "ui/views/controls/button/checkbox.h"
34 #include "ui/views/controls/button/label_button.h"
35 #include "ui/views/controls/button/label_button_border.h"
34 #include "ui/views/controls/image_view.h" 36 #include "ui/views/controls/image_view.h"
35 #include "ui/views/controls/label.h" 37 #include "ui/views/controls/label.h"
36 #include "ui/views/controls/scroll_view.h" 38 #include "ui/views/controls/scroll_view.h"
37 #include "ui/views/layout/box_layout.h" 39 #include "ui/views/layout/box_layout.h"
38 #include "ui/views/layout/layout_constants.h" 40 #include "ui/views/layout/layout_constants.h"
39 #include "ui/views/widget/widget.h" 41 #include "ui/views/widget/widget.h"
40 #include "ui/views/window/dialog_client_view.h" 42 #include "ui/views/window/dialog_client_view.h"
41 #include "ui/wm/core/shadow_types.h" 43 #include "ui/wm/core/shadow_types.h"
42 44
43 using content::DesktopMediaID; 45 using content::DesktopMediaID;
44 46
45 namespace { 47 namespace {
46 48
47 const int kThumbnailWidth = 160; 49 const int kThumbnailWidth = 160;
48 const int kThumbnailHeight = 100; 50 const int kThumbnailHeight = 100;
49 const int kThumbnailMargin = 10; 51 const int kThumbnailMargin = 10;
50 const int kLabelHeight = 40; 52 const int kLabelHeight = 40;
51 const int kListItemWidth = kThumbnailMargin * 2 + kThumbnailWidth; 53 const int kListItemWidth = kThumbnailMargin * 2 + kThumbnailWidth;
52 const int kListItemHeight = 54 const int kListItemHeight =
53 kThumbnailMargin * 2 + kThumbnailHeight + kLabelHeight; 55 kThumbnailMargin * 2 + kThumbnailHeight + kLabelHeight;
54 const int kListColumns = 3; 56 const int kListColumns = 3;
55 const int kTotalListWidth = kListColumns * kListItemWidth; 57 const int kTotalListWidth = kListColumns * kListItemWidth;
56 58
57 const int kDesktopMediaSourceViewGroupId = 1; 59 const int kDesktopMediaSourceViewGroupId = 1;
58 60
59 const char kDesktopMediaSourceViewClassName[] = 61 const char kDesktopMediaSourceViewClassName[] =
60 "DesktopMediaPicker_DesktopMediaSourceView"; 62 "DesktopMediaPicker_DesktopMediaSourceView";
61 63
64 const SkColor kActiveButtonColor = 0xFF4444FF;
65 const SkColor kActiveBorderColor = 0xFF8888FF;
66 const SkColor kInactiveButtonColor = 0xFF000000;
67
62 DesktopMediaID::Id AcceleratedWidgetToDesktopMediaId( 68 DesktopMediaID::Id AcceleratedWidgetToDesktopMediaId(
63 gfx::AcceleratedWidget accelerated_widget) { 69 gfx::AcceleratedWidget accelerated_widget) {
64 #if defined(OS_WIN) 70 #if defined(OS_WIN)
65 return reinterpret_cast<DesktopMediaID::Id>(accelerated_widget); 71 return reinterpret_cast<DesktopMediaID::Id>(accelerated_widget);
66 #else 72 #else
67 return static_cast<DesktopMediaID::Id>(accelerated_widget); 73 return static_cast<DesktopMediaID::Id>(accelerated_widget);
68 #endif 74 #endif
69 } 75 }
70 76
71 int GetMediaListViewHeightForRows(size_t rows) { 77 int GetMediaListViewHeightForRows(size_t rows) {
(...skipping 165 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 current_index_(0) {
408 sources_scroll_view_(views::ScrollView::CreateScrollViewWithBorder()) { 420 int index = 0;
409 std::vector<std::unique_ptr<DesktopMediaList>> media_lists; 421 if (screen_list) {
410 if (screen_list) 422 source_types_.push_back(DesktopMediaID::TYPE_SCREEN);
411 media_lists.push_back(std::move(screen_list)); 423 scroll_views_.push_back(views::ScrollView::CreateScrollViewWithBorder());
412 if (window_list) 424 list_views_.push_back(
413 media_lists.push_back(std::move(window_list)); 425 new DesktopMediaListView(this, std::move(screen_list)));
414 if (tab_list)
415 media_lists.push_back(std::move(tab_list));
416 426
417 std::unique_ptr<DesktopMediaList> media_list; 427 views::LabelButton* button = new views::LabelButton(
418 if (media_lists.size() > 1) 428 this,
419 media_list.reset(new CombinedDesktopMediaList(media_lists)); 429 l10n_util::GetStringUTF16(IDS_DESKTOP_MEDIA_PICKER_SOURCE_TYPE_SCREEN));
420 else 430 button->set_tag(index);
421 media_list = std::move(media_lists[0]); 431 source_type_buttons_.push_back(button);
432 index++;
433 }
422 434
423 DCHECK(media_list != nullptr); 435 if (window_list) {
424 sources_list_view_ = new DesktopMediaListView(this, std::move(media_list)); 436 source_types_.push_back(DesktopMediaID::TYPE_WINDOW);
437 scroll_views_.push_back(views::ScrollView::CreateScrollViewWithBorder());
438 list_views_.push_back(
439 new DesktopMediaListView(this, std::move(window_list)));
440 views::LabelButton* button = new views::LabelButton(
441 this,
442 l10n_util::GetStringUTF16(IDS_DESKTOP_MEDIA_PICKER_SOURCE_TYPE_WINDOW));
443 button->set_tag(index);
444 source_type_buttons_.push_back(button);
445 index++;
446 }
425 447
426 // TODO(estade): we should be getting the inside-border spacing by default as 448 if (tab_list) {
427 // a DialogDelegateView subclass, via default BubbleFrameView content margins. 449 source_types_.push_back(DesktopMediaID::TYPE_WEB_CONTENTS);
428 SetLayoutManager(new views::BoxLayout( 450 scroll_views_.push_back(views::ScrollView::CreateScrollViewWithBorder());
429 views::BoxLayout::kVertical, views::kButtonHEdgeMarginNew, 451 list_views_.push_back(new DesktopMediaListView(this, std::move(tab_list)));
430 views::kPanelVertMargin, views::kLabelToControlVerticalSpacing)); 452 views::LabelButton* button = new views::LabelButton(
453 this,
454 l10n_util::GetStringUTF16(IDS_DESKTOP_MEDIA_PICKER_SOURCE_TYPE_TAB));
455 button->set_tag(index);
456 source_type_buttons_.push_back(button);
457 index++;
458 }
459
460 DCHECK(index > 0);
431 461
432 if (app_name == target_name) { 462 if (app_name == target_name) {
433 description_label_->SetText( 463 description_label_->SetText(
434 l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TEXT, app_name)); 464 l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TEXT, app_name));
435 } else { 465 } else {
436 description_label_->SetText(l10n_util::GetStringFUTF16( 466 description_label_->SetText(l10n_util::GetStringFUTF16(
437 IDS_DESKTOP_MEDIA_PICKER_TEXT_DELEGATED, app_name, target_name)); 467 IDS_DESKTOP_MEDIA_PICKER_TEXT_DELEGATED, app_name, target_name));
438 } 468 }
439 description_label_->SetMultiLine(true); 469 description_label_->SetMultiLine(true);
440 description_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 470 description_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
441 AddChildView(description_label_); 471 AddChildView(description_label_);
442 472
443 sources_scroll_view_->SetContents(sources_list_view_); 473 std::vector<gfx::Font> font =
444 sources_scroll_view_->ClipHeightTo(GetMediaListViewHeightForRows(1), 474 source_type_buttons_[0]->GetFontList().GetFonts();
445 GetMediaListViewHeightForRows(2)); 475 font[0] = gfx::Font(font[0].GetFontName(), 16);
446 AddChildView(sources_scroll_view_); 476 for (auto& button : source_type_buttons_) {
477 button->SetFontList(gfx::FontList(font));
478 button->SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_CENTER);
479 AddChildView(button);
480 }
481
482 for (size_t i = 0; i < source_types_.size(); i++) {
483 scroll_views_[i]->SetContents(list_views_[i]);
484 scroll_views_[i]->ClipHeightTo(GetMediaListViewHeightForRows(1),
485 GetMediaListViewHeightForRows(2));
486 AddChildView(scroll_views_[i]);
487 }
447 488
448 if (request_audio) { 489 if (request_audio) {
449 audio_share_checkbox_ = new views::Checkbox( 490 audio_share_checkbox_ = new views::Checkbox(
450 l10n_util::GetStringUTF16(IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE)); 491 l10n_util::GetStringUTF16(IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE));
492 audio_share_checkbox_->SetChecked(true);
451 AddChildView(audio_share_checkbox_); 493 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 } 494 }
456 495
496 SwitchSourceType(0);
497
457 // If |parent_web_contents| is set and it's not a background page then the 498 // 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 499 // picker will be shown modal to the web contents. Otherwise the picker is
459 // shown in a separate window. 500 // shown in a separate window.
460 views::Widget* widget = NULL; 501 views::Widget* widget = NULL;
461 bool modal_dialog = 502 bool modal_dialog =
462 parent_web_contents && 503 parent_web_contents &&
463 !parent_web_contents->GetDelegate()->IsNeverVisible(parent_web_contents); 504 !parent_web_contents->GetDelegate()->IsNeverVisible(parent_web_contents);
464 if (modal_dialog) { 505 if (modal_dialog) {
465 widget = constrained_window::ShowWebModalDialogViews(this, 506 widget = constrained_window::ShowWebModalDialogViews(this,
466 parent_web_contents); 507 parent_web_contents);
(...skipping 16 matching lines...) Expand all
483 is_ash_window = chrome::IsNativeWindowInAsh(widget->GetNativeWindow()); 524 is_ash_window = chrome::IsNativeWindowInAsh(widget->GetNativeWindow());
484 #endif 525 #endif
485 526
486 // Set native window ID if the windows is outside Ash. 527 // Set native window ID if the windows is outside Ash.
487 if (!is_ash_window) { 528 if (!is_ash_window) {
488 dialog_window_id.id = AcceleratedWidgetToDesktopMediaId( 529 dialog_window_id.id = AcceleratedWidgetToDesktopMediaId(
489 widget->GetNativeWindow()->GetHost()->GetAcceleratedWidget()); 530 widget->GetNativeWindow()->GetHost()->GetAcceleratedWidget());
490 } 531 }
491 } 532 }
492 533
493 sources_list_view_->StartUpdating(dialog_window_id); 534 for (auto& list_view : list_views_) {
535 list_view->StartUpdating(dialog_window_id);
536 }
494 } 537 }
495 538
496 DesktopMediaPickerDialogView::~DesktopMediaPickerDialogView() {} 539 DesktopMediaPickerDialogView::~DesktopMediaPickerDialogView() {}
497 540
541 void DesktopMediaPickerDialogView::ButtonPressed(views::Button* sender,
542 const ui::Event& event) {
543 const int index = static_cast<views::LabelButton*>(sender)->tag();
544 SwitchSourceType(index);
545
546 // Repaint the buttons.
547 for (auto& button : source_type_buttons_) {
548 button->SchedulePaint();
549 }
550 GetDialogClientView()->UpdateDialogButtons();
551 }
552
553 void DesktopMediaPickerDialogView::SwitchSourceType(int index) {
554 current_index_ = index;
555
556 // Set the border of source type buttons
557 for (size_t i = 0; i < source_type_buttons_.size(); i++) {
558 if (static_cast<int>(i) == index) {
559 source_type_buttons_[i]->SetBorder(views::Border::CreateSolidSidedBorder(
560 0, 0, 4, 0, kActiveBorderColor));
561 source_type_buttons_[i]->SetEnabledTextColors(kActiveButtonColor);
562 scroll_views_[i]->SetVisible(true);
563 } else {
564 source_type_buttons_[i]->SetBorder(views::Border::NullBorder());
565 source_type_buttons_[i]->SetEnabledTextColors(kInactiveButtonColor);
566 scroll_views_[i]->SetVisible(false);
567 }
568 }
569
570 // Set whether the checkbox is visible based on the source type
571 if (audio_share_checkbox_) {
572 switch (source_types_[index]) {
573 case DesktopMediaID::TYPE_SCREEN:
574 #if defined(USE_CRAS) || defined(OS_WIN)
575 audio_share_checkbox_->SetVisible(true);
576 #else
577 audio_share_checkbox_->SetVisible(false);
578 #endif
579 break;
580 case DesktopMediaID::TYPE_WINDOW:
581 audio_share_checkbox_->SetVisible(false);
582 break;
583 case DesktopMediaID::TYPE_WEB_CONTENTS:
584 audio_share_checkbox_->SetVisible(true);
585 break;
586 case DesktopMediaID::TYPE_NONE:
587 NOTREACHED();
588 break;
589 }
590 }
591 }
592
498 void DesktopMediaPickerDialogView::DetachParent() { 593 void DesktopMediaPickerDialogView::DetachParent() {
499 parent_ = NULL; 594 parent_ = NULL;
500 } 595 }
501 596
502 gfx::Size DesktopMediaPickerDialogView::GetPreferredSize() const { 597 gfx::Size DesktopMediaPickerDialogView::GetPreferredSize() const {
503 static const size_t kDialogViewWidth = 600; 598 static const size_t kDialogViewWidth = 600;
504 return gfx::Size(kDialogViewWidth, GetHeightForWidth(kDialogViewWidth)); 599 const size_t kInnerWidth = kDialogViewWidth - views::kPanelHorizMargin * 4;
600
601 int related_spacing_num = 0;
602 int unrelated_spacing_num = 0;
603
604 size_t label_height = description_label_->GetHeightForWidth(kInnerWidth);
605 unrelated_spacing_num++;
606
607 size_t checkbox_height = 0;
608 if (audio_share_checkbox_) {
609 checkbox_height = audio_share_checkbox_->GetHeightForWidth(kInnerWidth);
610 related_spacing_num++;
611 }
612
613 int button_height = 0;
614 for (size_t i = 0; i < source_type_buttons_.size(); i++) {
615 const int height = source_type_buttons_[i]->GetHeightForWidth(kInnerWidth);
616 if (height > button_height)
617 button_height = height;
618 }
619
620 int scroll_view_height =
621 scroll_views_[current_index_]->GetPreferredSize().height();
622 related_spacing_num++;
623
624 return gfx::Size(
625 kDialogViewWidth,
626 views::kPanelVertMargin * 2 + label_height + checkbox_height +
627 scroll_view_height + button_height +
628 views::kRelatedControlVerticalSpacing * related_spacing_num +
629 views::kUnrelatedControlVerticalSpacing * unrelated_spacing_num);
630 }
631
632 void DesktopMediaPickerDialogView::Layout() {
633 // DialogDelegate uses the bubble style frame.
634 gfx::Rect rect = GetLocalBounds();
635
636 // |left|, |top|, |right|, |bottom| describes the available area.
637 rect.Inset(views::kPanelHorizMargin * 2, views::kPanelVertMargin);
638 int left = rect.x();
639 int top = rect.y();
640 int right = rect.x() + rect.width();
641 int bottom = rect.y() + rect.height();
642
643 // Put on Label
644 gfx::Rect label_rect(left, top, right - left,
645 description_label_->GetHeightForWidth(right - left));
646 description_label_->SetBoundsRect(label_rect);
647 top += label_rect.height() + views::kUnrelatedControlVerticalSpacing;
648
649 // Put on Group button
650 std::vector<int> buttons_width;
651 int total_ideal_width = 0;
652 for (auto& button : source_type_buttons_) {
653 const int width = button->GetPreferredSize().width() + 16;
654 buttons_width.push_back(width);
655 total_ideal_width += width;
656 }
657
658 int button_height = 0;
659 int button_left = left;
660 for (size_t i = 0; i < buttons_width.size(); i++) {
661 if (right - left < total_ideal_width)
662 buttons_width[i] = (right - left) * buttons_width[i] / total_ideal_width;
663 const int height =
664 source_type_buttons_[i]->GetHeightForWidth(buttons_width[i]) + 8;
665 if (height > button_height)
666 button_height = height;
667 }
668
669 for (size_t i = 0; i < buttons_width.size(); i++) {
670 gfx::Rect button_rect(button_left, top, buttons_width[i], button_height);
671 button_left += buttons_width[i];
672 source_type_buttons_[i]->SetBoundsRect(button_rect);
673 }
674
675 top += button_height;
676
677 // Put on Checkbox
678 int checkbox_height = 0;
679 if (audio_share_checkbox_) {
680 checkbox_height = audio_share_checkbox_->GetHeightForWidth(right - left);
681 bottom -= checkbox_height;
682 gfx::Rect checkbox_rect(left, bottom, right - left, checkbox_height);
683 audio_share_checkbox_->SetBoundsRect(checkbox_rect);
684 }
685
686 // Put on scroll view
687 int scroll_view_height = bottom - top - views::kRelatedControlVerticalSpacing;
688 gfx::Rect scroll_view_rect(
689 0, top, right - left + views::kPanelHorizMargin * 4, scroll_view_height);
690
691 for (size_t i = 0; i < scroll_views_.size(); i++)
692 scroll_views_[i]->SetBoundsRect(scroll_view_rect);
505 } 693 }
506 694
507 ui::ModalType DesktopMediaPickerDialogView::GetModalType() const { 695 ui::ModalType DesktopMediaPickerDialogView::GetModalType() const {
508 return ui::MODAL_TYPE_CHILD; 696 return ui::MODAL_TYPE_CHILD;
509 } 697 }
510 698
511 base::string16 DesktopMediaPickerDialogView::GetWindowTitle() const { 699 base::string16 DesktopMediaPickerDialogView::GetWindowTitle() const {
512 return l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TITLE, app_name_); 700 return l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TITLE, app_name_);
513 } 701 }
514 702
515 bool DesktopMediaPickerDialogView::IsDialogButtonEnabled( 703 bool DesktopMediaPickerDialogView::IsDialogButtonEnabled(
516 ui::DialogButton button) const { 704 ui::DialogButton button) const {
517 if (button == ui::DIALOG_BUTTON_OK) 705 if (button == ui::DIALOG_BUTTON_OK) {
518 return sources_list_view_->GetSelection() != NULL; 706 return list_views_[current_index_]->GetSelection() != NULL;
707 }
519 return true; 708 return true;
520 } 709 }
521 710
522 views::View* DesktopMediaPickerDialogView::GetInitiallyFocusedView() { 711 views::View* DesktopMediaPickerDialogView::GetInitiallyFocusedView() {
523 return sources_list_view_; 712 return list_views_[0];
524 } 713 }
525 714
526 base::string16 DesktopMediaPickerDialogView::GetDialogButtonLabel( 715 base::string16 DesktopMediaPickerDialogView::GetDialogButtonLabel(
527 ui::DialogButton button) const { 716 ui::DialogButton button) const {
528 return l10n_util::GetStringUTF16(button == ui::DIALOG_BUTTON_OK ? 717 return l10n_util::GetStringUTF16(button == ui::DIALOG_BUTTON_OK ?
529 IDS_DESKTOP_MEDIA_PICKER_SHARE : IDS_CANCEL); 718 IDS_DESKTOP_MEDIA_PICKER_SHARE : IDS_CANCEL);
530 } 719 }
531 720
721 bool DesktopMediaPickerDialogView::ShouldDefaultButtonBeBlue() const {
722 return true;
723 }
724
532 bool DesktopMediaPickerDialogView::Accept() { 725 bool DesktopMediaPickerDialogView::Accept() {
533 DesktopMediaSourceView* selection = sources_list_view_->GetSelection(); 726 DesktopMediaSourceView* selection =
727 list_views_[current_index_]->GetSelection();
534 728
535 // Ok button should only be enabled when a source is selected. 729 // Ok button should only be enabled when a source is selected.
536 DCHECK(selection); 730 DCHECK(selection);
537 DesktopMediaID source = selection->source_id(); 731 DesktopMediaID source = selection->source_id();
538 source.audio_share = audio_share_checkbox_ && 732 source.audio_share = audio_share_checkbox_ &&
539 audio_share_checkbox_->enabled() && 733 audio_share_checkbox_->visible() &&
540 audio_share_checkbox_->checked(); 734 audio_share_checkbox_->checked();
541 735
542 // If the media source is an tab, activate it. 736 // If the media source is an tab, activate it.
543 if (source.type == DesktopMediaID::TYPE_WEB_CONTENTS) { 737 if (source.type == DesktopMediaID::TYPE_WEB_CONTENTS) {
544 content::WebContents* tab = content::WebContents::FromRenderFrameHost( 738 content::WebContents* tab = content::WebContents::FromRenderFrameHost(
545 content::RenderFrameHost::FromID( 739 content::RenderFrameHost::FromID(
546 source.web_contents_id.render_process_id, 740 source.web_contents_id.render_process_id,
547 source.web_contents_id.main_render_frame_id)); 741 source.web_contents_id.main_render_frame_id));
548 if (tab) 742 if (tab)
549 tab->GetDelegate()->ActivateContents(tab); 743 tab->GetDelegate()->ActivateContents(tab);
550 } 744 }
551 745
552 if (parent_) 746 if (parent_)
553 parent_->NotifyDialogResult(source); 747 parent_->NotifyDialogResult(source);
554 748
555 // Return true to close the window. 749 // Return true to close the window.
556 return true; 750 return true;
557 } 751 }
558 752
559 void DesktopMediaPickerDialogView::DeleteDelegate() { 753 void DesktopMediaPickerDialogView::DeleteDelegate() {
560 // If the dialog is being closed then notify the parent about it. 754 // If the dialog is being closed then notify the parent about it.
561 if (parent_) 755 if (parent_)
562 parent_->NotifyDialogResult(DesktopMediaID()); 756 parent_->NotifyDialogResult(DesktopMediaID());
563 delete this; 757 delete this;
564 } 758 }
565 759
566 void DesktopMediaPickerDialogView::OnSelectionChanged() { 760 void DesktopMediaPickerDialogView::OnSelectionChanged() {
567 GetDialogClientView()->UpdateDialogButtons(); 761 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 } 762 }
597 763
598 void DesktopMediaPickerDialogView::OnDoubleClick() { 764 void DesktopMediaPickerDialogView::OnDoubleClick() {
599 // This will call Accept() and close the dialog. 765 // This will call Accept() and close the dialog.
600 GetDialogClientView()->AcceptWindow(); 766 GetDialogClientView()->AcceptWindow();
601 } 767 }
602 768
603 void DesktopMediaPickerDialogView::OnMediaListRowsChanged() { 769 void DesktopMediaPickerDialogView::OnMediaListRowsChanged() {
604 gfx::Rect widget_bound = GetWidget()->GetWindowBoundsInScreen(); 770 gfx::Rect widget_bound = GetWidget()->GetWindowBoundsInScreen();
605 771
606 int new_height = widget_bound.height() - sources_scroll_view_->height() + 772 int new_height = widget_bound.height() -
607 sources_scroll_view_->GetPreferredSize().height(); 773 scroll_views_[current_index_]->height() +
774 scroll_views_[current_index_]->GetPreferredSize().height();
608 775
609 GetWidget()->CenterWindow(gfx::Size(widget_bound.width(), new_height)); 776 GetWidget()->CenterWindow(gfx::Size(widget_bound.width(), new_height));
610 } 777 }
611 778
612 DesktopMediaListView* DesktopMediaPickerDialogView::GetMediaListViewForTesting() 779 DesktopMediaListView* DesktopMediaPickerDialogView::GetMediaListViewForTesting()
613 const { 780 const {
614 return sources_list_view_; 781 return list_views_[current_index_];
615 } 782 }
616 783
617 DesktopMediaSourceView* 784 DesktopMediaSourceView*
618 DesktopMediaPickerDialogView::GetMediaSourceViewForTesting(int index) const { 785 DesktopMediaPickerDialogView::GetMediaSourceViewForTesting(int index) const {
619 if (sources_list_view_->child_count() <= index) 786 if (list_views_[current_index_]->child_count() <= index)
620 return NULL; 787 return NULL;
621 788
622 return reinterpret_cast<DesktopMediaSourceView*>( 789 return reinterpret_cast<DesktopMediaSourceView*>(
623 sources_list_view_->child_at(index)); 790 list_views_[current_index_]->child_at(index));
791 }
792
793 views::LabelButton* DesktopMediaPickerDialogView::GetSourceTypeButtonForTesting(
794 DesktopMediaID::Type source_type) const {
795 for (size_t i = 0; i < source_types_.size(); i++) {
796 if (source_types_[i] == source_type)
797 return source_type_buttons_[i];
798 }
799 return nullptr;
800 }
801
802 views::Checkbox* DesktopMediaPickerDialogView::GetCheckboxForTesting() const {
803 return audio_share_checkbox_;
624 } 804 }
625 805
626 DesktopMediaPickerViews::DesktopMediaPickerViews() : dialog_(NULL) { 806 DesktopMediaPickerViews::DesktopMediaPickerViews() : dialog_(NULL) {
627 } 807 }
628 808
629 DesktopMediaPickerViews::~DesktopMediaPickerViews() { 809 DesktopMediaPickerViews::~DesktopMediaPickerViews() {
630 if (dialog_) { 810 if (dialog_) {
631 dialog_->DetachParent(); 811 dialog_->DetachParent();
632 dialog_->GetWidget()->Close(); 812 dialog_->GetWidget()->Close();
633 } 813 }
(...skipping 29 matching lines...) Expand all
663 content::BrowserThread::PostTask( 843 content::BrowserThread::PostTask(
664 content::BrowserThread::UI, FROM_HERE, 844 content::BrowserThread::UI, FROM_HERE,
665 base::Bind(callback_, source)); 845 base::Bind(callback_, source));
666 callback_.Reset(); 846 callback_.Reset();
667 } 847 }
668 848
669 // static 849 // static
670 std::unique_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() { 850 std::unique_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() {
671 return std::unique_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews()); 851 return std::unique_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews());
672 } 852 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698