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.
5 #ifndef CHROME_BROWSER_UI_VIEWS_DESKTOP_MEDIA_PICKER_VIEWS_H_
6 #define CHROME_BROWSER_UI_VIEWS_DESKTOP_MEDIA_PICKER_VIEWS_H_
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"
17 class DesktopMediaPickerDialogView
;
18 class DesktopMediaPickerViews
;
19 class DesktopMediaSourceView
;
21 // View that shows a list of desktop media sources available from
23 class DesktopMediaListView
: public views::View
,
24 public DesktopMediaListObserver
{
26 DesktopMediaListView(DesktopMediaPickerDialogView
* parent
,
27 scoped_ptr
<DesktopMediaList
> media_list
);
28 virtual ~DesktopMediaListView();
30 void StartUpdating(content::DesktopMediaID::Id dialog_window_id
);
32 // Called by DesktopMediaSourceView when selection has changed.
33 void OnSelectionChanged();
35 // Called by DesktopMediaSourceView when a source has been double-clicked.
38 // Returns currently selected source.
39 DesktopMediaSourceView
* GetSelection();
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
;
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
;
54 // Accepts whatever happens to be selected right now.
55 void AcceptSelection();
57 DesktopMediaPickerDialogView
* parent_
;
58 scoped_ptr
<DesktopMediaList
> media_list_
;
59 base::WeakPtrFactory
<DesktopMediaListView
> weak_factory_
;
61 DISALLOW_COPY_AND_ASSIGN(DesktopMediaListView
);
64 // View used for each item in DesktopMediaListView. Shows a single desktop media
65 // source as a thumbnail with the title under it.
66 class DesktopMediaSourceView
: public views::View
{
68 DesktopMediaSourceView(DesktopMediaListView
* parent
,
69 content::DesktopMediaID source_id
);
70 virtual ~DesktopMediaSourceView();
72 // Updates thumbnail and title from |source|.
73 void SetName(const base::string16
& name
);
74 void SetThumbnail(const gfx::ImageSkia
& thumbnail
);
76 // Id for the source shown by this View.
77 const content::DesktopMediaID
& source_id() const { return source_id_
; }
79 // Returns true if the source is selected.
80 bool is_selected() const { return selected_
; }
82 // views::View interface.
83 virtual const char* GetClassName() const override
;
84 virtual void Layout() override
;
85 virtual views::View
* GetSelectedViewForGroup(int group
) override
;
86 virtual bool IsGroupFocusTraversable() const override
;
87 virtual void OnPaint(gfx::Canvas
* canvas
) override
;
88 virtual void OnFocus() override
;
89 virtual void OnBlur() override
;
90 virtual bool OnMousePressed(const ui::MouseEvent
& event
) override
;
91 virtual void OnGestureEvent(ui::GestureEvent
* event
) override
;
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
97 void SetSelected(bool selected
);
99 DesktopMediaListView
* parent_
;
100 content::DesktopMediaID source_id_
;
102 views::ImageView
* image_view_
;
103 views::Label
* label_
;
107 DISALLOW_COPY_AND_ASSIGN(DesktopMediaSourceView
);
110 // Dialog view used for DesktopMediaPickerViews.
111 class DesktopMediaPickerDialogView
: public views::DialogDelegateView
{
113 DesktopMediaPickerDialogView(content::WebContents
* parent_web_contents
,
114 gfx::NativeWindow context
,
115 DesktopMediaPickerViews
* parent
,
116 const base::string16
& app_name
,
117 const base::string16
& target_name
,
118 scoped_ptr
<DesktopMediaList
> media_list
);
119 virtual ~DesktopMediaPickerDialogView();
121 // Called by parent (DesktopMediaPickerViews) when it's destroyed.
124 // Called by DesktopMediaListView.
125 void OnSelectionChanged();
126 void OnDoubleClick();
128 // views::View overrides.
129 virtual gfx::Size
GetPreferredSize() const override
;
130 virtual void Layout() override
;
132 // views::DialogDelegateView overrides.
133 virtual ui::ModalType
GetModalType() const override
;
134 virtual base::string16
GetWindowTitle() const override
;
135 virtual bool IsDialogButtonEnabled(ui::DialogButton button
) const override
;
136 virtual base::string16
GetDialogButtonLabel(
137 ui::DialogButton button
) const override
;
138 virtual bool Accept() override
;
139 virtual void DeleteDelegate() override
;
141 void OnMediaListRowsChanged();
143 DesktopMediaSourceView
* GetMediaSourceViewForTesting(int index
) const;
146 DesktopMediaPickerViews
* parent_
;
147 base::string16 app_name_
;
149 views::Label
* label_
;
150 views::ScrollView
* scroll_view_
;
151 DesktopMediaListView
* list_view_
;
153 DISALLOW_COPY_AND_ASSIGN(DesktopMediaPickerDialogView
);
156 // Implementation of DesktopMediaPicker for Views.
157 class DesktopMediaPickerViews
: public DesktopMediaPicker
{
159 DesktopMediaPickerViews();
160 virtual ~DesktopMediaPickerViews();
162 void NotifyDialogResult(content::DesktopMediaID source
);
164 // DesktopMediaPicker overrides.
165 virtual void Show(content::WebContents
* web_contents
,
166 gfx::NativeWindow context
,
167 gfx::NativeWindow parent
,
168 const base::string16
& app_name
,
169 const base::string16
& target_name
,
170 scoped_ptr
<DesktopMediaList
> media_list
,
171 const DoneCallback
& done_callback
) override
;
173 DesktopMediaPickerDialogView
* GetDialogViewForTesting() const {
178 DoneCallback callback_
;
180 // The |dialog_| is owned by the corresponding views::Widget instance.
181 // When DesktopMediaPickerViews is destroyed the |dialog_| is destroyed
182 // asynchronously by closing the widget.
183 DesktopMediaPickerDialogView
* dialog_
;
185 DISALLOW_COPY_AND_ASSIGN(DesktopMediaPickerViews
);
188 #endif // CHROME_BROWSER_UI_VIEWS_DESKTOP_MEDIA_PICKER_VIEWS_H_