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