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