Commit 10ebffd7 authored by Taylor Bergquist's avatar Taylor Bergquist Committed by Commit Bot

Update font and border size for tab counter.

This also adjusts the internal View hierarchy for the tab counter; this
will be important when the animation is changed to move the border and
the text separately.

Bug: 999557
Change-Id: I1f9f7d8544ca87e6ec463b29ce2370f1f88bedfa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1982722
Commit-Queue: Taylor Bergquist <tbergquist@chromium.org>
Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#728674}
parent 39131ff6
...@@ -13,6 +13,23 @@ ...@@ -13,6 +13,23 @@
int GetFontSizeDeltaBoundedByAvailableHeight(int available_height, int GetFontSizeDeltaBoundedByAvailableHeight(int available_height,
int desired_font_size) { int desired_font_size) {
int size_delta =
GetFontSizeDeltaIgnoringUserOrLocaleSettings(desired_font_size);
ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
gfx::FontList base_font = bundle.GetFontListWithDelta(size_delta);
// Shrink large fonts to ensure they fit. Default fonts should fit already.
// TODO(tapted): Move DeriveWithHeightUpperBound() to ui::ResourceBundle to
// take advantage of the font cache.
int user_or_locale_delta =
size_delta + gfx::PlatformFont::kDefaultBaseFontSize - desired_font_size;
base_font = base_font.DeriveWithHeightUpperBound(available_height);
return base_font.GetFontSize() - gfx::PlatformFont::kDefaultBaseFontSize +
user_or_locale_delta;
}
int GetFontSizeDeltaIgnoringUserOrLocaleSettings(int desired_font_size) {
int size_delta = desired_font_size - gfx::PlatformFont::kDefaultBaseFontSize; int size_delta = desired_font_size - gfx::PlatformFont::kDefaultBaseFontSize;
ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
gfx::FontList base_font = bundle.GetFontListWithDelta(size_delta); gfx::FontList base_font = bundle.GetFontListWithDelta(size_delta);
...@@ -28,11 +45,6 @@ int GetFontSizeDeltaBoundedByAvailableHeight(int available_height, ...@@ -28,11 +45,6 @@ int GetFontSizeDeltaBoundedByAvailableHeight(int available_height,
} }
DCHECK_EQ(desired_font_size, base_font.GetFontSize()); DCHECK_EQ(desired_font_size, base_font.GetFontSize());
// Shrink large fonts to ensure they fit. Default fonts should fit already.
// TODO(tapted): Move DeriveWithHeightUpperBound() to ui::ResourceBundle to
// take advantage of the font cache.
base_font = base_font.DeriveWithHeightUpperBound(available_height);
// To ensure a subsequent request from the ResourceBundle ignores the delta // To ensure a subsequent request from the ResourceBundle ignores the delta
// due to user or locale settings, include it here. // due to user or locale settings, include it here.
return base_font.GetFontSize() - gfx::PlatformFont::kDefaultBaseFontSize + return base_font.GetFontSize() - gfx::PlatformFont::kDefaultBaseFontSize +
...@@ -48,10 +60,13 @@ void ApplyCommonFontStyles(int context, ...@@ -48,10 +60,13 @@ void ApplyCommonFontStyles(int context,
// TODO(pbos): Instead of fixing the toolbar button height this way // TODO(pbos): Instead of fixing the toolbar button height this way
// consider dynamically resizing all of the toolbar based on the actual // consider dynamically resizing all of the toolbar based on the actual
// final item height. // final item height.
const int height = ui::MaterialDesignController::touch_ui() ? 22 : 17; int height = ui::MaterialDesignController::touch_ui() ? 22 : 17;
static const int toolbar_button_delta = *size_delta = GetFontSizeDeltaBoundedByAvailableHeight(height, height);
GetFontSizeDeltaBoundedByAvailableHeight(height, height); break;
*size_delta = toolbar_button_delta; }
case CONTEXT_WEB_UI_TAB_COUNTER: {
*size_delta = GetFontSizeDeltaIgnoringUserOrLocaleSettings(14);
*weight = gfx::Font::Weight::BOLD;
break; break;
} }
case CONTEXT_OMNIBOX_PRIMARY: case CONTEXT_OMNIBOX_PRIMARY:
......
...@@ -34,6 +34,9 @@ enum ChromeTextContext { ...@@ -34,6 +34,9 @@ enum ChromeTextContext {
// Text of the page title in the tab hover card. // Text of the page title in the tab hover card.
CONTEXT_TAB_HOVER_CARD_TITLE, CONTEXT_TAB_HOVER_CARD_TITLE,
// Text of the number of tabs in the webui tab counter.
CONTEXT_WEB_UI_TAB_COUNTER,
// Text in the location bar entry, and primary text in the omnibox dropdown. // Text in the location bar entry, and primary text in the omnibox dropdown.
CONTEXT_OMNIBOX_PRIMARY, CONTEXT_OMNIBOX_PRIMARY,
...@@ -85,6 +88,11 @@ enum ChromeTextStyle { ...@@ -85,6 +88,11 @@ enum ChromeTextStyle {
int GetFontSizeDeltaBoundedByAvailableHeight(int available_height, int GetFontSizeDeltaBoundedByAvailableHeight(int available_height,
int desired_font_size); int desired_font_size);
// Takes a desired font size and returns the size delta to request from
// ui::ResourceBundle that will result in exactly that font size, canceling
// out any font size changes made to account for locale or user settings.
int GetFontSizeDeltaIgnoringUserOrLocaleSettings(int desired_font_size);
// Sets the |size_delta| and |font_weight| for text that should not be affected // Sets the |size_delta| and |font_weight| for text that should not be affected
// by the Harmony spec. // by the Harmony spec.
void ApplyCommonFontStyles(int context, void ApplyCommonFontStyles(int context,
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/tabs/tab_strip_model_observer.h" #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
#include "chrome/browser/ui/view_ids.h" #include "chrome/browser/ui/view_ids.h"
#include "chrome/browser/ui/views/chrome_typography.h"
#include "chrome/browser/ui/views/chrome_view_class_properties.h" #include "chrome/browser/ui/views/chrome_view_class_properties.h"
#include "chrome/browser/ui/views/feature_promos/feature_promo_colors.h" #include "chrome/browser/ui/views/feature_promos/feature_promo_colors.h"
#include "chrome/browser/ui/views/toolbar/toolbar_ink_drop_util.h" #include "chrome/browser/ui/views/toolbar/toolbar_ink_drop_util.h"
...@@ -67,8 +68,12 @@ class TabCounterAnimator : public gfx::AnimationDelegate { ...@@ -67,8 +68,12 @@ class TabCounterAnimator : public gfx::AnimationDelegate {
class TabCounterUpdater : public TabStripModelObserver { class TabCounterUpdater : public TabStripModelObserver {
public: public:
TabCounterUpdater(views::Button* button, views::Label* tab_counter) TabCounterUpdater(views::Button* button,
: button_(button), tab_counter_(tab_counter), animator_(tab_counter) {} views::Label* tab_counter,
views::View* tab_counter_container)
: button_(button),
tab_counter_(tab_counter),
animator_(tab_counter_container) {}
~TabCounterUpdater() override = default; ~TabCounterUpdater() override = default;
void UpdateCounter(TabStripModel* model) { void UpdateCounter(TabStripModel* model) {
...@@ -113,6 +118,7 @@ class WebUITabCounterButton : public views::Button { ...@@ -113,6 +118,7 @@ class WebUITabCounterButton : public views::Button {
std::unique_ptr<TabCounterUpdater> counter_updater_; std::unique_ptr<TabCounterUpdater> counter_updater_;
views::InkDropContainerView* ink_drop_container_; views::InkDropContainerView* ink_drop_container_;
views::Label* label_; views::Label* label_;
views::View* border_;
}; };
WebUITabCounterButton::WebUITabCounterButton(views::ButtonListener* listener) WebUITabCounterButton::WebUITabCounterButton(views::ButtonListener* listener)
...@@ -137,7 +143,7 @@ void WebUITabCounterButton::UpdateColors() { ...@@ -137,7 +143,7 @@ void WebUITabCounterButton::UpdateColors() {
: normal_text_color; : normal_text_color;
label_->SetEnabledColor(current_text_color); label_->SetEnabledColor(current_text_color);
label_->SetBorder(views::CreateRoundedRectBorder( border_->SetBorder(views::CreateRoundedRectBorder(
2, 2,
views::LayoutProvider::Get()->GetCornerRadiusMetric( views::LayoutProvider::Get()->GetCornerRadiusMetric(
views::EMPHASIS_MEDIUM), views::EMPHASIS_MEDIUM),
...@@ -189,17 +195,22 @@ std::unique_ptr<views::View> CreateWebUITabCounterButton( ...@@ -189,17 +195,22 @@ std::unique_ptr<views::View> CreateWebUITabCounterButton(
tab_counter->ink_drop_container_ = ink_drop_container; tab_counter->ink_drop_container_ = ink_drop_container;
ink_drop_container->SetBoundsRect(tab_counter->GetLocalBounds()); ink_drop_container->SetBoundsRect(tab_counter->GetLocalBounds());
views::Label* label = views::View* border =
tab_counter->AddChildView(std::make_unique<views::Label>()); tab_counter->AddChildView(std::make_unique<views::View>());
tab_counter->border_ = border;
views::Label* label = border->AddChildView(std::make_unique<views::Label>(
base::string16(), CONTEXT_WEB_UI_TAB_COUNTER));
tab_counter->label_ = label; tab_counter->label_ = label;
constexpr int kDesiredBorderHeight = 18; constexpr int kDesiredBorderHeight = 22;
const int inset_height = (button_height - kDesiredBorderHeight) / 2; const int inset_height = (button_height - kDesiredBorderHeight) / 2;
label->SetBounds(inset_height, inset_height, kDesiredBorderHeight, border->SetBounds(inset_height, inset_height, kDesiredBorderHeight,
kDesiredBorderHeight); kDesiredBorderHeight);
label->SetBounds(0, 0, kDesiredBorderHeight, kDesiredBorderHeight);
tab_counter->counter_updater_ = tab_counter->counter_updater_ =
std::make_unique<TabCounterUpdater>(tab_counter.get(), label); std::make_unique<TabCounterUpdater>(tab_counter.get(), label, border);
tab_strip_model->AddObserver(tab_counter->counter_updater_.get()); tab_strip_model->AddObserver(tab_counter->counter_updater_.get());
tab_counter->counter_updater_->UpdateCounter(tab_strip_model); tab_counter->counter_updater_->UpdateCounter(tab_strip_model);
......
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