2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2006-03-30 05:56:38 +00:00
|
|
|
|
|
|
|
/* utility functions for drawing borders and backgrounds */
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
#ifndef nsCSSRendering_h___
|
|
|
|
#define nsCSSRendering_h___
|
|
|
|
|
2008-09-25 19:53:09 +00:00
|
|
|
#include "gfxBlur.h"
|
2007-08-06 08:15:00 +00:00
|
|
|
#include "gfxContext.h"
|
2012-05-03 20:11:57 +00:00
|
|
|
#include "nsLayoutUtils.h"
|
2013-09-30 21:26:04 +00:00
|
|
|
#include "nsStyleStruct.h"
|
|
|
|
#include "nsIFrame.h"
|
2008-09-25 19:53:09 +00:00
|
|
|
|
2003-02-22 00:32:13 +00:00
|
|
|
class nsStyleContext;
|
2004-07-31 23:15:21 +00:00
|
|
|
class nsPresContext;
|
2011-04-08 01:04:40 +00:00
|
|
|
class nsRenderingContext;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2013-07-19 08:39:58 +00:00
|
|
|
namespace mozilla {
|
|
|
|
|
2013-10-01 21:00:38 +00:00
|
|
|
namespace layers {
|
|
|
|
class ImageContainer;
|
|
|
|
}
|
|
|
|
|
2013-07-19 08:39:58 +00:00
|
|
|
// A CSSSizeOrRatio represents a (possibly partially specified) size for use
|
|
|
|
// in computing image sizes. Either or both of the width and height might be
|
|
|
|
// given. A ratio of width to height may also be given. If we at least two
|
|
|
|
// of these then we can compute a concrete size, that is a width and height.
|
|
|
|
struct CSSSizeOrRatio
|
|
|
|
{
|
|
|
|
CSSSizeOrRatio()
|
|
|
|
: mRatio(0, 0)
|
|
|
|
, mHasWidth(false)
|
|
|
|
, mHasHeight(false) {}
|
|
|
|
|
|
|
|
bool CanComputeConcreteSize() const
|
|
|
|
{
|
|
|
|
return mHasWidth + mHasHeight + HasRatio() >= 2;
|
|
|
|
}
|
|
|
|
bool IsConcrete() const { return mHasWidth && mHasHeight; }
|
|
|
|
bool HasRatio() const { return mRatio.width > 0 && mRatio.height > 0; }
|
|
|
|
bool IsEmpty() const
|
|
|
|
{
|
|
|
|
return (mHasWidth && mWidth <= 0) ||
|
|
|
|
(mHasHeight && mHeight <= 0) ||
|
|
|
|
mRatio.width <= 0 || mRatio.height <= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// CanComputeConcreteSize must return true when ComputeConcreteSize is
|
|
|
|
// called.
|
|
|
|
nsSize ComputeConcreteSize() const;
|
|
|
|
|
|
|
|
void SetWidth(nscoord aWidth)
|
|
|
|
{
|
|
|
|
mWidth = aWidth;
|
|
|
|
mHasWidth = true;
|
|
|
|
if (mHasHeight) {
|
|
|
|
mRatio = nsSize(mWidth, mHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void SetHeight(nscoord aHeight)
|
|
|
|
{
|
|
|
|
mHeight = aHeight;
|
|
|
|
mHasHeight = true;
|
|
|
|
if (mHasWidth) {
|
|
|
|
mRatio = nsSize(mWidth, mHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void SetSize(const nsSize& aSize)
|
|
|
|
{
|
|
|
|
mWidth = aSize.width;
|
|
|
|
mHeight = aSize.height;
|
|
|
|
mHasWidth = true;
|
|
|
|
mHasHeight = true;
|
|
|
|
mRatio = aSize;
|
|
|
|
}
|
|
|
|
void SetRatio(const nsSize& aRatio)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mHasWidth || !mHasHeight,
|
|
|
|
"Probably shouldn't be setting a ratio if we have a concrete size");
|
|
|
|
mRatio = aRatio;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSize mRatio;
|
|
|
|
nscoord mWidth;
|
|
|
|
nscoord mHeight;
|
|
|
|
bool mHasWidth;
|
|
|
|
bool mHasHeight;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-05-03 20:11:57 +00:00
|
|
|
/**
|
|
|
|
* This is a small wrapper class to encapsulate image drawing that can draw an
|
|
|
|
* nsStyleImage image, which may internally be a real image, a sub image, or a
|
|
|
|
* CSS gradient.
|
|
|
|
*
|
|
|
|
* @note Always call the member functions in the order of PrepareImage(),
|
2013-07-19 08:40:02 +00:00
|
|
|
* SetSize(), and Draw*().
|
2012-05-03 20:11:57 +00:00
|
|
|
*/
|
|
|
|
class nsImageRenderer {
|
|
|
|
public:
|
2012-11-28 02:34:45 +00:00
|
|
|
typedef mozilla::layers::LayerManager LayerManager;
|
2012-05-03 20:11:57 +00:00
|
|
|
typedef mozilla::layers::ImageContainer ImageContainer;
|
|
|
|
|
|
|
|
enum {
|
2013-04-25 22:08:58 +00:00
|
|
|
FLAG_SYNC_DECODE_IMAGES = 0x01,
|
|
|
|
FLAG_PAINTING_TO_WINDOW = 0x02
|
2012-05-03 20:11:57 +00:00
|
|
|
};
|
2013-07-19 08:39:58 +00:00
|
|
|
enum FitType
|
|
|
|
{
|
|
|
|
CONTAIN,
|
|
|
|
COVER
|
|
|
|
};
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
nsImageRenderer(nsIFrame* aForFrame, const nsStyleImage* aImage, uint32_t aFlags);
|
2012-05-03 20:11:57 +00:00
|
|
|
~nsImageRenderer();
|
|
|
|
/**
|
|
|
|
* Populates member variables to get ready for rendering.
|
|
|
|
* @return true iff the image is ready, and there is at least a pixel to
|
|
|
|
* draw.
|
|
|
|
*/
|
|
|
|
bool PrepareImage();
|
2013-07-19 08:39:58 +00:00
|
|
|
|
2012-05-03 20:11:57 +00:00
|
|
|
/**
|
2013-07-19 08:39:58 +00:00
|
|
|
* The three Compute*Size functions correspond to the sizing algorthms and
|
|
|
|
* definitions from the CSS Image Values and Replaced Content spec. See
|
|
|
|
* http://dev.w3.org/csswg/css-images-3/#sizing .
|
2012-05-03 20:11:57 +00:00
|
|
|
*/
|
2013-07-19 08:39:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Compute the intrinsic size of the image as defined in the CSS Image Values
|
|
|
|
* spec. The intrinsic size is the unscaled size which the image would ideally
|
|
|
|
* like to be in app units.
|
|
|
|
*/
|
|
|
|
mozilla::CSSSizeOrRatio ComputeIntrinsicSize();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compute the size of the rendered image using either the 'cover' or
|
|
|
|
* 'contain' constraints (aFitType).
|
|
|
|
* aIntrinsicRatio may be an invalid ratio, that is one or both of its
|
|
|
|
* dimensions can be less than or equal to zero.
|
|
|
|
*/
|
|
|
|
static nsSize ComputeConstrainedSize(const nsSize& aConstrainingSize,
|
|
|
|
const nsSize& aIntrinsicRatio,
|
|
|
|
FitType aFitType);
|
|
|
|
/**
|
|
|
|
* Compute the size of the rendered image (the concrete size) where no cover/
|
|
|
|
* contain constraints are given. The 'default algorithm' from the CSS Image
|
|
|
|
* Values spec.
|
|
|
|
*/
|
|
|
|
static nsSize ComputeConcreteSize(const mozilla::CSSSizeOrRatio& aSpecifiedSize,
|
|
|
|
const mozilla::CSSSizeOrRatio& aIntrinsicSize,
|
|
|
|
const nsSize& aDefaultSize);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set this image's preferred size. This will be its intrinsic size where
|
|
|
|
* specified and the default size where it is not. Used as the unscaled size
|
|
|
|
* when rendering the image.
|
|
|
|
*/
|
|
|
|
void SetPreferredSize(const mozilla::CSSSizeOrRatio& aIntrinsicSize,
|
|
|
|
const nsSize& aDefaultSize);
|
|
|
|
|
2012-05-03 20:11:57 +00:00
|
|
|
/**
|
|
|
|
* Draws the image to the target rendering context.
|
2013-07-19 08:40:02 +00:00
|
|
|
* @see nsLayoutUtils::DrawImage() for other parameters.
|
2012-05-03 20:11:57 +00:00
|
|
|
*/
|
|
|
|
void Draw(nsPresContext* aPresContext,
|
2013-07-19 08:40:02 +00:00
|
|
|
nsRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect,
|
2012-05-03 20:11:57 +00:00
|
|
|
const nsRect& aFill,
|
2013-07-31 22:09:30 +00:00
|
|
|
const nsRect& aDest);
|
2013-07-19 08:40:02 +00:00
|
|
|
/**
|
|
|
|
* Draws the image to the target rendering context using background-specific
|
|
|
|
* arguments.
|
|
|
|
* @see nsLayoutUtils::DrawImage() for parameters.
|
|
|
|
*/
|
|
|
|
void DrawBackground(nsPresContext* aPresContext,
|
|
|
|
nsRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDest,
|
|
|
|
const nsRect& aFill,
|
|
|
|
const nsPoint& aAnchor,
|
|
|
|
const nsRect& aDirty);
|
2012-05-03 20:11:57 +00:00
|
|
|
|
|
|
|
bool IsRasterImage();
|
2013-05-30 13:50:50 +00:00
|
|
|
bool IsAnimatedImage();
|
2012-11-28 02:34:45 +00:00
|
|
|
already_AddRefed<ImageContainer> GetContainer(LayerManager* aManager);
|
|
|
|
|
2013-07-19 08:40:02 +00:00
|
|
|
bool IsReady() { return mIsReady; }
|
|
|
|
|
2012-05-03 20:11:57 +00:00
|
|
|
private:
|
|
|
|
nsIFrame* mForFrame;
|
|
|
|
const nsStyleImage* mImage;
|
|
|
|
nsStyleImageType mType;
|
|
|
|
nsCOMPtr<imgIContainer> mImageContainer;
|
|
|
|
nsRefPtr<nsStyleGradient> mGradientData;
|
|
|
|
nsIFrame* mPaintServerFrame;
|
|
|
|
nsLayoutUtils::SurfaceFromElementResult mImageElementSurface;
|
|
|
|
bool mIsReady;
|
|
|
|
nsSize mSize; // unscaled size of the image, in app units
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mFlags;
|
2012-05-03 20:11:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A struct representing all the information needed to paint a background
|
|
|
|
* image to some target, taking into account all CSS background-* properties.
|
|
|
|
* See PrepareBackgroundLayer.
|
|
|
|
*/
|
|
|
|
struct nsBackgroundLayerState {
|
|
|
|
/**
|
|
|
|
* @param aFlags some combination of nsCSSRendering::PAINTBG_* flags
|
|
|
|
*/
|
2012-08-22 15:56:38 +00:00
|
|
|
nsBackgroundLayerState(nsIFrame* aForFrame, const nsStyleImage* aImage, uint32_t aFlags)
|
2013-11-08 15:08:03 +00:00
|
|
|
: mImageRenderer(aForFrame, aImage, aFlags), mCompositingOp(gfxContext::OPERATOR_OVER) {}
|
2012-05-03 20:11:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The nsImageRenderer that will be used to draw the background.
|
|
|
|
*/
|
|
|
|
nsImageRenderer mImageRenderer;
|
|
|
|
/**
|
|
|
|
* A rectangle that one copy of the image tile is mapped onto. Same
|
|
|
|
* coordinate system as aBorderArea/aBGClipRect passed into
|
|
|
|
* PrepareBackgroundLayer.
|
|
|
|
*/
|
|
|
|
nsRect mDestArea;
|
|
|
|
/**
|
|
|
|
* The actual rectangle that should be filled with (complete or partial)
|
|
|
|
* image tiles. Same coordinate system as aBorderArea/aBGClipRect passed into
|
|
|
|
* PrepareBackgroundLayer.
|
|
|
|
*/
|
|
|
|
nsRect mFillArea;
|
|
|
|
/**
|
|
|
|
* The anchor point that should be snapped to a pixel corner. Same
|
|
|
|
* coordinate system as aBorderArea/aBGClipRect passed into
|
|
|
|
* PrepareBackgroundLayer.
|
|
|
|
*/
|
|
|
|
nsPoint mAnchor;
|
2013-11-08 15:08:03 +00:00
|
|
|
/**
|
|
|
|
* The compositing operation that the image should use
|
|
|
|
*/
|
|
|
|
gfxContext::GraphicsOperator mCompositingOp;
|
2012-05-03 20:11:57 +00:00
|
|
|
};
|
|
|
|
|
2008-09-25 16:03:15 +00:00
|
|
|
struct nsCSSRendering {
|
2007-03-14 19:48:51 +00:00
|
|
|
/**
|
|
|
|
* Initialize any static variables used by nsCSSRendering.
|
|
|
|
*/
|
2011-06-02 12:56:46 +00:00
|
|
|
static void Init();
|
2007-03-14 19:48:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clean up any static variables used by nsCSSRendering.
|
|
|
|
*/
|
|
|
|
static void Shutdown();
|
|
|
|
|
2009-02-10 08:45:13 +00:00
|
|
|
static void PaintBoxShadowInner(nsPresContext* aPresContext,
|
2011-04-08 01:04:40 +00:00
|
|
|
nsRenderingContext& aRenderingContext,
|
2009-02-10 08:45:13 +00:00
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsRect& aFrameArea,
|
|
|
|
const nsRect& aDirtyRect);
|
|
|
|
|
|
|
|
static void PaintBoxShadowOuter(nsPresContext* aPresContext,
|
2011-04-08 01:04:40 +00:00
|
|
|
nsRenderingContext& aRenderingContext,
|
2009-02-10 08:45:13 +00:00
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsRect& aFrameArea,
|
2013-11-18 09:32:09 +00:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
float aOpacity = 1.0);
|
2008-07-08 00:57:47 +00:00
|
|
|
|
2010-09-07 22:20:35 +00:00
|
|
|
static void ComputePixelRadii(const nscoord *aAppUnitsRadii,
|
|
|
|
nscoord aAppUnitsPerPixel,
|
|
|
|
gfxCornerSizes *oBorderRadii);
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
/**
|
|
|
|
* Render the border for an element using css rendering rules
|
|
|
|
* for borders. aSkipSides is a bitmask of the sides to skip
|
|
|
|
* when rendering. If 0 then no sides are skipped.
|
|
|
|
*/
|
2004-07-31 23:15:21 +00:00
|
|
|
static void PaintBorder(nsPresContext* aPresContext,
|
2011-04-08 01:04:40 +00:00
|
|
|
nsRenderingContext& aRenderingContext,
|
1998-04-13 20:24:54 +00:00
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsRect& aDirtyRect,
|
1999-01-15 18:25:58 +00:00
|
|
|
const nsRect& aBorderArea,
|
2003-02-22 00:32:13 +00:00
|
|
|
nsStyleContext* aStyleContext,
|
2012-08-09 07:09:40 +00:00
|
|
|
int aSkipSides = 0);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2010-04-03 01:58:26 +00:00
|
|
|
/**
|
|
|
|
* Like PaintBorder, but taking an nsStyleBorder argument instead of
|
|
|
|
* getting it from aStyleContext.
|
|
|
|
*/
|
|
|
|
static void PaintBorderWithStyleBorder(nsPresContext* aPresContext,
|
2011-04-08 01:04:40 +00:00
|
|
|
nsRenderingContext& aRenderingContext,
|
2010-04-03 01:58:26 +00:00
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsRect& aBorderArea,
|
|
|
|
const nsStyleBorder& aBorderStyle,
|
|
|
|
nsStyleContext* aStyleContext,
|
2012-08-09 07:09:40 +00:00
|
|
|
int aSkipSides = 0);
|
2010-04-03 01:58:26 +00:00
|
|
|
|
|
|
|
|
1999-08-19 14:22:47 +00:00
|
|
|
/**
|
|
|
|
* Render the outline for an element using css rendering rules
|
|
|
|
* for borders. aSkipSides is a bitmask of the sides to skip
|
|
|
|
* when rendering. If 0 then no sides are skipped.
|
|
|
|
*/
|
2004-07-31 23:15:21 +00:00
|
|
|
static void PaintOutline(nsPresContext* aPresContext,
|
2011-04-08 01:04:40 +00:00
|
|
|
nsRenderingContext& aRenderingContext,
|
1999-08-19 14:22:47 +00:00
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsRect& aBorderArea,
|
2008-08-06 10:33:18 +00:00
|
|
|
nsStyleContext* aStyleContext);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render keyboard focus on an element.
|
|
|
|
* |aFocusRect| is the outer rectangle of the focused element.
|
|
|
|
* Uses a fixed style equivalent to "1px dotted |aColor|".
|
|
|
|
* Not used for controls, because the native theme may differ.
|
|
|
|
*/
|
|
|
|
static void PaintFocus(nsPresContext* aPresContext,
|
2011-04-08 01:04:40 +00:00
|
|
|
nsRenderingContext& aRenderingContext,
|
2008-08-06 10:33:18 +00:00
|
|
|
const nsRect& aFocusRect,
|
|
|
|
nscolor aColor);
|
1999-08-19 14:22:47 +00:00
|
|
|
|
2009-08-01 15:53:40 +00:00
|
|
|
/**
|
|
|
|
* Render a gradient for an element.
|
|
|
|
*/
|
|
|
|
static void PaintGradient(nsPresContext* aPresContext,
|
2011-04-08 01:04:40 +00:00
|
|
|
nsRenderingContext& aRenderingContext,
|
2009-08-01 15:53:40 +00:00
|
|
|
nsStyleGradient* aGradient,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsRect& aOneCellArea,
|
2009-11-02 19:36:43 +00:00
|
|
|
const nsRect& aFillArea);
|
2009-08-01 15:53:40 +00:00
|
|
|
|
2009-04-10 13:41:59 +00:00
|
|
|
/**
|
2009-12-01 17:21:00 +00:00
|
|
|
* Find the frame whose background style should be used to draw the
|
|
|
|
* canvas background. aForFrame must be the frame for the root element
|
|
|
|
* whose background style should be used. This function will return
|
|
|
|
* aForFrame unless the <body> background should be propagated, in
|
|
|
|
* which case we return the frame associated with the <body>'s background.
|
2009-04-10 13:41:59 +00:00
|
|
|
*/
|
2009-12-01 17:21:00 +00:00
|
|
|
static nsIFrame* FindBackgroundStyleFrame(nsIFrame* aForFrame);
|
2009-04-10 13:41:59 +00:00
|
|
|
|
2009-04-06 21:00:29 +00:00
|
|
|
/**
|
2011-10-17 14:59:28 +00:00
|
|
|
* @return true if |aFrame| is a canvas frame, in the CSS sense.
|
2009-02-16 01:11:34 +00:00
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool IsCanvasFrame(nsIFrame* aFrame);
|
2009-02-16 01:11:34 +00:00
|
|
|
|
|
|
|
/**
|
2010-04-03 01:58:26 +00:00
|
|
|
* Fill in an aBackgroundSC to be used to paint the background
|
2009-02-16 01:11:34 +00:00
|
|
|
* for an element. This applies the rules for propagating
|
2002-01-07 23:46:07 +00:00
|
|
|
* backgrounds between BODY, the root element, and the canvas.
|
2011-10-17 14:59:28 +00:00
|
|
|
* @return true if there is some meaningful background.
|
2002-01-07 23:46:07 +00:00
|
|
|
*/
|
2013-03-07 16:03:49 +00:00
|
|
|
static bool FindBackground(nsIFrame* aForFrame,
|
|
|
|
nsStyleContext** aBackgroundSC);
|
2009-02-16 01:11:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* As FindBackground, but the passed-in frame is known to be a root frame
|
|
|
|
* (returned from nsCSSFrameConstructor::GetRootElementStyleFrame())
|
|
|
|
* and there is always some meaningful background returned.
|
|
|
|
*/
|
2010-04-03 01:58:26 +00:00
|
|
|
static nsStyleContext* FindRootFrameBackground(nsIFrame* aForFrame);
|
2009-02-16 01:11:34 +00:00
|
|
|
|
2009-10-22 23:46:08 +00:00
|
|
|
/**
|
|
|
|
* Returns background style information for the canvas.
|
|
|
|
*
|
|
|
|
* @param aForFrame
|
|
|
|
* the frame used to represent the canvas, in the CSS sense (i.e.
|
|
|
|
* nsCSSRendering::IsCanvasFrame(aForFrame) must be true)
|
|
|
|
* @param aRootElementFrame
|
|
|
|
* the frame representing the root element of the document
|
|
|
|
* @param aBackground
|
|
|
|
* contains background style information for the canvas on return
|
|
|
|
*/
|
2010-04-03 01:58:26 +00:00
|
|
|
static nsStyleContext*
|
2009-10-22 23:46:08 +00:00
|
|
|
FindCanvasBackground(nsIFrame* aForFrame, nsIFrame* aRootElementFrame)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(IsCanvasFrame(aForFrame), "not a canvas frame");
|
|
|
|
if (aRootElementFrame)
|
|
|
|
return FindRootFrameBackground(aRootElementFrame);
|
|
|
|
|
|
|
|
// This should always give transparent, so we'll fill it in with the
|
|
|
|
// default color if needed. This seems to happen a bit while a page is
|
|
|
|
// being loaded.
|
2013-02-16 05:38:33 +00:00
|
|
|
return aForFrame->StyleContext();
|
2009-10-22 23:46:08 +00:00
|
|
|
}
|
|
|
|
|
2002-08-11 17:56:15 +00:00
|
|
|
/**
|
2010-04-08 12:44:57 +00:00
|
|
|
* Find a frame which draws a non-transparent background,
|
2009-01-09 00:29:38 +00:00
|
|
|
* for various table-related and HR-related backwards-compatibility hacks.
|
2010-04-08 12:44:57 +00:00
|
|
|
* This function will also stop if it finds themed frame which might draw
|
|
|
|
* background.
|
2009-01-09 00:29:38 +00:00
|
|
|
*
|
|
|
|
* Be very hesitant if you're considering calling this function -- it's
|
|
|
|
* usually not what you want.
|
2002-08-11 17:56:15 +00:00
|
|
|
*/
|
2010-04-08 12:44:57 +00:00
|
|
|
static nsIFrame*
|
|
|
|
FindNonTransparentBackgroundFrame(nsIFrame* aFrame,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aStartAtParent = false);
|
2002-08-11 17:56:15 +00:00
|
|
|
|
2009-07-04 09:30:59 +00:00
|
|
|
/**
|
|
|
|
* Determine the background color to draw taking into account print settings.
|
|
|
|
*/
|
|
|
|
static nscolor
|
|
|
|
DetermineBackgroundColor(nsPresContext* aPresContext,
|
2010-04-03 01:58:26 +00:00
|
|
|
nsStyleContext* aStyleContext,
|
2012-05-03 20:11:57 +00:00
|
|
|
nsIFrame* aFrame,
|
|
|
|
bool& aDrawBackgroundImage,
|
|
|
|
bool& aDrawBackgroundColor);
|
|
|
|
|
2012-11-08 15:05:32 +00:00
|
|
|
static nsRect
|
|
|
|
ComputeBackgroundPositioningArea(nsPresContext* aPresContext,
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsRect& aBorderArea,
|
|
|
|
const nsStyleBackground& aBackground,
|
|
|
|
const nsStyleBackground::Layer& aLayer,
|
|
|
|
nsIFrame** aAttachedToFrame);
|
|
|
|
|
2012-05-03 20:11:57 +00:00
|
|
|
static nsBackgroundLayerState
|
|
|
|
PrepareBackgroundLayer(nsPresContext* aPresContext,
|
|
|
|
nsIFrame* aForFrame,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aFlags,
|
2012-05-03 20:11:57 +00:00
|
|
|
const nsRect& aBorderArea,
|
|
|
|
const nsRect& aBGClipRect,
|
|
|
|
const nsStyleBackground& aBackground,
|
|
|
|
const nsStyleBackground::Layer& aLayer);
|
2009-07-04 09:30:59 +00:00
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
/**
|
|
|
|
* Render the background for an element using css rendering rules
|
|
|
|
* for backgrounds.
|
|
|
|
*/
|
2009-05-28 05:01:42 +00:00
|
|
|
enum {
|
|
|
|
/**
|
|
|
|
* When this flag is passed, the element's nsDisplayBorder will be
|
|
|
|
* painted immediately on top of this background.
|
|
|
|
*/
|
2009-09-12 22:44:18 +00:00
|
|
|
PAINTBG_WILL_PAINT_BORDER = 0x01,
|
|
|
|
/**
|
2010-10-25 14:38:09 +00:00
|
|
|
* When this flag is passed, images are synchronously decoded.
|
|
|
|
*/
|
|
|
|
PAINTBG_SYNC_DECODE_IMAGES = 0x02,
|
|
|
|
/**
|
|
|
|
* When this flag is passed, painting will go to the screen so we can
|
|
|
|
* take advantage of the fact that it will be clipped to the viewport.
|
|
|
|
*/
|
|
|
|
PAINTBG_TO_WINDOW = 0x04
|
2009-05-28 05:01:42 +00:00
|
|
|
};
|
2004-07-31 23:15:21 +00:00
|
|
|
static void PaintBackground(nsPresContext* aPresContext,
|
2011-04-08 01:04:40 +00:00
|
|
|
nsRenderingContext& aRenderingContext,
|
1998-04-13 20:24:54 +00:00
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsRect& aDirtyRect,
|
1999-01-15 18:25:58 +00:00
|
|
|
const nsRect& aBorderArea,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aFlags,
|
2012-09-13 10:34:23 +00:00
|
|
|
nsRect* aBGClipRect = nullptr,
|
|
|
|
int32_t aLayer = -1);
|
2012-10-25 05:32:25 +00:00
|
|
|
|
|
|
|
static void PaintBackgroundColor(nsPresContext* aPresContext,
|
|
|
|
nsRenderingContext& aRenderingContext,
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsRect& aBorderArea,
|
|
|
|
uint32_t aFlags);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2002-01-07 23:46:07 +00:00
|
|
|
/**
|
2008-09-24 04:07:22 +00:00
|
|
|
* Same as |PaintBackground|, except using the provided style structs.
|
|
|
|
* This short-circuits the code that ensures that the root element's
|
2002-01-07 23:46:07 +00:00
|
|
|
* background is drawn on the canvas.
|
2012-09-13 10:34:23 +00:00
|
|
|
* The aLayer parameter allows you to paint a single layer of the background.
|
|
|
|
* The default value for aLayer, -1, means that all layers will be painted.
|
|
|
|
* The background color will only be painted if the back-most layer is also
|
|
|
|
* being painted.
|
2002-01-07 23:46:07 +00:00
|
|
|
*/
|
2004-07-31 23:15:21 +00:00
|
|
|
static void PaintBackgroundWithSC(nsPresContext* aPresContext,
|
2011-04-08 01:04:40 +00:00
|
|
|
nsRenderingContext& aRenderingContext,
|
2002-01-07 23:46:07 +00:00
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsRect& aBorderArea,
|
2010-04-03 01:58:26 +00:00
|
|
|
nsStyleContext *aStyleContext,
|
2002-01-07 23:46:07 +00:00
|
|
|
const nsStyleBorder& aBorder,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aFlags,
|
2012-09-13 10:34:23 +00:00
|
|
|
nsRect* aBGClipRect = nullptr,
|
|
|
|
int32_t aLayer = -1);
|
2004-03-09 06:48:35 +00:00
|
|
|
|
2012-10-25 05:32:25 +00:00
|
|
|
static void PaintBackgroundColorWithSC(nsPresContext* aPresContext,
|
|
|
|
nsRenderingContext& aRenderingContext,
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsRect& aBorderArea,
|
|
|
|
nsStyleContext *aStyleContext,
|
|
|
|
const nsStyleBorder& aBorder,
|
|
|
|
uint32_t aFlags);
|
2011-01-03 01:48:09 +00:00
|
|
|
/**
|
|
|
|
* Returns the rectangle covered by the given background layer image, taking
|
|
|
|
* into account background positioning, sizing, and repetition, but not
|
|
|
|
* clipping.
|
|
|
|
*/
|
|
|
|
static nsRect GetBackgroundLayerRect(nsPresContext* aPresContext,
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsRect& aBorderArea,
|
2013-02-04 12:11:49 +00:00
|
|
|
const nsRect& aClipRect,
|
2011-01-03 01:48:09 +00:00
|
|
|
const nsStyleBackground& aBackground,
|
2013-06-04 04:49:03 +00:00
|
|
|
const nsStyleBackground::Layer& aLayer,
|
|
|
|
uint32_t aFlags);
|
2011-01-03 01:48:09 +00:00
|
|
|
|
2013-06-26 16:43:27 +00:00
|
|
|
/**
|
|
|
|
* Checks if image in layer aLayer of aBackground is currently decoded.
|
|
|
|
*/
|
|
|
|
static bool IsBackgroundImageDecodedForStyleContextAndLayer(
|
|
|
|
const nsStyleBackground *aBackground, uint32_t aLayer);
|
|
|
|
|
2013-06-26 16:43:26 +00:00
|
|
|
/**
|
|
|
|
* Checks if all images that are part of the background for aFrame are
|
|
|
|
* currently decoded.
|
|
|
|
*/
|
|
|
|
static bool AreAllBackgroundImagesDecodedForFrame(nsIFrame* aFrame);
|
|
|
|
|
2003-01-17 09:33:52 +00:00
|
|
|
/**
|
2012-11-19 10:54:41 +00:00
|
|
|
* Called when we start creating a display list. The frame tree will not
|
|
|
|
* change until a matching EndFrameTreeLocked is called.
|
2003-01-17 09:33:52 +00:00
|
|
|
*/
|
2012-11-19 10:54:41 +00:00
|
|
|
static void BeginFrameTreesLocked();
|
|
|
|
/**
|
|
|
|
* Called when we've finished using a display list. When all
|
|
|
|
* BeginFrameTreeLocked calls have been balanced by an EndFrameTreeLocked,
|
|
|
|
* the frame tree may start changing again.
|
|
|
|
*/
|
|
|
|
static void EndFrameTreesLocked();
|
2003-01-17 09:33:52 +00:00
|
|
|
|
2008-09-25 16:03:15 +00:00
|
|
|
// Draw a border segment in the table collapsing border model without
|
|
|
|
// beveling corners
|
2011-04-08 01:04:40 +00:00
|
|
|
static void DrawTableBorderSegment(nsRenderingContext& aContext,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint8_t aBorderStyle,
|
2008-09-25 16:03:15 +00:00
|
|
|
nscolor aBorderColor,
|
2002-02-19 15:48:28 +00:00
|
|
|
const nsStyleBackground* aBGColor,
|
2008-09-25 16:03:15 +00:00
|
|
|
const nsRect& aBorderRect,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aAppUnitsPerCSSPixel,
|
|
|
|
uint8_t aStartBevelSide = 0,
|
2008-09-25 16:03:15 +00:00
|
|
|
nscoord aStartBevelOffset = 0,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint8_t aEndBevelSide = 0,
|
2008-09-25 16:03:15 +00:00
|
|
|
nscoord aEndBevelOffset = 0);
|
2001-05-10 14:19:58 +00:00
|
|
|
|
2007-08-06 08:15:00 +00:00
|
|
|
/**
|
|
|
|
* Function for painting the decoration lines for the text.
|
2008-02-16 15:31:27 +00:00
|
|
|
* NOTE: aPt, aLineSize, aAscent and aOffset are non-rounded device pixels,
|
|
|
|
* not app units.
|
2007-08-06 08:15:00 +00:00
|
|
|
* input:
|
2012-07-04 05:59:50 +00:00
|
|
|
* @param aFrame the frame which needs the decoration line
|
2007-08-06 08:15:00 +00:00
|
|
|
* @param aGfxContext
|
2011-09-16 19:23:29 +00:00
|
|
|
* @param aDirtyRect no need to paint outside this rect
|
2007-08-06 08:15:00 +00:00
|
|
|
* @param aColor the color of the decoration line
|
|
|
|
* @param aPt the top/left edge of the text
|
2012-07-04 05:59:50 +00:00
|
|
|
* @param aXInFrame the distance between aPt.x and left edge of
|
|
|
|
* aFrame. If the decoration line is for shadow,
|
|
|
|
* set the distance between the left edge of
|
|
|
|
* the aFrame and the position of the text as
|
|
|
|
* positioned without offset of the shadow.
|
2007-08-06 08:15:00 +00:00
|
|
|
* @param aLineSize the width and the height of the decoration
|
|
|
|
* line
|
|
|
|
* @param aAscent the ascent of the text
|
|
|
|
* @param aOffset the offset of the decoration line from
|
|
|
|
* the baseline of the text (if the value is
|
|
|
|
* positive, the line is lifted up)
|
|
|
|
* @param aDecoration which line will be painted. The value can be
|
2011-04-23 05:16:41 +00:00
|
|
|
* NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE or
|
|
|
|
* NS_STYLE_TEXT_DECORATION_LINE_OVERLINE or
|
|
|
|
* NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH.
|
2011-03-31 12:26:49 +00:00
|
|
|
* @param aStyle the style of the decoration line such as
|
|
|
|
* NS_STYLE_TEXT_DECORATION_STYLE_*.
|
2009-04-06 05:53:00 +00:00
|
|
|
* @param aDescentLimit If aDescentLimit is zero or larger and the
|
|
|
|
* underline overflows from the descent space,
|
|
|
|
* the underline should be lifted up as far as
|
|
|
|
* possible. Note that this does not mean the
|
|
|
|
* underline never overflows from this
|
|
|
|
* limitation. Because if the underline is
|
|
|
|
* positioned to the baseline or upper, it causes
|
|
|
|
* unreadability. Note that if this is zero
|
|
|
|
* or larger, the underline rect may be shrunken
|
|
|
|
* if it's possible. Therefore, this value is
|
|
|
|
* used for strikeout line and overline too.
|
2007-08-06 08:15:00 +00:00
|
|
|
*/
|
2012-07-04 05:59:50 +00:00
|
|
|
static void PaintDecorationLine(nsIFrame* aFrame,
|
|
|
|
gfxContext* aGfxContext,
|
2011-09-16 19:23:29 +00:00
|
|
|
const gfxRect& aDirtyRect,
|
2007-08-06 08:15:00 +00:00
|
|
|
const nscolor aColor,
|
|
|
|
const gfxPoint& aPt,
|
2012-07-04 05:59:50 +00:00
|
|
|
const gfxFloat aXInFrame,
|
2007-08-06 08:15:00 +00:00
|
|
|
const gfxSize& aLineSize,
|
|
|
|
const gfxFloat aAscent,
|
|
|
|
const gfxFloat aOffset,
|
2012-08-22 15:56:38 +00:00
|
|
|
const uint8_t aDecoration,
|
|
|
|
const uint8_t aStyle,
|
2009-04-06 05:53:00 +00:00
|
|
|
const gfxFloat aDescentLimit = -1.0);
|
2007-08-06 08:15:00 +00:00
|
|
|
|
2012-08-08 11:37:11 +00:00
|
|
|
/**
|
|
|
|
* Adds a path corresponding to the outline of the decoration line to
|
|
|
|
* the specified context. Arguments have the same meaning as for
|
|
|
|
* PaintDecorationLine. Currently this only works for solid
|
|
|
|
* decorations; for other decoration styles, an empty path is added
|
|
|
|
* to the context.
|
|
|
|
*/
|
|
|
|
static void 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 15:56:38 +00:00
|
|
|
const uint8_t aDecoration,
|
|
|
|
const uint8_t aStyle,
|
2012-08-08 11:37:11 +00:00
|
|
|
const gfxFloat aDescentLimit = -1.0);
|
|
|
|
|
2008-02-16 15:31:27 +00:00
|
|
|
/**
|
|
|
|
* Function for getting the decoration line rect for the text.
|
|
|
|
* NOTE: aLineSize, aAscent and aOffset are non-rounded device pixels,
|
|
|
|
* not app units.
|
|
|
|
* input:
|
|
|
|
* @param aPresContext
|
|
|
|
* @param aLineSize the width and the height of the decoration
|
|
|
|
* line
|
|
|
|
* @param aAscent the ascent of the text
|
|
|
|
* @param aOffset the offset of the decoration line from
|
|
|
|
* the baseline of the text (if the value is
|
|
|
|
* positive, the line is lifted up)
|
|
|
|
* @param aDecoration which line will be painted. The value can be
|
2011-04-23 05:16:41 +00:00
|
|
|
* NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE or
|
|
|
|
* NS_STYLE_TEXT_DECORATION_LINE_OVERLINE or
|
|
|
|
* NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH.
|
2011-03-31 12:26:49 +00:00
|
|
|
* @param aStyle the style of the decoration line such as
|
|
|
|
* NS_STYLE_TEXT_DECORATION_STYLE_*.
|
2009-04-06 05:53:00 +00:00
|
|
|
* @param aDescentLimit If aDescentLimit is zero or larger and the
|
|
|
|
* underline overflows from the descent space,
|
|
|
|
* the underline should be lifted up as far as
|
|
|
|
* possible. Note that this does not mean the
|
|
|
|
* underline never overflows from this
|
|
|
|
* limitation. Because if the underline is
|
|
|
|
* positioned to the baseline or upper, it causes
|
|
|
|
* unreadability. Note that if this is zero
|
|
|
|
* or larger, the underline rect may be shrunken
|
|
|
|
* if it's possible. Therefore, this value is
|
|
|
|
* used for strikeout line and overline too.
|
2008-02-16 15:31:27 +00:00
|
|
|
* output:
|
|
|
|
* @return the decoration line rect for the input,
|
|
|
|
* the each values are app units.
|
|
|
|
*/
|
|
|
|
static nsRect GetTextDecorationRect(nsPresContext* aPresContext,
|
|
|
|
const gfxSize& aLineSize,
|
|
|
|
const gfxFloat aAscent,
|
|
|
|
const gfxFloat aOffset,
|
2012-08-22 15:56:38 +00:00
|
|
|
const uint8_t aDecoration,
|
|
|
|
const uint8_t aStyle,
|
2009-04-06 05:53:00 +00:00
|
|
|
const gfxFloat aDescentLimit = -1.0);
|
2009-04-03 07:26:28 +00:00
|
|
|
|
2013-11-15 02:43:56 +00:00
|
|
|
static gfxContext::GraphicsOperator GetGFXBlendMode(uint8_t mBlendMode) {
|
|
|
|
switch (mBlendMode) {
|
|
|
|
case NS_STYLE_BLEND_NORMAL: return gfxContext::OPERATOR_OVER;
|
|
|
|
case NS_STYLE_BLEND_MULTIPLY: return gfxContext::OPERATOR_MULTIPLY;
|
|
|
|
case NS_STYLE_BLEND_SCREEN: return gfxContext::OPERATOR_SCREEN;
|
|
|
|
case NS_STYLE_BLEND_OVERLAY: return gfxContext::OPERATOR_OVERLAY;
|
|
|
|
case NS_STYLE_BLEND_DARKEN: return gfxContext::OPERATOR_DARKEN;
|
|
|
|
case NS_STYLE_BLEND_LIGHTEN: return gfxContext::OPERATOR_LIGHTEN;
|
|
|
|
case NS_STYLE_BLEND_COLOR_DODGE: return gfxContext::OPERATOR_COLOR_DODGE;
|
|
|
|
case NS_STYLE_BLEND_COLOR_BURN: return gfxContext::OPERATOR_COLOR_BURN;
|
|
|
|
case NS_STYLE_BLEND_HARD_LIGHT: return gfxContext::OPERATOR_HARD_LIGHT;
|
|
|
|
case NS_STYLE_BLEND_SOFT_LIGHT: return gfxContext::OPERATOR_SOFT_LIGHT;
|
|
|
|
case NS_STYLE_BLEND_DIFFERENCE: return gfxContext::OPERATOR_DIFFERENCE;
|
|
|
|
case NS_STYLE_BLEND_EXCLUSION: return gfxContext::OPERATOR_EXCLUSION;
|
|
|
|
case NS_STYLE_BLEND_HUE: return gfxContext::OPERATOR_HUE;
|
|
|
|
case NS_STYLE_BLEND_SATURATION: return gfxContext::OPERATOR_SATURATION;
|
|
|
|
case NS_STYLE_BLEND_COLOR: return gfxContext::OPERATOR_COLOR;
|
|
|
|
case NS_STYLE_BLEND_LUMINOSITY: return gfxContext::OPERATOR_LUMINOSITY;
|
|
|
|
default: MOZ_ASSERT(false); return gfxContext::OPERATOR_OVER;
|
|
|
|
}
|
|
|
|
|
|
|
|
return gfxContext::OPERATOR_OVER;
|
|
|
|
}
|
|
|
|
|
2009-04-03 07:26:28 +00:00
|
|
|
protected:
|
|
|
|
static gfxRect GetTextDecorationRectInternal(const gfxPoint& aPt,
|
|
|
|
const gfxSize& aLineSize,
|
|
|
|
const gfxFloat aAscent,
|
|
|
|
const gfxFloat aOffset,
|
2012-08-22 15:56:38 +00:00
|
|
|
const uint8_t aDecoration,
|
|
|
|
const uint8_t aStyle,
|
2009-04-06 05:53:00 +00:00
|
|
|
const gfxFloat aDscentLimit);
|
2012-07-04 05:59:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns inflated rect for painting a decoration line.
|
|
|
|
* Complex style decoration lines should be painted from leftmost of nearest
|
|
|
|
* ancestor block box because that makes better look of connection of lines
|
|
|
|
* for different nodes. ExpandPaintingRectForDecorationLine() returns
|
|
|
|
* a rect for actual painting rect for the clipped rect.
|
|
|
|
*
|
|
|
|
* input:
|
|
|
|
* @param aFrame the frame which needs the decoration line.
|
|
|
|
* @param aStyle the style of the complex decoration line
|
|
|
|
* NS_STYLE_TEXT_DECORATION_STYLE_DOTTED or
|
|
|
|
* NS_STYLE_TEXT_DECORATION_STYLE_DASHED or
|
|
|
|
* NS_STYLE_TEXT_DECORATION_STYLE_WAVY.
|
|
|
|
* @param aClippedRect the clipped rect for the decoration line.
|
|
|
|
* in other words, visible area of the line.
|
|
|
|
* @param aXInFrame the distance between left edge of aFrame and
|
|
|
|
* aClippedRect.pos.x.
|
|
|
|
* @param aCycleLength the width of one cycle of the line style.
|
|
|
|
*/
|
|
|
|
static gfxRect ExpandPaintingRectForDecorationLine(
|
|
|
|
nsIFrame* aFrame,
|
2012-08-22 15:56:38 +00:00
|
|
|
const uint8_t aStyle,
|
2012-07-04 05:59:50 +00:00
|
|
|
const gfxRect &aClippedRect,
|
|
|
|
const gfxFloat aXInFrame,
|
|
|
|
const gfxFloat aCycleLength);
|
1998-04-13 20:24:54 +00:00
|
|
|
};
|
|
|
|
|
2008-06-12 22:02:32 +00:00
|
|
|
/*
|
|
|
|
* nsContextBoxBlur
|
|
|
|
* Creates an 8-bit alpha channel context for callers to draw in, blurs the
|
|
|
|
* contents of that context and applies it as a 1-color mask on a
|
2008-09-25 19:53:09 +00:00
|
|
|
* different existing context. Uses gfxAlphaBoxBlur as its back end.
|
2008-06-12 22:02:32 +00:00
|
|
|
*
|
2008-09-25 16:03:15 +00:00
|
|
|
* You must call Init() first to create a suitable temporary surface to draw
|
|
|
|
* on. You must then draw any desired content onto the given context, then
|
|
|
|
* call DoPaint() to apply the blurred content as a single-color mask. You
|
|
|
|
* can only call Init() once, so objects cannot be reused.
|
2008-06-12 22:02:32 +00:00
|
|
|
*
|
|
|
|
* This is very useful for creating drop shadows or silhouettes.
|
|
|
|
*/
|
|
|
|
class nsContextBoxBlur {
|
|
|
|
public:
|
2010-08-23 09:30:07 +00:00
|
|
|
enum {
|
|
|
|
FORCE_MASK = 0x01
|
|
|
|
};
|
2008-06-12 22:02:32 +00:00
|
|
|
/**
|
2008-09-25 16:03:15 +00:00
|
|
|
* Prepares a gfxContext to draw on. Do not call this twice; if you want
|
|
|
|
* to get the gfxContext again use GetContext().
|
2008-06-12 22:02:32 +00:00
|
|
|
*
|
|
|
|
* @param aRect The coordinates of the surface to create.
|
|
|
|
* All coordinates must be in app units.
|
2008-09-25 16:03:15 +00:00
|
|
|
* This must not include the blur radius, pass
|
|
|
|
* it as the second parameter and everything
|
|
|
|
* is taken care of.
|
2008-06-12 22:02:32 +00:00
|
|
|
*
|
|
|
|
* @param aBlurRadius The blur radius in app units.
|
|
|
|
*
|
2008-09-25 16:03:15 +00:00
|
|
|
* @param aAppUnitsPerDevPixel The number of app units in a device pixel,
|
|
|
|
* for conversion. Most of the time you'll
|
|
|
|
* pass this from the current PresContext if
|
|
|
|
* available.
|
2008-06-12 22:02:32 +00:00
|
|
|
*
|
2008-09-25 16:03:15 +00:00
|
|
|
* @param aDestinationCtx The graphics context to apply the blurred
|
|
|
|
* mask to when you call DoPaint(). Make sure
|
|
|
|
* it is not destroyed before you call
|
|
|
|
* DoPaint(). To set the color of the
|
|
|
|
* resulting blurred graphic mask, you must
|
|
|
|
* set the color on this context before
|
|
|
|
* calling Init().
|
2008-06-12 22:02:32 +00:00
|
|
|
*
|
2008-12-02 21:16:22 +00:00
|
|
|
* @param aDirtyRect The absolute dirty rect in app units. Used to
|
|
|
|
* optimize the temporary surface size and speed up blur.
|
|
|
|
*
|
2010-04-18 03:13:10 +00:00
|
|
|
* @param aSkipRect An area in device pixels (NOT app units!) to avoid
|
|
|
|
* blurring over, to prevent unnecessary work.
|
2010-08-23 09:30:07 +00:00
|
|
|
*
|
|
|
|
* @param aFlags FORCE_MASK to ensure that the content drawn to the
|
|
|
|
* returned gfxContext is used as a mask, and not
|
|
|
|
* drawn directly to aDestinationCtx.
|
2010-04-18 03:13:10 +00:00
|
|
|
*
|
2008-09-25 16:03:15 +00:00
|
|
|
* @return A blank 8-bit alpha-channel-only graphics context to
|
|
|
|
* draw on, or null on error. Must not be freed. The
|
|
|
|
* context has a device offset applied to it given by
|
|
|
|
* aRect. This means you can use coordinates as if it
|
|
|
|
* were at the desired position at aRect and you don't
|
|
|
|
* need to worry about translating any coordinates to
|
|
|
|
* draw on this temporary surface.
|
2008-06-12 22:02:32 +00:00
|
|
|
*
|
2008-09-25 16:03:15 +00:00
|
|
|
* If aBlurRadius is 0, the returned context is aDestinationCtx and
|
|
|
|
* DoPaint() does nothing, because no blurring is required. Therefore, you
|
|
|
|
* should prepare the destination context as if you were going to draw
|
|
|
|
* directly on it instead of any temporary surface created in this class.
|
2008-06-12 22:02:32 +00:00
|
|
|
*/
|
2010-08-23 09:30:07 +00:00
|
|
|
gfxContext* Init(const nsRect& aRect, nscoord aSpreadRadius,
|
|
|
|
nscoord aBlurRadius,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aAppUnitsPerDevPixel, gfxContext* aDestinationCtx,
|
2010-08-23 09:30:07 +00:00
|
|
|
const nsRect& aDirtyRect, const gfxRect* aSkipRect,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aFlags = 0);
|
2008-06-12 22:02:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Does the actual blurring and mask applying. Users of this object *must*
|
|
|
|
* have called Init() first, then have drawn whatever they want to be
|
|
|
|
* blurred onto the internal gfxContext before calling this.
|
|
|
|
*/
|
|
|
|
void DoPaint();
|
|
|
|
|
|
|
|
/**
|
2008-09-25 16:03:15 +00:00
|
|
|
* Gets the internal gfxContext at any time. Must not be freed. Avoid
|
|
|
|
* calling this before calling Init() since the context would not be
|
|
|
|
* constructed at that point.
|
2008-06-12 22:02:32 +00:00
|
|
|
*/
|
|
|
|
gfxContext* GetContext();
|
|
|
|
|
2010-09-11 16:27:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the margin associated with the given blur radius, i.e., the
|
|
|
|
* additional area that might be painted as a result of it. (The
|
|
|
|
* margin for a spread radius is itself, on all sides.)
|
|
|
|
*/
|
|
|
|
static nsMargin GetBlurRadiusMargin(nscoord aBlurRadius,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aAppUnitsPerDevPixel);
|
2010-09-11 16:27:12 +00:00
|
|
|
|
2013-11-25 23:29:20 +00:00
|
|
|
/**
|
|
|
|
* Blurs a coloured rectangle onto aDestinationCtx. This is equivalent
|
|
|
|
* to calling Init(), drawing a rectangle onto the returned surface
|
|
|
|
* and then calling DoPaint, but may let us optimize better in the
|
|
|
|
* backend.
|
|
|
|
*
|
|
|
|
* @param aDestinationCtx The destination to blur to.
|
|
|
|
* @param aRect The rectangle to blur in app units.
|
|
|
|
* @param aAppUnitsPerDevPixel The number of app units in a device pixel,
|
|
|
|
* for conversion. Most of the time you'll
|
|
|
|
* pass this from the current PresContext if
|
|
|
|
* available.
|
|
|
|
* @param aCornerRadii Corner radii for aRect, if it is a rounded
|
|
|
|
* rectangle.
|
|
|
|
* @param aBlurRadius The blur radius in app units.
|
|
|
|
* @param aShadowColor The color to draw the blurred shadow.
|
|
|
|
* @param aDirtyRect The absolute dirty rect in app units. Used to
|
|
|
|
* optimize the temporary surface size and speed up blur.
|
|
|
|
* @param aSkipRect An area in device pixels (NOT app units!) to avoid
|
|
|
|
* blurring over, to prevent unnecessary work.
|
|
|
|
*/
|
2013-11-25 23:06:17 +00:00
|
|
|
static void BlurRectangle(gfxContext* aDestinationCtx,
|
|
|
|
const nsRect& aRect,
|
|
|
|
int32_t aAppUnitsPerDevPixel,
|
|
|
|
gfxCornerSizes* aCornerRadii,
|
|
|
|
nscoord aBlurRadius,
|
|
|
|
const gfxRGBA& aShadowColor,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const gfxRect& aSkipRect);
|
|
|
|
|
2008-06-12 22:02:32 +00:00
|
|
|
protected:
|
2008-09-25 19:53:09 +00:00
|
|
|
gfxAlphaBoxBlur blur;
|
2008-06-12 22:02:32 +00:00
|
|
|
nsRefPtr<gfxContext> mContext;
|
|
|
|
gfxContext* mDestinationCtx;
|
2012-05-16 20:45:25 +00:00
|
|
|
|
|
|
|
/* This is true if the blur already has it's content transformed
|
|
|
|
* by mDestinationCtx's transform */
|
|
|
|
bool mPreTransformed;
|
|
|
|
|
2008-06-12 22:02:32 +00:00
|
|
|
};
|
1999-04-19 05:27:55 +00:00
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
#endif /* nsCSSRendering_h___ */
|