Skip to content

Commit

Permalink
Also map width/height to aspect-ratio for <input type=image>
Browse files Browse the repository at this point in the history
See also https://crrev.com/c/2495560 and
whatwg/html#6032

Bug: 1137004
Change-Id: I17ff2c6f96b2cb9058858a0dc2439885f62ef414
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2690929
Auto-Submit: Christian Biesinger <cbiesinger@chromium.org>
Commit-Queue: Mason Freed <masonfreed@chromium.org>
Reviewed-by: Mason Freed <masonfreed@chromium.org>
Cr-Commit-Position: refs/heads/master@{#853591}
  • Loading branch information
cbiesinger authored and Chromium LUCI CQ committed Feb 12, 2021
1 parent efacd53 commit cc7930e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 10 additions & 2 deletions third_party/blink/renderer/core/html/forms/html_input_element.cc
Original file line number Diff line number Diff line change
Expand Up @@ -758,11 +758,19 @@ void HTMLInputElement::CollectStyleForPresentationAttribute(
if (input_type_->ShouldRespectAlignAttribute())
ApplyAlignmentAttributeToStyle(value, style);
} else if (name == html_names::kWidthAttr) {
if (input_type_->ShouldRespectHeightAndWidthAttributes())
if (input_type_->ShouldRespectHeightAndWidthAttributes()) {
AddHTMLLengthToStyle(style, CSSPropertyID::kWidth, value);
const AtomicString& height = FastGetAttribute(html_names::kHeightAttr);
if (height)
ApplyAspectRatioToStyle(value, height, style);
}
} else if (name == html_names::kHeightAttr) {
if (input_type_->ShouldRespectHeightAndWidthAttributes())
if (input_type_->ShouldRespectHeightAndWidthAttributes()) {
AddHTMLLengthToStyle(style, CSSPropertyID::kHeight, value);
const AtomicString& width = FastGetAttribute(html_names::kWidthAttr);
if (width)
ApplyAspectRatioToStyle(width, value, style);
}
} else if (name == html_names::kBorderAttr &&
type() == input_type_names::kImage) { // FIXME: Remove type check.
ApplyBorderAttributeToStyle(value, style);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@

function test_computed_style(width, height, expected) {
test_computed_style_aspect_ratio("img", {width: width, height: height}, expected);
test_computed_style_aspect_ratio("input", {type: "image", width: width, height: height}, expected);
// input type=submit should not do this mapping.
test_computed_style_aspect_ratio("input", {type: "submit", width: width, height: height}, "auto");
}

// Create and append a new image and immediately check the ratio.
Expand Down

0 comments on commit cc7930e

Please sign in to comment.