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