Bug 1284888 part 2: Make TextOverflow::WillProcessLines() return a UniquePtr, for stronger lifetime guarantees. r?jfkthame
MozReview-Commit-ID: 7KVsFlxuL9p
--- a/layout/generic/TextOverflow.cpp
+++ b/layout/generic/TextOverflow.cpp
@@ -330,32 +330,32 @@ TextOverflow::TextOverflow(nsDisplayList
} else {
mIStart.Init(style->mTextOverflow.GetRight(direction));
mIEnd.Init(style->mTextOverflow.GetLeft(direction));
}
// The left/right marker string is setup in ExamineLineFrames when a line
// has overflow on that side.
}
-/* static */ TextOverflow*
+/* static */ UniquePtr<TextOverflow>
TextOverflow::WillProcessLines(nsDisplayListBuilder* aBuilder,
nsIFrame* aBlockFrame)
{
// Ignore 'text-overflow' for event and frame visibility processing.
if (aBuilder->IsForEventDelivery() ||
aBuilder->IsForFrameVisibility() ||
!CanHaveTextOverflow(aBlockFrame)) {
return nullptr;
}
nsIScrollableFrame* scrollableFrame = nsLayoutUtils::GetScrollableFrameFor(aBlockFrame);
if (scrollableFrame && scrollableFrame->IsTransformingByAPZ()) {
// If the APZ is actively scrolling this, don't bother with markers.
return nullptr;
}
- return new TextOverflow(aBuilder, aBlockFrame);
+ return MakeUnique<TextOverflow>(aBuilder, aBlockFrame);
}
void
TextOverflow::ExamineFrameSubtree(nsIFrame* aFrame,
const LogicalRect& aContentArea,
const LogicalRect& aInsideMarkersArea,
FrameHashtable* aFramesToHide,
AlignmentEdges* aAlignmentEdges,
--- a/layout/generic/TextOverflow.h
+++ b/layout/generic/TextOverflow.h
@@ -6,16 +6,17 @@
#ifndef TextOverflow_h_
#define TextOverflow_h_
#include "nsDisplayList.h"
#include "nsTHashtable.h"
#include "mozilla/Attributes.h"
#include "mozilla/Likely.h"
+#include "mozilla/UniquePtr.h"
#include "mozilla/WritingModes.h"
#include <algorithm>
class nsIScrollableFrame;
class nsLineBox;
namespace mozilla {
namespace css {
@@ -27,18 +28,28 @@ namespace css {
* 2. then call ProcessLine for each line you are building display lists for
*/
class MOZ_HEAP_CLASS TextOverflow final {
public:
/**
* Allocate an object for text-overflow processing.
* @return nullptr if no processing is necessary. The caller owns the object.
*/
- static TextOverflow* WillProcessLines(nsDisplayListBuilder* aBuilder,
- nsIFrame* aBlockFrame);
+ static UniquePtr<TextOverflow>
+ WillProcessLines(nsDisplayListBuilder* aBuilder,
+ nsIFrame* aBlockFrame);
+
+ /**
+ * Constructor, which client code SHOULD NOT use directly. Instead, clients
+ * should call WillProcessLines(), which is basically the factory function
+ * for TextOverflow instances.
+ */
+ TextOverflow(nsDisplayListBuilder* aBuilder,
+ nsIFrame* aBlockFrame);
+
/**
* Analyze the display lists for text overflow and what kind of item is at
* the content edges. Add display items for text-overflow markers as needed
* and remove or clip items that would overlap a marker.
*/
void ProcessLine(const nsDisplayListSet& aLists, nsLineBox* aLine);
/**
@@ -54,19 +65,16 @@ class MOZ_HEAP_CLASS TextOverflow final
/**
* @return true if aBlockFrame needs analysis for text overflow.
*/
static bool CanHaveTextOverflow(nsIFrame* aBlockFrame);
typedef nsTHashtable<nsPtrHashKey<nsIFrame>> FrameHashtable;
private:
- TextOverflow(nsDisplayListBuilder* aBuilder,
- nsIFrame* aBlockFrame);
-
typedef mozilla::WritingMode WritingMode;
typedef mozilla::LogicalRect LogicalRect;
struct AlignmentEdges {
AlignmentEdges() : mAssigned(false) {}
void Accumulate(WritingMode aWM, const LogicalRect& aRect)
{
if (MOZ_LIKELY(mAssigned)) {
--- a/layout/generic/nsBlockFrame.cpp
+++ b/layout/generic/nsBlockFrame.cpp
@@ -6751,18 +6751,18 @@ nsBlockFrame::BuildDisplayList(nsDisplay
if (f->GetStateBits() & NS_FRAME_IS_PUSHED_FLOAT)
BuildDisplayListForChild(aBuilder, f, aDirtyRect, aLists);
}
}
aBuilder->MarkFramesForDisplayList(this, mFloats, aDirtyRect);
// Prepare for text-overflow processing.
- UniquePtr<TextOverflow> textOverflow(
- TextOverflow::WillProcessLines(aBuilder, this));
+ UniquePtr<TextOverflow> textOverflow =
+ TextOverflow::WillProcessLines(aBuilder, this);
// We'll collect our lines' display items here, & then append this to aLists.
nsDisplayListCollection linesDisplayListCollection;
// Don't use the line cursor if we might have a descendant placeholder ...
// it might skip lines that contain placeholders but don't themselves
// intersect with the dirty area.
// In particular, we really want to check ShouldDescendIntoFrame()