Chromium Code Reviews| 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_MEDIA_PICKER_VIEWS_H_ | |
| 6 #define CHROME_BROWSER_UI_VIEWS_DESKTOP_MEDIA_PICKER_VIEWS_H_ | |
| 7 | |
| 8 #include "chrome/browser/media/desktop_media_list_observer.h" | |
| 9 #include "chrome/browser/media/desktop_media_picker.h" | |
| 10 #include "ui/views/window/dialog_delegate.h" | |
| 11 | |
| 12 namespace views { | |
| 13 class ImageView; | |
| 14 class Label; | |
| 15 } // namespace views | |
| 16 | |
| 17 class DesktopMediaPickerDialogView; | |
| 18 class DesktopMediaPickerViews; | |
| 19 class DesktopMediaSourceView; | |
| 20 | |
| 21 // View that shows list of desktop media sources available from | |
|
msw
2014/07/15 03:29:56
nit: "a list"
| |
| 22 // DesktopMediaList. | |
| 23 class DesktopMediaListView : public views::View, | |
| 24 public DesktopMediaListObserver { | |
| 25 public: | |
| 26 DesktopMediaListView(DesktopMediaPickerDialogView* parent, | |
| 27 scoped_ptr<DesktopMediaList> media_list); | |
| 28 virtual ~DesktopMediaListView(); | |
| 29 | |
| 30 void StartUpdating(content::DesktopMediaID::Id dialog_window_id); | |
| 31 | |
| 32 // Called by DesktopMediaSourceView when selection has changed. | |
| 33 void OnSelectionChanged(); | |
| 34 | |
| 35 // Called by DesktopMediaSourceView when a source has been double-clicked. | |
| 36 void OnDoubleClick(); | |
| 37 | |
| 38 // Returns currently selected source. | |
| 39 DesktopMediaSourceView* GetSelection(); | |
| 40 | |
| 41 // views::View overrides. | |
| 42 virtual gfx::Size GetPreferredSize() const OVERRIDE; | |
| 43 virtual void Layout() OVERRIDE; | |
| 44 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; | |
| 45 | |
| 46 private: | |
| 47 // DesktopMediaList::Observer interface | |
| 48 virtual void OnSourceAdded(int index) OVERRIDE; | |
| 49 virtual void OnSourceRemoved(int index) OVERRIDE; | |
| 50 virtual void OnSourceMoved(int old_index, int new_index) OVERRIDE; | |
| 51 virtual void OnSourceNameChanged(int index) OVERRIDE; | |
| 52 virtual void OnSourceThumbnailChanged(int index) OVERRIDE; | |
| 53 | |
| 54 DesktopMediaPickerDialogView* parent_; | |
| 55 scoped_ptr<DesktopMediaList> media_list_; | |
| 56 | |
| 57 DISALLOW_COPY_AND_ASSIGN(DesktopMediaListView); | |
| 58 }; | |
| 59 | |
| 60 // View used for each item in DesktopMediaListView. Shows a single desktop media | |
| 61 // source as a thumbnail with the title under it. | |
| 62 class DesktopMediaSourceView : public views::View { | |
| 63 public: | |
| 64 DesktopMediaSourceView(DesktopMediaListView* parent, | |
| 65 content::DesktopMediaID source_id); | |
| 66 virtual ~DesktopMediaSourceView(); | |
| 67 | |
| 68 // Updates thumbnail and title from |source|. | |
| 69 void SetName(const base::string16& name); | |
| 70 void SetThumbnail(const gfx::ImageSkia& thumbnail); | |
| 71 | |
| 72 // Id for the source shown by this View. | |
| 73 const content::DesktopMediaID& source_id() const { return source_id_; } | |
| 74 | |
| 75 // Returns true if the source is selected. | |
| 76 bool is_selected() const { return selected_; } | |
| 77 | |
| 78 // views::View interface. | |
| 79 virtual const char* GetClassName() const OVERRIDE; | |
| 80 virtual void Layout() OVERRIDE; | |
| 81 virtual views::View* GetSelectedViewForGroup(int group) OVERRIDE; | |
| 82 virtual bool IsGroupFocusTraversable() const OVERRIDE; | |
| 83 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | |
| 84 virtual void OnFocus() OVERRIDE; | |
| 85 virtual void OnBlur() OVERRIDE; | |
| 86 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; | |
| 87 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; | |
| 88 | |
| 89 private: | |
| 90 // Updates selection state of the element. If |selected| is true then also | |
| 91 // calls SetSelected(false) for the source view that was selected before that | |
| 92 // (if any). | |
| 93 void SetSelected(bool selected); | |
| 94 | |
| 95 DesktopMediaListView* parent_; | |
| 96 content::DesktopMediaID source_id_; | |
| 97 | |
| 98 views::ImageView* image_view_; | |
| 99 views::Label* label_; | |
| 100 | |
| 101 bool selected_; | |
| 102 | |
| 103 DISALLOW_COPY_AND_ASSIGN(DesktopMediaSourceView); | |
| 104 }; | |
| 105 | |
| 106 // Dialog view used for DesktopMediaPickerViews. | |
| 107 class DesktopMediaPickerDialogView : public views::DialogDelegateView { | |
| 108 public: | |
| 109 DesktopMediaPickerDialogView(content::WebContents* parent_web_contents, | |
| 110 gfx::NativeWindow context, | |
| 111 gfx::NativeWindow parent_window, | |
| 112 DesktopMediaPickerViews* parent, | |
| 113 const base::string16& app_name, | |
| 114 const base::string16& target_name, | |
| 115 scoped_ptr<DesktopMediaList> media_list); | |
| 116 virtual ~DesktopMediaPickerDialogView(); | |
| 117 | |
| 118 // Called by parent (DesktopMediaPickerViews) when it's destroyed. | |
| 119 void DetachParent(); | |
| 120 | |
| 121 // Called by DesktopMediaListView. | |
| 122 void OnSelectionChanged(); | |
| 123 void OnDoubleClick(); | |
| 124 | |
| 125 // views::View overrides. | |
| 126 virtual gfx::Size GetPreferredSize() const OVERRIDE; | |
| 127 virtual void Layout() OVERRIDE; | |
| 128 | |
| 129 // views::DialogDelegateView overrides. | |
| 130 virtual ui::ModalType GetModalType() const OVERRIDE; | |
| 131 virtual base::string16 GetWindowTitle() const OVERRIDE; | |
| 132 virtual bool IsDialogButtonEnabled(ui::DialogButton button) const OVERRIDE; | |
| 133 virtual base::string16 GetDialogButtonLabel( | |
| 134 ui::DialogButton button) const OVERRIDE; | |
| 135 virtual bool Accept() OVERRIDE; | |
| 136 virtual void DeleteDelegate() OVERRIDE; | |
| 137 | |
| 138 void OnMediaListRowsChanged(); | |
| 139 | |
| 140 DesktopMediaSourceView* GetMediaSourceViewForTesting(int index) const; | |
| 141 | |
| 142 private: | |
| 143 DesktopMediaPickerViews* parent_; | |
| 144 base::string16 app_name_; | |
| 145 | |
| 146 views::Label* label_; | |
| 147 views::ScrollView* scroll_view_; | |
| 148 DesktopMediaListView* list_view_; | |
| 149 | |
| 150 DISALLOW_COPY_AND_ASSIGN(DesktopMediaPickerDialogView); | |
| 151 }; | |
| 152 | |
| 153 // Implementation of DesktopMediaPicker for Views. | |
| 154 class DesktopMediaPickerViews : public DesktopMediaPicker { | |
| 155 public: | |
| 156 DesktopMediaPickerViews(); | |
| 157 virtual ~DesktopMediaPickerViews(); | |
| 158 | |
| 159 void NotifyDialogResult(content::DesktopMediaID source); | |
| 160 | |
| 161 // DesktopMediaPicker overrides. | |
| 162 virtual void Show(content::WebContents* web_contents, | |
| 163 gfx::NativeWindow context, | |
| 164 gfx::NativeWindow parent, | |
| 165 const base::string16& app_name, | |
| 166 const base::string16& target_name, | |
| 167 scoped_ptr<DesktopMediaList> media_list, | |
| 168 const DoneCallback& done_callback) OVERRIDE; | |
| 169 | |
| 170 DesktopMediaPickerDialogView* GetDialogViewForTesting() const { | |
| 171 return dialog_; | |
| 172 } | |
| 173 | |
| 174 private: | |
| 175 DoneCallback callback_; | |
| 176 | |
| 177 // The |dialog_| is owned by the corresponding views::Widget instance. | |
| 178 // When DesktopMediaPickerViews is destroyed the |dialog_| is destroyed | |
| 179 // asynchronously by closing the widget. | |
| 180 DesktopMediaPickerDialogView* dialog_; | |
| 181 | |
| 182 DISALLOW_COPY_AND_ASSIGN(DesktopMediaPickerViews); | |
| 183 }; | |
| 184 | |
| 185 #endif // CHROME_BROWSER_UI_VIEWS_DESKTOP_MEDIA_PICKER_VIEWS_H_ | |
| OLD | NEW |