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 DesktopMediaPickerDialogView* parent_;
55 scoped_ptr<DesktopMediaList> media_list_;
57 DISALLOW_COPY_AND_ASSIGN(DesktopMediaListView);
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 {
64 DesktopMediaSourceView(DesktopMediaListView* parent,
65 content::DesktopMediaID source_id);
66 virtual ~DesktopMediaSourceView();
68 // Updates thumbnail and title from |source|.
69 void SetName(const base::string16& name);
70 void SetThumbnail(const gfx::ImageSkia& thumbnail);
72 // Id for the source shown by this View.
73 const content::DesktopMediaID& source_id() const { return source_id_; }
75 // Returns true if the source is selected.
76 bool is_selected() const { return selected_; }
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;
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
93 void SetSelected(bool selected);
95 DesktopMediaListView* parent_;
96 content::DesktopMediaID source_id_;
98 views::ImageView* image_view_;
103 DISALLOW_COPY_AND_ASSIGN(DesktopMediaSourceView);
106 // Dialog view used for DesktopMediaPickerViews.
107 class DesktopMediaPickerDialogView : public views::DialogDelegateView {
109 DesktopMediaPickerDialogView(content::WebContents* parent_web_contents,
110 gfx::NativeWindow context,
111 DesktopMediaPickerViews* parent,
112 const base::string16& app_name,
113 const base::string16& target_name,
114 scoped_ptr<DesktopMediaList> media_list);
115 virtual ~DesktopMediaPickerDialogView();
117 // Called by parent (DesktopMediaPickerViews) when it's destroyed.
120 // Called by DesktopMediaListView.
121 void OnSelectionChanged();
122 void OnDoubleClick();
124 // views::View overrides.
125 virtual gfx::Size GetPreferredSize() const OVERRIDE;
126 virtual void Layout() OVERRIDE;
128 // views::DialogDelegateView overrides.
129 virtual ui::ModalType GetModalType() const OVERRIDE;
130 virtual base::string16 GetWindowTitle() const OVERRIDE;
131 virtual bool IsDialogButtonEnabled(ui::DialogButton button) const OVERRIDE;
132 virtual base::string16 GetDialogButtonLabel(
133 ui::DialogButton button) const OVERRIDE;
134 virtual bool Accept() OVERRIDE;
135 virtual void DeleteDelegate() OVERRIDE;
137 void OnMediaListRowsChanged();
139 DesktopMediaSourceView* GetMediaSourceViewForTesting(int index) const;
142 DesktopMediaPickerViews* parent_;
143 base::string16 app_name_;
145 views::Label* label_;
146 views::ScrollView* scroll_view_;
147 DesktopMediaListView* list_view_;
149 DISALLOW_COPY_AND_ASSIGN(DesktopMediaPickerDialogView);
152 // Implementation of DesktopMediaPicker for Views.
153 class DesktopMediaPickerViews : public DesktopMediaPicker {
155 DesktopMediaPickerViews();
156 virtual ~DesktopMediaPickerViews();
158 void NotifyDialogResult(content::DesktopMediaID source);
160 // DesktopMediaPicker overrides.
161 virtual void Show(content::WebContents* web_contents,
162 gfx::NativeWindow context,
163 gfx::NativeWindow parent,
164 const base::string16& app_name,
165 const base::string16& target_name,
166 scoped_ptr<DesktopMediaList> media_list,
167 const DoneCallback& done_callback) OVERRIDE;
169 DesktopMediaPickerDialogView* GetDialogViewForTesting() const {
174 DoneCallback callback_;
176 // The |dialog_| is owned by the corresponding views::Widget instance.
177 // When DesktopMediaPickerViews is destroyed the |dialog_| is destroyed
178 // asynchronously by closing the widget.
179 DesktopMediaPickerDialogView* dialog_;
181 DISALLOW_COPY_AND_ASSIGN(DesktopMediaPickerViews);
184 #endif // CHROME_BROWSER_UI_VIEWS_DESKTOP_MEDIA_PICKER_VIEWS_H_