2014-08-06 21:48:47 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#ifndef __NS_CSSFILTERINSTANCE_H__
|
|
|
|
#define __NS_CSSFILTERINSTANCE_H__
|
|
|
|
|
|
|
|
#include "FilterSupport.h"
|
|
|
|
#include "gfxMatrix.h"
|
|
|
|
#include "gfxRect.h"
|
2014-08-14 22:29:56 +04:00
|
|
|
#include "mozilla/gfx/Point.h"
|
|
|
|
#include "mozilla/gfx/Types.h"
|
|
|
|
#include "nsColor.h"
|
2014-08-06 21:48:47 +04:00
|
|
|
|
2014-08-14 22:29:56 +04:00
|
|
|
class nsIFrame;
|
2014-08-06 21:48:47 +04:00
|
|
|
struct nsStyleFilter;
|
|
|
|
template<class T> class nsTArray;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class helps nsFilterInstance build its filter graph. It turns a CSS
|
|
|
|
* filter function (e.g. blur(3px)) from the style system into a
|
|
|
|
* FilterPrimitiveDescription connected to the filter graph.
|
|
|
|
*/
|
|
|
|
class nsCSSFilterInstance
|
|
|
|
{
|
2014-08-14 22:29:56 +04:00
|
|
|
typedef mozilla::gfx::Color Color;
|
2014-08-06 21:48:47 +04:00
|
|
|
typedef mozilla::gfx::FilterPrimitiveDescription FilterPrimitiveDescription;
|
2014-08-14 22:29:56 +04:00
|
|
|
typedef mozilla::gfx::IntPoint IntPoint;
|
2014-08-06 21:48:47 +04:00
|
|
|
typedef mozilla::gfx::PrimitiveType PrimitiveType;
|
2014-08-14 22:29:56 +04:00
|
|
|
typedef mozilla::gfx::Size Size;
|
2014-08-06 21:48:47 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @param aFilter The CSS filter from the style system. This class stores
|
|
|
|
* aFilter by reference, so callers should avoid modifying or deleting
|
|
|
|
* aFilter during the lifetime of nsCSSFilterInstance.
|
2014-09-15 14:12:51 +04:00
|
|
|
* @param aShadowFallbackColor The color that should be used for
|
|
|
|
* drop-shadow() filters that don't specify a shadow color.
|
|
|
|
* @param aTargetBBoxInFilterSpace The frame of element being filtered, in
|
2014-08-06 21:48:47 +04:00
|
|
|
* filter space.
|
|
|
|
* @param aFrameSpaceInCSSPxToFilterSpaceTransform The transformation from
|
|
|
|
* the filtered element's frame space in CSS pixels to filter space.
|
|
|
|
*/
|
|
|
|
nsCSSFilterInstance(const nsStyleFilter& aFilter,
|
2014-09-15 14:12:51 +04:00
|
|
|
nscolor aShadowFallbackColor,
|
|
|
|
const nsIntRect& aTargetBBoxInFilterSpace,
|
2014-08-06 21:48:47 +04:00
|
|
|
const gfxMatrix& aFrameSpaceInCSSPxToFilterSpaceTransform);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates at least one new FilterPrimitiveDescription based on the filter
|
|
|
|
* from the style system. Appends the new FilterPrimitiveDescription(s) to the
|
|
|
|
* aPrimitiveDescrs list.
|
|
|
|
*/
|
|
|
|
nsresult BuildPrimitives(nsTArray<FilterPrimitiveDescription>& aPrimitiveDescrs);
|
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Returns a new FilterPrimitiveDescription with its basic properties set up.
|
|
|
|
*/
|
|
|
|
FilterPrimitiveDescription CreatePrimitiveDescription(PrimitiveType aType,
|
|
|
|
const nsTArray<FilterPrimitiveDescription>& aPrimitiveDescrs);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets aDescr's attributes using the style info in mFilter.
|
|
|
|
*/
|
|
|
|
nsresult SetAttributesForBlur(FilterPrimitiveDescription& aDescr);
|
2014-08-25 23:23:20 +04:00
|
|
|
nsresult SetAttributesForBrightness(FilterPrimitiveDescription& aDescr);
|
2014-08-25 23:23:21 +04:00
|
|
|
nsresult SetAttributesForContrast(FilterPrimitiveDescription& aDescr);
|
2014-08-14 22:29:56 +04:00
|
|
|
nsresult SetAttributesForDropShadow(FilterPrimitiveDescription& aDescr);
|
2014-08-21 21:17:09 +04:00
|
|
|
nsresult SetAttributesForGrayscale(FilterPrimitiveDescription& aDescr);
|
2014-08-21 02:46:59 +04:00
|
|
|
nsresult SetAttributesForHueRotate(FilterPrimitiveDescription& aDescr);
|
2014-08-25 23:23:19 +04:00
|
|
|
nsresult SetAttributesForInvert(FilterPrimitiveDescription& aDescr);
|
2014-08-25 23:23:22 +04:00
|
|
|
nsresult SetAttributesForOpacity(FilterPrimitiveDescription& aDescr);
|
2014-08-21 04:52:28 +04:00
|
|
|
nsresult SetAttributesForSaturate(FilterPrimitiveDescription& aDescr);
|
2014-08-21 21:17:12 +04:00
|
|
|
nsresult SetAttributesForSepia(FilterPrimitiveDescription& aDescr);
|
2014-08-06 21:48:47 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the index of the last result in the aPrimitiveDescrs, which we'll
|
|
|
|
* use as the input to this CSS filter.
|
|
|
|
*/
|
|
|
|
int32_t GetLastResultIndex(const nsTArray<FilterPrimitiveDescription>& aPrimitiveDescrs);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets aDescr's filter region and primitive subregion to appropriate values
|
|
|
|
* based on this CSS filter's input and its attributes. For example, a CSS
|
|
|
|
* blur filter will have bounds equal to its input bounds, inflated by the
|
|
|
|
* blur extents.
|
|
|
|
*/
|
|
|
|
void SetBounds(FilterPrimitiveDescription& aDescr,
|
|
|
|
const nsTArray<FilterPrimitiveDescription>& aPrimitiveDescrs);
|
|
|
|
|
2014-08-14 22:29:56 +04:00
|
|
|
/**
|
|
|
|
* Converts an nscolor to a Color, suitable for use as a
|
|
|
|
* FilterPrimitiveDescription attribute.
|
|
|
|
*/
|
|
|
|
Color ToAttributeColor(nscolor aColor);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a blur radius in frame space to filter space.
|
|
|
|
*/
|
|
|
|
Size BlurRadiusToFilterSpace(nscoord aRadiusInFrameSpace);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a point defined by a pair of nscoord x, y coordinates from frame
|
|
|
|
* space to filter space.
|
|
|
|
*/
|
|
|
|
IntPoint OffsetToFilterSpace(nscoord aXOffsetInFrameSpace,
|
|
|
|
nscoord aYOffsetInFrameSpace);
|
|
|
|
|
2014-08-06 21:48:47 +04:00
|
|
|
/**
|
|
|
|
* The CSS filter originally from the style system.
|
|
|
|
*/
|
|
|
|
const nsStyleFilter& mFilter;
|
|
|
|
|
2014-08-14 22:29:56 +04:00
|
|
|
/**
|
2014-09-15 14:12:51 +04:00
|
|
|
* The color that should be used for drop-shadow() filters that don't
|
|
|
|
* specify a shadow color.
|
2014-08-14 22:29:56 +04:00
|
|
|
*/
|
2014-09-15 14:12:51 +04:00
|
|
|
nscolor mShadowFallbackColor;
|
2014-08-14 22:29:56 +04:00
|
|
|
|
2014-08-06 21:48:47 +04:00
|
|
|
/**
|
|
|
|
* The bounding box of the element being filtered, in filter space. Used for
|
|
|
|
* input bounds if this CSS filter is the first in the filter chain.
|
|
|
|
*/
|
|
|
|
nsIntRect mTargetBBoxInFilterSpace;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The transformation from the filtered element's frame space in CSS pixels to
|
|
|
|
* filter space. Used to transform style values to filter space.
|
|
|
|
*/
|
|
|
|
gfxMatrix mFrameSpaceInCSSPxToFilterSpaceTransform;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|