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

[Harmony Cast Dialog] Update the "no devices found" view to match the mocks

Per the mocks, move the throbber and the info icon to the left of the view.
Also factor out constants and throbber creating code into a helper file.
Screencap: https://drive.google.com/open?id=1UF1uamxoR0oG-3aEHwdJkoHU_7pJW_CB

Bug: 879630
Change-Id: I42ee54d063df0f9af74cad10a4a21a9a8f78a869
Reviewed-on: https://chromium-review.googlesource.com/1199945
Commit-Queue: Takumi Fujimoto <takumif@chromium.org>
Reviewed-by: default avatarDerek Cheng <imcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589206}
parent a63f1d10
...@@ -3175,6 +3175,8 @@ jumbo_split_static_library("ui") { ...@@ -3175,6 +3175,8 @@ jumbo_split_static_library("ui") {
"views/location_bar/selected_keyword_view.h", "views/location_bar/selected_keyword_view.h",
"views/location_bar/star_view.cc", "views/location_bar/star_view.cc",
"views/location_bar/star_view.h", "views/location_bar/star_view.h",
"views/media_router/cast_dialog_helper.cc",
"views/media_router/cast_dialog_helper.h",
"views/media_router/cast_dialog_metrics.cc", "views/media_router/cast_dialog_metrics.cc",
"views/media_router/cast_dialog_metrics.h", "views/media_router/cast_dialog_metrics.h",
"views/media_router/cast_dialog_no_sinks_view.cc", "views/media_router/cast_dialog_no_sinks_view.cc",
......
// Copyright 2018 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.
#include "chrome/browser/ui/views/media_router/cast_dialog_helper.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/views/border.h"
#include "ui/views/controls/throbber.h"
#include "ui/views/layout/fill_layout.h"
namespace media_router {
std::unique_ptr<views::View> CreateThrobber() {
views::Throbber* throbber = new views::Throbber();
throbber->Start();
auto throbber_container = std::make_unique<views::View>();
throbber_container->SetLayoutManager(std::make_unique<views::FillLayout>());
// The throbber is smaller than other icons, so the difference must be added
// to the border to make their overall sizes match.
const int extra_borders =
kPrimaryIconSize - throbber->CalculatePreferredSize().height();
throbber_container->SetBorder(views::CreateEmptyBorder(
gfx::Insets(extra_borders / 2 + kPrimaryIconBorderWidth)));
throbber_container->AddChildView(throbber);
return throbber_container;
}
} // namespace media_router
// Copyright 2018 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_MEDIA_ROUTER_CAST_DIALOG_HELPER_H_
#define CHROME_BROWSER_UI_VIEWS_MEDIA_ROUTER_CAST_DIALOG_HELPER_H_
#include <memory>
#include "ui/views/view.h"
namespace media_router {
// Icon sizes in DIP.
constexpr int kPrimaryIconSize = 20;
constexpr int kPrimaryIconBorderWidth = 6;
// Creates a view containing a throbber. The throbber has a border around it so
// that the view's size is the same with the primary icon with its border.
std::unique_ptr<views::View> CreateThrobber();
} // namespace media_router
#endif // CHROME_BROWSER_UI_VIEWS_MEDIA_ROUTER_CAST_DIALOG_HELPER_H_
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_tabstrip.h" #include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/views/hover_button.h" #include "chrome/browser/ui/views/hover_button.h"
#include "chrome/browser/ui/views/media_router/cast_dialog_sink_button.h" #include "chrome/browser/ui/views/media_router/cast_dialog_helper.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "components/vector_icons/vector_icons.h" #include "components/vector_icons/vector_icons.h"
...@@ -30,18 +30,6 @@ ...@@ -30,18 +30,6 @@
namespace media_router { namespace media_router {
namespace {
std::unique_ptr<views::ImageView> CreateTvIcon() {
auto icon = std::make_unique<views::ImageView>();
// Share the icon size with sink buttons for consistency.
icon->SetImage(gfx::CreateVectorIcon(
kTvIcon, CastDialogSinkButton::kPrimaryIconSize, gfx::kGoogleGrey500));
return icon;
}
} // namespace
CastDialogNoSinksView::CastDialogNoSinksView(Browser* browser) CastDialogNoSinksView::CastDialogNoSinksView(Browser* browser)
: browser_(browser), weak_factory_(this) { : browser_(browser), weak_factory_(this) {
SetLayoutManager( SetLayoutManager(
...@@ -81,10 +69,8 @@ void CastDialogNoSinksView::ShowHelpCenterArticle() { ...@@ -81,10 +69,8 @@ void CastDialogNoSinksView::ShowHelpCenterArticle() {
views::View* CastDialogNoSinksView::CreateLookingForSinksView() { views::View* CastDialogNoSinksView::CreateLookingForSinksView() {
base::string16 title = base::string16 title =
l10n_util::GetStringUTF16(IDS_MEDIA_ROUTER_STATUS_LOOKING_FOR_DEVICES); l10n_util::GetStringUTF16(IDS_MEDIA_ROUTER_STATUS_LOOKING_FOR_DEVICES);
auto throbber = std::make_unique<views::Throbber>(); HoverButton* view = new HoverButton(
throbber->Start(); /* button_listener */ nullptr, CreateThrobber(), title, base::string16());
HoverButton* view = new HoverButton(nullptr, CreateTvIcon(), title,
base::string16(), std::move(throbber));
view->SetEnabled(false); view->SetEnabled(false);
return view; return view;
} }
...@@ -96,12 +82,14 @@ views::View* CastDialogNoSinksView::CreateHelpIconView() { ...@@ -96,12 +82,14 @@ views::View* CastDialogNoSinksView::CreateHelpIconView() {
views::ImageButton* help_icon_ptr = help_icon.get(); views::ImageButton* help_icon_ptr = help_icon.get();
help_icon->SetImage( help_icon->SetImage(
views::Button::STATE_NORMAL, views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(::vector_icons::kHelpOutlineIcon, gfx::CreateVectorIcon(::vector_icons::kHelpOutlineIcon, kPrimaryIconSize,
CastDialogSinkButton::kPrimaryIconSize,
gfx::kChromeIconGrey)); gfx::kChromeIconGrey));
help_icon->SetFocusForPlatform(); help_icon->SetFocusForPlatform();
HoverButton* view = new HoverButton(nullptr, CreateTvIcon(), title, help_icon->SetBorder(
base::string16(), std::move(help_icon)); views::CreateEmptyBorder(gfx::Insets(kPrimaryIconBorderWidth)));
HoverButton* view =
new HoverButton(/* button_listener */ nullptr, std::move(help_icon),
title, base::string16());
view->SetEnabled(false); view->SetEnabled(false);
// HoverButton disables event handling by its icons, so enable it again. // HoverButton disables event handling by its icons, so enable it again.
help_icon_ptr->set_can_process_events_within_subtree(true); help_icon_ptr->set_can_process_events_within_subtree(true);
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "chrome/app/vector_icons/vector_icons.h" #include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h" #include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/browser/ui/views/chrome_typography.h" #include "chrome/browser/ui/views/chrome_typography.h"
#include "chrome/browser/ui/views/media_router/cast_dialog_helper.h"
#include "chrome/common/media_router/issue.h" #include "chrome/common/media_router/issue.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "components/vector_icons/vector_icons.h" #include "components/vector_icons/vector_icons.h"
...@@ -38,13 +39,11 @@ class StopButton : public views::LabelButton { ...@@ -38,13 +39,11 @@ class StopButton : public views::LabelButton {
: views::LabelButton(button_listener, base::string16()) { : views::LabelButton(button_listener, base::string16()) {
// TODO(https://crbug.com/877702): Update the icon to match the mocks. // TODO(https://crbug.com/877702): Update the icon to match the mocks.
static const gfx::ImageSkia icon = CreateVectorIcon( static const gfx::ImageSkia icon = CreateVectorIcon(
kNavigateStopIcon, CastDialogSinkButton::kPrimaryIconSize, kNavigateStopIcon, kPrimaryIconSize, gfx::kGoogleBlue500);
gfx::kGoogleBlue500);
SetImage(views::Button::STATE_NORMAL, icon); SetImage(views::Button::STATE_NORMAL, icon);
SetInkDropMode(views::InkDropHostView::InkDropMode::ON); SetInkDropMode(views::InkDropHostView::InkDropMode::ON);
set_tag(button_tag); set_tag(button_tag);
SetBorder(views::CreateEmptyBorder( SetBorder(views::CreateEmptyBorder(gfx::Insets(kPrimaryIconBorderWidth)));
gfx::Insets(CastDialogSinkButton::kPrimaryIconBorderWidth)));
SetEnabled(enabled); SetEnabled(enabled);
// Make it possible to navigate to this button by pressing the tab key. // Make it possible to navigate to this button by pressing the tab key.
SetFocusBehavior(FocusBehavior::ALWAYS); SetFocusBehavior(FocusBehavior::ALWAYS);
...@@ -103,29 +102,13 @@ gfx::ImageSkia CreateSinkIcon(SinkIconType icon_type, bool enabled = true) { ...@@ -103,29 +102,13 @@ gfx::ImageSkia CreateSinkIcon(SinkIconType icon_type, bool enabled = true) {
break; break;
} }
SkColor icon_color = enabled ? gfx::kChromeIconGrey : gfx::kGoogleGrey500; SkColor icon_color = enabled ? gfx::kChromeIconGrey : gfx::kGoogleGrey500;
return gfx::CreateVectorIcon( return gfx::CreateVectorIcon(*vector_icon, kPrimaryIconSize, icon_color);
*vector_icon, CastDialogSinkButton::kPrimaryIconSize, icon_color);
} }
gfx::ImageSkia CreateDisabledSinkIcon(SinkIconType icon_type) { gfx::ImageSkia CreateDisabledSinkIcon(SinkIconType icon_type) {
return CreateSinkIcon(icon_type, false); return CreateSinkIcon(icon_type, false);
} }
std::unique_ptr<views::View> CreateThrobber() {
views::Throbber* throbber = new views::Throbber();
throbber->Start();
auto throbber_container = std::make_unique<views::View>();
throbber_container->SetLayoutManager(std::make_unique<views::FillLayout>());
// The throbber is smaller than other icons, so the difference must be added
// to the border to make their overall sizes match.
const int extra_borders = CastDialogSinkButton::kPrimaryIconSize -
throbber->CalculatePreferredSize().height();
throbber_container->SetBorder(views::CreateEmptyBorder(gfx::Insets(
extra_borders / 2 + CastDialogSinkButton::kPrimaryIconBorderWidth)));
throbber_container->AddChildView(throbber);
return throbber_container;
}
std::unique_ptr<views::View> CreatePrimaryIconForSink( std::unique_ptr<views::View> CreatePrimaryIconForSink(
views::ButtonListener* button_listener, views::ButtonListener* button_listener,
const UIMediaSink& sink, const UIMediaSink& sink,
...@@ -133,10 +116,10 @@ std::unique_ptr<views::View> CreatePrimaryIconForSink( ...@@ -133,10 +116,10 @@ std::unique_ptr<views::View> CreatePrimaryIconForSink(
if (sink.issue) { if (sink.issue) {
auto icon_view = std::make_unique<views::ImageView>(); auto icon_view = std::make_unique<views::ImageView>();
icon_view->SetImage(CreateVectorIcon(::vector_icons::kInfoOutlineIcon, icon_view->SetImage(CreateVectorIcon(::vector_icons::kInfoOutlineIcon,
CastDialogSinkButton::kPrimaryIconSize, kPrimaryIconSize,
gfx::kChromeIconGrey)); gfx::kChromeIconGrey));
icon_view->SetBorder(views::CreateEmptyBorder( icon_view->SetBorder(
gfx::Insets(CastDialogSinkButton::kPrimaryIconBorderWidth))); views::CreateEmptyBorder(gfx::Insets(kPrimaryIconBorderWidth)));
return icon_view; return icon_view;
} else if (sink.state == UIMediaSinkState::CONNECTED || } else if (sink.state == UIMediaSinkState::CONNECTED ||
sink.state == UIMediaSinkState::DISCONNECTING) { sink.state == UIMediaSinkState::DISCONNECTING) {
...@@ -147,8 +130,8 @@ std::unique_ptr<views::View> CreatePrimaryIconForSink( ...@@ -147,8 +130,8 @@ std::unique_ptr<views::View> CreatePrimaryIconForSink(
} }
auto icon_view = std::make_unique<views::ImageView>(); auto icon_view = std::make_unique<views::ImageView>();
icon_view->SetImage(CreateSinkIcon(sink.icon_type)); icon_view->SetImage(CreateSinkIcon(sink.icon_type));
icon_view->SetBorder(views::CreateEmptyBorder( icon_view->SetBorder(
gfx::Insets(CastDialogSinkButton::kPrimaryIconBorderWidth))); views::CreateEmptyBorder(gfx::Insets(kPrimaryIconBorderWidth)));
return icon_view; return icon_view;
} }
...@@ -169,11 +152,6 @@ base::string16 GetStatusTextForSink(const UIMediaSink& sink) { ...@@ -169,11 +152,6 @@ base::string16 GetStatusTextForSink(const UIMediaSink& sink) {
} // namespace } // namespace
// static
int CastDialogSinkButton::kPrimaryIconSize = 20;
int CastDialogSinkButton::kPrimaryIconBorderWidth = 6;
int CastDialogSinkButton::kSecondaryIconSize = 16;
CastDialogSinkButton::CastDialogSinkButton( CastDialogSinkButton::CastDialogSinkButton(
views::ButtonListener* button_listener, views::ButtonListener* button_listener,
const UIMediaSink& sink, const UIMediaSink& sink,
......
...@@ -18,12 +18,6 @@ namespace media_router { ...@@ -18,12 +18,6 @@ namespace media_router {
// hovered. // hovered.
class CastDialogSinkButton : public HoverButton { class CastDialogSinkButton : public HoverButton {
public: public:
// Icon sizes in DIP. These values are also used by the "no devices" view for
// consistency.
static int kPrimaryIconSize;
static int kPrimaryIconBorderWidth;
static int kSecondaryIconSize;
CastDialogSinkButton(views::ButtonListener* button_listener, CastDialogSinkButton(views::ButtonListener* button_listener,
const UIMediaSink& sink, const UIMediaSink& sink,
int button_tag); int button_tag);
......
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