Bug 982141 - Introduce nsLayoutUtils::SetDisplayPortMargins, with an option to not repaint. r=tn
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -429,44 +429,25 @@ nsDOMWindowUtils::SetDisplayPortMarginsF
if (!content) {
return NS_ERROR_INVALID_ARG;
}
if (content->GetCurrentDoc() != presShell->GetDocument()) {
return NS_ERROR_INVALID_ARG;
}
- DisplayPortMarginsPropertyData* currentData =
- static_cast<DisplayPortMarginsPropertyData*>(content->GetProperty(nsGkAtoms::DisplayPortMargins));
- if (currentData && currentData->mPriority > aPriority) {
- return NS_OK;
- }
-
// Note order change of arguments between our function signature and
// LayerMargin constructor.
LayerMargin displayportMargins(aTopMargin,
aRightMargin,
aBottomMargin,
aLeftMargin);
- content->SetProperty(nsGkAtoms::DisplayPortMargins,
- new DisplayPortMarginsPropertyData(displayportMargins, aAlignmentX, aAlignmentY, aPriority),
- nsINode::DeleteProperty<DisplayPortMarginsPropertyData>);
-
- nsIFrame* rootScrollFrame = presShell->GetRootScrollFrame();
- if (rootScrollFrame && content == rootScrollFrame->GetContent()) {
- // We are setting a root displayport for a document.
- // The pres shell needs a special flag set.
- presShell->SetIgnoreViewportScrolling(true);
- }
-
- nsIFrame* rootFrame = presShell->FrameManager()->GetRootFrame();
- if (rootFrame) {
- rootFrame->SchedulePaint();
- }
+ nsLayoutUtils::SetDisplayPortMargins(content, presShell, displayportMargins,
+ aAlignmentX, aAlignmentY, aPriority);
return NS_OK;
}
NS_IMETHODIMP
nsDOMWindowUtils::SetDisplayPortBaseForElement(int32_t aX,
int32_t aY,
@@ -492,18 +473,17 @@ nsDOMWindowUtils::SetDisplayPortBaseForE
if (!content) {
return NS_ERROR_INVALID_ARG;
}
if (content->GetCurrentDoc() != presShell->GetDocument()) {
return NS_ERROR_INVALID_ARG;
}
- content->SetProperty(nsGkAtoms::DisplayPortBase, new nsRect(aX, aY, aWidth, aHeight),
- nsINode::DeleteProperty<nsRect>);
+ nsLayoutUtils::SetDisplayPortBase(content, nsRect(aX, aY, aWidth, aHeight));
return NS_OK;
}
NS_IMETHODIMP
nsDOMWindowUtils::SetCriticalDisplayPortForElement(float aXPx, float aYPx,
float aWidthPx, float aHeightPx,
nsIDOMElement* aElement)
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -768,16 +768,51 @@ nsLayoutUtils::GetDisplayPort(nsIContent
}
}
}
return true;
}
void
+nsLayoutUtils::SetDisplayPortMargins(nsIContent* aContent,
+ nsIPresShell* aPresShell,
+ const LayerMargin& aMargins,
+ uint32_t aAlignmentX,
+ uint32_t aAlignmentY,
+ uint32_t aPriority,
+ RepaintMode aRepaintMode)
+{
+ DisplayPortMarginsPropertyData* currentData =
+ static_cast<DisplayPortMarginsPropertyData*>(aContent->GetProperty(nsGkAtoms::DisplayPortMargins));
+ if (currentData && currentData->mPriority > aPriority) {
+ return;
+ }
+
+ aContent->SetProperty(nsGkAtoms::DisplayPortMargins,
+ new DisplayPortMarginsPropertyData(
+ aMargins, aAlignmentX, aAlignmentY, aPriority),
+ nsINode::DeleteProperty<DisplayPortMarginsPropertyData>);
+
+ nsIFrame* rootScrollFrame = aPresShell->GetRootScrollFrame();
+ if (rootScrollFrame && aContent == rootScrollFrame->GetContent()) {
+ // We are setting a root displayport for a document.
+ // The pres shell needs a special flag set.
+ aPresShell->SetIgnoreViewportScrolling(true);
+ }
+
+ if (aRepaintMode == RepaintMode::Repaint) {
+ nsIFrame* rootFrame = aPresShell->FrameManager()->GetRootFrame();
+ if (rootFrame) {
+ rootFrame->SchedulePaint();
+ }
+ }
+}
+
+void
nsLayoutUtils::SetDisplayPortBase(nsIContent* aContent, const nsRect& aBase)
{
aContent->SetProperty(nsGkAtoms::DisplayPortBase, new nsRect(aBase),
nsINode::DeleteProperty<nsRect>);
}
bool
nsLayoutUtils::GetCriticalDisplayPort(nsIContent* aContent, nsRect* aResult)
--- a/layout/base/nsLayoutUtils.h
+++ b/layout/base/nsLayoutUtils.h
@@ -122,16 +122,17 @@ class nsLayoutUtils
typedef mozilla::gfx::DrawTarget DrawTarget;
typedef mozilla::gfx::Rect Rect;
public:
typedef mozilla::layers::FrameMetrics FrameMetrics;
typedef FrameMetrics::ViewID ViewID;
typedef mozilla::CSSPoint CSSPoint;
typedef mozilla::CSSSize CSSSize;
+ typedef mozilla::LayerMargin LayerMargin;
/**
* Finds previously assigned ViewID for the given content element, if any.
* Returns whether a ViewID was previously assigned.
*/
static bool FindIDFor(const nsIContent* aContent, ViewID* aOutViewId);
/**
@@ -150,21 +151,48 @@ public:
*/
static nsIScrollableFrame* FindScrollableFrameFor(ViewID aId);
/**
* Get display port for the given element.
*/
static bool GetDisplayPort(nsIContent* aContent, nsRect *aResult = nullptr);
- /**
- * Set the display port base rect for given element to be used with display
- * port margins.
- */
- static void SetDisplayPortBase(nsIContent* aContent, const nsRect& aBase);
+ MOZ_BEGIN_ENUM_CLASS(RepaintMode, uint8_t)
+ Repaint,
+ DoNotRepaint
+ MOZ_END_ENUM_CLASS(RepaintMode)
+
+ /**
+ * Set the display port margins for a content element to be used with a
+ * display port base (see SetDisplayPortBase()).
+ * See also nsIDOMWindowUtils.setDisplayPortMargins.
+ * @param aContent the content element for which to set the margins
+ * @param aPresShell the pres shell for the document containing the element
+ * @param aMargins the margins to set
+ * @param aAlignmentX, alignmentY the amount of pixels to which to align the
+ * displayport built by combining the base
+ * rect with the margins, in either direction
+ * @param aPriority a priority value to determine which margins take effect
+ * when multiple callers specify margins
+ * @param aRepaintMode whether to schedule a paint after setting the margins
+ */
+ static void SetDisplayPortMargins(nsIContent* aContent,
+ nsIPresShell* aPresShell,
+ const LayerMargin& aMargins,
+ uint32_t aAlignmentX,
+ uint32_t aAlignmentY,
+ uint32_t aPriority = 0,
+ RepaintMode aRepaintMode = RepaintMode::Repaint);
+
+ /**
+ * Set the display port base rect for given element to be used with display
+ * port margins.
+ */
+ static void SetDisplayPortBase(nsIContent* aContent, const nsRect& aBase);
/**
* Get the critical display port for the given element.
*/
static bool GetCriticalDisplayPort(nsIContent* aContent, nsRect* aResult = nullptr);
/**
* Use heuristics to figure out the child list that