| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_UI_VIEWS_DESKTOP_CAPTURE_DESKTOP_MEDIA_PICKER_VIEWS_H_ | |
| 6 #define CHROME_BROWSER_UI_VIEWS_DESKTOP_CAPTURE_DESKTOP_MEDIA_PICKER_VIEWS_H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "chrome/browser/media/desktop_media_list_observer.h" | |
| 10 #include "chrome/browser/media/desktop_media_picker.h" | |
| 11 #include "ui/views/controls/tabbed_pane/tabbed_pane_listener.h" | |
| 12 #include "ui/views/window/dialog_delegate.h" | |
| 13 | |
| 14 namespace views { | |
| 15 class ImageView; | |
| 16 class Label; | |
| 17 class Checkbox; | |
| 18 class TabbedPane; | |
| 19 } // namespace views | |
| 20 | |
| 21 class DesktopMediaPickerDialogView; | |
| 22 class DesktopMediaPickerViews; | |
| 23 class DesktopMediaSourceView; | |
| 24 | |
| 25 // View that shows a list of desktop media sources available from | |
| 26 // DesktopMediaList. | |
| 27 class DesktopMediaListView : public views::View, | |
| 28 public DesktopMediaListObserver { | |
| 29 public: | |
| 30 DesktopMediaListView(DesktopMediaPickerDialogView* parent, | |
| 31 std::unique_ptr<DesktopMediaList> media_list); | |
| 32 ~DesktopMediaListView() override; | |
| 33 | |
| 34 void StartUpdating(content::DesktopMediaID dialog_window_id); | |
| 35 | |
| 36 // Called by DesktopMediaSourceView when selection has changed. | |
| 37 void OnSelectionChanged(); | |
| 38 | |
| 39 // Called by DesktopMediaSourceView when a source has been double-clicked. | |
| 40 void OnDoubleClick(); | |
| 41 | |
| 42 // Returns currently selected source. | |
| 43 DesktopMediaSourceView* GetSelection(); | |
| 44 | |
| 45 // views::View overrides. | |
| 46 gfx::Size GetPreferredSize() const override; | |
| 47 void Layout() override; | |
| 48 bool OnKeyPressed(const ui::KeyEvent& event) override; | |
| 49 | |
| 50 private: | |
| 51 // DesktopMediaList::Observer interface | |
| 52 void OnSourceAdded(DesktopMediaList* list, int index) override; | |
| 53 void OnSourceRemoved(DesktopMediaList* list, int index) override; | |
| 54 void OnSourceMoved(DesktopMediaList* list, | |
| 55 int old_index, | |
| 56 int new_index) override; | |
| 57 void OnSourceNameChanged(DesktopMediaList* list, int index) override; | |
| 58 void OnSourceThumbnailChanged(DesktopMediaList* list, int index) override; | |
| 59 | |
| 60 // Accepts whatever happens to be selected right now. | |
| 61 void AcceptSelection(); | |
| 62 | |
| 63 DesktopMediaPickerDialogView* parent_; | |
| 64 std::unique_ptr<DesktopMediaList> media_list_; | |
| 65 base::WeakPtrFactory<DesktopMediaListView> weak_factory_; | |
| 66 | |
| 67 DISALLOW_COPY_AND_ASSIGN(DesktopMediaListView); | |
| 68 }; | |
| 69 | |
| 70 // View used for each item in DesktopMediaListView. Shows a single desktop media | |
| 71 // source as a thumbnail with the title under it. | |
| 72 class DesktopMediaSourceView : public views::View { | |
| 73 public: | |
| 74 DesktopMediaSourceView(DesktopMediaListView* parent, | |
| 75 content::DesktopMediaID source_id); | |
| 76 ~DesktopMediaSourceView() override; | |
| 77 | |
| 78 // Updates thumbnail and title from |source|. | |
| 79 void SetName(const base::string16& name); | |
| 80 void SetThumbnail(const gfx::ImageSkia& thumbnail); | |
| 81 | |
| 82 // Id for the source shown by this View. | |
| 83 const content::DesktopMediaID& source_id() const { return source_id_; } | |
| 84 | |
| 85 // Returns true if the source is selected. | |
| 86 bool is_selected() const { return selected_; } | |
| 87 | |
| 88 // views::View interface. | |
| 89 const char* GetClassName() const override; | |
| 90 void Layout() override; | |
| 91 views::View* GetSelectedViewForGroup(int group) override; | |
| 92 bool IsGroupFocusTraversable() const override; | |
| 93 void OnPaint(gfx::Canvas* canvas) override; | |
| 94 void OnFocus() override; | |
| 95 void OnBlur() override; | |
| 96 bool OnMousePressed(const ui::MouseEvent& event) override; | |
| 97 void OnGestureEvent(ui::GestureEvent* event) override; | |
| 98 | |
| 99 private: | |
| 100 // Updates selection state of the element. If |selected| is true then also | |
| 101 // calls SetSelected(false) for the source view that was selected before that | |
| 102 // (if any). | |
| 103 void SetSelected(bool selected); | |
| 104 | |
| 105 DesktopMediaListView* parent_; | |
| 106 content::DesktopMediaID source_id_; | |
| 107 | |
| 108 views::ImageView* image_view_; | |
| 109 views::Label* label_; | |
| 110 | |
| 111 bool selected_; | |
| 112 | |
| 113 DISALLOW_COPY_AND_ASSIGN(DesktopMediaSourceView); | |
| 114 }; | |
| 115 | |
| 116 // Dialog view used for DesktopMediaPickerViews. | |
| 117 class DesktopMediaPickerDialogView : public views::DialogDelegateView, | |
| 118 public views::TabbedPaneListener { | |
| 119 public: | |
| 120 DesktopMediaPickerDialogView(content::WebContents* parent_web_contents, | |
| 121 gfx::NativeWindow context, | |
| 122 DesktopMediaPickerViews* parent, | |
| 123 const base::string16& app_name, | |
| 124 const base::string16& target_name, | |
| 125 std::unique_ptr<DesktopMediaList> screen_list, | |
| 126 std::unique_ptr<DesktopMediaList> window_list, | |
| 127 std::unique_ptr<DesktopMediaList> tab_list, | |
| 128 bool request_audio); | |
| 129 ~DesktopMediaPickerDialogView() override; | |
| 130 | |
| 131 // Called by parent (DesktopMediaPickerViews) when it's destroyed. | |
| 132 void DetachParent(); | |
| 133 | |
| 134 // Called by DesktopMediaListView. | |
| 135 void OnSelectionChanged(); | |
| 136 void OnDoubleClick(); | |
| 137 | |
| 138 // views::TabbedPaneListener overrides. | |
| 139 void TabSelectedAt(int index) override; | |
| 140 | |
| 141 // views::View overrides. | |
| 142 gfx::Size GetPreferredSize() const override; | |
| 143 | |
| 144 // views::DialogDelegateView overrides. | |
| 145 ui::ModalType GetModalType() const override; | |
| 146 base::string16 GetWindowTitle() const override; | |
| 147 bool IsDialogButtonEnabled(ui::DialogButton button) const override; | |
| 148 views::View* GetInitiallyFocusedView() override; | |
| 149 bool ShouldDefaultButtonBeBlue() const override; | |
| 150 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; | |
| 151 View* CreateExtraView() override; | |
| 152 bool Accept() override; | |
| 153 void DeleteDelegate() override; | |
| 154 | |
| 155 void OnMediaListRowsChanged(); | |
| 156 | |
| 157 DesktopMediaListView* GetMediaListViewForTesting() const; | |
| 158 DesktopMediaSourceView* GetMediaSourceViewForTesting(int index) const; | |
| 159 views::Checkbox* GetCheckboxForTesting() const; | |
| 160 int GetIndexOfSourceTypeForTesting( | |
| 161 content::DesktopMediaID::Type source_type) const; | |
| 162 views::TabbedPane* GetPaneForTesting() const; | |
| 163 | |
| 164 private: | |
| 165 void SwitchSourceType(int index); | |
| 166 | |
| 167 DesktopMediaPickerViews* parent_; | |
| 168 | |
| 169 views::Label* description_label_; | |
| 170 | |
| 171 views::Checkbox* audio_share_checkbox_; | |
| 172 | |
| 173 views::TabbedPane* pane_; | |
| 174 std::vector<DesktopMediaListView*> list_views_; | |
| 175 std::vector<content::DesktopMediaID::Type> source_types_; | |
| 176 | |
| 177 DISALLOW_COPY_AND_ASSIGN(DesktopMediaPickerDialogView); | |
| 178 }; | |
| 179 | |
| 180 // Implementation of DesktopMediaPicker for Views. | |
| 181 class DesktopMediaPickerViews : public DesktopMediaPicker { | |
| 182 public: | |
| 183 DesktopMediaPickerViews(); | |
| 184 ~DesktopMediaPickerViews() override; | |
| 185 | |
| 186 void NotifyDialogResult(content::DesktopMediaID source); | |
| 187 | |
| 188 // DesktopMediaPicker overrides. | |
| 189 void Show(content::WebContents* web_contents, | |
| 190 gfx::NativeWindow context, | |
| 191 gfx::NativeWindow parent, | |
| 192 const base::string16& app_name, | |
| 193 const base::string16& target_name, | |
| 194 std::unique_ptr<DesktopMediaList> screen_list, | |
| 195 std::unique_ptr<DesktopMediaList> window_list, | |
| 196 std::unique_ptr<DesktopMediaList> tab_list, | |
| 197 bool request_audio, | |
| 198 const DoneCallback& done_callback) override; | |
| 199 | |
| 200 DesktopMediaPickerDialogView* GetDialogViewForTesting() const { | |
| 201 return dialog_; | |
| 202 } | |
| 203 | |
| 204 private: | |
| 205 DoneCallback callback_; | |
| 206 | |
| 207 // The |dialog_| is owned by the corresponding views::Widget instance. | |
| 208 // When DesktopMediaPickerViews is destroyed the |dialog_| is destroyed | |
| 209 // asynchronously by closing the widget. | |
| 210 DesktopMediaPickerDialogView* dialog_; | |
| 211 | |
| 212 DISALLOW_COPY_AND_ASSIGN(DesktopMediaPickerViews); | |
| 213 }; | |
| 214 | |
| 215 #endif // CHROME_BROWSER_UI_VIEWS_DESKTOP_CAPTURE_DESKTOP_MEDIA_PICKER_VIEWS_H_ | |
| OLD | NEW |