2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is the Mozilla SVG project.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Crocodile Clips Ltd..
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2001
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Alex Fritze <alex.fritze@crocodile-clips.com> (original author)
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsSVGOuterSVGFrame.h"
|
|
|
|
#include "nsIDOMSVGSVGElement.h"
|
|
|
|
#include "nsSVGSVGElement.h"
|
|
|
|
#include "nsSVGTextFrame.h"
|
2007-11-20 01:10:18 -08:00
|
|
|
#include "nsSVGForeignObjectFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsDisplayList.h"
|
|
|
|
#include "nsStubMutationObserver.h"
|
|
|
|
#include "gfxContext.h"
|
2010-12-06 12:57:18 -08:00
|
|
|
#include "gfxMatrix.h"
|
|
|
|
#include "gfxRect.h"
|
2007-11-18 04:09:03 -08:00
|
|
|
#include "nsIContentViewer.h"
|
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
2011-07-15 03:31:34 -07:00
|
|
|
#include "nsIDOMWindow.h"
|
2007-11-18 04:09:03 -08:00
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsIObjectLoadingContent.h"
|
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2007-12-20 01:13:38 -08:00
|
|
|
#include "nsSVGMatrix.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-24 00:05:56 -07:00
|
|
|
namespace dom = mozilla::dom;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsSVGMutationObserver : public nsStubMutationObserver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// nsIMutationObserver interface
|
2007-04-27 07:37:15 -07:00
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-04-27 07:37:15 -07:00
|
|
|
// nsISupports interface:
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
|
|
|
|
private:
|
|
|
|
NS_IMETHOD_(nsrefcnt) AddRef() { return 1; }
|
|
|
|
NS_IMETHOD_(nsrefcnt) Release() { return 1; }
|
|
|
|
|
|
|
|
static void UpdateTextFragmentTrees(nsIFrame *aFrame);
|
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISupports methods
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsSVGMutationObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIMutationObserver)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
static nsSVGMutationObserver sSVGMutationObserver;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIMutationObserver methods
|
|
|
|
|
|
|
|
void
|
2010-08-24 00:05:56 -07:00
|
|
|
nsSVGMutationObserver::AttributeChanged(nsIDocument* aDocument,
|
|
|
|
dom::Element* aElement,
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt32 aNameSpaceID,
|
2010-08-24 00:05:56 -07:00
|
|
|
nsIAtom* aAttribute,
|
2009-12-10 14:36:04 -08:00
|
|
|
PRInt32 aModType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aNameSpaceID != kNameSpaceID_XML || aAttribute != nsGkAtoms::space) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-24 00:05:56 -07:00
|
|
|
nsIFrame* frame = aElement->GetPrimaryFrame();
|
2010-01-07 02:36:11 -08:00
|
|
|
if (!frame) {
|
|
|
|
return;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-01-07 02:36:11 -08:00
|
|
|
// is the content a child of a text element
|
|
|
|
nsSVGTextContainerFrame* containerFrame = do_QueryFrame(frame);
|
|
|
|
if (containerFrame) {
|
|
|
|
containerFrame->NotifyGlyphMetricsChange();
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-01-07 02:36:11 -08:00
|
|
|
// if not, are there text elements amongst its descendents
|
|
|
|
UpdateTextFragmentTrees(frame);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation helpers
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSVGMutationObserver::UpdateTextFragmentTrees(nsIFrame *aFrame)
|
|
|
|
{
|
2011-08-24 13:54:30 -07:00
|
|
|
nsIFrame* kid = aFrame->GetFirstPrincipalChild();
|
2007-03-22 10:30:00 -07:00
|
|
|
while (kid) {
|
|
|
|
if (kid->GetType() == nsGkAtoms::svgTextFrame) {
|
2007-07-08 00:08:04 -07:00
|
|
|
nsSVGTextFrame* textFrame = static_cast<nsSVGTextFrame*>(kid);
|
2007-03-22 10:30:00 -07:00
|
|
|
textFrame->NotifyGlyphMetricsChange();
|
|
|
|
} else {
|
|
|
|
UpdateTextFragmentTrees(kid);
|
|
|
|
}
|
|
|
|
kid = kid->GetNextSibling();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
|
|
|
nsIFrame*
|
2009-01-19 10:31:34 -08:00
|
|
|
NS_NewSVGOuterSVGFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return new (aPresShell) nsSVGOuterSVGFrame(aContext);
|
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSVGOuterSVGFrame)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSVGOuterSVGFrame::nsSVGOuterSVGFrame(nsStyleContext* aContext)
|
2008-01-09 14:53:59 -08:00
|
|
|
: nsSVGOuterSVGFrameBase(aContext)
|
|
|
|
, mRedrawSuspendCount(0)
|
|
|
|
, mFullZoom(0)
|
|
|
|
, mViewportInitialized(PR_FALSE)
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
, mEnableBitmapFallback(PR_FALSE)
|
|
|
|
#endif
|
2009-04-28 06:25:03 -07:00
|
|
|
, mIsRootContent(PR_FALSE)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2007-08-30 10:01:37 -07:00
|
|
|
nsSVGOuterSVGFrame::Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-01-19 10:31:34 -08:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsCOMPtr<nsIDOMSVGSVGElement> svgElement = do_QueryInterface(aContent);
|
|
|
|
NS_ASSERTION(svgElement, "Content is not an SVG 'svg' element!");
|
|
|
|
#endif
|
|
|
|
|
2008-06-22 08:59:48 -07:00
|
|
|
AddStateBits(NS_STATE_IS_OUTER_SVG);
|
|
|
|
|
2010-12-06 12:57:18 -08:00
|
|
|
// Check for conditional processing attributes here rather than in
|
|
|
|
// nsCSSFrameConstructor::FindSVGData because we want to avoid
|
|
|
|
// simply giving failing outer <svg> elements an nsSVGContainerFrame.
|
|
|
|
if (!nsSVGFeatures::PassesConditionalProcessingTests(aContent)) {
|
|
|
|
AddStateBits(NS_STATE_SVG_NONDISPLAY_CHILD);
|
|
|
|
}
|
|
|
|
|
2007-08-30 10:01:37 -07:00
|
|
|
nsresult rv = nsSVGOuterSVGFrameBase::Init(aContent, aParent, aPrevInFlow);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIDocument* doc = mContent->GetCurrentDoc();
|
|
|
|
if (doc) {
|
|
|
|
// we only care about our content's zoom and pan values if it's the root element
|
2010-04-30 06:12:05 -07:00
|
|
|
if (doc->GetRootElement() == mContent) {
|
2009-04-28 06:25:03 -07:00
|
|
|
mIsRootContent = PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
// sSVGMutationObserver has the same lifetime as the document so does
|
|
|
|
// not need to be removed
|
2010-05-05 11:18:03 -07:00
|
|
|
doc->AddMutationObserverUnlessExists(&sSVGMutationObserver);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-06-14 13:51:42 -07:00
|
|
|
SuspendRedraw(); // UnsuspendRedraw is in DidReflow
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-08-30 10:01:37 -07:00
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2009-01-12 11:20:59 -08:00
|
|
|
// nsQueryFrame methods
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-01-12 11:20:59 -08:00
|
|
|
NS_QUERYFRAME_HEAD(nsSVGOuterSVGFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsISVGSVGFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsSVGOuterSVGFrameBase)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIFrame methods
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// reflowing
|
|
|
|
|
2007-11-18 04:09:03 -08:00
|
|
|
/* virtual */ nscoord
|
2011-04-07 18:04:40 -07:00
|
|
|
nsSVGOuterSVGFrame::GetMinWidth(nsRenderingContext *aRenderingContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-11-18 04:09:03 -08:00
|
|
|
nscoord result;
|
|
|
|
DISPLAY_MIN_WIDTH(this, result);
|
|
|
|
|
|
|
|
result = nscoord(0);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
2011-04-07 18:04:40 -07:00
|
|
|
nsSVGOuterSVGFrame::GetPrefWidth(nsRenderingContext *aRenderingContext)
|
2007-11-18 04:09:03 -08:00
|
|
|
{
|
|
|
|
nscoord result;
|
|
|
|
DISPLAY_PREF_WIDTH(this, result);
|
|
|
|
|
|
|
|
nsSVGSVGElement *svg = static_cast<nsSVGSVGElement*>(mContent);
|
|
|
|
nsSVGLength2 &width = svg->mLengthAttributes[nsSVGSVGElement::WIDTH];
|
|
|
|
|
2008-01-25 01:27:03 -08:00
|
|
|
if (width.IsPercentage()) {
|
2008-02-08 13:50:24 -08:00
|
|
|
// It looks like our containing block's width may depend on our width. In
|
|
|
|
// that case our behavior is undefined according to CSS 2.1 section 10.3.2,
|
|
|
|
// so return zero.
|
|
|
|
result = nscoord(0);
|
2007-11-18 04:09:03 -08:00
|
|
|
} else {
|
|
|
|
result = nsPresContext::CSSPixelsToAppUnits(width.GetAnimValue(svg));
|
2008-01-25 00:54:59 -08:00
|
|
|
if (result < 0) {
|
|
|
|
result = nscoord(0);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-11-18 04:09:03 -08:00
|
|
|
return result;
|
|
|
|
}
|
2007-06-14 13:51:42 -07:00
|
|
|
|
2007-11-18 04:09:03 -08:00
|
|
|
/* virtual */ nsIFrame::IntrinsicSize
|
|
|
|
nsSVGOuterSVGFrame::GetIntrinsicSize()
|
|
|
|
{
|
|
|
|
// XXXjwatt Note that here we want to return the CSS width/height if they're
|
|
|
|
// specified and we're embedded inside an nsIObjectLoadingContent.
|
|
|
|
|
|
|
|
IntrinsicSize intrinsicSize;
|
|
|
|
|
|
|
|
nsSVGSVGElement *content = static_cast<nsSVGSVGElement*>(mContent);
|
|
|
|
nsSVGLength2 &width = content->mLengthAttributes[nsSVGSVGElement::WIDTH];
|
|
|
|
nsSVGLength2 &height = content->mLengthAttributes[nsSVGSVGElement::HEIGHT];
|
|
|
|
|
2011-06-12 18:52:32 -07:00
|
|
|
if (!width.IsPercentage()) {
|
2007-11-18 04:09:03 -08:00
|
|
|
nscoord val = nsPresContext::CSSPixelsToAppUnits(width.GetAnimValue(content));
|
|
|
|
if (val < 0) val = 0;
|
|
|
|
intrinsicSize.width.SetCoordValue(val);
|
|
|
|
}
|
2007-06-14 13:51:42 -07:00
|
|
|
|
2011-06-12 18:52:32 -07:00
|
|
|
if (!height.IsPercentage()) {
|
2007-11-18 04:09:03 -08:00
|
|
|
nscoord val = nsPresContext::CSSPixelsToAppUnits(height.GetAnimValue(content));
|
|
|
|
if (val < 0) val = 0;
|
|
|
|
intrinsicSize.height.SetCoordValue(val);
|
|
|
|
}
|
2007-06-14 13:51:42 -07:00
|
|
|
|
2007-11-18 04:09:03 -08:00
|
|
|
return intrinsicSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nsSize
|
|
|
|
nsSVGOuterSVGFrame::GetIntrinsicRatio()
|
|
|
|
{
|
|
|
|
// We only have an intrinsic size/ratio if our width and height attributes
|
|
|
|
// are both specified and set to non-percentage values, or we have a viewBox
|
|
|
|
// rect: http://www.w3.org/TR/SVGMobile12/coords.html#IntrinsicSizing
|
|
|
|
|
|
|
|
nsSVGSVGElement *content = static_cast<nsSVGSVGElement*>(mContent);
|
|
|
|
nsSVGLength2 &width = content->mLengthAttributes[nsSVGSVGElement::WIDTH];
|
|
|
|
nsSVGLength2 &height = content->mLengthAttributes[nsSVGSVGElement::HEIGHT];
|
|
|
|
|
2008-01-25 01:27:03 -08:00
|
|
|
if (!width.IsPercentage() && !height.IsPercentage()) {
|
2011-06-13 14:48:50 -07:00
|
|
|
nsSize ratio(NSToCoordRoundWithClamp(width.GetAnimValue(content)),
|
|
|
|
NSToCoordRoundWithClamp(height.GetAnimValue(content)));
|
2008-01-25 00:54:59 -08:00
|
|
|
if (ratio.width < 0) {
|
|
|
|
ratio.width = 0;
|
|
|
|
}
|
|
|
|
if (ratio.height < 0) {
|
|
|
|
ratio.height = 0;
|
|
|
|
}
|
|
|
|
return ratio;
|
2007-11-18 04:09:03 -08:00
|
|
|
}
|
|
|
|
|
2010-02-18 13:51:00 -08:00
|
|
|
if (content->mViewBox.IsValid()) {
|
2010-02-25 10:20:43 -08:00
|
|
|
const nsSVGViewBoxRect viewbox = content->mViewBox.GetAnimValue();
|
2009-02-03 06:42:24 -08:00
|
|
|
float viewBoxWidth = viewbox.width;
|
|
|
|
float viewBoxHeight = viewbox.height;
|
|
|
|
|
2008-02-21 09:43:25 -08:00
|
|
|
if (viewBoxWidth < 0.0f) {
|
|
|
|
viewBoxWidth = 0.0f;
|
|
|
|
}
|
|
|
|
if (viewBoxHeight < 0.0f) {
|
|
|
|
viewBoxHeight = 0.0f;
|
|
|
|
}
|
2011-06-13 14:48:50 -07:00
|
|
|
return nsSize(NSToCoordRoundWithClamp(viewBoxWidth),
|
|
|
|
NSToCoordRoundWithClamp(viewBoxHeight));
|
2007-11-18 04:09:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsSVGOuterSVGFrameBase::GetIntrinsicRatio();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nsSize
|
2011-04-07 18:04:40 -07:00
|
|
|
nsSVGOuterSVGFrame::ComputeSize(nsRenderingContext *aRenderingContext,
|
2007-11-18 04:09:03 -08:00
|
|
|
nsSize aCBSize, nscoord aAvailableWidth,
|
|
|
|
nsSize aMargin, nsSize aBorder, nsSize aPadding,
|
|
|
|
PRBool aShrinkWrap)
|
|
|
|
{
|
2011-02-09 12:13:18 -08:00
|
|
|
nsSVGSVGElement* content = static_cast<nsSVGSVGElement*>(mContent);
|
|
|
|
|
2011-06-12 18:52:32 -07:00
|
|
|
IntrinsicSize intrinsicSize = GetIntrinsicSize();
|
|
|
|
|
|
|
|
if (!mContent->GetParent()) {
|
|
|
|
if (IsRootOfImage() || IsRootOfReplacedElementSubDoc()) {
|
|
|
|
// The embedding element has done the replaced element sizing,
|
|
|
|
// using our intrinsic dimensions as necessary. We just need to
|
|
|
|
// fill the viewport.
|
|
|
|
return aCBSize;
|
|
|
|
} else {
|
|
|
|
// We're the root of a browsing context, so we need to honor
|
|
|
|
// widths and heights in percentages. (GetIntrinsicSize() doesn't
|
|
|
|
// report these since there's no such thing as a percentage
|
|
|
|
// intrinsic size.)
|
|
|
|
nsSVGLength2 &width =
|
|
|
|
content->mLengthAttributes[nsSVGSVGElement::WIDTH];
|
|
|
|
if (width.IsPercentage()) {
|
|
|
|
NS_ABORT_IF_FALSE(intrinsicSize.width.GetUnit() == eStyleUnit_None,
|
|
|
|
"GetIntrinsicSize should have reported no "
|
|
|
|
"intrinsic width");
|
|
|
|
float val = width.GetAnimValInSpecifiedUnits() / 100.0f;
|
|
|
|
if (val < 0.0f) val = 0.0f;
|
|
|
|
intrinsicSize.width.SetCoordValue(val * aCBSize.width);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGLength2 &height =
|
|
|
|
content->mLengthAttributes[nsSVGSVGElement::HEIGHT];
|
|
|
|
NS_ABORT_IF_FALSE(aCBSize.height != NS_AUTOHEIGHT,
|
|
|
|
"root should not have auto-height containing block");
|
|
|
|
if (height.IsPercentage()) {
|
|
|
|
NS_ABORT_IF_FALSE(intrinsicSize.height.GetUnit() == eStyleUnit_None,
|
|
|
|
"GetIntrinsicSize should have reported no "
|
|
|
|
"intrinsic height");
|
|
|
|
float val = height.GetAnimValInSpecifiedUnits() / 100.0f;
|
|
|
|
if (val < 0.0f) val = 0.0f;
|
|
|
|
intrinsicSize.height.SetCoordValue(val * aCBSize.height);
|
|
|
|
}
|
|
|
|
NS_ABORT_IF_FALSE(intrinsicSize.height.GetUnit() == eStyleUnit_Coord &&
|
|
|
|
intrinsicSize.width.GetUnit() == eStyleUnit_Coord,
|
|
|
|
"We should have just handled the only situation where"
|
|
|
|
"we lack an intrinsic height or width.");
|
|
|
|
}
|
2007-11-18 04:09:03 -08:00
|
|
|
}
|
2007-06-14 13:51:42 -07:00
|
|
|
|
2007-11-18 04:09:03 -08:00
|
|
|
return nsLayoutUtils::ComputeSizeWithIntrinsicDimensions(
|
|
|
|
aRenderingContext, this,
|
2011-06-12 18:52:32 -07:00
|
|
|
intrinsicSize, GetIntrinsicRatio(), aCBSize,
|
2007-11-18 04:09:03 -08:00
|
|
|
aMargin, aBorder, aPadding);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-11-18 04:09:03 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGOuterSVGFrame::Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsSVGOuterSVGFrame");
|
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
|
|
|
NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS,
|
|
|
|
("enter nsSVGOuterSVGFrame::Reflow: availSize=%d,%d",
|
|
|
|
aReflowState.availableWidth, aReflowState.availableHeight));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-11-18 04:09:03 -08:00
|
|
|
NS_PRECONDITION(mState & NS_FRAME_IN_REFLOW, "frame is not in reflow");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-11-18 04:09:03 -08:00
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-11-18 04:09:03 -08:00
|
|
|
aDesiredSize.width = aReflowState.ComputedWidth() +
|
|
|
|
aReflowState.mComputedBorderPadding.LeftRight();
|
|
|
|
aDesiredSize.height = aReflowState.ComputedHeight() +
|
|
|
|
aReflowState.mComputedBorderPadding.TopBottom();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-11-18 04:09:03 -08:00
|
|
|
NS_ASSERTION(!GetPrevInFlow(), "SVG can't currently be broken across pages.");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-08-30 14:20:41 -07:00
|
|
|
// Make sure we scroll if we're too big:
|
|
|
|
// XXX Use the bounding box of our descendants? (See bug 353460 comment 14.)
|
2010-10-06 21:25:46 -07:00
|
|
|
aDesiredSize.SetOverflowAreasToDesiredBounds();
|
2007-08-30 14:20:41 -07:00
|
|
|
FinishAndStoreOverflow(&aDesiredSize);
|
|
|
|
|
2007-11-18 04:09:03 -08:00
|
|
|
// If our SVG viewport has changed, update our content and notify.
|
|
|
|
// http://www.w3.org/TR/SVG11/coords.html#ViewportSpace
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-11-18 04:09:03 -08:00
|
|
|
svgFloatSize newViewportSize(
|
|
|
|
nsPresContext::AppUnitsToFloatCSSPixels(aReflowState.ComputedWidth()),
|
|
|
|
nsPresContext::AppUnitsToFloatCSSPixels(aReflowState.ComputedHeight()));
|
|
|
|
|
|
|
|
nsSVGSVGElement *svgElem = static_cast<nsSVGSVGElement*>(mContent);
|
|
|
|
|
2007-12-03 20:40:52 -08:00
|
|
|
if (newViewportSize != svgElem->GetViewportSize() ||
|
|
|
|
mFullZoom != PresContext()->GetFullZoom()) {
|
2007-11-18 04:09:03 -08:00
|
|
|
svgElem->SetViewportSize(newViewportSize);
|
2007-12-20 06:26:34 -08:00
|
|
|
mViewportInitialized = PR_TRUE;
|
2007-12-03 20:40:52 -08:00
|
|
|
mFullZoom = PresContext()->GetFullZoom();
|
2007-06-14 13:51:42 -07:00
|
|
|
NotifyViewportChange();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-11-18 04:09:03 -08:00
|
|
|
NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS,
|
|
|
|
("exit nsSVGOuterSVGFrame::Reflow: size=%d,%d",
|
|
|
|
aDesiredSize.width, aDesiredSize.height));
|
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
static PLDHashOperator
|
2007-11-20 01:10:18 -08:00
|
|
|
ReflowForeignObject(nsVoidPtrHashKey *aEntry, void* aUserArg)
|
|
|
|
{
|
|
|
|
static_cast<nsSVGForeignObjectFrame*>
|
|
|
|
(const_cast<void*>(aEntry->GetKey()))->MaybeReflowFromOuterSVGFrame();
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGOuterSVGFrame::DidReflow(nsPresContext* aPresContext,
|
|
|
|
const nsHTMLReflowState* aReflowState,
|
|
|
|
nsDidReflowStatus aStatus)
|
|
|
|
{
|
2007-12-20 06:26:34 -08:00
|
|
|
PRBool firstReflow = (GetStateBits() & NS_FRAME_FIRST_REFLOW) != 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-12-20 06:26:34 -08:00
|
|
|
nsresult rv = nsSVGOuterSVGFrameBase::DidReflow(aPresContext,aReflowState,aStatus);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-12-20 06:26:34 -08:00
|
|
|
if (firstReflow) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// call InitialUpdate() on all frames:
|
|
|
|
nsIFrame* kid = mFrames.FirstChild();
|
|
|
|
while (kid) {
|
2009-01-12 11:20:59 -08:00
|
|
|
nsISVGChildFrame* SVGFrame = do_QueryFrame(kid);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (SVGFrame) {
|
|
|
|
SVGFrame->InitialUpdate();
|
|
|
|
}
|
|
|
|
kid = kid->GetNextSibling();
|
|
|
|
}
|
|
|
|
|
2007-06-14 13:51:42 -07:00
|
|
|
UnsuspendRedraw(); // For the SuspendRedraw in InitSVG
|
2007-11-20 01:10:18 -08:00
|
|
|
} else {
|
|
|
|
// Now that all viewport establishing descendants have their correct size,
|
|
|
|
// tell our foreignObject descendants to reflow their children.
|
|
|
|
if (mForeignObjectHash.IsInitialized()) {
|
2008-09-20 06:42:03 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
PRUint32 count =
|
|
|
|
#endif
|
|
|
|
mForeignObjectHash.EnumerateEntries(ReflowForeignObject, nsnull);
|
2007-11-20 01:10:18 -08:00
|
|
|
NS_ASSERTION(count == mForeignObjectHash.Count(),
|
|
|
|
"We didn't reflow all our nsSVGForeignObjectFrames!");
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// container methods
|
|
|
|
|
|
|
|
class nsDisplaySVG : public nsDisplayItem {
|
|
|
|
public:
|
2010-08-13 03:01:13 -07:00
|
|
|
nsDisplaySVG(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsSVGOuterSVGFrame* aFrame) :
|
|
|
|
nsDisplayItem(aBuilder, aFrame) {
|
2007-03-22 10:30:00 -07:00
|
|
|
MOZ_COUNT_CTOR(nsDisplaySVG);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplaySVG() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplaySVG);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-04-07 17:31:26 -07:00
|
|
|
virtual void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
|
|
|
|
HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames);
|
2009-09-06 17:35:14 -07:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aCtx);
|
2010-07-15 14:07:49 -07:00
|
|
|
NS_DISPLAY_DECL_NAME("SVGEventReceiver", TYPE_SVG_EVENT_RECEIVER)
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2010-04-07 17:31:26 -07:00
|
|
|
void
|
|
|
|
nsDisplaySVG::HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
|
|
|
|
HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-05-12 14:41:47 -07:00
|
|
|
nsSVGOuterSVGFrame *outerSVGFrame = static_cast<nsSVGOuterSVGFrame*>(mFrame);
|
2010-08-13 03:01:58 -07:00
|
|
|
nsRect rectAtOrigin = aRect - ToReferenceFrame();
|
2010-05-12 14:41:47 -07:00
|
|
|
nsRect thisRect(nsPoint(0,0), outerSVGFrame->GetSize());
|
2010-04-07 17:31:26 -07:00
|
|
|
if (!thisRect.Intersects(rectAtOrigin))
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsPoint rectCenter(rectAtOrigin.x + rectAtOrigin.width / 2,
|
|
|
|
rectAtOrigin.y + rectAtOrigin.height / 2);
|
|
|
|
|
2010-05-12 14:41:47 -07:00
|
|
|
nsIFrame* frame = nsSVGUtils::HitTestChildren(
|
|
|
|
outerSVGFrame, rectCenter + outerSVGFrame->GetPosition() -
|
|
|
|
outerSVGFrame->GetContentRect().TopLeft());
|
2010-04-07 17:31:26 -07:00
|
|
|
if (frame) {
|
|
|
|
aOutFrames->AppendElement(frame);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-09-06 17:35:14 -07:00
|
|
|
nsDisplaySVG::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aCtx)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsSVGOuterSVGFrame*>(mFrame)->
|
2010-10-14 18:03:45 -07:00
|
|
|
Paint(aBuilder, *aCtx, mVisibleRect, ToReferenceFrame());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-11-18 04:09:03 -08:00
|
|
|
// helper
|
|
|
|
static inline PRBool
|
|
|
|
DependsOnIntrinsicSize(const nsIFrame* aEmbeddingFrame)
|
|
|
|
{
|
|
|
|
const nsStylePosition *pos = aEmbeddingFrame->GetStylePosition();
|
2010-08-11 12:32:53 -07:00
|
|
|
const nsStyleCoord &width = pos->mWidth;
|
|
|
|
const nsStyleCoord &height = pos->mHeight;
|
2007-11-18 04:09:03 -08:00
|
|
|
|
|
|
|
// XXX it would be nice to know if the size of aEmbeddingFrame's containing
|
|
|
|
// block depends on aEmbeddingFrame, then we'd know if we can return false
|
|
|
|
// for eStyleUnit_Percent too.
|
2010-08-25 03:17:55 -07:00
|
|
|
return !width.ConvertsToLength() ||
|
|
|
|
!height.ConvertsToLength();
|
2007-11-18 04:09:03 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2007-11-18 04:09:03 -08:00
|
|
|
nsSVGOuterSVGFrame::AttributeChanged(PRInt32 aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aModType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aNameSpaceID == kNameSpaceID_None &&
|
|
|
|
!(GetStateBits() & NS_FRAME_FIRST_REFLOW) &&
|
|
|
|
(aAttribute == nsGkAtoms::width || aAttribute == nsGkAtoms::height)) {
|
2007-11-18 04:09:03 -08:00
|
|
|
nsIFrame* embeddingFrame;
|
2011-02-09 12:13:18 -08:00
|
|
|
if (IsRootOfReplacedElementSubDoc(&embeddingFrame) && embeddingFrame) {
|
2007-11-18 04:09:03 -08:00
|
|
|
if (DependsOnIntrinsicSize(embeddingFrame)) {
|
|
|
|
// Tell embeddingFrame's presShell it needs to be reflowed (which takes
|
|
|
|
// care of reflowing us too).
|
|
|
|
embeddingFrame->PresContext()->PresShell()->
|
|
|
|
FrameNeedsReflow(embeddingFrame, nsIPresShell::eStyleChange, NS_FRAME_IS_DIRTY);
|
|
|
|
}
|
|
|
|
// else our width and height is overridden - don't reflow anything
|
|
|
|
} else {
|
|
|
|
// We are not embedded by reference, so our 'width' and 'height'
|
|
|
|
// attributes are not overridden - we need to reflow.
|
|
|
|
PresContext()->PresShell()->
|
|
|
|
FrameNeedsReflow(this, nsIPresShell::eStyleChange, NS_FRAME_IS_DIRTY);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// painting
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGOuterSVGFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
2007-11-18 04:09:03 -08:00
|
|
|
nsresult rv = DisplayBorderBackgroundOutline(aBuilder, aLists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-08-13 03:01:13 -07:00
|
|
|
return aLists.Content()->AppendNewToTop(
|
|
|
|
new (aBuilder) nsDisplaySVG(aBuilder, this));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-10-14 18:03:45 -07:00
|
|
|
nsSVGOuterSVGFrame::Paint(const nsDisplayListBuilder* aBuilder,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext& aRenderingContext,
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsRect& aDirtyRect, nsPoint aPt)
|
|
|
|
{
|
|
|
|
// initialize Mozilla rendering context
|
|
|
|
aRenderingContext.PushState();
|
2007-11-18 04:09:03 -08:00
|
|
|
|
|
|
|
nsRect viewportRect = GetContentRect();
|
2010-05-12 14:41:47 -07:00
|
|
|
nsPoint viewportOffset = aPt + viewportRect.TopLeft() - GetPosition();
|
2007-11-18 04:09:03 -08:00
|
|
|
viewportRect.MoveTo(viewportOffset);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsRect clipRect;
|
2007-11-18 04:09:03 -08:00
|
|
|
clipRect.IntersectRect(aDirtyRect, viewportRect);
|
2011-04-07 18:04:40 -07:00
|
|
|
aRenderingContext.IntersectClip(clipRect);
|
2011-04-07 18:04:39 -07:00
|
|
|
aRenderingContext.Translate(viewportRect.TopLeft());
|
2007-11-18 04:09:03 -08:00
|
|
|
nsRect dirtyRect = clipRect - viewportOffset;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#if defined(DEBUG) && defined(SVG_DEBUG_PAINT_TIMING)
|
|
|
|
PRTime start = PR_Now();
|
|
|
|
#endif
|
|
|
|
|
2009-05-07 19:31:04 -07:00
|
|
|
nsIntRect dirtyPxRect = dirtyRect.ToOutsidePixels(PresContext()->AppUnitsPerDevPixel());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsSVGRenderState ctx(&aRenderingContext);
|
|
|
|
|
2010-10-14 18:03:45 -07:00
|
|
|
if (aBuilder->IsPaintingToWindow()) {
|
|
|
|
ctx.SetPaintingToWindow(PR_TRUE);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef XP_MACOSX
|
2008-01-09 14:53:59 -08:00
|
|
|
if (mEnableBitmapFallback) {
|
|
|
|
// nquartz fallback paths, which svg tends to trigger, need
|
|
|
|
// a non-window context target
|
|
|
|
ctx.GetGfxContext()->PushGroup(gfxASurface::CONTENT_COLOR_ALPHA);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2009-01-14 19:27:09 -08:00
|
|
|
nsSVGUtils::PaintFrameWithEffects(&ctx, &dirtyPxRect, this);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
2008-01-09 14:53:59 -08:00
|
|
|
if (mEnableBitmapFallback) {
|
|
|
|
// show the surface we pushed earlier for fallbacks
|
|
|
|
ctx.GetGfxContext()->PopGroupToSource();
|
|
|
|
ctx.GetGfxContext()->Paint();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ctx.GetGfxContext()->HasError() && !mEnableBitmapFallback) {
|
|
|
|
mEnableBitmapFallback = PR_TRUE;
|
|
|
|
// It's not really clear what area to invalidate here. We might have
|
|
|
|
// stuffed up rendering for the entire window in this paint pass,
|
|
|
|
// so we can't just invalidate our own rect. Invalidate everything
|
|
|
|
// in sight.
|
|
|
|
// This won't work for printing, by the way, but failure to print the
|
|
|
|
// odd document is probably no worse than printing horribly for all
|
|
|
|
// documents. Better to fix things so we don't need fallback.
|
|
|
|
nsIFrame* frame = this;
|
2008-09-18 02:47:21 -07:00
|
|
|
PRUint32 flags = 0;
|
2008-01-09 14:53:59 -08:00
|
|
|
while (PR_TRUE) {
|
|
|
|
nsIFrame* next = nsLayoutUtils::GetCrossDocParentFrame(frame);
|
|
|
|
if (!next)
|
|
|
|
break;
|
2008-09-18 02:47:21 -07:00
|
|
|
if (frame->GetParent() != next) {
|
|
|
|
// We're crossing a document boundary. Logically, the invalidation is
|
|
|
|
// being triggered by a subdocument of the root document. This will
|
|
|
|
// prevent an untrusted root document being told about invalidation
|
|
|
|
// that happened because a child was using SVG...
|
|
|
|
flags |= INVALIDATE_CROSS_DOC;
|
|
|
|
}
|
2008-01-09 14:53:59 -08:00
|
|
|
frame = next;
|
|
|
|
}
|
2008-09-18 02:47:21 -07:00
|
|
|
frame->InvalidateWithFlags(nsRect(nsPoint(0, 0), frame->GetSize()), flags);
|
2008-01-09 14:53:59 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(DEBUG) && defined(SVG_DEBUG_PAINT_TIMING)
|
|
|
|
PRTime end = PR_Now();
|
|
|
|
printf("SVG Paint Timing: %f ms\n", (end-start)/1000.0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
aRenderingContext.PopState();
|
|
|
|
}
|
|
|
|
|
2008-02-22 02:50:32 -08:00
|
|
|
nsSplittableType
|
|
|
|
nsSVGOuterSVGFrame::GetSplittableType() const
|
|
|
|
{
|
|
|
|
return NS_FRAME_NOT_SPLITTABLE;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom *
|
|
|
|
nsSVGOuterSVGFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::svgOuterSVGFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGOuterSVGFrame methods:
|
|
|
|
|
2008-03-19 14:27:33 -07:00
|
|
|
void
|
|
|
|
nsSVGOuterSVGFrame::InvalidateCoveredRegion(nsIFrame *aFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-01-12 11:20:59 -08:00
|
|
|
nsISVGChildFrame *svgFrame = do_QueryFrame(aFrame);
|
2008-03-19 14:27:33 -07:00
|
|
|
if (!svgFrame)
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-07-22 19:15:27 -07:00
|
|
|
nsRect rect = nsSVGUtils::FindFilterInvalidation(aFrame, svgFrame->GetCoveredRegion());
|
2008-08-25 02:23:54 -07:00
|
|
|
Invalidate(rect);
|
2008-03-19 14:27:33 -07:00
|
|
|
}
|
|
|
|
|
2008-07-22 19:15:27 -07:00
|
|
|
PRBool
|
|
|
|
nsSVGOuterSVGFrame::UpdateAndInvalidateCoveredRegion(nsIFrame *aFrame)
|
|
|
|
{
|
2009-01-12 11:20:59 -08:00
|
|
|
nsISVGChildFrame *svgFrame = do_QueryFrame(aFrame);
|
2008-07-22 19:15:27 -07:00
|
|
|
if (!svgFrame)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsRect oldRegion = svgFrame->GetCoveredRegion();
|
2008-08-25 02:23:54 -07:00
|
|
|
Invalidate(nsSVGUtils::FindFilterInvalidation(aFrame, oldRegion));
|
2008-07-22 19:15:27 -07:00
|
|
|
svgFrame->UpdateCoveredRegion();
|
|
|
|
nsRect newRegion = svgFrame->GetCoveredRegion();
|
2011-04-18 20:07:23 -07:00
|
|
|
if (oldRegion.IsEqualInterior(newRegion))
|
2008-07-22 19:15:27 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
|
2008-08-25 02:23:54 -07:00
|
|
|
Invalidate(nsSVGUtils::FindFilterInvalidation(aFrame, newRegion));
|
2008-07-22 19:15:27 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2007-03-28 02:41:46 -07:00
|
|
|
PRBool
|
|
|
|
nsSVGOuterSVGFrame::IsRedrawSuspended()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-03-28 02:41:46 -07:00
|
|
|
return (mRedrawSuspendCount>0) || !mViewportInitialized;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISVGSVGFrame methods:
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGOuterSVGFrame::SuspendRedraw()
|
|
|
|
{
|
|
|
|
if (++mRedrawSuspendCount != 1)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
for (nsIFrame* kid = mFrames.FirstChild(); kid;
|
|
|
|
kid = kid->GetNextSibling()) {
|
2009-01-12 11:20:59 -08:00
|
|
|
nsISVGChildFrame* SVGFrame = do_QueryFrame(kid);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (SVGFrame) {
|
|
|
|
SVGFrame->NotifyRedrawSuspended();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGOuterSVGFrame::UnsuspendRedraw()
|
|
|
|
{
|
2007-08-21 12:29:37 -07:00
|
|
|
NS_ASSERTION(mRedrawSuspendCount >=0, "unbalanced suspend count!");
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (--mRedrawSuspendCount > 0)
|
|
|
|
return NS_OK;
|
2007-08-21 12:29:37 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
for (nsIFrame* kid = mFrames.FirstChild(); kid;
|
|
|
|
kid = kid->GetNextSibling()) {
|
2009-01-12 11:20:59 -08:00
|
|
|
nsISVGChildFrame* SVGFrame = do_QueryFrame(kid);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (SVGFrame) {
|
|
|
|
SVGFrame->NotifyRedrawUnsuspended();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGOuterSVGFrame::NotifyViewportChange()
|
|
|
|
{
|
|
|
|
// no point in doing anything when were not init'ed yet:
|
2008-01-25 01:27:03 -08:00
|
|
|
if (!mViewportInitialized) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 flags = COORD_CONTEXT_CHANGED;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-06-14 13:51:42 -07:00
|
|
|
// viewport changes only affect our transform if we have a viewBox attribute
|
2008-01-25 01:27:03 -08:00
|
|
|
#if 1
|
|
|
|
{
|
|
|
|
#else
|
|
|
|
// XXX this caused reftest failures (bug 413960)
|
|
|
|
if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::viewBox)) {
|
|
|
|
#endif
|
|
|
|
// make sure canvas transform matrix gets (lazily) recalculated:
|
|
|
|
mCanvasTM = nsnull;
|
|
|
|
|
|
|
|
flags |= TRANSFORM_CHANGED;
|
2007-06-14 13:51:42 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// inform children
|
|
|
|
SuspendRedraw();
|
2008-01-25 01:27:03 -08:00
|
|
|
nsSVGUtils::NotifyChildrenOfSVGChange(this, flags);
|
2007-03-22 10:30:00 -07:00
|
|
|
UnsuspendRedraw();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGContainerFrame methods:
|
|
|
|
|
2009-04-28 21:31:34 -07:00
|
|
|
gfxMatrix
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSVGOuterSVGFrame::GetCanvasTM()
|
|
|
|
{
|
|
|
|
if (!mCanvasTM) {
|
2009-07-23 01:35:59 -07:00
|
|
|
nsSVGSVGElement *content = static_cast<nsSVGSVGElement*>(mContent);
|
2007-12-03 20:40:52 -08:00
|
|
|
|
|
|
|
float devPxPerCSSPx =
|
2009-07-23 01:35:59 -07:00
|
|
|
1.0f / PresContext()->AppUnitsToFloatCSSPixels(
|
2007-12-03 20:40:52 -08:00
|
|
|
PresContext()->AppUnitsPerDevPixel());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-07-23 01:35:59 -07:00
|
|
|
gfxMatrix viewBoxTM = content->GetViewBoxTransform();
|
|
|
|
|
|
|
|
gfxMatrix zoomPanTM;
|
2009-04-28 06:25:03 -07:00
|
|
|
if (mIsRootContent) {
|
2009-07-23 01:35:59 -07:00
|
|
|
const nsSVGTranslatePoint& translate = content->GetCurrentTranslate();
|
|
|
|
zoomPanTM.Translate(gfxPoint(translate.GetX(), translate.GetY()));
|
|
|
|
zoomPanTM.Scale(content->GetCurrentScale(), content->GetCurrentScale());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-07-23 01:35:59 -07:00
|
|
|
|
|
|
|
gfxMatrix TM = viewBoxTM * zoomPanTM * gfxMatrix().Scale(devPxPerCSSPx, devPxPerCSSPx);
|
|
|
|
mCanvasTM = NS_NewSVGMatrix(TM);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-04-28 21:31:34 -07:00
|
|
|
return nsSVGUtils::ConvertSVGMatrixToThebes(mCanvasTM);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation helpers
|
|
|
|
|
2007-11-20 01:10:18 -08:00
|
|
|
void
|
|
|
|
nsSVGOuterSVGFrame::RegisterForeignObject(nsSVGForeignObjectFrame* aFrame)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aFrame, "Who on earth is calling us?!");
|
|
|
|
|
|
|
|
if (!mForeignObjectHash.IsInitialized()) {
|
|
|
|
if (!mForeignObjectHash.Init()) {
|
|
|
|
NS_ERROR("Failed to initialize foreignObject hash.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(!mForeignObjectHash.GetEntry(aFrame),
|
|
|
|
"nsSVGForeignObjectFrame already registered!");
|
|
|
|
|
|
|
|
mForeignObjectHash.PutEntry(aFrame);
|
|
|
|
|
|
|
|
NS_ASSERTION(mForeignObjectHash.GetEntry(aFrame),
|
|
|
|
"Failed to register nsSVGForeignObjectFrame!");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-10-24 00:47:04 -07:00
|
|
|
nsSVGOuterSVGFrame::UnregisterForeignObject(nsSVGForeignObjectFrame* aFrame)
|
|
|
|
{
|
2007-11-20 01:10:18 -08:00
|
|
|
NS_ASSERTION(aFrame, "Who on earth is calling us?!");
|
|
|
|
NS_ASSERTION(mForeignObjectHash.GetEntry(aFrame),
|
|
|
|
"nsSVGForeignObjectFrame not in registry!");
|
|
|
|
return mForeignObjectHash.RemoveEntry(aFrame);
|
|
|
|
}
|
|
|
|
|
2007-11-18 04:09:03 -08:00
|
|
|
PRBool
|
2011-02-09 12:13:18 -08:00
|
|
|
nsSVGOuterSVGFrame::IsRootOfReplacedElementSubDoc(nsIFrame **aEmbeddingFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-09-08 13:40:39 -07:00
|
|
|
if (!mContent->GetParent()) {
|
2007-11-18 04:09:03 -08:00
|
|
|
// Our content is the document element
|
|
|
|
nsCOMPtr<nsISupports> container = PresContext()->GetContainer();
|
2011-07-15 03:31:34 -07:00
|
|
|
nsCOMPtr<nsIDOMWindow> window = do_GetInterface(container);
|
2007-11-18 04:09:03 -08:00
|
|
|
if (window) {
|
|
|
|
nsCOMPtr<nsIDOMElement> frameElement;
|
|
|
|
window->GetFrameElement(getter_AddRefs(frameElement));
|
|
|
|
nsCOMPtr<nsIObjectLoadingContent> olc = do_QueryInterface(frameElement);
|
|
|
|
if (olc) {
|
|
|
|
// Our document is inside an HTML 'object', 'embed' or 'applet' element
|
|
|
|
if (aEmbeddingFrame) {
|
|
|
|
nsCOMPtr<nsIContent> element = do_QueryInterface(frameElement);
|
|
|
|
*aEmbeddingFrame =
|
|
|
|
static_cast<nsGenericElement*>(element.get())->GetPrimaryFrame();
|
|
|
|
NS_ASSERTION(*aEmbeddingFrame, "Yikes, no embedding frame!");
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (aEmbeddingFrame) {
|
|
|
|
*aEmbeddingFrame = nsnull;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2010-09-08 13:40:39 -07:00
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsSVGOuterSVGFrame::IsRootOfImage()
|
|
|
|
{
|
|
|
|
if (!mContent->GetParent()) {
|
|
|
|
// Our content is the document element
|
|
|
|
nsIDocument* doc = mContent->GetCurrentDoc();
|
|
|
|
if (doc && doc->IsBeingUsedAsImage()) {
|
|
|
|
// Our document is being used as an image
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|