Bug 1448763 part 1 - Make DOMIntersectionObserver use nsStyleSides for mRootMargin, and use Servo code to serialize it. r=emilio

MozReview-Commit-ID: 8RsoLflRtzE

--HG--
extra : rebase_source : 7e9c53dafe473e77087c880ab39e5265638f0f7e
This commit is contained in:
Xidorn Quan 2018-04-05 18:27:33 +10:00
parent 2120e04223
commit 65a9ee4d6a
6 changed files with 13 additions and 39 deletions

View file

@ -10,7 +10,7 @@
#include "nsIFrame.h"
#include "nsContentUtils.h"
#include "nsLayoutUtils.h"
#include "mozilla/ServoCSSParser.h"
#include "mozilla/ServoBindings.h"
namespace mozilla {
namespace dom {
@ -116,14 +116,14 @@ DOMIntersectionObserver::Constructor(const mozilla::dom::GlobalObject& aGlobal,
bool
DOMIntersectionObserver::SetRootMargin(const nsAString& aString)
{
return ServoCSSParser::ParseIntersectionObserverRootMargin(aString,
&mRootMargin);
return Servo_IntersectionObserverRootMargin_Parse(&aString, &mRootMargin);
}
void
DOMIntersectionObserver::GetRootMargin(mozilla::dom::DOMString& aRetVal)
{
mRootMargin.AppendToString(eCSSProperty_DOM, aRetVal);
nsString& retVal = aRetVal;
Servo_IntersectionObserverRootMargin_ToString(&mRootMargin, &retVal);
}
void
@ -306,15 +306,7 @@ DOMIntersectionObserver::Update(nsIDocument* aDocument, DOMHighResTimeStamp time
NS_FOR_CSS_SIDES(side) {
nscoord basis = side == eSideTop || side == eSideBottom ?
rootRect.Height() : rootRect.Width();
nsCSSValue value = mRootMargin.*nsCSSRect::sides[side];
nsStyleCoord coord;
if (value.IsPixelLengthUnit()) {
coord.SetCoordValue(value.GetPixelLength());
} else if (value.IsPercentLengthUnit()) {
coord.SetPercentValue(value.GetPercentValue());
} else {
MOZ_ASSERT_UNREACHABLE("invalid length unit");
}
nsStyleCoord coord = mRootMargin.Get(side);
rootMargin.Side(side) = nsLayoutUtils::ComputeCBDependentValue(basis, coord);
}

View file

@ -8,7 +8,7 @@
#define DOMIntersectionObserver_h
#include "mozilla/dom/IntersectionObserverBinding.h"
#include "nsCSSValue.h"
#include "nsStyleCoord.h"
#include "nsTArray.h"
using mozilla::dom::DOMRect;
@ -177,7 +177,7 @@ protected:
RefPtr<nsIDocument> mDocument;
RefPtr<mozilla::dom::IntersectionCallback> mCallback;
RefPtr<Element> mRoot;
nsCSSRect mRootMargin;
nsStyleSides mRootMargin;
nsTArray<double> mThresholds;
// Holds raw pointers which are explicitly cleared by UnlinkTarget().

View file

@ -836,9 +836,10 @@ SERVO_BINDING_FUNC(Servo_ComputeColor, bool,
nscolor* result_color,
bool* was_current_color,
mozilla::css::Loader* loader)
SERVO_BINDING_FUNC(Servo_ParseIntersectionObserverRootMargin, bool,
const nsAString* value,
nsCSSRect* result);
SERVO_BINDING_FUNC(Servo_IntersectionObserverRootMargin_Parse, bool,
const nsAString* value, nsStyleSides* result)
SERVO_BINDING_FUNC(Servo_IntersectionObserverRootMargin_ToString, void,
const nsStyleSides* rect, nsAString* result)
// Returning false means the parsed transform contains relative lengths or
// percentage value, so we cannot compute the matrix. In this case, we keep
// |result| and |contains_3d_transform| as-is.

View file

@ -282,8 +282,6 @@ whitelist-types = [
"nsCSSPropertyID",
"nsCSSPropertyIDSet",
"nsCSSProps",
"nsCSSRect",
"nsCSSRect_heap",
"nsCSSShadowArray",
"nsCSSValue",
"nsCSSValueFloatColor",
@ -334,6 +332,7 @@ whitelist-types = [
"nsStyleOutline",
"nsStylePadding",
"nsStylePosition",
"nsStyleSides",
"nsStyleSVG",
"nsStyleSVGOpacitySource",
"nsStyleSVGPaint",
@ -534,7 +533,6 @@ structs-types = [
"nsCSSKeyword",
"nsCSSPropertyID",
"nsCSSPropertyIDSet",
"nsCSSRect",
"nsCSSShadowArray",
"nsCSSUnit",
"nsCSSValue",
@ -580,6 +578,7 @@ structs-types = [
"nsStyleSVGOpacitySource",
"nsStyleSVGPaint",
"nsStyleSVGReset",
"nsStyleSides",
"nsStyleTable",
"nsStyleTableBorder",
"nsStyleText",

View file

@ -33,13 +33,6 @@ ServoCSSParser::ComputeColor(ServoStyleSet* aStyleSet,
aWasCurrentColor, aLoader);
}
/* static */ bool
ServoCSSParser::ParseIntersectionObserverRootMargin(const nsAString& aValue,
nsCSSRect* aResult)
{
return Servo_ParseIntersectionObserverRootMargin(&aValue, aResult);
}
/* static */ already_AddRefed<RawServoDeclarationBlock>
ServoCSSParser::ParseProperty(nsCSSPropertyID aProperty,
const nsAString& aValue,

View file

@ -72,17 +72,6 @@ public:
bool* aWasCurrentColor = nullptr,
css::Loader* aLoader = nullptr);
/**
* Parses a IntersectionObserver's initialization dictionary's rootMargin
* property.
*
* @param aValue The rootMargin value.
* @param aResult The nsCSSRect object to write the result into.
* @return Whether the value was successfully parsed.
*/
static bool ParseIntersectionObserverRootMargin(const nsAString& aValue,
nsCSSRect* aResult);
/**
* Parse a string representing a CSS property value into a
* RawServoDeclarationBlock.