2019-05-09 15:43:19 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
/* Some inline functions declared in cbindgen.toml */
|
|
|
|
|
|
|
|
#ifndef mozilla_ServoStyleConstsInlines_h
|
|
|
|
#define mozilla_ServoStyleConstsInlines_h
|
|
|
|
|
|
|
|
#include "mozilla/ServoStyleConsts.h"
|
2020-02-10 20:12:44 +03:00
|
|
|
#include "mozilla/EndianUtils.h"
|
Bug 1552708 - Use cbindgen for URIs. r=heycam
This doesn't clean up as much as a whole, but it's a step in the right
direction. In particular, it allows us to start using simple bindings for:
* Filters
* Shapes and images, almost. Need to:
* Get rid of the complex -moz- gradient parsing (let
layout.css.simple-moz-gradient.enabled get to release).
* Counters, almost. Need to:
* Share the Attr representation with Gecko, by not using Option<>.
* Just another variant should be enough (ContentItem::{Attr,Prefixedattr},
maybe).
Which in turn allows us to remove a whole lot of bindings in followups to this.
The setup changes a bit. This also removes the double pointer I complained about
while reviewing the shared UA sheet patches. The old setup is:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* UrlValueSource
* Arc<CssUrlData>
* load id
* resolved uri
* CORS mode.
* ...
```
The new one removes the double reference to the url data via URLValue, and looks
like:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* CorsMode
* LoadData
* load id
* resolved URI
```
The LoadData is the only mutable bit that C++ can change, and is not used from
Rust. Ideally, in the future, we could just use rust-url to resolve the URL
after parsing or something, and make it all immutable. Maybe.
I've verified that this approach still works with the UA sheet patches (via the
LoadDataSource::Lazy).
The reordering of mWillChange is to avoid nsStyleDisplay from going over the
size limit. We want to split it up anyway in bug 1552587, but mBinding gains a
tag member, which means that we were having a bit of extra padding.
One thing I want to explore is to see if we can abuse rustc's non-zero
optimizations to predict the layout from C++, but that's something to explore at
some other point in time and with a lot of care and help from Michael (who sits
next to me and works on rustc ;)).
Differential Revision: https://phabricator.services.mozilla.com/D31742
2019-05-27 14:45:12 +03:00
|
|
|
#include "mozilla/URLExtraData.h"
|
2019-05-17 02:03:29 +03:00
|
|
|
#include "nsGkAtoms.h"
|
Bug 1552708 - Use cbindgen for URIs. r=heycam
This doesn't clean up as much as a whole, but it's a step in the right
direction. In particular, it allows us to start using simple bindings for:
* Filters
* Shapes and images, almost. Need to:
* Get rid of the complex -moz- gradient parsing (let
layout.css.simple-moz-gradient.enabled get to release).
* Counters, almost. Need to:
* Share the Attr representation with Gecko, by not using Option<>.
* Just another variant should be enough (ContentItem::{Attr,Prefixedattr},
maybe).
Which in turn allows us to remove a whole lot of bindings in followups to this.
The setup changes a bit. This also removes the double pointer I complained about
while reviewing the shared UA sheet patches. The old setup is:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* UrlValueSource
* Arc<CssUrlData>
* load id
* resolved uri
* CORS mode.
* ...
```
The new one removes the double reference to the url data via URLValue, and looks
like:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* CorsMode
* LoadData
* load id
* resolved URI
```
The LoadData is the only mutable bit that C++ can change, and is not used from
Rust. Ideally, in the future, we could just use rust-url to resolve the URL
after parsing or something, and make it all immutable. Maybe.
I've verified that this approach still works with the UA sheet patches (via the
LoadDataSource::Lazy).
The reordering of mWillChange is to avoid nsStyleDisplay from going over the
size limit. We want to split it up anyway in bug 1552587, but mBinding gains a
tag member, which means that we were having a bit of extra padding.
One thing I want to explore is to see if we can abuse rustc's non-zero
optimizations to predict the layout from C++, but that's something to explore at
some other point in time and with a lot of care and help from Michael (who sits
next to me and works on rustc ;)).
Differential Revision: https://phabricator.services.mozilla.com/D31742
2019-05-27 14:45:12 +03:00
|
|
|
#include "MainThreadUtils.h"
|
|
|
|
#include "nsNetUtil.h"
|
2019-05-09 15:43:19 +03:00
|
|
|
#include <type_traits>
|
2019-05-17 02:04:32 +03:00
|
|
|
#include <new>
|
2019-05-09 15:43:19 +03:00
|
|
|
|
|
|
|
// TODO(emilio): there are quite a few other implementations scattered around
|
|
|
|
// that should move here.
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2020-02-06 01:20:29 +03:00
|
|
|
// We need to explicitly instantiate these so that the clang plugin can see that
|
|
|
|
// they're trivially copiable...
|
|
|
|
//
|
|
|
|
// https://github.com/eqrion/cbindgen/issues/402 tracks doing something like
|
|
|
|
// this automatically from cbindgen.
|
|
|
|
template struct StyleOwned<RawServoAnimationValueMap>;
|
|
|
|
template struct StyleOwned<RawServoAuthorStyles>;
|
|
|
|
template struct StyleOwned<RawServoSourceSizeList>;
|
|
|
|
template struct StyleOwned<StyleUseCounters>;
|
|
|
|
template struct StyleOwnedOrNull<StyleUseCounters>;
|
|
|
|
template struct StyleOwnedOrNull<RawServoSelectorList>;
|
|
|
|
template struct StyleStrong<ComputedStyle>;
|
|
|
|
template struct StyleStrong<ServoCssRules>;
|
|
|
|
template struct StyleStrong<RawServoAnimationValue>;
|
|
|
|
template struct StyleStrong<RawServoDeclarationBlock>;
|
|
|
|
template struct StyleStrong<RawServoStyleSheetContents>;
|
|
|
|
template struct StyleStrong<RawServoKeyframe>;
|
|
|
|
template struct StyleStrong<RawServoMediaList>;
|
|
|
|
template struct StyleStrong<RawServoStyleRule>;
|
|
|
|
template struct StyleStrong<RawServoImportRule>;
|
|
|
|
template struct StyleStrong<RawServoKeyframesRule>;
|
|
|
|
template struct StyleStrong<RawServoMediaRule>;
|
|
|
|
template struct StyleStrong<RawServoMozDocumentRule>;
|
|
|
|
template struct StyleStrong<RawServoNamespaceRule>;
|
|
|
|
template struct StyleStrong<RawServoPageRule>;
|
|
|
|
template struct StyleStrong<RawServoSupportsRule>;
|
|
|
|
template struct StyleStrong<RawServoFontFeatureValuesRule>;
|
|
|
|
template struct StyleStrong<RawServoFontFaceRule>;
|
|
|
|
template struct StyleStrong<RawServoCounterStyleRule>;
|
|
|
|
|
2019-05-17 02:04:32 +03:00
|
|
|
template <typename T>
|
2019-05-27 15:37:37 +03:00
|
|
|
inline void StyleOwnedSlice<T>::Clear() {
|
|
|
|
if (!len) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (size_t i : IntegerRange(len)) {
|
|
|
|
ptr[i].~T();
|
|
|
|
}
|
|
|
|
free(ptr);
|
|
|
|
ptr = (T*)alignof(T);
|
|
|
|
len = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline void StyleOwnedSlice<T>::CopyFrom(const StyleOwnedSlice& aOther) {
|
|
|
|
Clear();
|
2019-05-17 02:04:32 +03:00
|
|
|
len = aOther.len;
|
|
|
|
if (!len) {
|
|
|
|
ptr = (T*)alignof(T);
|
|
|
|
} else {
|
|
|
|
ptr = (T*)malloc(len * sizeof(T));
|
|
|
|
size_t i = 0;
|
|
|
|
for (const T& elem : aOther.AsSpan()) {
|
|
|
|
new (ptr + i++) T(elem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2019-05-27 15:37:37 +03:00
|
|
|
inline void StyleOwnedSlice<T>::SwapElements(StyleOwnedSlice& aOther) {
|
|
|
|
std::swap(ptr, aOther.ptr);
|
|
|
|
std::swap(len, aOther.len);
|
2019-05-27 15:37:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2019-05-27 15:37:37 +03:00
|
|
|
inline StyleOwnedSlice<T>::StyleOwnedSlice(const StyleOwnedSlice& aOther)
|
|
|
|
: StyleOwnedSlice() {
|
|
|
|
CopyFrom(aOther);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline StyleOwnedSlice<T>::StyleOwnedSlice(StyleOwnedSlice&& aOther)
|
|
|
|
: StyleOwnedSlice() {
|
|
|
|
SwapElements(aOther);
|
|
|
|
}
|
|
|
|
|
2020-01-22 23:20:38 +03:00
|
|
|
template <typename T>
|
|
|
|
inline StyleOwnedSlice<T>::StyleOwnedSlice(Vector<T>&& aVector)
|
|
|
|
: StyleOwnedSlice() {
|
|
|
|
if (!aVector.length()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We could handle this if Vector provided the relevant APIs, see bug 1610702.
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aVector.length() == aVector.capacity(),
|
|
|
|
"Shouldn't over-allocate");
|
|
|
|
len = aVector.length();
|
|
|
|
ptr = aVector.extractRawBuffer();
|
|
|
|
MOZ_ASSERT(ptr,
|
|
|
|
"How did extractRawBuffer return null if we're not using inline "
|
|
|
|
"capacity?");
|
|
|
|
}
|
|
|
|
|
2019-05-27 15:37:37 +03:00
|
|
|
template <typename T>
|
|
|
|
inline StyleOwnedSlice<T>& StyleOwnedSlice<T>::operator=(
|
|
|
|
const StyleOwnedSlice& aOther) {
|
|
|
|
CopyFrom(aOther);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline StyleOwnedSlice<T>& StyleOwnedSlice<T>::operator=(
|
|
|
|
StyleOwnedSlice&& aOther) {
|
|
|
|
Clear();
|
|
|
|
SwapElements(aOther);
|
|
|
|
return *this;
|
2019-05-17 02:04:32 +03:00
|
|
|
}
|
|
|
|
|
2019-05-17 02:05:54 +03:00
|
|
|
template <typename T>
|
|
|
|
inline StyleOwnedSlice<T>::~StyleOwnedSlice() {
|
|
|
|
Clear();
|
|
|
|
}
|
|
|
|
|
2019-05-09 15:43:19 +03:00
|
|
|
// This code is basically a C++ port of the Arc::clone() implementation in
|
|
|
|
// servo/components/servo_arc/lib.rs.
|
|
|
|
static constexpr const size_t kStaticRefcount =
|
|
|
|
std::numeric_limits<size_t>::max();
|
|
|
|
static constexpr const size_t kMaxRefcount =
|
|
|
|
std::numeric_limits<intptr_t>::max();
|
Bug 1552708 - Use cbindgen for URIs. r=heycam
This doesn't clean up as much as a whole, but it's a step in the right
direction. In particular, it allows us to start using simple bindings for:
* Filters
* Shapes and images, almost. Need to:
* Get rid of the complex -moz- gradient parsing (let
layout.css.simple-moz-gradient.enabled get to release).
* Counters, almost. Need to:
* Share the Attr representation with Gecko, by not using Option<>.
* Just another variant should be enough (ContentItem::{Attr,Prefixedattr},
maybe).
Which in turn allows us to remove a whole lot of bindings in followups to this.
The setup changes a bit. This also removes the double pointer I complained about
while reviewing the shared UA sheet patches. The old setup is:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* UrlValueSource
* Arc<CssUrlData>
* load id
* resolved uri
* CORS mode.
* ...
```
The new one removes the double reference to the url data via URLValue, and looks
like:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* CorsMode
* LoadData
* load id
* resolved URI
```
The LoadData is the only mutable bit that C++ can change, and is not used from
Rust. Ideally, in the future, we could just use rust-url to resolve the URL
after parsing or something, and make it all immutable. Maybe.
I've verified that this approach still works with the UA sheet patches (via the
LoadDataSource::Lazy).
The reordering of mWillChange is to avoid nsStyleDisplay from going over the
size limit. We want to split it up anyway in bug 1552587, but mBinding gains a
tag member, which means that we were having a bit of extra padding.
One thing I want to explore is to see if we can abuse rustc's non-zero
optimizations to predict the layout from C++, but that's something to explore at
some other point in time and with a lot of care and help from Michael (who sits
next to me and works on rustc ;)).
Differential Revision: https://phabricator.services.mozilla.com/D31742
2019-05-27 14:45:12 +03:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline void StyleArcInner<T>::IncrementRef() {
|
|
|
|
if (count.load(std::memory_order_relaxed) != kStaticRefcount) {
|
|
|
|
auto old_size = count.fetch_add(1, std::memory_order_relaxed);
|
|
|
|
if (MOZ_UNLIKELY(old_size > kMaxRefcount)) {
|
|
|
|
::abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is a C++ port-ish of Arc::drop().
|
|
|
|
template <typename T>
|
|
|
|
inline bool StyleArcInner<T>::DecrementRef() {
|
|
|
|
if (count.load(std::memory_order_relaxed) == kStaticRefcount) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (count.fetch_sub(1, std::memory_order_release) != 1) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-08-14 16:55:31 +03:00
|
|
|
#ifdef MOZ_TSAN
|
|
|
|
// TSan doesn't understand std::atomic_thread_fence, so in order
|
|
|
|
// to avoid a false positive for every time a refcounted object
|
|
|
|
// is deleted, we replace the fence with an atomic operation.
|
Bug 1552708 - Use cbindgen for URIs. r=heycam
This doesn't clean up as much as a whole, but it's a step in the right
direction. In particular, it allows us to start using simple bindings for:
* Filters
* Shapes and images, almost. Need to:
* Get rid of the complex -moz- gradient parsing (let
layout.css.simple-moz-gradient.enabled get to release).
* Counters, almost. Need to:
* Share the Attr representation with Gecko, by not using Option<>.
* Just another variant should be enough (ContentItem::{Attr,Prefixedattr},
maybe).
Which in turn allows us to remove a whole lot of bindings in followups to this.
The setup changes a bit. This also removes the double pointer I complained about
while reviewing the shared UA sheet patches. The old setup is:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* UrlValueSource
* Arc<CssUrlData>
* load id
* resolved uri
* CORS mode.
* ...
```
The new one removes the double reference to the url data via URLValue, and looks
like:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* CorsMode
* LoadData
* load id
* resolved URI
```
The LoadData is the only mutable bit that C++ can change, and is not used from
Rust. Ideally, in the future, we could just use rust-url to resolve the URL
after parsing or something, and make it all immutable. Maybe.
I've verified that this approach still works with the UA sheet patches (via the
LoadDataSource::Lazy).
The reordering of mWillChange is to avoid nsStyleDisplay from going over the
size limit. We want to split it up anyway in bug 1552587, but mBinding gains a
tag member, which means that we were having a bit of extra padding.
One thing I want to explore is to see if we can abuse rustc's non-zero
optimizations to predict the layout from C++, but that's something to explore at
some other point in time and with a lot of care and help from Michael (who sits
next to me and works on rustc ;)).
Differential Revision: https://phabricator.services.mozilla.com/D31742
2019-05-27 14:45:12 +03:00
|
|
|
count.load(std::memory_order_acquire);
|
2019-08-14 16:55:31 +03:00
|
|
|
#else
|
|
|
|
std::atomic_thread_fence(std::memory_order_acquire);
|
|
|
|
#endif
|
2019-05-16 05:35:34 +03:00
|
|
|
MOZ_LOG_DTOR(this, "ServoArc", 8);
|
Bug 1552708 - Use cbindgen for URIs. r=heycam
This doesn't clean up as much as a whole, but it's a step in the right
direction. In particular, it allows us to start using simple bindings for:
* Filters
* Shapes and images, almost. Need to:
* Get rid of the complex -moz- gradient parsing (let
layout.css.simple-moz-gradient.enabled get to release).
* Counters, almost. Need to:
* Share the Attr representation with Gecko, by not using Option<>.
* Just another variant should be enough (ContentItem::{Attr,Prefixedattr},
maybe).
Which in turn allows us to remove a whole lot of bindings in followups to this.
The setup changes a bit. This also removes the double pointer I complained about
while reviewing the shared UA sheet patches. The old setup is:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* UrlValueSource
* Arc<CssUrlData>
* load id
* resolved uri
* CORS mode.
* ...
```
The new one removes the double reference to the url data via URLValue, and looks
like:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* CorsMode
* LoadData
* load id
* resolved URI
```
The LoadData is the only mutable bit that C++ can change, and is not used from
Rust. Ideally, in the future, we could just use rust-url to resolve the URL
after parsing or something, and make it all immutable. Maybe.
I've verified that this approach still works with the UA sheet patches (via the
LoadDataSource::Lazy).
The reordering of mWillChange is to avoid nsStyleDisplay from going over the
size limit. We want to split it up anyway in bug 1552587, but mBinding gains a
tag member, which means that we were having a bit of extra padding.
One thing I want to explore is to see if we can abuse rustc's non-zero
optimizations to predict the layout from C++, but that's something to explore at
some other point in time and with a lot of care and help from Michael (who sits
next to me and works on rustc ;)).
Differential Revision: https://phabricator.services.mozilla.com/D31742
2019-05-27 14:45:12 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-05-17 02:22:04 +03:00
|
|
|
static constexpr const uint64_t kArcSliceCanary = 0xf3f3f3f3f3f3f3f3;
|
2019-05-09 15:43:19 +03:00
|
|
|
|
|
|
|
#define ASSERT_CANARY \
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(_0.ptr->data.header.header == kArcSliceCanary, "Uh?");
|
|
|
|
|
2019-05-17 02:03:29 +03:00
|
|
|
template <typename T>
|
|
|
|
inline StyleArcSlice<T>::StyleArcSlice() {
|
|
|
|
_0.ptr = reinterpret_cast<decltype(_0.ptr)>(Servo_StyleArcSlice_EmptyPtr());
|
Bug 1552708 - Use cbindgen for URIs. r=heycam
This doesn't clean up as much as a whole, but it's a step in the right
direction. In particular, it allows us to start using simple bindings for:
* Filters
* Shapes and images, almost. Need to:
* Get rid of the complex -moz- gradient parsing (let
layout.css.simple-moz-gradient.enabled get to release).
* Counters, almost. Need to:
* Share the Attr representation with Gecko, by not using Option<>.
* Just another variant should be enough (ContentItem::{Attr,Prefixedattr},
maybe).
Which in turn allows us to remove a whole lot of bindings in followups to this.
The setup changes a bit. This also removes the double pointer I complained about
while reviewing the shared UA sheet patches. The old setup is:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* UrlValueSource
* Arc<CssUrlData>
* load id
* resolved uri
* CORS mode.
* ...
```
The new one removes the double reference to the url data via URLValue, and looks
like:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* CorsMode
* LoadData
* load id
* resolved URI
```
The LoadData is the only mutable bit that C++ can change, and is not used from
Rust. Ideally, in the future, we could just use rust-url to resolve the URL
after parsing or something, and make it all immutable. Maybe.
I've verified that this approach still works with the UA sheet patches (via the
LoadDataSource::Lazy).
The reordering of mWillChange is to avoid nsStyleDisplay from going over the
size limit. We want to split it up anyway in bug 1552587, but mBinding gains a
tag member, which means that we were having a bit of extra padding.
One thing I want to explore is to see if we can abuse rustc's non-zero
optimizations to predict the layout from C++, but that's something to explore at
some other point in time and with a lot of care and help from Michael (who sits
next to me and works on rustc ;)).
Differential Revision: https://phabricator.services.mozilla.com/D31742
2019-05-27 14:45:12 +03:00
|
|
|
ASSERT_CANARY
|
2019-05-17 02:03:29 +03:00
|
|
|
}
|
|
|
|
|
2019-05-09 15:43:19 +03:00
|
|
|
template <typename T>
|
|
|
|
inline StyleArcSlice<T>::StyleArcSlice(const StyleArcSlice& aOther) {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aOther._0.ptr);
|
|
|
|
_0.ptr = aOther._0.ptr;
|
Bug 1552708 - Use cbindgen for URIs. r=heycam
This doesn't clean up as much as a whole, but it's a step in the right
direction. In particular, it allows us to start using simple bindings for:
* Filters
* Shapes and images, almost. Need to:
* Get rid of the complex -moz- gradient parsing (let
layout.css.simple-moz-gradient.enabled get to release).
* Counters, almost. Need to:
* Share the Attr representation with Gecko, by not using Option<>.
* Just another variant should be enough (ContentItem::{Attr,Prefixedattr},
maybe).
Which in turn allows us to remove a whole lot of bindings in followups to this.
The setup changes a bit. This also removes the double pointer I complained about
while reviewing the shared UA sheet patches. The old setup is:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* UrlValueSource
* Arc<CssUrlData>
* load id
* resolved uri
* CORS mode.
* ...
```
The new one removes the double reference to the url data via URLValue, and looks
like:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* CorsMode
* LoadData
* load id
* resolved URI
```
The LoadData is the only mutable bit that C++ can change, and is not used from
Rust. Ideally, in the future, we could just use rust-url to resolve the URL
after parsing or something, and make it all immutable. Maybe.
I've verified that this approach still works with the UA sheet patches (via the
LoadDataSource::Lazy).
The reordering of mWillChange is to avoid nsStyleDisplay from going over the
size limit. We want to split it up anyway in bug 1552587, but mBinding gains a
tag member, which means that we were having a bit of extra padding.
One thing I want to explore is to see if we can abuse rustc's non-zero
optimizations to predict the layout from C++, but that's something to explore at
some other point in time and with a lot of care and help from Michael (who sits
next to me and works on rustc ;)).
Differential Revision: https://phabricator.services.mozilla.com/D31742
2019-05-27 14:45:12 +03:00
|
|
|
_0.ptr->IncrementRef();
|
2019-05-09 15:43:19 +03:00
|
|
|
ASSERT_CANARY
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline StyleArcSlice<T>::StyleArcSlice(
|
|
|
|
const StyleForgottenArcSlicePtr<T>& aPtr) {
|
|
|
|
// See the forget() implementation to see why reinterpret_cast() is ok.
|
|
|
|
_0.ptr = reinterpret_cast<decltype(_0.ptr)>(aPtr._0);
|
|
|
|
ASSERT_CANARY
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline size_t StyleArcSlice<T>::Length() const {
|
|
|
|
ASSERT_CANARY
|
|
|
|
return _0.ptr->data.header.length;
|
|
|
|
}
|
|
|
|
|
2019-05-17 02:04:32 +03:00
|
|
|
template <typename T>
|
|
|
|
inline bool StyleArcSlice<T>::IsEmpty() const {
|
|
|
|
ASSERT_CANARY
|
|
|
|
return Length() == 0;
|
|
|
|
}
|
|
|
|
|
2019-05-09 15:43:19 +03:00
|
|
|
template <typename T>
|
|
|
|
inline Span<const T> StyleArcSlice<T>::AsSpan() const {
|
|
|
|
ASSERT_CANARY
|
|
|
|
return MakeSpan(_0.ptr->data.slice, Length());
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline bool StyleArcSlice<T>::operator==(const StyleArcSlice& aOther) const {
|
|
|
|
ASSERT_CANARY
|
|
|
|
return AsSpan() == aOther.AsSpan();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline bool StyleArcSlice<T>::operator!=(const StyleArcSlice& aOther) const {
|
|
|
|
return !(*this == aOther);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline StyleArcSlice<T>::~StyleArcSlice() {
|
|
|
|
ASSERT_CANARY
|
Bug 1552708 - Use cbindgen for URIs. r=heycam
This doesn't clean up as much as a whole, but it's a step in the right
direction. In particular, it allows us to start using simple bindings for:
* Filters
* Shapes and images, almost. Need to:
* Get rid of the complex -moz- gradient parsing (let
layout.css.simple-moz-gradient.enabled get to release).
* Counters, almost. Need to:
* Share the Attr representation with Gecko, by not using Option<>.
* Just another variant should be enough (ContentItem::{Attr,Prefixedattr},
maybe).
Which in turn allows us to remove a whole lot of bindings in followups to this.
The setup changes a bit. This also removes the double pointer I complained about
while reviewing the shared UA sheet patches. The old setup is:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* UrlValueSource
* Arc<CssUrlData>
* load id
* resolved uri
* CORS mode.
* ...
```
The new one removes the double reference to the url data via URLValue, and looks
like:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* CorsMode
* LoadData
* load id
* resolved URI
```
The LoadData is the only mutable bit that C++ can change, and is not used from
Rust. Ideally, in the future, we could just use rust-url to resolve the URL
after parsing or something, and make it all immutable. Maybe.
I've verified that this approach still works with the UA sheet patches (via the
LoadDataSource::Lazy).
The reordering of mWillChange is to avoid nsStyleDisplay from going over the
size limit. We want to split it up anyway in bug 1552587, but mBinding gains a
tag member, which means that we were having a bit of extra padding.
One thing I want to explore is to see if we can abuse rustc's non-zero
optimizations to predict the layout from C++, but that's something to explore at
some other point in time and with a lot of care and help from Michael (who sits
next to me and works on rustc ;)).
Differential Revision: https://phabricator.services.mozilla.com/D31742
2019-05-27 14:45:12 +03:00
|
|
|
if (MOZ_LIKELY(!_0.ptr->DecrementRef())) {
|
2019-05-09 15:43:19 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (T& elem : MakeSpan(_0.ptr->data.slice, Length())) {
|
|
|
|
elem.~T();
|
|
|
|
}
|
|
|
|
free(_0.ptr); // Drop the allocation now.
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef ASSERT_CANARY
|
|
|
|
|
Bug 1552708 - Use cbindgen for URIs. r=heycam
This doesn't clean up as much as a whole, but it's a step in the right
direction. In particular, it allows us to start using simple bindings for:
* Filters
* Shapes and images, almost. Need to:
* Get rid of the complex -moz- gradient parsing (let
layout.css.simple-moz-gradient.enabled get to release).
* Counters, almost. Need to:
* Share the Attr representation with Gecko, by not using Option<>.
* Just another variant should be enough (ContentItem::{Attr,Prefixedattr},
maybe).
Which in turn allows us to remove a whole lot of bindings in followups to this.
The setup changes a bit. This also removes the double pointer I complained about
while reviewing the shared UA sheet patches. The old setup is:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* UrlValueSource
* Arc<CssUrlData>
* load id
* resolved uri
* CORS mode.
* ...
```
The new one removes the double reference to the url data via URLValue, and looks
like:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* CorsMode
* LoadData
* load id
* resolved URI
```
The LoadData is the only mutable bit that C++ can change, and is not used from
Rust. Ideally, in the future, we could just use rust-url to resolve the URL
after parsing or something, and make it all immutable. Maybe.
I've verified that this approach still works with the UA sheet patches (via the
LoadDataSource::Lazy).
The reordering of mWillChange is to avoid nsStyleDisplay from going over the
size limit. We want to split it up anyway in bug 1552587, but mBinding gains a
tag member, which means that we were having a bit of extra padding.
One thing I want to explore is to see if we can abuse rustc's non-zero
optimizations to predict the layout from C++, but that's something to explore at
some other point in time and with a lot of care and help from Michael (who sits
next to me and works on rustc ;)).
Differential Revision: https://phabricator.services.mozilla.com/D31742
2019-05-27 14:45:12 +03:00
|
|
|
template <typename T>
|
|
|
|
inline StyleArc<T>::StyleArc(const StyleArc& aOther) : p(aOther.p) {
|
|
|
|
p->IncrementRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline void StyleArc<T>::Release() {
|
|
|
|
if (MOZ_LIKELY(!p->DecrementRef())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
p->data.~T();
|
|
|
|
free(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline StyleArc<T>& StyleArc<T>::operator=(const StyleArc& aOther) {
|
|
|
|
if (p != aOther.p) {
|
|
|
|
Release();
|
|
|
|
p = aOther.p;
|
|
|
|
p->IncrementRef();
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline StyleArc<T>& StyleArc<T>::operator=(StyleArc&& aOther) {
|
|
|
|
std::swap(p, aOther.p);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline StyleArc<T>::~StyleArc() {
|
|
|
|
Release();
|
|
|
|
}
|
|
|
|
|
2019-05-17 02:03:29 +03:00
|
|
|
inline bool StyleAtom::IsStatic() const { return !!(_0 & 1); }
|
|
|
|
|
2019-05-17 02:23:28 +03:00
|
|
|
inline nsAtom* StyleAtom::AsAtom() const {
|
|
|
|
if (IsStatic()) {
|
2019-06-15 04:35:15 +03:00
|
|
|
auto* atom = reinterpret_cast<const nsStaticAtom*>(
|
|
|
|
reinterpret_cast<const uint8_t*>(&detail::gGkAtoms) + (_0 >> 1));
|
|
|
|
MOZ_ASSERT(atom->IsStatic());
|
|
|
|
return const_cast<nsStaticAtom*>(atom);
|
2019-05-17 02:23:28 +03:00
|
|
|
}
|
|
|
|
return reinterpret_cast<nsAtom*>(_0);
|
|
|
|
}
|
|
|
|
|
2019-06-27 00:21:38 +03:00
|
|
|
inline void StyleAtom::AddRef() {
|
|
|
|
if (!IsStatic()) {
|
|
|
|
AsAtom()->AddRef();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void StyleAtom::Release() {
|
2019-05-17 02:03:29 +03:00
|
|
|
if (!IsStatic()) {
|
2019-05-17 02:23:28 +03:00
|
|
|
AsAtom()->Release();
|
2019-05-17 02:03:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-19 08:58:01 +03:00
|
|
|
inline StyleAtom::StyleAtom(already_AddRefed<nsAtom> aAtom) {
|
|
|
|
nsAtom* atom = aAtom.take();
|
|
|
|
if (atom->IsStatic()) {
|
|
|
|
ptrdiff_t offset = reinterpret_cast<const uint8_t*>(atom->AsStatic()) -
|
2019-07-06 11:18:28 +03:00
|
|
|
reinterpret_cast<const uint8_t*>(&detail::gGkAtoms);
|
2019-06-19 08:58:01 +03:00
|
|
|
_0 = (offset << 1) | 1;
|
|
|
|
} else {
|
|
|
|
_0 = reinterpret_cast<uintptr_t>(atom);
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(IsStatic() == atom->IsStatic());
|
|
|
|
MOZ_ASSERT(AsAtom() == atom);
|
|
|
|
}
|
|
|
|
|
2019-05-17 02:03:29 +03:00
|
|
|
inline StyleAtom::StyleAtom(const StyleAtom& aOther) : _0(aOther._0) {
|
2019-06-27 00:21:38 +03:00
|
|
|
AddRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline StyleAtom& StyleAtom::operator=(const StyleAtom& aOther) {
|
|
|
|
if (MOZ_LIKELY(this != &aOther)) {
|
|
|
|
Release();
|
|
|
|
_0 = aOther._0;
|
|
|
|
AddRef();
|
2019-05-17 02:03:29 +03:00
|
|
|
}
|
2019-06-27 00:21:38 +03:00
|
|
|
return *this;
|
2019-05-17 02:03:29 +03:00
|
|
|
}
|
|
|
|
|
2019-06-27 00:21:38 +03:00
|
|
|
inline StyleAtom::~StyleAtom() { Release(); }
|
|
|
|
|
2019-05-17 02:23:28 +03:00
|
|
|
inline nsAtom* StyleCustomIdent::AsAtom() const { return _0.AsAtom(); }
|
|
|
|
|
2019-05-17 02:04:31 +03:00
|
|
|
inline nsDependentCSubstring StyleOwnedStr::AsString() const {
|
|
|
|
Span<const uint8_t> s = _0.AsSpan();
|
|
|
|
return nsDependentCSubstring(reinterpret_cast<const char*>(s.Elements()),
|
|
|
|
s.Length());
|
|
|
|
}
|
|
|
|
|
2019-05-17 02:25:10 +03:00
|
|
|
template <typename T>
|
|
|
|
inline Span<const T> StyleGenericTransform<T>::Operations() const {
|
|
|
|
return _0.AsSpan();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline bool StyleGenericTransform<T>::IsNone() const {
|
|
|
|
return Operations().IsEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline StyleAngle StyleAngle::Zero() { return {0.0f}; }
|
|
|
|
|
|
|
|
inline float StyleAngle::ToDegrees() const { return _0; }
|
|
|
|
|
|
|
|
inline double StyleAngle::ToRadians() const {
|
|
|
|
return double(ToDegrees()) * M_PI / 180.0;
|
|
|
|
}
|
|
|
|
|
Bug 1552708 - Use cbindgen for URIs. r=heycam
This doesn't clean up as much as a whole, but it's a step in the right
direction. In particular, it allows us to start using simple bindings for:
* Filters
* Shapes and images, almost. Need to:
* Get rid of the complex -moz- gradient parsing (let
layout.css.simple-moz-gradient.enabled get to release).
* Counters, almost. Need to:
* Share the Attr representation with Gecko, by not using Option<>.
* Just another variant should be enough (ContentItem::{Attr,Prefixedattr},
maybe).
Which in turn allows us to remove a whole lot of bindings in followups to this.
The setup changes a bit. This also removes the double pointer I complained about
while reviewing the shared UA sheet patches. The old setup is:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* UrlValueSource
* Arc<CssUrlData>
* load id
* resolved uri
* CORS mode.
* ...
```
The new one removes the double reference to the url data via URLValue, and looks
like:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* CorsMode
* LoadData
* load id
* resolved URI
```
The LoadData is the only mutable bit that C++ can change, and is not used from
Rust. Ideally, in the future, we could just use rust-url to resolve the URL
after parsing or something, and make it all immutable. Maybe.
I've verified that this approach still works with the UA sheet patches (via the
LoadDataSource::Lazy).
The reordering of mWillChange is to avoid nsStyleDisplay from going over the
size limit. We want to split it up anyway in bug 1552587, but mBinding gains a
tag member, which means that we were having a bit of extra padding.
One thing I want to explore is to see if we can abuse rustc's non-zero
optimizations to predict the layout from C++, but that's something to explore at
some other point in time and with a lot of care and help from Michael (who sits
next to me and works on rustc ;)).
Differential Revision: https://phabricator.services.mozilla.com/D31742
2019-05-27 14:45:12 +03:00
|
|
|
inline bool StyleUrlExtraData::IsShared() const { return !!(_0 & 1); }
|
|
|
|
|
|
|
|
inline StyleUrlExtraData::~StyleUrlExtraData() {
|
|
|
|
if (!IsShared()) {
|
|
|
|
reinterpret_cast<URLExtraData*>(_0)->Release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const URLExtraData& StyleUrlExtraData::get() const {
|
|
|
|
if (IsShared()) {
|
|
|
|
return *URLExtraData::sShared[_0 >> 1].get();
|
|
|
|
}
|
|
|
|
return *reinterpret_cast<const URLExtraData*>(_0);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline nsDependentCSubstring StyleCssUrl::SpecifiedSerialization() const {
|
|
|
|
return _0->serialization.AsString();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const URLExtraData& StyleCssUrl::ExtraData() const {
|
|
|
|
return _0->extra_data.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline StyleLoadData& StyleCssUrl::LoadData() const {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(NS_IsMainThread());
|
|
|
|
if (MOZ_LIKELY(_0->load_data.tag == StyleLoadDataSource::Tag::Owned)) {
|
|
|
|
return const_cast<StyleLoadData&>(_0->load_data.owned._0);
|
|
|
|
}
|
|
|
|
return const_cast<StyleLoadData&>(*Servo_LoadData_GetLazy(&_0->load_data));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline nsIURI* StyleCssUrl::GetURI() const {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(NS_IsMainThread());
|
|
|
|
auto& loadData = LoadData();
|
2020-02-07 23:36:34 +03:00
|
|
|
if (!(loadData.flags & StyleLoadDataFlags::TRIED_TO_RESOLVE_URI)) {
|
|
|
|
loadData.flags |= StyleLoadDataFlags::TRIED_TO_RESOLVE_URI;
|
|
|
|
RefPtr<nsIURI> resolved;
|
|
|
|
NS_NewURI(getter_AddRefs(resolved), SpecifiedSerialization(), nullptr,
|
|
|
|
ExtraData().BaseURI());
|
|
|
|
loadData.resolved_uri = resolved.forget().take();
|
Bug 1552708 - Use cbindgen for URIs. r=heycam
This doesn't clean up as much as a whole, but it's a step in the right
direction. In particular, it allows us to start using simple bindings for:
* Filters
* Shapes and images, almost. Need to:
* Get rid of the complex -moz- gradient parsing (let
layout.css.simple-moz-gradient.enabled get to release).
* Counters, almost. Need to:
* Share the Attr representation with Gecko, by not using Option<>.
* Just another variant should be enough (ContentItem::{Attr,Prefixedattr},
maybe).
Which in turn allows us to remove a whole lot of bindings in followups to this.
The setup changes a bit. This also removes the double pointer I complained about
while reviewing the shared UA sheet patches. The old setup is:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* UrlValueSource
* Arc<CssUrlData>
* load id
* resolved uri
* CORS mode.
* ...
```
The new one removes the double reference to the url data via URLValue, and looks
like:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* CorsMode
* LoadData
* load id
* resolved URI
```
The LoadData is the only mutable bit that C++ can change, and is not used from
Rust. Ideally, in the future, we could just use rust-url to resolve the URL
after parsing or something, and make it all immutable. Maybe.
I've verified that this approach still works with the UA sheet patches (via the
LoadDataSource::Lazy).
The reordering of mWillChange is to avoid nsStyleDisplay from going over the
size limit. We want to split it up anyway in bug 1552587, but mBinding gains a
tag member, which means that we were having a bit of extra padding.
One thing I want to explore is to see if we can abuse rustc's non-zero
optimizations to predict the layout from C++, but that's something to explore at
some other point in time and with a lot of care and help from Michael (who sits
next to me and works on rustc ;)).
Differential Revision: https://phabricator.services.mozilla.com/D31742
2019-05-27 14:45:12 +03:00
|
|
|
}
|
2020-02-07 23:36:34 +03:00
|
|
|
return loadData.resolved_uri;
|
Bug 1552708 - Use cbindgen for URIs. r=heycam
This doesn't clean up as much as a whole, but it's a step in the right
direction. In particular, it allows us to start using simple bindings for:
* Filters
* Shapes and images, almost. Need to:
* Get rid of the complex -moz- gradient parsing (let
layout.css.simple-moz-gradient.enabled get to release).
* Counters, almost. Need to:
* Share the Attr representation with Gecko, by not using Option<>.
* Just another variant should be enough (ContentItem::{Attr,Prefixedattr},
maybe).
Which in turn allows us to remove a whole lot of bindings in followups to this.
The setup changes a bit. This also removes the double pointer I complained about
while reviewing the shared UA sheet patches. The old setup is:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* UrlValueSource
* Arc<CssUrlData>
* load id
* resolved uri
* CORS mode.
* ...
```
The new one removes the double reference to the url data via URLValue, and looks
like:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* CorsMode
* LoadData
* load id
* resolved URI
```
The LoadData is the only mutable bit that C++ can change, and is not used from
Rust. Ideally, in the future, we could just use rust-url to resolve the URL
after parsing or something, and make it all immutable. Maybe.
I've verified that this approach still works with the UA sheet patches (via the
LoadDataSource::Lazy).
The reordering of mWillChange is to avoid nsStyleDisplay from going over the
size limit. We want to split it up anyway in bug 1552587, but mBinding gains a
tag member, which means that we were having a bit of extra padding.
One thing I want to explore is to see if we can abuse rustc's non-zero
optimizations to predict the layout from C++, but that's something to explore at
some other point in time and with a lot of care and help from Michael (who sits
next to me and works on rustc ;)).
Differential Revision: https://phabricator.services.mozilla.com/D31742
2019-05-27 14:45:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
inline nsDependentCSubstring StyleComputedUrl::SpecifiedSerialization() const {
|
|
|
|
return _0.SpecifiedSerialization();
|
|
|
|
}
|
|
|
|
inline const URLExtraData& StyleComputedUrl::ExtraData() const {
|
|
|
|
return _0.ExtraData();
|
|
|
|
}
|
|
|
|
inline StyleLoadData& StyleComputedUrl::LoadData() const {
|
|
|
|
return _0.LoadData();
|
|
|
|
}
|
2019-08-09 21:09:55 +03:00
|
|
|
inline StyleCorsMode StyleComputedUrl::CorsMode() const {
|
|
|
|
return _0._0->cors_mode;
|
Bug 1552708 - Use cbindgen for URIs. r=heycam
This doesn't clean up as much as a whole, but it's a step in the right
direction. In particular, it allows us to start using simple bindings for:
* Filters
* Shapes and images, almost. Need to:
* Get rid of the complex -moz- gradient parsing (let
layout.css.simple-moz-gradient.enabled get to release).
* Counters, almost. Need to:
* Share the Attr representation with Gecko, by not using Option<>.
* Just another variant should be enough (ContentItem::{Attr,Prefixedattr},
maybe).
Which in turn allows us to remove a whole lot of bindings in followups to this.
The setup changes a bit. This also removes the double pointer I complained about
while reviewing the shared UA sheet patches. The old setup is:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* UrlValueSource
* Arc<CssUrlData>
* load id
* resolved uri
* CORS mode.
* ...
```
The new one removes the double reference to the url data via URLValue, and looks
like:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* CorsMode
* LoadData
* load id
* resolved URI
```
The LoadData is the only mutable bit that C++ can change, and is not used from
Rust. Ideally, in the future, we could just use rust-url to resolve the URL
after parsing or something, and make it all immutable. Maybe.
I've verified that this approach still works with the UA sheet patches (via the
LoadDataSource::Lazy).
The reordering of mWillChange is to avoid nsStyleDisplay from going over the
size limit. We want to split it up anyway in bug 1552587, but mBinding gains a
tag member, which means that we were having a bit of extra padding.
One thing I want to explore is to see if we can abuse rustc's non-zero
optimizations to predict the layout from C++, but that's something to explore at
some other point in time and with a lot of care and help from Michael (who sits
next to me and works on rustc ;)).
Differential Revision: https://phabricator.services.mozilla.com/D31742
2019-05-27 14:45:12 +03:00
|
|
|
}
|
|
|
|
inline nsIURI* StyleComputedUrl::GetURI() const { return _0.GetURI(); }
|
|
|
|
|
|
|
|
inline bool StyleComputedUrl::IsLocalRef() const {
|
|
|
|
return Servo_CssUrl_IsLocalRef(&_0);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool StyleComputedUrl::HasRef() const {
|
|
|
|
if (IsLocalRef()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (nsIURI* uri = GetURI()) {
|
|
|
|
bool hasRef = false;
|
|
|
|
return NS_SUCCEEDED(uri->GetHasRef(&hasRef)) && hasRef;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-02-07 23:36:34 +03:00
|
|
|
inline bool StyleComputedImageUrl::IsImageResolved() const {
|
|
|
|
return bool(LoadData().flags & StyleLoadDataFlags::TRIED_TO_RESOLVE_IMAGE);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline imgRequestProxy* StyleComputedImageUrl::GetImage() const {
|
|
|
|
MOZ_ASSERT(IsImageResolved());
|
|
|
|
return LoadData().resolved_image;
|
|
|
|
}
|
|
|
|
|
2020-02-16 01:04:35 +03:00
|
|
|
template <>
|
|
|
|
inline bool StyleGradient::Repeating() const {
|
2020-02-21 01:07:32 +03:00
|
|
|
if (IsLinear()) {
|
|
|
|
return AsLinear().repeating;
|
|
|
|
}
|
|
|
|
if (IsRadial()) {
|
|
|
|
return AsRadial().repeating;
|
|
|
|
}
|
|
|
|
return AsConic().repeating;
|
2020-02-16 01:04:35 +03:00
|
|
|
}
|
|
|
|
|
2019-06-07 17:13:17 +03:00
|
|
|
template <>
|
|
|
|
bool StyleGradient::IsOpaque() const;
|
|
|
|
|
2019-06-27 00:21:38 +03:00
|
|
|
template <typename Integer>
|
|
|
|
inline StyleGenericGridLine<Integer>::StyleGenericGridLine()
|
|
|
|
: ident(do_AddRef(static_cast<nsAtom*>(nsGkAtoms::_empty))),
|
|
|
|
line_num(0),
|
|
|
|
is_span(false) {}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline nsAtom* StyleGridLine::LineName() const {
|
|
|
|
return ident.AsAtom();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline bool StyleGridLine::IsAuto() const {
|
|
|
|
return LineName()->IsEmpty() && line_num == 0 && !is_span;
|
|
|
|
}
|
|
|
|
|
2019-06-28 12:46:26 +03:00
|
|
|
using LengthPercentage = StyleLengthPercentage;
|
|
|
|
using LengthPercentageOrAuto = StyleLengthPercentageOrAuto;
|
|
|
|
using NonNegativeLengthPercentage = StyleNonNegativeLengthPercentage;
|
|
|
|
using NonNegativeLengthPercentageOrAuto =
|
|
|
|
StyleNonNegativeLengthPercentageOrAuto;
|
|
|
|
using NonNegativeLengthPercentageOrNormal =
|
|
|
|
StyleNonNegativeLengthPercentageOrNormal;
|
|
|
|
using Length = StyleLength;
|
|
|
|
using LengthOrAuto = StyleLengthOrAuto;
|
|
|
|
using NonNegativeLength = StyleNonNegativeLength;
|
|
|
|
using NonNegativeLengthOrAuto = StyleNonNegativeLengthOrAuto;
|
|
|
|
using BorderRadius = StyleBorderRadius;
|
|
|
|
|
|
|
|
bool StyleCSSPixelLength::IsZero() const { return _0 == 0.0f; }
|
|
|
|
|
2020-01-13 16:21:58 +03:00
|
|
|
void StyleCSSPixelLength::ScaleBy(float aScale) { _0 *= aScale; }
|
|
|
|
|
2019-06-28 12:46:26 +03:00
|
|
|
nscoord StyleCSSPixelLength::ToAppUnits() const {
|
|
|
|
// We want to resolve the length part of the calc() expression rounding 0.5
|
|
|
|
// away from zero, instead of the default behavior of
|
|
|
|
// NSToCoordRound{,WithClamp} which do floor(x + 0.5).
|
|
|
|
//
|
|
|
|
// This is what the rust code in the app_units crate does, and not doing this
|
|
|
|
// would regress bug 1323735, for example.
|
|
|
|
//
|
|
|
|
// FIXME(emilio, bug 1528114): Probably we should do something smarter.
|
2019-08-30 01:19:36 +03:00
|
|
|
if (IsZero()) {
|
|
|
|
// Avoid the expensive FP math below.
|
|
|
|
return 0;
|
|
|
|
}
|
2019-06-28 12:46:26 +03:00
|
|
|
float length = _0 * float(mozilla::AppUnitsPerCSSPixel());
|
2019-09-12 15:32:12 +03:00
|
|
|
if (length >= float(nscoord_MAX)) {
|
2019-09-11 18:48:22 +03:00
|
|
|
return nscoord_MAX;
|
|
|
|
}
|
2019-09-12 15:32:12 +03:00
|
|
|
if (length <= float(nscoord_MIN)) {
|
2019-09-11 18:48:22 +03:00
|
|
|
return nscoord_MIN;
|
|
|
|
}
|
|
|
|
return NSToIntRound(length);
|
2019-06-28 12:46:26 +03:00
|
|
|
}
|
|
|
|
|
2020-01-13 16:23:22 +03:00
|
|
|
bool LengthPercentage::IsLength() const { return Tag() == TAG_LENGTH; }
|
|
|
|
|
|
|
|
StyleLengthPercentageUnion::StyleLengthPercentageUnion() {
|
|
|
|
length = {TAG_LENGTH, {0.0f}};
|
|
|
|
MOZ_ASSERT(IsLength());
|
|
|
|
}
|
|
|
|
|
|
|
|
static_assert(sizeof(LengthPercentage) == sizeof(uint64_t), "");
|
|
|
|
|
|
|
|
Length& LengthPercentage::AsLength() {
|
|
|
|
MOZ_ASSERT(IsLength());
|
|
|
|
return length.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Length& LengthPercentage::AsLength() const {
|
|
|
|
return const_cast<LengthPercentage*>(this)->AsLength();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LengthPercentage::IsPercentage() const { return Tag() == TAG_PERCENTAGE; }
|
|
|
|
|
|
|
|
StylePercentage& LengthPercentage::AsPercentage() {
|
|
|
|
MOZ_ASSERT(IsPercentage());
|
|
|
|
return percentage.percentage;
|
|
|
|
}
|
|
|
|
|
|
|
|
const StylePercentage& LengthPercentage::AsPercentage() const {
|
|
|
|
return const_cast<LengthPercentage*>(this)->AsPercentage();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LengthPercentage::IsCalc() const { return Tag() == TAG_CALC; }
|
|
|
|
|
|
|
|
StyleCalcLengthPercentage& LengthPercentage::AsCalc() {
|
|
|
|
MOZ_ASSERT(IsCalc());
|
2020-02-10 21:20:16 +03:00
|
|
|
// NOTE: in 32-bits, the pointer is not swapped, and goes along with the tag.
|
2020-02-10 20:12:44 +03:00
|
|
|
#ifdef SERVO_32_BITS
|
2020-01-13 16:23:22 +03:00
|
|
|
return *calc.ptr;
|
2020-02-10 20:12:44 +03:00
|
|
|
#else
|
|
|
|
return *reinterpret_cast<StyleCalcLengthPercentage*>(
|
|
|
|
NativeEndian::swapFromLittleEndian(calc.ptr));
|
|
|
|
#endif
|
2020-01-13 16:23:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const StyleCalcLengthPercentage& LengthPercentage::AsCalc() const {
|
|
|
|
return const_cast<LengthPercentage*>(this)->AsCalc();
|
|
|
|
}
|
|
|
|
|
|
|
|
StyleLengthPercentageUnion::StyleLengthPercentageUnion(const Self& aOther) {
|
|
|
|
if (aOther.IsLength()) {
|
|
|
|
length = {TAG_LENGTH, aOther.AsLength()};
|
|
|
|
} else if (aOther.IsPercentage()) {
|
|
|
|
percentage = {TAG_PERCENTAGE, aOther.AsPercentage()};
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(aOther.IsCalc());
|
2020-02-10 20:12:44 +03:00
|
|
|
auto* ptr = new StyleCalcLengthPercentage(aOther.AsCalc());
|
2020-02-10 21:20:16 +03:00
|
|
|
// NOTE: in 32-bits, the pointer is not swapped, and goes along with the
|
|
|
|
// tag.
|
2020-01-13 16:23:22 +03:00
|
|
|
calc = {
|
|
|
|
#ifdef SERVO_32_BITS
|
|
|
|
TAG_CALC,
|
2020-02-10 20:12:44 +03:00
|
|
|
ptr,
|
|
|
|
#else
|
|
|
|
NativeEndian::swapToLittleEndian(reinterpret_cast<uintptr_t>(ptr)),
|
2020-01-13 16:23:22 +03:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(Tag() == aOther.Tag());
|
|
|
|
}
|
|
|
|
|
|
|
|
StyleLengthPercentageUnion::~StyleLengthPercentageUnion() {
|
|
|
|
if (IsCalc()) {
|
2020-02-10 20:12:44 +03:00
|
|
|
delete &AsCalc();
|
2020-01-13 16:23:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LengthPercentage& LengthPercentage::operator=(const LengthPercentage& aOther) {
|
|
|
|
if (this != &aOther) {
|
|
|
|
this->~LengthPercentage();
|
|
|
|
new (this) LengthPercentage(aOther);
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LengthPercentage::operator==(const LengthPercentage& aOther) const {
|
|
|
|
if (Tag() != aOther.Tag()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (IsLength()) {
|
|
|
|
return AsLength() == aOther.AsLength();
|
|
|
|
}
|
|
|
|
if (IsPercentage()) {
|
|
|
|
return AsPercentage() == aOther.AsPercentage();
|
|
|
|
}
|
|
|
|
return AsCalc() == aOther.AsCalc();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LengthPercentage::operator!=(const LengthPercentage& aOther) const {
|
|
|
|
return !(*this == aOther);
|
2019-06-28 12:46:26 +03:00
|
|
|
}
|
|
|
|
|
2020-01-13 16:21:58 +03:00
|
|
|
LengthPercentage LengthPercentage::Zero() { return {}; }
|
|
|
|
|
2019-06-28 12:46:26 +03:00
|
|
|
LengthPercentage LengthPercentage::FromPixels(CSSCoord aCoord) {
|
2020-01-13 16:23:22 +03:00
|
|
|
LengthPercentage l;
|
|
|
|
MOZ_ASSERT(l.IsLength());
|
|
|
|
l.length.length = {aCoord};
|
|
|
|
return l;
|
2019-06-28 12:46:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
LengthPercentage LengthPercentage::FromAppUnits(nscoord aCoord) {
|
2020-01-13 16:21:58 +03:00
|
|
|
return FromPixels(CSSPixel::FromAppUnits(aCoord));
|
2019-06-28 12:46:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
LengthPercentage LengthPercentage::FromPercentage(float aPercentage) {
|
2020-01-13 16:23:22 +03:00
|
|
|
LengthPercentage l;
|
|
|
|
l.percentage = {TAG_PERCENTAGE, {aPercentage}};
|
|
|
|
return l;
|
2019-06-28 12:46:26 +03:00
|
|
|
}
|
|
|
|
|
2020-02-24 18:33:38 +03:00
|
|
|
bool LengthPercentage::HasPercent() const { return IsPercentage() || IsCalc(); }
|
2019-06-28 12:46:26 +03:00
|
|
|
|
2020-01-23 12:18:39 +03:00
|
|
|
bool LengthPercentage::ConvertsToLength() const { return IsLength(); }
|
2020-01-23 08:39:48 +03:00
|
|
|
|
|
|
|
nscoord LengthPercentage::ToLength() const {
|
2020-01-23 03:36:27 +03:00
|
|
|
MOZ_ASSERT(ConvertsToLength());
|
2020-01-23 12:18:39 +03:00
|
|
|
return AsLength().ToAppUnits();
|
2020-01-23 03:36:27 +03:00
|
|
|
}
|
|
|
|
|
2020-01-23 12:18:39 +03:00
|
|
|
CSSCoord LengthPercentage::ToLengthInCSSPixels() const {
|
|
|
|
MOZ_ASSERT(ConvertsToLength());
|
2020-01-23 12:18:39 +03:00
|
|
|
return AsLength().ToCSSPixels();
|
2020-01-23 12:18:39 +03:00
|
|
|
}
|
|
|
|
|
2020-02-24 18:33:38 +03:00
|
|
|
bool LengthPercentage::ConvertsToPercentage() const { return IsPercentage(); }
|
2019-06-28 12:46:26 +03:00
|
|
|
|
|
|
|
float LengthPercentage::ToPercentage() const {
|
|
|
|
MOZ_ASSERT(ConvertsToPercentage());
|
2020-01-23 12:18:39 +03:00
|
|
|
return AsPercentage()._0;
|
2019-06-28 12:46:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool LengthPercentage::HasLengthAndPercentage() const {
|
2020-01-23 12:18:39 +03:00
|
|
|
if (!IsCalc()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(!ConvertsToLength() && !ConvertsToPercentage(),
|
|
|
|
"Should've been simplified earlier");
|
|
|
|
return true;
|
2019-06-28 12:46:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool LengthPercentage::IsDefinitelyZero() const {
|
2020-01-13 16:21:58 +03:00
|
|
|
if (IsLength()) {
|
|
|
|
return AsLength().IsZero();
|
|
|
|
}
|
|
|
|
if (IsPercentage()) {
|
|
|
|
return AsPercentage()._0 == 0.0f;
|
|
|
|
}
|
2020-02-21 03:46:50 +03:00
|
|
|
// calc() should've been simplified to a percentage.
|
2020-01-23 12:18:39 +03:00
|
|
|
return false;
|
2019-06-28 12:46:26 +03:00
|
|
|
}
|
|
|
|
|
2020-02-21 03:46:50 +03:00
|
|
|
template <>
|
|
|
|
CSSCoord StyleCalcNode::ResolveToCSSPixels(CSSCoord aPercentageBasis) const;
|
|
|
|
|
|
|
|
template <>
|
|
|
|
void StyleCalcNode::ScaleLengthsBy(float);
|
|
|
|
|
2019-06-28 12:46:26 +03:00
|
|
|
CSSCoord LengthPercentage::ResolveToCSSPixels(CSSCoord aPercentageBasis) const {
|
2020-01-23 12:18:39 +03:00
|
|
|
if (IsLength()) {
|
|
|
|
return AsLength().ToCSSPixels();
|
|
|
|
}
|
|
|
|
if (IsPercentage()) {
|
|
|
|
return AsPercentage()._0 * aPercentageBasis;
|
|
|
|
}
|
2020-02-21 03:46:50 +03:00
|
|
|
return AsCalc().node.ResolveToCSSPixels(aPercentageBasis);
|
2019-06-28 12:46:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
CSSCoord LengthPercentage::ResolveToCSSPixelsWith(T aPercentageGetter) const {
|
|
|
|
static_assert(std::is_same<decltype(aPercentageGetter()), CSSCoord>::value,
|
|
|
|
"Should return CSS pixels");
|
|
|
|
if (ConvertsToLength()) {
|
2020-01-23 12:18:39 +03:00
|
|
|
return ToLengthInCSSPixels();
|
2019-06-28 12:46:26 +03:00
|
|
|
}
|
|
|
|
return ResolveToCSSPixels(aPercentageGetter());
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, typename U>
|
2020-02-21 03:46:50 +03:00
|
|
|
nscoord LengthPercentage::Resolve(T aPercentageGetter, U aRounder) const {
|
2019-06-28 12:46:26 +03:00
|
|
|
static_assert(std::is_same<decltype(aPercentageGetter()), nscoord>::value,
|
|
|
|
"Should return app units");
|
2020-02-24 18:33:38 +03:00
|
|
|
static_assert(std::is_same<decltype(aRounder(1.0f)), nscoord>::value,
|
|
|
|
"Should return app units");
|
2019-06-28 12:46:26 +03:00
|
|
|
if (ConvertsToLength()) {
|
|
|
|
return ToLength();
|
|
|
|
}
|
2020-01-13 16:21:58 +03:00
|
|
|
if (IsPercentage() && AsPercentage()._0 == 0.0f) {
|
|
|
|
return 0.0f;
|
|
|
|
}
|
2019-06-28 12:46:26 +03:00
|
|
|
nscoord basis = aPercentageGetter();
|
2020-01-13 16:21:58 +03:00
|
|
|
if (IsPercentage()) {
|
2020-02-21 03:46:50 +03:00
|
|
|
return aRounder(basis * AsPercentage()._0);
|
2020-01-13 16:21:58 +03:00
|
|
|
}
|
2020-02-21 03:46:50 +03:00
|
|
|
return AsCalc().node.Resolve(basis, aRounder);
|
2019-06-28 12:46:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nscoord LengthPercentage::Resolve(nscoord aPercentageBasis) const {
|
|
|
|
return Resolve([=] { return aPercentageBasis; }, NSToCoordFloorClamped);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
nscoord LengthPercentage::Resolve(T aPercentageGetter) const {
|
|
|
|
return Resolve(aPercentageGetter, NSToCoordFloorClamped);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
nscoord LengthPercentage::Resolve(nscoord aPercentageBasis,
|
|
|
|
T aPercentageRounder) const {
|
2020-01-23 12:18:39 +03:00
|
|
|
return Resolve([aPercentageBasis] { return aPercentageBasis; },
|
|
|
|
aPercentageRounder);
|
2019-06-28 12:46:26 +03:00
|
|
|
}
|
|
|
|
|
2020-01-13 16:21:58 +03:00
|
|
|
void LengthPercentage::ScaleLengthsBy(float aScale) {
|
|
|
|
if (IsLength()) {
|
|
|
|
AsLength().ScaleBy(aScale);
|
|
|
|
}
|
|
|
|
if (IsCalc()) {
|
2020-02-21 03:46:50 +03:00
|
|
|
AsCalc().node.ScaleLengthsBy(aScale);
|
2020-01-13 16:21:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-28 12:46:26 +03:00
|
|
|
#define IMPL_LENGTHPERCENTAGE_FORWARDS(ty_) \
|
|
|
|
template <> \
|
|
|
|
inline bool ty_::HasPercent() const { \
|
|
|
|
return IsLengthPercentage() && AsLengthPercentage().HasPercent(); \
|
|
|
|
} \
|
|
|
|
template <> \
|
|
|
|
inline bool ty_::ConvertsToLength() const { \
|
|
|
|
return IsLengthPercentage() && AsLengthPercentage().ConvertsToLength(); \
|
|
|
|
} \
|
|
|
|
template <> \
|
|
|
|
inline bool ty_::HasLengthAndPercentage() const { \
|
|
|
|
return IsLengthPercentage() && \
|
|
|
|
AsLengthPercentage().HasLengthAndPercentage(); \
|
|
|
|
} \
|
|
|
|
template <> \
|
|
|
|
inline nscoord ty_::ToLength() const { \
|
|
|
|
MOZ_ASSERT(ConvertsToLength()); \
|
|
|
|
return AsLengthPercentage().ToLength(); \
|
|
|
|
} \
|
|
|
|
template <> \
|
|
|
|
inline bool ty_::ConvertsToPercentage() const { \
|
|
|
|
return IsLengthPercentage() && \
|
|
|
|
AsLengthPercentage().ConvertsToPercentage(); \
|
|
|
|
} \
|
|
|
|
template <> \
|
|
|
|
inline float ty_::ToPercentage() const { \
|
|
|
|
MOZ_ASSERT(ConvertsToPercentage()); \
|
|
|
|
return AsLengthPercentage().ToPercentage(); \
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPL_LENGTHPERCENTAGE_FORWARDS(LengthPercentageOrAuto)
|
|
|
|
IMPL_LENGTHPERCENTAGE_FORWARDS(StyleSize)
|
|
|
|
IMPL_LENGTHPERCENTAGE_FORWARDS(StyleMaxSize)
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline bool LengthOrAuto::IsLength() const {
|
|
|
|
return IsLengthPercentage();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline const Length& LengthOrAuto::AsLength() const {
|
|
|
|
return AsLengthPercentage();
|
|
|
|
}
|
|
|
|
|
2019-08-27 02:09:47 +03:00
|
|
|
template <>
|
|
|
|
inline nscoord LengthOrAuto::ToLength() const {
|
|
|
|
return AsLength().ToAppUnits();
|
|
|
|
}
|
|
|
|
|
2019-06-28 12:46:26 +03:00
|
|
|
template <>
|
|
|
|
inline bool StyleFlexBasis::IsAuto() const {
|
|
|
|
return IsSize() && AsSize().IsAuto();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline bool StyleSize::BehavesLikeInitialValueOnBlockAxis() const {
|
|
|
|
return IsAuto() || IsExtremumLength();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline bool StyleMaxSize::BehavesLikeInitialValueOnBlockAxis() const {
|
|
|
|
return IsNone() || IsExtremumLength();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline bool StyleBackgroundSize::IsInitialValue() const {
|
|
|
|
return IsExplicitSize() && explicit_size.width.IsAuto() &&
|
|
|
|
explicit_size.height.IsAuto();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
const T& StyleRect<T>::Get(mozilla::Side aSide) const {
|
|
|
|
static_assert(sizeof(StyleRect<T>) == sizeof(T) * 4, "");
|
|
|
|
static_assert(alignof(StyleRect<T>) == alignof(T), "");
|
|
|
|
return reinterpret_cast<const T*>(this)[aSide];
|
|
|
|
}
|
|
|
|
|
2020-02-27 23:58:00 +03:00
|
|
|
template <typename T>
|
|
|
|
T& StyleRect<T>::Get(mozilla::Side aSide) {
|
|
|
|
return const_cast<T&>(static_cast<const StyleRect&>(*this).Get(aSide));
|
|
|
|
}
|
|
|
|
|
2019-06-28 12:46:26 +03:00
|
|
|
template <typename T>
|
|
|
|
template <typename Predicate>
|
|
|
|
bool StyleRect<T>::All(Predicate aPredicate) const {
|
|
|
|
return aPredicate(_0) && aPredicate(_1) && aPredicate(_2) && aPredicate(_3);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
template <typename Predicate>
|
|
|
|
bool StyleRect<T>::Any(Predicate aPredicate) const {
|
|
|
|
return aPredicate(_0) || aPredicate(_1) || aPredicate(_2) || aPredicate(_3);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline const LengthPercentage& BorderRadius::Get(HalfCorner aCorner) const {
|
|
|
|
static_assert(sizeof(BorderRadius) == sizeof(LengthPercentage) * 8, "");
|
|
|
|
static_assert(alignof(BorderRadius) == alignof(LengthPercentage), "");
|
|
|
|
auto* self = reinterpret_cast<const LengthPercentage*>(this);
|
|
|
|
return self[aCorner];
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline bool StyleTrackBreadth::HasPercent() const {
|
|
|
|
return IsBreadth() && AsBreadth().HasPercent();
|
|
|
|
}
|
|
|
|
|
2019-08-01 12:17:51 +03:00
|
|
|
// Implemented in nsStyleStructs.cpp
|
|
|
|
template <>
|
|
|
|
bool StyleTransform::HasPercent() const;
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline bool StyleTransformOrigin::HasPercent() const {
|
|
|
|
// NOTE(emilio): `depth` is just a `<length>` so doesn't have a percentage at
|
|
|
|
// all.
|
|
|
|
return horizontal.HasPercent() || vertical.HasPercent();
|
|
|
|
}
|
|
|
|
|
Bug 1519958 - Refactor grid types to preserve repeat() at computed value time and use cbindgen. r=mats,boris
I'm _really_ sorry for the size of the patch. I tried to do this in two steps
but it was a lot of work and pretty ugly.
This patch makes us use cbindgen for grid-template-{rows,columns}, in order to:
* Make us preserve repeat() at computed-value time. This is per spec since
interpolation needs to know about repeat(). Except for subgrid, which did the
repeat expansion at parse-time and was a bit more annoying (plus it doesn't
really animate yet so we don't need it to comply with the spec).
* Tweaks the WPT tests for interpolation to adopt the resolution at:
https://github.com/w3c/csswg-drafts/issues/3503.
Trade-off here, as this patch stands, is that this change makes us use less
long-living memory, since we expand repeat() during layout, but at the cost of a
bit of CPU time during layout (conditional on the property applying though,
which wasn't the case before). It should be very easy to store a cached version
of the template, should this be too hot (I expect it isn't), or to change the
representation in other ways to optimize grid layout code if it's worth it.
Another trade-off: I've used SmallPointerArray to handle line-name merging,
pointing to the individual arrays in the style data, rather than actually
heap-allocating the merged lists. This would also be pretty easy to change
should we measure and see that it's not worth it.
This patch also opens the gate to potentially improving memory usage in some
other ways, by reference-counting line-name lists for example, though I don't
have data that suggests it is worth it.
In general, this patch makes much easier to tweak the internal representation of
the grid style data structures. Overall, I think it's a win, the amount of magic
going on in that mako code was a bit huge; it took a bit to wrap my head around
it.
This patch comments out the style struct size assertions. They will be
uncommented in a follow-up patch which contains some improvements for this type,
which are worth getting reviewed separately.
Also, this patch doesn't remove as much code as I would've hoped for because of
I tried not to change most of the dom/grid code for inspector, but I think a
fair bit of the nsGridContainerFrame.cpp code that collects information for it
can be simplified / de-copy-pasted to some extent. But that was a pre-existing
problem and this patch is already quite massive.
Differential Revision: https://phabricator.services.mozilla.com/D36598
2019-06-28 14:27:19 +03:00
|
|
|
template <>
|
|
|
|
inline Maybe<size_t> StyleGridTemplateComponent::RepeatAutoIndex() const {
|
|
|
|
if (!IsTrackList()) {
|
|
|
|
return Nothing();
|
|
|
|
}
|
2019-07-02 02:35:50 +03:00
|
|
|
auto& list = *AsTrackList();
|
Bug 1519958 - Refactor grid types to preserve repeat() at computed value time and use cbindgen. r=mats,boris
I'm _really_ sorry for the size of the patch. I tried to do this in two steps
but it was a lot of work and pretty ugly.
This patch makes us use cbindgen for grid-template-{rows,columns}, in order to:
* Make us preserve repeat() at computed-value time. This is per spec since
interpolation needs to know about repeat(). Except for subgrid, which did the
repeat expansion at parse-time and was a bit more annoying (plus it doesn't
really animate yet so we don't need it to comply with the spec).
* Tweaks the WPT tests for interpolation to adopt the resolution at:
https://github.com/w3c/csswg-drafts/issues/3503.
Trade-off here, as this patch stands, is that this change makes us use less
long-living memory, since we expand repeat() during layout, but at the cost of a
bit of CPU time during layout (conditional on the property applying though,
which wasn't the case before). It should be very easy to store a cached version
of the template, should this be too hot (I expect it isn't), or to change the
representation in other ways to optimize grid layout code if it's worth it.
Another trade-off: I've used SmallPointerArray to handle line-name merging,
pointing to the individual arrays in the style data, rather than actually
heap-allocating the merged lists. This would also be pretty easy to change
should we measure and see that it's not worth it.
This patch also opens the gate to potentially improving memory usage in some
other ways, by reference-counting line-name lists for example, though I don't
have data that suggests it is worth it.
In general, this patch makes much easier to tweak the internal representation of
the grid style data structures. Overall, I think it's a win, the amount of magic
going on in that mako code was a bit huge; it took a bit to wrap my head around
it.
This patch comments out the style struct size assertions. They will be
uncommented in a follow-up patch which contains some improvements for this type,
which are worth getting reviewed separately.
Also, this patch doesn't remove as much code as I would've hoped for because of
I tried not to change most of the dom/grid code for inspector, but I think a
fair bit of the nsGridContainerFrame.cpp code that collects information for it
can be simplified / de-copy-pasted to some extent. But that was a pre-existing
problem and this patch is already quite massive.
Differential Revision: https://phabricator.services.mozilla.com/D36598
2019-06-28 14:27:19 +03:00
|
|
|
return list.auto_repeat_index < list.values.Length()
|
|
|
|
? Some(list.auto_repeat_index)
|
|
|
|
: Nothing();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline bool StyleGridTemplateComponent::HasRepeatAuto() const {
|
|
|
|
return RepeatAutoIndex().isSome();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline Span<const StyleGenericTrackListValue<LengthPercentage, StyleInteger>>
|
|
|
|
StyleGridTemplateComponent::TrackListValues() const {
|
|
|
|
if (IsTrackList()) {
|
2019-07-02 02:35:50 +03:00
|
|
|
return AsTrackList()->values.AsSpan();
|
Bug 1519958 - Refactor grid types to preserve repeat() at computed value time and use cbindgen. r=mats,boris
I'm _really_ sorry for the size of the patch. I tried to do this in two steps
but it was a lot of work and pretty ugly.
This patch makes us use cbindgen for grid-template-{rows,columns}, in order to:
* Make us preserve repeat() at computed-value time. This is per spec since
interpolation needs to know about repeat(). Except for subgrid, which did the
repeat expansion at parse-time and was a bit more annoying (plus it doesn't
really animate yet so we don't need it to comply with the spec).
* Tweaks the WPT tests for interpolation to adopt the resolution at:
https://github.com/w3c/csswg-drafts/issues/3503.
Trade-off here, as this patch stands, is that this change makes us use less
long-living memory, since we expand repeat() during layout, but at the cost of a
bit of CPU time during layout (conditional on the property applying though,
which wasn't the case before). It should be very easy to store a cached version
of the template, should this be too hot (I expect it isn't), or to change the
representation in other ways to optimize grid layout code if it's worth it.
Another trade-off: I've used SmallPointerArray to handle line-name merging,
pointing to the individual arrays in the style data, rather than actually
heap-allocating the merged lists. This would also be pretty easy to change
should we measure and see that it's not worth it.
This patch also opens the gate to potentially improving memory usage in some
other ways, by reference-counting line-name lists for example, though I don't
have data that suggests it is worth it.
In general, this patch makes much easier to tweak the internal representation of
the grid style data structures. Overall, I think it's a win, the amount of magic
going on in that mako code was a bit huge; it took a bit to wrap my head around
it.
This patch comments out the style struct size assertions. They will be
uncommented in a follow-up patch which contains some improvements for this type,
which are worth getting reviewed separately.
Also, this patch doesn't remove as much code as I would've hoped for because of
I tried not to change most of the dom/grid code for inspector, but I think a
fair bit of the nsGridContainerFrame.cpp code that collects information for it
can be simplified / de-copy-pasted to some extent. But that was a pre-existing
problem and this patch is already quite massive.
Differential Revision: https://phabricator.services.mozilla.com/D36598
2019-06-28 14:27:19 +03:00
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline const StyleGenericTrackRepeat<LengthPercentage, StyleInteger>*
|
|
|
|
StyleGridTemplateComponent::GetRepeatAutoValue() const {
|
|
|
|
auto index = RepeatAutoIndex();
|
|
|
|
if (!index) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return &TrackListValues()[*index].AsTrackRepeat();
|
|
|
|
}
|
|
|
|
|
2019-08-21 22:47:53 +03:00
|
|
|
constexpr const auto kPaintOrderShift = StylePAINT_ORDER_SHIFT;
|
|
|
|
constexpr const auto kPaintOrderMask = StylePAINT_ORDER_MASK;
|
|
|
|
|
2019-08-27 02:09:47 +03:00
|
|
|
template <>
|
2019-09-12 15:32:12 +03:00
|
|
|
inline nsRect StyleGenericClipRect<LengthOrAuto>::ToLayoutRect(
|
|
|
|
nscoord aAutoSize) const {
|
2019-08-27 02:09:47 +03:00
|
|
|
nscoord x = left.IsLength() ? left.ToLength() : 0;
|
|
|
|
nscoord y = top.IsLength() ? top.ToLength() : 0;
|
|
|
|
nscoord width = right.IsLength() ? right.ToLength() - x : aAutoSize;
|
|
|
|
nscoord height = bottom.IsLength() ? bottom.ToLength() - y : aAutoSize;
|
|
|
|
return nsRect(x, y, width, height);
|
|
|
|
}
|
|
|
|
|
2020-02-11 04:22:15 +03:00
|
|
|
using RestyleHint = StyleRestyleHint;
|
|
|
|
|
|
|
|
inline RestyleHint RestyleHint::RestyleSubtree() {
|
2020-03-06 23:11:51 +03:00
|
|
|
return RESTYLE_SELF | RESTYLE_DESCENDANTS;
|
2020-02-11 04:22:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
inline RestyleHint RestyleHint::RecascadeSubtree() {
|
2020-03-06 23:11:51 +03:00
|
|
|
return RECASCADE_SELF | RECASCADE_DESCENDANTS;
|
2020-02-11 04:22:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
inline RestyleHint RestyleHint::ForAnimations() {
|
2020-03-06 23:11:51 +03:00
|
|
|
return RESTYLE_CSS_TRANSITIONS | RESTYLE_CSS_ANIMATIONS | RESTYLE_SMIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool RestyleHint::DefinitelyRecascadesAllSubtree() const {
|
|
|
|
if (!(*this & (RECASCADE_DESCENDANTS | RESTYLE_DESCENDANTS))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return bool(*this & (RESTYLE_SELF | RECASCADE_SELF));
|
2020-02-11 04:22:15 +03:00
|
|
|
}
|
|
|
|
|
2020-02-11 23:56:20 +03:00
|
|
|
template <>
|
|
|
|
inline bool StyleImage::IsImageRequestType() const {
|
|
|
|
return IsUrl() || IsRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline const StyleComputedImageUrl* StyleImage::GetImageRequestURLValue()
|
|
|
|
const {
|
|
|
|
if (IsUrl()) {
|
|
|
|
return &AsUrl();
|
|
|
|
}
|
|
|
|
if (IsRect()) {
|
|
|
|
return &AsRect()->url;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline imgRequestProxy* StyleImage::GetImageRequest() const {
|
|
|
|
auto* url = GetImageRequestURLValue();
|
|
|
|
return url ? url->GetImage() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline bool StyleImage::IsResolved() const {
|
|
|
|
auto* url = GetImageRequestURLValue();
|
|
|
|
return !url || url->IsImageResolved();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
bool StyleImage::IsOpaque() const;
|
|
|
|
template <>
|
|
|
|
bool StyleImage::IsSizeAvailable() const;
|
|
|
|
template <>
|
|
|
|
bool StyleImage::IsComplete() const;
|
|
|
|
template <>
|
|
|
|
bool StyleImage::StartDecoding() const;
|
|
|
|
template <>
|
|
|
|
Maybe<StyleImage::ActualCropRect> StyleImage::ComputeActualCropRect() const;
|
|
|
|
template <>
|
|
|
|
void StyleImage::ResolveImage(dom::Document&, const StyleImage*);
|
|
|
|
|
2019-05-09 15:43:19 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|