зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1638917 - Replace mozilla::Tuple with std::tuple in layout. r=emilio
Also, replace mozilla::Tie with std::tie, and use C++17 structured binding at some places where they make sense. Differential Revision: https://phabricator.services.mozilla.com/D75821
This commit is contained in:
Родитель
f8ddec1645
Коммит
0865183345
|
@ -8,6 +8,8 @@
|
|||
|
||||
#include "nsCSSRenderingGradients.h"
|
||||
|
||||
#include <tuple>
|
||||
|
||||
#include "gfx2DGlue.h"
|
||||
#include "mozilla/ArrayUtils.h"
|
||||
#include "mozilla/ComputedStyle.h"
|
||||
|
@ -60,7 +62,7 @@ static CSSPoint ComputeGradientLineEndFromAngle(const CSSPoint& aStart,
|
|||
}
|
||||
|
||||
// Compute the start and end points of the gradient line for a linear gradient.
|
||||
static Tuple<CSSPoint, CSSPoint> ComputeLinearGradientLine(
|
||||
static std::tuple<CSSPoint, CSSPoint> ComputeLinearGradientLine(
|
||||
nsPresContext* aPresContext, const StyleGradient& aGradient,
|
||||
const CSSSize& aBoxSize) {
|
||||
using X = StyleHorizontalPositionKeyword;
|
||||
|
@ -79,7 +81,7 @@ static Tuple<CSSPoint, CSSPoint> ComputeLinearGradientLine(
|
|||
}
|
||||
CSSPoint end = ComputeGradientLineEndFromAngle(center, angle, aBoxSize);
|
||||
CSSPoint start = CSSPoint(aBoxSize.width, aBoxSize.height) - end;
|
||||
return MakeTuple(start, end);
|
||||
return {start, end};
|
||||
}
|
||||
case StyleLineDirection::Tag::Vertical: {
|
||||
CSSPoint start(center.x, 0);
|
||||
|
@ -87,7 +89,7 @@ static Tuple<CSSPoint, CSSPoint> ComputeLinearGradientLine(
|
|||
if (isModern == (direction.AsVertical() == Y::Top)) {
|
||||
std::swap(start.y, end.y);
|
||||
}
|
||||
return MakeTuple(start, end);
|
||||
return {start, end};
|
||||
}
|
||||
case StyleLineDirection::Tag::Horizontal: {
|
||||
CSSPoint start(0, center.y);
|
||||
|
@ -95,7 +97,7 @@ static Tuple<CSSPoint, CSSPoint> ComputeLinearGradientLine(
|
|||
if (isModern == (direction.AsHorizontal() == X::Left)) {
|
||||
std::swap(start.x, end.x);
|
||||
}
|
||||
return MakeTuple(start, end);
|
||||
return {start, end};
|
||||
}
|
||||
case StyleLineDirection::Tag::Corner: {
|
||||
const auto& corner = direction.AsCorner();
|
||||
|
@ -108,7 +110,7 @@ static Tuple<CSSPoint, CSSPoint> ComputeLinearGradientLine(
|
|||
double angle = atan2(ySign * aBoxSize.width, xSign * aBoxSize.height);
|
||||
CSSPoint end = ComputeGradientLineEndFromAngle(center, angle, aBoxSize);
|
||||
CSSPoint start = CSSPoint(aBoxSize.width, aBoxSize.height) - end;
|
||||
return MakeTuple(start, end);
|
||||
return {start, end};
|
||||
}
|
||||
|
||||
CSSCoord startX = h == X::Left ? 0.0 : aBoxSize.width;
|
||||
|
@ -116,13 +118,13 @@ static Tuple<CSSPoint, CSSPoint> ComputeLinearGradientLine(
|
|||
|
||||
CSSPoint start(startX, startY);
|
||||
CSSPoint end = CSSPoint(aBoxSize.width, aBoxSize.height) - start;
|
||||
return MakeTuple(start, end);
|
||||
return {start, end};
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
MOZ_ASSERT_UNREACHABLE("Unknown line direction");
|
||||
return MakeTuple(CSSPoint(), CSSPoint());
|
||||
return {CSSPoint(), CSSPoint()};
|
||||
}
|
||||
|
||||
using EndingShape = StyleGenericEndingShape<Length, LengthPercentage>;
|
||||
|
@ -153,8 +155,9 @@ static RadialGradientRadii ComputeRadialGradientRadii(const EndingShape& aShape,
|
|||
// Compute the start and end points of the gradient line for a radial gradient.
|
||||
// Also returns the horizontal and vertical radii defining the circle or
|
||||
// ellipse to use.
|
||||
static Tuple<CSSPoint, CSSPoint, CSSCoord, CSSCoord> ComputeRadialGradientLine(
|
||||
const StyleGradient& aGradient, const CSSSize& aBoxSize) {
|
||||
static std::tuple<CSSPoint, CSSPoint, CSSCoord, CSSCoord>
|
||||
ComputeRadialGradientLine(const StyleGradient& aGradient,
|
||||
const CSSSize& aBoxSize) {
|
||||
const auto& radial = aGradient.AsRadial();
|
||||
const EndingShape& endingShape = radial.shape;
|
||||
const Position& position = radial.position;
|
||||
|
@ -223,18 +226,18 @@ static Tuple<CSSPoint, CSSPoint, CSSCoord, CSSCoord> ComputeRadialGradientLine(
|
|||
// The gradient line end point is where the gradient line intersects
|
||||
// the ellipse.
|
||||
CSSPoint end = start + CSSPoint(radiusX, 0);
|
||||
return MakeTuple(start, end, radiusX, radiusY);
|
||||
return {start, end, radiusX, radiusY};
|
||||
}
|
||||
|
||||
// Compute the center and the start angle of the conic gradient.
|
||||
static Tuple<CSSPoint, float> ComputeConicGradientProperties(
|
||||
static std::tuple<CSSPoint, float> ComputeConicGradientProperties(
|
||||
const StyleGradient& aGradient, const CSSSize& aBoxSize) {
|
||||
const auto& conic = aGradient.AsConic();
|
||||
const Position& position = conic.position;
|
||||
float angle = static_cast<float>(conic.angle.ToRadians());
|
||||
CSSPoint center = ResolvePosition(position, aBoxSize);
|
||||
|
||||
return MakeTuple(center, angle);
|
||||
return {center, angle};
|
||||
}
|
||||
|
||||
static float Interpolate(float aF1, float aF2, float aFrac) {
|
||||
|
@ -693,14 +696,15 @@ nsCSSGradientRenderer nsCSSGradientRenderer::Create(
|
|||
CSSCoord radiusX = 0, radiusY = 0; // for radial gradients only
|
||||
float angle = 0.0; // for conic gradients only
|
||||
if (aGradient.IsLinear()) {
|
||||
Tie(lineStart, lineEnd) =
|
||||
std::tie(lineStart, lineEnd) =
|
||||
ComputeLinearGradientLine(aPresContext, aGradient, srcSize);
|
||||
} else if (aGradient.IsRadial()) {
|
||||
Tie(lineStart, lineEnd, radiusX, radiusY) =
|
||||
std::tie(lineStart, lineEnd, radiusX, radiusY) =
|
||||
ComputeRadialGradientLine(aGradient, srcSize);
|
||||
} else {
|
||||
MOZ_ASSERT(aGradient.IsConic());
|
||||
Tie(center, angle) = ComputeConicGradientProperties(aGradient, srcSize);
|
||||
std::tie(center, angle) =
|
||||
ComputeConicGradientProperties(aGradient, srcSize);
|
||||
}
|
||||
// Avoid sending Infs or Nans to downwind draw targets.
|
||||
if (!lineStart.IsFinite() || !lineEnd.IsFinite()) {
|
||||
|
|
|
@ -502,7 +502,7 @@ struct Loader::Sheets {
|
|||
RefPtr<StyleSheet> LookupInline(const nsAString&);
|
||||
|
||||
// A cache hit or miss. It is a miss if the `StyleSheet` is null.
|
||||
using CacheResult = Tuple<RefPtr<StyleSheet>, SheetState>;
|
||||
using CacheResult = std::tuple<RefPtr<StyleSheet>, SheetState>;
|
||||
CacheResult Lookup(SheetLoadDataHashKey&, bool aSyncLoad);
|
||||
|
||||
size_t SizeOfIncludingThis(MallocSizeOf) const;
|
||||
|
@ -559,7 +559,7 @@ auto Loader::Sheets::Lookup(SheetLoadDataHashKey& aKey, bool aSyncLoad)
|
|||
// keys off the URI. See below for the unique inner check.
|
||||
if (!sheet->HasModifiedRules() &&
|
||||
sheet->ParsingMode() == aKey.ParsingMode()) {
|
||||
return MakeTuple(CloneSheet(*sheet), SheetState::Complete);
|
||||
return {CloneSheet(*sheet), SheetState::Complete};
|
||||
}
|
||||
LOG(
|
||||
(" Not cloning due to forced unique inner or mismatched "
|
||||
|
@ -603,7 +603,7 @@ auto Loader::Sheets::Lookup(SheetLoadDataHashKey& aKey, bool aSyncLoad)
|
|||
cachedSheet = clone;
|
||||
}
|
||||
|
||||
return MakeTuple(std::move(clone), SheetState::Complete);
|
||||
return {std::move(clone), SheetState::Complete};
|
||||
}
|
||||
LOG((" Not cloning due to modified rules"));
|
||||
// Remove it now that we know that we're never going to use this stylesheet
|
||||
|
@ -618,13 +618,13 @@ auto Loader::Sheets::Lookup(SheetLoadDataHashKey& aKey, bool aSyncLoad)
|
|||
if (SheetLoadData* data = mLoadingDatas.Get(&aKey)) {
|
||||
LOG((" From loading: %p", data->mSheet.get()));
|
||||
AssertIncompleteSheetMatches(*data, aKey);
|
||||
return MakeTuple(CloneSheet(*data->mSheet), SheetState::Loading);
|
||||
return {CloneSheet(*data->mSheet), SheetState::Loading};
|
||||
}
|
||||
|
||||
if (SheetLoadData* data = mPendingDatas.GetWeak(&aKey)) {
|
||||
LOG((" From pending: %p", data->mSheet.get()));
|
||||
AssertIncompleteSheetMatches(*data, aKey);
|
||||
return MakeTuple(CloneSheet(*data->mSheet), SheetState::Pending);
|
||||
return {CloneSheet(*data->mSheet), SheetState::Pending};
|
||||
}
|
||||
|
||||
return {};
|
||||
|
@ -1141,7 +1141,7 @@ nsresult Loader::CheckContentPolicy(nsIPrincipal* aLoadingPrincipal,
|
|||
* state of the sheet they are clones off; make sure to call PrepareSheet() on
|
||||
* the result of CreateSheet().
|
||||
*/
|
||||
Tuple<RefPtr<StyleSheet>, Loader::SheetState> Loader::CreateSheet(
|
||||
std::tuple<RefPtr<StyleSheet>, Loader::SheetState> Loader::CreateSheet(
|
||||
nsIURI* aURI, nsIContent* aLinkingContent, nsIPrincipal* aLoaderPrincipal,
|
||||
css::SheetParsingMode aParsingMode, CORSMode aCORSMode,
|
||||
nsIReferrerInfo* aLoadingReferrerInfo, const nsAString& aIntegrity,
|
||||
|
@ -1169,9 +1169,8 @@ Tuple<RefPtr<StyleSheet>, Loader::SheetState> Loader::CreateSheet(
|
|||
aCORSMode, aParsingMode, sriMetadata,
|
||||
false /** TODO - is-link-preload **/);
|
||||
auto cacheResult = mSheets->Lookup(key, aSyncLoad);
|
||||
if (Get<0>(cacheResult)) {
|
||||
LOG((" Hit cache with state: %s",
|
||||
gStateStrings[size_t(Get<1>(cacheResult))]));
|
||||
if (const auto& [styleSheet, sheetState] = cacheResult; styleSheet) {
|
||||
LOG((" Hit cache with state: %s", gStateStrings[size_t(sheetState)]));
|
||||
return cacheResult;
|
||||
}
|
||||
|
||||
|
@ -1185,7 +1184,7 @@ Tuple<RefPtr<StyleSheet>, Loader::SheetState> Loader::CreateSheet(
|
|||
ReferrerInfo::CreateForExternalCSSResources(sheet);
|
||||
sheet->SetReferrerInfo(referrerInfo);
|
||||
LOG((" Needs parser"));
|
||||
return MakeTuple(std::move(sheet), SheetState::NeedsParser);
|
||||
return {std::move(sheet), SheetState::NeedsParser};
|
||||
}
|
||||
|
||||
static Loader::MediaMatched MediaListMatches(const MediaList* aMediaList,
|
||||
|
@ -2086,10 +2085,7 @@ Result<Loader::LoadSheetResult, nsresult> Loader::LoadStyleLink(
|
|||
// Check IsAlternateSheet now, since it can mutate our document and make
|
||||
// pending sheets go to the non-pending state.
|
||||
auto isAlternate = IsAlternateSheet(aInfo.mTitle, aInfo.mHasAlternateRel);
|
||||
|
||||
SheetState state;
|
||||
RefPtr<StyleSheet> sheet;
|
||||
Tie(sheet, state) =
|
||||
auto [sheet, state] =
|
||||
CreateSheet(aInfo, principal, eAuthorSheetFeatures, syncLoad);
|
||||
|
||||
LOG((" Sheet is alternate: %d", static_cast<int>(isAlternate)));
|
||||
|
@ -2252,7 +2248,7 @@ nsresult Loader::LoadChildSheet(StyleSheet& aParentSheet,
|
|||
state = SheetState::Complete;
|
||||
} else {
|
||||
// For now, use CORS_NONE for child sheets
|
||||
Tie(sheet, state) =
|
||||
std::tie(sheet, state) =
|
||||
CreateSheet(aURL, nullptr, principal, aParentSheet.ParsingMode(),
|
||||
CORS_NONE, aParentSheet.GetReferrerInfo(),
|
||||
EmptyString(), // integrity is only checked on main sheet
|
||||
|
@ -2346,10 +2342,7 @@ Result<RefPtr<StyleSheet>, nsresult> Loader::InternalLoadNonDocumentSheet(
|
|||
}
|
||||
|
||||
bool syncLoad = !aObserver;
|
||||
|
||||
SheetState state;
|
||||
RefPtr<StyleSheet> sheet;
|
||||
Tie(sheet, state) =
|
||||
auto [sheet, state] =
|
||||
CreateSheet(aURL, nullptr, aOriginPrincipal, aParsingMode, aCORSMode,
|
||||
aReferrerInfo, aIntegrity, syncLoad);
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#ifndef mozilla_css_Loader_h
|
||||
#define mozilla_css_Loader_h
|
||||
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
|
@ -342,7 +343,7 @@ class Loader final {
|
|||
Complete
|
||||
};
|
||||
|
||||
Tuple<RefPtr<StyleSheet>, SheetState> CreateSheet(
|
||||
std::tuple<RefPtr<StyleSheet>, SheetState> CreateSheet(
|
||||
const SheetInfo& aInfo, nsIPrincipal* aLoaderPrincipal,
|
||||
css::SheetParsingMode aParsingMode, bool aSyncLoad) {
|
||||
return CreateSheet(aInfo.mURI, aInfo.mContent, aLoaderPrincipal,
|
||||
|
@ -353,7 +354,7 @@ class Loader final {
|
|||
// For inline style, the aURI param is null, but the aLinkingContent
|
||||
// must be non-null then. The loader principal must never be null
|
||||
// if aURI is not null.
|
||||
Tuple<RefPtr<StyleSheet>, SheetState> CreateSheet(
|
||||
std::tuple<RefPtr<StyleSheet>, SheetState> CreateSheet(
|
||||
nsIURI* aURI, nsIContent* aLinkingContent, nsIPrincipal* aLoaderPrincipal,
|
||||
css::SheetParsingMode, CORSMode, nsIReferrerInfo* aLoadingReferrerInfo,
|
||||
const nsAString& aIntegrity, bool aSyncLoad);
|
||||
|
|
Загрузка…
Ссылка в новой задаче