OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/harmony/layout_delegate.h" | 5 #include "chrome/browser/ui/views/harmony/layout_delegate.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "chrome/browser/ui/views/chrome_views_delegate.h" | 9 #include "chrome/browser/ui/views/chrome_views_delegate.h" |
10 #include "chrome/browser/ui/views/harmony/harmony_layout_delegate.h" | 10 #include "chrome/browser/ui/views/harmony/harmony_layout_delegate.h" |
| 11 #include "ui/base/default_style.h" |
11 #include "ui/base/material_design/material_design_controller.h" | 12 #include "ui/base/material_design/material_design_controller.h" |
| 13 #include "ui/base/resource/resource_bundle.h" |
12 #include "ui/views/layout/layout_constants.h" | 14 #include "ui/views/layout/layout_constants.h" |
| 15 #include "ui/views/style/typography_provider.h" |
13 | 16 |
14 static base::LazyInstance<LayoutDelegate>::DestructorAtExit layout_delegate_ = | 17 namespace { |
| 18 |
| 19 // TypographyProvider that provides pre-Harmony fonts in Chrome. |
| 20 class LegacyTypographyProvider : public views::DefaultTypographyProvider { |
| 21 public: |
| 22 LegacyTypographyProvider() = default; |
| 23 |
| 24 const gfx::FontList& GetFont(views::TextContext context, |
| 25 views::TextStyle style) const override; |
| 26 |
| 27 private: |
| 28 DISALLOW_COPY_AND_ASSIGN(LegacyTypographyProvider); |
| 29 }; |
| 30 |
| 31 const gfx::FontList& LegacyTypographyProvider::GetFont( |
| 32 views::TextContext context, |
| 33 views::TextStyle style) const { |
| 34 constexpr int kHeadlineDelta = 8; |
| 35 constexpr int kDialogMessageDelta = 1; |
| 36 |
| 37 int size_delta; |
| 38 gfx::Font::Weight font_weight; |
| 39 GetDefaultFont(context, style, &size_delta, &font_weight); |
| 40 |
| 41 switch (context.value()) { |
| 42 case ChromeTextContext::HEADLINE: |
| 43 size_delta = kHeadlineDelta; |
| 44 break; |
| 45 case ChromeTextContext::DIALOG_MESSAGE: |
| 46 // Note: Not using ui::kMessageFontSizeDelta, so 13pt in most cases. |
| 47 size_delta = kDialogMessageDelta; |
| 48 break; |
| 49 case ChromeTextContext::DIALOG_TEXT_SMALL: |
| 50 size_delta = ui::kLabelFontSizeDelta; |
| 51 break; |
| 52 case ChromeTextContext::DEPRECATED_SMALL: |
| 53 size_delta = ui::ResourceBundle::kSmallFontDelta; |
| 54 break; |
| 55 } |
| 56 |
| 57 switch (style.value()) { |
| 58 case ChromeTextStyle::WEB_DOMAIN: |
| 59 case ChromeTextStyle::EXTENSION_NAME: |
| 60 font_weight = gfx::Font::Weight::BOLD; |
| 61 break; |
| 62 } |
| 63 constexpr gfx::Font::FontStyle kFontStyle = gfx::Font::NORMAL; |
| 64 return ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta( |
| 65 size_delta, kFontStyle, font_weight); |
| 66 } |
| 67 |
| 68 base::LazyInstance<LayoutDelegate>::DestructorAtExit layout_delegate_ = |
15 LAZY_INSTANCE_INITIALIZER; | 69 LAZY_INSTANCE_INITIALIZER; |
16 | 70 |
| 71 } // namespace |
| 72 |
| 73 constexpr const views::TextContext::Value ChromeTextContext::HEADLINE; |
| 74 constexpr const views::TextContext::Value ChromeTextContext::DIALOG_TEXT_SMALL; |
| 75 constexpr const views::TextContext::Value ChromeTextContext::DEPRECATED_SMALL; |
| 76 constexpr const views::TextStyle::Value ChromeTextStyle::SECONDARY; |
| 77 constexpr const views::TextStyle::Value ChromeTextStyle::HINT; |
| 78 constexpr const views::TextStyle::Value ChromeTextStyle::RED; |
| 79 constexpr const views::TextStyle::Value ChromeTextStyle::GREEN; |
| 80 constexpr const views::TextStyle::Value ChromeTextStyle::WEB_DOMAIN; |
| 81 constexpr const views::TextStyle::Value ChromeTextStyle::EXTENSION_NAME; |
| 82 |
17 // static | 83 // static |
18 LayoutDelegate* LayoutDelegate::Get() { | 84 LayoutDelegate* LayoutDelegate::Get() { |
| 85 // TODO(tapted): Move this to the LayoutDelegate constructor when |
| 86 // HarmonyLayoutDelegate sets provides its own TypographyProvider. |
| 87 views::TypographyProvider::Set(base::WrapUnique<views::TypographyProvider>( |
| 88 new LegacyTypographyProvider)); |
19 return ui::MaterialDesignController::IsSecondaryUiMaterial() | 89 return ui::MaterialDesignController::IsSecondaryUiMaterial() |
20 ? HarmonyLayoutDelegate::Get() | 90 ? HarmonyLayoutDelegate::Get() |
21 : layout_delegate_.Pointer(); | 91 : layout_delegate_.Pointer(); |
22 } | 92 } |
23 | 93 |
24 int LayoutDelegate::GetMetric(Metric metric) const { | 94 int LayoutDelegate::GetMetric(Metric metric) const { |
25 switch (metric) { | 95 switch (metric) { |
26 case Metric::BUTTON_HORIZONTAL_PADDING: | 96 case Metric::BUTTON_HORIZONTAL_PADDING: |
27 return ChromeViewsDelegate::GetInstance()->GetDefaultDistanceMetric( | 97 return ChromeViewsDelegate::GetInstance()->GetDefaultDistanceMetric( |
28 views::DistanceMetric::BUTTON_HORIZONTAL_PADDING); | 98 views::DistanceMetric::BUTTON_HORIZONTAL_PADDING); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 return true; | 147 return true; |
78 } | 148 } |
79 | 149 |
80 bool LayoutDelegate::IsHarmonyMode() const { | 150 bool LayoutDelegate::IsHarmonyMode() const { |
81 return false; | 151 return false; |
82 } | 152 } |
83 | 153 |
84 int LayoutDelegate::GetDialogPreferredWidth(DialogWidth width) const { | 154 int LayoutDelegate::GetDialogPreferredWidth(DialogWidth width) const { |
85 return 0; | 155 return 0; |
86 } | 156 } |
OLD | NEW |