Files
palemoon27/dom/svg/SVGTransformableElement.cpp
T
roytam1 0b93aaef9b import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1194466. Use the table-outer frame's margin when requesting the margin for table element with getBoxQuads. r=mats (cb73af6b17)
- Backed out changeset 3f51676191a6 (bug 1225703) for cpp unittest failures on at least Windows CLOSED TREE (833dc52434)
- Bug 1225703 - Update in-tree libcubeb. r=padenot (103b1296c1)
- Bug 1236977 - Default initialize IMMDevice temporary to avoid potential garbage CloseHandle on error. r=padenot (fdb076c905)
- Bug 1221228 - Work around busted OpenSL causing hangs/reboots on Android r=padenot (a9f8c9e5dd)
- Bug 1104643 - Interpolate the audio clock by system clock if the qudio clock is not going forward. r=padenot (180c4ae7c7)
- Bug 1241476: Update libcubeb from upstream rs=kinetik (f68d4010e9)
- Bug 1242152 - fix sndio build after full-duplex API changes r=kinetik (cd30999c19)
- Bug 1243275: Update libcubeb to pick up device-change-notification changes and a pulse fix rs=kinetik (1c5bf75ac2)
- Bug 1189197 - enqueue a silent frame to kick off the buffer queue callbacks. r=kinetik. (98a312ec62)
- Bug 948267. Part 1 - add the interface DataSource to implement pull model and remove members no longer useful in the pull model. r=kinetik. (8ff0635fca)
- Bug 948267. Part 2 - implement AudioStream::DataSource for DecodedAudioDataSink and remove its audio thread. r=kinetik. (00365c71b8)
- Bug 948267. Part 3 - remove MDSM::AdjustAudioThresholds() to ensure we have enough data for AudioStream::DataCallback() to consume in the audio-only case. Also increase the amount of prerolling audio to 1s (which is the size of the circular buffer of AudioStream) to ensure a smooth start of playback. r=kinetik. (00f1bfbe02)
- Bug 1240417. Part 1 - add a writer class to encapsulate pointer arithmetic. r=kinetik. (a625befc30)
- Bug 1240417. Part 2 - remove unused code. r=kinetik. (086c6c461b)
- Bug 1240419 - improve logging macros and include |this| in the log message. r=kinetik. (a0242c4e78)
- Bug 1240420. Part 1 - move checks of mismatched sample rate or channel numbers to AudioStream. r=kinetik. (41435e9551)
- Bug 1240420. Part 2 - fix warnings of signed/unsigned comparison. r=kinetik. (558ce6a918)
- Bug 1230902 - initialize mSampleRate and mMicrophoneActive. r=cpearce (a99b661e8b)
- Bug 1203585 - Add comments about threading and locking on GraphDriver's members. r=jesup (5dcaa286c3)
- Bug 1203585 - Remove some dead code in GraphDriver.cpp. r=jesup (9618d10e70)
- Bug 1070216 - Assert main MediaEngine APIs are called on the owning thread. r=jib (6c950d62d0)
- Bug 1221587: allow getUserMedia to use full-duplex cubeb streams r=padenot (f67c2219aa)
- Bug 1221587: Rename MediaStreamGraphShutdownThreadRunnable2 r=padenot (d9fe2125e7)
- Bug 1203585 - Add new methods to GraphDriver to assert that locks are held. r=jesup (a8e2bfbcef)
- Bug 1221587: Base update of the MSG API for full-duplex r=padenot (4be37a6184)
- Bug 1221587: change audio listeners for full-duplex audio r=padenot (5d94102a32)
- Bug 1221587: use cubeb devids to select input devices r=padenot (2f0806756b)
- Bug 1221587: Update for API changes in cubeb r=padenot (87c581ce5f)
- Bug 1237414: Switch AsyncCubebOperation to a SharedThreadPool r=padenot (965831dac8)
- Bug 1203585 - Add a comment block on how MediaStreamGraph switch GraphDrivers. r=jesup (a4839dccb1)
- Bug 1240411: P7. Clean up webspeech header declarations. r=rillian (2e91bebdb5)
- Bug 1207220: Ensure MediaShutdownManager waits until all MediaDecoder have completed their shutdown. r=cpearce (1782ffb35a)
- Bug 1240411: P8. Clean up MediaSource headers. r=cpearce Remove redundant virtual keyword and add missing override if any. (0f99efac9e)
- Bug 1240411: P9. Clean up media headers. r=jwwang (cc1165a3f2)
- Bug 1203585 - Update the MediaStreamGraph code to lock properly. r=jesup (d523db643a)
- Bug 1221587: Implement switching of AudioCallbackDrivers for full-duplex r=padenot (2349ec7734)
- Bug 1221587: stall MSG final shutdown until AudioCallbackDriver shutdown has finished r=pehrsons (ad2dfb76dd)
- Bug 1203585 - Add threading assertions to GraphDriver switching methods. r=jesup (8c1c2b4d9d)
- Bug 1221587: Improve logging of callback driver/switching r=padenot (87253e8f9c)
- Bug 1237794: Extend ClearOnShutdown() to allow specifying the shutdown phase r=froyd (cfe5e30311)
- Bug 1221587: add per-platform prefs to control full-duplex cubeb input r=jib (0b004cfd10)
- Bug 1229240 - test that applyConstraints() rejects on non-Gum track. r=jesup (c65f7ecc4a)
- Bug 987186 - remove AudioConfig, send agc/aec/noise from prefs r=jib,smaug (812108e255)
- Bug 1245216: plumb preferred sample rate from full_duplex cubeb through NotifyInput/Output r=padenot (9c123866cc)
- Bug 1245216: Fix getUserMedia input in full_duplex mode coming from the wrong place r=padenot (8d10177675)
- Bug 1227407 - Ensure Cameras is alive before calling through it. r=jesup (e94d7803ee)
- Bug 1239384 - Remove static interface for Cameras using forwarding. r=jesup (e5329280c5)
- Bug 1239384 - Encapsulate Cameras dispatch, locking and success handling in a class. r=jesup (a0c2391c44)
- Bug 1177242 - Verify whether sandboxed Content process has permissions to access the camera/mic. r=jesup (611c4cb04e)
- Bug 1247236. r=jesup (fc0286ccb3)
- Bug 1239873 - Use AsyncShutdown API to shut down MediaStreamGraph thread. r=jesup (9e45760ab9)
- Bug 1247395 - use UniquePtr for control messages in MediaStreamGraphImpl; r=roc (949149234e)
- Bug 1221587: Block attempts to open two mics at once until supported in full-duplex r=jib (4bb1412bb1)
- Bug 1242061: re-enumerate audio devices in full_duplex via cubeb when getUserMedia is called r=jib (aa98e4dfff)
- Bug 1242061 follow up to fix static analysis build bustage. r=me (3ee4f733f1)
- Bug 1242061: fix leaked static nsTArrays r=bustage on a CLOSED TREE (6f57c3e0fd)
- Bug 1237816: count open input sources for MediaStreams to release inputs on Destroy() r=roc,padenot (e9fd08c6bd)
- Bug 1245216: white-list the fake 440Hz audio source used in automation for getUserMedia enumeration r=padenot (5c1632f0bd)
- Bug 1242061: remove small strdup() leak of devicename strings in getUserMedia enumeration rs=jib (112163f77c)
- Bug 1245216: Avoid reallocating and leaking AudioPacketizer output buffer r=padenot (86c0a5c277)
- Bug 1165963 - Fix regression by bug 1104643: Detect "over compensation" and reset the anchor. r=padenot (9393a44d1b)
- Bug 1145195 part 1 - Create a helper function for PrependLocalTransformsTo in SVGContentUtils r=dholbert (91bcee16ad)
- Bug 1138065 - view elements as fragment identifiers should have normal target matching. r=dholbert (17b6b7af57)
- Bug 1145195 part 2 - SVGFragmentIdentifier::ProcessSVGViewSpec() shouldn't actually let #svgView() affect attribute values r=dholbert (e7663e08c2)
2023-10-28 00:10:42 +08:00

