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"
|
2017-01-11 04:48:29 +03:00
|
|
|
#include "mozilla/SVGContextPaint.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
|
|
|
|
2017-01-11 04:48:29 +03:00
|
|
|
class nsIFrame;
|
|
|
|
|
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)
|
2017-02-04 01:21:04 +03:00
|
|
|
, mIsPaintingSVGImageElement(false)
|
2014-08-29 18:04:34 +04:00
|
|
|
{ }
|
2013-10-22 15:37:57 +04:00
|
|
|
|
2017-01-30 16:25:00 +03:00
|
|
|
/**
|
|
|
|
* Currently it seems that the aViewportSize parameter ends up being used
|
|
|
|
* for different things by different pieces of code, and probably in some
|
|
|
|
* cases being used incorrectly (specifically in the case of pixel snapping
|
|
|
|
* under the nsLayoutUtils::Draw*Image() methods). An unfortunate result of
|
|
|
|
* the messy code is that aViewportSize is currently a Maybe<T> since it
|
|
|
|
* is difficult to create a utility function that consumers can use up
|
|
|
|
* front to get the "correct" viewport size (i.e. which for compatibility
|
|
|
|
* with the current code (bugs and all) would mean the size including all
|
|
|
|
* the snapping and resizing magic that happens in various places under the
|
|
|
|
* nsLayoutUtils::Draw*Image() methods on the way to DrawImageInternal
|
|
|
|
* creating |fallbackContext|). Using Maybe<T> allows code to pass Nothing()
|
|
|
|
* in order to get the size that's created for |fallbackContext|. At some
|
|
|
|
* point we need to clean this code up, make our abstractions clear, create
|
|
|
|
* that utility and stop using Maybe for this parameter.
|
|
|
|
*
|
|
|
|
* Note: 'aIsPaintingSVGImageElement' should be used to indicate whether
|
|
|
|
* the SVG image in question is being painted for an SVG <image> element.
|
|
|
|
*/
|
|
|
|
explicit SVGImageContext(const Maybe<CSSIntSize>& aViewportSize,
|
2017-02-13 20:07:40 +03:00
|
|
|
const Maybe<SVGPreserveAspectRatio>& aPreserveAspectRatio = Nothing(),
|
2017-01-11 04:48:29 +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
|
|
|
{ }
|
|
|
|
|
2017-03-06 16:49:21 +03:00
|
|
|
static void MaybeInitAndStoreContextPaint(Maybe<SVGImageContext>& aContext,
|
|
|
|
nsIFrame* aFromFrame,
|
|
|
|
imgIContainer* aImgContainer);
|
2017-01-11 04:48:29 +03:00
|
|
|
|
2017-01-30 16:25:00 +03:00
|
|
|
const Maybe<CSSIntSize>& GetViewportSize() const {
|
2014-08-23 00:12:38 +04:00
|
|
|
return mViewportSize;
|
|
|
|
}
|
|
|
|
|
2017-01-30 16:25:00 +03:00
|
|
|
void SetViewportSize(const Maybe<CSSIntSize>& aSize) {
|
2017-01-09 22:12:02 +03:00
|
|
|
mViewportSize = aSize;
|
|
|
|
}
|
|
|
|
|
2014-08-23 00:12:38 +04:00
|
|
|
const Maybe<SVGPreserveAspectRatio>& GetPreserveAspectRatio() const {
|
2013-03-01 00:22:43 +04:00
|
|
|
return mPreserveAspectRatio;
|
|
|
|
}
|
|
|
|
|
2017-01-09 22:12:02 +03:00
|
|
|
void SetPreserveAspectRatio(const Maybe<SVGPreserveAspectRatio>& aPAR) {
|
|
|
|
mPreserveAspectRatio = aPAR;
|
|
|
|
}
|
|
|
|
|
2014-08-29 18:04:34 +04:00
|
|
|
gfxFloat GetGlobalOpacity() const {
|
|
|
|
return mGlobalOpacity;
|
|
|
|
}
|
|
|
|
|
2017-03-01 13:41:14 +03:00
|
|
|
const SVGEmbeddingContextPaint* GetContextPaint() const {
|
2017-01-11 04:48:29 +03:00
|
|
|
return mContextPaint.get();
|
|
|
|
}
|
|
|
|
|
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 {
|
2017-03-01 13:41:14 +03:00
|
|
|
bool contextPaintIsEqual =
|
|
|
|
// neither have context paint, or they have the same object:
|
|
|
|
(mContextPaint == aOther.mContextPaint) ||
|
|
|
|
// or both have context paint that are different but equivalent objects:
|
|
|
|
(mContextPaint && aOther.mContextPaint &&
|
|
|
|
*mContextPaint == *aOther.mContextPaint);
|
|
|
|
|
|
|
|
return contextPaintIsEqual &&
|
|
|
|
mViewportSize == aOther.mViewportSize &&
|
2014-08-29 18:04:34 +04:00
|
|
|
mPreserveAspectRatio == aOther.mPreserveAspectRatio &&
|
2016-08-29 11:11:03 +03:00
|
|
|
mGlobalOpacity == aOther.mGlobalOpacity &&
|
|
|
|
mIsPaintingSVGImageElement == aOther.mIsPaintingSVGImageElement;
|
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 {
|
2017-01-11 04:48:29 +03:00
|
|
|
uint32_t hash = 0;
|
|
|
|
if (mContextPaint) {
|
|
|
|
hash = HashGeneric(hash, mContextPaint->Hash());
|
|
|
|
}
|
|
|
|
return HashGeneric(hash,
|
2017-01-30 16:25:00 +03:00
|
|
|
mViewportSize.map(HashSize).valueOr(0),
|
2014-08-29 18:04:34 +04:00
|
|
|
mPreserveAspectRatio.map(HashPAR).valueOr(0),
|
2017-01-11 04:48:29 +03:00
|
|
|
HashBytes(&mGlobalOpacity, sizeof(mGlobalOpacity)),
|
2016-08-29 11:11:03 +03:00
|
|
|
mIsPaintingSVGImageElement);
|
2013-10-22 15:37:57 +04:00
|
|
|
}
|
|
|
|
|
2013-03-01 00:22:43 +04:00
|
|
|
private:
|
2017-01-30 16:25:00 +03:00
|
|
|
static uint32_t HashSize(const CSSIntSize& aSize) {
|
|
|
|
return HashGeneric(aSize.width, aSize.height);
|
|
|
|
}
|
2014-08-23 00:12:38 +04:00
|
|
|
static uint32_t HashPAR(const SVGPreserveAspectRatio& aPAR) {
|
|
|
|
return aPAR.Hash();
|
|
|
|
}
|
|
|
|
|
2016-09-14 22:28:54 +03:00
|
|
|
// NOTE: When adding new member-vars, remember to update Hash() & operator==.
|
2017-03-01 13:41:14 +03:00
|
|
|
RefPtr<SVGEmbeddingContextPaint> mContextPaint;
|
2017-01-30 16:25:00 +03:00
|
|
|
Maybe<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_
|