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

Remove unnecessary ComputedStyle cloning in CustomStyleForLayoutObject()

This CL has no user-visible behavior changes.

Change-Id: I80da7333d3a8a91fd37b460a2f2582b6182ae9a9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2062845Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742588}
parent 3f912638
......@@ -574,8 +574,7 @@ void DateTimeEditElement::BlurByOwner() {
scoped_refptr<ComputedStyle> DateTimeEditElement::CustomStyleForLayoutObject() {
// FIXME: This is a kind of layout. We might want to introduce new
// layoutObject.
scoped_refptr<ComputedStyle> original_style = OriginalStyleForLayoutObject();
scoped_refptr<ComputedStyle> style = ComputedStyle::Clone(*original_style);
scoped_refptr<ComputedStyle> style = OriginalStyleForLayoutObject();
float width = 0;
for (Node* child = FieldsWrapperElement()->firstChild(); child;
child = child->nextSibling()) {
......
......@@ -1964,8 +1964,9 @@ bool HTMLInputElement::IsInteractiveContent() const {
}
scoped_refptr<ComputedStyle> HTMLInputElement::CustomStyleForLayoutObject() {
return input_type_view_->CustomStyleForLayoutObject(
OriginalStyleForLayoutObject());
scoped_refptr<ComputedStyle> style = OriginalStyleForLayoutObject();
input_type_view_->CustomStyleForLayoutObject(*style);
return style;
}
void HTMLInputElement::DidRecalcStyle(const StyleRecalcChange change) {
......
......@@ -279,13 +279,9 @@ void ImageInputType::CreateShadowSubtree() {
HTMLImageFallbackHelper::CreateAltTextShadowTree(GetElement());
}
scoped_refptr<ComputedStyle> ImageInputType::CustomStyleForLayoutObject(
scoped_refptr<ComputedStyle> new_style) {
if (!use_fallback_content_)
return new_style;
return HTMLImageFallbackHelper::CustomStyleForAltText(GetElement(),
std::move(new_style));
void ImageInputType::CustomStyleForLayoutObject(ComputedStyle& style) {
if (use_fallback_content_)
HTMLImageFallbackHelper::CustomStyleForAltText(GetElement(), style);
}
} // namespace blink
......@@ -41,8 +41,7 @@ namespace blink {
class ImageInputType final : public BaseButtonInputType {
public:
explicit ImageInputType(HTMLInputElement&);
scoped_refptr<ComputedStyle> CustomStyleForLayoutObject(
scoped_refptr<ComputedStyle>) override;
void CustomStyleForLayoutObject(ComputedStyle& style) override;
private:
void CountUsage() override;
......
......@@ -96,10 +96,7 @@ LayoutObject* InputTypeView::CreateLayoutObject(const ComputedStyle& style,
return LayoutObject::CreateObject(&GetElement(), style, legacy);
}
scoped_refptr<ComputedStyle> InputTypeView::CustomStyleForLayoutObject(
scoped_refptr<ComputedStyle> original_style) {
return original_style;
}
void InputTypeView::CustomStyleForLayoutObject(ComputedStyle&) {}
TextDirection InputTypeView::ComputedTextDirection() {
return GetElement().ComputedStyleRef().Direction();
......
......@@ -103,8 +103,7 @@ class CORE_EXPORT InputTypeView : public GarbageCollectedMixin {
virtual bool TypeShouldForceLegacyLayout() const;
virtual LayoutObject* CreateLayoutObject(const ComputedStyle&,
LegacyLayout) const;
virtual scoped_refptr<ComputedStyle> CustomStyleForLayoutObject(
scoped_refptr<ComputedStyle>);
virtual void CustomStyleForLayoutObject(ComputedStyle& style);
virtual TextDirection ComputedTextDirection();
virtual void StartResourceLoading();
virtual void ClosePopupView();
......
......@@ -365,25 +365,17 @@ void MultipleFieldsTemporalInputTypeView::Blur() {
ClosePopupView();
}
scoped_refptr<ComputedStyle>
MultipleFieldsTemporalInputTypeView::CustomStyleForLayoutObject(
scoped_refptr<ComputedStyle> original_style) {
EDisplay original_display = original_style->Display();
void MultipleFieldsTemporalInputTypeView::CustomStyleForLayoutObject(
ComputedStyle& style) {
EDisplay original_display = style.Display();
EDisplay new_display = original_display;
if (original_display == EDisplay::kInline ||
original_display == EDisplay::kInlineBlock)
new_display = EDisplay::kInlineFlex;
else if (original_display == EDisplay::kBlock)
new_display = EDisplay::kFlex;
TextDirection content_direction = ComputedTextDirection();
if (original_style->Direction() == content_direction &&
original_display == new_display)
return original_style;
scoped_refptr<ComputedStyle> style = ComputedStyle::Clone(*original_style);
style->SetDirection(content_direction);
style->SetDisplay(new_display);
return style;
style.SetDisplay(new_display);
style.SetDirection(ComputedTextDirection());
}
void MultipleFieldsTemporalInputTypeView::CreateShadowSubtree() {
......
......@@ -98,8 +98,7 @@ class MultipleFieldsTemporalInputTypeView final
void Blur() final;
void ClosePopupView() override;
bool HasOpenedPopup() const override;
scoped_refptr<ComputedStyle> CustomStyleForLayoutObject(
scoped_refptr<ComputedStyle>) override;
void CustomStyleForLayoutObject(ComputedStyle& style) override;
void CreateShadowSubtree() final;
void DestroyShadowSubtree() final;
void DisabledAttributeChanged() final;
......
......@@ -276,12 +276,10 @@ bool TextFieldInputType::ShouldSubmitImplicitly(const Event& event) {
InputTypeView::ShouldSubmitImplicitly(event);
}
scoped_refptr<ComputedStyle> TextFieldInputType::CustomStyleForLayoutObject(
scoped_refptr<ComputedStyle> style) {
void TextFieldInputType::CustomStyleForLayoutObject(ComputedStyle& style) {
// The flag is necessary in order that a text field <input> with non-'visible'
// overflow property doesn't change its baseline.
style->SetShouldIgnoreOverflowPropertyForInlineBlockBaseline();
return style;
style.SetShouldIgnoreOverflowPropertyForInlineBlockBaseline();
}
LayoutObject* TextFieldInputType::CreateLayoutObject(const ComputedStyle&,
......
......@@ -70,8 +70,7 @@ class TextFieldInputType : public InputType,
TextFieldEventBehavior,
TextControlSetValueSelection) override;
void UpdateView() override;
scoped_refptr<ComputedStyle> CustomStyleForLayoutObject(
scoped_refptr<ComputedStyle> original_style) override;
void CustomStyleForLayoutObject(ComputedStyle& style) override;
LayoutObject* CreateLayoutObject(const ComputedStyle&,
LegacyLayout) const override;
......
......@@ -805,9 +805,11 @@ scoped_refptr<ComputedStyle> HTMLImageElement::CustomStyleForLayoutObject() {
case LayoutDisposition::kPrimaryContent: // Fall through.
case LayoutDisposition::kCollapsed:
return OriginalStyleForLayoutObject();
case LayoutDisposition::kFallbackContent:
return HTMLImageFallbackHelper::CustomStyleForAltText(
*this, ComputedStyle::Clone(*OriginalStyleForLayoutObject()));
case LayoutDisposition::kFallbackContent: {
scoped_refptr<ComputedStyle> style = OriginalStyleForLayoutObject();
HTMLImageFallbackHelper::CustomStyleForAltText(*this, *style);
return style;
}
default:
NOTREACHED();
return nullptr;
......
......@@ -138,39 +138,38 @@ void HTMLImageFallbackHelper::CreateAltTextShadowTree(Element& element) {
element.EnsureUserAgentShadowRoot().AppendChild(container);
}
scoped_refptr<ComputedStyle> HTMLImageFallbackHelper::CustomStyleForAltText(
Element& element,
scoped_refptr<ComputedStyle> new_style) {
void HTMLImageFallbackHelper::CustomStyleForAltText(Element& element,
ComputedStyle& new_style) {
// If we have an author shadow root or have not created the UA shadow root
// yet, bail early. We can't use ensureUserAgentShadowRoot() here because that
// would alter the DOM tree during style recalc.
if (element.AuthorShadowRoot() || !element.UserAgentShadowRoot())
return new_style;
return;
ImageFallbackContentBuilder fallback(*element.UserAgentShadowRoot());
// Input elements have a UA shadow root of their own. We may not have replaced
// it with fallback content yet.
if (!fallback.HasContentElements())
return new_style;
return;
if (element.GetDocument().InQuirksMode()) {
// Mimic the behaviour of the image host by setting symmetric dimensions if
// only one dimension is specified.
if (new_style->Width().IsSpecifiedOrIntrinsic() &&
new_style->Height().IsAuto())
new_style->SetHeight(new_style->Width());
else if (new_style->Height().IsSpecifiedOrIntrinsic() &&
new_style->Width().IsAuto())
new_style->SetWidth(new_style->Height());
if (new_style->Width().IsSpecifiedOrIntrinsic() &&
new_style->Height().IsSpecifiedOrIntrinsic()) {
if (new_style.Width().IsSpecifiedOrIntrinsic() &&
new_style.Height().IsAuto())
new_style.SetHeight(new_style.Width());
else if (new_style.Height().IsSpecifiedOrIntrinsic() &&
new_style.Width().IsAuto())
new_style.SetWidth(new_style.Height());
if (new_style.Width().IsSpecifiedOrIntrinsic() &&
new_style.Height().IsSpecifiedOrIntrinsic()) {
fallback.AlignToBaseline();
}
}
bool image_has_intrinsic_dimensions =
new_style->Width().IsSpecifiedOrIntrinsic() &&
new_style->Height().IsSpecifiedOrIntrinsic();
new_style.Width().IsSpecifiedOrIntrinsic() &&
new_style.Height().IsSpecifiedOrIntrinsic();
bool image_has_no_alt_attribute = To<HTMLElement>(element).AltText().IsNull();
bool treat_as_replaced =
image_has_intrinsic_dimensions &&
......@@ -184,22 +183,22 @@ scoped_refptr<ComputedStyle> HTMLImageFallbackHelper::CustomStyleForAltText(
// attribute, or the Document is in quirks mode The user agent is expected
// to treat the element as a replaced element whose content is the text that
// the element represents, if any."
fallback.ShowAsReplaced(new_style->Width(), new_style->Height(),
new_style->EffectiveZoom());
fallback.ShowAsReplaced(new_style.Width(), new_style.Height(),
new_style.EffectiveZoom());
// 16px for the image and 2px for its top/left border/padding offset.
int pixels_for_alt_image = 18;
if (ImageSmallerThanAltImage(pixels_for_alt_image, new_style->Width(),
new_style->Height())) {
if (ImageSmallerThanAltImage(pixels_for_alt_image, new_style.Width(),
new_style.Height())) {
fallback.HideBrokenImageIcon();
} else {
fallback.ShowBorder();
fallback.ShowBrokenImageIcon(new_style->IsLeftToRightDirection());
fallback.ShowBrokenImageIcon(new_style.IsLeftToRightDirection());
}
} else {
if (new_style->Display() == EDisplay::kInline) {
new_style->SetWidth(Length());
new_style->SetHeight(Length());
if (new_style.Display() == EDisplay::kInline) {
new_style.SetWidth(Length());
new_style.SetHeight(Length());
}
if (ElementRepresentsNothing(element)) {
// "If the element is an img element that represents nothing and the user
......@@ -215,11 +214,9 @@ scoped_refptr<ComputedStyle> HTMLImageFallbackHelper::CustomStyleForAltText(
// the text, optionally with an icon indicating that an image is missing,
// so that the user can request the image be displayed or investigate why
// it is not rendering."
fallback.ShowBrokenImageIcon(new_style->IsLeftToRightDirection());
fallback.ShowBrokenImageIcon(new_style.IsLeftToRightDirection());
}
}
return new_style;
}
} // namespace blink
......@@ -5,7 +5,6 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_HTML_HTML_IMAGE_FALLBACK_HELPER_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_HTML_HTML_IMAGE_FALLBACK_HELPER_H_
#include "base/memory/scoped_refptr.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
namespace blink {
......@@ -18,9 +17,7 @@ class HTMLImageFallbackHelper {
public:
static void CreateAltTextShadowTree(Element&);
static scoped_refptr<ComputedStyle> CustomStyleForAltText(
Element&,
scoped_refptr<ComputedStyle> new_style);
static void CustomStyleForAltText(Element&, ComputedStyle& new_style);
};
} // namespace blink
......
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