Commit 4fc02f6f authored by Emilio Cobos Álvarez's avatar Emilio Cobos Álvarez
Browse files

Bug 1742411 - Prefer content property to img src on image elements. r=dholbert

Given the compat reports in bug 1484928, I don't think it's worth
keeping the current behavior.

Our behavior should match other browsers now. Rather than making
content: url() work everywhere even for otherwise-replaced elements,
just special-case this since that's what other browsers seem to do.

Differential Revision: https://phabricator.services.mozilla.com/D131797
parent 08952898
Loading
Loading
Loading
Loading
+1 −14
Original line number Diff line number Diff line
@@ -1432,19 +1432,6 @@ static void MoveChildrenTo(nsIFrame* aOldParent, nsContainerFrame* aNewParent,
  }
}

static bool ShouldCreateImageFrameForContent(const Element& aElement,
                                             ComputedStyle& aStyle) {
  if (aElement.IsRootOfNativeAnonymousSubtree()) {
    return false;
  }
  auto& content = aStyle.StyleContent()->mContent;
  if (!content.IsItems()) {
    return false;
  }
  Span<const StyleContentItem> items = content.AsItems().AsSpan();
  return items.Length() == 1 && items[0].IsImage();
}

//----------------------------------------------------------------------

nsCSSFrameConstructor::nsCSSFrameConstructor(Document* aDocument,
@@ -5341,7 +5328,7 @@ nsCSSFrameConstructor::FindElementData(const Element& aElement,

  // Check for 'content: <image-url>' on the element (which makes us ignore
  // 'display' values other than 'none' or 'contents').
  if (ShouldCreateImageFrameForContent(aElement, aStyle)) {
  if (nsImageFrame::ShouldCreateImageFrameForContent(aElement, aStyle)) {
    static const FrameConstructionData sImgData =
        SIMPLE_FCDATA(NS_NewImageFrameForContentProperty);
    return &sImgData;
+19 −1
Original line number Diff line number Diff line
@@ -830,11 +830,29 @@ static bool HasAltText(const Element& aElement) {
  return aElement.HasNonEmptyAttr(nsGkAtoms::alt);
}

bool nsImageFrame::ShouldCreateImageFrameForContent(
    const Element& aElement, const ComputedStyle& aStyle) {
  if (aElement.IsRootOfNativeAnonymousSubtree()) {
    return false;
  }
  const auto& content = aStyle.StyleContent()->mContent;
  if (!content.IsItems()) {
    return false;
  }
  Span<const StyleContentItem> items = content.AsItems().AsSpan();
  return items.Length() == 1 && items[0].IsImage();
}

// Check if we want to use an image frame or just let the frame constructor make
// us into an inline.
/* static */
bool nsImageFrame::ShouldCreateImageFrameFor(const Element& aElement,
                                             ComputedStyle& aStyle) {
                                             const ComputedStyle& aStyle) {
  if (ShouldCreateImageFrameForContent(aElement, aStyle)) {
    // Prefer the content property, for compat reasons, see bug 1484928.
    return false;
  }

  if (ImageOk(aElement.State())) {
    // Image is fine or loading; do the image frame thing
    return true;
+8 −1
Original line number Diff line number Diff line
@@ -133,13 +133,20 @@ class nsImageFrame : public nsAtomicContainerFrame, public nsIReflowCallback {
  already_AddRefed<imgIRequest> GetCurrentRequest() const;
  void Notify(imgIRequest*, int32_t aType, const nsIntRect* aData);

  /**
   * Returns whether we should replace an element with an image corresponding to
   * its 'content' CSS property.
   */
  static bool ShouldCreateImageFrameForContent(const mozilla::dom::Element&,
                                               const ComputedStyle&);

  /**
   * Function to test whether given an element and its style, that element
   * should get an image frame.  Note that this method is only used by the
   * frame constructor; it's only here because it uses gIconLoad for now.
   */
  static bool ShouldCreateImageFrameFor(const mozilla::dom::Element&,
                                        ComputedStyle&);
                                        const ComputedStyle&);

  ImgDrawResult DisplayAltFeedback(gfxContext& aRenderingContext,
                                   const nsRect& aDirtyRect, nsPoint aPt,
+2 −0
Original line number Diff line number Diff line
[element-replacement-on-replaced-element.tentative.html]
  expected: FAIL
+2 −0
Original line number Diff line number Diff line
<!doctype html>
<img src="/images/yellow.png" width=100 height=100>
Loading