Bug 1448759 part 1 - Make KTableEntry an independent type. r=heycam

MozReview-Commit-ID: oZfJAigThN

--HG--
extra : rebase_source : 6a0efbf40fed8c9eaba7bb3af74d281b536677c8
This commit is contained in:
Xidorn Quan 2018-04-29 21:17:26 +10:00
Родитель 3eabec8954
Коммит f2ba299166
8 изменённых файлов: 46 добавлений и 42 удалений

Просмотреть файл

@ -14,6 +14,7 @@
#include "mozilla/mozalloc.h"
#include "nsAString.h"
#include "nsCOMPtr.h"
#include "nsCSSProps.h"
#include "nsColor.h"
#include "nsComputedDOMStyle.h"
#include "nsDebug.h"

Просмотреть файл

@ -77,6 +77,7 @@ headers = [
"mozilla/ServoDeclarationBlock.h",
"mozilla/ServoTraversalStatistics.h",
"mozilla/SizeOfState.h",
"nsCSSProps.h",
"nsContentUtils.h",
"nsNameSpaceManager.h",
"nsMediaFeatures.h",
@ -272,6 +273,7 @@ whitelist-types = [
"nsChangeHint",
"nsCSSCounterDesc",
"nsCSSFontDesc",
"nsCSSKTableEntry",
"nsCSSKeyword",
"nsCSSPropertyID",
"nsCSSPropertyIDSet",

Просмотреть файл

@ -29,40 +29,41 @@
// and, in the future, custom media query names).
#define CSS_CUSTOM_NAME_PREFIX_LENGTH 2
struct nsCSSKTableEntry
{
// nsCSSKTableEntry objects can be initialized either with an int16_t value
// or a value of an enumeration type that can fit within an int16_t.
constexpr nsCSSKTableEntry(nsCSSKeyword aKeyword, int16_t aValue)
: mKeyword(aKeyword)
, mValue(aValue)
{
}
template<typename T,
typename = typename std::enable_if<std::is_enum<T>::value>::type>
constexpr nsCSSKTableEntry(nsCSSKeyword aKeyword, T aValue)
: mKeyword(aKeyword)
, mValue(static_cast<int16_t>(aValue))
{
static_assert(mozilla::EnumTypeFitsWithin<T, int16_t>::value,
"aValue must be an enum that fits within mValue");
}
bool IsSentinel() const
{
return mKeyword == eCSSKeyword_UNKNOWN && mValue == -1;
}
nsCSSKeyword mKeyword;
int16_t mValue;
};
class nsCSSProps {
public:
typedef mozilla::CSSEnabledState EnabledState;
typedef mozilla::CSSPropFlags Flags;
struct KTableEntry
{
// KTableEntry objects can be initialized either with an int16_t value
// or a value of an enumeration type that can fit within an int16_t.
constexpr KTableEntry(nsCSSKeyword aKeyword, int16_t aValue)
: mKeyword(aKeyword)
, mValue(aValue)
{
}
template<typename T,
typename = typename std::enable_if<std::is_enum<T>::value>::type>
constexpr KTableEntry(nsCSSKeyword aKeyword, T aValue)
: mKeyword(aKeyword)
, mValue(static_cast<int16_t>(aValue))
{
static_assert(mozilla::EnumTypeFitsWithin<T, int16_t>::value,
"aValue must be an enum that fits within mValue");
}
bool IsSentinel() const
{
return mKeyword == eCSSKeyword_UNKNOWN && mValue == -1;
}
nsCSSKeyword mKeyword;
int16_t mValue;
};
typedef nsCSSKTableEntry KTableEntry;
static void AddRefTable(void);
static void ReleaseTable(void);

Просмотреть файл

@ -88,7 +88,7 @@ already_AddRefed<CSSValue>
GetBackgroundList(T nsStyleImageLayers::Layer::* aMember,
uint32_t nsStyleImageLayers::* aCount,
const nsStyleImageLayers& aLayers,
const nsCSSProps::KTableEntry aTable[])
const nsCSSKTableEntry aTable[])
{
RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(true);

Просмотреть файл

@ -17,7 +17,6 @@
#include "nsCOMPtr.h"
#include "nsContentUtils.h"
#include "nscore.h"
#include "nsCSSProps.h"
#include "nsDOMCSSDeclaration.h"
#include "mozilla/ComputedStyle.h"
#include "nsIWeakReferenceUtils.h"
@ -36,6 +35,7 @@ struct ComputedGridTrackInfo;
} // namespace mozilla
struct ComputedStyleMap;
struct nsCSSKTableEntry;
class nsIFrame;
class nsIPresShell;
class nsDOMCSSValueList;
@ -54,7 +54,7 @@ class nsComputedDOMStyle final : public nsDOMCSSDeclaration
{
private:
// Convenience typedefs:
typedef nsCSSProps::KTableEntry KTableEntry;
typedef nsCSSKTableEntry KTableEntry;
typedef mozilla::dom::CSSValue CSSValue;
typedef mozilla::StyleGeometryBox StyleGeometryBox;

Просмотреть файл

@ -11,6 +11,7 @@
#include "nsCSSKeywords.h"
#include "nsStyleConsts.h"
#include "nsPresContext.h"
#include "nsCSSProps.h"
#include "nsCSSValue.h"
#ifdef XP_WIN
#include "mozilla/LookAndFeel.h"
@ -33,19 +34,19 @@ static nsTArray<RefPtr<nsAtom>>* sSystemMetrics = nullptr;
static uint8_t sWinThemeId = LookAndFeel::eWindowsTheme_Generic;
#endif
static const nsCSSProps::KTableEntry kOrientationKeywords[] = {
static const nsCSSKTableEntry kOrientationKeywords[] = {
{ eCSSKeyword_portrait, StyleOrientation::Portrait },
{ eCSSKeyword_landscape, StyleOrientation::Landscape },
{ eCSSKeyword_UNKNOWN, -1 }
};
static const nsCSSProps::KTableEntry kScanKeywords[] = {
static const nsCSSKTableEntry kScanKeywords[] = {
{ eCSSKeyword_progressive, StyleScan::Progressive },
{ eCSSKeyword_interlace, StyleScan::Interlace },
{ eCSSKeyword_UNKNOWN, -1 }
};
static const nsCSSProps::KTableEntry kDisplayModeKeywords[] = {
static const nsCSSKTableEntry kDisplayModeKeywords[] = {
{ eCSSKeyword_browser, StyleDisplayMode::Browser },
{ eCSSKeyword_minimal_ui, StyleDisplayMode::MinimalUi },
{ eCSSKeyword_standalone, StyleDisplayMode::Standalone },

Просмотреть файл

@ -9,10 +9,9 @@
#ifndef nsMediaFeatures_h_
#define nsMediaFeatures_h_
#include "nsCSSProps.h"
class nsAtom;
class nsIDocument;
struct nsCSSKTableEntry;
class nsCSSValue;
class nsStaticAtom;
@ -71,7 +70,7 @@ struct nsMediaFeature
const void* mInitializer_;
// If mValueType == eEnumerated: const int32_t*: keyword table in
// the same format as the keyword tables in nsCSSProps.
const nsCSSProps::KTableEntry* mKeywordTable;
const nsCSSKTableEntry* mKeywordTable;
// If mGetter == GetSystemMetric (which implies mValueType ==
// eBoolInteger): nsAtom * const *, for the system metric.
nsAtom * const * mMetric;

Просмотреть файл

@ -13,7 +13,7 @@ use euclid::TypedScale;
use gecko::values::{convert_nscolor_to_rgba, convert_rgba_to_nscolor};
use gecko_bindings::bindings;
use gecko_bindings::structs;
use gecko_bindings::structs::{nsCSSKeyword, nsCSSProps_KTableEntry, nsCSSUnit, nsCSSValue};
use gecko_bindings::structs::{nsCSSKTableEntry, nsCSSKeyword, nsCSSUnit, nsCSSValue};
use gecko_bindings::structs::{nsMediaFeature, nsMediaFeature_RangeType};
use gecko_bindings::structs::{nsMediaFeature_ValueType, nsPresContext};
use gecko_bindings::structs::RawGeckoPresContextOwned;
@ -479,7 +479,7 @@ where
}
unsafe fn find_in_table<F>(
mut current_entry: *const nsCSSProps_KTableEntry,
mut current_entry: *const nsCSSKTableEntry,
mut f: F,
) -> Option<(nsCSSKeyword, i16)>
where
@ -544,7 +544,7 @@ fn parse_feature_value<'i, 't>(
bindings::Gecko_LookupCSSKeyword(keyword.as_bytes().as_ptr(), keyword.len() as u32)
};
let first_table_entry: *const nsCSSProps_KTableEntry =
let first_table_entry: *const nsCSSKTableEntry =
unsafe { *feature.mData.mKeywordTable.as_ref() };
let value = match unsafe { find_in_table(first_table_entry, |kw, _| kw == keyword) } {