Bug 1408312 - Part 1: Add ServoCSSParser utility class. r=xidorn
authorCameron McCormack <cam@mcc.id.au>
Mon, 16 Oct 2017 08:54:47 +0800
changeset 386512 2e36022d5347c2cea0c4d9847829a3ee516bb6e1
parent 386511 615798b405f4994de32c6a9b0a464601accb0b0e
child 386513 9fb995f9e98499fd0c6474c6bcb9e3fcd5d658f8
push id53435
push usercmccormack@mozilla.com
push dateTue, 17 Oct 2017 04:00:05 +0000
treeherderautoland@4e4073c0e143 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersxidorn
bugs1408312
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1408312 - Part 1: Add ServoCSSParser utility class. r=xidorn MozReview-Commit-ID: KzM9332hBSx
layout/style/ServoBindingList.h
layout/style/ServoCSSParser.cpp
layout/style/ServoCSSParser.h
layout/style/moz.build
--- a/layout/style/ServoBindingList.h
+++ b/layout/style/ServoBindingList.h
@@ -677,14 +677,22 @@ SERVO_BINDING_FUNC(Servo_HasPendingResty
 
 SERVO_BINDING_FUNC(Servo_GetArcStringData, void,
                    const RustString*, uint8_t const** chars, uint32_t* len);
 SERVO_BINDING_FUNC(Servo_ReleaseArcStringData, void,
                    const mozilla::ServoRawOffsetArc<RustString>* string);
 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) \
   SERVO_BINDING_FUNC(Servo_##name_##_Release, void, type_##Borrowed)
 #include "mozilla/ServoArcTypeList.h"
 #undef SERVO_ARC_TYPE
new file mode 100644
--- /dev/null
+++ b/layout/style/ServoCSSParser.cpp
@@ -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);
+}
new file mode 100644
--- /dev/null
+++ b/layout/style/ServoCSSParser.h
@@ -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
--- a/layout/style/moz.build
+++ b/layout/style/moz.build
@@ -98,16 +98,17 @@ EXPORTS.mozilla += [
     'PostTraversalTask.h',
     'PreloadedStyleSheet.h',
     'RuleNodeCacheConditions.h',
     'RuleProcessorCache.h',
     'ServoArcTypeList.h',
     'ServoBindingList.h',
     'ServoBindings.h',
     'ServoBindingTypes.h',
+    'ServoCSSParser.h',
     'ServoCSSRuleList.h',
     'ServoDeclarationBlock.h',
     'ServoDocumentRule.h',
     'ServoElementSnapshot.h',
     'ServoElementSnapshotTable.h',
     'ServoFontFeatureValuesRule.h',
     'ServoImportRule.h',
     'ServoKeyframeRule.h',
@@ -244,16 +245,17 @@ UNIFIED_SOURCES += [
     'nsStyleTransformMatrix.cpp',
     'nsStyleUtil.cpp',
     'nsTransitionManager.cpp',
     'PostTraversalTask.cpp',
     'PreloadedStyleSheet.cpp',
     'RuleNodeCacheConditions.cpp',
     'RuleProcessorCache.cpp',
     'ServoBindings.cpp',
+    'ServoCSSParser.cpp',
     'ServoCSSRuleList.cpp',
     'ServoDeclarationBlock.cpp',
     'ServoDocumentRule.cpp',
     'ServoElementSnapshot.cpp',
     'ServoFontFeatureValuesRule.cpp',
     'ServoImportRule.cpp',
     'ServoKeyframeRule.cpp',
     'ServoKeyframesRule.cpp',