Bug 811836. Fast path eCSSUnit_Color colors when parsing colors in canvas. r=dholbert

This will avoid doing extra work/flushing layout in the common case.

--HG--
extra : rebase_source : 95df23c3e6a5118ec4964336465a6554705b99dd
This commit is contained in:
Jeff Muizelaar 2012-11-14 12:46:26 -08:00
parent 9b8069b669
commit 517a0e7414

View File

@ -591,17 +591,23 @@ CanvasRenderingContext2D::ParseColor(const nsAString& aString,
return false;
}
nsIPresShell* presShell = GetPresShell();
nsRefPtr<nsStyleContext> parentContext;
if (mCanvasElement && mCanvasElement->IsInDoc()) {
// Inherit from the canvas element.
parentContext = nsComputedDOMStyle::GetStyleContextForElement(
mCanvasElement, nullptr, presShell);
}
if (value.GetUnit() == nsCSSUnit::eCSSUnit_Color) {
// if we already have a color we can just use it directly
*aColor = value.GetColorValue();
} else {
// otherwise resolve it
nsIPresShell* presShell = GetPresShell();
nsRefPtr<nsStyleContext> parentContext;
if (mCanvasElement && mCanvasElement->IsInDoc()) {
// Inherit from the canvas element.
parentContext = nsComputedDOMStyle::GetStyleContextForElement(
mCanvasElement, nullptr, presShell);
}
unused << nsRuleNode::ComputeColor(
value, presShell ? presShell->GetPresContext() : nullptr, parentContext,
*aColor);
unused << nsRuleNode::ComputeColor(
value, presShell ? presShell->GetPresContext() : nullptr, parentContext,
*aColor);
}
return true;
}