Commit 5144c66e authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

TextControl NG: Make ScrollbarThickness() and HasValidAvgCharWidth() static and public

This CL makes ScrollbarThickness() and HasValidAvgCharWidth() of
LayoutTextControl static and public in order to share them with
LayoutNG.

- ScrollbarThickness(): It takes a LayoutBox argument

- HasValidAvgCharWidth(): Pass only Font to it because both of
  SimpleFontData and the family name can be obtained through the Font.

This CL has no behavior changes.

Bug: 1040826
Change-Id: Ie7000ef7cca04284b2b1a6ff934809560d37a2da
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2449094
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@{#813654}
parent f1e6067d
...@@ -81,11 +81,11 @@ void LayoutTextControl::StyleDidChange(StyleDifference diff, ...@@ -81,11 +81,11 @@ void LayoutTextControl::StyleDidChange(StyleDifference diff,
} }
} }
int LayoutTextControl::ScrollbarThickness() const { // static
NOT_DESTROYED(); int LayoutTextControl::ScrollbarThickness(const LayoutBox& box) {
return GetDocument().GetPage()->GetScrollbarTheme().ScrollbarThickness( const Page& page = *box.GetDocument().GetPage();
GetDocument().GetPage()->GetChromeClient().WindowToViewportScalar( return page.GetScrollbarTheme().ScrollbarThickness(
GetFrame(), 1.0f)); page.GetChromeClient().WindowToViewportScalar(box.GetFrame(), 1.0f));
} }
void LayoutTextControl::ComputeLogicalHeight( void LayoutTextControl::ComputeLogicalHeight(
...@@ -109,7 +109,7 @@ void LayoutTextControl::ComputeLogicalHeight( ...@@ -109,7 +109,7 @@ void LayoutTextControl::ComputeLogicalHeight(
(StyleRef().OverflowInlineDirection() == EOverflow::kAuto && (StyleRef().OverflowInlineDirection() == EOverflow::kAuto &&
inner_editor->GetLayoutObject()->StyleRef().OverflowWrap() == inner_editor->GetLayoutObject()->StyleRef().OverflowWrap() ==
EOverflowWrap::kNormal)) EOverflowWrap::kNormal))
logical_height += ScrollbarThickness(); logical_height += ScrollbarThickness(*this);
// FIXME: The logical height of the inner text box should have been added // FIXME: The logical height of the inner text box should have been added
// before calling computeLogicalHeight to avoid this hack. // before calling computeLogicalHeight to avoid this hack.
...@@ -179,13 +179,14 @@ static const char* const kFontFamiliesWithInvalidCharWidth[] = { ...@@ -179,13 +179,14 @@ static const char* const kFontFamiliesWithInvalidCharWidth[] = {
// avgCharWidth from the width of a '0'. This only seems to apply to a fixed // avgCharWidth from the width of a '0'. This only seems to apply to a fixed
// number of Mac fonts, but, in order to get similar rendering across platforms, // number of Mac fonts, but, in order to get similar rendering across platforms,
// we do this check for all platforms. // we do this check for all platforms.
bool LayoutTextControl::HasValidAvgCharWidth(const SimpleFontData* font_data, bool LayoutTextControl::HasValidAvgCharWidth(const Font& font) {
const AtomicString& family) { const AtomicString family = font.GetFontDescription().Family().Family();
// Some fonts match avgCharWidth to CJK full-width characters. const SimpleFontData* font_data = font.PrimaryFont();
// Heuristic check to avoid such fonts.
DCHECK(font_data); DCHECK(font_data);
if (!font_data) if (!font_data)
return false; return false;
// Some fonts match avgCharWidth to CJK full-width characters.
// Heuristic check to avoid such fonts.
const FontMetrics& metrics = font_data->GetFontMetrics(); const FontMetrics& metrics = font_data->GetFontMetrics();
if (metrics.HasZeroWidth() && if (metrics.HasZeroWidth() &&
font_data->AvgCharWidth() > metrics.ZeroWidth() * 1.7) font_data->AvgCharWidth() > metrics.ZeroWidth() * 1.7)
...@@ -211,9 +212,8 @@ bool LayoutTextControl::HasValidAvgCharWidth(const SimpleFontData* font_data, ...@@ -211,9 +212,8 @@ bool LayoutTextControl::HasValidAvgCharWidth(const SimpleFontData* font_data,
// static // static
float LayoutTextControl::GetAvgCharWidth(const ComputedStyle& style) { float LayoutTextControl::GetAvgCharWidth(const ComputedStyle& style) {
const Font& font = style.GetFont(); const Font& font = style.GetFont();
const AtomicString family = font.GetFontDescription().Family().Family();
const SimpleFontData* primary_font = font.PrimaryFont(); const SimpleFontData* primary_font = font.PrimaryFont();
if (primary_font && HasValidAvgCharWidth(primary_font, family)) if (primary_font && HasValidAvgCharWidth(font))
return roundf(primary_font->AvgCharWidth()); return roundf(primary_font->AvgCharWidth());
const UChar kCh = '0'; const UChar kCh = '0';
......
...@@ -49,7 +49,9 @@ class CORE_EXPORT LayoutTextControl : public LayoutBlockFlow { ...@@ -49,7 +49,9 @@ class CORE_EXPORT LayoutTextControl : public LayoutBlockFlow {
return true; return true;
} }
static int ScrollbarThickness(const LayoutBox& box);
static float GetAvgCharWidth(const ComputedStyle& style); static float GetAvgCharWidth(const ComputedStyle& style);
static bool HasValidAvgCharWidth(const Font& font);
protected: protected:
LayoutTextControl(TextControlElement*); LayoutTextControl(TextControlElement*);
...@@ -58,16 +60,12 @@ class CORE_EXPORT LayoutTextControl : public LayoutBlockFlow { ...@@ -58,16 +60,12 @@ class CORE_EXPORT LayoutTextControl : public LayoutBlockFlow {
// innerEditorElement may outlive the layout tree. // innerEditorElement may outlive the layout tree.
TextControlInnerEditorElement* InnerEditorElement() const; TextControlInnerEditorElement* InnerEditorElement() const;
int ScrollbarThickness() const;
void StyleDidChange(StyleDifference, const ComputedStyle* old_style) override; void StyleDidChange(StyleDifference, const ComputedStyle* old_style) override;
void HitInnerEditorElement(HitTestResult&, void HitInnerEditorElement(HitTestResult&,
const HitTestLocation&, const HitTestLocation&,
const PhysicalOffset& accumulated_offset); const PhysicalOffset& accumulated_offset);
static bool HasValidAvgCharWidth(const SimpleFontData*,
const AtomicString& family);
virtual LayoutUnit PreferredContentLogicalWidth(float char_width) const = 0; virtual LayoutUnit PreferredContentLogicalWidth(float char_width) const = 0;
virtual LayoutUnit ComputeControlLogicalHeight( virtual LayoutUnit ComputeControlLogicalHeight(
LayoutUnit line_height, LayoutUnit line_height,
......
...@@ -61,7 +61,7 @@ LayoutUnit LayoutTextControlMultiLine::PreferredContentLogicalWidth( ...@@ -61,7 +61,7 @@ LayoutUnit LayoutTextControlMultiLine::PreferredContentLogicalWidth(
NOT_DESTROYED(); NOT_DESTROYED();
int factor = To<HTMLTextAreaElement>(GetNode())->cols(); int factor = To<HTMLTextAreaElement>(GetNode())->cols();
return static_cast<LayoutUnit>(ceilf(char_width * factor)) + return static_cast<LayoutUnit>(ceilf(char_width * factor)) +
ScrollbarThickness(); ScrollbarThickness(*this);
} }
LayoutUnit LayoutTextControlMultiLine::ComputeControlLogicalHeight( LayoutUnit LayoutTextControlMultiLine::ComputeControlLogicalHeight(
......
...@@ -189,8 +189,7 @@ LayoutUnit LayoutTextControlSingleLine::PreferredContentLogicalWidth( ...@@ -189,8 +189,7 @@ LayoutUnit LayoutTextControlSingleLine::PreferredContentLogicalWidth(
float max_char_width = 0.f; float max_char_width = 0.f;
const Font& font = StyleRef().GetFont(); const Font& font = StyleRef().GetFont();
AtomicString family = font.GetFontDescription().Family().Family(); if (HasValidAvgCharWidth(font))
if (HasValidAvgCharWidth(font.PrimaryFont(), family))
max_char_width = roundf(font.PrimaryFont()->MaxCharWidth()); max_char_width = roundf(font.PrimaryFont()->MaxCharWidth());
// For text inputs, IE adds some extra width. // For text inputs, IE adds some extra width.
......
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