Commit cc39d222 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Move the logic of scrollWidth / scrollHeight from LayotuTextControlSingleLine to HTMLInputElement

We'd like to share the logic with LayoutNG. This CL fixes some failing
tests with LayoutNGTextField flag.

This CL has no behavior changes for now.

Bug: 1040826
Change-Id: I0c5fa3da1eab44b35c0395298c72ba123bdd1ea3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2491700Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819759}
parent 0ab7f08f
......@@ -71,7 +71,8 @@
#include "third_party/blink/renderer/core/html/parser/html_parser_idioms.h"
#include "third_party/blink/renderer/core/html_names.h"
#include "third_party/blink/renderer/core/input_type_names.h"
#include "third_party/blink/renderer/core/layout/layout_object.h"
#include "third_party/blink/renderer/core/layout/adjust_for_absolute_zoom.h"
#include "third_party/blink/renderer/core/layout/layout_box.h"
#include "third_party/blink/renderer/core/page/chrome_client.h"
#include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/platform/bindings/exception_messages.h"
......@@ -1785,19 +1786,50 @@ bool HTMLInputElement::MatchesDefaultPseudoClass() const {
}
int HTMLInputElement::scrollWidth() {
if (!IsTextField())
return TextControlElement::scrollWidth();
// If in preview state, fake the scroll width to prevent that any information
// about the suggested content can be derived from the size.
if (IsTextField() && !SuggestedValue().IsEmpty())
if (!SuggestedValue().IsEmpty())
return clientWidth();
return TextControlElement::scrollWidth();
GetDocument().UpdateStyleAndLayoutForNode(this,
DocumentUpdateReason::kJavaScript);
const auto* editor = InnerEditorElement();
const auto* editor_box = editor ? editor->GetLayoutBox() : nullptr;
const auto* box = GetLayoutBox();
if (!editor_box || !box)
return TextControlElement::scrollWidth();
// Adjust scrollWidth to include input element horizontal paddings and
// decoration width.
LayoutUnit adjustment = box->ClientWidth() - editor_box->ClientWidth();
return AdjustForAbsoluteZoom::AdjustLayoutUnit(
editor_box->ScrollWidth() + adjustment, box->StyleRef())
.Round();
}
int HTMLInputElement::scrollHeight() {
if (!IsTextField())
return TextControlElement::scrollHeight();
// If in preview state, fake the scroll height to prevent that any information
// about the suggested content can be derived from the size.
if (IsTextField() && !SuggestedValue().IsEmpty())
if (!SuggestedValue().IsEmpty())
return clientHeight();
return TextControlElement::scrollHeight();
GetDocument().UpdateStyleAndLayoutForNode(this,
DocumentUpdateReason::kJavaScript);
const auto* editor = InnerEditorElement();
const auto* editor_box = editor ? editor->GetLayoutBox() : nullptr;
const auto* box = GetLayoutBox();
if (!editor_box || !box)
return TextControlElement::scrollHeight();
// Adjust scrollHeight to include input element vertical paddings and
// decoration height.
LayoutUnit adjustment = box->ClientHeight() - editor_box->ClientHeight();
return AdjustForAbsoluteZoom::AdjustLayoutUnit(
editor_box->ScrollHeight() + adjustment, box->StyleRef())
.Round();
}
bool HTMLInputElement::ShouldAppearChecked() const {
......
......@@ -177,34 +177,6 @@ bool LayoutTextControlSingleLine::NodeAtPoint(
return true;
}
LayoutUnit LayoutTextControlSingleLine::ScrollWidth() const {
NOT_DESTROYED();
// TODO(crbug.com/1040826): Move this logic to HTMLInputElement::scrollWidth.
if (LayoutBox* inner = InnerEditorElement()
? InnerEditorElement()->GetLayoutBox()
: nullptr) {
// Adjust scrollWidth to inculde input element horizontal paddings and
// decoration width
LayoutUnit adjustment = ClientWidth() - inner->ClientWidth();
return inner->ScrollWidth() + adjustment;
}
return LayoutBlockFlow::ScrollWidth();
}
LayoutUnit LayoutTextControlSingleLine::ScrollHeight() const {
NOT_DESTROYED();
// TODO(crbug.com/1040826): Move this logic to HTMLInputElement::scrollHeight.
if (LayoutBox* inner = InnerEditorElement()
? InnerEditorElement()->GetLayoutBox()
: nullptr) {
// Adjust scrollHeight to include input element vertical paddings and
// decoration height
LayoutUnit adjustment = ClientHeight() - inner->ClientHeight();
return inner->ScrollHeight() + adjustment;
}
return LayoutBlockFlow::ScrollHeight();
}
HTMLInputElement* LayoutTextControlSingleLine::InputElement() const {
NOT_DESTROYED();
return To<HTMLInputElement>(GetNode());
......
......@@ -59,10 +59,6 @@ class LayoutTextControlSingleLine : public LayoutTextControl {
const PhysicalOffset& accumulated_offset,
HitTestAction) final;
// Subclassed to forward to our inner div.
LayoutUnit ScrollWidth() const final;
LayoutUnit ScrollHeight() const final;
int TextBlockWidth() const;
void ComputeVisualOverflow(bool recompute_floats) override;
......
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