layout/style/nsCSSPropertySet.h

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 /* bit vectors for sets of CSS properties */
michael@0 6
michael@0 7 #ifndef nsCSSPropertySet_h__
michael@0 8 #define nsCSSPropertySet_h__
michael@0 9
michael@0 10 #include "mozilla/ArrayUtils.h"
michael@0 11
michael@0 12 #include "nsCSSProperty.h"
michael@0 13 #include <limits.h> // for CHAR_BIT
michael@0 14
michael@0 15 /**
michael@0 16 * nsCSSPropertySet maintains a set of non-shorthand CSS properties. In
michael@0 17 * other words, for each longhand CSS property we support, it has a bit
michael@0 18 * for whether that property is in the set.
michael@0 19 */
michael@0 20 class nsCSSPropertySet {
michael@0 21 public:
michael@0 22 nsCSSPropertySet() { Empty(); }
michael@0 23 // auto-generated copy-constructor OK
michael@0 24
michael@0 25 void AssertInSetRange(nsCSSProperty aProperty) const {
michael@0 26 NS_ASSERTION(0 <= aProperty &&
michael@0 27 aProperty < eCSSProperty_COUNT_no_shorthands,
michael@0 28 "out of bounds");
michael@0 29 }
michael@0 30
michael@0 31 // Conversion of aProperty to |size_t| after AssertInSetRange
michael@0 32 // lets the compiler generate significantly tighter code.
michael@0 33
michael@0 34 void AddProperty(nsCSSProperty aProperty) {
michael@0 35 AssertInSetRange(aProperty);
michael@0 36 size_t p = aProperty;
michael@0 37 mProperties[p / kBitsInChunk] |=
michael@0 38 property_set_type(1) << (p % kBitsInChunk);
michael@0 39 }
michael@0 40
michael@0 41 void RemoveProperty(nsCSSProperty aProperty) {
michael@0 42 AssertInSetRange(aProperty);
michael@0 43 size_t p = aProperty;
michael@0 44 mProperties[p / kBitsInChunk] &=
michael@0 45 ~(property_set_type(1) << (p % kBitsInChunk));
michael@0 46 }
michael@0 47
michael@0 48 bool HasProperty(nsCSSProperty aProperty) const {
michael@0 49 AssertInSetRange(aProperty);
michael@0 50 size_t p = aProperty;
michael@0 51 return (mProperties[p / kBitsInChunk] &
michael@0 52 (property_set_type(1) << (p % kBitsInChunk))) != 0;
michael@0 53 }
michael@0 54
michael@0 55 void Empty() {
michael@0 56 memset(mProperties, 0, sizeof(mProperties));
michael@0 57 }
michael@0 58
michael@0 59 void AssertIsEmpty(const char* aText) const {
michael@0 60 for (size_t i = 0; i < mozilla::ArrayLength(mProperties); ++i) {
michael@0 61 NS_ASSERTION(mProperties[i] == 0, aText);
michael@0 62 }
michael@0 63 }
michael@0 64
michael@0 65 private:
michael@0 66 typedef unsigned long property_set_type;
michael@0 67 public:
michael@0 68 // number of bits in |property_set_type|.
michael@0 69 static const size_t kBitsInChunk = sizeof(property_set_type)*CHAR_BIT;
michael@0 70 // number of |property_set_type|s in the set
michael@0 71 static const size_t kChunkCount =
michael@0 72 (eCSSProperty_COUNT_no_shorthands + kBitsInChunk - 1) / kBitsInChunk;
michael@0 73
michael@0 74 /*
michael@0 75 * For fast enumeration of all the bits that are set, callers can
michael@0 76 * check each chunk against zero (since in normal cases few bits are
michael@0 77 * likely to be set).
michael@0 78 */
michael@0 79 bool HasPropertyInChunk(size_t aChunk) const {
michael@0 80 return mProperties[aChunk] != 0;
michael@0 81 }
michael@0 82 bool HasPropertyAt(size_t aChunk, size_t aBit) const {
michael@0 83 return (mProperties[aChunk] & (property_set_type(1) << aBit)) != 0;
michael@0 84 }
michael@0 85 static nsCSSProperty CSSPropertyAt(size_t aChunk, size_t aBit) {
michael@0 86 return nsCSSProperty(aChunk * kBitsInChunk + aBit);
michael@0 87 }
michael@0 88
michael@0 89 private:
michael@0 90 property_set_type mProperties[kChunkCount];
michael@0 91 };
michael@0 92
michael@0 93 #endif /* !defined(nsCSSPropertySet_h__) */

mercurial