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

View file

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

View file

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

View file

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

View file

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

View file

@ -72,17 +72,6 @@ public:
bool* aWasCurrentColor = nullptr, bool* aWasCurrentColor = nullptr,
css::Loader* aLoader = 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 * Parse a string representing a CSS property value into a
* RawServoDeclarationBlock. * RawServoDeclarationBlock.