Commit d76a70f7 authored by Takumi Fujimoto's avatar Takumi Fujimoto Committed by Commit Bot

[Cast UI] Make the entire sink button a stop button

Instead of having a stop button contained in the sink button, make
the entire sink button clickable when the sink state is CONNECTED,

The stop button worked by activating the entire button, so no extra
logic is necessary to make the sink button send the stop request.

Focusing on the sink button (tab or mouse hover) changes the status text
to "Stop casting".

Bug: 900012
Change-Id: I6abce70735bf7920e314063a3326268b54d27b7c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1497632Reviewed-by: default avatarBret Sepulveda <bsep@chromium.org>
Commit-Queue: Takumi Fujimoto <takumif@chromium.org>
Cr-Commit-Position: refs/heads/master@{#637827}
parent 257f4c55
...@@ -31,64 +31,6 @@ namespace media_router { ...@@ -31,64 +31,6 @@ namespace media_router {
namespace { namespace {
class StopButton : public views::LabelButton {
public:
StopButton(CastDialogSinkButton* owner,
views::ButtonListener* button_listener,
const UIMediaSink& sink,
int button_tag,
bool enabled)
: views::LabelButton(button_listener, base::string16()), owner_(owner) {
const gfx::ImageSkia icon = CreateVectorIcon(
kGenericStopIcon, kPrimaryIconSize, gfx::kGoogleBlue500);
SetImage(views::Button::STATE_NORMAL, icon);
SetInkDropMode(InkDropMode::ON);
set_tag(button_tag);
SetBorder(views::CreateEmptyBorder(gfx::Insets(kPrimaryIconBorderWidth)));
SetEnabled(enabled);
// Make it possible to navigate to this button by pressing the tab key.
SetFocusBehavior(FocusBehavior::ALWAYS);
// Remove the outlines drawn when the button is in focus.
SetInstallFocusRingOnFocus(false);
SetAccessibleName(l10n_util::GetStringFUTF16(
IDS_MEDIA_ROUTER_STOP_CASTING_BUTTON_ACCESSIBLE_NAME,
sink.friendly_name, sink.status_text));
}
~StopButton() override = default;
SkColor GetInkDropBaseColor() const override {
return views::style::GetColor(*this, views::style::CONTEXT_BUTTON,
STYLE_SECONDARY);
}
std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight()
const override {
return std::make_unique<views::InkDropHighlight>(
size(), height() / 2,
gfx::PointF(GetMirroredRect(GetLocalBounds()).CenterPoint()),
GetInkDropBaseColor());
}
bool CanProcessEventsWithinSubtree() const override { return true; }
// views::Button:
void StateChanged(ButtonState old_state) override {
if (state() == Button::STATE_HOVERED) {
owner_->OverrideStatusText(
l10n_util::GetStringUTF16(IDS_MEDIA_ROUTER_STOP_CASTING));
} else if (old_state == Button::STATE_HOVERED) {
owner_->RestoreStatusText();
}
}
private:
CastDialogSinkButton* const owner_;
DISALLOW_COPY_AND_ASSIGN(StopButton);
};
gfx::ImageSkia CreateSinkIcon(SinkIconType icon_type, bool enabled = true) { gfx::ImageSkia CreateSinkIcon(SinkIconType icon_type, bool enabled = true) {
const gfx::VectorIcon* vector_icon; const gfx::VectorIcon* vector_icon;
switch (icon_type) { switch (icon_type) {
...@@ -128,6 +70,15 @@ gfx::ImageSkia CreateDisabledSinkIcon(SinkIconType icon_type) { ...@@ -128,6 +70,15 @@ gfx::ImageSkia CreateDisabledSinkIcon(SinkIconType icon_type) {
return CreateSinkIcon(icon_type, false); return CreateSinkIcon(icon_type, false);
} }
std::unique_ptr<views::ImageView> CreatePrimaryIconView(
const gfx::ImageSkia& image) {
auto icon_view = std::make_unique<views::ImageView>();
icon_view->SetImage(image);
icon_view->SetBorder(
views::CreateEmptyBorder(gfx::Insets(kPrimaryIconBorderWidth)));
return icon_view;
}
std::unique_ptr<views::View> CreatePrimaryIconForSink( std::unique_ptr<views::View> CreatePrimaryIconForSink(
CastDialogSinkButton* sink_button, CastDialogSinkButton* sink_button,
views::ButtonListener* button_listener, views::ButtonListener* button_listener,
...@@ -135,27 +86,19 @@ std::unique_ptr<views::View> CreatePrimaryIconForSink( ...@@ -135,27 +86,19 @@ std::unique_ptr<views::View> CreatePrimaryIconForSink(
int button_tag) { int button_tag) {
// The stop button has the highest priority, and the issue icon comes second. // The stop button has the highest priority, and the issue icon comes second.
if (sink.state == UIMediaSinkState::CONNECTED) { if (sink.state == UIMediaSinkState::CONNECTED) {
return std::make_unique<StopButton>( return CreatePrimaryIconView(gfx::CreateVectorIcon(
sink_button, button_listener, sink, button_tag, kGenericStopIcon, kPrimaryIconSize, gfx::kGoogleBlue500));
sink.state == UIMediaSinkState::CONNECTED);
} else if (sink.issue) { } else if (sink.issue) {
auto icon_view = std::make_unique<views::ImageView>(); const SkColor icon_color =
const SkColor icon_color = icon_view->GetNativeTheme()->GetSystemColor( ui::NativeTheme::GetInstanceForNativeUi()->GetSystemColor(
ui::NativeTheme::kColorId_DefaultIconColor); ui::NativeTheme::kColorId_DefaultIconColor);
icon_view->SetImage(CreateVectorIcon(::vector_icons::kInfoOutlineIcon, return CreatePrimaryIconView(gfx::CreateVectorIcon(
kPrimaryIconSize, icon_color)); ::vector_icons::kInfoOutlineIcon, kPrimaryIconSize, icon_color));
icon_view->SetBorder(
views::CreateEmptyBorder(gfx::Insets(kPrimaryIconBorderWidth)));
return icon_view;
} else if (sink.state == UIMediaSinkState::CONNECTING || } else if (sink.state == UIMediaSinkState::CONNECTING ||
sink.state == UIMediaSinkState::DISCONNECTING) { sink.state == UIMediaSinkState::DISCONNECTING) {
return CreateThrobber(); return CreateThrobber();
} }
auto icon_view = std::make_unique<views::ImageView>(); return CreatePrimaryIconView(CreateSinkIcon(sink.icon_type));
icon_view->SetImage(CreateSinkIcon(sink.icon_type));
icon_view->SetBorder(
views::CreateEmptyBorder(gfx::Insets(kPrimaryIconBorderWidth)));
return icon_view;
} }
base::string16 GetStatusTextForSink(const UIMediaSink& sink) { base::string16 GetStatusTextForSink(const UIMediaSink& sink) {
...@@ -191,7 +134,8 @@ CastDialogSinkButton::CastDialogSinkButton( ...@@ -191,7 +134,8 @@ CastDialogSinkButton::CastDialogSinkButton(
/** secondary_icon_view */ nullptr), /** secondary_icon_view */ nullptr),
sink_(sink) { sink_(sink) {
set_tag(button_tag); set_tag(button_tag);
SetEnabled(sink.state == UIMediaSinkState::AVAILABLE); SetEnabled(sink.state == UIMediaSinkState::AVAILABLE ||
sink.state == UIMediaSinkState::CONNECTED);
} }
CastDialogSinkButton::~CastDialogSinkButton() = default; CastDialogSinkButton::~CastDialogSinkButton() = default;
...@@ -264,4 +208,17 @@ void CastDialogSinkButton::RequestFocus() { ...@@ -264,4 +208,17 @@ void CastDialogSinkButton::RequestFocus() {
} }
} }
void CastDialogSinkButton::OnFocus() {
HoverButton::OnFocus();
if (sink_.state == UIMediaSinkState::CONNECTED) {
OverrideStatusText(
l10n_util::GetStringUTF16(IDS_MEDIA_ROUTER_STOP_CASTING));
}
}
void CastDialogSinkButton::OnBlur() {
if (sink_.state == UIMediaSinkState::CONNECTED)
RestoreStatusText();
}
} // namespace media_router } // namespace media_router
...@@ -31,6 +31,8 @@ class CastDialogSinkButton : public HoverButton { ...@@ -31,6 +31,8 @@ class CastDialogSinkButton : public HoverButton {
void OnMouseReleased(const ui::MouseEvent& event) override; void OnMouseReleased(const ui::MouseEvent& event) override;
void OnEnabledChanged() override; void OnEnabledChanged() override;
void RequestFocus() override; void RequestFocus() override;
void OnFocus() override;
void OnBlur() override;
const UIMediaSink& sink() const { return sink_; } const UIMediaSink& sink() const { return sink_; }
......
...@@ -440,7 +440,11 @@ base::Optional<MediaCastMode> CastDialogView::GetCastModeToUse( ...@@ -440,7 +440,11 @@ base::Optional<MediaCastMode> CastDialogView::GetCastModeToUse(
} }
void CastDialogView::DisableUnsupportedSinks() { void CastDialogView::DisableUnsupportedSinks() {
// Go through the AVAILABLE sinks and enable or disable them depending on
// whether they support the selected cast mode.
for (CastDialogSinkButton* sink_button : sink_buttons_) { for (CastDialogSinkButton* sink_button : sink_buttons_) {
if (sink_button->sink().state != UIMediaSinkState::AVAILABLE)
continue;
const bool enable = GetCastModeToUse(sink_button->sink()).has_value(); const bool enable = GetCastModeToUse(sink_button->sink()).has_value();
sink_button->SetEnabled(enable); sink_button->SetEnabled(enable);
} }
......
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