2001-09-29 00:14:13 +04:00
|
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2002-01-08 02:46:07 +03:00
|
|
|
|
// vim:cindent:ts=2:et:sw=2:
|
2012-05-21 15:12:37 +04:00
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2006-03-30 09:56:38 +04:00
|
|
|
|
|
|
|
|
|
/* utility functions for drawing borders and backgrounds */
|
|
|
|
|
|
2012-12-15 03:58:45 +04:00
|
|
|
|
#include <ctime>
|
|
|
|
|
|
|
|
|
|
#include "mozilla/DebugOnly.h"
|
|
|
|
|
#include "mozilla/HashFunctions.h"
|
2013-02-16 07:55:36 +04:00
|
|
|
|
#include "mozilla/MathAlgorithms.h"
|
2012-12-15 03:58:45 +04:00
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
|
#include "nsStyleConsts.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
|
#include "nsPresContext.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
|
#include "nsPoint.h"
|
|
|
|
|
#include "nsRect.h"
|
|
|
|
|
#include "nsIPresShell.h"
|
2004-09-02 07:08:51 +04:00
|
|
|
|
#include "nsFrameManager.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
|
#include "nsStyleContext.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
|
#include "nsGkAtoms.h"
|
2008-06-03 02:52:25 +04:00
|
|
|
|
#include "nsCSSAnonBoxes.h"
|
2000-03-30 10:27:32 +04:00
|
|
|
|
#include "nsIContent.h"
|
2013-01-13 01:53:01 +04:00
|
|
|
|
#include "nsIDocumentInlines.h"
|
2000-06-08 03:06:41 +04:00
|
|
|
|
#include "nsIScrollableFrame.h"
|
2001-08-10 00:22:39 +04:00
|
|
|
|
#include "imgIRequest.h"
|
|
|
|
|
#include "imgIContainer.h"
|
2013-04-06 01:14:37 +04:00
|
|
|
|
#include "ImageOps.h"
|
2001-10-24 04:01:09 +04:00
|
|
|
|
#include "nsCSSRendering.h"
|
2002-09-12 08:43:31 +04:00
|
|
|
|
#include "nsCSSColorUtils.h"
|
2001-12-18 01:51:39 +03:00
|
|
|
|
#include "nsITheme.h"
|
2003-02-23 05:49:22 +03:00
|
|
|
|
#include "nsLayoutUtils.h"
|
2008-02-27 13:46:29 +03:00
|
|
|
|
#include "nsBlockFrame.h"
|
2006-04-21 21:52:05 +04:00
|
|
|
|
#include "gfxContext.h"
|
2012-03-20 16:15:55 +04:00
|
|
|
|
#include "nsRenderingContext.h"
|
2008-07-17 10:30:25 +04:00
|
|
|
|
#include "nsStyleStructInlines.h"
|
2008-08-08 12:21:13 +04:00
|
|
|
|
#include "nsCSSFrameConstructor.h"
|
2010-04-03 05:58:26 +04:00
|
|
|
|
#include "nsCSSProps.h"
|
2010-08-13 17:34:01 +04:00
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
|
#include "nsSVGEffects.h"
|
|
|
|
|
#include "nsSVGIntegrationUtils.h"
|
|
|
|
|
#include "gfxDrawable.h"
|
2013-03-18 18:25:50 +04:00
|
|
|
|
#include "GeckoProfiler.h"
|
2008-07-23 21:25:23 +04:00
|
|
|
|
#include "nsCSSRenderingBorders.h"
|
2012-08-14 02:04:19 +04:00
|
|
|
|
#include "mozilla/css/ImageLoader.h"
|
2012-08-19 23:33:25 +04:00
|
|
|
|
#include "ImageContainer.h"
|
2012-08-27 08:12:36 +04:00
|
|
|
|
#include "mozilla/Telemetry.h"
|
2012-12-07 03:58:13 +04:00
|
|
|
|
#include "gfxUtils.h"
|
2013-10-08 03:15:59 +04:00
|
|
|
|
#include "gfxColor.h"
|
2013-11-08 08:50:39 +04:00
|
|
|
|
#include "gfxGradientCache.h"
|
2014-01-31 07:36:41 +04:00
|
|
|
|
#include "GraphicsFilter.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
|
#include <algorithm>
|
1999-04-19 09:27:55 +04:00
|
|
|
|
|
2011-06-02 16:56:46 +04:00
|
|
|
|
using namespace mozilla;
|
2012-08-14 02:04:19 +04:00
|
|
|
|
using namespace mozilla::css;
|
2013-11-08 08:50:39 +04:00
|
|
|
|
using namespace mozilla::gfx;
|
2013-04-06 01:14:37 +04:00
|
|
|
|
using mozilla::image::ImageOps;
|
2013-07-19 12:39:58 +04:00
|
|
|
|
using mozilla::CSSSizeOrRatio;
|
2011-06-02 16:56:46 +04:00
|
|
|
|
|
2012-11-19 14:54:41 +04:00
|
|
|
|
static int gFrameTreeLockCount = 0;
|
|
|
|
|
|
2003-01-17 12:33:52 +03: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()
|
2012-07-30 18:20:58 +04:00
|
|
|
|
: mFrame(nullptr), mBlockFrame(nullptr)
|
2003-01-17 12:33:52 +03:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~InlineBackgroundData()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Reset()
|
|
|
|
|
{
|
|
|
|
|
mBoundingBox.SetRect(0,0,0,0);
|
2008-02-27 13:46:29 +03:00
|
|
|
|
mContinuationPoint = mLineContinuationPoint = mUnbrokenWidth = 0;
|
2012-07-30 18:20:58 +04:00
|
|
|
|
mFrame = mBlockFrame = nullptr;
|
2003-01-17 12:33:52 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsRect GetContinuousRect(nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
SetFrame(aFrame);
|
|
|
|
|
|
2008-02-27 13:46:29 +03:00
|
|
|
|
nscoord x;
|
|
|
|
|
if (mBidiEnabled) {
|
|
|
|
|
x = mLineContinuationPoint;
|
|
|
|
|
|
|
|
|
|
// Scan continuations on the same line as aFrame and accumulate the widths
|
2010-04-27 20:15:01 +04:00
|
|
|
|
// of frames that are to the left (if this is an LTR block) or right
|
2008-02-27 13:46:29 +03:00
|
|
|
|
// (if it's RTL) of the current one.
|
2013-02-17 01:51:02 +04:00
|
|
|
|
bool isRtlBlock = (mBlockFrame->StyleVisibility()->mDirection ==
|
2010-04-27 20:15:01 +04:00
|
|
|
|
NS_STYLE_DIRECTION_RTL);
|
2008-02-27 13:46:29 +03:00
|
|
|
|
nscoord curOffset = aFrame->GetOffsetTo(mBlockFrame).x;
|
|
|
|
|
|
2009-03-06 23:32:20 +03:00
|
|
|
|
// No need to use our GetPrevContinuation/GetNextContinuation methods
|
2014-02-07 05:45:33 +04:00
|
|
|
|
// here, since ib-split siblings are certainly not on the same line.
|
2010-04-27 20:15:01 +04:00
|
|
|
|
|
2008-02-27 13:46:29 +03:00
|
|
|
|
nsIFrame* inlineFrame = aFrame->GetPrevContinuation();
|
|
|
|
|
// If the continuation is fluid we know inlineFrame is not on the same line.
|
2009-03-06 23:32:20 +03:00
|
|
|
|
// If it's not fluid, we need to test further to be sure.
|
2008-02-27 13:46:29 +03:00
|
|
|
|
while (inlineFrame && !inlineFrame->GetNextInFlow() &&
|
|
|
|
|
AreOnSameLine(aFrame, inlineFrame)) {
|
|
|
|
|
nscoord frameXOffset = inlineFrame->GetOffsetTo(mBlockFrame).x;
|
|
|
|
|
if(isRtlBlock == (frameXOffset >= curOffset)) {
|
|
|
|
|
x += inlineFrame->GetSize().width;
|
|
|
|
|
}
|
|
|
|
|
inlineFrame = inlineFrame->GetPrevContinuation();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inlineFrame = aFrame->GetNextContinuation();
|
|
|
|
|
while (inlineFrame && !inlineFrame->GetPrevInFlow() &&
|
|
|
|
|
AreOnSameLine(aFrame, inlineFrame)) {
|
|
|
|
|
nscoord frameXOffset = inlineFrame->GetOffsetTo(mBlockFrame).x;
|
|
|
|
|
if(isRtlBlock == (frameXOffset >= curOffset)) {
|
|
|
|
|
x += inlineFrame->GetSize().width;
|
|
|
|
|
}
|
|
|
|
|
inlineFrame = inlineFrame->GetNextContinuation();
|
|
|
|
|
}
|
|
|
|
|
if (isRtlBlock) {
|
|
|
|
|
// aFrame itself is also to the right of its left edge, so add its width.
|
|
|
|
|
x += aFrame->GetSize().width;
|
|
|
|
|
// x is now the distance from the left edge of aFrame to the right edge
|
|
|
|
|
// of the unbroken content. Change it to indicate the distance from the
|
|
|
|
|
// left edge of the unbroken content to the left edge of aFrame.
|
|
|
|
|
x = mUnbrokenWidth - x;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
x = mContinuationPoint;
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-17 12:33:52 +03: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.
|
2008-02-27 13:46:29 +03:00
|
|
|
|
return nsRect(-x, 0, mUnbrokenWidth, mFrame->GetSize().height);
|
2003-01-17 12:33:52 +03: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 19:04:34 +04:00
|
|
|
|
nsPoint point = mFrame->GetPosition();
|
2003-01-17 12:33:52 +03:00
|
|
|
|
boundingBox.MoveBy(-point.x, -point.y);
|
|
|
|
|
|
|
|
|
|
return boundingBox;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
nsIFrame* mFrame;
|
2009-05-13 12:26:48 +04:00
|
|
|
|
nsBlockFrame* mBlockFrame;
|
|
|
|
|
nsRect mBoundingBox;
|
2003-01-17 12:33:52 +03:00
|
|
|
|
nscoord mContinuationPoint;
|
|
|
|
|
nscoord mUnbrokenWidth;
|
2008-02-27 13:46:29 +03:00
|
|
|
|
nscoord mLineContinuationPoint;
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool mBidiEnabled;
|
2010-04-27 20:15:01 +04:00
|
|
|
|
|
2003-01-17 12:33:52 +03:00
|
|
|
|
void SetFrame(nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
NS_PRECONDITION(aFrame, "Need a frame");
|
2012-11-19 14:54:41 +04:00
|
|
|
|
NS_ASSERTION(gFrameTreeLockCount > 0,
|
|
|
|
|
"Can't call this when frame tree is not locked");
|
2003-01-17 12:33:52 +03:00
|
|
|
|
|
2012-10-25 09:32:25 +04:00
|
|
|
|
if (aFrame == mFrame) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-06 23:32:20 +03:00
|
|
|
|
nsIFrame *prevContinuation = GetPrevContinuation(aFrame);
|
2003-01-17 12:33:52 +03:00
|
|
|
|
|
2008-01-09 22:19:49 +03:00
|
|
|
|
if (!prevContinuation || mFrame != prevContinuation) {
|
2003-01-17 12:33:52 +03: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.
|
2003-07-05 19:04:34 +04:00
|
|
|
|
mContinuationPoint += mFrame->GetSize().width;
|
2003-01-17 12:33:52 +03:00
|
|
|
|
|
2008-02-27 13:46:29 +03:00
|
|
|
|
// If this a new line, update mLineContinuationPoint.
|
|
|
|
|
if (mBidiEnabled &&
|
|
|
|
|
(aFrame->GetPrevInFlow() || !AreOnSameLine(mFrame, aFrame))) {
|
|
|
|
|
mLineContinuationPoint = mContinuationPoint;
|
|
|
|
|
}
|
2010-04-27 20:15:01 +04:00
|
|
|
|
|
2003-01-17 12:33:52 +03:00
|
|
|
|
mFrame = aFrame;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-06 23:32:20 +03:00
|
|
|
|
nsIFrame* GetPrevContinuation(nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
nsIFrame* prevCont = aFrame->GetPrevContinuation();
|
2014-02-07 05:45:28 +04:00
|
|
|
|
if (!prevCont &&
|
|
|
|
|
(aFrame->GetStateBits() & NS_FRAME_PART_OF_IBSPLIT)) {
|
2010-03-29 05:46:55 +04:00
|
|
|
|
nsIFrame* block = static_cast<nsIFrame*>
|
2014-02-07 05:45:31 +04:00
|
|
|
|
(aFrame->Properties().Get(nsIFrame::IBSplitPrevSibling()));
|
2009-03-06 23:32:20 +03:00
|
|
|
|
if (block) {
|
|
|
|
|
// The {ib} properties are only stored on first continuations
|
2009-09-18 22:00:20 +04:00
|
|
|
|
NS_ASSERTION(!block->GetPrevContinuation(),
|
2014-02-07 05:45:31 +04:00
|
|
|
|
"Incorrect value for IBSplitPrevSibling");
|
2010-03-29 05:46:55 +04:00
|
|
|
|
prevCont = static_cast<nsIFrame*>
|
2014-02-07 05:45:31 +04:00
|
|
|
|
(block->Properties().Get(nsIFrame::IBSplitPrevSibling()));
|
2009-03-06 23:32:20 +03:00
|
|
|
|
NS_ASSERTION(prevCont, "How did that happen?");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return prevCont;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsIFrame* GetNextContinuation(nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
nsIFrame* nextCont = aFrame->GetNextContinuation();
|
2014-02-07 05:45:28 +04:00
|
|
|
|
if (!nextCont &&
|
|
|
|
|
(aFrame->GetStateBits() & NS_FRAME_PART_OF_IBSPLIT)) {
|
2009-03-06 23:32:20 +03:00
|
|
|
|
// The {ib} properties are only stored on first continuations
|
2013-09-25 15:42:34 +04:00
|
|
|
|
aFrame = aFrame->FirstContinuation();
|
2010-03-29 05:46:55 +04:00
|
|
|
|
nsIFrame* block = static_cast<nsIFrame*>
|
2014-02-07 05:45:30 +04:00
|
|
|
|
(aFrame->Properties().Get(nsIFrame::IBSplitSibling()));
|
2009-03-06 23:32:20 +03:00
|
|
|
|
if (block) {
|
2010-03-29 05:46:55 +04:00
|
|
|
|
nextCont = static_cast<nsIFrame*>
|
2014-02-07 05:45:30 +04:00
|
|
|
|
(block->Properties().Get(nsIFrame::IBSplitSibling()));
|
2009-03-06 23:32:20 +03:00
|
|
|
|
NS_ASSERTION(nextCont, "How did that happen?");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nextCont;
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-17 12:33:52 +03:00
|
|
|
|
void Init(nsIFrame* aFrame)
|
2010-04-27 20:15:01 +04:00
|
|
|
|
{
|
2012-10-25 09:32:25 +04:00
|
|
|
|
mBidiEnabled = aFrame->PresContext()->BidiEnabled();
|
|
|
|
|
if (mBidiEnabled) {
|
|
|
|
|
// Find the containing block frame
|
|
|
|
|
nsIFrame* frame = aFrame;
|
|
|
|
|
do {
|
|
|
|
|
frame = frame->GetParent();
|
|
|
|
|
mBlockFrame = do_QueryFrame(frame);
|
|
|
|
|
}
|
|
|
|
|
while (frame && frame->IsFrameOfType(nsIFrame::eLineParticipant));
|
|
|
|
|
|
|
|
|
|
NS_ASSERTION(mBlockFrame, "Cannot find containing block.");
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-17 12:33:52 +03:00
|
|
|
|
// Start with the previous flow frame as our continuation point
|
|
|
|
|
// is the total of the widths of the previous frames.
|
2009-03-06 23:32:20 +03:00
|
|
|
|
nsIFrame* inlineFrame = GetPrevContinuation(aFrame);
|
2003-01-17 12:33:52 +03:00
|
|
|
|
|
|
|
|
|
while (inlineFrame) {
|
2003-07-05 19:04:34 +04:00
|
|
|
|
nsRect rect = inlineFrame->GetRect();
|
2003-01-17 12:33:52 +03:00
|
|
|
|
mContinuationPoint += rect.width;
|
2012-10-25 09:32:25 +04:00
|
|
|
|
if (mBidiEnabled && !AreOnSameLine(aFrame, inlineFrame)) {
|
|
|
|
|
mLineContinuationPoint += rect.width;
|
|
|
|
|
}
|
2003-01-17 12:33:52 +03:00
|
|
|
|
mUnbrokenWidth += rect.width;
|
|
|
|
|
mBoundingBox.UnionRect(mBoundingBox, rect);
|
2009-03-06 23:32:20 +03:00
|
|
|
|
inlineFrame = GetPrevContinuation(inlineFrame);
|
2003-01-17 12:33:52 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Next add this frame and subsequent frames to the bounding box and
|
|
|
|
|
// unbroken width.
|
|
|
|
|
inlineFrame = aFrame;
|
|
|
|
|
while (inlineFrame) {
|
2003-07-05 19:04:34 +04:00
|
|
|
|
nsRect rect = inlineFrame->GetRect();
|
2003-01-17 12:33:52 +03:00
|
|
|
|
mUnbrokenWidth += rect.width;
|
|
|
|
|
mBoundingBox.UnionRect(mBoundingBox, rect);
|
2009-03-06 23:32:20 +03:00
|
|
|
|
inlineFrame = GetNextContinuation(inlineFrame);
|
2003-01-17 12:33:52 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mFrame = aFrame;
|
2008-02-27 13:46:29 +03:00
|
|
|
|
}
|
2010-04-27 20:15:01 +04:00
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool AreOnSameLine(nsIFrame* aFrame1, nsIFrame* aFrame2) {
|
|
|
|
|
bool isValid1, isValid2;
|
2008-02-27 13:46:29 +03:00
|
|
|
|
nsBlockInFlowLineIterator it1(mBlockFrame, aFrame1, &isValid1);
|
|
|
|
|
nsBlockInFlowLineIterator it2(mBlockFrame, aFrame2, &isValid2);
|
2011-06-26 20:48:37 +04:00
|
|
|
|
return isValid1 && isValid2 &&
|
|
|
|
|
// Make sure aFrame1 and aFrame2 are in the same continuation of
|
|
|
|
|
// mBlockFrame.
|
|
|
|
|
it1.GetContainer() == it2.GetContainer() &&
|
|
|
|
|
// And on the same line in it
|
|
|
|
|
it1.GetLine() == it2.GetLine();
|
2003-01-17 12:33:52 +03:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2013-02-15 22:54:49 +04:00
|
|
|
|
// A resolved color stop --- with a specific position along the gradient line,
|
|
|
|
|
// and a Thebes color
|
|
|
|
|
struct ColorStop {
|
|
|
|
|
ColorStop(double aPosition, gfxRGBA aColor) :
|
|
|
|
|
mPosition(aPosition), mColor(aColor) {}
|
|
|
|
|
double mPosition; // along the gradient line; 0=start, 1=end
|
|
|
|
|
gfxRGBA mColor;
|
|
|
|
|
};
|
|
|
|
|
|
2008-09-25 20:03:15 +04:00
|
|
|
|
/* Local functions */
|
|
|
|
|
static void DrawBorderImage(nsPresContext* aPresContext,
|
2011-04-08 05:04:40 +04:00
|
|
|
|
nsRenderingContext& aRenderingContext,
|
2008-09-25 20:03:15 +04:00
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
|
const nsRect& aBorderArea,
|
2009-11-14 07:23:00 +03:00
|
|
|
|
const nsStyleBorder& aStyleBorder,
|
2009-02-16 04:04:03 +03:00
|
|
|
|
const nsRect& aDirtyRect);
|
2008-09-25 20:03:15 +04:00
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
|
static nscolor MakeBevelColor(mozilla::css::Side whichSide, uint8_t style,
|
2008-09-25 20:03:15 +04:00
|
|
|
|
nscolor aBackgroundColor,
|
|
|
|
|
nscolor aBorderColor);
|
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
|
static InlineBackgroundData* gInlineBGData = nullptr;
|
2003-01-17 12:33:52 +03:00
|
|
|
|
|
2007-03-14 22:48:51 +03:00
|
|
|
|
// Initialize any static variables used by nsCSSRendering.
|
2011-06-02 16:56:46 +04:00
|
|
|
|
void nsCSSRendering::Init()
|
2010-04-27 20:15:01 +04:00
|
|
|
|
{
|
2007-03-14 22:48:51 +03: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 18:20:58 +04:00
|
|
|
|
gInlineBGData = nullptr;
|
2007-03-14 22:48:51 +03:00
|
|
|
|
}
|
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
|
/**
|
|
|
|
|
* Make a bevel color
|
|
|
|
|
*/
|
2008-09-25 20:03:15 +04:00
|
|
|
|
static nscolor
|
2012-08-22 19:56:38 +04:00
|
|
|
|
MakeBevelColor(mozilla::css::Side whichSide, uint8_t style,
|
2008-09-25 20:03:15 +04:00
|
|
|
|
nscolor aBackgroundColor, nscolor aBorderColor)
|
1998-04-14 00:24:54 +04:00
|
|
|
|
{
|
1998-05-27 00:52:59 +04:00
|
|
|
|
|
|
|
|
|
nscolor colors[2];
|
|
|
|
|
nscolor theColor;
|
|
|
|
|
|
1999-03-05 22:23:52 +03:00
|
|
|
|
// Given a background color and a border color
|
|
|
|
|
// calculate the color used for the shading
|
2007-02-01 05:45:55 +03:00
|
|
|
|
NS_GetSpecial3DColors(colors, aBackgroundColor, aBorderColor);
|
2010-04-27 20:15:01 +04:00
|
|
|
|
|
2007-02-01 05:45:55 +03:00
|
|
|
|
if ((style == NS_STYLE_BORDER_STYLE_OUTSET) ||
|
1998-04-14 00:24:54 +04:00
|
|
|
|
(style == NS_STYLE_BORDER_STYLE_RIDGE)) {
|
2007-02-01 05:45:55 +03:00
|
|
|
|
// Flip colors for these two border styles
|
1998-04-14 00:24:54 +04: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-27 00:52:59 +04:00
|
|
|
|
theColor = colors[1];
|
1998-04-14 00:24:54 +04:00
|
|
|
|
break;
|
|
|
|
|
case NS_SIDE_RIGHT:
|
1998-05-27 00:52:59 +04:00
|
|
|
|
theColor = colors[1];
|
1998-04-14 00:24:54 +04:00
|
|
|
|
break;
|
|
|
|
|
case NS_SIDE_TOP:
|
1998-05-27 00:52:59 +04:00
|
|
|
|
theColor = colors[0];
|
1998-04-14 00:24:54 +04:00
|
|
|
|
break;
|
|
|
|
|
case NS_SIDE_LEFT:
|
1999-04-14 01:52:19 +04:00
|
|
|
|
default:
|
1998-05-27 00:52:59 +04:00
|
|
|
|
theColor = colors[0];
|
1998-04-14 00:24:54 +04:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return theColor;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
// Thebes Border Rendering Code Start
|
|
|
|
|
|
|
|
|
|
/*
|
2008-07-23 21:25:23 +04:00
|
|
|
|
* Compute the float-pixel radii that should be used for drawing
|
|
|
|
|
* this border/outline, given the various input bits.
|
2007-05-30 06:46:54 +04:00
|
|
|
|
*/
|
2010-09-08 02:20:35 +04:00
|
|
|
|
/* static */ void
|
|
|
|
|
nsCSSRendering::ComputePixelRadii(const nscoord *aAppUnitsRadii,
|
|
|
|
|
nscoord aAppUnitsPerPixel,
|
|
|
|
|
gfxCornerSizes *oBorderRadii)
|
2007-05-01 07:31:25 +04:00
|
|
|
|
{
|
2008-10-01 09:50:52 +04:00
|
|
|
|
gfxFloat radii[8];
|
|
|
|
|
NS_FOR_CSS_HALF_CORNERS(corner)
|
2010-09-08 02:20:35 +04:00
|
|
|
|
radii[corner] = gfxFloat(aAppUnitsRadii[corner]) / aAppUnitsPerPixel;
|
2008-10-01 09:50:52 +04:00
|
|
|
|
|
|
|
|
|
(*oBorderRadii)[C_TL] = gfxSize(radii[NS_CORNER_TOP_LEFT_X],
|
|
|
|
|
radii[NS_CORNER_TOP_LEFT_Y]);
|
|
|
|
|
(*oBorderRadii)[C_TR] = gfxSize(radii[NS_CORNER_TOP_RIGHT_X],
|
|
|
|
|
radii[NS_CORNER_TOP_RIGHT_Y]);
|
|
|
|
|
(*oBorderRadii)[C_BR] = gfxSize(radii[NS_CORNER_BOTTOM_RIGHT_X],
|
|
|
|
|
radii[NS_CORNER_BOTTOM_RIGHT_Y]);
|
|
|
|
|
(*oBorderRadii)[C_BL] = gfxSize(radii[NS_CORNER_BOTTOM_LEFT_X],
|
|
|
|
|
radii[NS_CORNER_BOTTOM_LEFT_Y]);
|
2007-05-30 06:46:54 +04:00
|
|
|
|
}
|
|
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
|
void
|
|
|
|
|
nsCSSRendering::PaintBorder(nsPresContext* aPresContext,
|
2011-04-08 05:04:40 +04:00
|
|
|
|
nsRenderingContext& aRenderingContext,
|
2008-07-23 21:25:23 +04:00
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
|
const nsRect& aBorderArea,
|
|
|
|
|
nsStyleContext* aStyleContext,
|
2012-08-09 11:09:40 +04:00
|
|
|
|
int aSkipSides)
|
2010-04-03 05:58:26 +04:00
|
|
|
|
{
|
2013-03-16 08:47:02 +04:00
|
|
|
|
PROFILER_LABEL("nsCSSRendering", "PaintBorder");
|
2010-04-03 05:58:26 +04:00
|
|
|
|
nsStyleContext *styleIfVisited = aStyleContext->GetStyleIfVisited();
|
2013-02-17 01:51:02 +04:00
|
|
|
|
const nsStyleBorder *styleBorder = aStyleContext->StyleBorder();
|
2010-04-03 05:58:26 +04:00
|
|
|
|
// Don't check RelevantLinkVisited here, since we want to take the
|
|
|
|
|
// same amount of time whether or not it's true.
|
|
|
|
|
if (!styleIfVisited) {
|
|
|
|
|
PaintBorderWithStyleBorder(aPresContext, aRenderingContext, aForFrame,
|
|
|
|
|
aDirtyRect, aBorderArea, *styleBorder,
|
|
|
|
|
aStyleContext, aSkipSides);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsStyleBorder newStyleBorder(*styleBorder);
|
2010-09-08 04:30:40 +04:00
|
|
|
|
|
2010-04-03 05:58:26 +04:00
|
|
|
|
NS_FOR_CSS_SIDES(side) {
|
|
|
|
|
newStyleBorder.SetBorderColor(side,
|
|
|
|
|
aStyleContext->GetVisitedDependentColor(
|
|
|
|
|
nsCSSProps::SubpropertyEntryFor(eCSSProperty_border_color)[side]));
|
|
|
|
|
}
|
|
|
|
|
PaintBorderWithStyleBorder(aPresContext, aRenderingContext, aForFrame,
|
|
|
|
|
aDirtyRect, aBorderArea, newStyleBorder,
|
|
|
|
|
aStyleContext, aSkipSides);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nsCSSRendering::PaintBorderWithStyleBorder(nsPresContext* aPresContext,
|
2011-04-08 05:04:40 +04:00
|
|
|
|
nsRenderingContext& aRenderingContext,
|
2010-04-03 05:58:26 +04:00
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
|
const nsRect& aBorderArea,
|
|
|
|
|
const nsStyleBorder& aStyleBorder,
|
|
|
|
|
nsStyleContext* aStyleContext,
|
2012-08-09 11:09:40 +04:00
|
|
|
|
int aSkipSides)
|
2007-05-30 06:46:54 +04:00
|
|
|
|
{
|
2008-07-23 21:25:23 +04:00
|
|
|
|
nsMargin border;
|
2008-10-01 09:50:52 +04:00
|
|
|
|
nscoord twipsRadii[8];
|
2008-07-23 21:25:23 +04:00
|
|
|
|
nsCompatibility compatMode = aPresContext->CompatibilityMode();
|
2007-05-30 06:46:54 +04:00
|
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
|
SN("++ PaintBorder");
|
2007-05-30 06:46:54 +04:00
|
|
|
|
|
2008-07-23 21:25:23 +04: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-17 01:51:02 +04:00
|
|
|
|
const nsStyleDisplay* displayData = aStyleContext->StyleDisplay();
|
2008-07-23 21:25:23 +04:00
|
|
|
|
if (displayData->mAppearance) {
|
|
|
|
|
nsITheme *theme = aPresContext->GetTheme();
|
|
|
|
|
if (theme && theme->ThemeSupportsWidget(aPresContext, aForFrame, displayData->mAppearance))
|
|
|
|
|
return; // Let the theme handle it.
|
2007-05-30 06:46:54 +04:00
|
|
|
|
}
|
2007-05-08 21:40:08 +04:00
|
|
|
|
|
2009-11-14 07:23:00 +03:00
|
|
|
|
if (aStyleBorder.IsBorderImageLoaded()) {
|
2008-07-23 21:25:23 +04:00
|
|
|
|
DrawBorderImage(aPresContext, aRenderingContext, aForFrame,
|
2009-11-14 07:23:00 +03:00
|
|
|
|
aBorderArea, aStyleBorder, aDirtyRect);
|
2008-07-23 21:25:23 +04:00
|
|
|
|
return;
|
2007-05-30 06:46:54 +04:00
|
|
|
|
}
|
2010-04-27 20:15:01 +04:00
|
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
|
// Get our style context's color struct.
|
2013-02-17 01:51:02 +04:00
|
|
|
|
const nsStyleColor* ourColor = aStyleContext->StyleColor();
|
2007-05-01 07:31:25 +04:00
|
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
|
// in NavQuirks mode we want to use the parent's context as a starting point
|
|
|
|
|
// for determining the background color
|
2010-04-08 16:44:57 +04:00
|
|
|
|
nsIFrame* bgFrame = nsCSSRendering::FindNonTransparentBackgroundFrame
|
2011-10-17 18:59:28 +04:00
|
|
|
|
(aForFrame, compatMode == eCompatibility_NavQuirks ? true : false);
|
2013-02-16 09:38:33 +04:00
|
|
|
|
nsStyleContext* bgContext = bgFrame->StyleContext();
|
2010-04-03 05:58:26 +04:00
|
|
|
|
nscolor bgColor =
|
|
|
|
|
bgContext->GetVisitedDependentColor(eCSSProperty_background_color);
|
2007-05-01 07:31:25 +04:00
|
|
|
|
|
2009-11-14 07:23:00 +03:00
|
|
|
|
border = aStyleBorder.GetComputedBorder();
|
2008-07-23 21:25:23 +04:00
|
|
|
|
if ((0 == border.left) && (0 == border.right) &&
|
|
|
|
|
(0 == border.top) && (0 == border.bottom)) {
|
|
|
|
|
// Empty border area
|
|
|
|
|
return;
|
2007-05-01 07:31:25 +04:00
|
|
|
|
}
|
2007-05-30 06:46:54 +04:00
|
|
|
|
|
2010-09-08 02:20:35 +04:00
|
|
|
|
nsSize frameSize = aForFrame->GetSize();
|
2013-02-17 01:51:02 +04:00
|
|
|
|
if (&aStyleBorder == aForFrame->StyleBorder() &&
|
2010-09-08 02:20:35 +04:00
|
|
|
|
frameSize == aBorderArea.Size()) {
|
|
|
|
|
aForFrame->GetBorderRadii(twipsRadii);
|
|
|
|
|
} else {
|
|
|
|
|
nsIFrame::ComputeBorderRadii(aStyleBorder.mBorderRadius, frameSize,
|
|
|
|
|
aBorderArea.Size(), aSkipSides, twipsRadii);
|
|
|
|
|
}
|
2007-05-30 06:46:54 +04:00
|
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
|
// Turn off rendering for all of the zero sized sides
|
|
|
|
|
if (aSkipSides & SIDE_BIT_TOP) border.top = 0;
|
|
|
|
|
if (aSkipSides & SIDE_BIT_RIGHT) border.right = 0;
|
|
|
|
|
if (aSkipSides & SIDE_BIT_BOTTOM) border.bottom = 0;
|
|
|
|
|
if (aSkipSides & SIDE_BIT_LEFT) border.left = 0;
|
2007-05-30 06:46:54 +04:00
|
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
|
// get the inside and outside parts of the border
|
|
|
|
|
nsRect outerRect(aBorderArea);
|
2007-05-01 07:31:25 +04:00
|
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
|
SF(" outerRect: %d %d %d %d\n", outerRect.x, outerRect.y, outerRect.width, outerRect.height);
|
2007-05-30 06:46:54 +04:00
|
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
|
// we can assume that we're already clipped to aDirtyRect -- I think? (!?)
|
2007-05-30 06:46:54 +04:00
|
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
|
// Get our conversion values
|
|
|
|
|
nscoord twipsPerPixel = aPresContext->DevPixelsToAppUnits(1);
|
2007-05-30 06:46:54 +04:00
|
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
|
// convert outer and inner rects
|
2010-09-08 02:20:35 +04:00
|
|
|
|
gfxRect oRect(nsLayoutUtils::RectToGfxRect(outerRect, twipsPerPixel));
|
2007-05-30 06:46:54 +04:00
|
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
|
// convert the border widths
|
2010-04-20 12:41:21 +04:00
|
|
|
|
gfxFloat borderWidths[4] = { gfxFloat(border.top / twipsPerPixel),
|
|
|
|
|
gfxFloat(border.right / twipsPerPixel),
|
|
|
|
|
gfxFloat(border.bottom / twipsPerPixel),
|
|
|
|
|
gfxFloat(border.left / twipsPerPixel) };
|
2007-05-30 06:46:54 +04:00
|
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
|
// convert the radii
|
|
|
|
|
gfxCornerSizes borderRadii;
|
2010-09-08 02:20:35 +04:00
|
|
|
|
ComputePixelRadii(twipsRadii, twipsPerPixel, &borderRadii);
|
2007-05-30 06:46:54 +04:00
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint8_t borderStyles[4];
|
2008-07-23 21:25:23 +04:00
|
|
|
|
nscolor borderColors[4];
|
|
|
|
|
nsBorderColors *compositeColors[4];
|
2007-05-30 06:46:54 +04:00
|
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
|
// pull out styles, colors, composite colors
|
|
|
|
|
NS_FOR_CSS_SIDES (i) {
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool foreground;
|
2009-11-14 07:23:00 +03:00
|
|
|
|
borderStyles[i] = aStyleBorder.GetBorderStyle(i);
|
|
|
|
|
aStyleBorder.GetBorderColor(i, borderColors[i], foreground);
|
|
|
|
|
aStyleBorder.GetCompositeColors(i, &compositeColors[i]);
|
2007-05-30 06:46:54 +04:00
|
|
|
|
|
2008-09-12 19:35:53 +04:00
|
|
|
|
if (foreground)
|
2008-07-23 21:25:23 +04:00
|
|
|
|
borderColors[i] = ourColor->mColor;
|
2007-05-30 06:46:54 +04:00
|
|
|
|
}
|
|
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
|
SF(" borderStyles: %d %d %d %d\n", borderStyles[0], borderStyles[1], borderStyles[2], borderStyles[3]);
|
2007-05-30 06:46:54 +04:00
|
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
|
// start drawing
|
|
|
|
|
gfxContext *ctx = aRenderingContext.ThebesContext();
|
2007-05-30 06:46:54 +04:00
|
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
|
ctx->Save();
|
2007-05-30 06:46:54 +04:00
|
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
|
#if 0
|
|
|
|
|
// this will draw a transparent red backround underneath the oRect area
|
|
|
|
|
ctx->Save();
|
|
|
|
|
ctx->Rectangle(oRect);
|
|
|
|
|
ctx->SetColor(gfxRGBA(1.0, 0.0, 0.0, 0.5));
|
|
|
|
|
ctx->Fill();
|
|
|
|
|
ctx->Restore();
|
|
|
|
|
#endif
|
2007-05-30 06:46:54 +04:00
|
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
|
//SF ("borderRadii: %f %f %f %f\n", borderRadii[0], borderRadii[1], borderRadii[2], borderRadii[3]);
|
|
|
|
|
|
|
|
|
|
nsCSSBorderRenderer br(twipsPerPixel,
|
|
|
|
|
ctx,
|
|
|
|
|
oRect,
|
|
|
|
|
borderStyles,
|
|
|
|
|
borderWidths,
|
|
|
|
|
borderRadii,
|
|
|
|
|
borderColors,
|
|
|
|
|
compositeColors,
|
|
|
|
|
aSkipSides,
|
2010-04-03 05:58:26 +04:00
|
|
|
|
bgColor);
|
2008-07-23 21:25:23 +04:00
|
|
|
|
br.DrawBorders();
|
2007-05-01 07:31:25 +04:00
|
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
|
ctx->Restore();
|
2007-05-30 06:46:54 +04:00
|
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
|
SN();
|
2007-05-30 06:46:54 +04:00
|
|
|
|
}
|
2007-05-01 07:31:25 +04:00
|
|
|
|
|
2008-09-11 04:24:16 +04:00
|
|
|
|
static nsRect
|
|
|
|
|
GetOutlineInnerRect(nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
nsRect* savedOutlineInnerRect = static_cast<nsRect*>
|
2010-03-29 05:46:55 +04:00
|
|
|
|
(aFrame->Properties().Get(nsIFrame::OutlineInnerRectProperty()));
|
2008-09-11 04:24:16 +04:00
|
|
|
|
if (savedOutlineInnerRect)
|
|
|
|
|
return *savedOutlineInnerRect;
|
2014-02-17 04:05:10 +04:00
|
|
|
|
NS_NOTREACHED("we should have saved a frame property");
|
|
|
|
|
return nsRect(nsPoint(0, 0), aFrame->GetSize());
|
2008-09-11 04:24:16 +04:00
|
|
|
|
}
|
|
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
|
void
|
|
|
|
|
nsCSSRendering::PaintOutline(nsPresContext* aPresContext,
|
2011-04-08 05:04:40 +04:00
|
|
|
|
nsRenderingContext& aRenderingContext,
|
2008-07-23 21:25:23 +04:00
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
|
const nsRect& aBorderArea,
|
2008-08-06 14:33:18 +04:00
|
|
|
|
nsStyleContext* aStyleContext)
|
2007-05-30 06:46:54 +04:00
|
|
|
|
{
|
2008-10-01 09:50:52 +04:00
|
|
|
|
nscoord twipsRadii[8];
|
2007-05-30 06:46:54 +04:00
|
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
|
// Get our style context's color struct.
|
2013-02-17 01:51:02 +04:00
|
|
|
|
const nsStyleOutline* ourOutline = aStyleContext->StyleOutline();
|
2007-05-30 06:46:54 +04:00
|
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
|
nscoord width;
|
2010-04-03 05:58:26 +04:00
|
|
|
|
ourOutline->GetOutlineWidth(width);
|
2007-05-30 06:46:54 +04:00
|
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
|
if (width == 0) {
|
|
|
|
|
// Empty outline
|
|
|
|
|
return;
|
2007-05-30 06:46:54 +04:00
|
|
|
|
}
|
|
|
|
|
|
2010-04-08 16:44:57 +04:00
|
|
|
|
nsIFrame* bgFrame = nsCSSRendering::FindNonTransparentBackgroundFrame
|
2011-10-17 18:59:28 +04:00
|
|
|
|
(aForFrame, false);
|
2013-02-16 09:38:33 +04:00
|
|
|
|
nsStyleContext* bgContext = bgFrame->StyleContext();
|
2010-04-03 05:58:26 +04:00
|
|
|
|
nscolor bgColor =
|
|
|
|
|
bgContext->GetVisitedDependentColor(eCSSProperty_background_color);
|
2007-05-30 06:46:54 +04:00
|
|
|
|
|
2014-02-17 04:05:10 +04:00
|
|
|
|
nsRect innerRect;
|
|
|
|
|
if (
|
|
|
|
|
#ifdef MOZ_XUL
|
|
|
|
|
aStyleContext->GetPseudoType() == nsCSSPseudoElements::ePseudo_XULTree
|
|
|
|
|
#else
|
|
|
|
|
false
|
|
|
|
|
#endif
|
|
|
|
|
) {
|
2014-02-18 08:07:46 +04:00
|
|
|
|
innerRect = aBorderArea;
|
2014-02-15 11:45:31 +04:00
|
|
|
|
} else {
|
2014-02-18 08:07:46 +04:00
|
|
|
|
innerRect = GetOutlineInnerRect(aForFrame) + aBorderArea.TopLeft();
|
2008-06-03 02:52:25 +04:00
|
|
|
|
}
|
2010-04-03 05:58:26 +04:00
|
|
|
|
nscoord offset = ourOutline->mOutlineOffset;
|
2008-09-11 04:24:16 +04:00
|
|
|
|
innerRect.Inflate(offset, offset);
|
2007-05-01 07:31:25 +04: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 04:24:16 +04:00
|
|
|
|
if (innerRect.Contains(aDirtyRect))
|
2007-05-01 07:31:25 +04:00
|
|
|
|
return;
|
2008-09-11 04:24:16 +04:00
|
|
|
|
|
|
|
|
|
nsRect outerRect = innerRect;
|
|
|
|
|
outerRect.Inflate(width, width);
|
2000-02-01 19:03:13 +03:00
|
|
|
|
|
2010-09-08 02:20:35 +04:00
|
|
|
|
// get the radius for our outline
|
|
|
|
|
nsIFrame::ComputeBorderRadii(ourOutline->mOutlineRadius, aBorderArea.Size(),
|
|
|
|
|
outerRect.Size(), 0, twipsRadii);
|
|
|
|
|
|
2007-05-30 06:46:54 +04:00
|
|
|
|
// Get our conversion values
|
2007-05-01 07:31:25 +04:00
|
|
|
|
nscoord twipsPerPixel = aPresContext->DevPixelsToAppUnits(1);
|
|
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
|
// get the outer rectangles
|
2010-09-08 02:20:35 +04:00
|
|
|
|
gfxRect oRect(nsLayoutUtils::RectToGfxRect(outerRect, twipsPerPixel));
|
1999-08-19 18:22:47 +04:00
|
|
|
|
|
2007-05-30 06:46:54 +04:00
|
|
|
|
// convert the radii
|
2007-07-18 18:14:53 +04:00
|
|
|
|
nsMargin outlineMargin(width, width, width, width);
|
2008-07-23 21:25:23 +04:00
|
|
|
|
gfxCornerSizes outlineRadii;
|
2010-09-08 02:20:35 +04:00
|
|
|
|
ComputePixelRadii(twipsRadii, twipsPerPixel, &outlineRadii);
|
1999-08-19 18:22:47 +04:00
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint8_t outlineStyle = ourOutline->GetOutlineStyle();
|
|
|
|
|
uint8_t outlineStyles[4] = { outlineStyle,
|
2007-05-30 06:46:54 +04:00
|
|
|
|
outlineStyle,
|
|
|
|
|
outlineStyle,
|
|
|
|
|
outlineStyle };
|
2007-05-21 02:41:21 +04:00
|
|
|
|
|
2010-04-03 05:58:26 +04: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 06:46:54 +04:00
|
|
|
|
nscolor outlineColors[4] = { outlineColor,
|
|
|
|
|
outlineColor,
|
|
|
|
|
outlineColor,
|
|
|
|
|
outlineColor };
|
2007-05-01 08:58:44 +04:00
|
|
|
|
|
2007-05-30 06:46:54 +04:00
|
|
|
|
// convert the border widths
|
2010-04-20 12:41:21 +04:00
|
|
|
|
gfxFloat outlineWidths[4] = { gfxFloat(width / twipsPerPixel),
|
|
|
|
|
gfxFloat(width / twipsPerPixel),
|
|
|
|
|
gfxFloat(width / twipsPerPixel),
|
|
|
|
|
gfxFloat(width / twipsPerPixel) };
|
1999-08-19 18:22:47 +04:00
|
|
|
|
|
2007-05-30 06:46:54 +04:00
|
|
|
|
// start drawing
|
2008-06-04 02:25:31 +04:00
|
|
|
|
gfxContext *ctx = aRenderingContext.ThebesContext();
|
1999-01-03 22:23:21 +03:00
|
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
|
ctx->Save();
|
1999-02-12 20:45:58 +03:00
|
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
|
nsCSSBorderRenderer br(twipsPerPixel,
|
|
|
|
|
ctx,
|
|
|
|
|
oRect,
|
|
|
|
|
outlineStyles,
|
|
|
|
|
outlineWidths,
|
|
|
|
|
outlineRadii,
|
|
|
|
|
outlineColors,
|
2012-07-30 18:20:58 +04:00
|
|
|
|
nullptr, 0,
|
2010-04-03 05:58:26 +04:00
|
|
|
|
bgColor);
|
2008-08-06 14:33:18 +04:00
|
|
|
|
br.DrawBorders();
|
|
|
|
|
|
|
|
|
|
ctx->Restore();
|
|
|
|
|
|
|
|
|
|
SN();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nsCSSRendering::PaintFocus(nsPresContext* aPresContext,
|
2011-04-08 05:04:40 +04:00
|
|
|
|
nsRenderingContext& aRenderingContext,
|
2008-08-06 14:33:18 +04:00
|
|
|
|
const nsRect& aFocusRect,
|
|
|
|
|
nscolor aColor)
|
|
|
|
|
{
|
|
|
|
|
nscoord oneCSSPixel = nsPresContext::CSSPixelsToAppUnits(1);
|
|
|
|
|
nscoord oneDevPixel = aPresContext->DevPixelsToAppUnits(1);
|
|
|
|
|
|
2010-09-08 02:20:35 +04:00
|
|
|
|
gfxRect focusRect(nsLayoutUtils::RectToGfxRect(aFocusRect, oneDevPixel));
|
2008-08-06 14:33:18 +04:00
|
|
|
|
|
|
|
|
|
gfxCornerSizes focusRadii;
|
|
|
|
|
{
|
2008-10-01 09:50:52 +04:00
|
|
|
|
nscoord twipsRadii[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
|
2010-09-08 02:20:35 +04:00
|
|
|
|
ComputePixelRadii(twipsRadii, oneDevPixel, &focusRadii);
|
2008-08-06 14:33:18 +04:00
|
|
|
|
}
|
2010-04-20 12:41:21 +04:00
|
|
|
|
gfxFloat focusWidths[4] = { gfxFloat(oneCSSPixel / oneDevPixel),
|
|
|
|
|
gfxFloat(oneCSSPixel / oneDevPixel),
|
|
|
|
|
gfxFloat(oneCSSPixel / oneDevPixel),
|
|
|
|
|
gfxFloat(oneCSSPixel / oneDevPixel) };
|
2008-08-06 14:33:18 +04:00
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint8_t focusStyles[4] = { NS_STYLE_BORDER_STYLE_DOTTED,
|
2008-08-06 14:33:18 +04:00
|
|
|
|
NS_STYLE_BORDER_STYLE_DOTTED,
|
|
|
|
|
NS_STYLE_BORDER_STYLE_DOTTED,
|
|
|
|
|
NS_STYLE_BORDER_STYLE_DOTTED };
|
|
|
|
|
nscolor focusColors[4] = { aColor, aColor, aColor, aColor };
|
|
|
|
|
|
|
|
|
|
gfxContext *ctx = aRenderingContext.ThebesContext();
|
|
|
|
|
|
|
|
|
|
ctx->Save();
|
|
|
|
|
|
|
|
|
|
// 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.)
|
|
|
|
|
nsCSSBorderRenderer br(oneDevPixel,
|
|
|
|
|
ctx,
|
|
|
|
|
focusRect,
|
|
|
|
|
focusStyles,
|
|
|
|
|
focusWidths,
|
|
|
|
|
focusRadii,
|
|
|
|
|
focusColors,
|
2012-07-30 18:20:58 +04:00
|
|
|
|
nullptr, 0,
|
2008-08-06 14:33:18 +04:00
|
|
|
|
NS_RGB(255, 0, 0));
|
2008-07-23 21:25:23 +04:00
|
|
|
|
br.DrawBorders();
|
2007-05-01 07:31:25 +04:00
|
|
|
|
|
|
|
|
|
ctx->Restore();
|
|
|
|
|
|
|
|
|
|
SN();
|
1998-12-18 01:58:51 +03:00
|
|
|
|
}
|
|
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
|
// Thebes Border Rendering Code End
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
1998-12-18 01:58:51 +03:00
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
2008-11-05 01:01:21 +03:00
|
|
|
|
/**
|
|
|
|
|
* Computes the placement of a background image.
|
|
|
|
|
*
|
|
|
|
|
* @param aOriginBounds is the box to which the tiling position should be
|
|
|
|
|
* relative
|
|
|
|
|
* This should correspond to 'background-origin' for the frame,
|
|
|
|
|
* except when painting on the canvas, in which case the origin bounds
|
|
|
|
|
* should be the bounds of the root element's frame.
|
|
|
|
|
* @param aTopLeft the top-left corner where an image tile should be drawn
|
|
|
|
|
* @param aAnchorPoint a point which should be pixel-aligned by
|
|
|
|
|
* nsLayoutUtils::DrawImage. This is the same as aTopLeft, unless CSS
|
|
|
|
|
* specifies a percentage (including 'right' or 'bottom'), in which case
|
|
|
|
|
* it's that percentage within of aOriginBounds. So 'right' would set
|
|
|
|
|
* aAnchorPoint.x to aOriginBounds.XMost().
|
2010-04-27 20:15:01 +04:00
|
|
|
|
*
|
2008-11-05 01:01:21 +03:00
|
|
|
|
* Points are returned relative to aOriginBounds.
|
|
|
|
|
*/
|
1998-12-12 06:06:02 +03:00
|
|
|
|
static void
|
2009-02-20 08:29:21 +03:00
|
|
|
|
ComputeBackgroundAnchorPoint(const nsStyleBackground::Layer& aLayer,
|
2008-11-05 01:01:21 +03:00
|
|
|
|
const nsSize& aOriginBounds,
|
|
|
|
|
const nsSize& aImageSize,
|
|
|
|
|
nsPoint* aTopLeft,
|
|
|
|
|
nsPoint* aAnchorPoint)
|
1998-09-26 21:16:56 +04:00
|
|
|
|
{
|
2010-09-15 19:11:26 +04:00
|
|
|
|
double percentX = aLayer.mPosition.mXPosition.mPercent;
|
|
|
|
|
nscoord lengthX = aLayer.mPosition.mXPosition.mLength;
|
|
|
|
|
aAnchorPoint->x = lengthX + NSToCoordRound(percentX*aOriginBounds.width);
|
|
|
|
|
aTopLeft->x = lengthX +
|
|
|
|
|
NSToCoordRound(percentX*(aOriginBounds.width - aImageSize.width));
|
|
|
|
|
|
|
|
|
|
double percentY = aLayer.mPosition.mYPosition.mPercent;
|
|
|
|
|
nscoord lengthY = aLayer.mPosition.mYPosition.mLength;
|
|
|
|
|
aAnchorPoint->y = lengthY + NSToCoordRound(percentY*aOriginBounds.height);
|
|
|
|
|
aTopLeft->y = lengthY +
|
|
|
|
|
NSToCoordRound(percentY*(aOriginBounds.height - aImageSize.height));
|
1999-04-25 06:43:50 +04:00
|
|
|
|
}
|
|
|
|
|
|
2010-04-08 16:44:57 +04:00
|
|
|
|
nsIFrame*
|
|
|
|
|
nsCSSRendering::FindNonTransparentBackgroundFrame(nsIFrame* aFrame,
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool aStartAtParent /*= false*/)
|
2002-08-11 21:56:15 +04:00
|
|
|
|
{
|
2010-04-08 16:44:57 +04:00
|
|
|
|
NS_ASSERTION(aFrame, "Cannot find NonTransparentBackgroundFrame in a null frame");
|
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
|
nsIFrame* frame = nullptr;
|
2002-08-11 21:56:15 +04:00
|
|
|
|
if (aStartAtParent) {
|
2012-06-08 16:22:25 +04:00
|
|
|
|
frame = nsLayoutUtils::GetParentOrPlaceholderFor(aFrame);
|
2004-03-31 07:13:54 +04:00
|
|
|
|
}
|
2010-04-08 16:44:57 +04:00
|
|
|
|
if (!frame) {
|
|
|
|
|
frame = aFrame;
|
2002-08-11 21:56:15 +04:00
|
|
|
|
}
|
2010-04-08 16:44:57 +04:00
|
|
|
|
|
|
|
|
|
while (frame) {
|
2010-04-03 05:58:26 +04:00
|
|
|
|
// No need to call GetVisitedDependentColor because it always uses
|
|
|
|
|
// this alpha component anyway.
|
2013-02-17 01:51:02 +04:00
|
|
|
|
if (NS_GET_A(frame->StyleBackground()->mBackgroundColor) > 0)
|
2002-08-11 21:56:15 +04:00
|
|
|
|
break;
|
|
|
|
|
|
2010-04-08 16:44:57 +04:00
|
|
|
|
if (frame->IsThemed())
|
2009-01-09 03:29:38 +03:00
|
|
|
|
break;
|
|
|
|
|
|
2012-06-08 16:22:25 +04:00
|
|
|
|
nsIFrame* parent = nsLayoutUtils::GetParentOrPlaceholderFor(frame);
|
2009-01-09 03:29:38 +03:00
|
|
|
|
if (!parent)
|
|
|
|
|
break;
|
|
|
|
|
|
2010-04-08 16:44:57 +04:00
|
|
|
|
frame = parent;
|
2002-08-11 21:56:15 +04:00
|
|
|
|
}
|
2010-04-08 16:44:57 +04:00
|
|
|
|
return frame;
|
2002-08-11 21:56:15 +04:00
|
|
|
|
}
|
|
|
|
|
|
2009-04-10 17:41:59 +04: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 10:19:26 +04:00
|
|
|
|
bool
|
2009-04-10 17:41:59 +04: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 21:56:15 +04:00
|
|
|
|
|
2009-04-10 17:41:59 +04:00
|
|
|
|
nsIFrame*
|
2009-12-01 20:21:00 +03:00
|
|
|
|
nsCSSRendering::FindBackgroundStyleFrame(nsIFrame* aForFrame)
|
2009-04-10 17:41:59 +04:00
|
|
|
|
{
|
2013-02-17 01:51:02 +04:00
|
|
|
|
const nsStyleBackground* result = aForFrame->StyleBackground();
|
2009-04-10 17:41:59 +04:00
|
|
|
|
|
|
|
|
|
// Check if we need to do propagation from BODY rather than HTML.
|
2011-06-02 16:56:46 +04: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 15:19:44 +04:00
|
|
|
|
// Use |OwnerDoc| so it works during destruction.
|
2011-06-02 16:56:46 +04:00
|
|
|
|
if (!content) {
|
|
|
|
|
return aForFrame;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-18 14:53:36 +04:00
|
|
|
|
nsIDocument* document = content->OwnerDoc();
|
2011-06-02 16:56:46 +04: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 08:16:09 +04:00
|
|
|
|
// and thus |Initialize| on the pres shell. See bug 119351
|
2011-06-02 16:56:46 +04:00
|
|
|
|
// for the ugly details.
|
|
|
|
|
if (!bodyContent) {
|
|
|
|
|
return aForFrame;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsIFrame *bodyFrame = bodyContent->GetPrimaryFrame();
|
|
|
|
|
if (!bodyFrame) {
|
|
|
|
|
return aForFrame;
|
2009-04-10 17:41:59 +04:00
|
|
|
|
}
|
|
|
|
|
|
2011-06-02 16:56:46 +04:00
|
|
|
|
return nsLayoutUtils::GetStyleFrame(bodyFrame);
|
2009-04-10 17:41:59 +04:00
|
|
|
|
}
|
2002-01-08 02:46:07 +03:00
|
|
|
|
|
2009-04-07 01:00:29 +04: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 12:19:23 +04:00
|
|
|
|
* will be filled in to |aBackground|.
|
2009-04-07 01:00:29 +04:00
|
|
|
|
*/
|
2010-04-03 05:58:26 +04:00
|
|
|
|
nsStyleContext*
|
2009-04-07 01:00:29 +04:00
|
|
|
|
nsCSSRendering::FindRootFrameBackground(nsIFrame* aForFrame)
|
|
|
|
|
{
|
2013-02-16 09:38:33 +04:00
|
|
|
|
return FindBackgroundStyleFrame(aForFrame)->StyleContext();
|
2009-02-16 04:11:34 +03:00
|
|
|
|
}
|
2002-01-08 02:46:07 +03:00
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
|
inline bool
|
2008-08-08 12:21:13 +04:00
|
|
|
|
FindElementBackground(nsIFrame* aForFrame, nsIFrame* aRootElementFrame,
|
2010-04-03 05:58:26 +04:00
|
|
|
|
nsStyleContext** aBackgroundSC)
|
2002-01-08 02:46:07 +03:00
|
|
|
|
{
|
2008-08-08 12:21:13 +04:00
|
|
|
|
if (aForFrame == aRootElementFrame) {
|
|
|
|
|
// We must have propagated our background to the viewport or canvas. Abort.
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return false;
|
2002-01-08 02:46:07 +03:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-16 09:38:33 +04:00
|
|
|
|
*aBackgroundSC = aForFrame->StyleContext();
|
2002-01-08 02:46:07 +03:00
|
|
|
|
|
2005-08-03 00:11:09 +04:00
|
|
|
|
// Return true unless the frame is for a BODY element whose background
|
|
|
|
|
// was propagated to the viewport.
|
|
|
|
|
|
2008-08-08 07:34:43 +04:00
|
|
|
|
nsIContent* content = aForFrame->GetContent();
|
2008-08-08 12:21:13 +04:00
|
|
|
|
if (!content || content->Tag() != nsGkAtoms::body)
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return true; // not frame for a "body" element
|
2008-08-08 12:21:13 +04:00
|
|
|
|
// It could be a non-HTML "body" element but that's OK, we'd fail the
|
|
|
|
|
// bodyContent check below
|
2008-08-08 07:34:43 +04:00
|
|
|
|
|
2013-02-16 09:38:33 +04:00
|
|
|
|
if (aForFrame->StyleContext()->GetPseudo())
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return true; // A pseudo-element frame.
|
2008-08-08 07:34:43 +04:00
|
|
|
|
|
2002-02-26 01:18:26 +03:00
|
|
|
|
// We should only look at the <html> background if we're in an HTML document
|
2011-10-18 14:53:36 +04:00
|
|
|
|
nsIDocument* document = content->OwnerDoc();
|
2002-02-26 01:18:26 +03:00
|
|
|
|
|
2011-06-02 16:56:46 +04:00
|
|
|
|
dom::Element* bodyContent = document->GetBodyElement();
|
2005-11-04 02:06:54 +03:00
|
|
|
|
if (bodyContent != content)
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return true; // this wasn't the background that was propagated
|
2005-11-04 02:06:54 +03:00
|
|
|
|
|
2008-08-08 12:21:13 +04: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 18:59:28 +04:00
|
|
|
|
return true;
|
2008-08-08 12:21:13 +04:00
|
|
|
|
|
2013-02-17 01:51:02 +04:00
|
|
|
|
const nsStyleBackground* htmlBG = aRootElementFrame->StyleBackground();
|
2003-01-17 12:33:52 +03:00
|
|
|
|
return !htmlBG->IsTransparent();
|
2002-01-08 02:46:07 +03:00
|
|
|
|
}
|
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool
|
2013-03-07 20:03:49 +04:00
|
|
|
|
nsCSSRendering::FindBackground(nsIFrame* aForFrame,
|
2010-04-03 05:58:26 +04:00
|
|
|
|
nsStyleContext** aBackgroundSC)
|
2002-01-08 02:46:07 +03:00
|
|
|
|
{
|
2008-08-08 12:21:13 +04:00
|
|
|
|
nsIFrame* rootElementFrame =
|
2013-03-07 20:03:49 +04:00
|
|
|
|
aForFrame->PresContext()->PresShell()->FrameConstructor()->GetRootElementStyleFrame();
|
2009-02-16 04:11:34 +03:00
|
|
|
|
if (IsCanvasFrame(aForFrame)) {
|
2010-04-03 05:58:26 +04:00
|
|
|
|
*aBackgroundSC = FindCanvasBackground(aForFrame, rootElementFrame);
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return true;
|
2009-02-16 04:11:34 +03:00
|
|
|
|
} else {
|
2010-04-03 05:58:26 +04:00
|
|
|
|
return FindElementBackground(aForFrame, rootElementFrame, aBackgroundSC);
|
2009-02-16 04:11:34 +03:00
|
|
|
|
}
|
2002-01-08 02:46:07 +03:00
|
|
|
|
}
|
|
|
|
|
|
2003-01-17 12:33:52 +03:00
|
|
|
|
void
|
2012-11-19 14:54:41 +04:00
|
|
|
|
nsCSSRendering::BeginFrameTreesLocked()
|
|
|
|
|
{
|
|
|
|
|
++gFrameTreeLockCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nsCSSRendering::EndFrameTreesLocked()
|
2003-01-17 12:33:52 +03:00
|
|
|
|
{
|
2012-11-19 14:54:41 +04:00
|
|
|
|
NS_ASSERTION(gFrameTreeLockCount > 0, "Unbalanced EndFrameTreeLocked");
|
|
|
|
|
--gFrameTreeLockCount;
|
|
|
|
|
if (gFrameTreeLockCount == 0) {
|
|
|
|
|
gInlineBGData->Reset();
|
|
|
|
|
}
|
2003-01-17 12:33:52 +03:00
|
|
|
|
}
|
|
|
|
|
|
2008-07-08 04:57:47 +04:00
|
|
|
|
void
|
2009-02-10 11:45:13 +03:00
|
|
|
|
nsCSSRendering::PaintBoxShadowOuter(nsPresContext* aPresContext,
|
2011-04-08 05:04:40 +04:00
|
|
|
|
nsRenderingContext& aRenderingContext,
|
2009-02-10 11:45:13 +03:00
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
|
const nsRect& aFrameArea,
|
2013-11-18 13:32:09 +04:00
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
|
float aOpacity)
|
2008-07-08 04:57:47 +04:00
|
|
|
|
{
|
2013-02-17 01:51:02 +04:00
|
|
|
|
const nsStyleBorder* styleBorder = aForFrame->StyleBorder();
|
2010-08-23 13:30:08 +04:00
|
|
|
|
nsCSSShadowArray* shadows = styleBorder->mBoxShadow;
|
2009-04-06 03:35:53 +04:00
|
|
|
|
if (!shadows)
|
2009-01-28 12:28:14 +03:00
|
|
|
|
return;
|
2008-07-08 04:57:47 +04:00
|
|
|
|
nscoord twipsPerPixel = aPresContext->DevPixelsToAppUnits(1);
|
2008-07-23 21:25:23 +04:00
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool hasBorderRadius;
|
|
|
|
|
bool nativeTheme; // mutually exclusive with hasBorderRadius
|
2008-07-23 21:25:23 +04:00
|
|
|
|
gfxCornerSizes borderRadii;
|
2008-07-08 04:57:47 +04:00
|
|
|
|
|
2010-08-23 13:30:08 +04:00
|
|
|
|
// Get any border radius, since box-shadow must also have rounded corners if the frame does
|
2013-02-17 01:51:02 +04:00
|
|
|
|
const nsStyleDisplay* styleDisplay = aForFrame->StyleDisplay();
|
2010-08-23 13:30:08 +04:00
|
|
|
|
nsITheme::Transparency transparency;
|
|
|
|
|
if (aForFrame->IsThemed(styleDisplay, &transparency)) {
|
|
|
|
|
// We don't respect border-radius for native-themed widgets
|
2011-10-17 18:59:28 +04:00
|
|
|
|
hasBorderRadius = false;
|
2010-08-23 13:30:08 +04: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 18:59:28 +04:00
|
|
|
|
nativeTheme = false;
|
2010-08-23 13:30:08 +04:00
|
|
|
|
nscoord twipsRadii[8];
|
2013-04-18 00:16:14 +04:00
|
|
|
|
NS_ASSERTION(aFrameArea.Size() == aForFrame->VisualBorderRectRelativeToSelf().Size(),
|
|
|
|
|
"unexpected size");
|
2010-09-08 02:20:35 +04:00
|
|
|
|
hasBorderRadius = aForFrame->GetBorderRadii(twipsRadii);
|
2010-08-23 13:30:08 +04:00
|
|
|
|
if (hasBorderRadius) {
|
2010-09-08 02:20:35 +04:00
|
|
|
|
ComputePixelRadii(twipsRadii, twipsPerPixel, &borderRadii);
|
2010-08-23 13:30:08 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsRect frameRect =
|
2010-10-07 08:25:47 +04:00
|
|
|
|
nativeTheme ? aForFrame->GetVisualOverflowRectRelativeToSelf() + aFrameArea.TopLeft() : aFrameArea;
|
2010-09-08 02:20:35 +04:00
|
|
|
|
gfxRect frameGfxRect(nsLayoutUtils::RectToGfxRect(frameRect, twipsPerPixel));
|
2009-01-05 03:41:01 +03:00
|
|
|
|
frameGfxRect.Round();
|
2008-12-03 00:16:22 +03:00
|
|
|
|
|
2010-04-18 07:13:10 +04: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.
|
|
|
|
|
gfxRect skipGfxRect = frameGfxRect;
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool useSkipGfxRect = true;
|
2010-08-23 13:30:08 +04: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-08 02:20:35 +04:00
|
|
|
|
skipGfxRect = nsLayoutUtils::RectToGfxRect(paddingRect, twipsPerPixel);
|
2010-08-23 13:30:08 +04:00
|
|
|
|
} else if (hasBorderRadius) {
|
2011-04-19 07:07:51 +04:00
|
|
|
|
skipGfxRect.Deflate(gfxMargin(
|
2013-03-06 12:05:55 +04: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 07:13:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
|
for (uint32_t i = shadows->Length(); i > 0; --i) {
|
2009-04-06 03:35:53 +04:00
|
|
|
|
nsCSSShadowItem* shadowItem = shadows->ShadowAt(i - 1);
|
2009-02-10 11:45:13 +03:00
|
|
|
|
if (shadowItem->mInset)
|
|
|
|
|
continue;
|
|
|
|
|
|
2010-08-23 13:30:08 +04:00
|
|
|
|
nsRect shadowRect = frameRect;
|
2009-09-18 22:18:35 +04:00
|
|
|
|
shadowRect.MoveBy(shadowItem->mXOffset, shadowItem->mYOffset);
|
2013-11-26 03:06:17 +04:00
|
|
|
|
if (!nativeTheme) {
|
2010-08-23 13:30:08 +04:00
|
|
|
|
shadowRect.Inflate(shadowItem->mSpread, shadowItem->mSpread);
|
|
|
|
|
}
|
2008-07-08 04:57:47 +04: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 22:18:35 +04:00
|
|
|
|
nsRect shadowRectPlusBlur = shadowRect;
|
2008-09-13 07:45:37 +04:00
|
|
|
|
nscoord blurRadius = shadowItem->mRadius;
|
2010-09-11 20:27:12 +04:00
|
|
|
|
shadowRectPlusBlur.Inflate(
|
|
|
|
|
nsContextBoxBlur::GetBlurRadiusMargin(blurRadius, twipsPerPixel));
|
2009-09-18 22:18:35 +04:00
|
|
|
|
|
2010-09-08 02:20:35 +04:00
|
|
|
|
gfxRect shadowGfxRectPlusBlur =
|
|
|
|
|
nsLayoutUtils::RectToGfxRect(shadowRectPlusBlur, twipsPerPixel);
|
2009-09-18 22:18:35 +04:00
|
|
|
|
shadowGfxRectPlusBlur.RoundOut();
|
2008-07-08 04:57:47 +04:00
|
|
|
|
|
|
|
|
|
// Set the shadow color; if not specified, use the foreground color
|
|
|
|
|
nscolor shadowColor;
|
|
|
|
|
if (shadowItem->mHasColor)
|
|
|
|
|
shadowColor = shadowItem->mColor;
|
|
|
|
|
else
|
2013-02-17 01:51:02 +04:00
|
|
|
|
shadowColor = aForFrame->StyleColor()->mColor;
|
2008-07-08 04:57:47 +04:00
|
|
|
|
|
2013-11-18 13:32:09 +04:00
|
|
|
|
gfxRGBA gfxShadowColor(shadowColor);
|
|
|
|
|
gfxShadowColor.a *= aOpacity;
|
|
|
|
|
|
2013-11-26 03:06:17 +04:00
|
|
|
|
gfxContext* renderContext = aRenderingContext.ThebesContext();
|
2010-08-23 13:30:08 +04:00
|
|
|
|
if (nativeTheme) {
|
2013-11-26 03:06:17 +04: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;
|
|
|
|
|
|
|
|
|
|
// shadowContext is owned by either blurringArea or aRenderingContext.
|
|
|
|
|
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 13:30:08 +04: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);
|
2011-04-17 08:08:22 +04:00
|
|
|
|
nsRefPtr<nsRenderingContext> wrapperCtx = new nsRenderingContext();
|
|
|
|
|
wrapperCtx->Init(aPresContext->DeviceContext(), shadowContext);
|
|
|
|
|
wrapperCtx->Translate(nsPoint(shadowItem->mXOffset,
|
|
|
|
|
shadowItem->mYOffset));
|
2010-12-01 06:20:05 +03:00
|
|
|
|
|
|
|
|
|
nsRect nativeRect;
|
|
|
|
|
nativeRect.IntersectRect(frameRect, aDirtyRect);
|
2010-08-23 13:30:08 +04:00
|
|
|
|
aPresContext->GetTheme()->DrawWidgetBackground(wrapperCtx, aForFrame,
|
2010-12-01 06:20:05 +03:00
|
|
|
|
styleDisplay->mAppearance, aFrameArea, nativeRect);
|
2013-11-26 03:06:17 +04:00
|
|
|
|
|
|
|
|
|
blurringArea.DoPaint();
|
|
|
|
|
renderContext->Restore();
|
2010-08-23 13:30:08 +04:00
|
|
|
|
} else {
|
2013-11-26 03:06:17 +04:00
|
|
|
|
renderContext->Save();
|
2010-08-23 13:30:08 +04:00
|
|
|
|
// Clip out the area of the actual frame so the shadow is not shown within
|
|
|
|
|
// the frame
|
|
|
|
|
renderContext->NewPath();
|
|
|
|
|
renderContext->Rectangle(shadowGfxRectPlusBlur);
|
|
|
|
|
if (hasBorderRadius) {
|
|
|
|
|
renderContext->RoundedRectangle(frameGfxRect, borderRadii);
|
|
|
|
|
} else {
|
|
|
|
|
renderContext->Rectangle(frameGfxRect);
|
2009-09-24 10:46:39 +04:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-23 13:30:08 +04:00
|
|
|
|
renderContext->SetFillRule(gfxContext::FILL_RULE_EVEN_ODD);
|
|
|
|
|
renderContext->Clip();
|
|
|
|
|
|
2013-11-26 03:06:17 +04:00
|
|
|
|
gfxCornerSizes clipRectRadii;
|
2010-08-23 13:30:08 +04:00
|
|
|
|
if (hasBorderRadius) {
|
2012-04-30 06:37:04 +04:00
|
|
|
|
gfxFloat spreadDistance = shadowItem->mSpread / twipsPerPixel;
|
2009-09-24 10:46:39 +04:00
|
|
|
|
|
2012-04-30 06:37:04 +04:00
|
|
|
|
gfxFloat borderSizes[4];
|
2009-09-24 10:46:39 +04:00
|
|
|
|
|
2012-04-30 06:37:04 +04:00
|
|
|
|
borderSizes[NS_SIDE_LEFT] = spreadDistance;
|
|
|
|
|
borderSizes[NS_SIDE_TOP] = spreadDistance;
|
|
|
|
|
borderSizes[NS_SIDE_RIGHT] = spreadDistance;
|
|
|
|
|
borderSizes[NS_SIDE_BOTTOM] = spreadDistance;
|
2010-08-23 13:30:08 +04:00
|
|
|
|
|
2012-04-30 06:37:04 +04:00
|
|
|
|
nsCSSBorderRenderer::ComputeOuterRadii(borderRadii, borderSizes,
|
2010-08-23 13:30:08 +04:00
|
|
|
|
&clipRectRadii);
|
2013-11-26 03:06:17 +04:00
|
|
|
|
|
2010-08-23 13:30:08 +04:00
|
|
|
|
}
|
2013-11-26 03:06:17 +04:00
|
|
|
|
nsContextBoxBlur::BlurRectangle(renderContext,
|
|
|
|
|
shadowRect,
|
|
|
|
|
twipsPerPixel,
|
|
|
|
|
hasBorderRadius ? &clipRectRadii : nullptr,
|
|
|
|
|
blurRadius,
|
|
|
|
|
gfxShadowColor,
|
|
|
|
|
aDirtyRect,
|
|
|
|
|
skipGfxRect);
|
|
|
|
|
renderContext->Restore();
|
2009-05-13 13:42:39 +04:00
|
|
|
|
}
|
2008-07-08 04:57:47 +04:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-10 11:45:13 +03:00
|
|
|
|
void
|
|
|
|
|
nsCSSRendering::PaintBoxShadowInner(nsPresContext* aPresContext,
|
2011-04-08 05:04:40 +04:00
|
|
|
|
nsRenderingContext& aRenderingContext,
|
2009-02-10 11:45:13 +03:00
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
|
const nsRect& aFrameArea,
|
|
|
|
|
const nsRect& aDirtyRect)
|
|
|
|
|
{
|
2013-02-17 01:51:02 +04:00
|
|
|
|
const nsStyleBorder* styleBorder = aForFrame->StyleBorder();
|
2010-08-23 13:30:08 +04:00
|
|
|
|
nsCSSShadowArray* shadows = styleBorder->mBoxShadow;
|
2009-04-06 03:35:53 +04:00
|
|
|
|
if (!shadows)
|
2009-02-10 11:45:13 +03:00
|
|
|
|
return;
|
2010-08-23 13:30:08 +04:00
|
|
|
|
if (aForFrame->IsThemed() && aForFrame->GetContent() &&
|
|
|
|
|
!nsContentUtils::IsChromeDoc(aForFrame->GetContent()->GetCurrentDoc())) {
|
|
|
|
|
// 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 11:45:13 +03:00
|
|
|
|
|
2010-11-28 01:49:40 +03:00
|
|
|
|
// Get any border radius, since box-shadow must also have rounded corners
|
|
|
|
|
// if the frame does.
|
2009-02-10 11:45:13 +03:00
|
|
|
|
nscoord twipsRadii[8];
|
2010-11-28 01:49:40 +03:00
|
|
|
|
NS_ASSERTION(aForFrame->GetType() == nsGkAtoms::fieldSetFrame ||
|
|
|
|
|
aFrameArea.Size() == aForFrame->GetSize(), "unexpected size");
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool hasBorderRadius = aForFrame->GetBorderRadii(twipsRadii);
|
2009-02-10 11:45:13 +03:00
|
|
|
|
nscoord twipsPerPixel = aPresContext->DevPixelsToAppUnits(1);
|
|
|
|
|
|
|
|
|
|
nsRect paddingRect = aFrameArea;
|
|
|
|
|
nsMargin border = aForFrame->GetUsedBorder();
|
|
|
|
|
aForFrame->ApplySkipSides(border);
|
|
|
|
|
paddingRect.Deflate(border);
|
|
|
|
|
|
|
|
|
|
gfxCornerSizes innerRadii;
|
|
|
|
|
if (hasBorderRadius) {
|
|
|
|
|
gfxCornerSizes borderRadii;
|
|
|
|
|
|
2010-09-08 02:20:35 +04:00
|
|
|
|
ComputePixelRadii(twipsRadii, twipsPerPixel, &borderRadii);
|
2009-02-10 11:45:13 +03:00
|
|
|
|
gfxFloat borderSizes[4] = {
|
2010-04-20 12:41:21 +04:00
|
|
|
|
gfxFloat(border.top / twipsPerPixel),
|
|
|
|
|
gfxFloat(border.right / twipsPerPixel),
|
|
|
|
|
gfxFloat(border.bottom / twipsPerPixel),
|
|
|
|
|
gfxFloat(border.left / twipsPerPixel)
|
2009-02-10 11:45:13 +03:00
|
|
|
|
};
|
|
|
|
|
nsCSSBorderRenderer::ComputeInnerRadii(borderRadii, borderSizes,
|
|
|
|
|
&innerRadii);
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
|
for (uint32_t i = shadows->Length(); i > 0; --i) {
|
2009-04-06 03:35:53 +04:00
|
|
|
|
nsCSSShadowItem* shadowItem = shadows->ShadowAt(i - 1);
|
2009-02-10 11:45:13 +03:00
|
|
|
|
if (!shadowItem->mInset)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* shadowRect: the frame's padding rect
|
|
|
|
|
* shadowPaintRect: the area to paint on the temp surface, larger than shadowRect
|
|
|
|
|
* so that blurs still happen properly near the edges
|
|
|
|
|
* shadowClipRect: the area on the temporary surface within shadowPaintRect
|
|
|
|
|
* that we will NOT paint in
|
|
|
|
|
*/
|
|
|
|
|
nscoord blurRadius = shadowItem->mRadius;
|
2010-09-11 20:27:12 +04:00
|
|
|
|
nsMargin blurMargin =
|
|
|
|
|
nsContextBoxBlur::GetBlurRadiusMargin(blurRadius, twipsPerPixel);
|
2009-09-18 22:18:35 +04:00
|
|
|
|
nsRect shadowPaintRect = paddingRect;
|
2010-09-11 20:27:12 +04:00
|
|
|
|
shadowPaintRect.Inflate(blurMargin);
|
2009-02-10 11:45:13 +03:00
|
|
|
|
|
2009-09-18 22:18:35 +04:00
|
|
|
|
nsRect shadowClipRect = paddingRect;
|
|
|
|
|
shadowClipRect.MoveBy(shadowItem->mXOffset, shadowItem->mYOffset);
|
|
|
|
|
shadowClipRect.Deflate(shadowItem->mSpread, shadowItem->mSpread);
|
2009-02-10 11:45:13 +03:00
|
|
|
|
|
2010-04-18 07:13:10 +04:00
|
|
|
|
gfxCornerSizes clipRectRadii;
|
|
|
|
|
if (hasBorderRadius) {
|
|
|
|
|
// Calculate the radii the inner clipping rect will have
|
|
|
|
|
gfxFloat spreadDistance = shadowItem->mSpread / twipsPerPixel;
|
|
|
|
|
gfxFloat borderSizes[4] = {0, 0, 0, 0};
|
|
|
|
|
|
|
|
|
|
// 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-28 01:49:40 +03:00
|
|
|
|
// including after blurring.
|
2010-04-18 07:13:10 +04:00
|
|
|
|
nsRect skipRect = shadowClipRect;
|
2010-09-11 20:27:12 +04:00
|
|
|
|
skipRect.Deflate(blurMargin);
|
2010-09-08 02:20:35 +04:00
|
|
|
|
gfxRect skipGfxRect = nsLayoutUtils::RectToGfxRect(skipRect, twipsPerPixel);
|
2010-04-18 07:13:10 +04:00
|
|
|
|
if (hasBorderRadius) {
|
2013-03-06 12:05:55 +04: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 07:13:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
2010-11-28 01:49:40 +03: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 11:45:13 +03:00
|
|
|
|
gfxContext* renderContext = aRenderingContext.ThebesContext();
|
|
|
|
|
nsContextBoxBlur blurringArea;
|
2012-10-25 15:17:10 +04:00
|
|
|
|
gfxContext* shadowContext =
|
2010-11-28 01:49:40 +03:00
|
|
|
|
blurringArea.Init(shadowPaintRect, 0, blurRadius, twipsPerPixel,
|
|
|
|
|
renderContext, aDirtyRect, &skipGfxRect);
|
2009-02-10 11:45:13 +03:00
|
|
|
|
if (!shadowContext)
|
|
|
|
|
continue;
|
|
|
|
|
|
2012-10-25 15:17:10 +04:00
|
|
|
|
// shadowContext is owned by either blurringArea or aRenderingContext.
|
|
|
|
|
MOZ_ASSERT(shadowContext == renderContext ||
|
|
|
|
|
shadowContext == blurringArea.GetContext());
|
|
|
|
|
|
2009-02-10 11:45:13 +03:00
|
|
|
|
// Set the shadow color; if not specified, use the foreground color
|
|
|
|
|
nscolor shadowColor;
|
|
|
|
|
if (shadowItem->mHasColor)
|
|
|
|
|
shadowColor = shadowItem->mColor;
|
|
|
|
|
else
|
2013-02-17 01:51:02 +04:00
|
|
|
|
shadowColor = aForFrame->StyleColor()->mColor;
|
2009-02-10 11:45:13 +03:00
|
|
|
|
|
|
|
|
|
renderContext->Save();
|
|
|
|
|
renderContext->SetColor(gfxRGBA(shadowColor));
|
|
|
|
|
|
|
|
|
|
// Clip the context to the area of the frame's padding rect, so no part of the
|
2010-04-18 07:13:10 +04:00
|
|
|
|
// shadow is painted outside. Also cut out anything beyond where the inset shadow
|
|
|
|
|
// will be.
|
2010-09-08 02:20:35 +04:00
|
|
|
|
gfxRect shadowGfxRect =
|
|
|
|
|
nsLayoutUtils::RectToGfxRect(paddingRect, twipsPerPixel);
|
2009-09-18 22:18:35 +04:00
|
|
|
|
shadowGfxRect.Round();
|
2009-02-10 11:45:13 +03:00
|
|
|
|
renderContext->NewPath();
|
|
|
|
|
if (hasBorderRadius)
|
2011-10-17 18:59:28 +04:00
|
|
|
|
renderContext->RoundedRectangle(shadowGfxRect, innerRadii, false);
|
2009-02-10 11:45:13 +03:00
|
|
|
|
else
|
2009-09-18 22:18:35 +04:00
|
|
|
|
renderContext->Rectangle(shadowGfxRect);
|
2009-02-10 11:45:13 +03:00
|
|
|
|
renderContext->Clip();
|
|
|
|
|
|
2010-11-28 01:49:40 +03:00
|
|
|
|
// Fill the surface minus the area within the frame that we should
|
|
|
|
|
// not paint in, and blur and apply it.
|
2010-09-08 02:20:35 +04:00
|
|
|
|
gfxRect shadowPaintGfxRect =
|
|
|
|
|
nsLayoutUtils::RectToGfxRect(shadowPaintRect, twipsPerPixel);
|
2010-02-04 22:55:10 +03:00
|
|
|
|
shadowPaintGfxRect.RoundOut();
|
2010-09-08 02:20:35 +04:00
|
|
|
|
gfxRect shadowClipGfxRect =
|
|
|
|
|
nsLayoutUtils::RectToGfxRect(shadowClipRect, twipsPerPixel);
|
2009-09-18 22:18:35 +04:00
|
|
|
|
shadowClipGfxRect.Round();
|
2009-02-10 11:45:13 +03:00
|
|
|
|
shadowContext->NewPath();
|
2009-09-18 22:18:35 +04:00
|
|
|
|
shadowContext->Rectangle(shadowPaintGfxRect);
|
2010-04-18 07:13:10 +04:00
|
|
|
|
if (hasBorderRadius)
|
2011-10-17 18:59:28 +04:00
|
|
|
|
shadowContext->RoundedRectangle(shadowClipGfxRect, clipRectRadii, false);
|
2010-04-18 07:13:10 +04:00
|
|
|
|
else
|
2009-09-18 22:18:35 +04:00
|
|
|
|
shadowContext->Rectangle(shadowClipGfxRect);
|
2009-02-10 11:45:13 +03:00
|
|
|
|
shadowContext->SetFillRule(gfxContext::FILL_RULE_EVEN_ODD);
|
|
|
|
|
shadowContext->Fill();
|
|
|
|
|
|
|
|
|
|
blurringArea.DoPaint();
|
|
|
|
|
renderContext->Restore();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1998-09-26 21:16:56 +04:00
|
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
|
nsCSSRendering::PaintBackground(nsPresContext* aPresContext,
|
2011-04-08 05:04:40 +04:00
|
|
|
|
nsRenderingContext& aRenderingContext,
|
1998-09-26 21:16:56 +04:00
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
|
const nsRect& aDirtyRect,
|
1999-01-15 21:25:58 +03:00
|
|
|
|
const nsRect& aBorderArea,
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t aFlags,
|
2012-09-13 14:34:23 +04:00
|
|
|
|
nsRect* aBGClipRect,
|
|
|
|
|
int32_t aLayer)
|
1998-04-14 00:24:54 +04:00
|
|
|
|
{
|
2013-03-16 08:47:02 +04:00
|
|
|
|
PROFILER_LABEL("nsCSSRendering", "PaintBackground");
|
2002-01-08 02:46:07 +03:00
|
|
|
|
NS_PRECONDITION(aForFrame,
|
|
|
|
|
"Frame is expected to be provided to PaintBackground");
|
|
|
|
|
|
2010-04-03 05:58:26 +04:00
|
|
|
|
nsStyleContext *sc;
|
2013-03-07 20:03:49 +04:00
|
|
|
|
if (!FindBackground(aForFrame, &sc)) {
|
2009-07-04 13:30:59 +04:00
|
|
|
|
// We don't want to bail out if moz-appearance is set on a root
|
2002-02-20 05:14:18 +03:00
|
|
|
|
// node. If it has a parent content node, bail because it's not
|
2012-10-25 09:32:25 +04:00
|
|
|
|
// a root, otherwise keep going in order to let the theme stuff
|
2002-02-20 05:14:18 +03:00
|
|
|
|
// draw the background. The canvas really should be drawing the
|
|
|
|
|
// bg, but there's no way to hook that up via css.
|
2013-02-17 01:51:02 +04:00
|
|
|
|
if (!aForFrame->StyleDisplay()->mAppearance) {
|
2003-07-29 01:25:13 +04:00
|
|
|
|
return;
|
2002-02-20 05:14:18 +03:00
|
|
|
|
}
|
2003-07-29 01:25:13 +04:00
|
|
|
|
|
|
|
|
|
nsIContent* content = aForFrame->GetContent();
|
|
|
|
|
if (!content || content->GetParent()) {
|
2002-02-20 05:14:18 +03:00
|
|
|
|
return;
|
2003-07-29 01:25:13 +04:00
|
|
|
|
}
|
2009-07-04 13:30:59 +04:00
|
|
|
|
|
2013-02-16 09:38:33 +04:00
|
|
|
|
sc = aForFrame->StyleContext();
|
2002-02-20 05:14:18 +03:00
|
|
|
|
}
|
2002-01-08 02:46:07 +03:00
|
|
|
|
|
|
|
|
|
PaintBackgroundWithSC(aPresContext, aRenderingContext, aForFrame,
|
2010-04-03 05:58:26 +04:00
|
|
|
|
aDirtyRect, aBorderArea, sc,
|
2013-02-17 01:51:02 +04:00
|
|
|
|
*aForFrame->StyleBorder(), aFlags,
|
2012-09-13 14:34:23 +04:00
|
|
|
|
aBGClipRect, aLayer);
|
2002-01-08 02:46:07 +03:00
|
|
|
|
}
|
|
|
|
|
|
2012-10-25 09:32:25 +04:00
|
|
|
|
void
|
|
|
|
|
nsCSSRendering::PaintBackgroundColor(nsPresContext* aPresContext,
|
|
|
|
|
nsRenderingContext& aRenderingContext,
|
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
|
const nsRect& aBorderArea,
|
|
|
|
|
uint32_t aFlags)
|
|
|
|
|
{
|
2013-03-16 08:47:02 +04:00
|
|
|
|
PROFILER_LABEL("nsCSSRendering", "PaintBackgroundColor");
|
2012-10-25 09:32:25 +04:00
|
|
|
|
NS_PRECONDITION(aForFrame,
|
|
|
|
|
"Frame is expected to be provided to PaintBackground");
|
|
|
|
|
|
|
|
|
|
nsStyleContext *sc;
|
2013-03-07 20:03:49 +04:00
|
|
|
|
if (!FindBackground(aForFrame, &sc)) {
|
2012-10-25 09:32:25 +04:00
|
|
|
|
// We don't want to bail out if moz-appearance is set on a root
|
|
|
|
|
// node. If it has a parent content node, bail because it's not
|
|
|
|
|
// a root, other wise keep going in order to let the theme stuff
|
|
|
|
|
// draw the background. The canvas really should be drawing the
|
|
|
|
|
// bg, but there's no way to hook that up via css.
|
2013-02-17 01:51:02 +04:00
|
|
|
|
if (!aForFrame->StyleDisplay()->mAppearance) {
|
2012-10-25 09:32:25 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsIContent* content = aForFrame->GetContent();
|
|
|
|
|
if (!content || content->GetParent()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-16 09:38:33 +04:00
|
|
|
|
sc = aForFrame->StyleContext();
|
2012-10-25 09:32:25 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PaintBackgroundColorWithSC(aPresContext, aRenderingContext, aForFrame,
|
|
|
|
|
aDirtyRect, aBorderArea, sc,
|
2013-02-17 01:51:02 +04:00
|
|
|
|
*aForFrame->StyleBorder(), aFlags);
|
2012-10-25 09:32:25 +04:00
|
|
|
|
}
|
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
|
static bool
|
2010-04-27 20:15:02 +04:00
|
|
|
|
IsOpaqueBorderEdge(const nsStyleBorder& aBorder, mozilla::css::Side aSide)
|
2008-08-13 07:11:35 +04:00
|
|
|
|
{
|
2012-05-31 09:19:49 +04:00
|
|
|
|
if (aBorder.GetComputedBorder().Side(aSide) == 0)
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return true;
|
2009-10-27 04:43:56 +03: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 18:59:28 +04:00
|
|
|
|
return false;
|
2009-10-27 04:43:56 +03:00
|
|
|
|
}
|
2008-08-13 07:11:35 +04:00
|
|
|
|
|
2008-10-30 12:24:58 +03: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 07:36:41 +04:00
|
|
|
|
if (aBorder.mBorderImageSource.GetType() != eStyleImageType_Null)
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return false;
|
2008-10-30 12:24:58 +03:00
|
|
|
|
|
2008-08-13 07:11:35 +04:00
|
|
|
|
nscolor color;
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool isForeground;
|
2008-09-12 19:35:53 +04:00
|
|
|
|
aBorder.GetBorderColor(aSide, color, isForeground);
|
2008-10-30 12:24:58 +03: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 18:59:28 +04:00
|
|
|
|
return false;
|
2008-10-30 12:24:58 +03:00
|
|
|
|
|
2008-09-12 19:35:53 +04:00
|
|
|
|
return NS_GET_A(color) == 255;
|
2008-08-13 07:11:35 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns true if all border edges are either missing or opaque.
|
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
|
static bool
|
2009-10-27 04:43:56 +03:00
|
|
|
|
IsOpaqueBorder(const nsStyleBorder& aBorder)
|
2008-08-13 07:11:35 +04:00
|
|
|
|
{
|
2009-01-09 03:28:32 +03:00
|
|
|
|
if (aBorder.mBorderColors)
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return false;
|
2010-04-27 20:15:02 +04:00
|
|
|
|
NS_FOR_CSS_SIDES(i) {
|
2009-10-27 04:43:56 +03:00
|
|
|
|
if (!IsOpaqueBorderEdge(aBorder, i))
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return false;
|
2008-08-13 07:11:35 +04:00
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return true;
|
2008-08-13 07:11:35 +04:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-20 08:29:21 +03: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-08 02:20:35 +04:00
|
|
|
|
*aDirtyRectGfx = nsLayoutUtils::RectToGfxRect(*aDirtyRect, aAppUnitsPerPixel);
|
2009-02-20 08:29:21 +03:00
|
|
|
|
NS_WARN_IF_FALSE(aDirtyRect->IsEmpty() || !aDirtyRectGfx->IsEmpty(),
|
|
|
|
|
"converted dirty rect should not be empty");
|
|
|
|
|
NS_ABORT_IF_FALSE(!aDirtyRect->IsEmpty() || aDirtyRectGfx->IsEmpty(),
|
|
|
|
|
"second should be empty if first is");
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-18 22:43:47 +03:00
|
|
|
|
struct BackgroundClipState {
|
2013-07-23 17:22:58 +04:00
|
|
|
|
nsRect mBGClipArea; // Affected by mClippedRadii
|
|
|
|
|
nsRect mAdditionalBGClipArea; // Not affected by mClippedRadii
|
2011-01-18 22:43:47 +03:00
|
|
|
|
nsRect mDirtyRect;
|
|
|
|
|
gfxRect mDirtyRectGfx;
|
|
|
|
|
|
|
|
|
|
gfxCornerSizes mClippedRadii;
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool mRadiiAreOuter;
|
2013-07-23 17:22:58 +04:00
|
|
|
|
bool mHasAdditionalBGClipArea;
|
2011-01-18 22:43:47 +03:00
|
|
|
|
|
|
|
|
|
// Whether we are being asked to draw with a caller provided background
|
|
|
|
|
// clipping area. If this is true we also disable rounded corners.
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool mCustomClip;
|
2011-01-18 22:43:47 +03:00
|
|
|
|
};
|
|
|
|
|
|
2009-02-20 08:29:21 +03:00
|
|
|
|
static void
|
2012-08-22 19:56:38 +04:00
|
|
|
|
GetBackgroundClip(gfxContext *aCtx, uint8_t aBackgroundClip,
|
2013-07-23 17:22:58 +04:00
|
|
|
|
uint8_t aBackgroundAttachment,
|
2011-01-18 22:43:47 +03:00
|
|
|
|
nsIFrame* aForFrame, const nsRect& aBorderArea,
|
2011-09-29 10:19:26 +04:00
|
|
|
|
const nsRect& aCallerDirtyRect, bool aHaveRoundedCorners,
|
2011-01-18 22:43:47 +03:00
|
|
|
|
const gfxCornerSizes& aBGRadii, nscoord aAppUnitsPerPixel,
|
|
|
|
|
/* out */ BackgroundClipState* aClipState)
|
2009-02-20 08:29:21 +03:00
|
|
|
|
{
|
2011-01-18 22:43:47 +03:00
|
|
|
|
aClipState->mBGClipArea = aBorderArea;
|
2013-07-23 17:22:58 +04:00
|
|
|
|
aClipState->mHasAdditionalBGClipArea = false;
|
2011-10-17 18:59:28 +04:00
|
|
|
|
aClipState->mCustomClip = false;
|
|
|
|
|
aClipState->mRadiiAreOuter = true;
|
2011-01-18 22:43:47 +03:00
|
|
|
|
aClipState->mClippedRadii = aBGRadii;
|
2013-07-23 17:22:58 +04:00
|
|
|
|
if (aForFrame->GetType() == nsGkAtoms::scrollFrame &&
|
|
|
|
|
NS_STYLE_BG_ATTACHMENT_LOCAL == aBackgroundAttachment) {
|
|
|
|
|
// 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.
|
|
|
|
|
if (aBackgroundClip == NS_STYLE_BG_CLIP_CONTENT) {
|
|
|
|
|
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;
|
|
|
|
|
aForFrame->ApplySkipSides(padding);
|
|
|
|
|
aClipState->mAdditionalBGClipArea.Deflate(padding);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Also clip at a non-scrolling, rounded-corner 'padding-box',
|
|
|
|
|
// same as the scrolled content because of the 'overflow' property.
|
|
|
|
|
aBackgroundClip = NS_STYLE_BG_CLIP_PADDING;
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-20 08:29:21 +03:00
|
|
|
|
if (aBackgroundClip != NS_STYLE_BG_CLIP_BORDER) {
|
|
|
|
|
nsMargin border = aForFrame->GetUsedBorder();
|
2011-11-23 21:59:51 +04:00
|
|
|
|
if (aBackgroundClip == NS_STYLE_BG_CLIP_MOZ_ALMOST_PADDING) {
|
|
|
|
|
// 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 16:22:03 +04: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);
|
2011-11-23 21:59:51 +04:00
|
|
|
|
} else if (aBackgroundClip != NS_STYLE_BG_CLIP_PADDING) {
|
2010-06-09 05:44:32 +04:00
|
|
|
|
NS_ASSERTION(aBackgroundClip == NS_STYLE_BG_CLIP_CONTENT,
|
|
|
|
|
"unexpected background-clip");
|
|
|
|
|
border += aForFrame->GetUsedPadding();
|
|
|
|
|
}
|
2009-02-20 08:29:21 +03:00
|
|
|
|
aForFrame->ApplySkipSides(border);
|
2011-01-18 22:43:47 +03:00
|
|
|
|
aClipState->mBGClipArea.Deflate(border);
|
2009-02-20 08:29:21 +03:00
|
|
|
|
|
|
|
|
|
if (aHaveRoundedCorners) {
|
|
|
|
|
gfxFloat borderSizes[4] = {
|
2010-04-20 12:41:21 +04:00
|
|
|
|
gfxFloat(border.top / aAppUnitsPerPixel),
|
|
|
|
|
gfxFloat(border.right / aAppUnitsPerPixel),
|
|
|
|
|
gfxFloat(border.bottom / aAppUnitsPerPixel),
|
|
|
|
|
gfxFloat(border.left / aAppUnitsPerPixel)
|
2009-02-20 08:29:21 +03:00
|
|
|
|
};
|
|
|
|
|
nsCSSBorderRenderer::ComputeInnerRadii(aBGRadii, borderSizes,
|
2011-01-18 22:43:47 +03:00
|
|
|
|
&aClipState->mClippedRadii);
|
2011-10-17 18:59:28 +04:00
|
|
|
|
aClipState->mRadiiAreOuter = false;
|
2009-02-20 08:29:21 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-23 17:22:58 +04:00
|
|
|
|
if (!aHaveRoundedCorners && aClipState->mHasAdditionalBGClipArea) {
|
|
|
|
|
// Do the intersection here to account for the fast path(?) below.
|
|
|
|
|
aClipState->mBGClipArea =
|
|
|
|
|
aClipState->mBGClipArea.Intersect(aClipState->mAdditionalBGClipArea);
|
|
|
|
|
aClipState->mHasAdditionalBGClipArea = false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-18 22:43:47 +03:00
|
|
|
|
SetupDirtyRects(aClipState->mBGClipArea, aCallerDirtyRect, aAppUnitsPerPixel,
|
|
|
|
|
&aClipState->mDirtyRect, &aClipState->mDirtyRectGfx);
|
|
|
|
|
}
|
2009-02-20 08:29:21 +03:00
|
|
|
|
|
2011-01-18 22:43:47 +03:00
|
|
|
|
static void
|
|
|
|
|
SetupBackgroundClip(BackgroundClipState& aClipState, gfxContext *aCtx,
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool aHaveRoundedCorners, nscoord aAppUnitsPerPixel,
|
2011-01-18 22:43:47 +03:00
|
|
|
|
gfxContextAutoSaveRestore* aAutoSR)
|
|
|
|
|
{
|
|
|
|
|
if (aClipState.mDirtyRectGfx.IsEmpty()) {
|
2009-02-20 08:29:21 +03:00
|
|
|
|
// Our caller won't draw anything under this condition, so no need
|
|
|
|
|
// to set more up.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-18 22:43:47 +03: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;
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-20 08:29:21 +03: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 17:22:58 +04:00
|
|
|
|
if (aHaveRoundedCorners || aClipState.mHasAdditionalBGClipArea) {
|
|
|
|
|
aAutoSR->Reset(aCtx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (aClipState.mHasAdditionalBGClipArea) {
|
|
|
|
|
gfxRect bgAreaGfx = nsLayoutUtils::RectToGfxRect(
|
|
|
|
|
aClipState.mAdditionalBGClipArea, aAppUnitsPerPixel);
|
|
|
|
|
bgAreaGfx.Round();
|
|
|
|
|
bgAreaGfx.Condition();
|
|
|
|
|
aCtx->NewPath();
|
|
|
|
|
aCtx->Rectangle(bgAreaGfx, true);
|
|
|
|
|
aCtx->Clip();
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-20 08:29:21 +03:00
|
|
|
|
if (aHaveRoundedCorners) {
|
2010-09-08 02:20:35 +04:00
|
|
|
|
gfxRect bgAreaGfx =
|
2011-01-18 22:43:47 +03:00
|
|
|
|
nsLayoutUtils::RectToGfxRect(aClipState.mBGClipArea, aAppUnitsPerPixel);
|
2009-02-20 08:29:21 +03:00
|
|
|
|
bgAreaGfx.Round();
|
|
|
|
|
bgAreaGfx.Condition();
|
|
|
|
|
|
|
|
|
|
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 07:07:21 +04:00
|
|
|
|
aClipState.mDirtyRectGfx.SizeTo(gfxSize(0.0, 0.0));
|
2009-02-20 08:29:21 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
aCtx->NewPath();
|
2011-01-18 22:43:47 +03:00
|
|
|
|
aCtx->RoundedRectangle(bgAreaGfx, aClipState.mClippedRadii, aClipState.mRadiiAreOuter);
|
2009-02-20 08:29:21 +03:00
|
|
|
|
aCtx->Clip();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-18 22:43:47 +03:00
|
|
|
|
static void
|
|
|
|
|
DrawBackgroundColor(BackgroundClipState& aClipState, gfxContext *aCtx,
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool aHaveRoundedCorners, nscoord aAppUnitsPerPixel)
|
2011-01-18 22:43:47 +03:00
|
|
|
|
{
|
|
|
|
|
if (aClipState.mDirtyRectGfx.IsEmpty()) {
|
|
|
|
|
// Our caller won't draw anything under this condition, so no need
|
|
|
|
|
// to set more up.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We don't support custom clips and rounded corners, arguably a bug, but
|
|
|
|
|
// table painting seems to depend on it.
|
|
|
|
|
if (!aHaveRoundedCorners || aClipState.mCustomClip) {
|
|
|
|
|
aCtx->NewPath();
|
2011-10-17 18:59:28 +04:00
|
|
|
|
aCtx->Rectangle(aClipState.mDirtyRectGfx, true);
|
2011-01-18 22:43:47 +03:00
|
|
|
|
aCtx->Fill();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gfxRect bgAreaGfx =
|
|
|
|
|
nsLayoutUtils::RectToGfxRect(aClipState.mBGClipArea, aAppUnitsPerPixel);
|
|
|
|
|
bgAreaGfx.Round();
|
|
|
|
|
bgAreaGfx.Condition();
|
|
|
|
|
|
|
|
|
|
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 07:07:21 +04:00
|
|
|
|
aClipState.mDirtyRectGfx.SizeTo(gfxSize(0.0, 0.0));
|
2011-01-18 22:43:47 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
aCtx->Save();
|
|
|
|
|
gfxRect dirty = bgAreaGfx.Intersect(aClipState.mDirtyRectGfx);
|
|
|
|
|
|
|
|
|
|
aCtx->NewPath();
|
2011-10-17 18:59:28 +04:00
|
|
|
|
aCtx->Rectangle(dirty, true);
|
2011-01-18 22:43:47 +03:00
|
|
|
|
aCtx->Clip();
|
|
|
|
|
|
2013-07-23 17:22:58 +04:00
|
|
|
|
if (aClipState.mHasAdditionalBGClipArea) {
|
|
|
|
|
gfxRect bgAdditionalAreaGfx = nsLayoutUtils::RectToGfxRect(
|
|
|
|
|
aClipState.mAdditionalBGClipArea, aAppUnitsPerPixel);
|
|
|
|
|
bgAdditionalAreaGfx.Round();
|
|
|
|
|
bgAdditionalAreaGfx.Condition();
|
|
|
|
|
aCtx->NewPath();
|
|
|
|
|
aCtx->Rectangle(bgAdditionalAreaGfx, true);
|
|
|
|
|
aCtx->Clip();
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-18 22:43:47 +03:00
|
|
|
|
aCtx->NewPath();
|
|
|
|
|
aCtx->RoundedRectangle(bgAreaGfx, aClipState.mClippedRadii,
|
|
|
|
|
aClipState.mRadiiAreOuter);
|
2013-07-23 17:22:58 +04:00
|
|
|
|
|
2011-01-18 22:43:47 +03:00
|
|
|
|
aCtx->Fill();
|
|
|
|
|
aCtx->Restore();
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-04 00:11:57 +04:00
|
|
|
|
nscolor
|
|
|
|
|
nsCSSRendering::DetermineBackgroundColor(nsPresContext* aPresContext,
|
|
|
|
|
nsStyleContext* aStyleContext,
|
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
|
bool& aDrawBackgroundImage,
|
|
|
|
|
bool& aDrawBackgroundColor)
|
2009-07-04 13:30:59 +04:00
|
|
|
|
{
|
2014-01-18 15:51:03 +04:00
|
|
|
|
if (aFrame->IsThemed()) {
|
|
|
|
|
aDrawBackgroundColor = false;
|
|
|
|
|
aDrawBackgroundImage = false;
|
|
|
|
|
return NS_RGBA(0,0,0,0);
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
|
aDrawBackgroundImage = true;
|
|
|
|
|
aDrawBackgroundColor = true;
|
2009-07-04 13:30:59 +04:00
|
|
|
|
|
|
|
|
|
if (aFrame->HonorPrintBackgroundSettings()) {
|
2009-05-28 22:09:05 +04:00
|
|
|
|
aDrawBackgroundImage = aPresContext->GetBackgroundImageDraw();
|
|
|
|
|
aDrawBackgroundColor = aPresContext->GetBackgroundColorDraw();
|
2009-07-04 13:30:59 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-17 01:51:02 +04:00
|
|
|
|
const nsStyleBackground *bg = aStyleContext->StyleBackground();
|
2009-07-04 13:30:59 +04:00
|
|
|
|
nscolor bgColor;
|
2009-05-28 22:09:05 +04:00
|
|
|
|
if (aDrawBackgroundColor) {
|
2010-04-03 05:58:26 +04:00
|
|
|
|
bgColor =
|
|
|
|
|
aStyleContext->GetVisitedDependentColor(eCSSProperty_background_color);
|
2012-11-08 08:08:40 +04:00
|
|
|
|
if (NS_GET_A(bgColor) == 0) {
|
2011-10-17 18:59:28 +04:00
|
|
|
|
aDrawBackgroundColor = false;
|
2012-11-08 08:08:40 +04:00
|
|
|
|
}
|
2009-07-04 13:30:59 +04: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 08:08:40 +04:00
|
|
|
|
if (aDrawBackgroundImage || !bg->IsTransparent()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
|
aDrawBackgroundColor = true;
|
2012-11-08 08:08:40 +04:00
|
|
|
|
} else {
|
2009-07-04 13:30:59 +04:00
|
|
|
|
bgColor = NS_RGBA(0,0,0,0);
|
2012-11-08 08:08:40 +04:00
|
|
|
|
}
|
2009-07-04 13:30:59 +04:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-04 00:13:12 +04:00
|
|
|
|
// We can skip painting the background color if a background image is opaque.
|
|
|
|
|
if (aDrawBackgroundColor &&
|
|
|
|
|
bg->BottomLayer().mRepeat.mXRepeat == NS_STYLE_BG_REPEAT_REPEAT &&
|
|
|
|
|
bg->BottomLayer().mRepeat.mYRepeat == NS_STYLE_BG_REPEAT_REPEAT &&
|
2014-01-15 00:57:49 +04:00
|
|
|
|
bg->BottomLayer().mImage.IsOpaque() &&
|
|
|
|
|
bg->BottomLayer().mBlendMode == NS_STYLE_BLEND_NORMAL) {
|
2012-05-04 00:13:12 +04:00
|
|
|
|
aDrawBackgroundColor = false;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-04 13:30:59 +04:00
|
|
|
|
return bgColor;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-01 19:53:40 +04:00
|
|
|
|
static gfxFloat
|
|
|
|
|
ConvertGradientValueToPixels(const nsStyleCoord& aCoord,
|
2009-11-02 22:36:43 +03:00
|
|
|
|
gfxFloat aFillLength,
|
2012-08-22 19:56:38 +04:00
|
|
|
|
int32_t aAppUnitsPerPixel)
|
2009-08-01 19:53:40 +04:00
|
|
|
|
{
|
|
|
|
|
switch (aCoord.GetUnit()) {
|
|
|
|
|
case eStyleUnit_Percent:
|
2009-11-02 22:36:43 +03:00
|
|
|
|
return aCoord.GetPercentValue() * aFillLength;
|
2009-08-01 19:53:40 +04:00
|
|
|
|
case eStyleUnit_Coord:
|
2009-11-02 22:36:43 +03:00
|
|
|
|
return NSAppUnitsToFloatPixels(aCoord.GetCoordValue(), aAppUnitsPerPixel);
|
2010-09-15 19:11:26 +04:00
|
|
|
|
case eStyleUnit_Calc: {
|
|
|
|
|
const nsStyleCoord::Calc *calc = aCoord.GetCalcValue();
|
|
|
|
|
return calc->mPercent * aFillLength +
|
|
|
|
|
NSAppUnitsToFloatPixels(calc->mLength, aAppUnitsPerPixel);
|
|
|
|
|
}
|
2009-08-01 19:53:40 +04:00
|
|
|
|
default:
|
|
|
|
|
NS_WARNING("Unexpected coord unit");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-02 22:36:43 +03: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) {
|
|
|
|
|
double angle;
|
|
|
|
|
if (aGradient->mAngle.IsAngleValue()) {
|
|
|
|
|
angle = aGradient->mAngle.GetAngleValueInRadians();
|
2012-07-07 18:27:08 +04:00
|
|
|
|
if (!aGradient->mLegacySyntax) {
|
|
|
|
|
angle = M_PI_2 - angle;
|
|
|
|
|
}
|
2009-11-02 22:36:43 +03:00
|
|
|
|
} else {
|
|
|
|
|
angle = -M_PI_2; // defaults to vertical gradient starting from top
|
|
|
|
|
}
|
|
|
|
|
gfxPoint center(aBoxSize.width/2, aBoxSize.height/2);
|
|
|
|
|
*aLineEnd = ComputeGradientLineEndFromAngle(center, angle, aBoxSize);
|
|
|
|
|
*aLineStart = gfxPoint(aBoxSize.width, aBoxSize.height) - *aLineEnd;
|
2012-07-07 18:27:08 +04:00
|
|
|
|
} else if (!aGradient->mLegacySyntax) {
|
2011-10-22 23:41:11 +04:00
|
|
|
|
float xSign = aGradient->mBgPosX.GetPercentValue() * 2 - 1;
|
|
|
|
|
float ySign = 1 - aGradient->mBgPosY.GetPercentValue() * 2;
|
|
|
|
|
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;
|
2009-11-02 22:36:43 +03:00
|
|
|
|
} else {
|
2012-08-22 19:56:38 +04:00
|
|
|
|
int32_t appUnitsPerPixel = aPresContext->AppUnitsPerDevPixel();
|
2009-11-02 22:36:43 +03:00
|
|
|
|
*aLineStart = gfxPoint(
|
|
|
|
|
ConvertGradientValueToPixels(aGradient->mBgPosX, aBoxSize.width,
|
|
|
|
|
appUnitsPerPixel),
|
|
|
|
|
ConvertGradientValueToPixels(aGradient->mBgPosY, aBoxSize.height,
|
|
|
|
|
appUnitsPerPixel));
|
|
|
|
|
if (aGradient->mAngle.IsAngleValue()) {
|
2012-07-07 18:27:08 +04:00
|
|
|
|
MOZ_ASSERT(aGradient->mLegacySyntax);
|
2009-11-02 22:36:43 +03:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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 19:56:38 +04:00
|
|
|
|
int32_t appUnitsPerPixel = aPresContext->AppUnitsPerDevPixel();
|
2009-11-02 22:36:43 +03: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-06 03:43:44 +04: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 22:36:43 +03:00
|
|
|
|
switch (aGradient->mSize) {
|
|
|
|
|
case NS_STYLE_GRADIENT_SIZE_CLOSEST_SIDE:
|
2013-01-15 16:22:03 +04:00
|
|
|
|
radiusX = std::min(leftDistance, rightDistance);
|
|
|
|
|
radiusY = std::min(topDistance, bottomDistance);
|
2009-11-02 22:36:43 +03:00
|
|
|
|
if (aGradient->mShape == NS_STYLE_GRADIENT_SHAPE_CIRCULAR) {
|
2013-01-15 16:22:03 +04:00
|
|
|
|
radiusX = radiusY = std::min(radiusX, radiusY);
|
2009-11-02 22:36:43 +03:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case NS_STYLE_GRADIENT_SIZE_CLOSEST_CORNER: {
|
|
|
|
|
// Compute x and y distances to nearest corner
|
2013-01-15 16:22:03 +04:00
|
|
|
|
double offsetX = std::min(leftDistance, rightDistance);
|
|
|
|
|
double offsetY = std::min(topDistance, bottomDistance);
|
2009-11-02 22:36:43 +03: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 16:22:03 +04:00
|
|
|
|
radiusX = std::max(leftDistance, rightDistance);
|
|
|
|
|
radiusY = std::max(topDistance, bottomDistance);
|
2009-11-02 22:36:43 +03:00
|
|
|
|
if (aGradient->mShape == NS_STYLE_GRADIENT_SHAPE_CIRCULAR) {
|
2013-01-15 16:22:03 +04:00
|
|
|
|
radiusX = radiusY = std::max(radiusX, radiusY);
|
2009-11-02 22:36:43 +03:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case NS_STYLE_GRADIENT_SIZE_FARTHEST_CORNER: {
|
|
|
|
|
// Compute x and y distances to nearest corner
|
2013-01-15 16:22:03 +04:00
|
|
|
|
double offsetX = std::max(leftDistance, rightDistance);
|
|
|
|
|
double offsetY = std::max(topDistance, bottomDistance);
|
2009-11-02 22:36:43 +03: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 18:27:08 +04:00
|
|
|
|
case NS_STYLE_GRADIENT_SIZE_EXPLICIT_SIZE: {
|
2012-08-22 19:56:38 +04:00
|
|
|
|
int32_t appUnitsPerPixel = aPresContext->AppUnitsPerDevPixel();
|
2012-07-07 18:27:08 +04:00
|
|
|
|
radiusX = ConvertGradientValueToPixels(aGradient->mRadiusX,
|
|
|
|
|
aBoxSize.width, appUnitsPerPixel);
|
|
|
|
|
radiusY = ConvertGradientValueToPixels(aGradient->mRadiusY,
|
|
|
|
|
aBoxSize.height, appUnitsPerPixel);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2009-11-02 22:36:43 +03:00
|
|
|
|
default:
|
2012-10-10 09:00:05 +04:00
|
|
|
|
radiusX = radiusY = 0;
|
2011-10-17 18:59:28 +04:00
|
|
|
|
NS_ABORT_IF_FALSE(false, "unknown radial gradient sizing method");
|
2009-11-02 22:36:43 +03: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));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Returns aFrac*aC2 + (1 - aFrac)*C1. The interpolation is done
|
|
|
|
|
// in unpremultiplied space, which is what SVG gradients and cairo
|
|
|
|
|
// gradients expect.
|
|
|
|
|
static gfxRGBA
|
|
|
|
|
InterpolateColor(const gfxRGBA& aC1, const gfxRGBA& aC2, double aFrac)
|
|
|
|
|
{
|
|
|
|
|
double other = 1 - aFrac;
|
|
|
|
|
return gfxRGBA(aC2.r*aFrac + aC1.r*other,
|
|
|
|
|
aC2.g*aFrac + aC1.g*other,
|
|
|
|
|
aC2.b*aFrac + aC1.b*other,
|
|
|
|
|
aC2.a*aFrac + aC1.a*other);
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-14 05:30:05 +03:00
|
|
|
|
static nscoord
|
|
|
|
|
FindTileStart(nscoord aDirtyCoord, nscoord aTilePos, nscoord aTileDim)
|
|
|
|
|
{
|
|
|
|
|
NS_ASSERTION(aTileDim > 0, "Non-positive tile dimension");
|
2011-05-30 23:08:55 +04:00
|
|
|
|
double multiples = floor(double(aDirtyCoord - aTilePos)/aTileDim);
|
2010-01-14 05:30:05 +03:00
|
|
|
|
return NSToCoordRound(multiples*aTileDim + aTilePos);
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-01 19:53:40 +04:00
|
|
|
|
void
|
|
|
|
|
nsCSSRendering::PaintGradient(nsPresContext* aPresContext,
|
2011-04-08 05:04:40 +04:00
|
|
|
|
nsRenderingContext& aRenderingContext,
|
2009-08-01 19:53:40 +04:00
|
|
|
|
nsStyleGradient* aGradient,
|
|
|
|
|
const nsRect& aDirtyRect,
|
2014-01-31 07:36:41 +04:00
|
|
|
|
const nsRect& aDest,
|
|
|
|
|
const nsRect& aFillArea,
|
|
|
|
|
const CSSIntRect& aSrc,
|
|
|
|
|
const nsSize& aIntrinsicSize)
|
2009-08-01 19:53:40 +04:00
|
|
|
|
{
|
2013-03-16 08:47:02 +04:00
|
|
|
|
PROFILER_LABEL("nsCSSRendering", "PaintGradient");
|
2012-08-27 08:12:36 +04:00
|
|
|
|
Telemetry::AutoTimer<Telemetry::GRADIENT_DURATION, Telemetry::Microsecond> gradientTimer;
|
2014-01-31 07:36:41 +04:00
|
|
|
|
if (aDest.IsEmpty() || aFillArea.IsEmpty()) {
|
2009-11-02 22:36:43 +03:00
|
|
|
|
return;
|
2014-01-31 07:36:41 +04:00
|
|
|
|
}
|
2009-11-02 22:36:43 +03:00
|
|
|
|
|
2009-08-01 19:53:40 +04:00
|
|
|
|
gfxContext *ctx = aRenderingContext.ThebesContext();
|
2014-01-31 07:36:41 +04:00
|
|
|
|
nscoord appUnitsPerDevPixel = aPresContext->AppUnitsPerDevPixel();
|
|
|
|
|
gfxSize srcSize = gfxSize(gfxFloat(aIntrinsicSize.width)/appUnitsPerDevPixel,
|
|
|
|
|
gfxFloat(aIntrinsicSize.height)/appUnitsPerDevPixel);
|
2013-02-15 22:54:49 +04:00
|
|
|
|
|
2014-01-31 07:36:41 +04:00
|
|
|
|
bool cellContainsFill = aDest.Contains(aFillArea);
|
2012-10-26 17:34:43 +04:00
|
|
|
|
|
2014-01-31 07:36:41 +04:00
|
|
|
|
// Compute "gradient line" start and end relative to the intrinsic size of
|
|
|
|
|
// the gradient.
|
2013-02-15 22:54:49 +04:00
|
|
|
|
gfxPoint lineStart, lineEnd;
|
|
|
|
|
double radiusX = 0, radiusY = 0; // for radial gradients only
|
|
|
|
|
if (aGradient->mShape == NS_STYLE_GRADIENT_SHAPE_LINEAR) {
|
2014-01-31 07:36:41 +04:00
|
|
|
|
ComputeLinearGradientLine(aPresContext, aGradient, srcSize,
|
2013-02-15 22:54:49 +04:00
|
|
|
|
&lineStart, &lineEnd);
|
|
|
|
|
} else {
|
2014-01-31 07:36:41 +04:00
|
|
|
|
ComputeRadialGradientLine(aPresContext, aGradient, srcSize,
|
2013-02-15 22:54:49 +04:00
|
|
|
|
&lineStart, &lineEnd, &radiusX, &radiusY);
|
|
|
|
|
}
|
|
|
|
|
gfxFloat lineLength = NS_hypot(lineEnd.x - lineStart.x,
|
|
|
|
|
lineEnd.y - lineStart.y);
|
|
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(aGradient->mStops.Length() >= 2,
|
|
|
|
|
"The parser should reject gradients with less than two stops");
|
|
|
|
|
|
|
|
|
|
// 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 22:36:43 +03:00
|
|
|
|
}
|
2013-02-15 22:54:49 +04:00
|
|
|
|
stops.AppendElement(ColorStop(0, stop.mColor));
|
|
|
|
|
continue;
|
2009-11-02 22:36:43 +03:00
|
|
|
|
}
|
2013-02-15 22:54:49 +04:00
|
|
|
|
break;
|
|
|
|
|
case eStyleUnit_Percent:
|
|
|
|
|
position = stop.mLocation.GetPercentValue();
|
|
|
|
|
break;
|
|
|
|
|
case eStyleUnit_Coord:
|
|
|
|
|
position = lineLength < 1e-6 ? 0.0 :
|
2014-01-31 07:36:41 +04:00
|
|
|
|
stop.mLocation.GetCoordValue() / appUnitsPerDevPixel / lineLength;
|
2013-02-15 22:54:49 +04:00
|
|
|
|
break;
|
|
|
|
|
case eStyleUnit_Calc:
|
|
|
|
|
nsStyleCoord::Calc *calc;
|
|
|
|
|
calc = stop.mLocation.GetCalcValue();
|
|
|
|
|
position = calc->mPercent +
|
|
|
|
|
((lineLength < 1e-6) ? 0.0 :
|
2014-01-31 07:36:41 +04:00
|
|
|
|
(NSAppUnitsToFloatPixels(calc->mLength, appUnitsPerDevPixel) / lineLength));
|
2013-02-15 22:54:49 +04:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
NS_ABORT_IF_FALSE(false, "Unknown stop position type");
|
|
|
|
|
}
|
2009-08-01 19:53:40 +04:00
|
|
|
|
|
2013-02-15 22:54:49 +04: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);
|
|
|
|
|
}
|
|
|
|
|
stops.AppendElement(ColorStop(position, stop.mColor));
|
|
|
|
|
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 22:36:43 +03:00
|
|
|
|
}
|
2013-02-15 22:54:49 +04:00
|
|
|
|
firstUnsetPosition = -1;
|
2009-11-02 22:36:43 +03:00
|
|
|
|
}
|
2013-02-15 22:54:49 +04:00
|
|
|
|
}
|
2009-08-01 19:53:40 +04:00
|
|
|
|
|
2013-02-15 22:54:49 +04: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 08:09:46 +04:00
|
|
|
|
for (uint32_t i = 0; i < stops.Length(); i++) {
|
2013-02-15 22:54:49 +04: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!
|
|
|
|
|
double frac = (0.0 - pos)/(nextPos - pos);
|
|
|
|
|
stops[i].mColor =
|
|
|
|
|
InterpolateColor(stops[i].mColor, stops[i + 1].mColor, frac);
|
2009-11-02 22:36:43 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-15 22:54:49 +04:00
|
|
|
|
firstStop = stops[0].mPosition;
|
|
|
|
|
NS_ABORT_IF_FALSE(firstStop >= 0.0, "Failed to fix stop offsets");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 16:58:10 +04:00
|
|
|
|
double stopOrigin = firstStop;
|
|
|
|
|
double stopEnd = lastStop;
|
2013-02-15 22:54:49 +04: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 22:28:06 +04:00
|
|
|
|
}
|
2013-07-20 16:58:10 +04:00
|
|
|
|
stopDelta = 0.0;
|
2013-02-15 22:54:49 +04:00
|
|
|
|
lastStop = firstStop;
|
|
|
|
|
}
|
2013-01-18 22:28:06 +04:00
|
|
|
|
|
2013-07-20 16:58:10 +04: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 22:54:49 +04:00
|
|
|
|
// Create the gradient pattern.
|
|
|
|
|
nsRefPtr<gfxPattern> gradientPattern;
|
|
|
|
|
bool forceRepeatToCoverTiles = false;
|
2014-01-31 07:36:41 +04:00
|
|
|
|
gfxMatrix matrix;
|
2013-02-15 22:54:49 +04: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.
|
2013-07-20 16:58:10 +04:00
|
|
|
|
gfxPoint gradientStart = lineStart + (lineEnd - lineStart)*stopOrigin;
|
|
|
|
|
gfxPoint gradientEnd = lineStart + (lineEnd - lineStart)*stopEnd;
|
2013-09-24 08:04:36 +04:00
|
|
|
|
gfxPoint gradientStopStart = lineStart + (lineEnd - lineStart)*firstStop;
|
|
|
|
|
gfxPoint gradientStopEnd = lineStart + (lineEnd - lineStart)*lastStop;
|
2009-11-02 22:36:43 +03:00
|
|
|
|
|
2013-07-20 16:58:10 +04:00
|
|
|
|
if (stopDelta == 0.0) {
|
2013-02-15 22:54:49 +04: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 08:04:36 +04:00
|
|
|
|
gradientStopEnd = gradientStopStart + (lineEnd - lineStart);
|
2013-02-15 22:54:49 +04:00
|
|
|
|
}
|
2012-08-27 08:09:46 +04:00
|
|
|
|
|
2013-02-15 22:54:49 +04:00
|
|
|
|
gradientPattern = new gfxPattern(gradientStart.x, gradientStart.y,
|
|
|
|
|
gradientEnd.x, gradientEnd.y);
|
|
|
|
|
|
|
|
|
|
// When the gradient line is parallel to the x axis from the left edge
|
|
|
|
|
// to the right edge of a tile, then we can repeat by just repeating the
|
|
|
|
|
// gradient.
|
|
|
|
|
if (!cellContainsFill &&
|
2013-09-24 08:04:36 +04:00
|
|
|
|
((gradientStopStart.y == gradientStopEnd.y && gradientStopStart.x == 0 &&
|
2014-01-31 07:36:41 +04:00
|
|
|
|
gradientStopEnd.x == srcSize.width) ||
|
2013-09-24 08:04:36 +04:00
|
|
|
|
(gradientStopStart.x == gradientStopEnd.x && gradientStopStart.y == 0 &&
|
2014-01-31 07:36:41 +04:00
|
|
|
|
gradientStopEnd.y == srcSize.height))) {
|
2013-02-15 22:54:49 +04:00
|
|
|
|
forceRepeatToCoverTiles = true;
|
2012-07-02 03:46:32 +04:00
|
|
|
|
}
|
2013-02-15 22:54:49 +04:00
|
|
|
|
} else {
|
|
|
|
|
NS_ASSERTION(firstStop >= 0.0,
|
|
|
|
|
"Negative stops not allowed for radial gradients");
|
2009-11-02 22:36:43 +03:00
|
|
|
|
|
2013-02-15 22:54:49 +04:00
|
|
|
|
// To form an ellipse, we'll stretch a circle vertically, if necessary.
|
|
|
|
|
// So our radii are based on radiusX.
|
2013-07-20 16:58:10 +04:00
|
|
|
|
double innerRadius = radiusX*stopOrigin;
|
|
|
|
|
double outerRadius = radiusX*stopEnd;
|
|
|
|
|
if (stopDelta == 0.0) {
|
2013-02-15 22:54:49 +04: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 22:36:43 +03:00
|
|
|
|
}
|
2013-02-15 22:54:49 +04:00
|
|
|
|
gradientPattern = new gfxPattern(lineStart.x, lineStart.y, innerRadius,
|
2014-01-31 07:36:41 +04:00
|
|
|
|
lineStart.x, lineStart.y, outerRadius);
|
2013-02-15 22:54:49 +04: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 07:36:41 +04: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 22:54:49 +04:00
|
|
|
|
if (gradientPattern->CairoStatus())
|
|
|
|
|
return;
|
2009-08-01 19:53:40 +04:00
|
|
|
|
|
2013-07-20 16:58:10 +04:00
|
|
|
|
if (stopDelta == 0.0) {
|
2013-02-15 22:54:49 +04: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).
|
|
|
|
|
gfxRGBA firstColor(stops[0].mColor);
|
|
|
|
|
gfxRGBA lastColor(stops.LastElement().mColor);
|
|
|
|
|
stops.Clear();
|
|
|
|
|
|
|
|
|
|
if (!aGradient->mRepeating && !zeroRadius) {
|
|
|
|
|
stops.AppendElement(ColorStop(firstStop, firstColor));
|
|
|
|
|
}
|
|
|
|
|
stops.AppendElement(ColorStop(firstStop, lastColor));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool isRepeat = aGradient->mRepeating || forceRepeatToCoverTiles;
|
|
|
|
|
|
|
|
|
|
// Now set normalized color stops in pattern.
|
|
|
|
|
if (!ctx->IsCairo()) {
|
|
|
|
|
// 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++) {
|
|
|
|
|
rawStops[i].color = gfx::Color(stops[i].mColor.r, stops[i].mColor.g, stops[i].mColor.b, stops[i].mColor.a);
|
2013-11-08 08:50:39 +04:00
|
|
|
|
rawStops[i].offset = stopScale * (stops[i].mPosition - stopOrigin);
|
2013-02-15 22:54:49 +04:00
|
|
|
|
}
|
2013-11-08 08:50:39 +04:00
|
|
|
|
mozilla::RefPtr<mozilla::gfx::GradientStops> gs =
|
|
|
|
|
gfxGradientCache::GetOrCreateGradientStops(ctx->GetDrawTarget(),
|
|
|
|
|
rawStops,
|
2014-01-10 23:06:17 +04:00
|
|
|
|
isRepeat ? gfx::ExtendMode::REPEAT : gfx::ExtendMode::CLAMP);
|
2013-02-15 22:54:49 +04:00
|
|
|
|
gradientPattern->SetColorStops(gs);
|
|
|
|
|
} else {
|
|
|
|
|
for (uint32_t i = 0; i < stops.Length(); i++) {
|
2013-07-20 16:58:10 +04:00
|
|
|
|
double pos = stopScale*(stops[i].mPosition - stopOrigin);
|
2013-02-15 22:54:49 +04:00
|
|
|
|
gradientPattern->AddColorStop(pos, stops[i].mColor);
|
|
|
|
|
}
|
2012-08-27 08:09:46 +04:00
|
|
|
|
// Set repeat mode. Default cairo extend mode is PAD.
|
2013-02-15 22:54:49 +04:00
|
|
|
|
if (isRepeat) {
|
2012-08-27 08:09:46 +04:00
|
|
|
|
gradientPattern->SetExtend(gfxPattern::EXTEND_REPEAT);
|
2009-11-02 22:36:43 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2009-08-01 19:53:40 +04:00
|
|
|
|
|
2009-11-02 22:36:43 +03: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-12 00:45:16 +03:00
|
|
|
|
if (!dirty.IntersectRect(aDirtyRect, aFillArea))
|
|
|
|
|
return;
|
|
|
|
|
|
2010-09-08 02:20:35 +04:00
|
|
|
|
gfxRect areaToFill =
|
2014-01-31 07:36:41 +04:00
|
|
|
|
nsLayoutUtils::RectToGfxRect(aFillArea, appUnitsPerDevPixel);
|
2009-11-02 22:36:43 +03:00
|
|
|
|
gfxMatrix ctm = ctx->CurrentMatrix();
|
2012-09-25 07:25:48 +04:00
|
|
|
|
bool isCTMPreservingAxisAlignedRectangles = ctm.PreservesAxisAlignedRectangles();
|
2009-11-02 22:36:43 +03:00
|
|
|
|
|
|
|
|
|
// xStart/yStart are the top-left corner of the top-left tile.
|
2014-01-31 07:36:41 +04:00
|
|
|
|
nscoord xStart = FindTileStart(dirty.x, aDest.x, aDest.width);
|
|
|
|
|
nscoord yStart = FindTileStart(dirty.y, aDest.y, aDest.height);
|
|
|
|
|
nscoord xEnd = forceRepeatToCoverTiles ? xStart + aDest.width : dirty.XMost();
|
|
|
|
|
nscoord yEnd = forceRepeatToCoverTiles ? yStart + aDest.height : dirty.YMost();
|
2012-07-02 03:46:32 +04:00
|
|
|
|
|
2009-11-02 22:36:43 +03:00
|
|
|
|
// x and y are the top-left corner of the tile to draw
|
2014-01-31 07:36:41 +04:00
|
|
|
|
for (nscoord y = yStart; y < yEnd; y += aDest.height) {
|
|
|
|
|
for (nscoord x = xStart; x < xEnd; x += aDest.width) {
|
2009-11-02 22:36:43 +03:00
|
|
|
|
// The coordinates of the tile
|
2010-09-08 02:20:35 +04:00
|
|
|
|
gfxRect tileRect = nsLayoutUtils::RectToGfxRect(
|
2014-01-31 07:36:41 +04:00
|
|
|
|
nsRect(x, y, aDest.width, aDest.height),
|
|
|
|
|
appUnitsPerDevPixel);
|
2009-11-02 22:36:43 +03: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-02 03:46:32 +04:00
|
|
|
|
gfxRect fillRect =
|
2013-02-15 22:54:49 +04:00
|
|
|
|
forceRepeatToCoverTiles ? areaToFill : tileRect.Intersect(areaToFill);
|
2012-09-25 07:25:48 +04: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 05:09:12 +04:00
|
|
|
|
gfxPoint snappedFillRectTopRight = fillRect.TopRight();
|
2012-09-25 07:25:48 +04:00
|
|
|
|
gfxPoint snappedFillRectBottomRight = fillRect.BottomRight();
|
2012-11-23 05:09:12 +04:00
|
|
|
|
// Snap three points instead of just two to ensure we choose the
|
|
|
|
|
// correct orientation if there's a reflection.
|
2012-09-25 07:25:48 +04:00
|
|
|
|
if (isCTMPreservingAxisAlignedRectangles &&
|
|
|
|
|
ctx->UserToDevicePixelSnapped(snappedFillRectTopLeft, true) &&
|
2012-11-23 05:09:12 +04:00
|
|
|
|
ctx->UserToDevicePixelSnapped(snappedFillRectBottomRight, true) &&
|
|
|
|
|
ctx->UserToDevicePixelSnapped(snappedFillRectTopRight, true)) {
|
2012-09-25 07:25:48 +04: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-07 03:58:13 +04:00
|
|
|
|
gfxMatrix transform = gfxUtils::TransformRectToRect(fillRect,
|
2012-11-23 05:09:12 +04:00
|
|
|
|
snappedFillRectTopLeft, snappedFillRectTopRight,
|
|
|
|
|
snappedFillRectBottomRight);
|
|
|
|
|
ctx->SetMatrix(transform);
|
2012-08-10 15:10:12 +04:00
|
|
|
|
}
|
2013-10-30 23:29:22 +04:00
|
|
|
|
ctx->NewPath();
|
2012-09-25 07:25:48 +04:00
|
|
|
|
ctx->Rectangle(fillRect);
|
|
|
|
|
ctx->Translate(tileRect.TopLeft());
|
2013-02-15 22:54:49 +04:00
|
|
|
|
ctx->SetPattern(gradientPattern);
|
2009-11-02 22:36:43 +03:00
|
|
|
|
ctx->Fill();
|
|
|
|
|
ctx->SetMatrix(ctm);
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-08-01 19:53:40 +04:00
|
|
|
|
}
|
|
|
|
|
|
2002-01-08 02:46:07 +03:00
|
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
|
nsCSSRendering::PaintBackgroundWithSC(nsPresContext* aPresContext,
|
2011-04-08 05:04:40 +04:00
|
|
|
|
nsRenderingContext& aRenderingContext,
|
2002-01-08 02:46:07 +03:00
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
|
const nsRect& aBorderArea,
|
2010-04-03 05:58:26 +04:00
|
|
|
|
nsStyleContext* aBackgroundSC,
|
2002-01-08 02:46:07 +03:00
|
|
|
|
const nsStyleBorder& aBorder,
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t aFlags,
|
2012-09-13 14:34:23 +04:00
|
|
|
|
nsRect* aBGClipRect,
|
|
|
|
|
int32_t aLayer)
|
2002-01-08 02:46:07 +03:00
|
|
|
|
{
|
|
|
|
|
NS_PRECONDITION(aForFrame,
|
|
|
|
|
"Frame is expected to be provided to PaintBackground");
|
2000-05-11 03:24:08 +04:00
|
|
|
|
|
2001-12-18 01:51:39 +03:00
|
|
|
|
// Check to see if we have an appearance defined. If so, we let the theme
|
2002-02-21 00:51:25 +03:00
|
|
|
|
// renderer draw the background and bail out.
|
2009-01-09 03:28:32 +03:00
|
|
|
|
// XXXzw this ignores aBGClipRect.
|
2013-02-17 01:51:02 +04:00
|
|
|
|
const nsStyleDisplay* displayData = aForFrame->StyleDisplay();
|
2001-12-18 01:51:39 +03:00
|
|
|
|
if (displayData->mAppearance) {
|
2004-07-29 23:41:39 +04:00
|
|
|
|
nsITheme *theme = aPresContext->GetTheme();
|
2009-01-09 03:28:32 +03:00
|
|
|
|
if (theme && theme->ThemeSupportsWidget(aPresContext, aForFrame,
|
|
|
|
|
displayData->mAppearance)) {
|
2010-07-15 02:25:41 +04:00
|
|
|
|
nsRect drawing(aBorderArea);
|
|
|
|
|
theme->GetWidgetOverflow(aPresContext->DeviceContext(),
|
|
|
|
|
aForFrame, displayData->mAppearance, &drawing);
|
|
|
|
|
drawing.IntersectRect(drawing, aDirtyRect);
|
2010-04-27 20:15:01 +04:00
|
|
|
|
theme->DrawWidgetBackground(&aRenderingContext, aForFrame,
|
2010-07-15 02:25:41 +04:00
|
|
|
|
displayData->mAppearance, aBorderArea,
|
|
|
|
|
drawing);
|
2001-12-18 01:51:39 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-04 13:30:59 +04: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-16 01:07:53 +04: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.
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool isCanvasFrame = IsCanvasFrame(aForFrame);
|
2009-07-04 13:30:59 +04:00
|
|
|
|
|
2009-01-09 03:28:32 +03:00
|
|
|
|
// Determine whether we are drawing background images and/or
|
|
|
|
|
// background colors.
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool drawBackgroundImage;
|
|
|
|
|
bool drawBackgroundColor;
|
2009-01-09 03:28:32 +03:00
|
|
|
|
|
2012-05-04 00:11:57 +04:00
|
|
|
|
nscolor bgColor = DetermineBackgroundColor(aPresContext,
|
|
|
|
|
aBackgroundSC,
|
|
|
|
|
aForFrame,
|
|
|
|
|
drawBackgroundImage,
|
|
|
|
|
drawBackgroundColor);
|
2009-01-08 11:10:21 +03:00
|
|
|
|
|
2012-10-25 09:32:25 +04:00
|
|
|
|
// If we're drawing a specific layer, we don't want to draw the
|
2012-09-13 14:34:23 +04:00
|
|
|
|
// background color.
|
2013-02-17 01:51:02 +04:00
|
|
|
|
const nsStyleBackground *bg = aBackgroundSC->StyleBackground();
|
2012-10-25 09:32:25 +04:00
|
|
|
|
if (drawBackgroundColor && aLayer >= 0) {
|
2012-09-13 14:34:23 +04:00
|
|
|
|
drawBackgroundColor = false;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-09 03:28:32 +03: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)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Compute the outermost boundary of the area that might be painted.
|
2009-01-08 13:19:21 +03:00
|
|
|
|
gfxContext *ctx = aRenderingContext.ThebesContext();
|
2009-01-09 03:28:32 +03:00
|
|
|
|
nscoord appUnitsPerPixel = aPresContext->AppUnitsPerDevPixel();
|
|
|
|
|
|
|
|
|
|
// Same coordinate space as aBorderArea & aBGClipRect
|
|
|
|
|
gfxCornerSizes bgRadii;
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool haveRoundedCorners;
|
2009-01-09 03:28:32 +03:00
|
|
|
|
{
|
|
|
|
|
nscoord radii[8];
|
2010-09-08 02:20:35 +04:00
|
|
|
|
nsSize frameSize = aForFrame->GetSize();
|
2013-02-17 01:51:02 +04:00
|
|
|
|
if (&aBorder == aForFrame->StyleBorder() &&
|
2010-09-08 02:20:35 +04:00
|
|
|
|
frameSize == aBorderArea.Size()) {
|
|
|
|
|
haveRoundedCorners = aForFrame->GetBorderRadii(radii);
|
|
|
|
|
} else {
|
|
|
|
|
haveRoundedCorners = nsIFrame::ComputeBorderRadii(aBorder.mBorderRadius,
|
|
|
|
|
frameSize, aBorderArea.Size(),
|
|
|
|
|
aForFrame->GetSkipSides(), radii);
|
|
|
|
|
}
|
2009-01-09 03:28:32 +03:00
|
|
|
|
if (haveRoundedCorners)
|
2010-09-08 02:20:35 +04:00
|
|
|
|
ComputePixelRadii(radii, appUnitsPerPixel, &bgRadii);
|
2009-01-09 03:28:32 +03:00
|
|
|
|
}
|
2010-04-27 20:15:01 +04:00
|
|
|
|
|
2009-01-09 03:28:32 +03:00
|
|
|
|
// The 'bgClipArea' (used only by the image tiling logic, far below)
|
2009-02-20 08:29:21 +03:00
|
|
|
|
// is the caller-provided aBGClipRect if any, or else the area
|
|
|
|
|
// 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 22:09:05 +04:00
|
|
|
|
// taking the intersection breaks reftests/bugs/403249-1[ab].)
|
2011-01-18 22:43:47 +03:00
|
|
|
|
BackgroundClipState clipState;
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint8_t currentBackgroundClip;
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool isSolidBorder;
|
2009-02-20 08:29:21 +03:00
|
|
|
|
if (aBGClipRect) {
|
2011-01-18 22:43:47 +03:00
|
|
|
|
clipState.mBGClipArea = *aBGClipRect;
|
2011-10-17 18:59:28 +04:00
|
|
|
|
clipState.mCustomClip = true;
|
2011-01-18 22:43:47 +03:00
|
|
|
|
SetupDirtyRects(clipState.mBGClipArea, aDirtyRect, appUnitsPerPixel,
|
|
|
|
|
&clipState.mDirtyRect, &clipState.mDirtyRectGfx);
|
2009-02-20 08:29:21 +03:00
|
|
|
|
} else {
|
|
|
|
|
// The background is rendered over the 'background-clip' area,
|
|
|
|
|
// which is normally equal to the border area but may be reduced
|
|
|
|
|
// to the padding area by CSS. Also, if the border is solid, we
|
|
|
|
|
// don't need to draw outside the padding area. In either case,
|
|
|
|
|
// if the borders are rounded, make sure we use the same inner
|
|
|
|
|
// radii as the border code will.
|
|
|
|
|
// The background-color is drawn based on the bottom
|
|
|
|
|
// background-clip.
|
2010-04-03 05:58:26 +04:00
|
|
|
|
currentBackgroundClip = bg->BottomLayer().mClip;
|
2009-05-28 09:01:42 +04:00
|
|
|
|
isSolidBorder =
|
2009-10-27 04:43:56 +03:00
|
|
|
|
(aFlags & PAINTBG_WILL_PAINT_BORDER) && IsOpaqueBorder(aBorder);
|
2011-11-23 21:59:51 +04:00
|
|
|
|
if (isSolidBorder && currentBackgroundClip == NS_STYLE_BG_CLIP_BORDER) {
|
|
|
|
|
// If we have rounded corners, we need to inflate the background
|
|
|
|
|
// drawing area a bit to avoid seams between the border and
|
|
|
|
|
// background.
|
|
|
|
|
currentBackgroundClip = haveRoundedCorners ?
|
|
|
|
|
NS_STYLE_BG_CLIP_MOZ_ALMOST_PADDING : NS_STYLE_BG_CLIP_PADDING;
|
|
|
|
|
}
|
2011-01-18 22:43:47 +03:00
|
|
|
|
|
2013-07-23 17:22:58 +04:00
|
|
|
|
GetBackgroundClip(ctx, currentBackgroundClip, bg->BottomLayer().mAttachment,
|
|
|
|
|
aForFrame, aBorderArea,
|
2011-01-18 22:43:47 +03:00
|
|
|
|
aDirtyRect, haveRoundedCorners, bgRadii, appUnitsPerPixel,
|
|
|
|
|
&clipState);
|
2009-01-09 03:28:32 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If we might be using a background color, go ahead and set it now.
|
2009-07-04 13:30:59 +04:00
|
|
|
|
if (drawBackgroundColor && !isCanvasFrame)
|
2009-01-09 03:28:32 +03:00
|
|
|
|
ctx->SetColor(gfxRGBA(bgColor));
|
|
|
|
|
|
2011-01-18 22:43:47 +03:00
|
|
|
|
gfxContextAutoSaveRestore autoSR;
|
|
|
|
|
|
2009-01-09 03:28:32 +03: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 22:43:47 +03:00
|
|
|
|
if (!isCanvasFrame) {
|
|
|
|
|
DrawBackgroundColor(clipState, ctx, haveRoundedCorners, appUnitsPerPixel);
|
2009-02-20 08:29:21 +03:00
|
|
|
|
}
|
2009-01-09 03:28:32 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
2009-01-08 13:19:21 +03:00
|
|
|
|
|
2012-09-13 14:34:23 +04:00
|
|
|
|
if (bg->mImageCount < 1) {
|
|
|
|
|
// Return if there are no background layers, all work from this point
|
|
|
|
|
// onwards happens iteratively on these.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Validate the layer range before we start iterating.
|
|
|
|
|
int32_t startLayer = aLayer;
|
|
|
|
|
int32_t nLayers = 1;
|
|
|
|
|
if (startLayer < 0) {
|
|
|
|
|
startLayer = (int32_t)bg->mImageCount - 1;
|
|
|
|
|
nLayers = bg->mImageCount;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-07 21:36:49 +04: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 22:03:28 +03:00
|
|
|
|
// association of the style data with the frame.
|
2013-02-16 09:38:33 +04:00
|
|
|
|
if (aBackgroundSC != aForFrame->StyleContext()) {
|
2012-09-13 14:34:23 +04:00
|
|
|
|
NS_FOR_VISIBLE_BACKGROUND_LAYERS_BACK_TO_FRONT_WITH_RANGE(i, bg, startLayer, nLayers) {
|
2013-07-19 12:40:02 +04:00
|
|
|
|
aForFrame->AssociateImage(bg->mLayers[i].mImage, aPresContext);
|
2012-08-14 02:04:19 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2009-02-19 22:03:28 +03:00
|
|
|
|
|
2009-02-20 08:29:21 +03:00
|
|
|
|
// The background color is rendered over the entire dirty area,
|
|
|
|
|
// even if the image isn't.
|
2009-07-04 13:30:59 +04:00
|
|
|
|
if (drawBackgroundColor && !isCanvasFrame) {
|
2011-01-18 22:43:47 +03:00
|
|
|
|
DrawBackgroundColor(clipState, ctx, haveRoundedCorners, appUnitsPerPixel);
|
2009-02-20 08:29:21 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (drawBackgroundImage) {
|
2011-01-18 22:43:47 +03:00
|
|
|
|
bool clipSet = false;
|
2012-11-02 12:35:32 +04:00
|
|
|
|
NS_FOR_VISIBLE_BACKGROUND_LAYERS_BACK_TO_FRONT_WITH_RANGE(i, bg, bg->mImageCount - 1,
|
|
|
|
|
nLayers + (bg->mImageCount -
|
|
|
|
|
startLayer - 1)) {
|
2010-04-03 05:58:26 +04:00
|
|
|
|
const nsStyleBackground::Layer &layer = bg->mLayers[i];
|
2009-02-20 08:29:21 +03:00
|
|
|
|
if (!aBGClipRect) {
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint8_t newBackgroundClip = layer.mClip;
|
2011-11-23 21:59:51 +04:00
|
|
|
|
if (isSolidBorder && newBackgroundClip == NS_STYLE_BG_CLIP_BORDER) {
|
|
|
|
|
newBackgroundClip = haveRoundedCorners ?
|
|
|
|
|
NS_STYLE_BG_CLIP_MOZ_ALMOST_PADDING : NS_STYLE_BG_CLIP_PADDING;
|
|
|
|
|
}
|
2011-01-18 22:43:47 +03:00
|
|
|
|
if (currentBackgroundClip != newBackgroundClip || !clipSet) {
|
2009-02-20 08:29:21 +03:00
|
|
|
|
currentBackgroundClip = newBackgroundClip;
|
2011-01-18 22:43:47 +03:00
|
|
|
|
// If clipSet is false that means this is the bottom layer and we
|
|
|
|
|
// already called GetBackgroundClip above and it stored its results
|
|
|
|
|
// in clipState.
|
|
|
|
|
if (clipSet) {
|
2013-07-23 17:22:58 +04:00
|
|
|
|
GetBackgroundClip(ctx, currentBackgroundClip, layer.mAttachment, aForFrame,
|
2011-01-18 22:43:47 +03:00
|
|
|
|
aBorderArea, aDirtyRect, haveRoundedCorners,
|
|
|
|
|
bgRadii, appUnitsPerPixel, &clipState);
|
|
|
|
|
}
|
2011-01-18 22:43:47 +03:00
|
|
|
|
SetupBackgroundClip(clipState, ctx, haveRoundedCorners,
|
|
|
|
|
appUnitsPerPixel, &autoSR);
|
2011-01-18 22:43:47 +03:00
|
|
|
|
clipSet = true;
|
2009-02-20 08:29:21 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-11-02 12:35:32 +04:00
|
|
|
|
if ((aLayer < 0 || i == (uint32_t)startLayer) &&
|
|
|
|
|
!clipState.mDirtyRectGfx.IsEmpty()) {
|
2012-05-04 00:11:57 +04:00
|
|
|
|
nsBackgroundLayerState state = PrepareBackgroundLayer(aPresContext, aForFrame,
|
2011-01-18 22:43:47 +03:00
|
|
|
|
aFlags, aBorderArea, clipState.mBGClipArea, *bg, layer);
|
2011-01-03 04:48:09 +03:00
|
|
|
|
if (!state.mFillArea.IsEmpty()) {
|
2013-11-08 19:08:03 +04:00
|
|
|
|
if (state.mCompositingOp != gfxContext::OPERATOR_OVER) {
|
|
|
|
|
NS_ASSERTION(ctx->CurrentOperator() == gfxContext::OPERATOR_OVER,
|
|
|
|
|
"It is assumed the initial operator is OPERATOR_OVER, when it is restored later");
|
|
|
|
|
ctx->SetOperator(state.mCompositingOp);
|
|
|
|
|
}
|
2013-07-19 12:40:02 +04:00
|
|
|
|
state.mImageRenderer.DrawBackground(aPresContext, aRenderingContext,
|
|
|
|
|
state.mDestArea, state.mFillArea,
|
|
|
|
|
state.mAnchor + aBorderArea.TopLeft(),
|
|
|
|
|
clipState.mDirtyRect);
|
2013-11-08 19:08:03 +04:00
|
|
|
|
if (state.mCompositingOp != gfxContext::OPERATOR_OVER) {
|
|
|
|
|
ctx->SetOperator(gfxContext::OPERATOR_OVER);
|
|
|
|
|
}
|
2011-01-03 04:48:09 +03:00
|
|
|
|
}
|
2009-02-20 08:29:21 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-25 09:32:25 +04:00
|
|
|
|
void
|
|
|
|
|
nsCSSRendering::PaintBackgroundColorWithSC(nsPresContext* aPresContext,
|
|
|
|
|
nsRenderingContext& aRenderingContext,
|
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
|
const nsRect& aBorderArea,
|
|
|
|
|
nsStyleContext* aBackgroundSC,
|
|
|
|
|
const nsStyleBorder& aBorder,
|
|
|
|
|
uint32_t aFlags)
|
|
|
|
|
{
|
|
|
|
|
NS_PRECONDITION(aForFrame,
|
|
|
|
|
"Frame is expected to be provided to PaintBackground");
|
|
|
|
|
|
|
|
|
|
// Check to see if we have an appearance defined. If so, we let the theme
|
|
|
|
|
// renderer draw the background and bail out.
|
2013-02-17 01:51:02 +04:00
|
|
|
|
const nsStyleDisplay* displayData = aForFrame->StyleDisplay();
|
2012-10-25 09:32:25 +04:00
|
|
|
|
if (displayData->mAppearance) {
|
|
|
|
|
nsITheme *theme = aPresContext->GetTheme();
|
|
|
|
|
if (theme && theme->ThemeSupportsWidget(aPresContext, aForFrame,
|
|
|
|
|
displayData->mAppearance)) {
|
|
|
|
|
NS_ERROR("Shouldn't be trying to paint a background color if we are themed!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NS_ASSERTION(!IsCanvasFrame(aForFrame), "Should not be trying to paint a background color for canvas frames!");
|
|
|
|
|
|
|
|
|
|
// Determine whether we are drawing background images and/or
|
|
|
|
|
// background colors.
|
|
|
|
|
bool drawBackgroundImage;
|
|
|
|
|
bool drawBackgroundColor;
|
|
|
|
|
nscolor bgColor = DetermineBackgroundColor(aPresContext,
|
|
|
|
|
aBackgroundSC,
|
|
|
|
|
aForFrame,
|
|
|
|
|
drawBackgroundImage,
|
|
|
|
|
drawBackgroundColor);
|
|
|
|
|
|
2014-01-06 03:31:14 +04:00
|
|
|
|
NS_ASSERTION(drawBackgroundImage || drawBackgroundColor,
|
|
|
|
|
"Should not be trying to paint a background if we don't have one");
|
|
|
|
|
if (!drawBackgroundColor) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-10-25 09:32:25 +04:00
|
|
|
|
|
|
|
|
|
// Compute the outermost boundary of the area that might be painted.
|
|
|
|
|
gfxContext *ctx = aRenderingContext.ThebesContext();
|
|
|
|
|
nscoord appUnitsPerPixel = aPresContext->AppUnitsPerDevPixel();
|
|
|
|
|
|
|
|
|
|
// Same coordinate space as aBorderArea
|
|
|
|
|
gfxCornerSizes bgRadii;
|
|
|
|
|
bool haveRoundedCorners;
|
|
|
|
|
{
|
|
|
|
|
nscoord radii[8];
|
|
|
|
|
nsSize frameSize = aForFrame->GetSize();
|
2013-02-17 01:51:02 +04:00
|
|
|
|
if (&aBorder == aForFrame->StyleBorder() &&
|
2012-10-25 09:32:25 +04:00
|
|
|
|
frameSize == aBorderArea.Size()) {
|
|
|
|
|
haveRoundedCorners = aForFrame->GetBorderRadii(radii);
|
|
|
|
|
} else {
|
|
|
|
|
haveRoundedCorners = nsIFrame::ComputeBorderRadii(aBorder.mBorderRadius,
|
|
|
|
|
frameSize, aBorderArea.Size(),
|
|
|
|
|
aForFrame->GetSkipSides(), radii);
|
|
|
|
|
}
|
|
|
|
|
if (haveRoundedCorners)
|
|
|
|
|
ComputePixelRadii(radii, appUnitsPerPixel, &bgRadii);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The background is rendered over the 'background-clip' area,
|
|
|
|
|
// which is normally equal to the border area but may be reduced
|
|
|
|
|
// to the padding area by CSS. Also, if the border is solid, we
|
|
|
|
|
// don't need to draw outside the padding area. In either case,
|
|
|
|
|
// if the borders are rounded, make sure we use the same inner
|
|
|
|
|
// radii as the border code will.
|
|
|
|
|
// The background-color is drawn based on the bottom
|
|
|
|
|
// background-clip.
|
2013-02-17 01:51:02 +04:00
|
|
|
|
const nsStyleBackground *bg = aBackgroundSC->StyleBackground();
|
2012-10-25 09:32:25 +04:00
|
|
|
|
uint8_t currentBackgroundClip = bg->BottomLayer().mClip;
|
|
|
|
|
bool isSolidBorder =
|
|
|
|
|
(aFlags & PAINTBG_WILL_PAINT_BORDER) && IsOpaqueBorder(aBorder);
|
|
|
|
|
if (isSolidBorder && currentBackgroundClip == NS_STYLE_BG_CLIP_BORDER) {
|
|
|
|
|
// If we have rounded corners, we need to inflate the background
|
|
|
|
|
// drawing area a bit to avoid seams between the border and
|
|
|
|
|
// background.
|
|
|
|
|
currentBackgroundClip = haveRoundedCorners ?
|
|
|
|
|
NS_STYLE_BG_CLIP_MOZ_ALMOST_PADDING : NS_STYLE_BG_CLIP_PADDING;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BackgroundClipState clipState;
|
2013-07-23 17:22:58 +04:00
|
|
|
|
GetBackgroundClip(ctx, currentBackgroundClip, bg->BottomLayer().mAttachment,
|
|
|
|
|
aForFrame, aBorderArea,
|
2012-10-25 09:32:25 +04:00
|
|
|
|
aDirtyRect, haveRoundedCorners, bgRadii, appUnitsPerPixel,
|
|
|
|
|
&clipState);
|
|
|
|
|
|
|
|
|
|
ctx->SetColor(gfxRGBA(bgColor));
|
|
|
|
|
|
|
|
|
|
gfxContextAutoSaveRestore autoSR;
|
|
|
|
|
DrawBackgroundColor(clipState, ctx, haveRoundedCorners, appUnitsPerPixel);
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
|
static inline bool
|
2011-02-08 22:29:28 +03:00
|
|
|
|
IsTransformed(nsIFrame* aForFrame, nsIFrame* aTopFrame)
|
|
|
|
|
{
|
|
|
|
|
for (nsIFrame* f = aForFrame; f != aTopFrame; f = f->GetParent()) {
|
|
|
|
|
if (f->IsTransformed()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return true;
|
2011-02-08 22:29:28 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return false;
|
2011-02-08 22:29:28 +03:00
|
|
|
|
}
|
|
|
|
|
|
2012-11-08 19:05:32 +04:00
|
|
|
|
nsRect
|
|
|
|
|
nsCSSRendering::ComputeBackgroundPositioningArea(nsPresContext* aPresContext,
|
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
|
const nsRect& aBorderArea,
|
|
|
|
|
const nsStyleBackground& aBackground,
|
|
|
|
|
const nsStyleBackground::Layer& aLayer,
|
|
|
|
|
nsIFrame** aAttachedToFrame)
|
|
|
|
|
{
|
|
|
|
|
// Compute background origin area relative to aBorderArea now as we may need
|
|
|
|
|
// it to compute the effective image size for a CSS gradient.
|
|
|
|
|
nsRect bgPositioningArea(0, 0, 0, 0);
|
|
|
|
|
|
|
|
|
|
nsIAtom* frameType = aForFrame->GetType();
|
|
|
|
|
nsIFrame* geometryFrame = aForFrame;
|
|
|
|
|
if (frameType == nsGkAtoms::inlineFrame) {
|
|
|
|
|
// XXXjwalden Strictly speaking this is not quite faithful to how
|
|
|
|
|
// background-break is supposed to interact with background-origin values,
|
|
|
|
|
// but it's a non-trivial amount of work to make it fully conformant, and
|
|
|
|
|
// until the specification is more finalized (and assuming background-break
|
|
|
|
|
// even makes the cut) it doesn't make sense to hammer out exact behavior.
|
|
|
|
|
switch (aBackground.mBackgroundInlinePolicy) {
|
|
|
|
|
case NS_STYLE_BG_INLINE_POLICY_EACH_BOX:
|
|
|
|
|
bgPositioningArea = nsRect(nsPoint(0,0), aBorderArea.Size());
|
|
|
|
|
break;
|
|
|
|
|
case NS_STYLE_BG_INLINE_POLICY_BOUNDING_BOX:
|
|
|
|
|
bgPositioningArea = gInlineBGData->GetBoundingRect(aForFrame);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
NS_ERROR("Unknown background-inline-policy value! "
|
|
|
|
|
"Please, teach me what to do.");
|
|
|
|
|
case NS_STYLE_BG_INLINE_POLICY_CONTINUOUS:
|
|
|
|
|
bgPositioningArea = gInlineBGData->GetContinuousRect(aForFrame);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else if (frameType == nsGkAtoms::canvasFrame) {
|
|
|
|
|
geometryFrame = aForFrame->GetFirstPrincipalChild();
|
|
|
|
|
// 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();
|
|
|
|
|
}
|
2013-07-23 17:22:58 +04:00
|
|
|
|
} else if (frameType == nsGkAtoms::scrollFrame &&
|
|
|
|
|
NS_STYLE_BG_ATTACHMENT_LOCAL == aLayer.mAttachment) {
|
|
|
|
|
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.
|
|
|
|
|
if (aLayer.mOrigin == NS_STYLE_BG_ORIGIN_BORDER) {
|
|
|
|
|
nsMargin border = geometryFrame->GetUsedBorder();
|
|
|
|
|
geometryFrame->ApplySkipSides(border);
|
|
|
|
|
bgPositioningArea.Inflate(border);
|
|
|
|
|
bgPositioningArea.Inflate(scrollableFrame->GetActualScrollbarSizes());
|
|
|
|
|
} else if (aLayer.mOrigin != NS_STYLE_BG_ORIGIN_PADDING) {
|
|
|
|
|
nsMargin padding = geometryFrame->GetUsedPadding();
|
|
|
|
|
geometryFrame->ApplySkipSides(padding);
|
|
|
|
|
bgPositioningArea.Deflate(padding);
|
|
|
|
|
NS_ASSERTION(aLayer.mOrigin == NS_STYLE_BG_ORIGIN_CONTENT,
|
|
|
|
|
"unknown background-origin value");
|
|
|
|
|
}
|
|
|
|
|
*aAttachedToFrame = aForFrame;
|
|
|
|
|
return bgPositioningArea;
|
2012-11-08 19:05:32 +04: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
|
|
|
|
|
if (aLayer.mOrigin != NS_STYLE_BG_ORIGIN_BORDER && geometryFrame) {
|
|
|
|
|
nsMargin border = geometryFrame->GetUsedBorder();
|
|
|
|
|
if (aLayer.mOrigin != NS_STYLE_BG_ORIGIN_PADDING) {
|
|
|
|
|
border += geometryFrame->GetUsedPadding();
|
|
|
|
|
NS_ASSERTION(aLayer.mOrigin == NS_STYLE_BG_ORIGIN_CONTENT,
|
|
|
|
|
"unknown background-origin value");
|
|
|
|
|
}
|
|
|
|
|
geometryFrame->ApplySkipSides(border);
|
|
|
|
|
bgPositioningArea.Deflate(border);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsIFrame* attachedToFrame = aForFrame;
|
2012-12-14 02:16:14 +04:00
|
|
|
|
if (NS_STYLE_BG_ATTACHMENT_FIXED == aLayer.mAttachment) {
|
2012-11-08 19:05:32 +04: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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*aAttachedToFrame = attachedToFrame;
|
|
|
|
|
|
|
|
|
|
return bgPositioningArea;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-19 12:39:58 +04: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,
|
|
|
|
|
const nsStyleBackground::Size& aLayerSize)
|
|
|
|
|
{
|
|
|
|
|
// Size is dictated by cover or contain rules.
|
|
|
|
|
if (aLayerSize.mWidthType == nsStyleBackground::Size::eContain ||
|
|
|
|
|
aLayerSize.mWidthType == nsStyleBackground::Size::eCover) {
|
|
|
|
|
nsImageRenderer::FitType fitType =
|
|
|
|
|
aLayerSize.mWidthType == nsStyleBackground::Size::eCover
|
|
|
|
|
? nsImageRenderer::COVER
|
|
|
|
|
: nsImageRenderer::CONTAIN;
|
|
|
|
|
return nsImageRenderer::ComputeConstrainedSize(aBgPositioningArea,
|
|
|
|
|
aIntrinsicSize.mRatio,
|
|
|
|
|
fitType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// No cover/contain constraint, use default algorithm.
|
|
|
|
|
CSSSizeOrRatio specifiedSize;
|
|
|
|
|
if (aLayerSize.mWidthType == nsStyleBackground::Size::eLengthPercentage) {
|
|
|
|
|
specifiedSize.SetWidth(
|
|
|
|
|
aLayerSize.ResolveWidthLengthPercentage(aBgPositioningArea));
|
|
|
|
|
}
|
|
|
|
|
if (aLayerSize.mHeightType == nsStyleBackground::Size::eLengthPercentage) {
|
|
|
|
|
specifiedSize.SetHeight(
|
|
|
|
|
aLayerSize.ResolveHeightLengthPercentage(aBgPositioningArea));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nsImageRenderer::ComputeConcreteSize(specifiedSize,
|
|
|
|
|
aIntrinsicSize,
|
|
|
|
|
aBgPositioningArea);
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-04 00:11:57 +04:00
|
|
|
|
nsBackgroundLayerState
|
|
|
|
|
nsCSSRendering::PrepareBackgroundLayer(nsPresContext* aPresContext,
|
|
|
|
|
nsIFrame* aForFrame,
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t aFlags,
|
2012-05-04 00:11:57 +04:00
|
|
|
|
const nsRect& aBorderArea,
|
|
|
|
|
const nsRect& aBGClipRect,
|
|
|
|
|
const nsStyleBackground& aBackground,
|
|
|
|
|
const nsStyleBackground::Layer& aLayer)
|
2009-02-20 08:29:21 +03:00
|
|
|
|
{
|
2009-05-28 22:09:05 +04:00
|
|
|
|
/*
|
|
|
|
|
* The background properties we need to keep in mind when drawing background
|
|
|
|
|
* layers are:
|
|
|
|
|
*
|
|
|
|
|
* background-image
|
|
|
|
|
* background-repeat
|
|
|
|
|
* background-attachment
|
|
|
|
|
* background-position
|
2010-06-09 05:44:33 +04:00
|
|
|
|
* background-clip
|
|
|
|
|
* background-origin
|
2010-06-09 05:44:33 +04:00
|
|
|
|
* background-size
|
2009-05-28 22:09:05 +04:00
|
|
|
|
* background-break (-moz-background-inline-policy)
|
2013-11-08 19:08:03 +04:00
|
|
|
|
* background-blend-mode
|
2009-05-28 22:09:05 +04: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:
|
|
|
|
|
*
|
|
|
|
|
* background-image
|
|
|
|
|
* no dependencies
|
|
|
|
|
* background-repeat
|
|
|
|
|
* no dependencies
|
|
|
|
|
* background-attachment
|
|
|
|
|
* no dependencies
|
|
|
|
|
* background-position
|
|
|
|
|
* depends upon background-size (for the image's scaled size) and
|
|
|
|
|
* background-break (for the background positioning area)
|
|
|
|
|
* background-clip
|
|
|
|
|
* no dependencies
|
|
|
|
|
* background-origin
|
|
|
|
|
* depends upon background-attachment (only in the case where that value
|
|
|
|
|
* is 'fixed')
|
|
|
|
|
* background-size
|
|
|
|
|
* depends upon background-break (for the background positioning area for
|
|
|
|
|
* resolving percentages), background-image (for the image's intrinsic
|
|
|
|
|
* size), background-repeat (if that value is 'round'), and
|
|
|
|
|
* background-origin (for the background painting area, when
|
|
|
|
|
* background-repeat is 'round')
|
|
|
|
|
* background-break
|
|
|
|
|
* depends upon background-origin (specifying how the boxes making up the
|
|
|
|
|
* background positioning area are determined)
|
|
|
|
|
*
|
|
|
|
|
* 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:
|
|
|
|
|
*
|
|
|
|
|
* background-clip (by caller)
|
|
|
|
|
* background-image
|
|
|
|
|
* background-break, background-origin
|
|
|
|
|
* background-attachment (postfix for background-{origin,break} if 'fixed')
|
|
|
|
|
* background-size
|
|
|
|
|
* background-position
|
|
|
|
|
* background-repeat
|
|
|
|
|
*/
|
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t irFlags = 0;
|
2011-01-03 04:48:09 +03:00
|
|
|
|
if (aFlags & nsCSSRendering::PAINTBG_SYNC_DECODE_IMAGES) {
|
2012-05-04 00:11:57 +04:00
|
|
|
|
irFlags |= nsImageRenderer::FLAG_SYNC_DECODE_IMAGES;
|
2011-01-03 04:48:09 +03:00
|
|
|
|
}
|
2013-04-26 02:08:58 +04:00
|
|
|
|
if (aFlags & nsCSSRendering::PAINTBG_TO_WINDOW) {
|
|
|
|
|
irFlags |= nsImageRenderer::FLAG_PAINTING_TO_WINDOW;
|
|
|
|
|
}
|
2011-01-03 04:48:09 +03:00
|
|
|
|
|
2012-05-04 00:11:57 +04:00
|
|
|
|
nsBackgroundLayerState state(aForFrame, &aLayer.mImage, irFlags);
|
2011-01-03 04:48:09 +03:00
|
|
|
|
if (!state.mImageRenderer.PrepareImage()) {
|
2009-08-22 00:39:25 +04:00
|
|
|
|
// There's no image or it's not ready to be painted.
|
2011-01-03 04:48:09 +03:00
|
|
|
|
return state;
|
2009-08-22 00:39:25 +04:00
|
|
|
|
}
|
|
|
|
|
|
2012-11-08 19:05:32 +04:00
|
|
|
|
// The frame to which the background is attached
|
|
|
|
|
nsIFrame* attachedToFrame = aForFrame;
|
2009-08-22 00:39:25 +04: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 19:05:32 +04:00
|
|
|
|
nsRect bgPositioningArea =
|
|
|
|
|
ComputeBackgroundPositioningArea(aPresContext, aForFrame, aBorderArea,
|
|
|
|
|
aBackground, aLayer, &attachedToFrame);
|
1999-01-15 21:25:58 +03:00
|
|
|
|
|
2010-01-07 03:55:09 +03: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 14:24:53 +04:00
|
|
|
|
// Compute the anchor point.
|
|
|
|
|
//
|
2008-11-05 01:01:21 +03:00
|
|
|
|
// relative to aBorderArea.TopLeft() (which is where the top-left
|
|
|
|
|
// of aForFrame's border-box will be rendered)
|
2011-01-03 04:48:09 +03:00
|
|
|
|
nsPoint imageTopLeft;
|
2009-02-20 08:29:21 +03:00
|
|
|
|
if (NS_STYLE_BG_ATTACHMENT_FIXED == aLayer.mAttachment) {
|
2012-11-08 19:05:32 +04:00
|
|
|
|
if ((aFlags & nsCSSRendering::PAINTBG_TO_WINDOW) &&
|
|
|
|
|
!IsTransformed(aForFrame, attachedToFrame)) {
|
2010-01-07 03:55:09 +03:00
|
|
|
|
// Clip background-attachment:fixed backgrounds to the viewport, if we're
|
2011-02-08 22:29:28 +03: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 03:55:09 +03:00
|
|
|
|
bgClipRect.IntersectRect(bgClipRect, bgPositioningArea + aBorderArea.TopLeft());
|
|
|
|
|
}
|
2009-05-28 22:09:05 +04:00
|
|
|
|
}
|
2009-08-22 21:10:12 +04:00
|
|
|
|
|
2009-05-28 22:09:05 +04:00
|
|
|
|
// Scale the image as specified for background-size and as required for
|
|
|
|
|
// proper background positioning when background-position is defined with
|
|
|
|
|
// percentages.
|
2013-07-19 12:39:58 +04:00
|
|
|
|
CSSSizeOrRatio intrinsicSize = state.mImageRenderer.ComputeIntrinsicSize();
|
2013-08-01 08:22:40 +04:00
|
|
|
|
nsSize bgPositionSize = bgPositioningArea.Size();
|
2013-07-19 12:39:58 +04:00
|
|
|
|
nsSize imageSize = ComputeDrawnSizeForBackground(intrinsicSize,
|
2013-08-01 08:22:40 +04:00
|
|
|
|
bgPositionSize,
|
2013-07-19 12:39:58 +04:00
|
|
|
|
aLayer.mSize);
|
2011-01-13 13:40:12 +03:00
|
|
|
|
if (imageSize.width <= 0 || imageSize.height <= 0)
|
|
|
|
|
return state;
|
2009-05-28 22:09:05 +04:00
|
|
|
|
|
2013-07-19 12:39:58 +04:00
|
|
|
|
state.mImageRenderer.SetPreferredSize(intrinsicSize,
|
2013-08-01 08:22:40 +04:00
|
|
|
|
imageSize);
|
2013-07-19 12:39:58 +04:00
|
|
|
|
|
2009-05-28 22:09:05 +04:00
|
|
|
|
// Compute the position of the background now that the background's size is
|
|
|
|
|
// determined.
|
2013-08-01 08:22:40 +04:00
|
|
|
|
ComputeBackgroundAnchorPoint(aLayer, bgPositionSize, imageSize,
|
2011-01-03 04:48:09 +03:00
|
|
|
|
&imageTopLeft, &state.mAnchor);
|
2010-01-07 03:55:09 +03:00
|
|
|
|
imageTopLeft += bgPositioningArea.TopLeft();
|
2011-01-03 04:48:09 +03:00
|
|
|
|
state.mAnchor += bgPositioningArea.TopLeft();
|
2001-08-18 03:26:29 +04:00
|
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
|
state.mDestArea = nsRect(imageTopLeft + aBorderArea.TopLeft(), imageSize);
|
|
|
|
|
state.mFillArea = state.mDestArea;
|
2012-08-09 11:09:40 +04:00
|
|
|
|
int repeatX = aLayer.mRepeat.mXRepeat;
|
|
|
|
|
int repeatY = aLayer.mRepeat.mYRepeat;
|
2012-02-25 09:23:14 +04:00
|
|
|
|
if (repeatX == NS_STYLE_BG_REPEAT_REPEAT) {
|
2011-01-03 04:48:09 +03:00
|
|
|
|
state.mFillArea.x = bgClipRect.x;
|
|
|
|
|
state.mFillArea.width = bgClipRect.width;
|
2002-10-08 14:24:53 +04:00
|
|
|
|
}
|
2012-02-25 09:23:14 +04:00
|
|
|
|
if (repeatY == NS_STYLE_BG_REPEAT_REPEAT) {
|
2011-01-03 04:48:09 +03:00
|
|
|
|
state.mFillArea.y = bgClipRect.y;
|
|
|
|
|
state.mFillArea.height = bgClipRect.height;
|
2002-10-08 14:24:53 +04:00
|
|
|
|
}
|
2011-01-03 04:48:09 +03:00
|
|
|
|
state.mFillArea.IntersectRect(state.mFillArea, bgClipRect);
|
2013-11-08 19:08:03 +04:00
|
|
|
|
|
|
|
|
|
state.mCompositingOp = GetGFXBlendMode(aLayer.mBlendMode);
|
|
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
|
return state;
|
|
|
|
|
}
|
1998-07-31 03:31:42 +04:00
|
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
|
nsRect
|
|
|
|
|
nsCSSRendering::GetBackgroundLayerRect(nsPresContext* aPresContext,
|
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
|
const nsRect& aBorderArea,
|
2013-02-04 16:11:49 +04:00
|
|
|
|
const nsRect& aClipRect,
|
2011-01-03 04:48:09 +03:00
|
|
|
|
const nsStyleBackground& aBackground,
|
2013-06-04 08:49:03 +04:00
|
|
|
|
const nsStyleBackground::Layer& aLayer,
|
|
|
|
|
uint32_t aFlags)
|
2011-01-03 04:48:09 +03:00
|
|
|
|
{
|
2012-05-04 00:11:57 +04:00
|
|
|
|
nsBackgroundLayerState state =
|
2013-06-04 08:49:03 +04:00
|
|
|
|
PrepareBackgroundLayer(aPresContext, aForFrame, aFlags, aBorderArea,
|
2013-02-04 16:11:49 +04:00
|
|
|
|
aClipRect, aBackground, aLayer);
|
2011-01-03 04:48:09 +03:00
|
|
|
|
return state.mFillArea;
|
2002-10-08 14:24:53 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-26 20:43:27 +04:00
|
|
|
|
/* static */ bool
|
|
|
|
|
nsCSSRendering::IsBackgroundImageDecodedForStyleContextAndLayer(
|
|
|
|
|
const nsStyleBackground *aBackground, uint32_t aLayer)
|
|
|
|
|
{
|
|
|
|
|
const nsStyleImage* image = &aBackground->mLayers[aLayer].mImage;
|
|
|
|
|
if (image->GetType() == eStyleImageType_Image) {
|
|
|
|
|
nsCOMPtr<imgIContainer> img;
|
|
|
|
|
if (NS_SUCCEEDED(image->GetImageData()->GetImage(getter_AddRefs(img)))) {
|
|
|
|
|
if (!img->IsDecoded()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-26 20:43:26 +04:00
|
|
|
|
/* static */ bool
|
|
|
|
|
nsCSSRendering::AreAllBackgroundImagesDecodedForFrame(nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
const nsStyleBackground *bg = aFrame->StyleContext()->StyleBackground();
|
|
|
|
|
NS_FOR_VISIBLE_BACKGROUND_LAYERS_BACK_TO_FRONT(i, bg) {
|
2013-06-26 20:43:27 +04:00
|
|
|
|
if (!IsBackgroundImageDecodedForStyleContextAndLayer(bg, i)) {
|
|
|
|
|
return false;
|
2013-06-26 20:43:26 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-25 20:03:15 +04:00
|
|
|
|
static void
|
2009-02-16 04:04:03 +03:00
|
|
|
|
DrawBorderImage(nsPresContext* aPresContext,
|
2011-12-23 03:34:45 +04:00
|
|
|
|
nsRenderingContext& aRenderingContext,
|
2009-02-16 04:04:03 +03:00
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
|
const nsRect& aBorderArea,
|
2009-11-14 07:23:00 +03:00
|
|
|
|
const nsStyleBorder& aStyleBorder,
|
2009-02-16 04:04:03 +03:00
|
|
|
|
const nsRect& aDirtyRect)
|
2008-07-17 10:30:25 +04:00
|
|
|
|
{
|
2011-04-04 15:41:02 +04:00
|
|
|
|
NS_PRECONDITION(aStyleBorder.IsBorderImageLoaded(),
|
|
|
|
|
"drawing border image that isn't successfully loaded");
|
|
|
|
|
|
2009-02-16 04:04:03 +03:00
|
|
|
|
if (aDirtyRect.IsEmpty())
|
|
|
|
|
return;
|
2008-07-17 10:30:25 +04:00
|
|
|
|
|
2014-01-31 07:36:41 +04:00
|
|
|
|
nsImageRenderer renderer(aForFrame, &aStyleBorder.mBorderImageSource, 0);
|
|
|
|
|
|
2009-02-19 22:03:28 +03: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 07:36:41 +04:00
|
|
|
|
aForFrame->AssociateImage(aStyleBorder.mBorderImageSource, aPresContext);
|
2009-02-16 04:04:03 +03:00
|
|
|
|
|
2014-01-31 07:36:41 +04:00
|
|
|
|
if (!renderer.PrepareImage()) {
|
|
|
|
|
return;
|
2010-09-10 21:42:57 +04:00
|
|
|
|
}
|
2009-02-16 04:04:03 +03:00
|
|
|
|
|
2011-12-23 03:34:45 +04:00
|
|
|
|
// Determine the border image area, which by default corresponds to the
|
|
|
|
|
// border box but can be modified by 'border-image-outset'.
|
|
|
|
|
nsRect borderImgArea(aBorderArea);
|
|
|
|
|
borderImgArea.Inflate(aStyleBorder.GetImageOutset());
|
|
|
|
|
|
2014-01-31 07:36:41 +04: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 07:36:41 +04:00
|
|
|
|
renderer.SetPreferredSize(intrinsicSize, imageSize);
|
2014-01-31 07:36:41 +04:00
|
|
|
|
|
2011-12-23 03:34:45 +04: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 07:36:41 +04:00
|
|
|
|
nsMargin slice;
|
2011-12-23 03:34:45 +04:00
|
|
|
|
nsMargin border;
|
2009-02-16 04:04:03 +03:00
|
|
|
|
NS_FOR_CSS_SIDES(s) {
|
2011-12-23 03:34:45 +04:00
|
|
|
|
nsStyleCoord coord = aStyleBorder.mBorderImageSlice.Get(s);
|
2012-08-22 19:56:38 +04:00
|
|
|
|
int32_t imgDimension = NS_SIDE_IS_VERTICAL(s)
|
2014-01-31 07:36:41 +04:00
|
|
|
|
? imageSize.width : imageSize.height;
|
2011-12-23 03:34:45 +04:00
|
|
|
|
nscoord borderDimension = NS_SIDE_IS_VERTICAL(s)
|
|
|
|
|
? borderImgArea.width : borderImgArea.height;
|
2009-02-16 04:04:03 +03:00
|
|
|
|
double value;
|
|
|
|
|
switch (coord.GetUnit()) {
|
|
|
|
|
case eStyleUnit_Percent:
|
|
|
|
|
value = coord.GetPercentValue() * imgDimension;
|
|
|
|
|
break;
|
|
|
|
|
case eStyleUnit_Factor:
|
2014-01-31 07:36:41 +04:00
|
|
|
|
value = nsPresContext::CSSPixelsToAppUnits(
|
|
|
|
|
NS_lround(coord.GetFactorValue()));
|
2009-02-16 04:04:03 +03:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2011-12-23 03:34:45 +04:00
|
|
|
|
NS_NOTREACHED("unexpected CSS unit for image slice");
|
2009-02-16 04:04:03 +03:00
|
|
|
|
value = 0;
|
|
|
|
|
break;
|
2008-07-17 10:30:25 +04:00
|
|
|
|
}
|
2009-02-16 04:04:03 +03:00
|
|
|
|
if (value < 0)
|
|
|
|
|
value = 0;
|
|
|
|
|
if (value > imgDimension)
|
|
|
|
|
value = imgDimension;
|
2014-01-31 07:36:41 +04:00
|
|
|
|
slice.Side(s) = value;
|
2009-02-16 04:04:03 +03:00
|
|
|
|
|
2012-05-31 09:19:49 +04:00
|
|
|
|
nsMargin borderWidths(aStyleBorder.GetComputedBorder());
|
2011-12-23 03:34:45 +04: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 07:36:41 +04:00
|
|
|
|
value = slice.Side(s);
|
2011-12-23 03:34:45 +04:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
NS_NOTREACHED("unexpected CSS unit for border image area division");
|
|
|
|
|
value = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-02-19 02:14:31 +04: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 23:57:20 +04:00
|
|
|
|
MOZ_ASSERT(border.Side(s) >= 0);
|
2011-12-23 03:34:45 +04: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 23:57:20 +04: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-23 03:34:45 +04:00
|
|
|
|
: 1.0;
|
2013-02-14 23:57:20 +04: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-23 03:34:45 +04:00
|
|
|
|
: 1.0;
|
2013-01-15 16:22:03 +04:00
|
|
|
|
double scale = std::min(scaleX, scaleY);
|
2011-12-23 03:34:45 +04: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 04:04:03 +03: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-23 03:34:45 +04:00
|
|
|
|
// to be relative to the innerRect (for 'slice') or the page (for 'border').
|
2009-02-16 04:04:03 +03:00
|
|
|
|
enum {
|
|
|
|
|
LEFT, MIDDLE, RIGHT,
|
|
|
|
|
TOP = LEFT, BOTTOM = RIGHT
|
|
|
|
|
};
|
|
|
|
|
const nscoord borderX[3] = {
|
2011-12-23 03:34:45 +04:00
|
|
|
|
borderImgArea.x + 0,
|
|
|
|
|
borderImgArea.x + border.left,
|
|
|
|
|
borderImgArea.x + borderImgArea.width - border.right,
|
2009-02-16 04:04:03 +03:00
|
|
|
|
};
|
|
|
|
|
const nscoord borderY[3] = {
|
2011-12-23 03:34:45 +04:00
|
|
|
|
borderImgArea.y + 0,
|
|
|
|
|
borderImgArea.y + border.top,
|
|
|
|
|
borderImgArea.y + borderImgArea.height - border.bottom,
|
2009-02-16 04:04:03 +03:00
|
|
|
|
};
|
|
|
|
|
const nscoord borderWidth[3] = {
|
|
|
|
|
border.left,
|
2011-12-23 03:34:45 +04:00
|
|
|
|
borderImgArea.width - border.left - border.right,
|
2009-02-16 04:04:03 +03:00
|
|
|
|
border.right,
|
|
|
|
|
};
|
|
|
|
|
const nscoord borderHeight[3] = {
|
|
|
|
|
border.top,
|
2011-12-23 03:34:45 +04:00
|
|
|
|
borderImgArea.height - border.top - border.bottom,
|
2009-02-16 04:04:03 +03:00
|
|
|
|
border.bottom,
|
|
|
|
|
};
|
2012-08-22 19:56:38 +04: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 05:50:15 +04:00
|
|
|
|
0,
|
2011-12-23 03:34:45 +04:00
|
|
|
|
slice.left,
|
2014-01-31 07:36:41 +04:00
|
|
|
|
imageSize.width - slice.right,
|
2009-02-16 04:04:03 +03:00
|
|
|
|
};
|
2012-08-22 19:56:38 +04: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 05:50:15 +04:00
|
|
|
|
0,
|
2011-12-23 03:34:45 +04:00
|
|
|
|
slice.top,
|
2014-01-31 07:36:41 +04:00
|
|
|
|
imageSize.height - slice.bottom,
|
2009-02-16 04:04:03 +03:00
|
|
|
|
};
|
2012-08-22 19:56:38 +04:00
|
|
|
|
const int32_t sliceWidth[3] = {
|
2011-12-23 03:34:45 +04:00
|
|
|
|
slice.left,
|
2014-01-31 07:36:41 +04:00
|
|
|
|
std::max(imageSize.width - slice.left - slice.right, 0),
|
2011-12-23 03:34:45 +04:00
|
|
|
|
slice.right,
|
2009-02-16 04:04:03 +03:00
|
|
|
|
};
|
2012-08-22 19:56:38 +04:00
|
|
|
|
const int32_t sliceHeight[3] = {
|
2011-12-23 03:34:45 +04:00
|
|
|
|
slice.top,
|
2014-01-31 07:36:41 +04:00
|
|
|
|
std::max(imageSize.height - slice.top - slice.bottom, 0),
|
2011-12-23 03:34:45 +04:00
|
|
|
|
slice.bottom,
|
2009-02-16 04:04:03 +03:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for (int i = LEFT; i <= RIGHT; i++) {
|
|
|
|
|
for (int j = TOP; j <= BOTTOM; j++) {
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint8_t fillStyleH, fillStyleV;
|
2009-02-16 04:04:03 +03:00
|
|
|
|
nsSize unitSize;
|
2009-02-20 06:33:30 +03:00
|
|
|
|
|
2009-02-16 04:04:03 +03:00
|
|
|
|
if (i == MIDDLE && j == MIDDLE) {
|
2011-12-23 03:34:45 +04: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 06:33:30 +03:00
|
|
|
|
// css-background:
|
2009-02-24 11:31:22 +03: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 06:33:30 +03:00
|
|
|
|
gfxFloat hFactor, vFactor;
|
|
|
|
|
|
2011-12-23 03:34:45 +04: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 06:33:30 +03:00
|
|
|
|
else
|
2014-01-31 07:36:41 +04:00
|
|
|
|
vFactor = 1;
|
2009-02-20 06:33:30 +03:00
|
|
|
|
|
2011-12-23 03:34:45 +04: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 06:33:30 +03:00
|
|
|
|
else
|
2014-01-31 07:36:41 +04:00
|
|
|
|
hFactor = 1;
|
2009-02-20 06:33:30 +03:00
|
|
|
|
|
2011-12-23 03:34:45 +04:00
|
|
|
|
unitSize.width = sliceWidth[i]*hFactor;
|
|
|
|
|
unitSize.height = sliceHeight[j]*vFactor;
|
|
|
|
|
fillStyleH = aStyleBorder.mBorderImageRepeatH;
|
|
|
|
|
fillStyleV = aStyleBorder.mBorderImageRepeatV;
|
2009-02-20 06:33:30 +03: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 11:31:22 +03:00
|
|
|
|
gfxFloat factor;
|
2011-12-23 03:34:45 +04:00
|
|
|
|
if (0 < borderHeight[j] && 0 < sliceHeight[j])
|
|
|
|
|
factor = gfxFloat(borderHeight[j])/sliceHeight[j];
|
2009-02-24 11:31:22 +03:00
|
|
|
|
else
|
2014-01-31 07:36:41 +04:00
|
|
|
|
factor = 1;
|
2009-02-20 06:33:30 +03:00
|
|
|
|
|
2011-12-23 03:34:45 +04:00
|
|
|
|
unitSize.width = sliceWidth[i]*factor;
|
2009-02-16 04:04:03 +03:00
|
|
|
|
unitSize.height = borderHeight[j];
|
2011-12-23 03:34:45 +04:00
|
|
|
|
fillStyleH = aStyleBorder.mBorderImageRepeatH;
|
|
|
|
|
fillStyleV = NS_STYLE_BORDER_IMAGE_REPEAT_STRETCH;
|
2009-02-20 06:33:30 +03:00
|
|
|
|
|
|
|
|
|
} else if (j == MIDDLE) { // left, right
|
2009-02-24 11:31:22 +03:00
|
|
|
|
gfxFloat factor;
|
2011-12-23 03:34:45 +04:00
|
|
|
|
if (0 < borderWidth[i] && 0 < sliceWidth[i])
|
|
|
|
|
factor = gfxFloat(borderWidth[i])/sliceWidth[i];
|
2009-02-24 11:31:22 +03:00
|
|
|
|
else
|
2014-01-31 07:36:41 +04:00
|
|
|
|
factor = 1;
|
2009-02-20 06:33:30 +03:00
|
|
|
|
|
2009-02-16 04:04:03 +03:00
|
|
|
|
unitSize.width = borderWidth[i];
|
2011-12-23 03:34:45 +04:00
|
|
|
|
unitSize.height = sliceHeight[j]*factor;
|
|
|
|
|
fillStyleH = NS_STYLE_BORDER_IMAGE_REPEAT_STRETCH;
|
|
|
|
|
fillStyleV = aStyleBorder.mBorderImageRepeatV;
|
2009-02-20 06:33:30 +03:00
|
|
|
|
|
2009-02-16 04:04:03 +03:00
|
|
|
|
} else {
|
2009-02-20 06:33:30 +03:00
|
|
|
|
// Corners are always stretched to fit the corner.
|
2009-02-16 04:04:03 +03:00
|
|
|
|
unitSize.width = borderWidth[i];
|
|
|
|
|
unitSize.height = borderHeight[j];
|
2011-12-23 03:34:45 +04:00
|
|
|
|
fillStyleH = NS_STYLE_BORDER_IMAGE_REPEAT_STRETCH;
|
|
|
|
|
fillStyleV = NS_STYLE_BORDER_IMAGE_REPEAT_STRETCH;
|
2009-02-16 04:04:03 +03:00
|
|
|
|
}
|
2009-02-07 13:37:23 +03:00
|
|
|
|
|
2014-01-31 07:36:41 +04:00
|
|
|
|
nsRect destArea(borderX[i], borderY[j], borderWidth[i], borderHeight[j]);
|
|
|
|
|
nsRect subArea(sliceX[i], sliceY[j], sliceWidth[i], sliceHeight[j]);
|
|
|
|
|
nsIntRect intSubArea = subArea.ToOutsidePixels(nsPresContext::AppUnitsPerCSSPixel());
|
|
|
|
|
|
2014-01-31 07:36:41 +04:00
|
|
|
|
renderer.DrawBorderImageComponent(aPresContext,
|
|
|
|
|
aRenderingContext, aDirtyRect,
|
2014-01-31 07:36:41 +04:00
|
|
|
|
destArea, CSSIntRect(intSubArea.x,
|
|
|
|
|
intSubArea.y,
|
|
|
|
|
intSubArea.width,
|
|
|
|
|
intSubArea.height),
|
2014-01-31 07:36:41 +04:00
|
|
|
|
fillStyleH, fillStyleV,
|
2014-01-31 07:36:41 +04:00
|
|
|
|
unitSize, j * (RIGHT + 1) + i);
|
2009-02-16 04:04:03 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2008-07-17 10:30:25 +04:00
|
|
|
|
}
|
|
|
|
|
|
2002-02-19 18:48:28 +03: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 20:15:01 +04:00
|
|
|
|
RoundIntToPixel(nscoord aValue,
|
2002-02-19 18:48:28 +03:00
|
|
|
|
nscoord aTwipsPerPixel,
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool aRoundDown = false)
|
2002-02-19 18:48:28 +03:00
|
|
|
|
{
|
2010-04-27 20:15:01 +04:00
|
|
|
|
if (aTwipsPerPixel <= 0)
|
|
|
|
|
// We must be rendering to a device that has a resolution greater than Twips!
|
2002-04-07 02:28:39 +04:00
|
|
|
|
// In that case, aValue is as accurate as it's going to get.
|
2010-04-27 20:15:01 +04:00
|
|
|
|
return aValue;
|
2002-04-07 02:28:39 +04:00
|
|
|
|
|
2002-02-19 18:48:28 +03: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 20:15:01 +04:00
|
|
|
|
RoundFloatToPixel(float aValue,
|
2002-02-19 18:48:28 +03:00
|
|
|
|
nscoord aTwipsPerPixel,
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool aRoundDown = false)
|
2002-02-19 18:48:28 +03:00
|
|
|
|
{
|
|
|
|
|
return RoundIntToPixel(NSToCoordRound(aValue), aTwipsPerPixel, aRoundDown);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
SetPoly(const nsRect& aRect,
|
|
|
|
|
nsPoint* poly)
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
poly[4].x = aRect.x;
|
|
|
|
|
poly[4].y = aRect.y;
|
|
|
|
|
}
|
2010-04-27 20:15:01 +04:00
|
|
|
|
|
|
|
|
|
static void
|
2011-04-08 05:04:40 +04:00
|
|
|
|
DrawSolidBorderSegment(nsRenderingContext& aContext,
|
2002-02-19 18:48:28 +03:00
|
|
|
|
nsRect aRect,
|
|
|
|
|
nscoord aTwipsPerPixel,
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint8_t aStartBevelSide = 0,
|
2002-02-19 18:48:28 +03:00
|
|
|
|
nscoord aStartBevelOffset = 0,
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint8_t aEndBevelSide = 0,
|
2002-02-19 18:48:28 +03:00
|
|
|
|
nscoord aEndBevelOffset = 0)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if ((aRect.width == aTwipsPerPixel) || (aRect.height == aTwipsPerPixel) ||
|
|
|
|
|
((0 == aStartBevelOffset) && (0 == aEndBevelOffset))) {
|
|
|
|
|
// simple line or rectangle
|
|
|
|
|
if ((NS_SIDE_TOP == aStartBevelSide) || (NS_SIDE_BOTTOM == aStartBevelSide)) {
|
2010-04-27 20:15:01 +04:00
|
|
|
|
if (1 == aRect.height)
|
2011-04-08 05:04:39 +04:00
|
|
|
|
aContext.DrawLine(aRect.TopLeft(), aRect.BottomLeft());
|
2010-04-27 20:15:01 +04:00
|
|
|
|
else
|
2002-02-19 18:48:28 +03:00
|
|
|
|
aContext.FillRect(aRect);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2010-04-27 20:15:01 +04:00
|
|
|
|
if (1 == aRect.width)
|
2011-04-08 05:04:39 +04:00
|
|
|
|
aContext.DrawLine(aRect.TopLeft(), aRect.TopRight());
|
2010-04-27 20:15:01 +04:00
|
|
|
|
else
|
2002-02-19 18:48:28 +03:00
|
|
|
|
aContext.FillRect(aRect);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// polygon with beveling
|
|
|
|
|
nsPoint poly[5];
|
|
|
|
|
SetPoly(aRect, poly);
|
|
|
|
|
switch(aStartBevelSide) {
|
|
|
|
|
case NS_SIDE_TOP:
|
|
|
|
|
poly[0].x += aStartBevelOffset;
|
|
|
|
|
poly[4].x = poly[0].x;
|
|
|
|
|
break;
|
|
|
|
|
case NS_SIDE_BOTTOM:
|
|
|
|
|
poly[3].x += aStartBevelOffset;
|
|
|
|
|
break;
|
|
|
|
|
case NS_SIDE_RIGHT:
|
|
|
|
|
poly[1].y += aStartBevelOffset;
|
|
|
|
|
break;
|
|
|
|
|
case NS_SIDE_LEFT:
|
|
|
|
|
poly[0].y += aStartBevelOffset;
|
|
|
|
|
poly[4].y = poly[0].y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch(aEndBevelSide) {
|
|
|
|
|
case NS_SIDE_TOP:
|
|
|
|
|
poly[1].x -= aEndBevelOffset;
|
|
|
|
|
break;
|
|
|
|
|
case NS_SIDE_BOTTOM:
|
|
|
|
|
poly[2].x -= aEndBevelOffset;
|
|
|
|
|
break;
|
|
|
|
|
case NS_SIDE_RIGHT:
|
|
|
|
|
poly[2].y -= aEndBevelOffset;
|
|
|
|
|
break;
|
|
|
|
|
case NS_SIDE_LEFT:
|
|
|
|
|
poly[3].y -= aEndBevelOffset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
aContext.FillPolygon(poly, 5);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
GetDashInfo(nscoord aBorderLength,
|
|
|
|
|
nscoord aDashLength,
|
|
|
|
|
nscoord aTwipsPerPixel,
|
2012-08-22 19:56:38 +04:00
|
|
|
|
int32_t& aNumDashSpaces,
|
2002-02-19 18:48:28 +03:00
|
|
|
|
nscoord& aStartDashLength,
|
|
|
|
|
nscoord& aEndDashLength)
|
|
|
|
|
{
|
|
|
|
|
aNumDashSpaces = 0;
|
|
|
|
|
if (aStartDashLength + aDashLength + aEndDashLength >= aBorderLength) {
|
|
|
|
|
aStartDashLength = aBorderLength;
|
|
|
|
|
aEndDashLength = 0;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2009-02-08 19:42:01 +03:00
|
|
|
|
aNumDashSpaces = (aBorderLength - aDashLength)/ (2 * aDashLength); // round down
|
2002-02-19 18:48:28 +03: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 20:15:01 +04:00
|
|
|
|
void
|
2011-04-08 05:04:40 +04:00
|
|
|
|
nsCSSRendering::DrawTableBorderSegment(nsRenderingContext& aContext,
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint8_t aBorderStyle,
|
2002-02-19 18:48:28 +03:00
|
|
|
|
nscolor aBorderColor,
|
|
|
|
|
const nsStyleBackground* aBGColor,
|
|
|
|
|
const nsRect& aBorder,
|
2012-08-22 19:56:38 +04:00
|
|
|
|
int32_t aAppUnitsPerCSSPixel,
|
|
|
|
|
uint8_t aStartBevelSide,
|
2002-02-19 18:48:28 +03:00
|
|
|
|
nscoord aStartBevelOffset,
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint8_t aEndBevelSide,
|
2002-02-19 18:48:28 +03:00
|
|
|
|
nscoord aEndBevelOffset)
|
|
|
|
|
{
|
2010-04-27 20:15:01 +04:00
|
|
|
|
aContext.SetColor (aBorderColor);
|
2002-02-19 18:48:28 +03:00
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool horizontal = ((NS_SIDE_TOP == aStartBevelSide) || (NS_SIDE_BOTTOM == aStartBevelSide));
|
2007-02-23 20:52:09 +03:00
|
|
|
|
nscoord twipsPerPixel = NSIntPixelsToAppUnits(1, aAppUnitsPerCSSPixel);
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint8_t ridgeGroove = NS_STYLE_BORDER_STYLE_RIDGE;
|
2002-02-19 18:48:28 +03: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;
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-19 02:01:15 +03:00
|
|
|
|
gfxContext *ctx = aContext.ThebesContext();
|
2007-02-23 20:52:09 +03:00
|
|
|
|
gfxContext::AntialiasMode oldMode = ctx->CurrentAntialiasMode();
|
|
|
|
|
ctx->SetAntialiasMode(gfxContext::MODE_ALIASED);
|
|
|
|
|
|
2002-02-19 18:48:28 +03:00
|
|
|
|
switch (aBorderStyle) {
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_NONE:
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_HIDDEN:
|
2011-10-17 18:59:28 +04:00
|
|
|
|
//NS_ASSERTION(false, "style of none or hidden");
|
2002-02-19 18:48:28 +03:00
|
|
|
|
break;
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_DOTTED:
|
2010-04-27 20:15:01 +04:00
|
|
|
|
case NS_STYLE_BORDER_STYLE_DASHED:
|
2002-02-19 18:48:28 +03: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 20:15:01 +04:00
|
|
|
|
nscoord minDashLength = (NS_STYLE_BORDER_STYLE_DASHED == aBorderStyle)
|
2002-02-19 18:48:28 +03:00
|
|
|
|
? RoundFloatToPixel(((float)dashLength) / 2.0f, twipsPerPixel) : dashLength;
|
2013-01-15 16:22:03 +04:00
|
|
|
|
minDashLength = std::max(minDashLength, twipsPerPixel);
|
2002-02-19 18:48:28 +03:00
|
|
|
|
nscoord numDashSpaces = 0;
|
|
|
|
|
nscoord startDashLength = minDashLength;
|
|
|
|
|
nscoord endDashLength = minDashLength;
|
|
|
|
|
if (horizontal) {
|
|
|
|
|
GetDashInfo(aBorder.width, dashLength, twipsPerPixel, numDashSpaces, startDashLength, endDashLength);
|
|
|
|
|
nsRect rect(aBorder.x, aBorder.y, startDashLength, aBorder.height);
|
2007-03-30 06:53:45 +04:00
|
|
|
|
DrawSolidBorderSegment(aContext, rect, twipsPerPixel);
|
2012-08-22 19:56:38 +04:00
|
|
|
|
for (int32_t spaceX = 0; spaceX < numDashSpaces; spaceX++) {
|
2002-02-19 18:48:28 +03:00
|
|
|
|
rect.x += rect.width + dashLength;
|
|
|
|
|
rect.width = (spaceX == (numDashSpaces - 1)) ? endDashLength : dashLength;
|
2007-03-30 06:53:45 +04:00
|
|
|
|
DrawSolidBorderSegment(aContext, rect, twipsPerPixel);
|
2002-02-19 18:48:28 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
GetDashInfo(aBorder.height, dashLength, twipsPerPixel, numDashSpaces, startDashLength, endDashLength);
|
|
|
|
|
nsRect rect(aBorder.x, aBorder.y, aBorder.width, startDashLength);
|
2007-03-30 06:53:45 +04:00
|
|
|
|
DrawSolidBorderSegment(aContext, rect, twipsPerPixel);
|
2012-08-22 19:56:38 +04:00
|
|
|
|
for (int32_t spaceY = 0; spaceY < numDashSpaces; spaceY++) {
|
2002-02-19 18:48:28 +03:00
|
|
|
|
rect.y += rect.height + dashLength;
|
|
|
|
|
rect.height = (spaceY == (numDashSpaces - 1)) ? endDashLength : dashLength;
|
2007-03-30 06:53:45 +04:00
|
|
|
|
DrawSolidBorderSegment(aContext, rect, twipsPerPixel);
|
2002-02-19 18:48:28 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-04-27 20:15:01 +04:00
|
|
|
|
break;
|
2002-02-19 18:48:28 +03:00
|
|
|
|
case NS_STYLE_BORDER_STYLE_GROOVE:
|
|
|
|
|
ridgeGroove = NS_STYLE_BORDER_STYLE_GROOVE; // and fall through to ridge
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_RIDGE:
|
|
|
|
|
if ((horizontal && (twipsPerPixel >= aBorder.height)) ||
|
|
|
|
|
(!horizontal && (twipsPerPixel >= aBorder.width))) {
|
|
|
|
|
// a one pixel border
|
|
|
|
|
DrawSolidBorderSegment(aContext, aBorder, twipsPerPixel, aStartBevelSide, aStartBevelOffset,
|
|
|
|
|
aEndBevelSide, aEndBevelOffset);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2010-04-27 20:15:01 +04:00
|
|
|
|
nscoord startBevel = (aStartBevelOffset > 0)
|
2011-10-17 18:59:28 +04:00
|
|
|
|
? RoundFloatToPixel(0.5f * (float)aStartBevelOffset, twipsPerPixel, true) : 0;
|
2010-04-27 20:15:01 +04:00
|
|
|
|
nscoord endBevel = (aEndBevelOffset > 0)
|
2011-10-17 18:59:28 +04:00
|
|
|
|
? RoundFloatToPixel(0.5f * (float)aEndBevelOffset, twipsPerPixel, true) : 0;
|
2010-04-27 20:15:02 +04:00
|
|
|
|
mozilla::css::Side ridgeGrooveSide = (horizontal) ? NS_SIDE_TOP : NS_SIDE_LEFT;
|
2010-04-03 05:58:26 +04:00
|
|
|
|
// FIXME: In theory, this should use the visited-dependent
|
|
|
|
|
// background color, but I don't care.
|
2010-04-27 20:15:01 +04:00
|
|
|
|
aContext.SetColor (
|
2007-02-01 05:45:55 +03:00
|
|
|
|
MakeBevelColor(ridgeGrooveSide, ridgeGroove, aBGColor->mBackgroundColor, aBorderColor));
|
2002-02-19 18:48:28 +03: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;
|
|
|
|
|
}
|
2010-04-27 20:15:01 +04:00
|
|
|
|
DrawSolidBorderSegment(aContext, rect, twipsPerPixel, aStartBevelSide,
|
2002-02-19 18:48:28 +03:00
|
|
|
|
startBevel, aEndBevelSide, endBevel);
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
2010-04-27 20:15:01 +04:00
|
|
|
|
DrawSolidBorderSegment(aContext, rect, twipsPerPixel, aStartBevelSide,
|
2002-02-19 18:48:28 +03:00
|
|
|
|
startBevel, aEndBevelSide, endBevel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rect = aBorder;
|
|
|
|
|
ridgeGrooveSide = (NS_SIDE_TOP == ridgeGrooveSide) ? NS_SIDE_BOTTOM : NS_SIDE_RIGHT;
|
2010-04-03 05:58:26 +04:00
|
|
|
|
// FIXME: In theory, this should use the visited-dependent
|
|
|
|
|
// background color, but I don't care.
|
2010-04-27 20:15:01 +04:00
|
|
|
|
aContext.SetColor (
|
2007-02-01 05:45:55 +03:00
|
|
|
|
MakeBevelColor(ridgeGrooveSide, ridgeGroove, aBGColor->mBackgroundColor, aBorderColor));
|
2002-02-19 18:48:28 +03: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;
|
|
|
|
|
}
|
2010-04-27 20:15:01 +04:00
|
|
|
|
DrawSolidBorderSegment(aContext, rect, twipsPerPixel, aStartBevelSide,
|
2002-02-19 18:48:28 +03:00
|
|
|
|
startBevel, aEndBevelSide, endBevel);
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
2010-04-27 20:15:01 +04:00
|
|
|
|
DrawSolidBorderSegment(aContext, rect, twipsPerPixel, aStartBevelSide,
|
2002-02-19 18:48:28 +03:00
|
|
|
|
startBevel, aEndBevelSide, endBevel);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_DOUBLE:
|
2011-05-04 21:57:01 +04: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 20:15:01 +04:00
|
|
|
|
nscoord startBevel = (aStartBevelOffset > 0)
|
2002-02-19 18:48:28 +03:00
|
|
|
|
? RoundFloatToPixel(0.333333f * (float)aStartBevelOffset, twipsPerPixel) : 0;
|
2010-04-27 20:15:01 +04:00
|
|
|
|
nscoord endBevel = (aEndBevelOffset > 0)
|
2002-02-19 18:48:28 +03: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;
|
|
|
|
|
}
|
2010-04-27 20:15:01 +04:00
|
|
|
|
DrawSolidBorderSegment(aContext, topRect, twipsPerPixel, aStartBevelSide,
|
2002-02-19 18:48:28 +03:00
|
|
|
|
startBevel, aEndBevelSide, endBevel);
|
|
|
|
|
|
|
|
|
|
// draw the botom line or rect
|
2010-04-27 20:15:01 +04:00
|
|
|
|
nscoord heightOffset = aBorder.height - thirdHeight;
|
2002-02-19 18:48:28 +03: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;
|
|
|
|
|
}
|
2010-04-27 20:15:01 +04:00
|
|
|
|
DrawSolidBorderSegment(aContext, bottomRect, twipsPerPixel, aStartBevelSide,
|
2002-02-19 18:48:28 +03:00
|
|
|
|
startBevel, aEndBevelSide, endBevel);
|
|
|
|
|
}
|
|
|
|
|
else { // left, right
|
|
|
|
|
nscoord thirdWidth = RoundFloatToPixel(0.333333f * (float)aBorder.width, twipsPerPixel);
|
|
|
|
|
|
2010-04-27 20:15:01 +04:00
|
|
|
|
nsRect leftRect(aBorder.x, aBorder.y, thirdWidth, aBorder.height);
|
2002-02-19 18:48:28 +03:00
|
|
|
|
if (NS_SIDE_LEFT == aStartBevelSide) {
|
|
|
|
|
leftRect.y += aStartBevelOffset - startBevel;
|
|
|
|
|
leftRect.height -= aStartBevelOffset - startBevel;
|
|
|
|
|
}
|
|
|
|
|
if (NS_SIDE_LEFT == aEndBevelSide) {
|
|
|
|
|
leftRect.height -= aEndBevelOffset - endBevel;
|
|
|
|
|
}
|
|
|
|
|
DrawSolidBorderSegment(aContext, leftRect, twipsPerPixel, aStartBevelSide,
|
|
|
|
|
startBevel, aEndBevelSide, endBevel);
|
|
|
|
|
|
2010-04-27 20:15:01 +04:00
|
|
|
|
nscoord widthOffset = aBorder.width - thirdWidth;
|
2002-02-19 18:48:28 +03: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;
|
|
|
|
|
}
|
|
|
|
|
DrawSolidBorderSegment(aContext, rightRect, twipsPerPixel, aStartBevelSide,
|
|
|
|
|
startBevel, aEndBevelSide, endBevel);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// else fall through to solid
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_SOLID:
|
2010-04-27 20:15:01 +04:00
|
|
|
|
DrawSolidBorderSegment(aContext, aBorder, twipsPerPixel, aStartBevelSide,
|
2002-02-19 18:48:28 +03:00
|
|
|
|
aStartBevelOffset, aEndBevelSide, aEndBevelOffset);
|
|
|
|
|
break;
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_OUTSET:
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_INSET:
|
2011-10-17 18:59:28 +04:00
|
|
|
|
NS_ASSERTION(false, "inset, outset should have been converted to groove, ridge");
|
2002-02-19 18:48:28 +03:00
|
|
|
|
break;
|
2005-03-27 15:36:08 +04:00
|
|
|
|
case NS_STYLE_BORDER_STYLE_AUTO:
|
2011-10-17 18:59:28 +04:00
|
|
|
|
NS_ASSERTION(false, "Unexpected 'auto' table border");
|
2005-03-27 15:36:08 +04:00
|
|
|
|
break;
|
2002-02-19 18:48:28 +03:00
|
|
|
|
}
|
2007-02-23 20:52:09 +03:00
|
|
|
|
|
|
|
|
|
ctx->SetAntialiasMode(oldMode);
|
2002-02-19 18:48:28 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// End table border-collapsing section
|
|
|
|
|
|
2012-07-04 09:59:50 +04:00
|
|
|
|
gfxRect
|
|
|
|
|
nsCSSRendering::ExpandPaintingRectForDecorationLine(nsIFrame* aFrame,
|
2012-08-22 19:56:38 +04:00
|
|
|
|
const uint8_t aStyle,
|
2012-07-04 09:59:50 +04:00
|
|
|
|
const gfxRect& aClippedRect,
|
|
|
|
|
const gfxFloat aXInFrame,
|
|
|
|
|
const gfxFloat aCycleLength)
|
|
|
|
|
{
|
|
|
|
|
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 18:20:58 +04:00
|
|
|
|
nsBlockFrame* block = nullptr;
|
2012-07-04 09:59:50 +04: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.
|
2013-08-09 04:20:17 +04:00
|
|
|
|
nscoord frameXInBlockAppUnits = 0;
|
2012-07-04 09:59:50 +04:00
|
|
|
|
for (nsIFrame* f = aFrame; f; f = f->GetParent()) {
|
|
|
|
|
block = do_QueryFrame(f);
|
|
|
|
|
if (block) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-08-09 04:20:17 +04:00
|
|
|
|
frameXInBlockAppUnits += f->GetNormalPosition().x;
|
2012-07-04 09:59:50 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE(block, aClippedRect);
|
|
|
|
|
|
|
|
|
|
nsPresContext *pc = aFrame->PresContext();
|
|
|
|
|
gfxFloat frameXInBlock = pc->AppUnitsToGfxUnits(frameXInBlockAppUnits);
|
2012-08-22 19:56:38 +04:00
|
|
|
|
int32_t rectXInBlock = int32_t(NS_round(frameXInBlock + aXInFrame));
|
|
|
|
|
int32_t extraLeft =
|
|
|
|
|
rectXInBlock - (rectXInBlock / int32_t(aCycleLength) * aCycleLength);
|
2012-07-04 09:59:50 +04:00
|
|
|
|
gfxRect rect(aClippedRect);
|
|
|
|
|
rect.x -= extraLeft;
|
|
|
|
|
rect.width += extraLeft;
|
|
|
|
|
return rect;
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-06 12:15:00 +04:00
|
|
|
|
void
|
2012-07-04 09:59:50 +04:00
|
|
|
|
nsCSSRendering::PaintDecorationLine(nsIFrame* aFrame,
|
|
|
|
|
gfxContext* aGfxContext,
|
2011-09-16 23:23:29 +04:00
|
|
|
|
const gfxRect& aDirtyRect,
|
2007-08-06 12:15:00 +04:00
|
|
|
|
const nscolor aColor,
|
|
|
|
|
const gfxPoint& aPt,
|
2012-07-04 09:59:50 +04:00
|
|
|
|
const gfxFloat aXInFrame,
|
2007-08-06 12:15:00 +04:00
|
|
|
|
const gfxSize& aLineSize,
|
|
|
|
|
const gfxFloat aAscent,
|
|
|
|
|
const gfxFloat aOffset,
|
2012-08-22 19:56:38 +04:00
|
|
|
|
const uint8_t aDecoration,
|
|
|
|
|
const uint8_t aStyle,
|
2009-04-06 09:53:00 +04:00
|
|
|
|
const gfxFloat aDescentLimit)
|
2007-08-06 12:15:00 +04:00
|
|
|
|
{
|
2011-03-31 16:26:49 +04:00
|
|
|
|
NS_ASSERTION(aStyle != NS_STYLE_TEXT_DECORATION_STYLE_NONE, "aStyle is none");
|
2009-04-03 11:26:28 +04:00
|
|
|
|
|
2008-02-16 18:31:27 +03:00
|
|
|
|
gfxRect rect =
|
|
|
|
|
GetTextDecorationRectInternal(aPt, aLineSize, aAscent, aOffset,
|
2009-04-06 09:53:00 +04:00
|
|
|
|
aDecoration, aStyle, aDescentLimit);
|
2011-09-16 23:23:29 +04:00
|
|
|
|
if (rect.IsEmpty() || !rect.Intersects(aDirtyRect)) {
|
2007-08-06 12:15:00 +04:00
|
|
|
|
return;
|
2011-09-16 23:23:29 +04:00
|
|
|
|
}
|
2007-08-06 12:15:00 +04:00
|
|
|
|
|
2011-04-23 09:16:41 +04:00
|
|
|
|
if (aDecoration != NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE &&
|
|
|
|
|
aDecoration != NS_STYLE_TEXT_DECORATION_LINE_OVERLINE &&
|
|
|
|
|
aDecoration != NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH) {
|
2008-01-11 01:10:38 +03:00
|
|
|
|
NS_ERROR("Invalid decoration value!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-15 16:22:03 +04:00
|
|
|
|
gfxFloat lineHeight = std::max(NS_round(aLineSize.height), 1.0);
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool contextIsSaved = false;
|
2008-01-11 01:10:38 +03:00
|
|
|
|
|
|
|
|
|
gfxFloat oldLineWidth;
|
|
|
|
|
nsRefPtr<gfxPattern> oldPattern;
|
|
|
|
|
|
2007-08-06 12:15:00 +04:00
|
|
|
|
switch (aStyle) {
|
2011-03-31 16:26:49 +04:00
|
|
|
|
case NS_STYLE_TEXT_DECORATION_STYLE_SOLID:
|
|
|
|
|
case NS_STYLE_TEXT_DECORATION_STYLE_DOUBLE:
|
2008-01-11 01:10:38 +03:00
|
|
|
|
oldLineWidth = aGfxContext->CurrentLineWidth();
|
|
|
|
|
oldPattern = aGfxContext->GetPattern();
|
2007-08-06 12:15:00 +04:00
|
|
|
|
break;
|
2011-03-31 16:26:49 +04:00
|
|
|
|
case NS_STYLE_TEXT_DECORATION_STYLE_DASHED: {
|
2007-08-06 12:15:00 +04:00
|
|
|
|
aGfxContext->Save();
|
2011-10-17 18:59:28 +04:00
|
|
|
|
contextIsSaved = true;
|
2009-04-03 11:26:28 +04:00
|
|
|
|
aGfxContext->Clip(rect);
|
2008-02-16 18:31:27 +03:00
|
|
|
|
gfxFloat dashWidth = lineHeight * DOT_LENGTH * DASH_LENGTH;
|
2007-08-06 12:15:00 +04:00
|
|
|
|
gfxFloat dash[2] = { dashWidth, dashWidth };
|
|
|
|
|
aGfxContext->SetLineCap(gfxContext::LINE_CAP_BUTT);
|
|
|
|
|
aGfxContext->SetDash(dash, 2, 0.0);
|
2012-07-04 09:59:50 +04:00
|
|
|
|
rect = ExpandPaintingRectForDecorationLine(aFrame, aStyle, rect,
|
|
|
|
|
aXInFrame, dashWidth * 2);
|
2009-04-03 11:26:28 +04:00
|
|
|
|
// We should continue to draw the last dash even if it is not in the rect.
|
2011-04-19 07:07:21 +04:00
|
|
|
|
rect.width += dashWidth;
|
2007-08-06 12:15:00 +04:00
|
|
|
|
break;
|
|
|
|
|
}
|
2011-03-31 16:26:49 +04:00
|
|
|
|
case NS_STYLE_TEXT_DECORATION_STYLE_DOTTED: {
|
2007-08-06 12:15:00 +04:00
|
|
|
|
aGfxContext->Save();
|
2011-10-17 18:59:28 +04:00
|
|
|
|
contextIsSaved = true;
|
2009-04-03 11:26:28 +04:00
|
|
|
|
aGfxContext->Clip(rect);
|
2008-02-16 18:31:27 +03:00
|
|
|
|
gfxFloat dashWidth = lineHeight * DOT_LENGTH;
|
2007-08-06 12:15:00 +04:00
|
|
|
|
gfxFloat dash[2];
|
2008-02-16 18:31:27 +03:00
|
|
|
|
if (lineHeight > 2.0) {
|
2007-08-06 12:15:00 +04:00
|
|
|
|
dash[0] = 0.0;
|
|
|
|
|
dash[1] = dashWidth * 2.0;
|
|
|
|
|
aGfxContext->SetLineCap(gfxContext::LINE_CAP_ROUND);
|
|
|
|
|
} else {
|
|
|
|
|
dash[0] = dashWidth;
|
|
|
|
|
dash[1] = dashWidth;
|
|
|
|
|
}
|
|
|
|
|
aGfxContext->SetDash(dash, 2, 0.0);
|
2012-07-04 09:59:50 +04:00
|
|
|
|
rect = ExpandPaintingRectForDecorationLine(aFrame, aStyle, rect,
|
|
|
|
|
aXInFrame, dashWidth * 2);
|
2009-04-03 11:26:28 +04:00
|
|
|
|
// We should continue to draw the last dot even if it is not in the rect.
|
2011-04-19 07:07:21 +04:00
|
|
|
|
rect.width += dashWidth;
|
2007-08-06 12:15:00 +04:00
|
|
|
|
break;
|
|
|
|
|
}
|
2011-03-31 16:26:49 +04:00
|
|
|
|
case NS_STYLE_TEXT_DECORATION_STYLE_WAVY:
|
2009-04-03 11:26:28 +04:00
|
|
|
|
aGfxContext->Save();
|
2011-10-17 18:59:28 +04:00
|
|
|
|
contextIsSaved = true;
|
2009-04-03 11:26:28 +04:00
|
|
|
|
aGfxContext->Clip(rect);
|
|
|
|
|
if (lineHeight > 2.0) {
|
|
|
|
|
aGfxContext->SetAntialiasMode(gfxContext::MODE_COVERAGE);
|
|
|
|
|
} 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.
|
|
|
|
|
aGfxContext->SetAntialiasMode(gfxContext::MODE_ALIASED);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2007-08-06 12:15:00 +04:00
|
|
|
|
default:
|
|
|
|
|
NS_ERROR("Invalid style value!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The y position should be set to the middle of the line.
|
2011-04-19 07:07:21 +04:00
|
|
|
|
rect.y += lineHeight / 2;
|
2007-08-06 12:15:00 +04:00
|
|
|
|
|
|
|
|
|
aGfxContext->SetColor(gfxRGBA(aColor));
|
2008-02-16 18:31:27 +03:00
|
|
|
|
aGfxContext->SetLineWidth(lineHeight);
|
2007-08-06 12:15:00 +04:00
|
|
|
|
switch (aStyle) {
|
2011-03-31 16:26:49 +04:00
|
|
|
|
case NS_STYLE_TEXT_DECORATION_STYLE_SOLID:
|
2007-08-06 12:15:00 +04:00
|
|
|
|
aGfxContext->NewPath();
|
2008-02-16 18:31:27 +03:00
|
|
|
|
aGfxContext->MoveTo(rect.TopLeft());
|
|
|
|
|
aGfxContext->LineTo(rect.TopRight());
|
2007-08-06 12:15:00 +04:00
|
|
|
|
aGfxContext->Stroke();
|
|
|
|
|
break;
|
2011-03-31 16:26:49 +04:00
|
|
|
|
case NS_STYLE_TEXT_DECORATION_STYLE_DOUBLE:
|
2009-04-03 11:26:28 +04:00
|
|
|
|
/**
|
|
|
|
|
* We are drawing double line as:
|
|
|
|
|
*
|
|
|
|
|
* +-------------------------------------------+
|
|
|
|
|
* |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX| ^
|
|
|
|
|
* |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX| | lineHeight
|
|
|
|
|
* |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX| v
|
|
|
|
|
* | |
|
|
|
|
|
* | |
|
|
|
|
|
* |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX| ^
|
|
|
|
|
* |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX| | lineHeight
|
|
|
|
|
* |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX| v
|
|
|
|
|
* +-------------------------------------------+
|
|
|
|
|
*/
|
2007-08-06 12:15:00 +04:00
|
|
|
|
aGfxContext->NewPath();
|
2008-02-16 18:31:27 +03:00
|
|
|
|
aGfxContext->MoveTo(rect.TopLeft());
|
|
|
|
|
aGfxContext->LineTo(rect.TopRight());
|
2011-04-19 07:07:21 +04:00
|
|
|
|
rect.height -= lineHeight;
|
2008-02-16 18:31:27 +03:00
|
|
|
|
aGfxContext->MoveTo(rect.BottomLeft());
|
|
|
|
|
aGfxContext->LineTo(rect.BottomRight());
|
2007-08-06 12:15:00 +04:00
|
|
|
|
aGfxContext->Stroke();
|
|
|
|
|
break;
|
2011-03-31 16:26:49 +04:00
|
|
|
|
case NS_STYLE_TEXT_DECORATION_STYLE_DOTTED:
|
|
|
|
|
case NS_STYLE_TEXT_DECORATION_STYLE_DASHED:
|
2007-08-06 12:15:00 +04:00
|
|
|
|
aGfxContext->NewPath();
|
2008-04-08 03:57:13 +04:00
|
|
|
|
aGfxContext->MoveTo(rect.TopLeft());
|
|
|
|
|
aGfxContext->LineTo(rect.TopRight());
|
2007-08-06 12:15:00 +04:00
|
|
|
|
aGfxContext->Stroke();
|
|
|
|
|
break;
|
2011-03-31 16:26:49 +04:00
|
|
|
|
case NS_STYLE_TEXT_DECORATION_STYLE_WAVY: {
|
2009-04-03 11:26:28 +04: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.
|
|
|
|
|
*/
|
|
|
|
|
|
2011-09-16 23:23:29 +04:00
|
|
|
|
gfxFloat adv = rect.Height() - lineHeight;
|
2013-01-15 16:22:03 +04:00
|
|
|
|
gfxFloat flatLengthAtVertex = std::max((lineHeight - 1.0) * 2.0, 1.0);
|
2011-09-16 23:23:29 +04:00
|
|
|
|
|
2012-07-04 09:59:50 +04:00
|
|
|
|
// Align the start of wavy lines to the nearest ancestor block.
|
|
|
|
|
gfxFloat cycleLength = 2 * (adv + flatLengthAtVertex);
|
|
|
|
|
rect = ExpandPaintingRectForDecorationLine(aFrame, aStyle, rect,
|
|
|
|
|
aXInFrame, cycleLength);
|
2011-09-16 23:23:29 +04: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
|
2012-08-22 19:56:38 +04:00
|
|
|
|
int32_t skipCycles = floor((aDirtyRect.x - rect.x) / cycleLength);
|
2011-09-16 23:23:29 +04:00
|
|
|
|
if (skipCycles > 0) {
|
|
|
|
|
rect.x += skipCycles * cycleLength;
|
|
|
|
|
rect.width -= skipCycles * cycleLength;
|
|
|
|
|
}
|
2009-04-03 11:26:28 +04:00
|
|
|
|
|
2011-09-16 23:23:29 +04:00
|
|
|
|
rect.x += lineHeight / 2.0;
|
2011-04-19 07:07:21 +04:00
|
|
|
|
gfxPoint pt(rect.TopLeft());
|
2009-04-03 11:26:28 +04:00
|
|
|
|
gfxFloat rightMost = pt.x + rect.Width() + lineHeight;
|
2011-09-16 23:23:29 +04:00
|
|
|
|
|
|
|
|
|
skipCycles = floor((rightMost - aDirtyRect.XMost()) / cycleLength);
|
|
|
|
|
if (skipCycles > 0) {
|
|
|
|
|
rightMost -= skipCycles * cycleLength;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
aGfxContext->NewPath();
|
2009-04-03 11:26:28 +04:00
|
|
|
|
|
|
|
|
|
pt.x -= lineHeight;
|
|
|
|
|
aGfxContext->MoveTo(pt); // 1
|
|
|
|
|
|
2011-04-19 07:07:21 +04:00
|
|
|
|
pt.x = rect.X();
|
2009-04-03 11:26:28 +04:00
|
|
|
|
aGfxContext->LineTo(pt); // 2
|
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool goDown = true;
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t iter = 0;
|
2009-04-03 11:26:28 +04:00
|
|
|
|
while (pt.x < rightMost) {
|
2011-09-16 23:23:29 +04:00
|
|
|
|
if (++iter > 1000) {
|
|
|
|
|
// stroke the current path and start again, to avoid pathological
|
|
|
|
|
// behavior in cairo with huge numbers of path segments
|
|
|
|
|
aGfxContext->Stroke();
|
|
|
|
|
aGfxContext->NewPath();
|
|
|
|
|
aGfxContext->MoveTo(pt);
|
|
|
|
|
iter = 0;
|
|
|
|
|
}
|
2009-04-03 11:26:28 +04:00
|
|
|
|
pt.x += adv;
|
|
|
|
|
pt.y += goDown ? adv : -adv;
|
|
|
|
|
|
|
|
|
|
aGfxContext->LineTo(pt); // 3 and 5
|
|
|
|
|
|
|
|
|
|
pt.x += flatLengthAtVertex;
|
|
|
|
|
aGfxContext->LineTo(pt); // 4 and 6
|
|
|
|
|
|
|
|
|
|
goDown = !goDown;
|
|
|
|
|
}
|
|
|
|
|
aGfxContext->Stroke();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2007-08-06 12:15:00 +04:00
|
|
|
|
default:
|
|
|
|
|
NS_ERROR("Invalid style value!");
|
|
|
|
|
break;
|
|
|
|
|
}
|
2008-01-11 01:10:38 +03:00
|
|
|
|
|
|
|
|
|
if (contextIsSaved) {
|
|
|
|
|
aGfxContext->Restore();
|
|
|
|
|
} else {
|
|
|
|
|
aGfxContext->SetPattern(oldPattern);
|
|
|
|
|
aGfxContext->SetLineWidth(oldLineWidth);
|
|
|
|
|
}
|
2007-08-06 12:15:00 +04:00
|
|
|
|
}
|
2008-02-16 18:31:27 +03:00
|
|
|
|
|
2012-08-08 15:37:11 +04:00
|
|
|
|
void
|
|
|
|
|
nsCSSRendering::DecorationLineToPath(nsIFrame* aFrame,
|
|
|
|
|
gfxContext* aGfxContext,
|
|
|
|
|
const gfxRect& aDirtyRect,
|
|
|
|
|
const nscolor aColor,
|
|
|
|
|
const gfxPoint& aPt,
|
|
|
|
|
const gfxFloat aXInFrame,
|
|
|
|
|
const gfxSize& aLineSize,
|
|
|
|
|
const gfxFloat aAscent,
|
|
|
|
|
const gfxFloat aOffset,
|
2012-08-22 19:56:38 +04:00
|
|
|
|
const uint8_t aDecoration,
|
|
|
|
|
const uint8_t aStyle,
|
2012-08-08 15:37:11 +04:00
|
|
|
|
const gfxFloat aDescentLimit)
|
|
|
|
|
{
|
|
|
|
|
NS_ASSERTION(aStyle != NS_STYLE_TEXT_DECORATION_STYLE_NONE, "aStyle is none");
|
|
|
|
|
|
|
|
|
|
aGfxContext->NewPath();
|
|
|
|
|
|
|
|
|
|
gfxRect rect =
|
|
|
|
|
GetTextDecorationRectInternal(aPt, aLineSize, aAscent, aOffset,
|
|
|
|
|
aDecoration, aStyle, aDescentLimit);
|
|
|
|
|
if (rect.IsEmpty() || !rect.Intersects(aDirtyRect)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (aDecoration != NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE &&
|
|
|
|
|
aDecoration != NS_STYLE_TEXT_DECORATION_LINE_OVERLINE &&
|
|
|
|
|
aDecoration != NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH) {
|
|
|
|
|
NS_ERROR("Invalid decoration value!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (aStyle != NS_STYLE_TEXT_DECORATION_STYLE_SOLID) {
|
|
|
|
|
// For the moment, we support only solid text decorations.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-15 16:22:03 +04:00
|
|
|
|
gfxFloat lineHeight = std::max(NS_round(aLineSize.height), 1.0);
|
2012-08-08 15:37:11 +04:00
|
|
|
|
|
|
|
|
|
// The y position should be set to the middle of the line.
|
|
|
|
|
rect.y += lineHeight / 2;
|
|
|
|
|
|
|
|
|
|
aGfxContext->Rectangle
|
|
|
|
|
(gfxRect(gfxPoint(rect.TopLeft() - gfxPoint(0.0, lineHeight / 2)),
|
|
|
|
|
gfxSize(rect.Width(), lineHeight)));
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-16 18:31:27 +03:00
|
|
|
|
nsRect
|
|
|
|
|
nsCSSRendering::GetTextDecorationRect(nsPresContext* aPresContext,
|
|
|
|
|
const gfxSize& aLineSize,
|
|
|
|
|
const gfxFloat aAscent,
|
|
|
|
|
const gfxFloat aOffset,
|
2012-08-22 19:56:38 +04:00
|
|
|
|
const uint8_t aDecoration,
|
|
|
|
|
const uint8_t aStyle,
|
2009-04-06 09:53:00 +04:00
|
|
|
|
const gfxFloat aDescentLimit)
|
2008-02-16 18:31:27 +03:00
|
|
|
|
{
|
|
|
|
|
NS_ASSERTION(aPresContext, "aPresContext is null");
|
2011-03-31 16:26:49 +04:00
|
|
|
|
NS_ASSERTION(aStyle != NS_STYLE_TEXT_DECORATION_STYLE_NONE, "aStyle is none");
|
2008-02-16 18:31:27 +03:00
|
|
|
|
|
|
|
|
|
gfxRect rect =
|
|
|
|
|
GetTextDecorationRectInternal(gfxPoint(0, 0), aLineSize, aAscent, aOffset,
|
2009-04-06 09:53:00 +04:00
|
|
|
|
aDecoration, aStyle, aDescentLimit);
|
2008-02-16 18:31:27 +03: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 11:26:28 +04:00
|
|
|
|
gfxRect
|
|
|
|
|
nsCSSRendering::GetTextDecorationRectInternal(const gfxPoint& aPt,
|
|
|
|
|
const gfxSize& aLineSize,
|
|
|
|
|
const gfxFloat aAscent,
|
|
|
|
|
const gfxFloat aOffset,
|
2012-08-22 19:56:38 +04:00
|
|
|
|
const uint8_t aDecoration,
|
|
|
|
|
const uint8_t aStyle,
|
2009-04-06 09:53:00 +04:00
|
|
|
|
const gfxFloat aDescentLimit)
|
2008-02-16 18:31:27 +03:00
|
|
|
|
{
|
2011-03-31 16:26:49 +04:00
|
|
|
|
NS_ASSERTION(aStyle <= NS_STYLE_TEXT_DECORATION_STYLE_WAVY,
|
|
|
|
|
"Invalid aStyle value");
|
2009-04-03 11:26:28 +04:00
|
|
|
|
|
2011-03-31 16:26:49 +04:00
|
|
|
|
if (aStyle == NS_STYLE_TEXT_DECORATION_STYLE_NONE)
|
2009-04-03 11:26:28 +04:00
|
|
|
|
return gfxRect(0, 0, 0, 0);
|
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool canLiftUnderline = aDescentLimit >= 0.0;
|
2009-04-06 09:53:00 +04:00
|
|
|
|
|
2011-05-30 23:08:55 +04:00
|
|
|
|
const gfxFloat left = floor(aPt.x + 0.5),
|
|
|
|
|
right = floor(aPt.x + aLineSize.width + 0.5);
|
2011-08-03 22:30:58 +04:00
|
|
|
|
gfxRect r(left, 0, right - left, 0);
|
2008-02-16 18:31:27 +03:00
|
|
|
|
|
2009-04-03 11:26:28 +04:00
|
|
|
|
gfxFloat lineHeight = NS_round(aLineSize.height);
|
2013-01-15 16:22:03 +04:00
|
|
|
|
lineHeight = std::max(lineHeight, 1.0);
|
2009-04-06 09:53:00 +04:00
|
|
|
|
|
|
|
|
|
gfxFloat ascent = NS_round(aAscent);
|
2011-05-30 23:08:55 +04:00
|
|
|
|
gfxFloat descentLimit = floor(aDescentLimit);
|
2009-04-06 09:53:00 +04:00
|
|
|
|
|
2013-01-15 16:22:03 +04:00
|
|
|
|
gfxFloat suggestedMaxRectHeight = std::max(std::min(ascent, descentLimit), 1.0);
|
2011-04-19 07:07:21 +04:00
|
|
|
|
r.height = lineHeight;
|
2011-03-31 16:26:49 +04:00
|
|
|
|
if (aStyle == NS_STYLE_TEXT_DECORATION_STYLE_DOUBLE) {
|
2009-04-03 11:26:28 +04:00
|
|
|
|
/**
|
|
|
|
|
* We will draw double line as:
|
|
|
|
|
*
|
|
|
|
|
* +-------------------------------------------+
|
|
|
|
|
* |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX| ^
|
|
|
|
|
* |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX| | lineHeight
|
|
|
|
|
* |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX| v
|
|
|
|
|
* | | ^
|
|
|
|
|
* | | | gap
|
|
|
|
|
* | | v
|
|
|
|
|
* |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX| ^
|
|
|
|
|
* |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX| | lineHeight
|
|
|
|
|
* |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX| v
|
|
|
|
|
* +-------------------------------------------+
|
|
|
|
|
*/
|
|
|
|
|
gfxFloat gap = NS_round(lineHeight / 2.0);
|
2013-01-15 16:22:03 +04:00
|
|
|
|
gap = std::max(gap, 1.0);
|
2011-04-19 07:07:21 +04:00
|
|
|
|
r.height = lineHeight * 2.0 + gap;
|
2009-04-06 09:53:00 +04: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.
|
2013-01-15 16:22:03 +04:00
|
|
|
|
r.height = std::max(suggestedMaxRectHeight, lineHeight * 2.0 + 1.0);
|
2009-04-06 09:53:00 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-31 16:26:49 +04:00
|
|
|
|
} else if (aStyle == NS_STYLE_TEXT_DECORATION_STYLE_WAVY) {
|
2009-04-03 11:26:28 +04:00
|
|
|
|
/**
|
|
|
|
|
* We will draw wavy line as:
|
|
|
|
|
*
|
|
|
|
|
* +-------------------------------------------+
|
|
|
|
|
* |XXXXX XXXXXX XXXXXX | ^
|
|
|
|
|
* |XXXXXX XXXXXXXX XXXXXXXX | | lineHeight
|
|
|
|
|
* |XXXXXXX XXXXXXXXXX XXXXXXXXXX| v
|
|
|
|
|
* | XXX XXX XXX XXX XX|
|
|
|
|
|
* | XXXXXXXXXX XXXXXXXXXX X|
|
|
|
|
|
* | XXXXXXXX XXXXXXXX |
|
|
|
|
|
* | XXXXXX XXXXXX |
|
|
|
|
|
* +-------------------------------------------+
|
|
|
|
|
*/
|
2011-04-19 07:07:21 +04:00
|
|
|
|
r.height = lineHeight > 2.0 ? lineHeight * 4.0 : lineHeight * 3.0;
|
2009-04-06 09:53:00 +04: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.
|
2013-01-15 16:22:03 +04:00
|
|
|
|
r.height = std::max(suggestedMaxRectHeight, lineHeight * 2.0);
|
2009-04-06 09:53:00 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2008-02-16 18:31:27 +03:00
|
|
|
|
}
|
|
|
|
|
|
2011-05-30 23:08:55 +04:00
|
|
|
|
gfxFloat baseline = floor(aPt.y + aAscent + 0.5);
|
2009-04-03 11:26:28 +04:00
|
|
|
|
gfxFloat offset = 0.0;
|
2008-02-16 18:31:27 +03:00
|
|
|
|
switch (aDecoration) {
|
2011-04-23 09:16:41 +04:00
|
|
|
|
case NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE:
|
2009-06-30 20:52:16 +04:00
|
|
|
|
offset = aOffset;
|
2009-04-06 09:53:00 +04: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 20:52:16 +04:00
|
|
|
|
gfxFloat offsetTopAligned = 0.0;
|
2013-01-15 16:22:03 +04:00
|
|
|
|
offset = std::min(offsetBottomAligned, offsetTopAligned);
|
2009-04-06 09:53:00 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2008-02-16 18:31:27 +03:00
|
|
|
|
break;
|
2011-04-23 09:16:41 +04:00
|
|
|
|
case NS_STYLE_TEXT_DECORATION_LINE_OVERLINE:
|
2009-04-03 11:26:28 +04:00
|
|
|
|
offset = aOffset - lineHeight + r.Height();
|
2008-02-16 18:31:27 +03:00
|
|
|
|
break;
|
2011-04-23 09:16:41 +04:00
|
|
|
|
case NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH: {
|
2011-05-30 23:08:55 +04:00
|
|
|
|
gfxFloat extra = floor(r.Height() / 2.0 + 0.5);
|
2013-01-15 16:22:03 +04:00
|
|
|
|
extra = std::max(extra, lineHeight);
|
2009-04-03 11:26:28 +04:00
|
|
|
|
offset = aOffset - lineHeight + extra;
|
2008-02-16 18:31:27 +03:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
NS_ERROR("Invalid decoration value!");
|
|
|
|
|
}
|
2011-05-30 23:08:55 +04:00
|
|
|
|
r.y = baseline - floor(offset + 0.5);
|
2008-02-16 18:31:27 +03:00
|
|
|
|
return r;
|
|
|
|
|
}
|
2008-06-13 02:02:32 +04:00
|
|
|
|
|
2009-08-22 00:39:25 +04:00
|
|
|
|
// ------------------
|
|
|
|
|
// ImageRenderer
|
|
|
|
|
// ------------------
|
2012-05-04 00:11:57 +04:00
|
|
|
|
nsImageRenderer::nsImageRenderer(nsIFrame* aForFrame,
|
|
|
|
|
const nsStyleImage* aImage,
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t aFlags)
|
2009-08-22 00:39:25 +04:00
|
|
|
|
: mForFrame(aForFrame)
|
|
|
|
|
, mImage(aImage)
|
2010-08-06 01:30:19 +04:00
|
|
|
|
, mType(aImage->GetType())
|
2012-07-30 18:20:58 +04:00
|
|
|
|
, mImageContainer(nullptr)
|
|
|
|
|
, mGradientData(nullptr)
|
|
|
|
|
, mPaintServerFrame(nullptr)
|
2011-10-17 18:59:28 +04:00
|
|
|
|
, mIsReady(false)
|
2009-08-22 00:39:25 +04:00
|
|
|
|
, mSize(0, 0)
|
2009-09-13 02:44:18 +04:00
|
|
|
|
, mFlags(aFlags)
|
2009-08-22 00:39:25 +04:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-04 00:11:57 +04:00
|
|
|
|
nsImageRenderer::~nsImageRenderer()
|
2009-08-22 00:39:25 +04:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool
|
2012-05-04 00:11:57 +04:00
|
|
|
|
nsImageRenderer::PrepareImage()
|
2009-08-22 00:39:25 +04:00
|
|
|
|
{
|
2012-10-13 00:04:32 +04:00
|
|
|
|
if (mImage->IsEmpty())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (!mImage->IsComplete()) {
|
2009-09-13 02:44:18 +04:00
|
|
|
|
// Make sure the image is actually decoding
|
2012-10-13 00:04:03 +04:00
|
|
|
|
mImage->StartDecoding();
|
2009-09-13 02:44:18 +04:00
|
|
|
|
|
2012-10-13 00:04:32 +04:00
|
|
|
|
// check again to see if we finished
|
|
|
|
|
if (!mImage->IsComplete()) {
|
|
|
|
|
// We can not prepare the image for rendering if it is not fully loaded.
|
|
|
|
|
//
|
|
|
|
|
// Special case: If we requested a sync decode and we have an image, push
|
|
|
|
|
// on through because the Draw() will do a sync decode then
|
|
|
|
|
nsCOMPtr<imgIContainer> img;
|
|
|
|
|
if (!((mFlags & FLAG_SYNC_DECODE_IMAGES) &&
|
|
|
|
|
(mType == eStyleImageType_Image) &&
|
2012-10-17 03:05:54 +04:00
|
|
|
|
(NS_SUCCEEDED(mImage->GetImageData()->GetImage(getter_AddRefs(img))))))
|
2012-10-13 00:04:32 +04:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2009-08-22 00:39:25 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (mType) {
|
|
|
|
|
case eStyleImageType_Image:
|
|
|
|
|
{
|
|
|
|
|
nsCOMPtr<imgIContainer> srcImage;
|
2012-10-17 03:05:54 +04:00
|
|
|
|
DebugOnly<nsresult> rv =
|
|
|
|
|
mImage->GetImageData()->GetImage(getter_AddRefs(srcImage));
|
|
|
|
|
NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv) && srcImage,
|
|
|
|
|
"If GetImage() is failing, mImage->IsComplete() "
|
|
|
|
|
"should have returned false");
|
2009-08-22 00:39:25 +04:00
|
|
|
|
|
2010-08-06 01:30:19 +04:00
|
|
|
|
if (!mImage->GetCropRect()) {
|
2009-08-22 00:39:25 +04:00
|
|
|
|
mImageContainer.swap(srcImage);
|
|
|
|
|
} else {
|
|
|
|
|
nsIntRect actualCropRect;
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool isEntireImage;
|
|
|
|
|
bool success =
|
2010-08-06 01:30:19 +04:00
|
|
|
|
mImage->ComputeActualCropRect(actualCropRect, &isEntireImage);
|
2009-08-22 00:39:25 +04:00
|
|
|
|
NS_ASSERTION(success, "ComputeActualCropRect() should not fail here");
|
|
|
|
|
if (!success || actualCropRect.IsEmpty()) {
|
|
|
|
|
// The cropped image has zero size
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return false;
|
2009-08-22 00:39:25 +04:00
|
|
|
|
}
|
|
|
|
|
if (isEntireImage) {
|
|
|
|
|
// The cropped image is identical to the source image
|
|
|
|
|
mImageContainer.swap(srcImage);
|
|
|
|
|
} else {
|
2013-04-06 01:14:37 +04:00
|
|
|
|
nsCOMPtr<imgIContainer> subImage = ImageOps::Clip(srcImage, actualCropRect);
|
2009-08-22 00:39:25 +04:00
|
|
|
|
mImageContainer.swap(subImage);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
|
mIsReady = true;
|
2009-08-22 00:39:25 +04:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case eStyleImageType_Gradient:
|
2010-08-06 01:30:19 +04:00
|
|
|
|
mGradientData = mImage->GetGradientData();
|
2011-10-17 18:59:28 +04:00
|
|
|
|
mIsReady = true;
|
2009-08-22 00:39:25 +04:00
|
|
|
|
break;
|
2010-08-13 17:34:01 +04:00
|
|
|
|
case eStyleImageType_Element:
|
|
|
|
|
{
|
|
|
|
|
nsAutoString elementId =
|
2010-08-06 01:30:19 +04:00
|
|
|
|
NS_LITERAL_STRING("#") + nsDependentString(mImage->GetElementId());
|
2010-08-13 17:34:01 +04:00
|
|
|
|
nsCOMPtr<nsIURI> targetURI;
|
|
|
|
|
nsCOMPtr<nsIURI> base = mForFrame->GetContent()->GetBaseURI();
|
|
|
|
|
nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(targetURI), elementId,
|
|
|
|
|
mForFrame->GetContent()->GetCurrentDoc(), base);
|
|
|
|
|
nsSVGPaintingProperty* property = nsSVGEffects::GetPaintingPropertyForURI(
|
2013-09-25 15:42:34 +04:00
|
|
|
|
targetURI, mForFrame->FirstContinuation(),
|
2010-08-13 17:34:01 +04:00
|
|
|
|
nsSVGEffects::BackgroundImageProperty());
|
|
|
|
|
if (!property)
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return false;
|
2010-08-13 17:34:01 +04:00
|
|
|
|
mPaintServerFrame = property->GetReferencedFrame();
|
|
|
|
|
|
|
|
|
|
// If the referenced element doesn't have a frame we might still be able
|
|
|
|
|
// to paint it if it's an <img>, <canvas>, or <video> element.
|
|
|
|
|
if (!mPaintServerFrame) {
|
2011-12-04 01:50:16 +04:00
|
|
|
|
mImageElementSurface =
|
|
|
|
|
nsLayoutUtils::SurfaceFromElement(property->GetReferencedElement());
|
2013-12-12 01:05:27 +04:00
|
|
|
|
if (!mImageElementSurface.mSourceSurface)
|
2011-10-17 18:59:28 +04:00
|
|
|
|
return false;
|
2010-08-13 17:34:01 +04:00
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
|
mIsReady = true;
|
2010-08-13 17:34:01 +04:00
|
|
|
|
break;
|
|
|
|
|
}
|
2009-08-22 00:39:25 +04:00
|
|
|
|
case eStyleImageType_Null:
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return mIsReady;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-19 12:39:58 +04:00
|
|
|
|
nsSize
|
|
|
|
|
CSSSizeOrRatio::ComputeConcreteSize() const
|
2011-01-13 13:40:12 +03:00
|
|
|
|
{
|
2013-07-19 12:39:58 +04: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-15 00:57:49 +04:00
|
|
|
|
}
|
2013-07-19 12:39:58 +04:00
|
|
|
|
|
|
|
|
|
MOZ_ASSERT(mHasHeight);
|
|
|
|
|
nscoord width = NSCoordSaturatingNonnegativeMultiply(
|
|
|
|
|
mHeight,
|
2014-01-15 00:57:49 +04:00
|
|
|
|
double(mRatio.width) / mRatio.height);
|
2013-07-19 12:39:58 +04:00
|
|
|
|
return nsSize(width, mHeight);
|
2011-01-13 13:40:12 +03:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-19 12:39:58 +04:00
|
|
|
|
CSSSizeOrRatio
|
|
|
|
|
nsImageRenderer::ComputeIntrinsicSize()
|
2009-08-22 00:39:25 +04:00
|
|
|
|
{
|
|
|
|
|
NS_ASSERTION(mIsReady, "Ensure PrepareImage() has returned true "
|
|
|
|
|
"before calling me");
|
|
|
|
|
|
2013-07-19 12:39:58 +04:00
|
|
|
|
CSSSizeOrRatio result;
|
2009-08-22 00:39:25 +04:00
|
|
|
|
switch (mType) {
|
|
|
|
|
case eStyleImageType_Image:
|
|
|
|
|
{
|
2013-07-19 12:39:58 +04:00
|
|
|
|
bool haveWidth, haveHeight;
|
2009-08-22 00:39:25 +04:00
|
|
|
|
nsIntSize imageIntSize;
|
2010-09-09 00:40:39 +04:00
|
|
|
|
nsLayoutUtils::ComputeSizeForDrawing(mImageContainer, imageIntSize,
|
2013-07-19 12:39:58 +04:00
|
|
|
|
result.mRatio, haveWidth, haveHeight);
|
|
|
|
|
if (haveWidth) {
|
|
|
|
|
result.SetWidth(nsPresContext::CSSPixelsToAppUnits(imageIntSize.width));
|
2011-01-13 13:40:12 +03:00
|
|
|
|
}
|
2013-07-19 12:39:58 +04:00
|
|
|
|
if (haveHeight) {
|
|
|
|
|
result.SetHeight(nsPresContext::CSSPixelsToAppUnits(imageIntSize.height));
|
2011-01-13 13:40:12 +03:00
|
|
|
|
}
|
2013-07-19 12:39:58 +04:00
|
|
|
|
break;
|
2009-08-22 00:39:25 +04:00
|
|
|
|
}
|
2010-08-13 17:34:01 +04:00
|
|
|
|
case eStyleImageType_Element:
|
|
|
|
|
{
|
2011-01-13 13:40:12 +03: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 07:36:42 +04:00
|
|
|
|
// should have no width/height or ratio. See element() in CSS images:
|
|
|
|
|
// <http://dev.w3.org/csswg/css-images-4/#element-notation>.
|
2011-01-13 13:40:12 +03:00
|
|
|
|
// Make sure to change nsStyleBackground::Size::DependsOnFrameSize
|
|
|
|
|
// when fixing this!
|
2010-08-13 17:34:01 +04:00
|
|
|
|
if (mPaintServerFrame) {
|
2013-07-19 12:39:58 +04:00
|
|
|
|
// SVG images have no intrinsic size
|
|
|
|
|
if (!mPaintServerFrame->IsFrameOfType(nsIFrame::eSVG)) {
|
2010-08-13 17:34:01 +04:00
|
|
|
|
// The intrinsic image size for a generic nsIFrame paint server is
|
2012-06-19 19:28:04 +04:00
|
|
|
|
// the union of the border-box rects of all of its continuations,
|
|
|
|
|
// rounded to device pixels.
|
2012-08-22 19:56:38 +04:00
|
|
|
|
int32_t appUnitsPerDevPixel =
|
2010-08-13 17:34:01 +04:00
|
|
|
|
mForFrame->PresContext()->AppUnitsPerDevPixel();
|
2013-07-19 12:39:58 +04:00
|
|
|
|
result.SetSize(
|
2012-06-19 19:28:04 +04:00
|
|
|
|
nsSVGIntegrationUtils::GetContinuationUnionSize(mPaintServerFrame).
|
|
|
|
|
ToNearestPixels(appUnitsPerDevPixel).
|
2013-07-19 12:39:58 +04:00
|
|
|
|
ToAppUnits(appUnitsPerDevPixel));
|
2010-08-13 17:34:01 +04:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2013-12-12 01:05:27 +04:00
|
|
|
|
NS_ASSERTION(mImageElementSurface.mSourceSurface, "Surface should be ready.");
|
2011-01-13 13:40:12 +03:00
|
|
|
|
gfxIntSize surfaceSize = mImageElementSurface.mSize;
|
2013-07-19 12:39:58 +04:00
|
|
|
|
result.SetSize(
|
|
|
|
|
nsSize(nsPresContext::CSSPixelsToAppUnits(surfaceSize.width),
|
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(surfaceSize.height)));
|
2010-08-13 17:34:01 +04:00
|
|
|
|
}
|
2013-07-19 12:39:58 +04:00
|
|
|
|
break;
|
2010-08-13 17:34:01 +04:00
|
|
|
|
}
|
2013-07-19 12:39:58 +04:00
|
|
|
|
case eStyleImageType_Gradient:
|
|
|
|
|
// Per <http://dev.w3.org/csswg/css3-images/#gradients>, gradients have no
|
|
|
|
|
// intrinsic dimensions.
|
2009-08-22 00:39:25 +04:00
|
|
|
|
case eStyleImageType_Null:
|
|
|
|
|
default:
|
2013-07-19 12:39:58 +04:00
|
|
|
|
break;
|
2011-01-13 13:40:12 +03:00
|
|
|
|
}
|
2013-07-19 12:39:58 +04:00
|
|
|
|
|
|
|
|
|
return result;
|
2011-01-13 13:40:12 +03:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-19 12:39:58 +04:00
|
|
|
|
/* static */ nsSize
|
|
|
|
|
nsImageRenderer::ComputeConcreteSize(const CSSSizeOrRatio& aSpecifiedSize,
|
|
|
|
|
const CSSSizeOrRatio& aIntrinsicSize,
|
|
|
|
|
const nsSize& aDefaultSize)
|
2011-01-13 13:40:12 +03:00
|
|
|
|
{
|
2013-07-19 12:39:58 +04:00
|
|
|
|
// The specified size is fully specified, just use that
|
|
|
|
|
if (aSpecifiedSize.IsConcrete()) {
|
|
|
|
|
return aSpecifiedSize.ComputeConcreteSize();
|
2009-08-22 00:39:25 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-19 12:39:58 +04:00
|
|
|
|
MOZ_ASSERT(!aSpecifiedSize.mHasWidth || !aSpecifiedSize.mHasHeight);
|
2011-01-13 13:40:12 +03:00
|
|
|
|
|
2013-07-19 12:39:58 +04:00
|
|
|
|
if (!aSpecifiedSize.mHasWidth && !aSpecifiedSize.mHasHeight) {
|
|
|
|
|
// no specified size, try using the intrinsic size
|
|
|
|
|
if (aIntrinsicSize.CanComputeConcreteSize()) {
|
|
|
|
|
return aIntrinsicSize.ComputeConcreteSize();
|
2011-01-13 13:40:12 +03:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-19 12:39:58 +04:00
|
|
|
|
if (aIntrinsicSize.mHasWidth) {
|
|
|
|
|
return nsSize(aIntrinsicSize.mWidth, aDefaultSize.height);
|
|
|
|
|
}
|
|
|
|
|
if (aIntrinsicSize.mHasHeight) {
|
|
|
|
|
return nsSize(aDefaultSize.width, aIntrinsicSize.mHeight);
|
2011-01-13 13:40:12 +03:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-19 12:39:58 +04:00
|
|
|
|
// couldn't use the intrinsic size either, revert to using the default size
|
|
|
|
|
return ComputeConstrainedSize(aDefaultSize,
|
|
|
|
|
aIntrinsicSize.mRatio,
|
|
|
|
|
CONTAIN);
|
|
|
|
|
}
|
2011-01-13 13:40:12 +03:00
|
|
|
|
|
2013-07-19 12:39:58 +04:00
|
|
|
|
MOZ_ASSERT(aSpecifiedSize.mHasWidth || aSpecifiedSize.mHasHeight);
|
2011-01-13 13:40:12 +03:00
|
|
|
|
|
2013-07-19 12:39:58 +04: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 13:40:12 +03:00
|
|
|
|
} else {
|
2013-07-19 12:39:58 +04:00
|
|
|
|
height = aDefaultSize.height;
|
2011-01-13 13:40:12 +03:00
|
|
|
|
}
|
2013-07-19 12:39:58 +04:00
|
|
|
|
return nsSize(aSpecifiedSize.mWidth, height);
|
|
|
|
|
}
|
2011-01-13 13:40:12 +03:00
|
|
|
|
|
2013-07-19 12:39:58 +04: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 13:40:12 +03:00
|
|
|
|
}
|
2013-07-19 12:39:58 +04:00
|
|
|
|
return nsSize(width, aSpecifiedSize.mHeight);
|
|
|
|
|
}
|
2011-01-13 13:40:12 +03:00
|
|
|
|
|
2013-07-19 12:39:58 +04: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 13:40:12 +03:00
|
|
|
|
|
2013-07-19 12:39:58 +04:00
|
|
|
|
float scaleX = double(aConstrainingSize.width) / aIntrinsicRatio.width;
|
|
|
|
|
float scaleY = double(aConstrainingSize.height) / aIntrinsicRatio.height;
|
2011-01-13 13:40:12 +03:00
|
|
|
|
nsSize size;
|
2013-07-19 12:39:58 +04:00
|
|
|
|
if ((aFitType == CONTAIN) == (scaleX < scaleY)) {
|
|
|
|
|
size.width = aConstrainingSize.width;
|
|
|
|
|
size.height = NSCoordSaturatingNonnegativeMultiply(
|
|
|
|
|
aIntrinsicRatio.height, scaleX);
|
2011-01-13 13:40:12 +03:00
|
|
|
|
} else {
|
2013-07-19 12:39:58 +04:00
|
|
|
|
size.width = NSCoordSaturatingNonnegativeMultiply(
|
|
|
|
|
aIntrinsicRatio.width, scaleY);
|
|
|
|
|
size.height = aConstrainingSize.height;
|
2011-01-13 13:40:12 +03:00
|
|
|
|
}
|
|
|
|
|
return size;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-19 12:39:58 +04: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 13:40:12 +03: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 12:39:58 +04: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 13:40:12 +03: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 12:39:58 +04:00
|
|
|
|
void
|
|
|
|
|
nsImageRenderer::SetPreferredSize(const CSSSizeOrRatio& aIntrinsicSize,
|
|
|
|
|
const nsSize& aDefaultSize)
|
2011-01-13 13:40:12 +03:00
|
|
|
|
{
|
2013-07-19 12:39:58 +04:00
|
|
|
|
mSize.width = aIntrinsicSize.mHasWidth
|
|
|
|
|
? aIntrinsicSize.mWidth
|
|
|
|
|
: aDefaultSize.width;
|
|
|
|
|
mSize.height = aIntrinsicSize.mHasHeight
|
|
|
|
|
? aIntrinsicSize.mHeight
|
|
|
|
|
: aDefaultSize.height;
|
2009-08-22 00:39:25 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-01 02:09:30 +04: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;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-22 00:39:25 +04:00
|
|
|
|
void
|
2012-05-04 00:11:57 +04:00
|
|
|
|
nsImageRenderer::Draw(nsPresContext* aPresContext,
|
2013-07-19 12:40:02 +04:00
|
|
|
|
nsRenderingContext& aRenderingContext,
|
|
|
|
|
const nsRect& aDirtyRect,
|
2012-05-04 00:11:57 +04:00
|
|
|
|
const nsRect& aFill,
|
2014-01-31 07:36:41 +04:00
|
|
|
|
const nsRect& aDest,
|
|
|
|
|
const CSSIntRect& aSrc)
|
2009-08-22 00:39:25 +04:00
|
|
|
|
{
|
|
|
|
|
if (!mIsReady) {
|
|
|
|
|
NS_NOTREACHED("Ensure PrepareImage() has returned true before calling me");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-08-13 17:34:01 +04:00
|
|
|
|
if (aDest.IsEmpty() || aFill.IsEmpty() ||
|
2013-07-19 12:40:02 +04:00
|
|
|
|
mSize.width <= 0 || mSize.height <= 0) {
|
2009-08-22 00:39:25 +04:00
|
|
|
|
return;
|
2013-07-19 12:40:02 +04:00
|
|
|
|
}
|
2009-08-22 00:39:25 +04:00
|
|
|
|
|
2013-10-02 01:01:19 +04:00
|
|
|
|
GraphicsFilter graphicsFilter =
|
2010-08-13 17:34:01 +04:00
|
|
|
|
nsLayoutUtils::GetGraphicsFilterForFrame(mForFrame);
|
|
|
|
|
|
2009-08-22 00:39:25 +04:00
|
|
|
|
switch (mType) {
|
|
|
|
|
case eStyleImageType_Image:
|
2009-09-13 02:44:18 +04:00
|
|
|
|
{
|
2013-07-19 12:40:02 +04:00
|
|
|
|
nsLayoutUtils::DrawSingleImage(&aRenderingContext, mImageContainer,
|
|
|
|
|
graphicsFilter, aFill, aDirtyRect,
|
2013-08-01 02:09:30 +04:00
|
|
|
|
nullptr,
|
|
|
|
|
ConvertImageRendererToDrawFlags(mFlags));
|
2013-07-19 12:40:02 +04:00
|
|
|
|
return;
|
2009-09-13 02:44:18 +04:00
|
|
|
|
}
|
2009-08-22 00:39:25 +04:00
|
|
|
|
case eStyleImageType_Gradient:
|
2013-07-19 12:40:02 +04:00
|
|
|
|
{
|
2009-08-22 00:39:25 +04:00
|
|
|
|
nsCSSRendering::PaintGradient(aPresContext, aRenderingContext,
|
2014-01-31 07:36:41 +04:00
|
|
|
|
mGradientData, aDirtyRect,
|
|
|
|
|
aDest, aFill, aSrc, mSize);
|
2013-07-19 12:40:02 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
2010-08-13 17:34:01 +04:00
|
|
|
|
case eStyleImageType_Element:
|
2013-07-19 12:40:02 +04:00
|
|
|
|
{
|
2014-01-31 07:36:42 +04:00
|
|
|
|
nsRefPtr<gfxDrawable> drawable = DrawableForElement(aDest,
|
|
|
|
|
aRenderingContext);
|
|
|
|
|
if (!drawable) {
|
|
|
|
|
NS_WARNING("Could not create drawable for element");
|
|
|
|
|
return;
|
2010-08-13 17:34:01 +04:00
|
|
|
|
}
|
2014-01-31 07:36:42 +04:00
|
|
|
|
nsLayoutUtils::DrawPixelSnapped(&aRenderingContext, drawable, graphicsFilter,
|
2014-01-31 07:36:42 +04:00
|
|
|
|
aDest, aFill, aDest.TopLeft(), aDirtyRect);
|
2013-07-19 12:40:02 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
2009-08-22 00:39:25 +04:00
|
|
|
|
case eStyleImageType_Null:
|
|
|
|
|
default:
|
2013-07-19 12:40:02 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-31 07:36:42 +04: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) {
|
|
|
|
|
int32_t appUnitsPerDevPixel = mForFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
|
nsRect destRect = aImageRect - aImageRect.TopLeft();
|
|
|
|
|
nsIntSize roundedOut = destRect.ToOutsidePixels(appUnitsPerDevPixel).Size();
|
|
|
|
|
gfxIntSize imageSize(roundedOut.width, roundedOut.height);
|
|
|
|
|
nsRefPtr<gfxDrawable> drawable =
|
|
|
|
|
nsSVGIntegrationUtils::DrawableFromPaintServer(
|
|
|
|
|
mPaintServerFrame, mForFrame, mSize, imageSize,
|
|
|
|
|
aRenderingContext.ThebesContext()->CurrentMatrix(),
|
|
|
|
|
mFlags & FLAG_SYNC_DECODE_IMAGES
|
|
|
|
|
? nsSVGIntegrationUtils::FLAG_SYNC_DECODE_IMAGES
|
|
|
|
|
: 0);
|
|
|
|
|
|
|
|
|
|
return drawable.forget();
|
|
|
|
|
}
|
|
|
|
|
NS_ASSERTION(mImageElementSurface.mSourceSurface, "Surface should be ready.");
|
|
|
|
|
nsRefPtr<gfxDrawable> drawable = new gfxSurfaceDrawable(
|
|
|
|
|
mImageElementSurface.mSourceSurface,
|
|
|
|
|
mImageElementSurface.mSize);
|
|
|
|
|
return drawable.forget();
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-19 12:40:02 +04:00
|
|
|
|
void
|
|
|
|
|
nsImageRenderer::DrawBackground(nsPresContext* aPresContext,
|
|
|
|
|
nsRenderingContext& aRenderingContext,
|
|
|
|
|
const nsRect& aDest,
|
|
|
|
|
const nsRect& aFill,
|
|
|
|
|
const nsPoint& aAnchor,
|
|
|
|
|
const nsRect& aDirty)
|
|
|
|
|
{
|
|
|
|
|
if (!mIsReady) {
|
|
|
|
|
NS_NOTREACHED("Ensure PrepareImage() has returned true before calling me");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (aDest.IsEmpty() || aFill.IsEmpty() ||
|
|
|
|
|
mSize.width <= 0 || mSize.height <= 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mType == eStyleImageType_Image) {
|
2013-10-02 01:01:19 +04:00
|
|
|
|
GraphicsFilter graphicsFilter =
|
2013-07-19 12:40:02 +04:00
|
|
|
|
nsLayoutUtils::GetGraphicsFilterForFrame(mForFrame);
|
|
|
|
|
|
|
|
|
|
nsLayoutUtils::DrawBackgroundImage(&aRenderingContext, mImageContainer,
|
2014-01-31 07:36:41 +04:00
|
|
|
|
nsIntSize(nsPresContext::AppUnitsToIntCSSPixels(mSize.width),
|
|
|
|
|
nsPresContext::AppUnitsToIntCSSPixels(mSize.height)),
|
|
|
|
|
graphicsFilter,
|
|
|
|
|
aDest, aFill, aAnchor, aDirty,
|
|
|
|
|
ConvertImageRendererToDrawFlags(mFlags));
|
2013-07-19 12:40:02 +04:00
|
|
|
|
return;
|
2009-08-22 00:39:25 +04:00
|
|
|
|
}
|
2013-07-19 12:40:02 +04:00
|
|
|
|
|
2014-01-31 07:36:41 +04:00
|
|
|
|
Draw(aPresContext, aRenderingContext,
|
|
|
|
|
aDirty, aFill, aDest,
|
|
|
|
|
CSSIntRect(0, 0,
|
|
|
|
|
nsPresContext::AppUnitsToIntCSSPixels(mSize.width),
|
|
|
|
|
nsPresContext::AppUnitsToIntCSSPixels(mSize.height)));
|
2009-08-22 00:39:25 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-31 07:36:41 +04: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
|
|
|
|
|
ComputeTile(const nsRect& aFill,
|
|
|
|
|
uint8_t aHFill,
|
|
|
|
|
uint8_t aVFill,
|
|
|
|
|
const nsSize& aUnitSize)
|
|
|
|
|
{
|
|
|
|
|
nsRect tile;
|
|
|
|
|
switch (aHFill) {
|
|
|
|
|
case NS_STYLE_BORDER_IMAGE_REPEAT_STRETCH:
|
|
|
|
|
tile.x = aFill.x;
|
|
|
|
|
tile.width = aFill.width;
|
|
|
|
|
break;
|
|
|
|
|
case NS_STYLE_BORDER_IMAGE_REPEAT_REPEAT:
|
|
|
|
|
tile.x = aFill.x + aFill.width/2 - aUnitSize.width/2;
|
|
|
|
|
tile.width = aUnitSize.width;
|
|
|
|
|
break;
|
|
|
|
|
case NS_STYLE_BORDER_IMAGE_REPEAT_ROUND:
|
|
|
|
|
tile.x = aFill.x;
|
|
|
|
|
tile.width = aFill.width / ceil(gfxFloat(aFill.width)/aUnitSize.width);
|
|
|
|
|
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;
|
|
|
|
|
break;
|
|
|
|
|
case NS_STYLE_BORDER_IMAGE_REPEAT_REPEAT:
|
|
|
|
|
tile.y = aFill.y + aFill.height/2 - aUnitSize.height/2;
|
|
|
|
|
tile.height = aUnitSize.height;
|
|
|
|
|
break;
|
|
|
|
|
case NS_STYLE_BORDER_IMAGE_REPEAT_ROUND:
|
|
|
|
|
tile.y = aFill.y;
|
|
|
|
|
tile.height = aFill.height/ceil(gfxFloat(aFill.height)/aUnitSize.height);
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nsImageRenderer::DrawBorderImageComponent(nsPresContext* aPresContext,
|
|
|
|
|
nsRenderingContext& aRenderingContext,
|
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
|
const nsRect& aFill,
|
2014-01-31 07:36:41 +04:00
|
|
|
|
const CSSIntRect& aSrc,
|
2014-01-31 07:36:41 +04:00
|
|
|
|
uint8_t aHFill,
|
|
|
|
|
uint8_t aVFill,
|
|
|
|
|
const nsSize& aUnitSize,
|
|
|
|
|
uint8_t aIndex)
|
|
|
|
|
{
|
|
|
|
|
if (!mIsReady) {
|
|
|
|
|
NS_NOTREACHED("Ensure PrepareImage() has returned true before calling me");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (aFill.IsEmpty() || aSrc.IsEmpty()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mType == eStyleImageType_Image) {
|
|
|
|
|
nsCOMPtr<imgIContainer> subImage;
|
|
|
|
|
if ((subImage = mImage->GetSubImage(aIndex)) == nullptr) {
|
2014-01-31 07:36:41 +04:00
|
|
|
|
subImage = ImageOps::Clip(mImageContainer, nsIntRect(aSrc.x,
|
|
|
|
|
aSrc.y,
|
|
|
|
|
aSrc.width,
|
|
|
|
|
aSrc.height));
|
2014-01-31 07:36:41 +04:00
|
|
|
|
mImage->SetSubImage(aIndex, subImage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GraphicsFilter graphicsFilter =
|
|
|
|
|
nsLayoutUtils::GetGraphicsFilterForFrame(mForFrame);
|
|
|
|
|
|
|
|
|
|
if (!RequiresScaling(aFill, aHFill, aVFill, aUnitSize)) {
|
2014-01-31 07:36:41 +04:00
|
|
|
|
nsLayoutUtils::DrawSingleImage(&aRenderingContext,
|
|
|
|
|
subImage,
|
|
|
|
|
graphicsFilter,
|
|
|
|
|
aFill, aDirtyRect,
|
|
|
|
|
nullptr,
|
|
|
|
|
imgIContainer::FLAG_NONE);
|
2014-01-31 07:36:41 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsRect tile = ComputeTile(aFill, aHFill, aVFill, aUnitSize);
|
2014-01-31 07:36:41 +04:00
|
|
|
|
nsLayoutUtils::DrawImage(&aRenderingContext,
|
|
|
|
|
subImage,
|
|
|
|
|
graphicsFilter,
|
2014-01-31 07:36:41 +04:00
|
|
|
|
tile, aFill, tile.TopLeft(), aDirtyRect,
|
|
|
|
|
imgIContainer::FLAG_NONE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-31 07:36:42 +04:00
|
|
|
|
nsRect destTile = RequiresScaling(aFill, aHFill, aVFill, aUnitSize)
|
2014-01-31 07:36:41 +04:00
|
|
|
|
? ComputeTile(aFill, aHFill, aVFill, aUnitSize)
|
|
|
|
|
: aFill;
|
2014-01-31 07:36:42 +04:00
|
|
|
|
|
|
|
|
|
if (mType == eStyleImageType_Element) {
|
|
|
|
|
// This path is horribly slow - we read and copy the source nine times(!)
|
|
|
|
|
// It could be easily optimised by only reading the source once and caching
|
|
|
|
|
// it. It could be further optimised by caching the sub-images between draws
|
|
|
|
|
// but that would be a bit harder because you would have to know when to
|
|
|
|
|
// invalidate the cache. A special case optimisation would be when
|
|
|
|
|
// border-image-slice is proportional to the border widths, in which case
|
|
|
|
|
// the subimages do not need to be independently scaled, then we don't need
|
|
|
|
|
// subimages at all.
|
|
|
|
|
// In any case, such optimisations are probably not worth doing because it
|
|
|
|
|
// seems unlikely anyone would use -moz-element as the source for a border
|
|
|
|
|
// image.
|
|
|
|
|
|
|
|
|
|
// draw the source image slice into an intermediate surface
|
|
|
|
|
nsPresContext* presContext = mForFrame->PresContext();
|
|
|
|
|
gfxRect srcRect = gfxRect(presContext->CSSPixelsToDevPixels(aSrc.x),
|
|
|
|
|
presContext->CSSPixelsToDevPixels(aSrc.y),
|
|
|
|
|
presContext->CSSPixelsToDevPixels(aSrc.width),
|
|
|
|
|
presContext->CSSPixelsToDevPixels(aSrc.height));
|
2014-02-11 18:22:45 +04:00
|
|
|
|
RefPtr<DrawTarget> srcSlice = gfxPlatform::GetPlatform()->
|
|
|
|
|
CreateOffscreenContentDrawTarget(IntSize(srcRect.width, srcRect.height),
|
|
|
|
|
SurfaceFormat::B8G8R8A8);
|
2014-01-31 07:36:42 +04:00
|
|
|
|
nsRefPtr<gfxContext> ctx = new gfxContext(srcSlice);
|
|
|
|
|
|
|
|
|
|
// grab the entire source
|
|
|
|
|
nsRefPtr<gfxDrawable> drawable = DrawableForElement(nsRect(nsPoint(), mSize),
|
|
|
|
|
aRenderingContext);
|
|
|
|
|
if (!drawable) {
|
|
|
|
|
NS_WARNING("Could not create drawable for element");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// draw the source into our intermediate surface
|
|
|
|
|
GraphicsFilter graphicsFilter =
|
|
|
|
|
nsLayoutUtils::GetGraphicsFilterForFrame(mForFrame);
|
|
|
|
|
gfxMatrix transform;
|
|
|
|
|
transform.Translate(gfxPoint(srcRect.x, srcRect.y));
|
|
|
|
|
bool success = drawable->Draw(ctx,
|
|
|
|
|
gfxRect(0, 0, srcRect.width, srcRect.height),
|
|
|
|
|
false,
|
|
|
|
|
graphicsFilter,
|
|
|
|
|
transform);
|
|
|
|
|
if (!success) {
|
|
|
|
|
NS_WARNING("Could not copy element image");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ensure that drawing the image gets flushed to the target.
|
|
|
|
|
ctx = nullptr;
|
|
|
|
|
|
|
|
|
|
// draw the slice
|
|
|
|
|
nsRefPtr<gfxSurfaceDrawable> srcSliceDrawable =
|
|
|
|
|
new gfxSurfaceDrawable(srcSlice,
|
|
|
|
|
gfxIntSize(srcRect.width, srcRect.height));
|
|
|
|
|
nsPoint anchor(nsPresContext::CSSPixelsToAppUnits(aSrc.x),
|
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(aSrc.y));
|
|
|
|
|
nsLayoutUtils::DrawPixelSnapped(&aRenderingContext, srcSliceDrawable,
|
|
|
|
|
graphicsFilter, destTile, aFill,
|
|
|
|
|
anchor, aDirtyRect);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Draw(aPresContext, aRenderingContext, aDirtyRect, aFill, destTile, aSrc);
|
2014-01-31 07:36:41 +04:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-04 00:11:57 +04:00
|
|
|
|
bool
|
|
|
|
|
nsImageRenderer::IsRasterImage()
|
|
|
|
|
{
|
2012-12-10 09:34:17 +04:00
|
|
|
|
if (mType != eStyleImageType_Image || !mImageContainer)
|
2012-05-04 00:11:57 +04:00
|
|
|
|
return false;
|
2012-12-10 09:34:17 +04:00
|
|
|
|
return mImageContainer->GetType() == imgIContainer::TYPE_RASTER;
|
2012-05-04 00:11:57 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-30 17:50:50 +04: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;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-04 00:11:57 +04:00
|
|
|
|
already_AddRefed<mozilla::layers::ImageContainer>
|
2012-11-28 06:34:45 +04:00
|
|
|
|
nsImageRenderer::GetContainer(LayerManager* aManager)
|
2012-05-04 00:11:57 +04:00
|
|
|
|
{
|
2012-12-10 09:34:17 +04:00
|
|
|
|
if (mType != eStyleImageType_Image || !mImageContainer)
|
2012-07-30 18:20:58 +04:00
|
|
|
|
return nullptr;
|
2012-11-28 06:34:45 +04:00
|
|
|
|
|
2012-05-04 00:11:57 +04:00
|
|
|
|
nsRefPtr<ImageContainer> container;
|
2012-12-10 09:34:17 +04:00
|
|
|
|
nsresult rv = mImageContainer->GetImageContainer(aManager, getter_AddRefs(container));
|
2012-07-30 18:20:58 +04:00
|
|
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
2012-05-04 00:11:57 +04:00
|
|
|
|
return container.forget();
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-15 07:16:17 +03:00
|
|
|
|
#define MAX_BLUR_RADIUS 300
|
2010-08-23 13:30:07 +04:00
|
|
|
|
#define MAX_SPREAD_RADIUS 50
|
2010-03-15 07:16:17 +03:00
|
|
|
|
|
2013-11-26 03:09:04 +04:00
|
|
|
|
static inline gfxPoint ComputeBlurStdDev(nscoord aBlurRadius,
|
|
|
|
|
int32_t aAppUnitsPerDevPixel,
|
|
|
|
|
gfxFloat aScaleX,
|
|
|
|
|
gfxFloat aScaleY)
|
2010-09-11 20:27:12 +04: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-17 00:45:25 +04:00
|
|
|
|
gfxFloat blurStdDev = gfxFloat(aBlurRadius) / gfxFloat(aAppUnitsPerDevPixel);
|
|
|
|
|
|
2013-11-26 03:09:04 +04:00
|
|
|
|
return gfxPoint(std::min((blurStdDev * aScaleX),
|
|
|
|
|
gfxFloat(MAX_BLUR_RADIUS)) / 2.0,
|
|
|
|
|
std::min((blurStdDev * aScaleY),
|
|
|
|
|
gfxFloat(MAX_BLUR_RADIUS)) / 2.0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline gfxIntSize
|
|
|
|
|
ComputeBlurRadius(nscoord aBlurRadius,
|
|
|
|
|
int32_t aAppUnitsPerDevPixel,
|
|
|
|
|
gfxFloat aScaleX = 1.0,
|
|
|
|
|
gfxFloat aScaleY = 1.0)
|
|
|
|
|
{
|
|
|
|
|
gfxPoint scaledBlurStdDev = ComputeBlurStdDev(aBlurRadius, aAppUnitsPerDevPixel,
|
|
|
|
|
aScaleX, aScaleY);
|
2010-09-11 20:27:12 +04:00
|
|
|
|
return
|
2012-05-22 19:32:08 +04:00
|
|
|
|
gfxAlphaBoxBlur::CalculateBlurRadius(scaledBlurStdDev);
|
2010-09-11 20:27:12 +04:00
|
|
|
|
}
|
|
|
|
|
|
2008-06-13 02:02:32 +04:00
|
|
|
|
// -----
|
|
|
|
|
// nsContextBoxBlur
|
|
|
|
|
// -----
|
|
|
|
|
gfxContext*
|
2010-08-23 13:30:07 +04:00
|
|
|
|
nsContextBoxBlur::Init(const nsRect& aRect, nscoord aSpreadRadius,
|
|
|
|
|
nscoord aBlurRadius,
|
2012-08-22 19:56:38 +04:00
|
|
|
|
int32_t aAppUnitsPerDevPixel,
|
2008-12-03 00:16:22 +03:00
|
|
|
|
gfxContext* aDestinationCtx,
|
2010-04-18 07:13:10 +04:00
|
|
|
|
const nsRect& aDirtyRect,
|
2010-08-23 13:30:07 +04:00
|
|
|
|
const gfxRect* aSkipRect,
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t aFlags)
|
2008-06-13 02:02:32 +04:00
|
|
|
|
{
|
2010-01-06 21:02:11 +03:00
|
|
|
|
if (aRect.IsEmpty()) {
|
2012-07-30 18:20:58 +04:00
|
|
|
|
mContext = nullptr;
|
|
|
|
|
return nullptr;
|
2010-01-06 21:02:11 +03:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-22 19:32:08 +04:00
|
|
|
|
gfxFloat scaleX = 1;
|
|
|
|
|
gfxFloat scaleY = 1;
|
2012-05-17 00:45:25 +04:00
|
|
|
|
|
2012-06-01 02:22:28 +04:00
|
|
|
|
// Do blurs in device space when possible.
|
2012-05-17 00:45:25 +04:00
|
|
|
|
// Chrome/Skia always does the blurs in device space
|
|
|
|
|
// and will sometimes get incorrect results (e.g. rotated blurs)
|
|
|
|
|
gfxMatrix transform = aDestinationCtx->CurrentMatrix();
|
2012-06-01 02:22:28 +04:00
|
|
|
|
// XXX: we could probably handle negative scales but for now it's easier just to fallback
|
|
|
|
|
if (transform.HasNonAxisAlignedTransform() || transform.xx <= 0.0 || transform.yy <= 0.0) {
|
2012-05-17 00:45:25 +04:00
|
|
|
|
transform = gfxMatrix();
|
|
|
|
|
} else {
|
2012-05-22 19:32:08 +04:00
|
|
|
|
scaleX = transform.xx;
|
|
|
|
|
scaleY = transform.yy;
|
2012-05-17 00:45:25 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// compute a large or smaller blur radius
|
2012-05-22 19:32:08 +04:00
|
|
|
|
gfxIntSize blurRadius = ComputeBlurRadius(aBlurRadius, aAppUnitsPerDevPixel, scaleX, scaleY);
|
2013-01-15 16:22:03 +04:00
|
|
|
|
gfxIntSize spreadRadius = gfxIntSize(std::min(int32_t(aSpreadRadius * scaleX / aAppUnitsPerDevPixel),
|
2012-08-22 19:56:38 +04:00
|
|
|
|
int32_t(MAX_SPREAD_RADIUS)),
|
2013-01-15 16:22:03 +04:00
|
|
|
|
std::min(int32_t(aSpreadRadius * scaleY / aAppUnitsPerDevPixel),
|
2012-08-22 19:56:38 +04:00
|
|
|
|
int32_t(MAX_SPREAD_RADIUS)));
|
2009-09-18 22:18:35 +04:00
|
|
|
|
mDestinationCtx = aDestinationCtx;
|
2009-09-04 17:32:17 +04:00
|
|
|
|
|
2010-01-06 21:02:11 +03:00
|
|
|
|
// If not blurring, draw directly onto the destination device
|
2012-05-22 19:32:08 +04:00
|
|
|
|
if (blurRadius.width <= 0 && blurRadius.height <= 0 &&
|
|
|
|
|
spreadRadius.width <= 0 && spreadRadius.height <= 0 &&
|
2010-09-11 20:27:12 +04:00
|
|
|
|
!(aFlags & FORCE_MASK)) {
|
2008-06-13 02:02:32 +04:00
|
|
|
|
mContext = aDestinationCtx;
|
|
|
|
|
return mContext;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Convert from app units to device pixels
|
2010-09-08 02:20:35 +04:00
|
|
|
|
gfxRect rect = nsLayoutUtils::RectToGfxRect(aRect, aAppUnitsPerDevPixel);
|
2008-06-13 02:02:32 +04:00
|
|
|
|
|
2010-09-08 02:20:35 +04:00
|
|
|
|
gfxRect dirtyRect =
|
|
|
|
|
nsLayoutUtils::RectToGfxRect(aDirtyRect, aAppUnitsPerDevPixel);
|
2009-09-07 04:35:14 +04:00
|
|
|
|
dirtyRect.RoundOut();
|
2008-07-14 14:35:15 +04:00
|
|
|
|
|
2012-05-17 00:45:25 +04:00
|
|
|
|
rect = transform.TransformBounds(rect);
|
|
|
|
|
|
|
|
|
|
mPreTransformed = !transform.IsIdentity();
|
|
|
|
|
|
2008-12-06 21:54:36 +03:00
|
|
|
|
// Create the temporary surface for blurring
|
2012-05-17 00:45:25 +04:00
|
|
|
|
dirtyRect = transform.TransformBounds(dirtyRect);
|
|
|
|
|
if (aSkipRect) {
|
|
|
|
|
gfxRect skipRect = transform.TransformBounds(*aSkipRect);
|
2012-05-22 19:32:08 +04:00
|
|
|
|
mContext = blur.Init(rect, spreadRadius,
|
2012-05-17 00:45:25 +04:00
|
|
|
|
blurRadius, &dirtyRect, &skipRect);
|
|
|
|
|
} else {
|
2012-05-22 19:32:08 +04:00
|
|
|
|
mContext = blur.Init(rect, spreadRadius,
|
2013-10-08 22:47:21 +04:00
|
|
|
|
blurRadius, &dirtyRect, nullptr);
|
2012-05-17 00:45:25 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mContext) {
|
|
|
|
|
// we don't need to blur if skipRect is equal to rect
|
2013-10-08 22:47:21 +04:00
|
|
|
|
// and mContext will be nullptr
|
2013-10-02 08:20:47 +04:00
|
|
|
|
mContext->Multiply(transform);
|
2012-05-17 00:45:25 +04:00
|
|
|
|
}
|
2008-06-13 02:02:32 +04:00
|
|
|
|
return mContext;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nsContextBoxBlur::DoPaint()
|
|
|
|
|
{
|
2008-09-25 23:53:09 +04:00
|
|
|
|
if (mContext == mDestinationCtx)
|
2008-06-13 02:02:32 +04:00
|
|
|
|
return;
|
|
|
|
|
|
2012-05-17 00:45:25 +04:00
|
|
|
|
gfxContextMatrixAutoSaveRestore saveMatrix(mDestinationCtx);
|
|
|
|
|
|
|
|
|
|
if (mPreTransformed) {
|
|
|
|
|
mDestinationCtx->IdentityMatrix();
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-25 23:53:09 +04:00
|
|
|
|
blur.Paint(mDestinationCtx);
|
2008-06-13 02:02:32 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gfxContext*
|
|
|
|
|
nsContextBoxBlur::GetContext()
|
|
|
|
|
{
|
|
|
|
|
return mContext;
|
|
|
|
|
}
|
2008-12-03 00:16:22 +03:00
|
|
|
|
|
2010-09-11 20:27:12 +04:00
|
|
|
|
/* static */ nsMargin
|
|
|
|
|
nsContextBoxBlur::GetBlurRadiusMargin(nscoord aBlurRadius,
|
2012-08-22 19:56:38 +04:00
|
|
|
|
int32_t aAppUnitsPerDevPixel)
|
2010-09-11 20:27:12 +04:00
|
|
|
|
{
|
|
|
|
|
gfxIntSize blurRadius = ComputeBlurRadius(aBlurRadius, aAppUnitsPerDevPixel);
|
|
|
|
|
|
|
|
|
|
nsMargin result;
|
|
|
|
|
result.top = blurRadius.height * aAppUnitsPerDevPixel;
|
|
|
|
|
result.right = blurRadius.width * aAppUnitsPerDevPixel;
|
|
|
|
|
result.bottom = blurRadius.height * aAppUnitsPerDevPixel;
|
|
|
|
|
result.left = blurRadius.width * aAppUnitsPerDevPixel;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2013-11-26 03:06:17 +04:00
|
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
|
nsContextBoxBlur::BlurRectangle(gfxContext* aDestinationCtx,
|
|
|
|
|
const nsRect& aRect,
|
|
|
|
|
int32_t aAppUnitsPerDevPixel,
|
|
|
|
|
gfxCornerSizes* aCornerRadii,
|
|
|
|
|
nscoord aBlurRadius,
|
|
|
|
|
const gfxRGBA& aShadowColor,
|
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
|
const gfxRect& aSkipRect)
|
|
|
|
|
{
|
2013-11-26 03:07:03 +04:00
|
|
|
|
if (aRect.IsEmpty()) {
|
2013-11-26 03:06:17 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-26 03:08:29 +04:00
|
|
|
|
gfxRect shadowGfxRect =
|
|
|
|
|
nsLayoutUtils::RectToGfxRect(aRect, aAppUnitsPerDevPixel);
|
|
|
|
|
|
|
|
|
|
if (aBlurRadius <= 0) {
|
|
|
|
|
aDestinationCtx->SetColor(aShadowColor);
|
|
|
|
|
aDestinationCtx->NewPath();
|
|
|
|
|
if (aCornerRadii) {
|
|
|
|
|
aDestinationCtx->RoundedRectangle(shadowGfxRect, *aCornerRadii);
|
|
|
|
|
} else {
|
|
|
|
|
aDestinationCtx->Rectangle(shadowGfxRect);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
aDestinationCtx->Fill();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-26 03:07:03 +04: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
|
2013-11-26 03:08:29 +04:00
|
|
|
|
if (!transform.HasNonAxisAlignedTransform() && transform.xx > 0.0 && transform.yy > 0.0) {
|
2013-11-26 03:07:03 +04:00
|
|
|
|
scaleX = transform.xx;
|
|
|
|
|
scaleY = transform.yy;
|
2013-11-26 03:08:29 +04:00
|
|
|
|
aDestinationCtx->IdentityMatrix();
|
2013-12-18 05:58:21 +04:00
|
|
|
|
} else {
|
|
|
|
|
transform = gfxMatrix();
|
2013-11-26 03:07:03 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-26 03:09:04 +04:00
|
|
|
|
gfxPoint blurStdDev = ComputeBlurStdDev(aBlurRadius, aAppUnitsPerDevPixel, scaleX, scaleY);
|
2013-11-26 03:07:03 +04:00
|
|
|
|
|
2013-11-26 03:08:29 +04:00
|
|
|
|
gfxRect dirtyRect =
|
|
|
|
|
nsLayoutUtils::RectToGfxRect(aDirtyRect, aAppUnitsPerDevPixel);
|
|
|
|
|
dirtyRect.RoundOut();
|
2013-11-26 03:06:17 +04:00
|
|
|
|
|
2013-11-26 03:08:29 +04:00
|
|
|
|
shadowGfxRect = transform.TransformBounds(shadowGfxRect);
|
|
|
|
|
dirtyRect = transform.TransformBounds(dirtyRect);
|
|
|
|
|
gfxRect skipRect = transform.TransformBounds(aSkipRect);
|
2013-11-26 03:06:17 +04:00
|
|
|
|
|
|
|
|
|
if (aCornerRadii) {
|
2013-11-26 03:08:29 +04:00
|
|
|
|
aCornerRadii->Scale(scaleX, scaleY);
|
2013-11-26 03:07:03 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-26 03:08:29 +04:00
|
|
|
|
gfxAlphaBoxBlur::BlurRectangle(aDestinationCtx,
|
|
|
|
|
shadowGfxRect,
|
|
|
|
|
aCornerRadii,
|
2013-11-26 03:09:04 +04:00
|
|
|
|
blurStdDev,
|
2013-11-26 03:08:29 +04:00
|
|
|
|
aShadowColor,
|
|
|
|
|
dirtyRect,
|
|
|
|
|
skipRect);
|
2013-11-26 03:06:17 +04:00
|
|
|
|
}
|