Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: chrome/browser/ui/views/desktop_media_picker_views.h

Issue 1962073002: Desktop Capture Picker New UI: Non Mac Structure Change (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Unittest Crash Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "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/window/dialog_delegate.h"
12
13 namespace views {
14 class ImageView;
15 class Label;
16 class Checkbox;
17 } // namespace views
18
19 class DesktopMediaPickerDialogView;
20 class DesktopMediaPickerViews;
21 class DesktopMediaSourceView;
22
23 // View that shows a list of desktop media sources available from
24 // DesktopMediaList.
25 class DesktopMediaListView : public views::View,
26 public DesktopMediaListObserver {
27 public:
28 DesktopMediaListView(DesktopMediaPickerDialogView* parent,
29 std::unique_ptr<DesktopMediaList> media_list);
30 ~DesktopMediaListView() override;
31
32 void StartUpdating(content::DesktopMediaID dialog_window_id);
33
34 // Called by DesktopMediaSourceView when selection has changed.
35 void OnSelectionChanged();
36
37 // Called by DesktopMediaSourceView when a source has been double-clicked.
38 void OnDoubleClick();
39
40 // Returns currently selected source.
41 DesktopMediaSourceView* GetSelection();
42
43 // views::View overrides.
44 gfx::Size GetPreferredSize() const override;
45 void Layout() override;
46 bool OnKeyPressed(const ui::KeyEvent& event) override;
47
48 private:
49 // DesktopMediaList::Observer interface
50 void OnSourceAdded(DesktopMediaList* list, int index) override;
51 void OnSourceRemoved(DesktopMediaList* list, int index) override;
52 void OnSourceMoved(DesktopMediaList* list,
53 int old_index,
54 int new_index) override;
55 void OnSourceNameChanged(DesktopMediaList* list, int index) override;
56 void OnSourceThumbnailChanged(DesktopMediaList* list, int index) override;
57
58 // Accepts whatever happens to be selected right now.
59 void AcceptSelection();
60
61 DesktopMediaPickerDialogView* parent_;
62 std::unique_ptr<DesktopMediaList> media_list_;
63 base::WeakPtrFactory<DesktopMediaListView> weak_factory_;
64
65 DISALLOW_COPY_AND_ASSIGN(DesktopMediaListView);
66 };
67
68 // View used for each item in DesktopMediaListView. Shows a single desktop media
69 // source as a thumbnail with the title under it.
70 class DesktopMediaSourceView : public views::View {
71 public:
72 DesktopMediaSourceView(DesktopMediaListView* parent,
73 content::DesktopMediaID source_id);
74 ~DesktopMediaSourceView() override;
75
76 // Updates thumbnail and title from |source|.
77 void SetName(const base::string16& name);
78 void SetThumbnail(const gfx::ImageSkia& thumbnail);
79
80 // Id for the source shown by this View.
81 const content::DesktopMediaID& source_id() const { return source_id_; }
82
83 // Returns true if the source is selected.
84 bool is_selected() const { return selected_; }
85
86 // views::View interface.
87 const char* GetClassName() const override;
88 void Layout() override;
89 views::View* GetSelectedViewForGroup(int group) override;
90 bool IsGroupFocusTraversable() const override;
91 void OnPaint(gfx::Canvas* canvas) override;
92 void OnFocus() override;
93 void OnBlur() override;
94 bool OnMousePressed(const ui::MouseEvent& event) override;
95 void OnGestureEvent(ui::GestureEvent* event) override;
96
97 private:
98 // Updates selection state of the element. If |selected| is true then also
99 // calls SetSelected(false) for the source view that was selected before that
100 // (if any).
101 void SetSelected(bool selected);
102
103 DesktopMediaListView* parent_;
104 content::DesktopMediaID source_id_;
105
106 views::ImageView* image_view_;
107 views::Label* label_;
108
109 bool selected_;
110
111 DISALLOW_COPY_AND_ASSIGN(DesktopMediaSourceView);
112 };
113
114 // Dialog view used for DesktopMediaPickerViews.
115 class DesktopMediaPickerDialogView : public views::DialogDelegateView {
116 public:
117 DesktopMediaPickerDialogView(content::WebContents* parent_web_contents,
118 gfx::NativeWindow context,
119 DesktopMediaPickerViews* parent,
120 const base::string16& app_name,
121 const base::string16& target_name,
122 std::unique_ptr<DesktopMediaList> screen_list,
123 std::unique_ptr<DesktopMediaList> window_list,
124 std::unique_ptr<DesktopMediaList> tab_list,
125 bool request_audio);
126 ~DesktopMediaPickerDialogView() override;
127
128 // Called by parent (DesktopMediaPickerViews) when it's destroyed.
129 void DetachParent();
130
131 // Called by DesktopMediaListView.
132 void OnSelectionChanged();
133 void OnDoubleClick();
134
135 // views::View overrides.
136 gfx::Size GetPreferredSize() const override;
137
138 // views::DialogDelegateView overrides.
139 ui::ModalType GetModalType() const override;
140 base::string16 GetWindowTitle() const override;
141 bool IsDialogButtonEnabled(ui::DialogButton button) const override;
142 views::View* GetInitiallyFocusedView() override;
143 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override;
144 bool Accept() override;
145 void DeleteDelegate() override;
146
147 void OnMediaListRowsChanged();
148
149 DesktopMediaListView* GetMediaListViewForTesting() const;
150 DesktopMediaSourceView* GetMediaSourceViewForTesting(int index) const;
151
152 private:
153 DesktopMediaPickerViews* parent_;
154 base::string16 app_name_;
155
156 views::Label* description_label_;
157
158 // |audio_share_checked_| records whether the user permits audio, when
159 // |audio_share_checkbox_| is disabled.
160 views::Checkbox* audio_share_checkbox_;
161 bool audio_share_checked_;
162
163 views::ScrollView* sources_scroll_view_;
164 DesktopMediaListView* sources_list_view_;
165
166 DISALLOW_COPY_AND_ASSIGN(DesktopMediaPickerDialogView);
167 };
168
169 // Implementation of DesktopMediaPicker for Views.
170 class DesktopMediaPickerViews : public DesktopMediaPicker {
171 public:
172 DesktopMediaPickerViews();
173 ~DesktopMediaPickerViews() override;
174
175 void NotifyDialogResult(content::DesktopMediaID source);
176
177 // DesktopMediaPicker overrides.
178 void Show(content::WebContents* web_contents,
179 gfx::NativeWindow context,
180 gfx::NativeWindow parent,
181 const base::string16& app_name,
182 const base::string16& target_name,
183 std::unique_ptr<DesktopMediaList> screen_list,
184 std::unique_ptr<DesktopMediaList> window_list,
185 std::unique_ptr<DesktopMediaList> tab_list,
186 bool request_audio,
187 const DoneCallback& done_callback) override;
188
189 DesktopMediaPickerDialogView* GetDialogViewForTesting() const {
190 return dialog_;
191 }
192
193 private:
194 DoneCallback callback_;
195
196 // The |dialog_| is owned by the corresponding views::Widget instance.
197 // When DesktopMediaPickerViews is destroyed the |dialog_| is destroyed
198 // asynchronously by closing the widget.
199 DesktopMediaPickerDialogView* dialog_;
200
201 DISALLOW_COPY_AND_ASSIGN(DesktopMediaPickerViews);
202 };
203
204 #endif // CHROME_BROWSER_UI_VIEWS_DESKTOP_MEDIA_PICKER_VIEWS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698