2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2017-01-11 04:48:29 +03: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/. */
|
|
|
|
|
|
|
|
// Main header first:
|
|
|
|
#include "SVGImageContext.h"
|
|
|
|
|
|
|
|
// Keep others in (case-insensitive) order:
|
|
|
|
#include "gfxUtils.h"
|
2017-04-28 23:54:00 +03:00
|
|
|
#include "mozilla/Preferences.h"
|
2017-03-08 07:10:29 +03:00
|
|
|
#include "nsIFrame.h"
|
2017-01-11 04:48:29 +03:00
|
|
|
#include "nsPresContext.h"
|
2017-04-12 14:47:32 +03:00
|
|
|
#include "nsStyleStruct.h"
|
2017-01-11 04:48:29 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
void SVGImageContext::MaybeStoreContextPaint(Maybe<SVGImageContext>& aContext,
|
|
|
|
nsIFrame* aFromFrame,
|
|
|
|
imgIContainer* aImgContainer) {
|
2017-05-26 16:24:57 +03:00
|
|
|
return MaybeStoreContextPaint(aContext, aFromFrame->Style(), aImgContainer);
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
void SVGImageContext::MaybeStoreContextPaint(Maybe<SVGImageContext>& aContext,
|
|
|
|
ComputedStyle* aFromComputedStyle,
|
|
|
|
imgIContainer* aImgContainer) {
|
2018-03-22 21:20:41 +03:00
|
|
|
const nsStyleSVG* style = aFromComputedStyle->StyleSVG();
|
2017-04-19 16:52:25 +03:00
|
|
|
|
|
|
|
if (!style->ExposesContextProperties()) {
|
2017-04-12 14:47:32 +03:00
|
|
|
// Content must have '-moz-context-properties' set to the names of the
|
|
|
|
// properties it wants to expose to images it links to.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-06 16:49:21 +03:00
|
|
|
if (aImgContainer->GetType() != imgIContainer::TYPE_VECTOR) {
|
|
|
|
// Avoid this overhead for raster images.
|
|
|
|
return;
|
2017-01-11 04:48:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool haveContextPaint = false;
|
|
|
|
|
2020-02-23 18:43:03 +03:00
|
|
|
auto contextPaint = MakeRefPtr<SVGEmbeddingContextPaint>();
|
2017-01-11 04:48:29 +03:00
|
|
|
|
2019-12-09 06:32:28 +03:00
|
|
|
if ((style->mMozContextProperties.bits & StyleContextPropertyBits::FILL) &&
|
2019-07-06 11:31:02 +03:00
|
|
|
style->mFill.kind.IsColor()) {
|
2017-01-11 04:48:29 +03:00
|
|
|
haveContextPaint = true;
|
2019-07-06 11:31:02 +03:00
|
|
|
contextPaint->SetFill(
|
|
|
|
style->mFill.kind.AsColor().CalcColor(*aFromComputedStyle));
|
2017-01-11 04:48:29 +03:00
|
|
|
}
|
2019-12-09 06:32:28 +03:00
|
|
|
if ((style->mMozContextProperties.bits & StyleContextPropertyBits::STROKE) &&
|
2019-07-06 11:31:02 +03:00
|
|
|
style->mStroke.kind.IsColor()) {
|
2017-01-11 04:48:29 +03:00
|
|
|
haveContextPaint = true;
|
2019-07-06 11:31:02 +03:00
|
|
|
contextPaint->SetStroke(
|
|
|
|
style->mStroke.kind.AsColor().CalcColor(*aFromComputedStyle));
|
2017-01-11 04:48:29 +03:00
|
|
|
}
|
2019-05-25 20:46:15 +03:00
|
|
|
if (style->mMozContextProperties.bits &
|
2019-12-09 06:32:28 +03:00
|
|
|
StyleContextPropertyBits::FILL_OPACITY) {
|
2017-05-18 14:47:20 +03:00
|
|
|
haveContextPaint = true;
|
2020-02-23 18:43:03 +03:00
|
|
|
contextPaint->SetFillOpacity(style->mFillOpacity.IsOpacity()
|
|
|
|
? style->mFillOpacity.AsOpacity()
|
|
|
|
: 1.0f);
|
2017-05-18 14:47:20 +03:00
|
|
|
}
|
2019-05-25 20:46:15 +03:00
|
|
|
if (style->mMozContextProperties.bits &
|
2019-12-09 06:32:28 +03:00
|
|
|
StyleContextPropertyBits::STROKE_OPACITY) {
|
2017-05-18 14:47:20 +03:00
|
|
|
haveContextPaint = true;
|
2020-02-23 18:43:03 +03:00
|
|
|
contextPaint->SetStrokeOpacity(style->mStrokeOpacity.IsOpacity()
|
|
|
|
? style->mStrokeOpacity.AsOpacity()
|
|
|
|
: 1.0f);
|
2017-05-18 14:47:20 +03:00
|
|
|
}
|
2017-01-11 04:48:29 +03:00
|
|
|
|
|
|
|
if (haveContextPaint) {
|
2017-03-28 13:43:15 +03:00
|
|
|
if (!aContext) {
|
|
|
|
aContext.emplace();
|
|
|
|
}
|
2020-02-13 17:38:48 +03:00
|
|
|
aContext->mContextPaint = std::move(contextPaint);
|
2017-01-11 04:48:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla
|