250 lines
8.0 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#include "gfx2DGlue.h"
#include "mozilla/dom/SVGAnimatedTransformList.h"
#include "mozilla/dom/SVGGraphicsElementBinding.h"
#include "mozilla/dom/SVGTransformableElement.h"
#include "mozilla/dom/SVGMatrix.h"
#include "mozilla/dom/SVGSVGElement.h"
#include "nsContentUtils.h"
#include "nsIDOMMutationEvent.h"
#include "nsIFrame.h"
#include "nsISVGChildFrame.h"
#include "mozilla/dom/SVGRect.h"
#include "nsSVGUtils.h"
#include "SVGContentUtils.h"
using namespace mozilla::gfx;
namespace mozilla {
namespace dom {
already_AddRefed<SVGAnimatedTransformList>
SVGTransformableElement::Transform()
{
// We're creating a DOM wrapper, so we must tell GetAnimatedTransformList
// to allocate the SVGAnimatedTransformList if it hasn't already done so:
return SVGAnimatedTransformList::GetDOMWrapper(
GetAnimatedTransformList(DO_ALLOCATE), this);
}
//----------------------------------------------------------------------
// nsIContent methods
NS_IMETHODIMP_(bool)
SVGTransformableElement::IsAttributeMapped(const nsIAtom* name) const
{
static const MappedAttributeEntry* const map[] = {
sColorMap,
sFillStrokeMap,
sGraphicsMap
};
return FindAttributeDependence(name, map) ||
nsSVGElement::IsAttributeMapped(name);
}
nsChangeHint
SVGTransformableElement::GetAttributeChangeHint(const nsIAtom* aAttribute,
int32_t aModType) const
{
nsChangeHint retval =
nsSVGElement::GetAttributeChangeHint(aAttribute, aModType);
if (aAttribute == nsGkAtoms::transform ||
aAttribute == nsGkAtoms::mozAnimateMotionDummyAttr) {
nsIFrame* frame =
const_cast<SVGTransformableElement*>(this)->GetPrimaryFrame();
NS_UpdateHint(retval, nsChangeHint_InvalidateRenderingObservers);
if (!frame || (frame->GetStateBits() & NS_FRAME_IS_NONDISPLAY)) {
return retval;
}
if (aModType == nsIDOMMutationEvent::ADDITION ||
aModType == nsIDOMMutationEvent::REMOVAL ||
(aModType == nsIDOMMutationEvent::MODIFICATION &&
!(mTransforms && mTransforms->HasTransform()))) {
// Reconstruct the frame tree to handle stacking context changes:
NS_UpdateHint(retval, nsChangeHint_ReconstructFrame);
} else {
MOZ_ASSERT(aModType == nsIDOMMutationEvent::MODIFICATION,
"Unknown modification type.");
// We just assume the old and new transforms are different.
NS_UpdateHint(retval, NS_CombineHint(nsChangeHint_UpdatePostTransformOverflow,
nsChangeHint_UpdateTransformLayer));
}
}
return retval;
}
bool
SVGTransformableElement::IsEventAttributeName(nsIAtom* aName)
{
return nsContentUtils::IsEventAttributeName(aName, EventNameType_SVGGraphic);
}
//----------------------------------------------------------------------
// nsSVGElement overrides
gfxMatrix
SVGTransformableElement::PrependLocalTransformsTo(
const gfxMatrix &aMatrix,
SVGTransformTypes aWhich) const
{
return SVGContentUtils::PrependLocalTransformsTo(
aMatrix, aWhich, mAnimateMotionTransform, mTransforms);
}
const gfx::Matrix*
SVGTransformableElement::GetAnimateMotionTransform() const
{
return mAnimateMotionTransform.get();
}
void
SVGTransformableElement::SetAnimateMotionTransform(const gfx::Matrix* aMatrix)
{
if ((!aMatrix && !mAnimateMotionTransform) ||
(aMatrix && mAnimateMotionTransform && *aMatrix == *mAnimateMotionTransform)) {
return;
}
bool transformSet = mTransforms && mTransforms->IsExplicitlySet();
bool prevSet = mAnimateMotionTransform || transformSet;
mAnimateMotionTransform = aMatrix ? new gfx::Matrix(*aMatrix) : nullptr;
bool nowSet = mAnimateMotionTransform || transformSet;
int32_t modType;
if (prevSet && !nowSet) {
modType = nsIDOMMutationEvent::REMOVAL;
} else if(!prevSet && nowSet) {
modType = nsIDOMMutationEvent::ADDITION;
} else {
modType = nsIDOMMutationEvent::MODIFICATION;
}
DidAnimateTransformList(modType);
nsIFrame* frame = GetPrimaryFrame();
if (frame) {
// If the result of this transform and any other transforms on this frame
// is the identity matrix, then DoApplyRenderingChangeToTree won't handle
// our nsChangeHint_UpdateTransformLayer hint since aFrame->IsTransformed()
// will return false. That's fine, but we still need to schedule a repaint,
// and that won't otherwise happen. Since it's cheap to call SchedulePaint,
// we don't bother to check IsTransformed().
frame->SchedulePaint();
}
}
nsSVGAnimatedTransformList*
SVGTransformableElement::GetAnimatedTransformList(uint32_t aFlags)
{
if (!mTransforms && (aFlags & DO_ALLOCATE)) {
mTransforms = new nsSVGAnimatedTransformList();
}
return mTransforms;
}
nsSVGElement*
SVGTransformableElement::GetNearestViewportElement()
{
return SVGContentUtils::GetNearestViewportElement(this);
}
nsSVGElement*
SVGTransformableElement::GetFarthestViewportElement()
{
return SVGContentUtils::GetOuterSVGElement(this);
}
already_AddRefed<SVGIRect>
SVGTransformableElement::GetBBox(const SVGBoundingBoxOptions& aOptions,
ErrorResult& rv)
{
nsIFrame* frame = GetPrimaryFrame(Flush_Layout);
if (!frame || (frame->GetStateBits() & NS_FRAME_IS_NONDISPLAY)) {
rv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsISVGChildFrame* svgframe = do_QueryFrame(frame);
if (!svgframe) {
rv.Throw(NS_ERROR_NOT_IMPLEMENTED); // XXX: outer svg
return nullptr;
}
if (!NS_SVGNewGetBBoxEnabled()) {
return NS_NewSVGRect(this, ToRect(nsSVGUtils::GetBBox(frame)));
} else {
uint32_t aFlags = 0;
if (aOptions.mFill) {
aFlags |= nsSVGUtils::eBBoxIncludeFill;
}
if (aOptions.mStroke) {
aFlags |= nsSVGUtils::eBBoxIncludeStroke;
}
if (aOptions.mMarkers) {
aFlags |= nsSVGUtils::eBBoxIncludeMarkers;
}
if (aOptions.mClipped) {
aFlags |= nsSVGUtils::eBBoxIncludeClipped;
}
if (aFlags == 0) {
return NS_NewSVGRect(this,0,0,0,0);
}
if (aFlags == nsSVGUtils::eBBoxIncludeMarkers ||
aFlags == nsSVGUtils::eBBoxIncludeClipped) {
aFlags |= nsSVGUtils::eBBoxIncludeFill;
}
return NS_NewSVGRect(this, ToRect(nsSVGUtils::GetBBox(frame, aFlags)));
}
}
already_AddRefed<SVGMatrix>
SVGTransformableElement::GetCTM()
{
nsIDocument* currentDoc = GetComposedDoc();
if (currentDoc) {
// Flush all pending notifications so that our frames are up to date
currentDoc->FlushPendingNotifications(Flush_Layout);
}
gfx::Matrix m = SVGContentUtils::GetCTM(this, false);
RefPtr<SVGMatrix> mat = m.IsSingular() ? nullptr : new SVGMatrix(ThebesMatrix(m));
return mat.forget();
}
already_AddRefed<SVGMatrix>
SVGTransformableElement::GetScreenCTM()
{
nsIDocument* currentDoc = GetComposedDoc();
if (currentDoc) {
// Flush all pending notifications so that our frames are up to date
currentDoc->FlushPendingNotifications(Flush_Layout);
}
gfx::Matrix m = SVGContentUtils::GetCTM(this, true);
RefPtr<SVGMatrix> mat = m.IsSingular() ? nullptr : new SVGMatrix(ThebesMatrix(m));
return mat.forget();
}
already_AddRefed<SVGMatrix>
SVGTransformableElement::GetTransformToElement(SVGGraphicsElement& aElement,
ErrorResult& rv)
{
// the easiest way to do this (if likely to increase rounding error):
RefPtr<SVGMatrix> ourScreenCTM = GetScreenCTM();
RefPtr<SVGMatrix> targetScreenCTM = aElement.GetScreenCTM();
if (!ourScreenCTM || !targetScreenCTM) {
rv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return nullptr;
}
RefPtr<SVGMatrix> tmp = targetScreenCTM->Inverse(rv);
if (rv.Failed()) return nullptr;
RefPtr<SVGMatrix> mat = tmp->Multiply(*ourScreenCTM);
return mat.forget();
}
} // namespace dom
} // namespace mozilla