PassRefPtr<ComputedStyle> HTMLImageFallbackHelper::customStyleForAltText(Element& element, PassRefPtr<ComputedStyle> newStyle)
{
    // 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 newStyle;

    Element* placeHolder = element.userAgentShadowRoot()->getElementById("alttext-container");
    Element* brokenImage = element.userAgentShadowRoot()->getElementById("alttext-image");
    // Input elements have a UA shadow root of their own. We may not have replaced it with fallback content yet.
    if (!placeHolder || !brokenImage)
        return newStyle;


    if (element.document().inQuirksMode()) {
        // Mimic the behaviour of the image host by setting symmetric dimensions if only one dimension is specified.
        if (newStyle->width().isSpecifiedOrIntrinsic() && newStyle->height().isAuto())
            newStyle->setHeight(newStyle->width());
        else if (newStyle->height().isSpecifiedOrIntrinsic() && newStyle->width().isAuto())
            newStyle->setWidth(newStyle->height());
        if (newStyle->width().isSpecifiedOrIntrinsic() && newStyle->height().isSpecifiedOrIntrinsic()) {
            placeHolder->setInlineStyleProperty(CSSPropertyVerticalAlign, CSSValueBaseline);
        }
    }

    // If the image has specified dimensions allow the alt-text container expand to fill them.
    if (newStyle->width().isSpecifiedOrIntrinsic() && newStyle->height().isSpecifiedOrIntrinsic()) {
        placeHolder->setInlineStyleProperty(CSSPropertyWidth, 100, CSSPrimitiveValue::UnitType::Percentage);
        placeHolder->setInlineStyleProperty(CSSPropertyHeight, 100, CSSPrimitiveValue::UnitType::Percentage);
    }

    // Make sure the broken image icon appears on the appropriate side of the image for the element's writing direction.
    brokenImage->setInlineStyleProperty(CSSPropertyFloat, AtomicString(newStyle->direction() == LTR ? "left" : "right"));

    // This is an <img> with no attributes, so don't display anything.
    if (noImageSourceSpecified(element) && !newStyle->width().isSpecifiedOrIntrinsic() && !newStyle->height().isSpecifiedOrIntrinsic() && toHTMLElement(element).altText().isEmpty())
        newStyle->setDisplay(NONE);

    // This preserves legacy behaviour originally defined when alt-text was managed by LayoutImage.
    if (noImageSourceSpecified(element))
        brokenImage->setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone);
    else
        brokenImage->setInlineStyleProperty(CSSPropertyDisplay, CSSValueInline);

    return newStyle;
}
PassRefPtr<RenderStyle> BaseMultipleFieldsDateAndTimeInputType::customStyleForRenderer(PassRefPtr<RenderStyle> originalStyle)
{
    EDisplay originalDisplay = originalStyle->display();
    EDisplay newDisplay = originalDisplay;
    if (originalDisplay == INLINE || originalDisplay == INLINE_BLOCK)
        newDisplay = INLINE_FLEX;
    else if (originalDisplay == BLOCK)
        newDisplay = FLEX;
    TextDirection contentDirection = element()->locale().isRTL() ? RTL : LTR;
    if (originalStyle->direction() == contentDirection && originalDisplay == newDisplay)
        return originalStyle;

    RefPtr<RenderStyle> style = RenderStyle::clone(originalStyle.get());
    style->setDirection(contentDirection);
    style->setDisplay(newDisplay);
    return style.release();
}
PassRefPtr<ComputedStyle> BaseMultipleFieldsDateAndTimeInputType::customStyleForLayoutObject(PassRefPtr<ComputedStyle> originalStyle)
{
    EDisplay originalDisplay = originalStyle->display();
    EDisplay newDisplay = originalDisplay;
    if (originalDisplay == INLINE || originalDisplay == INLINE_BLOCK)
        newDisplay = INLINE_FLEX;
    else if (originalDisplay == BLOCK)
        newDisplay = FLEX;
    TextDirection contentDirection = computedTextDirection();
    if (originalStyle->direction() == contentDirection && originalDisplay == newDisplay)
        return originalStyle;

    RefPtr<ComputedStyle> style = ComputedStyle::clone(*originalStyle);
    style->setDirection(contentDirection);
    style->setDisplay(newDisplay);
    style->setUnique();
    return style.release();
}
PassRefPtr<ComputedStyle>
MultipleFieldsTemporalInputTypeView::customStyleForLayoutObject(
    PassRefPtr<ComputedStyle> originalStyle) {
  EDisplay originalDisplay = originalStyle->display();
  EDisplay newDisplay = originalDisplay;
  if (originalDisplay == EDisplay::Inline ||
      originalDisplay == EDisplay::InlineBlock)
    newDisplay = EDisplay::InlineFlex;
  else if (originalDisplay == EDisplay::Block)
    newDisplay = EDisplay::Flex;
  TextDirection contentDirection = computedTextDirection();
  if (originalStyle->direction() == contentDirection &&
      originalDisplay == newDisplay)
    return originalStyle;

  RefPtr<ComputedStyle> style = ComputedStyle::clone(*originalStyle);
  style->setDirection(contentDirection);
  style->setDisplay(newDisplay);
  style->setUnique();
  return style.release();
}