| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_BROWSER_UI_VIEWS_DESKTOP_CAPTURE_DESKTOP_MEDIA_PICKER_VIEWS_H_ | 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_ | 6 #define CHROME_BROWSER_UI_VIEWS_DESKTOP_CAPTURE_DESKTOP_MEDIA_PICKER_VIEWS_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "chrome/browser/media/desktop_media_list_observer.h" | |
| 10 #include "chrome/browser/media/desktop_media_picker.h" | 9 #include "chrome/browser/media/desktop_media_picker.h" |
| 10 #include "ui/views/controls/label.h" |
| 11 #include "ui/views/controls/tabbed_pane/tabbed_pane_listener.h" | 11 #include "ui/views/controls/tabbed_pane/tabbed_pane_listener.h" |
| 12 #include "ui/views/window/dialog_delegate.h" | 12 #include "ui/views/window/dialog_delegate.h" |
| 13 | 13 |
| 14 namespace views { | 14 namespace views { |
| 15 class ImageView; | |
| 16 class Label; | |
| 17 class Checkbox; | 15 class Checkbox; |
| 18 class TabbedPane; | 16 class TabbedPane; |
| 19 } // namespace views | 17 } // namespace views |
| 20 | 18 |
| 21 class DesktopMediaPickerDialogView; | 19 class DesktopMediaListView; |
| 20 class DesktopMediaSourceView; |
| 22 class DesktopMediaPickerViews; | 21 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 | 22 |
| 116 // Dialog view used for DesktopMediaPickerViews. | 23 // Dialog view used for DesktopMediaPickerViews. |
| 117 class DesktopMediaPickerDialogView : public views::DialogDelegateView, | 24 class DesktopMediaPickerDialogView : public views::DialogDelegateView, |
| 118 public views::TabbedPaneListener { | 25 public views::TabbedPaneListener { |
| 119 public: | 26 public: |
| 120 DesktopMediaPickerDialogView(content::WebContents* parent_web_contents, | 27 DesktopMediaPickerDialogView(content::WebContents* parent_web_contents, |
| 121 gfx::NativeWindow context, | 28 gfx::NativeWindow context, |
| 122 DesktopMediaPickerViews* parent, | 29 DesktopMediaPickerViews* parent, |
| 123 const base::string16& app_name, | 30 const base::string16& app_name, |
| 124 const base::string16& target_name, | 31 const base::string16& target_name, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 154 | 61 |
| 155 void OnMediaListRowsChanged(); | 62 void OnMediaListRowsChanged(); |
| 156 | 63 |
| 157 DesktopMediaListView* GetMediaListViewForTesting() const; | 64 DesktopMediaListView* GetMediaListViewForTesting() const; |
| 158 DesktopMediaSourceView* GetMediaSourceViewForTesting(int index) const; | 65 DesktopMediaSourceView* GetMediaSourceViewForTesting(int index) const; |
| 159 views::Checkbox* GetCheckboxForTesting() const; | 66 views::Checkbox* GetCheckboxForTesting() const; |
| 160 int GetIndexOfSourceTypeForTesting( | 67 int GetIndexOfSourceTypeForTesting( |
| 161 content::DesktopMediaID::Type source_type) const; | 68 content::DesktopMediaID::Type source_type) const; |
| 162 views::TabbedPane* GetPaneForTesting() const; | 69 views::TabbedPane* GetPaneForTesting() const; |
| 163 | 70 |
| 71 static const int kThumbnailWidth = 160; |
| 72 static const int kThumbnailHeight = 100; |
| 73 static const int kThumbnailMargin = 10; |
| 74 static const int kLabelHeight = 40; |
| 75 static const int kListItemWidth = kThumbnailMargin * 2 + kThumbnailWidth; |
| 76 static const int kListItemHeight = |
| 77 kThumbnailMargin * 2 + kThumbnailHeight + kLabelHeight; |
| 78 static const int kListColumns = 3; |
| 79 static const int kTotalListWidth = kListColumns * kListItemWidth; |
| 80 |
| 164 private: | 81 private: |
| 165 void SwitchSourceType(int index); | 82 void SwitchSourceType(int index); |
| 166 | 83 |
| 167 DesktopMediaPickerViews* parent_; | 84 DesktopMediaPickerViews* parent_; |
| 168 | 85 |
| 169 views::Label* description_label_; | 86 views::Label* description_label_; |
| 170 | 87 |
| 171 views::Checkbox* audio_share_checkbox_; | 88 views::Checkbox* audio_share_checkbox_; |
| 172 | 89 |
| 173 views::TabbedPane* pane_; | 90 views::TabbedPane* pane_; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 | 123 |
| 207 // The |dialog_| is owned by the corresponding views::Widget instance. | 124 // The |dialog_| is owned by the corresponding views::Widget instance. |
| 208 // When DesktopMediaPickerViews is destroyed the |dialog_| is destroyed | 125 // When DesktopMediaPickerViews is destroyed the |dialog_| is destroyed |
| 209 // asynchronously by closing the widget. | 126 // asynchronously by closing the widget. |
| 210 DesktopMediaPickerDialogView* dialog_; | 127 DesktopMediaPickerDialogView* dialog_; |
| 211 | 128 |
| 212 DISALLOW_COPY_AND_ASSIGN(DesktopMediaPickerViews); | 129 DISALLOW_COPY_AND_ASSIGN(DesktopMediaPickerViews); |
| 213 }; | 130 }; |
| 214 | 131 |
| 215 #endif // CHROME_BROWSER_UI_VIEWS_DESKTOP_CAPTURE_DESKTOP_MEDIA_PICKER_VIEWS_H_ | 132 #endif // CHROME_BROWSER_UI_VIEWS_DESKTOP_CAPTURE_DESKTOP_MEDIA_PICKER_VIEWS_H_ |
| OLD | NEW |