Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5207)

Unified Diff: chrome/browser/ui/views/harmony/layout_delegate.cc

Issue 2734113006: "Bootstrap" a toolkit-views Typography spec. (Closed)
Patch Set: Shred Typography class, follow-up on some other things. fix compile. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/harmony/layout_delegate.cc
diff --git a/chrome/browser/ui/views/harmony/layout_delegate.cc b/chrome/browser/ui/views/harmony/layout_delegate.cc
index 79d88b025d46793b2f222bb49774826f079f2359..059df53e913d0af1ebd9690ee61ee26e0664c2c7 100644
--- a/chrome/browser/ui/views/harmony/layout_delegate.cc
+++ b/chrome/browser/ui/views/harmony/layout_delegate.cc
@@ -8,14 +8,84 @@
#include "base/logging.h"
#include "chrome/browser/ui/views/chrome_views_delegate.h"
#include "chrome/browser/ui/views/harmony/harmony_layout_delegate.h"
+#include "ui/base/default_style.h"
#include "ui/base/material_design/material_design_controller.h"
+#include "ui/base/resource/resource_bundle.h"
#include "ui/views/layout/layout_constants.h"
+#include "ui/views/style/typography_provider.h"
-static base::LazyInstance<LayoutDelegate>::DestructorAtExit layout_delegate_ =
+namespace {
+
+// TypographyProvider that provides pre-Harmony fonts in Chrome.
+class LegacyTypographyProvider : public views::DefaultTypographyProvider {
+ public:
+ LegacyTypographyProvider() = default;
+
+ const gfx::FontList& GetFont(views::TextContext context,
+ views::TextStyle style) const override;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(LegacyTypographyProvider);
+};
+
+const gfx::FontList& LegacyTypographyProvider::GetFont(
+ views::TextContext context,
+ views::TextStyle style) const {
+ constexpr int kHeadlineDelta = 8;
+ constexpr int kDialogMessageDelta = 1;
+
+ int size_delta;
+ gfx::Font::Weight font_weight;
+ GetDefaultFont(context, style, &size_delta, &font_weight);
+
+ switch (context.value()) {
+ case ChromeTextContext::HEADLINE:
+ size_delta = kHeadlineDelta;
+ break;
+ case ChromeTextContext::DIALOG_MESSAGE:
+ // Note: Not using ui::kMessageFontSizeDelta, so 13pt in most cases.
+ size_delta = kDialogMessageDelta;
+ break;
+ case ChromeTextContext::DIALOG_TEXT_SMALL:
+ size_delta = ui::kLabelFontSizeDelta;
+ break;
+ case ChromeTextContext::DEPRECATED_SMALL:
+ size_delta = ui::ResourceBundle::kSmallFontDelta;
+ break;
+ }
+
+ switch (style.value()) {
+ case ChromeTextStyle::WEB_DOMAIN:
+ case ChromeTextStyle::EXTENSION_NAME:
+ font_weight = gfx::Font::Weight::BOLD;
+ break;
+ }
+ constexpr gfx::Font::FontStyle kFontStyle = gfx::Font::NORMAL;
+ return ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta(
+ size_delta, kFontStyle, font_weight);
+}
+
+base::LazyInstance<LayoutDelegate>::DestructorAtExit layout_delegate_ =
LAZY_INSTANCE_INITIALIZER;
+} // namespace
+
+constexpr const views::TextContext::Value ChromeTextContext::HEADLINE;
+constexpr const views::TextContext::Value ChromeTextContext::DIALOG_TEXT_SMALL;
+constexpr const views::TextContext::Value ChromeTextContext::DEPRECATED_SMALL;
+constexpr const views::TextStyle::Value ChromeTextStyle::SECONDARY;
+constexpr const views::TextStyle::Value ChromeTextStyle::HINT;
+constexpr const views::TextStyle::Value ChromeTextStyle::RED;
+constexpr const views::TextStyle::Value ChromeTextStyle::GREEN;
+constexpr const views::TextStyle::Value ChromeTextStyle::WEB_DOMAIN;
+constexpr const views::TextStyle::Value ChromeTextStyle::EXTENSION_NAME;
+
// static
LayoutDelegate* LayoutDelegate::Get() {
+ // TODO(tapted): Move this to the LayoutDelegate constructor when
+ // HarmonyLayoutDelegate sets provides its own TypographyProvider.
+ views::TypographyProvider::Set(base::WrapUnique<views::TypographyProvider>(
+ new LegacyTypographyProvider));
return ui::MaterialDesignController::IsSecondaryUiMaterial()
? HarmonyLayoutDelegate::Get()
: layout_delegate_.Pointer();

Powered by Google App Engine
This is Rietveld 408576698