2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-26 04:58:59 -07:00
|
|
|
// Main header first:
|
|
|
|
// This is also necessary to ensure our definition of M_SQRT1_2 is picked up
|
2009-04-02 13:29:31 -07:00
|
|
|
#include "nsSVGUtils.h"
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2012-03-20 05:15:55 -07:00
|
|
|
|
2012-03-26 04:58:59 -07:00
|
|
|
// Keep others in (case-insensitive) order:
|
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "gfxImageSurface.h"
|
|
|
|
#include "gfxMatrix.h"
|
|
|
|
#include "gfxPlatform.h"
|
|
|
|
#include "gfxRect.h"
|
|
|
|
#include "gfxUtils.h"
|
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
2012-05-16 21:05:09 -07:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
2012-06-24 05:59:26 -07:00
|
|
|
#include "nsDisplayList.h"
|
2012-03-26 04:58:59 -07:00
|
|
|
#include "nsFrameList.h"
|
|
|
|
#include "nsGkAtoms.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIFrame.h"
|
2012-03-26 04:58:59 -07:00
|
|
|
#include "nsINameSpaceManager.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsISVGChildFrame.h"
|
2012-03-26 04:58:59 -07:00
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsRenderingContext.h"
|
|
|
|
#include "nsStyleCoord.h"
|
|
|
|
#include "nsStyleStruct.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsSVGClipPathFrame.h"
|
|
|
|
#include "nsSVGContainerFrame.h"
|
2008-08-07 18:34:43 -07:00
|
|
|
#include "nsSVGEffects.h"
|
2012-03-26 04:58:59 -07:00
|
|
|
#include "nsSVGFilterFrame.h"
|
2008-09-10 17:24:16 -07:00
|
|
|
#include "nsSVGFilterPaintCallback.h"
|
2012-03-26 04:58:59 -07:00
|
|
|
#include "nsSVGForeignObjectFrame.h"
|
2009-03-31 05:19:39 -07:00
|
|
|
#include "nsSVGGeometryFrame.h"
|
2012-09-05 21:58:46 -07:00
|
|
|
#include "nsSVGGlyphFrame.h"
|
2012-03-26 04:58:59 -07:00
|
|
|
#include "nsSVGInnerSVGFrame.h"
|
|
|
|
#include "nsSVGIntegrationUtils.h"
|
|
|
|
#include "nsSVGLength2.h"
|
|
|
|
#include "nsSVGMaskFrame.h"
|
|
|
|
#include "nsSVGOuterSVGFrame.h"
|
2013-01-12 14:22:31 -08:00
|
|
|
#include "mozilla/dom/SVGPathElement.h"
|
2011-09-05 10:53:34 -07:00
|
|
|
#include "nsSVGPathGeometryElement.h"
|
2012-03-26 04:58:59 -07:00
|
|
|
#include "nsSVGPathGeometryFrame.h"
|
2012-08-05 12:10:21 -07:00
|
|
|
#include "nsSVGPaintServerFrame.h"
|
2013-01-09 15:02:45 -08:00
|
|
|
#include "mozilla/dom/SVGSVGElement.h"
|
2012-03-26 04:58:59 -07:00
|
|
|
#include "nsSVGTextContainerFrame.h"
|
2012-08-10 04:13:44 -07:00
|
|
|
#include "nsTextFrame.h"
|
2012-09-22 12:26:05 -07:00
|
|
|
#include "SVGContentUtils.h"
|
2012-06-01 02:48:39 -07:00
|
|
|
#include "mozilla/unused.h"
|
2012-01-04 23:17:52 -08:00
|
|
|
|
2010-12-19 16:45:29 -08:00
|
|
|
using namespace mozilla;
|
2010-04-30 06:12:06 -07:00
|
|
|
using namespace mozilla::dom;
|
2012-01-04 23:17:52 -08:00
|
|
|
using namespace mozilla::gfx;
|
2007-04-26 01:36:16 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// c = n / 255
|
|
|
|
// (c <= 0.0031308 ? c * 12.92 : 1.055 * pow(c, 1 / 2.4) - 0.055) * 255 + 0.5
|
2012-08-22 08:56:38 -07:00
|
|
|
static const uint8_t glinearRGBTosRGBMap[256] = {
|
2007-03-22 10:30:00 -07:00
|
|
|
0, 13, 22, 28, 34, 38, 42, 46,
|
|
|
|
50, 53, 56, 59, 61, 64, 66, 69,
|
|
|
|
71, 73, 75, 77, 79, 81, 83, 85,
|
|
|
|
86, 88, 90, 92, 93, 95, 96, 98,
|
|
|
|
99, 101, 102, 104, 105, 106, 108, 109,
|
|
|
|
110, 112, 113, 114, 115, 117, 118, 119,
|
|
|
|
120, 121, 122, 124, 125, 126, 127, 128,
|
|
|
|
129, 130, 131, 132, 133, 134, 135, 136,
|
|
|
|
137, 138, 139, 140, 141, 142, 143, 144,
|
|
|
|
145, 146, 147, 148, 148, 149, 150, 151,
|
|
|
|
152, 153, 154, 155, 155, 156, 157, 158,
|
|
|
|
159, 159, 160, 161, 162, 163, 163, 164,
|
|
|
|
165, 166, 167, 167, 168, 169, 170, 170,
|
|
|
|
171, 172, 173, 173, 174, 175, 175, 176,
|
|
|
|
177, 178, 178, 179, 180, 180, 181, 182,
|
|
|
|
182, 183, 184, 185, 185, 186, 187, 187,
|
|
|
|
188, 189, 189, 190, 190, 191, 192, 192,
|
|
|
|
193, 194, 194, 195, 196, 196, 197, 197,
|
|
|
|
198, 199, 199, 200, 200, 201, 202, 202,
|
|
|
|
203, 203, 204, 205, 205, 206, 206, 207,
|
|
|
|
208, 208, 209, 209, 210, 210, 211, 212,
|
|
|
|
212, 213, 213, 214, 214, 215, 215, 216,
|
|
|
|
216, 217, 218, 218, 219, 219, 220, 220,
|
|
|
|
221, 221, 222, 222, 223, 223, 224, 224,
|
|
|
|
225, 226, 226, 227, 227, 228, 228, 229,
|
|
|
|
229, 230, 230, 231, 231, 232, 232, 233,
|
|
|
|
233, 234, 234, 235, 235, 236, 236, 237,
|
|
|
|
237, 238, 238, 238, 239, 239, 240, 240,
|
|
|
|
241, 241, 242, 242, 243, 243, 244, 244,
|
|
|
|
245, 245, 246, 246, 246, 247, 247, 248,
|
|
|
|
248, 249, 249, 250, 250, 251, 251, 251,
|
|
|
|
252, 252, 253, 253, 254, 254, 255, 255
|
|
|
|
};
|
|
|
|
|
|
|
|
// c = n / 255
|
|
|
|
// c <= 0.04045 ? c / 12.92 : pow((c + 0.055) / 1.055, 2.4)) * 255 + 0.5
|
2012-08-22 08:56:38 -07:00
|
|
|
static const uint8_t gsRGBToLinearRGBMap[256] = {
|
2007-03-22 10:30:00 -07:00
|
|
|
0, 0, 0, 0, 0, 0, 0, 1,
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
1, 1, 2, 2, 2, 2, 2, 2,
|
|
|
|
2, 2, 3, 3, 3, 3, 3, 3,
|
|
|
|
4, 4, 4, 4, 4, 5, 5, 5,
|
|
|
|
5, 6, 6, 6, 6, 7, 7, 7,
|
|
|
|
8, 8, 8, 8, 9, 9, 9, 10,
|
|
|
|
10, 10, 11, 11, 12, 12, 12, 13,
|
|
|
|
13, 13, 14, 14, 15, 15, 16, 16,
|
|
|
|
17, 17, 17, 18, 18, 19, 19, 20,
|
|
|
|
20, 21, 22, 22, 23, 23, 24, 24,
|
|
|
|
25, 25, 26, 27, 27, 28, 29, 29,
|
|
|
|
30, 30, 31, 32, 32, 33, 34, 35,
|
|
|
|
35, 36, 37, 37, 38, 39, 40, 41,
|
|
|
|
41, 42, 43, 44, 45, 45, 46, 47,
|
|
|
|
48, 49, 50, 51, 51, 52, 53, 54,
|
|
|
|
55, 56, 57, 58, 59, 60, 61, 62,
|
|
|
|
63, 64, 65, 66, 67, 68, 69, 70,
|
|
|
|
71, 72, 73, 74, 76, 77, 78, 79,
|
|
|
|
80, 81, 82, 84, 85, 86, 87, 88,
|
|
|
|
90, 91, 92, 93, 95, 96, 97, 99,
|
|
|
|
100, 101, 103, 104, 105, 107, 108, 109,
|
|
|
|
111, 112, 114, 115, 116, 118, 119, 121,
|
|
|
|
122, 124, 125, 127, 128, 130, 131, 133,
|
|
|
|
134, 136, 138, 139, 141, 142, 144, 146,
|
|
|
|
147, 149, 151, 152, 154, 156, 157, 159,
|
|
|
|
161, 163, 164, 166, 168, 170, 171, 173,
|
|
|
|
175, 177, 179, 181, 183, 184, 186, 188,
|
|
|
|
190, 192, 194, 196, 198, 200, 202, 204,
|
|
|
|
206, 208, 210, 212, 214, 216, 218, 220,
|
|
|
|
222, 224, 226, 229, 231, 233, 235, 237,
|
|
|
|
239, 242, 244, 246, 248, 250, 253, 255
|
|
|
|
};
|
|
|
|
|
2012-05-16 21:05:04 -07:00
|
|
|
static bool sSVGDisplayListHitTestingEnabled;
|
|
|
|
static bool sSVGDisplayListPaintingEnabled;
|
2012-08-08 04:46:06 -07:00
|
|
|
static bool sSVGTextCSSFramesEnabled;
|
2009-03-09 18:20:17 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-05-16 21:05:04 -07:00
|
|
|
NS_SVGDisplayListHitTestingEnabled()
|
2009-03-09 18:20:17 -07:00
|
|
|
{
|
2012-05-16 21:05:04 -07:00
|
|
|
return sSVGDisplayListHitTestingEnabled;
|
|
|
|
}
|
2009-03-09 18:20:17 -07:00
|
|
|
|
2012-05-16 21:05:04 -07:00
|
|
|
bool
|
|
|
|
NS_SVGDisplayListPaintingEnabled()
|
|
|
|
{
|
|
|
|
return sSVGDisplayListPaintingEnabled;
|
2009-03-09 18:20:17 -07:00
|
|
|
}
|
|
|
|
|
2012-08-08 04:46:06 -07:00
|
|
|
bool
|
|
|
|
NS_SVGTextCSSFramesEnabled()
|
|
|
|
{
|
|
|
|
return sSVGTextCSSFramesEnabled;
|
|
|
|
}
|
|
|
|
|
2012-03-02 00:28:59 -08:00
|
|
|
// we only take the address of this:
|
|
|
|
static mozilla::gfx::UserDataKey sSVGAutoRenderStateKey;
|
|
|
|
|
|
|
|
SVGAutoRenderState::SVGAutoRenderState(nsRenderingContext *aContext,
|
|
|
|
RenderMode aMode)
|
|
|
|
: mContext(aContext)
|
2012-07-30 07:20:58 -07:00
|
|
|
, mOriginalRenderState(nullptr)
|
2012-03-02 00:28:59 -08:00
|
|
|
, mMode(aMode)
|
|
|
|
, mPaintingToWindow(false)
|
|
|
|
{
|
|
|
|
mOriginalRenderState = aContext->RemoveUserData(&sSVGAutoRenderStateKey);
|
|
|
|
// We always remove ourselves from aContext before it dies, so
|
2012-07-30 07:20:58 -07:00
|
|
|
// passing nullptr as the destroy function is okay.
|
|
|
|
aContext->AddUserData(&sSVGAutoRenderStateKey, this, nullptr);
|
2012-03-02 00:28:59 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
SVGAutoRenderState::~SVGAutoRenderState()
|
|
|
|
{
|
|
|
|
mContext->RemoveUserData(&sSVGAutoRenderStateKey);
|
|
|
|
if (mOriginalRenderState) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mContext->AddUserData(&sSVGAutoRenderStateKey, mOriginalRenderState, nullptr);
|
2012-03-02 00:28:59 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SVGAutoRenderState::SetPaintingToWindow(bool aPaintingToWindow)
|
|
|
|
{
|
|
|
|
mPaintingToWindow = aPaintingToWindow;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ SVGAutoRenderState::RenderMode
|
|
|
|
SVGAutoRenderState::GetRenderMode(nsRenderingContext *aContext)
|
|
|
|
{
|
|
|
|
void *state = aContext->GetUserData(&sSVGAutoRenderStateKey);
|
|
|
|
if (state) {
|
|
|
|
return static_cast<SVGAutoRenderState*>(state)->mMode;
|
|
|
|
}
|
|
|
|
return NORMAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ bool
|
|
|
|
SVGAutoRenderState::IsPaintingToWindow(nsRenderingContext *aContext)
|
|
|
|
{
|
|
|
|
void *state = aContext->GetUserData(&sSVGAutoRenderStateKey);
|
|
|
|
if (state) {
|
|
|
|
return static_cast<SVGAutoRenderState*>(state)->mPaintingToWindow;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-05-16 21:05:04 -07:00
|
|
|
void
|
|
|
|
nsSVGUtils::Init()
|
|
|
|
{
|
|
|
|
Preferences::AddBoolVarCache(&sSVGDisplayListHitTestingEnabled,
|
|
|
|
"svg.display-lists.hit-testing.enabled");
|
|
|
|
|
|
|
|
Preferences::AddBoolVarCache(&sSVGDisplayListPaintingEnabled,
|
|
|
|
"svg.display-lists.painting.enabled");
|
2012-08-08 04:46:06 -07:00
|
|
|
|
|
|
|
Preferences::AddBoolVarCache(&sSVGTextCSSFramesEnabled,
|
|
|
|
"svg.text.css-frames.enabled");
|
2012-05-16 21:05:04 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSVGUtils::UnPremultiplyImageDataAlpha(uint8_t *data,
|
|
|
|
int32_t stride,
|
2008-08-25 02:23:54 -07:00
|
|
|
const nsIntRect &rect)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t y = rect.y; y < rect.YMost(); y++) {
|
|
|
|
for (int32_t x = rect.x; x < rect.XMost(); x++) {
|
|
|
|
uint8_t *pixel = data + stride * y + 4 * x;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t a = pixel[GFX_ARGB32_OFFSET_A];
|
2007-03-22 10:30:00 -07:00
|
|
|
if (a == 255)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (a) {
|
|
|
|
pixel[GFX_ARGB32_OFFSET_B] = (255 * pixel[GFX_ARGB32_OFFSET_B]) / a;
|
|
|
|
pixel[GFX_ARGB32_OFFSET_G] = (255 * pixel[GFX_ARGB32_OFFSET_G]) / a;
|
|
|
|
pixel[GFX_ARGB32_OFFSET_R] = (255 * pixel[GFX_ARGB32_OFFSET_R]) / a;
|
|
|
|
} else {
|
|
|
|
pixel[GFX_ARGB32_OFFSET_B] = 0;
|
|
|
|
pixel[GFX_ARGB32_OFFSET_G] = 0;
|
|
|
|
pixel[GFX_ARGB32_OFFSET_R] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSVGUtils::PremultiplyImageDataAlpha(uint8_t *data,
|
|
|
|
int32_t stride,
|
2008-08-25 02:23:54 -07:00
|
|
|
const nsIntRect &rect)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t y = rect.y; y < rect.YMost(); y++) {
|
|
|
|
for (int32_t x = rect.x; x < rect.XMost(); x++) {
|
|
|
|
uint8_t *pixel = data + stride * y + 4 * x;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t a = pixel[GFX_ARGB32_OFFSET_A];
|
2007-03-22 10:30:00 -07:00
|
|
|
if (a == 255)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
FAST_DIVIDE_BY_255(pixel[GFX_ARGB32_OFFSET_B],
|
|
|
|
pixel[GFX_ARGB32_OFFSET_B] * a);
|
|
|
|
FAST_DIVIDE_BY_255(pixel[GFX_ARGB32_OFFSET_G],
|
|
|
|
pixel[GFX_ARGB32_OFFSET_G] * a);
|
|
|
|
FAST_DIVIDE_BY_255(pixel[GFX_ARGB32_OFFSET_R],
|
|
|
|
pixel[GFX_ARGB32_OFFSET_R] * a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSVGUtils::ConvertImageDataToLinearRGB(uint8_t *data,
|
|
|
|
int32_t stride,
|
2008-08-25 02:23:54 -07:00
|
|
|
const nsIntRect &rect)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t y = rect.y; y < rect.YMost(); y++) {
|
|
|
|
for (int32_t x = rect.x; x < rect.XMost(); x++) {
|
|
|
|
uint8_t *pixel = data + stride * y + 4 * x;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
pixel[GFX_ARGB32_OFFSET_B] =
|
|
|
|
gsRGBToLinearRGBMap[pixel[GFX_ARGB32_OFFSET_B]];
|
|
|
|
pixel[GFX_ARGB32_OFFSET_G] =
|
|
|
|
gsRGBToLinearRGBMap[pixel[GFX_ARGB32_OFFSET_G]];
|
|
|
|
pixel[GFX_ARGB32_OFFSET_R] =
|
|
|
|
gsRGBToLinearRGBMap[pixel[GFX_ARGB32_OFFSET_R]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSVGUtils::ConvertImageDataFromLinearRGB(uint8_t *data,
|
|
|
|
int32_t stride,
|
2008-08-25 02:23:54 -07:00
|
|
|
const nsIntRect &rect)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t y = rect.y; y < rect.YMost(); y++) {
|
|
|
|
for (int32_t x = rect.x; x < rect.XMost(); x++) {
|
|
|
|
uint8_t *pixel = data + stride * y + 4 * x;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
pixel[GFX_ARGB32_OFFSET_B] =
|
|
|
|
glinearRGBTosRGBMap[pixel[GFX_ARGB32_OFFSET_B]];
|
|
|
|
pixel[GFX_ARGB32_OFFSET_G] =
|
|
|
|
glinearRGBTosRGBMap[pixel[GFX_ARGB32_OFFSET_G]];
|
|
|
|
pixel[GFX_ARGB32_OFFSET_R] =
|
|
|
|
glinearRGBTosRGBMap[pixel[GFX_ARGB32_OFFSET_R]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-28 01:50:38 -08:00
|
|
|
void
|
|
|
|
nsSVGUtils::ComputesRGBLuminanceMask(uint8_t *aData,
|
|
|
|
int32_t aStride,
|
|
|
|
const nsIntRect &aRect,
|
|
|
|
float aOpacity)
|
|
|
|
{
|
|
|
|
for (int32_t y = aRect.y; y < aRect.YMost(); y++) {
|
|
|
|
for (int32_t x = aRect.x; x < aRect.XMost(); x++) {
|
|
|
|
uint8_t *pixel = aData + aStride * y + 4 * x;
|
|
|
|
uint8_t a = pixel[GFX_ARGB32_OFFSET_A];
|
|
|
|
|
|
|
|
uint8_t luminance;
|
|
|
|
if (a) {
|
|
|
|
/* sRGB -> intensity (unpremultiply cancels out the
|
|
|
|
* (a/255.0) multiplication with aOpacity */
|
|
|
|
luminance =
|
|
|
|
static_cast<uint8_t>
|
|
|
|
((pixel[GFX_ARGB32_OFFSET_R] * 0.2125 +
|
|
|
|
pixel[GFX_ARGB32_OFFSET_G] * 0.7154 +
|
|
|
|
pixel[GFX_ARGB32_OFFSET_B] * 0.0721) *
|
|
|
|
aOpacity);
|
|
|
|
} else {
|
|
|
|
luminance = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(pixel, luminance, 4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSVGUtils::ComputeLinearRGBLuminanceMask(uint8_t *aData,
|
|
|
|
int32_t aStride,
|
|
|
|
const nsIntRect &aRect,
|
|
|
|
float aOpacity)
|
|
|
|
{
|
|
|
|
for (int32_t y = aRect.y; y < aRect.YMost(); y++) {
|
|
|
|
for (int32_t x = aRect.x; x < aRect.XMost(); x++) {
|
|
|
|
uint8_t *pixel = aData + aStride * y + 4 * x;
|
|
|
|
uint8_t a = pixel[GFX_ARGB32_OFFSET_A];
|
|
|
|
|
|
|
|
uint8_t luminance;
|
|
|
|
// unpremultiply
|
|
|
|
if (a) {
|
|
|
|
if (a != 255) {
|
|
|
|
pixel[GFX_ARGB32_OFFSET_B] =
|
|
|
|
(255 * pixel[GFX_ARGB32_OFFSET_B]) / a;
|
|
|
|
pixel[GFX_ARGB32_OFFSET_G] =
|
|
|
|
(255 * pixel[GFX_ARGB32_OFFSET_G]) / a;
|
|
|
|
pixel[GFX_ARGB32_OFFSET_R] =
|
|
|
|
(255 * pixel[GFX_ARGB32_OFFSET_R]) / a;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* sRGB -> linearRGB -> intensity */
|
|
|
|
luminance =
|
|
|
|
static_cast<uint8_t>
|
|
|
|
((gsRGBToLinearRGBMap[pixel[GFX_ARGB32_OFFSET_R]] *
|
|
|
|
0.2125 +
|
|
|
|
gsRGBToLinearRGBMap[pixel[GFX_ARGB32_OFFSET_G]] *
|
|
|
|
0.7154 +
|
|
|
|
gsRGBToLinearRGBMap[pixel[GFX_ARGB32_OFFSET_B]] *
|
|
|
|
0.0721) * (a / 255.0) * aOpacity);
|
|
|
|
} else {
|
|
|
|
luminance = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(pixel, luminance, 4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSVGUtils::ComputeAlphaMask(uint8_t *aData,
|
|
|
|
int32_t aStride,
|
|
|
|
const nsIntRect &aRect,
|
|
|
|
float aOpacity)
|
|
|
|
{
|
|
|
|
for (int32_t y = aRect.y; y < aRect.YMost(); y++) {
|
|
|
|
for (int32_t x = aRect.x; x < aRect.XMost(); x++) {
|
|
|
|
uint8_t *pixel = aData + aStride * y + 4 * x;
|
|
|
|
uint8_t luminance = pixel[GFX_ARGB32_OFFSET_A] * aOpacity;
|
|
|
|
memset(pixel, luminance, 4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
float
|
|
|
|
nsSVGUtils::CoordToFloat(nsPresContext *aPresContext,
|
|
|
|
nsSVGElement *aContent,
|
|
|
|
const nsStyleCoord &aCoord)
|
|
|
|
{
|
|
|
|
switch (aCoord.GetUnit()) {
|
|
|
|
case eStyleUnit_Factor:
|
|
|
|
// user units
|
2009-01-16 00:02:40 -08:00
|
|
|
return aCoord.GetFactorValue();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
case eStyleUnit_Coord:
|
2009-01-16 00:02:40 -08:00
|
|
|
return nsPresContext::AppUnitsToFloatCSSPixels(aCoord.GetCoordValue());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
case eStyleUnit_Percent: {
|
2013-01-09 15:02:45 -08:00
|
|
|
SVGSVGElement* ctx = aContent->GetCtx();
|
2012-09-22 12:26:05 -07:00
|
|
|
return ctx ? aCoord.GetPercentValue() * ctx->GetLength(SVGContentUtils::XY) : 0.0f;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
default:
|
2009-01-16 00:02:40 -08:00
|
|
|
return 0.0f;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-24 16:17:43 -07:00
|
|
|
nsSVGDisplayContainerFrame*
|
|
|
|
nsSVGUtils::GetNearestSVGViewport(nsIFrame *aFrame)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aFrame->IsFrameOfType(nsIFrame::eSVG), "SVG frame expected");
|
|
|
|
if (aFrame->GetType() == nsGkAtoms::svgOuterSVGFrame) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-04-24 16:17:43 -07:00
|
|
|
}
|
|
|
|
while ((aFrame = aFrame->GetParent())) {
|
|
|
|
NS_ASSERTION(aFrame->IsFrameOfType(nsIFrame::eSVG), "SVG frame expected");
|
|
|
|
if (aFrame->GetType() == nsGkAtoms::svgInnerSVGFrame ||
|
|
|
|
aFrame->GetType() == nsGkAtoms::svgOuterSVGFrame) {
|
|
|
|
return do_QueryFrame(aFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_NOTREACHED("This is not reached. It's only needed to compile.");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-04-24 16:17:43 -07:00
|
|
|
}
|
|
|
|
|
2012-05-16 21:05:09 -07:00
|
|
|
nsRect
|
|
|
|
nsSVGUtils::GetPostFilterVisualOverflowRect(nsIFrame *aFrame,
|
2012-06-16 13:23:48 -07:00
|
|
|
const nsRect &aPreFilterRect)
|
2012-05-16 21:05:09 -07:00
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT,
|
|
|
|
"Called on invalid frame type");
|
|
|
|
|
|
|
|
nsSVGFilterFrame *filter = nsSVGEffects::GetFilterFrame(aFrame);
|
|
|
|
if (!filter) {
|
2012-06-16 13:23:48 -07:00
|
|
|
return aPreFilterRect;
|
2012-05-16 21:05:09 -07:00
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return filter->GetPostFilterBounds(aFrame, nullptr, &aPreFilterRect);
|
2012-05-16 21:05:09 -07:00
|
|
|
}
|
|
|
|
|
2012-03-20 05:15:53 -07:00
|
|
|
bool
|
2012-07-21 17:01:44 -07:00
|
|
|
nsSVGUtils::OuterSVGIsCallingReflowSVG(nsIFrame *aFrame)
|
2012-03-20 05:15:53 -07:00
|
|
|
{
|
2012-09-22 12:26:05 -07:00
|
|
|
return GetOuterSVGFrame(aFrame)->IsCallingReflowSVG();
|
2012-03-20 05:15:53 -07:00
|
|
|
}
|
|
|
|
|
2013-06-03 07:15:29 -07:00
|
|
|
bool
|
|
|
|
nsSVGUtils::AnyOuterSVGIsCallingReflowSVG(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsSVGOuterSVGFrame* outer = GetOuterSVGFrame(aFrame);
|
|
|
|
do {
|
|
|
|
if (outer->IsCallingReflowSVG()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
outer = GetOuterSVGFrame(outer->GetParent());
|
|
|
|
} while (outer);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-04-08 05:51:19 -07:00
|
|
|
void
|
2012-07-21 17:01:44 -07:00
|
|
|
nsSVGUtils::ScheduleReflowSVG(nsIFrame *aFrame)
|
2008-04-08 05:51:19 -07:00
|
|
|
{
|
2012-03-20 05:15:53 -07:00
|
|
|
NS_ABORT_IF_FALSE(aFrame->IsFrameOfType(nsIFrame::eSVG),
|
|
|
|
"Passed bad frame!");
|
2008-04-08 05:51:19 -07:00
|
|
|
|
2012-03-20 05:15:53 -07:00
|
|
|
// If this is triggered, the callers should be fixed to call us before
|
2012-07-21 17:01:44 -07:00
|
|
|
// ReflowSVG is called. If we try to mark dirty bits on frames while we're
|
2012-03-20 05:15:53 -07:00
|
|
|
// in the process of removing them, things will get messed up.
|
2012-07-21 17:01:44 -07:00
|
|
|
NS_ASSERTION(!OuterSVGIsCallingReflowSVG(aFrame),
|
|
|
|
"Do not call under nsISVGChildFrame::ReflowSVG!");
|
2012-03-20 05:15:53 -07:00
|
|
|
|
|
|
|
// We don't call nsSVGEffects::InvalidateRenderingObservers here because
|
2012-08-27 00:51:48 -07:00
|
|
|
// we should only be called under InvalidateAndScheduleReflowSVG (which
|
2012-03-20 05:15:53 -07:00
|
|
|
// calls InvalidateBounds) or nsSVGDisplayContainerFrame::InsertFrames
|
|
|
|
// (at which point the frame has no observers).
|
2008-09-30 17:51:05 -07:00
|
|
|
|
2013-07-12 00:13:07 -07:00
|
|
|
if (aFrame->GetStateBits() & NS_FRAME_IS_NONDISPLAY) {
|
2008-04-08 05:51:19 -07:00
|
|
|
return;
|
2012-02-04 05:58:46 -08:00
|
|
|
}
|
|
|
|
|
2012-03-20 05:15:53 -07:00
|
|
|
if (aFrame->GetStateBits() &
|
|
|
|
(NS_FRAME_IS_DIRTY | NS_FRAME_FIRST_REFLOW)) {
|
|
|
|
// Nothing to do if we're already dirty, or if the outer-<svg>
|
|
|
|
// hasn't yet had its initial reflow.
|
2012-02-04 05:58:46 -08:00
|
|
|
return;
|
2012-03-20 05:15:53 -07:00
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
nsSVGOuterSVGFrame *outerSVGFrame = nullptr;
|
2012-03-20 05:15:53 -07:00
|
|
|
|
|
|
|
// We must not add dirty bits to the nsSVGOuterSVGFrame or else
|
|
|
|
// PresShell::FrameNeedsReflow won't work when we pass it in below.
|
|
|
|
if (aFrame->GetStateBits() & NS_STATE_IS_OUTER_SVG) {
|
|
|
|
outerSVGFrame = static_cast<nsSVGOuterSVGFrame*>(aFrame);
|
|
|
|
} else {
|
|
|
|
aFrame->AddStateBits(NS_FRAME_IS_DIRTY);
|
|
|
|
|
|
|
|
nsIFrame *f = aFrame->GetParent();
|
|
|
|
while (f && !(f->GetStateBits() & NS_STATE_IS_OUTER_SVG)) {
|
|
|
|
if (f->GetStateBits() &
|
|
|
|
(NS_FRAME_IS_DIRTY | NS_FRAME_HAS_DIRTY_CHILDREN)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
f->AddStateBits(NS_FRAME_HAS_DIRTY_CHILDREN);
|
|
|
|
f = f->GetParent();
|
|
|
|
NS_ABORT_IF_FALSE(f->IsFrameOfType(nsIFrame::eSVG),
|
|
|
|
"NS_STATE_IS_OUTER_SVG check above not valid!");
|
|
|
|
}
|
|
|
|
|
|
|
|
outerSVGFrame = static_cast<nsSVGOuterSVGFrame*>(f);
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(outerSVGFrame &&
|
|
|
|
outerSVGFrame->GetType() == nsGkAtoms::svgOuterSVGFrame,
|
|
|
|
"Did not find nsSVGOuterSVGFrame!");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (outerSVGFrame->GetStateBits() & NS_FRAME_IN_REFLOW) {
|
|
|
|
// We're currently under an nsSVGOuterSVGFrame::Reflow call so there is no
|
|
|
|
// need to call PresShell::FrameNeedsReflow, since we have an
|
|
|
|
// nsSVGOuterSVGFrame::DidReflow call pending.
|
2008-04-08 05:51:19 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-20 05:15:53 -07:00
|
|
|
nsFrameState dirtyBit =
|
|
|
|
(outerSVGFrame == aFrame ? NS_FRAME_IS_DIRTY : NS_FRAME_HAS_DIRTY_CHILDREN);
|
2008-04-08 05:51:19 -07:00
|
|
|
|
2012-03-20 05:15:53 -07:00
|
|
|
aFrame->PresContext()->PresShell()->FrameNeedsReflow(
|
|
|
|
outerSVGFrame, nsIPresShell::eResize, dirtyBit);
|
|
|
|
}
|
2012-02-04 05:58:46 -08:00
|
|
|
|
2012-03-20 05:15:53 -07:00
|
|
|
bool
|
2012-07-21 17:01:44 -07:00
|
|
|
nsSVGUtils::NeedsReflowSVG(nsIFrame *aFrame)
|
2012-03-20 05:15:53 -07:00
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aFrame->IsFrameOfType(nsIFrame::eSVG),
|
|
|
|
"SVG uses bits differently!");
|
|
|
|
|
|
|
|
// The flags we test here may change, hence why we have this separate
|
|
|
|
// function.
|
|
|
|
return NS_SUBTREE_DIRTY(aFrame);
|
2008-04-08 05:51:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-03-19 14:27:33 -07:00
|
|
|
nsSVGUtils::NotifyAncestorsOfFilterRegionChange(nsIFrame *aFrame)
|
|
|
|
{
|
2012-02-04 05:58:46 -08:00
|
|
|
NS_ABORT_IF_FALSE(!(aFrame->GetStateBits() & NS_STATE_IS_OUTER_SVG),
|
|
|
|
"Not expecting to be called on the outer SVG Frame");
|
2008-04-15 01:31:06 -07:00
|
|
|
|
2008-03-19 14:27:33 -07:00
|
|
|
aFrame = aFrame->GetParent();
|
|
|
|
|
|
|
|
while (aFrame) {
|
|
|
|
if (aFrame->GetStateBits() & NS_STATE_IS_OUTER_SVG)
|
|
|
|
return;
|
|
|
|
|
2008-08-07 18:34:43 -07:00
|
|
|
nsSVGFilterProperty *property = nsSVGEffects::GetFilterProperty(aFrame);
|
2008-08-05 17:25:33 -07:00
|
|
|
if (property) {
|
2008-03-19 14:27:33 -07:00
|
|
|
property->Invalidate();
|
|
|
|
}
|
|
|
|
aFrame = aFrame->GetParent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
float
|
2009-06-11 08:21:03 -07:00
|
|
|
nsSVGUtils::ObjectSpace(const gfxRect &aRect, const nsSVGLength2 *aLength)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-06-30 13:21:31 -07:00
|
|
|
float axis;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
switch (aLength->GetCtxType()) {
|
2012-09-22 12:26:05 -07:00
|
|
|
case SVGContentUtils::X:
|
2009-06-11 08:21:03 -07:00
|
|
|
axis = aRect.Width();
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2012-09-22 12:26:05 -07:00
|
|
|
case SVGContentUtils::Y:
|
2009-06-11 08:21:03 -07:00
|
|
|
axis = aRect.Height();
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2012-09-22 12:26:05 -07:00
|
|
|
case SVGContentUtils::XY:
|
|
|
|
axis = float(SVGContentUtils::ComputeNormalizedHypotenuse(
|
|
|
|
aRect.Width(), aRect.Height()));
|
2009-12-12 22:27:30 -08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("unexpected ctx type");
|
|
|
|
axis = 0.0f;
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-01-25 01:27:03 -08:00
|
|
|
if (aLength->IsPercentage()) {
|
2012-06-30 13:21:31 -07:00
|
|
|
// Multiply first to avoid precision errors:
|
|
|
|
return axis * aLength->GetAnimValInSpecifiedUnits() / 100;
|
2009-12-12 22:27:30 -08:00
|
|
|
}
|
2013-01-09 15:02:45 -08:00
|
|
|
return aLength->GetAnimValue(static_cast<SVGSVGElement*>(nullptr)) * axis;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
float
|
2008-09-10 17:24:16 -07:00
|
|
|
nsSVGUtils::UserSpace(nsSVGElement *aSVGElement, const nsSVGLength2 *aLength)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return aLength->GetAnimValue(aSVGElement);
|
|
|
|
}
|
|
|
|
|
2008-09-10 17:24:16 -07:00
|
|
|
float
|
|
|
|
nsSVGUtils::UserSpace(nsIFrame *aNonSVGContext, const nsSVGLength2 *aLength)
|
|
|
|
{
|
|
|
|
return aLength->GetAnimValue(aNonSVGContext);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSVGOuterSVGFrame *
|
|
|
|
nsSVGUtils::GetOuterSVGFrame(nsIFrame *aFrame)
|
|
|
|
{
|
|
|
|
while (aFrame) {
|
|
|
|
if (aFrame->GetStateBits() & NS_STATE_IS_OUTER_SVG) {
|
2007-07-08 00:08:04 -07:00
|
|
|
return static_cast<nsSVGOuterSVGFrame*>(aFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
aFrame = aFrame->GetParent();
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-05-30 15:32:54 -07:00
|
|
|
nsIFrame*
|
|
|
|
nsSVGUtils::GetOuterSVGFrameAndCoveredRegion(nsIFrame* aFrame, nsRect* aRect)
|
|
|
|
{
|
2009-01-12 11:20:59 -08:00
|
|
|
nsISVGChildFrame* svg = do_QueryFrame(aFrame);
|
2007-05-30 15:32:54 -07:00
|
|
|
if (!svg)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2013-07-12 00:13:07 -07:00
|
|
|
*aRect = (aFrame->GetStateBits() & NS_FRAME_IS_NONDISPLAY) ?
|
2010-12-29 02:29:54 -08:00
|
|
|
nsRect(0, 0, 0, 0) : svg->GetCoveredRegion();
|
2007-05-30 15:32:54 -07:00
|
|
|
return GetOuterSVGFrame(aFrame);
|
|
|
|
}
|
|
|
|
|
2009-04-28 21:31:34 -07:00
|
|
|
gfxMatrix
|
2013-09-11 00:27:45 -07:00
|
|
|
nsSVGUtils::GetCanvasTM(nsIFrame *aFrame, uint32_t aFor,
|
|
|
|
nsIFrame* aTransformRoot)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-04-28 21:31:34 -07:00
|
|
|
// XXX yuck, we really need a common interface for GetCanvasTM
|
|
|
|
|
|
|
|
if (!aFrame->IsFrameOfType(nsIFrame::eSVG)) {
|
2012-06-20 17:29:50 -07:00
|
|
|
return nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(aFrame);
|
2009-04-28 21:31:34 -07:00
|
|
|
}
|
2008-09-10 17:24:16 -07:00
|
|
|
|
2013-09-11 00:27:45 -07:00
|
|
|
if (!(aFrame->GetStateBits() & NS_FRAME_IS_NONDISPLAY) &&
|
|
|
|
!aTransformRoot) {
|
2012-06-30 04:20:46 -07:00
|
|
|
if ((aFor == nsISVGChildFrame::FOR_PAINTING &&
|
|
|
|
NS_SVGDisplayListPaintingEnabled()) ||
|
|
|
|
(aFor == nsISVGChildFrame::FOR_HIT_TESTING &&
|
|
|
|
NS_SVGDisplayListHitTestingEnabled())) {
|
|
|
|
return nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(aFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-04 04:55:28 -08:00
|
|
|
nsIAtom* type = aFrame->GetType();
|
2009-04-28 21:31:34 -07:00
|
|
|
if (type == nsGkAtoms::svgForeignObjectFrame) {
|
2013-09-11 00:27:45 -07:00
|
|
|
return static_cast<nsSVGForeignObjectFrame*>(aFrame)->
|
|
|
|
GetCanvasTM(aFor, aTransformRoot);
|
2009-04-28 21:31:34 -07:00
|
|
|
}
|
2012-07-17 12:44:39 -07:00
|
|
|
if (type == nsGkAtoms::svgOuterSVGFrame) {
|
|
|
|
return nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(aFrame);
|
|
|
|
}
|
2009-04-28 21:31:34 -07:00
|
|
|
|
|
|
|
nsSVGContainerFrame *containerFrame = do_QueryFrame(aFrame);
|
|
|
|
if (containerFrame) {
|
2013-09-11 00:27:45 -07:00
|
|
|
return containerFrame->GetCanvasTM(aFor, aTransformRoot);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-09-11 00:27:45 -07:00
|
|
|
return static_cast<nsSVGGeometryFrame*>(aFrame)->
|
|
|
|
GetCanvasTM(aFor, aTransformRoot);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-06-26 03:49:23 -07:00
|
|
|
gfxMatrix
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSVGUtils::GetUserToCanvasTM(nsIFrame *aFrame, uint32_t aFor)
|
2012-06-26 03:49:23 -07:00
|
|
|
{
|
2012-06-30 04:20:46 -07:00
|
|
|
NS_ASSERTION(aFor == nsISVGChildFrame::FOR_OUTERSVG_TM,
|
|
|
|
"Unexpected aFor?");
|
|
|
|
|
2012-06-26 03:49:23 -07:00
|
|
|
nsISVGChildFrame* svgFrame = do_QueryFrame(aFrame);
|
|
|
|
NS_ASSERTION(svgFrame, "bad frame");
|
|
|
|
|
|
|
|
gfxMatrix tm;
|
|
|
|
if (svgFrame) {
|
|
|
|
nsSVGElement *content = static_cast<nsSVGElement*>(aFrame->GetContent());
|
2012-06-30 04:20:46 -07:00
|
|
|
tm = content->PrependLocalTransformsTo(
|
|
|
|
GetCanvasTM(aFrame->GetParent(), aFor),
|
|
|
|
nsSVGElement::eUserSpaceToParent);
|
2012-06-26 03:49:23 -07:00
|
|
|
}
|
|
|
|
return tm;
|
|
|
|
}
|
|
|
|
|
2007-12-20 06:26:34 -08:00
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSVGUtils::NotifyChildrenOfSVGChange(nsIFrame *aFrame, uint32_t aFlags)
|
2007-12-20 06:26:34 -08:00
|
|
|
{
|
2011-08-24 13:54:30 -07:00
|
|
|
nsIFrame *kid = aFrame->GetFirstPrincipalChild();
|
2007-12-20 06:26:34 -08:00
|
|
|
|
2010-01-13 03:09:58 -08:00
|
|
|
while (kid) {
|
|
|
|
nsISVGChildFrame* SVGFrame = do_QueryFrame(kid);
|
2007-12-20 06:26:34 -08:00
|
|
|
if (SVGFrame) {
|
2008-01-25 01:27:03 -08:00
|
|
|
SVGFrame->NotifySVGChanged(aFlags);
|
2007-12-20 06:26:34 -08:00
|
|
|
} else {
|
2012-08-22 18:23:23 -07:00
|
|
|
NS_ASSERTION(kid->IsFrameOfType(nsIFrame::eSVG) || kid->IsSVGText(),
|
|
|
|
"SVG frame expected");
|
2007-12-20 06:26:34 -08:00
|
|
|
// recurse into the children of container frames e.g. <clipPath>, <mask>
|
|
|
|
// in case they have child frames with transformation matrices
|
2012-08-22 18:23:23 -07:00
|
|
|
if (kid->IsFrameOfType(nsIFrame::eSVG)) {
|
|
|
|
NotifyChildrenOfSVGChange(kid, aFlags);
|
|
|
|
}
|
2007-12-20 06:26:34 -08:00
|
|
|
}
|
2010-01-13 03:09:58 -08:00
|
|
|
kid = kid->GetNextSibling();
|
2007-12-20 06:26:34 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// ************************************************************
|
|
|
|
|
2008-09-10 17:24:16 -07:00
|
|
|
class SVGPaintCallback : public nsSVGFilterPaintCallback
|
|
|
|
{
|
|
|
|
public:
|
2012-03-02 00:28:59 -08:00
|
|
|
virtual void Paint(nsRenderingContext *aContext, nsIFrame *aTarget,
|
2013-09-11 00:27:45 -07:00
|
|
|
const nsIntRect* aDirtyRect, nsIFrame* aTransformRoot)
|
2008-09-10 17:24:16 -07:00
|
|
|
{
|
2009-01-12 11:20:59 -08:00
|
|
|
nsISVGChildFrame *svgChildFrame = do_QueryFrame(aTarget);
|
2008-09-10 17:24:16 -07:00
|
|
|
NS_ASSERTION(svgChildFrame, "Expected SVG frame here");
|
2008-10-16 00:55:10 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIntRect* dirtyRect = nullptr;
|
2008-10-16 00:55:10 -07:00
|
|
|
nsIntRect tmpDirtyRect;
|
|
|
|
|
|
|
|
// aDirtyRect is in user-space pixels, we need to convert to
|
|
|
|
// outer-SVG-frame-relative device pixels.
|
|
|
|
if (aDirtyRect) {
|
2012-06-30 04:20:46 -07:00
|
|
|
gfxMatrix userToDeviceSpace =
|
2013-09-11 00:27:45 -07:00
|
|
|
nsSVGUtils::GetCanvasTM(aTarget, nsISVGChildFrame::FOR_PAINTING, aTransformRoot);
|
2009-04-28 21:31:34 -07:00
|
|
|
if (userToDeviceSpace.IsSingular()) {
|
|
|
|
return;
|
|
|
|
}
|
2009-02-09 16:54:28 -08:00
|
|
|
gfxRect dirtyBounds = userToDeviceSpace.TransformBounds(
|
2008-10-16 00:55:10 -07:00
|
|
|
gfxRect(aDirtyRect->x, aDirtyRect->y, aDirtyRect->width, aDirtyRect->height));
|
|
|
|
dirtyBounds.RoundOut();
|
2010-11-24 01:35:21 -08:00
|
|
|
if (gfxUtils::GfxRectToIntRect(dirtyBounds, &tmpDirtyRect)) {
|
2008-10-16 00:55:10 -07:00
|
|
|
dirtyRect = &tmpDirtyRect;
|
|
|
|
}
|
2008-09-10 17:24:16 -07:00
|
|
|
}
|
|
|
|
|
2013-09-11 00:27:45 -07:00
|
|
|
svgChildFrame->PaintSVG(aContext, dirtyRect, aTransformRoot);
|
2008-09-10 17:24:16 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
2012-03-02 00:28:59 -08:00
|
|
|
nsSVGUtils::PaintFrameWithEffects(nsRenderingContext *aContext,
|
2008-10-20 01:42:03 -07:00
|
|
|
const nsIntRect *aDirtyRect,
|
2013-09-11 00:27:45 -07:00
|
|
|
nsIFrame *aFrame,
|
|
|
|
nsIFrame *aTransformRoot)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-20 11:12:29 -07:00
|
|
|
NS_ASSERTION(!NS_SVGDisplayListPaintingEnabled() ||
|
2013-07-12 00:13:07 -07:00
|
|
|
(aFrame->GetStateBits() & NS_FRAME_IS_NONDISPLAY) ||
|
2012-09-05 21:58:47 -07:00
|
|
|
aFrame->PresContext()->IsGlyph(),
|
2012-07-20 11:12:29 -07:00
|
|
|
"If display lists are enabled, only painting of non-display "
|
|
|
|
"SVG should take this code path");
|
|
|
|
|
2009-01-12 11:20:59 -08:00
|
|
|
nsISVGChildFrame *svgChildFrame = do_QueryFrame(aFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!svgChildFrame)
|
|
|
|
return;
|
|
|
|
|
2013-02-16 13:51:02 -08:00
|
|
|
float opacity = aFrame->StyleDisplay()->mOpacity;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (opacity == 0.0f)
|
|
|
|
return;
|
|
|
|
|
2012-03-03 01:21:09 -08:00
|
|
|
const nsIContent* content = aFrame->GetContent();
|
|
|
|
if (content->IsSVG() &&
|
|
|
|
!static_cast<const nsSVGElement*>(content)->HasValidDimensions()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-18 04:21:24 -07:00
|
|
|
/* Properties are added lazily and may have been removed by a restyle,
|
|
|
|
so make sure all applicable ones are set again. */
|
|
|
|
|
|
|
|
nsSVGEffects::EffectProperties effectProperties =
|
|
|
|
nsSVGEffects::GetEffectProperties(aFrame);
|
|
|
|
|
|
|
|
bool isOK = true;
|
|
|
|
nsSVGFilterFrame *filterFrame = effectProperties.GetFilterFrame(&isOK);
|
|
|
|
|
2012-05-16 21:05:09 -07:00
|
|
|
if (aDirtyRect &&
|
2013-07-12 00:13:07 -07:00
|
|
|
!(aFrame->GetStateBits() & NS_FRAME_IS_NONDISPLAY)) {
|
2012-05-16 21:05:09 -07:00
|
|
|
// Here we convert aFrame's paint bounds to outer-<svg> device space,
|
|
|
|
// compare it to aDirtyRect, and return early if they don't intersect.
|
|
|
|
// We don't do this optimization for nondisplay SVG since nondisplay
|
|
|
|
// SVG doesn't maintain bounds/overflow rects.
|
|
|
|
nsRect overflowRect = aFrame->GetVisualOverflowRectRelativeToSelf();
|
2013-02-10 22:22:17 -08:00
|
|
|
if (aFrame->IsFrameOfType(nsIFrame::eSVGGeometry) ||
|
|
|
|
aFrame->IsSVGText()) {
|
2012-05-16 21:05:09 -07:00
|
|
|
// Unlike containers, leaf frames do not include GetPosition() in
|
|
|
|
// GetCanvasTM().
|
|
|
|
overflowRect = overflowRect + aFrame->GetPosition();
|
|
|
|
}
|
2013-02-19 13:46:27 -08:00
|
|
|
int32_t appUnitsPerDevPx = aFrame->PresContext()->AppUnitsPerDevPixel();
|
2013-09-11 00:27:45 -07:00
|
|
|
gfxMatrix tm = GetCanvasTM(aFrame, nsISVGChildFrame::FOR_PAINTING, aTransformRoot);
|
2012-05-16 21:05:09 -07:00
|
|
|
if (aFrame->IsFrameOfType(nsIFrame::eSVG | nsIFrame::eSVGContainer)) {
|
|
|
|
gfxMatrix childrenOnlyTM;
|
|
|
|
if (static_cast<nsSVGContainerFrame*>(aFrame)->
|
|
|
|
HasChildrenOnlyTransform(&childrenOnlyTM)) {
|
|
|
|
// Undo the children-only transform:
|
|
|
|
tm = childrenOnlyTM.Invert() * tm;
|
|
|
|
}
|
|
|
|
}
|
2012-09-22 12:26:05 -07:00
|
|
|
nsIntRect bounds = TransformFrameRectToOuterSVG(overflowRect,
|
2012-05-16 21:05:09 -07:00
|
|
|
tm, aFrame->PresContext()).
|
|
|
|
ToOutsidePixels(appUnitsPerDevPx);
|
|
|
|
if (!aDirtyRect->Intersects(bounds)) {
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* SVG defines the following rendering model:
|
|
|
|
*
|
2009-10-26 10:17:49 -07:00
|
|
|
* 1. Render fill
|
|
|
|
* 2. Render stroke
|
|
|
|
* 3. Render markers
|
|
|
|
* 4. Apply filter
|
|
|
|
* 5. Apply clipping, masking, group opacity
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
2007-04-26 01:36:16 -07:00
|
|
|
* We follow this, but perform a couple of optimizations:
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* + Use cairo's clipPath when representable natively (single object
|
|
|
|
* clip region).
|
|
|
|
*
|
|
|
|
* + Merge opacity and masking if both used together.
|
|
|
|
*/
|
|
|
|
|
2007-04-26 01:36:16 -07:00
|
|
|
if (opacity != 1.0f && CanOptimizeOpacity(aFrame))
|
|
|
|
opacity = 1.0f;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-02 00:28:59 -08:00
|
|
|
gfxContext *gfx = aContext->ThebesContext();
|
2011-09-28 23:19:26 -07:00
|
|
|
bool complexEffects = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-09-30 17:51:05 -07:00
|
|
|
nsSVGClipPathFrame *clipPathFrame = effectProperties.GetClipPathFrame(&isOK);
|
|
|
|
nsSVGMaskFrame *maskFrame = effectProperties.GetMaskFrame(&isOK);
|
2007-04-26 01:36:16 -07:00
|
|
|
|
2012-05-18 04:21:24 -07:00
|
|
|
bool isTrivialClip = clipPathFrame ? clipPathFrame->IsTrivial() : true;
|
|
|
|
|
2008-08-05 17:25:33 -07:00
|
|
|
if (!isOK) {
|
2010-12-19 09:47:01 -08:00
|
|
|
// Some resource is invalid. We shouldn't paint anything.
|
2008-08-05 17:25:33 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-07-23 01:35:59 -07:00
|
|
|
gfxMatrix matrix;
|
|
|
|
if (clipPathFrame || maskFrame)
|
2013-09-11 00:27:45 -07:00
|
|
|
matrix = GetCanvasTM(aFrame, nsISVGChildFrame::FOR_PAINTING, aTransformRoot);
|
2007-04-26 01:36:16 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* Check if we need to do additional operations on this child's
|
|
|
|
* rendering, which necessitates rendering into another surface. */
|
2013-09-14 20:40:11 -07:00
|
|
|
if (opacity != 1.0f || maskFrame || (clipPathFrame && !isTrivialClip)
|
|
|
|
|| aFrame->StyleDisplay()->mMixBlendMode != NS_STYLE_BLEND_NORMAL) {
|
2011-10-17 07:59:28 -07:00
|
|
|
complexEffects = true;
|
2007-05-22 12:31:04 -07:00
|
|
|
gfx->Save();
|
2013-07-12 00:13:07 -07:00
|
|
|
if (!(aFrame->GetStateBits() & NS_FRAME_IS_NONDISPLAY)) {
|
2012-06-20 02:02:43 -07:00
|
|
|
// aFrame has a valid visual overflow rect, so clip to it before calling
|
|
|
|
// PushGroup() to minimize the size of the surfaces we'll composite:
|
|
|
|
gfxContextMatrixAutoSaveRestore matrixAutoSaveRestore(gfx);
|
2013-09-11 00:27:45 -07:00
|
|
|
gfx->Multiply(GetCanvasTM(aFrame, nsISVGChildFrame::FOR_PAINTING, aTransformRoot));
|
2012-06-20 02:02:43 -07:00
|
|
|
nsRect overflowRect = aFrame->GetVisualOverflowRectRelativeToSelf();
|
2013-02-10 22:22:17 -08:00
|
|
|
if (aFrame->IsFrameOfType(nsIFrame::eSVGGeometry) ||
|
|
|
|
aFrame->IsSVGText()) {
|
2012-06-20 02:02:43 -07:00
|
|
|
// Unlike containers, leaf frames do not include GetPosition() in
|
|
|
|
// GetCanvasTM().
|
|
|
|
overflowRect = overflowRect + aFrame->GetPosition();
|
|
|
|
}
|
|
|
|
aContext->IntersectClip(overflowRect);
|
|
|
|
}
|
2013-09-24 13:45:13 -07:00
|
|
|
gfx->PushGroup(GFX_CONTENT_COLOR_ALPHA);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If this frame has only a trivial clipPath, set up cairo's clipping now so
|
|
|
|
* we can just do normal painting and get it clipped appropriately.
|
|
|
|
*/
|
2007-04-26 01:36:16 -07:00
|
|
|
if (clipPathFrame && isTrivialClip) {
|
2007-03-22 10:30:00 -07:00
|
|
|
gfx->Save();
|
2008-09-10 17:24:16 -07:00
|
|
|
clipPathFrame->ClipPaint(aContext, aFrame, matrix);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Paint the child */
|
2007-04-26 01:36:16 -07:00
|
|
|
if (filterFrame) {
|
2012-07-30 07:20:58 -07:00
|
|
|
nsRect* dirtyRect = nullptr;
|
2012-06-26 03:49:23 -07:00
|
|
|
nsRect tmpDirtyRect;
|
|
|
|
if (aDirtyRect) {
|
|
|
|
// aDirtyRect is in outer-<svg> device pixels, but the filter code needs
|
|
|
|
// it in frame space.
|
2012-06-30 04:20:46 -07:00
|
|
|
gfxMatrix userToDeviceSpace =
|
|
|
|
GetUserToCanvasTM(aFrame, nsISVGChildFrame::FOR_OUTERSVG_TM);
|
2012-06-26 03:49:23 -07:00
|
|
|
if (userToDeviceSpace.IsSingular()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
gfxMatrix deviceToUserSpace = userToDeviceSpace;
|
|
|
|
deviceToUserSpace.Invert();
|
|
|
|
gfxRect dirtyBounds = deviceToUserSpace.TransformBounds(
|
|
|
|
gfxRect(aDirtyRect->x, aDirtyRect->y,
|
|
|
|
aDirtyRect->width, aDirtyRect->height));
|
|
|
|
tmpDirtyRect =
|
|
|
|
nsLayoutUtils::RoundGfxRectToAppRect(
|
|
|
|
dirtyBounds, aFrame->PresContext()->AppUnitsPerCSSPixel()) -
|
|
|
|
aFrame->GetPosition();
|
|
|
|
dirtyRect = &tmpDirtyRect;
|
|
|
|
}
|
2008-09-10 17:24:16 -07:00
|
|
|
SVGPaintCallback paintCallback;
|
2013-09-11 00:27:45 -07:00
|
|
|
filterFrame->PaintFilteredFrame(aContext, aFrame, &paintCallback, dirtyRect, aTransformRoot);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2013-09-11 00:27:45 -07:00
|
|
|
svgChildFrame->PaintSVG(aContext, aDirtyRect, aTransformRoot);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-04-26 01:36:16 -07:00
|
|
|
if (clipPathFrame && isTrivialClip) {
|
2007-03-22 10:30:00 -07:00
|
|
|
gfx->Restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No more effects, we're done. */
|
2007-05-22 12:31:04 -07:00
|
|
|
if (!complexEffects)
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
|
2007-05-22 12:31:04 -07:00
|
|
|
gfx->PopGroupToSource();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-05-22 12:31:04 -07:00
|
|
|
nsRefPtr<gfxPattern> maskSurface =
|
2008-09-10 17:24:16 -07:00
|
|
|
maskFrame ? maskFrame->ComputeMaskAlpha(aContext, aFrame,
|
2012-07-30 07:20:58 -07:00
|
|
|
matrix, opacity) : nullptr;
|
2007-04-26 01:36:16 -07:00
|
|
|
|
2007-05-22 12:31:04 -07:00
|
|
|
nsRefPtr<gfxPattern> clipMaskSurface;
|
2007-04-26 01:36:16 -07:00
|
|
|
if (clipPathFrame && !isTrivialClip) {
|
2013-09-24 13:45:13 -07:00
|
|
|
gfx->PushGroup(GFX_CONTENT_COLOR_ALPHA);
|
2007-04-26 01:36:16 -07:00
|
|
|
|
2008-09-10 17:24:16 -07:00
|
|
|
nsresult rv = clipPathFrame->ClipPaint(aContext, aFrame, matrix);
|
2007-05-22 12:31:04 -07:00
|
|
|
clipMaskSurface = gfx->PopGroup();
|
2007-04-26 01:36:16 -07:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && clipMaskSurface) {
|
|
|
|
// Still more set after clipping, so clip to another surface
|
|
|
|
if (maskSurface || opacity != 1.0f) {
|
2013-09-24 13:45:13 -07:00
|
|
|
gfx->PushGroup(GFX_CONTENT_COLOR_ALPHA);
|
2007-05-22 12:31:04 -07:00
|
|
|
gfx->Mask(clipMaskSurface);
|
|
|
|
gfx->PopGroupToSource();
|
2007-04-26 01:36:16 -07:00
|
|
|
} else {
|
2007-05-22 12:31:04 -07:00
|
|
|
gfx->Mask(clipMaskSurface);
|
2007-04-26 01:36:16 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (maskSurface) {
|
2007-05-22 12:31:04 -07:00
|
|
|
gfx->Mask(maskSurface);
|
2007-04-26 01:36:16 -07:00
|
|
|
} else if (opacity != 1.0f) {
|
2007-05-22 12:31:04 -07:00
|
|
|
gfx->Paint(opacity);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-05-22 12:31:04 -07:00
|
|
|
gfx->Restore();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2008-08-25 02:23:54 -07:00
|
|
|
nsSVGUtils::HitTestClip(nsIFrame *aFrame, const nsPoint &aPoint)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-08-07 18:34:43 -07:00
|
|
|
nsSVGEffects::EffectProperties props =
|
|
|
|
nsSVGEffects::GetEffectProperties(aFrame);
|
2008-08-05 17:25:33 -07:00
|
|
|
if (!props.mClipPath)
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-04-26 01:36:16 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isOK = true;
|
2010-03-02 01:31:07 -08:00
|
|
|
nsSVGClipPathFrame *clipPathFrame = props.GetClipPathFrame(&isOK);
|
|
|
|
if (!clipPathFrame || !isOK) {
|
2008-08-05 17:25:33 -07:00
|
|
|
// clipPath is not a valid resource, so nothing gets painted, so
|
|
|
|
// hit-testing must fail.
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-06-30 04:20:46 -07:00
|
|
|
return clipPathFrame->ClipHitTest(aFrame, GetCanvasTM(aFrame,
|
|
|
|
nsISVGChildFrame::FOR_HIT_TESTING), aPoint);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-08-25 02:23:54 -07:00
|
|
|
nsIFrame *
|
|
|
|
nsSVGUtils::HitTestChildren(nsIFrame *aFrame, const nsPoint &aPoint)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-10-02 09:31:45 -07:00
|
|
|
// Traverse the list in reverse order, so that if we get a hit we know that's
|
|
|
|
// the topmost frame that intersects the point; then we can just return it.
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIFrame* result = nullptr;
|
2011-08-24 13:54:30 -07:00
|
|
|
for (nsIFrame* current = aFrame->PrincipalChildList().LastChild();
|
2009-10-02 09:31:45 -07:00
|
|
|
current;
|
|
|
|
current = current->GetPrevSibling()) {
|
2009-01-12 11:20:59 -08:00
|
|
|
nsISVGChildFrame* SVGFrame = do_QueryFrame(current);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (SVGFrame) {
|
2012-03-07 02:50:36 -08:00
|
|
|
const nsIContent* content = current->GetContent();
|
|
|
|
if (content->IsSVG() &&
|
|
|
|
!static_cast<const nsSVGElement*>(content)->HasValidDimensions()) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-03-03 01:21:09 -08:00
|
|
|
result = SVGFrame->GetFrameForPoint(aPoint);
|
|
|
|
if (result)
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-25 02:23:54 -07:00
|
|
|
if (result && !HitTestClip(aFrame, aPoint))
|
2012-07-30 07:20:58 -07:00
|
|
|
result = nullptr;
|
2008-08-25 02:23:54 -07:00
|
|
|
|
|
|
|
return result;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
|
|
|
nsSVGUtils::GetCoveredRegion(const nsFrameList &aFrames)
|
|
|
|
{
|
|
|
|
nsRect rect;
|
|
|
|
|
|
|
|
for (nsIFrame* kid = aFrames.FirstChild();
|
|
|
|
kid;
|
|
|
|
kid = kid->GetNextSibling()) {
|
2009-01-12 11:20:59 -08:00
|
|
|
nsISVGChildFrame* child = do_QueryFrame(kid);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (child) {
|
|
|
|
nsRect childRect = child->GetCoveredRegion();
|
|
|
|
rect.UnionRect(rect, childRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2012-02-10 04:33:46 -08:00
|
|
|
nsPoint
|
|
|
|
nsSVGUtils::TransformOuterSVGPointToChildFrame(nsPoint aPoint,
|
|
|
|
const gfxMatrix& aFrameToCanvasTM,
|
|
|
|
nsPresContext* aPresContext)
|
|
|
|
{
|
2012-02-16 22:07:51 -08:00
|
|
|
NS_ABORT_IF_FALSE(!aFrameToCanvasTM.IsSingular(),
|
|
|
|
"Callers must not pass a singular matrix");
|
|
|
|
gfxMatrix canvasDevToFrameUserSpace = aFrameToCanvasTM;
|
|
|
|
canvasDevToFrameUserSpace.Invert();
|
2012-02-10 04:33:46 -08:00
|
|
|
gfxPoint devPt = gfxPoint(aPoint.x, aPoint.y) /
|
|
|
|
aPresContext->AppUnitsPerDevPixel();
|
2012-06-13 18:12:38 -07:00
|
|
|
gfxPoint userPt = canvasDevToFrameUserSpace.Transform(devPt);
|
|
|
|
gfxPoint appPt = (userPt * aPresContext->AppUnitsPerCSSPixel()).Round();
|
2012-02-10 04:33:46 -08:00
|
|
|
userPt.x = clamped(appPt.x, gfxFloat(nscoord_MIN), gfxFloat(nscoord_MAX));
|
|
|
|
userPt.y = clamped(appPt.y, gfxFloat(nscoord_MIN), gfxFloat(nscoord_MAX));
|
|
|
|
// now guaranteed to be safe:
|
|
|
|
return nsPoint(nscoord(userPt.x), nscoord(userPt.y));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
|
|
|
nsSVGUtils::TransformFrameRectToOuterSVG(const nsRect& aRect,
|
|
|
|
const gfxMatrix& aMatrix,
|
|
|
|
nsPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
gfxRect r(aRect.x, aRect.y, aRect.width, aRect.height);
|
|
|
|
r.Scale(1.0 / nsPresContext::AppUnitsPerCSSPixel());
|
|
|
|
return nsLayoutUtils::RoundGfxRectToAppRect(
|
|
|
|
aMatrix.TransformBounds(r), aPresContext->AppUnitsPerDevPixel());
|
|
|
|
}
|
|
|
|
|
2011-04-21 12:36:46 -07:00
|
|
|
gfxIntSize
|
|
|
|
nsSVGUtils::ConvertToSurfaceSize(const gfxSize& aSize,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool *aResultOverflows)
|
2011-04-21 12:36:46 -07:00
|
|
|
{
|
2011-10-26 01:52:11 -07:00
|
|
|
gfxIntSize surfaceSize(ClampToInt(ceil(aSize.width)), ClampToInt(ceil(aSize.height)));
|
2011-04-21 12:36:46 -07:00
|
|
|
|
2011-10-26 01:52:11 -07:00
|
|
|
*aResultOverflows = surfaceSize.width != ceil(aSize.width) ||
|
|
|
|
surfaceSize.height != ceil(aSize.height);
|
2011-04-21 12:36:46 -07:00
|
|
|
|
|
|
|
if (!gfxASurface::CheckSurfaceSize(surfaceSize)) {
|
2013-01-15 04:22:03 -08:00
|
|
|
surfaceSize.width = std::min(NS_SVG_OFFSCREEN_MAX_DIMENSION,
|
2011-04-21 12:36:46 -07:00
|
|
|
surfaceSize.width);
|
2013-01-15 04:22:03 -08:00
|
|
|
surfaceSize.height = std::min(NS_SVG_OFFSCREEN_MAX_DIMENSION,
|
2011-04-21 12:36:46 -07:00
|
|
|
surfaceSize.height);
|
2011-10-17 07:59:28 -07:00
|
|
|
*aResultOverflows = true;
|
2011-04-21 12:36:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return surfaceSize;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2009-07-23 01:35:59 -07:00
|
|
|
nsSVGUtils::HitTestRect(const gfxMatrix &aMatrix,
|
2007-03-22 10:30:00 -07:00
|
|
|
float aRX, float aRY, float aRWidth, float aRHeight,
|
|
|
|
float aX, float aY)
|
|
|
|
{
|
2012-06-14 20:02:27 -07:00
|
|
|
gfxRect rect(aRX, aRY, aRWidth, aRHeight);
|
|
|
|
if (rect.IsEmpty() || aMatrix.IsSingular()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-06-14 20:02:27 -07:00
|
|
|
gfxMatrix toRectSpace = aMatrix;
|
|
|
|
toRectSpace.Invert();
|
|
|
|
gfxPoint p = toRectSpace.Transform(gfxPoint(aX, aY));
|
|
|
|
return rect.x <= p.x && p.x <= rect.XMost() &&
|
|
|
|
rect.y <= p.y && p.y <= rect.YMost();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-06-17 13:51:40 -07:00
|
|
|
gfxRect
|
|
|
|
nsSVGUtils::GetClipRectForFrame(nsIFrame *aFrame,
|
|
|
|
float aX, float aY, float aWidth, float aHeight)
|
|
|
|
{
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleDisplay* disp = aFrame->StyleDisplay();
|
2009-06-17 13:51:40 -07:00
|
|
|
|
|
|
|
if (!(disp->mClipFlags & NS_STYLE_CLIP_RECT)) {
|
|
|
|
NS_ASSERTION(disp->mClipFlags == NS_STYLE_CLIP_AUTO,
|
|
|
|
"We don't know about this type of clip.");
|
|
|
|
return gfxRect(aX, aY, aWidth, aHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (disp->mOverflowX == NS_STYLE_OVERFLOW_HIDDEN ||
|
|
|
|
disp->mOverflowY == NS_STYLE_OVERFLOW_HIDDEN) {
|
|
|
|
|
|
|
|
nsIntRect clipPxRect =
|
|
|
|
disp->mClip.ToOutsidePixels(aFrame->PresContext()->AppUnitsPerDevPixel());
|
|
|
|
gfxRect clipRect =
|
|
|
|
gfxRect(clipPxRect.x, clipPxRect.y, clipPxRect.width, clipPxRect.height);
|
|
|
|
|
|
|
|
if (NS_STYLE_CLIP_RIGHT_AUTO & disp->mClipFlags) {
|
2011-04-18 20:07:21 -07:00
|
|
|
clipRect.width = aWidth - clipRect.X();
|
2009-06-17 13:51:40 -07:00
|
|
|
}
|
|
|
|
if (NS_STYLE_CLIP_BOTTOM_AUTO & disp->mClipFlags) {
|
2011-04-18 20:07:21 -07:00
|
|
|
clipRect.height = aHeight - clipRect.Y();
|
2009-06-17 13:51:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (disp->mOverflowX != NS_STYLE_OVERFLOW_HIDDEN) {
|
2011-04-18 20:07:21 -07:00
|
|
|
clipRect.x = aX;
|
|
|
|
clipRect.width = aWidth;
|
2009-06-17 13:51:40 -07:00
|
|
|
}
|
|
|
|
if (disp->mOverflowY != NS_STYLE_OVERFLOW_HIDDEN) {
|
2011-04-18 20:07:21 -07:00
|
|
|
clipRect.y = aY;
|
|
|
|
clipRect.height = aHeight;
|
2009-06-17 13:51:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return clipRect;
|
|
|
|
}
|
|
|
|
return gfxRect(aX, aY, aWidth, aHeight);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsSVGUtils::CompositeSurfaceMatrix(gfxContext *aContext,
|
|
|
|
gfxASurface *aSurface,
|
2009-07-23 01:35:59 -07:00
|
|
|
const gfxMatrix &aCTM, float aOpacity)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-07-23 01:35:59 -07:00
|
|
|
if (aCTM.IsSingular())
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
2012-01-04 23:17:52 -08:00
|
|
|
|
|
|
|
if (aContext->IsCairo()) {
|
|
|
|
aContext->Save();
|
|
|
|
aContext->Multiply(aCTM);
|
|
|
|
aContext->SetSource(aSurface);
|
|
|
|
aContext->Paint(aOpacity);
|
|
|
|
aContext->Restore();
|
|
|
|
} else {
|
|
|
|
DrawTarget *dt = aContext->GetDrawTarget();
|
|
|
|
Matrix oldMat = dt->GetTransform();
|
|
|
|
RefPtr<SourceSurface> surf =
|
|
|
|
gfxPlatform::GetPlatform()->GetSourceSurfaceForSurface(dt, aSurface);
|
2012-07-18 12:15:17 -07:00
|
|
|
dt->SetTransform(ToMatrix(aCTM) * oldMat);
|
2012-01-04 23:17:52 -08:00
|
|
|
|
|
|
|
gfxSize size = aSurface->GetSize();
|
|
|
|
NS_ASSERTION(size.width >= 0 && size.height >= 0, "Failure to get size for aSurface.");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-01-04 23:17:52 -08:00
|
|
|
gfxPoint pt = aSurface->GetDeviceOffset();
|
|
|
|
|
|
|
|
dt->FillRect(Rect(-pt.x, -pt.y, size.width, size.height),
|
|
|
|
SurfacePattern(surf, EXTEND_CLAMP,
|
|
|
|
Matrix(1.0f, 0, 0, 1.0f, -pt.x, -pt.y)),
|
|
|
|
DrawOptions(aOpacity));
|
|
|
|
|
|
|
|
dt->SetTransform(oldMat);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-03-05 22:51:13 -08:00
|
|
|
void
|
|
|
|
nsSVGUtils::CompositePatternMatrix(gfxContext *aContext,
|
|
|
|
gfxPattern *aPattern,
|
2009-07-23 01:35:59 -07:00
|
|
|
const gfxMatrix &aCTM, float aWidth, float aHeight, float aOpacity)
|
2008-03-05 22:51:13 -08:00
|
|
|
{
|
2009-07-23 01:35:59 -07:00
|
|
|
if (aCTM.IsSingular())
|
2008-03-05 22:51:13 -08:00
|
|
|
return;
|
|
|
|
|
|
|
|
aContext->Save();
|
2009-07-23 01:35:59 -07:00
|
|
|
SetClipRect(aContext, aCTM, gfxRect(0, 0, aWidth, aHeight));
|
|
|
|
aContext->Multiply(aCTM);
|
2008-03-05 22:51:13 -08:00
|
|
|
aContext->SetPattern(aPattern);
|
|
|
|
aContext->Paint(aOpacity);
|
|
|
|
aContext->Restore();
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsSVGUtils::SetClipRect(gfxContext *aContext,
|
2009-06-18 04:31:25 -07:00
|
|
|
const gfxMatrix &aCTM,
|
2009-06-17 13:51:40 -07:00
|
|
|
const gfxRect &aRect)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-06-18 04:31:25 -07:00
|
|
|
if (aCTM.IsSingular())
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
|
2012-06-14 20:02:27 -07:00
|
|
|
gfxContextMatrixAutoSaveRestore matrixAutoSaveRestore(aContext);
|
2009-06-18 04:31:25 -07:00
|
|
|
aContext->Multiply(aCTM);
|
2009-06-17 13:51:40 -07:00
|
|
|
aContext->Clip(aRect);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-07-13 18:21:25 -07:00
|
|
|
void
|
|
|
|
nsSVGUtils::ClipToGfxRect(nsIntRect* aRect, const gfxRect& aGfxRect)
|
|
|
|
{
|
|
|
|
gfxRect r = aGfxRect;
|
|
|
|
r.RoundOut();
|
|
|
|
gfxRect r2(aRect->x, aRect->y, aRect->width, aRect->height);
|
|
|
|
r = r.Intersect(r2);
|
2012-08-22 08:56:38 -07:00
|
|
|
*aRect = nsIntRect(int32_t(r.X()), int32_t(r.Y()),
|
|
|
|
int32_t(r.Width()), int32_t(r.Height()));
|
2008-07-13 18:21:25 -07:00
|
|
|
}
|
|
|
|
|
2009-06-11 08:21:03 -07:00
|
|
|
gfxRect
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSVGUtils::GetBBox(nsIFrame *aFrame, uint32_t aFlags)
|
2008-09-10 17:24:16 -07:00
|
|
|
{
|
2010-08-07 02:38:11 -07:00
|
|
|
if (aFrame->GetContent()->IsNodeOfType(nsINode::eTEXT)) {
|
|
|
|
aFrame = aFrame->GetParent();
|
|
|
|
}
|
2009-06-11 08:21:03 -07:00
|
|
|
gfxRect bbox;
|
2009-01-12 11:20:59 -08:00
|
|
|
nsISVGChildFrame *svg = do_QueryFrame(aFrame);
|
2012-08-10 04:13:44 -07:00
|
|
|
if (svg || aFrame->IsSVGText()) {
|
2010-08-07 02:38:11 -07:00
|
|
|
// It is possible to apply a gradient, pattern, clipping path, mask or
|
|
|
|
// filter to text. When one of these facilities is applied to text
|
2011-05-24 23:31:59 -07:00
|
|
|
// the bounding box is the entire text element in all
|
2010-08-07 02:38:11 -07:00
|
|
|
// cases.
|
2013-02-10 22:22:18 -08:00
|
|
|
if (aFrame->IsSVGText()) {
|
2012-08-10 04:13:44 -07:00
|
|
|
nsIFrame* ancestor = GetFirstNonAAncestorFrame(aFrame);
|
|
|
|
if (ancestor && ancestor->IsSVGText()) {
|
|
|
|
while (ancestor->GetType() != nsGkAtoms::svgTextFrame2) {
|
|
|
|
ancestor = ancestor->GetParent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
svg = do_QueryFrame(ancestor);
|
|
|
|
} else {
|
|
|
|
nsSVGTextContainerFrame* metrics = do_QueryFrame(
|
|
|
|
GetFirstNonAAncestorFrame(aFrame));
|
|
|
|
if (metrics) {
|
|
|
|
while (aFrame->GetType() != nsGkAtoms::svgTextFrame) {
|
|
|
|
aFrame = aFrame->GetParent();
|
|
|
|
}
|
|
|
|
svg = do_QueryFrame(aFrame);
|
2010-08-07 02:38:11 -07:00
|
|
|
}
|
|
|
|
}
|
2012-03-03 01:21:09 -08:00
|
|
|
nsIContent* content = aFrame->GetContent();
|
|
|
|
if (content->IsSVG() &&
|
|
|
|
!static_cast<const nsSVGElement*>(content)->HasValidDimensions()) {
|
|
|
|
return bbox;
|
|
|
|
}
|
2012-02-17 00:12:47 -08:00
|
|
|
gfxMatrix matrix;
|
|
|
|
if (aFrame->GetType() == nsGkAtoms::svgForeignObjectFrame) {
|
|
|
|
// The spec says getBBox "Returns the tight bounding box in *current user
|
|
|
|
// space*". So we should really be doing this for all elements, but that
|
|
|
|
// needs investigation to check that we won't break too much content.
|
2012-03-03 01:21:09 -08:00
|
|
|
NS_ABORT_IF_FALSE(content->IsSVG(), "bad cast");
|
|
|
|
nsSVGElement *element = static_cast<nsSVGElement*>(content);
|
2012-02-17 00:12:47 -08:00
|
|
|
matrix = element->PrependLocalTransformsTo(matrix,
|
|
|
|
nsSVGElement::eChildToUserSpace);
|
|
|
|
}
|
2012-04-16 01:23:48 -07:00
|
|
|
return svg->GetBBoxContribution(matrix, aFlags);
|
2008-09-10 17:24:16 -07:00
|
|
|
}
|
2012-04-16 01:23:48 -07:00
|
|
|
return nsSVGIntegrationUtils::GetSVGBBoxForNonSVGFrame(aFrame);
|
2008-09-10 17:24:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxRect
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSVGUtils::GetRelativeRect(uint16_t aUnits, const nsSVGLength2 *aXYWH,
|
2009-06-11 08:21:03 -07:00
|
|
|
const gfxRect &aBBox, nsIFrame *aFrame)
|
2008-09-10 17:24:16 -07:00
|
|
|
{
|
|
|
|
float x, y, width, height;
|
2013-02-17 18:14:02 -08:00
|
|
|
if (aUnits == SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
|
2009-06-11 08:21:03 -07:00
|
|
|
x = aBBox.X() + ObjectSpace(aBBox, &aXYWH[0]);
|
|
|
|
y = aBBox.Y() + ObjectSpace(aBBox, &aXYWH[1]);
|
2008-09-10 17:24:16 -07:00
|
|
|
width = ObjectSpace(aBBox, &aXYWH[2]);
|
|
|
|
height = ObjectSpace(aBBox, &aXYWH[3]);
|
|
|
|
} else {
|
2011-09-19 10:09:59 -07:00
|
|
|
x = UserSpace(aFrame, &aXYWH[0]);
|
|
|
|
y = UserSpace(aFrame, &aXYWH[1]);
|
|
|
|
width = UserSpace(aFrame, &aXYWH[2]);
|
|
|
|
height = UserSpace(aFrame, &aXYWH[3]);
|
2008-09-10 17:24:16 -07:00
|
|
|
}
|
|
|
|
return gfxRect(x, y, width, height);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSVGUtils::CanOptimizeOpacity(nsIFrame *aFrame)
|
|
|
|
{
|
2012-07-20 11:12:29 -07:00
|
|
|
if (!(aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT)) {
|
|
|
|
return false;
|
|
|
|
}
|
2009-10-26 10:17:49 -07:00
|
|
|
nsIAtom *type = aFrame->GetType();
|
|
|
|
if (type != nsGkAtoms::svgImageFrame &&
|
|
|
|
type != nsGkAtoms::svgPathGeometryFrame) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-10-26 10:17:49 -07:00
|
|
|
}
|
2013-07-22 15:08:33 -07:00
|
|
|
if (aFrame->StyleSVGReset()->SingleFilter()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-10-26 10:17:49 -07:00
|
|
|
}
|
|
|
|
// XXX The SVG WG is intending to allow fill, stroke and markers on <image>
|
|
|
|
if (type == nsGkAtoms::svgImageFrame) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2009-10-26 10:17:49 -07:00
|
|
|
}
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleSVG *style = aFrame->StyleSVG();
|
2013-07-11 23:39:38 -07:00
|
|
|
if (style->HasMarker()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-10-26 10:17:49 -07:00
|
|
|
}
|
|
|
|
if (style->mFill.mType == eStyleSVGPaintType_None ||
|
|
|
|
style->mFillOpacity <= 0 ||
|
2012-08-10 04:13:43 -07:00
|
|
|
!HasStroke(aFrame)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-10-02 07:57:47 -07:00
|
|
|
float
|
2009-07-23 01:35:59 -07:00
|
|
|
nsSVGUtils::MaxExpansion(const gfxMatrix &aMatrix)
|
2007-10-02 07:57:47 -07:00
|
|
|
{
|
|
|
|
// maximum expansion derivation from
|
|
|
|
// http://lists.cairographics.org/archives/cairo/2004-October/001980.html
|
2009-07-23 01:35:59 -07:00
|
|
|
// and also implemented in cairo_matrix_transformed_circle_major_axis
|
|
|
|
double a = aMatrix.xx;
|
|
|
|
double b = aMatrix.yx;
|
|
|
|
double c = aMatrix.xy;
|
|
|
|
double d = aMatrix.yy;
|
|
|
|
double f = (a * a + b * b + c * c + d * d) / 2;
|
|
|
|
double g = (a * a + b * b - c * c - d * d) / 2;
|
|
|
|
double h = a * c + b * d;
|
2007-10-02 07:57:47 -07:00
|
|
|
return sqrt(f + sqrt(g * g + h * h));
|
|
|
|
}
|
|
|
|
|
2009-07-23 01:35:59 -07:00
|
|
|
gfxMatrix
|
|
|
|
nsSVGUtils::AdjustMatrixForUnits(const gfxMatrix &aMatrix,
|
2007-12-03 20:40:52 -08:00
|
|
|
nsSVGEnum *aUnits,
|
2008-09-10 17:24:16 -07:00
|
|
|
nsIFrame *aFrame)
|
2007-12-03 20:40:52 -08:00
|
|
|
{
|
|
|
|
if (aFrame &&
|
2013-02-17 18:14:02 -08:00
|
|
|
aUnits->GetAnimValue() == SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
|
2009-06-11 08:21:03 -07:00
|
|
|
gfxRect bbox = GetBBox(aFrame);
|
2009-07-23 01:35:59 -07:00
|
|
|
return gfxMatrix().Scale(bbox.Width(), bbox.Height()) *
|
|
|
|
gfxMatrix().Translate(gfxPoint(bbox.X(), bbox.Y())) *
|
|
|
|
aMatrix;
|
2007-12-03 20:40:52 -08:00
|
|
|
}
|
2009-07-23 01:35:59 -07:00
|
|
|
return aMatrix;
|
2007-12-03 20:40:52 -08:00
|
|
|
}
|
|
|
|
|
2009-01-19 10:31:34 -08:00
|
|
|
nsIFrame*
|
|
|
|
nsSVGUtils::GetFirstNonAAncestorFrame(nsIFrame* aStartFrame)
|
|
|
|
{
|
|
|
|
for (nsIFrame *ancestorFrame = aStartFrame; ancestorFrame;
|
|
|
|
ancestorFrame = ancestorFrame->GetParent()) {
|
|
|
|
if (ancestorFrame->GetType() != nsGkAtoms::svgAFrame) {
|
|
|
|
return ancestorFrame;
|
|
|
|
}
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-01-19 10:31:34 -08:00
|
|
|
}
|
|
|
|
|
2012-05-18 01:34:25 -07:00
|
|
|
gfxMatrix
|
|
|
|
nsSVGUtils::GetStrokeTransform(nsIFrame *aFrame)
|
|
|
|
{
|
2013-06-16 04:05:39 -07:00
|
|
|
if (aFrame->GetContent()->IsNodeOfType(nsINode::eTEXT)) {
|
|
|
|
aFrame = aFrame->GetParent();
|
|
|
|
}
|
|
|
|
|
2013-02-16 13:51:02 -08:00
|
|
|
if (aFrame->StyleSVGReset()->mVectorEffect ==
|
2012-05-18 01:34:25 -07:00
|
|
|
NS_STYLE_VECTOR_EFFECT_NON_SCALING_STROKE) {
|
|
|
|
|
|
|
|
nsIContent *content = aFrame->GetContent();
|
|
|
|
NS_ABORT_IF_FALSE(content->IsSVG(), "bad cast");
|
|
|
|
|
|
|
|
// a non-scaling stroke is in the screen co-ordinate
|
|
|
|
// space rather so we need to invert the transform
|
|
|
|
// to the screen co-ordinate space to get there.
|
|
|
|
// See http://www.w3.org/TR/SVGTiny12/painting.html#NonScalingStroke
|
2012-09-22 12:26:05 -07:00
|
|
|
gfxMatrix transform = SVGContentUtils::GetCTM(
|
2012-05-18 01:34:25 -07:00
|
|
|
static_cast<nsSVGElement*>(content), true);
|
|
|
|
if (!transform.IsSingular()) {
|
|
|
|
return transform.Invert();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return gfxMatrix();
|
|
|
|
}
|
|
|
|
|
2011-09-05 10:53:34 -07:00
|
|
|
// The logic here comes from _cairo_stroke_style_max_distance_from_path
|
|
|
|
static gfxRect
|
|
|
|
PathExtentsToMaxStrokeExtents(const gfxRect& aPathExtents,
|
2012-08-10 04:13:44 -07:00
|
|
|
nsIFrame* aFrame,
|
|
|
|
double aStyleExpansionFactor,
|
2012-02-10 04:33:39 -08:00
|
|
|
const gfxMatrix& aMatrix)
|
2009-03-31 05:19:39 -07:00
|
|
|
{
|
2011-09-05 10:53:34 -07:00
|
|
|
double style_expansion =
|
2012-08-10 04:13:44 -07:00
|
|
|
aStyleExpansionFactor * nsSVGUtils::GetStrokeWidth(aFrame);
|
2009-03-31 05:19:39 -07:00
|
|
|
|
2012-05-18 01:34:25 -07:00
|
|
|
gfxMatrix matrix = aMatrix;
|
|
|
|
matrix.Multiply(nsSVGUtils::GetStrokeTransform(aFrame));
|
|
|
|
|
|
|
|
double dx = style_expansion * (fabs(matrix.xx) + fabs(matrix.xy));
|
|
|
|
double dy = style_expansion * (fabs(matrix.yy) + fabs(matrix.yx));
|
2009-03-31 05:19:39 -07:00
|
|
|
|
|
|
|
gfxRect strokeExtents = aPathExtents;
|
2011-04-18 20:07:51 -07:00
|
|
|
strokeExtents.Inflate(dx, dy);
|
2009-03-31 05:19:39 -07:00
|
|
|
return strokeExtents;
|
|
|
|
}
|
|
|
|
|
2011-09-05 10:53:34 -07:00
|
|
|
/*static*/ gfxRect
|
|
|
|
nsSVGUtils::PathExtentsToMaxStrokeExtents(const gfxRect& aPathExtents,
|
2012-02-10 04:33:39 -08:00
|
|
|
nsSVGGeometryFrame* aFrame,
|
|
|
|
const gfxMatrix& aMatrix)
|
2011-09-05 10:53:34 -07:00
|
|
|
{
|
2012-02-10 04:33:39 -08:00
|
|
|
return ::PathExtentsToMaxStrokeExtents(aPathExtents, aFrame, 0.5, aMatrix);
|
2011-09-05 10:53:34 -07:00
|
|
|
}
|
|
|
|
|
2012-08-10 04:13:44 -07:00
|
|
|
/*static*/ gfxRect
|
|
|
|
nsSVGUtils::PathExtentsToMaxStrokeExtents(const gfxRect& aPathExtents,
|
|
|
|
nsTextFrame* aFrame,
|
|
|
|
const gfxMatrix& aMatrix)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aFrame->IsSVGText(), "expected an nsTextFrame for SVG text");
|
|
|
|
return ::PathExtentsToMaxStrokeExtents(aPathExtents, aFrame, 0.5, aMatrix);
|
|
|
|
}
|
|
|
|
|
2011-09-05 10:53:34 -07:00
|
|
|
/*static*/ gfxRect
|
|
|
|
nsSVGUtils::PathExtentsToMaxStrokeExtents(const gfxRect& aPathExtents,
|
2012-02-10 04:33:39 -08:00
|
|
|
nsSVGPathGeometryFrame* aFrame,
|
|
|
|
const gfxMatrix& aMatrix)
|
2011-09-05 10:53:34 -07:00
|
|
|
{
|
|
|
|
double styleExpansionFactor = 0.5;
|
|
|
|
|
|
|
|
if (static_cast<nsSVGPathGeometryElement*>(aFrame->GetContent())->IsMarkable()) {
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleSVG* style = aFrame->StyleSVG();
|
2011-09-05 10:53:34 -07:00
|
|
|
|
|
|
|
if (style->mStrokeLinecap == NS_STYLE_STROKE_LINECAP_SQUARE) {
|
|
|
|
styleExpansionFactor = M_SQRT1_2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (style->mStrokeLinejoin == NS_STYLE_STROKE_LINEJOIN_MITER &&
|
|
|
|
styleExpansionFactor < style->mStrokeMiterlimit &&
|
|
|
|
aFrame->GetContent()->Tag() != nsGkAtoms::line) {
|
|
|
|
styleExpansionFactor = style->mStrokeMiterlimit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ::PathExtentsToMaxStrokeExtents(aPathExtents,
|
|
|
|
aFrame,
|
2012-02-10 04:33:39 -08:00
|
|
|
styleExpansionFactor,
|
|
|
|
aMatrix);
|
2011-09-05 10:53:34 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
2012-08-05 12:10:21 -07:00
|
|
|
/* static */ nscolor
|
2012-02-04 05:11:09 -08:00
|
|
|
nsSVGUtils::GetFallbackOrPaintColor(gfxContext *aContext, nsStyleContext *aStyleContext,
|
2012-08-05 12:10:21 -07:00
|
|
|
nsStyleSVGPaint nsStyleSVG::*aFillOrStroke)
|
2012-02-04 05:11:09 -08:00
|
|
|
{
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleSVGPaint &paint = aStyleContext->StyleSVG()->*aFillOrStroke;
|
2012-02-04 05:11:09 -08:00
|
|
|
nsStyleContext *styleIfVisited = aStyleContext->GetStyleIfVisited();
|
2012-09-05 21:58:46 -07:00
|
|
|
bool isServer = paint.mType == eStyleSVGPaintType_Server ||
|
2013-05-15 19:35:15 -07:00
|
|
|
paint.mType == eStyleSVGPaintType_ContextFill ||
|
|
|
|
paint.mType == eStyleSVGPaintType_ContextStroke;
|
2012-08-05 12:10:21 -07:00
|
|
|
nscolor color = isServer ? paint.mFallbackColor : paint.mPaint.mColor;
|
2012-02-04 05:11:09 -08:00
|
|
|
if (styleIfVisited) {
|
|
|
|
const nsStyleSVGPaint &paintIfVisited =
|
2013-02-16 13:51:02 -08:00
|
|
|
styleIfVisited->StyleSVG()->*aFillOrStroke;
|
2012-02-04 05:11:09 -08:00
|
|
|
// To prevent Web content from detecting if a user has visited a URL
|
|
|
|
// (via URL loading triggered by paint servers or performance
|
|
|
|
// differences between paint servers or between a paint server and a
|
|
|
|
// color), we do not allow whether links are visited to change which
|
|
|
|
// paint server is used or switch between paint servers and simple
|
|
|
|
// colors. A :visited style may only override a simple color with
|
|
|
|
// another simple color.
|
|
|
|
if (paintIfVisited.mType == eStyleSVGPaintType_Color &&
|
|
|
|
paint.mType == eStyleSVGPaintType_Color) {
|
2012-08-05 12:10:21 -07:00
|
|
|
nscolor colors[2] = { color, paintIfVisited.mPaint.mColor };
|
|
|
|
return nsStyleContext::CombineVisitedColors(
|
|
|
|
colors, aStyleContext->RelevantLinkVisited());
|
2012-02-04 05:11:09 -08:00
|
|
|
}
|
|
|
|
}
|
2012-08-05 12:10:21 -07:00
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
SetupFallbackOrPaintColor(gfxContext *aContext, nsStyleContext *aStyleContext,
|
|
|
|
nsStyleSVGPaint nsStyleSVG::*aFillOrStroke,
|
|
|
|
float aOpacity)
|
|
|
|
{
|
|
|
|
nscolor color = nsSVGUtils::GetFallbackOrPaintColor(
|
|
|
|
aContext, aStyleContext, aFillOrStroke);
|
|
|
|
|
|
|
|
aContext->SetColor(gfxRGBA(NS_GET_R(color)/255.0,
|
|
|
|
NS_GET_G(color)/255.0,
|
|
|
|
NS_GET_B(color)/255.0,
|
|
|
|
NS_GET_A(color)/255.0 * aOpacity));
|
|
|
|
}
|
|
|
|
|
|
|
|
static float
|
|
|
|
MaybeOptimizeOpacity(nsIFrame *aFrame, float aFillOrStrokeOpacity)
|
|
|
|
{
|
2013-02-16 13:51:02 -08:00
|
|
|
float opacity = aFrame->StyleDisplay()->mOpacity;
|
2012-08-05 12:10:21 -07:00
|
|
|
if (opacity < 1 && nsSVGUtils::CanOptimizeOpacity(aFrame)) {
|
|
|
|
return aFillOrStrokeOpacity * opacity;
|
|
|
|
}
|
|
|
|
return aFillOrStrokeOpacity;
|
|
|
|
}
|
|
|
|
|
2012-09-05 21:58:46 -07:00
|
|
|
/* static */ bool
|
2013-05-15 19:35:12 -07:00
|
|
|
nsSVGUtils::SetupContextPaint(gfxContext *aContext,
|
|
|
|
gfxTextContextPaint *aContextPaint,
|
|
|
|
const nsStyleSVGPaint &aPaint,
|
|
|
|
float aOpacity)
|
2012-09-05 21:58:46 -07:00
|
|
|
{
|
|
|
|
nsRefPtr<gfxPattern> pattern;
|
|
|
|
|
2013-05-15 19:35:12 -07:00
|
|
|
if (!aContextPaint) {
|
2012-09-05 21:58:46 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aPaint.mType) {
|
2013-05-15 19:35:15 -07:00
|
|
|
case eStyleSVGPaintType_ContextFill:
|
2013-05-15 19:35:12 -07:00
|
|
|
pattern = aContextPaint->GetFillPattern(aOpacity, aContext->CurrentMatrix());
|
2012-09-05 21:58:46 -07:00
|
|
|
break;
|
2013-05-15 19:35:15 -07:00
|
|
|
case eStyleSVGPaintType_ContextStroke:
|
2013-05-15 19:35:12 -07:00
|
|
|
pattern = aContextPaint->GetStrokePattern(aOpacity, aContext->CurrentMatrix());
|
2012-09-05 21:58:46 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pattern) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aContext->SetPattern(pattern);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-08-05 12:10:21 -07:00
|
|
|
bool
|
2012-09-05 21:58:46 -07:00
|
|
|
nsSVGUtils::SetupCairoFillPaint(nsIFrame *aFrame, gfxContext* aContext,
|
2013-05-15 19:35:12 -07:00
|
|
|
gfxTextContextPaint *aContextPaint)
|
2012-08-05 12:10:21 -07:00
|
|
|
{
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleSVG* style = aFrame->StyleSVG();
|
2012-08-05 12:10:21 -07:00
|
|
|
if (style->mFill.mType == eStyleSVGPaintType_None)
|
|
|
|
return false;
|
2012-08-28 07:47:01 -07:00
|
|
|
|
|
|
|
if (style->mFillRule == NS_STYLE_FILL_RULE_EVENODD)
|
|
|
|
aContext->SetFillRule(gfxContext::FILL_RULE_EVEN_ODD);
|
|
|
|
else
|
|
|
|
aContext->SetFillRule(gfxContext::FILL_RULE_WINDING);
|
|
|
|
|
2012-09-05 21:58:47 -07:00
|
|
|
float opacity = MaybeOptimizeOpacity(aFrame,
|
|
|
|
GetOpacity(style->mFillOpacitySource,
|
|
|
|
style->mFillOpacity,
|
2013-05-15 19:35:12 -07:00
|
|
|
aContextPaint));
|
2012-08-05 12:10:21 -07:00
|
|
|
nsSVGPaintServerFrame *ps =
|
|
|
|
nsSVGEffects::GetPaintServer(aFrame, &style->mFill, nsSVGEffects::FillProperty());
|
|
|
|
if (ps && ps->SetupPaintServer(aContext, aFrame, &nsStyleSVG::mFill, opacity))
|
|
|
|
return true;
|
|
|
|
|
2013-05-15 19:35:12 -07:00
|
|
|
if (SetupContextPaint(aContext, aContextPaint, style->mFill, opacity)) {
|
2012-09-05 21:58:46 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-08-05 12:10:21 -07:00
|
|
|
// On failure, use the fallback colour in case we have an
|
|
|
|
// objectBoundingBox where the width or height of the object is zero.
|
|
|
|
// See http://www.w3.org/TR/SVG11/coords.html#ObjectBoundingBox
|
2013-02-15 21:38:33 -08:00
|
|
|
SetupFallbackOrPaintColor(aContext, aFrame->StyleContext(),
|
2012-08-05 12:10:21 -07:00
|
|
|
&nsStyleSVG::mFill, opacity);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-09-05 21:58:46 -07:00
|
|
|
nsSVGUtils::SetupCairoStrokePaint(nsIFrame *aFrame, gfxContext* aContext,
|
2013-05-15 19:35:12 -07:00
|
|
|
gfxTextContextPaint *aContextPaint)
|
2012-08-05 12:10:21 -07:00
|
|
|
{
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleSVG* style = aFrame->StyleSVG();
|
2012-08-05 12:10:21 -07:00
|
|
|
if (style->mStroke.mType == eStyleSVGPaintType_None)
|
|
|
|
return false;
|
|
|
|
|
2012-09-05 21:58:47 -07:00
|
|
|
float opacity = MaybeOptimizeOpacity(aFrame,
|
|
|
|
GetOpacity(style->mStrokeOpacitySource,
|
|
|
|
style->mStrokeOpacity,
|
2013-05-15 19:35:12 -07:00
|
|
|
aContextPaint));
|
2012-08-05 12:10:21 -07:00
|
|
|
|
|
|
|
nsSVGPaintServerFrame *ps =
|
|
|
|
nsSVGEffects::GetPaintServer(aFrame, &style->mStroke, nsSVGEffects::StrokeProperty());
|
|
|
|
if (ps && ps->SetupPaintServer(aContext, aFrame, &nsStyleSVG::mStroke, opacity))
|
|
|
|
return true;
|
|
|
|
|
2013-05-15 19:35:12 -07:00
|
|
|
if (SetupContextPaint(aContext, aContextPaint, style->mStroke, opacity)) {
|
2012-09-05 21:58:46 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-08-05 12:10:21 -07:00
|
|
|
// On failure, use the fallback colour in case we have an
|
|
|
|
// objectBoundingBox where the width or height of the object is zero.
|
|
|
|
// See http://www.w3.org/TR/SVG11/coords.html#ObjectBoundingBox
|
2013-02-15 21:38:33 -08:00
|
|
|
SetupFallbackOrPaintColor(aContext, aFrame->StyleContext(),
|
2012-08-05 12:10:21 -07:00
|
|
|
&nsStyleSVG::mStroke, opacity);
|
|
|
|
|
|
|
|
return true;
|
2012-02-04 05:11:09 -08:00
|
|
|
}
|
2012-08-10 04:13:43 -07:00
|
|
|
|
2012-09-05 21:58:47 -07:00
|
|
|
/* static */ float
|
|
|
|
nsSVGUtils::GetOpacity(nsStyleSVGOpacitySource aOpacityType,
|
|
|
|
const float& aOpacity,
|
2013-05-15 19:35:12 -07:00
|
|
|
gfxTextContextPaint *aOuterContextPaint)
|
2012-09-05 21:58:47 -07:00
|
|
|
{
|
|
|
|
float opacity = 1.0f;
|
|
|
|
switch (aOpacityType) {
|
|
|
|
case eStyleSVGOpacitySource_Normal:
|
|
|
|
opacity = aOpacity;
|
|
|
|
break;
|
2013-05-15 19:35:15 -07:00
|
|
|
case eStyleSVGOpacitySource_ContextFillOpacity:
|
2013-05-15 19:35:12 -07:00
|
|
|
if (aOuterContextPaint) {
|
|
|
|
opacity = aOuterContextPaint->GetFillOpacity();
|
2012-09-05 21:58:47 -07:00
|
|
|
} else {
|
2013-05-15 19:35:15 -07:00
|
|
|
NS_WARNING("context-fill-opacity used outside of an SVG glyph");
|
2012-09-05 21:58:47 -07:00
|
|
|
}
|
|
|
|
break;
|
2013-05-15 19:35:15 -07:00
|
|
|
case eStyleSVGOpacitySource_ContextStrokeOpacity:
|
2013-05-15 19:35:12 -07:00
|
|
|
if (aOuterContextPaint) {
|
|
|
|
opacity = aOuterContextPaint->GetStrokeOpacity();
|
2012-09-05 21:58:47 -07:00
|
|
|
} else {
|
2013-05-15 19:35:15 -07:00
|
|
|
NS_WARNING("context-stroke-opacity used outside of an SVG glyph");
|
2012-09-05 21:58:47 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Unknown object opacity inheritance type for SVG glyph");
|
|
|
|
}
|
|
|
|
return opacity;
|
|
|
|
}
|
|
|
|
|
2012-08-10 04:13:43 -07:00
|
|
|
bool
|
2013-05-15 19:35:12 -07:00
|
|
|
nsSVGUtils::HasStroke(nsIFrame* aFrame, gfxTextContextPaint *aContextPaint)
|
2012-08-10 04:13:43 -07:00
|
|
|
{
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleSVG *style = aFrame->StyleSVG();
|
2012-08-10 04:13:43 -07:00
|
|
|
return style->mStroke.mType != eStyleSVGPaintType_None &&
|
|
|
|
style->mStrokeOpacity > 0 &&
|
2013-05-15 19:35:12 -07:00
|
|
|
GetStrokeWidth(aFrame, aContextPaint) > 0;
|
2012-08-10 04:13:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
float
|
2013-05-15 19:35:12 -07:00
|
|
|
nsSVGUtils::GetStrokeWidth(nsIFrame* aFrame, gfxTextContextPaint *aContextPaint)
|
2012-08-10 04:13:43 -07:00
|
|
|
{
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleSVG *style = aFrame->StyleSVG();
|
2013-05-15 19:35:12 -07:00
|
|
|
if (aContextPaint && style->mStrokeWidthFromObject) {
|
|
|
|
return aContextPaint->GetStrokeWidth();
|
2012-09-05 21:58:47 -07:00
|
|
|
}
|
|
|
|
|
2012-08-10 04:13:43 -07:00
|
|
|
nsIContent* content = aFrame->GetContent();
|
|
|
|
if (content->IsNodeOfType(nsINode::eTEXT)) {
|
|
|
|
content = content->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGElement *ctx = static_cast<nsSVGElement*>(content);
|
|
|
|
|
2012-09-22 12:26:05 -07:00
|
|
|
return CoordToFloat(aFrame->PresContext(), ctx,
|
|
|
|
style->mStrokeWidth);
|
2012-08-10 04:13:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-24 23:05:31 -07:00
|
|
|
nsSVGUtils::SetupCairoStrokeBBoxGeometry(nsIFrame* aFrame,
|
|
|
|
gfxContext *aContext,
|
2013-05-15 19:35:12 -07:00
|
|
|
gfxTextContextPaint *aContextPaint)
|
2012-08-10 04:13:43 -07:00
|
|
|
{
|
2013-05-15 19:35:12 -07:00
|
|
|
float width = GetStrokeWidth(aFrame, aContextPaint);
|
2012-08-10 04:13:43 -07:00
|
|
|
if (width <= 0)
|
|
|
|
return;
|
|
|
|
aContext->SetLineWidth(width);
|
|
|
|
|
|
|
|
// Apply any stroke-specific transform
|
|
|
|
aContext->Multiply(GetStrokeTransform(aFrame));
|
|
|
|
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleSVG* style = aFrame->StyleSVG();
|
2012-08-10 04:13:43 -07:00
|
|
|
|
|
|
|
switch (style->mStrokeLinecap) {
|
|
|
|
case NS_STYLE_STROKE_LINECAP_BUTT:
|
|
|
|
aContext->SetLineCap(gfxContext::LINE_CAP_BUTT);
|
|
|
|
break;
|
|
|
|
case NS_STYLE_STROKE_LINECAP_ROUND:
|
|
|
|
aContext->SetLineCap(gfxContext::LINE_CAP_ROUND);
|
|
|
|
break;
|
|
|
|
case NS_STYLE_STROKE_LINECAP_SQUARE:
|
|
|
|
aContext->SetLineCap(gfxContext::LINE_CAP_SQUARE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
aContext->SetMiterLimit(style->mStrokeMiterlimit);
|
|
|
|
|
|
|
|
switch (style->mStrokeLinejoin) {
|
|
|
|
case NS_STYLE_STROKE_LINEJOIN_MITER:
|
|
|
|
aContext->SetLineJoin(gfxContext::LINE_JOIN_MITER);
|
|
|
|
break;
|
|
|
|
case NS_STYLE_STROKE_LINEJOIN_ROUND:
|
|
|
|
aContext->SetLineJoin(gfxContext::LINE_JOIN_ROUND);
|
|
|
|
break;
|
|
|
|
case NS_STYLE_STROKE_LINEJOIN_BEVEL:
|
|
|
|
aContext->SetLineJoin(gfxContext::LINE_JOIN_BEVEL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
GetStrokeDashData(nsIFrame* aFrame,
|
|
|
|
FallibleTArray<gfxFloat>& aDashes,
|
2012-09-05 21:58:47 -07:00
|
|
|
gfxFloat* aDashOffset,
|
2013-05-15 19:35:12 -07:00
|
|
|
gfxTextContextPaint *aContextPaint)
|
2012-08-10 04:13:43 -07:00
|
|
|
{
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleSVG* style = aFrame->StyleSVG();
|
2012-09-05 21:58:47 -07:00
|
|
|
nsPresContext *presContext = aFrame->PresContext();
|
|
|
|
nsIContent *content = aFrame->GetContent();
|
|
|
|
nsSVGElement *ctx = static_cast<nsSVGElement*>
|
|
|
|
(content->IsNodeOfType(nsINode::eTEXT) ?
|
|
|
|
content->GetParent() : content);
|
2012-08-10 04:13:43 -07:00
|
|
|
|
2012-09-05 21:58:47 -07:00
|
|
|
gfxFloat totalLength = 0.0;
|
2013-05-15 19:35:12 -07:00
|
|
|
if (aContextPaint && style->mStrokeDasharrayFromObject) {
|
|
|
|
aDashes = aContextPaint->GetStrokeDashArray();
|
2012-08-10 04:13:43 -07:00
|
|
|
|
2012-09-05 21:58:47 -07:00
|
|
|
for (uint32_t i = 0; i < aDashes.Length(); i++) {
|
|
|
|
if (aDashes[i] < 0.0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
totalLength += aDashes[i];
|
|
|
|
}
|
2012-08-10 04:13:43 -07:00
|
|
|
|
2012-09-05 21:58:47 -07:00
|
|
|
} else {
|
|
|
|
uint32_t count = style->mStrokeDasharrayLength;
|
|
|
|
if (!count || !aDashes.SetLength(count)) {
|
2012-08-10 04:13:43 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-09-05 21:58:47 -07:00
|
|
|
gfxFloat pathScale = 1.0;
|
2012-08-10 04:13:43 -07:00
|
|
|
|
2012-09-05 21:58:47 -07:00
|
|
|
if (content->Tag() == nsGkAtoms::path) {
|
2013-01-12 14:22:31 -08:00
|
|
|
pathScale = static_cast<SVGPathElement*>(content)->
|
|
|
|
GetPathLengthScale(SVGPathElement::eForStroking);
|
2012-09-05 21:58:47 -07:00
|
|
|
if (pathScale <= 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2012-08-10 04:13:43 -07:00
|
|
|
|
2012-09-05 21:58:47 -07:00
|
|
|
const nsStyleCoord *dasharray = style->mStrokeDasharray;
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < count; i++) {
|
|
|
|
aDashes[i] = nsSVGUtils::CoordToFloat(presContext,
|
|
|
|
ctx,
|
|
|
|
dasharray[i]) * pathScale;
|
|
|
|
if (aDashes[i] < 0.0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
totalLength += aDashes[i];
|
2012-08-10 04:13:43 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-15 19:35:12 -07:00
|
|
|
if (aContextPaint && style->mStrokeDashoffsetFromObject) {
|
|
|
|
*aDashOffset = aContextPaint->GetStrokeDashOffset();
|
2012-09-05 21:58:47 -07:00
|
|
|
} else {
|
|
|
|
*aDashOffset = nsSVGUtils::CoordToFloat(presContext,
|
2013-06-16 04:05:39 -07:00
|
|
|
ctx,
|
|
|
|
style->mStrokeDashoffset);
|
2012-09-05 21:58:47 -07:00
|
|
|
}
|
|
|
|
|
2012-08-10 04:13:43 -07:00
|
|
|
return (totalLength > 0.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-24 23:05:32 -07:00
|
|
|
nsSVGUtils::SetupCairoStrokeGeometry(nsIFrame* aFrame, gfxContext* aContext,
|
2013-05-15 19:35:12 -07:00
|
|
|
gfxTextContextPaint *aContextPaint)
|
2012-08-10 04:13:43 -07:00
|
|
|
{
|
2013-05-15 19:35:12 -07:00
|
|
|
SetupCairoStrokeBBoxGeometry(aFrame, aContext, aContextPaint);
|
2012-08-10 04:13:43 -07:00
|
|
|
|
|
|
|
AutoFallibleTArray<gfxFloat, 10> dashes;
|
|
|
|
gfxFloat dashOffset;
|
2013-05-15 19:35:12 -07:00
|
|
|
if (GetStrokeDashData(aFrame, dashes, &dashOffset, aContextPaint)) {
|
2012-08-10 04:13:43 -07:00
|
|
|
aContext->SetDash(dashes.Elements(), dashes.Length(), dashOffset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t
|
2012-08-10 04:13:43 -07:00
|
|
|
nsSVGUtils::GetGeometryHitTestFlags(nsIFrame* aFrame)
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t flags = 0;
|
2012-08-10 04:13:43 -07:00
|
|
|
|
2013-02-16 13:51:02 -08:00
|
|
|
switch(aFrame->StyleVisibility()->mPointerEvents) {
|
2012-08-10 04:13:43 -07:00
|
|
|
case NS_STYLE_POINTER_EVENTS_NONE:
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_AUTO:
|
|
|
|
case NS_STYLE_POINTER_EVENTS_VISIBLEPAINTED:
|
2013-02-16 13:51:02 -08:00
|
|
|
if (aFrame->StyleVisibility()->IsVisible()) {
|
|
|
|
if (aFrame->StyleSVG()->mFill.mType != eStyleSVGPaintType_None)
|
2012-08-10 04:13:43 -07:00
|
|
|
flags |= SVG_HIT_TEST_FILL;
|
2013-02-16 13:51:02 -08:00
|
|
|
if (aFrame->StyleSVG()->mStroke.mType != eStyleSVGPaintType_None)
|
2012-08-10 04:13:43 -07:00
|
|
|
flags |= SVG_HIT_TEST_STROKE;
|
2013-02-16 13:51:02 -08:00
|
|
|
if (aFrame->StyleSVG()->mStrokeOpacity > 0)
|
2012-08-10 04:13:43 -07:00
|
|
|
flags |= SVG_HIT_TEST_CHECK_MRECT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_VISIBLEFILL:
|
2013-02-16 13:51:02 -08:00
|
|
|
if (aFrame->StyleVisibility()->IsVisible()) {
|
2012-08-10 04:13:43 -07:00
|
|
|
flags |= SVG_HIT_TEST_FILL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_VISIBLESTROKE:
|
2013-02-16 13:51:02 -08:00
|
|
|
if (aFrame->StyleVisibility()->IsVisible()) {
|
2012-08-10 04:13:43 -07:00
|
|
|
flags |= SVG_HIT_TEST_STROKE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_VISIBLE:
|
2013-02-16 13:51:02 -08:00
|
|
|
if (aFrame->StyleVisibility()->IsVisible()) {
|
2012-08-10 04:13:43 -07:00
|
|
|
flags |= SVG_HIT_TEST_FILL | SVG_HIT_TEST_STROKE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_PAINTED:
|
2013-02-16 13:51:02 -08:00
|
|
|
if (aFrame->StyleSVG()->mFill.mType != eStyleSVGPaintType_None)
|
2012-08-10 04:13:43 -07:00
|
|
|
flags |= SVG_HIT_TEST_FILL;
|
2013-02-16 13:51:02 -08:00
|
|
|
if (aFrame->StyleSVG()->mStroke.mType != eStyleSVGPaintType_None)
|
2012-08-10 04:13:43 -07:00
|
|
|
flags |= SVG_HIT_TEST_STROKE;
|
2013-02-16 13:51:02 -08:00
|
|
|
if (aFrame->StyleSVG()->mStrokeOpacity)
|
2012-08-10 04:13:43 -07:00
|
|
|
flags |= SVG_HIT_TEST_CHECK_MRECT;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_FILL:
|
|
|
|
flags |= SVG_HIT_TEST_FILL;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_STROKE:
|
|
|
|
flags |= SVG_HIT_TEST_STROKE;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_ALL:
|
|
|
|
flags |= SVG_HIT_TEST_FILL | SVG_HIT_TEST_STROKE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ERROR("not reached");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-09-05 21:58:46 -07:00
|
|
|
nsSVGUtils::SetupCairoStroke(nsIFrame* aFrame, gfxContext* aContext,
|
2013-05-15 19:35:12 -07:00
|
|
|
gfxTextContextPaint *aContextPaint)
|
2012-08-10 04:13:43 -07:00
|
|
|
{
|
2013-05-15 19:35:12 -07:00
|
|
|
if (!HasStroke(aFrame, aContextPaint)) {
|
2012-08-10 04:13:43 -07:00
|
|
|
return false;
|
|
|
|
}
|
2013-05-15 19:35:12 -07:00
|
|
|
SetupCairoStrokeGeometry(aFrame, aContext, aContextPaint);
|
2012-08-10 04:13:43 -07:00
|
|
|
|
2013-05-15 19:35:12 -07:00
|
|
|
return SetupCairoStrokePaint(aFrame, aContext, aContextPaint);
|
2012-08-10 04:13:43 -07:00
|
|
|
}
|
2012-12-11 15:15:07 -08:00
|
|
|
|
|
|
|
bool
|
|
|
|
nsSVGUtils::PaintSVGGlyph(Element* aElement, gfxContext* aContext,
|
|
|
|
gfxFont::DrawMode aDrawMode,
|
2013-05-15 19:35:12 -07:00
|
|
|
gfxTextContextPaint* aContextPaint)
|
2012-12-11 15:15:07 -08:00
|
|
|
{
|
|
|
|
nsIFrame* frame = aElement->GetPrimaryFrame();
|
|
|
|
nsISVGChildFrame* svgFrame = do_QueryFrame(frame);
|
2013-08-19 06:08:43 -07:00
|
|
|
if (!svgFrame) {
|
|
|
|
return false;
|
2012-12-11 15:15:07 -08:00
|
|
|
}
|
2013-08-19 06:08:43 -07:00
|
|
|
nsRenderingContext context;
|
|
|
|
context.Init(frame->PresContext()->DeviceContext(), aContext);
|
2013-05-15 19:35:12 -07:00
|
|
|
context.AddUserData(&gfxTextContextPaint::sUserDataKey, aContextPaint, nullptr);
|
2013-09-11 00:27:45 -07:00
|
|
|
svgFrame->NotifySVGChanged(nsISVGChildFrame::TRANSFORM_CHANGED);
|
|
|
|
nsresult rv = svgFrame->PaintSVG(&context, nullptr, frame);
|
2013-08-19 06:08:43 -07:00
|
|
|
return NS_SUCCEEDED(rv);
|
2012-12-11 15:15:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsSVGUtils::GetSVGGlyphExtents(Element* aElement,
|
|
|
|
const gfxMatrix& aSVGToAppSpace,
|
|
|
|
gfxRect* aResult)
|
|
|
|
{
|
|
|
|
nsIFrame* frame = aElement->GetPrimaryFrame();
|
|
|
|
nsISVGChildFrame* svgFrame = do_QueryFrame(frame);
|
2013-08-19 06:08:43 -07:00
|
|
|
if (!svgFrame) {
|
|
|
|
return false;
|
2012-12-11 15:15:07 -08:00
|
|
|
}
|
2013-08-19 06:08:43 -07:00
|
|
|
*aResult = svgFrame->GetBBoxContribution(aSVGToAppSpace,
|
|
|
|
nsSVGUtils::eBBoxIncludeFill | nsSVGUtils::eBBoxIncludeFillGeometry |
|
|
|
|
nsSVGUtils::eBBoxIncludeStroke | nsSVGUtils::eBBoxIncludeStrokeGeometry |
|
|
|
|
nsSVGUtils::eBBoxIncludeMarkers);
|
|
|
|
return true;
|
2012-12-11 15:15:07 -08:00
|
|
|
}
|
2013-02-10 22:22:18 -08:00
|
|
|
|
|
|
|
nsRect
|
|
|
|
nsSVGUtils::ToCanvasBounds(const gfxRect &aUserspaceRect,
|
|
|
|
const gfxMatrix &aToCanvas,
|
|
|
|
const nsPresContext *presContext)
|
|
|
|
{
|
|
|
|
return nsLayoutUtils::RoundGfxRectToAppRect(
|
|
|
|
aToCanvas.TransformBounds(aUserspaceRect),
|
|
|
|
presContext->AppUnitsPerDevPixel());
|
|
|
|
}
|