Commit 1bf52f95 authored by Mugdha Lakhani's avatar Mugdha Lakhani Committed by Commit Bot

[Custom Tabs] Stop showing title in chrome custom tab bar.

Design Doc: https://docs.google.com/document/d/166h__sHZGVD7eTBKkBMF7beLGOmT6mwTVe8dtsTCU7A/edit?usp=sharing

Before screenshot here:
After screenshot here:

https: //drive.google.com/open?id=0B486O0P6jAtRZ0ptUEJXemUwczNjTjlGejFPZ1ZaZS02RXFr
https: //drive.google.com/a/google.com/file/d/15sHXrBgFOUAT5p2gccLHfIyP5ELYRsXV/view?usp=sharing
Bug: b/64863368
Change-Id: I05b8cc3c878f930d0c18b69a4f84ac43a10b2592
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1873631
Commit-Queue: Mugdha Lakhani <nator@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#743059}
parent 36055201
......@@ -91,21 +91,13 @@ bool IsUrlInAppScope(web_app::AppBrowserController* app_controller, GURL url) {
// page.
class CustomTabBarTitleOriginView : public views::View {
public:
CustomTabBarTitleOriginView() {
auto title_label = std::make_unique<views::Label>(
base::string16(), views::style::CONTEXT_LABEL);
CustomTabBarTitleOriginView(SkColor background_color,
bool should_show_title) {
auto location_label = std::make_unique<views::Label>(
base::string16(), views::style::CONTEXT_LABEL,
views::style::STYLE_SECONDARY,
gfx::DirectionalityMode::DIRECTIONALITY_AS_URL);
title_label->SetElideBehavior(gfx::ElideBehavior::ELIDE_TAIL);
title_label->SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_LEFT);
title_label->SetProperty(
views::kFlexBehaviorKey,
views::FlexSpecification(views::MinimumFlexSizeRule::kScaleToMinimum,
views::MaximumFlexSizeRule::kPreferred));
location_label->SetElideBehavior(gfx::ElideBehavior::ELIDE_HEAD);
location_label->SetHorizontalAlignment(
gfx::HorizontalAlignment::ALIGN_LEFT);
......@@ -113,24 +105,37 @@ class CustomTabBarTitleOriginView : public views::View {
views::kFlexBehaviorKey,
views::FlexSpecification(views::MinimumFlexSizeRule::kScaleToMinimum,
views::MaximumFlexSizeRule::kPreferred));
title_label_ = AddChildView(std::move(title_label));
location_label_ = AddChildView(std::move(location_label));
if (should_show_title) {
auto title_label = std::make_unique<views::Label>(
base::string16(), views::style::CONTEXT_LABEL);
title_label->SetElideBehavior(gfx::ElideBehavior::ELIDE_TAIL);
title_label->SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_LEFT);
title_label->SetProperty(
views::kFlexBehaviorKey,
views::FlexSpecification(views::MinimumFlexSizeRule::kScaleToMinimum,
views::MaximumFlexSizeRule::kPreferred));
title_label_ = AddChildView(std::move(title_label));
}
auto* layout = SetLayoutManager(std::make_unique<views::FlexLayout>());
layout->SetOrientation(views::LayoutOrientation::kVertical)
.SetMainAxisAlignment(views::LayoutAlignment::kCenter)
.SetCrossAxisAlignment(views::LayoutAlignment::kStart);
}
void Update(base::string16 title, base::string16 location) {
title_label_->SetText(title);
void Update(const base::string16 title, const base::string16 location) {
if (title_label_)
title_label_->SetText(title);
location_label_->SetText(location);
location_label_->SetVisible(!location.empty());
}
void SetColors(SkColor background_color) {
title_label_->SetBackgroundColor(background_color);
if (title_label_)
title_label_->SetBackgroundColor(background_color);
location_label_->SetBackgroundColor(background_color);
}
......@@ -143,7 +148,10 @@ class CustomTabBarTitleOriginView : public views::View {
// preferred size is at least as wide as the minimum size, and the
// minimum height of the control should be the preferred height.
constexpr int kMinCharacters = 20;
return title_label_->font_list().GetExpectedTextWidth(kMinCharacters);
return title_label_
? title_label_->font_list().GetExpectedTextWidth(kMinCharacters)
: location_label_->font_list().GetExpectedTextWidth(
kMinCharacters);
}
SkColor GetLocationColor() const {
......@@ -170,8 +178,10 @@ class CustomTabBarTitleOriginView : public views::View {
}
private:
views::Label* title_label_;
views::Label* location_label_;
// Can be nullptr.
views::Label* title_label_ = nullptr;
views::Label* location_label_ = nullptr;
};
// static
......@@ -192,7 +202,8 @@ CustomTabBarView::CustomTabBarView(BrowserView* browser_view,
location_icon_view_ =
AddChildView(std::make_unique<LocationIconView>(font_list, this, this));
auto title_origin_view = std::make_unique<CustomTabBarTitleOriginView>();
auto title_origin_view = std::make_unique<CustomTabBarTitleOriginView>(
background_color_, ShouldShowTitle());
title_origin_view->SetProperty(
views::kFlexBehaviorKey,
views::FlexSpecification(views::MinimumFlexSizeRule::kScaleToMinimum,
......@@ -497,3 +508,7 @@ base::Optional<SkColor> CustomTabBarView::GetThemeColor() const {
return application_controller ? application_controller->GetThemeColor()
: base::nullopt;
}
bool CustomTabBarView::ShouldShowTitle() const {
return app_controller() != nullptr;
}
......@@ -123,6 +123,8 @@ class CustomTabBarView : public views::AccessiblePaneView,
// Populates child elements with page details from the current WebContents.
void UpdateContents();
bool ShouldShowTitle() const;
SkColor title_bar_color_;
SkColor background_color_;
......
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