content/xul/templates/src/nsTemplateMatch.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/xul/templates/src/nsTemplateMatch.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,138 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nsTemplateMatch_h__
    1.10 +#define nsTemplateMatch_h__
    1.11 +
    1.12 +#include "nsIContent.h"
    1.13 +#include "nsIXULTemplateQueryProcessor.h"
    1.14 +#include "nsIXULTemplateResult.h"
    1.15 +#include "nsRuleNetwork.h"
    1.16 +
    1.17 +/**
    1.18 + * A match object, where each match object is associated with one result.
    1.19 + * There will be one match list for each unique id generated. However, since
    1.20 + * there are multiple querysets and each may generate results with the same
    1.21 + * id, they are all chained together in a linked list, ordered in the same
    1.22 + * order as the respective <queryset> elements they were generated from.
    1.23 + * A match can be identified by the container and id. The id is retrievable
    1.24 + * from the result.
    1.25 + *
    1.26 + * Only one match per container and id pair is active at a time, but which
    1.27 + * match is active may change as new results are added or removed. When a
    1.28 + * match is active, content is generated for that match.
    1.29 + *
    1.30 + * Matches are stored and owned by the mMatchToMap hash in the template
    1.31 + * builder.
    1.32 + */
    1.33 +
    1.34 +class nsTemplateRule;
    1.35 +class nsTemplateQuerySet;
    1.36 +
    1.37 +class nsTemplateMatch {
    1.38 +private:
    1.39 +    // Hide so that only Create() and Destroy() can be used to
    1.40 +    // allocate and deallocate from the heap
    1.41 +    void* operator new(size_t) CPP_THROW_NEW { MOZ_ASSERT(0); return nullptr; }
    1.42 +    void operator delete(void*, size_t) { MOZ_ASSERT(0); }
    1.43 +
    1.44 +public:
    1.45 +    nsTemplateMatch(uint16_t aQuerySetPriority,
    1.46 +                    nsIXULTemplateResult* aResult,
    1.47 +                    nsIContent* aContainer)
    1.48 +        : mRuleIndex(-1),
    1.49 +          mQuerySetPriority(aQuerySetPriority),
    1.50 +          mContainer(aContainer),
    1.51 +          mResult(aResult),
    1.52 +          mNext(nullptr)
    1.53 +    {
    1.54 +      MOZ_COUNT_CTOR(nsTemplateMatch);
    1.55 +    }
    1.56 +
    1.57 +    ~nsTemplateMatch()
    1.58 +    {
    1.59 +      MOZ_COUNT_DTOR(nsTemplateMatch);
    1.60 +    }
    1.61 +
    1.62 +    static nsTemplateMatch*
    1.63 +    Create(uint16_t aQuerySetPriority,
    1.64 +           nsIXULTemplateResult* aResult,
    1.65 +           nsIContent* aContainer) {
    1.66 +        return ::new nsTemplateMatch(aQuerySetPriority, aResult, aContainer);
    1.67 +    }
    1.68 +
    1.69 +    static void Destroy(nsTemplateMatch*& aMatch, bool aRemoveResult);
    1.70 +
    1.71 +    // return true if the the match is active, and has generated output
    1.72 +    bool IsActive() {
    1.73 +        return mRuleIndex >= 0;
    1.74 +    }
    1.75 +
    1.76 +    // indicate that a rule is no longer active, used when a query with a
    1.77 +    // lower priority has overriden the match
    1.78 +    void SetInactive() {
    1.79 +        mRuleIndex = -1;
    1.80 +    }
    1.81 +
    1.82 +    // return matching rule index
    1.83 +    int16_t RuleIndex() {
    1.84 +        return mRuleIndex;
    1.85 +    }
    1.86 +
    1.87 +    // return priority of query set
    1.88 +    uint16_t QuerySetPriority() {
    1.89 +        return mQuerySetPriority;
    1.90 +    }
    1.91 +
    1.92 +    // return container, not addrefed. May be null.
    1.93 +    nsIContent* GetContainer() {
    1.94 +        return mContainer;
    1.95 +    }
    1.96 +
    1.97 +    nsresult RuleMatched(nsTemplateQuerySet* aQuerySet,
    1.98 +                         nsTemplateRule* aRule,
    1.99 +                         int16_t aRuleIndex,
   1.100 +                         nsIXULTemplateResult* aResult);
   1.101 +
   1.102 +private:
   1.103 +
   1.104 +    /**
   1.105 +     * The index of the rule that matched, or -1 if the match is not active.
   1.106 +     */
   1.107 +    int16_t mRuleIndex;
   1.108 +
   1.109 +    /**
   1.110 +     * The priority of the queryset for this rule
   1.111 +     */
   1.112 +    uint16_t mQuerySetPriority;
   1.113 +
   1.114 +    /**
   1.115 +     * The container the content generated for the match is inside.
   1.116 +     */
   1.117 +    nsCOMPtr<nsIContent> mContainer;
   1.118 +
   1.119 +public:
   1.120 +
   1.121 +    /**
   1.122 +     * The result associated with this match
   1.123 +     */
   1.124 +    nsCOMPtr<nsIXULTemplateResult> mResult;
   1.125 +
   1.126 +    /**
   1.127 +     * Matches are stored in a linked list, in priority order. This first
   1.128 +     * match that has a rule set (mRule) is the active match and generates
   1.129 +     * content. The next match is owned by the builder, which will delete
   1.130 +     * template matches when needed.
   1.131 +     */
   1.132 +    nsTemplateMatch *mNext;
   1.133 +
   1.134 +private:
   1.135 +
   1.136 +    nsTemplateMatch(const nsTemplateMatch& aMatch); // not to be implemented
   1.137 +    void operator=(const nsTemplateMatch& aMatch); // not to be implemented
   1.138 +};
   1.139 +
   1.140 +#endif // nsTemplateMatch_h__
   1.141 +

mercurial