Files
palemoon27/layout/style/nsCSSParser.h
T
roytam1 9d253b796d import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1235610 - Add xpctall support for Bitrig and DragonFly. r=glandium (02b7d40eb3)
- Bug 1252072 - Prevent ASan instrumentation for unsafe xpcom functions. r=froydnj (881bfc18c0)
- Bug 1245099 - Fixed uninitialized variable warning. r=bsmedberg (6481aad0d5)
- Bug 1196370 - Remove the clang assembly workaround from bug 1028613. r=ehsan (b8b6f1a5e8)
- Bug 1234860 - move win32 NS_InvokeByIndex implementation to a separate assembly file; r=aklotz,ted.m (73ca54348f)
- Bug 1248534 (part 1) - Remove XPT encoding support. r=khuey. (e84c4dfd32)
- Bug 1248534 (part 2) - Remove unused XPT flags. r=khuey. (264be694d0)
- Bug 1248534 (part 3) - Remove almost all support for XPT annotations. r=khuey. (97a0d86e0b)
- Bug 1248534 (part 4) - Remove unused fields from XPTConstValue. r=khuey. (9eccf9eba5)
- Bug 1248534 (part 5) - Remove XPTDatapool. r=khuey. (139dab7a9f)
- Bug 1248534 (part 6) - Stack-allocate XPTState. r=khuey. (f32ce7cc9e)
- Bug 1249174 (part 7) - Only define XPTArena::name if XPT_ARENA_LOGGING is defined. r=khuey. (174a20c0a3)
- Bug 1248534 (part 8) - Remove useless XPT freeing code. r=khuey. (a5ade9739b)
- Bug 1248534 (part 9) - Remove XPT arena logging code. r=khuey. (a996dfad76)
- Bug 1251458 - Reinstate annotation handling in .xpt files. r=khuey. (fbe8d573bd)
- Bug 1249174 (part 1) - Don't store the unused XPTTypeDescriptorTags::argnum2 field in memory. r=khuey. (e1d12965eb)
- Bug 1253877 - Baldr: cast -1 to uint8 to avoid 'shifting negative' error on CLOSED TREE (r=bustage) (cdf8031264)
- Bug 1258599 - OdinMonkey: MIPS: Only reserving stack for argument registers on O32. r=huangwenjun06 (a77220a9fa)
- Bug 1253137 - Baldr: fold if_else into if to match ml-proto (r=sunfish) (54e89aafe3)
- Bug 1249174 (part 2) - Shrink xptiInterfaceEntry by reordering its fields. r=khuey. (c4d7c15e6e)
- Bug 1253137 - Baldr: update br_table syntax to match ml-proto (r=sunfish) (e7f253e4d8)
- Bug 1249174 (part 3) - Don't store the unused XPTInterfaceDirectoryEntry::name_space field in memory. r=khuey. (c308508e74)
- Bug 1249174 (part 4) - Don't store unused XPTHeader fields in memory. r=khuey. (2dfd238a54)
- Bug 1249174 (part 5) - Remove the useless BLK_HDR::size field. r=khuey. (1a362c278e)
- Bug 1249174 (part 6) - Shrink XPTTypeDescriptor. r=khuey. (5a313327fe)
- Bug 1249174 (part 7.5) - Avoid wasted space around XPT strings. r=khuey. (ac3653802c)
- Bug 1249174 (part 8) - Shrink XPTInterfaceDescriptor. r=khuey. (e9dc929d37)
- Bug 1254188 - Baldr: handle recycled phis when closing a loop with a  value (r=bbouvier) (2cb0895472)
- Bug 1254167: Don't allow folding to full range for atomic accesses; r=sunfish (96a851efda)
- Bug 1256637: Set definition before returning early in EmitBrTable; r=luke (0fdb365e82)
- Bug 1255695 - BaldrMonkey: Implement unaligned accesses. r=luke (205b798249)
- Bug 1238121 - Properly guard Profiler's RAII classes r=BenWa f=mystor (a3db8e6bc9)
- Bug 1251787 - Remove remaining references to MOZILLA_XPCOMRT_API from tools. r=mstange (1632205437)
- align profiler (c2638ecf1f)
- Bug 1235502 - Fix -Wunreachable-code warning in tools/profiler/. r=BenWa (0d564937c9)
- Bug 1221846 - Properly close the tasktracer property in the GeckoSampler JSON blob. r=BenWa (dca640fb03)
- Bug 1239498 - Use Stackwalk64 on win x64. r=jrmuizel (50ffe8a649)
- Bug 1258269: Declare logging string-literals in exception_handler.cc as 'const char[]' to fix build warning & for consistency. r=ted (a9454e735f)
- parts of Bug 1151175 - Update libvpx update.py for 1.4.0. (8700fa48ab)
- Bug 1249590 - Bullet-proofing AsyncShutdown wrt exceptions;r=froydnj (7e512f1029)
- Bug 1021151 - avoid memory leak in NS_GENERIC_AGGREGATED_CONSTRUCTOR_INIT, use nsAutoPtr instead of naked ptr. r=Ehsan (d0eb754af2)
- Bug 1255223 - Null crash when logging weak maps. r=mccr8. (0d02b4b469)
- Bug 1250134 - assert mJSRuntime when IsGrayJS() is true. r=mccr8 (a3987102ed)
- Bug 1254131: Fix non-unified wasm build. r=luke (cacb86e4d0)
- Bug 1246929 - Skip installing functions and properties on builtins for the self-hosting global. r=Waldo (aa04041de9)
- Bug 986294 - Remove Proxy.create from addon-sdk. r=mossop (da3d6c40ea)
- Bug 1243805 - Replace Proxy.create with new Proxy in devtools l10n code. r=jryans (9886f857be)
- Bug 1245141 - Use new Proxy for AddonManager.addonTypes. r=mossop (6cc8dd0870)
- Bug 1253866 - Remove Proxy.create from crash tests. r=bz (76a421cf97)
- Bug 892903 - Remove Proxy.create and Proxy.createFunction. r=efaust (7b572deb10)
- Bug 1049041 - Remove scary warning about mutating [[Prototype]]. r=efaust. (367ac3f6c5)
- Bug 1257445 - #ifdef on __GLIBC__ for sched_getcpu, which is a glibc feature. r=jimb (171a1729c1)
- Followup for bug 1257445 - Remove the AutoStopwatch::getCPU implementation using sched_getcpu. r=jimb (221f52d4c4)
- Bug 1178317 - eliminate large static constructor from ShimInterfaceInfo.cpp; r=poiru (aa66704aee)
- Bug 1247580 P1 Allow old nsIX509Cert serialized objects to be read off disk. r=bz (1f8bc280a6)
- Bug 1247580 P2 Add gtest to ensure we can continue to deserialize old security info strings. r=bz (323059ac29)
- Bug 864842 - Show error for browsing Windows drive without media, r=michal (1e438bdf2f)
- Bug 1233283 - Remove unless tmp from ReadDir in nsLocalFileWin. r=froydnj (1565d1cc14)
- Bug 1258498: Use fallible allocation in nsScriptableInputStream::ReadBytes. r= froydnj (eebcb8050d)
- Bug 1236108: Add temp directory for sandboxed content processes to directory r=bsmedberg (8384b33c10)
- Bug 1255362 - Null-check GetContainer() before using it in image-related ConfigureLayer() methods. r=mstange a=Tomcat (beab7149f1)
- Bug 1205473 - Add a state bit to optimize building event regions. r=mattwoodrow (c8b1eb9839)
- Bug 1222886 - Remove unused nsCSSParser::{SetStyleSheet,SetChildLoader,SetQuirkMode} methods. r=bzbarsky (c9c6621083)
- Bug 1247327. Fix WebGL acceptance rates in telemetry. r=milan (de10319664)
- Bug 1249664 - Save dropped-down state in nsPresState. r=dbaron (734c3ee18b)
- Bug 1256745 - Cancel the DidPaint timer in SetShell(nullptr). r=mattwoodrow (d2a4202512)
- Bug 1238846 (part 1) - Remove some dead code in nsLayoutUtils. r=mattwoodrow. (e6af806e52)
- Bug 1252414 - Handle lost_context for webgl ClearBuffer*. r=jgilbert (e6728605ff)
- Bug 1228687: ScopedResolveTexturesForDraw needs the context to be current, so make those calls earlier. r=jgilbert (6e731187c5)
- Bug 1247532 - Annotate intentional switch fallthrough to suppress -Wimplicit-fallthrough warning in dom/canvas/. r=jgilbert (d7faec1848)
- Bug 1249483 - Stop filling A with 1.0 on readback from no-alpha. - r=jrmuizel (9bf71fb220)
2024-03-10 21:39:46 +08:00

