2008-08-08 05:34:43 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2008-08-08 05:34:43 +04:00
|
|
|
|
2012-03-26 15:58:59 +04:00
|
|
|
// Main header first:
|
2008-08-08 05:34:43 +04:00
|
|
|
#include "nsSVGEffects.h"
|
2012-03-26 15:58:59 +04:00
|
|
|
|
|
|
|
// Keep others in (case-insensitive) order:
|
|
|
|
#include "nsCSSFrameConstructor.h"
|
2008-08-08 05:34:43 +04:00
|
|
|
#include "nsISupportsImpl.h"
|
2008-10-01 04:51:05 +04:00
|
|
|
#include "nsSVGClipPathFrame.h"
|
2012-08-05 23:10:21 +04:00
|
|
|
#include "nsSVGPaintServerFrame.h"
|
2012-11-01 13:41:51 +04:00
|
|
|
#include "nsSVGPathGeometryElement.h"
|
2012-03-26 15:58:59 +04:00
|
|
|
#include "nsSVGFilterFrame.h"
|
2008-10-01 04:51:05 +04:00
|
|
|
#include "nsSVGMaskFrame.h"
|
2012-08-29 09:49:16 +04:00
|
|
|
#include "nsIReflowCallback.h"
|
2013-08-20 02:55:18 +04:00
|
|
|
#include "RestyleManager.h"
|
2014-09-09 19:14:46 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2008-10-01 04:51:05 +04:00
|
|
|
|
2010-03-29 05:46:55 +04:00
|
|
|
using namespace mozilla;
|
2010-08-13 17:31:31 +04:00
|
|
|
using namespace mozilla::dom;
|
2010-03-29 05:46:55 +04:00
|
|
|
|
2010-09-09 00:40:39 +04:00
|
|
|
void
|
|
|
|
nsSVGRenderingObserver::StartListening()
|
|
|
|
{
|
|
|
|
Element* target = GetTarget();
|
|
|
|
if (target) {
|
|
|
|
target->AddMutationObserver(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSVGRenderingObserver::StopListening()
|
|
|
|
{
|
|
|
|
Element* target = GetTarget();
|
|
|
|
|
|
|
|
if (target) {
|
|
|
|
target->RemoveMutationObserver(this);
|
|
|
|
if (mInObserverList) {
|
|
|
|
nsSVGEffects::RemoveRenderingObserver(target, this);
|
2011-10-17 18:59:28 +04:00
|
|
|
mInObserverList = false;
|
2010-09-09 00:40:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_ASSERTION(!mInObserverList, "still in an observer list?");
|
|
|
|
}
|
|
|
|
|
2010-08-13 17:31:31 +04:00
|
|
|
static nsSVGRenderingObserverList *
|
|
|
|
GetObserverList(Element *aElement)
|
2008-08-08 05:34:43 +04:00
|
|
|
{
|
2010-08-13 17:31:31 +04:00
|
|
|
return static_cast<nsSVGRenderingObserverList*>
|
|
|
|
(aElement->GetProperty(nsGkAtoms::renderingobserverlist));
|
|
|
|
}
|
2008-10-01 04:51:05 +04:00
|
|
|
|
2010-08-13 17:31:31 +04:00
|
|
|
Element*
|
|
|
|
nsSVGRenderingObserver::GetReferencedElement()
|
|
|
|
{
|
2010-09-09 00:40:39 +04:00
|
|
|
Element* target = GetTarget();
|
2010-08-13 17:31:31 +04:00
|
|
|
#ifdef DEBUG
|
2010-09-09 00:40:39 +04:00
|
|
|
if (target) {
|
|
|
|
nsSVGRenderingObserverList *observerList = GetObserverList(target);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool inObserverList = observerList && observerList->Contains(this);
|
2010-08-13 17:31:31 +04:00
|
|
|
NS_ASSERTION(inObserverList == mInObserverList, "failed to track whether we're in our referenced element's observer list!");
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(!mInObserverList, "In whose observer list are we, then?");
|
2008-08-08 05:34:43 +04:00
|
|
|
}
|
2010-08-13 17:31:31 +04:00
|
|
|
#endif
|
2010-09-09 00:40:39 +04:00
|
|
|
if (target && !mInObserverList) {
|
|
|
|
nsSVGEffects::AddRenderingObserver(target, this);
|
2011-10-17 18:59:28 +04:00
|
|
|
mInObserverList = true;
|
2010-08-13 17:31:31 +04:00
|
|
|
}
|
2010-09-09 00:40:39 +04:00
|
|
|
return target;
|
2010-08-13 17:31:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
nsSVGRenderingObserver::GetReferencedFrame()
|
|
|
|
{
|
|
|
|
Element* referencedElement = GetReferencedElement();
|
2012-07-30 18:20:58 +04:00
|
|
|
return referencedElement ? referencedElement->GetPrimaryFrame() : nullptr;
|
2008-10-01 04:51:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame*
|
2011-09-29 10:19:26 +04:00
|
|
|
nsSVGRenderingObserver::GetReferencedFrame(nsIAtom* aFrameType, bool* aOK)
|
2008-10-01 04:51:05 +04:00
|
|
|
{
|
|
|
|
nsIFrame* frame = GetReferencedFrame();
|
2010-12-19 20:47:01 +03:00
|
|
|
if (frame) {
|
|
|
|
if (frame->GetType() == aFrameType)
|
|
|
|
return frame;
|
|
|
|
if (aOK) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*aOK = false;
|
2010-12-19 20:47:01 +03:00
|
|
|
}
|
2008-08-08 05:34:43 +04:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2008-08-08 05:34:43 +04:00
|
|
|
}
|
|
|
|
|
2008-10-01 04:51:05 +04:00
|
|
|
void
|
2010-08-13 17:31:31 +04:00
|
|
|
nsSVGRenderingObserver::InvalidateViaReferencedElement()
|
2008-10-01 04:51:05 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mInObserverList = false;
|
2008-10-01 04:51:05 +04:00
|
|
|
DoUpdate();
|
|
|
|
}
|
|
|
|
|
2010-11-16 21:35:59 +03:00
|
|
|
void
|
|
|
|
nsSVGRenderingObserver::NotifyEvictedFromRenderingObserverList()
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mInObserverList = false; // We've been removed from rendering-obs. list.
|
2010-11-16 21:35:59 +03:00
|
|
|
StopListening(); // Remove ourselves from mutation-obs. list.
|
|
|
|
}
|
|
|
|
|
2008-10-01 04:51:05 +04:00
|
|
|
void
|
2010-08-24 11:05:56 +04:00
|
|
|
nsSVGRenderingObserver::AttributeChanged(nsIDocument* aDocument,
|
|
|
|
dom::Element* aElement,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aNameSpaceID,
|
2010-08-24 11:05:56 +04:00
|
|
|
nsIAtom* aAttribute,
|
2015-07-25 09:01:19 +03:00
|
|
|
int32_t aModType,
|
|
|
|
const nsAttrValue* aOldValue)
|
2008-08-08 05:34:43 +04:00
|
|
|
{
|
2010-01-23 21:47:53 +03:00
|
|
|
// An attribute belonging to the element that we are observing *or one of its
|
|
|
|
// descendants* has changed.
|
|
|
|
//
|
|
|
|
// In the case of observing a gradient element, say, we want to know if any
|
|
|
|
// of its 'stop' element children change, but we don't actually want to do
|
|
|
|
// anything for changes to SMIL element children, for example. Maybe it's not
|
|
|
|
// worth having logic to optimize for that, but in most cases it could be a
|
|
|
|
// small check?
|
|
|
|
//
|
|
|
|
// XXXjwatt: do we really want to blindly break the link between our
|
|
|
|
// observers and ourselves for all attribute changes? For non-ID changes
|
|
|
|
// surely that is unnecessary.
|
|
|
|
|
2008-08-08 05:34:43 +04:00
|
|
|
DoUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-10-01 04:51:05 +04:00
|
|
|
nsSVGRenderingObserver::ContentAppended(nsIDocument *aDocument,
|
|
|
|
nsIContent *aContainer,
|
2010-05-11 05:12:34 +04:00
|
|
|
nsIContent *aFirstNewContent,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t /* unused */)
|
2008-08-08 05:34:43 +04:00
|
|
|
{
|
|
|
|
DoUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-10-01 04:51:05 +04:00
|
|
|
nsSVGRenderingObserver::ContentInserted(nsIDocument *aDocument,
|
|
|
|
nsIContent *aContainer,
|
|
|
|
nsIContent *aChild,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t /* unused */)
|
2008-08-08 05:34:43 +04:00
|
|
|
{
|
|
|
|
DoUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-10-01 04:51:05 +04:00
|
|
|
nsSVGRenderingObserver::ContentRemoved(nsIDocument *aDocument,
|
|
|
|
nsIContent *aContainer,
|
|
|
|
nsIContent *aChild,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aIndexInContainer,
|
2010-07-22 02:05:17 +04:00
|
|
|
nsIContent *aPreviousSibling)
|
2008-08-08 05:34:43 +04:00
|
|
|
{
|
|
|
|
DoUpdate();
|
|
|
|
}
|
|
|
|
|
2014-09-09 19:14:45 +04:00
|
|
|
/**
|
|
|
|
* Note that in the current setup there are two separate observer lists.
|
|
|
|
*
|
|
|
|
* In nsSVGIDRenderingObserver's ctor, the new object adds itself to the
|
|
|
|
* mutation observer list maintained by the referenced element. In this way the
|
|
|
|
* nsSVGIDRenderingObserver is notified if there are any attribute or content
|
|
|
|
* tree changes to the element or any of its *descendants*.
|
|
|
|
*
|
|
|
|
* In nsSVGIDRenderingObserver::GetReferencedElement() the
|
|
|
|
* nsSVGIDRenderingObserver object also adds itself to an
|
|
|
|
* nsSVGRenderingObserverList object belonging to the referenced
|
|
|
|
* element.
|
|
|
|
*
|
|
|
|
* XXX: it would be nice to have a clear and concise executive summary of the
|
|
|
|
* benefits/necessity of maintaining a second observer list.
|
|
|
|
*/
|
|
|
|
|
2014-09-09 19:14:45 +04:00
|
|
|
nsSVGIDRenderingObserver::nsSVGIDRenderingObserver(nsIURI* aURI,
|
|
|
|
nsIContent* aObservingContent,
|
2014-09-09 19:14:45 +04:00
|
|
|
bool aReferenceImage)
|
2015-01-07 08:39:46 +03:00
|
|
|
: mElement(this)
|
2014-09-09 19:14:45 +04:00
|
|
|
{
|
|
|
|
// Start watching the target element
|
2014-09-09 19:14:45 +04:00
|
|
|
mElement.Reset(aObservingContent, aURI, true, aReferenceImage);
|
2014-09-09 19:14:45 +04:00
|
|
|
StartListening();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGIDRenderingObserver::~nsSVGIDRenderingObserver()
|
|
|
|
{
|
|
|
|
StopListening();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSVGIDRenderingObserver::DoUpdate()
|
|
|
|
{
|
|
|
|
if (mElement.get() && mInObserverList) {
|
|
|
|
nsSVGEffects::RemoveRenderingObserver(mElement.get(), this);
|
|
|
|
mInObserverList = false;
|
|
|
|
}
|
2014-09-09 19:14:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSVGFrameReferenceFromProperty::Detach()
|
|
|
|
{
|
|
|
|
mFrame = nullptr;
|
|
|
|
mFramePresShell = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
nsSVGFrameReferenceFromProperty::Get()
|
|
|
|
{
|
|
|
|
if (mFramePresShell && mFramePresShell->IsDestroying()) {
|
|
|
|
// mFrame is no longer valid.
|
|
|
|
Detach();
|
|
|
|
}
|
|
|
|
return mFrame;
|
|
|
|
}
|
|
|
|
|
2015-07-09 21:32:00 +03:00
|
|
|
NS_IMPL_ISUPPORTS(nsSVGRenderingObserverProperty, nsIMutationObserver)
|
|
|
|
|
2014-09-09 19:14:45 +04:00
|
|
|
void
|
|
|
|
nsSVGRenderingObserverProperty::DoUpdate()
|
|
|
|
{
|
|
|
|
nsSVGIDRenderingObserver::DoUpdate();
|
|
|
|
|
|
|
|
nsIFrame* frame = mFrameReference.Get();
|
|
|
|
if (frame && frame->IsFrameOfType(nsIFrame::eSVG)) {
|
2014-09-09 19:14:45 +04:00
|
|
|
// Changes should propagate out to things that might be observing
|
|
|
|
// the referencing frame or its ancestors.
|
2014-11-06 12:30:11 +03:00
|
|
|
nsLayoutUtils::PostRestyleEvent(
|
|
|
|
frame->GetContent()->AsElement(), nsRestyleHint(0),
|
|
|
|
nsChangeHint_InvalidateRenderingObservers);
|
2014-09-09 19:14:45 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-09 19:14:46 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsSVGFilterReference)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsSVGFilterReference)
|
|
|
|
|
2014-09-10 14:18:57 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION(nsSVGFilterReference, mElement)
|
2014-09-09 19:14:46 +04:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsSVGFilterReference)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsSVGIDRenderingObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIMutationObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISVGFilterReference)
|
|
|
|
NS_INTERFACE_MAP_END
|
2014-09-09 19:14:45 +04:00
|
|
|
|
|
|
|
nsSVGFilterFrame *
|
|
|
|
nsSVGFilterReference::GetFilterFrame()
|
|
|
|
{
|
|
|
|
return static_cast<nsSVGFilterFrame *>
|
|
|
|
(GetReferencedFrame(nsGkAtoms::svgFilterFrame, nullptr));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSVGFilterReference::DoUpdate()
|
|
|
|
{
|
2014-09-09 19:14:46 +04:00
|
|
|
nsSVGIDRenderingObserver::DoUpdate();
|
2014-09-09 19:14:45 +04:00
|
|
|
|
2014-09-09 19:14:46 +04:00
|
|
|
if (mFilterChainObserver) {
|
|
|
|
mFilterChainObserver->Invalidate();
|
2014-09-09 19:14:45 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-09 19:14:46 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsSVGFilterChainObserver)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsSVGFilterChainObserver)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsSVGFilterChainObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION(nsSVGFilterChainObserver, mReferences)
|
2014-02-10 08:31:03 +04:00
|
|
|
|
2014-09-09 19:14:46 +04:00
|
|
|
nsSVGFilterChainObserver::nsSVGFilterChainObserver(const nsTArray<nsStyleFilter>& aFilters,
|
|
|
|
nsIContent* aFilteredElement)
|
2014-02-10 08:31:03 +04:00
|
|
|
{
|
2014-09-09 19:14:44 +04:00
|
|
|
for (uint32_t i = 0; i < aFilters.Length(); i++) {
|
|
|
|
if (aFilters[i].GetType() != NS_STYLE_FILTER_URL)
|
2014-02-10 08:31:03 +04:00
|
|
|
continue;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsSVGFilterReference> reference =
|
2014-09-09 19:14:46 +04:00
|
|
|
new nsSVGFilterReference(aFilters[i].GetURL(), aFilteredElement, this);
|
2014-02-10 08:31:03 +04:00
|
|
|
mReferences.AppendElement(reference);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-09 19:14:46 +04:00
|
|
|
nsSVGFilterChainObserver::~nsSVGFilterChainObserver()
|
2014-09-09 19:14:46 +04:00
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < mReferences.Length(); i++) {
|
|
|
|
mReferences[i]->DetachFromChainObserver();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 08:31:03 +04:00
|
|
|
bool
|
2014-09-09 19:14:46 +04:00
|
|
|
nsSVGFilterChainObserver::ReferencesValidResources()
|
2014-02-10 08:31:03 +04:00
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < mReferences.Length(); i++) {
|
|
|
|
if (!mReferences[i]->ReferencesValidResource())
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-09-09 19:14:46 +04:00
|
|
|
nsSVGFilterChainObserver::IsInObserverLists() const
|
2014-02-10 08:31:03 +04:00
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < mReferences.Length(); i++) {
|
|
|
|
if (!mReferences[i]->IsInObserverList())
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-09 19:14:46 +04:00
|
|
|
nsSVGFilterProperty::DoUpdate()
|
2014-02-10 08:31:03 +04:00
|
|
|
{
|
2014-09-09 19:14:46 +04:00
|
|
|
nsIFrame* frame = mFrameReference.Get();
|
|
|
|
if (!frame)
|
|
|
|
return;
|
|
|
|
|
2014-11-06 12:30:11 +03:00
|
|
|
// Repaint asynchronously in case the filter frame is being torn down
|
|
|
|
nsChangeHint changeHint =
|
|
|
|
nsChangeHint(nsChangeHint_RepaintFrame);
|
|
|
|
|
2014-09-09 19:14:46 +04:00
|
|
|
if (frame && frame->IsFrameOfType(nsIFrame::eSVG)) {
|
|
|
|
// Changes should propagate out to things that might be observing
|
|
|
|
// the referencing frame or its ancestors.
|
2014-11-06 12:30:11 +03:00
|
|
|
NS_UpdateHint(changeHint, nsChangeHint_InvalidateRenderingObservers);
|
2014-09-09 19:14:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Don't need to request UpdateOverflow if we're being reflowed.
|
|
|
|
if (!(frame->GetStateBits() & NS_FRAME_IN_REFLOW)) {
|
|
|
|
NS_UpdateHint(changeHint, nsChangeHint_UpdateOverflow);
|
2014-02-10 08:31:03 +04:00
|
|
|
}
|
2014-09-09 19:14:46 +04:00
|
|
|
frame->PresContext()->RestyleManager()->PostRestyleEvent(
|
|
|
|
frame->GetContent()->AsElement(), nsRestyleHint(0), changeHint);
|
2014-02-10 08:31:03 +04:00
|
|
|
}
|
2008-08-08 05:34:43 +04:00
|
|
|
|
2008-10-10 17:14:05 +04:00
|
|
|
void
|
|
|
|
nsSVGMarkerProperty::DoUpdate()
|
|
|
|
{
|
2014-09-09 19:14:45 +04:00
|
|
|
nsSVGRenderingObserverProperty::DoUpdate();
|
|
|
|
|
|
|
|
nsIFrame* frame = mFrameReference.Get();
|
|
|
|
if (!frame)
|
2008-10-10 17:14:05 +04:00
|
|
|
return;
|
|
|
|
|
2014-09-09 19:14:45 +04:00
|
|
|
NS_ASSERTION(frame->IsFrameOfType(nsIFrame::eSVG), "SVG frame expected");
|
2009-01-22 04:02:40 +03:00
|
|
|
|
2012-11-06 23:13:25 +04:00
|
|
|
// Repaint asynchronously in case the marker frame is being torn down
|
2009-01-22 04:02:40 +03:00
|
|
|
nsChangeHint changeHint =
|
2012-11-07 17:54:55 +04:00
|
|
|
nsChangeHint(nsChangeHint_RepaintFrame);
|
2014-08-01 04:37:35 +04:00
|
|
|
|
2012-07-20 08:54:20 +04:00
|
|
|
// Don't need to request ReflowFrame if we're being reflowed.
|
2014-09-09 19:14:45 +04:00
|
|
|
if (!(frame->GetStateBits() & NS_FRAME_IN_REFLOW)) {
|
2014-11-06 12:30:11 +03:00
|
|
|
NS_UpdateHint(changeHint, nsChangeHint_InvalidateRenderingObservers);
|
2012-07-20 08:54:20 +04:00
|
|
|
// XXXjwatt: We need to unify SVG into standard reflow so we can just use
|
2012-09-08 02:57:06 +04:00
|
|
|
// nsChangeHint_NeedReflow | nsChangeHint_NeedDirtyReflow here.
|
2012-11-28 13:42:13 +04:00
|
|
|
// XXXSDL KILL THIS!!!
|
2014-09-09 19:14:45 +04:00
|
|
|
nsSVGUtils::ScheduleReflowSVG(frame);
|
2012-07-20 08:54:20 +04:00
|
|
|
}
|
2014-09-09 19:14:45 +04:00
|
|
|
frame->PresContext()->RestyleManager()->PostRestyleEvent(
|
|
|
|
frame->GetContent()->AsElement(), nsRestyleHint(0), changeHint);
|
2008-10-10 17:14:05 +04:00
|
|
|
}
|
|
|
|
|
2013-02-11 10:22:20 +04:00
|
|
|
bool
|
|
|
|
nsSVGTextPathProperty::TargetIsValid()
|
|
|
|
{
|
|
|
|
Element* target = GetTarget();
|
2015-03-03 14:08:59 +03:00
|
|
|
return target && target->IsSVGElement(nsGkAtoms::path);
|
2013-02-11 10:22:20 +04:00
|
|
|
}
|
|
|
|
|
2008-10-11 15:29:35 +04:00
|
|
|
void
|
|
|
|
nsSVGTextPathProperty::DoUpdate()
|
|
|
|
{
|
2014-09-09 19:14:45 +04:00
|
|
|
nsSVGRenderingObserverProperty::DoUpdate();
|
|
|
|
|
|
|
|
nsIFrame* frame = mFrameReference.Get();
|
|
|
|
if (!frame)
|
2008-10-11 15:29:35 +04:00
|
|
|
return;
|
|
|
|
|
2014-09-09 19:14:45 +04:00
|
|
|
NS_ASSERTION(frame->IsFrameOfType(nsIFrame::eSVG) || frame->IsSVGText(),
|
2013-02-11 10:22:17 +04:00
|
|
|
"SVG frame expected");
|
2008-10-11 15:29:35 +04:00
|
|
|
|
2013-02-11 10:22:20 +04:00
|
|
|
// Avoid getting into an infinite loop of reflows if the <textPath> is
|
|
|
|
// pointing to one of its ancestors. TargetIsValid returns true iff
|
|
|
|
// the target element is a <path> element, and we would not have this
|
|
|
|
// nsSVGTextPathProperty if this <textPath> were a descendant of the
|
|
|
|
// target <path>.
|
|
|
|
//
|
|
|
|
// Note that we still have to post the restyle event when we
|
|
|
|
// change from being valid to invalid, so that mPositions on the
|
2013-12-20 20:38:51 +04:00
|
|
|
// SVGTextFrame gets updated, skipping the <textPath>, ensuring
|
2013-02-11 10:22:20 +04:00
|
|
|
// that nothing gets painted for that element.
|
|
|
|
bool nowValid = TargetIsValid();
|
|
|
|
if (!mValid && !nowValid) {
|
|
|
|
// Just return if we were previously invalid, and are still invalid.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mValid = nowValid;
|
|
|
|
|
2013-02-11 10:22:17 +04:00
|
|
|
// Repaint asynchronously in case the path frame is being torn down
|
|
|
|
nsChangeHint changeHint =
|
|
|
|
nsChangeHint(nsChangeHint_RepaintFrame | nsChangeHint_UpdateTextPath);
|
2014-09-09 19:14:45 +04:00
|
|
|
frame->PresContext()->RestyleManager()->PostRestyleEvent(
|
|
|
|
frame->GetContent()->AsElement(), nsRestyleHint(0), changeHint);
|
2008-10-11 15:29:35 +04:00
|
|
|
}
|
|
|
|
|
2014-09-09 19:14:45 +04:00
|
|
|
static void
|
|
|
|
InvalidateAllContinuations(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
for (nsIFrame* f = aFrame; f;
|
|
|
|
f = nsLayoutUtils::GetNextContinuationOrIBSplitSibling(f)) {
|
|
|
|
f->InvalidateFrame();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-30 15:28:20 +04:00
|
|
|
void
|
2008-10-01 04:51:05 +04:00
|
|
|
nsSVGPaintingProperty::DoUpdate()
|
2008-09-30 15:28:20 +04:00
|
|
|
{
|
2014-09-09 19:14:45 +04:00
|
|
|
nsSVGRenderingObserverProperty::DoUpdate();
|
|
|
|
|
|
|
|
nsIFrame* frame = mFrameReference.Get();
|
|
|
|
if (!frame)
|
2008-09-30 15:28:20 +04:00
|
|
|
return;
|
|
|
|
|
2014-09-09 19:14:45 +04:00
|
|
|
if (frame->GetStateBits() & NS_FRAME_SVG_LAYOUT) {
|
2014-11-06 12:30:11 +03:00
|
|
|
nsLayoutUtils::PostRestyleEvent(
|
|
|
|
frame->GetContent()->AsElement(), nsRestyleHint(0),
|
|
|
|
nsChangeHint_InvalidateRenderingObservers);
|
2014-09-09 19:14:45 +04:00
|
|
|
frame->InvalidateFrameSubtree();
|
2008-10-01 04:51:05 +04:00
|
|
|
} else {
|
2014-09-09 19:14:45 +04:00
|
|
|
InvalidateAllContinuations(frame);
|
2008-09-30 15:28:20 +04:00
|
|
|
}
|
2008-08-08 05:34:43 +04:00
|
|
|
}
|
|
|
|
|
2008-10-10 17:14:05 +04:00
|
|
|
static nsSVGRenderingObserver *
|
2011-09-29 10:19:26 +04:00
|
|
|
CreateMarkerProperty(nsIURI *aURI, nsIFrame *aFrame, bool aReferenceImage)
|
2010-08-13 17:36:05 +04:00
|
|
|
{ return new nsSVGMarkerProperty(aURI, aFrame, aReferenceImage); }
|
2008-10-10 17:14:05 +04:00
|
|
|
|
2008-10-11 15:29:35 +04:00
|
|
|
static nsSVGRenderingObserver *
|
2011-09-29 10:19:26 +04:00
|
|
|
CreateTextPathProperty(nsIURI *aURI, nsIFrame *aFrame, bool aReferenceImage)
|
2010-08-13 17:36:05 +04:00
|
|
|
{ return new nsSVGTextPathProperty(aURI, aFrame, aReferenceImage); }
|
2008-10-11 15:29:35 +04:00
|
|
|
|
2008-10-01 04:51:05 +04:00
|
|
|
static nsSVGRenderingObserver *
|
2011-09-29 10:19:26 +04:00
|
|
|
CreatePaintingProperty(nsIURI *aURI, nsIFrame *aFrame, bool aReferenceImage)
|
2010-08-13 17:36:05 +04:00
|
|
|
{ return new nsSVGPaintingProperty(aURI, aFrame, aReferenceImage); }
|
2008-08-08 05:34:43 +04:00
|
|
|
|
2008-10-01 04:51:05 +04:00
|
|
|
static nsSVGRenderingObserver *
|
2010-03-29 05:46:55 +04:00
|
|
|
GetEffectProperty(nsIURI *aURI, nsIFrame *aFrame,
|
2016-01-28 06:23:59 +03:00
|
|
|
nsSVGEffects::ObserverPropertyDescriptor aProperty,
|
2011-09-29 10:19:26 +04:00
|
|
|
nsSVGRenderingObserver * (* aCreate)(nsIURI *, nsIFrame *, bool))
|
2008-08-08 05:34:43 +04:00
|
|
|
{
|
|
|
|
if (!aURI)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-03-29 05:46:55 +04:00
|
|
|
|
|
|
|
FrameProperties props = aFrame->Properties();
|
2008-10-01 04:51:05 +04:00
|
|
|
nsSVGRenderingObserver *prop =
|
2010-03-29 05:46:55 +04:00
|
|
|
static_cast<nsSVGRenderingObserver*>(props.Get(aProperty));
|
2008-08-08 05:34:43 +04:00
|
|
|
if (prop)
|
|
|
|
return prop;
|
2011-10-17 18:59:28 +04:00
|
|
|
prop = aCreate(aURI, aFrame, false);
|
2008-08-08 05:34:43 +04:00
|
|
|
if (!prop)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2008-08-08 05:34:43 +04:00
|
|
|
NS_ADDREF(prop);
|
2010-03-29 05:46:55 +04:00
|
|
|
props.Set(aProperty, static_cast<nsISupports*>(prop));
|
2008-08-08 05:34:43 +04:00
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
|
2014-02-10 08:31:03 +04:00
|
|
|
static nsSVGFilterProperty*
|
|
|
|
GetOrCreateFilterProperty(nsIFrame *aFrame)
|
|
|
|
{
|
|
|
|
const nsStyleSVGReset* style = aFrame->StyleSVGReset();
|
|
|
|
if (!style->HasFilters())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
FrameProperties props = aFrame->Properties();
|
2016-01-28 06:23:59 +03:00
|
|
|
nsSVGFilterProperty *prop = props.Get(nsSVGEffects::FilterProperty());
|
2014-02-10 08:31:03 +04:00
|
|
|
if (prop)
|
|
|
|
return prop;
|
|
|
|
prop = new nsSVGFilterProperty(style->mFilters, aFrame);
|
|
|
|
if (!prop)
|
|
|
|
return nullptr;
|
|
|
|
NS_ADDREF(prop);
|
2016-01-28 06:23:59 +03:00
|
|
|
props.Set(nsSVGEffects::FilterProperty(), prop);
|
2014-02-10 08:31:03 +04:00
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
|
2008-10-10 17:14:05 +04:00
|
|
|
nsSVGMarkerProperty *
|
2010-03-29 05:46:55 +04:00
|
|
|
nsSVGEffects::GetMarkerProperty(nsIURI *aURI, nsIFrame *aFrame,
|
2016-01-28 06:23:59 +03:00
|
|
|
ObserverPropertyDescriptor aProp)
|
2008-10-10 17:14:05 +04:00
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(aFrame->GetType() == nsGkAtoms::svgPathGeometryFrame &&
|
|
|
|
static_cast<nsSVGPathGeometryElement*>(aFrame->GetContent())->IsMarkable(),
|
|
|
|
"Bad frame");
|
2008-10-10 17:14:05 +04:00
|
|
|
return static_cast<nsSVGMarkerProperty*>(
|
|
|
|
GetEffectProperty(aURI, aFrame, aProp, CreateMarkerProperty));
|
|
|
|
}
|
|
|
|
|
2008-10-11 15:29:35 +04:00
|
|
|
nsSVGTextPathProperty *
|
2010-03-29 05:46:55 +04:00
|
|
|
nsSVGEffects::GetTextPathProperty(nsIURI *aURI, nsIFrame *aFrame,
|
2016-01-28 06:23:59 +03:00
|
|
|
ObserverPropertyDescriptor aProp)
|
2008-10-11 15:29:35 +04:00
|
|
|
{
|
|
|
|
return static_cast<nsSVGTextPathProperty*>(
|
|
|
|
GetEffectProperty(aURI, aFrame, aProp, CreateTextPathProperty));
|
|
|
|
}
|
|
|
|
|
2008-10-01 04:51:05 +04:00
|
|
|
nsSVGPaintingProperty *
|
2010-03-29 05:46:55 +04:00
|
|
|
nsSVGEffects::GetPaintingProperty(nsIURI *aURI, nsIFrame *aFrame,
|
2016-01-28 06:23:59 +03:00
|
|
|
ObserverPropertyDescriptor aProp)
|
2008-10-01 04:51:05 +04:00
|
|
|
{
|
|
|
|
return static_cast<nsSVGPaintingProperty*>(
|
|
|
|
GetEffectProperty(aURI, aFrame, aProp, CreatePaintingProperty));
|
|
|
|
}
|
|
|
|
|
2010-08-13 17:30:45 +04:00
|
|
|
static nsSVGRenderingObserver *
|
|
|
|
GetEffectPropertyForURI(nsIURI *aURI, nsIFrame *aFrame,
|
2016-01-28 06:23:59 +03:00
|
|
|
nsSVGEffects::URIObserverHashtablePropertyDescriptor aProperty,
|
2011-09-29 10:19:26 +04:00
|
|
|
nsSVGRenderingObserver * (* aCreate)(nsIURI *, nsIFrame *, bool))
|
2010-08-13 17:30:45 +04:00
|
|
|
{
|
2010-09-14 23:50:41 +04:00
|
|
|
if (!aURI)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-09-14 23:50:41 +04:00
|
|
|
|
2010-08-13 17:30:45 +04:00
|
|
|
FrameProperties props = aFrame->Properties();
|
2016-01-28 06:23:59 +03:00
|
|
|
nsSVGEffects::URIObserverHashtable *hashtable = props.Get(aProperty);
|
2010-08-13 17:30:45 +04:00
|
|
|
if (!hashtable) {
|
|
|
|
hashtable = new nsSVGEffects::URIObserverHashtable();
|
|
|
|
props.Set(aProperty, hashtable);
|
|
|
|
}
|
|
|
|
nsSVGRenderingObserver* prop =
|
|
|
|
static_cast<nsSVGRenderingObserver*>(hashtable->GetWeak(aURI));
|
|
|
|
if (!prop) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool watchImage = aProperty == nsSVGEffects::BackgroundImageProperty();
|
2010-08-13 17:36:05 +04:00
|
|
|
prop = aCreate(aURI, aFrame, watchImage);
|
2010-08-13 17:30:45 +04:00
|
|
|
hashtable->Put(aURI, prop);
|
|
|
|
}
|
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGPaintingProperty *
|
|
|
|
nsSVGEffects::GetPaintingPropertyForURI(nsIURI *aURI, nsIFrame *aFrame,
|
2016-01-28 06:23:59 +03:00
|
|
|
URIObserverHashtablePropertyDescriptor aProp)
|
2010-08-13 17:30:45 +04:00
|
|
|
{
|
|
|
|
return static_cast<nsSVGPaintingProperty*>(
|
|
|
|
GetEffectPropertyForURI(aURI, aFrame, aProp, CreatePaintingProperty));
|
|
|
|
}
|
|
|
|
|
2008-08-08 05:34:43 +04:00
|
|
|
nsSVGEffects::EffectProperties
|
|
|
|
nsSVGEffects::GetEffectProperties(nsIFrame *aFrame)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!aFrame->GetPrevContinuation(), "aFrame should be first continuation");
|
|
|
|
|
|
|
|
EffectProperties result;
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleSVGReset *style = aFrame->StyleSVGReset();
|
2014-02-10 08:31:03 +04:00
|
|
|
result.mFilter = GetOrCreateFilterProperty(aFrame);
|
2014-09-28 03:56:00 +04:00
|
|
|
if (style->mClipPath.GetType() == NS_STYLE_CLIP_PATH_URL) {
|
|
|
|
result.mClipPath =
|
|
|
|
GetPaintingProperty(style->mClipPath.GetURL(), aFrame, ClipPathProperty());
|
|
|
|
} else {
|
|
|
|
result.mClipPath = nullptr;
|
|
|
|
}
|
2016-01-28 08:37:00 +03:00
|
|
|
|
|
|
|
// FIXME: Bug 1228280.
|
|
|
|
// Before fixing bug 1228280, we support only single svg mask as before.
|
|
|
|
MOZ_ASSERT(style->mLayers.mImageCount > 0);
|
|
|
|
nsCOMPtr<nsIURI> uri = style->mLayers.mLayers[0].mSourceURI;
|
|
|
|
result.mMask = uri ? GetPaintingProperty(uri, aFrame, MaskProperty()) :
|
|
|
|
nullptr;
|
|
|
|
|
2008-08-08 05:34:43 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-08-05 23:10:21 +04:00
|
|
|
nsSVGPaintServerFrame *
|
|
|
|
nsSVGEffects::GetPaintServer(nsIFrame *aTargetFrame, const nsStyleSVGPaint *aPaint,
|
2016-01-28 06:23:59 +03:00
|
|
|
ObserverPropertyDescriptor aType)
|
2012-08-05 23:10:21 +04:00
|
|
|
{
|
|
|
|
if (aPaint->mType != eStyleSVGPaintType_Server)
|
|
|
|
return nullptr;
|
|
|
|
|
2015-07-24 02:22:01 +03:00
|
|
|
// If we're looking at a frame within SVG text, then we need to look up
|
|
|
|
// to find the right frame to get the painting property off. We should at
|
|
|
|
// least look up past a text frame, and if the text frame's parent is the
|
|
|
|
// anonymous block frame, then we look up to its parent (the SVGTextFrame).
|
|
|
|
nsIFrame* frame = aTargetFrame;
|
|
|
|
if (frame->GetContent()->IsNodeOfType(nsINode::eTEXT)) {
|
|
|
|
frame = frame->GetParent();
|
|
|
|
nsIFrame* grandparent = frame->GetParent();
|
|
|
|
if (grandparent && grandparent->GetType() == nsGkAtoms::svgTextFrame) {
|
|
|
|
frame = grandparent;
|
|
|
|
}
|
|
|
|
}
|
2012-08-05 23:10:21 +04:00
|
|
|
nsSVGPaintingProperty *property =
|
|
|
|
nsSVGEffects::GetPaintingProperty(aPaint->mPaint.mPaintServer, frame, aType);
|
|
|
|
if (!property)
|
|
|
|
return nullptr;
|
|
|
|
nsIFrame *result = property->GetReferencedFrame();
|
|
|
|
if (!result)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
nsIAtom *type = result->GetType();
|
|
|
|
if (type != nsGkAtoms::svgLinearGradientFrame &&
|
|
|
|
type != nsGkAtoms::svgRadialGradientFrame &&
|
|
|
|
type != nsGkAtoms::svgPatternFrame)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return static_cast<nsSVGPaintServerFrame*>(result);
|
|
|
|
}
|
2014-08-01 04:37:35 +04:00
|
|
|
|
2008-10-01 04:51:05 +04:00
|
|
|
nsSVGClipPathFrame *
|
2011-09-29 10:19:26 +04:00
|
|
|
nsSVGEffects::EffectProperties::GetClipPathFrame(bool *aOK)
|
2008-10-10 17:14:05 +04:00
|
|
|
{
|
2008-10-01 04:51:05 +04:00
|
|
|
if (!mClipPath)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-03-02 12:31:07 +03:00
|
|
|
nsSVGClipPathFrame *frame = static_cast<nsSVGClipPathFrame *>
|
2008-10-01 04:51:05 +04:00
|
|
|
(mClipPath->GetReferencedFrame(nsGkAtoms::svgClipPathFrame, aOK));
|
2010-03-02 12:31:07 +03:00
|
|
|
if (frame && aOK && *aOK) {
|
|
|
|
*aOK = frame->IsValid();
|
|
|
|
}
|
|
|
|
return frame;
|
2008-10-01 04:51:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGMaskFrame *
|
2011-09-29 10:19:26 +04:00
|
|
|
nsSVGEffects::EffectProperties::GetMaskFrame(bool *aOK)
|
2008-10-10 17:14:05 +04:00
|
|
|
{
|
2008-10-01 04:51:05 +04:00
|
|
|
if (!mMask)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2008-10-01 04:51:05 +04:00
|
|
|
return static_cast<nsSVGMaskFrame *>
|
|
|
|
(mMask->GetReferencedFrame(nsGkAtoms::svgMaskFrame, aOK));
|
|
|
|
}
|
|
|
|
|
2008-08-08 05:34:43 +04:00
|
|
|
void
|
|
|
|
nsSVGEffects::UpdateEffects(nsIFrame *aFrame)
|
|
|
|
{
|
2010-04-30 17:12:06 +04:00
|
|
|
NS_ASSERTION(aFrame->GetContent()->IsElement(),
|
2010-01-13 14:09:58 +03:00
|
|
|
"aFrame's content should be an element");
|
|
|
|
|
2010-03-29 05:46:55 +04:00
|
|
|
FrameProperties props = aFrame->Properties();
|
|
|
|
props.Delete(FilterProperty());
|
|
|
|
props.Delete(MaskProperty());
|
|
|
|
props.Delete(ClipPathProperty());
|
|
|
|
props.Delete(MarkerBeginProperty());
|
|
|
|
props.Delete(MarkerMiddleProperty());
|
|
|
|
props.Delete(MarkerEndProperty());
|
|
|
|
props.Delete(FillProperty());
|
|
|
|
props.Delete(StrokeProperty());
|
2010-08-13 17:30:45 +04:00
|
|
|
props.Delete(BackgroundImageProperty());
|
2008-10-22 13:09:03 +04:00
|
|
|
|
2008-10-27 14:48:20 +03:00
|
|
|
// Ensure that the filter is repainted correctly
|
2008-10-22 13:09:03 +04:00
|
|
|
// We can't do that in DoUpdate as the referenced frame may not be valid
|
2014-02-10 08:31:03 +04:00
|
|
|
GetOrCreateFilterProperty(aFrame);
|
2009-01-22 04:02:40 +03:00
|
|
|
|
2012-11-01 13:41:51 +04:00
|
|
|
if (aFrame->GetType() == nsGkAtoms::svgPathGeometryFrame &&
|
|
|
|
static_cast<nsSVGPathGeometryElement*>(aFrame->GetContent())->IsMarkable()) {
|
2009-01-30 10:13:36 +03:00
|
|
|
// Set marker properties here to avoid reference loops
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleSVG *style = aFrame->StyleSVG();
|
2010-03-29 05:46:55 +04:00
|
|
|
GetEffectProperty(style->mMarkerStart, aFrame, MarkerBeginProperty(),
|
2009-01-30 10:13:36 +03:00
|
|
|
CreateMarkerProperty);
|
2010-03-29 05:46:55 +04:00
|
|
|
GetEffectProperty(style->mMarkerMid, aFrame, MarkerMiddleProperty(),
|
2009-01-30 10:13:36 +03:00
|
|
|
CreateMarkerProperty);
|
2010-03-29 05:46:55 +04:00
|
|
|
GetEffectProperty(style->mMarkerEnd, aFrame, MarkerEndProperty(),
|
2009-01-30 10:13:36 +03:00
|
|
|
CreateMarkerProperty);
|
|
|
|
}
|
2008-08-08 05:34:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGFilterProperty *
|
|
|
|
nsSVGEffects::GetFilterProperty(nsIFrame *aFrame)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!aFrame->GetPrevContinuation(), "aFrame should be first continuation");
|
|
|
|
|
2014-02-10 08:31:03 +04:00
|
|
|
if (!aFrame->StyleSVGReset()->HasFilters())
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2008-08-08 05:34:43 +04:00
|
|
|
|
2010-03-29 05:46:55 +04:00
|
|
|
return static_cast<nsSVGFilterProperty *>
|
|
|
|
(aFrame->Properties().Get(FilterProperty()));
|
2008-08-08 05:34:43 +04:00
|
|
|
}
|
2008-10-01 04:51:05 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
nsSVGRenderingObserverList::InvalidateAll()
|
|
|
|
{
|
|
|
|
if (mObservers.Count() == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsAutoTArray<nsSVGRenderingObserver*,10> observers;
|
2010-01-23 21:47:53 +03:00
|
|
|
|
2015-07-14 03:13:32 +03:00
|
|
|
for (auto it = mObservers.Iter(); !it.Done(); it.Next()) {
|
|
|
|
observers.AppendElement(it.Get()->GetKey());
|
|
|
|
}
|
|
|
|
mObservers.Clear();
|
2010-01-23 21:47:53 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < observers.Length(); ++i) {
|
2010-08-13 17:31:31 +04:00
|
|
|
observers[i]->InvalidateViaReferencedElement();
|
2008-10-01 04:51:05 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-29 09:49:16 +04:00
|
|
|
void
|
|
|
|
nsSVGRenderingObserverList::InvalidateAllForReflow()
|
|
|
|
{
|
|
|
|
if (mObservers.Count() == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsAutoTArray<nsSVGRenderingObserver*,10> observers;
|
|
|
|
|
2015-07-14 03:13:32 +03:00
|
|
|
for (auto it = mObservers.Iter(); !it.Done(); it.Next()) {
|
|
|
|
nsSVGRenderingObserver* obs = it.Get()->GetKey();
|
|
|
|
if (obs->ObservesReflow()) {
|
|
|
|
observers.AppendElement(obs);
|
|
|
|
it.Remove();
|
|
|
|
}
|
|
|
|
}
|
2012-08-29 09:49:16 +04:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < observers.Length(); ++i) {
|
|
|
|
observers[i]->InvalidateViaReferencedElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-16 21:35:59 +03:00
|
|
|
void
|
|
|
|
nsSVGRenderingObserverList::RemoveAll()
|
|
|
|
{
|
|
|
|
nsAutoTArray<nsSVGRenderingObserver*,10> observers;
|
|
|
|
|
2015-07-14 03:13:32 +03:00
|
|
|
for (auto it = mObservers.Iter(); !it.Done(); it.Next()) {
|
|
|
|
observers.AppendElement(it.Get()->GetKey());
|
|
|
|
}
|
|
|
|
mObservers.Clear();
|
2010-11-16 21:35:59 +03:00
|
|
|
|
|
|
|
// Our list is now cleared. We need to notify the observers we've removed,
|
|
|
|
// so they can update their state & remove themselves as mutation-observers.
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < observers.Length(); ++i) {
|
2010-11-16 21:35:59 +03:00
|
|
|
observers[i]->NotifyEvictedFromRenderingObserverList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-01 04:51:05 +04:00
|
|
|
void
|
2010-08-13 17:31:31 +04:00
|
|
|
nsSVGEffects::AddRenderingObserver(Element *aElement, nsSVGRenderingObserver *aObserver)
|
2008-10-01 04:51:05 +04:00
|
|
|
{
|
2010-08-13 17:31:31 +04:00
|
|
|
nsSVGRenderingObserverList *observerList = GetObserverList(aElement);
|
2008-10-01 04:51:05 +04:00
|
|
|
if (!observerList) {
|
|
|
|
observerList = new nsSVGRenderingObserverList();
|
|
|
|
if (!observerList)
|
|
|
|
return;
|
2014-03-25 17:25:47 +04:00
|
|
|
aElement->SetProperty(nsGkAtoms::renderingobserverlist, observerList,
|
|
|
|
nsINode::DeleteProperty<nsSVGRenderingObserverList>);
|
2008-10-01 04:51:05 +04:00
|
|
|
}
|
2010-08-13 17:31:31 +04:00
|
|
|
aElement->SetHasRenderingObservers(true);
|
2008-10-01 04:51:05 +04:00
|
|
|
observerList->Add(aObserver);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-08-13 17:31:31 +04:00
|
|
|
nsSVGEffects::RemoveRenderingObserver(Element *aElement, nsSVGRenderingObserver *aObserver)
|
2008-10-01 04:51:05 +04:00
|
|
|
{
|
2010-08-13 17:31:31 +04:00
|
|
|
nsSVGRenderingObserverList *observerList = GetObserverList(aElement);
|
2008-10-01 04:51:05 +04:00
|
|
|
if (observerList) {
|
2010-08-13 17:31:31 +04:00
|
|
|
NS_ASSERTION(observerList->Contains(aObserver),
|
|
|
|
"removing observer from an element we're not observing?");
|
2008-10-01 04:51:05 +04:00
|
|
|
observerList->Remove(aObserver);
|
2010-08-13 17:31:31 +04:00
|
|
|
if (observerList->IsEmpty()) {
|
|
|
|
aElement->SetHasRenderingObservers(false);
|
|
|
|
}
|
2008-10-01 04:51:05 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-16 21:35:59 +03:00
|
|
|
void
|
|
|
|
nsSVGEffects::RemoveAllRenderingObservers(Element *aElement)
|
|
|
|
{
|
|
|
|
nsSVGRenderingObserverList *observerList = GetObserverList(aElement);
|
|
|
|
if (observerList) {
|
|
|
|
observerList->RemoveAll();
|
|
|
|
aElement->SetHasRenderingObservers(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-01 04:51:05 +04:00
|
|
|
void
|
|
|
|
nsSVGEffects::InvalidateRenderingObservers(nsIFrame *aFrame)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!aFrame->GetPrevContinuation(), "aFrame must be first continuation");
|
|
|
|
|
2015-12-30 23:19:33 +03:00
|
|
|
nsIContent* content = aFrame->GetContent();
|
|
|
|
if (!content || !content->IsElement())
|
2010-08-13 17:31:31 +04:00
|
|
|
return;
|
|
|
|
|
2015-04-27 13:15:36 +03:00
|
|
|
// If the rendering has changed, the bounds may well have changed too:
|
|
|
|
aFrame->Properties().Delete(nsSVGUtils::ObjectBoundingBoxProperty());
|
|
|
|
|
2010-08-13 17:31:31 +04:00
|
|
|
nsSVGRenderingObserverList *observerList =
|
2015-12-30 23:19:33 +03:00
|
|
|
GetObserverList(content->AsElement());
|
2008-10-01 04:51:05 +04:00
|
|
|
if (observerList) {
|
|
|
|
observerList->InvalidateAll();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check ancestor SVG containers. The root frame cannot be of type
|
|
|
|
// eSVGContainer so we don't have to check f for null here.
|
|
|
|
for (nsIFrame *f = aFrame->GetParent();
|
|
|
|
f->IsFrameOfType(nsIFrame::eSVGContainer); f = f->GetParent()) {
|
2010-08-13 17:31:31 +04:00
|
|
|
if (f->GetContent()->IsElement()) {
|
|
|
|
observerList = GetObserverList(f->GetContent()->AsElement());
|
|
|
|
if (observerList) {
|
|
|
|
observerList->InvalidateAll();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-29 09:49:16 +04:00
|
|
|
nsSVGEffects::InvalidateDirectRenderingObservers(Element *aElement, uint32_t aFlags /* = 0 */)
|
2010-08-13 17:31:31 +04:00
|
|
|
{
|
2015-04-27 13:15:36 +03:00
|
|
|
nsIFrame* frame = aElement->GetPrimaryFrame();
|
|
|
|
if (frame) {
|
|
|
|
// If the rendering has changed, the bounds may well have changed too:
|
|
|
|
frame->Properties().Delete(nsSVGUtils::ObjectBoundingBoxProperty());
|
|
|
|
}
|
|
|
|
|
2010-08-13 17:31:31 +04:00
|
|
|
if (aElement->HasRenderingObservers()) {
|
|
|
|
nsSVGRenderingObserverList *observerList = GetObserverList(aElement);
|
2008-10-01 04:51:05 +04:00
|
|
|
if (observerList) {
|
2012-08-29 09:49:16 +04:00
|
|
|
if (aFlags & INVALIDATE_REFLOW) {
|
|
|
|
observerList->InvalidateAllForReflow();
|
|
|
|
} else {
|
|
|
|
observerList->InvalidateAll();
|
|
|
|
}
|
2008-10-01 04:51:05 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-29 09:49:16 +04:00
|
|
|
nsSVGEffects::InvalidateDirectRenderingObservers(nsIFrame *aFrame, uint32_t aFlags /* = 0 */)
|
2008-10-01 04:51:05 +04:00
|
|
|
{
|
2015-12-30 23:19:33 +03:00
|
|
|
nsIContent* content = aFrame->GetContent();
|
|
|
|
if (content && content->IsElement()) {
|
|
|
|
InvalidateDirectRenderingObservers(content->AsElement(), aFlags);
|
2008-10-01 04:51:05 +04:00
|
|
|
}
|
|
|
|
}
|