Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/media/desktop_media_picker.h" | 5 #include "chrome/browser/media/desktop_media_picker.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/command_line.h" | |
| 9 #include "base/strings/utf_string_conversions.h" | |
| 8 #include "chrome/browser/media/desktop_media_list.h" | 10 #include "chrome/browser/media/desktop_media_list.h" |
| 9 #include "chrome/browser/media/desktop_media_list_observer.h" | 11 #include "chrome/browser/media/desktop_media_list_observer.h" |
| 10 #include "chrome/browser/ui/ash/ash_util.h" | 12 #include "chrome/browser/ui/ash/ash_util.h" |
| 11 #include "chrome/browser/ui/views/constrained_window_views.h" | 13 #include "chrome/browser/ui/views/constrained_window_views.h" |
| 14 #include "chrome/common/chrome_switches.h" | |
| 12 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 15 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 13 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 14 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
| 15 #include "ui/aura/window_tree_host.h" | 18 #include "ui/aura/window_tree_host.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 17 #include "ui/events/event_constants.h" | 20 #include "ui/events/event_constants.h" |
| 18 #include "ui/events/keycodes/keyboard_codes.h" | 21 #include "ui/events/keycodes/keyboard_codes.h" |
| 19 #include "ui/gfx/canvas.h" | 22 #include "ui/gfx/canvas.h" |
| 20 #include "ui/native_theme/native_theme.h" | 23 #include "ui/native_theme/native_theme.h" |
| 21 #include "ui/views/background.h" | 24 #include "ui/views/background.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 return reinterpret_cast<content::DesktopMediaID::Id>(accelerated_widget); | 58 return reinterpret_cast<content::DesktopMediaID::Id>(accelerated_widget); |
| 56 #else | 59 #else |
| 57 return static_cast<content::DesktopMediaID::Id>(accelerated_widget); | 60 return static_cast<content::DesktopMediaID::Id>(accelerated_widget); |
| 58 #endif | 61 #endif |
| 59 } | 62 } |
| 60 | 63 |
| 61 int GetMediaListViewHeightForRows(size_t rows) { | 64 int GetMediaListViewHeightForRows(size_t rows) { |
| 62 return kListItemHeight * rows; | 65 return kListItemHeight * rows; |
| 63 } | 66 } |
| 64 | 67 |
| 68 static bool ShouldAutoSelectSource(const DesktopMediaList::Source& source) { | |
| 69 std::string desired_source = | |
| 70 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 71 switches::kAutoSelectDesktopCaptureSource); | |
| 72 if (desired_source.empty()) | |
| 73 return false; | |
| 74 | |
| 75 return desired_source == base::UTF16ToASCII(source.name); | |
| 76 } | |
| 77 | |
| 65 class DesktopMediaListView; | 78 class DesktopMediaListView; |
| 66 class DesktopMediaPickerDialogView; | 79 class DesktopMediaPickerDialogView; |
| 67 class DesktopMediaPickerViews; | 80 class DesktopMediaPickerViews; |
| 68 | 81 |
| 69 // View used for each item in DesktopMediaListView. Shows a single desktop media | 82 // View used for each item in DesktopMediaListView. Shows a single desktop media |
| 70 // source as a thumbnail with the title under it. | 83 // source as a thumbnail with the title under it. |
| 71 class DesktopMediaSourceView : public views::View { | 84 class DesktopMediaSourceView : public views::View { |
| 72 public: | 85 public: |
| 73 DesktopMediaSourceView(DesktopMediaListView* parent, | 86 DesktopMediaSourceView(DesktopMediaListView* parent, |
| 74 DesktopMediaID source_id); | 87 DesktopMediaID source_id); |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 466 } | 479 } |
| 467 | 480 |
| 468 return false; | 481 return false; |
| 469 } | 482 } |
| 470 | 483 |
| 471 void DesktopMediaListView::OnSourceAdded(int index) { | 484 void DesktopMediaListView::OnSourceAdded(int index) { |
| 472 const DesktopMediaList::Source& source = media_list_->GetSource(index); | 485 const DesktopMediaList::Source& source = media_list_->GetSource(index); |
| 473 DesktopMediaSourceView* source_view = | 486 DesktopMediaSourceView* source_view = |
| 474 new DesktopMediaSourceView(this, source.id); | 487 new DesktopMediaSourceView(this, source.id); |
| 475 source_view->SetName(source.name); | 488 source_view->SetName(source.name); |
| 489 std::cout << "!!! " << source.name << std::endl; | |
| 476 source_view->SetGroup(kDesktopMediaSourceViewGroupId); | 490 source_view->SetGroup(kDesktopMediaSourceViewGroupId); |
| 477 AddChildViewAt(source_view, index); | 491 AddChildViewAt(source_view, index); |
| 478 | 492 |
| 479 PreferredSizeChanged(); | 493 PreferredSizeChanged(); |
| 480 | 494 |
| 481 if (child_count() % kListColumns == 1) | 495 if (child_count() % kListColumns == 1) |
| 482 parent_->OnMediaListRowsChanged(); | 496 parent_->OnMediaListRowsChanged(); |
| 497 | |
| 498 if (ShouldAutoSelectSource(source)) { | |
|
jiayl
2014/07/09 17:02:34
It's not safe to do these in this callback, as it
phoglund_chromium
2014/08/04 12:37:25
Oh, right. Umm, I'm not very familiar with Chrome
| |
| 499 source_view->SetSelected(true); | |
| 500 OnSelectionChanged(); | |
| 501 parent_->OnDoubleClick(); | |
| 502 } | |
| 483 } | 503 } |
| 484 | 504 |
| 485 void DesktopMediaListView::OnSourceRemoved(int index) { | 505 void DesktopMediaListView::OnSourceRemoved(int index) { |
| 486 DesktopMediaSourceView* view = | 506 DesktopMediaSourceView* view = |
| 487 static_cast<DesktopMediaSourceView*>(child_at(index)); | 507 static_cast<DesktopMediaSourceView*>(child_at(index)); |
| 488 DCHECK(view); | 508 DCHECK(view); |
| 489 DCHECK_EQ(view->GetClassName(), kDesktopMediaSourceViewClassName); | 509 DCHECK_EQ(view->GetClassName(), kDesktopMediaSourceViewClassName); |
| 490 bool was_selected = view->is_selected(); | 510 bool was_selected = view->is_selected(); |
| 491 RemoveChildView(view); | 511 RemoveChildView(view); |
| 492 delete view; | 512 delete view; |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 731 base::Bind(callback_, source)); | 751 base::Bind(callback_, source)); |
| 732 callback_.Reset(); | 752 callback_.Reset(); |
| 733 } | 753 } |
| 734 | 754 |
| 735 } // namespace | 755 } // namespace |
| 736 | 756 |
| 737 // static | 757 // static |
| 738 scoped_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() { | 758 scoped_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() { |
| 739 return scoped_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews()); | 759 return scoped_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews()); |
| 740 } | 760 } |
| OLD | NEW |