337 lines
14 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
/* parsing of CSS stylesheets, based on a token stream from the CSS scanner */
#ifndef nsCSSParser_h___
#define nsCSSParser_h___
#include "mozilla/Attributes.h"
#include "mozilla/css/Loader.h"
#include "nsCSSProperty.h"
#include "nsCSSScanner.h"
#include "nsCOMPtr.h"
#include "nsAutoPtr.h"
#include "nsStringFwd.h"
#include "nsTArrayForwardDeclare.h"
class nsIPrincipal;
class nsIURI;
struct nsCSSSelectorList;
class nsMediaList;
class nsMediaQuery;
class nsCSSKeyframeRule;
class nsCSSValue;
struct nsRuleData;
namespace mozilla {
class CSSStyleSheet;
class CSSVariableValues;
namespace css {
class Rule;
class Declaration;
class StyleRule;
} // namespace css
} // namespace mozilla
// Interface to the css parser.
class MOZ_STACK_CLASS nsCSSParser {
public:
explicit nsCSSParser(mozilla::css::Loader* aLoader = nullptr,
mozilla::CSSStyleSheet* aSheet = nullptr);
~nsCSSParser();
static void Startup();
static void Shutdown();
private:
nsCSSParser(nsCSSParser const&) = delete;
nsCSSParser& operator=(nsCSSParser const&) = delete;
public:
/**
* Parse aInput into the stylesheet that was previously passed to the
* constructor. Calling this method on an nsCSSParser that had nullptr
* passed in as the style sheet is an error.
*
* @param aInput the data to parse
* @param aSheetURL the URI to use as the sheet URI (for error reporting).
* This must match the URI of the sheet passed to
* the constructor.
* @param aBaseURI the URI to use for relative URI resolution
* @param aSheetPrincipal the principal of the stylesheet. This must match
* the principal of the sheet passed to the
* constructor.
* @param aLineNumber the line number of the first line of the sheet.
* @param aParsingMode see SheetParsingMode in css/Loader.h
* @param aReusableSheets style sheets that can be reused by an @import.
* This can be nullptr.
*/
nsresult ParseSheet(const nsAString& aInput,
nsIURI* aSheetURL,
nsIURI* aBaseURI,
nsIPrincipal* aSheetPrincipal,
uint32_t aLineNumber,
mozilla::css::SheetParsingMode aParsingMode,
mozilla::css::LoaderReusableStyleSheets* aReusableSheets =
nullptr);
// Parse HTML style attribute or its equivalent in other markup
// languages. aBaseURL is the base url to use for relative links in
// the declaration.
already_AddRefed<mozilla::css::Declaration>
ParseStyleAttribute(const nsAString& aAttributeValue,
nsIURI* aDocURL,
nsIURI* aBaseURL,
nsIPrincipal* aNodePrincipal);
// Parse the body of a declaration block. Very similar to
// ParseStyleAttribute, but used under different circumstances.
// The contents of aDeclaration will be erased and replaced with the
// results of parsing; aChanged will be set true if the aDeclaration
// argument was modified.
nsresult ParseDeclarations(const nsAString& aBuffer,
nsIURI* aSheetURL,
nsIURI* aBaseURL,
nsIPrincipal* aSheetPrincipal,
mozilla::css::Declaration* aDeclaration,
bool* aChanged);
nsresult ParseRule(const nsAString& aRule,
nsIURI* aSheetURL,
nsIURI* aBaseURL,
nsIPrincipal* aSheetPrincipal,
mozilla::css::Rule** aResult);
// Parse the value of a single CSS property, and add or replace that
// property in aDeclaration.
//
// SVG "mapped attributes" (which correspond directly to CSS
// properties) are parsed slightly differently from regular CSS; in
// particular, units may be omitted from <length>. The 'aIsSVGMode'
// argument controls this quirk. Note that this *only* applies to
// mapped attributes, not inline styles or full style sheets in SVG.
void ParseProperty(const nsCSSProperty aPropID,
const nsAString& aPropValue,
nsIURI* aSheetURL,
nsIURI* aBaseURL,
nsIPrincipal* aSheetPrincipal,
mozilla::css::Declaration* aDeclaration,
bool* aChanged,
bool aIsImportant,
bool aIsSVGMode = false);
// Same as ParseProperty but returns an nsCSSValue in aResult
// rather than storing the property in a Declaration. aPropID
// must be a longhand property.
void ParseLonghandProperty(const nsCSSProperty aPropID,
const nsAString& aPropValue,
nsIURI* aSheetURL,
nsIURI* aBaseURL,
nsIPrincipal* aSheetPrincipal,
nsCSSValue& aResult);
// Parse the value of a CSS transform property. Returns
// whether the value was successfully parsed. If
// aDisallowRelativeValues is true then this method will
// only successfully parse if all values are numbers or
// have non-relative dimensions.
bool ParseTransformProperty(const nsAString& aPropValue,
bool aDisallowRelativeValues,
nsCSSValue& aResult);
// The same as ParseProperty but for a variable.
void ParseVariable(const nsAString& aVariableName,
const nsAString& aPropValue,
nsIURI* aSheetURL,
nsIURI* aBaseURL,
nsIPrincipal* aSheetPrincipal,
mozilla::css::Declaration* aDeclaration,
bool* aChanged,
bool aIsImportant);
/**
* Parse aBuffer into a media list |aMediaList|, which must be
* non-null, replacing its current contents. If aHTMLMode is true,
* parse according to HTML rules, with commas as the most important
* delimiter. Otherwise, parse according to CSS rules, with
* parentheses and strings more important than commas. |aURL| and
* |aLineNumber| are used for error reporting.
*/
void ParseMediaList(const nsSubstring& aBuffer,
nsIURI* aURL,
uint32_t aLineNumber,
nsMediaList* aMediaList,
bool aHTMLMode);
/*
* Parse aBuffer into a list of media queries and their associated values,
* according to grammar:
* <source-size-list> = <source-size>#?
* <source-size> = <media-condition>? <length>
*
* Note that this grammar is top-level: The function expects to consume the
* entire input buffer.
*
* Output arrays overwritten (not appended) and are cleared in case of parse
* failure.
*/
bool ParseSourceSizeList(const nsAString& aBuffer,
nsIURI* aURI, // for error reporting
uint32_t aLineNumber, // for error reporting
InfallibleTArray< nsAutoPtr<nsMediaQuery> >& aQueries,
InfallibleTArray<nsCSSValue>& aValues,
bool aHTMLMode);
/**
* Parse aBuffer into a nsCSSValue |aValue|. Will return false
* if aBuffer is not a valid font family list.
*/
bool ParseFontFamilyListString(const nsSubstring& aBuffer,
nsIURI* aURL,
uint32_t aLineNumber,
nsCSSValue& aValue);
/**
* Parse aBuffer into a nsCSSValue |aValue|. Will return false
* if aBuffer is not a valid CSS color specification.
* One can use nsRuleNode::ComputeColor to compute an nscolor from
* the returned nsCSSValue.
*/
bool ParseColorString(const nsSubstring& aBuffer,
nsIURI* aURL,
uint32_t aLineNumber,
nsCSSValue& aValue,
bool aSuppressErrors = false);
/**
* Parse aBuffer into a selector list. On success, caller must
* delete *aSelectorList when done with it.
*/
nsresult ParseSelectorString(const nsSubstring& aSelectorString,
nsIURI* aURL,
uint32_t aLineNumber,
nsCSSSelectorList** aSelectorList);
/*
* Parse a keyframe rule (which goes inside an @keyframes rule).
* Return it if the parse was successful.
*/
already_AddRefed<nsCSSKeyframeRule>
ParseKeyframeRule(const nsSubstring& aBuffer,
nsIURI* aURL,
uint32_t aLineNumber);
/*
* Parse a selector list for a keyframe rule. Return whether
* the parse succeeded.
*/
bool ParseKeyframeSelectorString(const nsSubstring& aSelectorString,
nsIURI* aURL,
uint32_t aLineNumber,
InfallibleTArray<float>& aSelectorList);
/**
* Parse a property and value and return whether the property/value pair
* is supported.
*/
bool EvaluateSupportsDeclaration(const nsAString& aProperty,
const nsAString& aValue,
nsIURI* aDocURL,
nsIURI* aBaseURL,
nsIPrincipal* aDocPrincipal);
/**
* Parse an @supports condition and returns the result of evaluating the
* condition.
*/
bool EvaluateSupportsCondition(const nsAString& aCondition,
nsIURI* aDocURL,
nsIURI* aBaseURL,
nsIPrincipal* aDocPrincipal);
typedef void (*VariableEnumFunc)(const nsAString&, void*);
/**
* Parses aPropertyValue as a property value and calls aFunc for each
* variable reference that is found. Returns false if there was
* a syntax error in the use of variable references.
*/
bool EnumerateVariableReferences(const nsAString& aPropertyValue,
VariableEnumFunc aFunc,
void* aData);
/**
* Parses aPropertyValue as a property value and resolves variable references
* using the values in aVariables.
*/
bool ResolveVariableValue(const nsAString& aPropertyValue,
const mozilla::CSSVariableValues* aVariables,
nsString& aResult,
nsCSSTokenSerializationType& aFirstToken,
nsCSSTokenSerializationType& aLastToken);
/**
* Parses a string as a CSS token stream value for particular property,
* resolving any variable references. The parsed property value is stored
* in the specified nsRuleData object. If aShorthandPropertyID has a value
* other than eCSSProperty_UNKNOWN, this is the property that will be parsed;
* otherwise, aPropertyID will be parsed. Either way, only aPropertyID,
* a longhand property, will be copied over to the rule data.
*
* If the property cannot be parsed, it will be treated as if 'initial' or
* 'inherit' were specified, for non-inherited and inherited properties
* respectively.
*/
void ParsePropertyWithVariableReferences(
nsCSSProperty aPropertyID,
nsCSSProperty aShorthandPropertyID,
const nsAString& aValue,
const mozilla::CSSVariableValues* aVariables,
nsRuleData* aRuleData,
nsIURI* aDocURL,
nsIURI* aBaseURL,
nsIPrincipal* aDocPrincipal,
mozilla::CSSStyleSheet* aSheet,
uint32_t aLineNumber,
uint32_t aLineOffset);
bool ParseCounterStyleName(const nsAString& aBuffer,
nsIURI* aURL,
nsAString& aName);
bool ParseCounterDescriptor(nsCSSCounterDesc aDescID,
const nsAString& aBuffer,
nsIURI* aSheetURL,
nsIURI* aBaseURL,
nsIPrincipal* aSheetPrincipal,
nsCSSValue& aValue);
bool ParseFontFaceDescriptor(nsCSSFontDesc aDescID,
const nsAString& aBuffer,
nsIURI* aSheetURL,
nsIURI* aBaseURL,
nsIPrincipal* aSheetPrincipal,
nsCSSValue& aValue);
// Check whether a given value can be applied to a property.
bool IsValueValidForProperty(const nsCSSProperty aPropID,
const nsAString& aPropValue);
// Return the default value to be used for -moz-control-character-visibility,
// from preferences (cached by our Startup(), so that both nsStyleText and
// nsRuleNode can have fast access to it).
static uint8_t ControlCharVisibilityDefault();
protected:
// This is a CSSParserImpl*, but if we expose that type name in this
// header, we can't put the type definition (in nsCSSParser.cpp) in
// the anonymous namespace.
void* mImpl;
};
#endif /* nsCSSParser_h___ */