Commit 987f3b42 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Text Control NG: Move the logic to mock scrollWidth/Height for autofill preview

... from LayoutTextControl*Line to HTMLInputElement and HTMLTextAreaElement.

Reasons:
- The mocking behavior is a matter of DOM, not layout.
- Share the logic between the legacy layout and LayoutNG
- Avoid a layout-overflow incompatibility described in the bug

This CL has no behavior changes.

Bug: 1138820
Change-Id: I437efed89e01f50896fa24d41735d2dfe9e0c00b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2488963Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Reviewed-by: default avatarDominic Battré <battre@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819369}
parent aa18dd9f
...@@ -316,8 +316,8 @@ class CORE_EXPORT Element : public ContainerNode, public Animatable { ...@@ -316,8 +316,8 @@ class CORE_EXPORT Element : public ContainerNode, public Animatable {
double scrollTop(); double scrollTop();
void setScrollLeft(double); void setScrollLeft(double);
void setScrollTop(double); void setScrollTop(double);
int scrollWidth(); virtual int scrollWidth();
int scrollHeight(); virtual int scrollHeight();
void scrollBy(double x, double y); void scrollBy(double x, double y);
void scrollBy(const ScrollToOptions*); void scrollBy(const ScrollToOptions*);
......
...@@ -1784,6 +1784,22 @@ bool HTMLInputElement::MatchesDefaultPseudoClass() const { ...@@ -1784,6 +1784,22 @@ bool HTMLInputElement::MatchesDefaultPseudoClass() const {
return input_type_->MatchesDefaultPseudoClass(); return input_type_->MatchesDefaultPseudoClass();
} }
int HTMLInputElement::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())
return clientWidth();
return TextControlElement::scrollWidth();
}
int HTMLInputElement::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())
return clientHeight();
return TextControlElement::scrollHeight();
}
bool HTMLInputElement::ShouldAppearChecked() const { bool HTMLInputElement::ShouldAppearChecked() const {
return checked() && input_type_->IsCheckable(); return checked() && input_type_->IsCheckable();
} }
......
...@@ -374,8 +374,9 @@ class CORE_EXPORT HTMLInputElement ...@@ -374,8 +374,9 @@ class CORE_EXPORT HTMLInputElement
bool IsInteractiveContent() const final; bool IsInteractiveContent() const final;
bool IsLabelable() const final; bool IsLabelable() const final;
bool MatchesDefaultPseudoClass() const override; bool MatchesDefaultPseudoClass() const override;
bool IsTextControl() const final { return IsTextField(); } bool IsTextControl() const final { return IsTextField(); }
int scrollWidth() override;
int scrollHeight() override;
bool CanTriggerImplicitSubmission() const final { return IsTextField(); } bool CanTriggerImplicitSubmission() const final { return IsTextField(); }
......
...@@ -47,6 +47,8 @@ ...@@ -47,6 +47,8 @@
#include "third_party/blink/renderer/core/html/parser/html_parser_idioms.h" #include "third_party/blink/renderer/core/html/parser/html_parser_idioms.h"
#include "third_party/blink/renderer/core/html/shadow/shadow_element_names.h" #include "third_party/blink/renderer/core/html/shadow/shadow_element_names.h"
#include "third_party/blink/renderer/core/html_names.h" #include "third_party/blink/renderer/core/html_names.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/layout/layout_object.h" #include "third_party/blink/renderer/core/layout/layout_object.h"
#include "third_party/blink/renderer/core/layout/layout_object_factory.h" #include "third_party/blink/renderer/core/layout/layout_object_factory.h"
#include "third_party/blink/renderer/core/page/chrome_client.h" #include "third_party/blink/renderer/core/page/chrome_client.h"
...@@ -106,6 +108,42 @@ void HTMLTextAreaElement::RestoreFormControlState( ...@@ -106,6 +108,42 @@ void HTMLTextAreaElement::RestoreFormControlState(
setValue(state[0]); setValue(state[0]);
} }
int HTMLTextAreaElement::scrollWidth() {
if (SuggestedValue().IsEmpty())
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.
GetDocument().UpdateStyleAndLayoutForNode(this,
DocumentUpdateReason::kJavaScript);
auto* editor = InnerEditorElement();
auto* editor_box = editor ? editor->GetLayoutBox() : nullptr;
auto* box = GetLayoutBox();
if (!box || !editor_box)
return TextControlElement::scrollWidth();
LayoutUnit width =
editor_box->ClientWidth() + box->PaddingLeft() + box->PaddingRight();
return AdjustForAbsoluteZoom::AdjustLayoutUnit(width, box->StyleRef())
.Round();
}
int HTMLTextAreaElement::scrollHeight() {
if (SuggestedValue().IsEmpty())
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.
GetDocument().UpdateStyleAndLayoutForNode(this,
DocumentUpdateReason::kJavaScript);
auto* editor = InnerEditorElement();
auto* editor_box = editor ? editor->GetLayoutBox() : nullptr;
auto* box = GetLayoutBox();
if (!box || !editor_box)
return TextControlElement::scrollHeight();
LayoutUnit height =
editor_box->ClientHeight() + box->PaddingTop() + box->PaddingBottom();
return AdjustForAbsoluteZoom::AdjustLayoutUnit(height, box->StyleRef())
.Round();
}
void HTMLTextAreaElement::ChildrenChanged(const ChildrenChange& change) { void HTMLTextAreaElement::ChildrenChanged(const ChildrenChange& change) {
HTMLElement::ChildrenChanged(change); HTMLElement::ChildrenChanged(change);
SetLastChangeWasNotUserEdit(); SetLastChangeWasNotUserEdit();
......
...@@ -109,7 +109,8 @@ class CORE_EXPORT HTMLTextAreaElement final : public TextControlElement { ...@@ -109,7 +109,8 @@ class CORE_EXPORT HTMLTextAreaElement final : public TextControlElement {
void RestoreFormControlState(const FormControlState&) override; void RestoreFormControlState(const FormControlState&) override;
bool IsTextControl() const override { return true; } bool IsTextControl() const override { return true; }
int scrollWidth() override;
int scrollHeight() override;
void ChildrenChanged(const ChildrenChange&) override; void ChildrenChanged(const ChildrenChange&) override;
void ParseAttribute(const AttributeModificationParams&) override; void ParseAttribute(const AttributeModificationParams&) override;
bool IsPresentationAttribute(const QualifiedName&) const override; bool IsPresentationAttribute(const QualifiedName&) const override;
......
...@@ -85,22 +85,4 @@ LayoutObject* LayoutTextControlMultiLine::LayoutSpecialExcludedChild( ...@@ -85,22 +85,4 @@ LayoutObject* LayoutTextControlMultiLine::LayoutSpecialExcludedChild(
return placeholder_layout_object; return placeholder_layout_object;
} }
LayoutUnit LayoutTextControlMultiLine::ScrollWidth() const {
NOT_DESTROYED();
// If in preview state, fake the scroll width to prevent that any information
// about the suggested content can be derived from the size.
if (!GetTextControlElement()->SuggestedValue().IsEmpty())
return ClientWidth();
return LayoutTextControl::ScrollWidth();
}
LayoutUnit LayoutTextControlMultiLine::ScrollHeight() const {
NOT_DESTROYED();
// If in preview state, fake the scroll height to prevent that any information
// about the suggested content can be derived from the size.
if (!GetTextControlElement()->SuggestedValue().IsEmpty())
return ClientHeight();
return LayoutTextControl::ScrollHeight();
}
} // namespace blink } // namespace blink
...@@ -58,9 +58,6 @@ class LayoutTextControlMultiLine final : public LayoutTextControl { ...@@ -58,9 +58,6 @@ class LayoutTextControlMultiLine final : public LayoutTextControl {
LayoutObject* LayoutSpecialExcludedChild(bool relayout_children, LayoutObject* LayoutSpecialExcludedChild(bool relayout_children,
SubtreeLayoutScope&) override; SubtreeLayoutScope&) override;
LayoutUnit ScrollWidth() const override;
LayoutUnit ScrollHeight() const override;
}; };
} // namespace blink } // namespace blink
......
...@@ -179,11 +179,7 @@ bool LayoutTextControlSingleLine::NodeAtPoint( ...@@ -179,11 +179,7 @@ bool LayoutTextControlSingleLine::NodeAtPoint(
LayoutUnit LayoutTextControlSingleLine::ScrollWidth() const { LayoutUnit LayoutTextControlSingleLine::ScrollWidth() const {
NOT_DESTROYED(); NOT_DESTROYED();
// If in preview state, fake the scroll width to prevent that any information // TODO(crbug.com/1040826): Move this logic to HTMLInputElement::scrollWidth.
// about the suggested content can be derived from the size.
if (!GetTextControlElement()->SuggestedValue().IsEmpty())
return ClientWidth();
if (LayoutBox* inner = InnerEditorElement() if (LayoutBox* inner = InnerEditorElement()
? InnerEditorElement()->GetLayoutBox() ? InnerEditorElement()->GetLayoutBox()
: nullptr) { : nullptr) {
...@@ -197,11 +193,7 @@ LayoutUnit LayoutTextControlSingleLine::ScrollWidth() const { ...@@ -197,11 +193,7 @@ LayoutUnit LayoutTextControlSingleLine::ScrollWidth() const {
LayoutUnit LayoutTextControlSingleLine::ScrollHeight() const { LayoutUnit LayoutTextControlSingleLine::ScrollHeight() const {
NOT_DESTROYED(); NOT_DESTROYED();
// If in preview state, fake the scroll height to prevent that any information // TODO(crbug.com/1040826): Move this logic to HTMLInputElement::scrollHeight.
// about the suggested content can be derived from the size.
if (!GetTextControlElement()->SuggestedValue().IsEmpty())
return ClientHeight();
if (LayoutBox* inner = InnerEditorElement() if (LayoutBox* inner = InnerEditorElement()
? InnerEditorElement()->GetLayoutBox() ? InnerEditorElement()->GetLayoutBox()
: nullptr) { : nullptr) {
......
...@@ -1195,7 +1195,6 @@ crbug.com/1121942 virtual/layout_ng_printing/printing/webgl-oversized-printing.h ...@@ -1195,7 +1195,6 @@ crbug.com/1121942 virtual/layout_ng_printing/printing/webgl-oversized-printing.h
### Textarea NG ### Textarea NG
crbug.com/1140307 accessibility/inline-text-textarea.html [ Failure ] crbug.com/1140307 accessibility/inline-text-textarea.html [ Failure ]
crbug.com/1137666 editing/caret/caret-direction-auto.html [ Failure ] crbug.com/1137666 editing/caret/caret-direction-auto.html [ Failure ]
crbug.com/1138820 fast/forms/text/input-appearance-scroll-size-mocked.html [ Failure ]
# ====== LayoutNG-only failures until here ====== # ====== LayoutNG-only failures until here ======
......
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