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