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