Backed out changeset 47c73e5e08a4 (bug 1685078) for multiple failures related to CSS. CLOSED TREE

This commit is contained in:
Dorel Luca 2021-01-07 10:44:10 +02:00
parent 15f0a34f7b
commit 7d7078d54e
17 changed files with 493 additions and 106 deletions

View File

@ -42,8 +42,7 @@ HTMLLIAccessible::HTMLLIAccessible(nsIContent* aContent, DocAccessible* aDoc)
if (nsBulletFrame* bulletFrame =
do_QueryFrame(nsLayoutUtils::GetMarkerFrame(aContent))) {
const nsStyleList* styleList = bulletFrame->StyleList();
if (!styleList->mListStyleImage.IsNone() ||
!styleList->mCounterStyle.IsNone()) {
if (styleList->GetListStyleImage() || !styleList->mCounterStyle.IsNone()) {
mBullet = new HTMLListBulletAccessible(mContent, mDoc);
Document()->BindToDocument(mBullet, nullptr);
AppendChild(mBullet);
@ -143,7 +142,7 @@ ENameValueFlag HTMLListBulletAccessible::Name(nsString& aName) const {
return eNameOK;
}
if (!frame->StyleList()->mListStyleImage.IsNone()) {
if (frame->StyleList()->GetListStyleImage()) {
// Bullet is an image, so use default bullet character.
const char16_t kDiscCharacter = 0x2022;
aName.Assign(kDiscCharacter);

View File

@ -7394,7 +7394,7 @@ bool nsBlockFrame::MarkerIsEmpty() const {
"should only care when we have an outside ::marker");
nsIFrame* marker = GetMarker();
const nsStyleList* list = marker->StyleList();
return list->mCounterStyle.IsNone() && list->mListStyleImage.IsNone() &&
return list->mCounterStyle.IsNone() && !list->GetListStyleImage() &&
marker->StyleContent()->ContentCount() == 0;
}

View File

@ -23,7 +23,6 @@
#include "mozilla/MathAlgorithms.h"
#include "mozilla/PresShell.h"
#include "mozilla/SVGImageContext.h"
#include "mozilla/css/ImageLoader.h"
#include "mozilla/dom/Document.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/PathHelpers.h"
@ -42,7 +41,6 @@
#include "nsGenericHTMLElement.h"
#include "nsGkAtoms.h"
#include "nsIURI.h"
#include "nsLayoutUtils.h"
#include "nsPresContext.h"
#ifdef ACCESSIBILITY
@ -53,6 +51,7 @@ using namespace mozilla;
using namespace mozilla::gfx;
using namespace mozilla::image;
using namespace mozilla::layout;
using mozilla::dom::Document;
nsIFrame* NS_NewBulletFrame(PresShell* aPresShell, ComputedStyle* aStyle) {
return new (aPresShell) nsBulletFrame(aStyle, aPresShell->GetPresContext());
@ -75,6 +74,19 @@ CounterStyle* nsBulletFrame::ResolveCounterStyle() {
StyleList()->mCounterStyle);
}
void nsBulletFrame::DestroyFrom(nsIFrame* aDestructRoot,
PostDestroyData& aPostDestroyData) {
// Stop image loading first.
DeregisterAndCancelImageRequest();
if (mListener) {
mListener->SetFrame(nullptr);
}
// Let base class do the rest
nsIFrame::DestroyFrom(aDestructRoot, aPostDestroyData);
}
#ifdef DEBUG_FRAME_DUMP
nsresult nsBulletFrame::GetFrameName(nsAString& aResult) const {
return MakeFrameName(u"Bullet"_ns, aResult);
@ -88,36 +100,69 @@ bool nsBulletFrame::IsSelfEmpty() {
}
/* virtual */
void nsBulletFrame::DidSetComputedStyle(ComputedStyle* aOldStyle) {
nsIFrame::DidSetComputedStyle(aOldStyle);
void nsBulletFrame::DidSetComputedStyle(ComputedStyle* aOldComputedStyle) {
nsIFrame::DidSetComputedStyle(aOldComputedStyle);
css::ImageLoader* loader = PresContext()->Document()->StyleImageLoader();
imgIRequest* oldListImage =
aOldStyle ? aOldStyle->StyleList()->mListStyleImage.GetImageRequest()
: nullptr;
imgIRequest* newListImage = StyleList()->mListStyleImage.GetImageRequest();
if (oldListImage != newListImage) {
if (oldListImage && HasImageRequest()) {
loader->DisassociateRequestFromFrame(oldListImage, this);
imgRequestProxy* newRequest = StyleList()->GetListStyleImage();
if (newRequest) {
if (!mListener) {
mListener = new nsBulletListener();
mListener->SetFrame(this);
}
if (newListImage) {
loader->AssociateRequestToFrame(
newListImage, this, css::ImageLoader::REQUEST_REQUIRES_REFLOW);
bool needNewRequest = true;
if (mImageRequest) {
// Reload the image, maybe...
nsCOMPtr<nsIURI> oldURI;
mImageRequest->GetURI(getter_AddRefs(oldURI));
nsCOMPtr<nsIURI> newURI;
newRequest->GetURI(getter_AddRefs(newURI));
if (oldURI && newURI) {
bool same;
newURI->Equals(oldURI, &same);
if (same) {
needNewRequest = false;
}
}
}
if (needNewRequest) {
RefPtr<imgRequestProxy> newRequestClone;
newRequest->SyncClone(mListener, PresContext()->Document(),
getter_AddRefs(newRequestClone));
// Deregister the old request. We wait until after Clone is done in case
// the old request and the new request are the same underlying image
// accessed via different URLs.
DeregisterAndCancelImageRequest();
// Register the new request.
mImageRequest = std::move(newRequestClone);
RegisterImageRequest(/* aKnownToBeAnimated = */ false);
// Image bullets can affect the layout of the page, so boost the image
// load priority.
mImageRequest->BoostPriority(imgIRequest::CATEGORY_SIZE_QUERY);
}
} else {
// No image request on the new ComputedStyle.
DeregisterAndCancelImageRequest();
}
#ifdef ACCESSIBILITY
// Update the list bullet accessible. If old style list isn't available then
// no need to update the accessible tree because it's not created yet.
if (aOldStyle) {
if (aOldComputedStyle) {
if (nsAccessibilityService* accService =
PresShell::GetAccessibilityService()) {
const nsStyleList* oldStyleList = aOldStyle->StyleList();
bool hadBullet = !oldStyleList->mListStyleImage.IsNone() ||
const nsStyleList* oldStyleList = aOldComputedStyle->StyleList();
bool hadBullet = oldStyleList->GetListStyleImage() ||
!oldStyleList->mCounterStyle.IsNone();
const nsStyleList* newStyleList = StyleList();
bool hasBullet = !oldStyleList->mListStyleImage.IsNone() ||
bool hasBullet = newStyleList->GetListStyleImage() ||
!newStyleList->mCounterStyle.IsNone();
if (hadBullet != hasBullet) {
@ -150,13 +195,11 @@ class nsDisplayBulletGeometry
class BulletRenderer final {
public:
BulletRenderer(nsIFrame* aFrame, const StyleImage& aImage,
const nsRect& aDest)
: mDest(aDest),
BulletRenderer(imgIContainer* image, const nsRect& dest)
: mImage(image),
mDest(dest),
mColor(NS_RGBA(0, 0, 0, 0)),
mListStyleType(NS_STYLE_LIST_STYLE_NONE) {
mImageRenderer.emplace(aFrame, &aImage, 0);
mImageRenderer->SetPreferredSize({}, aDest.Size());
MOZ_ASSERT(IsImageType());
}
@ -192,11 +235,8 @@ class BulletRenderer final {
const nsRect& aDirtyRect, uint32_t aFlags,
bool aDisableSubpixelAA, nsIFrame* aFrame);
bool IsImageType() const { return !!mImageRenderer; }
bool PrepareImage() {
MOZ_ASSERT(IsImageType());
return mImageRenderer->PrepareImage();
bool IsImageType() const {
return mListStyleType == NS_STYLE_LIST_STYLE_NONE && mImage;
}
bool IsPathType() const {
@ -220,6 +260,9 @@ class BulletRenderer final {
void PaintTextToContext(nsIFrame* aFrame, gfxContext* aCtx,
bool aDisableSubpixelAA);
bool IsImageContainerAvailable(layers::LayerManager* aManager,
uint32_t aFlags);
private:
ImgDrawResult CreateWebRenderCommandsForImage(
nsDisplayItem* aItem, wr::DisplayListBuilder& aBuilder,
@ -243,9 +286,9 @@ class BulletRenderer final {
nsDisplayListBuilder* aDisplayListBuilder);
private:
Maybe<nsImageRenderer> mImageRenderer;
// The position and size of the image bullet.
// mImage and mDest are the properties for list-style-image.
// mImage is the image content and mDest is the image position.
RefPtr<imgIContainer> mImage;
nsRect mDest;
// Some bullet types are stored as a rect (in device pixels) instead of a Path
@ -304,10 +347,11 @@ ImgDrawResult BulletRenderer::Paint(gfxContext& aRenderingContext, nsPoint aPt,
const nsRect& aDirtyRect, uint32_t aFlags,
bool aDisableSubpixelAA, nsIFrame* aFrame) {
if (IsImageType()) {
return mImageRenderer->DrawLayer(aFrame->PresContext(), aRenderingContext,
mDest, mDest, nsPoint(), aDirtyRect,
mDest.Size(),
/* aOpacity = */ 1.0f);
SamplingFilter filter = nsLayoutUtils::GetSamplingFilterForFrame(aFrame);
return nsLayoutUtils::DrawSingleImage(
aRenderingContext, aFrame->PresContext(), mImage, filter, mDest,
aDirtyRect,
/* no SVGImageContext */ Nothing(), aFlags);
}
if (IsPathType()) {
@ -370,6 +414,13 @@ void BulletRenderer::PaintTextToContext(nsIFrame* aFrame, gfxContext* aCtx,
mText.Length(), mPoint);
}
bool BulletRenderer::IsImageContainerAvailable(layers::LayerManager* aManager,
uint32_t aFlags) {
MOZ_ASSERT(IsImageType());
return mImage->IsImageContainerAvailable(aManager, aFlags);
}
ImgDrawResult BulletRenderer::CreateWebRenderCommandsForImage(
nsDisplayItem* aItem, wr::DisplayListBuilder& aBuilder,
wr::IpcResourceUpdateQueue& aResources,
@ -377,10 +428,43 @@ ImgDrawResult BulletRenderer::CreateWebRenderCommandsForImage(
mozilla::layers::RenderRootStateManager* aManager,
nsDisplayListBuilder* aDisplayListBuilder) {
MOZ_RELEASE_ASSERT(IsImageType());
return mImageRenderer->BuildWebRenderDisplayItemsForLayer(
aItem->Frame()->PresContext(), aBuilder, aResources, aSc, aManager, aItem,
mDest, mDest, nsPoint(), mDest, mDest.Size(),
/* aOpacity = */ 1.0f);
MOZ_RELEASE_ASSERT(mImage);
uint32_t flags = aDisplayListBuilder->GetImageDecodeFlags();
const int32_t appUnitsPerDevPixel =
aItem->Frame()->PresContext()->AppUnitsPerDevPixel();
LayoutDeviceRect destRect =
LayoutDeviceRect::FromAppUnits(mDest, appUnitsPerDevPixel);
Maybe<SVGImageContext> svgContext;
gfx::IntSize decodeSize =
nsLayoutUtils::ComputeImageContainerDrawingParameters(
mImage, aItem->Frame(), destRect, aSc, flags, svgContext);
RefPtr<layers::ImageContainer> container;
ImgDrawResult drawResult = mImage->GetImageContainerAtSize(
aManager->LayerManager(), decodeSize, svgContext, flags,
getter_AddRefs(container));
if (!container) {
return drawResult;
}
mozilla::wr::ImageRendering rendering = wr::ToImageRendering(
nsLayoutUtils::GetSamplingFilterForFrame(aItem->Frame()));
gfx::IntSize size;
Maybe<wr::ImageKey> key = aManager->CommandBuilder().CreateImageKey(
aItem, container, aBuilder, aResources, rendering, aSc, size, Nothing());
if (key.isNothing()) {
return drawResult;
}
wr::LayoutRect dest = wr::ToLayoutRect(destRect);
aBuilder.PushImage(dest, dest, !aItem->BackfaceIsHidden(), rendering,
key.value());
return drawResult;
}
bool BulletRenderer::CreateWebRenderCommandsForPath(
@ -565,23 +649,36 @@ void nsBulletFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
Maybe<BulletRenderer> nsBulletFrame::CreateBulletRenderer(
gfxContext& aRenderingContext, nsPoint aPt) {
const nsStyleList* myList = StyleList();
CounterStyle* listStyleType = ResolveCounterStyle();
nsMargin padding = mPadding.GetPhysicalMargin(GetWritingMode());
if (!StyleList()->mListStyleImage.IsNone()) {
nsRect dest(padding.left, padding.top,
mRect.width - (padding.left + padding.right),
mRect.height - (padding.top + padding.bottom));
BulletRenderer br(this, StyleList()->mListStyleImage, dest + aPt);
if (br.PrepareImage()) {
return Some(br);
}
if (auto* request = StyleList()->mListStyleImage.GetImageRequest()) {
request->BoostPriority(imgIRequest::CATEGORY_DISPLAY);
if (myList->GetListStyleImage() && mImageRequest) {
uint32_t status;
mImageRequest->GetImageStatus(&status);
if (!(status & imgIRequest::STATUS_ERROR)) {
if (status & imgIRequest::STATUS_LOAD_COMPLETE) {
nsCOMPtr<imgIContainer> imageCon;
mImageRequest->GetImage(getter_AddRefs(imageCon));
if (imageCon) {
imageCon = nsLayoutUtils::OrientImage(
imageCon, StyleVisibility()->mImageOrientation);
nsRect dest(padding.left, padding.top,
mRect.width - (padding.left + padding.right),
mRect.height - (padding.top + padding.bottom));
BulletRenderer br(imageCon, dest + aPt);
return Some(br);
}
} else {
// Boost the load priority further now that we know we want to display
// the bullet image.
mImageRequest->BoostPriority(imgIRequest::CATEGORY_DISPLAY);
}
}
}
nscolor color = nsLayoutUtils::GetColor(this, &nsStyleText::mColor);
DrawTarget* drawTarget = aRenderingContext.GetDrawTarget();
int32_t appUnitsPerDevPixel = PresContext()->AppUnitsPerDevPixel();
@ -764,30 +861,40 @@ void nsBulletFrame::GetDesiredSize(nsPresContext* aCX,
aPadding->SizeTo(wm, 0, 0, 0, 0);
LogicalSize finalSize(wm);
const nsStyleList* myList = StyleList();
nscoord ascent;
RefPtr<nsFontMetrics> fm =
nsLayoutUtils::GetFontMetricsForFrame(this, aFontSizeInflation);
RemoveStateBits(BULLET_FRAME_IMAGE_LOADING);
if (RefPtr<imgIContainer> image = GetImage()) {
int32_t w = 0;
int32_t h = 0;
image->GetWidth(&w);
image->GetHeight(&h);
LogicalSize size(GetWritingMode(), CSSPixel::ToAppUnits(CSSIntSize(w, h)));
// auto size the image
finalSize.ISize(wm) = size.ISize(wm);
finalSize.BSize(wm) = size.BSize(wm);
aMetrics.SetBlockStartAscent(size.BSize(wm));
aMetrics.SetSize(wm, finalSize);
if (myList->GetListStyleImage() && mImageRequest) {
uint32_t status;
mImageRequest->GetImageStatus(&status);
if (status & imgIRequest::STATUS_SIZE_AVAILABLE &&
!(status & imgIRequest::STATUS_ERROR)) {
// auto size the image
finalSize.ISize(wm) = mIntrinsicSize.ISize(wm);
aMetrics.SetBlockStartAscent(finalSize.BSize(wm) =
mIntrinsicSize.BSize(wm));
aMetrics.SetSize(wm, finalSize);
AppendSpacingToPadding(fm, aPadding);
AppendSpacingToPadding(fm, aPadding);
AddStateBits(BULLET_FRAME_IMAGE_LOADING);
return;
AddStateBits(BULLET_FRAME_IMAGE_LOADING);
return;
}
}
// If we're getting our desired size and don't have an image, reset
// mIntrinsicSize to (0,0). Otherwise, if we used to have an image, it
// changed, and the new one is coming in, but we're reflowing before it's
// fully there, we'll end up with mIntrinsicSize not matching our size, but
// won't trigger a reflow in OnStartContainer (because mIntrinsicSize will
// match the image size).
mIntrinsicSize.SizeTo(wm, 0, 0);
nscoord bulletSize;
nsAutoString text;
@ -797,6 +904,7 @@ void nsBulletFrame::GetDesiredSize(nsPresContext* aCX,
finalSize.ISize(wm) = finalSize.BSize(wm) = 0;
aMetrics.SetBlockStartAscent(0);
break;
case NS_STYLE_LIST_STYLE_DISC:
case NS_STYLE_LIST_STYLE_CIRCLE:
case NS_STYLE_LIST_STYLE_SQUARE: {
@ -906,8 +1014,7 @@ static inline bool IsIgnoreable(const nsIFrame* aFrame, nscoord aISize) {
return false;
}
auto listStyle = aFrame->StyleList();
return listStyle->mCounterStyle.IsNone() &&
listStyle->mListStyleImage.IsNone();
return listStyle->mCounterStyle.IsNone() && !listStyle->GetListStyleImage();
}
/* virtual */
@ -930,6 +1037,126 @@ void nsBulletFrame::AddInlinePrefISize(gfxContext* aRenderingContext,
}
}
void nsBulletFrame::Notify(imgIRequest* aRequest, int32_t aType,
const nsIntRect* aData) {
if (aType == imgINotificationObserver::SIZE_AVAILABLE) {
nsCOMPtr<imgIContainer> image;
aRequest->GetImage(getter_AddRefs(image));
return OnSizeAvailable(aRequest, image);
}
if (aType == imgINotificationObserver::FRAME_UPDATE) {
// The image has changed.
// Invalidate the entire content area. Maybe it's not optimal but it's
// simple and always correct, and I'll be a stunned mullet if it ever
// matters for performance
InvalidateFrame();
}
if (aType == imgINotificationObserver::IS_ANIMATED) {
// Register the image request with the refresh driver now that we know it's
// animated.
if (aRequest == mImageRequest) {
RegisterImageRequest(/* aKnownToBeAnimated = */ true);
}
}
if (aType == imgINotificationObserver::LOAD_COMPLETE) {
// Unconditionally start decoding for now.
// XXX(seth): We eventually want to decide whether to do this based on
// visibility. We should get that for free from bug 1091236.
nsCOMPtr<imgIContainer> container;
aRequest->GetImage(getter_AddRefs(container));
if (container) {
// Retrieve the intrinsic size of the image.
int32_t width = 0;
int32_t height = 0;
container->GetWidth(&width);
container->GetHeight(&height);
// Request a decode at that size.
container->RequestDecodeForSize(
IntSize(width, height), imgIContainer::DECODE_FLAGS_DEFAULT |
imgIContainer::FLAG_HIGH_QUALITY_SCALING);
}
InvalidateFrame();
}
if (aType == imgINotificationObserver::DECODE_COMPLETE) {
if (Document* parent = GetOurCurrentDoc()) {
nsCOMPtr<imgIContainer> container;
aRequest->GetImage(getter_AddRefs(container));
if (container) {
container->PropagateUseCounters(parent);
}
}
}
}
Document* nsBulletFrame::GetOurCurrentDoc() const {
nsIContent* parentContent = GetParent()->GetContent();
return parentContent ? parentContent->GetComposedDoc() : nullptr;
}
void nsBulletFrame::OnSizeAvailable(imgIRequest* aRequest,
imgIContainer* aImage) {
if (!aImage) return;
if (!aRequest) return;
uint32_t status;
aRequest->GetImageStatus(&status);
if (status & imgIRequest::STATUS_ERROR) {
return;
}
nscoord w, h;
aImage->GetWidth(&w);
aImage->GetHeight(&h);
nsPresContext* presContext = PresContext();
LogicalSize newsize(GetWritingMode(),
nsSize(nsPresContext::CSSPixelsToAppUnits(w),
nsPresContext::CSSPixelsToAppUnits(h)));
if (mIntrinsicSize != newsize) {
mIntrinsicSize = newsize;
// Now that the size is available (or an error occurred), trigger
// a reflow of the bullet frame.
mozilla::PresShell* presShell = presContext->GetPresShell();
if (presShell) {
presShell->FrameNeedsReflow(this, IntrinsicDirty::StyleChange,
NS_FRAME_IS_DIRTY);
}
}
// Handle animations
aImage->SetAnimationMode(presContext->ImageAnimationMode());
// Ensure the animation (if any) is started. Note: There is no
// corresponding call to Decrement for this. This Increment will be
// 'cleaned up' by the Request when it is destroyed, but only then.
aRequest->IncrementAnimationConsumers();
}
void nsBulletFrame::GetLoadGroup(nsPresContext* aPresContext,
nsILoadGroup** aLoadGroup) {
if (!aPresContext) return;
MOZ_ASSERT(nullptr != aLoadGroup, "null OUT parameter pointer");
mozilla::PresShell* presShell = aPresContext->GetPresShell();
if (!presShell) {
return;
}
Document* doc = presShell->GetDocument();
if (!doc) return;
*aLoadGroup = doc->GetDocumentLoadGroup().take();
}
float nsBulletFrame::GetFontSizeInflation() const {
if (!HasFontSizeInflation()) {
return 1.0f;
@ -951,11 +1178,12 @@ void nsBulletFrame::SetFontSizeInflation(float aInflation) {
}
already_AddRefed<imgIContainer> nsBulletFrame::GetImage() const {
if (auto* request = StyleList()->mListStyleImage.GetImageRequest()) {
if (mImageRequest && StyleList()->GetListStyleImage()) {
nsCOMPtr<imgIContainer> imageCon;
request->GetImage(getter_AddRefs(imageCon));
mImageRequest->GetImage(getter_AddRefs(imageCon));
return imageCon.forget();
}
return nullptr;
}
@ -1036,6 +1264,42 @@ void nsBulletFrame::GetSpokenText(nsAString& aText) {
}
#endif
void nsBulletFrame::RegisterImageRequest(bool aKnownToBeAnimated) {
if (mImageRequest) {
// mRequestRegistered is a bitfield; unpack it temporarily so we can take
// the address.
bool isRequestRegistered = mRequestRegistered;
if (aKnownToBeAnimated) {
nsLayoutUtils::RegisterImageRequest(PresContext(), mImageRequest,
&isRequestRegistered);
} else {
nsLayoutUtils::RegisterImageRequestIfAnimated(
PresContext(), mImageRequest, &isRequestRegistered);
}
mRequestRegistered = isRequestRegistered;
}
}
void nsBulletFrame::DeregisterAndCancelImageRequest() {
if (mImageRequest) {
// mRequestRegistered is a bitfield; unpack it temporarily so we can take
// the address.
bool isRequestRegistered = mRequestRegistered;
// Deregister our image request from the refresh driver.
nsLayoutUtils::DeregisterImageRequest(PresContext(), mImageRequest,
&isRequestRegistered);
mRequestRegistered = isRequestRegistered;
// Cancel the image request and forget about it.
mImageRequest->CancelAndForgetObserver(NS_ERROR_FAILURE);
mImageRequest = nullptr;
}
}
void nsBulletFrame::SetOrdinal(int32_t aOrdinal, bool aNotify) {
if (mOrdinal == aOrdinal) {
return;
@ -1046,3 +1310,17 @@ void nsBulletFrame::SetOrdinal(int32_t aOrdinal, bool aNotify) {
NS_FRAME_IS_DIRTY);
}
}
NS_IMPL_ISUPPORTS(nsBulletListener, imgINotificationObserver)
nsBulletListener::nsBulletListener() : mFrame(nullptr) {}
nsBulletListener::~nsBulletListener() = default;
void nsBulletListener::Notify(imgIRequest* aRequest, int32_t aType,
const nsIntRect* aData) {
if (!mFrame) {
return;
}
return mFrame->Notify(aRequest, aType, aData);
}

View File

@ -12,11 +12,32 @@
#include "mozilla/Attributes.h"
#include "nsIFrame.h"
#include "imgIContainer.h"
#include "imgINotificationObserver.h"
class imgIContainer;
class imgRequestProxy;
class nsBulletFrame;
class BulletRenderer;
class nsFontMetrics;
class nsBulletListener final : public imgINotificationObserver {
public:
nsBulletListener();
NS_DECL_ISUPPORTS
NS_DECL_IMGINOTIFICATIONOBSERVER
void SetFrame(nsBulletFrame* frame) { mFrame = frame; }
private:
virtual ~nsBulletListener();
nsBulletFrame* mFrame;
};
/**
* A simple class that manages the layout and rendering of html bullets.
* This class also supports the CSS list-style properties.
@ -31,26 +52,36 @@ class nsBulletFrame final : public nsIFrame {
#endif
explicit nsBulletFrame(ComputedStyle* aStyle, nsPresContext* aPresContext)
: nsIFrame(aStyle, aPresContext, kClassID), mPadding(GetWritingMode()) {}
: nsIFrame(aStyle, aPresContext, kClassID),
mPadding(GetWritingMode()),
mIntrinsicSize(GetWritingMode()),
mRequestRegistered(false) {}
virtual ~nsBulletFrame();
void Notify(imgIRequest* aRequest, int32_t aType, const nsIntRect* aData);
// nsIFrame
void BuildDisplayList(nsDisplayListBuilder*,
const nsDisplayListSet&) override;
void DidSetComputedStyle(ComputedStyle* aOldStyle) override;
virtual void DestroyFrom(nsIFrame* aDestructRoot,
PostDestroyData& aPostDestroyData) override;
virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
const nsDisplayListSet& aLists) override;
virtual void DidSetComputedStyle(ComputedStyle* aOldComputedStyle) override;
#ifdef DEBUG_FRAME_DUMP
nsresult GetFrameName(nsAString& aResult) const override;
virtual nsresult GetFrameName(nsAString& aResult) const override;
#endif
void Reflow(nsPresContext* aPresContext, ReflowOutput& aMetrics,
const ReflowInput&, nsReflowStatus&) override;
nscoord GetMinISize(gfxContext*) override;
nscoord GetPrefISize(gfxContext*) override;
void AddInlineMinISize(gfxContext*, nsIFrame::InlineMinISizeData*) override;
void AddInlinePrefISize(gfxContext*, nsIFrame::InlinePrefISizeData*) override;
virtual void Reflow(nsPresContext* aPresContext, ReflowOutput& aMetrics,
const ReflowInput& aReflowInput,
nsReflowStatus& aStatus) override;
virtual nscoord GetMinISize(gfxContext* aRenderingContext) override;
virtual nscoord GetPrefISize(gfxContext* aRenderingContext) override;
void AddInlineMinISize(gfxContext* aRenderingContext,
nsIFrame::InlineMinISizeData* aData) override;
void AddInlinePrefISize(gfxContext* aRenderingContext,
nsIFrame::InlinePrefISizeData* aData) override;
bool IsFrameOfType(uint32_t aFlags) const override {
virtual bool IsFrameOfType(uint32_t aFlags) const override {
if (aFlags & (eSupportsCSSTransforms | eSupportsContainLayoutAndPaint)) {
return false;
}
@ -73,14 +104,15 @@ class nsBulletFrame final : public nsIFrame {
const nsRect& aDirtyRect, uint32_t aFlags,
bool aDisableSubpixelAA);
bool IsEmpty() override;
bool IsSelfEmpty() override;
virtual bool IsEmpty() override;
virtual bool IsSelfEmpty() override;
// XXXmats note that this method returns a non-standard baseline that includes
// the ::marker block-start margin. New code should probably use
// GetNaturalBaselineBOffset instead, which returns a normal baseline offset
// as documented in nsIFrame.h.
nscoord GetLogicalBaseline(mozilla::WritingMode aWritingMode) const override;
virtual nscoord GetLogicalBaseline(
mozilla::WritingMode aWritingMode) const override;
bool GetNaturalBaselineBOffset(mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup,
@ -98,6 +130,8 @@ class nsBulletFrame final : public nsIFrame {
already_AddRefed<imgIContainer> GetImage() const;
protected:
void OnSizeAvailable(imgIRequest* aRequest, imgIContainer* aImage);
void AppendSpacingToPadding(nsFontMetrics* aFontMetrics,
mozilla::LogicalMargin* aPadding);
void GetDesiredSize(nsPresContext* aPresContext,
@ -105,14 +139,27 @@ class nsBulletFrame final : public nsIFrame {
float aFontSizeInflation,
mozilla::LogicalMargin* aPadding);
void GetLoadGroup(nsPresContext* aPresContext, nsILoadGroup** aLoadGroup);
mozilla::dom::Document* GetOurCurrentDoc() const;
mozilla::LogicalMargin mPadding;
RefPtr<imgRequestProxy> mImageRequest;
RefPtr<nsBulletListener> mListener;
mozilla::LogicalSize mIntrinsicSize;
private:
mozilla::CounterStyle* ResolveCounterStyle();
nscoord GetListStyleAscent() const;
void RegisterImageRequest(bool aKnownToBeAnimated);
void DeregisterAndCancelImageRequest();
// Requires being set via SetOrdinal.
int32_t mOrdinal = 0;
// This is a boolean flag indicating whether or not the current image request
// has been registered with the refresh driver.
bool mRequestRegistered : 1;
};
#endif /* nsBulletFrame_h___ */

View File

@ -603,7 +603,7 @@ nsChangeHint nsStyleOutline::CalcDifference(
nsStyleList::nsStyleList(const Document& aDocument)
: mListStylePosition(NS_STYLE_LIST_STYLE_POSITION_OUTSIDE),
mQuotes(StyleQuotes::Auto()),
mListStyleImage(StyleImage::None()),
mListStyleImage(StyleImageUrlOrNone::None()),
mImageRegion(StyleClipRectOrAuto::Auto()),
mMozListReversed(StyleMozListReversed::False) {
MOZ_COUNT_CTOR(nsStyleList);
@ -627,8 +627,14 @@ nsStyleList::nsStyleList(const nsStyleList& aSource)
void nsStyleList::TriggerImageLoads(Document& aDocument,
const nsStyleList* aOldStyle) {
MOZ_ASSERT(NS_IsMainThread());
mListStyleImage.ResolveImage(
aDocument, aOldStyle ? &aOldStyle->mListStyleImage : nullptr);
if (mListStyleImage.IsUrl() && !mListStyleImage.AsUrl().IsImageResolved()) {
auto* oldUrl = aOldStyle && aOldStyle->mListStyleImage.IsUrl()
? &aOldStyle->mListStyleImage.AsUrl()
: nullptr;
const_cast<StyleComputedImageUrl&>(mListStyleImage.AsUrl())
.ResolveImage(aDocument, oldUrl);
}
}
nsChangeHint nsStyleList::CalcDifference(

View File

@ -672,6 +672,11 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleList {
nsChangeHint CalcDifference(const nsStyleList& aNewData,
const nsStyleDisplay& aOldDisplay) const;
imgRequestProxy* GetListStyleImage() const {
return mListStyleImage.IsUrl() ? mListStyleImage.AsUrl().GetImage()
: nullptr;
}
nsRect GetImageRegion() const {
if (!mImageRegion.IsRect()) {
return nsRect();
@ -685,7 +690,7 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleList {
mozilla::CounterStylePtr mCounterStyle;
mozilla::StyleQuotes mQuotes;
mozilla::StyleImage mListStyleImage;
mozilla::StyleImageUrlOrNone mListStyleImage;
// the rect to use within an image.
mozilla::StyleClipRectOrAuto mImageRegion;

View File

@ -6413,11 +6413,8 @@ var gCSSProperties = {
"url('data:text/plain,\\\"')",
'url("data:text/plain,\\\'")',
"url(data:text/plain,\\\\)",
].concat(validNonUrlImageValues),
invalid_values: ["url('border.png') url('border.png')"].concat(
invalidNonUrlImageValues
),
unbalanced_values: [].concat(unbalancedGradientAndElementValues),
],
invalid_values: [],
},
"list-style-position": {
domProp: "listStylePosition",

View File

@ -612,7 +612,8 @@ imgRequestProxy* nsImageBoxFrame::GetRequestFromStyle() {
return nullptr;
}
}
return StyleList()->mListStyleImage.GetImageRequest();
return StyleList()->GetListStyleImage();
}
/* virtual */

View File

@ -1862,8 +1862,7 @@ nsresult nsTreeBodyFrame::GetImage(int32_t aRowIndex, nsTreeColumn* aCol,
} else {
// Obtain the URL from the ComputedStyle.
aAllowImageRegions = true;
styleRequest =
aComputedStyle->StyleList()->mListStyleImage.GetImageRequest();
styleRequest = aComputedStyle->StyleList()->GetListStyleImage();
if (!styleRequest) return NS_OK;
nsCOMPtr<nsIURI> uri;
styleRequest->GetURI(getter_AddRefs(uri));

View File

@ -52,10 +52,10 @@ ${helpers.single_keyword(
${helpers.predefined_type(
"list-style-image",
"Image",
"url::ImageUrlOrNone",
engines="gecko servo-2013",
initial_value="computed::Image::None",
initial_specified_value="specified::Image::None",
initial_value="computed::url::ImageUrlOrNone::none()",
initial_specified_value="specified::url::ImageUrlOrNone::none()",
animation_value_type="discrete",
spec="https://drafts.csswg.org/css-lists/#propdef-list-style-image",
servo_restyle_damage="rebuild_and_reflow",

View File

@ -10,7 +10,7 @@
derive_serialize="True"
spec="https://drafts.csswg.org/css-lists/#propdef-list-style">
use crate::properties::longhands::{list_style_image, list_style_position, list_style_type};
use crate::values::specified::Image;
use crate::values::specified::url::ImageUrlOrNone;
pub fn parse_value<'i, 't>(
context: &ParserContext,
@ -69,7 +69,7 @@
(true, 2, None, None) => {
Ok(expanded! {
list_style_position: position,
list_style_image: Image::None,
list_style_image: ImageUrlOrNone::none(),
list_style_type: ListStyleType::None,
})
}
@ -83,14 +83,14 @@
(true, 1, Some(list_style_type), None) => {
Ok(expanded! {
list_style_position: position,
list_style_image: Image::None,
list_style_image: ImageUrlOrNone::none(),
list_style_type: list_style_type,
})
}
(true, 1, None, None) => {
Ok(expanded! {
list_style_position: position,
list_style_image: Image::None,
list_style_image: ImageUrlOrNone::none(),
list_style_type: ListStyleType::None,
})
}

View File

@ -13,3 +13,6 @@ pub use crate::servo::url::{ComputedImageUrl, ComputedUrl};
/// Computed <url> | <none>
pub type UrlOrNone = GenericUrlOrNone<ComputedUrl>;
/// Computed image <url> | <none>
pub type ImageUrlOrNone = GenericUrlOrNone<ComputedImageUrl>;

View File

@ -13,3 +13,6 @@ pub use crate::servo::url::{SpecifiedImageUrl, SpecifiedUrl};
/// Specified <url> | <none>
pub type UrlOrNone = GenericUrlOrNone<SpecifiedUrl>;
/// Specified image <url> | <none>
pub type ImageUrlOrNone = GenericUrlOrNone<SpecifiedImageUrl>;

View File

@ -177,6 +177,7 @@ include = [
"ComputedUrl",
"ComputedImageUrl",
"UrlOrNone",
"ImageUrlOrNone",
"Filter",
"Gradient",
"GridTemplateAreas",

View File

@ -459,6 +459,34 @@ mod shorthand_serialization {
}
}
mod list_style {
use style::properties::longhands::list_style_position::SpecifiedValue as ListStylePosition;
use style::properties::longhands::list_style_type::SpecifiedValue as ListStyleType;
use style::values::generics::url::UrlOrNone as ImageUrlOrNone;
use super::*;
#[test]
fn list_style_should_show_all_properties_when_values_are_set() {
let mut properties = Vec::new();
let position = ListStylePosition::Inside;
let image = ImageUrlOrNone::Url(SpecifiedUrl::new_for_testing("http://servo/test.png"));
let style_type = ListStyleType::Disc;
properties.push(PropertyDeclaration::ListStylePosition(position));
#[cfg(feature = "gecko")]
properties.push(PropertyDeclaration::ListStyleImage(Box::new(image)));
#[cfg(not(feature = "gecko"))]
properties.push(PropertyDeclaration::ListStyleImage(image));
properties.push(PropertyDeclaration::ListStyleType(style_type));
let serialization = shorthand_properties_to_string(properties);
assert_eq!(serialization, "list-style: inside url(\"http://servo/test.png\") disc;");
}
}
mod background {
use super::*;

View File

@ -0,0 +1,16 @@
[list-style-image-computed.sub.html]
[Property list-style-image value 'linear-gradient(to left bottom, red , blue )']
expected: FAIL
[Property list-style-image value 'radial-gradient(ellipse calc(-0.5em + 10px) calc(0.5em + 10px) at 20px 30px, rgb(255, 0, 0), rgb(0, 0, 255))']
expected: FAIL
[Property list-style-image value 'radial-gradient(10px at 20px 30px, rgb(255, 0, 0), rgb(0, 0, 255))']
expected: FAIL
[Property list-style-image value 'radial-gradient(circle calc(-0.5em + 10px) at calc(-1em + 10px) calc(-2em + 10px), rgb(255, 0, 0), rgb(0, 0, 255))']
expected: FAIL
[Property list-style-image value 'radial-gradient(ellipse calc(0.5em + 10px) calc(-0.5em + 10px) at 20px 30px, rgb(255, 0, 0), rgb(0, 0, 255))']
expected: FAIL

View File

@ -0,0 +1,4 @@
[list-style-image-valid.html]
[e.style['list-style-image'\] = "linear-gradient(to left bottom, red, blue)" should set the property value]
expected: FAIL