2001-09-28 20:14:13 +00:00
|
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2002-01-07 23:46:07 +00:00
|
|
|
|
// vim:cindent:ts=2:et:sw=2:
|
2012-05-21 11:12:37 +00: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/. */
|
2006-03-30 05:56:38 +00:00
|
|
|
|
|
|
|
|
|
/* utility functions for drawing borders and backgrounds */
|
|
|
|
|
|
2012-12-14 23:58:45 +00:00
|
|
|
|
#include <ctime>
|
|
|
|
|
|
2014-10-26 00:15:26 +00:00
|
|
|
|
#include "gfx2DGlue.h"
|
|
|
|
|
#include "mozilla/ArrayUtils.h"
|
2012-12-14 23:58:45 +00:00
|
|
|
|
#include "mozilla/DebugOnly.h"
|
2014-09-15 11:10:30 +00:00
|
|
|
|
#include "mozilla/gfx/2D.h"
|
2014-10-26 00:15:26 +00:00
|
|
|
|
#include "mozilla/gfx/Helpers.h"
|
2014-10-31 11:16:27 +00:00
|
|
|
|
#include "mozilla/gfx/PathHelpers.h"
|
2012-12-14 23:58:45 +00:00
|
|
|
|
#include "mozilla/HashFunctions.h"
|
2013-02-16 03:55:36 +00:00
|
|
|
|
#include "mozilla/MathAlgorithms.h"
|
2012-12-14 23:58:45 +00:00
|
|
|
|
|
2015-08-06 02:42:09 +00:00
|
|
|
|
#include "BorderConsts.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
|
#include "nsStyleConsts.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
|
#include "nsPresContext.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
|
#include "nsPoint.h"
|
|
|
|
|
#include "nsRect.h"
|
|
|
|
|
#include "nsIPresShell.h"
|
2004-09-02 03:08:51 +00:00
|
|
|
|
#include "nsFrameManager.h"
|
2003-02-22 00:32:13 +00:00
|
|
|
|
#include "nsStyleContext.h"
|
2007-01-30 00:06:41 +00:00
|
|
|
|
#include "nsGkAtoms.h"
|
2008-06-02 22:52:25 +00:00
|
|
|
|
#include "nsCSSAnonBoxes.h"
|
2000-03-30 06:27:32 +00:00
|
|
|
|
#include "nsIContent.h"
|
2013-01-12 21:53:01 +00:00
|
|
|
|
#include "nsIDocumentInlines.h"
|
2000-06-07 23:06:41 +00:00
|
|
|
|
#include "nsIScrollableFrame.h"
|
2001-08-09 20:22:39 +00:00
|
|
|
|
#include "imgIRequest.h"
|
|
|
|
|
#include "imgIContainer.h"
|
2013-04-05 21:14:37 +00:00
|
|
|
|
#include "ImageOps.h"
|
2001-10-24 00:01:09 +00:00
|
|
|
|
#include "nsCSSRendering.h"
|
2002-09-12 04:43:31 +00:00
|
|
|
|
#include "nsCSSColorUtils.h"
|
2001-12-17 22:51:39 +00:00
|
|
|
|
#include "nsITheme.h"
|
2014-06-14 12:48:07 +00:00
|
|
|
|
#include "nsThemeConstants.h"
|
2003-02-23 02:49:22 +00:00
|
|
|
|
#include "nsLayoutUtils.h"
|
2008-02-27 10:46:29 +00:00
|
|
|
|
#include "nsBlockFrame.h"
|
2006-04-21 17:52:05 +00:00
|
|
|
|
#include "gfxContext.h"
|
2012-03-20 12:15:55 +00:00
|
|
|
|
#include "nsRenderingContext.h"
|
2008-07-17 06:30:25 +00:00
|
|
|
|
#include "nsStyleStructInlines.h"
|
2008-08-08 08:21:13 +00:00
|
|
|
|
#include "nsCSSFrameConstructor.h"
|
2010-04-03 01:58:26 +00:00
|
|
|
|
#include "nsCSSProps.h"
|
2010-08-13 13:34:01 +00:00
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
|
#include "nsSVGEffects.h"
|
|
|
|
|
#include "nsSVGIntegrationUtils.h"
|
|
|
|
|
#include "gfxDrawable.h"
|
2013-03-18 14:25:50 +00:00
|
|
|
|
#include "GeckoProfiler.h"
|
2008-07-23 17:25:23 +00:00
|
|
|
|
#include "nsCSSRenderingBorders.h"
|
2012-08-13 22:04:19 +00:00
|
|
|
|
#include "mozilla/css/ImageLoader.h"
|
2012-08-19 19:33:25 +00:00
|
|
|
|
#include "ImageContainer.h"
|
2012-08-27 04:12:36 +00:00
|
|
|
|
#include "mozilla/Telemetry.h"
|
2012-12-06 23:58:13 +00:00
|
|
|
|
#include "gfxUtils.h"
|
2013-11-08 04:50:39 +00:00
|
|
|
|
#include "gfxGradientCache.h"
|
2015-01-15 09:02:11 +00:00
|
|
|
|
#include "nsInlineFrame.h"
|
2016-08-01 20:31:57 +00:00
|
|
|
|
#include "nsRubyTextContainerFrame.h"
|
2013-01-15 12:22:03 +00:00
|
|
|
|
#include <algorithm>
|
1999-04-19 05:27:55 +00:00
|
|
|
|
|
2011-06-02 12:56:46 +00:00
|
|
|
|
using namespace mozilla;
|
2012-08-13 22:04:19 +00:00
|
|
|
|
using namespace mozilla::css;
|
2013-11-08 04:50:39 +00:00
|
|
|
|
using namespace mozilla::gfx;
|
2015-02-10 07:27:39 +00:00
|
|
|
|
using namespace mozilla::image;
|
2013-07-19 08:39:58 +00:00
|
|
|
|
using mozilla::CSSSizeOrRatio;
|
2011-06-02 12:56:46 +00:00
|
|
|
|
|
2012-11-19 10:54:41 +00:00
|
|
|
|
static int gFrameTreeLockCount = 0;
|
|
|
|
|
|
2003-01-17 09:33:52 +00:00
|
|
|
|
// To avoid storing this data on nsInlineFrame (bloat) and to avoid
|
|
|
|
|
// recalculating this for each frame in a continuation (perf), hold
|
|
|
|
|
// a cache of various coordinate information that we need in order
|
|
|
|
|
// to paint inline backgrounds.
|
|
|
|
|
struct InlineBackgroundData
|
|
|
|
|
{
|
|
|
|
|
InlineBackgroundData()
|
2016-07-19 03:32:47 +00:00
|
|
|
|
: mFrame(nullptr), mLineContainer(nullptr)
|
2003-01-17 09:33:52 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~InlineBackgroundData()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Reset()
|
|
|
|
|
{
|
|
|
|
|
mBoundingBox.SetRect(0,0,0,0);
|
2014-11-24 23:16:04 +00:00
|
|
|
|
mContinuationPoint = mLineContinuationPoint = mUnbrokenMeasure = 0;
|
2016-07-19 03:32:47 +00:00
|
|
|
|
mFrame = mLineContainer = nullptr;
|
2014-11-24 23:16:04 +00:00
|
|
|
|
mPIStartBorderData.Reset();
|
2003-01-17 09:33:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-05 17:55:54 +00:00
|
|
|
|
/**
|
|
|
|
|
* Return a continuous rect for (an inline) aFrame relative to the
|
|
|
|
|
* continuation that draws the left-most part of the background.
|
|
|
|
|
* This is used when painting backgrounds.
|
|
|
|
|
*/
|
2003-01-17 09:33:52 +00:00
|
|
|
|
nsRect GetContinuousRect(nsIFrame* aFrame)
|
|
|
|
|
{
|
2015-01-15 09:02:11 +00:00
|
|
|
|
MOZ_ASSERT(static_cast<nsInlineFrame*>(do_QueryFrame(aFrame)));
|
2014-05-05 17:55:54 +00:00
|
|
|
|
|
2003-01-17 09:33:52 +00:00
|
|
|
|
SetFrame(aFrame);
|
|
|
|
|
|
2014-11-24 23:16:04 +00:00
|
|
|
|
nscoord pos; // an x coordinate if writing-mode is horizontal;
|
|
|
|
|
// y coordinate if vertical
|
2008-02-27 10:46:29 +00:00
|
|
|
|
if (mBidiEnabled) {
|
2014-11-24 23:16:04 +00:00
|
|
|
|
pos = mLineContinuationPoint;
|
2008-02-27 10:46:29 +00:00
|
|
|
|
|
|
|
|
|
// Scan continuations on the same line as aFrame and accumulate the widths
|
2010-04-27 16:15:01 +00:00
|
|
|
|
// of frames that are to the left (if this is an LTR block) or right
|
2008-02-27 10:46:29 +00:00
|
|
|
|
// (if it's RTL) of the current one.
|
2016-07-19 03:32:47 +00:00
|
|
|
|
bool isRtlBlock = (mLineContainer->StyleVisibility()->mDirection ==
|
2010-04-27 16:15:01 +00:00
|
|
|
|
NS_STYLE_DIRECTION_RTL);
|
2016-07-19 03:32:47 +00:00
|
|
|
|
nscoord curOffset = mVertical ? aFrame->GetOffsetTo(mLineContainer).y
|
|
|
|
|
: aFrame->GetOffsetTo(mLineContainer).x;
|
2008-02-27 10:46:29 +00:00
|
|
|
|
|
|
|
|
|
// If the continuation is fluid we know inlineFrame is not on the same line.
|
2009-03-06 20:32:20 +00:00
|
|
|
|
// If it's not fluid, we need to test further to be sure.
|
2014-05-05 17:55:54 +00:00
|
|
|
|
nsIFrame* inlineFrame = aFrame->GetPrevContinuation();
|
2008-02-27 10:46:29 +00:00
|
|
|
|
while (inlineFrame && !inlineFrame->GetNextInFlow() &&
|
|
|
|
|
AreOnSameLine(aFrame, inlineFrame)) {
|
2014-11-24 23:16:04 +00:00
|
|
|
|
nscoord frameOffset = mVertical
|
2016-07-19 03:32:47 +00:00
|
|
|
|
? inlineFrame->GetOffsetTo(mLineContainer).y
|
|
|
|
|
: inlineFrame->GetOffsetTo(mLineContainer).x;
|
2014-11-24 23:16:04 +00:00
|
|
|
|
if (isRtlBlock == (frameOffset >= curOffset)) {
|
|
|
|
|
pos += mVertical
|
|
|
|
|
? inlineFrame->GetSize().height
|
|
|
|
|
: inlineFrame->GetSize().width;
|
2008-02-27 10:46:29 +00:00
|
|
|
|
}
|
|
|
|
|
inlineFrame = inlineFrame->GetPrevContinuation();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inlineFrame = aFrame->GetNextContinuation();
|
|
|
|
|
while (inlineFrame && !inlineFrame->GetPrevInFlow() &&
|
|
|
|
|
AreOnSameLine(aFrame, inlineFrame)) {
|
2014-11-24 23:16:04 +00:00
|
|
|
|
nscoord frameOffset = mVertical
|
2016-07-19 03:32:47 +00:00
|
|
|
|
? inlineFrame->GetOffsetTo(mLineContainer).y
|
|
|
|
|
: inlineFrame->GetOffsetTo(mLineContainer).x;
|
2014-11-24 23:16:04 +00:00
|
|
|
|
if (isRtlBlock == (frameOffset >= curOffset)) {
|
|
|
|
|
pos += mVertical
|
|
|
|
|
? inlineFrame->GetSize().height
|
|
|
|
|
: inlineFrame->GetSize().width;
|
2008-02-27 10:46:29 +00:00
|
|
|
|
}
|
|
|
|
|
inlineFrame = inlineFrame->GetNextContinuation();
|
|
|
|
|
}
|
|
|
|
|
if (isRtlBlock) {
|
|
|
|
|
// aFrame itself is also to the right of its left edge, so add its width.
|
2014-11-24 23:16:04 +00:00
|
|
|
|
pos += mVertical ? aFrame->GetSize().height : aFrame->GetSize().width;
|
|
|
|
|
// pos is now the distance from the left [top] edge of aFrame to the right [bottom] edge
|
2008-02-27 10:46:29 +00:00
|
|
|
|
// of the unbroken content. Change it to indicate the distance from the
|
2014-11-24 23:16:04 +00:00
|
|
|
|
// left [top] edge of the unbroken content to the left [top] edge of aFrame.
|
|
|
|
|
pos = mUnbrokenMeasure - pos;
|
2008-02-27 10:46:29 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2014-11-24 23:16:04 +00:00
|
|
|
|
pos = mContinuationPoint;
|
2008-02-27 10:46:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-01-17 09:33:52 +00:00
|
|
|
|
// Assume background-origin: border and return a rect with offsets
|
|
|
|
|
// relative to (0,0). If we have a different background-origin,
|
|
|
|
|
// then our rect should be deflated appropriately by our caller.
|
2014-11-24 23:16:04 +00:00
|
|
|
|
return mVertical
|
|
|
|
|
? nsRect(0, -pos, mFrame->GetSize().width, mUnbrokenMeasure)
|
|
|
|
|
: nsRect(-pos, 0, mUnbrokenMeasure, mFrame->GetSize().height);
|
2003-01-17 09:33:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-05 17:55:54 +00:00
|
|
|
|
/**
|
|
|
|
|
* Return a continuous rect for (an inline) aFrame relative to the
|
2014-11-24 23:16:04 +00:00
|
|
|
|
* continuation that should draw the left[top]-border. This is used when painting
|
2014-05-05 17:55:54 +00:00
|
|
|
|
* borders and clipping backgrounds. This may NOT be the same continuous rect
|
2014-11-24 23:16:04 +00:00
|
|
|
|
* as for drawing backgrounds; the continuation with the left[top]-border might be
|
2014-05-05 17:55:54 +00:00
|
|
|
|
* somewhere in the middle of that rect (e.g. BIDI), in those cases we need
|
2014-11-24 23:16:04 +00:00
|
|
|
|
* the reverse background order starting at the left[top]-border continuation.
|
2014-05-05 17:55:54 +00:00
|
|
|
|
*/
|
|
|
|
|
nsRect GetBorderContinuousRect(nsIFrame* aFrame, nsRect aBorderArea)
|
|
|
|
|
{
|
|
|
|
|
// Calling GetContinuousRect(aFrame) here may lead to Reset/Init which
|
2014-11-24 23:16:04 +00:00
|
|
|
|
// resets our mPIStartBorderData so we save it ...
|
|
|
|
|
PhysicalInlineStartBorderData saved(mPIStartBorderData);
|
2014-05-05 17:55:54 +00:00
|
|
|
|
nsRect joinedBorderArea = GetContinuousRect(aFrame);
|
2014-11-24 23:16:04 +00:00
|
|
|
|
if (!saved.mIsValid || saved.mFrame != mPIStartBorderData.mFrame) {
|
|
|
|
|
if (aFrame == mPIStartBorderData.mFrame) {
|
|
|
|
|
if (mVertical) {
|
|
|
|
|
mPIStartBorderData.SetCoord(joinedBorderArea.y);
|
|
|
|
|
} else {
|
|
|
|
|
mPIStartBorderData.SetCoord(joinedBorderArea.x);
|
|
|
|
|
}
|
|
|
|
|
} else if (mPIStartBorderData.mFrame) {
|
|
|
|
|
if (mVertical) {
|
|
|
|
|
mPIStartBorderData.SetCoord(GetContinuousRect(mPIStartBorderData.mFrame).y);
|
|
|
|
|
} else {
|
|
|
|
|
mPIStartBorderData.SetCoord(GetContinuousRect(mPIStartBorderData.mFrame).x);
|
|
|
|
|
}
|
2014-05-05 17:55:54 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// ... and restore it when possible.
|
2014-11-24 23:16:04 +00:00
|
|
|
|
mPIStartBorderData.mCoord = saved.mCoord;
|
2014-05-05 17:55:54 +00:00
|
|
|
|
}
|
2014-11-24 23:16:04 +00:00
|
|
|
|
if (mVertical) {
|
|
|
|
|
if (joinedBorderArea.y > mPIStartBorderData.mCoord) {
|
|
|
|
|
joinedBorderArea.y =
|
|
|
|
|
-(mUnbrokenMeasure + joinedBorderArea.y - aBorderArea.height);
|
|
|
|
|
} else {
|
|
|
|
|
joinedBorderArea.y -= mPIStartBorderData.mCoord;
|
|
|
|
|
}
|
2014-05-05 17:55:54 +00:00
|
|
|
|
} else {
|
2014-11-24 23:16:04 +00:00
|
|
|
|
if (joinedBorderArea.x > mPIStartBorderData.mCoord) {
|
|
|
|
|
joinedBorderArea.x =
|
|
|
|
|
-(mUnbrokenMeasure + joinedBorderArea.x - aBorderArea.width);
|
|
|
|
|
} else {
|
|
|
|
|
joinedBorderArea.x -= mPIStartBorderData.mCoord;
|
|
|
|
|
}
|
2014-05-05 17:55:54 +00:00
|
|
|
|
}
|
|
|
|
|
return joinedBorderArea;
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-17 09:33:52 +00:00
|
|
|
|
nsRect GetBoundingRect(nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
SetFrame(aFrame);
|
|
|
|
|
|
|
|
|
|
// Move the offsets relative to (0,0) which puts the bounding box into
|
|
|
|
|
// our coordinate system rather than our parent's. We do this by
|
|
|
|
|
// moving it the back distance from us to the bounding box.
|
|
|
|
|
// This also assumes background-origin: border, so our caller will
|
|
|
|
|
// need to deflate us if needed.
|
|
|
|
|
nsRect boundingBox(mBoundingBox);
|
2003-07-05 15:04:34 +00:00
|
|
|
|
nsPoint point = mFrame->GetPosition();
|
2003-01-17 09:33:52 +00:00
|
|
|
|
boundingBox.MoveBy(-point.x, -point.y);
|
|
|
|
|
|
|
|
|
|
return boundingBox;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
2014-11-24 23:16:04 +00:00
|
|
|
|
// This is a coordinate on the inline axis, but is not a true logical inline-
|
|
|
|
|
// coord because it is always measured from left to right (if horizontal) or
|
|
|
|
|
// from top to bottom (if vertical), ignoring any bidi RTL directionality.
|
|
|
|
|
// We'll call this "physical inline start", or PIStart for short.
|
|
|
|
|
struct PhysicalInlineStartBorderData {
|
2014-05-05 17:55:54 +00:00
|
|
|
|
nsIFrame* mFrame; // the continuation that may have a left-border
|
2014-11-24 23:16:04 +00:00
|
|
|
|
nscoord mCoord; // cached GetContinuousRect(mFrame).x or .y
|
|
|
|
|
bool mIsValid; // true if mCoord is valid
|
2014-05-05 17:55:54 +00:00
|
|
|
|
void Reset() { mFrame = nullptr; mIsValid = false; }
|
2014-11-24 23:16:04 +00:00
|
|
|
|
void SetCoord(nscoord aCoord) { mCoord = aCoord; mIsValid = true; }
|
2014-05-05 17:55:54 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
nsIFrame* mFrame;
|
2016-07-19 03:32:47 +00:00
|
|
|
|
nsIFrame* mLineContainer;
|
2014-05-05 17:55:54 +00:00
|
|
|
|
nsRect mBoundingBox;
|
|
|
|
|
nscoord mContinuationPoint;
|
2014-11-24 23:16:04 +00:00
|
|
|
|
nscoord mUnbrokenMeasure;
|
2014-05-05 17:55:54 +00:00
|
|
|
|
nscoord mLineContinuationPoint;
|
2014-11-24 23:16:04 +00:00
|
|
|
|
PhysicalInlineStartBorderData mPIStartBorderData;
|
2014-05-05 17:55:54 +00:00
|
|
|
|
bool mBidiEnabled;
|
2014-11-24 23:16:04 +00:00
|
|
|
|
bool mVertical;
|
2010-04-27 16:15:01 +00:00
|
|
|
|
|
2003-01-17 09:33:52 +00:00
|
|
|
|
void SetFrame(nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
NS_PRECONDITION(aFrame, "Need a frame");
|
2012-11-19 10:54:41 +00:00
|
|
|
|
NS_ASSERTION(gFrameTreeLockCount > 0,
|
|
|
|
|
"Can't call this when frame tree is not locked");
|
2003-01-17 09:33:52 +00:00
|
|
|
|
|
2012-10-25 05:32:25 +00:00
|
|
|
|
if (aFrame == mFrame) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-06 20:32:20 +00:00
|
|
|
|
nsIFrame *prevContinuation = GetPrevContinuation(aFrame);
|
2003-01-17 09:33:52 +00:00
|
|
|
|
|
2008-01-09 19:19:49 +00:00
|
|
|
|
if (!prevContinuation || mFrame != prevContinuation) {
|
2003-01-17 09:33:52 +00:00
|
|
|
|
// Ok, we've got the wrong frame. We have to start from scratch.
|
|
|
|
|
Reset();
|
|
|
|
|
Init(aFrame);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get our last frame's size and add its width to our continuation
|
|
|
|
|
// point before we cache the new frame.
|
2014-11-24 23:16:04 +00:00
|
|
|
|
mContinuationPoint += mVertical ? mFrame->GetSize().height
|
|
|
|
|
: mFrame->GetSize().width;
|
2003-01-17 09:33:52 +00:00
|
|
|
|
|
2008-02-27 10:46:29 +00:00
|
|
|
|
// If this a new line, update mLineContinuationPoint.
|
|
|
|
|
if (mBidiEnabled &&
|
|
|
|
|
(aFrame->GetPrevInFlow() || !AreOnSameLine(mFrame, aFrame))) {
|
|
|
|
|
mLineContinuationPoint = mContinuationPoint;
|
|
|
|
|
}
|
2010-04-27 16:15:01 +00:00
|
|
|
|
|
2003-01-17 09:33:52 +00:00
|
|
|
|
mFrame = aFrame;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-06 20:32:20 +00:00
|
|
|
|
nsIFrame* GetPrevContinuation(nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
nsIFrame* prevCont = aFrame->GetPrevContinuation();
|
2014-02-07 01:45:28 +00:00
|
|
|
|
if (!prevCont &&
|
|
|
|
|
(aFrame->GetStateBits() & NS_FRAME_PART_OF_IBSPLIT)) {
|
2016-06-21 20:17:11 +00:00
|
|
|
|
nsIFrame* block =
|
|
|
|
|
aFrame->Properties().Get(nsIFrame::IBSplitPrevSibling());
|
2009-03-06 20:32:20 +00:00
|
|
|
|
if (block) {
|
|
|
|
|
// The {ib} properties are only stored on first continuations
|
2009-09-18 18:00:20 +00:00
|
|
|
|
NS_ASSERTION(!block->GetPrevContinuation(),
|
2014-02-07 01:45:31 +00:00
|
|
|
|
"Incorrect value for IBSplitPrevSibling");
|
2016-06-21 20:17:11 +00:00
|
|
|
|
prevCont =
|
|
|
|
|
block->Properties().Get(nsIFrame::IBSplitPrevSibling());
|
2009-03-06 20:32:20 +00:00
|
|
|
|
NS_ASSERTION(prevCont, "How did that happen?");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return prevCont;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsIFrame* GetNextContinuation(nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
nsIFrame* nextCont = aFrame->GetNextContinuation();
|
2014-02-07 01:45:28 +00:00
|
|
|
|
if (!nextCont &&
|
|
|
|
|
(aFrame->GetStateBits() & NS_FRAME_PART_OF_IBSPLIT)) {
|
2009-03-06 20:32:20 +00:00
|
|
|
|
// The {ib} properties are only stored on first continuations
|
2013-09-25 11:42:34 +00:00
|
|
|
|
aFrame = aFrame->FirstContinuation();
|
2016-06-21 20:17:11 +00:00
|
|
|
|
nsIFrame* block = aFrame->Properties().Get(nsIFrame::IBSplitSibling());
|
2009-03-06 20:32:20 +00:00
|
|
|
|
if (block) {
|
2016-06-21 20:17:11 +00:00
|
|
|
|
nextCont = block->Properties().Get(nsIFrame::IBSplitSibling());
|
2009-03-06 20:32:20 +00:00
|
|
|
|
NS_ASSERTION(nextCont, "How did that happen?");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nextCont;
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-17 09:33:52 +00:00
|
|
|
|
void Init(nsIFrame* aFrame)
|
2010-04-27 16:15:01 +00:00
|
|
|
|
{
|
2014-11-24 23:16:04 +00:00
|
|
|
|
mPIStartBorderData.Reset();
|
2012-10-25 05:32:25 +00:00
|
|
|
|
mBidiEnabled = aFrame->PresContext()->BidiEnabled();
|
|
|
|
|
if (mBidiEnabled) {
|
2016-07-19 03:32:47 +00:00
|
|
|
|
// Find the line container frame
|
|
|
|
|
mLineContainer = aFrame;
|
|
|
|
|
while (mLineContainer &&
|
|
|
|
|
mLineContainer->IsFrameOfType(nsIFrame::eLineParticipant)) {
|
|
|
|
|
mLineContainer = mLineContainer->GetParent();
|
2012-10-25 05:32:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-19 03:32:47 +00:00
|
|
|
|
MOZ_ASSERT(mLineContainer, "Cannot find line containing frame.");
|
|
|
|
|
MOZ_ASSERT(mLineContainer != aFrame, "line container frame "
|
|
|
|
|
"should be an ancestor of the target frame.");
|
2012-10-25 05:32:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-24 23:16:04 +00:00
|
|
|
|
mVertical = aFrame->GetWritingMode().IsVertical();
|
|
|
|
|
|
2003-01-17 09:33:52 +00:00
|
|
|
|
// Start with the previous flow frame as our continuation point
|
|
|
|
|
// is the total of the widths of the previous frames.
|
2009-03-06 20:32:20 +00:00
|
|
|
|
nsIFrame* inlineFrame = GetPrevContinuation(aFrame);
|
2003-01-17 09:33:52 +00:00
|
|
|
|
while (inlineFrame) {
|
2014-11-24 23:16:04 +00:00
|
|
|
|
if (!mPIStartBorderData.mFrame &&
|
|
|
|
|
!(mVertical ? inlineFrame->GetSkipSides().Top()
|
|
|
|
|
: inlineFrame->GetSkipSides().Left())) {
|
|
|
|
|
mPIStartBorderData.mFrame = inlineFrame;
|
2014-05-05 17:55:54 +00:00
|
|
|
|
}
|
2003-07-05 15:04:34 +00:00
|
|
|
|
nsRect rect = inlineFrame->GetRect();
|
2014-11-24 23:16:04 +00:00
|
|
|
|
mContinuationPoint += mVertical ? rect.height : rect.width;
|
2012-10-25 05:32:25 +00:00
|
|
|
|
if (mBidiEnabled && !AreOnSameLine(aFrame, inlineFrame)) {
|
2014-11-24 23:16:04 +00:00
|
|
|
|
mLineContinuationPoint += mVertical ? rect.height : rect.width;
|
2012-10-25 05:32:25 +00:00
|
|
|
|
}
|
2014-11-24 23:16:04 +00:00
|
|
|
|
mUnbrokenMeasure += mVertical ? rect.height : rect.width;
|
2003-01-17 09:33:52 +00:00
|
|
|
|
mBoundingBox.UnionRect(mBoundingBox, rect);
|
2009-03-06 20:32:20 +00:00
|
|
|
|
inlineFrame = GetPrevContinuation(inlineFrame);
|
2003-01-17 09:33:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Next add this frame and subsequent frames to the bounding box and
|
|
|
|
|
// unbroken width.
|
|
|
|
|
inlineFrame = aFrame;
|
|
|
|
|
while (inlineFrame) {
|
2014-11-24 23:16:04 +00:00
|
|
|
|
if (!mPIStartBorderData.mFrame &&
|
|
|
|
|
!(mVertical ? inlineFrame->GetSkipSides().Top()
|
|
|
|
|
: inlineFrame->GetSkipSides().Left())) {
|
|
|
|
|
mPIStartBorderData.mFrame = inlineFrame;
|
2014-05-05 17:55:54 +00:00
|
|
|
|
}
|
2003-07-05 15:04:34 +00:00
|
|
|
|
nsRect rect = inlineFrame->GetRect();
|
2014-11-24 23:16:04 +00:00
|
|
|
|
mUnbrokenMeasure += mVertical ? rect.height : rect.width;
|
2003-01-17 09:33:52 +00:00
|
|
|
|
mBoundingBox.UnionRect(mBoundingBox, rect);
|
2009-03-06 20:32:20 +00:00
|
|
|
|
inlineFrame = GetNextContinuation(inlineFrame);
|
2003-01-17 09:33:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mFrame = aFrame;
|
2008-02-27 10:46:29 +00:00
|
|
|
|
}
|
2010-04-27 16:15:01 +00:00
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
|
bool AreOnSameLine(nsIFrame* aFrame1, nsIFrame* aFrame2) {
|
2016-07-19 03:32:47 +00:00
|
|
|
|
if (nsBlockFrame* blockFrame = do_QueryFrame(mLineContainer)) {
|
|
|
|
|
bool isValid1, isValid2;
|
|
|
|
|
nsBlockInFlowLineIterator it1(blockFrame, aFrame1, &isValid1);
|
|
|
|
|
nsBlockInFlowLineIterator it2(blockFrame, aFrame2, &isValid2);
|
|
|
|
|
return isValid1 && isValid2 &&
|
|
|
|
|
// Make sure aFrame1 and aFrame2 are in the same continuation of
|
|
|
|
|
// blockFrame.
|
|
|
|
|
it1.GetContainer() == it2.GetContainer() &&
|
|
|
|
|
// And on the same line in it
|
|
|
|
|
it1.GetLine() == it2.GetLine();
|
|
|
|
|
}
|
|
|
|
|
if (nsRubyTextContainerFrame* rtcFrame = do_QueryFrame(mLineContainer)) {
|
|
|
|
|
nsBlockFrame* block = nsLayoutUtils::FindNearestBlockAncestor(rtcFrame);
|
|
|
|
|
// Ruby text container can only hold one line of text, so if they
|
|
|
|
|
// are in the same continuation, they are in the same line. Since
|
|
|
|
|
// ruby text containers are bidi isolate, they are never split for
|
|
|
|
|
// bidi reordering, which means being in different continuation
|
|
|
|
|
// indicates being in different lines.
|
|
|
|
|
for (nsIFrame* frame = rtcFrame->FirstContinuation();
|
|
|
|
|
frame; frame = frame->GetNextContinuation()) {
|
|
|
|
|
bool isDescendant1 =
|
|
|
|
|
nsLayoutUtils::IsProperAncestorFrame(frame, aFrame1, block);
|
|
|
|
|
bool isDescendant2 =
|
|
|
|
|
nsLayoutUtils::IsProperAncestorFrame(frame, aFrame2, block);
|
|
|
|
|
if (isDescendant1 && isDescendant2) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (isDescendant1 || isDescendant2) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
MOZ_ASSERT_UNREACHABLE("None of the frames is a descendant of this rtc?");
|
|
|
|
|
}
|
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Do we have any other type of line container?");
|
|
|
|
|
return false;
|
2003-01-17 09:33:52 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2015-09-24 07:40:20 +00:00
|
|
|
|
// A resolved color stop, with a specific position along the gradient line and
|
|
|
|
|
// a color.
|
2013-02-15 18:54:49 +00:00
|
|
|
|
struct ColorStop {
|
2014-10-22 12:25:00 +00:00
|
|
|
|
ColorStop(): mPosition(0), mIsMidpoint(false) {}
|
2015-09-24 07:40:20 +00:00
|
|
|
|
ColorStop(double aPosition, bool aIsMidPoint, const Color& aColor) :
|
2014-10-22 12:25:00 +00:00
|
|
|
|
mPosition(aPosition), mIsMidpoint(aIsMidPoint), mColor(aColor) {}
|
2013-02-15 18:54:49 +00:00
|
|
|
|
double mPosition; // along the gradient line; 0=start, 1=end
|
2014-10-22 12:25:00 +00:00
|
|
|
|
bool mIsMidpoint;
|
2015-09-24 07:40:20 +00:00
|
|
|
|
Color mColor;
|
2013-02-15 18:54:49 +00:00
|
|
|
|
};
|
|
|
|
|
|
2008-09-25 16:03:15 +00:00
|
|
|
|
/* Local functions */
|
2015-10-23 02:54:48 +00:00
|
|
|
|
static DrawResult DrawBorderImage(nsPresContext* aPresContext,
|
|
|
|
|
nsRenderingContext& aRenderingContext,
|
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
|
const nsRect& aBorderArea,
|
|
|
|
|
const nsStyleBorder& aStyleBorder,
|
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
|
Sides aSkipSides,
|
|
|
|
|
PaintBorderFlags aFlags);
|
2008-09-25 16:03:15 +00:00
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
|
static nscolor MakeBevelColor(mozilla::css::Side whichSide, uint8_t style,
|
2008-09-25 16:03:15 +00:00
|
|
|
|
nscolor aBackgroundColor,
|
|
|
|
|
nscolor aBorderColor);
|
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
|
static InlineBackgroundData* gInlineBGData = nullptr;
|
2003-01-17 09:33:52 +00:00
|
|
|
|
|
2007-03-14 19:48:51 +00:00
|
|
|
|
// Initialize any static variables used by nsCSSRendering.
|
2011-06-02 12:56:46 +00:00
|
|
|
|
void nsCSSRendering::Init()
|
2010-04-27 16:15:01 +00:00
|
|
|
|
{
|
2007-03-14 19:48:51 +00:00
|
|
|
|
NS_ASSERTION(!gInlineBGData, "Init called twice");
|
|
|
|
|
gInlineBGData = new InlineBackgroundData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Clean up any global variables used by nsCSSRendering.
|
|
|
|
|
void nsCSSRendering::Shutdown()
|
|
|
|
|
{
|
|
|
|
|
delete gInlineBGData;
|
2012-07-30 14:20:58 +00:00
|
|
|
|
gInlineBGData = nullptr;
|
2007-03-14 19:48:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
|
/**
|
|
|
|
|
* Make a bevel color
|
|
|
|
|
*/
|
2008-09-25 16:03:15 +00:00
|
|
|
|
static nscolor
|
2012-08-22 15:56:38 +00:00
|
|
|
|
MakeBevelColor(mozilla::css::Side whichSide, uint8_t style,
|
2008-09-25 16:03:15 +00:00
|
|
|
|
nscolor aBackgroundColor, nscolor aBorderColor)
|
1998-04-13 20:24:54 +00:00
|
|
|
|
{
|
1998-05-26 20:52:59 +00:00
|
|
|
|
|
|
|
|
|
nscolor colors[2];
|
|
|
|
|
nscolor theColor;
|
|
|
|
|
|
1999-03-05 19:23:52 +00:00
|
|
|
|
// Given a background color and a border color
|
|
|
|
|
// calculate the color used for the shading
|
2007-02-01 02:45:55 +00:00
|
|
|
|
NS_GetSpecial3DColors(colors, aBackgroundColor, aBorderColor);
|
2010-04-27 16:15:01 +00:00
|
|
|
|
|
2007-02-01 02:45:55 +00:00
|
|
|
|
if ((style == NS_STYLE_BORDER_STYLE_OUTSET) ||
|
1998-04-13 20:24:54 +00:00
|
|
|
|
(style == NS_STYLE_BORDER_STYLE_RIDGE)) {
|
2007-02-01 02:45:55 +00:00
|
|
|
|
// Flip colors for these two border styles
|
1998-04-13 20:24:54 +00:00
|
|
|
|
switch (whichSide) {
|
|
|
|
|
case NS_SIDE_BOTTOM: whichSide = NS_SIDE_TOP; break;
|
|
|
|
|
case NS_SIDE_RIGHT: whichSide = NS_SIDE_LEFT; break;
|
|
|
|
|
case NS_SIDE_TOP: whichSide = NS_SIDE_BOTTOM; break;
|
|
|
|
|
case NS_SIDE_LEFT: whichSide = NS_SIDE_RIGHT; break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (whichSide) {
|
|
|
|
|
case NS_SIDE_BOTTOM:
|
1998-05-26 20:52:59 +00:00
|
|
|
|
theColor = colors[1];
|
1998-04-13 20:24:54 +00:00
|
|
|
|
break;
|
|
|
|
|
case NS_SIDE_RIGHT:
|
1998-05-26 20:52:59 +00:00
|
|
|
|
theColor = colors[1];
|
1998-04-13 20:24:54 +00:00
|
|
|
|
break;
|
|
|
|
|
case NS_SIDE_TOP:
|
1998-05-26 20:52:59 +00:00
|
|
|
|
theColor = colors[0];
|
1998-04-13 20:24:54 +00:00
|
|
|
|
break;
|
|
|
|
|
case NS_SIDE_LEFT:
|
1999-04-13 21:52:19 +00:00
|
|
|
|
default:
|
1998-05-26 20:52:59 +00:00
|
|
|
|
theColor = colors[0];
|
1998-04-13 20:24:54 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return theColor;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-05 17:55:54 +00:00
|
|
|
|
static bool
|
|
|
|
|
GetRadii(nsIFrame* aForFrame, const nsStyleBorder& aBorder,
|
|
|
|
|
const nsRect& aOrigBorderArea, const nsRect& aBorderArea,
|
2014-07-23 05:20:39 +00:00
|
|
|
|
nscoord aRadii[8])
|
2014-05-05 17:55:54 +00:00
|
|
|
|
{
|
|
|
|
|
bool haveRoundedCorners;
|
|
|
|
|
nsSize sz = aBorderArea.Size();
|
|
|
|
|
nsSize frameSize = aForFrame->GetSize();
|
|
|
|
|
if (&aBorder == aForFrame->StyleBorder() &&
|
|
|
|
|
frameSize == aOrigBorderArea.Size()) {
|
2014-07-23 05:20:39 +00:00
|
|
|
|
haveRoundedCorners = aForFrame->GetBorderRadii(sz, sz, Sides(), aRadii);
|
2014-05-05 17:55:54 +00:00
|
|
|
|
} else {
|
|
|
|
|
haveRoundedCorners =
|
2014-07-23 05:20:39 +00:00
|
|
|
|
nsIFrame::ComputeBorderRadii(aBorder.mBorderRadius, frameSize, sz, Sides(), aRadii);
|
2014-05-05 17:55:54 +00:00
|
|
|
|
}
|
2014-07-23 05:20:39 +00:00
|
|
|
|
|
|
|
|
|
return haveRoundedCorners;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
GetRadii(nsIFrame* aForFrame, const nsStyleBorder& aBorder,
|
|
|
|
|
const nsRect& aOrigBorderArea, const nsRect& aBorderArea,
|
2014-11-01 10:45:10 +00:00
|
|
|
|
RectCornerRadii* aBgRadii)
|
2014-07-23 05:20:39 +00:00
|
|
|
|
{
|
|
|
|
|
nscoord radii[8];
|
|
|
|
|
bool haveRoundedCorners = GetRadii(aForFrame, aBorder, aOrigBorderArea, aBorderArea, radii);
|
|
|
|
|
|
2014-05-05 17:55:54 +00:00
|
|
|
|
if (haveRoundedCorners) {
|
|
|
|
|
auto d2a = aForFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
|
nsCSSRendering::ComputePixelRadii(radii, d2a, aBgRadii);
|
|
|
|
|
}
|
|
|
|
|
return haveRoundedCorners;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static nsRect
|
|
|
|
|
JoinBoxesForVerticalSlice(nsIFrame* aFrame, const nsRect& aBorderArea)
|
|
|
|
|
{
|
|
|
|
|
// Inflate vertically as if our continuations were laid out vertically
|
|
|
|
|
// adjacent. Note that we don't touch the width.
|
|
|
|
|
nsRect borderArea = aBorderArea;
|
|
|
|
|
nscoord h = 0;
|
|
|
|
|
nsIFrame* f = aFrame->GetNextContinuation();
|
|
|
|
|
for (; f; f = f->GetNextContinuation()) {
|
|
|
|
|
MOZ_ASSERT(!(f->GetStateBits() & NS_FRAME_PART_OF_IBSPLIT),
|
|
|
|
|
"anonymous ib-split block shouldn't have border/background");
|
|
|
|
|
h += f->GetRect().height;
|
|
|
|
|
}
|
|
|
|
|
borderArea.height += h;
|
|
|
|
|
h = 0;
|
|
|
|
|
f = aFrame->GetPrevContinuation();
|
|
|
|
|
for (; f; f = f->GetPrevContinuation()) {
|
|
|
|
|
MOZ_ASSERT(!(f->GetStateBits() & NS_FRAME_PART_OF_IBSPLIT),
|
|
|
|
|
"anonymous ib-split block shouldn't have border/background");
|
|
|
|
|
h += f->GetRect().height;
|
|
|
|
|
}
|
|
|
|
|
borderArea.y -= h;
|
|
|
|
|
borderArea.height += h;
|
|
|
|
|
return borderArea;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Inflate aBorderArea which is relative to aFrame's origin to calculate
|
|
|
|
|
* a hypothetical non-split frame area for all the continuations.
|
|
|
|
|
* See "Joining Boxes for 'slice'" in
|
|
|
|
|
* http://dev.w3.org/csswg/css-break/#break-decoration
|
|
|
|
|
*/
|
|
|
|
|
enum InlineBoxOrder { eForBorder, eForBackground };
|
|
|
|
|
static nsRect
|
|
|
|
|
JoinBoxesForSlice(nsIFrame* aFrame, const nsRect& aBorderArea,
|
|
|
|
|
InlineBoxOrder aOrder)
|
|
|
|
|
{
|
2015-01-15 09:02:11 +00:00
|
|
|
|
if (static_cast<nsInlineFrame*>(do_QueryFrame(aFrame))) {
|
2014-05-05 17:55:54 +00:00
|
|
|
|
return (aOrder == eForBorder
|
|
|
|
|
? gInlineBGData->GetBorderContinuousRect(aFrame, aBorderArea)
|
|
|
|
|
: gInlineBGData->GetContinuousRect(aFrame)) +
|
|
|
|
|
aBorderArea.TopLeft();
|
|
|
|
|
}
|
|
|
|
|
return JoinBoxesForVerticalSlice(aFrame, aBorderArea);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
IsBoxDecorationSlice(const nsStyleBorder& aStyleBorder)
|
|
|
|
|
{
|
|
|
|
|
return aStyleBorder.mBoxDecorationBreak ==
|
|
|
|
|
NS_STYLE_BOX_DECORATION_BREAK_SLICE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static nsRect
|
|
|
|
|
BoxDecorationRectForBorder(nsIFrame* aFrame, const nsRect& aBorderArea,
|
2014-09-17 00:36:57 +00:00
|
|
|
|
Sides aSkipSides,
|
2014-05-05 17:55:54 +00:00
|
|
|
|
const nsStyleBorder* aStyleBorder = nullptr)
|
|
|
|
|
{
|
|
|
|
|
if (!aStyleBorder) {
|
|
|
|
|
aStyleBorder = aFrame->StyleBorder();
|
|
|
|
|
}
|
2014-09-17 00:36:57 +00:00
|
|
|
|
// If aSkipSides.IsEmpty() then there are no continuations, or it's
|
|
|
|
|
// a ::first-letter that wants all border sides on the first continuation.
|
|
|
|
|
return ::IsBoxDecorationSlice(*aStyleBorder) && !aSkipSides.IsEmpty()
|
2014-05-05 17:55:54 +00:00
|
|
|
|
? ::JoinBoxesForSlice(aFrame, aBorderArea, eForBorder)
|
|
|
|
|
: aBorderArea;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-05 17:55:54 +00:00
|
|
|
|
static nsRect
|
|
|
|
|
BoxDecorationRectForBackground(nsIFrame* aFrame, const nsRect& aBorderArea,
|
2014-09-17 00:36:57 +00:00
|
|
|
|
Sides aSkipSides,
|
2014-05-05 17:55:54 +00:00
|
|
|
|
const nsStyleBorder* aStyleBorder = nullptr)
|
|
|
|
|
{
|
|
|
|
|
if (!aStyleBorder) {
|
|
|
|
|
aStyleBorder = aFrame->StyleBorder();
|
|
|
|
|
}
|
2014-09-17 00:36:57 +00:00
|
|
|
|
// If aSkipSides.IsEmpty() then there are no continuations, or it's
|
|
|
|
|
// a ::first-letter that wants all border sides on the first continuation.
|
|
|
|
|
return ::IsBoxDecorationSlice(*aStyleBorder) && !aSkipSides.IsEmpty()
|
2014-05-05 17:55:54 +00:00
|
|
|
|
? ::JoinBoxesForSlice(aFrame, aBorderArea, eForBackground)
|
|
|
|
|
: aBorderArea;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-01 03:31:25 +00:00
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
// Thebes Border Rendering Code Start
|
|
|
|
|
|
|
|
|
|
/*
|
2008-07-23 17:25:23 +00:00
|
|
|
|
* Compute the float-pixel radii that should be used for drawing
|
|
|
|
|
* this border/outline, given the various input bits.
|
2007-05-30 02:46:54 +00:00
|
|
|
|
*/
|
2014-10-31 11:16:27 +00:00
|
|
|
|
/* static */ void
|
|
|
|
|
nsCSSRendering::ComputePixelRadii(const nscoord *aAppUnitsRadii,
|
|
|
|
|
nscoord aAppUnitsPerPixel,
|
|
|
|
|
RectCornerRadii *oBorderRadii)
|
|
|
|
|
{
|
|
|
|
|
Float radii[8];
|
|
|
|
|
NS_FOR_CSS_HALF_CORNERS(corner)
|
|
|
|
|
radii[corner] = Float(aAppUnitsRadii[corner]) / aAppUnitsPerPixel;
|
|
|
|
|
|
|
|
|
|
(*oBorderRadii)[C_TL] = Size(radii[NS_CORNER_TOP_LEFT_X],
|
|
|
|
|
radii[NS_CORNER_TOP_LEFT_Y]);
|
|
|
|
|
(*oBorderRadii)[C_TR] = Size(radii[NS_CORNER_TOP_RIGHT_X],
|
|
|
|
|
radii[NS_CORNER_TOP_RIGHT_Y]);
|
|
|
|
|
(*oBorderRadii)[C_BR] = Size(radii[NS_CORNER_BOTTOM_RIGHT_X],
|
|
|
|
|
radii[NS_CORNER_BOTTOM_RIGHT_Y]);
|
|
|
|
|
(*oBorderRadii)[C_BL] = Size(radii[NS_CORNER_BOTTOM_LEFT_X],
|
|
|
|
|
radii[NS_CORNER_BOTTOM_LEFT_Y]);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-23 02:54:48 +00:00
|
|
|
|
DrawResult
|
2008-07-23 17:25:23 +00:00
|
|
|
|
nsCSSRendering::PaintBorder(nsPresContext* aPresContext,
|
2011-04-08 01:04:40 +00:00
|
|
|
|
nsRenderingContext& aRenderingContext,
|
2008-07-23 17:25:23 +00:00
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
|
const nsRect& aBorderArea,
|
|
|
|
|
nsStyleContext* aStyleContext,
|
2015-10-23 02:54:48 +00:00
|
|
|
|
PaintBorderFlags aFlags,
|
2014-06-28 10:13:13 +00:00
|
|
|
|
Sides aSkipSides)
|
2010-04-03 01:58:26 +00:00
|
|
|
|
{
|
2014-05-23 21:12:29 +00:00
|
|
|
|
PROFILER_LABEL("nsCSSRendering", "PaintBorder",
|
|
|
|
|
js::ProfileEntry::Category::GRAPHICS);
|
|
|
|
|
|
2010-04-03 01:58:26 +00:00
|
|
|
|
nsStyleContext *styleIfVisited = aStyleContext->GetStyleIfVisited();
|
2013-02-16 21:51:02 +00:00
|
|
|
|
const nsStyleBorder *styleBorder = aStyleContext->StyleBorder();
|
2010-04-03 01:58:26 +00:00
|
|
|
|
// Don't check RelevantLinkVisited here, since we want to take the
|
|
|
|
|
// same amount of time whether or not it's true.
|
|
|
|
|
if (!styleIfVisited) {
|
2015-10-23 02:54:48 +00:00
|
|
|
|
return PaintBorderWithStyleBorder(aPresContext, aRenderingContext, aForFrame,
|
|
|
|
|
aDirtyRect, aBorderArea, *styleBorder,
|
|
|
|
|
aStyleContext, aFlags, aSkipSides);
|
2010-04-03 01:58:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsStyleBorder newStyleBorder(*styleBorder);
|
2014-04-03 05:56:19 +00:00
|
|
|
|
// We could do something fancy to avoid the TrackImage/UntrackImage
|
|
|
|
|
// work, but it doesn't seem worth it. (We need to call TrackImage
|
|
|
|
|
// since we're not going through nsRuleNode::ComputeBorderData.)
|
|
|
|
|
newStyleBorder.TrackImage(aPresContext);
|
2010-09-08 00:30:40 +00:00
|
|
|
|
|
2010-04-03 01:58:26 +00:00
|
|
|
|
NS_FOR_CSS_SIDES(side) {
|
|
|
|
|
newStyleBorder.SetBorderColor(side,
|
|
|
|
|
aStyleContext->GetVisitedDependentColor(
|
|
|
|
|
nsCSSProps::SubpropertyEntryFor(eCSSProperty_border_color)[side]));
|
|
|
|
|
}
|
2015-10-23 02:54:48 +00:00
|
|
|
|
DrawResult result =
|
|
|
|
|
PaintBorderWithStyleBorder(aPresContext, aRenderingContext, aForFrame,
|
|
|
|
|
aDirtyRect, aBorderArea, newStyleBorder,
|
|
|
|
|
aStyleContext, aFlags, aSkipSides);
|
2014-04-03 05:56:19 +00:00
|
|
|
|
|
|
|
|
|
// We could do something fancy to avoid the TrackImage/UntrackImage
|
|
|
|
|
// work, but it doesn't seem worth it. (We need to call UntrackImage
|
|
|
|
|
// since we're not going through nsStyleBorder::Destroy.)
|
|
|
|
|
newStyleBorder.UntrackImage(aPresContext);
|
2015-10-23 02:54:48 +00:00
|
|
|
|
|
|
|
|
|
return result;
|
2010-04-03 01:58:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-23 02:54:48 +00:00
|
|
|
|
DrawResult
|
2010-04-03 01:58:26 +00:00
|
|
|
|
nsCSSRendering::PaintBorderWithStyleBorder(nsPresContext* aPresContext,
|
2011-04-08 01:04:40 +00:00
|
|
|
|
nsRenderingContext& aRenderingContext,
|
2010-04-03 01:58:26 +00:00
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
|
const nsRect& aBorderArea,
|
|
|
|
|
const nsStyleBorder& aStyleBorder,
|
|
|
|
|
nsStyleContext* aStyleContext,
|
2015-10-23 02:54:48 +00:00
|
|
|
|
PaintBorderFlags aFlags,
|
2014-06-28 10:13:13 +00:00
|
|
|
|
Sides aSkipSides)
|
2007-05-30 02:46:54 +00:00
|
|
|
|
{
|
2014-11-24 00:04:33 +00:00
|
|
|
|
DrawTarget& aDrawTarget = *aRenderingContext.GetDrawTarget();
|
|
|
|
|
|
2014-09-10 01:08:00 +00:00
|
|
|
|
PrintAsStringNewline("++ PaintBorder");
|
2007-05-30 02:46:54 +00:00
|
|
|
|
|
2008-07-23 17:25:23 +00:00
|
|
|
|
// Check to see if we have an appearance defined. If so, we let the theme
|
|
|
|
|
// renderer draw the border. DO not get the data from aForFrame, since the passed in style context
|
|
|
|
|
// may be different! Always use |aStyleContext|!
|
2013-02-16 21:51:02 +00:00
|
|
|
|
const nsStyleDisplay* displayData = aStyleContext->StyleDisplay();
|
2008-07-23 17:25:23 +00:00
|
|
|
|
if (displayData->mAppearance) {
|
|
|
|
|
nsITheme *theme = aPresContext->GetTheme();
|
2015-10-23 02:54:48 +00:00
|
|
|
|
if (theme &&
|
|
|
|
|
theme->ThemeSupportsWidget(aPresContext, aForFrame,
|
|
|
|
|
displayData->mAppearance)) {
|
|
|
|
|
return DrawResult::SUCCESS; // Let the theme handle it.
|
|
|
|
|
}
|
2007-05-30 02:46:54 +00:00
|
|
|
|
}
|
2007-05-08 17:40:08 +00:00
|
|
|
|
|
2009-11-14 04:23:00 +00:00
|
|
|
|
if (aStyleBorder.IsBorderImageLoaded()) {
|
2015-10-23 02:54:48 +00:00
|
|
|
|
return DrawBorderImage(aPresContext, aRenderingContext, aForFrame,
|
|
|
|
|
aBorderArea, aStyleBorder, aDirtyRect,
|
|
|
|
|
aSkipSides, aFlags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DrawResult result = DrawResult::SUCCESS;
|
|
|
|
|
|
|
|
|
|
// If we had a border-image, but it wasn't loaded, then we should return
|
|
|
|
|
// DrawResult::NOT_READY; we'll want to try again if we do a paint with sync
|
|
|
|
|
// decoding enabled.
|
|
|
|
|
if (aStyleBorder.mBorderImageSource.GetType() != eStyleImageType_Null) {
|
|
|
|
|
result = DrawResult::NOT_READY;
|
2007-05-30 02:46:54 +00:00
|
|
|
|
}
|
2010-04-27 16:15:01 +00:00
|
|
|
|
|
2008-07-23 17:25:23 +00:00
|
|
|
|
// Get our style context's color struct.
|
2013-02-16 21:51:02 +00:00
|
|
|
|
const nsStyleColor* ourColor = aStyleContext->StyleColor();
|
2007-05-01 03:31:25 +00:00
|
|
|
|
|
2014-05-05 17:55:54 +00:00
|
|
|
|
// In NavQuirks mode we want to use the parent's context as a starting point
|
|
|
|
|
// for determining the background color.
|
|
|
|
|
bool quirks = aPresContext->CompatibilityMode() == eCompatibility_NavQuirks;
|
|
|
|
|
nsIFrame* bgFrame = FindNonTransparentBackgroundFrame(aForFrame, quirks);
|
2013-02-16 05:38:33 +00:00
|
|
|
|
nsStyleContext* bgContext = bgFrame->StyleContext();
|
2010-04-03 01:58:26 +00:00
|
|
|
|
nscolor bgColor =
|
|
|
|
|
bgContext->GetVisitedDependentColor(eCSSProperty_background_color);
|
2007-05-01 03:31:25 +00:00
|
|
|
|
|
2014-05-05 17:55:54 +00:00
|
|
|
|
nsMargin border = aStyleBorder.GetComputedBorder();
|
2014-05-05 17:55:55 +00:00
|
|
|
|
if (0 == border.left && 0 == border.right &&
|
|
|
|
|
0 == border.top && 0 == border.bottom) {
|
2008-07-23 17:25:23 +00:00
|
|
|
|
// Empty border area
|
2015-10-23 02:54:48 +00:00
|
|
|
|
return result;
|
2007-05-01 03:31:25 +00:00
|
|
|
|
}
|
2007-05-30 02:46:54 +00:00
|
|
|
|
|
2014-05-05 17:55:54 +00:00
|
|
|
|
// Compute the outermost boundary of the area that might be painted.
|
|
|
|
|
// Same coordinate space as aBorderArea & aBGClipRect.
|
|
|
|
|
nsRect joinedBorderArea =
|
2014-09-17 00:36:57 +00:00
|
|
|
|
::BoxDecorationRectForBorder(aForFrame, aBorderArea, aSkipSides, &aStyleBorder);
|
2014-11-01 10:45:10 +00:00
|
|
|
|
RectCornerRadii bgRadii;
|
2014-05-05 17:55:54 +00:00
|
|
|
|
::GetRadii(aForFrame, aStyleBorder, aBorderArea, joinedBorderArea, &bgRadii);
|
2007-05-30 02:46:54 +00:00
|
|
|
|
|
2014-09-10 01:08:00 +00:00
|
|
|
|
PrintAsFormatString(" joinedBorderArea: %d %d %d %d\n", joinedBorderArea.x, joinedBorderArea.y,
|
2014-05-05 17:55:54 +00:00
|
|
|
|
joinedBorderArea.width, joinedBorderArea.height);
|
2007-05-01 03:31:25 +00:00
|
|
|
|
|
2014-05-05 17:55:54 +00:00
|
|
|
|
// start drawing
|
2015-12-04 03:16:25 +00:00
|
|
|
|
bool needToPopClip = false;
|
2007-05-30 02:46:54 +00:00
|
|
|
|
|
2014-05-05 17:55:54 +00:00
|
|
|
|
if (::IsBoxDecorationSlice(aStyleBorder)) {
|
2014-09-17 00:36:57 +00:00
|
|
|
|
if (joinedBorderArea.IsEqualEdges(aBorderArea)) {
|
2014-05-05 17:55:54 +00:00
|
|
|
|
// No need for a clip, just skip the sides we don't want.
|
2014-06-24 17:52:19 +00:00
|
|
|
|
border.ApplySkipSides(aSkipSides);
|
2014-05-05 17:55:54 +00:00
|
|
|
|
} else {
|
|
|
|
|
// We're drawing borders around the joined continuation boxes so we need
|
|
|
|
|
// to clip that to the slice that we want for this frame.
|
2015-12-04 03:16:25 +00:00
|
|
|
|
aDrawTarget.PushClipRect(
|
|
|
|
|
NSRectToSnappedRect(aBorderArea,
|
|
|
|
|
aForFrame->PresContext()->AppUnitsPerDevPixel(),
|
|
|
|
|
aDrawTarget));
|
|
|
|
|
needToPopClip = true;
|
2014-05-05 17:55:54 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
MOZ_ASSERT(joinedBorderArea.IsEqualEdges(aBorderArea),
|
|
|
|
|
"Should use aBorderArea for box-decoration-break:clone");
|
2016-03-02 22:39:34 +00:00
|
|
|
|
MOZ_ASSERT(aForFrame->GetSkipSides().IsEmpty() ||
|
|
|
|
|
IS_TRUE_OVERFLOW_CONTAINER(aForFrame),
|
2014-05-05 17:55:54 +00:00
|
|
|
|
"Should not skip sides for box-decoration-break:clone except "
|
|
|
|
|
"::first-letter/line continuations or other frame types that "
|
2016-03-02 22:39:34 +00:00
|
|
|
|
"don't have borders but those shouldn't reach this point. "
|
|
|
|
|
"Overflow containers do reach this point though.");
|
|
|
|
|
border.ApplySkipSides(aSkipSides);
|
2014-05-05 17:55:54 +00:00
|
|
|
|
}
|
2007-05-30 02:46:54 +00:00
|
|
|
|
|
2014-05-05 17:55:54 +00:00
|
|
|
|
// Convert to dev pixels.
|
2008-07-23 17:25:23 +00:00
|
|
|
|
nscoord twipsPerPixel = aPresContext->DevPixelsToAppUnits(1);
|
2014-11-03 10:03:09 +00:00
|
|
|
|
Rect joinedBorderAreaPx = NSRectToRect(joinedBorderArea, twipsPerPixel);
|
|
|
|
|
Float borderWidths[4] = { Float(border.top / twipsPerPixel),
|
|
|
|
|
Float(border.right / twipsPerPixel),
|
|
|
|
|
Float(border.bottom / twipsPerPixel),
|
|
|
|
|
Float(border.left / twipsPerPixel) };
|
2016-06-10 04:10:03 +00:00
|
|
|
|
Rect dirtyRect = NSRectToRect(aDirtyRect, twipsPerPixel);
|
2007-05-30 02:46:54 +00:00
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
|
uint8_t borderStyles[4];
|
2008-07-23 17:25:23 +00:00
|
|
|
|
nscolor borderColors[4];
|
|
|
|
|
nsBorderColors *compositeColors[4];
|
2007-05-30 02:46:54 +00:00
|
|
|
|
|
2008-07-23 17:25:23 +00:00
|
|
|
|
// pull out styles, colors, composite colors
|
|
|
|
|
NS_FOR_CSS_SIDES (i) {
|
2011-09-29 06:19:26 +00:00
|
|
|
|
bool foreground;
|
2009-11-14 04:23:00 +00:00
|
|
|
|
borderStyles[i] = aStyleBorder.GetBorderStyle(i);
|
|
|
|
|
aStyleBorder.GetBorderColor(i, borderColors[i], foreground);
|
|
|
|
|
aStyleBorder.GetCompositeColors(i, &compositeColors[i]);
|
2007-05-30 02:46:54 +00:00
|
|
|
|
|
2008-09-12 15:35:53 +00:00
|
|
|
|
if (foreground)
|
2008-07-23 17:25:23 +00:00
|
|
|
|
borderColors[i] = ourColor->mColor;
|
2007-05-30 02:46:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-09-10 01:08:00 +00:00
|
|
|
|
PrintAsFormatString(" borderStyles: %d %d %d %d\n", borderStyles[0], borderStyles[1], borderStyles[2], borderStyles[3]);
|
|
|
|
|
//PrintAsFormatString ("bgRadii: %f %f %f %f\n", bgRadii[0], bgRadii[1], bgRadii[2], bgRadii[3]);
|
2007-05-30 02:46:54 +00:00
|
|
|
|
|
2008-07-23 17:25:23 +00:00
|
|
|
|
#if 0
|
2014-05-05 17:55:54 +00:00
|
|
|
|
// this will draw a transparent red backround underneath the border area
|
2014-11-24 00:04:33 +00:00
|
|
|
|
ColorPattern color(ToDeviceColor(Color(1.f, 0.f, 0.f, 0.5f)));
|
|
|
|
|
aDrawTarget.FillRect(joinedBorderAreaPx, color);
|
2008-07-23 17:25:23 +00:00
|
|
|
|
#endif
|
2007-05-30 02:46:54 +00:00
|
|
|
|
|
2016-06-10 04:10:03 +00:00
|
|
|
|
nsIDocument* document = nullptr;
|
|
|
|
|
nsIContent* content = aForFrame->GetContent();
|
|
|
|
|
if (content) {
|
|
|
|
|
document = content->OwnerDoc();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsCSSBorderRenderer br(aPresContext,
|
|
|
|
|
document,
|
2015-07-31 18:09:29 +00:00
|
|
|
|
&aDrawTarget,
|
2016-06-10 04:10:03 +00:00
|
|
|
|
dirtyRect,
|
2014-05-05 17:55:54 +00:00
|
|
|
|
joinedBorderAreaPx,
|
2008-07-23 17:25:23 +00:00
|
|
|
|
borderStyles,
|
|
|
|
|
borderWidths,
|
2014-05-05 17:55:54 +00:00
|
|
|
|
bgRadii,
|
2008-07-23 17:25:23 +00:00
|
|
|
|
borderColors,
|
|
|
|
|
compositeColors,
|
2010-04-03 01:58:26 +00:00
|
|
|
|
bgColor);
|
2008-07-23 17:25:23 +00:00
|
|
|
|
br.DrawBorders();
|
2007-05-01 03:31:25 +00:00
|
|
|
|
|
2015-12-04 03:16:25 +00:00
|
|
|
|
if (needToPopClip) {
|
|
|
|
|
aDrawTarget.PopClip();
|
|
|
|
|
}
|
2007-05-30 02:46:54 +00:00
|
|
|
|
|
2014-09-10 01:08:00 +00:00
|
|
|
|
PrintAsStringNewline();
|
2015-10-23 02:54:48 +00:00
|
|
|
|
|
|
|
|
|
return result;
|
2007-05-30 02:46:54 +00:00
|
|
|
|
}
|
2007-05-01 03:31:25 +00:00
|
|
|
|
|
2008-09-11 00:24:16 +00:00
|
|
|
|
static nsRect
|
|
|
|
|
GetOutlineInnerRect(nsIFrame* aFrame)
|
|
|
|
|
{
|
2016-06-21 20:17:11 +00:00
|
|
|
|
nsRect* savedOutlineInnerRect =
|
|
|
|
|
aFrame->Properties().Get(nsIFrame::OutlineInnerRectProperty());
|
2008-09-11 00:24:16 +00:00
|
|
|
|
if (savedOutlineInnerRect)
|
|
|
|
|
return *savedOutlineInnerRect;
|
2014-02-17 00:05:10 +00:00
|
|
|
|
NS_NOTREACHED("we should have saved a frame property");
|
|
|
|
|
return nsRect(nsPoint(0, 0), aFrame->GetSize());
|
2008-09-11 00:24:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-07-23 17:25:23 +00:00
|
|
|
|
void
|
|
|
|
|
nsCSSRendering::PaintOutline(nsPresContext* aPresContext,
|
2011-04-08 01:04:40 +00:00
|
|
|
|
nsRenderingContext& aRenderingContext,
|
2008-07-23 17:25:23 +00:00
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
|
const nsRect& aBorderArea,
|
2008-08-06 10:33:18 +00:00
|
|
|
|
nsStyleContext* aStyleContext)
|
2007-05-30 02:46:54 +00:00
|
|
|
|
{
|
2008-10-01 05:50:52 +00:00
|
|
|
|
nscoord twipsRadii[8];
|
2007-05-30 02:46:54 +00:00
|
|
|
|
|
2008-07-23 17:25:23 +00:00
|
|
|
|
// Get our style context's color struct.
|
2013-02-16 21:51:02 +00:00
|
|
|
|
const nsStyleOutline* ourOutline = aStyleContext->StyleOutline();
|
2014-06-14 12:48:07 +00:00
|
|
|
|
MOZ_ASSERT(ourOutline != NS_STYLE_BORDER_STYLE_NONE,
|
|
|
|
|
"shouldn't have created nsDisplayOutline item");
|
2007-05-30 02:46:54 +00:00
|
|
|
|
|
2014-06-14 12:48:07 +00:00
|
|
|
|
uint8_t outlineStyle = ourOutline->GetOutlineStyle();
|
2016-04-20 22:05:30 +00:00
|
|
|
|
nscoord width = ourOutline->GetOutlineWidth();
|
2007-05-30 02:46:54 +00:00
|
|
|
|
|
2014-06-14 12:48:07 +00:00
|
|
|
|
if (width == 0 && outlineStyle != NS_STYLE_BORDER_STYLE_AUTO) {
|
2008-07-23 17:25:23 +00:00
|
|
|
|
// Empty outline
|
|
|
|
|
return;
|
2007-05-30 02:46:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-04-08 12:44:57 +00:00
|
|
|
|
nsIFrame* bgFrame = nsCSSRendering::FindNonTransparentBackgroundFrame
|
2011-10-17 14:59:28 +00:00
|
|
|
|
(aForFrame, false);
|
2013-02-16 05:38:33 +00:00
|
|
|
|
nsStyleContext* bgContext = bgFrame->StyleContext();
|
2010-04-03 01:58:26 +00:00
|
|
|
|
nscolor bgColor =
|
|
|
|
|
bgContext->GetVisitedDependentColor(eCSSProperty_background_color);
|
2007-05-30 02:46:54 +00:00
|
|
|
|
|
2014-02-17 00:05:10 +00:00
|
|
|
|
nsRect innerRect;
|
|
|
|
|
if (
|
|
|
|
|
#ifdef MOZ_XUL
|
2016-02-16 22:07:00 +00:00
|
|
|
|
aStyleContext->GetPseudoType() == CSSPseudoElementType::XULTree
|
2014-02-17 00:05:10 +00:00
|
|
|
|
#else
|
|
|
|
|
false
|
|
|
|
|
#endif
|
|
|
|
|
) {
|
2014-02-18 04:07:46 +00:00
|
|
|
|
innerRect = aBorderArea;
|
2014-02-15 07:45:31 +00:00
|
|
|
|
} else {
|
2014-02-18 04:07:46 +00:00
|
|
|
|
innerRect = GetOutlineInnerRect(aForFrame) + aBorderArea.TopLeft();
|
2008-06-02 22:52:25 +00:00
|
|
|
|
}
|
2010-04-03 01:58:26 +00:00
|
|
|
|
nscoord offset = ourOutline->mOutlineOffset;
|
2008-09-11 00:24:16 +00:00
|
|
|
|
innerRect.Inflate(offset, offset);
|
2007-05-01 03:31:25 +00:00
|
|
|
|
// If the dirty rect is completely inside the border area (e.g., only the
|
|
|
|
|
// content is being painted), then we can skip out now
|
|
|
|
|
// XXX this isn't exactly true for rounded borders, where the inside curves may
|
|
|
|
|
// encroach into the content area. A safer calculation would be to
|
|
|
|
|
// shorten insideRect by the radius one each side before performing this test.
|
2008-09-11 00:24:16 +00:00
|
|
|
|
if (innerRect.Contains(aDirtyRect))
|
2007-05-01 03:31:25 +00:00
|
|
|
|
return;
|
2008-09-11 00:24:16 +00:00
|
|
|
|
|
|
|
|
|
nsRect outerRect = innerRect;
|
|
|
|
|
outerRect.Inflate(width, width);
|
2000-02-01 16:03:13 +00:00
|
|
|
|
|
2010-09-07 22:20:35 +00:00
|
|
|
|
// get the radius for our outline
|
|
|
|
|
nsIFrame::ComputeBorderRadii(ourOutline->mOutlineRadius, aBorderArea.Size(),
|
2014-06-28 10:13:13 +00:00
|
|
|
|
outerRect.Size(), Sides(), twipsRadii);
|
2010-09-07 22:20:35 +00:00
|
|
|
|
|
2007-05-30 02:46:54 +00:00
|
|
|
|
// Get our conversion values
|
2007-05-01 03:31:25 +00:00
|
|
|
|
nscoord twipsPerPixel = aPresContext->DevPixelsToAppUnits(1);
|
|
|
|
|
|
2008-07-23 17:25:23 +00:00
|
|
|
|
// get the outer rectangles
|
2014-11-03 10:03:09 +00:00
|
|
|
|
Rect oRect(NSRectToRect(outerRect, twipsPerPixel));
|
1999-08-19 14:22:47 +00:00
|
|
|
|
|
2007-05-30 02:46:54 +00:00
|
|
|
|
// convert the radii
|
2007-07-18 14:14:53 +00:00
|
|
|
|
nsMargin outlineMargin(width, width, width, width);
|
2014-11-01 10:45:10 +00:00
|
|
|
|
RectCornerRadii outlineRadii;
|
2010-09-07 22:20:35 +00:00
|
|
|
|
ComputePixelRadii(twipsRadii, twipsPerPixel, &outlineRadii);
|
1999-08-19 14:22:47 +00:00
|
|
|
|
|
2015-10-16 23:13:26 +00:00
|
|
|
|
if (outlineStyle == NS_STYLE_BORDER_STYLE_AUTO) {
|
|
|
|
|
if (nsLayoutUtils::IsOutlineStyleAutoEnabled()) {
|
2014-06-26 12:48:05 +00:00
|
|
|
|
nsITheme* theme = aPresContext->GetTheme();
|
|
|
|
|
if (theme && theme->ThemeSupportsWidget(aPresContext, aForFrame,
|
|
|
|
|
NS_THEME_FOCUS_OUTLINE)) {
|
|
|
|
|
theme->DrawWidgetBackground(&aRenderingContext, aForFrame,
|
|
|
|
|
NS_THEME_FOCUS_OUTLINE, innerRect,
|
|
|
|
|
aDirtyRect);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-06-14 12:48:07 +00:00
|
|
|
|
}
|
2015-10-16 23:13:26 +00:00
|
|
|
|
if (width == 0) {
|
|
|
|
|
return; // empty outline
|
|
|
|
|
}
|
|
|
|
|
// http://dev.w3.org/csswg/css-ui/#outline
|
|
|
|
|
// "User agents may treat 'auto' as 'solid'."
|
|
|
|
|
outlineStyle = NS_STYLE_BORDER_STYLE_SOLID;
|
2014-06-14 12:48:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t outlineStyles[4] = { outlineStyle, outlineStyle,
|
|
|
|
|
outlineStyle, outlineStyle };
|
2007-05-20 22:41:21 +00:00
|
|
|
|
|
2010-04-03 01:58:26 +00:00
|
|
|
|
// This handles treating the initial color as 'currentColor'; if we
|
|
|
|
|
// ever want 'invert' back we'll need to do a bit of work here too.
|
|
|
|
|
nscolor outlineColor =
|
|
|
|
|
aStyleContext->GetVisitedDependentColor(eCSSProperty_outline_color);
|
2007-05-30 02:46:54 +00:00
|
|
|
|
nscolor outlineColors[4] = { outlineColor,
|
|
|
|
|
outlineColor,
|
|
|
|
|
outlineColor,
|
|
|
|
|
outlineColor };
|
2007-05-01 04:58:44 +00:00
|
|
|
|
|
2007-05-30 02:46:54 +00:00
|
|
|
|
// convert the border widths
|
2014-11-03 10:03:09 +00:00
|
|
|
|
Float outlineWidths[4] = { Float(width / twipsPerPixel),
|
|
|
|
|
Float(width / twipsPerPixel),
|
|
|
|
|
Float(width / twipsPerPixel),
|
|
|
|
|
Float(width / twipsPerPixel) };
|
2016-06-10 04:10:03 +00:00
|
|
|
|
Rect dirtyRect = NSRectToRect(aDirtyRect, twipsPerPixel);
|
1999-08-19 14:22:47 +00:00
|
|
|
|
|
2016-06-10 04:10:03 +00:00
|
|
|
|
nsIDocument* document = nullptr;
|
|
|
|
|
nsIContent* content = aForFrame->GetContent();
|
|
|
|
|
if (content) {
|
|
|
|
|
document = content->OwnerDoc();
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-30 02:46:54 +00:00
|
|
|
|
// start drawing
|
1999-01-03 19:23:21 +00:00
|
|
|
|
|
2016-06-10 04:10:03 +00:00
|
|
|
|
nsCSSBorderRenderer br(aPresContext,
|
|
|
|
|
document,
|
2015-12-18 03:36:09 +00:00
|
|
|
|
aRenderingContext.GetDrawTarget(),
|
2016-06-10 04:10:03 +00:00
|
|
|
|
dirtyRect,
|
2008-07-23 17:25:23 +00:00
|
|
|
|
oRect,
|
|
|
|
|
outlineStyles,
|
|
|
|
|
outlineWidths,
|
|
|
|
|
outlineRadii,
|
|
|
|
|
outlineColors,
|
2014-05-05 17:55:54 +00:00
|
|
|
|
nullptr,
|
2010-04-03 01:58:26 +00:00
|
|
|
|
bgColor);
|
2008-08-06 10:33:18 +00:00
|
|
|
|
br.DrawBorders();
|
|
|
|
|
|
2014-09-10 01:08:00 +00:00
|
|
|
|
PrintAsStringNewline();
|
2008-08-06 10:33:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nsCSSRendering::PaintFocus(nsPresContext* aPresContext,
|
2015-12-04 03:16:59 +00:00
|
|
|
|
DrawTarget* aDrawTarget,
|
2008-08-06 10:33:18 +00:00
|
|
|
|
const nsRect& aFocusRect,
|
|
|
|
|
nscolor aColor)
|
|
|
|
|
{
|
|
|
|
|
nscoord oneCSSPixel = nsPresContext::CSSPixelsToAppUnits(1);
|
|
|
|
|
nscoord oneDevPixel = aPresContext->DevPixelsToAppUnits(1);
|
|
|
|
|
|
2014-11-03 10:03:09 +00:00
|
|
|
|
Rect focusRect(NSRectToRect(aFocusRect, oneDevPixel));
|
2008-08-06 10:33:18 +00:00
|
|
|
|
|
2014-11-01 10:45:10 +00:00
|
|
|
|
RectCornerRadii focusRadii;
|
2008-08-06 10:33:18 +00:00
|
|
|
|
{
|
2008-10-01 05:50:52 +00:00
|
|
|
|
nscoord twipsRadii[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
|
2010-09-07 22:20:35 +00:00
|
|
|
|
ComputePixelRadii(twipsRadii, oneDevPixel, &focusRadii);
|
2008-08-06 10:33:18 +00:00
|
|
|
|
}
|
2014-11-03 10:03:09 +00:00
|
|
|
|
Float focusWidths[4] = { Float(oneCSSPixel / oneDevPixel),
|
|
|
|
|
Float(oneCSSPixel / oneDevPixel),
|
|
|
|
|
Float(oneCSSPixel / oneDevPixel),
|
|
|
|
|
Float(oneCSSPixel / oneDevPixel) };
|
2008-08-06 10:33:18 +00:00
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
|
uint8_t focusStyles[4] = { NS_STYLE_BORDER_STYLE_DOTTED,
|
2008-08-06 10:33:18 +00:00
|
|
|
|
NS_STYLE_BORDER_STYLE_DOTTED,
|
|
|
|
|
NS_STYLE_BORDER_STYLE_DOTTED,
|
|
|
|
|
NS_STYLE_BORDER_STYLE_DOTTED };
|
|
|
|
|
nscolor focusColors[4] = { aColor, aColor, aColor, aColor };
|
|
|
|
|
|
|
|
|
|
// Because this renders a dotted border, the background color
|
|
|
|
|
// should not be used. Therefore, we provide a value that will
|
|
|
|
|
// be blatantly wrong if it ever does get used. (If this becomes
|
|
|
|
|
// something that CSS can style, this function will then have access
|
|
|
|
|
// to a style context and can use the same logic that PaintBorder
|
|
|
|
|
// and PaintOutline do.)
|
2016-06-10 04:10:03 +00:00
|
|
|
|
nsCSSBorderRenderer br(aPresContext,
|
|
|
|
|
nullptr,
|
2015-12-04 03:16:59 +00:00
|
|
|
|
aDrawTarget,
|
2008-08-06 10:33:18 +00:00
|
|
|
|
focusRect,
|
2016-06-10 04:10:03 +00:00
|
|
|
|
focusRect,
|
2008-08-06 10:33:18 +00:00
|
|
|
|
focusStyles,
|
|
|
|
|
focusWidths,
|
|
|
|
|
focusRadii,
|
|
|
|
|
focusColors,
|
2014-05-05 17:55:54 +00:00
|
|
|
|
nullptr,
|
2008-08-06 10:33:18 +00:00
|
|
|
|
NS_RGB(255, 0, 0));
|
2008-07-23 17:25:23 +00:00
|
|
|
|
br.DrawBorders();
|
2007-05-01 03:31:25 +00:00
|
|
|
|
|
2014-09-10 01:08:00 +00:00
|
|
|
|
PrintAsStringNewline();
|
1998-12-17 22:58:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-05-01 03:31:25 +00:00
|
|
|
|
// Thebes Border Rendering Code End
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
1998-12-17 22:58:51 +00:00
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
2014-10-22 20:03:18 +00:00
|
|
|
|
/**
|
2014-10-22 20:03:18 +00:00
|
|
|
|
* Helper for ComputeObjectAnchorPoint; parameters are the same as for
|
2014-10-22 20:03:18 +00:00
|
|
|
|
* that function, except they're for a single coordinate / a single size
|
|
|
|
|
* dimension. (so, x/width vs. y/height)
|
|
|
|
|
*/
|
2016-01-28 05:24:00 +00:00
|
|
|
|
typedef nsStyleImageLayers::Position::PositionCoord PositionCoord;
|
2014-10-22 20:03:18 +00:00
|
|
|
|
static void
|
2014-10-22 20:03:18 +00:00
|
|
|
|
ComputeObjectAnchorCoord(const PositionCoord& aCoord,
|
|
|
|
|
const nscoord aOriginBounds,
|
|
|
|
|
const nscoord aImageSize,
|
|
|
|
|
nscoord* aTopLeftCoord,
|
|
|
|
|
nscoord* aAnchorPointCoord)
|
2014-10-22 20:03:18 +00:00
|
|
|
|
{
|
|
|
|
|
*aAnchorPointCoord = aCoord.mLength;
|
|
|
|
|
*aTopLeftCoord = aCoord.mLength;
|
|
|
|
|
|
|
|
|
|
if (aCoord.mHasPercent) {
|
|
|
|
|
// Adjust aTopLeftCoord by the specified % of the extra space.
|
|
|
|
|
nscoord extraSpace = aOriginBounds - aImageSize;
|
|
|
|
|
*aTopLeftCoord += NSToCoordRound(aCoord.mPercent * extraSpace);
|
|
|
|
|
|
|
|
|
|
// The anchor-point doesn't care about our image's size; just the size
|
|
|
|
|
// of the region we're rendering into.
|
|
|
|
|
*aAnchorPointCoord += NSToCoordRound(aCoord.mPercent * aOriginBounds);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-22 20:03:18 +00:00
|
|
|
|
void
|
|
|
|
|
nsImageRenderer::ComputeObjectAnchorPoint(
|
2016-01-28 05:24:00 +00:00
|
|
|
|
const nsStyleImageLayers::Position& aPos,
|
2014-10-22 20:03:18 +00:00
|
|
|
|
const nsSize& aOriginBounds,
|
|
|
|
|
const nsSize& aImageSize,
|
|
|
|
|
nsPoint* aTopLeft,
|
|
|
|
|
nsPoint* aAnchorPoint)
|
1998-09-26 17:16:56 +00:00
|
|
|
|
{
|
2014-10-22 20:03:18 +00:00
|
|
|
|
ComputeObjectAnchorCoord(aPos.mXPosition,
|
|
|
|
|
aOriginBounds.width, aImageSize.width,
|
|
|
|
|
&aTopLeft->x, &aAnchorPoint->x);
|
2014-10-22 20:03:18 +00:00
|
|
|
|
|
2014-10-22 20:03:18 +00:00
|
|
|
|
ComputeObjectAnchorCoord(aPos.mYPosition,
|
|
|
|
|
aOriginBounds.height, aImageSize.height,
|
|
|
|
|
&aTopLeft->y, &aAnchorPoint->y);
|
1999-04-25 02:43:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-04-08 12:44:57 +00:00
|
|
|
|
nsIFrame*
|
|
|
|
|
nsCSSRendering::FindNonTransparentBackgroundFrame(nsIFrame* aFrame,
|
2011-09-29 06:19:26 +00:00
|
|
|
|
bool aStartAtParent /*= false*/)
|
2002-08-11 17:56:15 +00:00
|
|
|
|
{
|
2010-04-08 12:44:57 +00:00
|
|
|
|
NS_ASSERTION(aFrame, "Cannot find NonTransparentBackgroundFrame in a null frame");
|
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
|
nsIFrame* frame = nullptr;
|
2002-08-11 17:56:15 +00:00
|
|
|
|
if (aStartAtParent) {
|
2012-06-08 12:22:25 +00:00
|
|
|
|
frame = nsLayoutUtils::GetParentOrPlaceholderFor(aFrame);
|
2004-03-31 03:13:54 +00:00
|
|
|
|
}
|
2010-04-08 12:44:57 +00:00
|
|
|
|
if (!frame) {
|
|
|
|
|
frame = aFrame;
|
2002-08-11 17:56:15 +00:00
|
|
|
|
}
|
2010-04-08 12:44:57 +00:00
|
|
|
|
|
|
|
|
|
while (frame) {
|
2010-04-03 01:58:26 +00:00
|
|
|
|
// No need to call GetVisitedDependentColor because it always uses
|
|
|
|
|
// this alpha component anyway.
|
2013-02-16 21:51:02 +00:00
|
|
|
|
if (NS_GET_A(frame->StyleBackground()->mBackgroundColor) > 0)
|
2002-08-11 17:56:15 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2010-04-08 12:44:57 +00:00
|
|
|
|
if (frame->IsThemed())
|
2009-01-09 00:29:38 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2012-06-08 12:22:25 +00:00
|
|
|
|
nsIFrame* parent = nsLayoutUtils::GetParentOrPlaceholderFor(frame);
|
2009-01-09 00:29:38 +00:00
|
|
|
|
if (!parent)
|
|
|
|
|
break;
|
|
|
|
|
|
2010-04-08 12:44:57 +00:00
|
|
|
|
frame = parent;
|
2002-08-11 17:56:15 +00:00
|
|
|
|
}
|
2010-04-08 12:44:57 +00:00
|
|
|
|
return frame;
|
2002-08-11 17:56:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-04-10 13:41:59 +00:00
|
|
|
|
// Returns true if aFrame is a canvas frame.
|
|
|
|
|
// We need to treat the viewport as canvas because, even though
|
|
|
|
|
// it does not actually paint a background, we need to get the right
|
|
|
|
|
// background style so we correctly detect transparent documents.
|
2011-09-29 06:19:26 +00:00
|
|
|
|
bool
|
2009-04-10 13:41:59 +00:00
|
|
|
|
nsCSSRendering::IsCanvasFrame(nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
nsIAtom* frameType = aFrame->GetType();
|
|
|
|
|
return frameType == nsGkAtoms::canvasFrame ||
|
|
|
|
|
frameType == nsGkAtoms::rootFrame ||
|
|
|
|
|
frameType == nsGkAtoms::pageContentFrame ||
|
|
|
|
|
frameType == nsGkAtoms::viewportFrame;
|
|
|
|
|
}
|
2002-08-11 17:56:15 +00:00
|
|
|
|
|
2009-04-10 13:41:59 +00:00
|
|
|
|
nsIFrame*
|
2009-12-01 17:21:00 +00:00
|
|
|
|
nsCSSRendering::FindBackgroundStyleFrame(nsIFrame* aForFrame)
|
2009-04-10 13:41:59 +00:00
|
|
|
|
{
|
2013-02-16 21:51:02 +00:00
|
|
|
|
const nsStyleBackground* result = aForFrame->StyleBackground();
|
2009-04-10 13:41:59 +00:00
|
|
|
|
|
|
|
|
|
// Check if we need to do propagation from BODY rather than HTML.
|
2011-06-02 12:56:46 +00:00
|
|
|
|
if (!result->IsTransparent()) {
|
|
|
|
|
return aForFrame;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsIContent* content = aForFrame->GetContent();
|
|
|
|
|
// The root element content can't be null. We wouldn't know what
|
|
|
|
|
// frame to create for aFrame.
|
2011-10-18 11:19:44 +00:00
|
|
|
|
// Use |OwnerDoc| so it works during destruction.
|
2011-06-02 12:56:46 +00:00
|
|
|
|
if (!content) {
|
|
|
|
|
return aForFrame;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-18 10:53:36 +00:00
|
|
|
|
nsIDocument* document = content->OwnerDoc();
|
2011-06-02 12:56:46 +00:00
|
|
|
|
|
|
|
|
|
dom::Element* bodyContent = document->GetBodyElement();
|
|
|
|
|
// We need to null check the body node (bug 118829) since
|
|
|
|
|
// there are cases, thanks to the fix for bug 5569, where we
|
|
|
|
|
// will reflow a document with no body. In particular, if a
|
|
|
|
|
// SCRIPT element in the head blocks the parser and then has a
|
|
|
|
|
// SCRIPT that does "document.location.href = 'foo'", then
|
|
|
|
|
// nsParser::Terminate will call |DidBuildModel| methods
|
|
|
|
|
// through to the content sink, which will call |StartLayout|
|
2012-09-07 04:16:09 +00:00
|
|
|
|
// and thus |Initialize| on the pres shell. See bug 119351
|
2011-06-02 12:56:46 +00:00
|
|
|
|
// for the ugly details.
|
|
|
|
|
if (!bodyContent) {
|
|
|
|
|
return aForFrame;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsIFrame *bodyFrame = bodyContent->GetPrimaryFrame();
|
|
|
|
|
if (!bodyFrame) {
|
|
|
|
|
return aForFrame;
|
2009-04-10 13:41:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-06-02 12:56:46 +00:00
|
|
|
|
return nsLayoutUtils::GetStyleFrame(bodyFrame);
|
2009-04-10 13:41:59 +00:00
|
|
|
|
}
|
2002-01-07 23:46:07 +00:00
|
|
|
|
|
2009-04-06 21:00:29 +00:00
|
|
|
|
/**
|
|
|
|
|
* |FindBackground| finds the correct style data to use to paint the
|
|
|
|
|
* background. It is responsible for handling the following two
|
|
|
|
|
* statements in section 14.2 of CSS2:
|
|
|
|
|
*
|
|
|
|
|
* The background of the box generated by the root element covers the
|
|
|
|
|
* entire canvas.
|
|
|
|
|
*
|
|
|
|
|
* For HTML documents, however, we recommend that authors specify the
|
|
|
|
|
* background for the BODY element rather than the HTML element. User
|
|
|
|
|
* agents should observe the following precedence rules to fill in the
|
|
|
|
|
* background: if the value of the 'background' property for the HTML
|
|
|
|
|
* element is different from 'transparent' then use it, else use the
|
|
|
|
|
* value of the 'background' property for the BODY element. If the
|
|
|
|
|
* resulting value is 'transparent', the rendering is undefined.
|
|
|
|
|
*
|
|
|
|
|
* Thus, in our implementation, it is responsible for ensuring that:
|
|
|
|
|
* + we paint the correct background on the |nsCanvasFrame|,
|
|
|
|
|
* |nsRootBoxFrame|, or |nsPageFrame|,
|
|
|
|
|
* + we don't paint the background on the root element, and
|
|
|
|
|
* + we don't paint the background on the BODY element in *some* cases,
|
|
|
|
|
* and for SGML-based HTML documents only.
|
|
|
|
|
*
|
|
|
|
|
* |FindBackground| returns true if a background should be painted, and
|
|
|
|
|
* the resulting style context to use for the background information
|
2009-04-25 08:19:23 +00:00
|
|
|
|
* will be filled in to |aBackground|.
|
2009-04-06 21:00:29 +00:00
|
|
|
|
*/
|
2010-04-03 01:58:26 +00:00
|
|
|
|
nsStyleContext*
|
2009-04-06 21:00:29 +00:00
|
|
|
|
nsCSSRendering::FindRootFrameBackground(nsIFrame* aForFrame)
|
|
|
|
|
{
|
2013-02-16 05:38:33 +00:00
|
|
|
|
return FindBackgroundStyleFrame(aForFrame)->StyleContext();
|
2009-02-16 01:11:34 +00:00
|
|
|
|
}
|
2002-01-07 23:46:07 +00:00
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
|
inline bool
|
2008-08-08 08:21:13 +00:00
|
|
|
|
FindElementBackground(nsIFrame* aForFrame, nsIFrame* aRootElementFrame,
|
2010-04-03 01:58:26 +00:00
|
|
|
|
nsStyleContext** aBackgroundSC)
|
2002-01-07 23:46:07 +00:00
|
|
|
|
{
|
2008-08-08 08:21:13 +00:00
|
|
|
|
if (aForFrame == aRootElementFrame) {
|
|
|
|
|
// We must have propagated our background to the viewport or canvas. Abort.
|
2011-10-17 14:59:28 +00:00
|
|
|
|
return false;
|
2002-01-07 23:46:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-16 05:38:33 +00:00
|
|
|
|
*aBackgroundSC = aForFrame->StyleContext();
|
2002-01-07 23:46:07 +00:00
|
|
|
|
|
2005-08-02 20:11:09 +00:00
|
|
|
|
// Return true unless the frame is for a BODY element whose background
|
|
|
|
|
// was propagated to the viewport.
|
|
|
|
|
|
2008-08-08 03:34:43 +00:00
|
|
|
|
nsIContent* content = aForFrame->GetContent();
|
2015-03-03 11:09:00 +00:00
|
|
|
|
if (!content || content->NodeInfo()->NameAtom() != nsGkAtoms::body)
|
2011-10-17 14:59:28 +00:00
|
|
|
|
return true; // not frame for a "body" element
|
2008-08-08 08:21:13 +00:00
|
|
|
|
// It could be a non-HTML "body" element but that's OK, we'd fail the
|
|
|
|
|
// bodyContent check below
|
2008-08-08 03:34:43 +00:00
|
|
|
|
|
2013-02-16 05:38:33 +00:00
|
|
|
|
if (aForFrame->StyleContext()->GetPseudo())
|
2011-10-17 14:59:28 +00:00
|
|
|
|
return true; // A pseudo-element frame.
|
2008-08-08 03:34:43 +00:00
|
|
|
|
|
2002-02-25 22:18:26 +00:00
|
|
|
|
// We should only look at the <html> background if we're in an HTML document
|
2011-10-18 10:53:36 +00:00
|
|
|
|
nsIDocument* document = content->OwnerDoc();
|
2002-02-25 22:18:26 +00:00
|
|
|
|
|
2011-06-02 12:56:46 +00:00
|
|
|
|
dom::Element* bodyContent = document->GetBodyElement();
|
2005-11-03 23:06:54 +00:00
|
|
|
|
if (bodyContent != content)
|
2011-10-17 14:59:28 +00:00
|
|
|
|
return true; // this wasn't the background that was propagated
|
2005-11-03 23:06:54 +00:00
|
|
|
|
|
2008-08-08 08:21:13 +00:00
|
|
|
|
// This can be called even when there's no root element yet, during frame
|
|
|
|
|
// construction, via nsLayoutUtils::FrameHasTransparency and
|
|
|
|
|
// nsContainerFrame::SyncFrameViewProperties.
|
|
|
|
|
if (!aRootElementFrame)
|
2011-10-17 14:59:28 +00:00
|
|
|
|
return true;
|
2008-08-08 08:21:13 +00:00
|
|
|
|
|
2013-02-16 21:51:02 +00:00
|
|
|
|
const nsStyleBackground* htmlBG = aRootElementFrame->StyleBackground();
|
2003-01-17 09:33:52 +00:00
|
|
|
|
return !htmlBG->IsTransparent();
|
2002-01-07 23:46:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
|
bool
|
2013-03-07 16:03:49 +00:00
|
|
|
|
nsCSSRendering::FindBackground(nsIFrame* aForFrame,
|
2010-04-03 01:58:26 +00:00
|
|
|
|
nsStyleContext** aBackgroundSC)
|
2002-01-07 23:46:07 +00:00
|
|
|
|
{
|
2008-08-08 08:21:13 +00:00
|
|
|
|
nsIFrame* rootElementFrame =
|
2013-03-07 16:03:49 +00:00
|
|
|
|
aForFrame->PresContext()->PresShell()->FrameConstructor()->GetRootElementStyleFrame();
|
2009-02-16 01:11:34 +00:00
|
|
|
|
if (IsCanvasFrame(aForFrame)) {
|
2010-04-03 01:58:26 +00:00
|
|
|
|
*aBackgroundSC = FindCanvasBackground(aForFrame, rootElementFrame);
|
2011-10-17 14:59:28 +00:00
|
|
|
|
return true;
|
2009-02-16 01:11:34 +00:00
|
|
|
|
} else {
|
2010-04-03 01:58:26 +00:00
|
|
|
|
return FindElementBackground(aForFrame, rootElementFrame, aBackgroundSC);
|
2009-02-16 01:11:34 +00:00
|
|
|
|
}
|
2002-01-07 23:46:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-01-17 09:33:52 +00:00
|
|
|
|
void
|
2012-11-19 10:54:41 +00:00
|
|
|
|
nsCSSRendering::BeginFrameTreesLocked()
|
|
|
|
|
{
|
|
|
|
|
++gFrameTreeLockCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nsCSSRendering::EndFrameTreesLocked()
|
2003-01-17 09:33:52 +00:00
|
|
|
|
{
|
2012-11-19 10:54:41 +00:00
|
|
|
|
NS_ASSERTION(gFrameTreeLockCount > 0, "Unbalanced EndFrameTreeLocked");
|
|
|
|
|
--gFrameTreeLockCount;
|
|
|
|
|
if (gFrameTreeLockCount == 0) {
|
|
|
|
|
gInlineBGData->Reset();
|
|
|
|
|
}
|
2003-01-17 09:33:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-07-08 00:57:47 +00:00
|
|
|
|
void
|
2009-02-10 08:45:13 +00:00
|
|
|
|
nsCSSRendering::PaintBoxShadowOuter(nsPresContext* aPresContext,
|
2011-04-08 01:04:40 +00:00
|
|
|
|
nsRenderingContext& aRenderingContext,
|
2009-02-10 08:45:13 +00:00
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
|
const nsRect& aFrameArea,
|
2013-11-18 09:32:09 +00:00
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
|
float aOpacity)
|
2008-07-08 00:57:47 +00:00
|
|
|
|
{
|
2014-10-31 11:16:27 +00:00
|
|
|
|
DrawTarget& aDrawTarget = *aRenderingContext.GetDrawTarget();
|
2016-04-12 05:52:42 +00:00
|
|
|
|
nsCSSShadowArray* shadows = aForFrame->StyleEffects()->mBoxShadow;
|
2009-04-05 23:35:53 +00:00
|
|
|
|
if (!shadows)
|
2009-01-28 09:28:14 +00:00
|
|
|
|
return;
|
2008-07-23 17:25:23 +00:00
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
|
bool hasBorderRadius;
|
|
|
|
|
bool nativeTheme; // mutually exclusive with hasBorderRadius
|
2013-02-16 21:51:02 +00:00
|
|
|
|
const nsStyleDisplay* styleDisplay = aForFrame->StyleDisplay();
|
2010-08-23 09:30:08 +00:00
|
|
|
|
nsITheme::Transparency transparency;
|
|
|
|
|
if (aForFrame->IsThemed(styleDisplay, &transparency)) {
|
|
|
|
|
// We don't respect border-radius for native-themed widgets
|
2011-10-17 14:59:28 +00:00
|
|
|
|
hasBorderRadius = false;
|
2010-08-23 09:30:08 +00:00
|
|
|
|
// For opaque (rectangular) theme widgets we can take the generic
|
|
|
|
|
// border-box path with border-radius disabled.
|
|
|
|
|
nativeTheme = transparency != nsITheme::eOpaque;
|
|
|
|
|
} else {
|
2011-10-17 14:59:28 +00:00
|
|
|
|
nativeTheme = false;
|
2014-05-05 17:55:54 +00:00
|
|
|
|
hasBorderRadius = true; // we'll update this below
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsRect frameRect = nativeTheme ?
|
|
|
|
|
aForFrame->GetVisualOverflowRectRelativeToSelf() + aFrameArea.TopLeft() :
|
|
|
|
|
aFrameArea;
|
2014-09-17 00:36:57 +00:00
|
|
|
|
Sides skipSides = aForFrame->GetSkipSides();
|
|
|
|
|
frameRect = ::BoxDecorationRectForBorder(aForFrame, frameRect, skipSides);
|
2014-05-05 17:55:54 +00:00
|
|
|
|
|
|
|
|
|
// Get any border radius, since box-shadow must also have rounded corners if
|
|
|
|
|
// the frame does.
|
2014-10-31 11:16:27 +00:00
|
|
|
|
RectCornerRadii borderRadii;
|
2014-05-05 17:55:54 +00:00
|
|
|
|
const nscoord twipsPerPixel = aPresContext->DevPixelsToAppUnits(1);
|
|
|
|
|
if (hasBorderRadius) {
|
2010-08-23 09:30:08 +00:00
|
|
|
|
nscoord twipsRadii[8];
|
2013-04-17 20:16:14 +00:00
|
|
|
|
NS_ASSERTION(aFrameArea.Size() == aForFrame->VisualBorderRectRelativeToSelf().Size(),
|
|
|
|
|
"unexpected size");
|
2014-05-05 17:55:54 +00:00
|
|
|
|
nsSize sz = frameRect.Size();
|
2014-06-28 10:13:13 +00:00
|
|
|
|
hasBorderRadius = aForFrame->GetBorderRadii(sz, sz, Sides(), twipsRadii);
|
2010-08-23 09:30:08 +00:00
|
|
|
|
if (hasBorderRadius) {
|
2010-09-07 22:20:35 +00:00
|
|
|
|
ComputePixelRadii(twipsRadii, twipsPerPixel, &borderRadii);
|
2010-08-23 09:30:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 21:16:22 +00:00
|
|
|
|
|
2010-04-18 03:13:10 +00:00
|
|
|
|
// We don't show anything that intersects with the frame we're blurring on. So tell the
|
|
|
|
|
// blurrer not to do unnecessary work there.
|
2015-11-30 23:47:26 +00:00
|
|
|
|
gfxRect skipGfxRect = ThebesRect(NSRectToRect(frameRect, twipsPerPixel));
|
|
|
|
|
skipGfxRect.Round();
|
2011-09-29 06:19:26 +00:00
|
|
|
|
bool useSkipGfxRect = true;
|
2010-08-23 09:30:08 +00:00
|
|
|
|
if (nativeTheme) {
|
|
|
|
|
// Optimize non-leaf native-themed frames by skipping computing pixels
|
|
|
|
|
// in the padding-box. We assume the padding-box is going to be painted
|
|
|
|
|
// opaquely for non-leaf frames.
|
|
|
|
|
// XXX this may not be a safe assumption; we should make this go away
|
|
|
|
|
// by optimizing box-shadow drawing more for the cases where we don't have a skip-rect.
|
|
|
|
|
useSkipGfxRect = !aForFrame->IsLeaf();
|
|
|
|
|
nsRect paddingRect =
|
|
|
|
|
aForFrame->GetPaddingRect() - aForFrame->GetPosition() + aFrameArea.TopLeft();
|
2010-09-07 22:20:35 +00:00
|
|
|
|
skipGfxRect = nsLayoutUtils::RectToGfxRect(paddingRect, twipsPerPixel);
|
2010-08-23 09:30:08 +00:00
|
|
|
|
} else if (hasBorderRadius) {
|
2011-04-19 03:07:51 +00:00
|
|
|
|
skipGfxRect.Deflate(gfxMargin(
|
2013-03-06 08:05:55 +00:00
|
|
|
|
std::max(borderRadii[C_TL].height, borderRadii[C_TR].height), 0,
|
|
|
|
|
std::max(borderRadii[C_BL].height, borderRadii[C_BR].height), 0));
|
2010-04-18 03:13:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-31 11:16:27 +00:00
|
|
|
|
gfxContext* renderContext = aRenderingContext.ThebesContext();
|
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
|
for (uint32_t i = shadows->Length(); i > 0; --i) {
|
2009-04-05 23:35:53 +00:00
|
|
|
|
nsCSSShadowItem* shadowItem = shadows->ShadowAt(i - 1);
|
2009-02-10 08:45:13 +00:00
|
|
|
|
if (shadowItem->mInset)
|
|
|
|
|
continue;
|
|
|
|
|
|
2010-08-23 09:30:08 +00:00
|
|
|
|
nsRect shadowRect = frameRect;
|
2009-09-18 18:18:35 +00:00
|
|
|
|
shadowRect.MoveBy(shadowItem->mXOffset, shadowItem->mYOffset);
|
2013-11-25 23:06:17 +00:00
|
|
|
|
if (!nativeTheme) {
|
2010-08-23 09:30:08 +00:00
|
|
|
|
shadowRect.Inflate(shadowItem->mSpread, shadowItem->mSpread);
|
|
|
|
|
}
|
2008-07-08 00:57:47 +00:00
|
|
|
|
|
|
|
|
|
// shadowRect won't include the blur, so make an extra rect here that includes the blur
|
|
|
|
|
// for use in the even-odd rule below.
|
2009-09-18 18:18:35 +00:00
|
|
|
|
nsRect shadowRectPlusBlur = shadowRect;
|
2008-09-13 03:45:37 +00:00
|
|
|
|
nscoord blurRadius = shadowItem->mRadius;
|
2010-09-11 16:27:12 +00:00
|
|
|
|
shadowRectPlusBlur.Inflate(
|
|
|
|
|
nsContextBoxBlur::GetBlurRadiusMargin(blurRadius, twipsPerPixel));
|
2009-09-18 18:18:35 +00:00
|
|
|
|
|
2014-10-31 11:16:27 +00:00
|
|
|
|
Rect shadowGfxRectPlusBlur =
|
|
|
|
|
NSRectToRect(shadowRectPlusBlur, twipsPerPixel);
|
2009-09-18 18:18:35 +00:00
|
|
|
|
shadowGfxRectPlusBlur.RoundOut();
|
2014-10-31 11:16:27 +00:00
|
|
|
|
MaybeSnapToDevicePixels(shadowGfxRectPlusBlur, aDrawTarget, true);
|
2008-07-08 00:57:47 +00:00
|
|
|
|
|
|
|
|
|
// Set the shadow color; if not specified, use the foreground color
|
|
|
|
|
nscolor shadowColor;
|
|
|
|
|
if (shadowItem->mHasColor)
|
|
|
|
|
shadowColor = shadowItem->mColor;
|
|
|
|
|
else
|
2013-02-16 21:51:02 +00:00
|
|
|
|
shadowColor = aForFrame->StyleColor()->mColor;
|
2008-07-08 00:57:47 +00:00
|
|
|
|
|
2015-09-24 07:43:32 +00:00
|
|
|
|
Color gfxShadowColor(Color::FromABGR(shadowColor));
|
2013-11-18 09:32:09 +00:00
|
|
|
|
gfxShadowColor.a *= aOpacity;
|
|
|
|
|
|
2010-08-23 09:30:08 +00:00
|
|
|
|
if (nativeTheme) {
|
2013-11-25 23:06:17 +00:00
|
|
|
|
nsContextBoxBlur blurringArea;
|
|
|
|
|
|
|
|
|
|
// When getting the widget shape from the native theme, we're going
|
|
|
|
|
// to draw the widget into the shadow surface to create a mask.
|
|
|
|
|
// We need to ensure that there actually *is* a shadow surface
|
|
|
|
|
// and that we're not going to draw directly into renderContext.
|
|
|
|
|
gfxContext* shadowContext =
|
|
|
|
|
blurringArea.Init(shadowRect, shadowItem->mSpread,
|
|
|
|
|
blurRadius, twipsPerPixel, renderContext, aDirtyRect,
|
|
|
|
|
useSkipGfxRect ? &skipGfxRect : nullptr,
|
|
|
|
|
nsContextBoxBlur::FORCE_MASK);
|
|
|
|
|
if (!shadowContext)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
MOZ_ASSERT(shadowContext == blurringArea.GetContext());
|
|
|
|
|
|
|
|
|
|
renderContext->Save();
|
|
|
|
|
renderContext->SetColor(gfxShadowColor);
|
|
|
|
|
|
|
|
|
|
// Draw the shape of the frame so it can be blurred. Recall how nsContextBoxBlur
|
|
|
|
|
// doesn't make any temporary surfaces if blur is 0 and it just returns the original
|
|
|
|
|
// surface? If we have no blur, we're painting this fill on the actual content surface
|
|
|
|
|
// (renderContext == shadowContext) which is why we set up the color and clip
|
|
|
|
|
// before doing this.
|
|
|
|
|
|
2010-08-23 09:30:08 +00:00
|
|
|
|
// We don't clip the border-box from the shadow, nor any other box.
|
|
|
|
|
// We assume that the native theme is going to paint over the shadow.
|
|
|
|
|
|
|
|
|
|
// Draw the widget shape
|
|
|
|
|
gfxContextMatrixAutoSaveRestore save(shadowContext);
|
2014-09-11 06:48:10 +00:00
|
|
|
|
gfxPoint devPixelOffset =
|
|
|
|
|
nsLayoutUtils::PointToGfxPoint(nsPoint(shadowItem->mXOffset,
|
|
|
|
|
shadowItem->mYOffset),
|
|
|
|
|
aPresContext->AppUnitsPerDevPixel());
|
2014-10-31 20:08:49 +00:00
|
|
|
|
shadowContext->SetMatrix(
|
|
|
|
|
shadowContext->CurrentMatrix().Translate(devPixelOffset));
|
2010-12-01 03:20:05 +00:00
|
|
|
|
|
2015-11-12 02:23:11 +00:00
|
|
|
|
nsRect nativeRect = aDirtyRect;
|
|
|
|
|
nativeRect.MoveBy(-nsPoint(shadowItem->mXOffset, shadowItem->mYOffset));
|
|
|
|
|
nativeRect.IntersectRect(frameRect, nativeRect);
|
2014-10-31 20:08:49 +00:00
|
|
|
|
nsRenderingContext wrapperCtx(shadowContext);
|
|
|
|
|
aPresContext->GetTheme()->DrawWidgetBackground(&wrapperCtx, aForFrame,
|
2010-12-01 03:20:05 +00:00
|
|
|
|
styleDisplay->mAppearance, aFrameArea, nativeRect);
|
2013-11-25 23:06:17 +00:00
|
|
|
|
|
|
|
|
|
blurringArea.DoPaint();
|
|
|
|
|
renderContext->Restore();
|
2010-08-23 09:30:08 +00:00
|
|
|
|
} else {
|
2013-11-25 23:06:17 +00:00
|
|
|
|
renderContext->Save();
|
2009-09-24 06:46:39 +00:00
|
|
|
|
|
2014-10-31 11:16:27 +00:00
|
|
|
|
{
|
2015-11-30 23:47:26 +00:00
|
|
|
|
Rect innerClipRect = NSRectToRect(frameRect, twipsPerPixel);
|
|
|
|
|
if (!MaybeSnapToDevicePixels(innerClipRect, aDrawTarget, true)) {
|
|
|
|
|
innerClipRect.Round();
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-31 11:16:27 +00:00
|
|
|
|
// Clip out the interior of the frame's border edge so that the shadow
|
|
|
|
|
// is only painted outside that area.
|
2015-10-18 05:24:48 +00:00
|
|
|
|
RefPtr<PathBuilder> builder =
|
2014-10-31 11:16:27 +00:00
|
|
|
|
aDrawTarget.CreatePathBuilder(FillRule::FILL_EVEN_ODD);
|
|
|
|
|
AppendRectToPath(builder, shadowGfxRectPlusBlur);
|
|
|
|
|
if (hasBorderRadius) {
|
2015-11-30 23:47:26 +00:00
|
|
|
|
AppendRoundedRectToPath(builder, innerClipRect, borderRadii);
|
2014-10-31 11:16:27 +00:00
|
|
|
|
} else {
|
2015-11-30 23:47:26 +00:00
|
|
|
|
AppendRectToPath(builder, innerClipRect);
|
2014-10-31 11:16:27 +00:00
|
|
|
|
}
|
2015-10-18 05:24:48 +00:00
|
|
|
|
RefPtr<Path> path = builder->Finish();
|
2014-10-31 11:16:27 +00:00
|
|
|
|
renderContext->Clip(path);
|
|
|
|
|
}
|
2010-08-23 09:30:08 +00:00
|
|
|
|
|
2014-05-05 17:55:54 +00:00
|
|
|
|
// Clip the shadow so that we only get the part that applies to aForFrame.
|
|
|
|
|
nsRect fragmentClip = shadowRectPlusBlur;
|
2014-06-28 10:13:13 +00:00
|
|
|
|
if (!skipSides.IsEmpty()) {
|
|
|
|
|
if (skipSides.Left()) {
|
2014-05-05 17:55:54 +00:00
|
|
|
|
nscoord xmost = fragmentClip.XMost();
|
|
|
|
|
fragmentClip.x = aFrameArea.x;
|
|
|
|
|
fragmentClip.width = xmost - fragmentClip.x;
|
|
|
|
|
}
|
2014-06-28 10:13:13 +00:00
|
|
|
|
if (skipSides.Right()) {
|
2014-05-05 17:55:54 +00:00
|
|
|
|
nscoord xmost = fragmentClip.XMost();
|
|
|
|
|
nscoord overflow = xmost - aFrameArea.XMost();
|
|
|
|
|
if (overflow > 0) {
|
|
|
|
|
fragmentClip.width -= overflow;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-28 10:13:13 +00:00
|
|
|
|
if (skipSides.Top()) {
|
2014-05-05 17:55:54 +00:00
|
|
|
|
nscoord ymost = fragmentClip.YMost();
|
|
|
|
|
fragmentClip.y = aFrameArea.y;
|
|
|
|
|
fragmentClip.height = ymost - fragmentClip.y;
|
|
|
|
|
}
|
2014-06-28 10:13:13 +00:00
|
|
|
|
if (skipSides.Bottom()) {
|
2014-05-05 17:55:54 +00:00
|
|
|
|
nscoord ymost = fragmentClip.YMost();
|
|
|
|
|
nscoord overflow = ymost - aFrameArea.YMost();
|
|
|
|
|
if (overflow > 0) {
|
|
|
|
|
fragmentClip.height -= overflow;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-08-07 12:05:48 +00:00
|
|
|
|
fragmentClip = fragmentClip.Intersect(aDirtyRect);
|
2014-10-31 11:16:27 +00:00
|
|
|
|
renderContext->
|
2014-10-22 11:29:06 +00:00
|
|
|
|
Clip(NSRectToSnappedRect(fragmentClip,
|
|
|
|
|
aForFrame->PresContext()->AppUnitsPerDevPixel(),
|
2014-10-31 11:16:27 +00:00
|
|
|
|
aDrawTarget));
|
2014-05-05 17:55:54 +00:00
|
|
|
|
|
2014-11-01 10:45:10 +00:00
|
|
|
|
RectCornerRadii clipRectRadii;
|
2010-08-23 09:30:08 +00:00
|
|
|
|
if (hasBorderRadius) {
|
2014-10-31 11:16:27 +00:00
|
|
|
|
Float spreadDistance = shadowItem->mSpread / twipsPerPixel;
|
2009-09-24 06:46:39 +00:00
|
|
|
|
|
2014-10-31 11:16:27 +00:00
|
|
|
|
Float borderSizes[4];
|
2009-09-24 06:46:39 +00:00
|
|
|
|
|
2012-04-30 02:37:04 +00:00
|
|
|
|
borderSizes[NS_SIDE_LEFT] = spreadDistance;
|
|
|
|
|
borderSizes[NS_SIDE_TOP] = spreadDistance;
|
|
|
|
|
borderSizes[NS_SIDE_RIGHT] = spreadDistance;
|
|
|
|
|
borderSizes[NS_SIDE_BOTTOM] = spreadDistance;
|
2010-08-23 09:30:08 +00:00
|
|
|
|
|
2012-04-30 02:37:04 +00:00
|
|
|
|
nsCSSBorderRenderer::ComputeOuterRadii(borderRadii, borderSizes,
|
2010-08-23 09:30:08 +00:00
|
|
|
|
&clipRectRadii);
|
2013-11-25 23:06:17 +00:00
|
|
|
|
|
2010-08-23 09:30:08 +00:00
|
|
|
|
}
|
2013-11-25 23:06:17 +00:00
|
|
|
|
nsContextBoxBlur::BlurRectangle(renderContext,
|
|
|
|
|
shadowRect,
|
|
|
|
|
twipsPerPixel,
|
|
|
|
|
hasBorderRadius ? &clipRectRadii : nullptr,
|
|
|
|
|
blurRadius,
|
|
|
|
|
gfxShadowColor,
|
|
|
|
|
aDirtyRect,
|
|
|
|
|
skipGfxRect);
|
|
|
|
|
renderContext->Restore();
|
2009-05-13 09:42:39 +00:00
|
|
|
|
}
|
2008-07-08 00:57:47 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-10 08:45:13 +00:00
|
|
|
|
void
|
|
|
|
|
nsCSSRendering::PaintBoxShadowInner(nsPresContext* aPresContext,
|
2011-04-08 01:04:40 +00:00
|
|
|
|
nsRenderingContext& aRenderingContext,
|
2009-02-10 08:45:13 +00:00
|
|
|
|
nsIFrame* aForFrame,
|
2016-01-06 00:08:17 +00:00
|
|
|
|
const nsRect& aFrameArea)
|
2009-02-10 08:45:13 +00:00
|
|
|
|
{
|
2016-04-12 05:52:42 +00:00
|
|
|
|
nsCSSShadowArray* shadows = aForFrame->StyleEffects()->mBoxShadow;
|
2009-04-05 23:35:53 +00:00
|
|
|
|
if (!shadows)
|
2009-02-10 08:45:13 +00:00
|
|
|
|
return;
|
2010-08-23 09:30:08 +00:00
|
|
|
|
if (aForFrame->IsThemed() && aForFrame->GetContent() &&
|
2016-03-31 11:46:32 +00:00
|
|
|
|
!nsContentUtils::IsChromeDoc(aForFrame->GetContent()->GetUncomposedDoc())) {
|
2010-08-23 09:30:08 +00:00
|
|
|
|
// There's no way of getting hold of a shape corresponding to a
|
|
|
|
|
// "padding-box" for native-themed widgets, so just don't draw
|
|
|
|
|
// inner box-shadows for them. But we allow chrome to paint inner
|
|
|
|
|
// box shadows since chrome can be aware of the platform theme.
|
|
|
|
|
return;
|
|
|
|
|
}
|
2009-02-10 08:45:13 +00:00
|
|
|
|
|
2010-11-27 22:49:40 +00:00
|
|
|
|
NS_ASSERTION(aForFrame->GetType() == nsGkAtoms::fieldSetFrame ||
|
|
|
|
|
aFrameArea.Size() == aForFrame->GetSize(), "unexpected size");
|
2009-02-10 08:45:13 +00:00
|
|
|
|
|
2014-09-17 00:36:57 +00:00
|
|
|
|
Sides skipSides = aForFrame->GetSkipSides();
|
|
|
|
|
nsRect frameRect =
|
|
|
|
|
::BoxDecorationRectForBorder(aForFrame, aFrameArea, skipSides);
|
2014-05-05 17:55:54 +00:00
|
|
|
|
nsRect paddingRect = frameRect;
|
2009-02-10 08:45:13 +00:00
|
|
|
|
nsMargin border = aForFrame->GetUsedBorder();
|
|
|
|
|
paddingRect.Deflate(border);
|
|
|
|
|
|
2014-05-05 17:55:54 +00:00
|
|
|
|
// Get any border radius, since box-shadow must also have rounded corners
|
|
|
|
|
// if the frame does.
|
|
|
|
|
nscoord twipsRadii[8];
|
|
|
|
|
nsSize sz = frameRect.Size();
|
2014-06-28 10:13:13 +00:00
|
|
|
|
bool hasBorderRadius = aForFrame->GetBorderRadii(sz, sz, Sides(), twipsRadii);
|
2014-05-05 17:55:54 +00:00
|
|
|
|
const nscoord twipsPerPixel = aPresContext->DevPixelsToAppUnits(1);
|
|
|
|
|
|
2014-11-01 10:45:10 +00:00
|
|
|
|
RectCornerRadii innerRadii;
|
2009-02-10 08:45:13 +00:00
|
|
|
|
if (hasBorderRadius) {
|
2014-11-01 10:45:10 +00:00
|
|
|
|
RectCornerRadii borderRadii;
|
2009-02-10 08:45:13 +00:00
|
|
|
|
|
2010-09-07 22:20:35 +00:00
|
|
|
|
ComputePixelRadii(twipsRadii, twipsPerPixel, &borderRadii);
|
2014-11-01 10:45:10 +00:00
|
|
|
|
Float borderSizes[4] = {
|
|
|
|
|
Float(border.top / twipsPerPixel),
|
|
|
|
|
Float(border.right / twipsPerPixel),
|
|
|
|
|
Float(border.bottom / twipsPerPixel),
|
|
|
|
|
Float(border.left / twipsPerPixel)
|
2009-02-10 08:45:13 +00:00
|
|
|
|
};
|
|
|
|
|
nsCSSBorderRenderer::ComputeInnerRadii(borderRadii, borderSizes,
|
|
|
|
|
&innerRadii);
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
|
for (uint32_t i = shadows->Length(); i > 0; --i) {
|
2009-04-05 23:35:53 +00:00
|
|
|
|
nsCSSShadowItem* shadowItem = shadows->ShadowAt(i - 1);
|
2009-02-10 08:45:13 +00:00
|
|
|
|
if (!shadowItem->mInset)
|
|
|
|
|
continue;
|
|
|
|
|
|
2014-05-05 17:55:54 +00:00
|
|
|
|
// shadowPaintRect: the area to paint on the temp surface
|
|
|
|
|
// shadowClipRect: the area on the temporary surface within shadowPaintRect
|
|
|
|
|
// that we will NOT paint in
|
2009-02-10 08:45:13 +00:00
|
|
|
|
nscoord blurRadius = shadowItem->mRadius;
|
2010-09-11 16:27:12 +00:00
|
|
|
|
nsMargin blurMargin =
|
|
|
|
|
nsContextBoxBlur::GetBlurRadiusMargin(blurRadius, twipsPerPixel);
|
2009-09-18 18:18:35 +00:00
|
|
|
|
nsRect shadowPaintRect = paddingRect;
|
2010-09-11 16:27:12 +00:00
|
|
|
|
shadowPaintRect.Inflate(blurMargin);
|
2009-02-10 08:45:13 +00:00
|
|
|
|
|
2015-07-17 18:42:44 +00:00
|
|
|
|
Rect shadowPaintGfxRect = NSRectToRect(shadowPaintRect, twipsPerPixel);
|
|
|
|
|
shadowPaintGfxRect.RoundOut();
|
|
|
|
|
|
|
|
|
|
// Round the spread radius to device pixels (by truncation).
|
|
|
|
|
// This mostly matches what we do for borders, except that we don't round
|
|
|
|
|
// up values between zero and one device pixels to one device pixel.
|
|
|
|
|
// This way of rounding is symmetric around zero, which makes sense for
|
|
|
|
|
// the spread radius.
|
|
|
|
|
int32_t spreadDistance = shadowItem->mSpread / twipsPerPixel;
|
|
|
|
|
nscoord spreadDistanceAppUnits = aPresContext->DevPixelsToAppUnits(spreadDistance);
|
|
|
|
|
|
2009-09-18 18:18:35 +00:00
|
|
|
|
nsRect shadowClipRect = paddingRect;
|
|
|
|
|
shadowClipRect.MoveBy(shadowItem->mXOffset, shadowItem->mYOffset);
|
2015-07-17 18:42:44 +00:00
|
|
|
|
shadowClipRect.Deflate(spreadDistanceAppUnits, spreadDistanceAppUnits);
|
|
|
|
|
|
|
|
|
|
Rect shadowClipGfxRect = NSRectToRect(shadowClipRect, twipsPerPixel);
|
|
|
|
|
shadowClipGfxRect.Round();
|
2009-02-10 08:45:13 +00:00
|
|
|
|
|
2014-11-01 10:45:10 +00:00
|
|
|
|
RectCornerRadii clipRectRadii;
|
2010-04-18 03:13:10 +00:00
|
|
|
|
if (hasBorderRadius) {
|
|
|
|
|
// Calculate the radii the inner clipping rect will have
|
2014-11-01 10:45:10 +00:00
|
|
|
|
Float borderSizes[4] = {0, 0, 0, 0};
|
2010-04-18 03:13:10 +00:00
|
|
|
|
|
|
|
|
|
// See PaintBoxShadowOuter and bug 514670
|
|
|
|
|
if (innerRadii[C_TL].width > 0 || innerRadii[C_BL].width > 0) {
|
|
|
|
|
borderSizes[NS_SIDE_LEFT] = spreadDistance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (innerRadii[C_TL].height > 0 || innerRadii[C_TR].height > 0) {
|
|
|
|
|
borderSizes[NS_SIDE_TOP] = spreadDistance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (innerRadii[C_TR].width > 0 || innerRadii[C_BR].width > 0) {
|
|
|
|
|
borderSizes[NS_SIDE_RIGHT] = spreadDistance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (innerRadii[C_BL].height > 0 || innerRadii[C_BR].height > 0) {
|
|
|
|
|
borderSizes[NS_SIDE_BOTTOM] = spreadDistance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsCSSBorderRenderer::ComputeInnerRadii(innerRadii, borderSizes,
|
|
|
|
|
&clipRectRadii);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set the "skip rect" to the area within the frame that we don't paint in,
|
2010-11-27 22:49:40 +00:00
|
|
|
|
// including after blurring.
|
2010-04-18 03:13:10 +00:00
|
|
|
|
nsRect skipRect = shadowClipRect;
|
2010-09-11 16:27:12 +00:00
|
|
|
|
skipRect.Deflate(blurMargin);
|
2010-09-07 22:20:35 +00:00
|
|
|
|
gfxRect skipGfxRect = nsLayoutUtils::RectToGfxRect(skipRect, twipsPerPixel);
|
2010-04-18 03:13:10 +00:00
|
|
|
|
if (hasBorderRadius) {
|
2013-03-06 08:05:55 +00:00
|
|
|
|
skipGfxRect.Deflate(gfxMargin(
|
|
|
|
|
std::max(clipRectRadii[C_TL].height, clipRectRadii[C_TR].height), 0,
|
|
|
|
|
std::max(clipRectRadii[C_BL].height, clipRectRadii[C_BR].height), 0));
|
2010-04-18 03:13:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-11-27 22:49:40 +00:00
|
|
|
|
// When there's a blur radius, gfxAlphaBoxBlur leaves the skiprect area
|
|
|
|
|
// unchanged. And by construction the gfxSkipRect is not touched by the
|
|
|
|
|
// rendered shadow (even after blurring), so those pixels must be completely
|
|
|
|
|
// transparent in the shadow, so drawing them changes nothing.
|
2009-02-10 08:45:13 +00:00
|
|
|
|
gfxContext* renderContext = aRenderingContext.ThebesContext();
|
2014-11-02 15:41:08 +00:00
|
|
|
|
DrawTarget* drawTarget = renderContext->GetDrawTarget();
|
2009-02-10 08:45:13 +00:00
|
|
|
|
nsContextBoxBlur blurringArea;
|
|
|
|
|
|
2015-09-24 16:50:29 +00:00
|
|
|
|
// Clip the context to the area of the frame's padding rect, so no part of the
|
|
|
|
|
// shadow is painted outside. Also cut out anything beyond where the inset shadow
|
|
|
|
|
// will be.
|
|
|
|
|
Rect shadowGfxRect = NSRectToRect(paddingRect, twipsPerPixel);
|
|
|
|
|
shadowGfxRect.Round();
|
2012-10-25 11:17:10 +00:00
|
|
|
|
|
2009-02-10 08:45:13 +00:00
|
|
|
|
// Set the shadow color; if not specified, use the foreground color
|
2014-11-02 15:41:08 +00:00
|
|
|
|
Color shadowColor = Color::FromABGR(shadowItem->mHasColor ?
|
|
|
|
|
shadowItem->mColor :
|
|
|
|
|
aForFrame->StyleColor()->mColor);
|
2015-09-24 16:50:29 +00:00
|
|
|
|
|
2009-02-10 08:45:13 +00:00
|
|
|
|
renderContext->Save();
|
|
|
|
|
|
2015-09-24 16:50:29 +00:00
|
|
|
|
// This clips the outside border radius.
|
|
|
|
|
// clipRectRadii is the border radius inside the inset shadow.
|
2014-11-02 15:41:08 +00:00
|
|
|
|
if (hasBorderRadius) {
|
2015-10-18 05:24:48 +00:00
|
|
|
|
RefPtr<Path> roundedRect =
|
2014-11-02 15:41:08 +00:00
|
|
|
|
MakePathForRoundedRect(*drawTarget, shadowGfxRect, innerRadii);
|
|
|
|
|
renderContext->Clip(roundedRect);
|
|
|
|
|
} else {
|
|
|
|
|
renderContext->Clip(shadowGfxRect);
|
|
|
|
|
}
|
2009-02-10 08:45:13 +00:00
|
|
|
|
|
2015-09-24 16:50:29 +00:00
|
|
|
|
nsContextBoxBlur insetBoxBlur;
|
|
|
|
|
gfxRect destRect = nsLayoutUtils::RectToGfxRect(shadowPaintRect, twipsPerPixel);
|
2015-10-19 17:53:04 +00:00
|
|
|
|
Point shadowOffset(shadowItem->mXOffset / twipsPerPixel,
|
|
|
|
|
shadowItem->mYOffset / twipsPerPixel);
|
|
|
|
|
|
2015-09-24 16:50:29 +00:00
|
|
|
|
insetBoxBlur.InsetBoxBlur(renderContext, ToRect(destRect),
|
|
|
|
|
shadowClipGfxRect, shadowColor,
|
|
|
|
|
blurRadius, spreadDistanceAppUnits,
|
|
|
|
|
twipsPerPixel, hasBorderRadius,
|
2015-10-19 17:53:04 +00:00
|
|
|
|
clipRectRadii, ToRect(skipGfxRect),
|
|
|
|
|
shadowOffset);
|
2009-02-10 08:45:13 +00:00
|
|
|
|
renderContext->Restore();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-19 07:43:20 +00:00
|
|
|
|
/* static */
|
|
|
|
|
nsCSSRendering::PaintBGParams
|
|
|
|
|
nsCSSRendering::PaintBGParams::ForAllLayers(nsPresContext& aPresCtx,
|
|
|
|
|
nsRenderingContext& aRenderingCtx,
|
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
|
const nsRect& aBorderArea,
|
|
|
|
|
nsIFrame *aFrame,
|
|
|
|
|
uint32_t aPaintFlags)
|
|
|
|
|
{
|
|
|
|
|
MOZ_ASSERT(aFrame);
|
|
|
|
|
|
|
|
|
|
PaintBGParams result(aPresCtx, aRenderingCtx, aDirtyRect, aBorderArea);
|
|
|
|
|
|
|
|
|
|
result.frame = aFrame;
|
|
|
|
|
result.paintFlags = aPaintFlags;
|
|
|
|
|
result.layer = -1;
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
|
nsCSSRendering::PaintBGParams
|
|
|
|
|
nsCSSRendering::PaintBGParams::ForSingleLayer(nsPresContext& aPresCtx,
|
|
|
|
|
nsRenderingContext& aRenderingCtx,
|
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
|
const nsRect& aBorderArea,
|
|
|
|
|
nsIFrame *aFrame,
|
|
|
|
|
uint32_t aPaintFlags,
|
|
|
|
|
int32_t aLayer,
|
|
|
|
|
CompositionOp aCompositionOp)
|
|
|
|
|
{
|
|
|
|
|
MOZ_ASSERT(aFrame && (aLayer != -1));
|
|
|
|
|
|
|
|
|
|
PaintBGParams result(aPresCtx, aRenderingCtx, aDirtyRect, aBorderArea);
|
|
|
|
|
|
|
|
|
|
result.frame = aFrame;
|
|
|
|
|
result.paintFlags = aPaintFlags;
|
|
|
|
|
|
|
|
|
|
result.layer = aLayer;
|
|
|
|
|
result.compositionOp = aCompositionOp;
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-10 07:27:39 +00:00
|
|
|
|
DrawResult
|
2016-05-19 07:43:20 +00:00
|
|
|
|
nsCSSRendering::PaintBackground(const PaintBGParams& aParams)
|
1998-04-13 20:24:54 +00:00
|
|
|
|
{
|
2014-05-23 21:12:29 +00:00
|
|
|
|
PROFILER_LABEL("nsCSSRendering", "PaintBackground",
|
|
|
|
|
js::ProfileEntry::Category::GRAPHICS);
|
|
|
|
|
|
2016-05-19 07:43:20 +00:00
|
|
|
|
NS_PRECONDITION(aParams.frame,
|
2002-01-07 23:46:07 +00:00
|
|
|
|
"Frame is expected to be provided to PaintBackground");
|
|
|
|
|
|
2010-04-03 01:58:26 +00:00
|
|
|
|
nsStyleContext *sc;
|
2016-05-19 07:43:20 +00:00
|
|
|
|
if (!FindBackground(aParams.frame, &sc)) {
|
2009-07-04 09:30:59 +00:00
|
|
|
|
// We don't want to bail out if moz-appearance is set on a root
|
2002-02-20 02:14:18 +00:00
|
|
|
|
// node. If it has a parent content node, bail because it's not
|
2012-10-25 05:32:25 +00:00
|
|
|
|
// a root, otherwise keep going in order to let the theme stuff
|
2002-02-20 02:14:18 +00:00
|
|
|
|
// draw the background. The canvas really should be drawing the
|
|
|
|
|
// bg, but there's no way to hook that up via css.
|
2016-05-19 07:43:20 +00:00
|
|
|
|
if (!aParams.frame->StyleDisplay()->mAppearance) {
|
2015-02-10 07:27:39 +00:00
|
|
|
|
return DrawResult::SUCCESS;
|
2002-02-20 02:14:18 +00:00
|
|
|
|
}
|
2003-07-28 21:25:13 +00:00
|
|
|
|
|
2016-05-19 07:43:20 +00:00
|
|
|
|
nsIContent* content = aParams.frame->GetContent();
|
2003-07-28 21:25:13 +00:00
|
|
|
|
if (!content || content->GetParent()) {
|
2015-02-10 07:27:39 +00:00
|
|
|
|
return DrawResult::SUCCESS;
|
2003-07-28 21:25:13 +00:00
|
|
|
|
}
|
2009-07-04 09:30:59 +00:00
|
|
|
|
|
2016-05-19 07:43:20 +00:00
|
|
|
|
sc = aParams.frame->StyleContext();
|
2002-02-20 02:14:18 +00:00
|
|
|
|
}
|
2002-01-07 23:46:07 +00:00
|
|
|
|
|
2016-05-19 07:43:20 +00:00
|
|
|
|
return PaintBackgroundWithSC(aParams, sc, *aParams.frame->StyleBorder());
|
2002-01-07 23:46:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
|
static bool
|
2010-04-27 16:15:02 +00:00
|
|
|
|
IsOpaqueBorderEdge(const nsStyleBorder& aBorder, mozilla::css::Side aSide)
|
2008-08-13 03:11:35 +00:00
|
|
|
|
{
|
2012-05-31 05:19:49 +00:00
|
|
|
|
if (aBorder.GetComputedBorder().Side(aSide) == 0)
|
2011-10-17 14:59:28 +00:00
|
|
|
|
return true;
|
2009-10-27 01:43:56 +00:00
|
|
|
|
switch (aBorder.GetBorderStyle(aSide)) {
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_SOLID:
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_GROOVE:
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_RIDGE:
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_INSET:
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_OUTSET:
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2011-10-17 14:59:28 +00:00
|
|
|
|
return false;
|
2009-10-27 01:43:56 +00:00
|
|
|
|
}
|
2008-08-13 03:11:35 +00:00
|
|
|
|
|
2008-10-30 09:24:58 +00:00
|
|
|
|
// If we're using a border image, assume it's not fully opaque,
|
|
|
|
|
// because we may not even have the image loaded at this point, and
|
|
|
|
|
// even if we did, checking whether the relevant tile is fully
|
|
|
|
|
// opaque would be too much work.
|
2014-01-31 03:36:41 +00:00
|
|
|
|
if (aBorder.mBorderImageSource.GetType() != eStyleImageType_Null)
|
2011-10-17 14:59:28 +00:00
|
|
|
|
return false;
|
2008-10-30 09:24:58 +00:00
|
|
|
|
|
2008-08-13 03:11:35 +00:00
|
|
|
|
nscolor color;
|
2011-09-29 06:19:26 +00:00
|
|
|
|
bool isForeground;
|
2008-09-12 15:35:53 +00:00
|
|
|
|
aBorder.GetBorderColor(aSide, color, isForeground);
|
2008-10-30 09:24:58 +00:00
|
|
|
|
|
|
|
|
|
// We don't know the foreground color here, so if it's being used
|
|
|
|
|
// we must assume it might be transparent.
|
|
|
|
|
if (isForeground)
|
2011-10-17 14:59:28 +00:00
|
|
|
|
return false;
|
2008-10-30 09:24:58 +00:00
|
|
|
|
|
2008-09-12 15:35:53 +00:00
|
|
|
|
return NS_GET_A(color) == 255;
|
2008-08-13 03:11:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns true if all border edges are either missing or opaque.
|
|
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
|
static bool
|
2009-10-27 01:43:56 +00:00
|
|
|
|
IsOpaqueBorder(const nsStyleBorder& aBorder)
|
2008-08-13 03:11:35 +00:00
|
|
|
|
{
|
2009-01-09 00:28:32 +00:00
|
|
|
|
if (aBorder.mBorderColors)
|
2011-10-17 14:59:28 +00:00
|
|
|
|
return false;
|
2010-04-27 16:15:02 +00:00
|
|
|
|
NS_FOR_CSS_SIDES(i) {
|
2009-10-27 01:43:56 +00:00
|
|
|
|
if (!IsOpaqueBorderEdge(aBorder, i))
|
2011-10-17 14:59:28 +00:00
|
|
|
|
return false;
|
2008-08-13 03:11:35 +00:00
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
|
return true;
|
2008-08-13 03:11:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-20 05:29:21 +00:00
|
|
|
|
static inline void
|
|
|
|
|
SetupDirtyRects(const nsRect& aBGClipArea, const nsRect& aCallerDirtyRect,
|
|
|
|
|
nscoord aAppUnitsPerPixel,
|
|
|
|
|
/* OUT: */
|
|
|
|
|
nsRect* aDirtyRect, gfxRect* aDirtyRectGfx)
|
|
|
|
|
{
|
|
|
|
|
aDirtyRect->IntersectRect(aBGClipArea, aCallerDirtyRect);
|
|
|
|
|
|
|
|
|
|
// Compute the Thebes equivalent of the dirtyRect.
|
2010-09-07 22:20:35 +00:00
|
|
|
|
*aDirtyRectGfx = nsLayoutUtils::RectToGfxRect(*aDirtyRect, aAppUnitsPerPixel);
|
2009-02-20 05:29:21 +00:00
|
|
|
|
NS_WARN_IF_FALSE(aDirtyRect->IsEmpty() || !aDirtyRectGfx->IsEmpty(),
|
|
|
|
|
"converted dirty rect should not be empty");
|
2015-02-09 22:34:50 +00:00
|
|
|
|
MOZ_ASSERT(!aDirtyRect->IsEmpty() || aDirtyRectGfx->IsEmpty(),
|
|
|
|
|
"second should be empty if first is");
|
2009-02-20 05:29:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-23 05:20:39 +00:00
|
|
|
|
/* static */ void
|
2016-01-28 05:27:00 +00:00
|
|
|
|
nsCSSRendering::GetImageLayerClip(const nsStyleImageLayers::Layer& aLayer,
|
2014-07-23 05:20:39 +00:00
|
|
|
|
nsIFrame* aForFrame, const nsStyleBorder& aBorder,
|
|
|
|
|
const nsRect& aBorderArea, const nsRect& aCallerDirtyRect,
|
|
|
|
|
bool aWillPaintBorder, nscoord aAppUnitsPerPixel,
|
2016-01-28 05:27:00 +00:00
|
|
|
|
/* out */ ImageLayerClipState* aClipState)
|
2014-07-23 05:20:39 +00:00
|
|
|
|
{
|
|
|
|
|
// Compute the outermost boundary of the area that might be painted.
|
|
|
|
|
// Same coordinate space as aBorderArea.
|
2014-09-17 00:36:57 +00:00
|
|
|
|
Sides skipSides = aForFrame->GetSkipSides();
|
2014-07-23 05:20:39 +00:00
|
|
|
|
nsRect clipBorderArea =
|
2014-09-17 00:36:57 +00:00
|
|
|
|
::BoxDecorationRectForBorder(aForFrame, aBorderArea, skipSides, &aBorder);
|
2011-01-18 19:43:47 +00:00
|
|
|
|
|
2014-07-23 05:20:39 +00:00
|
|
|
|
bool haveRoundedCorners = GetRadii(aForFrame, aBorder, aBorderArea,
|
|
|
|
|
clipBorderArea, aClipState->mRadii);
|
2011-01-18 19:43:47 +00:00
|
|
|
|
|
2014-07-23 05:20:39 +00:00
|
|
|
|
uint8_t backgroundClip = aLayer.mClip;
|
|
|
|
|
|
|
|
|
|
bool isSolidBorder =
|
|
|
|
|
aWillPaintBorder && IsOpaqueBorder(aBorder);
|
2016-01-28 05:27:00 +00:00
|
|
|
|
if (isSolidBorder && backgroundClip == NS_STYLE_IMAGELAYER_CLIP_BORDER) {
|
2014-07-23 05:20:39 +00:00
|
|
|
|
// If we have rounded corners, we need to inflate the background
|
|
|
|
|
// drawing area a bit to avoid seams between the border and
|
|
|
|
|
// background.
|
|
|
|
|
backgroundClip = haveRoundedCorners ?
|
2016-01-28 05:27:00 +00:00
|
|
|
|
NS_STYLE_IMAGELAYER_CLIP_MOZ_ALMOST_PADDING : NS_STYLE_IMAGELAYER_CLIP_PADDING;
|
2014-07-23 05:20:39 +00:00
|
|
|
|
}
|
2011-01-18 19:43:47 +00:00
|
|
|
|
|
2014-08-26 22:15:50 +00:00
|
|
|
|
aClipState->mBGClipArea = clipBorderArea;
|
2013-07-23 13:22:58 +00:00
|
|
|
|
aClipState->mHasAdditionalBGClipArea = false;
|
2011-10-17 14:59:28 +00:00
|
|
|
|
aClipState->mCustomClip = false;
|
2014-05-05 17:55:54 +00:00
|
|
|
|
|
2013-07-23 13:22:58 +00:00
|
|
|
|
if (aForFrame->GetType() == nsGkAtoms::scrollFrame &&
|
2016-01-28 05:27:00 +00:00
|
|
|
|
NS_STYLE_IMAGELAYER_ATTACHMENT_LOCAL == aLayer.mAttachment) {
|
2013-07-23 13:22:58 +00:00
|
|
|
|
// As of this writing, this is still in discussion in the CSS Working Group
|
|
|
|
|
// http://lists.w3.org/Archives/Public/www-style/2013Jul/0250.html
|
|
|
|
|
|
|
|
|
|
// The rectangle for 'background-clip' scrolls with the content,
|
|
|
|
|
// but the background is also clipped at a non-scrolling 'padding-box'
|
|
|
|
|
// like the content. (See below.)
|
|
|
|
|
// Therefore, only 'content-box' makes a difference here.
|
2016-01-28 05:27:00 +00:00
|
|
|
|
if (backgroundClip == NS_STYLE_IMAGELAYER_CLIP_CONTENT) {
|
2013-07-23 13:22:58 +00:00
|
|
|
|
nsIScrollableFrame* scrollableFrame = do_QueryFrame(aForFrame);
|
|
|
|
|
// Clip at a rectangle attached to the scrolled content.
|
|
|
|
|
aClipState->mHasAdditionalBGClipArea = true;
|
|
|
|
|
aClipState->mAdditionalBGClipArea = nsRect(
|
|
|
|
|
aClipState->mBGClipArea.TopLeft()
|
|
|
|
|
+ scrollableFrame->GetScrolledFrame()->GetPosition()
|
|
|
|
|
// For the dir=rtl case:
|
|
|
|
|
+ scrollableFrame->GetScrollRange().TopLeft(),
|
|
|
|
|
scrollableFrame->GetScrolledRect().Size());
|
|
|
|
|
nsMargin padding = aForFrame->GetUsedPadding();
|
|
|
|
|
// padding-bottom is ignored on scrollable frames:
|
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=748518
|
|
|
|
|
padding.bottom = 0;
|
2014-09-17 00:36:57 +00:00
|
|
|
|
padding.ApplySkipSides(skipSides);
|
2013-07-23 13:22:58 +00:00
|
|
|
|
aClipState->mAdditionalBGClipArea.Deflate(padding);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Also clip at a non-scrolling, rounded-corner 'padding-box',
|
|
|
|
|
// same as the scrolled content because of the 'overflow' property.
|
2016-01-28 05:27:00 +00:00
|
|
|
|
backgroundClip = NS_STYLE_IMAGELAYER_CLIP_PADDING;
|
2013-07-23 13:22:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-14 08:28:07 +00:00
|
|
|
|
if (backgroundClip != NS_STYLE_IMAGELAYER_CLIP_BORDER &&
|
|
|
|
|
backgroundClip != NS_STYLE_IMAGELAYER_CLIP_TEXT) {
|
2009-02-20 05:29:21 +00:00
|
|
|
|
nsMargin border = aForFrame->GetUsedBorder();
|
2016-01-28 05:27:00 +00:00
|
|
|
|
if (backgroundClip == NS_STYLE_IMAGELAYER_CLIP_MOZ_ALMOST_PADDING) {
|
2011-11-23 17:59:51 +00:00
|
|
|
|
// Reduce |border| by 1px (device pixels) on all sides, if
|
|
|
|
|
// possible, so that we don't get antialiasing seams between the
|
|
|
|
|
// background and border.
|
2013-01-15 12:22:03 +00:00
|
|
|
|
border.top = std::max(0, border.top - aAppUnitsPerPixel);
|
|
|
|
|
border.right = std::max(0, border.right - aAppUnitsPerPixel);
|
|
|
|
|
border.bottom = std::max(0, border.bottom - aAppUnitsPerPixel);
|
|
|
|
|
border.left = std::max(0, border.left - aAppUnitsPerPixel);
|
2016-01-28 05:27:00 +00:00
|
|
|
|
} else if (backgroundClip != NS_STYLE_IMAGELAYER_CLIP_PADDING) {
|
|
|
|
|
NS_ASSERTION(backgroundClip == NS_STYLE_IMAGELAYER_CLIP_CONTENT,
|
2010-06-09 01:44:32 +00:00
|
|
|
|
"unexpected background-clip");
|
|
|
|
|
border += aForFrame->GetUsedPadding();
|
|
|
|
|
}
|
2014-09-17 00:36:57 +00:00
|
|
|
|
border.ApplySkipSides(skipSides);
|
2011-01-18 19:43:47 +00:00
|
|
|
|
aClipState->mBGClipArea.Deflate(border);
|
2009-02-20 05:29:21 +00:00
|
|
|
|
|
2014-07-23 05:20:39 +00:00
|
|
|
|
if (haveRoundedCorners) {
|
|
|
|
|
nsIFrame::InsetBorderRadii(aClipState->mRadii, border);
|
2009-02-20 05:29:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-23 05:20:39 +00:00
|
|
|
|
if (haveRoundedCorners) {
|
|
|
|
|
auto d2a = aForFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
|
nsCSSRendering::ComputePixelRadii(aClipState->mRadii, d2a, &aClipState->mClippedRadii);
|
|
|
|
|
aClipState->mHasRoundedCorners = true;
|
|
|
|
|
} else {
|
|
|
|
|
aClipState->mHasRoundedCorners = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!haveRoundedCorners && aClipState->mHasAdditionalBGClipArea) {
|
2013-07-23 13:22:58 +00:00
|
|
|
|
// Do the intersection here to account for the fast path(?) below.
|
|
|
|
|
aClipState->mBGClipArea =
|
|
|
|
|
aClipState->mBGClipArea.Intersect(aClipState->mAdditionalBGClipArea);
|
|
|
|
|
aClipState->mHasAdditionalBGClipArea = false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-18 19:43:47 +00:00
|
|
|
|
SetupDirtyRects(aClipState->mBGClipArea, aCallerDirtyRect, aAppUnitsPerPixel,
|
|
|
|
|
&aClipState->mDirtyRect, &aClipState->mDirtyRectGfx);
|
|
|
|
|
}
|
2009-02-20 05:29:21 +00:00
|
|
|
|
|
2011-01-18 19:43:47 +00:00
|
|
|
|
static void
|
2016-01-28 05:27:00 +00:00
|
|
|
|
SetupImageLayerClip(nsCSSRendering::ImageLayerClipState& aClipState,
|
2014-07-23 05:20:39 +00:00
|
|
|
|
gfxContext *aCtx, nscoord aAppUnitsPerPixel,
|
2011-01-18 19:43:47 +00:00
|
|
|
|
gfxContextAutoSaveRestore* aAutoSR)
|
|
|
|
|
{
|
|
|
|
|
if (aClipState.mDirtyRectGfx.IsEmpty()) {
|
2009-02-20 05:29:21 +00:00
|
|
|
|
// Our caller won't draw anything under this condition, so no need
|
|
|
|
|
// to set more up.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-18 19:43:47 +00:00
|
|
|
|
if (aClipState.mCustomClip) {
|
|
|
|
|
// We don't support custom clips and rounded corners, arguably a bug, but
|
|
|
|
|
// table painting seems to depend on it.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-02 15:41:08 +00:00
|
|
|
|
DrawTarget* drawTarget = aCtx->GetDrawTarget();
|
|
|
|
|
|
2009-02-20 05:29:21 +00:00
|
|
|
|
// If we have rounded corners, clip all subsequent drawing to the
|
|
|
|
|
// rounded rectangle defined by bgArea and bgRadii (we don't know
|
|
|
|
|
// whether the rounded corners intrude on the dirtyRect or not).
|
|
|
|
|
// Do not do this if we have a caller-provided clip rect --
|
|
|
|
|
// as above with bgArea, arguably a bug, but table painting seems
|
|
|
|
|
// to depend on it.
|
|
|
|
|
|
2013-07-23 13:22:58 +00:00
|
|
|
|
if (aClipState.mHasAdditionalBGClipArea) {
|
|
|
|
|
gfxRect bgAreaGfx = nsLayoutUtils::RectToGfxRect(
|
|
|
|
|
aClipState.mAdditionalBGClipArea, aAppUnitsPerPixel);
|
|
|
|
|
bgAreaGfx.Round();
|
|
|
|
|
bgAreaGfx.Condition();
|
2014-05-05 17:55:54 +00:00
|
|
|
|
|
|
|
|
|
aAutoSR->EnsureSaved(aCtx);
|
2013-07-23 13:22:58 +00:00
|
|
|
|
aCtx->NewPath();
|
|
|
|
|
aCtx->Rectangle(bgAreaGfx, true);
|
|
|
|
|
aCtx->Clip();
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-23 05:20:39 +00:00
|
|
|
|
if (aClipState.mHasRoundedCorners) {
|
2014-11-02 15:41:08 +00:00
|
|
|
|
Rect bgAreaGfx = NSRectToRect(aClipState.mBGClipArea, aAppUnitsPerPixel);
|
2009-02-20 05:29:21 +00:00
|
|
|
|
bgAreaGfx.Round();
|
|
|
|
|
|
|
|
|
|
if (bgAreaGfx.IsEmpty()) {
|
|
|
|
|
// I think it's become possible to hit this since
|
|
|
|
|
// http://hg.mozilla.org/mozilla-central/rev/50e934e4979b landed.
|
|
|
|
|
NS_WARNING("converted background area should not be empty");
|
|
|
|
|
// Make our caller not do anything.
|
2011-04-19 03:07:21 +00:00
|
|
|
|
aClipState.mDirtyRectGfx.SizeTo(gfxSize(0.0, 0.0));
|
2009-02-20 05:29:21 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-05 17:55:54 +00:00
|
|
|
|
aAutoSR->EnsureSaved(aCtx);
|
2014-11-02 15:41:08 +00:00
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
|
RefPtr<Path> roundedRect =
|
2014-11-02 15:41:08 +00:00
|
|
|
|
MakePathForRoundedRect(*drawTarget, bgAreaGfx, aClipState.mClippedRadii);
|
|
|
|
|
aCtx->Clip(roundedRect);
|
2009-02-20 05:29:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-18 19:43:47 +00:00
|
|
|
|
static void
|
2016-01-28 05:27:00 +00:00
|
|
|
|
DrawBackgroundColor(nsCSSRendering::ImageLayerClipState& aClipState,
|
2014-07-23 05:20:39 +00:00
|
|
|
|
gfxContext *aCtx, nscoord aAppUnitsPerPixel)
|
2011-01-18 19:43:47 +00:00
|
|
|
|
{
|
|
|
|
|
if (aClipState.mDirtyRectGfx.IsEmpty()) {
|
|
|
|
|
// Our caller won't draw anything under this condition, so no need
|
|
|
|
|
// to set more up.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-02 15:41:08 +00:00
|
|
|
|
DrawTarget* drawTarget = aCtx->GetDrawTarget();
|
|
|
|
|
|
2011-01-18 19:43:47 +00:00
|
|
|
|
// We don't support custom clips and rounded corners, arguably a bug, but
|
|
|
|
|
// table painting seems to depend on it.
|
2014-07-23 05:20:39 +00:00
|
|
|
|
if (!aClipState.mHasRoundedCorners || aClipState.mCustomClip) {
|
2011-01-18 19:43:47 +00:00
|
|
|
|
aCtx->NewPath();
|
2011-10-17 14:59:28 +00:00
|
|
|
|
aCtx->Rectangle(aClipState.mDirtyRectGfx, true);
|
2011-01-18 19:43:47 +00:00
|
|
|
|
aCtx->Fill();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-02 15:41:08 +00:00
|
|
|
|
Rect bgAreaGfx = NSRectToRect(aClipState.mBGClipArea, aAppUnitsPerPixel);
|
2011-01-18 19:43:47 +00:00
|
|
|
|
bgAreaGfx.Round();
|
|
|
|
|
|
|
|
|
|
if (bgAreaGfx.IsEmpty()) {
|
|
|
|
|
// I think it's become possible to hit this since
|
|
|
|
|
// http://hg.mozilla.org/mozilla-central/rev/50e934e4979b landed.
|
|
|
|
|
NS_WARNING("converted background area should not be empty");
|
|
|
|
|
// Make our caller not do anything.
|
2011-04-19 03:07:21 +00:00
|
|
|
|
aClipState.mDirtyRectGfx.SizeTo(gfxSize(0.0, 0.0));
|
2011-01-18 19:43:47 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
aCtx->Save();
|
2014-11-02 15:41:08 +00:00
|
|
|
|
gfxRect dirty = ThebesRect(bgAreaGfx).Intersect(aClipState.mDirtyRectGfx);
|
2011-01-18 19:43:47 +00:00
|
|
|
|
|
|
|
|
|
aCtx->NewPath();
|
2011-10-17 14:59:28 +00:00
|
|
|
|
aCtx->Rectangle(dirty, true);
|
2011-01-18 19:43:47 +00:00
|
|
|
|
aCtx->Clip();
|
|
|
|
|
|
2013-07-23 13:22:58 +00:00
|
|
|
|
if (aClipState.mHasAdditionalBGClipArea) {
|
|
|
|
|
gfxRect bgAdditionalAreaGfx = nsLayoutUtils::RectToGfxRect(
|
|
|
|
|
aClipState.mAdditionalBGClipArea, aAppUnitsPerPixel);
|
|
|
|
|
bgAdditionalAreaGfx.Round();
|
|
|
|
|
bgAdditionalAreaGfx.Condition();
|
|
|
|
|
aCtx->NewPath();
|
|
|
|
|
aCtx->Rectangle(bgAdditionalAreaGfx, true);
|
|
|
|
|
aCtx->Clip();
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
|
RefPtr<Path> roundedRect =
|
2014-11-02 15:41:08 +00:00
|
|
|
|
MakePathForRoundedRect(*drawTarget, bgAreaGfx, aClipState.mClippedRadii);
|
|
|
|
|
aCtx->SetPath(roundedRect);
|
2011-01-18 19:43:47 +00:00
|
|
|
|
aCtx->Fill();
|
|
|
|
|
aCtx->Restore();
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-03 20:11:57 +00:00
|
|
|
|
nscolor
|
|
|
|
|
nsCSSRendering::DetermineBackgroundColor(nsPresContext* aPresContext,
|
|
|
|
|
nsStyleContext* aStyleContext,
|
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
|
bool& aDrawBackgroundImage,
|
|
|
|
|
bool& aDrawBackgroundColor)
|
2009-07-04 09:30:59 +00:00
|
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
|
aDrawBackgroundImage = true;
|
|
|
|
|
aDrawBackgroundColor = true;
|
2009-07-04 09:30:59 +00:00
|
|
|
|
|
2016-03-08 14:44:00 +00:00
|
|
|
|
const nsStyleVisibility* visibility = aStyleContext->StyleVisibility();
|
|
|
|
|
|
|
|
|
|
if (visibility->mColorAdjust != NS_STYLE_COLOR_ADJUST_EXACT &&
|
|
|
|
|
aFrame->HonorPrintBackgroundSettings()) {
|
2009-05-28 18:09:05 +00:00
|
|
|
|
aDrawBackgroundImage = aPresContext->GetBackgroundImageDraw();
|
|
|
|
|
aDrawBackgroundColor = aPresContext->GetBackgroundColorDraw();
|
2009-07-04 09:30:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-16 21:51:02 +00:00
|
|
|
|
const nsStyleBackground *bg = aStyleContext->StyleBackground();
|
2009-07-04 09:30:59 +00:00
|
|
|
|
nscolor bgColor;
|
2009-05-28 18:09:05 +00:00
|
|
|
|
if (aDrawBackgroundColor) {
|
2010-04-03 01:58:26 +00:00
|
|
|
|
bgColor =
|
|
|
|
|
aStyleContext->GetVisitedDependentColor(eCSSProperty_background_color);
|
2012-11-08 04:08:40 +00:00
|
|
|
|
if (NS_GET_A(bgColor) == 0) {
|
2011-10-17 14:59:28 +00:00
|
|
|
|
aDrawBackgroundColor = false;
|
2012-11-08 04:08:40 +00:00
|
|
|
|
}
|
2009-07-04 09:30:59 +00:00
|
|
|
|
} else {
|
|
|
|
|
// If GetBackgroundColorDraw() is false, we are still expected to
|
|
|
|
|
// draw color in the background of any frame that's not completely
|
|
|
|
|
// transparent, but we are expected to use white instead of whatever
|
|
|
|
|
// color was specified.
|
|
|
|
|
bgColor = NS_RGB(255, 255, 255);
|
2012-11-08 04:08:40 +00:00
|
|
|
|
if (aDrawBackgroundImage || !bg->IsTransparent()) {
|
2011-10-17 14:59:28 +00:00
|
|
|
|
aDrawBackgroundColor = true;
|
2012-11-08 04:08:40 +00:00
|
|
|
|
} else {
|
2009-07-04 09:30:59 +00:00
|
|
|
|
bgColor = NS_RGBA(0,0,0,0);
|
2012-11-08 04:08:40 +00:00
|
|
|
|
}
|
2009-07-04 09:30:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-03 20:13:12 +00:00
|
|
|
|
// We can skip painting the background color if a background image is opaque.
|
2016-05-25 00:29:00 +00:00
|
|
|
|
nsStyleImageLayers::Repeat repeat = bg->BottomLayer().mRepeat;
|
|
|
|
|
bool xFullRepeat = repeat.mXRepeat == NS_STYLE_IMAGELAYER_REPEAT_REPEAT ||
|
|
|
|
|
repeat.mXRepeat == NS_STYLE_IMAGELAYER_REPEAT_ROUND;
|
|
|
|
|
bool yFullRepeat = repeat.mYRepeat == NS_STYLE_IMAGELAYER_REPEAT_REPEAT ||
|
|
|
|
|
repeat.mYRepeat == NS_STYLE_IMAGELAYER_REPEAT_ROUND;
|
2012-05-03 20:13:12 +00:00
|
|
|
|
if (aDrawBackgroundColor &&
|
2016-05-25 00:29:00 +00:00
|
|
|
|
xFullRepeat && yFullRepeat &&
|
2014-01-14 20:57:49 +00:00
|
|
|
|
bg->BottomLayer().mImage.IsOpaque() &&
|
|
|
|
|
bg->BottomLayer().mBlendMode == NS_STYLE_BLEND_NORMAL) {
|
2012-05-03 20:13:12 +00:00
|
|
|
|
aDrawBackgroundColor = false;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-04 09:30:59 +00:00
|
|
|
|
return bgColor;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-01 15:53:40 +00:00
|
|
|
|
static gfxFloat
|
|
|
|
|
ConvertGradientValueToPixels(const nsStyleCoord& aCoord,
|
2009-11-02 19:36:43 +00:00
|
|
|
|
gfxFloat aFillLength,
|
2012-08-22 15:56:38 +00:00
|
|
|
|
int32_t aAppUnitsPerPixel)
|
2009-08-01 15:53:40 +00:00
|
|
|
|
{
|
|
|
|
|
switch (aCoord.GetUnit()) {
|
|
|
|
|
case eStyleUnit_Percent:
|
2009-11-02 19:36:43 +00:00
|
|
|
|
return aCoord.GetPercentValue() * aFillLength;
|
2009-08-01 15:53:40 +00:00
|
|
|
|
case eStyleUnit_Coord:
|
2009-11-02 19:36:43 +00:00
|
|
|
|
return NSAppUnitsToFloatPixels(aCoord.GetCoordValue(), aAppUnitsPerPixel);
|
2010-09-15 15:11:26 +00:00
|
|
|
|
case eStyleUnit_Calc: {
|
|
|
|
|
const nsStyleCoord::Calc *calc = aCoord.GetCalcValue();
|
|
|
|
|
return calc->mPercent * aFillLength +
|
|
|
|
|
NSAppUnitsToFloatPixels(calc->mLength, aAppUnitsPerPixel);
|
|
|
|
|
}
|
2009-08-01 15:53:40 +00:00
|
|
|
|
default:
|
|
|
|
|
NS_WARNING("Unexpected coord unit");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-02 19:36:43 +00:00
|
|
|
|
// Given a box with size aBoxSize and origin (0,0), and an angle aAngle,
|
|
|
|
|
// and a starting point for the gradient line aStart, find the endpoint of
|
|
|
|
|
// the gradient line --- the intersection of the gradient line with a line
|
|
|
|
|
// perpendicular to aAngle that passes through the farthest corner in the
|
|
|
|
|
// direction aAngle.
|
|
|
|
|
static gfxPoint
|
|
|
|
|
ComputeGradientLineEndFromAngle(const gfxPoint& aStart,
|
|
|
|
|
double aAngle,
|
|
|
|
|
const gfxSize& aBoxSize)
|
|
|
|
|
{
|
|
|
|
|
double dx = cos(-aAngle);
|
|
|
|
|
double dy = sin(-aAngle);
|
|
|
|
|
gfxPoint farthestCorner(dx > 0 ? aBoxSize.width : 0,
|
|
|
|
|
dy > 0 ? aBoxSize.height : 0);
|
|
|
|
|
gfxPoint delta = farthestCorner - aStart;
|
|
|
|
|
double u = delta.x*dy - delta.y*dx;
|
|
|
|
|
return farthestCorner + gfxPoint(-u*dy, u*dx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Compute the start and end points of the gradient line for a linear gradient.
|
|
|
|
|
static void
|
|
|
|
|
ComputeLinearGradientLine(nsPresContext* aPresContext,
|
|
|
|
|
nsStyleGradient* aGradient,
|
|
|
|
|
const gfxSize& aBoxSize,
|
|
|
|
|
gfxPoint* aLineStart,
|
|
|
|
|
gfxPoint* aLineEnd)
|
|
|
|
|
{
|
|
|
|
|
if (aGradient->mBgPosX.GetUnit() == eStyleUnit_None) {
|
2015-07-15 14:37:22 +00:00
|
|
|
|
double angle;
|
2009-11-02 19:36:43 +00:00
|
|
|
|
if (aGradient->mAngle.IsAngleValue()) {
|
2015-07-15 14:37:22 +00:00
|
|
|
|
angle = aGradient->mAngle.GetAngleValueInRadians();
|
|
|
|
|
if (!aGradient->mLegacySyntax) {
|
|
|
|
|
angle = M_PI_2 - angle;
|
|
|
|
|
}
|
2009-11-02 19:36:43 +00:00
|
|
|
|
} else {
|
|
|
|
|
angle = -M_PI_2; // defaults to vertical gradient starting from top
|
|
|
|
|
}
|
2015-07-15 14:37:22 +00:00
|
|
|
|
gfxPoint center(aBoxSize.width/2, aBoxSize.height/2);
|
|
|
|
|
*aLineEnd = ComputeGradientLineEndFromAngle(center, angle, aBoxSize);
|
|
|
|
|
*aLineStart = gfxPoint(aBoxSize.width, aBoxSize.height) - *aLineEnd;
|
|
|
|
|
} else if (!aGradient->mLegacySyntax) {
|
2011-10-22 19:41:11 +00:00
|
|
|
|
float xSign = aGradient->mBgPosX.GetPercentValue() * 2 - 1;
|
|
|
|
|
float ySign = 1 - aGradient->mBgPosY.GetPercentValue() * 2;
|
2015-07-15 14:37:22 +00:00
|
|
|
|
double angle = atan2(ySign * aBoxSize.width, xSign * aBoxSize.height);
|
|
|
|
|
gfxPoint center(aBoxSize.width/2, aBoxSize.height/2);
|
|
|
|
|
*aLineEnd = ComputeGradientLineEndFromAngle(center, angle, aBoxSize);
|
|
|
|
|
*aLineStart = gfxPoint(aBoxSize.width, aBoxSize.height) - *aLineEnd;
|
|
|
|
|
} else {
|
|
|
|
|
int32_t appUnitsPerPixel = aPresContext->AppUnitsPerDevPixel();
|
|
|
|
|
*aLineStart = gfxPoint(
|
|
|
|
|
ConvertGradientValueToPixels(aGradient->mBgPosX, aBoxSize.width,
|
|
|
|
|
appUnitsPerPixel),
|
|
|
|
|
ConvertGradientValueToPixels(aGradient->mBgPosY, aBoxSize.height,
|
|
|
|
|
appUnitsPerPixel));
|
|
|
|
|
if (aGradient->mAngle.IsAngleValue()) {
|
|
|
|
|
MOZ_ASSERT(aGradient->mLegacySyntax);
|
|
|
|
|
double angle = aGradient->mAngle.GetAngleValueInRadians();
|
|
|
|
|
*aLineEnd = ComputeGradientLineEndFromAngle(*aLineStart, angle, aBoxSize);
|
|
|
|
|
} else {
|
|
|
|
|
// No angle, the line end is just the reflection of the start point
|
|
|
|
|
// through the center of the box
|
|
|
|
|
*aLineEnd = gfxPoint(aBoxSize.width, aBoxSize.height) - *aLineStart;
|
|
|
|
|
}
|
2009-11-02 19:36:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Compute the start and end points of the gradient line for a radial gradient.
|
|
|
|
|
// Also returns the horizontal and vertical radii defining the circle or
|
|
|
|
|
// ellipse to use.
|
|
|
|
|
static void
|
|
|
|
|
ComputeRadialGradientLine(nsPresContext* aPresContext,
|
|
|
|
|
nsStyleGradient* aGradient,
|
|
|
|
|
const gfxSize& aBoxSize,
|
|
|
|
|
gfxPoint* aLineStart,
|
|
|
|
|
gfxPoint* aLineEnd,
|
|
|
|
|
double* aRadiusX,
|
|
|
|
|
double* aRadiusY)
|
|
|
|
|
{
|
|
|
|
|
if (aGradient->mBgPosX.GetUnit() == eStyleUnit_None) {
|
|
|
|
|
// Default line start point is the center of the box
|
|
|
|
|
*aLineStart = gfxPoint(aBoxSize.width/2, aBoxSize.height/2);
|
|
|
|
|
} else {
|
2012-08-22 15:56:38 +00:00
|
|
|
|
int32_t appUnitsPerPixel = aPresContext->AppUnitsPerDevPixel();
|
2009-11-02 19:36:43 +00:00
|
|
|
|
*aLineStart = gfxPoint(
|
|
|
|
|
ConvertGradientValueToPixels(aGradient->mBgPosX, aBoxSize.width,
|
|
|
|
|
appUnitsPerPixel),
|
|
|
|
|
ConvertGradientValueToPixels(aGradient->mBgPosY, aBoxSize.height,
|
|
|
|
|
appUnitsPerPixel));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Compute gradient shape: the x and y radii of an ellipse.
|
|
|
|
|
double radiusX, radiusY;
|
2013-03-05 23:43:44 +00:00
|
|
|
|
double leftDistance = Abs(aLineStart->x);
|
|
|
|
|
double rightDistance = Abs(aBoxSize.width - aLineStart->x);
|
|
|
|
|
double topDistance = Abs(aLineStart->y);
|
|
|
|
|
double bottomDistance = Abs(aBoxSize.height - aLineStart->y);
|
2009-11-02 19:36:43 +00:00
|
|
|
|
switch (aGradient->mSize) {
|
|
|
|
|
case NS_STYLE_GRADIENT_SIZE_CLOSEST_SIDE:
|
2013-01-15 12:22:03 +00:00
|
|
|
|
radiusX = std::min(leftDistance, rightDistance);
|
|
|
|
|
radiusY = std::min(topDistance, bottomDistance);
|
2009-11-02 19:36:43 +00:00
|
|
|
|
if (aGradient->mShape == NS_STYLE_GRADIENT_SHAPE_CIRCULAR) {
|
2013-01-15 12:22:03 +00:00
|
|
|
|
radiusX = radiusY = std::min(radiusX, radiusY);
|
2009-11-02 19:36:43 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case NS_STYLE_GRADIENT_SIZE_CLOSEST_CORNER: {
|
|
|
|
|
// Compute x and y distances to nearest corner
|
2013-01-15 12:22:03 +00:00
|
|
|
|
double offsetX = std::min(leftDistance, rightDistance);
|
|
|
|
|
double offsetY = std::min(topDistance, bottomDistance);
|
2009-11-02 19:36:43 +00:00
|
|
|
|
if (aGradient->mShape == NS_STYLE_GRADIENT_SHAPE_CIRCULAR) {
|
|
|
|
|
radiusX = radiusY = NS_hypot(offsetX, offsetY);
|
|
|
|
|
} else {
|
|
|
|
|
// maintain aspect ratio
|
|
|
|
|
radiusX = offsetX*M_SQRT2;
|
|
|
|
|
radiusY = offsetY*M_SQRT2;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case NS_STYLE_GRADIENT_SIZE_FARTHEST_SIDE:
|
2013-01-15 12:22:03 +00:00
|
|
|
|
radiusX = std::max(leftDistance, rightDistance);
|
|
|
|
|
radiusY = std::max(topDistance, bottomDistance);
|
2009-11-02 19:36:43 +00:00
|
|
|
|
if (aGradient->mShape == NS_STYLE_GRADIENT_SHAPE_CIRCULAR) {
|
2013-01-15 12:22:03 +00:00
|
|
|
|
radiusX = radiusY = std::max(radiusX, radiusY);
|
2009-11-02 19:36:43 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case NS_STYLE_GRADIENT_SIZE_FARTHEST_CORNER: {
|
|
|
|
|
// Compute x and y distances to nearest corner
|
2013-01-15 12:22:03 +00:00
|
|
|
|
double offsetX = std::max(leftDistance, rightDistance);
|
|
|
|
|
double offsetY = std::max(topDistance, bottomDistance);
|
2009-11-02 19:36:43 +00:00
|
|
|
|
if (aGradient->mShape == NS_STYLE_GRADIENT_SHAPE_CIRCULAR) {
|
|
|
|
|
radiusX = radiusY = NS_hypot(offsetX, offsetY);
|
|
|
|
|
} else {
|
|
|
|
|
// maintain aspect ratio
|
|
|
|
|
radiusX = offsetX*M_SQRT2;
|
|
|
|
|
radiusY = offsetY*M_SQRT2;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-07-07 14:27:08 +00:00
|
|
|
|
case NS_STYLE_GRADIENT_SIZE_EXPLICIT_SIZE: {
|
2012-08-22 15:56:38 +00:00
|
|
|
|
int32_t appUnitsPerPixel = aPresContext->AppUnitsPerDevPixel();
|
2012-07-07 14:27:08 +00:00
|
|
|
|
radiusX = ConvertGradientValueToPixels(aGradient->mRadiusX,
|
|
|
|
|
aBoxSize.width, appUnitsPerPixel);
|
|
|
|
|
radiusY = ConvertGradientValueToPixels(aGradient->mRadiusY,
|
|
|
|
|
aBoxSize.height, appUnitsPerPixel);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2009-11-02 19:36:43 +00:00
|
|
|
|
default:
|
2012-10-10 05:00:05 +00:00
|
|
|
|
radiusX = radiusY = 0;
|
2015-02-09 22:34:50 +00:00
|
|
|
|
MOZ_ASSERT(false, "unknown radial gradient sizing method");
|
2009-11-02 19:36:43 +00:00
|
|
|
|
}
|
|
|
|
|
*aRadiusX = radiusX;
|
|
|
|
|
*aRadiusY = radiusY;
|
|
|
|
|
|
|
|
|
|
double angle;
|
|
|
|
|
if (aGradient->mAngle.IsAngleValue()) {
|
|
|
|
|
angle = aGradient->mAngle.GetAngleValueInRadians();
|
|
|
|
|
} else {
|
|
|
|
|
// Default angle is 0deg
|
|
|
|
|
angle = 0.0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The gradient line end point is where the gradient line intersects
|
|
|
|
|
// the ellipse.
|
|
|
|
|
*aLineEnd = *aLineStart + gfxPoint(radiusX*cos(-angle), radiusY*sin(-angle));
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-22 06:13:56 +00:00
|
|
|
|
|
|
|
|
|
static float Interpolate(float aF1, float aF2, float aFrac)
|
|
|
|
|
{
|
|
|
|
|
return aF1 + aFrac * (aF2 - aF1);
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-02 19:36:43 +00:00
|
|
|
|
// Returns aFrac*aC2 + (1 - aFrac)*C1. The interpolation is done
|
|
|
|
|
// in unpremultiplied space, which is what SVG gradients and cairo
|
|
|
|
|
// gradients expect.
|
2015-09-24 07:40:20 +00:00
|
|
|
|
static Color
|
|
|
|
|
InterpolateColor(const Color& aC1, const Color& aC2, float aFrac)
|
2009-11-02 19:36:43 +00:00
|
|
|
|
{
|
|
|
|
|
double other = 1 - aFrac;
|
2015-09-24 07:40:20 +00:00
|
|
|
|
return Color(aC2.r*aFrac + aC1.r*other,
|
|
|
|
|
aC2.g*aFrac + aC1.g*other,
|
|
|
|
|
aC2.b*aFrac + aC1.b*other,
|
|
|
|
|
aC2.a*aFrac + aC1.a*other);
|
2009-11-02 19:36:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-01-14 02:30:05 +00:00
|
|
|
|
static nscoord
|
|
|
|
|
FindTileStart(nscoord aDirtyCoord, nscoord aTilePos, nscoord aTileDim)
|
|
|
|
|
{
|
|
|
|
|
NS_ASSERTION(aTileDim > 0, "Non-positive tile dimension");
|
2011-05-30 19:08:55 +00:00
|
|
|
|
double multiples = floor(double(aDirtyCoord - aTilePos)/aTileDim);
|
2010-01-14 02:30:05 +00:00
|
|
|
|
return NSToCoordRound(multiples*aTileDim + aTilePos);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-28 14:14:42 +00:00
|
|
|
|
static gfxFloat
|
|
|
|
|
LinearGradientStopPositionForPoint(const gfxPoint& aGradientStart,
|
|
|
|
|
const gfxPoint& aGradientEnd,
|
|
|
|
|
const gfxPoint& aPoint)
|
|
|
|
|
{
|
|
|
|
|
gfxPoint d = aGradientEnd - aGradientStart;
|
|
|
|
|
gfxPoint p = aPoint - aGradientStart;
|
|
|
|
|
/**
|
|
|
|
|
* Compute a parameter t such that a line perpendicular to the
|
|
|
|
|
* d vector, passing through aGradientStart + d*t, also
|
|
|
|
|
* passes through aPoint.
|
|
|
|
|
*
|
|
|
|
|
* t is given by
|
|
|
|
|
* (p.x - d.x*t)*d.x + (p.y - d.y*t)*d.y = 0
|
|
|
|
|
*
|
|
|
|
|
* Solving for t we get
|
|
|
|
|
* numerator = d.x*p.x + d.y*p.y
|
|
|
|
|
* denominator = d.x^2 + d.y^2
|
|
|
|
|
* t = numerator/denominator
|
|
|
|
|
*
|
|
|
|
|
* In nsCSSRendering::PaintGradient we know the length of d
|
|
|
|
|
* is not zero.
|
|
|
|
|
*/
|
|
|
|
|
double numerator = d.x * p.x + d.y * p.y;
|
|
|
|
|
double denominator = d.x * d.x + d.y * d.y;
|
|
|
|
|
return numerator / denominator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
RectIsBeyondLinearGradientEdge(const gfxRect& aRect,
|
|
|
|
|
const gfxMatrix& aPatternMatrix,
|
|
|
|
|
const nsTArray<ColorStop>& aStops,
|
|
|
|
|
const gfxPoint& aGradientStart,
|
|
|
|
|
const gfxPoint& aGradientEnd,
|
2015-09-24 07:40:20 +00:00
|
|
|
|
Color* aOutEdgeColor)
|
2014-05-28 14:14:42 +00:00
|
|
|
|
{
|
|
|
|
|
gfxFloat topLeft = LinearGradientStopPositionForPoint(
|
|
|
|
|
aGradientStart, aGradientEnd, aPatternMatrix.Transform(aRect.TopLeft()));
|
|
|
|
|
gfxFloat topRight = LinearGradientStopPositionForPoint(
|
|
|
|
|
aGradientStart, aGradientEnd, aPatternMatrix.Transform(aRect.TopRight()));
|
|
|
|
|
gfxFloat bottomLeft = LinearGradientStopPositionForPoint(
|
|
|
|
|
aGradientStart, aGradientEnd, aPatternMatrix.Transform(aRect.BottomLeft()));
|
|
|
|
|
gfxFloat bottomRight = LinearGradientStopPositionForPoint(
|
|
|
|
|
aGradientStart, aGradientEnd, aPatternMatrix.Transform(aRect.BottomRight()));
|
|
|
|
|
|
|
|
|
|
const ColorStop& firstStop = aStops[0];
|
|
|
|
|
if (topLeft < firstStop.mPosition && topRight < firstStop.mPosition &&
|
|
|
|
|
bottomLeft < firstStop.mPosition && bottomRight < firstStop.mPosition) {
|
|
|
|
|
*aOutEdgeColor = firstStop.mColor;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const ColorStop& lastStop = aStops.LastElement();
|
|
|
|
|
if (topLeft >= lastStop.mPosition && topRight >= lastStop.mPosition &&
|
|
|
|
|
bottomLeft >= lastStop.mPosition && bottomRight >= lastStop.mPosition) {
|
|
|
|
|
*aOutEdgeColor = lastStop.mColor;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-22 12:25:00 +00:00
|
|
|
|
static void ResolveMidpoints(nsTArray<ColorStop>& stops)
|
|
|
|
|
{
|
|
|
|
|
for (size_t x = 1; x < stops.Length() - 1;) {
|
|
|
|
|
if (!stops[x].mIsMidpoint) {
|
|
|
|
|
x++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-24 07:40:20 +00:00
|
|
|
|
Color color1 = stops[x-1].mColor;
|
|
|
|
|
Color color2 = stops[x+1].mColor;
|
2014-10-22 12:25:00 +00:00
|
|
|
|
float offset1 = stops[x-1].mPosition;
|
|
|
|
|
float offset2 = stops[x+1].mPosition;
|
|
|
|
|
float offset = stops[x].mPosition;
|
|
|
|
|
// check if everything coincides. If so, ignore the midpoint.
|
|
|
|
|
if (offset - offset1 == offset2 - offset) {
|
|
|
|
|
stops.RemoveElementAt(x);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if we coincide with the left colorstop.
|
|
|
|
|
if (offset1 == offset) {
|
|
|
|
|
// Morph the midpoint to a regular stop with the color of the next
|
|
|
|
|
// color stop.
|
|
|
|
|
stops[x].mColor = color2;
|
|
|
|
|
stops[x].mIsMidpoint = false;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if we coincide with the right colorstop.
|
|
|
|
|
if (offset2 == offset) {
|
|
|
|
|
// Morph the midpoint to a regular stop with the color of the previous
|
|
|
|
|
// color stop.
|
|
|
|
|
stops[x].mColor = color1;
|
|
|
|
|
stops[x].mIsMidpoint = false;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float midpoint = (offset - offset1) / (offset2 - offset1);
|
|
|
|
|
ColorStop newStops[9];
|
|
|
|
|
if (midpoint > .5f) {
|
|
|
|
|
for (size_t y = 0; y < 7; y++) {
|
|
|
|
|
newStops[y].mPosition = offset1 + (offset - offset1) * (7 + y) / 13;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
newStops[7].mPosition = offset + (offset2 - offset) / 3;
|
|
|
|
|
newStops[8].mPosition = offset + (offset2 - offset) * 2 / 3;
|
|
|
|
|
} else {
|
|
|
|
|
newStops[0].mPosition = offset1 + (offset - offset1) / 3;
|
|
|
|
|
newStops[1].mPosition = offset1 + (offset - offset1) * 2 / 3;
|
|
|
|
|
|
|
|
|
|
for (size_t y = 0; y < 7; y++) {
|
|
|
|
|
newStops[y+2].mPosition = offset + (offset2 - offset) * y / 13;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// calculate colors
|
|
|
|
|
|
|
|
|
|
for (size_t y = 0; y < 9; y++) {
|
|
|
|
|
// Calculate the intermediate color stops per the formula of the CSS images
|
|
|
|
|
// spec. http://dev.w3.org/csswg/css-images/#color-stop-syntax
|
|
|
|
|
// 9 points were chosen since it is the minimum number of stops that always
|
|
|
|
|
// give the smoothest appearace regardless of midpoint position and difference
|
|
|
|
|
// in luminance of the end points.
|
|
|
|
|
float relativeOffset = (newStops[y].mPosition - offset1) / (offset2 - offset1);
|
|
|
|
|
float multiplier = powf(relativeOffset, logf(.5f) / logf(midpoint));
|
|
|
|
|
|
2015-09-24 07:40:20 +00:00
|
|
|
|
gfx::Float red = color1.r + multiplier * (color2.r - color1.r);
|
|
|
|
|
gfx::Float green = color1.g + multiplier * (color2.g - color1.g);
|
|
|
|
|
gfx::Float blue = color1.b + multiplier * (color2.b - color1.b);
|
|
|
|
|
gfx::Float alpha = color1.a + multiplier * (color2.a - color1.a);
|
|
|
|
|
|
|
|
|
|
newStops[y].mColor = Color(red, green, blue, alpha);
|
2014-10-22 12:25:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stops.ReplaceElementsAt(x, 1, newStops, 9);
|
|
|
|
|
x += 9;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-24 07:40:20 +00:00
|
|
|
|
static Color
|
|
|
|
|
Premultiply(const Color& aColor)
|
2014-10-22 06:13:56 +00:00
|
|
|
|
{
|
2015-09-24 07:40:20 +00:00
|
|
|
|
gfx::Float a = aColor.a;
|
|
|
|
|
return Color(aColor.r * a, aColor.g * a, aColor.b * a, a);
|
2014-10-22 06:13:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-24 07:40:20 +00:00
|
|
|
|
static Color
|
|
|
|
|
Unpremultiply(const Color& aColor)
|
2014-10-22 06:13:56 +00:00
|
|
|
|
{
|
2015-09-24 07:40:20 +00:00
|
|
|
|
gfx::Float a = aColor.a;
|
|
|
|
|
return (a > 0.f)
|
|
|
|
|
? Color(aColor.r / a, aColor.g / a, aColor.b / a, a)
|
|
|
|
|
: aColor;
|
2014-10-22 06:13:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-24 07:40:20 +00:00
|
|
|
|
static Color
|
|
|
|
|
TransparentColor(Color aColor) {
|
2014-10-22 06:13:56 +00:00
|
|
|
|
aColor.a = 0;
|
|
|
|
|
return aColor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Adjusts and adds color stops in such a way that drawing the gradient with
|
|
|
|
|
// unpremultiplied interpolation looks nearly the same as if it were drawn with
|
|
|
|
|
// premultiplied interpolation.
|
|
|
|
|
static const float kAlphaIncrementPerGradientStep = 0.1f;
|
|
|
|
|
static void
|
|
|
|
|
ResolvePremultipliedAlpha(nsTArray<ColorStop>& aStops)
|
|
|
|
|
{
|
|
|
|
|
for (size_t x = 1; x < aStops.Length(); x++) {
|
|
|
|
|
const ColorStop leftStop = aStops[x - 1];
|
|
|
|
|
const ColorStop rightStop = aStops[x];
|
|
|
|
|
|
|
|
|
|
// if the left and right stop have the same alpha value, we don't need
|
|
|
|
|
// to do anything
|
|
|
|
|
if (leftStop.mColor.a == rightStop.mColor.a) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Is the stop on the left 100% transparent? If so, have it adopt the color
|
|
|
|
|
// of the right stop
|
|
|
|
|
if (leftStop.mColor.a == 0) {
|
|
|
|
|
aStops[x - 1].mColor = TransparentColor(rightStop.mColor);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Is the stop on the right completely transparent?
|
|
|
|
|
// If so, duplicate it and assign it the color on the left.
|
|
|
|
|
if (rightStop.mColor.a == 0) {
|
|
|
|
|
ColorStop newStop = rightStop;
|
|
|
|
|
newStop.mColor = TransparentColor(leftStop.mColor);
|
|
|
|
|
aStops.InsertElementAt(x, newStop);
|
|
|
|
|
x++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Now handle cases where one or both of the stops are partially transparent.
|
|
|
|
|
if (leftStop.mColor.a != 1.0f || rightStop.mColor.a != 1.0f) {
|
2015-09-24 07:40:20 +00:00
|
|
|
|
Color premulLeftColor = Premultiply(leftStop.mColor);
|
|
|
|
|
Color premulRightColor = Premultiply(rightStop.mColor);
|
2014-10-22 06:13:56 +00:00
|
|
|
|
// Calculate how many extra steps. We do a step per 10% transparency.
|
2015-09-24 07:40:20 +00:00
|
|
|
|
size_t stepCount = NSToIntFloor(fabsf(leftStop.mColor.a - rightStop.mColor.a) / kAlphaIncrementPerGradientStep);
|
2014-10-22 06:13:56 +00:00
|
|
|
|
for (size_t y = 1; y < stepCount; y++) {
|
|
|
|
|
float frac = static_cast<float>(y) / stepCount;
|
2014-10-22 12:25:00 +00:00
|
|
|
|
ColorStop newStop(Interpolate(leftStop.mPosition, rightStop.mPosition, frac), false,
|
2014-10-22 06:13:56 +00:00
|
|
|
|
Unpremultiply(InterpolateColor(premulLeftColor, premulRightColor, frac)));
|
|
|
|
|
aStops.InsertElementAt(x, newStop);
|
|
|
|
|
x++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-27 15:57:53 +00:00
|
|
|
|
static ColorStop
|
|
|
|
|
InterpolateColorStop(const ColorStop& aFirst, const ColorStop& aSecond,
|
|
|
|
|
double aPosition, const Color& aDefault)
|
|
|
|
|
{
|
|
|
|
|
MOZ_ASSERT(aFirst.mPosition <= aPosition);
|
|
|
|
|
MOZ_ASSERT(aPosition <= aSecond.mPosition);
|
|
|
|
|
|
|
|
|
|
double delta = aSecond.mPosition - aFirst.mPosition;
|
|
|
|
|
|
|
|
|
|
if (delta < 1e-6) {
|
|
|
|
|
return ColorStop(aPosition, false, aDefault);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ColorStop(aPosition, false,
|
|
|
|
|
Unpremultiply(InterpolateColor(Premultiply(aFirst.mColor),
|
|
|
|
|
Premultiply(aSecond.mColor),
|
|
|
|
|
(aPosition - aFirst.mPosition) / delta)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Clamp and extend the given ColorStop array in-place to fit exactly into the
|
|
|
|
|
// range [0, 1].
|
|
|
|
|
static void
|
|
|
|
|
ClampColorStops(nsTArray<ColorStop>& aStops)
|
|
|
|
|
{
|
|
|
|
|
MOZ_ASSERT(aStops.Length() > 0);
|
|
|
|
|
|
|
|
|
|
// If all stops are outside the range, then get rid of everything and replace
|
|
|
|
|
// with a single colour.
|
|
|
|
|
if (aStops.Length() < 2 || aStops[0].mPosition > 1 ||
|
|
|
|
|
aStops.LastElement().mPosition < 0) {
|
|
|
|
|
Color c = aStops[0].mPosition > 1 ? aStops[0].mColor : aStops.LastElement().mColor;
|
|
|
|
|
aStops.Clear();
|
|
|
|
|
aStops.AppendElement(ColorStop(0, false, c));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create the 0 and 1 points if they fall in the range of |aStops|, and discard
|
|
|
|
|
// all stops outside the range [0, 1].
|
|
|
|
|
// XXX: If we have stops positioned at 0 or 1, we only keep the innermost of
|
|
|
|
|
// those stops. This should be fine for the current user(s) of this function.
|
|
|
|
|
for (size_t i = aStops.Length() - 1; i > 0; i--) {
|
|
|
|
|
if (aStops[i - 1].mPosition < 1 && aStops[i].mPosition >= 1) {
|
|
|
|
|
// Add a point to position 1.
|
|
|
|
|
aStops[i] = InterpolateColorStop(aStops[i - 1], aStops[i],
|
|
|
|
|
/* aPosition = */ 1,
|
|
|
|
|
aStops[i - 1].mColor);
|
|
|
|
|
// Remove all the elements whose position is greater than 1.
|
|
|
|
|
aStops.RemoveElementsAt(i + 1, aStops.Length() - (i + 1));
|
|
|
|
|
}
|
|
|
|
|
if (aStops[i - 1].mPosition <= 0 && aStops[i].mPosition > 0) {
|
|
|
|
|
// Add a point to position 0.
|
|
|
|
|
aStops[i - 1] = InterpolateColorStop(aStops[i - 1], aStops[i],
|
|
|
|
|
/* aPosition = */ 0,
|
|
|
|
|
aStops[i].mColor);
|
|
|
|
|
// Remove all of the preceding stops -- they are all negative.
|
|
|
|
|
aStops.RemoveElementsAt(0, i - 1);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MOZ_ASSERT(aStops[0].mPosition >= 0);
|
|
|
|
|
MOZ_ASSERT(aStops.LastElement().mPosition <= 1);
|
|
|
|
|
|
|
|
|
|
// The end points won't exist yet if they don't fall in the original range of
|
|
|
|
|
// |aStops|. Create them if needed.
|
|
|
|
|
if (aStops[0].mPosition > 0) {
|
|
|
|
|
aStops.InsertElementAt(0, ColorStop(0, false, aStops[0].mColor));
|
|
|
|
|
}
|
|
|
|
|
if (aStops.LastElement().mPosition < 1) {
|
|
|
|
|
aStops.AppendElement(ColorStop(1, false, aStops.LastElement().mColor));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-01 15:53:40 +00:00
|
|
|
|
void
|
|
|
|
|
nsCSSRendering::PaintGradient(nsPresContext* aPresContext,
|
2011-04-08 01:04:40 +00:00
|
|
|
|
nsRenderingContext& aRenderingContext,
|
2009-08-01 15:53:40 +00:00
|
|
|
|
nsStyleGradient* aGradient,
|
|
|
|
|
const nsRect& aDirtyRect,
|
2014-01-31 03:36:41 +00:00
|
|
|
|
const nsRect& aDest,
|
|
|
|
|
const nsRect& aFillArea,
|
2016-06-02 00:09:00 +00:00
|
|
|
|
const nsSize& aRepeatSize,
|
2014-01-31 03:36:41 +00:00
|
|
|
|
const CSSIntRect& aSrc,
|
|
|
|
|
const nsSize& aIntrinsicSize)
|
2009-08-01 15:53:40 +00:00
|
|
|
|
{
|
2014-05-23 21:12:29 +00:00
|
|
|
|
PROFILER_LABEL("nsCSSRendering", "PaintGradient",
|
|
|
|
|
js::ProfileEntry::Category::GRAPHICS);
|
|
|
|
|
|
2012-08-27 04:12:36 +00:00
|
|
|
|
Telemetry::AutoTimer<Telemetry::GRADIENT_DURATION, Telemetry::Microsecond> gradientTimer;
|
2014-01-31 03:36:41 +00:00
|
|
|
|
if (aDest.IsEmpty() || aFillArea.IsEmpty()) {
|
2009-11-02 19:36:43 +00:00
|
|
|
|
return;
|
2014-01-31 03:36:41 +00:00
|
|
|
|
}
|
2009-11-02 19:36:43 +00:00
|
|
|
|
|
2009-08-01 15:53:40 +00:00
|
|
|
|
gfxContext *ctx = aRenderingContext.ThebesContext();
|
2014-01-31 03:36:41 +00:00
|
|
|
|
nscoord appUnitsPerDevPixel = aPresContext->AppUnitsPerDevPixel();
|
|
|
|
|
gfxSize srcSize = gfxSize(gfxFloat(aIntrinsicSize.width)/appUnitsPerDevPixel,
|
|
|
|
|
gfxFloat(aIntrinsicSize.height)/appUnitsPerDevPixel);
|
2013-02-15 18:54:49 +00:00
|
|
|
|
|
2014-01-31 03:36:41 +00:00
|
|
|
|
bool cellContainsFill = aDest.Contains(aFillArea);
|
2012-10-26 13:34:43 +00:00
|
|
|
|
|
2014-01-31 03:36:41 +00:00
|
|
|
|
// Compute "gradient line" start and end relative to the intrinsic size of
|
|
|
|
|
// the gradient.
|
2013-02-15 18:54:49 +00:00
|
|
|
|
gfxPoint lineStart, lineEnd;
|
|
|
|
|
double radiusX = 0, radiusY = 0; // for radial gradients only
|
|
|
|
|
if (aGradient->mShape == NS_STYLE_GRADIENT_SHAPE_LINEAR) {
|
2014-01-31 03:36:41 +00:00
|
|
|
|
ComputeLinearGradientLine(aPresContext, aGradient, srcSize,
|
2013-02-15 18:54:49 +00:00
|
|
|
|
&lineStart, &lineEnd);
|
|
|
|
|
} else {
|
2014-01-31 03:36:41 +00:00
|
|
|
|
ComputeRadialGradientLine(aPresContext, aGradient, srcSize,
|
2013-02-15 18:54:49 +00:00
|
|
|
|
&lineStart, &lineEnd, &radiusX, &radiusY);
|
|
|
|
|
}
|
2016-04-24 00:54:07 +00:00
|
|
|
|
// Avoid sending Infs or Nans to downwind draw targets.
|
|
|
|
|
if (!lineStart.IsFinite() || !lineEnd.IsFinite()) {
|
|
|
|
|
lineStart = lineEnd = gfxPoint(0, 0);
|
|
|
|
|
}
|
2013-02-15 18:54:49 +00:00
|
|
|
|
gfxFloat lineLength = NS_hypot(lineEnd.x - lineStart.x,
|
|
|
|
|
lineEnd.y - lineStart.y);
|
|
|
|
|
|
2015-02-09 22:34:50 +00:00
|
|
|
|
MOZ_ASSERT(aGradient->mStops.Length() >= 2,
|
|
|
|
|
"The parser should reject gradients with less than two stops");
|
2013-02-15 18:54:49 +00:00
|
|
|
|
|
|
|
|
|
// Build color stop array and compute stop positions
|
|
|
|
|
nsTArray<ColorStop> stops;
|
|
|
|
|
// If there is a run of stops before stop i that did not have specified
|
|
|
|
|
// positions, then this is the index of the first stop in that run, otherwise
|
|
|
|
|
// it's -1.
|
|
|
|
|
int32_t firstUnsetPosition = -1;
|
|
|
|
|
for (uint32_t i = 0; i < aGradient->mStops.Length(); ++i) {
|
|
|
|
|
const nsStyleGradientStop& stop = aGradient->mStops[i];
|
|
|
|
|
double position;
|
|
|
|
|
switch (stop.mLocation.GetUnit()) {
|
|
|
|
|
case eStyleUnit_None:
|
|
|
|
|
if (i == 0) {
|
|
|
|
|
// First stop defaults to position 0.0
|
|
|
|
|
position = 0.0;
|
|
|
|
|
} else if (i == aGradient->mStops.Length() - 1) {
|
|
|
|
|
// Last stop defaults to position 1.0
|
|
|
|
|
position = 1.0;
|
|
|
|
|
} else {
|
|
|
|
|
// Other stops with no specified position get their position assigned
|
|
|
|
|
// later by interpolation, see below.
|
|
|
|
|
// Remeber where the run of stops with no specified position starts,
|
|
|
|
|
// if it starts here.
|
|
|
|
|
if (firstUnsetPosition < 0) {
|
|
|
|
|
firstUnsetPosition = i;
|
2009-11-02 19:36:43 +00:00
|
|
|
|
}
|
2015-09-24 07:40:20 +00:00
|
|
|
|
stops.AppendElement(ColorStop(0, stop.mIsInterpolationHint,
|
|
|
|
|
Color::FromABGR(stop.mColor)));
|
2013-02-15 18:54:49 +00:00
|
|
|
|
continue;
|
2009-11-02 19:36:43 +00:00
|
|
|
|
}
|
2013-02-15 18:54:49 +00:00
|
|
|
|
break;
|
|
|
|
|
case eStyleUnit_Percent:
|
|
|
|
|
position = stop.mLocation.GetPercentValue();
|
|
|
|
|
break;
|
|
|
|
|
case eStyleUnit_Coord:
|
|
|
|
|
position = lineLength < 1e-6 ? 0.0 :
|
2014-01-31 03:36:41 +00:00
|
|
|
|
stop.mLocation.GetCoordValue() / appUnitsPerDevPixel / lineLength;
|
2013-02-15 18:54:49 +00:00
|
|
|
|
break;
|
|
|
|
|
case eStyleUnit_Calc:
|
|
|
|
|
nsStyleCoord::Calc *calc;
|
|
|
|
|
calc = stop.mLocation.GetCalcValue();
|
|
|
|
|
position = calc->mPercent +
|
|
|
|
|
((lineLength < 1e-6) ? 0.0 :
|
2014-01-31 03:36:41 +00:00
|
|
|
|
(NSAppUnitsToFloatPixels(calc->mLength, appUnitsPerDevPixel) / lineLength));
|
2013-02-15 18:54:49 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2015-02-09 22:34:50 +00:00
|
|
|
|
MOZ_ASSERT(false, "Unknown stop position type");
|
2013-02-15 18:54:49 +00:00
|
|
|
|
}
|
2009-08-01 15:53:40 +00:00
|
|
|
|
|
2013-02-15 18:54:49 +00:00
|
|
|
|
if (i > 0) {
|
|
|
|
|
// Prevent decreasing stop positions by advancing this position
|
|
|
|
|
// to the previous stop position, if necessary
|
|
|
|
|
position = std::max(position, stops[i - 1].mPosition);
|
|
|
|
|
}
|
2015-09-24 07:40:20 +00:00
|
|
|
|
stops.AppendElement(ColorStop(position, stop.mIsInterpolationHint,
|
|
|
|
|
Color::FromABGR(stop.mColor)));
|
2013-02-15 18:54:49 +00:00
|
|
|
|
if (firstUnsetPosition > 0) {
|
|
|
|
|
// Interpolate positions for all stops that didn't have a specified position
|
|
|
|
|
double p = stops[firstUnsetPosition - 1].mPosition;
|
|
|
|
|
double d = (stops[i].mPosition - p)/(i - firstUnsetPosition + 1);
|
|
|
|
|
for (uint32_t j = firstUnsetPosition; j < i; ++j) {
|
|
|
|
|
p += d;
|
|
|
|
|
stops[j].mPosition = p;
|
2009-11-02 19:36:43 +00:00
|
|
|
|
}
|
2013-02-15 18:54:49 +00:00
|
|
|
|
firstUnsetPosition = -1;
|
2009-11-02 19:36:43 +00:00
|
|
|
|
}
|
2013-02-15 18:54:49 +00:00
|
|
|
|
}
|
2009-08-01 15:53:40 +00:00
|
|
|
|
|
2016-07-27 15:57:53 +00:00
|
|
|
|
// If a non-repeating linear gradient is axis-aligned and there are no gaps
|
|
|
|
|
// between tiles, we can optimise away most of the work by converting to a
|
|
|
|
|
// repeating linear gradient and filling the whole destination rect at once.
|
|
|
|
|
bool forceRepeatToCoverTiles =
|
|
|
|
|
aGradient->mShape == NS_STYLE_GRADIENT_SHAPE_LINEAR &&
|
|
|
|
|
(lineStart.x == lineEnd.x) != (lineStart.y == lineEnd.y) &&
|
|
|
|
|
aRepeatSize.width == aDest.width && aRepeatSize.height == aDest.height &&
|
|
|
|
|
!aGradient->mRepeating && !cellContainsFill;
|
|
|
|
|
|
|
|
|
|
gfxMatrix matrix;
|
|
|
|
|
if (forceRepeatToCoverTiles) {
|
|
|
|
|
// Length of the source rectangle along the gradient axis.
|
|
|
|
|
double rectLen;
|
|
|
|
|
// The position of the start of the rectangle along the gradient.
|
|
|
|
|
double offset;
|
|
|
|
|
|
|
|
|
|
// The gradient line is "backwards". Flip the line upside down to make
|
|
|
|
|
// things easier, and then rotate the matrix to turn everything back the
|
|
|
|
|
// right way up.
|
|
|
|
|
if (lineStart.x > lineEnd.x || lineStart.y > lineEnd.y) {
|
|
|
|
|
std::swap(lineStart, lineEnd);
|
|
|
|
|
matrix.Scale(-1, -1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fit the gradient line exactly into the source rect.
|
|
|
|
|
if (lineStart.x != lineEnd.x) {
|
|
|
|
|
rectLen = srcSize.width;
|
|
|
|
|
offset = ((double)aSrc.x - lineStart.x) / lineLength;
|
|
|
|
|
lineStart.x = aSrc.x;
|
|
|
|
|
lineEnd.x = aSrc.x + srcSize.width;
|
|
|
|
|
} else {
|
|
|
|
|
rectLen = srcSize.height;
|
|
|
|
|
offset = ((double)aSrc.y - lineStart.y) / lineLength;
|
|
|
|
|
lineStart.y = aSrc.y;
|
|
|
|
|
lineEnd.y = aSrc.y + srcSize.height;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Adjust gradient stop positions for the new gradient line.
|
|
|
|
|
double scale = lineLength / rectLen;
|
|
|
|
|
for (size_t i = 0; i < stops.Length(); i++) {
|
|
|
|
|
stops[i].mPosition = (stops[i].mPosition - offset) * fabs(scale);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Clamp or extrapolate gradient stops to exactly [0, 1].
|
|
|
|
|
ClampColorStops(stops);
|
|
|
|
|
|
|
|
|
|
lineLength = rectLen;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-15 18:54:49 +00:00
|
|
|
|
// Eliminate negative-position stops if the gradient is radial.
|
|
|
|
|
double firstStop = stops[0].mPosition;
|
|
|
|
|
if (aGradient->mShape != NS_STYLE_GRADIENT_SHAPE_LINEAR && firstStop < 0.0) {
|
|
|
|
|
if (aGradient->mRepeating) {
|
|
|
|
|
// Choose an instance of the repeated pattern that gives us all positive
|
|
|
|
|
// stop-offsets.
|
|
|
|
|
double lastStop = stops[stops.Length() - 1].mPosition;
|
|
|
|
|
double stopDelta = lastStop - firstStop;
|
|
|
|
|
// If all the stops are in approximately the same place then logic below
|
|
|
|
|
// will kick in that makes us draw just the last stop color, so don't
|
|
|
|
|
// try to do anything in that case. We certainly need to avoid
|
|
|
|
|
// dividing by zero.
|
|
|
|
|
if (stopDelta >= 1e-6) {
|
|
|
|
|
double instanceCount = ceil(-firstStop/stopDelta);
|
|
|
|
|
// Advance stops by instanceCount multiples of the period of the
|
|
|
|
|
// repeating gradient.
|
|
|
|
|
double offset = instanceCount*stopDelta;
|
2012-08-27 04:09:46 +00:00
|
|
|
|
for (uint32_t i = 0; i < stops.Length(); i++) {
|
2013-02-15 18:54:49 +00:00
|
|
|
|
stops[i].mPosition += offset;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// Move negative-position stops to position 0.0. We may also need
|
|
|
|
|
// to set the color of the stop to the color the gradient should have
|
|
|
|
|
// at the center of the ellipse.
|
|
|
|
|
for (uint32_t i = 0; i < stops.Length(); i++) {
|
|
|
|
|
double pos = stops[i].mPosition;
|
|
|
|
|
if (pos < 0.0) {
|
|
|
|
|
stops[i].mPosition = 0.0;
|
|
|
|
|
// If this is the last stop, we don't need to adjust the color,
|
|
|
|
|
// it will fill the entire area.
|
|
|
|
|
if (i < stops.Length() - 1) {
|
|
|
|
|
double nextPos = stops[i + 1].mPosition;
|
|
|
|
|
// If nextPos is approximately equal to pos, then we don't
|
|
|
|
|
// need to adjust the color of this stop because it's
|
|
|
|
|
// not going to be displayed.
|
|
|
|
|
// If nextPos is negative, we don't need to adjust the color of
|
|
|
|
|
// this stop since it's not going to be displayed because
|
|
|
|
|
// nextPos will also be moved to 0.0.
|
|
|
|
|
if (nextPos >= 0.0 && nextPos - pos >= 1e-6) {
|
|
|
|
|
// Compute how far the new position 0.0 is along the interval
|
|
|
|
|
// between pos and nextPos.
|
|
|
|
|
// XXX Color interpolation (in cairo, too) should use the
|
|
|
|
|
// CSS 'color-interpolation' property!
|
2015-09-24 07:40:20 +00:00
|
|
|
|
float frac = float((0.0 - pos)/(nextPos - pos));
|
2013-02-15 18:54:49 +00:00
|
|
|
|
stops[i].mColor =
|
|
|
|
|
InterpolateColor(stops[i].mColor, stops[i + 1].mColor, frac);
|
2009-11-02 19:36:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-15 18:54:49 +00:00
|
|
|
|
firstStop = stops[0].mPosition;
|
2015-02-09 22:34:50 +00:00
|
|
|
|
MOZ_ASSERT(firstStop >= 0.0, "Failed to fix stop offsets");
|
2013-02-15 18:54:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (aGradient->mShape != NS_STYLE_GRADIENT_SHAPE_LINEAR && !aGradient->mRepeating) {
|
|
|
|
|
// Direct2D can only handle a particular class of radial gradients because
|
|
|
|
|
// of the way the it specifies gradients. Setting firstStop to 0, when we
|
|
|
|
|
// can, will help us stay on the fast path. Currently we don't do this
|
|
|
|
|
// for repeating gradients but we could by adjusting the stop collection
|
|
|
|
|
// to start at 0
|
|
|
|
|
firstStop = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double lastStop = stops[stops.Length() - 1].mPosition;
|
|
|
|
|
// Cairo gradients must have stop positions in the range [0, 1]. So,
|
|
|
|
|
// stop positions will be normalized below by subtracting firstStop and then
|
|
|
|
|
// multiplying by stopScale.
|
|
|
|
|
double stopScale;
|
2013-07-20 12:58:10 +00:00
|
|
|
|
double stopOrigin = firstStop;
|
|
|
|
|
double stopEnd = lastStop;
|
2013-02-15 18:54:49 +00:00
|
|
|
|
double stopDelta = lastStop - firstStop;
|
|
|
|
|
bool zeroRadius = aGradient->mShape != NS_STYLE_GRADIENT_SHAPE_LINEAR &&
|
|
|
|
|
(radiusX < 1e-6 || radiusY < 1e-6);
|
|
|
|
|
if (stopDelta < 1e-6 || lineLength < 1e-6 || zeroRadius) {
|
|
|
|
|
// Stops are all at the same place. Map all stops to 0.0.
|
|
|
|
|
// For repeating radial gradients, or for any radial gradients with
|
|
|
|
|
// a zero radius, we need to fill with the last stop color, so just set
|
|
|
|
|
// both radii to 0.
|
|
|
|
|
if (aGradient->mRepeating || zeroRadius) {
|
|
|
|
|
radiusX = radiusY = 0.0;
|
2013-01-18 18:28:06 +00:00
|
|
|
|
}
|
2013-07-20 12:58:10 +00:00
|
|
|
|
stopDelta = 0.0;
|
2013-02-15 18:54:49 +00:00
|
|
|
|
lastStop = firstStop;
|
|
|
|
|
}
|
2013-01-18 18:28:06 +00:00
|
|
|
|
|
2013-07-20 12:58:10 +00:00
|
|
|
|
// Don't normalize non-repeating or degenerate gradients below 0..1
|
|
|
|
|
// This keeps the gradient line as large as the box and doesn't
|
|
|
|
|
// lets us avoiding having to get padding correct for stops
|
|
|
|
|
// at 0 and 1
|
|
|
|
|
if (!aGradient->mRepeating || stopDelta == 0.0) {
|
|
|
|
|
stopOrigin = std::min(stopOrigin, 0.0);
|
|
|
|
|
stopEnd = std::max(stopEnd, 1.0);
|
|
|
|
|
}
|
|
|
|
|
stopScale = 1.0/(stopEnd - stopOrigin);
|
|
|
|
|
|
2013-02-15 18:54:49 +00:00
|
|
|
|
// Create the gradient pattern.
|
2015-10-18 05:24:48 +00:00
|
|
|
|
RefPtr<gfxPattern> gradientPattern;
|
2014-05-28 14:14:42 +00:00
|
|
|
|
gfxPoint gradientStart;
|
|
|
|
|
gfxPoint gradientEnd;
|
2013-02-15 18:54:49 +00:00
|
|
|
|
if (aGradient->mShape == NS_STYLE_GRADIENT_SHAPE_LINEAR) {
|
|
|
|
|
// Compute the actual gradient line ends we need to pass to cairo after
|
|
|
|
|
// stops have been normalized.
|
2014-05-28 14:14:42 +00:00
|
|
|
|
gradientStart = lineStart + (lineEnd - lineStart)*stopOrigin;
|
|
|
|
|
gradientEnd = lineStart + (lineEnd - lineStart)*stopEnd;
|
2013-09-24 04:04:36 +00:00
|
|
|
|
gfxPoint gradientStopStart = lineStart + (lineEnd - lineStart)*firstStop;
|
|
|
|
|
gfxPoint gradientStopEnd = lineStart + (lineEnd - lineStart)*lastStop;
|
2009-11-02 19:36:43 +00:00
|
|
|
|
|
2013-07-20 12:58:10 +00:00
|
|
|
|
if (stopDelta == 0.0) {
|
2013-02-15 18:54:49 +00:00
|
|
|
|
// Stops are all at the same place. For repeating gradients, this will
|
|
|
|
|
// just paint the last stop color. We don't need to do anything.
|
|
|
|
|
// For non-repeating gradients, this should render as two colors, one
|
|
|
|
|
// on each "side" of the gradient line segment, which is a point. All
|
|
|
|
|
// our stops will be at 0.0; we just need to set the direction vector
|
|
|
|
|
// correctly.
|
|
|
|
|
gradientEnd = gradientStart + (lineEnd - lineStart);
|
2013-09-24 04:04:36 +00:00
|
|
|
|
gradientStopEnd = gradientStopStart + (lineEnd - lineStart);
|
2013-02-15 18:54:49 +00:00
|
|
|
|
}
|
2012-08-27 04:09:46 +00:00
|
|
|
|
|
2013-02-15 18:54:49 +00:00
|
|
|
|
gradientPattern = new gfxPattern(gradientStart.x, gradientStart.y,
|
|
|
|
|
gradientEnd.x, gradientEnd.y);
|
|
|
|
|
} else {
|
|
|
|
|
NS_ASSERTION(firstStop >= 0.0,
|
|
|
|
|
"Negative stops not allowed for radial gradients");
|
2009-11-02 19:36:43 +00:00
|
|
|
|
|
2013-02-15 18:54:49 +00:00
|
|
|
|
// To form an ellipse, we'll stretch a circle vertically, if necessary.
|
|
|
|
|
// So our radii are based on radiusX.
|
2013-07-20 12:58:10 +00:00
|
|
|
|
double innerRadius = radiusX*stopOrigin;
|
|
|
|
|
double outerRadius = radiusX*stopEnd;
|
|
|
|
|
if (stopDelta == 0.0) {
|
2013-02-15 18:54:49 +00:00
|
|
|
|
// Stops are all at the same place. See above (except we now have
|
|
|
|
|
// the inside vs. outside of an ellipse).
|
|
|
|
|
outerRadius = innerRadius + 1;
|
2009-11-02 19:36:43 +00:00
|
|
|
|
}
|
2013-02-15 18:54:49 +00:00
|
|
|
|
gradientPattern = new gfxPattern(lineStart.x, lineStart.y, innerRadius,
|
2014-01-31 03:36:41 +00:00
|
|
|
|
lineStart.x, lineStart.y, outerRadius);
|
2013-02-15 18:54:49 +00:00
|
|
|
|
if (radiusX != radiusY) {
|
|
|
|
|
// Stretch the circles into ellipses vertically by setting a transform
|
|
|
|
|
// in the pattern.
|
|
|
|
|
// Recall that this is the transform from user space to pattern space.
|
|
|
|
|
// So to stretch the ellipse by factor of P vertically, we scale
|
|
|
|
|
// user coordinates by 1/P.
|
|
|
|
|
matrix.Translate(lineStart);
|
|
|
|
|
matrix.Scale(1.0, radiusX/radiusY);
|
|
|
|
|
matrix.Translate(-lineStart);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-31 03:36:41 +00:00
|
|
|
|
// Use a pattern transform to take account of source and dest rects
|
|
|
|
|
matrix.Translate(gfxPoint(aPresContext->CSSPixelsToDevPixels(aSrc.x),
|
|
|
|
|
aPresContext->CSSPixelsToDevPixels(aSrc.y)));
|
|
|
|
|
matrix.Scale(gfxFloat(aPresContext->CSSPixelsToAppUnits(aSrc.width))/aDest.width,
|
|
|
|
|
gfxFloat(aPresContext->CSSPixelsToAppUnits(aSrc.height))/aDest.height);
|
|
|
|
|
gradientPattern->SetMatrix(matrix);
|
|
|
|
|
|
2013-02-15 18:54:49 +00:00
|
|
|
|
if (gradientPattern->CairoStatus())
|
|
|
|
|
return;
|
2009-08-01 15:53:40 +00:00
|
|
|
|
|
2013-07-20 12:58:10 +00:00
|
|
|
|
if (stopDelta == 0.0) {
|
2013-02-15 18:54:49 +00:00
|
|
|
|
// Non-repeating gradient with all stops in same place -> just add
|
|
|
|
|
// first stop and last stop, both at position 0.
|
|
|
|
|
// Repeating gradient with all stops in the same place, or radial
|
|
|
|
|
// gradient with radius of 0 -> just paint the last stop color.
|
|
|
|
|
// We use firstStop offset to keep |stops| with same units (will later normalize to 0).
|
2015-09-24 07:40:20 +00:00
|
|
|
|
Color firstColor(stops[0].mColor);
|
|
|
|
|
Color lastColor(stops.LastElement().mColor);
|
2013-02-15 18:54:49 +00:00
|
|
|
|
stops.Clear();
|
|
|
|
|
|
|
|
|
|
if (!aGradient->mRepeating && !zeroRadius) {
|
2014-10-22 12:25:00 +00:00
|
|
|
|
stops.AppendElement(ColorStop(firstStop, false, firstColor));
|
2013-02-15 18:54:49 +00:00
|
|
|
|
}
|
2014-10-22 12:25:00 +00:00
|
|
|
|
stops.AppendElement(ColorStop(firstStop, false, lastColor));
|
2013-02-15 18:54:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-22 12:25:00 +00:00
|
|
|
|
ResolveMidpoints(stops);
|
2014-10-22 06:13:56 +00:00
|
|
|
|
ResolvePremultipliedAlpha(stops);
|
|
|
|
|
|
2013-02-15 18:54:49 +00:00
|
|
|
|
bool isRepeat = aGradient->mRepeating || forceRepeatToCoverTiles;
|
|
|
|
|
|
|
|
|
|
// Now set normalized color stops in pattern.
|
2014-07-10 09:58:07 +00:00
|
|
|
|
// Offscreen gradient surface cache (not a tile):
|
|
|
|
|
// On some backends (e.g. D2D), the GradientStops object holds an offscreen surface
|
|
|
|
|
// which is a lookup table used to evaluate the gradient. This surface can use
|
|
|
|
|
// much memory (ram and/or GPU ram) and can be expensive to create. So we cache it.
|
|
|
|
|
// The cache key correlates 1:1 with the arguments for CreateGradientStops (also the implied backend type)
|
|
|
|
|
// Note that GradientStop is a simple struct with a stop value (while GradientStops has the surface).
|
|
|
|
|
nsTArray<gfx::GradientStop> rawStops(stops.Length());
|
|
|
|
|
rawStops.SetLength(stops.Length());
|
|
|
|
|
for(uint32_t i = 0; i < stops.Length(); i++) {
|
2015-09-24 07:40:20 +00:00
|
|
|
|
rawStops[i].color = stops[i].mColor;
|
2014-07-10 09:58:07 +00:00
|
|
|
|
rawStops[i].offset = stopScale * (stops[i].mPosition - stopOrigin);
|
|
|
|
|
}
|
2015-10-18 05:24:48 +00:00
|
|
|
|
RefPtr<mozilla::gfx::GradientStops> gs =
|
2014-07-10 09:58:07 +00:00
|
|
|
|
gfxGradientCache::GetOrCreateGradientStops(ctx->GetDrawTarget(),
|
|
|
|
|
rawStops,
|
|
|
|
|
isRepeat ? gfx::ExtendMode::REPEAT : gfx::ExtendMode::CLAMP);
|
|
|
|
|
gradientPattern->SetColorStops(gs);
|
2009-08-01 15:53:40 +00:00
|
|
|
|
|
2009-11-02 19:36:43 +00:00
|
|
|
|
// Paint gradient tiles. This isn't terribly efficient, but doing it this
|
|
|
|
|
// way is simple and sure to get pixel-snapping right. We could speed things
|
|
|
|
|
// up by drawing tiles into temporary surfaces and copying those to the
|
|
|
|
|
// destination, but after pixel-snapping tiles may not all be the same size.
|
|
|
|
|
nsRect dirty;
|
2010-01-11 21:45:16 +00:00
|
|
|
|
if (!dirty.IntersectRect(aDirtyRect, aFillArea))
|
|
|
|
|
return;
|
|
|
|
|
|
2010-09-07 22:20:35 +00:00
|
|
|
|
gfxRect areaToFill =
|
2014-01-31 03:36:41 +00:00
|
|
|
|
nsLayoutUtils::RectToGfxRect(aFillArea, appUnitsPerDevPixel);
|
2014-05-28 14:14:42 +00:00
|
|
|
|
gfxRect dirtyAreaToFill = nsLayoutUtils::RectToGfxRect(dirty, appUnitsPerDevPixel);
|
|
|
|
|
dirtyAreaToFill.RoundOut();
|
|
|
|
|
|
2009-11-02 19:36:43 +00:00
|
|
|
|
gfxMatrix ctm = ctx->CurrentMatrix();
|
2012-09-25 03:25:48 +00:00
|
|
|
|
bool isCTMPreservingAxisAlignedRectangles = ctm.PreservesAxisAlignedRectangles();
|
2009-11-02 19:36:43 +00:00
|
|
|
|
|
|
|
|
|
// xStart/yStart are the top-left corner of the top-left tile.
|
2016-06-02 00:09:00 +00:00
|
|
|
|
nscoord xStart = FindTileStart(dirty.x, aDest.x, aRepeatSize.width);
|
|
|
|
|
nscoord yStart = FindTileStart(dirty.y, aDest.y, aRepeatSize.height);
|
2014-01-31 03:36:41 +00:00
|
|
|
|
nscoord xEnd = forceRepeatToCoverTiles ? xStart + aDest.width : dirty.XMost();
|
|
|
|
|
nscoord yEnd = forceRepeatToCoverTiles ? yStart + aDest.height : dirty.YMost();
|
2012-07-01 23:46:32 +00:00
|
|
|
|
|
2009-11-02 19:36:43 +00:00
|
|
|
|
// x and y are the top-left corner of the tile to draw
|
2016-06-02 00:09:00 +00:00
|
|
|
|
for (nscoord y = yStart; y < yEnd; y += aRepeatSize.height) {
|
|
|
|
|
for (nscoord x = xStart; x < xEnd; x += aRepeatSize.width) {
|
2009-11-02 19:36:43 +00:00
|
|
|
|
// The coordinates of the tile
|
2010-09-07 22:20:35 +00:00
|
|
|
|
gfxRect tileRect = nsLayoutUtils::RectToGfxRect(
|
2014-01-31 03:36:41 +00:00
|
|
|
|
nsRect(x, y, aDest.width, aDest.height),
|
|
|
|
|
appUnitsPerDevPixel);
|
2009-11-02 19:36:43 +00:00
|
|
|
|
// The actual area to fill with this tile is the intersection of this
|
|
|
|
|
// tile with the overall area we're supposed to be filling
|
2012-07-01 23:46:32 +00:00
|
|
|
|
gfxRect fillRect =
|
2013-02-15 18:54:49 +00:00
|
|
|
|
forceRepeatToCoverTiles ? areaToFill : tileRect.Intersect(areaToFill);
|
2012-09-25 03:25:48 +00:00
|
|
|
|
// Try snapping the fill rect. Snap its top-left and bottom-right
|
|
|
|
|
// independently to preserve the orientation.
|
|
|
|
|
gfxPoint snappedFillRectTopLeft = fillRect.TopLeft();
|
2012-11-23 01:09:12 +00:00
|
|
|
|
gfxPoint snappedFillRectTopRight = fillRect.TopRight();
|
2012-09-25 03:25:48 +00:00
|
|
|
|
gfxPoint snappedFillRectBottomRight = fillRect.BottomRight();
|
2012-11-23 01:09:12 +00:00
|
|
|
|
// Snap three points instead of just two to ensure we choose the
|
|
|
|
|
// correct orientation if there's a reflection.
|
2012-09-25 03:25:48 +00:00
|
|
|
|
if (isCTMPreservingAxisAlignedRectangles &&
|
|
|
|
|
ctx->UserToDevicePixelSnapped(snappedFillRectTopLeft, true) &&
|
2012-11-23 01:09:12 +00:00
|
|
|
|
ctx->UserToDevicePixelSnapped(snappedFillRectBottomRight, true) &&
|
|
|
|
|
ctx->UserToDevicePixelSnapped(snappedFillRectTopRight, true)) {
|
2012-09-25 03:25:48 +00:00
|
|
|
|
if (snappedFillRectTopLeft.x == snappedFillRectBottomRight.x ||
|
|
|
|
|
snappedFillRectTopLeft.y == snappedFillRectBottomRight.y) {
|
|
|
|
|
// Nothing to draw; avoid scaling by zero and other weirdness that
|
|
|
|
|
// could put the context in an error state.
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
// Set the context's transform to the transform that maps fillRect to
|
|
|
|
|
// snappedFillRect. The part of the gradient that was going to
|
|
|
|
|
// exactly fill fillRect will fill snappedFillRect instead.
|
2012-12-06 23:58:13 +00:00
|
|
|
|
gfxMatrix transform = gfxUtils::TransformRectToRect(fillRect,
|
2012-11-23 01:09:12 +00:00
|
|
|
|
snappedFillRectTopLeft, snappedFillRectTopRight,
|
|
|
|
|
snappedFillRectBottomRight);
|
|
|
|
|
ctx->SetMatrix(transform);
|
2012-08-10 11:10:12 +00:00
|
|
|
|
}
|
2013-10-30 19:29:22 +00:00
|
|
|
|
ctx->NewPath();
|
2012-09-25 03:25:48 +00:00
|
|
|
|
ctx->Rectangle(fillRect);
|
2014-05-28 14:14:42 +00:00
|
|
|
|
|
|
|
|
|
gfxRect dirtyFillRect = fillRect.Intersect(dirtyAreaToFill);
|
|
|
|
|
gfxRect fillRectRelativeToTile = dirtyFillRect - tileRect.TopLeft();
|
2015-09-24 07:40:20 +00:00
|
|
|
|
Color edgeColor;
|
2014-05-28 14:14:42 +00:00
|
|
|
|
if (aGradient->mShape == NS_STYLE_GRADIENT_SHAPE_LINEAR && !isRepeat &&
|
|
|
|
|
RectIsBeyondLinearGradientEdge(fillRectRelativeToTile, matrix, stops,
|
|
|
|
|
gradientStart, gradientEnd, &edgeColor)) {
|
|
|
|
|
ctx->SetColor(edgeColor);
|
|
|
|
|
} else {
|
2014-09-11 06:57:38 +00:00
|
|
|
|
ctx->SetMatrix(
|
|
|
|
|
ctx->CurrentMatrix().Copy().Translate(tileRect.TopLeft()));
|
2014-05-28 14:14:42 +00:00
|
|
|
|
ctx->SetPattern(gradientPattern);
|
|
|
|
|
}
|
2009-11-02 19:36:43 +00:00
|
|
|
|
ctx->Fill();
|
|
|
|
|
ctx->SetMatrix(ctm);
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-08-01 15:53:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-10 07:27:39 +00:00
|
|
|
|
DrawResult
|
2016-05-19 07:43:20 +00:00
|
|
|
|
nsCSSRendering::PaintBackgroundWithSC(const PaintBGParams& aParams,
|
|
|
|
|
nsStyleContext *aBackgroundSC,
|
|
|
|
|
const nsStyleBorder& aBorder)
|
2002-01-07 23:46:07 +00:00
|
|
|
|
{
|
2016-05-19 07:43:20 +00:00
|
|
|
|
NS_PRECONDITION(aParams.frame,
|
2002-01-07 23:46:07 +00:00
|
|
|
|
"Frame is expected to be provided to PaintBackground");
|
2000-05-10 23:24:08 +00:00
|
|
|
|
|
2016-03-08 21:54:09 +00:00
|
|
|
|
// If we're drawing all layers, aCompositonOp is ignored, so make sure that
|
|
|
|
|
// it was left at its default value.
|
2016-05-19 07:43:20 +00:00
|
|
|
|
MOZ_ASSERT_IF(aParams.layer == -1,
|
|
|
|
|
aParams.compositionOp == CompositionOp::OP_OVER);
|
2016-03-08 21:54:09 +00:00
|
|
|
|
|
2015-02-10 07:27:39 +00:00
|
|
|
|
DrawResult result = DrawResult::SUCCESS;
|
|
|
|
|
|
2001-12-17 22:51:39 +00:00
|
|
|
|
// Check to see if we have an appearance defined. If so, we let the theme
|
2002-02-20 21:51:25 +00:00
|
|
|
|
// renderer draw the background and bail out.
|
2016-05-19 07:43:20 +00:00
|
|
|
|
// XXXzw this ignores aParams.bgClipRect.
|
|
|
|
|
const nsStyleDisplay* displayData = aParams.frame->StyleDisplay();
|
2001-12-17 22:51:39 +00:00
|
|
|
|
if (displayData->mAppearance) {
|
2016-05-19 07:43:20 +00:00
|
|
|
|
nsITheme *theme = aParams.presCtx.GetTheme();
|
|
|
|
|
if (theme && theme->ThemeSupportsWidget(&aParams.presCtx,
|
|
|
|
|
aParams.frame,
|
2009-01-09 00:28:32 +00:00
|
|
|
|
displayData->mAppearance)) {
|
2016-05-19 07:43:20 +00:00
|
|
|
|
nsRect drawing(aParams.borderArea);
|
|
|
|
|
theme->GetWidgetOverflow(aParams.presCtx.DeviceContext(),
|
|
|
|
|
aParams.frame, displayData->mAppearance,
|
|
|
|
|
&drawing);
|
|
|
|
|
drawing.IntersectRect(drawing, aParams.dirtyRect);
|
|
|
|
|
theme->DrawWidgetBackground(&aParams.renderingCtx, aParams.frame,
|
|
|
|
|
displayData->mAppearance, aParams.borderArea,
|
2010-07-14 22:25:41 +00:00
|
|
|
|
drawing);
|
2015-02-10 07:27:39 +00:00
|
|
|
|
return DrawResult::SUCCESS;
|
2001-12-17 22:51:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-04 09:30:59 +00:00
|
|
|
|
// For canvas frames (in the CSS sense) we draw the background color using
|
|
|
|
|
// a solid color item that gets added in nsLayoutUtils::PaintFrame,
|
2010-07-15 21:07:53 +00:00
|
|
|
|
// or nsSubDocumentFrame::BuildDisplayList (bug 488242). (The solid
|
|
|
|
|
// color may be moved into nsDisplayCanvasBackground by
|
|
|
|
|
// nsPresShell::AddCanvasBackgroundColorItem, and painted by
|
|
|
|
|
// nsDisplayCanvasBackground directly.) Either way we don't need to
|
|
|
|
|
// paint the background color here.
|
2016-05-19 07:43:20 +00:00
|
|
|
|
bool isCanvasFrame = IsCanvasFrame(aParams.frame);
|
2009-07-04 09:30:59 +00:00
|
|
|
|
|
2009-01-09 00:28:32 +00:00
|
|
|
|
// Determine whether we are drawing background images and/or
|
|
|
|
|
// background colors.
|
2011-09-29 06:19:26 +00:00
|
|
|
|
bool drawBackgroundImage;
|
|
|
|
|
bool drawBackgroundColor;
|
2009-01-09 00:28:32 +00:00
|
|
|
|
|
2016-05-19 07:43:20 +00:00
|
|
|
|
nscolor bgColor = DetermineBackgroundColor(&aParams.presCtx,
|
2012-05-03 20:11:57 +00:00
|
|
|
|
aBackgroundSC,
|
2016-05-19 07:43:20 +00:00
|
|
|
|
aParams.frame,
|
2012-05-03 20:11:57 +00:00
|
|
|
|
drawBackgroundImage,
|
|
|
|
|
drawBackgroundColor);
|
2009-01-08 08:10:21 +00:00
|
|
|
|
|
2016-05-19 07:43:20 +00:00
|
|
|
|
bool paintMask = (aParams.paintFlags & PAINTBG_MASK_IMAGE);
|
2016-01-28 05:29:00 +00:00
|
|
|
|
const nsStyleImageLayers& layers = paintMask ?
|
2016-01-28 05:39:00 +00:00
|
|
|
|
aBackgroundSC->StyleSVGReset()->mMask :
|
|
|
|
|
aBackgroundSC->StyleBackground()->mImage;
|
2012-10-25 05:32:25 +00:00
|
|
|
|
// If we're drawing a specific layer, we don't want to draw the
|
2012-09-13 10:34:23 +00:00
|
|
|
|
// background color.
|
2016-05-19 07:43:20 +00:00
|
|
|
|
if ((drawBackgroundColor && aParams.layer >= 0) || paintMask) {
|
2012-09-13 10:34:23 +00:00
|
|
|
|
drawBackgroundColor = false;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-09 00:28:32 +00:00
|
|
|
|
// At this point, drawBackgroundImage and drawBackgroundColor are
|
|
|
|
|
// true if and only if we are actually supposed to paint an image or
|
|
|
|
|
// color into aDirtyRect, respectively.
|
|
|
|
|
if (!drawBackgroundImage && !drawBackgroundColor)
|
2015-02-10 07:27:39 +00:00
|
|
|
|
return DrawResult::SUCCESS;
|
2009-01-09 00:28:32 +00:00
|
|
|
|
|
|
|
|
|
// Compute the outermost boundary of the area that might be painted.
|
2016-05-19 07:43:20 +00:00
|
|
|
|
// Same coordinate space as aParams.borderArea & aParams.bgClipRect.
|
|
|
|
|
Sides skipSides = aParams.frame->GetSkipSides();
|
2014-05-05 17:55:54 +00:00
|
|
|
|
nsRect paintBorderArea =
|
2016-05-19 07:43:20 +00:00
|
|
|
|
::BoxDecorationRectForBackground(aParams.frame, aParams.borderArea,
|
|
|
|
|
skipSides, &aBorder);
|
2014-05-05 17:55:54 +00:00
|
|
|
|
nsRect clipBorderArea =
|
2016-05-19 07:43:20 +00:00
|
|
|
|
::BoxDecorationRectForBorder(aParams.frame, aParams.borderArea,
|
|
|
|
|
skipSides, &aBorder);
|
2010-04-27 16:15:01 +00:00
|
|
|
|
|
2009-01-09 00:28:32 +00:00
|
|
|
|
// The 'bgClipArea' (used only by the image tiling logic, far below)
|
2016-05-19 07:43:20 +00:00
|
|
|
|
// is the caller-provided aParams.bgClipRect if any, or else the area
|
2009-02-20 05:29:21 +00:00
|
|
|
|
// determined by the value of 'background-clip' in
|
|
|
|
|
// SetupCurrentBackgroundClip. (Arguably it should be the
|
|
|
|
|
// intersection, but that breaks the table painter -- in particular,
|
2009-05-28 18:09:05 +00:00
|
|
|
|
// taking the intersection breaks reftests/bugs/403249-1[ab].)
|
2016-05-19 07:43:20 +00:00
|
|
|
|
gfxContext* ctx = aParams.renderingCtx.ThebesContext();
|
|
|
|
|
nscoord appUnitsPerPixel = aParams.presCtx.AppUnitsPerDevPixel();
|
2016-01-28 05:27:00 +00:00
|
|
|
|
ImageLayerClipState clipState;
|
2016-05-19 07:43:20 +00:00
|
|
|
|
if (aParams.bgClipRect) {
|
|
|
|
|
clipState.mBGClipArea = *aParams.bgClipRect;
|
2011-10-17 14:59:28 +00:00
|
|
|
|
clipState.mCustomClip = true;
|
2014-08-13 09:26:33 +00:00
|
|
|
|
clipState.mHasRoundedCorners = false;
|
2016-05-19 07:43:20 +00:00
|
|
|
|
SetupDirtyRects(clipState.mBGClipArea, aParams.dirtyRect, appUnitsPerPixel,
|
2011-01-18 19:43:47 +00:00
|
|
|
|
&clipState.mDirtyRect, &clipState.mDirtyRectGfx);
|
2009-02-20 05:29:21 +00:00
|
|
|
|
} else {
|
2016-01-28 05:27:00 +00:00
|
|
|
|
GetImageLayerClip(layers.BottomLayer(),
|
2016-05-19 07:43:20 +00:00
|
|
|
|
aParams.frame, aBorder, aParams.borderArea,
|
|
|
|
|
aParams.dirtyRect,
|
|
|
|
|
(aParams.paintFlags & PAINTBG_WILL_PAINT_BORDER),
|
2016-01-28 05:27:00 +00:00
|
|
|
|
appUnitsPerPixel,
|
2011-01-18 19:43:47 +00:00
|
|
|
|
&clipState);
|
2009-01-09 00:28:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If we might be using a background color, go ahead and set it now.
|
2009-07-04 09:30:59 +00:00
|
|
|
|
if (drawBackgroundColor && !isCanvasFrame)
|
2015-09-24 06:41:30 +00:00
|
|
|
|
ctx->SetColor(Color::FromABGR(bgColor));
|
2009-01-09 00:28:32 +00:00
|
|
|
|
|
2014-05-05 17:55:54 +00:00
|
|
|
|
// NOTE: no Save() yet, we do that later by calling autoSR.EnsureSaved(ctx)
|
|
|
|
|
// in the cases we need it.
|
2011-01-18 19:43:47 +00:00
|
|
|
|
gfxContextAutoSaveRestore autoSR;
|
|
|
|
|
|
2009-01-09 00:28:32 +00:00
|
|
|
|
// If there is no background image, draw a color. (If there is
|
|
|
|
|
// neither a background image nor a color, we wouldn't have gotten
|
|
|
|
|
// this far.)
|
|
|
|
|
if (!drawBackgroundImage) {
|
2011-01-18 19:43:47 +00:00
|
|
|
|
if (!isCanvasFrame) {
|
2014-07-23 05:20:39 +00:00
|
|
|
|
DrawBackgroundColor(clipState, ctx, appUnitsPerPixel);
|
2009-02-20 05:29:21 +00:00
|
|
|
|
}
|
2015-02-10 07:27:39 +00:00
|
|
|
|
return DrawResult::SUCCESS;
|
2009-01-09 00:28:32 +00:00
|
|
|
|
}
|
2009-01-08 10:19:21 +00:00
|
|
|
|
|
2016-01-28 05:24:00 +00:00
|
|
|
|
if (layers.mImageCount < 1) {
|
2012-09-13 10:34:23 +00:00
|
|
|
|
// Return if there are no background layers, all work from this point
|
|
|
|
|
// onwards happens iteratively on these.
|
2015-02-10 07:27:39 +00:00
|
|
|
|
return DrawResult::SUCCESS;
|
2012-09-13 10:34:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Validate the layer range before we start iterating.
|
2016-05-19 07:43:20 +00:00
|
|
|
|
int32_t startLayer = aParams.layer;
|
2012-09-13 10:34:23 +00:00
|
|
|
|
int32_t nLayers = 1;
|
|
|
|
|
if (startLayer < 0) {
|
2016-01-28 05:24:00 +00:00
|
|
|
|
startLayer = (int32_t)layers.mImageCount - 1;
|
|
|
|
|
nLayers = layers.mImageCount;
|
2012-09-13 10:34:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-04-07 17:36:49 +00:00
|
|
|
|
// Ensure we get invalidated for loads of the image. We need to do
|
|
|
|
|
// this here because this might be the only code that knows about the
|
2009-02-19 19:03:28 +00:00
|
|
|
|
// association of the style data with the frame.
|
2016-05-19 07:43:20 +00:00
|
|
|
|
if (aBackgroundSC != aParams.frame->StyleContext()) {
|
2016-01-28 05:24:00 +00:00
|
|
|
|
NS_FOR_VISIBLE_IMAGE_LAYERS_BACK_TO_FRONT_WITH_RANGE(i, layers, startLayer, nLayers) {
|
2016-05-19 07:43:20 +00:00
|
|
|
|
aParams.frame->AssociateImage(layers.mLayers[i].mImage,
|
|
|
|
|
&aParams.presCtx);
|
2012-08-13 22:04:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2009-02-19 19:03:28 +00:00
|
|
|
|
|
2009-02-20 05:29:21 +00:00
|
|
|
|
// The background color is rendered over the entire dirty area,
|
|
|
|
|
// even if the image isn't.
|
2009-07-04 09:30:59 +00:00
|
|
|
|
if (drawBackgroundColor && !isCanvasFrame) {
|
2014-07-23 05:20:39 +00:00
|
|
|
|
DrawBackgroundColor(clipState, ctx, appUnitsPerPixel);
|
2009-02-20 05:29:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (drawBackgroundImage) {
|
2011-01-18 19:43:47 +00:00
|
|
|
|
bool clipSet = false;
|
2016-01-28 05:27:00 +00:00
|
|
|
|
uint8_t currentBackgroundClip = NS_STYLE_IMAGELAYER_CLIP_BORDER;
|
2016-01-28 05:24:00 +00:00
|
|
|
|
NS_FOR_VISIBLE_IMAGE_LAYERS_BACK_TO_FRONT_WITH_RANGE(i, layers, layers.mImageCount - 1,
|
2016-01-28 05:27:00 +00:00
|
|
|
|
nLayers + (layers.mImageCount -
|
|
|
|
|
startLayer - 1)) {
|
2016-01-28 05:24:00 +00:00
|
|
|
|
const nsStyleImageLayers::Layer& layer = layers.mLayers[i];
|
2016-05-19 07:43:20 +00:00
|
|
|
|
if (!aParams.bgClipRect) {
|
2014-07-23 05:20:39 +00:00
|
|
|
|
if (currentBackgroundClip != layer.mClip || !clipSet) {
|
|
|
|
|
currentBackgroundClip = layer.mClip;
|
2011-01-18 19:43:47 +00:00
|
|
|
|
// If clipSet is false that means this is the bottom layer and we
|
2016-01-28 05:27:00 +00:00
|
|
|
|
// already called GetImageLayerClip above and it stored its results
|
2011-01-18 19:43:47 +00:00
|
|
|
|
// in clipState.
|
|
|
|
|
if (clipSet) {
|
2014-05-05 17:55:55 +00:00
|
|
|
|
autoSR.Restore(); // reset the previous one
|
2016-05-19 07:43:20 +00:00
|
|
|
|
GetImageLayerClip(layer, aParams.frame,
|
|
|
|
|
aBorder, aParams.borderArea, aParams.dirtyRect,
|
|
|
|
|
(aParams.paintFlags & PAINTBG_WILL_PAINT_BORDER),
|
2014-07-23 05:20:39 +00:00
|
|
|
|
appUnitsPerPixel, &clipState);
|
2011-01-18 19:43:47 +00:00
|
|
|
|
}
|
2016-01-28 05:27:00 +00:00
|
|
|
|
SetupImageLayerClip(clipState, ctx, appUnitsPerPixel, &autoSR);
|
2011-01-18 19:43:47 +00:00
|
|
|
|
clipSet = true;
|
2016-05-19 07:43:20 +00:00
|
|
|
|
if (!clipBorderArea.IsEqualEdges(aParams.borderArea)) {
|
2014-05-05 17:55:54 +00:00
|
|
|
|
// We're drawing the background for the joined continuation boxes
|
|
|
|
|
// so we need to clip that to the slice that we want for this frame.
|
|
|
|
|
gfxRect clip =
|
2016-05-19 07:43:20 +00:00
|
|
|
|
nsLayoutUtils::RectToGfxRect(aParams.borderArea, appUnitsPerPixel);
|
2014-05-05 17:55:54 +00:00
|
|
|
|
autoSR.EnsureSaved(ctx);
|
|
|
|
|
ctx->NewPath();
|
|
|
|
|
ctx->SnappedRectangle(clip);
|
|
|
|
|
ctx->Clip();
|
|
|
|
|
}
|
2009-02-20 05:29:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-05-19 07:43:20 +00:00
|
|
|
|
if ((aParams.layer < 0 || i == (uint32_t)startLayer) &&
|
2012-11-02 08:35:32 +00:00
|
|
|
|
!clipState.mDirtyRectGfx.IsEmpty()) {
|
2016-03-08 21:54:09 +00:00
|
|
|
|
// When we're drawing a single layer, use the specified composition op,
|
|
|
|
|
// otherwise get the compositon op from the image layer.
|
2016-05-19 07:43:20 +00:00
|
|
|
|
CompositionOp co = (aParams.layer >= 0) ? aParams.compositionOp :
|
2016-03-08 21:54:09 +00:00
|
|
|
|
(paintMask ? GetGFXCompositeMode(layer.mComposite) :
|
|
|
|
|
GetGFXBlendMode(layer.mBlendMode));
|
2016-01-28 05:29:00 +00:00
|
|
|
|
nsBackgroundLayerState state =
|
2016-05-19 07:43:20 +00:00
|
|
|
|
PrepareImageLayer(&aParams.presCtx, aParams.frame,
|
|
|
|
|
aParams.paintFlags, paintBorderArea, clipState.mBGClipArea,
|
2016-04-25 21:20:13 +00:00
|
|
|
|
layer, nullptr, co);
|
2015-10-14 07:02:37 +00:00
|
|
|
|
result &= state.mImageRenderer.PrepareResult();
|
2011-01-03 01:48:09 +00:00
|
|
|
|
if (!state.mFillArea.IsEmpty()) {
|
2016-01-28 05:29:00 +00:00
|
|
|
|
// Always using OP_OVER mode while drawing the bottom mask layer.
|
|
|
|
|
bool isBottomMaskLayer = paintMask ?
|
|
|
|
|
(i == (layers.mImageCount - 1)) : false;
|
2016-03-08 21:54:09 +00:00
|
|
|
|
if (co != CompositionOp::OP_OVER && !isBottomMaskLayer) {
|
2015-09-25 05:38:58 +00:00
|
|
|
|
NS_ASSERTION(ctx->CurrentOp() == CompositionOp::OP_OVER,
|
|
|
|
|
"It is assumed the initial op is OP_OVER, when it is restored later");
|
2016-03-08 21:54:09 +00:00
|
|
|
|
ctx->SetOp(co);
|
2013-11-08 15:08:03 +00:00
|
|
|
|
}
|
2015-02-10 07:27:39 +00:00
|
|
|
|
|
2015-10-14 06:21:39 +00:00
|
|
|
|
result &=
|
2016-05-19 07:43:20 +00:00
|
|
|
|
state.mImageRenderer.DrawBackground(&aParams.presCtx,
|
|
|
|
|
aParams.renderingCtx,
|
2015-02-10 07:27:39 +00:00
|
|
|
|
state.mDestArea, state.mFillArea,
|
|
|
|
|
state.mAnchor + paintBorderArea.TopLeft(),
|
2016-05-25 00:29:00 +00:00
|
|
|
|
clipState.mDirtyRect,
|
|
|
|
|
state.mRepeatSize);
|
2015-02-10 07:27:39 +00:00
|
|
|
|
|
2016-03-08 21:54:09 +00:00
|
|
|
|
if (co != CompositionOp::OP_OVER) {
|
2015-09-25 05:38:58 +00:00
|
|
|
|
ctx->SetOp(CompositionOp::OP_OVER);
|
2013-11-08 15:08:03 +00:00
|
|
|
|
}
|
2011-01-03 01:48:09 +00:00
|
|
|
|
}
|
2009-02-20 05:29:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-02-10 07:27:39 +00:00
|
|
|
|
|
|
|
|
|
return result;
|
2009-02-20 05:29:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-11-08 15:05:32 +00:00
|
|
|
|
nsRect
|
2016-01-28 05:27:00 +00:00
|
|
|
|
nsCSSRendering::ComputeImageLayerPositioningArea(nsPresContext* aPresContext,
|
2012-11-08 15:05:32 +00:00
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
|
const nsRect& aBorderArea,
|
2016-01-28 05:24:00 +00:00
|
|
|
|
const nsStyleImageLayers::Layer& aLayer,
|
2016-04-25 21:20:13 +00:00
|
|
|
|
nsIFrame** aAttachedToFrame,
|
|
|
|
|
bool* aOutIsTransformedFixed)
|
2012-11-08 15:05:32 +00:00
|
|
|
|
{
|
|
|
|
|
// Compute background origin area relative to aBorderArea now as we may need
|
|
|
|
|
// it to compute the effective image size for a CSS gradient.
|
2014-05-05 17:55:54 +00:00
|
|
|
|
nsRect bgPositioningArea;
|
2012-11-08 15:05:32 +00:00
|
|
|
|
|
|
|
|
|
nsIAtom* frameType = aForFrame->GetType();
|
|
|
|
|
nsIFrame* geometryFrame = aForFrame;
|
2014-05-05 17:55:54 +00:00
|
|
|
|
if (MOZ_UNLIKELY(frameType == nsGkAtoms::scrollFrame &&
|
2016-01-28 05:27:00 +00:00
|
|
|
|
NS_STYLE_IMAGELAYER_ATTACHMENT_LOCAL == aLayer.mAttachment)) {
|
2013-07-23 13:22:58 +00:00
|
|
|
|
nsIScrollableFrame* scrollableFrame = do_QueryFrame(aForFrame);
|
|
|
|
|
bgPositioningArea = nsRect(
|
|
|
|
|
scrollableFrame->GetScrolledFrame()->GetPosition()
|
|
|
|
|
// For the dir=rtl case:
|
|
|
|
|
+ scrollableFrame->GetScrollRange().TopLeft(),
|
|
|
|
|
scrollableFrame->GetScrolledRect().Size());
|
|
|
|
|
// The ScrolledRect’s size does not include the borders or scrollbars,
|
|
|
|
|
// reverse the handling of background-origin
|
|
|
|
|
// compared to the common case below.
|
2016-01-28 05:27:00 +00:00
|
|
|
|
if (aLayer.mOrigin == NS_STYLE_IMAGELAYER_ORIGIN_BORDER) {
|
2013-07-23 13:22:58 +00:00
|
|
|
|
nsMargin border = geometryFrame->GetUsedBorder();
|
2014-06-24 17:52:19 +00:00
|
|
|
|
border.ApplySkipSides(geometryFrame->GetSkipSides());
|
2013-07-23 13:22:58 +00:00
|
|
|
|
bgPositioningArea.Inflate(border);
|
|
|
|
|
bgPositioningArea.Inflate(scrollableFrame->GetActualScrollbarSizes());
|
2016-01-28 05:27:00 +00:00
|
|
|
|
} else if (aLayer.mOrigin != NS_STYLE_IMAGELAYER_ORIGIN_PADDING) {
|
2013-07-23 13:22:58 +00:00
|
|
|
|
nsMargin padding = geometryFrame->GetUsedPadding();
|
2014-06-24 17:52:19 +00:00
|
|
|
|
padding.ApplySkipSides(geometryFrame->GetSkipSides());
|
2013-07-23 13:22:58 +00:00
|
|
|
|
bgPositioningArea.Deflate(padding);
|
2016-01-28 05:27:00 +00:00
|
|
|
|
NS_ASSERTION(aLayer.mOrigin == NS_STYLE_IMAGELAYER_ORIGIN_CONTENT,
|
2013-07-23 13:22:58 +00:00
|
|
|
|
"unknown background-origin value");
|
|
|
|
|
}
|
|
|
|
|
*aAttachedToFrame = aForFrame;
|
|
|
|
|
return bgPositioningArea;
|
2014-05-05 17:55:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (MOZ_UNLIKELY(frameType == nsGkAtoms::canvasFrame)) {
|
2016-01-29 14:42:14 +00:00
|
|
|
|
geometryFrame = aForFrame->PrincipalChildList().FirstChild();
|
2014-05-05 17:55:54 +00:00
|
|
|
|
// geometryFrame might be null if this canvas is a page created
|
|
|
|
|
// as an overflow container (e.g. the in-flow content has already
|
|
|
|
|
// finished and this page only displays the continuations of
|
|
|
|
|
// absolutely positioned content).
|
|
|
|
|
if (geometryFrame) {
|
|
|
|
|
bgPositioningArea = geometryFrame->GetRect();
|
|
|
|
|
}
|
2012-11-08 15:05:32 +00:00
|
|
|
|
} else {
|
|
|
|
|
bgPositioningArea = nsRect(nsPoint(0,0), aBorderArea.Size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Background images are tiled over the 'background-clip' area
|
|
|
|
|
// but the origin of the tiling is based on the 'background-origin' area
|
2016-01-28 05:27:00 +00:00
|
|
|
|
if (aLayer.mOrigin != NS_STYLE_IMAGELAYER_ORIGIN_BORDER && geometryFrame) {
|
2012-11-08 15:05:32 +00:00
|
|
|
|
nsMargin border = geometryFrame->GetUsedBorder();
|
2016-01-28 05:27:00 +00:00
|
|
|
|
if (aLayer.mOrigin != NS_STYLE_IMAGELAYER_ORIGIN_PADDING) {
|
2012-11-08 15:05:32 +00:00
|
|
|
|
border += geometryFrame->GetUsedPadding();
|
2016-01-28 05:27:00 +00:00
|
|
|
|
NS_ASSERTION(aLayer.mOrigin == NS_STYLE_IMAGELAYER_ORIGIN_CONTENT,
|
2012-11-08 15:05:32 +00:00
|
|
|
|
"unknown background-origin value");
|
|
|
|
|
}
|
|
|
|
|
bgPositioningArea.Deflate(border);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsIFrame* attachedToFrame = aForFrame;
|
2016-01-28 05:27:00 +00:00
|
|
|
|
if (NS_STYLE_IMAGELAYER_ATTACHMENT_FIXED == aLayer.mAttachment) {
|
2012-11-08 15:05:32 +00:00
|
|
|
|
// If it's a fixed background attachment, then the image is placed
|
|
|
|
|
// relative to the viewport, which is the area of the root frame
|
|
|
|
|
// in a screen context or the page content frame in a print context.
|
|
|
|
|
attachedToFrame = aPresContext->PresShell()->FrameManager()->GetRootFrame();
|
|
|
|
|
NS_ASSERTION(attachedToFrame, "no root frame");
|
|
|
|
|
nsIFrame* pageContentFrame = nullptr;
|
|
|
|
|
if (aPresContext->IsPaginated()) {
|
|
|
|
|
pageContentFrame =
|
|
|
|
|
nsLayoutUtils::GetClosestFrameOfType(aForFrame, nsGkAtoms::pageContentFrame);
|
|
|
|
|
if (pageContentFrame) {
|
|
|
|
|
attachedToFrame = pageContentFrame;
|
|
|
|
|
}
|
|
|
|
|
// else this is an embedded shell and its root frame is what we want
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-25 21:20:13 +00:00
|
|
|
|
// If the background is affected by a transform, treat is as if it
|
|
|
|
|
// wasn't fixed.
|
|
|
|
|
if (nsLayoutUtils::IsTransformed(aForFrame, attachedToFrame)) {
|
|
|
|
|
attachedToFrame = aForFrame;
|
|
|
|
|
*aOutIsTransformedFixed = true;
|
|
|
|
|
} else {
|
|
|
|
|
// Set the background positioning area to the viewport's area
|
|
|
|
|
// (relative to aForFrame)
|
|
|
|
|
bgPositioningArea =
|
|
|
|
|
nsRect(-aForFrame->GetOffsetTo(attachedToFrame), attachedToFrame->GetSize());
|
|
|
|
|
|
|
|
|
|
if (!pageContentFrame) {
|
|
|
|
|
// Subtract the size of scrollbars.
|
|
|
|
|
nsIScrollableFrame* scrollableFrame =
|
|
|
|
|
aPresContext->PresShell()->GetRootScrollFrameAsScrollable();
|
|
|
|
|
if (scrollableFrame) {
|
|
|
|
|
nsMargin scrollbars = scrollableFrame->GetActualScrollbarSizes();
|
|
|
|
|
bgPositioningArea.Deflate(scrollbars);
|
|
|
|
|
}
|
2012-11-08 15:05:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*aAttachedToFrame = attachedToFrame;
|
|
|
|
|
|
|
|
|
|
return bgPositioningArea;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-25 00:29:00 +00:00
|
|
|
|
// Implementation of the formula for computation of background-repeat round
|
|
|
|
|
// See http://dev.w3.org/csswg/css3-background/#the-background-size
|
|
|
|
|
// This function returns the adjusted size of the background image.
|
|
|
|
|
static nscoord
|
|
|
|
|
ComputeRoundedSize(nscoord aCurrentSize, nscoord aPositioningSize)
|
|
|
|
|
{
|
|
|
|
|
float repeatCount = NS_roundf(float(aPositioningSize) / float(aCurrentSize));
|
|
|
|
|
if (repeatCount < 1.0f) {
|
|
|
|
|
return aPositioningSize;
|
|
|
|
|
}
|
|
|
|
|
return nscoord(NS_lround(float(aPositioningSize) / repeatCount));
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-19 08:39:58 +00:00
|
|
|
|
// Apply the CSS image sizing algorithm as it applies to background images.
|
|
|
|
|
// See http://www.w3.org/TR/css3-background/#the-background-size .
|
|
|
|
|
// aIntrinsicSize is the size that the background image 'would like to be'.
|
|
|
|
|
// It can be found by calling nsImageRenderer::ComputeIntrinsicSize.
|
|
|
|
|
static nsSize
|
|
|
|
|
ComputeDrawnSizeForBackground(const CSSSizeOrRatio& aIntrinsicSize,
|
|
|
|
|
const nsSize& aBgPositioningArea,
|
2016-05-25 00:29:00 +00:00
|
|
|
|
const nsStyleImageLayers::Size& aLayerSize,
|
|
|
|
|
uint8_t aXRepeat, uint8_t aYRepeat)
|
2013-07-19 08:39:58 +00:00
|
|
|
|
{
|
2016-05-25 00:29:00 +00:00
|
|
|
|
nsSize imageSize;
|
|
|
|
|
|
2013-07-19 08:39:58 +00:00
|
|
|
|
// Size is dictated by cover or contain rules.
|
2016-01-28 05:24:00 +00:00
|
|
|
|
if (aLayerSize.mWidthType == nsStyleImageLayers::Size::eContain ||
|
|
|
|
|
aLayerSize.mWidthType == nsStyleImageLayers::Size::eCover) {
|
2013-07-19 08:39:58 +00:00
|
|
|
|
nsImageRenderer::FitType fitType =
|
2016-01-28 05:24:00 +00:00
|
|
|
|
aLayerSize.mWidthType == nsStyleImageLayers::Size::eCover
|
2013-07-19 08:39:58 +00:00
|
|
|
|
? nsImageRenderer::COVER
|
|
|
|
|
: nsImageRenderer::CONTAIN;
|
2016-05-25 00:29:00 +00:00
|
|
|
|
imageSize = nsImageRenderer::ComputeConstrainedSize(aBgPositioningArea,
|
|
|
|
|
aIntrinsicSize.mRatio,
|
|
|
|
|
fitType);
|
|
|
|
|
} else {
|
|
|
|
|
// No cover/contain constraint, use default algorithm.
|
|
|
|
|
CSSSizeOrRatio specifiedSize;
|
|
|
|
|
if (aLayerSize.mWidthType == nsStyleImageLayers::Size::eLengthPercentage) {
|
|
|
|
|
specifiedSize.SetWidth(
|
|
|
|
|
aLayerSize.ResolveWidthLengthPercentage(aBgPositioningArea));
|
|
|
|
|
}
|
|
|
|
|
if (aLayerSize.mHeightType == nsStyleImageLayers::Size::eLengthPercentage) {
|
|
|
|
|
specifiedSize.SetHeight(
|
|
|
|
|
aLayerSize.ResolveHeightLengthPercentage(aBgPositioningArea));
|
|
|
|
|
}
|
2013-07-19 08:39:58 +00:00
|
|
|
|
|
2016-05-25 00:29:00 +00:00
|
|
|
|
imageSize = nsImageRenderer::ComputeConcreteSize(specifiedSize,
|
|
|
|
|
aIntrinsicSize,
|
|
|
|
|
aBgPositioningArea);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// See https://www.w3.org/TR/css3-background/#background-size .
|
|
|
|
|
// "If 'background-repeat' is 'round' for one (or both) dimensions, there is a second
|
|
|
|
|
// step. The UA must scale the image in that dimension (or both dimensions) so that
|
|
|
|
|
// it fits a whole number of times in the background positioning area."
|
|
|
|
|
// "If 'background-repeat' is 'round' for one dimension only and if 'background-size'
|
|
|
|
|
// is 'auto' for the other dimension, then there is a third step: that other dimension
|
|
|
|
|
// is scaled so that the original aspect ratio is restored."
|
|
|
|
|
bool isRepeatRoundInBothDimensions = aXRepeat == NS_STYLE_IMAGELAYER_REPEAT_ROUND &&
|
|
|
|
|
aYRepeat == NS_STYLE_IMAGELAYER_REPEAT_ROUND;
|
|
|
|
|
|
|
|
|
|
// Calculate the rounded size only if the background-size computation
|
|
|
|
|
// returned a correct size for the image.
|
|
|
|
|
if (imageSize.width && aXRepeat == NS_STYLE_IMAGELAYER_REPEAT_ROUND) {
|
|
|
|
|
imageSize.width = ComputeRoundedSize(imageSize.width, aBgPositioningArea.width);
|
|
|
|
|
if (!isRepeatRoundInBothDimensions &&
|
|
|
|
|
aLayerSize.mHeightType == nsStyleImageLayers::Size::DimensionType::eAuto) {
|
|
|
|
|
// Restore intrinsic rato
|
|
|
|
|
if (aIntrinsicSize.mRatio.width) {
|
|
|
|
|
float scale = float(aIntrinsicSize.mRatio.height) / aIntrinsicSize.mRatio.width;
|
|
|
|
|
imageSize.height = NSCoordSaturatingNonnegativeMultiply(imageSize.width, scale);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-07-19 08:39:58 +00:00
|
|
|
|
}
|
2016-05-25 00:29:00 +00:00
|
|
|
|
|
|
|
|
|
// Calculate the rounded size only if the background-size computation
|
|
|
|
|
// returned a correct size for the image.
|
|
|
|
|
if (imageSize.height && aYRepeat == NS_STYLE_IMAGELAYER_REPEAT_ROUND) {
|
|
|
|
|
imageSize.height = ComputeRoundedSize(imageSize.height, aBgPositioningArea.height);
|
|
|
|
|
if (!isRepeatRoundInBothDimensions &&
|
|
|
|
|
aLayerSize.mWidthType == nsStyleImageLayers::Size::DimensionType::eAuto) {
|
|
|
|
|
// Restore intrinsic rato
|
|
|
|
|
if (aIntrinsicSize.mRatio.height) {
|
|
|
|
|
float scale = float(aIntrinsicSize.mRatio.width) / aIntrinsicSize.mRatio.height;
|
|
|
|
|
imageSize.width = NSCoordSaturatingNonnegativeMultiply(imageSize.height, scale);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-07-19 08:39:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-25 00:29:00 +00:00
|
|
|
|
return imageSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ComputeSpacedRepeatSize
|
|
|
|
|
* aImageDimension: the image width/height
|
|
|
|
|
* aAvailableSpace: the background positioning area width/height
|
2016-05-28 04:23:00 +00:00
|
|
|
|
* aRepeat: determine whether the image is repeated
|
2016-07-15 01:37:00 +00:00
|
|
|
|
* Returns the image size plus gap size of app units for use as spacing
|
2016-05-25 00:29:00 +00:00
|
|
|
|
*/
|
|
|
|
|
static nscoord
|
|
|
|
|
ComputeSpacedRepeatSize(nscoord aImageDimension,
|
2016-05-28 04:23:00 +00:00
|
|
|
|
nscoord aAvailableSpace,
|
|
|
|
|
bool& aRepeat) {
|
2016-06-06 14:14:37 +00:00
|
|
|
|
float ratio = static_cast<float>(aAvailableSpace) / aImageDimension;
|
2016-05-25 00:29:00 +00:00
|
|
|
|
|
|
|
|
|
if (ratio < 2.0f) { // If you can't repeat at least twice, then don't repeat.
|
2016-05-28 04:23:00 +00:00
|
|
|
|
aRepeat = false;
|
2016-05-25 00:29:00 +00:00
|
|
|
|
return aImageDimension;
|
|
|
|
|
} else {
|
2016-05-28 04:23:00 +00:00
|
|
|
|
aRepeat = true;
|
2016-05-25 00:29:00 +00:00
|
|
|
|
return (aAvailableSpace - aImageDimension) / (NSToIntFloor(ratio) - 1);
|
|
|
|
|
}
|
2013-07-19 08:39:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-15 01:37:00 +00:00
|
|
|
|
/* ComputeBorderSpacedRepeatSize
|
|
|
|
|
* aImageDimension: the image width/height
|
|
|
|
|
* aAvailableSpace: the background positioning area width/height
|
|
|
|
|
* aSpace: the space between each image
|
|
|
|
|
* Returns the image size plus gap size of app units for use as spacing
|
|
|
|
|
*/
|
|
|
|
|
static nscoord
|
|
|
|
|
ComputeBorderSpacedRepeatSize(nscoord aImageDimension,
|
|
|
|
|
nscoord aAvailableSpace,
|
|
|
|
|
nscoord& aSpace)
|
|
|
|
|
{
|
|
|
|
|
int32_t count = aAvailableSpace / aImageDimension;
|
|
|
|
|
aSpace = (aAvailableSpace - aImageDimension * count) / (count + 1);
|
|
|
|
|
return aSpace + aImageDimension;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-03 20:11:57 +00:00
|
|
|
|
nsBackgroundLayerState
|
2016-01-28 05:27:00 +00:00
|
|
|
|
nsCSSRendering::PrepareImageLayer(nsPresContext* aPresContext,
|
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
|
uint32_t aFlags,
|
|
|
|
|
const nsRect& aBorderArea,
|
|
|
|
|
const nsRect& aBGClipRect,
|
2016-01-28 05:29:00 +00:00
|
|
|
|
const nsStyleImageLayers::Layer& aLayer,
|
2016-04-25 21:20:13 +00:00
|
|
|
|
bool* aOutIsTransformedFixed,
|
2016-03-08 21:54:09 +00:00
|
|
|
|
CompositionOp aCompositonOp)
|
2009-02-20 05:29:21 +00:00
|
|
|
|
{
|
2009-05-28 18:09:05 +00:00
|
|
|
|
/*
|
2016-01-28 05:27:00 +00:00
|
|
|
|
* The properties we need to keep in mind when drawing style image
|
2009-05-28 18:09:05 +00:00
|
|
|
|
* layers are:
|
|
|
|
|
*
|
2016-01-28 05:27:00 +00:00
|
|
|
|
* background-image/ mask-image
|
|
|
|
|
* background-repeat/ mask-repeat
|
2009-05-28 18:09:05 +00:00
|
|
|
|
* background-attachment
|
2016-01-28 05:27:00 +00:00
|
|
|
|
* background-position/ mask-position
|
|
|
|
|
* background-clip/ mask-clip
|
|
|
|
|
* background-origin/ mask-origin
|
|
|
|
|
* background-size/ mask-size
|
2013-11-08 15:08:03 +00:00
|
|
|
|
* background-blend-mode
|
2014-05-05 17:55:54 +00:00
|
|
|
|
* box-decoration-break
|
2016-01-28 05:27:00 +00:00
|
|
|
|
* mask-mode
|
|
|
|
|
* mask-composite
|
2009-05-28 18:09:05 +00:00
|
|
|
|
*
|
|
|
|
|
* (background-color applies to the entire element and not to individual
|
|
|
|
|
* layers, so it is irrelevant to this method.)
|
|
|
|
|
*
|
|
|
|
|
* These properties have the following dependencies upon each other when
|
|
|
|
|
* determining rendering:
|
|
|
|
|
*
|
2016-01-28 05:27:00 +00:00
|
|
|
|
* background-image/ mask-image
|
2009-05-28 18:09:05 +00:00
|
|
|
|
* no dependencies
|
2016-01-28 05:27:00 +00:00
|
|
|
|
* background-repeat/ mask-repeat
|
2009-05-28 18:09:05 +00:00
|
|
|
|
* no dependencies
|
|
|
|
|
* background-attachment
|
|
|
|
|
* no dependencies
|
2016-01-28 05:27:00 +00:00
|
|
|
|
* background-position/ mask-position
|
|
|
|
|
* depends upon background-size/mask-size (for the image's scaled size)
|
|
|
|
|
* and background-break (for the background positioning area)
|
|
|
|
|
* background-clip/ mask-clip
|
2009-05-28 18:09:05 +00:00
|
|
|
|
* no dependencies
|
2016-01-28 05:27:00 +00:00
|
|
|
|
* background-origin/ mask-origin
|
2009-05-28 18:09:05 +00:00
|
|
|
|
* depends upon background-attachment (only in the case where that value
|
|
|
|
|
* is 'fixed')
|
2016-01-28 05:27:00 +00:00
|
|
|
|
* background-size/ mask-size
|
2014-05-05 17:55:54 +00:00
|
|
|
|
* depends upon box-decoration-break (for the background positioning area
|
|
|
|
|
* for resolving percentages), background-image (for the image's intrinsic
|
2009-05-28 18:09:05 +00:00
|
|
|
|
* size), background-repeat (if that value is 'round'), and
|
|
|
|
|
* background-origin (for the background painting area, when
|
|
|
|
|
* background-repeat is 'round')
|
2016-01-28 05:27:00 +00:00
|
|
|
|
* background-blend-mode
|
|
|
|
|
* no dependencies
|
|
|
|
|
* mask-mode
|
|
|
|
|
* no dependencies
|
|
|
|
|
* mask-composite
|
|
|
|
|
* no dependencies
|
2014-05-05 17:55:54 +00:00
|
|
|
|
* box-decoration-break
|
|
|
|
|
* no dependencies
|
2009-05-28 18:09:05 +00:00
|
|
|
|
*
|
|
|
|
|
* As a result of only-if dependencies we don't strictly do a topological
|
|
|
|
|
* sort of the above properties when processing, but it's pretty close to one:
|
|
|
|
|
*
|
2016-01-28 05:27:00 +00:00
|
|
|
|
* background-clip/mask-clip (by caller)
|
|
|
|
|
* background-image/ mask-image
|
|
|
|
|
* box-decoration-break, background-origin/ mask origin
|
2014-05-05 17:55:54 +00:00
|
|
|
|
* background-attachment (postfix for background-origin if 'fixed')
|
2016-01-28 05:27:00 +00:00
|
|
|
|
* background-size/ mask-size
|
|
|
|
|
* background-position/ mask-position
|
|
|
|
|
* background-repeat/ mask-repeat
|
2009-05-28 18:09:05 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
|
uint32_t irFlags = 0;
|
2011-01-03 01:48:09 +00:00
|
|
|
|
if (aFlags & nsCSSRendering::PAINTBG_SYNC_DECODE_IMAGES) {
|
2012-05-03 20:11:57 +00:00
|
|
|
|
irFlags |= nsImageRenderer::FLAG_SYNC_DECODE_IMAGES;
|
2011-01-03 01:48:09 +00:00
|
|
|
|
}
|
2013-04-25 22:08:58 +00:00
|
|
|
|
if (aFlags & nsCSSRendering::PAINTBG_TO_WINDOW) {
|
|
|
|
|
irFlags |= nsImageRenderer::FLAG_PAINTING_TO_WINDOW;
|
|
|
|
|
}
|
2011-01-03 01:48:09 +00:00
|
|
|
|
|
2012-05-03 20:11:57 +00:00
|
|
|
|
nsBackgroundLayerState state(aForFrame, &aLayer.mImage, irFlags);
|
2011-01-03 01:48:09 +00:00
|
|
|
|
if (!state.mImageRenderer.PrepareImage()) {
|
2009-08-21 20:39:25 +00:00
|
|
|
|
// There's no image or it's not ready to be painted.
|
2011-01-03 01:48:09 +00:00
|
|
|
|
return state;
|
2009-08-21 20:39:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-11-08 15:05:32 +00:00
|
|
|
|
// The frame to which the background is attached
|
|
|
|
|
nsIFrame* attachedToFrame = aForFrame;
|
2016-04-25 21:20:13 +00:00
|
|
|
|
// Is the background marked 'fixed', but affected by a transform?
|
|
|
|
|
bool transformedFixed = false;
|
2009-08-21 20:39:25 +00:00
|
|
|
|
// Compute background origin area relative to aBorderArea now as we may need
|
|
|
|
|
// it to compute the effective image size for a CSS gradient.
|
2012-11-08 15:05:32 +00:00
|
|
|
|
nsRect bgPositioningArea =
|
2016-01-28 05:27:00 +00:00
|
|
|
|
ComputeImageLayerPositioningArea(aPresContext, aForFrame, aBorderArea,
|
2016-04-25 21:20:13 +00:00
|
|
|
|
aLayer, &attachedToFrame, &transformedFixed);
|
|
|
|
|
if (aOutIsTransformedFixed) {
|
|
|
|
|
*aOutIsTransformedFixed = transformedFixed;
|
|
|
|
|
}
|
1999-01-15 18:25:58 +00:00
|
|
|
|
|
2010-01-07 00:55:09 +00:00
|
|
|
|
// For background-attachment:fixed backgrounds, we'll limit the area
|
|
|
|
|
// where the background can be drawn to the viewport.
|
|
|
|
|
nsRect bgClipRect = aBGClipRect;
|
|
|
|
|
|
2002-10-08 10:24:53 +00:00
|
|
|
|
// Compute the anchor point.
|
|
|
|
|
//
|
2008-11-04 22:01:21 +00:00
|
|
|
|
// relative to aBorderArea.TopLeft() (which is where the top-left
|
|
|
|
|
// of aForFrame's border-box will be rendered)
|
2011-01-03 01:48:09 +00:00
|
|
|
|
nsPoint imageTopLeft;
|
2016-04-25 21:20:13 +00:00
|
|
|
|
if (NS_STYLE_IMAGELAYER_ATTACHMENT_FIXED == aLayer.mAttachment && !transformedFixed) {
|
|
|
|
|
if (aFlags & nsCSSRendering::PAINTBG_TO_WINDOW) {
|
2010-01-07 00:55:09 +00:00
|
|
|
|
// Clip background-attachment:fixed backgrounds to the viewport, if we're
|
2011-02-08 19:29:28 +00:00
|
|
|
|
// painting to the screen and not transformed. This avoids triggering
|
|
|
|
|
// tiling in common cases, without affecting output since drawing is
|
|
|
|
|
// always clipped to the viewport when we draw to the screen. (But it's
|
|
|
|
|
// not a pure optimization since it can affect the values of pixels at the
|
|
|
|
|
// edge of the viewport --- whether they're sampled from a putative "next
|
|
|
|
|
// tile" or not.)
|
2010-01-07 00:55:09 +00:00
|
|
|
|
bgClipRect.IntersectRect(bgClipRect, bgPositioningArea + aBorderArea.TopLeft());
|
|
|
|
|
}
|
2009-05-28 18:09:05 +00:00
|
|
|
|
}
|
2009-08-22 17:10:12 +00:00
|
|
|
|
|
2016-05-25 00:29:00 +00:00
|
|
|
|
int repeatX = aLayer.mRepeat.mXRepeat;
|
|
|
|
|
int repeatY = aLayer.mRepeat.mYRepeat;
|
|
|
|
|
|
|
|
|
|
// Scale the image as specified for background-size and background-repeat.
|
|
|
|
|
// Also as required for proper background positioning when background-position
|
|
|
|
|
// is defined with percentages.
|
2013-07-19 08:39:58 +00:00
|
|
|
|
CSSSizeOrRatio intrinsicSize = state.mImageRenderer.ComputeIntrinsicSize();
|
2013-08-01 04:22:40 +00:00
|
|
|
|
nsSize bgPositionSize = bgPositioningArea.Size();
|
2013-07-19 08:39:58 +00:00
|
|
|
|
nsSize imageSize = ComputeDrawnSizeForBackground(intrinsicSize,
|
2013-08-01 04:22:40 +00:00
|
|
|
|
bgPositionSize,
|
2016-05-25 00:29:00 +00:00
|
|
|
|
aLayer.mSize,
|
|
|
|
|
repeatX,
|
|
|
|
|
repeatY);
|
|
|
|
|
|
2011-01-13 10:40:12 +00:00
|
|
|
|
if (imageSize.width <= 0 || imageSize.height <= 0)
|
|
|
|
|
return state;
|
2009-05-28 18:09:05 +00:00
|
|
|
|
|
2013-07-19 08:39:58 +00:00
|
|
|
|
state.mImageRenderer.SetPreferredSize(intrinsicSize,
|
2013-08-01 04:22:40 +00:00
|
|
|
|
imageSize);
|
2013-07-19 08:39:58 +00:00
|
|
|
|
|
2009-05-28 18:09:05 +00:00
|
|
|
|
// Compute the position of the background now that the background's size is
|
|
|
|
|
// determined.
|
2014-10-22 20:03:18 +00:00
|
|
|
|
nsImageRenderer::ComputeObjectAnchorPoint(aLayer.mPosition,
|
|
|
|
|
bgPositionSize, imageSize,
|
|
|
|
|
&imageTopLeft, &state.mAnchor);
|
2016-05-25 00:29:00 +00:00
|
|
|
|
state.mRepeatSize = imageSize;
|
|
|
|
|
if (repeatX == NS_STYLE_IMAGELAYER_REPEAT_SPACE) {
|
2016-05-28 04:23:00 +00:00
|
|
|
|
bool isRepeat;
|
2016-05-25 00:29:00 +00:00
|
|
|
|
state.mRepeatSize.width = ComputeSpacedRepeatSize(imageSize.width,
|
2016-05-28 04:23:00 +00:00
|
|
|
|
bgPositionSize.width,
|
|
|
|
|
isRepeat);
|
|
|
|
|
if (isRepeat) {
|
2016-05-25 00:29:00 +00:00
|
|
|
|
imageTopLeft.x = 0;
|
|
|
|
|
state.mAnchor.x = 0;
|
|
|
|
|
} else {
|
|
|
|
|
repeatX = NS_STYLE_IMAGELAYER_REPEAT_NO_REPEAT;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (repeatY == NS_STYLE_IMAGELAYER_REPEAT_SPACE) {
|
2016-05-28 04:23:00 +00:00
|
|
|
|
bool isRepeat;
|
2016-05-25 00:29:00 +00:00
|
|
|
|
state.mRepeatSize.height = ComputeSpacedRepeatSize(imageSize.height,
|
2016-05-28 04:23:00 +00:00
|
|
|
|
bgPositionSize.height,
|
|
|
|
|
isRepeat);
|
|
|
|
|
if (isRepeat) {
|
2016-05-25 00:29:00 +00:00
|
|
|
|
imageTopLeft.y = 0;
|
|
|
|
|
state.mAnchor.y = 0;
|
|
|
|
|
} else {
|
|
|
|
|
repeatY = NS_STYLE_IMAGELAYER_REPEAT_NO_REPEAT;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-07 00:55:09 +00:00
|
|
|
|
imageTopLeft += bgPositioningArea.TopLeft();
|
2011-01-03 01:48:09 +00:00
|
|
|
|
state.mAnchor += bgPositioningArea.TopLeft();
|
|
|
|
|
state.mDestArea = nsRect(imageTopLeft + aBorderArea.TopLeft(), imageSize);
|
|
|
|
|
state.mFillArea = state.mDestArea;
|
2015-11-23 16:17:35 +00:00
|
|
|
|
|
|
|
|
|
ExtendMode repeatMode = ExtendMode::CLAMP;
|
2016-05-25 00:29:00 +00:00
|
|
|
|
if (repeatX == NS_STYLE_IMAGELAYER_REPEAT_REPEAT ||
|
|
|
|
|
repeatX == NS_STYLE_IMAGELAYER_REPEAT_ROUND ||
|
|
|
|
|
repeatX == NS_STYLE_IMAGELAYER_REPEAT_SPACE) {
|
2011-01-03 01:48:09 +00:00
|
|
|
|
state.mFillArea.x = bgClipRect.x;
|
|
|
|
|
state.mFillArea.width = bgClipRect.width;
|
2015-11-23 16:17:35 +00:00
|
|
|
|
repeatMode = ExtendMode::REPEAT_X;
|
2002-10-08 10:24:53 +00:00
|
|
|
|
}
|
2016-05-25 00:29:00 +00:00
|
|
|
|
if (repeatY == NS_STYLE_IMAGELAYER_REPEAT_REPEAT ||
|
|
|
|
|
repeatY == NS_STYLE_IMAGELAYER_REPEAT_ROUND ||
|
|
|
|
|
repeatY == NS_STYLE_IMAGELAYER_REPEAT_SPACE) {
|
2011-01-03 01:48:09 +00:00
|
|
|
|
state.mFillArea.y = bgClipRect.y;
|
|
|
|
|
state.mFillArea.height = bgClipRect.height;
|
2015-11-23 16:17:35 +00:00
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
* We're repeating on the X axis already,
|
|
|
|
|
* so if we have to repeat in the Y axis,
|
|
|
|
|
* we really need to repeat in both directions.
|
|
|
|
|
*/
|
|
|
|
|
if (repeatMode == ExtendMode::REPEAT_X) {
|
|
|
|
|
repeatMode = ExtendMode::REPEAT;
|
|
|
|
|
} else {
|
|
|
|
|
repeatMode = ExtendMode::REPEAT_Y;
|
|
|
|
|
}
|
2002-10-08 10:24:53 +00:00
|
|
|
|
}
|
2015-11-23 16:17:35 +00:00
|
|
|
|
state.mImageRenderer.SetExtendMode(repeatMode);
|
2016-03-24 00:32:00 +00:00
|
|
|
|
state.mImageRenderer.SetMaskOp(aLayer.mMaskMode);
|
2015-11-23 16:17:35 +00:00
|
|
|
|
|
2011-01-03 01:48:09 +00:00
|
|
|
|
state.mFillArea.IntersectRect(state.mFillArea, bgClipRect);
|
2013-11-08 15:08:03 +00:00
|
|
|
|
|
2011-01-03 01:48:09 +00:00
|
|
|
|
return state;
|
|
|
|
|
}
|
1998-07-30 23:31:42 +00:00
|
|
|
|
|
2011-01-03 01:48:09 +00:00
|
|
|
|
nsRect
|
|
|
|
|
nsCSSRendering::GetBackgroundLayerRect(nsPresContext* aPresContext,
|
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
|
const nsRect& aBorderArea,
|
2013-02-04 12:11:49 +00:00
|
|
|
|
const nsRect& aClipRect,
|
2016-01-28 05:24:00 +00:00
|
|
|
|
const nsStyleImageLayers::Layer& aLayer,
|
2013-06-04 04:49:03 +00:00
|
|
|
|
uint32_t aFlags)
|
2011-01-03 01:48:09 +00:00
|
|
|
|
{
|
2014-09-17 00:36:57 +00:00
|
|
|
|
Sides skipSides = aForFrame->GetSkipSides();
|
|
|
|
|
nsRect borderArea =
|
|
|
|
|
::BoxDecorationRectForBackground(aForFrame, aBorderArea, skipSides);
|
2012-05-03 20:11:57 +00:00
|
|
|
|
nsBackgroundLayerState state =
|
2016-01-28 05:27:00 +00:00
|
|
|
|
PrepareImageLayer(aPresContext, aForFrame, aFlags, borderArea,
|
2014-05-05 17:55:54 +00:00
|
|
|
|
aClipRect, aLayer);
|
2011-01-03 01:48:09 +00:00
|
|
|
|
return state.mFillArea;
|
2002-10-08 10:24:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-23 02:54:48 +00:00
|
|
|
|
static DrawResult
|
2009-02-16 01:04:03 +00:00
|
|
|
|
DrawBorderImage(nsPresContext* aPresContext,
|
2011-12-22 23:34:45 +00:00
|
|
|
|
nsRenderingContext& aRenderingContext,
|
2009-02-16 01:04:03 +00:00
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
|
const nsRect& aBorderArea,
|
2009-11-14 04:23:00 +00:00
|
|
|
|
const nsStyleBorder& aStyleBorder,
|
2014-05-05 17:55:55 +00:00
|
|
|
|
const nsRect& aDirtyRect,
|
2015-10-23 02:54:48 +00:00
|
|
|
|
Sides aSkipSides,
|
|
|
|
|
PaintBorderFlags aFlags)
|
2008-07-17 06:30:25 +00:00
|
|
|
|
{
|
2011-04-04 11:41:02 +00:00
|
|
|
|
NS_PRECONDITION(aStyleBorder.IsBorderImageLoaded(),
|
|
|
|
|
"drawing border image that isn't successfully loaded");
|
|
|
|
|
|
2015-10-23 02:54:48 +00:00
|
|
|
|
if (aDirtyRect.IsEmpty()) {
|
|
|
|
|
return DrawResult::SUCCESS;
|
|
|
|
|
}
|
2008-07-17 06:30:25 +00:00
|
|
|
|
|
2015-10-23 02:54:48 +00:00
|
|
|
|
uint32_t irFlags = 0;
|
|
|
|
|
if (aFlags & PaintBorderFlags::SYNC_DECODE_IMAGES) {
|
|
|
|
|
irFlags |= nsImageRenderer::FLAG_SYNC_DECODE_IMAGES;
|
|
|
|
|
}
|
|
|
|
|
nsImageRenderer renderer(aForFrame, &aStyleBorder.mBorderImageSource, irFlags);
|
2014-01-31 03:36:41 +00:00
|
|
|
|
|
2009-02-19 19:03:28 +00:00
|
|
|
|
// Ensure we get invalidated for loads and animations of the image.
|
|
|
|
|
// We need to do this here because this might be the only code that
|
|
|
|
|
// knows about the association of the style data with the frame.
|
|
|
|
|
// XXX We shouldn't really... since if anybody is passing in a
|
|
|
|
|
// different style, they'll potentially have the wrong size for the
|
|
|
|
|
// border too.
|
2014-01-31 03:36:41 +00:00
|
|
|
|
aForFrame->AssociateImage(aStyleBorder.mBorderImageSource, aPresContext);
|
2009-02-16 01:04:03 +00:00
|
|
|
|
|
2014-01-31 03:36:41 +00:00
|
|
|
|
if (!renderer.PrepareImage()) {
|
2015-10-23 02:54:48 +00:00
|
|
|
|
return renderer.PrepareResult();
|
2010-09-10 17:42:57 +00:00
|
|
|
|
}
|
2009-02-16 01:04:03 +00:00
|
|
|
|
|
2014-05-05 17:55:55 +00:00
|
|
|
|
// NOTE: no Save() yet, we do that later by calling autoSR.EnsureSaved()
|
|
|
|
|
// in case we need it.
|
|
|
|
|
gfxContextAutoSaveRestore autoSR;
|
|
|
|
|
|
2011-12-22 23:34:45 +00:00
|
|
|
|
// Determine the border image area, which by default corresponds to the
|
|
|
|
|
// border box but can be modified by 'border-image-outset'.
|
2014-05-05 17:55:55 +00:00
|
|
|
|
// Note that 'border-radius' do not apply to 'border-image' borders per
|
|
|
|
|
// <http://dev.w3.org/csswg/css-backgrounds/#corner-clipping>.
|
|
|
|
|
nsRect borderImgArea;
|
|
|
|
|
nsMargin borderWidths(aStyleBorder.GetComputedBorder());
|
|
|
|
|
nsMargin imageOutset(aStyleBorder.GetImageOutset());
|
2014-06-28 10:13:13 +00:00
|
|
|
|
if (::IsBoxDecorationSlice(aStyleBorder) && !aSkipSides.IsEmpty()) {
|
2014-09-17 00:36:57 +00:00
|
|
|
|
borderImgArea = ::BoxDecorationRectForBorder(aForFrame, aBorderArea,
|
|
|
|
|
aSkipSides, &aStyleBorder);
|
2014-05-05 17:55:55 +00:00
|
|
|
|
if (borderImgArea.IsEqualEdges(aBorderArea)) {
|
|
|
|
|
// No need for a clip, just skip the sides we don't want.
|
2014-06-24 17:52:19 +00:00
|
|
|
|
borderWidths.ApplySkipSides(aSkipSides);
|
|
|
|
|
imageOutset.ApplySkipSides(aSkipSides);
|
2014-05-05 17:55:55 +00:00
|
|
|
|
borderImgArea.Inflate(imageOutset);
|
|
|
|
|
} else {
|
|
|
|
|
// We're drawing borders around the joined continuation boxes so we need
|
|
|
|
|
// to clip that to the slice that we want for this frame.
|
|
|
|
|
borderImgArea.Inflate(imageOutset);
|
2014-06-24 17:52:19 +00:00
|
|
|
|
imageOutset.ApplySkipSides(aSkipSides);
|
2014-05-05 17:55:55 +00:00
|
|
|
|
nsRect clip = aBorderArea;
|
|
|
|
|
clip.Inflate(imageOutset);
|
|
|
|
|
autoSR.EnsureSaved(aRenderingContext.ThebesContext());
|
2014-10-20 09:55:48 +00:00
|
|
|
|
aRenderingContext.ThebesContext()->
|
2014-10-22 11:29:06 +00:00
|
|
|
|
Clip(NSRectToSnappedRect(clip,
|
|
|
|
|
aForFrame->PresContext()->AppUnitsPerDevPixel(),
|
|
|
|
|
*aRenderingContext.GetDrawTarget()));
|
2014-05-05 17:55:55 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
borderImgArea = aBorderArea;
|
|
|
|
|
borderImgArea.Inflate(imageOutset);
|
|
|
|
|
}
|
2011-12-22 23:34:45 +00:00
|
|
|
|
|
2014-01-31 03:36:41 +00:00
|
|
|
|
// Calculate the image size used to compute slice points.
|
|
|
|
|
CSSSizeOrRatio intrinsicSize = renderer.ComputeIntrinsicSize();
|
|
|
|
|
nsSize imageSize = nsImageRenderer::ComputeConcreteSize(CSSSizeOrRatio(),
|
|
|
|
|
intrinsicSize,
|
|
|
|
|
borderImgArea.Size());
|
2014-01-31 03:36:41 +00:00
|
|
|
|
renderer.SetPreferredSize(intrinsicSize, imageSize);
|
2014-01-31 03:36:41 +00:00
|
|
|
|
|
2011-12-22 23:34:45 +00:00
|
|
|
|
// Compute the used values of 'border-image-slice' and 'border-image-width';
|
|
|
|
|
// we do them together because the latter can depend on the former.
|
2014-01-31 03:36:41 +00:00
|
|
|
|
nsMargin slice;
|
2011-12-22 23:34:45 +00:00
|
|
|
|
nsMargin border;
|
2009-02-16 01:04:03 +00:00
|
|
|
|
NS_FOR_CSS_SIDES(s) {
|
2011-12-22 23:34:45 +00:00
|
|
|
|
nsStyleCoord coord = aStyleBorder.mBorderImageSlice.Get(s);
|
2012-08-22 15:56:38 +00:00
|
|
|
|
int32_t imgDimension = NS_SIDE_IS_VERTICAL(s)
|
2014-01-31 03:36:41 +00:00
|
|
|
|
? imageSize.width : imageSize.height;
|
2011-12-22 23:34:45 +00:00
|
|
|
|
nscoord borderDimension = NS_SIDE_IS_VERTICAL(s)
|
|
|
|
|
? borderImgArea.width : borderImgArea.height;
|
2009-02-16 01:04:03 +00:00
|
|
|
|
double value;
|
|
|
|
|
switch (coord.GetUnit()) {
|
|
|
|
|
case eStyleUnit_Percent:
|
|
|
|
|
value = coord.GetPercentValue() * imgDimension;
|
|
|
|
|
break;
|
|
|
|
|
case eStyleUnit_Factor:
|
2014-01-31 03:36:41 +00:00
|
|
|
|
value = nsPresContext::CSSPixelsToAppUnits(
|
|
|
|
|
NS_lround(coord.GetFactorValue()));
|
2009-02-16 01:04:03 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2011-12-22 23:34:45 +00:00
|
|
|
|
NS_NOTREACHED("unexpected CSS unit for image slice");
|
2009-02-16 01:04:03 +00:00
|
|
|
|
value = 0;
|
|
|
|
|
break;
|
2008-07-17 06:30:25 +00:00
|
|
|
|
}
|
2009-02-16 01:04:03 +00:00
|
|
|
|
if (value < 0)
|
|
|
|
|
value = 0;
|
|
|
|
|
if (value > imgDimension)
|
|
|
|
|
value = imgDimension;
|
2014-01-31 03:36:41 +00:00
|
|
|
|
slice.Side(s) = value;
|
2009-02-16 01:04:03 +00:00
|
|
|
|
|
2011-12-22 23:34:45 +00:00
|
|
|
|
coord = aStyleBorder.mBorderImageWidth.Get(s);
|
|
|
|
|
switch (coord.GetUnit()) {
|
|
|
|
|
case eStyleUnit_Coord: // absolute dimension
|
|
|
|
|
value = coord.GetCoordValue();
|
|
|
|
|
break;
|
|
|
|
|
case eStyleUnit_Percent:
|
|
|
|
|
value = coord.GetPercentValue() * borderDimension;
|
|
|
|
|
break;
|
|
|
|
|
case eStyleUnit_Factor:
|
|
|
|
|
value = coord.GetFactorValue() * borderWidths.Side(s);
|
|
|
|
|
break;
|
|
|
|
|
case eStyleUnit_Auto: // same as the slice value, in CSS pixels
|
2014-01-31 03:36:41 +00:00
|
|
|
|
value = slice.Side(s);
|
2011-12-22 23:34:45 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
NS_NOTREACHED("unexpected CSS unit for border image area division");
|
|
|
|
|
value = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-02-18 22:14:31 +00:00
|
|
|
|
// NSToCoordRoundWithClamp rounds towards infinity, but that's OK
|
|
|
|
|
// because we expect value to be non-negative.
|
|
|
|
|
MOZ_ASSERT(value >= 0);
|
|
|
|
|
border.Side(s) = NSToCoordRoundWithClamp(value);
|
2013-02-14 19:57:20 +00:00
|
|
|
|
MOZ_ASSERT(border.Side(s) >= 0);
|
2011-12-22 23:34:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// "If two opposite border-image-width offsets are large enough that they
|
|
|
|
|
// overlap, their used values are proportionately reduced until they no
|
|
|
|
|
// longer overlap."
|
2013-02-14 19:57:20 +00:00
|
|
|
|
uint32_t combinedBorderWidth = uint32_t(border.left) +
|
|
|
|
|
uint32_t(border.right);
|
|
|
|
|
double scaleX = combinedBorderWidth > uint32_t(borderImgArea.width)
|
|
|
|
|
? borderImgArea.width / double(combinedBorderWidth)
|
2011-12-22 23:34:45 +00:00
|
|
|
|
: 1.0;
|
2013-02-14 19:57:20 +00:00
|
|
|
|
uint32_t combinedBorderHeight = uint32_t(border.top) +
|
|
|
|
|
uint32_t(border.bottom);
|
|
|
|
|
double scaleY = combinedBorderHeight > uint32_t(borderImgArea.height)
|
|
|
|
|
? borderImgArea.height / double(combinedBorderHeight)
|
2011-12-22 23:34:45 +00:00
|
|
|
|
: 1.0;
|
2013-01-15 12:22:03 +00:00
|
|
|
|
double scale = std::min(scaleX, scaleY);
|
2011-12-22 23:34:45 +00:00
|
|
|
|
if (scale < 1.0) {
|
|
|
|
|
border.left *= scale;
|
|
|
|
|
border.right *= scale;
|
|
|
|
|
border.top *= scale;
|
|
|
|
|
border.bottom *= scale;
|
|
|
|
|
NS_ASSERTION(border.left + border.right <= borderImgArea.width &&
|
|
|
|
|
border.top + border.bottom <= borderImgArea.height,
|
|
|
|
|
"rounding error in width reduction???");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// These helper tables recharacterize the 'slice' and 'width' margins
|
2009-02-16 01:04:03 +00:00
|
|
|
|
// in a more convenient form: they are the x/y/width/height coords
|
|
|
|
|
// required for various bands of the border, and they have been transformed
|
2011-12-22 23:34:45 +00:00
|
|
|
|
// to be relative to the innerRect (for 'slice') or the page (for 'border').
|
2009-02-16 01:04:03 +00:00
|
|
|
|
enum {
|
|
|
|
|
LEFT, MIDDLE, RIGHT,
|
|
|
|
|
TOP = LEFT, BOTTOM = RIGHT
|
|
|
|
|
};
|
|
|
|
|
const nscoord borderX[3] = {
|
2011-12-22 23:34:45 +00:00
|
|
|
|
borderImgArea.x + 0,
|
|
|
|
|
borderImgArea.x + border.left,
|
|
|
|
|
borderImgArea.x + borderImgArea.width - border.right,
|
2009-02-16 01:04:03 +00:00
|
|
|
|
};
|
|
|
|
|
const nscoord borderY[3] = {
|
2011-12-22 23:34:45 +00:00
|
|
|
|
borderImgArea.y + 0,
|
|
|
|
|
borderImgArea.y + border.top,
|
|
|
|
|
borderImgArea.y + borderImgArea.height - border.bottom,
|
2009-02-16 01:04:03 +00:00
|
|
|
|
};
|
|
|
|
|
const nscoord borderWidth[3] = {
|
|
|
|
|
border.left,
|
2011-12-22 23:34:45 +00:00
|
|
|
|
borderImgArea.width - border.left - border.right,
|
2009-02-16 01:04:03 +00:00
|
|
|
|
border.right,
|
|
|
|
|
};
|
|
|
|
|
const nscoord borderHeight[3] = {
|
|
|
|
|
border.top,
|
2011-12-22 23:34:45 +00:00
|
|
|
|
borderImgArea.height - border.top - border.bottom,
|
2009-02-16 01:04:03 +00:00
|
|
|
|
border.bottom,
|
|
|
|
|
};
|
2012-08-22 15:56:38 +00:00
|
|
|
|
const int32_t sliceX[3] = {
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 01:50:15 +00:00
|
|
|
|
0,
|
2011-12-22 23:34:45 +00:00
|
|
|
|
slice.left,
|
2014-01-31 03:36:41 +00:00
|
|
|
|
imageSize.width - slice.right,
|
2009-02-16 01:04:03 +00:00
|
|
|
|
};
|
2012-08-22 15:56:38 +00:00
|
|
|
|
const int32_t sliceY[3] = {
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 01:50:15 +00:00
|
|
|
|
0,
|
2011-12-22 23:34:45 +00:00
|
|
|
|
slice.top,
|
2014-01-31 03:36:41 +00:00
|
|
|
|
imageSize.height - slice.bottom,
|
2009-02-16 01:04:03 +00:00
|
|
|
|
};
|
2012-08-22 15:56:38 +00:00
|
|
|
|
const int32_t sliceWidth[3] = {
|
2011-12-22 23:34:45 +00:00
|
|
|
|
slice.left,
|
2014-01-31 03:36:41 +00:00
|
|
|
|
std::max(imageSize.width - slice.left - slice.right, 0),
|
2011-12-22 23:34:45 +00:00
|
|
|
|
slice.right,
|
2009-02-16 01:04:03 +00:00
|
|
|
|
};
|
2012-08-22 15:56:38 +00:00
|
|
|
|
const int32_t sliceHeight[3] = {
|
2011-12-22 23:34:45 +00:00
|
|
|
|
slice.top,
|
2014-01-31 03:36:41 +00:00
|
|
|
|
std::max(imageSize.height - slice.top - slice.bottom, 0),
|
2011-12-22 23:34:45 +00:00
|
|
|
|
slice.bottom,
|
2009-02-16 01:04:03 +00:00
|
|
|
|
};
|
|
|
|
|
|
2015-10-23 02:54:48 +00:00
|
|
|
|
DrawResult result = DrawResult::SUCCESS;
|
|
|
|
|
|
2016-08-01 00:24:00 +00:00
|
|
|
|
// intrinsicSize.CanComputeConcreteSize() return false means we can not
|
|
|
|
|
// read intrinsic size from aStyleBorder.mBorderImageSource.
|
|
|
|
|
// In this condition, we pass imageSize(a resolved size comes from
|
|
|
|
|
// default sizing algorithm) to renderer as the viewport size.
|
|
|
|
|
Maybe<nsSize> svgViewportSize = intrinsicSize.CanComputeConcreteSize() ?
|
|
|
|
|
Nothing() : Some(imageSize);
|
|
|
|
|
bool hasIntrinsicRatio = intrinsicSize.HasRatio();
|
|
|
|
|
renderer.PurgeCacheForViewportChange(svgViewportSize, hasIntrinsicRatio);
|
|
|
|
|
|
2009-02-16 01:04:03 +00:00
|
|
|
|
for (int i = LEFT; i <= RIGHT; i++) {
|
|
|
|
|
for (int j = TOP; j <= BOTTOM; j++) {
|
2012-08-22 15:56:38 +00:00
|
|
|
|
uint8_t fillStyleH, fillStyleV;
|
2009-02-16 01:04:03 +00:00
|
|
|
|
nsSize unitSize;
|
2009-02-20 03:33:30 +00:00
|
|
|
|
|
2009-02-16 01:04:03 +00:00
|
|
|
|
if (i == MIDDLE && j == MIDDLE) {
|
2011-12-22 23:34:45 +00:00
|
|
|
|
// Discard the middle portion unless set to fill.
|
|
|
|
|
if (NS_STYLE_BORDER_IMAGE_SLICE_NOFILL ==
|
|
|
|
|
aStyleBorder.mBorderImageFill) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NS_ASSERTION(NS_STYLE_BORDER_IMAGE_SLICE_FILL ==
|
|
|
|
|
aStyleBorder.mBorderImageFill,
|
|
|
|
|
"Unexpected border image fill");
|
|
|
|
|
|
2009-02-20 03:33:30 +00:00
|
|
|
|
// css-background:
|
2009-02-24 08:31:22 +00:00
|
|
|
|
// The middle image's width is scaled by the same factor as the
|
|
|
|
|
// top image unless that factor is zero or infinity, in which
|
|
|
|
|
// case the scaling factor of the bottom is substituted, and
|
|
|
|
|
// failing that, the width is not scaled. The height of the
|
|
|
|
|
// middle image is scaled by the same factor as the left image
|
|
|
|
|
// unless that factor is zero or infinity, in which case the
|
|
|
|
|
// scaling factor of the right image is substituted, and failing
|
|
|
|
|
// that, the height is not scaled.
|
2009-02-20 03:33:30 +00:00
|
|
|
|
gfxFloat hFactor, vFactor;
|
|
|
|
|
|
2011-12-22 23:34:45 +00:00
|
|
|
|
if (0 < border.left && 0 < slice.left)
|
|
|
|
|
vFactor = gfxFloat(border.left)/slice.left;
|
|
|
|
|
else if (0 < border.right && 0 < slice.right)
|
|
|
|
|
vFactor = gfxFloat(border.right)/slice.right;
|
2009-02-20 03:33:30 +00:00
|
|
|
|
else
|
2014-01-31 03:36:41 +00:00
|
|
|
|
vFactor = 1;
|
2009-02-20 03:33:30 +00:00
|
|
|
|
|
2011-12-22 23:34:45 +00:00
|
|
|
|
if (0 < border.top && 0 < slice.top)
|
|
|
|
|
hFactor = gfxFloat(border.top)/slice.top;
|
|
|
|
|
else if (0 < border.bottom && 0 < slice.bottom)
|
|
|
|
|
hFactor = gfxFloat(border.bottom)/slice.bottom;
|
2009-02-20 03:33:30 +00:00
|
|
|
|
else
|
2014-01-31 03:36:41 +00:00
|
|
|
|
hFactor = 1;
|
2009-02-20 03:33:30 +00:00
|
|
|
|
|
2011-12-22 23:34:45 +00:00
|
|
|
|
unitSize.width = sliceWidth[i]*hFactor;
|
|
|
|
|
unitSize.height = sliceHeight[j]*vFactor;
|
|
|
|
|
fillStyleH = aStyleBorder.mBorderImageRepeatH;
|
|
|
|
|
fillStyleV = aStyleBorder.mBorderImageRepeatV;
|
2009-02-20 03:33:30 +00:00
|
|
|
|
|
|
|
|
|
} else if (i == MIDDLE) { // top, bottom
|
|
|
|
|
// Sides are always stretched to the thickness of their border,
|
|
|
|
|
// and stretched proportionately on the other axis.
|
2009-02-24 08:31:22 +00:00
|
|
|
|
gfxFloat factor;
|
2011-12-22 23:34:45 +00:00
|
|
|
|
if (0 < borderHeight[j] && 0 < sliceHeight[j])
|
|
|
|
|
factor = gfxFloat(borderHeight[j])/sliceHeight[j];
|
2009-02-24 08:31:22 +00:00
|
|
|
|
else
|
2014-01-31 03:36:41 +00:00
|
|
|
|
factor = 1;
|
2009-02-20 03:33:30 +00:00
|
|
|
|
|
2011-12-22 23:34:45 +00:00
|
|
|
|
unitSize.width = sliceWidth[i]*factor;
|
2009-02-16 01:04:03 +00:00
|
|
|
|
unitSize.height = borderHeight[j];
|
2011-12-22 23:34:45 +00:00
|
|
|
|
fillStyleH = aStyleBorder.mBorderImageRepeatH;
|
|
|
|
|
fillStyleV = NS_STYLE_BORDER_IMAGE_REPEAT_STRETCH;
|
2009-02-20 03:33:30 +00:00
|
|
|
|
|
|
|
|
|
} else if (j == MIDDLE) { // left, right
|
2009-02-24 08:31:22 +00:00
|
|
|
|
gfxFloat factor;
|
2011-12-22 23:34:45 +00:00
|
|
|
|
if (0 < borderWidth[i] && 0 < sliceWidth[i])
|
|
|
|
|
factor = gfxFloat(borderWidth[i])/sliceWidth[i];
|
2009-02-24 08:31:22 +00:00
|
|
|
|
else
|
2014-01-31 03:36:41 +00:00
|
|
|
|
factor = 1;
|
2009-02-20 03:33:30 +00:00
|
|
|
|
|
2009-02-16 01:04:03 +00:00
|
|
|
|
unitSize.width = borderWidth[i];
|
2011-12-22 23:34:45 +00:00
|
|
|
|
unitSize.height = sliceHeight[j]*factor;
|
|
|
|
|
fillStyleH = NS_STYLE_BORDER_IMAGE_REPEAT_STRETCH;
|
|
|
|
|
fillStyleV = aStyleBorder.mBorderImageRepeatV;
|
2009-02-20 03:33:30 +00:00
|
|
|
|
|
2009-02-16 01:04:03 +00:00
|
|
|
|
} else {
|
2009-02-20 03:33:30 +00:00
|
|
|
|
// Corners are always stretched to fit the corner.
|
2009-02-16 01:04:03 +00:00
|
|
|
|
unitSize.width = borderWidth[i];
|
|
|
|
|
unitSize.height = borderHeight[j];
|
2011-12-22 23:34:45 +00:00
|
|
|
|
fillStyleH = NS_STYLE_BORDER_IMAGE_REPEAT_STRETCH;
|
|
|
|
|
fillStyleV = NS_STYLE_BORDER_IMAGE_REPEAT_STRETCH;
|
2009-02-16 01:04:03 +00:00
|
|
|
|
}
|
2009-02-07 10:37:23 +00:00
|
|
|
|
|
2014-01-31 03:36:41 +00:00
|
|
|
|
nsRect destArea(borderX[i], borderY[j], borderWidth[i], borderHeight[j]);
|
|
|
|
|
nsRect subArea(sliceX[i], sliceY[j], sliceWidth[i], sliceHeight[j]);
|
2016-03-08 07:54:13 +00:00
|
|
|
|
if (subArea.IsEmpty())
|
|
|
|
|
continue;
|
|
|
|
|
|
2014-01-31 03:36:41 +00:00
|
|
|
|
nsIntRect intSubArea = subArea.ToOutsidePixels(nsPresContext::AppUnitsPerCSSPixel());
|
2015-10-23 02:54:48 +00:00
|
|
|
|
result &=
|
|
|
|
|
renderer.DrawBorderImageComponent(aPresContext,
|
|
|
|
|
aRenderingContext, aDirtyRect,
|
|
|
|
|
destArea, CSSIntRect(intSubArea.x,
|
|
|
|
|
intSubArea.y,
|
|
|
|
|
intSubArea.width,
|
|
|
|
|
intSubArea.height),
|
|
|
|
|
fillStyleH, fillStyleV,
|
2016-03-08 07:54:13 +00:00
|
|
|
|
unitSize, j * (RIGHT + 1) + i,
|
2016-08-01 00:24:00 +00:00
|
|
|
|
svgViewportSize, hasIntrinsicRatio);
|
2009-02-16 01:04:03 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-10-23 02:54:48 +00:00
|
|
|
|
|
|
|
|
|
return result;
|
2008-07-17 06:30:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-02-19 15:48:28 +00:00
|
|
|
|
// Begin table border-collapsing section
|
|
|
|
|
// These functions were written to not disrupt the normal ones and yet satisfy some additional requirements
|
|
|
|
|
// At some point, all functions should be unified to include the additional functionality that these provide
|
|
|
|
|
|
|
|
|
|
static nscoord
|
2010-04-27 16:15:01 +00:00
|
|
|
|
RoundIntToPixel(nscoord aValue,
|
2002-02-19 15:48:28 +00:00
|
|
|
|
nscoord aTwipsPerPixel,
|
2011-09-29 06:19:26 +00:00
|
|
|
|
bool aRoundDown = false)
|
2002-02-19 15:48:28 +00:00
|
|
|
|
{
|
2010-04-27 16:15:01 +00:00
|
|
|
|
if (aTwipsPerPixel <= 0)
|
|
|
|
|
// We must be rendering to a device that has a resolution greater than Twips!
|
2002-04-06 22:28:39 +00:00
|
|
|
|
// In that case, aValue is as accurate as it's going to get.
|
2010-04-27 16:15:01 +00:00
|
|
|
|
return aValue;
|
2002-04-06 22:28:39 +00:00
|
|
|
|
|
2002-02-19 15:48:28 +00:00
|
|
|
|
nscoord halfPixel = NSToCoordRound(aTwipsPerPixel / 2.0f);
|
|
|
|
|
nscoord extra = aValue % aTwipsPerPixel;
|
|
|
|
|
nscoord finalValue = (!aRoundDown && (extra >= halfPixel)) ? aValue + (aTwipsPerPixel - extra) : aValue - extra;
|
|
|
|
|
return finalValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static nscoord
|
2010-04-27 16:15:01 +00:00
|
|
|
|
RoundFloatToPixel(float aValue,
|
2002-02-19 15:48:28 +00:00
|
|
|
|
nscoord aTwipsPerPixel,
|
2011-09-29 06:19:26 +00:00
|
|
|
|
bool aRoundDown = false)
|
2002-02-19 15:48:28 +00:00
|
|
|
|
{
|
|
|
|
|
return RoundIntToPixel(NSToCoordRound(aValue), aTwipsPerPixel, aRoundDown);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-17 14:06:34 +00:00
|
|
|
|
static void SetPoly(const Rect& aRect, Point* poly)
|
2002-02-19 15:48:28 +00:00
|
|
|
|
{
|
|
|
|
|
poly[0].x = aRect.x;
|
|
|
|
|
poly[0].y = aRect.y;
|
|
|
|
|
poly[1].x = aRect.x + aRect.width;
|
|
|
|
|
poly[1].y = aRect.y;
|
|
|
|
|
poly[2].x = aRect.x + aRect.width;
|
|
|
|
|
poly[2].y = aRect.y + aRect.height;
|
|
|
|
|
poly[3].x = aRect.x;
|
|
|
|
|
poly[3].y = aRect.y + aRect.height;
|
|
|
|
|
}
|
2010-04-27 16:15:01 +00:00
|
|
|
|
|
2015-07-03 19:22:22 +00:00
|
|
|
|
static void
|
2015-12-06 22:13:58 +00:00
|
|
|
|
DrawDashedSegment(DrawTarget& aDrawTarget,
|
2015-07-03 19:22:22 +00:00
|
|
|
|
nsRect aRect,
|
|
|
|
|
nscoord aDashLength,
|
|
|
|
|
nscolor aColor,
|
|
|
|
|
int32_t aAppUnitsPerDevPixel,
|
|
|
|
|
nscoord aTwipsPerPixel,
|
|
|
|
|
bool aHorizontal)
|
|
|
|
|
{
|
|
|
|
|
ColorPattern color(ToDeviceColor(aColor));
|
|
|
|
|
DrawOptions drawOptions(1.f, CompositionOp::OP_OVER, AntialiasMode::NONE);
|
|
|
|
|
StrokeOptions strokeOptions;
|
|
|
|
|
|
|
|
|
|
Float dash[2];
|
|
|
|
|
dash[0] = Float(aDashLength) / aAppUnitsPerDevPixel;
|
|
|
|
|
dash[1] = dash[0];
|
|
|
|
|
|
|
|
|
|
strokeOptions.mDashPattern = dash;
|
|
|
|
|
strokeOptions.mDashLength = MOZ_ARRAY_LENGTH(dash);
|
|
|
|
|
|
|
|
|
|
if (aHorizontal) {
|
|
|
|
|
nsPoint left = (aRect.TopLeft() + aRect.BottomLeft()) / 2;
|
|
|
|
|
nsPoint right = (aRect.TopRight() + aRect.BottomRight()) / 2;
|
|
|
|
|
strokeOptions.mLineWidth = Float(aRect.height) / aAppUnitsPerDevPixel;
|
|
|
|
|
StrokeLineWithSnapping(left, right,
|
2015-12-06 22:13:58 +00:00
|
|
|
|
aAppUnitsPerDevPixel, aDrawTarget,
|
2015-07-03 19:22:22 +00:00
|
|
|
|
color, strokeOptions, drawOptions);
|
|
|
|
|
} else {
|
|
|
|
|
nsPoint top = (aRect.TopLeft() + aRect.TopRight()) / 2;
|
|
|
|
|
nsPoint bottom = (aRect.BottomLeft() + aRect.BottomRight()) / 2;
|
|
|
|
|
strokeOptions.mLineWidth = Float(aRect.width) / aAppUnitsPerDevPixel;
|
|
|
|
|
StrokeLineWithSnapping(top, bottom,
|
2015-12-06 22:13:58 +00:00
|
|
|
|
aAppUnitsPerDevPixel, aDrawTarget,
|
2015-07-03 19:22:22 +00:00
|
|
|
|
color, strokeOptions, drawOptions);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-27 16:15:01 +00:00
|
|
|
|
static void
|
2015-12-06 22:13:58 +00:00
|
|
|
|
DrawSolidBorderSegment(DrawTarget& aDrawTarget,
|
2002-02-19 15:48:28 +00:00
|
|
|
|
nsRect aRect,
|
2014-10-17 14:06:34 +00:00
|
|
|
|
nscolor aColor,
|
2014-10-20 09:55:49 +00:00
|
|
|
|
int32_t aAppUnitsPerDevPixel,
|
2002-02-19 15:48:28 +00:00
|
|
|
|
nscoord aTwipsPerPixel,
|
2012-08-22 15:56:38 +00:00
|
|
|
|
uint8_t aStartBevelSide = 0,
|
2002-02-19 15:48:28 +00:00
|
|
|
|
nscoord aStartBevelOffset = 0,
|
2012-08-22 15:56:38 +00:00
|
|
|
|
uint8_t aEndBevelSide = 0,
|
2002-02-19 15:48:28 +00:00
|
|
|
|
nscoord aEndBevelOffset = 0)
|
|
|
|
|
{
|
2014-10-19 12:22:22 +00:00
|
|
|
|
ColorPattern color(ToDeviceColor(aColor));
|
|
|
|
|
DrawOptions drawOptions(1.f, CompositionOp::OP_OVER, AntialiasMode::NONE);
|
2002-02-19 15:48:28 +00:00
|
|
|
|
|
2015-07-06 19:39:42 +00:00
|
|
|
|
// We don't need to bevel single pixel borders
|
2002-02-19 15:48:28 +00:00
|
|
|
|
if ((aRect.width == aTwipsPerPixel) || (aRect.height == aTwipsPerPixel) ||
|
|
|
|
|
((0 == aStartBevelOffset) && (0 == aEndBevelOffset))) {
|
2015-07-06 19:39:42 +00:00
|
|
|
|
// simple rectangle
|
2015-12-06 22:13:58 +00:00
|
|
|
|
aDrawTarget.FillRect(NSRectToSnappedRect(aRect, aAppUnitsPerDevPixel,
|
|
|
|
|
aDrawTarget),
|
2015-07-06 19:39:42 +00:00
|
|
|
|
color, drawOptions);
|
2002-02-19 15:48:28 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// polygon with beveling
|
2014-10-17 14:06:34 +00:00
|
|
|
|
Point poly[4];
|
2015-12-06 22:13:58 +00:00
|
|
|
|
SetPoly(NSRectToSnappedRect(aRect, aAppUnitsPerDevPixel, aDrawTarget),
|
2014-10-22 11:29:06 +00:00
|
|
|
|
poly);
|
2014-10-17 14:06:34 +00:00
|
|
|
|
|
|
|
|
|
Float startBevelOffset =
|
2014-10-20 09:55:49 +00:00
|
|
|
|
NSAppUnitsToFloatPixels(aStartBevelOffset, aAppUnitsPerDevPixel);
|
2002-02-19 15:48:28 +00:00
|
|
|
|
switch(aStartBevelSide) {
|
|
|
|
|
case NS_SIDE_TOP:
|
2014-10-17 14:06:34 +00:00
|
|
|
|
poly[0].x += startBevelOffset;
|
2002-02-19 15:48:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case NS_SIDE_BOTTOM:
|
2014-10-17 14:06:34 +00:00
|
|
|
|
poly[3].x += startBevelOffset;
|
2002-02-19 15:48:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case NS_SIDE_RIGHT:
|
2014-10-17 14:06:34 +00:00
|
|
|
|
poly[1].y += startBevelOffset;
|
2002-02-19 15:48:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case NS_SIDE_LEFT:
|
2014-10-17 14:06:34 +00:00
|
|
|
|
poly[0].y += startBevelOffset;
|
2002-02-19 15:48:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-17 14:06:34 +00:00
|
|
|
|
Float endBevelOffset =
|
2014-10-20 09:55:49 +00:00
|
|
|
|
NSAppUnitsToFloatPixels(aEndBevelOffset, aAppUnitsPerDevPixel);
|
2002-02-19 15:48:28 +00:00
|
|
|
|
switch(aEndBevelSide) {
|
|
|
|
|
case NS_SIDE_TOP:
|
2014-10-17 14:06:34 +00:00
|
|
|
|
poly[1].x -= endBevelOffset;
|
2002-02-19 15:48:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case NS_SIDE_BOTTOM:
|
2014-10-17 14:06:34 +00:00
|
|
|
|
poly[2].x -= endBevelOffset;
|
2002-02-19 15:48:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case NS_SIDE_RIGHT:
|
2014-10-17 14:06:34 +00:00
|
|
|
|
poly[2].y -= endBevelOffset;
|
2002-02-19 15:48:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case NS_SIDE_LEFT:
|
2014-10-17 14:06:34 +00:00
|
|
|
|
poly[3].y -= endBevelOffset;
|
2002-02-19 15:48:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-06 22:13:58 +00:00
|
|
|
|
RefPtr<PathBuilder> builder = aDrawTarget.CreatePathBuilder();
|
2014-10-17 14:06:34 +00:00
|
|
|
|
builder->MoveTo(poly[0]);
|
|
|
|
|
builder->LineTo(poly[1]);
|
|
|
|
|
builder->LineTo(poly[2]);
|
|
|
|
|
builder->LineTo(poly[3]);
|
|
|
|
|
builder->Close();
|
2015-10-18 05:24:48 +00:00
|
|
|
|
RefPtr<Path> path = builder->Finish();
|
2015-12-06 22:13:58 +00:00
|
|
|
|
aDrawTarget.Fill(path, color, drawOptions);
|
2002-02-19 15:48:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
GetDashInfo(nscoord aBorderLength,
|
|
|
|
|
nscoord aDashLength,
|
|
|
|
|
nscoord aTwipsPerPixel,
|
2012-08-22 15:56:38 +00:00
|
|
|
|
int32_t& aNumDashSpaces,
|
2002-02-19 15:48:28 +00:00
|
|
|
|
nscoord& aStartDashLength,
|
|
|
|
|
nscoord& aEndDashLength)
|
|
|
|
|
{
|
|
|
|
|
aNumDashSpaces = 0;
|
|
|
|
|
if (aStartDashLength + aDashLength + aEndDashLength >= aBorderLength) {
|
|
|
|
|
aStartDashLength = aBorderLength;
|
|
|
|
|
aEndDashLength = 0;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2009-02-08 16:42:01 +00:00
|
|
|
|
aNumDashSpaces = (aBorderLength - aDashLength)/ (2 * aDashLength); // round down
|
2002-02-19 15:48:28 +00:00
|
|
|
|
nscoord extra = aBorderLength - aStartDashLength - aEndDashLength - (((2 * aNumDashSpaces) - 1) * aDashLength);
|
|
|
|
|
if (extra > 0) {
|
|
|
|
|
nscoord half = RoundIntToPixel(extra / 2, aTwipsPerPixel);
|
|
|
|
|
aStartDashLength += half;
|
|
|
|
|
aEndDashLength += (extra - half);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-27 16:15:01 +00:00
|
|
|
|
void
|
2016-01-08 04:20:06 +00:00
|
|
|
|
nsCSSRendering::DrawTableBorderSegment(DrawTarget& aDrawTarget,
|
2012-08-22 15:56:38 +00:00
|
|
|
|
uint8_t aBorderStyle,
|
2002-02-19 15:48:28 +00:00
|
|
|
|
nscolor aBorderColor,
|
|
|
|
|
const nsStyleBackground* aBGColor,
|
|
|
|
|
const nsRect& aBorder,
|
2014-10-20 09:55:49 +00:00
|
|
|
|
int32_t aAppUnitsPerDevPixel,
|
2012-08-22 15:56:38 +00:00
|
|
|
|
int32_t aAppUnitsPerCSSPixel,
|
|
|
|
|
uint8_t aStartBevelSide,
|
2002-02-19 15:48:28 +00:00
|
|
|
|
nscoord aStartBevelOffset,
|
2012-08-22 15:56:38 +00:00
|
|
|
|
uint8_t aEndBevelSide,
|
2002-02-19 15:48:28 +00:00
|
|
|
|
nscoord aEndBevelOffset)
|
|
|
|
|
{
|
2011-09-29 06:19:26 +00:00
|
|
|
|
bool horizontal = ((NS_SIDE_TOP == aStartBevelSide) || (NS_SIDE_BOTTOM == aStartBevelSide));
|
2007-02-23 17:52:09 +00:00
|
|
|
|
nscoord twipsPerPixel = NSIntPixelsToAppUnits(1, aAppUnitsPerCSSPixel);
|
2012-08-22 15:56:38 +00:00
|
|
|
|
uint8_t ridgeGroove = NS_STYLE_BORDER_STYLE_RIDGE;
|
2002-02-19 15:48:28 +00:00
|
|
|
|
|
|
|
|
|
if ((twipsPerPixel >= aBorder.width) || (twipsPerPixel >= aBorder.height) ||
|
|
|
|
|
(NS_STYLE_BORDER_STYLE_DASHED == aBorderStyle) || (NS_STYLE_BORDER_STYLE_DOTTED == aBorderStyle)) {
|
|
|
|
|
// no beveling for 1 pixel border, dash or dot
|
|
|
|
|
aStartBevelOffset = 0;
|
|
|
|
|
aEndBevelOffset = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (aBorderStyle) {
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_NONE:
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_HIDDEN:
|
2011-10-17 14:59:28 +00:00
|
|
|
|
//NS_ASSERTION(false, "style of none or hidden");
|
2002-02-19 15:48:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_DOTTED:
|
2010-04-27 16:15:01 +00:00
|
|
|
|
case NS_STYLE_BORDER_STYLE_DASHED:
|
2002-02-19 15:48:28 +00:00
|
|
|
|
{
|
|
|
|
|
nscoord dashLength = (NS_STYLE_BORDER_STYLE_DASHED == aBorderStyle) ? DASH_LENGTH : DOT_LENGTH;
|
|
|
|
|
// make the dash length proportional to the border thickness
|
|
|
|
|
dashLength *= (horizontal) ? aBorder.height : aBorder.width;
|
|
|
|
|
// make the min dash length for the ends 1/2 the dash length
|
2010-04-27 16:15:01 +00:00
|
|
|
|
nscoord minDashLength = (NS_STYLE_BORDER_STYLE_DASHED == aBorderStyle)
|
2002-02-19 15:48:28 +00:00
|
|
|
|
? RoundFloatToPixel(((float)dashLength) / 2.0f, twipsPerPixel) : dashLength;
|
2013-01-15 12:22:03 +00:00
|
|
|
|
minDashLength = std::max(minDashLength, twipsPerPixel);
|
2002-02-19 15:48:28 +00:00
|
|
|
|
nscoord numDashSpaces = 0;
|
|
|
|
|
nscoord startDashLength = minDashLength;
|
|
|
|
|
nscoord endDashLength = minDashLength;
|
|
|
|
|
if (horizontal) {
|
2015-07-03 19:22:22 +00:00
|
|
|
|
GetDashInfo(aBorder.width, dashLength, twipsPerPixel, numDashSpaces,
|
|
|
|
|
startDashLength, endDashLength);
|
2002-02-19 15:48:28 +00:00
|
|
|
|
nsRect rect(aBorder.x, aBorder.y, startDashLength, aBorder.height);
|
2016-01-08 04:20:06 +00:00
|
|
|
|
DrawSolidBorderSegment(aDrawTarget, rect, aBorderColor,
|
2015-07-03 19:22:22 +00:00
|
|
|
|
aAppUnitsPerDevPixel, twipsPerPixel);
|
|
|
|
|
|
|
|
|
|
rect.x += startDashLength + dashLength;
|
|
|
|
|
rect.width = aBorder.width
|
|
|
|
|
- (startDashLength + endDashLength + dashLength);
|
2016-01-08 04:20:06 +00:00
|
|
|
|
DrawDashedSegment(aDrawTarget, rect, dashLength, aBorderColor,
|
2015-07-03 19:22:22 +00:00
|
|
|
|
aAppUnitsPerDevPixel, twipsPerPixel, horizontal);
|
|
|
|
|
|
|
|
|
|
rect.x += rect.width;
|
|
|
|
|
rect.width = endDashLength;
|
2016-01-08 04:20:06 +00:00
|
|
|
|
DrawSolidBorderSegment(aDrawTarget, rect, aBorderColor,
|
2015-07-03 19:22:22 +00:00
|
|
|
|
aAppUnitsPerDevPixel, twipsPerPixel);
|
2002-02-19 15:48:28 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
2015-07-03 19:22:22 +00:00
|
|
|
|
GetDashInfo(aBorder.height, dashLength, twipsPerPixel, numDashSpaces,
|
|
|
|
|
startDashLength, endDashLength);
|
2002-02-19 15:48:28 +00:00
|
|
|
|
nsRect rect(aBorder.x, aBorder.y, aBorder.width, startDashLength);
|
2016-01-08 04:20:06 +00:00
|
|
|
|
DrawSolidBorderSegment(aDrawTarget, rect, aBorderColor,
|
2015-07-03 19:22:22 +00:00
|
|
|
|
aAppUnitsPerDevPixel, twipsPerPixel);
|
|
|
|
|
|
|
|
|
|
rect.y += rect.height + dashLength;
|
|
|
|
|
rect.height = aBorder.height
|
|
|
|
|
- (startDashLength + endDashLength + dashLength);
|
2016-01-08 04:20:06 +00:00
|
|
|
|
DrawDashedSegment(aDrawTarget, rect, dashLength, aBorderColor,
|
2015-07-03 19:22:22 +00:00
|
|
|
|
aAppUnitsPerDevPixel, twipsPerPixel, horizontal);
|
|
|
|
|
|
|
|
|
|
rect.y += rect.height;
|
|
|
|
|
rect.height = endDashLength;
|
2016-01-08 04:20:06 +00:00
|
|
|
|
DrawSolidBorderSegment(aDrawTarget, rect, aBorderColor,
|
2015-07-03 19:22:22 +00:00
|
|
|
|
aAppUnitsPerDevPixel, twipsPerPixel);
|
2002-02-19 15:48:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2010-04-27 16:15:01 +00:00
|
|
|
|
break;
|
2002-02-19 15:48:28 +00:00
|
|
|
|
case NS_STYLE_BORDER_STYLE_GROOVE:
|
|
|
|
|
ridgeGroove = NS_STYLE_BORDER_STYLE_GROOVE; // and fall through to ridge
|
2015-11-23 05:33:47 +00:00
|
|
|
|
MOZ_FALLTHROUGH;
|
2002-02-19 15:48:28 +00:00
|
|
|
|
case NS_STYLE_BORDER_STYLE_RIDGE:
|
|
|
|
|
if ((horizontal && (twipsPerPixel >= aBorder.height)) ||
|
|
|
|
|
(!horizontal && (twipsPerPixel >= aBorder.width))) {
|
|
|
|
|
// a one pixel border
|
2016-01-08 04:20:06 +00:00
|
|
|
|
DrawSolidBorderSegment(aDrawTarget, aBorder, aBorderColor,
|
2015-12-06 22:13:58 +00:00
|
|
|
|
aAppUnitsPerDevPixel, twipsPerPixel,
|
2014-10-17 14:06:34 +00:00
|
|
|
|
aStartBevelSide, aStartBevelOffset,
|
2002-02-19 15:48:28 +00:00
|
|
|
|
aEndBevelSide, aEndBevelOffset);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2010-04-27 16:15:01 +00:00
|
|
|
|
nscoord startBevel = (aStartBevelOffset > 0)
|
2011-10-17 14:59:28 +00:00
|
|
|
|
? RoundFloatToPixel(0.5f * (float)aStartBevelOffset, twipsPerPixel, true) : 0;
|
2010-04-27 16:15:01 +00:00
|
|
|
|
nscoord endBevel = (aEndBevelOffset > 0)
|
2011-10-17 14:59:28 +00:00
|
|
|
|
? RoundFloatToPixel(0.5f * (float)aEndBevelOffset, twipsPerPixel, true) : 0;
|
2010-04-27 16:15:02 +00:00
|
|
|
|
mozilla::css::Side ridgeGrooveSide = (horizontal) ? NS_SIDE_TOP : NS_SIDE_LEFT;
|
2010-04-03 01:58:26 +00:00
|
|
|
|
// FIXME: In theory, this should use the visited-dependent
|
|
|
|
|
// background color, but I don't care.
|
2015-07-23 15:51:09 +00:00
|
|
|
|
nscolor bevelColor = MakeBevelColor(ridgeGrooveSide, ridgeGroove,
|
|
|
|
|
aBGColor->mBackgroundColor,
|
|
|
|
|
aBorderColor);
|
2002-02-19 15:48:28 +00:00
|
|
|
|
nsRect rect(aBorder);
|
|
|
|
|
nscoord half;
|
|
|
|
|
if (horizontal) { // top, bottom
|
|
|
|
|
half = RoundFloatToPixel(0.5f * (float)aBorder.height, twipsPerPixel);
|
|
|
|
|
rect.height = half;
|
|
|
|
|
if (NS_SIDE_TOP == aStartBevelSide) {
|
|
|
|
|
rect.x += startBevel;
|
|
|
|
|
rect.width -= startBevel;
|
|
|
|
|
}
|
|
|
|
|
if (NS_SIDE_TOP == aEndBevelSide) {
|
|
|
|
|
rect.width -= endBevel;
|
|
|
|
|
}
|
2016-01-08 04:20:06 +00:00
|
|
|
|
DrawSolidBorderSegment(aDrawTarget, rect, bevelColor,
|
2015-12-06 22:13:58 +00:00
|
|
|
|
aAppUnitsPerDevPixel, twipsPerPixel,
|
|
|
|
|
aStartBevelSide, startBevel, aEndBevelSide,
|
|
|
|
|
endBevel);
|
2002-02-19 15:48:28 +00:00
|
|
|
|
}
|
|
|
|
|
else { // left, right
|
|
|
|
|
half = RoundFloatToPixel(0.5f * (float)aBorder.width, twipsPerPixel);
|
|
|
|
|
rect.width = half;
|
|
|
|
|
if (NS_SIDE_LEFT == aStartBevelSide) {
|
|
|
|
|
rect.y += startBevel;
|
|
|
|
|
rect.height -= startBevel;
|
|
|
|
|
}
|
|
|
|
|
if (NS_SIDE_LEFT == aEndBevelSide) {
|
|
|
|
|
rect.height -= endBevel;
|
|
|
|
|
}
|
2016-01-08 04:20:06 +00:00
|
|
|
|
DrawSolidBorderSegment(aDrawTarget, rect, bevelColor,
|
2015-12-06 22:13:58 +00:00
|
|
|
|
aAppUnitsPerDevPixel, twipsPerPixel,
|
|
|
|
|
aStartBevelSide, startBevel, aEndBevelSide,
|
|
|
|
|
endBevel);
|
2002-02-19 15:48:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rect = aBorder;
|
|
|
|
|
ridgeGrooveSide = (NS_SIDE_TOP == ridgeGrooveSide) ? NS_SIDE_BOTTOM : NS_SIDE_RIGHT;
|
2010-04-03 01:58:26 +00:00
|
|
|
|
// FIXME: In theory, this should use the visited-dependent
|
|
|
|
|
// background color, but I don't care.
|
2015-07-23 15:51:09 +00:00
|
|
|
|
bevelColor = MakeBevelColor(ridgeGrooveSide, ridgeGroove,
|
|
|
|
|
aBGColor->mBackgroundColor, aBorderColor);
|
2002-02-19 15:48:28 +00:00
|
|
|
|
if (horizontal) {
|
|
|
|
|
rect.y = rect.y + half;
|
|
|
|
|
rect.height = aBorder.height - half;
|
|
|
|
|
if (NS_SIDE_BOTTOM == aStartBevelSide) {
|
|
|
|
|
rect.x += startBevel;
|
|
|
|
|
rect.width -= startBevel;
|
|
|
|
|
}
|
|
|
|
|
if (NS_SIDE_BOTTOM == aEndBevelSide) {
|
|
|
|
|
rect.width -= endBevel;
|
|
|
|
|
}
|
2016-01-08 04:20:06 +00:00
|
|
|
|
DrawSolidBorderSegment(aDrawTarget, rect, bevelColor,
|
2015-12-06 22:13:58 +00:00
|
|
|
|
aAppUnitsPerDevPixel, twipsPerPixel,
|
|
|
|
|
aStartBevelSide, startBevel, aEndBevelSide,
|
|
|
|
|
endBevel);
|
2002-02-19 15:48:28 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
rect.x = rect.x + half;
|
|
|
|
|
rect.width = aBorder.width - half;
|
|
|
|
|
if (NS_SIDE_RIGHT == aStartBevelSide) {
|
|
|
|
|
rect.y += aStartBevelOffset - startBevel;
|
|
|
|
|
rect.height -= startBevel;
|
|
|
|
|
}
|
|
|
|
|
if (NS_SIDE_RIGHT == aEndBevelSide) {
|
|
|
|
|
rect.height -= endBevel;
|
|
|
|
|
}
|
2016-01-08 04:20:06 +00:00
|
|
|
|
DrawSolidBorderSegment(aDrawTarget, rect, bevelColor,
|
2015-12-06 22:13:58 +00:00
|
|
|
|
aAppUnitsPerDevPixel, twipsPerPixel,
|
|
|
|
|
aStartBevelSide, startBevel, aEndBevelSide,
|
|
|
|
|
endBevel);
|
2002-02-19 15:48:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_DOUBLE:
|
2011-05-04 17:57:01 +00:00
|
|
|
|
// We can only do "double" borders if the thickness of the border
|
|
|
|
|
// is more than 2px. Otherwise, we fall through to painting a
|
|
|
|
|
// solid border.
|
|
|
|
|
if ((aBorder.width > 2*twipsPerPixel || horizontal) &&
|
|
|
|
|
(aBorder.height > 2*twipsPerPixel || !horizontal)) {
|
2010-04-27 16:15:01 +00:00
|
|
|
|
nscoord startBevel = (aStartBevelOffset > 0)
|
2002-02-19 15:48:28 +00:00
|
|
|
|
? RoundFloatToPixel(0.333333f * (float)aStartBevelOffset, twipsPerPixel) : 0;
|
2010-04-27 16:15:01 +00:00
|
|
|
|
nscoord endBevel = (aEndBevelOffset > 0)
|
2002-02-19 15:48:28 +00:00
|
|
|
|
? RoundFloatToPixel(0.333333f * (float)aEndBevelOffset, twipsPerPixel) : 0;
|
|
|
|
|
if (horizontal) { // top, bottom
|
|
|
|
|
nscoord thirdHeight = RoundFloatToPixel(0.333333f * (float)aBorder.height, twipsPerPixel);
|
|
|
|
|
|
|
|
|
|
// draw the top line or rect
|
|
|
|
|
nsRect topRect(aBorder.x, aBorder.y, aBorder.width, thirdHeight);
|
|
|
|
|
if (NS_SIDE_TOP == aStartBevelSide) {
|
|
|
|
|
topRect.x += aStartBevelOffset - startBevel;
|
|
|
|
|
topRect.width -= aStartBevelOffset - startBevel;
|
|
|
|
|
}
|
|
|
|
|
if (NS_SIDE_TOP == aEndBevelSide) {
|
|
|
|
|
topRect.width -= aEndBevelOffset - endBevel;
|
|
|
|
|
}
|
2016-01-08 04:20:06 +00:00
|
|
|
|
DrawSolidBorderSegment(aDrawTarget, topRect, aBorderColor,
|
2015-12-06 22:13:58 +00:00
|
|
|
|
aAppUnitsPerDevPixel, twipsPerPixel,
|
|
|
|
|
aStartBevelSide, startBevel, aEndBevelSide,
|
|
|
|
|
endBevel);
|
2002-02-19 15:48:28 +00:00
|
|
|
|
|
|
|
|
|
// draw the botom line or rect
|
2010-04-27 16:15:01 +00:00
|
|
|
|
nscoord heightOffset = aBorder.height - thirdHeight;
|
2002-02-19 15:48:28 +00:00
|
|
|
|
nsRect bottomRect(aBorder.x, aBorder.y + heightOffset, aBorder.width, aBorder.height - heightOffset);
|
|
|
|
|
if (NS_SIDE_BOTTOM == aStartBevelSide) {
|
|
|
|
|
bottomRect.x += aStartBevelOffset - startBevel;
|
|
|
|
|
bottomRect.width -= aStartBevelOffset - startBevel;
|
|
|
|
|
}
|
|
|
|
|
if (NS_SIDE_BOTTOM == aEndBevelSide) {
|
|
|
|
|
bottomRect.width -= aEndBevelOffset - endBevel;
|
|
|
|
|
}
|
2016-01-08 04:20:06 +00:00
|
|
|
|
DrawSolidBorderSegment(aDrawTarget, bottomRect, aBorderColor,
|
2015-12-06 22:13:58 +00:00
|
|
|
|
aAppUnitsPerDevPixel, twipsPerPixel,
|
|
|
|
|
aStartBevelSide, startBevel, aEndBevelSide,
|
|
|
|
|
endBevel);
|
2002-02-19 15:48:28 +00:00
|
|
|
|
}
|
|
|
|
|
else { // left, right
|
|
|
|
|
nscoord thirdWidth = RoundFloatToPixel(0.333333f * (float)aBorder.width, twipsPerPixel);
|
|
|
|
|
|
2010-04-27 16:15:01 +00:00
|
|
|
|
nsRect leftRect(aBorder.x, aBorder.y, thirdWidth, aBorder.height);
|
2002-02-19 15:48:28 +00:00
|
|
|
|
if (NS_SIDE_LEFT == aStartBevelSide) {
|
|
|
|
|
leftRect.y += aStartBevelOffset - startBevel;
|
|
|
|
|
leftRect.height -= aStartBevelOffset - startBevel;
|
|
|
|
|
}
|
|
|
|
|
if (NS_SIDE_LEFT == aEndBevelSide) {
|
|
|
|
|
leftRect.height -= aEndBevelOffset - endBevel;
|
|
|
|
|
}
|
2016-01-08 04:20:06 +00:00
|
|
|
|
DrawSolidBorderSegment(aDrawTarget, leftRect, aBorderColor,
|
2015-12-06 22:13:58 +00:00
|
|
|
|
aAppUnitsPerDevPixel, twipsPerPixel,
|
|
|
|
|
aStartBevelSide, startBevel, aEndBevelSide,
|
|
|
|
|
endBevel);
|
2002-02-19 15:48:28 +00:00
|
|
|
|
|
2010-04-27 16:15:01 +00:00
|
|
|
|
nscoord widthOffset = aBorder.width - thirdWidth;
|
2002-02-19 15:48:28 +00:00
|
|
|
|
nsRect rightRect(aBorder.x + widthOffset, aBorder.y, aBorder.width - widthOffset, aBorder.height);
|
|
|
|
|
if (NS_SIDE_RIGHT == aStartBevelSide) {
|
|
|
|
|
rightRect.y += aStartBevelOffset - startBevel;
|
|
|
|
|
rightRect.height -= aStartBevelOffset - startBevel;
|
|
|
|
|
}
|
|
|
|
|
if (NS_SIDE_RIGHT == aEndBevelSide) {
|
|
|
|
|
rightRect.height -= aEndBevelOffset - endBevel;
|
|
|
|
|
}
|
2016-01-08 04:20:06 +00:00
|
|
|
|
DrawSolidBorderSegment(aDrawTarget, rightRect, aBorderColor,
|
2015-12-06 22:13:58 +00:00
|
|
|
|
aAppUnitsPerDevPixel, twipsPerPixel,
|
|
|
|
|
aStartBevelSide, startBevel, aEndBevelSide,
|
|
|
|
|
endBevel);
|
2002-02-19 15:48:28 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// else fall through to solid
|
2015-11-23 05:33:47 +00:00
|
|
|
|
MOZ_FALLTHROUGH;
|
2002-02-19 15:48:28 +00:00
|
|
|
|
case NS_STYLE_BORDER_STYLE_SOLID:
|
2016-01-08 04:20:06 +00:00
|
|
|
|
DrawSolidBorderSegment(aDrawTarget, aBorder, aBorderColor,
|
2015-12-06 22:13:58 +00:00
|
|
|
|
aAppUnitsPerDevPixel, twipsPerPixel, aStartBevelSide,
|
2002-02-19 15:48:28 +00:00
|
|
|
|
aStartBevelOffset, aEndBevelSide, aEndBevelOffset);
|
|
|
|
|
break;
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_OUTSET:
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_INSET:
|
2011-10-17 14:59:28 +00:00
|
|
|
|
NS_ASSERTION(false, "inset, outset should have been converted to groove, ridge");
|
2002-02-19 15:48:28 +00:00
|
|
|
|
break;
|
2005-03-27 11:36:08 +00:00
|
|
|
|
case NS_STYLE_BORDER_STYLE_AUTO:
|
2011-10-17 14:59:28 +00:00
|
|
|
|
NS_ASSERTION(false, "Unexpected 'auto' table border");
|
2005-03-27 11:36:08 +00:00
|
|
|
|
break;
|
2002-02-19 15:48:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// End table border-collapsing section
|
|
|
|
|
|
2014-10-26 00:15:26 +00:00
|
|
|
|
Rect
|
2014-10-08 09:32:55 +00:00
|
|
|
|
nsCSSRendering::ExpandPaintingRectForDecorationLine(
|
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
|
const uint8_t aStyle,
|
2014-10-26 00:15:26 +00:00
|
|
|
|
const Rect& aClippedRect,
|
|
|
|
|
const Float aICoordInFrame,
|
|
|
|
|
const Float aCycleLength,
|
2014-10-08 09:32:55 +00:00
|
|
|
|
bool aVertical)
|
2012-07-04 05:59:50 +00:00
|
|
|
|
{
|
|
|
|
|
switch (aStyle) {
|
|
|
|
|
case NS_STYLE_TEXT_DECORATION_STYLE_DOTTED:
|
|
|
|
|
case NS_STYLE_TEXT_DECORATION_STYLE_DASHED:
|
|
|
|
|
case NS_STYLE_TEXT_DECORATION_STYLE_WAVY:
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
NS_ERROR("Invalid style was specified");
|
|
|
|
|
return aClippedRect;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
|
nsBlockFrame* block = nullptr;
|
2012-07-04 05:59:50 +00:00
|
|
|
|
// Note that when we paint the decoration lines in relative positioned
|
|
|
|
|
// box, we should paint them like all of the boxes are positioned as static.
|
2014-10-08 09:32:55 +00:00
|
|
|
|
nscoord framePosInBlockAppUnits = 0;
|
2012-07-04 05:59:50 +00:00
|
|
|
|
for (nsIFrame* f = aFrame; f; f = f->GetParent()) {
|
|
|
|
|
block = do_QueryFrame(f);
|
|
|
|
|
if (block) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-10-08 09:32:55 +00:00
|
|
|
|
framePosInBlockAppUnits += aVertical ?
|
|
|
|
|
f->GetNormalPosition().y : f->GetNormalPosition().x;
|
2012-07-04 05:59:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE(block, aClippedRect);
|
|
|
|
|
|
|
|
|
|
nsPresContext *pc = aFrame->PresContext();
|
2014-10-26 00:15:26 +00:00
|
|
|
|
Float framePosInBlock = Float(pc->AppUnitsToGfxUnits(framePosInBlockAppUnits));
|
2014-10-08 09:32:55 +00:00
|
|
|
|
int32_t rectPosInBlock =
|
|
|
|
|
int32_t(NS_round(framePosInBlock + aICoordInFrame));
|
|
|
|
|
int32_t extraStartEdge =
|
|
|
|
|
rectPosInBlock - (rectPosInBlock / int32_t(aCycleLength) * aCycleLength);
|
2014-10-26 00:15:26 +00:00
|
|
|
|
Rect rect(aClippedRect);
|
2014-10-08 09:32:55 +00:00
|
|
|
|
if (aVertical) {
|
|
|
|
|
rect.y -= extraStartEdge;
|
|
|
|
|
rect.height += extraStartEdge;
|
|
|
|
|
} else {
|
|
|
|
|
rect.x -= extraStartEdge;
|
|
|
|
|
rect.width += extraStartEdge;
|
|
|
|
|
}
|
2012-07-04 05:59:50 +00:00
|
|
|
|
return rect;
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-06 08:15:00 +00:00
|
|
|
|
void
|
2016-03-22 08:51:15 +00:00
|
|
|
|
nsCSSRendering::PaintDecorationLine(nsIFrame* aFrame, DrawTarget& aDrawTarget,
|
|
|
|
|
const PaintDecorationLineParams& aParams)
|
2007-08-06 08:15:00 +00:00
|
|
|
|
{
|
2016-03-22 08:51:15 +00:00
|
|
|
|
NS_ASSERTION(aParams.style != NS_STYLE_TEXT_DECORATION_STYLE_NONE,
|
|
|
|
|
"aStyle is none");
|
2009-04-03 07:26:28 +00:00
|
|
|
|
|
2016-03-22 08:51:15 +00:00
|
|
|
|
Rect rect = ToRect(GetTextDecorationRectInternal(aParams.pt, aParams));
|
|
|
|
|
if (rect.IsEmpty() || !rect.Intersects(aParams.dirtyRect)) {
|
2007-08-06 08:15:00 +00:00
|
|
|
|
return;
|
2011-09-16 19:23:29 +00:00
|
|
|
|
}
|
2007-08-06 08:15:00 +00:00
|
|
|
|
|
2016-03-22 08:51:15 +00:00
|
|
|
|
if (aParams.decoration != NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE &&
|
|
|
|
|
aParams.decoration != NS_STYLE_TEXT_DECORATION_LINE_OVERLINE &&
|
|
|
|
|
aParams.decoration != NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH) {
|
2008-01-10 22:10:38 +00:00
|
|
|
|
NS_ERROR("Invalid decoration value!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-22 08:51:15 +00:00
|
|
|
|
Float lineThickness = std::max(NS_round(aParams.lineSize.height), 1.0);
|
2014-10-26 00:15:26 +00:00
|
|
|
|
|
2016-03-22 08:51:15 +00:00
|
|
|
|
ColorPattern color(ToDeviceColor(aParams.color));
|
2014-10-26 00:15:26 +00:00
|
|
|
|
StrokeOptions strokeOptions(lineThickness);
|
|
|
|
|
DrawOptions drawOptions;
|
|
|
|
|
|
|
|
|
|
Float dash[2];
|
2008-01-10 22:10:38 +00:00
|
|
|
|
|
2014-10-26 00:15:26 +00:00
|
|
|
|
AutoPopClips autoPopClips(&aDrawTarget);
|
2008-01-10 22:10:38 +00:00
|
|
|
|
|
2016-03-22 08:51:15 +00:00
|
|
|
|
switch (aParams.style) {
|
2011-03-31 12:26:49 +00:00
|
|
|
|
case NS_STYLE_TEXT_DECORATION_STYLE_SOLID:
|
|
|
|
|
case NS_STYLE_TEXT_DECORATION_STYLE_DOUBLE:
|
2007-08-06 08:15:00 +00:00
|
|
|
|
break;
|
2011-03-31 12:26:49 +00:00
|
|
|
|
case NS_STYLE_TEXT_DECORATION_STYLE_DASHED: {
|
2014-10-26 00:15:26 +00:00
|
|
|
|
autoPopClips.PushClipRect(rect);
|
|
|
|
|
Float dashWidth = lineThickness * DOT_LENGTH * DASH_LENGTH;
|
|
|
|
|
dash[0] = dashWidth;
|
|
|
|
|
dash[1] = dashWidth;
|
|
|
|
|
strokeOptions.mDashPattern = dash;
|
|
|
|
|
strokeOptions.mDashLength = MOZ_ARRAY_LENGTH(dash);
|
|
|
|
|
strokeOptions.mLineCap = CapStyle::BUTT;
|
2016-03-22 08:51:15 +00:00
|
|
|
|
rect = ExpandPaintingRectForDecorationLine(aFrame, aParams.style,
|
|
|
|
|
rect, aParams.icoordInFrame,
|
2014-10-08 09:32:55 +00:00
|
|
|
|
dashWidth * 2,
|
2016-03-22 08:51:15 +00:00
|
|
|
|
aParams.vertical);
|
2009-04-03 07:26:28 +00:00
|
|
|
|
// We should continue to draw the last dash even if it is not in the rect.
|
2011-04-19 03:07:21 +00:00
|
|
|
|
rect.width += dashWidth;
|
2007-08-06 08:15:00 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2011-03-31 12:26:49 +00:00
|
|
|
|
case NS_STYLE_TEXT_DECORATION_STYLE_DOTTED: {
|
2014-10-26 00:15:26 +00:00
|
|
|
|
autoPopClips.PushClipRect(rect);
|
|
|
|
|
Float dashWidth = lineThickness * DOT_LENGTH;
|
2014-10-08 09:32:55 +00:00
|
|
|
|
if (lineThickness > 2.0) {
|
2014-10-26 00:15:26 +00:00
|
|
|
|
dash[0] = 0.f;
|
|
|
|
|
dash[1] = dashWidth * 2.f;
|
|
|
|
|
strokeOptions.mLineCap = CapStyle::ROUND;
|
2007-08-06 08:15:00 +00:00
|
|
|
|
} else {
|
|
|
|
|
dash[0] = dashWidth;
|
|
|
|
|
dash[1] = dashWidth;
|
|
|
|
|
}
|
2014-10-26 00:15:26 +00:00
|
|
|
|
strokeOptions.mDashPattern = dash;
|
|
|
|
|
strokeOptions.mDashLength = MOZ_ARRAY_LENGTH(dash);
|
2016-03-22 08:51:15 +00:00
|
|
|
|
rect = ExpandPaintingRectForDecorationLine(aFrame, aParams.style,
|
|
|
|
|
rect, aParams.icoordInFrame,
|
2014-10-08 09:32:55 +00:00
|
|
|
|
dashWidth * 2,
|
2016-03-22 08:51:15 +00:00
|
|
|
|
aParams.vertical);
|
2009-04-03 07:26:28 +00:00
|
|
|
|
// We should continue to draw the last dot even if it is not in the rect.
|
2011-04-19 03:07:21 +00:00
|
|
|
|
rect.width += dashWidth;
|
2007-08-06 08:15:00 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2011-03-31 12:26:49 +00:00
|
|
|
|
case NS_STYLE_TEXT_DECORATION_STYLE_WAVY:
|
2014-10-26 00:15:26 +00:00
|
|
|
|
autoPopClips.PushClipRect(rect);
|
2014-10-08 09:32:55 +00:00
|
|
|
|
if (lineThickness > 2.0) {
|
2014-10-26 00:15:26 +00:00
|
|
|
|
drawOptions.mAntialiasMode = AntialiasMode::SUBPIXEL;
|
2009-04-03 07:26:28 +00:00
|
|
|
|
} else {
|
|
|
|
|
// Don't use anti-aliasing here. Because looks like lighter color wavy
|
|
|
|
|
// line at this case. And probably, users don't think the
|
|
|
|
|
// non-anti-aliased wavy line is not pretty.
|
2014-10-26 00:15:26 +00:00
|
|
|
|
drawOptions.mAntialiasMode = AntialiasMode::NONE;
|
2009-04-03 07:26:28 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2007-08-06 08:15:00 +00:00
|
|
|
|
default:
|
|
|
|
|
NS_ERROR("Invalid style value!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-13 08:58:06 +00:00
|
|
|
|
// The block-direction position should be set to the middle of the line.
|
2016-03-22 08:51:15 +00:00
|
|
|
|
if (aParams.vertical) {
|
2014-12-04 08:57:18 +00:00
|
|
|
|
rect.x += lineThickness / 2;
|
2014-11-13 08:58:06 +00:00
|
|
|
|
} else {
|
|
|
|
|
rect.y += lineThickness / 2;
|
|
|
|
|
}
|
2007-08-06 08:15:00 +00:00
|
|
|
|
|
2016-03-22 08:51:15 +00:00
|
|
|
|
switch (aParams.style) {
|
2011-03-31 12:26:49 +00:00
|
|
|
|
case NS_STYLE_TEXT_DECORATION_STYLE_SOLID:
|
2014-10-08 09:32:55 +00:00
|
|
|
|
case NS_STYLE_TEXT_DECORATION_STYLE_DOTTED:
|
2014-10-26 00:15:26 +00:00
|
|
|
|
case NS_STYLE_TEXT_DECORATION_STYLE_DASHED: {
|
|
|
|
|
Point p1 = rect.TopLeft();
|
2016-03-22 08:51:15 +00:00
|
|
|
|
Point p2 = aParams.vertical ? rect.BottomLeft() : rect.TopRight();
|
2014-10-26 00:15:26 +00:00
|
|
|
|
aDrawTarget.StrokeLine(p1, p2, color, strokeOptions, drawOptions);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
case NS_STYLE_TEXT_DECORATION_STYLE_DOUBLE: {
|
2009-04-03 07:26:28 +00:00
|
|
|
|
/**
|
|
|
|
|
* We are drawing double line as:
|
|
|
|
|
*
|
|
|
|
|
* +-------------------------------------------+
|
|
|
|
|
* |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX| ^
|
2014-10-08 09:32:55 +00:00
|
|
|
|
* |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX| | lineThickness
|
2009-04-03 07:26:28 +00:00
|
|
|
|
* |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX| v
|
|
|
|
|
* | |
|
|
|
|
|
* | |
|
|
|
|
|
* |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX| ^
|
2014-10-08 09:32:55 +00:00
|
|
|
|
* |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX| | lineThickness
|
2009-04-03 07:26:28 +00:00
|
|
|
|
* |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX| v
|
|
|
|
|
* +-------------------------------------------+
|
|
|
|
|
*/
|
2014-10-26 00:15:26 +00:00
|
|
|
|
Point p1 = rect.TopLeft();
|
2016-03-22 08:51:15 +00:00
|
|
|
|
Point p2 = aParams.vertical ? rect.BottomLeft() : rect.TopRight();
|
2014-10-26 00:15:26 +00:00
|
|
|
|
aDrawTarget.StrokeLine(p1, p2, color, strokeOptions, drawOptions);
|
|
|
|
|
|
2016-03-22 08:51:15 +00:00
|
|
|
|
if (aParams.vertical) {
|
2014-10-08 09:32:55 +00:00
|
|
|
|
rect.width -= lineThickness;
|
|
|
|
|
} else {
|
|
|
|
|
rect.height -= lineThickness;
|
|
|
|
|
}
|
2014-10-26 00:15:26 +00:00
|
|
|
|
|
2016-03-22 08:51:15 +00:00
|
|
|
|
p1 = aParams.vertical ? rect.TopRight() : rect.BottomLeft();
|
2014-10-26 00:15:26 +00:00
|
|
|
|
p2 = rect.BottomRight();
|
|
|
|
|
aDrawTarget.StrokeLine(p1, p2, color, strokeOptions, drawOptions);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-03-31 12:26:49 +00:00
|
|
|
|
case NS_STYLE_TEXT_DECORATION_STYLE_WAVY: {
|
2009-04-03 07:26:28 +00:00
|
|
|
|
/**
|
|
|
|
|
* We are drawing wavy line as:
|
|
|
|
|
*
|
|
|
|
|
* P: Path, X: Painted pixel
|
|
|
|
|
*
|
|
|
|
|
* +---------------------------------------+
|
|
|
|
|
* XX|X XXXXXX XXXXXX |
|
|
|
|
|
* PP|PX XPPPPPPX XPPPPPPX | ^
|
|
|
|
|
* XX|XPX XPXXXXXXPX XPXXXXXXPX| |
|
|
|
|
|
* | XPX XPX XPX XPX XP|X |adv
|
|
|
|
|
* | XPXXXXXXPX XPXXXXXXPX X|PX |
|
|
|
|
|
* | XPPPPPPX XPPPPPPX |XPX v
|
|
|
|
|
* | XXXXXX XXXXXX | XX
|
|
|
|
|
* +---------------------------------------+
|
|
|
|
|
* <---><---> ^
|
|
|
|
|
* adv flatLengthAtVertex rightMost
|
|
|
|
|
*
|
|
|
|
|
* 1. Always starts from top-left of the drawing area, however, we need
|
|
|
|
|
* to draw the line from outside of the rect. Because the start
|
|
|
|
|
* point of the line is not good style if we draw from inside it.
|
|
|
|
|
* 2. First, draw horizontal line from outside the rect to top-left of
|
|
|
|
|
* the rect;
|
|
|
|
|
* 3. Goes down to bottom of the area at 45 degrees.
|
|
|
|
|
* 4. Slides to right horizontaly, see |flatLengthAtVertex|.
|
|
|
|
|
* 5. Goes up to top of the area at 45 degrees.
|
|
|
|
|
* 6. Slides to right horizontaly.
|
|
|
|
|
* 7. Repeat from 2 until reached to right-most edge of the area.
|
2014-10-08 09:32:55 +00:00
|
|
|
|
*
|
|
|
|
|
* In the vertical case, swap horizontal and vertical coordinates and
|
|
|
|
|
* directions in the above description.
|
2009-04-03 07:26:28 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2016-03-22 08:51:15 +00:00
|
|
|
|
Float& rectICoord = aParams.vertical ? rect.y : rect.x;
|
|
|
|
|
Float& rectISize = aParams.vertical ? rect.height : rect.width;
|
|
|
|
|
const Float rectBSize = aParams.vertical ? rect.width : rect.height;
|
2014-10-08 09:32:55 +00:00
|
|
|
|
|
2014-10-26 00:15:26 +00:00
|
|
|
|
const Float adv = rectBSize - lineThickness;
|
|
|
|
|
const Float flatLengthAtVertex =
|
2014-10-08 09:32:55 +00:00
|
|
|
|
std::max((lineThickness - 1.0) * 2.0, 1.0);
|
2011-09-16 19:23:29 +00:00
|
|
|
|
|
2012-07-04 05:59:50 +00:00
|
|
|
|
// Align the start of wavy lines to the nearest ancestor block.
|
2014-10-26 00:15:26 +00:00
|
|
|
|
const Float cycleLength = 2 * (adv + flatLengthAtVertex);
|
2016-03-22 08:51:15 +00:00
|
|
|
|
rect = ExpandPaintingRectForDecorationLine(aFrame, aParams.style, rect,
|
|
|
|
|
aParams.icoordInFrame,
|
|
|
|
|
cycleLength, aParams.vertical);
|
2011-09-16 19:23:29 +00:00
|
|
|
|
// figure out if we can trim whole cycles from the left and right edges
|
|
|
|
|
// of the line, to try and avoid creating an unnecessarily long and
|
|
|
|
|
// complex path
|
2016-03-22 08:51:15 +00:00
|
|
|
|
const Float dirtyRectICoord = aParams.vertical ? aParams.dirtyRect.y
|
|
|
|
|
: aParams.dirtyRect.x;
|
2014-10-08 09:32:55 +00:00
|
|
|
|
int32_t skipCycles = floor((dirtyRectICoord - rectICoord) / cycleLength);
|
2011-09-16 19:23:29 +00:00
|
|
|
|
if (skipCycles > 0) {
|
2014-10-08 09:32:55 +00:00
|
|
|
|
rectICoord += skipCycles * cycleLength;
|
|
|
|
|
rectISize -= skipCycles * cycleLength;
|
2011-09-16 19:23:29 +00:00
|
|
|
|
}
|
2009-04-03 07:26:28 +00:00
|
|
|
|
|
2014-10-08 09:32:55 +00:00
|
|
|
|
rectICoord += lineThickness / 2.0;
|
2014-10-26 00:15:26 +00:00
|
|
|
|
Point pt(rect.TopLeft());
|
2016-03-22 08:51:15 +00:00
|
|
|
|
Float& ptICoord = aParams.vertical ? pt.y : pt.x;
|
|
|
|
|
Float& ptBCoord = aParams.vertical ? pt.x : pt.y;
|
|
|
|
|
if (aParams.vertical) {
|
2014-10-08 09:32:55 +00:00
|
|
|
|
ptBCoord += adv + lineThickness / 2.0;
|
|
|
|
|
}
|
2014-10-26 00:15:26 +00:00
|
|
|
|
Float iCoordLimit = ptICoord + rectISize + lineThickness;
|
2011-09-16 19:23:29 +00:00
|
|
|
|
|
2016-03-22 08:51:15 +00:00
|
|
|
|
const Float dirtyRectIMost = aParams.vertical ?
|
|
|
|
|
aParams.dirtyRect.YMost() : aParams.dirtyRect.XMost();
|
2014-10-08 09:32:55 +00:00
|
|
|
|
skipCycles = floor((iCoordLimit - dirtyRectIMost) / cycleLength);
|
2011-09-16 19:23:29 +00:00
|
|
|
|
if (skipCycles > 0) {
|
2014-10-08 09:32:55 +00:00
|
|
|
|
iCoordLimit -= skipCycles * cycleLength;
|
2011-09-16 19:23:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
|
RefPtr<PathBuilder> builder = aDrawTarget.CreatePathBuilder();
|
|
|
|
|
RefPtr<Path> path;
|
2009-04-03 07:26:28 +00:00
|
|
|
|
|
2014-10-08 09:32:55 +00:00
|
|
|
|
ptICoord -= lineThickness;
|
2014-10-26 00:15:26 +00:00
|
|
|
|
builder->MoveTo(pt); // 1
|
2009-04-03 07:26:28 +00:00
|
|
|
|
|
2014-10-08 09:32:55 +00:00
|
|
|
|
ptICoord = rectICoord;
|
2014-10-26 00:15:26 +00:00
|
|
|
|
builder->LineTo(pt); // 2
|
2009-04-03 07:26:28 +00:00
|
|
|
|
|
2014-10-08 09:32:55 +00:00
|
|
|
|
// In vertical mode, to go "down" relative to the text we need to
|
|
|
|
|
// decrease the block coordinate, whereas in horizontal we increase
|
|
|
|
|
// it. So the sense of this flag is effectively inverted.
|
2016-03-22 08:51:15 +00:00
|
|
|
|
bool goDown = aParams.vertical ? false : true;
|
2012-08-22 15:56:38 +00:00
|
|
|
|
uint32_t iter = 0;
|
2014-10-08 09:32:55 +00:00
|
|
|
|
while (ptICoord < iCoordLimit) {
|
2011-09-16 19:23:29 +00:00
|
|
|
|
if (++iter > 1000) {
|
|
|
|
|
// stroke the current path and start again, to avoid pathological
|
|
|
|
|
// behavior in cairo with huge numbers of path segments
|
2014-10-26 00:15:26 +00:00
|
|
|
|
path = builder->Finish();
|
|
|
|
|
aDrawTarget.Stroke(path, color, strokeOptions, drawOptions);
|
|
|
|
|
builder = aDrawTarget.CreatePathBuilder();
|
|
|
|
|
builder->MoveTo(pt);
|
2011-09-16 19:23:29 +00:00
|
|
|
|
iter = 0;
|
|
|
|
|
}
|
2014-10-08 09:32:55 +00:00
|
|
|
|
ptICoord += adv;
|
|
|
|
|
ptBCoord += goDown ? adv : -adv;
|
2009-04-03 07:26:28 +00:00
|
|
|
|
|
2014-10-26 00:15:26 +00:00
|
|
|
|
builder->LineTo(pt); // 3 and 5
|
2009-04-03 07:26:28 +00:00
|
|
|
|
|
2014-10-08 09:32:55 +00:00
|
|
|
|
ptICoord += flatLengthAtVertex;
|
2014-10-26 00:15:26 +00:00
|
|
|
|
builder->LineTo(pt); // 4 and 6
|
2009-04-03 07:26:28 +00:00
|
|
|
|
|
|
|
|
|
goDown = !goDown;
|
|
|
|
|
}
|
2014-10-26 00:15:26 +00:00
|
|
|
|
path = builder->Finish();
|
|
|
|
|
aDrawTarget.Stroke(path, color, strokeOptions, drawOptions);
|
|
|
|
|
return;
|
2009-04-03 07:26:28 +00:00
|
|
|
|
}
|
2007-08-06 08:15:00 +00:00
|
|
|
|
default:
|
|
|
|
|
NS_ERROR("Invalid style value!");
|
2008-01-10 22:10:38 +00:00
|
|
|
|
}
|
2007-08-06 08:15:00 +00:00
|
|
|
|
}
|
2008-02-16 15:31:27 +00:00
|
|
|
|
|
2015-02-03 14:34:14 +00:00
|
|
|
|
Rect
|
2016-03-22 08:51:15 +00:00
|
|
|
|
nsCSSRendering::DecorationLineToPath(const PaintDecorationLineParams& aParams)
|
2012-08-08 11:37:11 +00:00
|
|
|
|
{
|
2016-03-22 08:51:15 +00:00
|
|
|
|
NS_ASSERTION(aParams.style != NS_STYLE_TEXT_DECORATION_STYLE_NONE,
|
|
|
|
|
"aStyle is none");
|
2012-08-08 11:37:11 +00:00
|
|
|
|
|
2015-02-03 14:34:14 +00:00
|
|
|
|
Rect path; // To benefit from RVO, we return this from all return points
|
2012-08-08 11:37:11 +00:00
|
|
|
|
|
2016-03-22 08:51:15 +00:00
|
|
|
|
Rect rect = ToRect(GetTextDecorationRectInternal(aParams.pt, aParams));
|
|
|
|
|
if (rect.IsEmpty() || !rect.Intersects(aParams.dirtyRect)) {
|
2015-02-03 14:34:14 +00:00
|
|
|
|
return path;
|
2012-08-08 11:37:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-22 08:51:15 +00:00
|
|
|
|
if (aParams.decoration != NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE &&
|
|
|
|
|
aParams.decoration != NS_STYLE_TEXT_DECORATION_LINE_OVERLINE &&
|
|
|
|
|
aParams.decoration != NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH) {
|
2012-08-08 11:37:11 +00:00
|
|
|
|
NS_ERROR("Invalid decoration value!");
|
2015-02-03 14:34:14 +00:00
|
|
|
|
return path;
|
2012-08-08 11:37:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-22 08:51:15 +00:00
|
|
|
|
if (aParams.style != NS_STYLE_TEXT_DECORATION_STYLE_SOLID) {
|
2012-08-08 11:37:11 +00:00
|
|
|
|
// For the moment, we support only solid text decorations.
|
2015-02-03 14:34:14 +00:00
|
|
|
|
return path;
|
2012-08-08 11:37:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-22 08:51:15 +00:00
|
|
|
|
Float lineThickness = std::max(NS_round(aParams.lineSize.height), 1.0);
|
2012-08-08 11:37:11 +00:00
|
|
|
|
|
2014-11-13 08:58:06 +00:00
|
|
|
|
// The block-direction position should be set to the middle of the line.
|
2016-03-22 08:51:15 +00:00
|
|
|
|
if (aParams.vertical) {
|
2014-12-04 08:57:18 +00:00
|
|
|
|
rect.x += lineThickness / 2;
|
2015-02-03 14:34:14 +00:00
|
|
|
|
path = Rect(rect.TopLeft() - Point(lineThickness / 2, 0.0),
|
|
|
|
|
Size(lineThickness, rect.Height()));
|
2014-11-13 08:58:06 +00:00
|
|
|
|
} else {
|
|
|
|
|
rect.y += lineThickness / 2;
|
2015-02-03 14:34:14 +00:00
|
|
|
|
path = Rect(rect.TopLeft() - Point(0.0, lineThickness / 2),
|
|
|
|
|
Size(rect.Width(), lineThickness));
|
2014-11-13 08:58:06 +00:00
|
|
|
|
}
|
2015-02-03 14:34:14 +00:00
|
|
|
|
|
|
|
|
|
return path;
|
2012-08-08 11:37:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-02-16 15:31:27 +00:00
|
|
|
|
nsRect
|
|
|
|
|
nsCSSRendering::GetTextDecorationRect(nsPresContext* aPresContext,
|
2016-03-22 08:51:15 +00:00
|
|
|
|
const DecorationRectParams& aParams)
|
2008-02-16 15:31:27 +00:00
|
|
|
|
{
|
|
|
|
|
NS_ASSERTION(aPresContext, "aPresContext is null");
|
2016-03-22 08:51:15 +00:00
|
|
|
|
NS_ASSERTION(aParams.style != NS_STYLE_TEXT_DECORATION_STYLE_NONE,
|
|
|
|
|
"aStyle is none");
|
2008-02-16 15:31:27 +00:00
|
|
|
|
|
2016-03-22 08:51:15 +00:00
|
|
|
|
gfxRect rect = GetTextDecorationRectInternal(Point(0, 0), aParams);
|
2008-02-16 15:31:27 +00:00
|
|
|
|
// The rect values are already rounded to nearest device pixels.
|
|
|
|
|
nsRect r;
|
|
|
|
|
r.x = aPresContext->GfxUnitsToAppUnits(rect.X());
|
|
|
|
|
r.y = aPresContext->GfxUnitsToAppUnits(rect.Y());
|
|
|
|
|
r.width = aPresContext->GfxUnitsToAppUnits(rect.Width());
|
|
|
|
|
r.height = aPresContext->GfxUnitsToAppUnits(rect.Height());
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-03 07:26:28 +00:00
|
|
|
|
gfxRect
|
2015-11-09 04:19:00 +00:00
|
|
|
|
nsCSSRendering::GetTextDecorationRectInternal(const Point& aPt,
|
2016-03-22 08:51:15 +00:00
|
|
|
|
const DecorationRectParams& aParams)
|
2008-02-16 15:31:27 +00:00
|
|
|
|
{
|
2016-03-22 08:51:15 +00:00
|
|
|
|
NS_ASSERTION(aParams.style <= NS_STYLE_TEXT_DECORATION_STYLE_WAVY,
|
2011-03-31 12:26:49 +00:00
|
|
|
|
"Invalid aStyle value");
|
2009-04-03 07:26:28 +00:00
|
|
|
|
|
2016-03-22 08:51:15 +00:00
|
|
|
|
if (aParams.style == NS_STYLE_TEXT_DECORATION_STYLE_NONE)
|
2009-04-03 07:26:28 +00:00
|
|
|
|
return gfxRect(0, 0, 0, 0);
|
|
|
|
|
|
2016-03-22 08:51:15 +00:00
|
|
|
|
bool canLiftUnderline = aParams.descentLimit >= 0.0;
|
2009-04-06 05:53:00 +00:00
|
|
|
|
|
2016-03-22 08:51:15 +00:00
|
|
|
|
gfxFloat iCoord = aParams.vertical ? aPt.y : aPt.x;
|
|
|
|
|
gfxFloat bCoord = aParams.vertical ? aPt.x : aPt.y;
|
2014-10-08 09:32:55 +00:00
|
|
|
|
|
|
|
|
|
// 'left' and 'right' are relative to the line, so for vertical writing modes
|
|
|
|
|
// they will actually become top and bottom of the rendered line.
|
|
|
|
|
// Similarly, aLineSize.width and .height are actually length and thickness
|
|
|
|
|
// of the line, which runs horizontally or vertically according to aVertical.
|
|
|
|
|
const gfxFloat left = floor(iCoord + 0.5),
|
2016-03-22 08:51:15 +00:00
|
|
|
|
right = floor(iCoord + aParams.lineSize.width + 0.5);
|
2014-10-08 09:32:55 +00:00
|
|
|
|
|
|
|
|
|
// We compute |r| as if for a horizontal text run, and then swap vertical
|
|
|
|
|
// and horizontal coordinates at the end if vertical was requested.
|
2011-08-03 18:30:58 +00:00
|
|
|
|
gfxRect r(left, 0, right - left, 0);
|
2008-02-16 15:31:27 +00:00
|
|
|
|
|
2016-03-22 08:51:15 +00:00
|
|
|
|
gfxFloat lineThickness = NS_round(aParams.lineSize.height);
|
2014-10-08 09:32:55 +00:00
|
|
|
|
lineThickness = std::max(lineThickness, 1.0);
|
2009-04-06 05:53:00 +00:00
|
|
|
|
|
2016-03-22 08:51:15 +00:00
|
|
|
|
gfxFloat ascent = NS_round(aParams.ascent);
|
|
|
|
|
gfxFloat descentLimit = floor(aParams.descentLimit);
|
2009-04-06 05:53:00 +00:00
|
|
|
|
|
2013-01-15 12:22:03 +00:00
|
|
|
|
gfxFloat suggestedMaxRectHeight = std::max(std::min(ascent, descentLimit), 1.0);
|
2014-10-08 09:32:55 +00:00
|
|
|
|
r.height = lineThickness;
|
2016-03-22 08:51:15 +00:00
|
|
|
|
if (aParams.style == NS_STYLE_TEXT_DECORATION_STYLE_DOUBLE) {
|
2009-04-03 07:26:28 +00:00
|
|
|
|
/**
|
|
|
|
|
* We will draw double line as:
|
|
|
|
|
*
|
|
|
|
|
* +-------------------------------------------+
|
|
|
|
|
* |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX| ^
|
2014-10-08 09:32:55 +00:00
|
|
|
|
* |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX| | lineThickness
|
2009-04-03 07:26:28 +00:00
|
|
|
|
* |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX| v
|
|
|
|
|
* | | ^
|
|
|
|
|
* | | | gap
|
|
|
|
|
* | | v
|
|
|
|
|
* |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX| ^
|
2014-10-08 09:32:55 +00:00
|
|
|
|
* |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX| | lineThickness
|
2009-04-03 07:26:28 +00:00
|
|
|
|
* |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX| v
|
|
|
|
|
* +-------------------------------------------+
|
|
|
|
|
*/
|
2014-10-08 09:32:55 +00:00
|
|
|
|
gfxFloat gap = NS_round(lineThickness / 2.0);
|
2013-01-15 12:22:03 +00:00
|
|
|
|
gap = std::max(gap, 1.0);
|
2014-10-08 09:32:55 +00:00
|
|
|
|
r.height = lineThickness * 2.0 + gap;
|
2009-04-06 05:53:00 +00:00
|
|
|
|
if (canLiftUnderline) {
|
|
|
|
|
if (r.Height() > suggestedMaxRectHeight) {
|
|
|
|
|
// Don't shrink the line height, because the thickness has some meaning.
|
|
|
|
|
// We can just shrink the gap at this time.
|
2014-10-08 09:32:55 +00:00
|
|
|
|
r.height = std::max(suggestedMaxRectHeight, lineThickness * 2.0 + 1.0);
|
2009-04-06 05:53:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-22 08:51:15 +00:00
|
|
|
|
} else if (aParams.style == NS_STYLE_TEXT_DECORATION_STYLE_WAVY) {
|
2009-04-03 07:26:28 +00:00
|
|
|
|
/**
|
|
|
|
|
* We will draw wavy line as:
|
|
|
|
|
*
|
|
|
|
|
* +-------------------------------------------+
|
|
|
|
|
* |XXXXX XXXXXX XXXXXX | ^
|
2014-10-08 09:32:55 +00:00
|
|
|
|
* |XXXXXX XXXXXXXX XXXXXXXX | | lineThickness
|
2009-04-03 07:26:28 +00:00
|
|
|
|
* |XXXXXXX XXXXXXXXXX XXXXXXXXXX| v
|
|
|
|
|
* | XXX XXX XXX XXX XX|
|
|
|
|
|
* | XXXXXXXXXX XXXXXXXXXX X|
|
|
|
|
|
* | XXXXXXXX XXXXXXXX |
|
|
|
|
|
* | XXXXXX XXXXXX |
|
|
|
|
|
* +-------------------------------------------+
|
|
|
|
|
*/
|
2014-10-08 09:32:55 +00:00
|
|
|
|
r.height = lineThickness > 2.0 ? lineThickness * 4.0 : lineThickness * 3.0;
|
2009-04-06 05:53:00 +00:00
|
|
|
|
if (canLiftUnderline) {
|
|
|
|
|
if (r.Height() > suggestedMaxRectHeight) {
|
|
|
|
|
// Don't shrink the line height even if there is not enough space,
|
|
|
|
|
// because the thickness has some meaning. E.g., the 1px wavy line and
|
|
|
|
|
// 2px wavy line can be used for different meaning in IME selections
|
|
|
|
|
// at same time.
|
2014-10-08 09:32:55 +00:00
|
|
|
|
r.height = std::max(suggestedMaxRectHeight, lineThickness * 2.0);
|
2009-04-06 05:53:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2008-02-16 15:31:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-22 08:51:15 +00:00
|
|
|
|
gfxFloat baseline = floor(bCoord + aParams.ascent + 0.5);
|
2009-04-03 07:26:28 +00:00
|
|
|
|
gfxFloat offset = 0.0;
|
2016-03-22 08:51:15 +00:00
|
|
|
|
switch (aParams.decoration) {
|
2011-04-23 05:16:41 +00:00
|
|
|
|
case NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE:
|
2016-03-22 08:51:15 +00:00
|
|
|
|
offset = aParams.offset;
|
2009-04-06 05:53:00 +00:00
|
|
|
|
if (canLiftUnderline) {
|
|
|
|
|
if (descentLimit < -offset + r.Height()) {
|
|
|
|
|
// If we can ignore the offset and the decoration line is overflowing,
|
|
|
|
|
// we should align the bottom edge of the decoration line rect if it's
|
|
|
|
|
// possible. Otherwise, we should lift up the top edge of the rect as
|
|
|
|
|
// far as possible.
|
|
|
|
|
gfxFloat offsetBottomAligned = -descentLimit + r.Height();
|
2009-06-30 16:52:16 +00:00
|
|
|
|
gfxFloat offsetTopAligned = 0.0;
|
2013-01-15 12:22:03 +00:00
|
|
|
|
offset = std::min(offsetBottomAligned, offsetTopAligned);
|
2009-04-06 05:53:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2008-02-16 15:31:27 +00:00
|
|
|
|
break;
|
2011-04-23 05:16:41 +00:00
|
|
|
|
case NS_STYLE_TEXT_DECORATION_LINE_OVERLINE:
|
2016-03-22 08:51:15 +00:00
|
|
|
|
offset = aParams.offset - lineThickness + r.Height();
|
2008-02-16 15:31:27 +00:00
|
|
|
|
break;
|
2011-04-23 05:16:41 +00:00
|
|
|
|
case NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH: {
|
2011-05-30 19:08:55 +00:00
|
|
|
|
gfxFloat extra = floor(r.Height() / 2.0 + 0.5);
|
2014-10-08 09:32:55 +00:00
|
|
|
|
extra = std::max(extra, lineThickness);
|
2016-03-22 08:51:15 +00:00
|
|
|
|
offset = aParams.offset - lineThickness + extra;
|
2008-02-16 15:31:27 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
NS_ERROR("Invalid decoration value!");
|
|
|
|
|
}
|
2014-10-08 09:32:55 +00:00
|
|
|
|
|
2016-03-22 08:51:15 +00:00
|
|
|
|
if (aParams.vertical) {
|
2015-09-24 09:23:34 +00:00
|
|
|
|
r.y = baseline + floor(offset + 0.5);
|
2014-10-08 09:32:55 +00:00
|
|
|
|
Swap(r.x, r.y);
|
|
|
|
|
Swap(r.width, r.height);
|
|
|
|
|
} else {
|
2015-05-11 10:32:55 +00:00
|
|
|
|
r.y = baseline - floor(offset + 0.5);
|
2014-10-08 09:32:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-02-16 15:31:27 +00:00
|
|
|
|
return r;
|
|
|
|
|
}
|
2008-06-12 22:02:32 +00:00
|
|
|
|
|
2009-08-21 20:39:25 +00:00
|
|
|
|
// ------------------
|
|
|
|
|
// ImageRenderer
|
|
|
|
|
// ------------------
|
2012-05-03 20:11:57 +00:00
|
|
|
|
nsImageRenderer::nsImageRenderer(nsIFrame* aForFrame,
|
|
|
|
|
const nsStyleImage* aImage,
|
2012-08-22 15:56:38 +00:00
|
|
|
|
uint32_t aFlags)
|
2009-08-21 20:39:25 +00:00
|
|
|
|
: mForFrame(aForFrame)
|
|
|
|
|
, mImage(aImage)
|
2010-08-05 21:30:19 +00:00
|
|
|
|
, mType(aImage->GetType())
|
2012-07-30 14:20:58 +00:00
|
|
|
|
, mImageContainer(nullptr)
|
|
|
|
|
, mGradientData(nullptr)
|
|
|
|
|
, mPaintServerFrame(nullptr)
|
2015-10-14 07:02:37 +00:00
|
|
|
|
, mPrepareResult(DrawResult::NOT_READY)
|
2009-08-21 20:39:25 +00:00
|
|
|
|
, mSize(0, 0)
|
2009-09-12 22:44:18 +00:00
|
|
|
|
, mFlags(aFlags)
|
2015-11-23 16:17:35 +00:00
|
|
|
|
, mExtendMode(ExtendMode::CLAMP)
|
2016-03-24 00:32:00 +00:00
|
|
|
|
, mMaskOp(NS_STYLE_MASK_MODE_MATCH_SOURCE)
|
2009-08-21 20:39:25 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-03 20:11:57 +00:00
|
|
|
|
nsImageRenderer::~nsImageRenderer()
|
2009-08-21 20:39:25 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-14 07:02:37 +00:00
|
|
|
|
static bool
|
|
|
|
|
ShouldTreatAsCompleteDueToSyncDecode(const nsStyleImage* aImage,
|
|
|
|
|
uint32_t aFlags)
|
|
|
|
|
{
|
|
|
|
|
if (!(aFlags & nsImageRenderer::FLAG_SYNC_DECODE_IMAGES)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (aImage->GetType() != eStyleImageType_Image) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t status = 0;
|
|
|
|
|
if (NS_FAILED(aImage->GetImageData()->GetImageStatus(&status))) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (status & imgIRequest::STATUS_ERROR) {
|
|
|
|
|
// The image is "complete" since it's a corrupt image. If we created an
|
|
|
|
|
// imgIContainer at all, return true.
|
|
|
|
|
nsCOMPtr<imgIContainer> image;
|
|
|
|
|
aImage->GetImageData()->GetImage(getter_AddRefs(image));
|
|
|
|
|
return bool(image);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!(status & imgIRequest::STATUS_LOAD_COMPLETE)) {
|
|
|
|
|
// We must have loaded all of the image's data and the size must be
|
|
|
|
|
// available, or else sync decoding won't be able to decode the image.
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
|
bool
|
2012-05-03 20:11:57 +00:00
|
|
|
|
nsImageRenderer::PrepareImage()
|
2009-08-21 20:39:25 +00:00
|
|
|
|
{
|
2015-10-14 07:02:37 +00:00
|
|
|
|
if (mImage->IsEmpty()) {
|
|
|
|
|
mPrepareResult = DrawResult::BAD_IMAGE;
|
2012-10-12 20:04:32 +00:00
|
|
|
|
return false;
|
2015-10-14 07:02:37 +00:00
|
|
|
|
}
|
2012-10-12 20:04:32 +00:00
|
|
|
|
|
|
|
|
|
if (!mImage->IsComplete()) {
|
2015-10-14 07:02:37 +00:00
|
|
|
|
// Make sure the image is actually decoding.
|
2012-10-12 20:04:03 +00:00
|
|
|
|
mImage->StartDecoding();
|
2009-09-12 22:44:18 +00:00
|
|
|
|
|
2015-10-14 07:02:37 +00:00
|
|
|
|
// Check again to see if we finished.
|
|
|
|
|
// We cannot prepare the image for rendering if it is not fully loaded.
|
|
|
|
|
// Special case: If we requested a sync decode and the image has loaded, push
|
|
|
|
|
// on through because the Draw() will do a sync decode then.
|
|
|
|
|
if (!mImage->IsComplete() &&
|
|
|
|
|
!ShouldTreatAsCompleteDueToSyncDecode(mImage, mFlags)) {
|
|
|
|
|
mPrepareResult = DrawResult::NOT_READY;
|
|
|
|
|
return false;
|
2012-10-12 20:04:32 +00:00
|
|
|
|
}
|
2009-08-21 20:39:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (mType) {
|
|
|
|
|
case eStyleImageType_Image:
|
|
|
|
|
{
|
|
|
|
|
nsCOMPtr<imgIContainer> srcImage;
|
2012-10-16 23:05:54 +00:00
|
|
|
|
DebugOnly<nsresult> rv =
|
|
|
|
|
mImage->GetImageData()->GetImage(getter_AddRefs(srcImage));
|
2015-02-09 22:34:50 +00:00
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv) && srcImage,
|
|
|
|
|
"If GetImage() is failing, mImage->IsComplete() "
|
|
|
|
|
"should have returned false");
|
2009-08-21 20:39:25 +00:00
|
|
|
|
|
2010-08-05 21:30:19 +00:00
|
|
|
|
if (!mImage->GetCropRect()) {
|
2009-08-21 20:39:25 +00:00
|
|
|
|
mImageContainer.swap(srcImage);
|
|
|
|
|
} else {
|
|
|
|
|
nsIntRect actualCropRect;
|
2011-09-29 06:19:26 +00:00
|
|
|
|
bool isEntireImage;
|
|
|
|
|
bool success =
|
2010-08-05 21:30:19 +00:00
|
|
|
|
mImage->ComputeActualCropRect(actualCropRect, &isEntireImage);
|
2009-08-21 20:39:25 +00:00
|
|
|
|
NS_ASSERTION(success, "ComputeActualCropRect() should not fail here");
|
|
|
|
|
if (!success || actualCropRect.IsEmpty()) {
|
|
|
|
|
// The cropped image has zero size
|
2015-10-14 07:02:37 +00:00
|
|
|
|
mPrepareResult = DrawResult::BAD_IMAGE;
|
2011-10-17 14:59:28 +00:00
|
|
|
|
return false;
|
2009-08-21 20:39:25 +00:00
|
|
|
|
}
|
|
|
|
|
if (isEntireImage) {
|
|
|
|
|
// The cropped image is identical to the source image
|
|
|
|
|
mImageContainer.swap(srcImage);
|
|
|
|
|
} else {
|
2016-03-08 07:54:13 +00:00
|
|
|
|
nsCOMPtr<imgIContainer> subImage = ImageOps::Clip(srcImage,
|
|
|
|
|
actualCropRect,
|
|
|
|
|
Nothing());
|
2009-08-21 20:39:25 +00:00
|
|
|
|
mImageContainer.swap(subImage);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-10-14 07:02:37 +00:00
|
|
|
|
mPrepareResult = DrawResult::SUCCESS;
|
2009-08-21 20:39:25 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case eStyleImageType_Gradient:
|
2010-08-05 21:30:19 +00:00
|
|
|
|
mGradientData = mImage->GetGradientData();
|
2015-10-14 07:02:37 +00:00
|
|
|
|
mPrepareResult = DrawResult::SUCCESS;
|
2009-08-21 20:39:25 +00:00
|
|
|
|
break;
|
2010-08-13 13:34:01 +00:00
|
|
|
|
case eStyleImageType_Element:
|
|
|
|
|
{
|
|
|
|
|
nsAutoString elementId =
|
2010-08-05 21:30:19 +00:00
|
|
|
|
NS_LITERAL_STRING("#") + nsDependentString(mImage->GetElementId());
|
2010-08-13 13:34:01 +00:00
|
|
|
|
nsCOMPtr<nsIURI> targetURI;
|
|
|
|
|
nsCOMPtr<nsIURI> base = mForFrame->GetContent()->GetBaseURI();
|
|
|
|
|
nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(targetURI), elementId,
|
2016-03-31 11:46:32 +00:00
|
|
|
|
mForFrame->GetContent()->GetUncomposedDoc(), base);
|
2010-08-13 13:34:01 +00:00
|
|
|
|
nsSVGPaintingProperty* property = nsSVGEffects::GetPaintingPropertyForURI(
|
2013-09-25 11:42:34 +00:00
|
|
|
|
targetURI, mForFrame->FirstContinuation(),
|
2010-08-13 13:34:01 +00:00
|
|
|
|
nsSVGEffects::BackgroundImageProperty());
|
2015-10-01 18:31:44 +00:00
|
|
|
|
if (!property) {
|
2015-10-14 07:02:37 +00:00
|
|
|
|
mPrepareResult = DrawResult::BAD_IMAGE;
|
2011-10-17 14:59:28 +00:00
|
|
|
|
return false;
|
2015-10-01 18:31:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the referenced element is an <img>, <canvas>, or <video> element,
|
|
|
|
|
// prefer SurfaceFromElement as it's more reliable.
|
|
|
|
|
mImageElementSurface =
|
|
|
|
|
nsLayoutUtils::SurfaceFromElement(property->GetReferencedElement());
|
2015-11-25 04:15:29 +00:00
|
|
|
|
if (!mImageElementSurface.GetSourceSurface()) {
|
2015-10-01 18:31:44 +00:00
|
|
|
|
mPaintServerFrame = property->GetReferencedFrame();
|
|
|
|
|
if (!mPaintServerFrame) {
|
2015-10-14 07:02:37 +00:00
|
|
|
|
mPrepareResult = DrawResult::BAD_IMAGE;
|
2011-10-17 14:59:28 +00:00
|
|
|
|
return false;
|
2015-10-01 18:31:44 +00:00
|
|
|
|
}
|
2010-08-13 13:34:01 +00:00
|
|
|
|
}
|
2015-10-01 18:31:44 +00:00
|
|
|
|
|
2015-10-14 07:02:37 +00:00
|
|
|
|
mPrepareResult = DrawResult::SUCCESS;
|
2010-08-13 13:34:01 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2009-08-21 20:39:25 +00:00
|
|
|
|
case eStyleImageType_Null:
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-14 07:02:37 +00:00
|
|
|
|
return IsReady();
|
2009-08-21 20:39:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-19 08:39:58 +00:00
|
|
|
|
nsSize
|
|
|
|
|
CSSSizeOrRatio::ComputeConcreteSize() const
|
2011-01-13 10:40:12 +00:00
|
|
|
|
{
|
2013-07-19 08:39:58 +00:00
|
|
|
|
NS_ASSERTION(CanComputeConcreteSize(), "Cannot compute");
|
|
|
|
|
if (mHasWidth && mHasHeight) {
|
|
|
|
|
return nsSize(mWidth, mHeight);
|
|
|
|
|
}
|
|
|
|
|
if (mHasWidth) {
|
|
|
|
|
nscoord height = NSCoordSaturatingNonnegativeMultiply(
|
|
|
|
|
mWidth,
|
|
|
|
|
double(mRatio.height) / mRatio.width);
|
|
|
|
|
return nsSize(mWidth, height);
|
2014-01-14 20:57:49 +00:00
|
|
|
|
}
|
2013-07-19 08:39:58 +00:00
|
|
|
|
|
|
|
|
|
MOZ_ASSERT(mHasHeight);
|
|
|
|
|
nscoord width = NSCoordSaturatingNonnegativeMultiply(
|
|
|
|
|
mHeight,
|
2014-01-14 20:57:49 +00:00
|
|
|
|
double(mRatio.width) / mRatio.height);
|
2013-07-19 08:39:58 +00:00
|
|
|
|
return nsSize(width, mHeight);
|
2011-01-13 10:40:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-19 08:39:58 +00:00
|
|
|
|
CSSSizeOrRatio
|
|
|
|
|
nsImageRenderer::ComputeIntrinsicSize()
|
2009-08-21 20:39:25 +00:00
|
|
|
|
{
|
2015-10-14 07:02:37 +00:00
|
|
|
|
NS_ASSERTION(IsReady(), "Ensure PrepareImage() has returned true "
|
|
|
|
|
"before calling me");
|
2009-08-21 20:39:25 +00:00
|
|
|
|
|
2013-07-19 08:39:58 +00:00
|
|
|
|
CSSSizeOrRatio result;
|
2009-08-21 20:39:25 +00:00
|
|
|
|
switch (mType) {
|
|
|
|
|
case eStyleImageType_Image:
|
|
|
|
|
{
|
2013-07-19 08:39:58 +00:00
|
|
|
|
bool haveWidth, haveHeight;
|
2015-03-30 15:35:47 +00:00
|
|
|
|
CSSIntSize imageIntSize;
|
2010-09-08 20:40:39 +00:00
|
|
|
|
nsLayoutUtils::ComputeSizeForDrawing(mImageContainer, imageIntSize,
|
2013-07-19 08:39:58 +00:00
|
|
|
|
result.mRatio, haveWidth, haveHeight);
|
|
|
|
|
if (haveWidth) {
|
|
|
|
|
result.SetWidth(nsPresContext::CSSPixelsToAppUnits(imageIntSize.width));
|
2011-01-13 10:40:12 +00:00
|
|
|
|
}
|
2013-07-19 08:39:58 +00:00
|
|
|
|
if (haveHeight) {
|
|
|
|
|
result.SetHeight(nsPresContext::CSSPixelsToAppUnits(imageIntSize.height));
|
2011-01-13 10:40:12 +00:00
|
|
|
|
}
|
2013-07-19 08:39:58 +00:00
|
|
|
|
break;
|
2009-08-21 20:39:25 +00:00
|
|
|
|
}
|
2010-08-13 13:34:01 +00:00
|
|
|
|
case eStyleImageType_Element:
|
|
|
|
|
{
|
2011-01-13 10:40:12 +00:00
|
|
|
|
// XXX element() should have the width/height of the referenced element,
|
|
|
|
|
// and that element's ratio, if it matches. If it doesn't match, it
|
2014-01-31 03:36:42 +00:00
|
|
|
|
// should have no width/height or ratio. See element() in CSS images:
|
|
|
|
|
// <http://dev.w3.org/csswg/css-images-4/#element-notation>.
|
2016-01-28 05:24:00 +00:00
|
|
|
|
// Make sure to change nsStyleImageLayers::Size::DependsOnFrameSize
|
2011-01-13 10:40:12 +00:00
|
|
|
|
// when fixing this!
|
2010-08-13 13:34:01 +00:00
|
|
|
|
if (mPaintServerFrame) {
|
2013-07-19 08:39:58 +00:00
|
|
|
|
// SVG images have no intrinsic size
|
|
|
|
|
if (!mPaintServerFrame->IsFrameOfType(nsIFrame::eSVG)) {
|
2010-08-13 13:34:01 +00:00
|
|
|
|
// The intrinsic image size for a generic nsIFrame paint server is
|
2012-06-19 15:28:04 +00:00
|
|
|
|
// the union of the border-box rects of all of its continuations,
|
|
|
|
|
// rounded to device pixels.
|
2012-08-22 15:56:38 +00:00
|
|
|
|
int32_t appUnitsPerDevPixel =
|
2010-08-13 13:34:01 +00:00
|
|
|
|
mForFrame->PresContext()->AppUnitsPerDevPixel();
|
2013-07-19 08:39:58 +00:00
|
|
|
|
result.SetSize(
|
2015-03-29 14:59:08 +00:00
|
|
|
|
IntSizeToAppUnits(
|
|
|
|
|
nsSVGIntegrationUtils::GetContinuationUnionSize(mPaintServerFrame).
|
|
|
|
|
ToNearestPixels(appUnitsPerDevPixel),
|
|
|
|
|
appUnitsPerDevPixel));
|
2010-08-13 13:34:01 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2015-11-25 04:15:29 +00:00
|
|
|
|
NS_ASSERTION(mImageElementSurface.GetSourceSurface(),
|
|
|
|
|
"Surface should be ready.");
|
2015-09-23 18:49:05 +00:00
|
|
|
|
IntSize surfaceSize = mImageElementSurface.mSize;
|
2013-07-19 08:39:58 +00:00
|
|
|
|
result.SetSize(
|
|
|
|
|
nsSize(nsPresContext::CSSPixelsToAppUnits(surfaceSize.width),
|
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(surfaceSize.height)));
|
2010-08-13 13:34:01 +00:00
|
|
|
|
}
|
2013-07-19 08:39:58 +00:00
|
|
|
|
break;
|
2010-08-13 13:34:01 +00:00
|
|
|
|
}
|
2013-07-19 08:39:58 +00:00
|
|
|
|
case eStyleImageType_Gradient:
|
|
|
|
|
// Per <http://dev.w3.org/csswg/css3-images/#gradients>, gradients have no
|
|
|
|
|
// intrinsic dimensions.
|
2009-08-21 20:39:25 +00:00
|
|
|
|
case eStyleImageType_Null:
|
|
|
|
|
default:
|
2013-07-19 08:39:58 +00:00
|
|
|
|
break;
|
2011-01-13 10:40:12 +00:00
|
|
|
|
}
|
2013-07-19 08:39:58 +00:00
|
|
|
|
|
|
|
|
|
return result;
|
2011-01-13 10:40:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-19 08:39:58 +00:00
|
|
|
|
/* static */ nsSize
|
|
|
|
|
nsImageRenderer::ComputeConcreteSize(const CSSSizeOrRatio& aSpecifiedSize,
|
|
|
|
|
const CSSSizeOrRatio& aIntrinsicSize,
|
|
|
|
|
const nsSize& aDefaultSize)
|
2011-01-13 10:40:12 +00:00
|
|
|
|
{
|
2013-07-19 08:39:58 +00:00
|
|
|
|
// The specified size is fully specified, just use that
|
|
|
|
|
if (aSpecifiedSize.IsConcrete()) {
|
|
|
|
|
return aSpecifiedSize.ComputeConcreteSize();
|
2009-08-21 20:39:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-19 08:39:58 +00:00
|
|
|
|
MOZ_ASSERT(!aSpecifiedSize.mHasWidth || !aSpecifiedSize.mHasHeight);
|
2011-01-13 10:40:12 +00:00
|
|
|
|
|
2013-07-19 08:39:58 +00:00
|
|
|
|
if (!aSpecifiedSize.mHasWidth && !aSpecifiedSize.mHasHeight) {
|
|
|
|
|
// no specified size, try using the intrinsic size
|
|
|
|
|
if (aIntrinsicSize.CanComputeConcreteSize()) {
|
|
|
|
|
return aIntrinsicSize.ComputeConcreteSize();
|
2011-01-13 10:40:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-19 08:39:58 +00:00
|
|
|
|
if (aIntrinsicSize.mHasWidth) {
|
|
|
|
|
return nsSize(aIntrinsicSize.mWidth, aDefaultSize.height);
|
|
|
|
|
}
|
|
|
|
|
if (aIntrinsicSize.mHasHeight) {
|
|
|
|
|
return nsSize(aDefaultSize.width, aIntrinsicSize.mHeight);
|
2011-01-13 10:40:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-19 08:39:58 +00:00
|
|
|
|
// couldn't use the intrinsic size either, revert to using the default size
|
|
|
|
|
return ComputeConstrainedSize(aDefaultSize,
|
|
|
|
|
aIntrinsicSize.mRatio,
|
|
|
|
|
CONTAIN);
|
|
|
|
|
}
|
2011-01-13 10:40:12 +00:00
|
|
|
|
|
2013-07-19 08:39:58 +00:00
|
|
|
|
MOZ_ASSERT(aSpecifiedSize.mHasWidth || aSpecifiedSize.mHasHeight);
|
2011-01-13 10:40:12 +00:00
|
|
|
|
|
2013-07-19 08:39:58 +00:00
|
|
|
|
// The specified height is partial, try to compute the missing part.
|
|
|
|
|
if (aSpecifiedSize.mHasWidth) {
|
|
|
|
|
nscoord height;
|
|
|
|
|
if (aIntrinsicSize.HasRatio()) {
|
|
|
|
|
height = NSCoordSaturatingNonnegativeMultiply(
|
|
|
|
|
aSpecifiedSize.mWidth,
|
|
|
|
|
double(aIntrinsicSize.mRatio.height) / aIntrinsicSize.mRatio.width);
|
|
|
|
|
} else if (aIntrinsicSize.mHasHeight) {
|
|
|
|
|
height = aIntrinsicSize.mHeight;
|
2011-01-13 10:40:12 +00:00
|
|
|
|
} else {
|
2013-07-19 08:39:58 +00:00
|
|
|
|
height = aDefaultSize.height;
|
2011-01-13 10:40:12 +00:00
|
|
|
|
}
|
2013-07-19 08:39:58 +00:00
|
|
|
|
return nsSize(aSpecifiedSize.mWidth, height);
|
|
|
|
|
}
|
2011-01-13 10:40:12 +00:00
|
|
|
|
|
2013-07-19 08:39:58 +00:00
|
|
|
|
MOZ_ASSERT(aSpecifiedSize.mHasHeight);
|
|
|
|
|
nscoord width;
|
|
|
|
|
if (aIntrinsicSize.HasRatio()) {
|
|
|
|
|
width = NSCoordSaturatingNonnegativeMultiply(
|
|
|
|
|
aSpecifiedSize.mHeight,
|
|
|
|
|
double(aIntrinsicSize.mRatio.width) / aIntrinsicSize.mRatio.height);
|
|
|
|
|
} else if (aIntrinsicSize.mHasWidth) {
|
|
|
|
|
width = aIntrinsicSize.mWidth;
|
|
|
|
|
} else {
|
|
|
|
|
width = aDefaultSize.width;
|
2011-01-13 10:40:12 +00:00
|
|
|
|
}
|
2013-07-19 08:39:58 +00:00
|
|
|
|
return nsSize(width, aSpecifiedSize.mHeight);
|
|
|
|
|
}
|
2011-01-13 10:40:12 +00:00
|
|
|
|
|
2013-07-19 08:39:58 +00:00
|
|
|
|
/* static */ nsSize
|
|
|
|
|
nsImageRenderer::ComputeConstrainedSize(const nsSize& aConstrainingSize,
|
|
|
|
|
const nsSize& aIntrinsicRatio,
|
|
|
|
|
FitType aFitType)
|
|
|
|
|
{
|
|
|
|
|
if (aIntrinsicRatio.width <= 0 && aIntrinsicRatio.height <= 0) {
|
|
|
|
|
return aConstrainingSize;
|
|
|
|
|
}
|
2011-01-13 10:40:12 +00:00
|
|
|
|
|
2013-07-19 08:39:58 +00:00
|
|
|
|
float scaleX = double(aConstrainingSize.width) / aIntrinsicRatio.width;
|
|
|
|
|
float scaleY = double(aConstrainingSize.height) / aIntrinsicRatio.height;
|
2011-01-13 10:40:12 +00:00
|
|
|
|
nsSize size;
|
2013-07-19 08:39:58 +00:00
|
|
|
|
if ((aFitType == CONTAIN) == (scaleX < scaleY)) {
|
|
|
|
|
size.width = aConstrainingSize.width;
|
|
|
|
|
size.height = NSCoordSaturatingNonnegativeMultiply(
|
|
|
|
|
aIntrinsicRatio.height, scaleX);
|
2016-04-07 06:51:45 +00:00
|
|
|
|
// If we're reducing the size by less than one css pixel, then just use the
|
|
|
|
|
// constraining size.
|
|
|
|
|
if (aFitType == CONTAIN && aConstrainingSize.height - size.height < nsPresContext::AppUnitsPerCSSPixel()) {
|
|
|
|
|
size.height = aConstrainingSize.height;
|
|
|
|
|
}
|
2011-01-13 10:40:12 +00:00
|
|
|
|
} else {
|
2013-07-19 08:39:58 +00:00
|
|
|
|
size.width = NSCoordSaturatingNonnegativeMultiply(
|
|
|
|
|
aIntrinsicRatio.width, scaleY);
|
2016-04-07 06:51:45 +00:00
|
|
|
|
if (aFitType == CONTAIN && aConstrainingSize.width - size.width < nsPresContext::AppUnitsPerCSSPixel()) {
|
|
|
|
|
size.width = aConstrainingSize.width;
|
|
|
|
|
}
|
2013-07-19 08:39:58 +00:00
|
|
|
|
size.height = aConstrainingSize.height;
|
2011-01-13 10:40:12 +00:00
|
|
|
|
}
|
|
|
|
|
return size;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-19 08:39:58 +00:00
|
|
|
|
/**
|
|
|
|
|
* mSize is the image's "preferred" size for this particular rendering, while
|
|
|
|
|
* the drawn (aka concrete) size is the actual rendered size after accounting
|
|
|
|
|
* for background-size etc.. The preferred size is most often the image's
|
|
|
|
|
* intrinsic dimensions. But for images with incomplete intrinsic dimensions,
|
|
|
|
|
* the preferred size varies, depending on the specified and default sizes, see
|
|
|
|
|
* nsImageRenderer::Compute*Size.
|
2011-01-13 10:40:12 +00:00
|
|
|
|
*
|
|
|
|
|
* This distinction is necessary because the components of a vector image are
|
|
|
|
|
* specified with respect to its preferred size for a rendering situation, not
|
2013-07-19 08:39:58 +00:00
|
|
|
|
* to its actual rendered size. For example, consider a 4px wide background
|
|
|
|
|
* vector image with no height which contains a left-aligned
|
2011-01-13 10:40:12 +00:00
|
|
|
|
* 2px wide black rectangle with height 100%. If the background-size width is
|
|
|
|
|
* auto (or 4px), the vector image will render 4px wide, and the black rectangle
|
|
|
|
|
* will be 2px wide. If the background-size width is 8px, the vector image will
|
|
|
|
|
* render 8px wide, and the black rectangle will be 4px wide -- *not* 2px wide.
|
|
|
|
|
* In both cases mSize.width will be 4px; but in the first case the returned
|
|
|
|
|
* width will be 4px, while in the second case the returned width will be 8px.
|
|
|
|
|
*/
|
2013-07-19 08:39:58 +00:00
|
|
|
|
void
|
|
|
|
|
nsImageRenderer::SetPreferredSize(const CSSSizeOrRatio& aIntrinsicSize,
|
|
|
|
|
const nsSize& aDefaultSize)
|
2011-01-13 10:40:12 +00:00
|
|
|
|
{
|
2013-07-19 08:39:58 +00:00
|
|
|
|
mSize.width = aIntrinsicSize.mHasWidth
|
|
|
|
|
? aIntrinsicSize.mWidth
|
|
|
|
|
: aDefaultSize.width;
|
|
|
|
|
mSize.height = aIntrinsicSize.mHasHeight
|
|
|
|
|
? aIntrinsicSize.mHeight
|
|
|
|
|
: aDefaultSize.height;
|
2009-08-21 20:39:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-31 22:09:30 +00:00
|
|
|
|
// Convert from nsImageRenderer flags to the flags we want to use for drawing in
|
|
|
|
|
// the imgIContainer namespace.
|
|
|
|
|
static uint32_t
|
|
|
|
|
ConvertImageRendererToDrawFlags(uint32_t aImageRendererFlags)
|
|
|
|
|
{
|
|
|
|
|
uint32_t drawFlags = imgIContainer::FLAG_NONE;
|
|
|
|
|
if (aImageRendererFlags & nsImageRenderer::FLAG_SYNC_DECODE_IMAGES) {
|
|
|
|
|
drawFlags |= imgIContainer::FLAG_SYNC_DECODE;
|
|
|
|
|
}
|
|
|
|
|
if (aImageRendererFlags & nsImageRenderer::FLAG_PAINTING_TO_WINDOW) {
|
|
|
|
|
drawFlags |= imgIContainer::FLAG_HIGH_QUALITY_SCALING;
|
|
|
|
|
}
|
|
|
|
|
return drawFlags;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-24 00:32:00 +00:00
|
|
|
|
/*
|
|
|
|
|
* SVG11: A luminanceToAlpha operation is equivalent to the following matrix operation: |
|
|
|
|
|
* | R' | | 0 0 0 0 0 | | R |
|
|
|
|
|
* | G' | | 0 0 0 0 0 | | G |
|
|
|
|
|
* | B' | = | 0 0 0 0 0 | * | B |
|
|
|
|
|
* | A' | | 0.2125 0.7154 0.0721 0 0 | | A |
|
|
|
|
|
* | 1 | | 0 0 0 0 1 | | 1 |
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
RGBALuminanceOperation(uint8_t *aData,
|
|
|
|
|
int32_t aStride,
|
|
|
|
|
const IntSize &aSize)
|
|
|
|
|
{
|
|
|
|
|
int32_t redFactor = 55; // 256 * 0.2125
|
|
|
|
|
int32_t greenFactor = 183; // 256 * 0.7154
|
|
|
|
|
int32_t blueFactor = 18; // 256 * 0.0721
|
|
|
|
|
|
|
|
|
|
for (int32_t y = 0; y < aSize.height; y++) {
|
|
|
|
|
uint32_t *pixel = (uint32_t*)(aData + aStride * y);
|
|
|
|
|
for (int32_t x = 0; x < aSize.width; x++) {
|
|
|
|
|
*pixel = (((((*pixel & 0x00FF0000) >> 16) * redFactor) +
|
|
|
|
|
(((*pixel & 0x0000FF00) >> 8) * greenFactor) +
|
|
|
|
|
((*pixel & 0x000000FF) * blueFactor)) >> 8) << 24;
|
|
|
|
|
pixel++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-02-10 07:27:39 +00:00
|
|
|
|
DrawResult
|
2012-05-03 20:11:57 +00:00
|
|
|
|
nsImageRenderer::Draw(nsPresContext* aPresContext,
|
2013-07-19 08:40:02 +00:00
|
|
|
|
nsRenderingContext& aRenderingContext,
|
|
|
|
|
const nsRect& aDirtyRect,
|
2014-01-31 03:36:41 +00:00
|
|
|
|
const nsRect& aDest,
|
2014-07-22 00:59:23 +00:00
|
|
|
|
const nsRect& aFill,
|
|
|
|
|
const nsPoint& aAnchor,
|
2016-05-25 00:29:00 +00:00
|
|
|
|
const nsSize& aRepeatSize,
|
2014-01-31 03:36:41 +00:00
|
|
|
|
const CSSIntRect& aSrc)
|
2009-08-21 20:39:25 +00:00
|
|
|
|
{
|
2015-10-14 07:02:37 +00:00
|
|
|
|
if (!IsReady()) {
|
2009-08-21 20:39:25 +00:00
|
|
|
|
NS_NOTREACHED("Ensure PrepareImage() has returned true before calling me");
|
2015-02-10 07:27:39 +00:00
|
|
|
|
return DrawResult::TEMPORARY_ERROR;
|
2009-08-21 20:39:25 +00:00
|
|
|
|
}
|
2010-08-13 13:34:01 +00:00
|
|
|
|
if (aDest.IsEmpty() || aFill.IsEmpty() ||
|
2013-07-19 08:40:02 +00:00
|
|
|
|
mSize.width <= 0 || mSize.height <= 0) {
|
2015-02-10 07:27:39 +00:00
|
|
|
|
return DrawResult::SUCCESS;
|
2013-07-19 08:40:02 +00:00
|
|
|
|
}
|
2009-08-21 20:39:25 +00:00
|
|
|
|
|
2016-05-25 16:01:18 +00:00
|
|
|
|
SamplingFilter samplingFilter = nsLayoutUtils::GetSamplingFilterForFrame(mForFrame);
|
2016-03-24 00:32:00 +00:00
|
|
|
|
DrawResult result = DrawResult::SUCCESS;
|
|
|
|
|
RefPtr<gfxContext> ctx = aRenderingContext.ThebesContext();
|
|
|
|
|
IntRect tmpDTRect;
|
|
|
|
|
|
|
|
|
|
if (ctx->CurrentOp() != CompositionOp::OP_OVER || mMaskOp == NS_STYLE_MASK_MODE_LUMINANCE) {
|
|
|
|
|
gfxRect clipRect = ctx->GetClipExtents();
|
|
|
|
|
tmpDTRect = RoundedOut(ToRect(clipRect));
|
2016-06-13 15:34:51 +00:00
|
|
|
|
RefPtr<DrawTarget> tempDT =
|
2016-07-28 22:32:00 +00:00
|
|
|
|
gfxPlatform::GetPlatform()->CreateSimilarSoftwareDrawTarget(ctx->GetDrawTarget(),
|
|
|
|
|
tmpDTRect.Size(),
|
|
|
|
|
SurfaceFormat::B8G8R8A8);
|
2016-06-13 15:34:51 +00:00
|
|
|
|
if (!tempDT || !tempDT->IsValid()) {
|
|
|
|
|
gfxDevCrash(LogReason::InvalidContext) << "ImageRenderer::Draw problem " << gfx::hexa(tempDT);
|
|
|
|
|
return DrawResult::TEMPORARY_ERROR;
|
|
|
|
|
}
|
|
|
|
|
tempDT->SetTransform(Matrix::Translation(-tmpDTRect.TopLeft()));
|
|
|
|
|
ctx = gfxContext::CreatePreservingTransformOrNull(tempDT);
|
2016-04-12 19:18:11 +00:00
|
|
|
|
if (!ctx) {
|
|
|
|
|
gfxDevCrash(LogReason::InvalidContext) << "ImageRenderer::Draw problem " << gfx::hexa(tempDT);
|
|
|
|
|
return DrawResult::TEMPORARY_ERROR;
|
|
|
|
|
}
|
2016-03-24 00:32:00 +00:00
|
|
|
|
}
|
2010-08-13 13:34:01 +00:00
|
|
|
|
|
2009-08-21 20:39:25 +00:00
|
|
|
|
switch (mType) {
|
|
|
|
|
case eStyleImageType_Image:
|
2009-09-12 22:44:18 +00:00
|
|
|
|
{
|
2015-04-03 19:48:12 +00:00
|
|
|
|
CSSIntSize imageSize(nsPresContext::AppUnitsToIntCSSPixels(mSize.width),
|
|
|
|
|
nsPresContext::AppUnitsToIntCSSPixels(mSize.height));
|
2016-03-24 00:32:00 +00:00
|
|
|
|
result =
|
|
|
|
|
nsLayoutUtils::DrawBackgroundImage(*ctx,
|
2015-02-10 07:27:39 +00:00
|
|
|
|
aPresContext,
|
2016-05-25 16:01:18 +00:00
|
|
|
|
mImageContainer, imageSize,
|
|
|
|
|
samplingFilter,
|
2016-05-25 00:29:00 +00:00
|
|
|
|
aDest, aFill, aRepeatSize,
|
|
|
|
|
aAnchor, aDirtyRect,
|
2015-11-23 16:17:35 +00:00
|
|
|
|
ConvertImageRendererToDrawFlags(mFlags),
|
|
|
|
|
mExtendMode);
|
2016-03-24 00:32:00 +00:00
|
|
|
|
break;
|
2009-09-12 22:44:18 +00:00
|
|
|
|
}
|
2009-08-21 20:39:25 +00:00
|
|
|
|
case eStyleImageType_Gradient:
|
2013-07-19 08:40:02 +00:00
|
|
|
|
{
|
2009-08-21 20:39:25 +00:00
|
|
|
|
nsCSSRendering::PaintGradient(aPresContext, aRenderingContext,
|
2014-01-31 03:36:41 +00:00
|
|
|
|
mGradientData, aDirtyRect,
|
2016-06-02 00:09:00 +00:00
|
|
|
|
aDest, aFill, aRepeatSize, aSrc, mSize);
|
2016-03-24 00:32:00 +00:00
|
|
|
|
break;
|
2013-07-19 08:40:02 +00:00
|
|
|
|
}
|
2010-08-13 13:34:01 +00:00
|
|
|
|
case eStyleImageType_Element:
|
2013-07-19 08:40:02 +00:00
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
|
RefPtr<gfxDrawable> drawable = DrawableForElement(aDest,
|
2014-01-31 03:36:42 +00:00
|
|
|
|
aRenderingContext);
|
|
|
|
|
if (!drawable) {
|
|
|
|
|
NS_WARNING("Could not create drawable for element");
|
2015-02-10 07:27:39 +00:00
|
|
|
|
return DrawResult::TEMPORARY_ERROR;
|
2010-08-13 13:34:01 +00:00
|
|
|
|
}
|
2014-07-22 00:59:23 +00:00
|
|
|
|
|
|
|
|
|
nsCOMPtr<imgIContainer> image(ImageOps::CreateFromDrawable(drawable));
|
2016-03-24 00:32:00 +00:00
|
|
|
|
result =
|
|
|
|
|
nsLayoutUtils::DrawImage(*ctx,
|
2015-10-23 02:54:48 +00:00
|
|
|
|
aPresContext, image,
|
2016-05-25 16:01:18 +00:00
|
|
|
|
samplingFilter, aDest, aFill, aAnchor, aDirtyRect,
|
2015-10-23 02:54:48 +00:00
|
|
|
|
ConvertImageRendererToDrawFlags(mFlags));
|
2016-03-24 00:32:00 +00:00
|
|
|
|
break;
|
2013-07-19 08:40:02 +00:00
|
|
|
|
}
|
2009-08-21 20:39:25 +00:00
|
|
|
|
case eStyleImageType_Null:
|
|
|
|
|
default:
|
2016-03-24 00:32:00 +00:00
|
|
|
|
break;
|
2013-07-19 08:40:02 +00:00
|
|
|
|
}
|
2016-03-24 00:32:00 +00:00
|
|
|
|
|
|
|
|
|
if (!tmpDTRect.IsEmpty()) {
|
|
|
|
|
RefPtr<SourceSurface> surf = ctx->GetDrawTarget()->Snapshot();
|
|
|
|
|
if (mMaskOp == NS_STYLE_MASK_MODE_LUMINANCE) {
|
|
|
|
|
RefPtr<DataSourceSurface> maskData = surf->GetDataSurface();
|
|
|
|
|
DataSourceSurface::MappedSurface map;
|
|
|
|
|
if (!maskData->Map(DataSourceSurface::MapType::WRITE, &map)) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RGBALuminanceOperation(map.mData, map.mStride, maskData->GetSize());
|
|
|
|
|
maskData->Unmap();
|
|
|
|
|
surf = maskData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DrawTarget* dt = aRenderingContext.ThebesContext()->GetDrawTarget();
|
|
|
|
|
dt->DrawSurface(surf, Rect(tmpDTRect.x, tmpDTRect.y, tmpDTRect.width, tmpDTRect.height),
|
|
|
|
|
Rect(0, 0, tmpDTRect.width, tmpDTRect.height),
|
2016-05-25 16:01:18 +00:00
|
|
|
|
DrawSurfaceOptions(SamplingFilter::POINT),
|
2016-03-24 00:32:00 +00:00
|
|
|
|
DrawOptions(1.0f, aRenderingContext.ThebesContext()->CurrentOp()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
2013-07-19 08:40:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-31 03:36:42 +00:00
|
|
|
|
already_AddRefed<gfxDrawable>
|
|
|
|
|
nsImageRenderer::DrawableForElement(const nsRect& aImageRect,
|
|
|
|
|
nsRenderingContext& aRenderingContext)
|
|
|
|
|
{
|
|
|
|
|
NS_ASSERTION(mType == eStyleImageType_Element,
|
|
|
|
|
"DrawableForElement only makes sense if backed by an element");
|
|
|
|
|
if (mPaintServerFrame) {
|
2015-10-01 18:31:44 +00:00
|
|
|
|
// XXX(seth): In order to not pass FLAG_SYNC_DECODE_IMAGES here,
|
|
|
|
|
// DrawableFromPaintServer would have to return a DrawResult indicating
|
|
|
|
|
// whether any images could not be painted because they weren't fully
|
|
|
|
|
// decoded. Even always passing FLAG_SYNC_DECODE_IMAGES won't eliminate all
|
|
|
|
|
// problems, as it won't help if there are image which haven't finished
|
|
|
|
|
// loading, but it's better than nothing.
|
2014-01-31 03:36:42 +00:00
|
|
|
|
int32_t appUnitsPerDevPixel = mForFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
|
nsRect destRect = aImageRect - aImageRect.TopLeft();
|
|
|
|
|
nsIntSize roundedOut = destRect.ToOutsidePixels(appUnitsPerDevPixel).Size();
|
2015-09-23 18:49:05 +00:00
|
|
|
|
IntSize imageSize(roundedOut.width, roundedOut.height);
|
2015-10-18 05:24:48 +00:00
|
|
|
|
RefPtr<gfxDrawable> drawable =
|
2014-01-31 03:36:42 +00:00
|
|
|
|
nsSVGIntegrationUtils::DrawableFromPaintServer(
|
|
|
|
|
mPaintServerFrame, mForFrame, mSize, imageSize,
|
2014-09-29 13:15:19 +00:00
|
|
|
|
aRenderingContext.GetDrawTarget(),
|
2014-01-31 03:36:42 +00:00
|
|
|
|
aRenderingContext.ThebesContext()->CurrentMatrix(),
|
2015-10-01 18:31:44 +00:00
|
|
|
|
nsSVGIntegrationUtils::FLAG_SYNC_DECODE_IMAGES);
|
2014-01-31 03:36:42 +00:00
|
|
|
|
|
|
|
|
|
return drawable.forget();
|
|
|
|
|
}
|
2015-11-25 04:15:29 +00:00
|
|
|
|
NS_ASSERTION(mImageElementSurface.GetSourceSurface(), "Surface should be ready.");
|
2015-10-18 05:24:48 +00:00
|
|
|
|
RefPtr<gfxDrawable> drawable = new gfxSurfaceDrawable(
|
2015-11-25 04:15:29 +00:00
|
|
|
|
mImageElementSurface.GetSourceSurface().get(),
|
2014-01-31 03:36:42 +00:00
|
|
|
|
mImageElementSurface.mSize);
|
|
|
|
|
return drawable.forget();
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-10 07:27:39 +00:00
|
|
|
|
DrawResult
|
2013-07-19 08:40:02 +00:00
|
|
|
|
nsImageRenderer::DrawBackground(nsPresContext* aPresContext,
|
|
|
|
|
nsRenderingContext& aRenderingContext,
|
|
|
|
|
const nsRect& aDest,
|
|
|
|
|
const nsRect& aFill,
|
|
|
|
|
const nsPoint& aAnchor,
|
2016-05-25 00:29:00 +00:00
|
|
|
|
const nsRect& aDirty,
|
|
|
|
|
const nsSize& aRepeatSize)
|
2013-07-19 08:40:02 +00:00
|
|
|
|
{
|
2015-10-14 07:02:37 +00:00
|
|
|
|
if (!IsReady()) {
|
2013-07-19 08:40:02 +00:00
|
|
|
|
NS_NOTREACHED("Ensure PrepareImage() has returned true before calling me");
|
2015-02-10 07:27:39 +00:00
|
|
|
|
return DrawResult::TEMPORARY_ERROR;
|
2013-07-19 08:40:02 +00:00
|
|
|
|
}
|
|
|
|
|
if (aDest.IsEmpty() || aFill.IsEmpty() ||
|
|
|
|
|
mSize.width <= 0 || mSize.height <= 0) {
|
2015-02-10 07:27:39 +00:00
|
|
|
|
return DrawResult::SUCCESS;
|
2013-07-19 08:40:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-10 07:27:39 +00:00
|
|
|
|
return Draw(aPresContext, aRenderingContext,
|
2016-05-25 00:29:00 +00:00
|
|
|
|
aDirty, aDest, aFill, aAnchor, aRepeatSize,
|
2015-02-10 07:27:39 +00:00
|
|
|
|
CSSIntRect(0, 0,
|
|
|
|
|
nsPresContext::AppUnitsToIntCSSPixels(mSize.width),
|
|
|
|
|
nsPresContext::AppUnitsToIntCSSPixels(mSize.height)));
|
2009-08-21 20:39:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-31 03:36:41 +00:00
|
|
|
|
/**
|
|
|
|
|
* Compute the size and position of the master copy of the image. I.e., a single
|
|
|
|
|
* tile used to fill the dest rect.
|
|
|
|
|
* aFill The destination rect to be filled
|
|
|
|
|
* aHFill and aVFill are the repeat patterns for the component -
|
|
|
|
|
* NS_STYLE_BORDER_IMAGE_REPEAT_* - i.e., how a tiling unit is used to fill aFill
|
|
|
|
|
* aUnitSize The size of the source rect in dest coords.
|
|
|
|
|
*/
|
|
|
|
|
static nsRect
|
2016-07-15 01:37:00 +00:00
|
|
|
|
ComputeTile(nsRect& aFill,
|
2014-01-31 03:36:41 +00:00
|
|
|
|
uint8_t aHFill,
|
|
|
|
|
uint8_t aVFill,
|
2016-07-15 01:37:00 +00:00
|
|
|
|
const nsSize& aUnitSize,
|
|
|
|
|
nsSize& aRepeatSize)
|
2014-01-31 03:36:41 +00:00
|
|
|
|
{
|
|
|
|
|
nsRect tile;
|
|
|
|
|
switch (aHFill) {
|
|
|
|
|
case NS_STYLE_BORDER_IMAGE_REPEAT_STRETCH:
|
|
|
|
|
tile.x = aFill.x;
|
|
|
|
|
tile.width = aFill.width;
|
2016-07-15 01:37:00 +00:00
|
|
|
|
aRepeatSize.width = tile.width;
|
2014-01-31 03:36:41 +00:00
|
|
|
|
break;
|
|
|
|
|
case NS_STYLE_BORDER_IMAGE_REPEAT_REPEAT:
|
|
|
|
|
tile.x = aFill.x + aFill.width/2 - aUnitSize.width/2;
|
|
|
|
|
tile.width = aUnitSize.width;
|
2016-07-15 01:37:00 +00:00
|
|
|
|
aRepeatSize.width = tile.width;
|
2014-01-31 03:36:41 +00:00
|
|
|
|
break;
|
|
|
|
|
case NS_STYLE_BORDER_IMAGE_REPEAT_ROUND:
|
|
|
|
|
tile.x = aFill.x;
|
2016-06-05 01:36:49 +00:00
|
|
|
|
tile.width = ComputeRoundedSize(aUnitSize.width, aFill.width);
|
2016-07-15 01:37:00 +00:00
|
|
|
|
aRepeatSize.width = tile.width;
|
|
|
|
|
break;
|
|
|
|
|
case NS_STYLE_BORDER_IMAGE_REPEAT_SPACE:
|
|
|
|
|
{
|
|
|
|
|
nscoord space;
|
|
|
|
|
aRepeatSize.width =
|
|
|
|
|
ComputeBorderSpacedRepeatSize(aUnitSize.width, aFill.width, space);
|
|
|
|
|
tile.x = aFill.x + space;
|
|
|
|
|
tile.width = aUnitSize.width;
|
|
|
|
|
aFill.x = tile.x;
|
|
|
|
|
aFill.width = aFill.width - space * 2;
|
|
|
|
|
}
|
2014-01-31 03:36:41 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
NS_NOTREACHED("unrecognized border-image fill style");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (aVFill) {
|
|
|
|
|
case NS_STYLE_BORDER_IMAGE_REPEAT_STRETCH:
|
|
|
|
|
tile.y = aFill.y;
|
|
|
|
|
tile.height = aFill.height;
|
2016-07-15 01:37:00 +00:00
|
|
|
|
aRepeatSize.height = tile.height;
|
2014-01-31 03:36:41 +00:00
|
|
|
|
break;
|
|
|
|
|
case NS_STYLE_BORDER_IMAGE_REPEAT_REPEAT:
|
|
|
|
|
tile.y = aFill.y + aFill.height/2 - aUnitSize.height/2;
|
|
|
|
|
tile.height = aUnitSize.height;
|
2016-07-15 01:37:00 +00:00
|
|
|
|
aRepeatSize.height = tile.height;
|
2014-01-31 03:36:41 +00:00
|
|
|
|
break;
|
|
|
|
|
case NS_STYLE_BORDER_IMAGE_REPEAT_ROUND:
|
|
|
|
|
tile.y = aFill.y;
|
2016-06-05 01:36:49 +00:00
|
|
|
|
tile.height = ComputeRoundedSize(aUnitSize.height, aFill.height);
|
2016-07-15 01:37:00 +00:00
|
|
|
|
aRepeatSize.height = tile.height;
|
|
|
|
|
break;
|
|
|
|
|
case NS_STYLE_BORDER_IMAGE_REPEAT_SPACE:
|
|
|
|
|
{
|
|
|
|
|
nscoord space;
|
|
|
|
|
aRepeatSize.height =
|
|
|
|
|
ComputeBorderSpacedRepeatSize(aUnitSize.height, aFill.height, space);
|
|
|
|
|
tile.y = aFill.y + space;
|
|
|
|
|
tile.height = aUnitSize.height;
|
|
|
|
|
aFill.y = tile.y;
|
|
|
|
|
aFill.height = aFill.height - space * 2;
|
|
|
|
|
}
|
2014-01-31 03:36:41 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
NS_NOTREACHED("unrecognized border-image fill style");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tile;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns true if the given set of arguments will require the tiles which fill
|
|
|
|
|
* the dest rect to be scaled from the source tile. See comment on ComputeTile
|
|
|
|
|
* for argument descriptions.
|
|
|
|
|
*/
|
|
|
|
|
static bool
|
|
|
|
|
RequiresScaling(const nsRect& aFill,
|
|
|
|
|
uint8_t aHFill,
|
|
|
|
|
uint8_t aVFill,
|
|
|
|
|
const nsSize& aUnitSize)
|
|
|
|
|
{
|
|
|
|
|
// If we have no tiling in either direction, we can skip the intermediate
|
|
|
|
|
// scaling step.
|
|
|
|
|
return (aHFill != NS_STYLE_BORDER_IMAGE_REPEAT_STRETCH ||
|
|
|
|
|
aVFill != NS_STYLE_BORDER_IMAGE_REPEAT_STRETCH) &&
|
|
|
|
|
(aUnitSize.width != aFill.width ||
|
|
|
|
|
aUnitSize.height != aFill.height);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-23 02:54:48 +00:00
|
|
|
|
DrawResult
|
2014-01-31 03:36:41 +00:00
|
|
|
|
nsImageRenderer::DrawBorderImageComponent(nsPresContext* aPresContext,
|
|
|
|
|
nsRenderingContext& aRenderingContext,
|
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
|
const nsRect& aFill,
|
2014-01-31 03:36:41 +00:00
|
|
|
|
const CSSIntRect& aSrc,
|
2014-01-31 03:36:41 +00:00
|
|
|
|
uint8_t aHFill,
|
|
|
|
|
uint8_t aVFill,
|
|
|
|
|
const nsSize& aUnitSize,
|
2016-03-08 07:54:13 +00:00
|
|
|
|
uint8_t aIndex,
|
2016-08-01 00:24:00 +00:00
|
|
|
|
const Maybe<nsSize>& aSVGViewportSize,
|
|
|
|
|
const bool aHasIntrinsicRatio)
|
2014-01-31 03:36:41 +00:00
|
|
|
|
{
|
2015-10-14 07:02:37 +00:00
|
|
|
|
if (!IsReady()) {
|
2014-01-31 03:36:41 +00:00
|
|
|
|
NS_NOTREACHED("Ensure PrepareImage() has returned true before calling me");
|
2015-10-23 02:54:48 +00:00
|
|
|
|
return DrawResult::BAD_ARGS;
|
2014-01-31 03:36:41 +00:00
|
|
|
|
}
|
|
|
|
|
if (aFill.IsEmpty() || aSrc.IsEmpty()) {
|
2015-10-23 02:54:48 +00:00
|
|
|
|
return DrawResult::SUCCESS;
|
2014-01-31 03:36:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-22 00:59:23 +00:00
|
|
|
|
if (mType == eStyleImageType_Image || mType == eStyleImageType_Element) {
|
2014-01-31 03:36:41 +00:00
|
|
|
|
nsCOMPtr<imgIContainer> subImage;
|
2014-07-22 00:59:23 +00:00
|
|
|
|
|
2016-03-08 07:54:13 +00:00
|
|
|
|
// To draw one portion of an image into a border component, we stretch that
|
|
|
|
|
// portion to match the size of that border component and then draw onto.
|
|
|
|
|
// However, preserveAspectRatio attribute of a SVG image may break this rule.
|
|
|
|
|
// To get correct rendering result, we add
|
|
|
|
|
// FLAG_FORCE_PRESERVEASPECTRATIO_NONE flag here, to tell mImage to ignore
|
|
|
|
|
// preserveAspectRatio attribute, and always do non-uniform stretch.
|
|
|
|
|
uint32_t drawFlags = ConvertImageRendererToDrawFlags(mFlags) |
|
|
|
|
|
imgIContainer::FLAG_FORCE_PRESERVEASPECTRATIO_NONE;
|
2016-07-01 00:27:00 +00:00
|
|
|
|
// For those SVG image sources which don't have fixed aspect ratio (i.e.
|
|
|
|
|
// without viewport size and viewBox), we should scale the source uniformly
|
|
|
|
|
// after the viewport size is decided by "Default Sizing Algorithm".
|
2016-08-01 00:24:00 +00:00
|
|
|
|
if (!aHasIntrinsicRatio) {
|
2016-07-01 00:27:00 +00:00
|
|
|
|
drawFlags = drawFlags | imgIContainer::FLAG_FORCE_UNIFORM_SCALING;
|
|
|
|
|
}
|
2014-07-22 00:59:23 +00:00
|
|
|
|
// Retrieve or create the subimage we'll draw.
|
|
|
|
|
nsIntRect srcRect(aSrc.x, aSrc.y, aSrc.width, aSrc.height);
|
|
|
|
|
if (mType == eStyleImageType_Image) {
|
|
|
|
|
if ((subImage = mImage->GetSubImage(aIndex)) == nullptr) {
|
2016-03-08 07:54:13 +00:00
|
|
|
|
subImage = ImageOps::Clip(mImageContainer, srcRect, aSVGViewportSize);
|
2014-07-22 00:59:23 +00:00
|
|
|
|
mImage->SetSubImage(aIndex, subImage);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// This path, for eStyleImageType_Element, is currently slower than it
|
|
|
|
|
// needs to be because we don't cache anything. (In particular, if we have
|
|
|
|
|
// to draw to a temporary surface inside ClippedImage, we don't cache that
|
|
|
|
|
// temporary surface since we immediately throw the ClippedImage we create
|
|
|
|
|
// here away.) However, if we did cache, we'd need to know when to
|
|
|
|
|
// invalidate that cache, and it's not clear that it's worth the trouble
|
|
|
|
|
// since using border-image with -moz-element is rare.
|
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
|
RefPtr<gfxDrawable> drawable = DrawableForElement(nsRect(nsPoint(), mSize),
|
2014-07-22 00:59:23 +00:00
|
|
|
|
aRenderingContext);
|
|
|
|
|
if (!drawable) {
|
|
|
|
|
NS_WARNING("Could not create drawable for element");
|
2015-10-23 02:54:48 +00:00
|
|
|
|
return DrawResult::TEMPORARY_ERROR;
|
2014-07-22 00:59:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<imgIContainer> image(ImageOps::CreateFromDrawable(drawable));
|
2016-03-08 07:54:13 +00:00
|
|
|
|
subImage = ImageOps::Clip(image, srcRect, aSVGViewportSize);
|
2014-01-31 03:36:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-08 07:54:13 +00:00
|
|
|
|
MOZ_ASSERT_IF(aSVGViewportSize,
|
|
|
|
|
subImage->GetType() == imgIContainer::TYPE_VECTOR);
|
|
|
|
|
|
2016-05-25 16:01:18 +00:00
|
|
|
|
SamplingFilter samplingFilter = nsLayoutUtils::GetSamplingFilterForFrame(mForFrame);
|
2014-01-31 03:36:41 +00:00
|
|
|
|
|
|
|
|
|
if (!RequiresScaling(aFill, aHFill, aVFill, aUnitSize)) {
|
2015-10-23 02:54:48 +00:00
|
|
|
|
return nsLayoutUtils::DrawSingleImage(*aRenderingContext.ThebesContext(),
|
|
|
|
|
aPresContext,
|
|
|
|
|
subImage,
|
2016-05-25 16:01:18 +00:00
|
|
|
|
samplingFilter,
|
2015-10-23 02:54:48 +00:00
|
|
|
|
aFill, aDirtyRect,
|
|
|
|
|
nullptr,
|
2016-03-08 07:54:13 +00:00
|
|
|
|
drawFlags);
|
2014-01-31 03:36:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-15 01:37:00 +00:00
|
|
|
|
nsSize repeatSize;
|
|
|
|
|
nsRect fillRect(aFill);
|
|
|
|
|
nsRect tile = ComputeTile(fillRect, aHFill, aVFill, aUnitSize, repeatSize);
|
|
|
|
|
CSSIntSize imageSize(nsPresContext::AppUnitsToIntCSSPixels(srcRect.width),
|
|
|
|
|
nsPresContext::AppUnitsToIntCSSPixels(srcRect.height));
|
|
|
|
|
return nsLayoutUtils::DrawBackgroundImage(*aRenderingContext.ThebesContext(),
|
|
|
|
|
aPresContext,
|
|
|
|
|
subImage, imageSize, samplingFilter,
|
|
|
|
|
tile, fillRect, repeatSize,
|
|
|
|
|
tile.TopLeft(), aDirtyRect,
|
|
|
|
|
drawFlags,
|
|
|
|
|
ExtendMode::CLAMP);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsSize repeatSize(aFill.Size());
|
|
|
|
|
nsRect fillRect(aFill);
|
|
|
|
|
nsRect destTile = RequiresScaling(fillRect, aHFill, aVFill, aUnitSize)
|
|
|
|
|
? ComputeTile(fillRect, aHFill, aVFill, aUnitSize, repeatSize)
|
|
|
|
|
: fillRect;
|
2015-10-23 02:54:48 +00:00
|
|
|
|
return Draw(aPresContext, aRenderingContext, aDirtyRect, destTile,
|
2016-07-15 01:37:00 +00:00
|
|
|
|
fillRect, destTile.TopLeft(), repeatSize, aSrc);
|
2014-01-31 03:36:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-03 20:11:57 +00:00
|
|
|
|
bool
|
|
|
|
|
nsImageRenderer::IsRasterImage()
|
|
|
|
|
{
|
2012-12-10 05:34:17 +00:00
|
|
|
|
if (mType != eStyleImageType_Image || !mImageContainer)
|
2012-05-03 20:11:57 +00:00
|
|
|
|
return false;
|
2012-12-10 05:34:17 +00:00
|
|
|
|
return mImageContainer->GetType() == imgIContainer::TYPE_RASTER;
|
2012-05-03 20:11:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-30 13:50:50 +00:00
|
|
|
|
bool
|
|
|
|
|
nsImageRenderer::IsAnimatedImage()
|
|
|
|
|
{
|
|
|
|
|
if (mType != eStyleImageType_Image || !mImageContainer)
|
|
|
|
|
return false;
|
|
|
|
|
bool animated = false;
|
|
|
|
|
if (NS_SUCCEEDED(mImageContainer->GetAnimated(&animated)) && animated)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-13 07:23:46 +00:00
|
|
|
|
already_AddRefed<imgIContainer>
|
|
|
|
|
nsImageRenderer::GetImage()
|
2012-05-03 20:11:57 +00:00
|
|
|
|
{
|
2015-03-18 02:40:16 +00:00
|
|
|
|
if (mType != eStyleImageType_Image || !mImageContainer) {
|
2012-07-30 14:20:58 +00:00
|
|
|
|
return nullptr;
|
2015-03-18 02:40:16 +00:00
|
|
|
|
}
|
2012-11-28 02:34:45 +00:00
|
|
|
|
|
2015-05-13 07:23:46 +00:00
|
|
|
|
nsCOMPtr<imgIContainer> image = mImageContainer;
|
|
|
|
|
return image.forget();
|
2012-05-03 20:11:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-01 00:24:00 +00:00
|
|
|
|
void
|
|
|
|
|
nsImageRenderer::PurgeCacheForViewportChange(
|
|
|
|
|
const Maybe<nsSize>& aSVGViewportSize, const bool aHasIntrinsicRatio)
|
|
|
|
|
{
|
|
|
|
|
// Check if we should flush the cached data - only vector images need to do
|
|
|
|
|
// the check since they might not have fixed ratio.
|
|
|
|
|
if (mImageContainer &&
|
|
|
|
|
mImageContainer->GetType() == imgIContainer::TYPE_VECTOR) {
|
|
|
|
|
mImage->PurgeCacheForViewportChange(aSVGViewportSize, aHasIntrinsicRatio);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-15 04:16:17 +00:00
|
|
|
|
#define MAX_BLUR_RADIUS 300
|
2010-08-23 09:30:07 +00:00
|
|
|
|
#define MAX_SPREAD_RADIUS 50
|
2010-03-15 04:16:17 +00:00
|
|
|
|
|
2013-11-25 23:09:04 +00:00
|
|
|
|
static inline gfxPoint ComputeBlurStdDev(nscoord aBlurRadius,
|
|
|
|
|
int32_t aAppUnitsPerDevPixel,
|
|
|
|
|
gfxFloat aScaleX,
|
|
|
|
|
gfxFloat aScaleY)
|
2010-09-11 16:27:12 +00:00
|
|
|
|
{
|
|
|
|
|
// http://dev.w3.org/csswg/css3-background/#box-shadow says that the
|
|
|
|
|
// standard deviation of the blur should be half the given blur value.
|
2012-05-16 20:45:25 +00:00
|
|
|
|
gfxFloat blurStdDev = gfxFloat(aBlurRadius) / gfxFloat(aAppUnitsPerDevPixel);
|
|
|
|
|
|
2013-11-25 23:09:04 +00:00
|
|
|
|
return gfxPoint(std::min((blurStdDev * aScaleX),
|
|
|
|
|
gfxFloat(MAX_BLUR_RADIUS)) / 2.0,
|
|
|
|
|
std::min((blurStdDev * aScaleY),
|
|
|
|
|
gfxFloat(MAX_BLUR_RADIUS)) / 2.0);
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-23 18:49:05 +00:00
|
|
|
|
static inline IntSize
|
2013-11-25 23:09:04 +00:00
|
|
|
|
ComputeBlurRadius(nscoord aBlurRadius,
|
|
|
|
|
int32_t aAppUnitsPerDevPixel,
|
|
|
|
|
gfxFloat aScaleX = 1.0,
|
|
|
|
|
gfxFloat aScaleY = 1.0)
|
|
|
|
|
{
|
|
|
|
|
gfxPoint scaledBlurStdDev = ComputeBlurStdDev(aBlurRadius, aAppUnitsPerDevPixel,
|
|
|
|
|
aScaleX, aScaleY);
|
2010-09-11 16:27:12 +00:00
|
|
|
|
return
|
2012-05-22 15:32:08 +00:00
|
|
|
|
gfxAlphaBoxBlur::CalculateBlurRadius(scaledBlurStdDev);
|
2010-09-11 16:27:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-06-12 22:02:32 +00:00
|
|
|
|
// -----
|
|
|
|
|
// nsContextBoxBlur
|
|
|
|
|
// -----
|
|
|
|
|
gfxContext*
|
2010-08-23 09:30:07 +00:00
|
|
|
|
nsContextBoxBlur::Init(const nsRect& aRect, nscoord aSpreadRadius,
|
|
|
|
|
nscoord aBlurRadius,
|
2012-08-22 15:56:38 +00:00
|
|
|
|
int32_t aAppUnitsPerDevPixel,
|
2008-12-02 21:16:22 +00:00
|
|
|
|
gfxContext* aDestinationCtx,
|
2010-04-18 03:13:10 +00:00
|
|
|
|
const nsRect& aDirtyRect,
|
2010-08-23 09:30:07 +00:00
|
|
|
|
const gfxRect* aSkipRect,
|
2012-08-22 15:56:38 +00:00
|
|
|
|
uint32_t aFlags)
|
2008-06-12 22:02:32 +00:00
|
|
|
|
{
|
2010-01-06 18:02:11 +00:00
|
|
|
|
if (aRect.IsEmpty()) {
|
2012-07-30 14:20:58 +00:00
|
|
|
|
mContext = nullptr;
|
|
|
|
|
return nullptr;
|
2010-01-06 18:02:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-23 18:49:05 +00:00
|
|
|
|
IntSize blurRadius;
|
|
|
|
|
IntSize spreadRadius;
|
2015-12-18 04:04:12 +00:00
|
|
|
|
GetBlurAndSpreadRadius(aDestinationCtx->GetDrawTarget(), aAppUnitsPerDevPixel,
|
2015-09-24 16:50:29 +00:00
|
|
|
|
aBlurRadius, aSpreadRadius,
|
|
|
|
|
blurRadius, spreadRadius);
|
2012-05-16 20:45:25 +00:00
|
|
|
|
|
2009-09-18 18:18:35 +00:00
|
|
|
|
mDestinationCtx = aDestinationCtx;
|
2009-09-04 13:32:17 +00:00
|
|
|
|
|
2010-01-06 18:02:11 +00:00
|
|
|
|
// If not blurring, draw directly onto the destination device
|
2012-05-22 15:32:08 +00:00
|
|
|
|
if (blurRadius.width <= 0 && blurRadius.height <= 0 &&
|
|
|
|
|
spreadRadius.width <= 0 && spreadRadius.height <= 0 &&
|
2010-09-11 16:27:12 +00:00
|
|
|
|
!(aFlags & FORCE_MASK)) {
|
2008-06-12 22:02:32 +00:00
|
|
|
|
mContext = aDestinationCtx;
|
|
|
|
|
return mContext;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Convert from app units to device pixels
|
2010-09-07 22:20:35 +00:00
|
|
|
|
gfxRect rect = nsLayoutUtils::RectToGfxRect(aRect, aAppUnitsPerDevPixel);
|
2008-06-12 22:02:32 +00:00
|
|
|
|
|
2010-09-07 22:20:35 +00:00
|
|
|
|
gfxRect dirtyRect =
|
|
|
|
|
nsLayoutUtils::RectToGfxRect(aDirtyRect, aAppUnitsPerDevPixel);
|
2009-09-07 00:35:14 +00:00
|
|
|
|
dirtyRect.RoundOut();
|
2008-07-14 10:35:15 +00:00
|
|
|
|
|
2015-09-24 16:50:29 +00:00
|
|
|
|
gfxMatrix transform = aDestinationCtx->CurrentMatrix();
|
2012-05-16 20:45:25 +00:00
|
|
|
|
rect = transform.TransformBounds(rect);
|
|
|
|
|
|
|
|
|
|
mPreTransformed = !transform.IsIdentity();
|
|
|
|
|
|
2008-12-06 18:54:36 +00:00
|
|
|
|
// Create the temporary surface for blurring
|
2012-05-16 20:45:25 +00:00
|
|
|
|
dirtyRect = transform.TransformBounds(dirtyRect);
|
|
|
|
|
if (aSkipRect) {
|
|
|
|
|
gfxRect skipRect = transform.TransformBounds(*aSkipRect);
|
2014-09-17 07:46:39 +00:00
|
|
|
|
mContext = mAlphaBoxBlur.Init(rect, spreadRadius,
|
|
|
|
|
blurRadius, &dirtyRect, &skipRect);
|
2012-05-16 20:45:25 +00:00
|
|
|
|
} else {
|
2014-09-17 07:46:39 +00:00
|
|
|
|
mContext = mAlphaBoxBlur.Init(rect, spreadRadius,
|
|
|
|
|
blurRadius, &dirtyRect, nullptr);
|
2012-05-16 20:45:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mContext) {
|
|
|
|
|
// we don't need to blur if skipRect is equal to rect
|
2013-10-08 18:47:21 +00:00
|
|
|
|
// and mContext will be nullptr
|
2013-10-02 04:20:47 +00:00
|
|
|
|
mContext->Multiply(transform);
|
2012-05-16 20:45:25 +00:00
|
|
|
|
}
|
2008-06-12 22:02:32 +00:00
|
|
|
|
return mContext;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nsContextBoxBlur::DoPaint()
|
|
|
|
|
{
|
2015-09-24 16:50:29 +00:00
|
|
|
|
if (mContext == mDestinationCtx) {
|
2008-06-12 22:02:32 +00:00
|
|
|
|
return;
|
2015-09-24 16:50:29 +00:00
|
|
|
|
}
|
2008-06-12 22:02:32 +00:00
|
|
|
|
|
2012-05-16 20:45:25 +00:00
|
|
|
|
gfxContextMatrixAutoSaveRestore saveMatrix(mDestinationCtx);
|
|
|
|
|
|
|
|
|
|
if (mPreTransformed) {
|
2014-09-11 06:57:39 +00:00
|
|
|
|
mDestinationCtx->SetMatrix(gfxMatrix());
|
2012-05-16 20:45:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-09-17 07:46:39 +00:00
|
|
|
|
mAlphaBoxBlur.Paint(mDestinationCtx);
|
2008-06-12 22:02:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gfxContext*
|
|
|
|
|
nsContextBoxBlur::GetContext()
|
|
|
|
|
{
|
|
|
|
|
return mContext;
|
|
|
|
|
}
|
2008-12-02 21:16:22 +00:00
|
|
|
|
|
2010-09-11 16:27:12 +00:00
|
|
|
|
/* static */ nsMargin
|
|
|
|
|
nsContextBoxBlur::GetBlurRadiusMargin(nscoord aBlurRadius,
|
2012-08-22 15:56:38 +00:00
|
|
|
|
int32_t aAppUnitsPerDevPixel)
|
2010-09-11 16:27:12 +00:00
|
|
|
|
{
|
2015-09-23 18:49:05 +00:00
|
|
|
|
IntSize blurRadius = ComputeBlurRadius(aBlurRadius, aAppUnitsPerDevPixel);
|
2010-09-11 16:27:12 +00:00
|
|
|
|
|
|
|
|
|
nsMargin result;
|
2014-05-05 17:55:54 +00:00
|
|
|
|
result.top = result.bottom = blurRadius.height * aAppUnitsPerDevPixel;
|
|
|
|
|
result.left = result.right = blurRadius.width * aAppUnitsPerDevPixel;
|
2010-09-11 16:27:12 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
2013-11-25 23:06:17 +00:00
|
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
|
nsContextBoxBlur::BlurRectangle(gfxContext* aDestinationCtx,
|
|
|
|
|
const nsRect& aRect,
|
|
|
|
|
int32_t aAppUnitsPerDevPixel,
|
2014-11-01 10:45:10 +00:00
|
|
|
|
RectCornerRadii* aCornerRadii,
|
2013-11-25 23:06:17 +00:00
|
|
|
|
nscoord aBlurRadius,
|
2015-09-24 07:43:32 +00:00
|
|
|
|
const Color& aShadowColor,
|
2013-11-25 23:06:17 +00:00
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
|
const gfxRect& aSkipRect)
|
|
|
|
|
{
|
2014-11-01 10:45:10 +00:00
|
|
|
|
DrawTarget& aDestDrawTarget = *aDestinationCtx->GetDrawTarget();
|
|
|
|
|
|
2013-11-25 23:07:03 +00:00
|
|
|
|
if (aRect.IsEmpty()) {
|
2013-11-25 23:06:17 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-01 10:45:10 +00:00
|
|
|
|
Rect shadowGfxRect = NSRectToRect(aRect, aAppUnitsPerDevPixel);
|
2013-11-25 23:08:29 +00:00
|
|
|
|
|
|
|
|
|
if (aBlurRadius <= 0) {
|
2014-11-01 10:45:10 +00:00
|
|
|
|
ColorPattern color(ToDeviceColor(aShadowColor));
|
2013-11-25 23:08:29 +00:00
|
|
|
|
if (aCornerRadii) {
|
2015-10-18 05:24:48 +00:00
|
|
|
|
RefPtr<Path> roundedRect = MakePathForRoundedRect(aDestDrawTarget,
|
2014-11-01 10:45:10 +00:00
|
|
|
|
shadowGfxRect,
|
|
|
|
|
*aCornerRadii);
|
|
|
|
|
aDestDrawTarget.Fill(roundedRect, color);
|
2013-11-25 23:08:29 +00:00
|
|
|
|
} else {
|
2014-11-01 10:45:10 +00:00
|
|
|
|
aDestDrawTarget.FillRect(shadowGfxRect, color);
|
2013-11-25 23:08:29 +00:00
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-25 23:07:03 +00:00
|
|
|
|
gfxFloat scaleX = 1;
|
|
|
|
|
gfxFloat scaleY = 1;
|
|
|
|
|
|
|
|
|
|
// Do blurs in device space when possible.
|
|
|
|
|
// Chrome/Skia always does the blurs in device space
|
|
|
|
|
// and will sometimes get incorrect results (e.g. rotated blurs)
|
|
|
|
|
gfxMatrix transform = aDestinationCtx->CurrentMatrix();
|
|
|
|
|
// XXX: we could probably handle negative scales but for now it's easier just to fallback
|
2014-06-17 17:35:51 +00:00
|
|
|
|
if (!transform.HasNonAxisAlignedTransform() && transform._11 > 0.0 && transform._22 > 0.0) {
|
|
|
|
|
scaleX = transform._11;
|
|
|
|
|
scaleY = transform._22;
|
2014-09-11 06:57:39 +00:00
|
|
|
|
aDestinationCtx->SetMatrix(gfxMatrix());
|
2013-12-18 01:58:21 +00:00
|
|
|
|
} else {
|
|
|
|
|
transform = gfxMatrix();
|
2013-11-25 23:07:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-25 23:09:04 +00:00
|
|
|
|
gfxPoint blurStdDev = ComputeBlurStdDev(aBlurRadius, aAppUnitsPerDevPixel, scaleX, scaleY);
|
2013-11-25 23:07:03 +00:00
|
|
|
|
|
2013-11-25 23:08:29 +00:00
|
|
|
|
gfxRect dirtyRect =
|
|
|
|
|
nsLayoutUtils::RectToGfxRect(aDirtyRect, aAppUnitsPerDevPixel);
|
|
|
|
|
dirtyRect.RoundOut();
|
2013-11-25 23:06:17 +00:00
|
|
|
|
|
2014-11-01 10:45:10 +00:00
|
|
|
|
gfxRect shadowThebesRect = transform.TransformBounds(ThebesRect(shadowGfxRect));
|
2013-11-25 23:08:29 +00:00
|
|
|
|
dirtyRect = transform.TransformBounds(dirtyRect);
|
|
|
|
|
gfxRect skipRect = transform.TransformBounds(aSkipRect);
|
2013-11-25 23:06:17 +00:00
|
|
|
|
|
|
|
|
|
if (aCornerRadii) {
|
2013-11-25 23:08:29 +00:00
|
|
|
|
aCornerRadii->Scale(scaleX, scaleY);
|
2013-11-25 23:07:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-25 23:08:29 +00:00
|
|
|
|
gfxAlphaBoxBlur::BlurRectangle(aDestinationCtx,
|
2014-11-01 10:45:10 +00:00
|
|
|
|
shadowThebesRect,
|
2013-11-25 23:08:29 +00:00
|
|
|
|
aCornerRadii,
|
2013-11-25 23:09:04 +00:00
|
|
|
|
blurStdDev,
|
2013-11-25 23:08:29 +00:00
|
|
|
|
aShadowColor,
|
|
|
|
|
dirtyRect,
|
|
|
|
|
skipRect);
|
2013-11-25 23:06:17 +00:00
|
|
|
|
}
|
2015-09-24 16:50:29 +00:00
|
|
|
|
|
|
|
|
|
/* static */ void
|
2015-12-18 04:04:12 +00:00
|
|
|
|
nsContextBoxBlur::GetBlurAndSpreadRadius(DrawTarget* aDestDrawTarget,
|
2015-09-24 16:50:29 +00:00
|
|
|
|
int32_t aAppUnitsPerDevPixel,
|
|
|
|
|
nscoord aBlurRadius,
|
|
|
|
|
nscoord aSpreadRadius,
|
2015-09-23 18:49:05 +00:00
|
|
|
|
IntSize& aOutBlurRadius,
|
|
|
|
|
IntSize& aOutSpreadRadius,
|
2015-09-24 16:50:29 +00:00
|
|
|
|
bool aConstrainSpreadRadius)
|
|
|
|
|
{
|
|
|
|
|
// Do blurs in device space when possible.
|
|
|
|
|
// Chrome/Skia always does the blurs in device space
|
|
|
|
|
// and will sometimes get incorrect results (e.g. rotated blurs)
|
2015-12-18 04:04:12 +00:00
|
|
|
|
Matrix transform = aDestDrawTarget->GetTransform();
|
2015-09-24 16:50:29 +00:00
|
|
|
|
// XXX: we could probably handle negative scales but for now it's easier just to fallback
|
2015-12-18 04:04:12 +00:00
|
|
|
|
gfxFloat scaleX, scaleY;
|
2015-09-24 16:50:29 +00:00
|
|
|
|
if (transform.HasNonAxisAlignedTransform() || transform._11 <= 0.0 || transform._22 <= 0.0) {
|
2015-12-18 04:04:12 +00:00
|
|
|
|
scaleX = 1;
|
|
|
|
|
scaleY = 1;
|
2015-09-24 16:50:29 +00:00
|
|
|
|
} else {
|
|
|
|
|
scaleX = transform._11;
|
|
|
|
|
scaleY = transform._22;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// compute a large or smaller blur radius
|
|
|
|
|
aOutBlurRadius = ComputeBlurRadius(aBlurRadius, aAppUnitsPerDevPixel, scaleX, scaleY);
|
|
|
|
|
aOutSpreadRadius =
|
2015-09-23 18:49:05 +00:00
|
|
|
|
IntSize(int32_t(aSpreadRadius * scaleX / aAppUnitsPerDevPixel),
|
|
|
|
|
int32_t(aSpreadRadius * scaleY / aAppUnitsPerDevPixel));
|
2015-09-24 16:50:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (aConstrainSpreadRadius) {
|
|
|
|
|
aOutSpreadRadius.width = std::min(aOutSpreadRadius.width, int32_t(MAX_SPREAD_RADIUS));
|
|
|
|
|
aOutSpreadRadius.height = std::min(aOutSpreadRadius.height, int32_t(MAX_SPREAD_RADIUS));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* static */ bool
|
|
|
|
|
nsContextBoxBlur::InsetBoxBlur(gfxContext* aDestinationCtx,
|
|
|
|
|
Rect aDestinationRect,
|
|
|
|
|
Rect aShadowClipRect,
|
|
|
|
|
Color& aShadowColor,
|
|
|
|
|
nscoord aBlurRadiusAppUnits,
|
|
|
|
|
nscoord aSpreadDistanceAppUnits,
|
|
|
|
|
int32_t aAppUnitsPerDevPixel,
|
|
|
|
|
bool aHasBorderRadius,
|
|
|
|
|
RectCornerRadii& aInnerClipRectRadii,
|
2015-10-19 17:53:04 +00:00
|
|
|
|
Rect aSkipRect, Point aShadowOffset)
|
2015-09-24 16:50:29 +00:00
|
|
|
|
{
|
|
|
|
|
if (aDestinationRect.IsEmpty()) {
|
|
|
|
|
mContext = nullptr;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-03 15:38:34 +00:00
|
|
|
|
gfxContextAutoSaveRestore autoRestore(aDestinationCtx);
|
|
|
|
|
|
2015-09-23 18:49:05 +00:00
|
|
|
|
IntSize blurRadius;
|
|
|
|
|
IntSize spreadRadius;
|
2015-09-24 16:50:29 +00:00
|
|
|
|
// Convert the blur and spread radius to device pixels
|
|
|
|
|
bool constrainSpreadRadius = false;
|
2015-12-18 04:04:12 +00:00
|
|
|
|
GetBlurAndSpreadRadius(aDestinationCtx->GetDrawTarget(), aAppUnitsPerDevPixel,
|
2015-09-24 16:50:29 +00:00
|
|
|
|
aBlurRadiusAppUnits, aSpreadDistanceAppUnits,
|
|
|
|
|
blurRadius, spreadRadius, constrainSpreadRadius);
|
|
|
|
|
|
|
|
|
|
// The blur and spread radius are scaled already, so scale all
|
|
|
|
|
// input data to the blur. This way, we don't have to scale the min
|
|
|
|
|
// inset blur to the invert of the dest context, then rescale it back
|
|
|
|
|
// when we draw to the destination surface.
|
|
|
|
|
gfxSize scale = aDestinationCtx->CurrentMatrix().ScaleFactors(true);
|
2015-11-03 15:38:34 +00:00
|
|
|
|
Matrix transform = ToMatrix(aDestinationCtx->CurrentMatrix());
|
2015-09-24 16:50:29 +00:00
|
|
|
|
|
2015-11-03 15:38:34 +00:00
|
|
|
|
// XXX: we could probably handle negative scales but for now it's easier just to fallback
|
|
|
|
|
if (!transform.HasNonAxisAlignedTransform() && transform._11 > 0.0 && transform._22 > 0.0) {
|
|
|
|
|
// If we don't have a rotation, we're pre-transforming all the rects.
|
|
|
|
|
aDestinationCtx->SetMatrix(gfxMatrix());
|
|
|
|
|
} else {
|
|
|
|
|
// Don't touch anything, we have a rotation.
|
|
|
|
|
transform = Matrix();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Rect transformedDestRect = transform.TransformBounds(aDestinationRect);
|
|
|
|
|
Rect transformedShadowClipRect = transform.TransformBounds(aShadowClipRect);
|
|
|
|
|
Rect transformedSkipRect = transform.TransformBounds(aSkipRect);
|
2015-09-24 16:50:29 +00:00
|
|
|
|
|
|
|
|
|
transformedDestRect.Round();
|
|
|
|
|
transformedShadowClipRect.Round();
|
|
|
|
|
transformedSkipRect.RoundIn();
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < 4; i++) {
|
2015-10-16 15:27:51 +00:00
|
|
|
|
aInnerClipRectRadii[i].width = std::floor(scale.width * aInnerClipRectRadii[i].width);
|
|
|
|
|
aInnerClipRectRadii[i].height = std::floor(scale.height * aInnerClipRectRadii[i].height);
|
2015-09-24 16:50:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-03 15:38:34 +00:00
|
|
|
|
mAlphaBoxBlur.BlurInsetBox(aDestinationCtx, transformedDestRect,
|
|
|
|
|
transformedShadowClipRect,
|
|
|
|
|
blurRadius, spreadRadius,
|
|
|
|
|
aShadowColor, aHasBorderRadius,
|
|
|
|
|
aInnerClipRectRadii, transformedSkipRect,
|
|
|
|
|
aShadowOffset);
|
2015-09-24 16:50:29 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|