2017-10-16 03:54:47 +03:00
|
|
|
/* -*- 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
|
|
|
|
|
2017-12-01 12:35:47 +03:00
|
|
|
#include "mozilla/gfx/Types.h"
|
|
|
|
#include "mozilla/RefPtr.h"
|
2018-11-13 01:20:52 +03:00
|
|
|
#include "mozilla/ServoStyleConsts.h"
|
2017-12-01 12:35:47 +03:00
|
|
|
#include "mozilla/ServoTypes.h"
|
|
|
|
#include "nsColor.h"
|
|
|
|
#include "nsCSSPropertyID.h"
|
|
|
|
#include "nsDOMCSSDeclaration.h"
|
2018-03-09 22:55:12 +03:00
|
|
|
#include "nsStringFwd.h"
|
2017-12-01 12:35:47 +03:00
|
|
|
|
|
|
|
struct nsCSSRect;
|
2018-02-13 03:53:44 +03:00
|
|
|
struct nsTimingFunction;
|
|
|
|
struct RawServoDeclarationBlock;
|
2017-12-01 12:35:47 +03:00
|
|
|
|
2017-10-16 03:54:47 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
2017-12-01 12:35:47 +03:00
|
|
|
class ServoStyleSet;
|
|
|
|
class SharedFontList;
|
|
|
|
struct URLExtraData;
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
namespace css {
|
|
|
|
class Loader;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
class Document;
|
|
|
|
}
|
|
|
|
|
2017-10-16 03:54:47 +03:00
|
|
|
class ServoCSSParser {
|
|
|
|
public:
|
2018-05-14 19:22:20 +03:00
|
|
|
using ParsingEnvironment = nsDOMCSSDeclaration::ParsingEnvironment;
|
2017-12-01 12:35:47 +03:00
|
|
|
|
2017-10-16 03:54:47 +03:00
|
|
|
/**
|
|
|
|
* 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.
|
2017-11-30 12:27:18 +03:00
|
|
|
* @param aWasCurrentColor Whether aValue was currentcolor. Can be nullptr
|
|
|
|
* if the caller doesn't care.
|
2017-12-04 07:53:57 +03:00
|
|
|
* @param aLoader The CSS loader for document we're parsing a color for,
|
|
|
|
* so that parse errors can be reported to the console. If nullptr, errors
|
|
|
|
* won't be reported to the console.
|
2017-10-16 03:54:47 +03:00
|
|
|
* @return Whether aValue was successfully parsed and aResultColor was set.
|
|
|
|
*/
|
|
|
|
static bool ComputeColor(ServoStyleSet* aStyleSet, nscolor aCurrentColor,
|
|
|
|
const nsAString& aValue, nscolor* aResultColor,
|
2017-12-04 07:53:57 +03:00
|
|
|
bool* aWasCurrentColor = nullptr,
|
|
|
|
css::Loader* aLoader = nullptr);
|
2017-10-16 13:02:16 +03:00
|
|
|
|
2017-12-01 12:35:47 +03:00
|
|
|
/**
|
|
|
|
* Parse a string representing a CSS property value into a
|
|
|
|
* RawServoDeclarationBlock.
|
|
|
|
*
|
|
|
|
* @param aProperty The property to be parsed.
|
|
|
|
* @param aValue The specified value.
|
|
|
|
* @param aParsingEnvironment All the parsing environment data we need.
|
|
|
|
* @param aParsingMode The paring mode we apply.
|
|
|
|
* @return The parsed value as a RawServoDeclarationBlock. We put the value
|
|
|
|
* in a declaration block since that is how we represent specified values
|
|
|
|
* in Servo.
|
|
|
|
*/
|
|
|
|
static already_AddRefed<RawServoDeclarationBlock> ParseProperty(
|
|
|
|
nsCSSPropertyID aProperty, const nsAString& aValue,
|
|
|
|
const ParsingEnvironment& aParsingEnvironment,
|
|
|
|
ParsingMode aParsingMode = ParsingMode::Default);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse a animation timing function.
|
|
|
|
*
|
|
|
|
* @param aValue The specified value.
|
|
|
|
* @param aUrl The parser url extra data.
|
|
|
|
* @param aResult The output timing function. (output)
|
|
|
|
* @return Whether the value was successfully parsed.
|
|
|
|
*/
|
|
|
|
static bool ParseEasing(const nsAString& aValue, URLExtraData* aUrl,
|
|
|
|
nsTimingFunction& aResult);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse a specified transform list into a gfx matrix.
|
|
|
|
*
|
|
|
|
* @param aValue The specified value.
|
|
|
|
* @param aContains3DTransform The output flag indicates whether this is any
|
|
|
|
* 3d transform function. (output)
|
|
|
|
* @param aResult The output matrix. (output)
|
|
|
|
* @return Whether the value was successfully parsed.
|
|
|
|
*/
|
|
|
|
static bool ParseTransformIntoMatrix(const nsAString& aValue,
|
|
|
|
bool& aContains3DTransform,
|
2019-03-21 20:00:27 +03:00
|
|
|
gfx::Matrix4x4& aResult);
|
2017-12-01 12:35:47 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse a font shorthand for FontFaceSet matching, so we only care about
|
|
|
|
* FontFamily, FontStyle, FontStretch, and FontWeight.
|
|
|
|
*
|
|
|
|
* @param aValue The specified value.
|
|
|
|
* @param aUrl The parser url extra data.
|
|
|
|
* @param aList The parsed FontFamily list. (output)
|
|
|
|
* @param aStyle The parsed FontStyle. (output)
|
|
|
|
* @param aStretch The parsed FontStretch. (output)
|
|
|
|
* @param aWeight The parsed FontWeight. (output)
|
|
|
|
* @return Whether the value was successfully parsed.
|
|
|
|
*/
|
|
|
|
static bool ParseFontShorthandForMatching(
|
|
|
|
const nsAString& aValue, URLExtraData* aUrl,
|
2018-10-04 00:50:21 +03:00
|
|
|
RefPtr<SharedFontList>& aList, StyleComputedFontStyleDescriptor& aStyle,
|
|
|
|
float& aStretch, float& aWeight);
|
2017-12-01 12:35:47 +03:00
|
|
|
|
|
|
|
/**
|
2019-01-02 16:05:23 +03:00
|
|
|
* Get a URLExtraData from a document.
|
2017-12-01 12:35:47 +03:00
|
|
|
*/
|
2019-01-02 16:05:23 +03:00
|
|
|
static already_AddRefed<URLExtraData> GetURLExtraData(dom::Document*);
|
2017-12-01 12:35:47 +03:00
|
|
|
|
|
|
|
/**
|
2019-01-02 16:05:23 +03:00
|
|
|
* Get a ParsingEnvironment from a document.
|
2017-12-01 12:35:47 +03:00
|
|
|
*/
|
2019-01-02 16:05:23 +03:00
|
|
|
static ParsingEnvironment GetParsingEnvironment(dom::Document*);
|
2017-10-16 03:54:47 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_ServoCSSParser_h
|