Commit 6a77e6af authored by Peter Kasting's avatar Peter Kasting Committed by Chromium LUCI CQ

Add metadata to classes in c/b/ui/views/desktop_capture.

Bug: 1159562
Change-Id: I4f81a69f44b0e0cc9efb4f75b4adbce97d7e5dc8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2630289
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Allen Bauer <kylixrd@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarAllen Bauer <kylixrd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843776}
parent 25a9714b
......@@ -21,6 +21,7 @@
#include "ui/accessibility/ax_enums.mojom.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/views/view_utils.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "ui/aura/window.h"
......@@ -54,8 +55,7 @@ gfx::ImageSkia LoadDefaultIcon(aura::Window* window) {
#endif
DesktopMediaSourceView* AsDesktopMediaSourceView(views::View* view) {
DCHECK_EQ(DesktopMediaSourceView::kDesktopMediaSourceViewClassName,
view->GetClassName());
DCHECK(views::IsViewClass<DesktopMediaSourceView>(view));
return static_cast<DesktopMediaSourceView*>(view);
}
......@@ -192,7 +192,7 @@ void DesktopMediaListView::OnSourceRemoved(size_t index) {
DesktopMediaSourceView* view = AsDesktopMediaSourceView(children()[index]);
DCHECK(view);
bool was_selected = view->is_selected();
bool was_selected = view->GetSelected();
RemoveChildView(view);
delete view;
......@@ -239,7 +239,7 @@ void DesktopMediaListView::SetStyle(DesktopMediaSourceViewStyle* style) {
DesktopMediaSourceView* DesktopMediaListView::GetSelectedView() {
const auto i = std::find_if(
children().cbegin(), children().cend(),
[](View* v) { return AsDesktopMediaSourceView(v)->is_selected(); });
[](View* v) { return AsDesktopMediaSourceView(v)->GetSelected(); });
return (i == children().cend()) ? nullptr : AsDesktopMediaSourceView(*i);
}
......
......@@ -37,6 +37,7 @@
#include "ui/views/controls/scroll_view.h"
#include "ui/views/controls/tabbed_pane/tabbed_pane.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/metadata/metadata_impl_macros.h"
#include "ui/views/widget/widget.h"
#if defined(USE_AURA)
......@@ -310,10 +311,6 @@ gfx::Size DesktopMediaPickerDialogView::CalculatePreferredSize() const {
return gfx::Size(kDialogViewWidth, GetHeightForWidth(kDialogViewWidth));
}
const char* DesktopMediaPickerDialogView::GetClassName() const {
return "DesktopMediaPickerDialogView";
}
ui::ModalType DesktopMediaPickerDialogView::GetModalType() const {
return modality_;
}
......@@ -449,6 +446,9 @@ void DesktopMediaPickerDialogView::OnSourceListLayoutChanged() {
GetWidget()->CenterWindow(new_size);
}
BEGIN_METADATA(DesktopMediaPickerDialogView, views::DialogDelegateView)
END_METADATA
constexpr bool DesktopMediaPickerViews::kScreenAudioShareSupportedOnPlatform;
DesktopMediaPickerViews::DesktopMediaPickerViews() : dialog_(nullptr) {}
......
......@@ -5,12 +5,12 @@
#ifndef CHROME_BROWSER_UI_VIEWS_DESKTOP_CAPTURE_DESKTOP_MEDIA_PICKER_VIEWS_H_
#define CHROME_BROWSER_UI_VIEWS_DESKTOP_CAPTURE_DESKTOP_MEDIA_PICKER_VIEWS_H_
#include "base/macros.h"
#include "build/build_config.h"
#include "chrome/browser/media/webrtc/desktop_media_picker.h"
#include "chrome/browser/ui/views/desktop_capture/desktop_media_list_controller.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/tabbed_pane/tabbed_pane_listener.h"
#include "ui/views/metadata/metadata_header_macros.h"
#include "ui/views/window/dialog_delegate.h"
namespace views {
......@@ -26,10 +26,14 @@ class DesktopMediaPickerViews;
class DesktopMediaPickerDialogView : public views::DialogDelegateView,
public views::TabbedPaneListener {
public:
METADATA_HEADER(DesktopMediaPickerDialogView);
DesktopMediaPickerDialogView(
const DesktopMediaPicker::Params& params,
DesktopMediaPickerViews* parent,
std::vector<std::unique_ptr<DesktopMediaList>> source_lists);
DesktopMediaPickerDialogView(const DesktopMediaPickerDialogView&) = delete;
DesktopMediaPickerDialogView& operator=(const DesktopMediaPickerDialogView&) =
delete;
~DesktopMediaPickerDialogView() override;
// Called by parent (DesktopMediaPickerViews) when it's destroyed.
......@@ -47,7 +51,6 @@ class DesktopMediaPickerDialogView : public views::DialogDelegateView,
// views::DialogDelegateView:
gfx::Size CalculatePreferredSize() const override;
const char* GetClassName() const override;
ui::ModalType GetModalType() const override;
base::string16 GetWindowTitle() const override;
bool IsDialogButtonEnabled(ui::DialogButton button) const override;
......@@ -76,8 +79,6 @@ class DesktopMediaPickerDialogView : public views::DialogDelegateView,
std::vector<content::DesktopMediaID::Type> source_types_;
base::Optional<content::DesktopMediaID> accepted_source_;
DISALLOW_COPY_AND_ASSIGN(DesktopMediaPickerDialogView);
};
// Implementation of DesktopMediaPicker for Views.
......@@ -94,6 +95,8 @@ class DesktopMediaPickerViews : public DesktopMediaPicker {
#endif
DesktopMediaPickerViews();
DesktopMediaPickerViews(const DesktopMediaPickerViews&) = delete;
DesktopMediaPickerViews& operator=(const DesktopMediaPickerViews&) = delete;
~DesktopMediaPickerViews() override;
void NotifyDialogResult(content::DesktopMediaID source);
......@@ -116,8 +119,6 @@ class DesktopMediaPickerViews : public DesktopMediaPicker {
// 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_CAPTURE_DESKTOP_MEDIA_PICKER_VIEWS_H_
......@@ -15,6 +15,8 @@
#include "ui/views/controls/focus_ring.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/metadata/metadata_impl_macros.h"
#include "ui/views/view_utils.h"
using content::DesktopMediaID;
......@@ -43,7 +45,6 @@ DesktopMediaSourceView::DesktopMediaSourceView(
DesktopMediaSourceViewStyle style)
: parent_(parent),
source_id_(source_id),
style_(style),
selected_(false) {
AddChildView(icon_view_);
AddChildView(image_view_);
......@@ -51,15 +52,12 @@ DesktopMediaSourceView::DesktopMediaSourceView(
icon_view_->SetCanProcessEventsWithinSubtree(false);
image_view_->SetCanProcessEventsWithinSubtree(false);
SetFocusBehavior(FocusBehavior::ALWAYS);
SetStyle(style_);
SetStyle(style);
views::FocusRing::Install(this);
}
DesktopMediaSourceView::~DesktopMediaSourceView() {}
const char DesktopMediaSourceView::kDesktopMediaSourceViewClassName[] =
"DesktopMediaPicker_DesktopMediaSourceView";
void DesktopMediaSourceView::SetName(const base::string16& name) {
label_->SetText(name);
}
......@@ -83,8 +81,7 @@ void DesktopMediaSourceView::SetSelected(bool selected) {
parent()->GetViewsInGroup(GetGroup(), &neighbours);
for (auto i(neighbours.begin()); i != neighbours.end(); ++i) {
if (*i != this) {
DCHECK_EQ((*i)->GetClassName(),
DesktopMediaSourceView::kDesktopMediaSourceViewClassName);
DCHECK(views::IsViewClass<DesktopMediaSourceView>(*i));
DesktopMediaSourceView* source_view =
static_cast<DesktopMediaSourceView*>(*i);
source_view->SetSelected(false);
......@@ -103,20 +100,19 @@ void DesktopMediaSourceView::SetSelected(bool selected) {
gfx::Font::Weight::NORMAL));
}
SchedulePaint();
OnPropertyChanged(&selected_, views::kPropertyEffectsPaint);
}
const char* DesktopMediaSourceView::GetClassName() const {
return DesktopMediaSourceView::kDesktopMediaSourceViewClassName;
void DesktopMediaSourceView::SetStyle(DesktopMediaSourceViewStyle style) {
image_view_->SetBoundsRect(style.image_rect);
icon_view_->SetBoundsRect(style.icon_rect);
icon_view_->SetImageSize(style.icon_rect.size());
label_->SetBoundsRect(style.label_rect);
label_->SetHorizontalAlignment(style.text_alignment);
}
void DesktopMediaSourceView::SetStyle(DesktopMediaSourceViewStyle style) {
style_ = style;
image_view_->SetBoundsRect(style_.image_rect);
icon_view_->SetBoundsRect(style_.icon_rect);
icon_view_->SetImageSize(style_.icon_rect.size());
label_->SetBoundsRect(style_.label_rect);
label_->SetHorizontalAlignment(style_.text_alignment);
bool DesktopMediaSourceView::GetSelected() const {
return selected_;
}
views::View* DesktopMediaSourceView::GetSelectedViewForGroup(int group) {
......@@ -126,8 +122,7 @@ views::View* DesktopMediaSourceView::GetSelectedViewForGroup(int group) {
return nullptr;
for (auto i(neighbours.begin()); i != neighbours.end(); ++i) {
DCHECK_EQ((*i)->GetClassName(),
DesktopMediaSourceView::kDesktopMediaSourceViewClassName);
DCHECK(views::IsViewClass<DesktopMediaSourceView>(*i));
DesktopMediaSourceView* source_view =
static_cast<DesktopMediaSourceView*>(*i);
if (source_view->selected_)
......@@ -164,3 +159,7 @@ void DesktopMediaSourceView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
node_data->role = ax::mojom::Role::kButton;
node_data->SetName(label_->GetText());
}
BEGIN_METADATA(DesktopMediaSourceView, views::View)
ADD_PROPERTY_METADATA(bool, Selected)
END_METADATA
......@@ -10,6 +10,7 @@
#include "ui/views/controls/focus_ring.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/metadata/metadata_header_macros.h"
#include "ui/views/view.h"
namespace views {
......@@ -53,9 +54,12 @@ struct DesktopMediaSourceViewStyle {
// source as a thumbnail with the title under it.
class DesktopMediaSourceView : public views::View {
public:
METADATA_HEADER(DesktopMediaSourceView);
DesktopMediaSourceView(DesktopMediaListView* parent,
content::DesktopMediaID source_id,
DesktopMediaSourceViewStyle style);
DesktopMediaSourceView(const DesktopMediaSourceView&) = delete;
DesktopMediaSourceView& operator=(const DesktopMediaSourceView&) = delete;
~DesktopMediaSourceView() override;
// Used to update the style when the number of available items changes.
......@@ -70,10 +74,9 @@ class DesktopMediaSourceView : public views::View {
const content::DesktopMediaID& source_id() const { return source_id_; }
// Returns true if the source is selected.
bool is_selected() const { return selected_; }
bool GetSelected() const;
// views::View interface.
const char* GetClassName() const override;
views::View* GetSelectedViewForGroup(int group) override;
bool IsGroupFocusTraversable() const override;
void OnFocus() override;
......@@ -81,28 +84,20 @@ class DesktopMediaSourceView : public views::View {
void OnGestureEvent(ui::GestureEvent* event) override;
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
static const char kDesktopMediaSourceViewClassName[];
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);
// Updates hover state of the element, and the appearance.
void SetHovered(bool hovered);
DesktopMediaListView* parent_;
content::DesktopMediaID source_id_;
DesktopMediaSourceViewStyle style_;
views::ImageView* icon_view_ = new views::ImageView;
views::ImageView* image_view_ = new views::ImageView;
views::Label* label_ = new views::Label;
bool selected_;
DISALLOW_COPY_AND_ASSIGN(DesktopMediaSourceView);
};
#endif // CHROME_BROWSER_UI_VIEWS_DESKTOP_CAPTURE_DESKTOP_MEDIA_SOURCE_VIEW_H_
......@@ -13,6 +13,7 @@
#include "ui/views/controls/table/table_view.h"
#include "ui/views/controls/table/table_view_observer.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/metadata/metadata_impl_macros.h"
#include "ui/views/view.h"
namespace {
......@@ -147,10 +148,6 @@ DesktopMediaTabList::~DesktopMediaTabList() {
child_->SetModel(nullptr);
}
const char* DesktopMediaTabList::GetClassName() const {
return "DesktopMediaTabList";
}
gfx::Size DesktopMediaTabList::CalculatePreferredSize() const {
// The picker should have a fixed height of 10 rows.
return gfx::Size(0, child_->GetRowHeight() * 10);
......@@ -176,3 +173,6 @@ DesktopMediaListController::SourceListListener*
DesktopMediaTabList::GetSourceListListener() {
return model_.get();
}
BEGIN_METADATA(DesktopMediaTabList, DesktopMediaListController::ListView)
END_METADATA
......@@ -6,6 +6,7 @@
#define CHROME_BROWSER_UI_VIEWS_DESKTOP_CAPTURE_DESKTOP_MEDIA_TAB_LIST_H_
#include "chrome/browser/ui/views/desktop_capture/desktop_media_list_controller.h"
#include "ui/views/metadata/metadata_header_macros.h"
namespace views {
class TableView;
......@@ -37,12 +38,14 @@ class TabListViewObserver;
// TableView
class DesktopMediaTabList : public DesktopMediaListController::ListView {
public:
METADATA_HEADER(DesktopMediaTabList);
DesktopMediaTabList(DesktopMediaListController* controller,
const base::string16& accessible_name);
DesktopMediaTabList(const DesktopMediaTabList&) = delete;
DesktopMediaTabList& operator=(const DesktopMediaTabList&) = delete;
~DesktopMediaTabList() override;
// views::View:
const char* GetClassName() const override;
gfx::Size CalculatePreferredSize() const override;
int GetHeightForWidth(int width) const override;
......@@ -54,9 +57,6 @@ class DesktopMediaTabList : public DesktopMediaListController::ListView {
private:
friend class DesktopMediaPickerViewsTestApi;
DesktopMediaTabList(const DesktopMediaTabList&) = delete;
DesktopMediaTabList operator=(const DesktopMediaTabList&) = delete;
DesktopMediaListController* controller_;
std::unique_ptr<TabListModel> model_;
std::unique_ptr<TabListViewObserver> view_observer_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment