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