Bug 1440961: Make canvas style-related code interact a bit better with Shadow DOM. r?smaug
The only relevant spec reference unfortunately is for color parsing[1], which
mentions:
> Otherwise, set color to the computed value of the 'color' property of element.
Using IsInComposedDoc there should be fine, since the computed style of an
element is well defined there.
The rest look like implementation limitations, for which should not be an issue
to extend the check for the composed doc.
[1]: https://html.spec.whatwg.org/#parsed-as-a-css-color-value
MozReview-Commit-ID: ADnVPNqf3X1
--- a/dom/canvas/CanvasRenderingContext2D.cpp
+++ b/dom/canvas/CanvasRenderingContext2D.cpp
@@ -1221,17 +1221,17 @@ CanvasRenderingContext2D::ParseColor(con
if (value.IsNumericColorUnit()) {
// if we already have a color we can just use it directly
*aColor = value.GetColorValue();
} else {
// otherwise resolve it
nsCOMPtr<nsIPresShell> presShell = GetPresShell();
RefPtr<nsStyleContext> parentContext;
- if (mCanvasElement && mCanvasElement->IsInUncomposedDoc()) {
+ if (mCanvasElement && mCanvasElement->IsInComposedDoc()) {
// Inherit from the canvas element.
parentContext =
nsComputedDOMStyle::GetStyleContext(mCanvasElement, nullptr);
}
Unused << nsRuleNode::ComputeColor(
value, presShell ? presShell->GetPresContext() : nullptr, parentContext,
*aColor);
@@ -1997,17 +1997,17 @@ void
CanvasRenderingContext2D::ClearTarget()
{
Reset();
mResetLayer = true;
SetInitialState();
- if (!mCanvasElement || !mCanvasElement->IsInUncomposedDoc()) {
+ if (!mCanvasElement || !mCanvasElement->IsInComposedDoc()) {
return;
}
// For vertical writing-mode, unless text-orientation is sideways,
// we'll modify the initial value of textBaseline to 'middle'.
RefPtr<nsStyleContext> canvasStyle =
nsComputedDOMStyle::GetStyleContext(mCanvasElement, nullptr);
if (canvasStyle) {
@@ -2734,17 +2734,17 @@ CreateFontDeclaration(const nsAString& a
eCSSProperty_line_height, NS_LITERAL_STRING("normal"), &lineHeightChanged);
}
static already_AddRefed<GeckoStyleContext>
GetFontParentStyleContext(Element* aElement,
nsIPresShell* aPresShell,
ErrorResult& aError)
{
- if (aElement && aElement->IsInUncomposedDoc()) {
+ if (aElement && aElement->IsInComposedDoc()) {
// Inherit from the canvas element.
RefPtr<nsStyleContext> result =
nsComputedDOMStyle::GetStyleContext(aElement, nullptr);
if (!result) {
aError.Throw(NS_ERROR_FAILURE);
return nullptr;
}
return GeckoStyleContext::TakeRef(result.forget());
@@ -2914,17 +2914,17 @@ GetFontStyleForServo(Element* aElement,
return nullptr;
}
ServoStyleSet* styleSet = aPresShell->StyleSet()->AsServo();
RefPtr<nsStyleContext> parentStyle;
// have to get a parent style context for inherit-like relative
// values (2em, bolder, etc.)
- if (aElement && aElement->IsInUncomposedDoc()) {
+ if (aElement && aElement->IsInComposedDoc()) {
parentStyle = nsComputedDOMStyle::GetStyleContext(aElement, nullptr);
} else {
RefPtr<RawServoDeclarationBlock> declarations =
CreateFontDeclarationForServo(NS_LITERAL_STRING("10px sans-serif"),
aPresShell->GetDocument());
MOZ_ASSERT(declarations);
parentStyle = aPresShell->StyleSet()->AsServo()->
@@ -4571,17 +4571,17 @@ CanvasRenderingContext2D::DrawOrMeasureT
if (aMaxWidth.WasPassed() && (aMaxWidth.Value() <= 0 || IsNaN(aMaxWidth.Value()))) {
textToDraw.Truncate();
}
// for now, default to ltr if not in doc
bool isRTL = false;
RefPtr<nsStyleContext> canvasStyle;
- if (mCanvasElement && mCanvasElement->IsInUncomposedDoc()) {
+ if (mCanvasElement && mCanvasElement->IsInComposedDoc()) {
// try to find the closest context
canvasStyle =
nsComputedDOMStyle::GetStyleContext(mCanvasElement, nullptr);
if (!canvasStyle) {
return NS_ERROR_FAILURE;
}
isRTL = canvasStyle->StyleVisibility()->mDirection ==