Bug 1525372 - Add background-clip:text rendering observer so that we get notified of changes to the clipped contents. r=jwatt

Differential Revision: https://phabricator.services.mozilla.com/D20110

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Matt Woodrow 2019-03-18 16:24:20 +00:00
Родитель acb34df20e
Коммит 756b5124bc
3 изменённых файлов: 51 добавлений и 0 удалений

Просмотреть файл

@ -813,6 +813,8 @@ static bool GenerateAndPushTextMask(nsIFrame* aFrame, gfxContext* aContext,
return false;
}
SVGObserverUtils::GetAndObserveBackgroundClip(aFrame);
// The main function of enabling background-clip:text property value.
// When a nsDisplayBackgroundImage detects "text" bg-clip style, it will call
// this function to

Просмотреть файл

@ -459,6 +459,34 @@ class SVGMozElementObserver final : public nsSVGPaintingProperty {
bool ObservesReflow() override { return true; }
};
class BackgroundClipRenderingObserver : public SVGRenderingObserver {
public:
explicit BackgroundClipRenderingObserver(nsIFrame* aFrame) : mFrame(aFrame) {}
NS_DECL_ISUPPORTS
private:
virtual ~BackgroundClipRenderingObserver() { StopObserving(); }
Element* GetReferencedElementWithoutObserving() final {
return mFrame->GetContent()->AsElement();
}
void OnRenderingChange() final;
bool ObservesReflow() final { return true; }
nsIFrame* mFrame;
};
NS_IMPL_ISUPPORTS(BackgroundClipRenderingObserver, nsIMutationObserver)
void BackgroundClipRenderingObserver::OnRenderingChange() {
for (nsIFrame* f = mFrame; f;
f = nsLayoutUtils::GetNextContinuationOrIBSplitSibling(f)) {
f->InvalidateFrame();
}
}
/**
* In a filter chain, there can be multiple SVG reference filters.
* e.g. filter: url(#svg-filter-1) blur(10px) url(#svg-filter-2);
@ -991,6 +1019,8 @@ NS_DECLARE_FRAME_PROPERTY_RELEASABLE(HrefAsTextPathProperty,
SVGTextPathObserver)
NS_DECLARE_FRAME_PROPERTY_DELETABLE(BackgroundImageProperty,
URIObserverHashtable)
NS_DECLARE_FRAME_PROPERTY_RELEASABLE(BackgroundClipObserverProperty,
BackgroundClipRenderingObserver)
template <class T>
static T* GetEffectProperty(
@ -1355,6 +1385,19 @@ Element* SVGObserverUtils::GetAndObserveBackgroundImage(nsIFrame* aFrame,
return observer->GetAndObserveReferencedElement();
}
Element* SVGObserverUtils::GetAndObserveBackgroundClip(nsIFrame* aFrame) {
bool found;
BackgroundClipRenderingObserver* obs =
aFrame->GetProperty(BackgroundClipObserverProperty(), &found);
if (!found) {
obs = new BackgroundClipRenderingObserver(aFrame);
NS_ADDREF(obs);
aFrame->AddProperty(BackgroundClipObserverProperty(), obs);
}
return obs->GetAndObserveReferencedElement();
}
nsSVGPaintServerFrame* SVGObserverUtils::GetAndObservePaintServer(
nsIFrame* aTargetFrame, nsStyleSVGPaint nsStyleSVG::*aPaint) {
// If we're looking at a frame within SVG text, then we need to look up

Просмотреть файл

@ -393,6 +393,12 @@ class SVGObserverUtils {
static Element* GetAndObserveBackgroundImage(nsIFrame* aFrame,
const nsAtom* aHref);
/**
* Gets an arbitrary element and starts observing it. Used to detect
* invalidation changes for background-clip:text.
*/
static Element* GetAndObserveBackgroundClip(nsIFrame* aFrame);
/**
* A helper function to resolve filter URL.
*/