Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / desktop_media_picker_views.h
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 a list of desktop media sources available from
22 // DesktopMediaList.
23 class DesktopMediaListView : public views::View,
24                              public DesktopMediaListObserver {
25  public:
26   DesktopMediaListView(DesktopMediaPickerDialogView* parent,
27                        scoped_ptr<DesktopMediaList> media_list);
28   ~DesktopMediaListView() override;
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   gfx::Size GetPreferredSize() const override;
43   void Layout() override;
44   bool OnKeyPressed(const ui::KeyEvent& event) override;
45
46  private:
47   // DesktopMediaList::Observer interface
48   void OnSourceAdded(int index) override;
49   void OnSourceRemoved(int index) override;
50   void OnSourceMoved(int old_index, int new_index) override;
51   void OnSourceNameChanged(int index) override;
52   void OnSourceThumbnailChanged(int index) override;
53
54   // Accepts whatever happens to be selected right now.
55   void AcceptSelection();
56
57   DesktopMediaPickerDialogView* parent_;
58   scoped_ptr<DesktopMediaList> media_list_;
59   base::WeakPtrFactory<DesktopMediaListView> weak_factory_;
60
61   DISALLOW_COPY_AND_ASSIGN(DesktopMediaListView);
62 };
63
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 {
67  public:
68   DesktopMediaSourceView(DesktopMediaListView* parent,
69                          content::DesktopMediaID source_id);
70   ~DesktopMediaSourceView() override;
71
72   // Updates thumbnail and title from |source|.
73   void SetName(const base::string16& name);
74   void SetThumbnail(const gfx::ImageSkia& thumbnail);
75
76   // Id for the source shown by this View.
77   const content::DesktopMediaID& source_id() const { return source_id_; }
78
79   // Returns true if the source is selected.
80   bool is_selected() const { return selected_; }
81
82   // views::View interface.
83   const char* GetClassName() const override;
84   void Layout() override;
85   views::View* GetSelectedViewForGroup(int group) override;
86   bool IsGroupFocusTraversable() const override;
87   void OnPaint(gfx::Canvas* canvas) override;
88   void OnFocus() override;
89   void OnBlur() override;
90   bool OnMousePressed(const ui::MouseEvent& event) override;
91   void OnGestureEvent(ui::GestureEvent* event) override;
92
93  private:
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
96   // (if any).
97   void SetSelected(bool selected);
98
99   DesktopMediaListView* parent_;
100   content::DesktopMediaID source_id_;
101
102   views::ImageView* image_view_;
103   views::Label* label_;
104
105   bool selected_;
106
107   DISALLOW_COPY_AND_ASSIGN(DesktopMediaSourceView);
108 };
109
110 // Dialog view used for DesktopMediaPickerViews.
111 class DesktopMediaPickerDialogView : public views::DialogDelegateView {
112  public:
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   ~DesktopMediaPickerDialogView() override;
120
121   // Called by parent (DesktopMediaPickerViews) when it's destroyed.
122   void DetachParent();
123
124   // Called by DesktopMediaListView.
125   void OnSelectionChanged();
126   void OnDoubleClick();
127
128   // views::View overrides.
129   gfx::Size GetPreferredSize() const override;
130   void Layout() override;
131
132   // views::DialogDelegateView overrides.
133   ui::ModalType GetModalType() const override;
134   base::string16 GetWindowTitle() const override;
135   bool IsDialogButtonEnabled(ui::DialogButton button) const override;
136   base::string16 GetDialogButtonLabel(ui::DialogButton button) const override;
137   bool Accept() override;
138   void DeleteDelegate() override;
139
140   void OnMediaListRowsChanged();
141
142   DesktopMediaSourceView* GetMediaSourceViewForTesting(int index) const;
143
144  private:
145   DesktopMediaPickerViews* parent_;
146   base::string16 app_name_;
147
148   views::Label* label_;
149   views::ScrollView* scroll_view_;
150   DesktopMediaListView* list_view_;
151
152   DISALLOW_COPY_AND_ASSIGN(DesktopMediaPickerDialogView);
153 };
154
155 // Implementation of DesktopMediaPicker for Views.
156 class DesktopMediaPickerViews : public DesktopMediaPicker {
157  public:
158   DesktopMediaPickerViews();
159   ~DesktopMediaPickerViews() override;
160
161   void NotifyDialogResult(content::DesktopMediaID source);
162
163   // DesktopMediaPicker overrides.
164   void Show(content::WebContents* web_contents,
165             gfx::NativeWindow context,
166             gfx::NativeWindow parent,
167             const base::string16& app_name,
168             const base::string16& target_name,
169             scoped_ptr<DesktopMediaList> media_list,
170             const DoneCallback& done_callback) override;
171
172   DesktopMediaPickerDialogView* GetDialogViewForTesting() const {
173     return dialog_;
174   }
175
176  private:
177   DoneCallback callback_;
178
179   // The |dialog_| is owned by the corresponding views::Widget instance.
180   // When DesktopMediaPickerViews is destroyed the |dialog_| is destroyed
181   // asynchronously by closing the widget.
182   DesktopMediaPickerDialogView* dialog_;
183
184   DISALLOW_COPY_AND_ASSIGN(DesktopMediaPickerViews);
185 };
186
187 #endif  // CHROME_BROWSER_UI_VIEWS_DESKTOP_MEDIA_PICKER_VIEWS_H_