| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "ui/views/style/typography_provider.h" | 5 #include "ui/views/style/typography_provider.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ui/base/default_style.h" | 8 #include "ui/base/default_style.h" |
| 9 #include "ui/base/resource/resource_bundle.h" | 9 #include "ui/base/resource/resource_bundle.h" |
| 10 #include "ui/views/style/typography.h" | 10 #include "ui/views/style/typography.h" |
| 11 | 11 |
| 12 using gfx::Font; |
| 13 |
| 12 namespace views { | 14 namespace views { |
| 15 namespace { |
| 16 |
| 17 Font::Weight GetValueBolderThan(Font::Weight weight) { |
| 18 switch (weight) { |
| 19 case Font::Weight::BOLD: |
| 20 return Font::Weight::EXTRA_BOLD; |
| 21 case Font::Weight::EXTRA_BOLD: |
| 22 case Font::Weight::BLACK: |
| 23 return Font::Weight::BLACK; |
| 24 default: |
| 25 return Font::Weight::BOLD; |
| 26 } |
| 27 } |
| 28 |
| 29 } // namespace |
| 30 |
| 31 // static |
| 32 Font::Weight TypographyProvider::WeightNotLighterThanNormal( |
| 33 Font::Weight weight) { |
| 34 if (ResourceBundle::GetSharedInstance() |
| 35 .GetFontListWithDelta(0, Font::NORMAL, Font::Weight::NORMAL) |
| 36 .GetFontWeight() < weight) |
| 37 return weight; |
| 38 return Font::Weight::NORMAL; |
| 39 } |
| 13 | 40 |
| 14 const gfx::FontList& DefaultTypographyProvider::GetFont(int context, | 41 const gfx::FontList& DefaultTypographyProvider::GetFont(int context, |
| 15 int style) const { | 42 int style) const { |
| 16 int size_delta; | 43 int size_delta; |
| 17 gfx::Font::Weight font_weight; | 44 Font::Weight font_weight; |
| 18 GetDefaultFont(context, style, &size_delta, &font_weight); | 45 GetDefaultFont(context, style, &size_delta, &font_weight); |
| 19 return ResourceBundle::GetSharedInstance().GetFontListWithDelta( | 46 return ResourceBundle::GetSharedInstance().GetFontListWithDelta( |
| 20 size_delta, gfx::Font::NORMAL, font_weight); | 47 size_delta, Font::NORMAL, font_weight); |
| 21 } | 48 } |
| 22 | 49 |
| 23 void DefaultTypographyProvider::GetDefaultFont( | 50 SkColor DefaultTypographyProvider::GetColor(int context, int style) const { |
| 24 int context, | 51 return SK_ColorBLACK; |
| 25 int style, | 52 } |
| 26 int* size_delta, | 53 |
| 27 gfx::Font::Weight* font_weight) const { | 54 int DefaultTypographyProvider::GetLineHeight(int context, int style) const { |
| 55 return 0; |
| 56 } |
| 57 |
| 58 // static |
| 59 void DefaultTypographyProvider::GetDefaultFont(int context, |
| 60 int style, |
| 61 int* size_delta, |
| 62 Font::Weight* font_weight) { |
| 63 *font_weight = Font::Weight::NORMAL; |
| 64 |
| 28 switch (context) { | 65 switch (context) { |
| 66 case style::CONTEXT_BUTTON_MD: |
| 67 *size_delta = ui::kLabelFontSizeDelta; |
| 68 *font_weight = WeightNotLighterThanNormal(Font::Weight::MEDIUM); |
| 69 break; |
| 29 case style::CONTEXT_DIALOG_TITLE: | 70 case style::CONTEXT_DIALOG_TITLE: |
| 30 *size_delta = ui::kTitleFontSizeDelta; | 71 *size_delta = ui::kTitleFontSizeDelta; |
| 31 break; | 72 break; |
| 73 case style::CONTEXT_TOUCH_MENU: |
| 74 *size_delta = -1; |
| 75 break; |
| 32 default: | 76 default: |
| 33 *size_delta = ui::kLabelFontSizeDelta; | 77 *size_delta = ui::kLabelFontSizeDelta; |
| 34 break; | 78 break; |
| 35 } | 79 } |
| 36 | 80 |
| 37 switch (style) { | 81 switch (style) { |
| 38 case style::STYLE_TAB_ACTIVE: | 82 case style::STYLE_TAB_ACTIVE: |
| 39 *font_weight = gfx::Font::Weight::BOLD; | 83 *font_weight = Font::Weight::BOLD; |
| 40 break; | 84 break; |
| 41 default: | 85 case style::STYLE_DIALOG_BUTTON_DEFAULT: |
| 42 *font_weight = gfx::Font::Weight::NORMAL; | 86 // Only non-MD default buttons should "increase" in boldness. |
| 87 if (context == style::CONTEXT_BUTTON) { |
| 88 *font_weight = GetValueBolderThan( |
| 89 ResourceBundle::GetSharedInstance() |
| 90 .GetFontListWithDelta(*size_delta, Font::NORMAL, *font_weight) |
| 91 .GetFontWeight()); |
| 92 } |
| 43 break; | 93 break; |
| 44 } | 94 } |
| 45 } | 95 } |
| 46 | 96 |
| 47 SkColor DefaultTypographyProvider::GetColor(int context, int style) const { | |
| 48 return SK_ColorBLACK; | |
| 49 } | |
| 50 | |
| 51 int DefaultTypographyProvider::GetLineHeight(int context, int style) const { | |
| 52 return 0; | |
| 53 } | |
| 54 | |
| 55 } // namespace views | 97 } // namespace views |
| OLD | NEW |