Commit 2cdb2cb6 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

TextControl NG: Make LayoutTextControl::GetAvgCharWidth() static and public

This CL will help to implement intrinsic sizes of LayoutNGTextControl*.

- Change the argument of the function to |const ComputedStyle&| in order
to avoid using StyleRef() member function.

This CL has no behavior changes.

Bug: 1040826
Change-Id: Ic66b5a25d28806bfc71ab0011357571924d1e189
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2440725
Commit-Queue: Kent Tamura <tkent@chromium.org>
Commit-Queue: Koji Ishii <kojii@chromium.org>
Auto-Submit: Kent Tamura <tkent@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812617}
parent 1ddd9414
......@@ -208,10 +208,10 @@ bool LayoutTextControl::HasValidAvgCharWidth(const SimpleFontData* font_data,
return !font_families_with_invalid_char_width_map->Contains(family);
}
float LayoutTextControl::GetAvgCharWidth(const AtomicString& family) const {
NOT_DESTROYED();
const Font& font = StyleRef().GetFont();
// static
float LayoutTextControl::GetAvgCharWidth(const ComputedStyle& style) {
const Font& font = style.GetFont();
const AtomicString family = font.GetFontDescription().Family().Family();
const SimpleFontData* primary_font = font.PrimaryFont();
if (primary_font && HasValidAvgCharWidth(primary_font, family))
return roundf(primary_font->AvgCharWidth());
......@@ -219,7 +219,7 @@ float LayoutTextControl::GetAvgCharWidth(const AtomicString& family) const {
const UChar kCh = '0';
const String str = String(&kCh, 1);
TextRun text_run =
ConstructTextRun(font, str, StyleRef(), TextRun::kAllowTrailingExpansion);
ConstructTextRun(font, str, style, TextRun::kAllowTrailingExpansion);
return font.Width(text_run);
}
......@@ -229,10 +229,7 @@ MinMaxSizes LayoutTextControl::ComputeIntrinsicLogicalWidths() const {
sizes += BorderAndPaddingLogicalWidth();
// Use average character width. Matches IE.
AtomicString family =
StyleRef().GetFont().GetFontDescription().Family().Family();
sizes.max_size += PreferredContentLogicalWidth(
const_cast<LayoutTextControl*>(this)->GetAvgCharWidth(family));
sizes.max_size += PreferredContentLogicalWidth(GetAvgCharWidth(StyleRef()));
if (InnerEditorElement()) {
if (LayoutBox* inner_editor_layout_box =
InnerEditorElement()->GetLayoutBox()) {
......
......@@ -49,6 +49,8 @@ class CORE_EXPORT LayoutTextControl : public LayoutBlockFlow {
return true;
}
static float GetAvgCharWidth(const ComputedStyle& style);
protected:
LayoutTextControl(TextControlElement*);
......@@ -66,7 +68,6 @@ class CORE_EXPORT LayoutTextControl : public LayoutBlockFlow {
static bool HasValidAvgCharWidth(const SimpleFontData*,
const AtomicString& family);
float GetAvgCharWidth(const AtomicString& family) const;
virtual LayoutUnit PreferredContentLogicalWidth(float char_width) const = 0;
virtual LayoutUnit ComputeControlLogicalHeight(
LayoutUnit line_height,
......
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