Bug 1408312 - Part 1: Add ServoCSSParser utility class. r=xidorn

MozReview-Commit-ID: KzM9332hBSx

--HG--
extra : rebase_source : c048323e36bef9dceb3c86d3cc9ee66aa39efb51
This commit is contained in:
Cameron McCormack 2017-10-16 08:54:47 +08:00
Родитель 19dcaa9aa1
Коммит b9be378e65
4 изменённых файлов: 82 добавлений и 0 удалений

Просмотреть файл

@ -682,6 +682,14 @@ SERVO_BINDING_FUNC(Servo_ReleaseArcStringData, void,
SERVO_BINDING_FUNC(Servo_CloneArcStringData, mozilla::ServoRawOffsetArc<RustString>,
const mozilla::ServoRawOffsetArc<RustString>* string);
// CSS parsing utility functions.
SERVO_BINDING_FUNC(Servo_IsValidCSSColor, bool, const nsAString* value);
SERVO_BINDING_FUNC(Servo_ComputeColor, bool,
RawServoStyleSetBorrowedOrNull set,
nscolor current_color,
const nsAString* value,
nscolor* result_color);
// AddRef / Release functions
#define SERVO_ARC_TYPE(name_, type_) \
SERVO_BINDING_FUNC(Servo_##name_##_AddRef, void, type_##Borrowed) \

Просмотреть файл

@ -0,0 +1,27 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
/* CSS parsing utility functions */
#include "ServoCSSParser.h"
using namespace mozilla;
/* static */ bool
ServoCSSParser::IsValidCSSColor(const nsAString& aValue)
{
return Servo_IsValidCSSColor(&aValue);
}
/* static */ bool
ServoCSSParser::ComputeColor(ServoStyleSet* aStyleSet,
nscolor aCurrentColor,
const nsAString& aValue,
nscolor* aResultColor)
{
return Servo_ComputeColor(aStyleSet ? aStyleSet->RawSet() : nullptr,
aCurrentColor, &aValue, aResultColor);
}

Просмотреть файл

@ -0,0 +1,45 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
/* CSS parsing utility functions */
#ifndef mozilla_ServoCSSParser_h
#define mozilla_ServoCSSParser_h
#include "mozilla/ServoBindings.h"
namespace mozilla {
class ServoCSSParser
{
public:
/**
* Returns whether the specified string can be parsed as a valid CSS
* <color> value.
*
* This includes Mozilla-specific keywords such as -moz-default-color.
*/
static bool IsValidCSSColor(const nsAString& aValue);
/**
* Computes an nscolor from the given CSS <color> value.
*
* @param aStyleSet The style set whose nsPresContext will be used to
* compute system colors and other special color values.
* @param aCurrentColor The color value that currentcolor should compute to.
* @param aValue The CSS <color> value.
* @param aResultColor The resulting computed color value.
* @return Whether aValue was successfully parsed and aResultColor was set.
*/
static bool ComputeColor(ServoStyleSet* aStyleSet,
nscolor aCurrentColor,
const nsAString& aValue,
nscolor* aResultColor);
};
} // namespace mozilla
#endif // mozilla_ServoCSSParser_h

Просмотреть файл

@ -103,6 +103,7 @@ EXPORTS.mozilla += [
'ServoBindingList.h',
'ServoBindings.h',
'ServoBindingTypes.h',
'ServoCSSParser.h',
'ServoCSSRuleList.h',
'ServoDeclarationBlock.h',
'ServoDocumentRule.h',
@ -249,6 +250,7 @@ UNIFIED_SOURCES += [
'RuleNodeCacheConditions.cpp',
'RuleProcessorCache.cpp',
'ServoBindings.cpp',
'ServoCSSParser.cpp',
'ServoCSSRuleList.cpp',
'ServoDeclarationBlock.cpp',
'ServoDocumentRule.cpp',