| Index: ui/views/style/typography.cc
|
| diff --git a/ui/views/style/typography.cc b/ui/views/style/typography.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..c4a422b25d2922a397c862c8a59898732c750c05
|
| --- /dev/null
|
| +++ b/ui/views/style/typography.cc
|
| @@ -0,0 +1,111 @@
|
| +// Copyright 2017 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 "ui/views/style/typography.h"
|
| +
|
| +#include "base/logging.h"
|
| +#include "ui/base/default_style.h"
|
| +#include "ui/base/resource/resource_bundle.h"
|
| +
|
| +namespace views {
|
| +namespace {
|
| +
|
| +constexpr int kHeadlineDelta = 8;
|
| +constexpr int kDialogMessageDelta = 1;
|
| +
|
| +// The default provider aims to provide values to match pre-Harmony constants
|
| +// for the given contexts so that old UI does not change.
|
| +class DefaultProvider : public TypographyProvider {
|
| + public:
|
| + DefaultProvider() {}
|
| +
|
| + const gfx::FontList& GetFont(TextContext context, TextStyle style) override;
|
| + SkColor GetColor(TextContext context, TextStyle style) override;
|
| + int GetLineSpacing(TextContext context, TextStyle style) override;
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(DefaultProvider);
|
| +};
|
| +
|
| +const gfx::FontList& DefaultProvider::GetFont(TextContext context,
|
| + TextStyle style) {
|
| + int size_delta = 0;
|
| + gfx::Font::Weight font_weight = gfx::Font::Weight::NORMAL;
|
| + switch (context.value()) {
|
| + case TextContext::HEADLINE:
|
| + size_delta = kHeadlineDelta;
|
| + break;
|
| + case TextContext::DIALOG_TITLE:
|
| + size_delta = ui::kTitleFontSizeDelta;
|
| + break;
|
| + case TextContext::DIALOG_MESSAGE:
|
| + // Note: Not using ui::kMessageFontSizeDelta, so is 13pt in most cases.
|
| + size_delta = kDialogMessageDelta;
|
| + break;
|
| + case TextContext::CONTROL_LABEL:
|
| + case TextContext::FIELD:
|
| + case TextContext::BUTTON_TEXT:
|
| + size_delta = ui::kLabelFontSizeDelta;
|
| + break;
|
| + }
|
| + switch (style) {
|
| + case TextStyle::WEB_DOMAIN:
|
| + case TextStyle::ACTIVE_TAB:
|
| + case TextStyle::EXTENSION_NAME:
|
| + font_weight = gfx::Font::Weight::BOLD;
|
| + break;
|
| + default:
|
| + break;
|
| + }
|
| + constexpr gfx::Font::FontStyle kFontStyle = gfx::Font::NORMAL;
|
| + return ResourceBundle::GetSharedInstance().GetFontListWithDelta(
|
| + size_delta, kFontStyle, font_weight);
|
| +}
|
| +
|
| +SkColor DefaultProvider::GetColor(TextContext context, TextStyle style) {
|
| + return SK_ColorBLACK;
|
| +}
|
| +
|
| +int DefaultProvider::GetLineSpacing(TextContext context, TextStyle style) {
|
| + return 0;
|
| +}
|
| +
|
| +std::unique_ptr<TypographyProvider>& Storage() {
|
| + CR_DEFINE_STATIC_LOCAL(std::unique_ptr<TypographyProvider>, storage,
|
| + (new DefaultProvider));
|
| + return storage;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +// Linker storage.
|
| +const TextContext::Value TextContext::HEADLINE;
|
| +const TextContext::Value TextContext::DIALOG_TITLE;
|
| +const TextContext::Value TextContext::DIALOG_MESSAGE;
|
| +const TextContext::Value TextContext::CONTROL_LABEL;
|
| +const TextContext::Value TextContext::FIELD;
|
| +const TextContext::Value TextContext::BUTTON_TEXT;
|
| +
|
| +// static
|
| +void Typography::SetProvider(std::unique_ptr<TypographyProvider> provider) {
|
| + DCHECK(provider);
|
| + Storage() = std::move(provider);
|
| +}
|
| +
|
| +// static
|
| +const gfx::FontList& Typography::GetFont(TextContext context, TextStyle style) {
|
| + return Storage()->GetFont(context, style);
|
| +}
|
| +
|
| +// static
|
| +SkColor Typography::GetColor(TextContext context, TextStyle style) {
|
| + return Storage()->GetColor(context, style);
|
| +}
|
| +
|
| +// static
|
| +int Typography::GetLineSpacing(TextContext context, TextStyle style) {
|
| + return Storage()->GetLineSpacing(context, style);
|
| +}
|
| +
|
| +} // namespace views
|
|
|