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) { ...@@ -91,21 +91,13 @@ bool IsUrlInAppScope(web_app::AppBrowserController* app_controller, GURL url) {
// page. // page.
class CustomTabBarTitleOriginView : public views::View { class CustomTabBarTitleOriginView : public views::View {
public: public:
CustomTabBarTitleOriginView() { CustomTabBarTitleOriginView(SkColor background_color,
auto title_label = std::make_unique<views::Label>( bool should_show_title) {
base::string16(), views::style::CONTEXT_LABEL);
auto location_label = std::make_unique<views::Label>( auto location_label = std::make_unique<views::Label>(
base::string16(), views::style::CONTEXT_LABEL, base::string16(), views::style::CONTEXT_LABEL,
views::style::STYLE_SECONDARY, views::style::STYLE_SECONDARY,
gfx::DirectionalityMode::DIRECTIONALITY_AS_URL); 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->SetElideBehavior(gfx::ElideBehavior::ELIDE_HEAD);
location_label->SetHorizontalAlignment( location_label->SetHorizontalAlignment(
gfx::HorizontalAlignment::ALIGN_LEFT); gfx::HorizontalAlignment::ALIGN_LEFT);
...@@ -113,9 +105,20 @@ class CustomTabBarTitleOriginView : public views::View { ...@@ -113,9 +105,20 @@ class CustomTabBarTitleOriginView : public views::View {
views::kFlexBehaviorKey, views::kFlexBehaviorKey,
views::FlexSpecification(views::MinimumFlexSizeRule::kScaleToMinimum, views::FlexSpecification(views::MinimumFlexSizeRule::kScaleToMinimum,
views::MaximumFlexSizeRule::kPreferred)); views::MaximumFlexSizeRule::kPreferred));
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)); title_label_ = AddChildView(std::move(title_label));
location_label_ = AddChildView(std::move(location_label)); }
auto* layout = SetLayoutManager(std::make_unique<views::FlexLayout>()); auto* layout = SetLayoutManager(std::make_unique<views::FlexLayout>());
layout->SetOrientation(views::LayoutOrientation::kVertical) layout->SetOrientation(views::LayoutOrientation::kVertical)
...@@ -123,13 +126,15 @@ class CustomTabBarTitleOriginView : public views::View { ...@@ -123,13 +126,15 @@ class CustomTabBarTitleOriginView : public views::View {
.SetCrossAxisAlignment(views::LayoutAlignment::kStart); .SetCrossAxisAlignment(views::LayoutAlignment::kStart);
} }
void Update(base::string16 title, base::string16 location) { void Update(const base::string16 title, const base::string16 location) {
if (title_label_)
title_label_->SetText(title); title_label_->SetText(title);
location_label_->SetText(location); location_label_->SetText(location);
location_label_->SetVisible(!location.empty()); location_label_->SetVisible(!location.empty());
} }
void SetColors(SkColor background_color) { void SetColors(SkColor background_color) {
if (title_label_)
title_label_->SetBackgroundColor(background_color); title_label_->SetBackgroundColor(background_color);
location_label_->SetBackgroundColor(background_color); location_label_->SetBackgroundColor(background_color);
} }
...@@ -143,7 +148,10 @@ class CustomTabBarTitleOriginView : public views::View { ...@@ -143,7 +148,10 @@ class CustomTabBarTitleOriginView : public views::View {
// preferred size is at least as wide as the minimum size, and the // preferred size is at least as wide as the minimum size, and the
// minimum height of the control should be the preferred height. // minimum height of the control should be the preferred height.
constexpr int kMinCharacters = 20; 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 { SkColor GetLocationColor() const {
...@@ -170,8 +178,10 @@ class CustomTabBarTitleOriginView : public views::View { ...@@ -170,8 +178,10 @@ class CustomTabBarTitleOriginView : public views::View {
} }
private: private:
views::Label* title_label_; // Can be nullptr.
views::Label* location_label_; views::Label* title_label_ = nullptr;
views::Label* location_label_ = nullptr;
}; };
// static // static
...@@ -192,7 +202,8 @@ CustomTabBarView::CustomTabBarView(BrowserView* browser_view, ...@@ -192,7 +202,8 @@ CustomTabBarView::CustomTabBarView(BrowserView* browser_view,
location_icon_view_ = location_icon_view_ =
AddChildView(std::make_unique<LocationIconView>(font_list, this, this)); 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( title_origin_view->SetProperty(
views::kFlexBehaviorKey, views::kFlexBehaviorKey,
views::FlexSpecification(views::MinimumFlexSizeRule::kScaleToMinimum, views::FlexSpecification(views::MinimumFlexSizeRule::kScaleToMinimum,
...@@ -497,3 +508,7 @@ base::Optional<SkColor> CustomTabBarView::GetThemeColor() const { ...@@ -497,3 +508,7 @@ base::Optional<SkColor> CustomTabBarView::GetThemeColor() const {
return application_controller ? application_controller->GetThemeColor() return application_controller ? application_controller->GetThemeColor()
: base::nullopt; : base::nullopt;
} }
bool CustomTabBarView::ShouldShowTitle() const {
return app_controller() != nullptr;
}
...@@ -123,6 +123,8 @@ class CustomTabBarView : public views::AccessiblePaneView, ...@@ -123,6 +123,8 @@ class CustomTabBarView : public views::AccessiblePaneView,
// Populates child elements with page details from the current WebContents. // Populates child elements with page details from the current WebContents.
void UpdateContents(); void UpdateContents();
bool ShouldShowTitle() const;
SkColor title_bar_color_; SkColor title_bar_color_;
SkColor background_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