2013-02-28 20:22:43 +00: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-22 20:12:38 +00:00
|
|
|
#include "mozilla/Maybe.h"
|
2013-02-28 20:22:43 +00:00
|
|
|
#include "SVGPreserveAspectRatio.h"
|
2015-04-03 19:48:12 +00:00
|
|
|
#include "Units.h"
|
2013-02-28 20:22:43 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
// SVG image-specific rendering context. For imgIContainer::Draw.
|
2014-08-22 20:12:38 +00: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-25 22:58:27 +00:00
|
|
|
class SVGImageContext
|
2013-02-28 20:22:43 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-08-29 14:04:34 +00:00
|
|
|
SVGImageContext()
|
|
|
|
: mGlobalOpacity(1.0)
|
|
|
|
{ }
|
2013-10-22 11:37:57 +00:00
|
|
|
|
2015-04-03 19:48:12 +00:00
|
|
|
SVGImageContext(CSSIntSize aViewportSize,
|
2014-08-29 14:04:34 +00:00
|
|
|
Maybe<SVGPreserveAspectRatio> aPreserveAspectRatio,
|
|
|
|
gfxFloat aOpacity = 1.0)
|
2014-08-22 20:12:38 +00:00
|
|
|
: mViewportSize(aViewportSize)
|
|
|
|
, mPreserveAspectRatio(aPreserveAspectRatio)
|
2014-08-29 14:04:34 +00:00
|
|
|
, mGlobalOpacity(aOpacity)
|
2013-02-28 20:22:43 +00:00
|
|
|
{ }
|
|
|
|
|
2015-04-03 19:48:12 +00:00
|
|
|
const CSSIntSize& GetViewportSize() const {
|
2014-08-22 20:12:38 +00:00
|
|
|
return mViewportSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Maybe<SVGPreserveAspectRatio>& GetPreserveAspectRatio() const {
|
2013-02-28 20:22:43 +00:00
|
|
|
return mPreserveAspectRatio;
|
|
|
|
}
|
|
|
|
|
2014-08-29 14:04:34 +00:00
|
|
|
gfxFloat GetGlobalOpacity() const {
|
|
|
|
return mGlobalOpacity;
|
|
|
|
}
|
|
|
|
|
2013-04-25 22:58:27 +00:00
|
|
|
bool operator==(const SVGImageContext& aOther) const {
|
2014-08-22 20:12:38 +00:00
|
|
|
return mViewportSize == aOther.mViewportSize &&
|
2014-08-29 14:04:34 +00:00
|
|
|
mPreserveAspectRatio == aOther.mPreserveAspectRatio &&
|
|
|
|
mGlobalOpacity == aOther.mGlobalOpacity;
|
2013-04-25 22:58:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const SVGImageContext& aOther) const {
|
|
|
|
return !(*this == aOther);
|
|
|
|
}
|
|
|
|
|
2013-10-22 11:37:57 +00:00
|
|
|
uint32_t Hash() const {
|
2014-08-22 20:12:38 +00:00
|
|
|
return HashGeneric(mViewportSize.width,
|
|
|
|
mViewportSize.height,
|
2014-08-29 14:04:34 +00:00
|
|
|
mPreserveAspectRatio.map(HashPAR).valueOr(0),
|
|
|
|
HashBytes(&mGlobalOpacity, sizeof(gfxFloat)));
|
2013-10-22 11:37:57 +00:00
|
|
|
}
|
|
|
|
|
2013-02-28 20:22:43 +00:00
|
|
|
private:
|
2014-08-22 20:12:38 +00:00
|
|
|
static uint32_t HashPAR(const SVGPreserveAspectRatio& aPAR) {
|
|
|
|
return aPAR.Hash();
|
|
|
|
}
|
|
|
|
|
2015-04-03 19:48:12 +00:00
|
|
|
CSSIntSize mViewportSize;
|
2014-08-22 20:12:38 +00:00
|
|
|
Maybe<SVGPreserveAspectRatio> mPreserveAspectRatio;
|
2014-08-29 14:04:34 +00:00
|
|
|
gfxFloat mGlobalOpacity;
|
2013-02-28 20:22:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // MOZILLA_SVGCONTEXT_H_
|