author Gerald Squelart <>
Fri, 11 Nov 2016 11:25:52 +1100
changeset 367314 680467d99ed63d1b3a37e5c61d3c4302f5181418
parent 271829 7617f4ffb3145987ec717a29789ff5636889fbf8
child 399001 e4062da24f6b02d3d6998088e82d780a07047e63
permissions -rw-r--r--
Bug 1316524 - Use 'media.wmf.skip-blacklist' to set some gfxVars - r=mattwoodrow Reversing bug 1313343, as MediaPrefs are not available from the UI process. Instead media.wmf.skip-blacklist is used when setting D3D-blacklisting gfxVars, leaving them empty if we want to skip these blacklists. MozReview-Commit-ID: JYED4ovC0jq

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* 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 */


#include "txOutputFormat.h"
#include "txExpandedNameMap.h"
#include "txList.h"
#include "txXSLTPatterns.h"
#include "nsISupportsImpl.h"

class txInstruction;
class txTemplateItem;
class txVariableItem;
class txStripSpaceItem;
class txAttributeSetItem;
class txDecimalFormat;
class txStripSpaceTest;
class txXSLKey;

class txStylesheet final
    class ImportFrame;
    class GlobalVariable;
    friend class txStylesheetCompilerState;
    // To be able to do some cleaning up in destructor
    friend class ImportFrame;

    nsresult init();

    txInstruction* findTemplate(const txXPathNode& aNode,
                                const txExpandedName& aMode,
                                txIMatchContext* aContext,
                                ImportFrame* aImportedBy,
                                ImportFrame** aImportFrame);
    txDecimalFormat* getDecimalFormat(const txExpandedName& aName);
    txInstruction* getAttributeSet(const txExpandedName& aName);
    txInstruction* getNamedTemplate(const txExpandedName& aName);
    txOutputFormat* getOutputFormat();
    GlobalVariable* getGlobalVariable(const txExpandedName& aName);
    const txOwningExpandedNameMap<txXSLKey>& getKeyMap();
    bool isStripSpaceAllowed(const txXPathNode& aNode,
                               txIMatchContext* aContext);

     * Called by the stylesheet compiler once all stylesheets has been read.
    nsresult doneCompiling();

     * Add a key to the stylesheet
    nsresult addKey(const txExpandedName& aName, nsAutoPtr<txPattern> aMatch,
                    nsAutoPtr<Expr> aUse);

     * Add a decimal-format to the stylesheet
    nsresult addDecimalFormat(const txExpandedName& aName,
                              nsAutoPtr<txDecimalFormat>&& aFormat);

    struct MatchableTemplate {
        txInstruction* mFirstInstruction;
        nsAutoPtr<txPattern> mMatch;
        double mPriority;

     * Contain information that is import precedence dependant.
    class ImportFrame {
            : mFirstNotImported(nullptr)

        // List of toplevel items
        txList mToplevelItems;

        // Map of template modes
        txOwningExpandedNameMap< nsTArray<MatchableTemplate> > mMatchableTemplates;

        // ImportFrame which is the first one *not* imported by this frame
        ImportFrame* mFirstNotImported;

    class GlobalVariable : public txObject {
        GlobalVariable(nsAutoPtr<Expr>&& aExpr,
                       nsAutoPtr<txInstruction>&& aFirstInstruction,
                       bool aIsParam);

        nsAutoPtr<Expr> mExpr;
        nsAutoPtr<txInstruction> mFirstInstruction;
        bool mIsParam;

    // Private destructor, to discourage deletion outside of Release():

    nsresult addTemplate(txTemplateItem* aTemplate, ImportFrame* aImportFrame);
    nsresult addGlobalVariable(txVariableItem* aVariable);
    nsresult addFrames(txListIterator& aInsertIter);
    nsresult addStripSpace(txStripSpaceItem* aStripSpaceItem,
                           nsTArray<txStripSpaceTest*>& aFrameStripSpaceTests);
    nsresult addAttributeSet(txAttributeSetItem* aAttributeSetItem);

    // List of ImportFrames
    txList mImportFrames;
    // output format
    txOutputFormat mOutputFormat;

    // List of first instructions of templates. This is the owner of all
    // instructions used in templates
    txList mTemplateInstructions;
    // Root importframe
    ImportFrame* mRootFrame;
    // Named templates
    txExpandedNameMap<txInstruction> mNamedTemplates;
    // Map with all decimal-formats
    txOwningExpandedNameMap<txDecimalFormat> mDecimalFormats;

    // Map with all named attribute sets
    txExpandedNameMap<txInstruction> mAttributeSets;
    // Map with all global variables and parameters
    txOwningExpandedNameMap<GlobalVariable> mGlobalVariables;
    // Map with all keys
    txOwningExpandedNameMap<txXSLKey> mKeys;
    // Array of all txStripSpaceTests, sorted in acending order
    nsTArray<nsAutoPtr<txStripSpaceTest> > mStripSpaceTests;
    // Default templates
    nsAutoPtr<txInstruction> mContainerTemplate;
    nsAutoPtr<txInstruction> mCharactersTemplate;
    nsAutoPtr<txInstruction> mEmptyTemplate;

 * txStripSpaceTest holds both an txNameTest and a bool for use in
 * whitespace stripping.
class txStripSpaceTest {
    txStripSpaceTest(nsIAtom* aPrefix, nsIAtom* aLocalName, int32_t aNSID,
                     bool stripSpace)
        : mNameTest(aPrefix, aLocalName, aNSID, txXPathNodeType::ELEMENT_NODE),

    bool matches(const txXPathNode& aNode, txIMatchContext* aContext) {
        return mNameTest.matches(aNode, aContext);

    bool stripsSpace() {
        return mStrips;

    double getDefaultPriority() {
        return mNameTest.getDefaultPriority();

    txNameTest mNameTest;
    bool mStrips;

 * Value of a global parameter
class txIGlobalParameter
    virtual ~txIGlobalParameter()
    virtual nsresult getValue(txAExprResult** aValue) = 0;