Bug 1757230 - Avoid unneeded includes in nsTextFrame.h. r=longsonr

Move stuff to the C++ file where possible, and move ClipEdges to
nsTextFrame since it's the only thing using it (rather than keeping it
in nsDisplayText).

Also avoids a RemoteBrowser.h include from nsDisplayList.h while at it.

This came up in https://phabricator.services.mozilla.com/D137271#inline-768125

Differential Revision: https://phabricator.services.mozilla.com/D139759
This commit is contained in:
Emilio Cobos Álvarez 2022-02-25 22:18:11 +00:00
Родитель e1a3ac3d18
Коммит 384bfcf2b6
4 изменённых файлов: 118 добавлений и 114 удалений

Просмотреть файл

@ -196,6 +196,82 @@ NS_DECLARE_FRAME_PROPERTY_RELEASABLE(UninflatedTextRunProperty, gfxTextRun)
NS_DECLARE_FRAME_PROPERTY_SMALL_VALUE(FontSizeInflationProperty, float)
struct nsTextFrame::PaintTextSelectionParams : nsTextFrame::PaintTextParams {
Point textBaselinePt;
PropertyProvider* provider = nullptr;
Range contentRange;
nsTextPaintStyle* textPaintStyle = nullptr;
Range glyphRange;
explicit PaintTextSelectionParams(const PaintTextParams& aParams)
: PaintTextParams(aParams) {}
};
struct nsTextFrame::DrawTextRunParams {
gfxContext* context;
PropertyProvider* provider = nullptr;
gfxFloat* advanceWidth = nullptr;
mozilla::SVGContextPaint* contextPaint = nullptr;
DrawPathCallbacks* callbacks = nullptr;
nscolor textColor = NS_RGBA(0, 0, 0, 0);
nscolor textStrokeColor = NS_RGBA(0, 0, 0, 0);
float textStrokeWidth = 0.0f;
bool drawSoftHyphen = false;
explicit DrawTextRunParams(gfxContext* aContext) : context(aContext) {}
};
struct nsTextFrame::ClipEdges {
ClipEdges(const nsIFrame* aFrame, const nsPoint& aToReferenceFrame,
nscoord aVisIStartEdge, nscoord aVisIEndEdge) {
nsRect r = aFrame->ScrollableOverflowRect() + aToReferenceFrame;
if (aFrame->GetWritingMode().IsVertical()) {
mVisIStart = aVisIStartEdge > 0 ? r.y + aVisIStartEdge : nscoord_MIN;
mVisIEnd = aVisIEndEdge > 0
? std::max(r.YMost() - aVisIEndEdge, mVisIStart)
: nscoord_MAX;
} else {
mVisIStart = aVisIStartEdge > 0 ? r.x + aVisIStartEdge : nscoord_MIN;
mVisIEnd = aVisIEndEdge > 0
? std::max(r.XMost() - aVisIEndEdge, mVisIStart)
: nscoord_MAX;
}
}
void Intersect(nscoord* aVisIStart, nscoord* aVisISize) const {
nscoord end = *aVisIStart + *aVisISize;
*aVisIStart = std::max(*aVisIStart, mVisIStart);
*aVisISize = std::max(std::min(end, mVisIEnd) - *aVisIStart, 0);
}
nscoord mVisIStart;
nscoord mVisIEnd;
};
struct nsTextFrame::DrawTextParams : nsTextFrame::DrawTextRunParams {
Point framePt;
LayoutDeviceRect dirtyRect;
const nsTextPaintStyle* textStyle = nullptr;
const ClipEdges* clipEdges = nullptr;
const nscolor* decorationOverrideColor = nullptr;
Range glyphRange;
explicit DrawTextParams(gfxContext* aContext) : DrawTextRunParams(aContext) {}
};
struct nsTextFrame::PaintShadowParams {
gfxTextRun::Range range;
LayoutDeviceRect dirtyRect;
Point framePt;
Point textBaselinePt;
gfxContext* context;
nscolor foregroundColor = NS_RGBA(0, 0, 0, 0);
const ClipEdges* clipEdges = nullptr;
PropertyProvider* provider = nullptr;
nscoord leftSideOffset = 0;
explicit PaintShadowParams(const PaintTextParams& aParams)
: dirtyRect(aParams.dirtyRect),
framePt(aParams.framePt),
context(aParams.context) {}
};
/**
* A glyph observer for the change of a font glyph in a text run.
*
@ -4765,6 +4841,17 @@ nsTextFrame* nsTextFrame::LastContinuation() const {
return lastContinuation;
}
bool nsTextFrame::ShouldSuppressLineBreak() const {
// If the parent frame of the text frame is ruby content box, it must
// suppress line break inside. This check is necessary, because when
// a whitespace is only contained by pseudo ruby frames, its style
// context won't have SuppressLineBreak bit set.
if (mozilla::RubyUtils::IsRubyContentBox(GetParent()->Type())) {
return true;
}
return Style()->ShouldSuppressLineBreak();
}
void nsTextFrame::InvalidateFrame(uint32_t aDisplayItemKey,
bool aRebuildDisplayItems) {
InvalidateSelectionState();
@ -4797,6 +4884,10 @@ gfxTextRun* nsTextFrame::GetUninflatedTextRun() const {
return GetProperty(UninflatedTextRunProperty());
}
void nsTextFrame::SetInflatedFontMetrics(nsFontMetrics* aFontMetrics) {
mFontMetrics = aFontMetrics;
}
void nsTextFrame::SetTextRun(gfxTextRun* aTextRun, TextRunType aWhichTextRun,
float aInflation) {
NS_ASSERTION(aTextRun, "must have text run");
@ -6288,8 +6379,7 @@ void nsTextFrame::PaintOneShadow(const PaintShadowParams& aParams,
bool nsTextFrame::PaintTextWithSelectionColors(
const PaintTextSelectionParams& aParams,
const UniquePtr<SelectionDetails>& aDetails,
SelectionTypeMask* aAllSelectionTypeMask,
const nsDisplayText::ClipEdges& aClipEdges) {
SelectionTypeMask* aAllSelectionTypeMask, const ClipEdges& aClipEdges) {
const gfxTextRun::Range& contentRange = aParams.contentRange;
// Figure out which selections control the colors to use for each character.
@ -6550,8 +6640,7 @@ void nsTextFrame::PaintTextSelectionDecorations(
}
bool nsTextFrame::PaintTextWithSelection(
const PaintTextSelectionParams& aParams,
const nsDisplayText::ClipEdges& aClipEdges) {
const PaintTextSelectionParams& aParams, const ClipEdges& aClipEdges) {
NS_ASSERTION(GetContent()->IsMaybeSelected(), "wrong paint path");
UniquePtr<SelectionDetails> details = GetSelectionDetails();
@ -6906,7 +6995,7 @@ void nsTextFrame::PaintText(const PaintTextParams& aParams,
} else {
textBaselinePt.x += reversed ? -snappedEndEdge : snappedStartEdge;
}
nsDisplayText::ClipEdges clipEdges(this, aToReferenceFrame, snappedStartEdge,
const ClipEdges clipEdges(this, aToReferenceFrame, snappedStartEdge,
snappedEndEdge);
nsTextPaintStyle textPaintStyle(this);
textPaintStyle.SetResolveColors(!aParams.callbacks);

Просмотреть файл

@ -8,21 +8,16 @@
#define nsTextFrame_h__
#include "mozilla/Attributes.h"
#include "mozilla/EventForwards.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/dom/Text.h"
#include "nsDisplayList.h"
#include "nsIFrame.h"
#include "nsFrameSelection.h"
#include "nsISelectionController.h"
#include "nsSplittableFrame.h"
#include "nsLineBox.h"
#include "gfxSkipChars.h"
#include "gfxTextRun.h"
#include "nsDisplayList.h"
#include "nsFontMetrics.h"
#include "JustificationUtils.h"
#include "RubyUtils.h"
// Undo the windows.h damage
#if defined(XP_WIN) && defined(DrawText)
@ -30,16 +25,18 @@
#endif
class nsTextPaintStyle;
class nsLineList_iterator;
struct SelectionDetails;
class nsTextFragment;
namespace mozilla {
class SVGContextPaint;
class SVGTextFrame;
class nsDisplayTextGeometry;
class nsDisplayText;
} // namespace mozilla
class nsTextFrame : public nsIFrame {
using nsDisplayText = mozilla::nsDisplayText;
typedef mozilla::LayoutDeviceRect LayoutDeviceRect;
typedef mozilla::SelectionTypeMask SelectionTypeMask;
typedef mozilla::SelectionType SelectionType;
@ -289,16 +286,7 @@ class nsTextFrame : public nsIFrame {
aFlags & ~(nsIFrame::eReplaced | nsIFrame::eLineParticipant));
}
bool ShouldSuppressLineBreak() const {
// If the parent frame of the text frame is ruby content box, it must
// suppress line break inside. This check is necessary, because when
// a whitespace is only contained by pseudo ruby frames, its style
// context won't have SuppressLineBreak bit set.
if (mozilla::RubyUtils::IsRubyContentBox(GetParent()->Type())) {
return true;
}
return Style()->ShouldSuppressLineBreak();
}
bool ShouldSuppressLineBreak() const;
void InvalidateFrame(uint32_t aDisplayItemKey = 0,
bool aRebuildDisplayItems = true) final;
@ -565,7 +553,7 @@ class nsTextFrame : public nsIFrame {
struct PaintTextParams {
gfxContext* context;
mozilla::gfx::Point framePt;
Point framePt;
LayoutDeviceRect dirtyRect;
mozilla::SVGContextPaint* contextPaint = nullptr;
DrawPathCallbacks* callbacks = nullptr;
@ -583,39 +571,12 @@ class nsTextFrame : public nsIFrame {
bool IsGenerateTextMask() const { return state == GenerateTextMask; }
};
struct PaintTextSelectionParams : PaintTextParams {
mozilla::gfx::Point textBaselinePt;
PropertyProvider* provider = nullptr;
Range contentRange;
nsTextPaintStyle* textPaintStyle = nullptr;
Range glyphRange;
explicit PaintTextSelectionParams(const PaintTextParams& aParams)
: PaintTextParams(aParams) {}
};
struct DrawTextRunParams {
gfxContext* context;
PropertyProvider* provider = nullptr;
gfxFloat* advanceWidth = nullptr;
mozilla::SVGContextPaint* contextPaint = nullptr;
DrawPathCallbacks* callbacks = nullptr;
nscolor textColor = NS_RGBA(0, 0, 0, 0);
nscolor textStrokeColor = NS_RGBA(0, 0, 0, 0);
float textStrokeWidth = 0.0f;
bool drawSoftHyphen = false;
explicit DrawTextRunParams(gfxContext* aContext) : context(aContext) {}
};
struct DrawTextParams : DrawTextRunParams {
mozilla::gfx::Point framePt;
LayoutDeviceRect dirtyRect;
const nsTextPaintStyle* textStyle = nullptr;
const nsDisplayText::ClipEdges* clipEdges = nullptr;
const nscolor* decorationOverrideColor = nullptr;
Range glyphRange;
explicit DrawTextParams(gfxContext* aContext)
: DrawTextRunParams(aContext) {}
};
struct PaintTextSelectionParams;
struct DrawTextRunParams;
struct DrawTextParams;
struct ClipEdges;
struct PaintShadowParams;
struct PaintDecorationLineParams;
// Primary frame paint method called from nsDisplayText. Can also be used
// to generate paths rather than paint the frame's text by passing a callback
@ -628,7 +589,7 @@ class nsTextFrame : public nsIFrame {
// Return false if the text was not painted and we should continue with
// the fast path.
bool PaintTextWithSelection(const PaintTextSelectionParams& aParams,
const nsDisplayText::ClipEdges& aClipEdges);
const ClipEdges& aClipEdges);
// helper: paint text with foreground and background colors determined
// by selection(s). Also computes a mask of all selection types applying to
// our text, returned in aAllSelectionTypeMask.
@ -637,8 +598,7 @@ class nsTextFrame : public nsIFrame {
bool PaintTextWithSelectionColors(
const PaintTextSelectionParams& aParams,
const mozilla::UniquePtr<SelectionDetails>& aDetails,
SelectionTypeMask* aAllSelectionTypeMask,
const nsDisplayText::ClipEdges& aClipEdges);
SelectionTypeMask* aAllSelectionTypeMask, const ClipEdges& aClipEdges);
// helper: paint text decorations for text selected by aSelectionType
void PaintTextSelectionDecorations(
const PaintTextSelectionParams& aParams,
@ -688,10 +648,10 @@ class nsTextFrame : public nsIFrame {
* to offsets into the textrun; its initial offset is set to this frame's
* content offset
*/
gfxSkipCharsIterator EnsureTextRun(
TextRunType aWhichTextRun, DrawTarget* aRefDrawTarget = nullptr,
gfxSkipCharsIterator EnsureTextRun(TextRunType aWhichTextRun,
DrawTarget* aRefDrawTarget = nullptr,
nsIFrame* aLineContainer = nullptr,
const nsLineList::iterator* aLine = nullptr,
const nsLineList_iterator* aLine = nullptr,
uint32_t* aFlowEndInTextRun = nullptr);
gfxTextRun* GetTextRun(TextRunType aWhichTextRun) const {
@ -778,9 +738,7 @@ class nsTextFrame : public nsIFrame {
*/
void NotifyNativeAnonymousTextnodeChange(uint32_t aOldLength);
void SetInflatedFontMetrics(nsFontMetrics* aMetrics) {
mFontMetrics = aMetrics;
}
void SetInflatedFontMetrics(nsFontMetrics*);
nsFontMetrics* InflatedFontMetrics() const { return mFontMetrics; }
nsRect WebRenderBounds();
@ -849,22 +807,6 @@ class nsTextFrame : public nsIFrame {
nsRect UpdateTextEmphasis(mozilla::WritingMode aWM,
PropertyProvider& aProvider);
struct PaintShadowParams {
gfxTextRun::Range range;
LayoutDeviceRect dirtyRect;
mozilla::gfx::Point framePt;
mozilla::gfx::Point textBaselinePt;
gfxContext* context;
nscolor foregroundColor = NS_RGBA(0, 0, 0, 0);
const nsDisplayText::ClipEdges* clipEdges = nullptr;
PropertyProvider* provider = nullptr;
nscoord leftSideOffset = 0;
explicit PaintShadowParams(const PaintTextParams& aParams)
: dirtyRect(aParams.dirtyRect),
framePt(aParams.framePt),
context(aParams.context) {}
};
void PaintOneShadow(const PaintShadowParams& aParams,
const mozilla::StyleSimpleShadow& aShadowDetails,
gfxRect& aBoundingBox, uint32_t aBlurFlags);
@ -971,7 +913,6 @@ class nsTextFrame : public nsIFrame {
const gfxFont::Metrics& aFontMetrics, DrawPathCallbacks* aCallbacks,
bool aVertical, mozilla::StyleTextDecorationLine aDecoration);
struct PaintDecorationLineParams;
void PaintDecorationLine(const PaintDecorationLineParams& aParams);
/**
* ComputeDescentLimitForSelectionUnderline() computes the most far position

Просмотреть файл

@ -21,6 +21,7 @@
#include "mozilla/DisplayPortUtils.h"
#include "mozilla/dom/BrowserChild.h"
#include "mozilla/dom/HTMLCanvasElement.h"
#include "mozilla/dom/RemoteBrowser.h"
#include "mozilla/dom/Selection.h"
#include "mozilla/dom/ServiceWorkerRegistrar.h"
#include "mozilla/dom/ServiceWorkerRegistration.h"

Просмотреть файл

@ -39,7 +39,6 @@
#include "mozilla/TimeStamp.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/dom/EffectsInfo.h"
#include "mozilla/dom/RemoteBrowser.h"
#include "mozilla/gfx/UserData.h"
#include "mozilla/layers/BSPTree.h"
#include "mozilla/layers/LayerAttributes.h"
@ -100,6 +99,7 @@ class DisplayListBuilder;
} // namespace wr
namespace dom {
class RemoteBrowser;
class Selection;
} // namespace dom
@ -6581,33 +6581,6 @@ class nsDisplayText final : public nsPaintedDisplayItem {
: nullptr;
}
struct ClipEdges {
ClipEdges(const nsIFrame* aFrame, const nsPoint& aToReferenceFrame,
nscoord aVisIStartEdge, nscoord aVisIEndEdge) {
nsRect r = aFrame->ScrollableOverflowRect() + aToReferenceFrame;
if (aFrame->GetWritingMode().IsVertical()) {
mVisIStart = aVisIStartEdge > 0 ? r.y + aVisIStartEdge : nscoord_MIN;
mVisIEnd = aVisIEndEdge > 0
? std::max(r.YMost() - aVisIEndEdge, mVisIStart)
: nscoord_MAX;
} else {
mVisIStart = aVisIStartEdge > 0 ? r.x + aVisIStartEdge : nscoord_MIN;
mVisIEnd = aVisIEndEdge > 0
? std::max(r.XMost() - aVisIEndEdge, mVisIStart)
: nscoord_MAX;
}
}
void Intersect(nscoord* aVisIStart, nscoord* aVisISize) const {
nscoord end = *aVisIStart + *aVisISize;
*aVisIStart = std::max(*aVisIStart, mVisIStart);
*aVisISize = std::max(std::min(end, mVisIEnd) - *aVisIStart, 0);
}
nscoord mVisIStart;
nscoord mVisIEnd;
};
nscoord& VisIStartEdge() { return mVisIStartEdge; }
nscoord& VisIEndEdge() { return mVisIEndEdge; }