2013-03-01 00:22:43 +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 MOZILLA_SVGCONTEXT_H_
|
|
|
|
#define MOZILLA_SVGCONTEXT_H_
|
|
|
|
|
2014-08-23 00:12:38 +04:00
|
|
|
#include "mozilla/Maybe.h"
|
2013-03-01 00:22:43 +04:00
|
|
|
#include "SVGPreserveAspectRatio.h"
|
2015-04-03 22:48:12 +03:00
|
|
|
#include "Units.h"
|
2013-03-01 00:22:43 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
// SVG image-specific rendering context. For imgIContainer::Draw.
|
2014-08-23 00:12:38 +04:00
|
|
|
// Used to pass information such as
|
|
|
|
// - viewport information from CSS, and
|
|
|
|
// - overridden attributes from an SVG <image> element
|
|
|
|
// to the image's internal SVG document when it's drawn.
|
2013-04-26 02:58:27 +04:00
|
|
|
class SVGImageContext
|
2013-03-01 00:22:43 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-08-29 18:04:34 +04:00
|
|
|
SVGImageContext()
|
|
|
|
: mGlobalOpacity(1.0)
|
|
|
|
{ }
|
2013-10-22 15:37:57 +04:00
|
|
|
|
2016-07-01 01:41:00 +03:00
|
|
|
// Note: 'aIsPaintingSVGImageElement' should be used to indicate whether
|
|
|
|
// the SVG image in question is being painted for an SVG <image> element.
|
2015-04-03 22:48:12 +03:00
|
|
|
SVGImageContext(CSSIntSize aViewportSize,
|
2014-08-29 18:04:34 +04:00
|
|
|
Maybe<SVGPreserveAspectRatio> aPreserveAspectRatio,
|
2016-07-01 01:41:00 +03:00
|
|
|
gfxFloat aOpacity = 1.0,
|
|
|
|
bool aIsPaintingSVGImageElement = false)
|
2014-08-23 00:12:38 +04:00
|
|
|
: mViewportSize(aViewportSize)
|
|
|
|
, mPreserveAspectRatio(aPreserveAspectRatio)
|
2014-08-29 18:04:34 +04:00
|
|
|
, mGlobalOpacity(aOpacity)
|
2016-07-01 01:41:00 +03:00
|
|
|
, mIsPaintingSVGImageElement(aIsPaintingSVGImageElement)
|
2013-03-01 00:22:43 +04:00
|
|
|
{ }
|
|
|
|
|
2015-04-03 22:48:12 +03:00
|
|
|
const CSSIntSize& GetViewportSize() const {
|
2014-08-23 00:12:38 +04:00
|
|
|
return mViewportSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Maybe<SVGPreserveAspectRatio>& GetPreserveAspectRatio() const {
|
2013-03-01 00:22:43 +04:00
|
|
|
return mPreserveAspectRatio;
|
|
|
|
}
|
|
|
|
|
2014-08-29 18:04:34 +04:00
|
|
|
gfxFloat GetGlobalOpacity() const {
|
|
|
|
return mGlobalOpacity;
|
|
|
|
}
|
|
|
|
|
2016-07-01 01:41:00 +03:00
|
|
|
bool IsPaintingForSVGImageElement() const {
|
|
|
|
return mIsPaintingSVGImageElement;
|
|
|
|
}
|
|
|
|
|
2013-04-26 02:58:27 +04:00
|
|
|
bool operator==(const SVGImageContext& aOther) const {
|
2014-08-23 00:12:38 +04:00
|
|
|
return mViewportSize == aOther.mViewportSize &&
|
2014-08-29 18:04:34 +04:00
|
|
|
mPreserveAspectRatio == aOther.mPreserveAspectRatio &&
|
|
|
|
mGlobalOpacity == aOther.mGlobalOpacity;
|
2013-04-26 02:58:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const SVGImageContext& aOther) const {
|
|
|
|
return !(*this == aOther);
|
|
|
|
}
|
|
|
|
|
2013-10-22 15:37:57 +04:00
|
|
|
uint32_t Hash() const {
|
2014-08-23 00:12:38 +04:00
|
|
|
return HashGeneric(mViewportSize.width,
|
|
|
|
mViewportSize.height,
|
2014-08-29 18:04:34 +04:00
|
|
|
mPreserveAspectRatio.map(HashPAR).valueOr(0),
|
|
|
|
HashBytes(&mGlobalOpacity, sizeof(gfxFloat)));
|
2013-10-22 15:37:57 +04:00
|
|
|
}
|
|
|
|
|
2013-03-01 00:22:43 +04:00
|
|
|
private:
|
2014-08-23 00:12:38 +04:00
|
|
|
static uint32_t HashPAR(const SVGPreserveAspectRatio& aPAR) {
|
|
|
|
return aPAR.Hash();
|
|
|
|
}
|
|
|
|
|
2015-04-03 22:48:12 +03:00
|
|
|
CSSIntSize mViewportSize;
|
2014-08-23 00:12:38 +04:00
|
|
|
Maybe<SVGPreserveAspectRatio> mPreserveAspectRatio;
|
2014-08-29 18:04:34 +04:00
|
|
|
gfxFloat mGlobalOpacity;
|
2016-07-01 01:41:00 +03:00
|
|
|
bool mIsPaintingSVGImageElement;
|
2013-03-01 00:22:43 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // MOZILLA_SVGCONTEXT_H_
|