Bug 1408312 - Part 3: Replace nsCSSParser/nsRuleNode usage for color computation in Servo styled documents. r=xidorn

MozReview-Commit-ID: LuB0izWz7nk

--HG--
extra : rebase_source : 0fd4e9a3b62c668ab0a6925e70006646a3273e62
This commit is contained in:
Cameron McCormack 2017-10-16 09:06:39 +08:00
parent 04696a9b72
commit 64d0481dfd
5 changed files with 73 additions and 31 deletions

View File

@ -127,6 +127,7 @@
#include "mozilla/StyleSetHandle.h"
#include "mozilla/StyleSetHandleInlines.h"
#include "mozilla/layers/CanvasClient.h"
#include "mozilla/ServoCSSParser.h"
#undef free // apparently defined by some windows header, clashing with a free()
// method in SkTypes.h
@ -745,17 +746,28 @@ CanvasGradient::AddColorStop(float aOffset, const nsAString& aColorstr, ErrorRes
return;
}
nsCSSValue value;
nsCSSParser parser;
if (!parser.ParseColorString(aColorstr, nullptr, 0, value)) {
aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
return;
nscolor color;
bool ok;
nsIPresShell* shell = mContext ? mContext->GetPresShell() : nullptr;
ServoStyleSet* servoStyleSet = shell && shell->StyleSet()
? shell->StyleSet()->GetAsServo()
: nullptr;
if (servoStyleSet) {
ok = ServoCSSParser::ComputeColor(servoStyleSet, NS_RGB(0, 0, 0), aColorstr,
&color);
} else {
nsCSSValue value;
nsCSSParser parser;
nsPresContext* presContext = shell ? shell->GetPresContext() : nullptr;
ok = parser.ParseColorString(aColorstr, nullptr, 0, value) &&
nsRuleNode::ComputeColor(value, presContext, nullptr, color);
}
nscolor color;
nsCOMPtr<nsIPresShell> presShell = mContext ? mContext->GetPresShell() : nullptr;
if (!nsRuleNode::ComputeColor(value, presShell ? presShell->GetPresContext() : nullptr,
nullptr, color)) {
if (!ok) {
aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
return;
}

View File

@ -25,6 +25,7 @@
#include "nsCSSValue.h"
#include "nsRuleNode.h"
#include "mozilla/gfx/Matrix.h"
#include "mozilla/ServoCSSParser.h"
using namespace mozilla;
using namespace mozilla::gfx;
@ -59,15 +60,24 @@ DocumentRendererChild::RenderDocument(nsPIDOMWindowOuter* window,
if (!presContext)
return false;
nsCSSParser parser;
nsCSSValue bgColorValue;
if (!parser.ParseColorString(aBGColor, nullptr, 0, bgColorValue)) {
return false;
}
nscolor bgColor;
if (!nsRuleNode::ComputeColor(bgColorValue, presContext, nullptr, bgColor)) {
ServoStyleSet* servoStyleSet = presContext->StyleSet()
? presContext->StyleSet()->GetAsServo()
: nullptr;
if (servoStyleSet) {
if (!ServoCSSParser::ComputeColor(servoStyleSet, NS_RGB(0, 0, 0),
aBGColor, &bgColor)) {
return false;
}
} else {
nsCSSParser parser;
nsCSSValue bgColorValue;
if (!parser.ParseColorString(aBGColor, nullptr, 0, bgColorValue) ||
!nsRuleNode::ComputeColor(bgColorValue, presContext, nullptr, bgColor)) {
return false;
}
}
// Draw directly into the output array.

View File

@ -95,6 +95,7 @@
#include "nsBidi.h"
#include "mozilla/dom/URL.h"
#include "mozilla/ServoCSSParser.h"
using namespace mozilla;
using namespace mozilla::dom;
@ -146,17 +147,29 @@ private:
nscolor
nsPresContext::MakeColorPref(const nsString& aColor)
{
nsCSSParser parser;
nsCSSValue value;
if (!parser.ParseColorString(aColor, nullptr, 0, value)) {
// Any better choices?
return NS_RGB(0, 0, 0);
bool ok;
nscolor result;
ServoStyleSet* servoStyleSet = mShell && mShell->StyleSet()
? mShell->StyleSet()->GetAsServo()
: nullptr;
if (servoStyleSet) {
ok = ServoCSSParser::ComputeColor(servoStyleSet, NS_RGB(0, 0, 0), aColor,
&result);
} else {
nsCSSParser parser;
nsCSSValue value;
ok = parser.ParseColorString(aColor, nullptr, 0, value) &&
nsRuleNode::ComputeColor(value, this, nullptr, result);
}
nscolor color;
return nsRuleNode::ComputeColor(value, this, nullptr, color)
? color
: NS_RGB(0, 0, 0);
if (!ok) {
// Any better choices?
result = NS_RGB(0, 0, 0);
}
return result;
}
bool

View File

@ -1007,19 +1007,25 @@ NS_IMETHODIMP
inDOMUtils::ColorToRGBA(const nsAString& aColorString, JSContext* aCx,
JS::MutableHandle<JS::Value> aValue)
{
nscolor color = 0;
nscolor color = NS_RGB(0, 0, 0);
#ifdef MOZ_STYLO
if (!ServoCSSParser::ComputeColor(nullptr, NS_RGB(0, 0, 0), aColorString,
&color)) {
aValue.setNull();
return NS_OK;
}
#else
nsCSSParser cssParser;
nsCSSValue cssValue;
bool isColor = cssParser.ParseColorString(aColorString, nullptr, 0,
cssValue, true);
if (!isColor) {
if (!cssParser.ParseColorString(aColorString, nullptr, 0, cssValue, true)) {
aValue.setNull();
return NS_OK;
}
nsRuleNode::ComputeColor(cssValue, nullptr, nullptr, color);
#endif
InspectorRGBATuple tuple;
tuple.mR = NS_GET_R(color);

View File

@ -1,5 +1,6 @@
[2d.gradient.object.current.html]
type: testharness
[Canvas test: 2d.gradient.object.current]
expected: FAIL
expected:
if not stylo: FAIL