Commit 39f06061 authored by Dominic Battre's avatar Dominic Battre Committed by Commit Bot

Override scroll{Width,Height} in suggest state

We have added

  input::-internal-input-suggested,
  textarea::-internal-input-suggested {
      font: -webkit-small-control !important;
  }

to html.css to prevent that the scrollWidth/scrollHeight attributes of
an input element disclose information about autofill content that is in
suggest (preview) state.

This CL mocks out the scrollWidth/scrollHeight values in preview state
and may allow us to disable the font overriding again.

Bug: 1035058
Change-Id: I36a4a3498c240e15c7d72de1746f9697bb875e9e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1972849
Commit-Queue: Koji Ishii <kojii@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#726255}
parent 9bce9f6e
...@@ -533,6 +533,11 @@ input::-internal-input-suggested { ...@@ -533,6 +533,11 @@ input::-internal-input-suggested {
input::-internal-input-suggested, input::-internal-input-suggested,
textarea::-internal-input-suggested { textarea::-internal-input-suggested {
font: -webkit-small-control !important; font: -webkit-small-control !important;
/* Prevent that overflow affects the scrollable area. Without this,
LayoutBox::*Scroll{Height,Width}() may determine the scroll width/height
from the scrollable area instead of from the overrides in
LayoutTextControl{Single,Multi}Line::Scroll{Height,Width}(). */
overflow: hidden !important;
} }
input[type="password" i] { input[type="password" i] {
......
...@@ -96,4 +96,20 @@ LayoutObject* LayoutTextControlMultiLine::LayoutSpecialExcludedChild( ...@@ -96,4 +96,20 @@ LayoutObject* LayoutTextControlMultiLine::LayoutSpecialExcludedChild(
return placeholder_layout_object; return placeholder_layout_object;
} }
LayoutUnit LayoutTextControlMultiLine::ScrollWidth() const {
// 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 {
// 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
...@@ -61,6 +61,9 @@ class LayoutTextControlMultiLine final : public LayoutTextControl { ...@@ -61,6 +61,9 @@ 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;
}; };
DEFINE_LAYOUT_OBJECT_TYPE_CASTS(LayoutTextControlMultiLine, IsTextArea()); DEFINE_LAYOUT_OBJECT_TYPE_CASTS(LayoutTextControlMultiLine, IsTextArea());
......
...@@ -258,6 +258,11 @@ void LayoutTextControlSingleLine::Autoscroll(const PhysicalOffset& position) { ...@@ -258,6 +258,11 @@ void LayoutTextControlSingleLine::Autoscroll(const PhysicalOffset& position) {
} }
LayoutUnit LayoutTextControlSingleLine::ScrollWidth() const { LayoutUnit LayoutTextControlSingleLine::ScrollWidth() const {
// 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();
if (LayoutBox* inner = InnerEditorElement() if (LayoutBox* inner = InnerEditorElement()
? InnerEditorElement()->GetLayoutBox() ? InnerEditorElement()->GetLayoutBox()
: nullptr) { : nullptr) {
...@@ -270,6 +275,11 @@ LayoutUnit LayoutTextControlSingleLine::ScrollWidth() const { ...@@ -270,6 +275,11 @@ LayoutUnit LayoutTextControlSingleLine::ScrollWidth() const {
} }
LayoutUnit LayoutTextControlSingleLine::ScrollHeight() const { LayoutUnit LayoutTextControlSingleLine::ScrollHeight() const {
// 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();
if (LayoutBox* inner = InnerEditorElement() if (LayoutBox* inner = InnerEditorElement()
? InnerEditorElement()->GetLayoutBox() ? InnerEditorElement()->GetLayoutBox()
: nullptr) { : nullptr) {
......
<html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<body>
<p>Verify that the scroll size does not grow</p>
<div><input id="input" style="width: 10px; height: 6px; font-size: 100px"></div>
<div><textarea id="textarea" style="width: 10px; height: 6px; font-size: 100px">
</textarea></div>
<script>
test(() => {
var value = 'Foooooooooooooooooooooooooooooooooooo';
var input = document.getElementById('input');
var initialScrollWidth = input.scrollWidth;
var initialScrollHeight = input.scrollHeight;
internals.setSuggestedValue(input, value);
var suggestedScrollWidth = input.scrollWidth;
var suggestedScrollHeight = input.scrollHeight;
assert_approx_equals(initialScrollWidth, suggestedScrollWidth, 1,
'Suggestion should not increase the scroll width');
assert_approx_equals(initialScrollHeight, suggestedScrollHeight, 1,
'Suggestion should not increase the scroll height');
}, 'Testing that <input> elements\' scroll size does not grow by suggesting a value.');
test(() => {
var value = 'Foooooooooooooooooooooooooooooooooooo';
var input = document.getElementById('textarea');
var initialScrollWidth = input.scrollWidth;
var initialScrollHeight = input.scrollHeight;
internals.setSuggestedValue(input, value);
var suggestedScrollWidth = input.scrollWidth;
var suggestedScrollHeight = input.scrollHeight;
assert_approx_equals(initialScrollWidth, suggestedScrollWidth, 1,
'Suggestion should not increase the scroll width');
assert_approx_equals(initialScrollHeight, suggestedScrollHeight, 1,
'Suggestion should not increase the scroll height');
}, 'Testing that <textarea> elements\' scroll size does not grow by suggesting a value.');
</script>
</body>
</html>
...@@ -19,9 +19,9 @@ test(() => { ...@@ -19,9 +19,9 @@ test(() => {
internals.setSuggestedValue(reference, value); internals.setSuggestedValue(reference, value);
internals.setSuggestedValue(modified, value); internals.setSuggestedValue(modified, value);
assert_equals(reference.scrollWidth, modified.scrollWidth, assert_approx_equals(reference.scrollWidth, modified.scrollWidth, 1,
'Elements should have same scrollWidth'); 'Elements should have same scrollWidth');
assert_equals(reference.scrollHeight, modified.scrollHeight, assert_approx_equals(reference.scrollHeight, modified.scrollHeight, 1,
'Elements should have same scrollHeight'); 'Elements should have same scrollHeight');
}, 'Testing that <input> elements\' scroll size does not depend on font type.'); }, 'Testing that <input> elements\' scroll size does not depend on font type.');
...@@ -33,9 +33,9 @@ test(() => { ...@@ -33,9 +33,9 @@ test(() => {
internals.setSuggestedValue(reference, value); internals.setSuggestedValue(reference, value);
internals.setSuggestedValue(modified, value); internals.setSuggestedValue(modified, value);
assert_equals(reference.scrollWidth, modified.scrollWidth, assert_approx_equals(reference.scrollWidth, modified.scrollWidth, 1,
'Elements should have same scrollWidth'); 'Elements should have same scrollWidth');
assert_equals(reference.scrollHeight, modified.scrollHeight, assert_approx_equals(reference.scrollHeight, modified.scrollHeight, 1,
'Elements should have same scrollHeight'); 'Elements should have same scrollHeight');
}, 'Testing that <textarea> elements\' scroll size does not depend on font type.'); }, 'Testing that <textarea> elements\' scroll size does not depend on font type.');
</script> </script>
......
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