2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-06-22 22:11:48 +04:00
|
|
|
|
|
|
|
#include "TextOverflow.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2011-06-22 22:11:48 +04:00
|
|
|
|
|
|
|
// Please maintain alphabetical order below
|
2017-06-09 22:14:53 +03:00
|
|
|
#include "gfxContext.h"
|
2011-06-22 22:11:48 +04:00
|
|
|
#include "nsBlockFrame.h"
|
|
|
|
#include "nsCaret.h"
|
|
|
|
#include "nsContentUtils.h"
|
2013-03-03 04:31:48 +04:00
|
|
|
#include "nsCSSAnonBoxes.h"
|
2014-10-24 19:28:14 +04:00
|
|
|
#include "nsFontMetrics.h"
|
2012-01-28 07:35:59 +04:00
|
|
|
#include "nsGfxScrollFrame.h"
|
2011-06-22 22:11:48 +04:00
|
|
|
#include "nsIScrollableFrame.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsRect.h"
|
|
|
|
#include "nsTextFrame.h"
|
2013-10-02 01:00:38 +04:00
|
|
|
#include "nsIFrameInlines.h"
|
2013-12-09 06:52:54 +04:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2012-10-26 17:32:10 +04:00
|
|
|
#include "mozilla/Likely.h"
|
2018-05-08 20:52:38 +03:00
|
|
|
#include "mozilla/dom/Selection.h"
|
2017-09-21 22:15:58 +03:00
|
|
|
#include "TextDrawTarget.h"
|
2011-06-22 22:11:48 +04:00
|
|
|
|
2017-09-30 00:56:48 +03:00
|
|
|
using mozilla::layout::TextDrawTarget;
|
|
|
|
|
2011-06-22 22:11:48 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
|
|
|
|
2015-12-16 00:56:41 +03:00
|
|
|
class LazyReferenceRenderingDrawTargetGetterFromFrame final :
|
|
|
|
public gfxFontGroup::LazyReferenceDrawTargetGetter {
|
2013-03-08 14:41:31 +04:00
|
|
|
public:
|
2015-12-16 00:56:41 +03:00
|
|
|
typedef mozilla::gfx::DrawTarget DrawTarget;
|
|
|
|
|
|
|
|
explicit LazyReferenceRenderingDrawTargetGetterFromFrame(nsIFrame* aFrame)
|
2013-03-08 14:41:31 +04:00
|
|
|
: mFrame(aFrame) {}
|
2015-12-16 00:56:41 +03:00
|
|
|
virtual already_AddRefed<DrawTarget> GetRefDrawTarget() override
|
2013-03-08 14:41:31 +04:00
|
|
|
{
|
2015-12-16 00:56:41 +03:00
|
|
|
RefPtr<gfxContext> ctx =
|
2017-11-09 05:00:48 +03:00
|
|
|
mFrame->PresShell()->CreateReferenceRenderingContext();
|
2015-12-16 00:56:41 +03:00
|
|
|
RefPtr<DrawTarget> dt = ctx->GetDrawTarget();
|
|
|
|
return dt.forget();
|
2013-03-08 14:41:31 +04:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
nsIFrame* mFrame;
|
|
|
|
};
|
2011-06-22 22:11:48 +04:00
|
|
|
|
2013-03-08 14:41:31 +04:00
|
|
|
static gfxTextRun*
|
|
|
|
GetEllipsisTextRun(nsIFrame* aFrame)
|
2011-06-22 22:11:48 +04:00
|
|
|
{
|
2016-03-17 08:55:48 +03:00
|
|
|
RefPtr<nsFontMetrics> fm =
|
|
|
|
nsLayoutUtils::GetInflatedFontMetricsForFrame(aFrame);
|
2015-12-16 00:56:41 +03:00
|
|
|
LazyReferenceRenderingDrawTargetGetterFromFrame lazyRefDrawTargetGetter(aFrame);
|
2013-03-08 14:41:31 +04:00
|
|
|
return fm->GetThebesFontGroup()->GetEllipsisTextRun(
|
2015-04-24 01:15:32 +03:00
|
|
|
aFrame->PresContext()->AppUnitsPerDevPixel(),
|
2018-03-22 21:20:41 +03:00
|
|
|
nsLayoutUtils::GetTextRunOrientFlagsForStyle(aFrame->Style()),
|
2015-12-16 00:56:41 +03:00
|
|
|
lazyRefDrawTargetGetter);
|
2011-06-22 22:11:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static nsIFrame*
|
|
|
|
GetSelfOrNearestBlock(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
return nsLayoutUtils::GetAsBlock(aFrame) ? aFrame :
|
|
|
|
nsLayoutUtils::FindNearestBlockAncestor(aFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return true if the frame is an atomic inline-level element.
|
|
|
|
// It's not supposed to be called for block frames since we never
|
|
|
|
// process block descendants for text-overflow.
|
|
|
|
static bool
|
2017-05-01 20:32:52 +03:00
|
|
|
IsAtomicElement(nsIFrame* aFrame, LayoutFrameType aFrameType)
|
2011-06-22 22:11:48 +04:00
|
|
|
{
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(!nsLayoutUtils::GetAsBlock(aFrame) || !aFrame->IsBlockOutside(),
|
|
|
|
"unexpected block frame");
|
|
|
|
MOZ_ASSERT(aFrameType != LayoutFrameType::Placeholder,
|
|
|
|
"unexpected placeholder frame");
|
2011-07-04 09:47:59 +04:00
|
|
|
return !aFrame->IsFrameOfType(nsIFrame::eLineParticipant);
|
2011-06-22 22:11:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
IsFullyClipped(nsTextFrame* aFrame, nscoord aLeft, nscoord aRight,
|
|
|
|
nscoord* aSnappedLeft, nscoord* aSnappedRight)
|
|
|
|
{
|
|
|
|
*aSnappedLeft = aLeft;
|
|
|
|
*aSnappedRight = aRight;
|
|
|
|
if (aLeft <= 0 && aRight <= 0) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-11-24 06:48:23 +04:00
|
|
|
return !aFrame->MeasureCharClippedText(aLeft, aRight,
|
|
|
|
aSnappedLeft, aSnappedRight);
|
2011-06-22 22:11:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2015-04-24 01:15:32 +03:00
|
|
|
IsInlineAxisOverflowVisible(nsIFrame* aFrame)
|
2011-06-22 22:11:48 +04:00
|
|
|
{
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(nsLayoutUtils::GetAsBlock(aFrame) != nullptr,
|
|
|
|
"expected a block frame");
|
2011-06-22 22:11:48 +04:00
|
|
|
|
|
|
|
nsIFrame* f = aFrame;
|
2018-03-22 21:20:41 +03:00
|
|
|
while (f && f->Style()->IsAnonBox() && !f->IsScrollFrame()) {
|
2011-06-22 22:11:48 +04:00
|
|
|
f = f->GetParent();
|
|
|
|
}
|
2015-04-24 01:15:32 +03:00
|
|
|
if (!f) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
auto overflow = aFrame->GetWritingMode().IsVertical() ?
|
|
|
|
f->StyleDisplay()->mOverflowY : f->StyleDisplay()->mOverflowX;
|
|
|
|
return overflow == NS_STYLE_OVERFLOW_VISIBLE;
|
2011-06-22 22:11:48 +04:00
|
|
|
}
|
|
|
|
|
2013-03-04 13:56:02 +04:00
|
|
|
static void
|
2013-04-04 15:36:45 +04:00
|
|
|
ClipMarker(const nsRect& aContentArea,
|
|
|
|
const nsRect& aMarkerRect,
|
|
|
|
DisplayListClipState::AutoSaveRestore& aClipState)
|
2011-06-22 22:11:48 +04:00
|
|
|
{
|
2013-03-04 13:56:02 +04:00
|
|
|
nscoord rightOverflow = aMarkerRect.XMost() - aContentArea.XMost();
|
|
|
|
nsRect markerRect = aMarkerRect;
|
2011-06-22 22:11:48 +04:00
|
|
|
if (rightOverflow > 0) {
|
|
|
|
// Marker overflows on the right side (content width < marker width).
|
2013-03-04 13:56:02 +04:00
|
|
|
markerRect.width -= rightOverflow;
|
2013-04-04 15:36:45 +04:00
|
|
|
aClipState.ClipContentDescendants(markerRect);
|
2011-06-22 22:11:48 +04:00
|
|
|
} else {
|
2013-03-04 13:56:02 +04:00
|
|
|
nscoord leftOverflow = aContentArea.x - aMarkerRect.x;
|
2011-06-22 22:11:48 +04:00
|
|
|
if (leftOverflow > 0) {
|
|
|
|
// Marker overflows on the left side
|
2013-03-04 13:56:02 +04:00
|
|
|
markerRect.width -= leftOverflow;
|
|
|
|
markerRect.x += leftOverflow;
|
2013-04-04 15:36:45 +04:00
|
|
|
aClipState.ClipContentDescendants(markerRect);
|
2011-06-22 22:11:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-04-24 01:15:32 +03:00
|
|
|
InflateIStart(WritingMode aWM, LogicalRect* aRect, nscoord aDelta)
|
2011-06-22 22:11:48 +04:00
|
|
|
{
|
2015-04-24 01:15:32 +03:00
|
|
|
nscoord iend = aRect->IEnd(aWM);
|
|
|
|
aRect->IStart(aWM) -= aDelta;
|
|
|
|
aRect->ISize(aWM) = std::max(iend - aRect->IStart(aWM), 0);
|
2011-06-22 22:11:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-04-24 01:15:32 +03:00
|
|
|
InflateIEnd(WritingMode aWM, LogicalRect* aRect, nscoord aDelta)
|
2011-06-22 22:11:48 +04:00
|
|
|
{
|
2015-04-24 01:15:32 +03:00
|
|
|
aRect->ISize(aWM) = std::max(aRect->ISize(aWM) + aDelta, 0);
|
2011-06-22 22:11:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
IsFrameDescendantOfAny(nsIFrame* aChild,
|
|
|
|
const TextOverflow::FrameHashtable& aSetOfFrames,
|
|
|
|
nsIFrame* aCommonAncestor)
|
|
|
|
{
|
2011-06-24 23:12:52 +04:00
|
|
|
for (nsIFrame* f = aChild; f && f != aCommonAncestor;
|
2011-06-22 22:11:48 +04:00
|
|
|
f = nsLayoutUtils::GetCrossDocParentFrame(f)) {
|
|
|
|
if (aSetOfFrames.GetEntry(f)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-06 04:23:14 +03:00
|
|
|
class nsDisplayTextOverflowMarker final : public nsDisplayItem
|
2011-06-22 22:11:48 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsDisplayTextOverflowMarker(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame,
|
|
|
|
const nsRect& aRect, nscoord aAscent,
|
2013-03-08 14:41:31 +04:00
|
|
|
const nsStyleTextOverflowSide* aStyle,
|
2017-09-13 22:28:24 +03:00
|
|
|
uint32_t aLineNumber,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aIndex)
|
2013-03-08 14:41:31 +04:00
|
|
|
: nsDisplayItem(aBuilder, aFrame), mRect(aRect),
|
2018-04-04 07:17:25 +03:00
|
|
|
mStyle(*aStyle), mAscent(aAscent), mIndex((aLineNumber << 1) + aIndex) {
|
2011-06-22 22:11:48 +04:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayTextOverflowMarker);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayTextOverflowMarker() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayTextOverflowMarker);
|
|
|
|
}
|
|
|
|
#endif
|
2014-02-24 18:41:56 +04:00
|
|
|
virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder,
|
2017-08-24 18:09:44 +03:00
|
|
|
bool* aSnap) const override
|
|
|
|
{
|
2012-04-10 15:24:18 +04:00
|
|
|
*aSnap = false;
|
2011-07-01 10:43:11 +04:00
|
|
|
nsRect shadowRect =
|
|
|
|
nsLayoutUtils::GetTextShadowRectsUnion(mRect, mFrame);
|
|
|
|
return mRect.Union(shadowRect);
|
2011-06-22 22:11:48 +04:00
|
|
|
}
|
2017-06-02 00:08:54 +03:00
|
|
|
|
2017-08-24 18:09:44 +03:00
|
|
|
virtual nsRect GetComponentAlphaBounds(nsDisplayListBuilder* aBuilder) const override
|
2017-06-02 00:08:54 +03:00
|
|
|
{
|
|
|
|
if (gfxPlatform::GetPlatform()->RespectsFontStyleSmoothing()) {
|
|
|
|
// On OS X, web authors can turn off subpixel text rendering using the
|
|
|
|
// CSS property -moz-osx-font-smoothing. If they do that, we don't need
|
|
|
|
// to use component alpha layers for the affected text.
|
|
|
|
if (mFrame->StyleFont()->mFont.smoothing == NS_FONT_SMOOTHING_GRAYSCALE) {
|
|
|
|
return nsRect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool snap;
|
|
|
|
return GetBounds(aBuilder, &snap);
|
|
|
|
}
|
|
|
|
|
2011-06-22 22:11:48 +04:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2017-06-09 22:14:53 +03:00
|
|
|
gfxContext* aCtx) override;
|
2012-03-01 12:26:09 +04:00
|
|
|
|
2017-08-24 18:09:44 +03:00
|
|
|
virtual uint32_t GetPerFrameKey() const override {
|
2017-08-07 07:07:43 +03:00
|
|
|
return (mIndex << TYPE_BITS) | nsDisplayItem::GetPerFrameKey();
|
2012-03-01 12:26:09 +04:00
|
|
|
}
|
2017-06-09 22:14:53 +03:00
|
|
|
void PaintTextToContext(gfxContext* aCtx,
|
2011-07-01 10:43:11 +04:00
|
|
|
nsPoint aOffsetFromRect);
|
2017-09-21 22:15:58 +03:00
|
|
|
|
|
|
|
virtual bool CreateWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder,
|
|
|
|
mozilla::wr::IpcResourceUpdateQueue& aResources,
|
|
|
|
const StackingContextHelper& aSc,
|
|
|
|
layers::WebRenderLayerManager* aManager,
|
|
|
|
nsDisplayListBuilder* aDisplayListBuilder) override;
|
|
|
|
|
2011-06-22 22:11:48 +04:00
|
|
|
NS_DISPLAY_DECL_NAME("TextOverflow", TYPE_TEXT_OVERFLOW)
|
|
|
|
private:
|
|
|
|
nsRect mRect; // in reference frame coordinates
|
2018-04-04 07:17:25 +03:00
|
|
|
const nsStyleTextOverflowSide mStyle;
|
2011-06-22 22:11:48 +04:00
|
|
|
nscoord mAscent; // baseline for the marker text in mRect
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mIndex;
|
2011-06-22 22:11:48 +04:00
|
|
|
};
|
|
|
|
|
2011-07-01 10:43:11 +04:00
|
|
|
static void
|
2017-06-09 22:14:53 +03:00
|
|
|
PaintTextShadowCallback(gfxContext* aCtx,
|
2011-07-01 10:43:11 +04:00
|
|
|
nsPoint aShadowOffset,
|
|
|
|
const nscolor& aShadowColor,
|
|
|
|
void* aData)
|
|
|
|
{
|
|
|
|
reinterpret_cast<nsDisplayTextOverflowMarker*>(aData)->
|
|
|
|
PaintTextToContext(aCtx, aShadowOffset);
|
|
|
|
}
|
|
|
|
|
2011-06-22 22:11:48 +04:00
|
|
|
void
|
|
|
|
nsDisplayTextOverflowMarker::Paint(nsDisplayListBuilder* aBuilder,
|
2017-06-09 22:14:53 +03:00
|
|
|
gfxContext* aCtx)
|
2011-07-01 10:43:11 +04:00
|
|
|
{
|
2017-10-20 22:21:54 +03:00
|
|
|
DrawTargetAutoDisableSubpixelAntialiasing disable(aCtx->GetDrawTarget(),
|
|
|
|
mDisableSubpixelAA);
|
|
|
|
|
2016-09-16 07:40:45 +03:00
|
|
|
nscolor foregroundColor = nsLayoutUtils::
|
2016-12-30 16:57:37 +03:00
|
|
|
GetColor(mFrame, &nsStyleText::mWebkitTextFillColor);
|
2011-07-01 10:43:11 +04:00
|
|
|
|
|
|
|
// Paint the text-shadows for the overflow marker
|
2018-05-16 06:56:32 +03:00
|
|
|
nsLayoutUtils::PaintTextShadow(mFrame, aCtx, mRect, GetPaintRect(),
|
2011-07-01 10:43:11 +04:00
|
|
|
foregroundColor, PaintTextShadowCallback,
|
|
|
|
(void*)this);
|
2017-06-09 22:14:53 +03:00
|
|
|
aCtx->SetColor(gfx::Color::FromABGR(foregroundColor));
|
2011-07-01 10:43:11 +04:00
|
|
|
PaintTextToContext(aCtx, nsPoint(0, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-06-09 22:14:53 +03:00
|
|
|
nsDisplayTextOverflowMarker::PaintTextToContext(gfxContext* aCtx,
|
2011-07-01 10:43:11 +04:00
|
|
|
nsPoint aOffsetFromRect)
|
2011-06-22 22:11:48 +04:00
|
|
|
{
|
2015-04-24 01:15:32 +03:00
|
|
|
WritingMode wm = mFrame->GetWritingMode();
|
|
|
|
nsPoint pt(mRect.x, mRect.y);
|
|
|
|
if (wm.IsVertical()) {
|
|
|
|
if (wm.IsVerticalLR()) {
|
|
|
|
pt.x = NSToCoordFloor(nsLayoutUtils::GetSnappedBaselineX(
|
2017-06-09 22:14:53 +03:00
|
|
|
mFrame, aCtx, pt.x, mAscent));
|
2015-04-24 01:15:32 +03:00
|
|
|
} else {
|
|
|
|
pt.x = NSToCoordFloor(nsLayoutUtils::GetSnappedBaselineX(
|
2017-06-09 22:14:53 +03:00
|
|
|
mFrame, aCtx, pt.x + mRect.width, -mAscent));
|
2015-04-24 01:15:32 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pt.y = NSToCoordFloor(nsLayoutUtils::GetSnappedBaselineY(
|
2017-06-09 22:14:53 +03:00
|
|
|
mFrame, aCtx, pt.y, mAscent));
|
2015-04-24 01:15:32 +03:00
|
|
|
}
|
|
|
|
pt += aOffsetFromRect;
|
2013-03-08 14:41:31 +04:00
|
|
|
|
2018-04-04 07:17:25 +03:00
|
|
|
if (mStyle.mType == NS_STYLE_TEXT_OVERFLOW_ELLIPSIS) {
|
2013-03-08 14:41:31 +04:00
|
|
|
gfxTextRun* textRun = GetEllipsisTextRun(mFrame);
|
|
|
|
if (textRun) {
|
|
|
|
NS_ASSERTION(!textRun->IsRightToLeft(),
|
|
|
|
"Ellipsis textruns should always be LTR!");
|
2017-10-24 11:59:09 +03:00
|
|
|
gfx::Point gfxPt(pt.x, pt.y);
|
2016-03-08 10:56:18 +03:00
|
|
|
textRun->Draw(gfxTextRun::Range(textRun), gfxPt,
|
2017-06-09 22:14:53 +03:00
|
|
|
gfxTextRun::DrawParams(aCtx));
|
2013-03-08 14:41:31 +04:00
|
|
|
}
|
|
|
|
} else {
|
2016-03-17 08:55:48 +03:00
|
|
|
RefPtr<nsFontMetrics> fm =
|
|
|
|
nsLayoutUtils::GetInflatedFontMetricsForFrame(mFrame);
|
2018-04-04 07:17:25 +03:00
|
|
|
nsLayoutUtils::DrawString(mFrame, *fm, aCtx, mStyle.mString.get(),
|
|
|
|
mStyle.mString.Length(), pt);
|
2013-03-08 14:41:31 +04:00
|
|
|
}
|
2011-06-22 22:11:48 +04:00
|
|
|
}
|
|
|
|
|
2017-09-21 22:15:58 +03:00
|
|
|
bool
|
|
|
|
nsDisplayTextOverflowMarker::CreateWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder,
|
|
|
|
mozilla::wr::IpcResourceUpdateQueue& aResources,
|
|
|
|
const StackingContextHelper& aSc,
|
|
|
|
layers::WebRenderLayerManager* aManager,
|
|
|
|
nsDisplayListBuilder* aDisplayListBuilder)
|
|
|
|
{
|
|
|
|
bool snap;
|
|
|
|
nsRect bounds = GetBounds(aDisplayListBuilder, &snap);
|
|
|
|
if (bounds.IsEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run the rendering algorithm to capture the glyphs and shadows
|
2018-08-21 19:36:48 +03:00
|
|
|
RefPtr<TextDrawTarget> textDrawer = new TextDrawTarget(aBuilder, aResources, aSc, aManager, this, bounds);
|
2017-09-21 22:15:58 +03:00
|
|
|
RefPtr<gfxContext> captureCtx = gfxContext::CreateOrNull(textDrawer);
|
|
|
|
Paint(aDisplayListBuilder, captureCtx);
|
2017-10-06 20:06:10 +03:00
|
|
|
textDrawer->TerminateShadows();
|
2017-09-21 22:15:58 +03:00
|
|
|
|
2017-10-06 20:06:10 +03:00
|
|
|
return !textDrawer->HasUnsupportedFeatures();
|
2017-09-21 22:15:58 +03:00
|
|
|
}
|
|
|
|
|
2018-04-13 16:01:28 +03:00
|
|
|
|
2015-04-24 01:15:32 +03:00
|
|
|
TextOverflow::TextOverflow(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aBlockFrame)
|
|
|
|
: mContentArea(aBlockFrame->GetWritingMode(),
|
|
|
|
aBlockFrame->GetContentRectRelativeToSelf(),
|
2015-07-16 12:07:57 +03:00
|
|
|
aBlockFrame->GetSize())
|
2015-04-24 01:15:32 +03:00
|
|
|
, mBuilder(aBuilder)
|
|
|
|
, mBlock(aBlockFrame)
|
|
|
|
, mScrollableFrame(nsLayoutUtils::GetScrollableFrameFor(aBlockFrame))
|
2015-07-16 12:07:57 +03:00
|
|
|
, mBlockSize(aBlockFrame->GetSize())
|
2015-04-24 01:15:32 +03:00
|
|
|
, mBlockWM(aBlockFrame->GetWritingMode())
|
|
|
|
, mAdjustForPixelSnapping(false)
|
2012-01-28 07:35:59 +04:00
|
|
|
{
|
|
|
|
#ifdef MOZ_XUL
|
|
|
|
if (!mScrollableFrame) {
|
2018-03-22 21:20:41 +03:00
|
|
|
nsAtom* pseudoType = aBlockFrame->Style()->GetPseudo();
|
2018-08-15 08:46:39 +03:00
|
|
|
if (pseudoType == nsCSSAnonBoxes::mozXULAnonymousBlock()) {
|
2012-01-28 07:35:59 +04:00
|
|
|
mScrollableFrame =
|
|
|
|
nsLayoutUtils::GetScrollableFrameFor(aBlockFrame->GetParent());
|
|
|
|
// nsXULScrollFrame::ClampAndSetBounds rounds to nearest pixels
|
|
|
|
// for RTL blocks (also for overflow:hidden), so we need to move
|
|
|
|
// the edges 1px outward in ExamineLineFrames to avoid triggering
|
|
|
|
// a text-overflow marker in this case.
|
2015-04-24 01:15:32 +03:00
|
|
|
mAdjustForPixelSnapping = !mBlockWM.IsBidiLTR();
|
2012-01-28 07:35:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2015-04-24 01:15:32 +03:00
|
|
|
mCanHaveInlineAxisScrollbar = false;
|
2012-01-28 07:35:59 +04:00
|
|
|
if (mScrollableFrame) {
|
2015-04-24 01:15:32 +03:00
|
|
|
auto scrollbarStyle = mBlockWM.IsVertical() ?
|
2018-08-01 09:14:26 +03:00
|
|
|
mScrollableFrame->GetScrollStyles().mVertical :
|
|
|
|
mScrollableFrame->GetScrollStyles().mHorizontal;
|
2015-04-24 01:15:32 +03:00
|
|
|
mCanHaveInlineAxisScrollbar = scrollbarStyle != NS_STYLE_OVERFLOW_HIDDEN;
|
2012-01-28 07:35:59 +04:00
|
|
|
if (!mAdjustForPixelSnapping) {
|
|
|
|
// Scrolling to the end position can leave some text still overflowing due
|
|
|
|
// to pixel snapping behaviour in our scrolling code.
|
2015-04-24 01:15:32 +03:00
|
|
|
mAdjustForPixelSnapping = mCanHaveInlineAxisScrollbar;
|
2012-01-28 07:35:59 +04:00
|
|
|
}
|
2015-07-16 12:07:57 +03:00
|
|
|
// Use a null containerSize to convert a vector from logical to physical.
|
|
|
|
const nsSize nullContainerSize;
|
2015-04-24 01:15:32 +03:00
|
|
|
mContentArea.MoveBy(mBlockWM,
|
|
|
|
LogicalPoint(mBlockWM,
|
2015-07-16 12:07:57 +03:00
|
|
|
mScrollableFrame->GetScrollPosition(),
|
|
|
|
nullContainerSize));
|
2012-01-28 07:35:59 +04:00
|
|
|
}
|
2015-04-24 01:15:32 +03:00
|
|
|
uint8_t direction = aBlockFrame->StyleVisibility()->mDirection;
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleTextReset* style = aBlockFrame->StyleTextReset();
|
2015-04-24 01:15:32 +03:00
|
|
|
if (mBlockWM.IsBidiLTR()) {
|
|
|
|
mIStart.Init(style->mTextOverflow.GetLeft(direction));
|
|
|
|
mIEnd.Init(style->mTextOverflow.GetRight(direction));
|
|
|
|
} else {
|
|
|
|
mIStart.Init(style->mTextOverflow.GetRight(direction));
|
|
|
|
mIEnd.Init(style->mTextOverflow.GetLeft(direction));
|
|
|
|
}
|
2012-01-28 07:35:59 +04:00
|
|
|
// The left/right marker string is setup in ExamineLineFrames when a line
|
|
|
|
// has overflow on that side.
|
|
|
|
}
|
|
|
|
|
2017-07-19 08:42:42 +03:00
|
|
|
/* static */ UniquePtr<TextOverflow>
|
2011-06-22 22:11:48 +04:00
|
|
|
TextOverflow::WillProcessLines(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aBlockFrame)
|
|
|
|
{
|
2017-04-15 01:31:43 +03:00
|
|
|
// Ignore 'text-overflow' for event and frame visibility processing.
|
|
|
|
if (aBuilder->IsForEventDelivery() ||
|
|
|
|
aBuilder->IsForFrameVisibility() ||
|
|
|
|
!CanHaveTextOverflow(aBlockFrame)) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-06-22 22:11:48 +04:00
|
|
|
}
|
2015-02-25 17:33:00 +03:00
|
|
|
nsIScrollableFrame* scrollableFrame = nsLayoutUtils::GetScrollableFrameFor(aBlockFrame);
|
|
|
|
if (scrollableFrame && scrollableFrame->IsTransformingByAPZ()) {
|
|
|
|
// If the APZ is actively scrolling this, don't bother with markers.
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-07-19 08:42:42 +03:00
|
|
|
return MakeUnique<TextOverflow>(aBuilder, aBlockFrame);
|
2011-06-22 22:11:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TextOverflow::ExamineFrameSubtree(nsIFrame* aFrame,
|
2015-04-24 01:15:32 +03:00
|
|
|
const LogicalRect& aContentArea,
|
|
|
|
const LogicalRect& aInsideMarkersArea,
|
2011-06-22 22:11:48 +04:00
|
|
|
FrameHashtable* aFramesToHide,
|
2011-12-19 18:48:31 +04:00
|
|
|
AlignmentEdges* aAlignmentEdges,
|
2011-12-19 18:48:31 +04:00
|
|
|
bool* aFoundVisibleTextOrAtomic,
|
|
|
|
InnerClipEdges* aClippedMarkerEdges)
|
2011-06-22 22:11:48 +04:00
|
|
|
{
|
2017-05-01 20:32:52 +03:00
|
|
|
const LayoutFrameType frameType = aFrame->Type();
|
|
|
|
if (frameType == LayoutFrameType::Br ||
|
|
|
|
frameType == LayoutFrameType::Placeholder) {
|
2011-06-22 22:11:48 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const bool isAtomic = IsAtomicElement(aFrame, frameType);
|
2013-02-17 01:51:02 +04:00
|
|
|
if (aFrame->StyleVisibility()->IsVisible()) {
|
2015-04-24 01:15:32 +03:00
|
|
|
LogicalRect childRect =
|
|
|
|
GetLogicalScrollableOverflowRectRelativeToBlock(aFrame);
|
|
|
|
bool overflowIStart =
|
|
|
|
childRect.IStart(mBlockWM) < aContentArea.IStart(mBlockWM);
|
|
|
|
bool overflowIEnd =
|
|
|
|
childRect.IEnd(mBlockWM) > aContentArea.IEnd(mBlockWM);
|
|
|
|
if (overflowIStart) {
|
|
|
|
mIStart.mHasOverflow = true;
|
2011-06-22 22:11:48 +04:00
|
|
|
}
|
2015-04-24 01:15:32 +03:00
|
|
|
if (overflowIEnd) {
|
|
|
|
mIEnd.mHasOverflow = true;
|
2011-06-22 22:11:48 +04:00
|
|
|
}
|
2015-04-24 01:15:32 +03:00
|
|
|
if (isAtomic && ((mIStart.mActive && overflowIStart) ||
|
|
|
|
(mIEnd.mActive && overflowIEnd))) {
|
2011-06-22 22:11:48 +04:00
|
|
|
aFramesToHide->PutEntry(aFrame);
|
2017-05-01 20:32:52 +03:00
|
|
|
} else if (isAtomic || frameType == LayoutFrameType::Text) {
|
2011-06-22 22:11:48 +04:00
|
|
|
AnalyzeMarkerEdges(aFrame, frameType, aInsideMarkersArea,
|
2011-12-19 18:48:31 +04:00
|
|
|
aFramesToHide, aAlignmentEdges,
|
2011-12-19 18:48:31 +04:00
|
|
|
aFoundVisibleTextOrAtomic,
|
|
|
|
aClippedMarkerEdges);
|
2011-06-22 22:11:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isAtomic) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-29 17:42:15 +03:00
|
|
|
for (nsIFrame* child : aFrame->PrincipalChildList()) {
|
2011-06-22 22:11:48 +04:00
|
|
|
ExamineFrameSubtree(child, aContentArea, aInsideMarkersArea,
|
2011-12-19 18:48:31 +04:00
|
|
|
aFramesToHide, aAlignmentEdges,
|
2011-12-19 18:48:31 +04:00
|
|
|
aFoundVisibleTextOrAtomic,
|
|
|
|
aClippedMarkerEdges);
|
2011-06-22 22:11:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-04-30 18:30:08 +03:00
|
|
|
TextOverflow::AnalyzeMarkerEdges(nsIFrame* aFrame,
|
2017-05-01 20:32:52 +03:00
|
|
|
LayoutFrameType aFrameType,
|
2015-04-24 01:15:32 +03:00
|
|
|
const LogicalRect& aInsideMarkersArea,
|
2011-06-22 22:11:48 +04:00
|
|
|
FrameHashtable* aFramesToHide,
|
2011-12-19 18:48:31 +04:00
|
|
|
AlignmentEdges* aAlignmentEdges,
|
2017-04-30 18:30:08 +03:00
|
|
|
bool* aFoundVisibleTextOrAtomic,
|
2011-12-19 18:48:31 +04:00
|
|
|
InnerClipEdges* aClippedMarkerEdges)
|
2011-06-22 22:11:48 +04:00
|
|
|
{
|
2018-01-04 22:43:55 +03:00
|
|
|
MOZ_ASSERT(aFrameType == LayoutFrameType::Text ||
|
|
|
|
IsAtomicElement(aFrame, aFrameType));
|
2015-04-24 01:15:32 +03:00
|
|
|
LogicalRect borderRect(mBlockWM,
|
|
|
|
nsRect(aFrame->GetOffsetTo(mBlock),
|
|
|
|
aFrame->GetSize()),
|
2015-07-16 12:07:57 +03:00
|
|
|
mBlockSize);
|
2015-04-24 01:15:32 +03:00
|
|
|
nscoord istartOverlap = std::max(
|
|
|
|
aInsideMarkersArea.IStart(mBlockWM) - borderRect.IStart(mBlockWM), 0);
|
|
|
|
nscoord iendOverlap = std::max(
|
|
|
|
borderRect.IEnd(mBlockWM) - aInsideMarkersArea.IEnd(mBlockWM), 0);
|
|
|
|
bool insideIStartEdge =
|
|
|
|
aInsideMarkersArea.IStart(mBlockWM) <= borderRect.IEnd(mBlockWM);
|
|
|
|
bool insideIEndEdge =
|
|
|
|
borderRect.IStart(mBlockWM) <= aInsideMarkersArea.IEnd(mBlockWM);
|
|
|
|
|
|
|
|
if (istartOverlap > 0) {
|
|
|
|
aClippedMarkerEdges->AccumulateIStart(mBlockWM, borderRect);
|
|
|
|
if (!mIStart.mActive) {
|
|
|
|
istartOverlap = 0;
|
2011-12-19 18:48:31 +04:00
|
|
|
}
|
|
|
|
}
|
2015-04-24 01:15:32 +03:00
|
|
|
if (iendOverlap > 0) {
|
|
|
|
aClippedMarkerEdges->AccumulateIEnd(mBlockWM, borderRect);
|
|
|
|
if (!mIEnd.mActive) {
|
|
|
|
iendOverlap = 0;
|
2011-12-19 18:48:31 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-24 01:15:32 +03:00
|
|
|
if ((istartOverlap > 0 && insideIStartEdge) ||
|
|
|
|
(iendOverlap > 0 && insideIEndEdge)) {
|
2017-05-01 20:32:52 +03:00
|
|
|
if (aFrameType == LayoutFrameType::Text) {
|
2018-01-04 22:43:55 +03:00
|
|
|
auto textFrame = static_cast<nsTextFrame*>(aFrame);
|
|
|
|
if ((aInsideMarkersArea.IStart(mBlockWM) <
|
|
|
|
aInsideMarkersArea.IEnd(mBlockWM)) &&
|
|
|
|
textFrame->HasNonSuppressedText()) {
|
2011-12-19 18:48:31 +04:00
|
|
|
// a clipped text frame and there is some room between the markers
|
2015-04-24 01:15:32 +03:00
|
|
|
nscoord snappedIStart, snappedIEnd;
|
|
|
|
bool isFullyClipped = mBlockWM.IsBidiLTR() ?
|
|
|
|
IsFullyClipped(textFrame, istartOverlap, iendOverlap,
|
|
|
|
&snappedIStart, &snappedIEnd) :
|
|
|
|
IsFullyClipped(textFrame, iendOverlap, istartOverlap,
|
|
|
|
&snappedIEnd, &snappedIStart);
|
2011-12-19 18:48:31 +04:00
|
|
|
if (!isFullyClipped) {
|
2015-04-24 01:15:32 +03:00
|
|
|
LogicalRect snappedRect = borderRect;
|
|
|
|
if (istartOverlap > 0) {
|
|
|
|
snappedRect.IStart(mBlockWM) += snappedIStart;
|
|
|
|
snappedRect.ISize(mBlockWM) -= snappedIStart;
|
2011-12-19 18:48:31 +04:00
|
|
|
}
|
2015-04-24 01:15:32 +03:00
|
|
|
if (iendOverlap > 0) {
|
|
|
|
snappedRect.ISize(mBlockWM) -= snappedIEnd;
|
2011-12-19 18:48:31 +04:00
|
|
|
}
|
2015-04-24 01:15:32 +03:00
|
|
|
aAlignmentEdges->Accumulate(mBlockWM, snappedRect);
|
2011-12-19 18:48:31 +04:00
|
|
|
*aFoundVisibleTextOrAtomic = true;
|
2011-06-22 22:11:48 +04:00
|
|
|
}
|
2011-12-19 18:48:30 +04:00
|
|
|
}
|
2011-12-19 18:48:31 +04:00
|
|
|
} else {
|
|
|
|
aFramesToHide->PutEntry(aFrame);
|
2011-06-22 22:11:48 +04:00
|
|
|
}
|
2015-04-24 01:15:32 +03:00
|
|
|
} else if (!insideIStartEdge || !insideIEndEdge) {
|
2011-06-22 22:11:48 +04:00
|
|
|
// frame is outside
|
|
|
|
if (IsAtomicElement(aFrame, aFrameType)) {
|
|
|
|
aFramesToHide->PutEntry(aFrame);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// frame is inside
|
2015-04-24 01:15:32 +03:00
|
|
|
aAlignmentEdges->Accumulate(mBlockWM, borderRect);
|
2018-01-04 22:43:55 +03:00
|
|
|
if (aFrameType == LayoutFrameType::Text) {
|
|
|
|
auto textFrame = static_cast<nsTextFrame*>(aFrame);
|
|
|
|
if (textFrame->HasNonSuppressedText()) {
|
|
|
|
*aFoundVisibleTextOrAtomic = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*aFoundVisibleTextOrAtomic = true;
|
|
|
|
}
|
2011-06-22 22:11:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-15 01:31:44 +03:00
|
|
|
LogicalRect
|
2011-06-22 22:11:48 +04:00
|
|
|
TextOverflow::ExamineLineFrames(nsLineBox* aLine,
|
|
|
|
FrameHashtable* aFramesToHide,
|
|
|
|
AlignmentEdges* aAlignmentEdges)
|
|
|
|
{
|
2011-10-12 20:20:46 +04:00
|
|
|
// No ellipsing for 'clip' style.
|
2015-04-24 01:15:32 +03:00
|
|
|
bool suppressIStart = mIStart.mStyle->mType == NS_STYLE_TEXT_OVERFLOW_CLIP;
|
|
|
|
bool suppressIEnd = mIEnd.mStyle->mType == NS_STYLE_TEXT_OVERFLOW_CLIP;
|
|
|
|
if (mCanHaveInlineAxisScrollbar) {
|
|
|
|
LogicalPoint pos(mBlockWM, mScrollableFrame->GetScrollPosition(),
|
2015-07-16 12:07:57 +03:00
|
|
|
mBlockSize);
|
2015-04-24 01:15:32 +03:00
|
|
|
LogicalRect scrollRange(mBlockWM, mScrollableFrame->GetScrollRange(),
|
2015-07-16 12:07:57 +03:00
|
|
|
mBlockSize);
|
2011-10-12 20:20:46 +04:00
|
|
|
// No ellipsing when nothing to scroll to on that side (this includes
|
|
|
|
// overflow:auto that doesn't trigger a horizontal scrollbar).
|
2015-04-24 01:15:32 +03:00
|
|
|
if (pos.I(mBlockWM) <= scrollRange.IStart(mBlockWM)) {
|
|
|
|
suppressIStart = true;
|
2011-10-12 20:20:46 +04:00
|
|
|
}
|
2015-04-24 01:15:32 +03:00
|
|
|
if (pos.I(mBlockWM) >= scrollRange.IEnd(mBlockWM)) {
|
|
|
|
suppressIEnd = true;
|
2011-10-12 20:20:46 +04:00
|
|
|
}
|
|
|
|
}
|
2011-10-12 20:20:46 +04:00
|
|
|
|
2015-04-24 01:15:32 +03:00
|
|
|
LogicalRect contentArea = mContentArea;
|
2017-04-15 01:31:44 +03:00
|
|
|
bool snapStart = true, snapEnd = true;
|
2017-04-15 01:31:44 +03:00
|
|
|
nscoord startEdge, endEdge;
|
|
|
|
if (aLine->GetFloatEdges(&startEdge, &endEdge)) {
|
|
|
|
// Narrow the |contentArea| to account for any floats on this line, and
|
|
|
|
// don't bother with the snapping quirk on whichever side(s) we narrow.
|
|
|
|
nscoord delta = endEdge - contentArea.IEnd(mBlockWM);
|
|
|
|
if (delta < 0) {
|
|
|
|
nscoord newSize = contentArea.ISize(mBlockWM) + delta;
|
|
|
|
contentArea.ISize(mBlockWM) = std::max(nscoord(0), newSize);
|
|
|
|
snapEnd = false;
|
|
|
|
}
|
|
|
|
delta = startEdge - contentArea.IStart(mBlockWM);
|
|
|
|
if (delta > 0) {
|
|
|
|
contentArea.IStart(mBlockWM) = startEdge;
|
|
|
|
nscoord newSize = contentArea.ISize(mBlockWM) - delta;
|
|
|
|
contentArea.ISize(mBlockWM) = std::max(nscoord(0), newSize);
|
|
|
|
snapStart = false;
|
|
|
|
}
|
|
|
|
}
|
2017-04-15 01:31:44 +03:00
|
|
|
// Save the non-snapped area since that's what we want to use when placing
|
|
|
|
// the markers (our return value). The snapped area is only for analysis.
|
|
|
|
LogicalRect nonSnappedContentArea = contentArea;
|
|
|
|
if (mAdjustForPixelSnapping) {
|
|
|
|
const nscoord scrollAdjust = mBlock->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
if (snapStart) {
|
|
|
|
InflateIStart(mBlockWM, &contentArea, scrollAdjust);
|
|
|
|
}
|
|
|
|
if (snapEnd) {
|
|
|
|
InflateIEnd(mBlockWM, &contentArea, scrollAdjust);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-24 01:15:32 +03:00
|
|
|
LogicalRect lineRect(mBlockWM, aLine->GetScrollableOverflowArea(),
|
2015-07-16 12:07:57 +03:00
|
|
|
mBlockSize);
|
2015-04-24 01:15:32 +03:00
|
|
|
const bool istartOverflow =
|
|
|
|
!suppressIStart && lineRect.IStart(mBlockWM) < contentArea.IStart(mBlockWM);
|
|
|
|
const bool iendOverflow =
|
|
|
|
!suppressIEnd && lineRect.IEnd(mBlockWM) > contentArea.IEnd(mBlockWM);
|
|
|
|
if (!istartOverflow && !iendOverflow) {
|
2011-10-12 20:20:46 +04:00
|
|
|
// The line does not overflow on a side we should ellipsize.
|
2017-04-15 01:31:44 +03:00
|
|
|
return nonSnappedContentArea;
|
2011-06-22 22:11:48 +04:00
|
|
|
}
|
|
|
|
|
2011-12-19 18:48:31 +04:00
|
|
|
int pass = 0;
|
|
|
|
bool retryEmptyLine = true;
|
2015-04-24 01:15:32 +03:00
|
|
|
bool guessIStart = istartOverflow;
|
|
|
|
bool guessIEnd = iendOverflow;
|
|
|
|
mIStart.mActive = istartOverflow;
|
|
|
|
mIEnd.mActive = iendOverflow;
|
|
|
|
bool clippedIStartMarker = false;
|
|
|
|
bool clippedIEndMarker = false;
|
2011-06-22 22:11:48 +04:00
|
|
|
do {
|
|
|
|
// Setup marker strings as needed.
|
2015-04-24 01:15:32 +03:00
|
|
|
if (guessIStart) {
|
|
|
|
mIStart.SetupString(mBlock);
|
2011-08-21 00:41:39 +04:00
|
|
|
}
|
2015-04-24 01:15:32 +03:00
|
|
|
if (guessIEnd) {
|
|
|
|
mIEnd.SetupString(mBlock);
|
2011-06-22 22:11:48 +04:00
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2011-06-22 22:11:48 +04:00
|
|
|
// If there is insufficient space for both markers then keep the one on the
|
|
|
|
// end side per the block's 'direction'.
|
2015-04-24 01:15:32 +03:00
|
|
|
nscoord istartMarkerISize = mIStart.mActive ? mIStart.mISize : 0;
|
|
|
|
nscoord iendMarkerISize = mIEnd.mActive ? mIEnd.mISize : 0;
|
|
|
|
if (istartMarkerISize && iendMarkerISize &&
|
|
|
|
istartMarkerISize + iendMarkerISize > contentArea.ISize(mBlockWM)) {
|
|
|
|
istartMarkerISize = 0;
|
2011-06-22 22:11:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate the area between the potential markers aligned at the
|
|
|
|
// block's edge.
|
2017-04-15 01:31:44 +03:00
|
|
|
LogicalRect insideMarkersArea = nonSnappedContentArea;
|
2015-04-24 01:15:32 +03:00
|
|
|
if (guessIStart) {
|
|
|
|
InflateIStart(mBlockWM, &insideMarkersArea, -istartMarkerISize);
|
2011-12-19 18:48:30 +04:00
|
|
|
}
|
2015-04-24 01:15:32 +03:00
|
|
|
if (guessIEnd) {
|
|
|
|
InflateIEnd(mBlockWM, &insideMarkersArea, -iendMarkerISize);
|
2011-12-19 18:48:30 +04:00
|
|
|
}
|
2011-06-22 22:11:48 +04:00
|
|
|
|
|
|
|
// Analyze the frames on aLine for the overflow situation at the content
|
|
|
|
// edges and at the edges of the area between the markers.
|
2011-12-19 18:48:31 +04:00
|
|
|
bool foundVisibleTextOrAtomic = false;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t n = aLine->GetChildCount();
|
2011-06-22 22:11:48 +04:00
|
|
|
nsIFrame* child = aLine->mFirstChild;
|
2011-12-19 18:48:31 +04:00
|
|
|
InnerClipEdges clippedMarkerEdges;
|
2011-06-22 22:11:48 +04:00
|
|
|
for (; n-- > 0; child = child->GetNextSibling()) {
|
|
|
|
ExamineFrameSubtree(child, contentArea, insideMarkersArea,
|
2011-12-19 18:48:31 +04:00
|
|
|
aFramesToHide, aAlignmentEdges,
|
2011-12-19 18:48:31 +04:00
|
|
|
&foundVisibleTextOrAtomic,
|
|
|
|
&clippedMarkerEdges);
|
|
|
|
}
|
|
|
|
if (!foundVisibleTextOrAtomic && retryEmptyLine) {
|
|
|
|
aAlignmentEdges->mAssigned = false;
|
|
|
|
aFramesToHide->Clear();
|
|
|
|
pass = -1;
|
2015-04-24 01:15:32 +03:00
|
|
|
if (mIStart.IsNeeded() && mIStart.mActive && !clippedIStartMarker) {
|
|
|
|
if (clippedMarkerEdges.mAssignedIStart &&
|
2017-04-15 01:31:44 +03:00
|
|
|
clippedMarkerEdges.mIStart > nonSnappedContentArea.IStart(mBlockWM)) {
|
|
|
|
mIStart.mISize = clippedMarkerEdges.mIStart -
|
|
|
|
nonSnappedContentArea.IStart(mBlockWM);
|
2015-04-24 01:15:32 +03:00
|
|
|
NS_ASSERTION(mIStart.mISize < mIStart.mIntrinsicISize,
|
|
|
|
"clipping a marker should make it strictly smaller");
|
|
|
|
clippedIStartMarker = true;
|
2011-12-19 18:48:31 +04:00
|
|
|
} else {
|
2015-04-24 01:15:32 +03:00
|
|
|
mIStart.mActive = guessIStart = false;
|
2011-12-19 18:48:31 +04:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2015-04-24 01:15:32 +03:00
|
|
|
if (mIEnd.IsNeeded() && mIEnd.mActive && !clippedIEndMarker) {
|
|
|
|
if (clippedMarkerEdges.mAssignedIEnd &&
|
2017-04-15 01:31:44 +03:00
|
|
|
nonSnappedContentArea.IEnd(mBlockWM) > clippedMarkerEdges.mIEnd) {
|
|
|
|
mIEnd.mISize = nonSnappedContentArea.IEnd(mBlockWM) -
|
|
|
|
clippedMarkerEdges.mIEnd;
|
2015-04-24 01:15:32 +03:00
|
|
|
NS_ASSERTION(mIEnd.mISize < mIEnd.mIntrinsicISize,
|
|
|
|
"clipping a marker should make it strictly smaller");
|
|
|
|
clippedIEndMarker = true;
|
2011-12-19 18:48:31 +04:00
|
|
|
} else {
|
2015-04-24 01:15:32 +03:00
|
|
|
mIEnd.mActive = guessIEnd = false;
|
2011-12-19 18:48:31 +04:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// The line simply has no visible content even without markers,
|
|
|
|
// so examine the line again without suppressing markers.
|
|
|
|
retryEmptyLine = false;
|
2015-04-24 01:15:32 +03:00
|
|
|
mIStart.mISize = mIStart.mIntrinsicISize;
|
|
|
|
mIStart.mActive = guessIStart = istartOverflow;
|
|
|
|
mIEnd.mISize = mIEnd.mIntrinsicISize;
|
|
|
|
mIEnd.mActive = guessIEnd = iendOverflow;
|
2011-12-19 18:48:31 +04:00
|
|
|
continue;
|
2011-06-22 22:11:48 +04:00
|
|
|
}
|
2015-04-24 01:15:32 +03:00
|
|
|
if (guessIStart == (mIStart.mActive && mIStart.IsNeeded()) &&
|
|
|
|
guessIEnd == (mIEnd.mActive && mIEnd.IsNeeded())) {
|
2011-06-22 22:11:48 +04:00
|
|
|
break;
|
|
|
|
} else {
|
2015-04-24 01:15:32 +03:00
|
|
|
guessIStart = mIStart.mActive && mIStart.IsNeeded();
|
|
|
|
guessIEnd = mIEnd.mActive && mIEnd.IsNeeded();
|
|
|
|
mIStart.Reset();
|
|
|
|
mIEnd.Reset();
|
2011-06-22 22:11:48 +04:00
|
|
|
aFramesToHide->Clear();
|
|
|
|
}
|
|
|
|
NS_ASSERTION(pass == 0, "2nd pass should never guess wrong");
|
|
|
|
} while (++pass != 2);
|
2015-04-24 01:15:32 +03:00
|
|
|
if (!istartOverflow || !mIStart.mActive) {
|
|
|
|
mIStart.Reset();
|
2011-12-19 18:48:30 +04:00
|
|
|
}
|
2015-04-24 01:15:32 +03:00
|
|
|
if (!iendOverflow || !mIEnd.mActive) {
|
|
|
|
mIEnd.Reset();
|
2011-12-19 18:48:30 +04:00
|
|
|
}
|
2017-04-15 01:31:44 +03:00
|
|
|
return nonSnappedContentArea;
|
2011-06-22 22:11:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TextOverflow::ProcessLine(const nsDisplayListSet& aLists,
|
2017-09-13 22:28:24 +03:00
|
|
|
nsLineBox* aLine,
|
|
|
|
uint32_t aLineNumber)
|
2011-06-22 22:11:48 +04:00
|
|
|
{
|
2015-04-24 01:15:32 +03:00
|
|
|
NS_ASSERTION(mIStart.mStyle->mType != NS_STYLE_TEXT_OVERFLOW_CLIP ||
|
|
|
|
mIEnd.mStyle->mType != NS_STYLE_TEXT_OVERFLOW_CLIP,
|
2011-06-22 22:11:48 +04:00
|
|
|
"TextOverflow with 'clip' for both sides");
|
2015-04-24 01:15:32 +03:00
|
|
|
mIStart.Reset();
|
|
|
|
mIStart.mActive = mIStart.mStyle->mType != NS_STYLE_TEXT_OVERFLOW_CLIP;
|
|
|
|
mIEnd.Reset();
|
|
|
|
mIEnd.mActive = mIEnd.mStyle->mType != NS_STYLE_TEXT_OVERFLOW_CLIP;
|
2014-08-06 17:31:21 +04:00
|
|
|
|
|
|
|
FrameHashtable framesToHide(64);
|
2011-06-22 22:11:48 +04:00
|
|
|
AlignmentEdges alignmentEdges;
|
2017-04-15 01:31:44 +03:00
|
|
|
const LogicalRect contentArea =
|
|
|
|
ExamineLineFrames(aLine, &framesToHide, &alignmentEdges);
|
2015-04-24 01:15:32 +03:00
|
|
|
bool needIStart = mIStart.IsNeeded();
|
|
|
|
bool needIEnd = mIEnd.IsNeeded();
|
|
|
|
if (!needIStart && !needIEnd) {
|
2011-06-22 22:11:48 +04:00
|
|
|
return;
|
|
|
|
}
|
2015-04-24 01:15:32 +03:00
|
|
|
NS_ASSERTION(mIStart.mStyle->mType != NS_STYLE_TEXT_OVERFLOW_CLIP ||
|
|
|
|
!needIStart, "left marker for 'clip'");
|
|
|
|
NS_ASSERTION(mIEnd.mStyle->mType != NS_STYLE_TEXT_OVERFLOW_CLIP ||
|
|
|
|
!needIEnd, "right marker for 'clip'");
|
2011-06-22 22:11:48 +04:00
|
|
|
|
|
|
|
// If there is insufficient space for both markers then keep the one on the
|
|
|
|
// end side per the block's 'direction'.
|
2015-04-24 01:15:32 +03:00
|
|
|
if (needIStart && needIEnd &&
|
2017-04-15 01:31:44 +03:00
|
|
|
mIStart.mISize + mIEnd.mISize > contentArea.ISize(mBlockWM)) {
|
2015-04-24 01:15:32 +03:00
|
|
|
needIStart = false;
|
2011-06-22 22:11:48 +04:00
|
|
|
}
|
2017-04-15 01:31:44 +03:00
|
|
|
LogicalRect insideMarkersArea = contentArea;
|
2015-04-24 01:15:32 +03:00
|
|
|
if (needIStart) {
|
|
|
|
InflateIStart(mBlockWM, &insideMarkersArea, -mIStart.mISize);
|
2011-06-22 22:11:48 +04:00
|
|
|
}
|
2015-04-24 01:15:32 +03:00
|
|
|
if (needIEnd) {
|
|
|
|
InflateIEnd(mBlockWM, &insideMarkersArea, -mIEnd.mISize);
|
2011-06-22 22:11:48 +04:00
|
|
|
}
|
2015-04-24 01:15:32 +03:00
|
|
|
if (!mCanHaveInlineAxisScrollbar && alignmentEdges.mAssigned) {
|
|
|
|
LogicalRect alignmentRect(mBlockWM, alignmentEdges.mIStart,
|
|
|
|
insideMarkersArea.BStart(mBlockWM),
|
|
|
|
alignmentEdges.ISize(), 1);
|
2011-06-22 22:11:48 +04:00
|
|
|
insideMarkersArea.IntersectRect(insideMarkersArea, alignmentRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clip and remove display items as needed at the final marker edges.
|
|
|
|
nsDisplayList* lists[] = { aLists.Content(), aLists.PositionedDescendants() };
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < ArrayLength(lists); ++i) {
|
2011-06-22 22:11:48 +04:00
|
|
|
PruneDisplayListContents(lists[i], framesToHide, insideMarkersArea);
|
|
|
|
}
|
2017-09-13 22:28:24 +03:00
|
|
|
CreateMarkers(aLine, needIStart, needIEnd, insideMarkersArea, contentArea, aLineNumber);
|
2011-06-22 22:11:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-04-24 01:15:32 +03:00
|
|
|
TextOverflow::PruneDisplayListContents(nsDisplayList* aList,
|
2011-06-22 22:11:48 +04:00
|
|
|
const FrameHashtable& aFramesToHide,
|
2015-04-24 01:15:32 +03:00
|
|
|
const LogicalRect& aInsideMarkersArea)
|
2011-06-22 22:11:48 +04:00
|
|
|
{
|
2017-11-16 06:09:28 +03:00
|
|
|
nsDisplayList saved;
|
2011-06-22 22:11:48 +04:00
|
|
|
nsDisplayItem* item;
|
|
|
|
while ((item = aList->RemoveBottom())) {
|
2013-04-19 16:02:13 +04:00
|
|
|
nsIFrame* itemFrame = item->Frame();
|
2013-04-19 16:01:41 +04:00
|
|
|
if (IsFrameDescendantOfAny(itemFrame, aFramesToHide, mBlock)) {
|
2017-08-07 07:07:43 +03:00
|
|
|
item->Destroy(mBuilder);
|
2011-06-22 22:11:48 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-11-02 16:59:03 +04:00
|
|
|
nsDisplayList* wrapper = item->GetSameCoordinateSystemChildren();
|
2011-06-22 22:11:48 +04:00
|
|
|
if (wrapper) {
|
|
|
|
if (!itemFrame || GetSelfOrNearestBlock(itemFrame) == mBlock) {
|
|
|
|
PruneDisplayListContents(wrapper, aFramesToHide, aInsideMarkersArea);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
nsCharClipDisplayItem* charClip = itemFrame ?
|
2012-07-30 18:20:58 +04:00
|
|
|
nsCharClipDisplayItem::CheckCast(item) : nullptr;
|
2011-06-22 22:11:48 +04:00
|
|
|
if (charClip && GetSelfOrNearestBlock(itemFrame) == mBlock) {
|
2015-04-24 01:15:32 +03:00
|
|
|
LogicalRect rect =
|
|
|
|
GetLogicalScrollableOverflowRectRelativeToBlock(itemFrame);
|
|
|
|
if (mIStart.IsNeeded()) {
|
|
|
|
nscoord istart =
|
|
|
|
aInsideMarkersArea.IStart(mBlockWM) - rect.IStart(mBlockWM);
|
|
|
|
if (istart > 0) {
|
|
|
|
(mBlockWM.IsBidiLTR() ?
|
2015-04-29 10:18:53 +03:00
|
|
|
charClip->mVisIStartEdge : charClip->mVisIEndEdge) = istart;
|
2011-07-12 00:18:26 +04:00
|
|
|
}
|
2011-06-22 22:11:48 +04:00
|
|
|
}
|
2015-04-24 01:15:32 +03:00
|
|
|
if (mIEnd.IsNeeded()) {
|
|
|
|
nscoord iend = rect.IEnd(mBlockWM) - aInsideMarkersArea.IEnd(mBlockWM);
|
|
|
|
if (iend > 0) {
|
|
|
|
(mBlockWM.IsBidiLTR() ?
|
2015-04-29 10:18:53 +03:00
|
|
|
charClip->mVisIEndEdge : charClip->mVisIStartEdge) = iend;
|
2011-07-12 00:18:26 +04:00
|
|
|
}
|
2011-06-22 22:11:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
saved.AppendToTop(item);
|
|
|
|
}
|
|
|
|
aList->AppendToTop(&saved);
|
|
|
|
}
|
|
|
|
|
2015-02-25 17:33:00 +03:00
|
|
|
/* static */ bool
|
|
|
|
TextOverflow::HasClippedOverflow(nsIFrame* aBlockFrame)
|
|
|
|
{
|
|
|
|
const nsStyleTextReset* style = aBlockFrame->StyleTextReset();
|
|
|
|
return style->mTextOverflow.mLeft.mType == NS_STYLE_TEXT_OVERFLOW_CLIP &&
|
|
|
|
style->mTextOverflow.mRight.mType == NS_STYLE_TEXT_OVERFLOW_CLIP;
|
|
|
|
}
|
|
|
|
|
2011-06-22 22:11:48 +04:00
|
|
|
/* static */ bool
|
2017-04-15 01:31:43 +03:00
|
|
|
TextOverflow::CanHaveTextOverflow(nsIFrame* aBlockFrame)
|
2011-06-22 22:11:48 +04:00
|
|
|
{
|
2017-04-15 01:31:43 +03:00
|
|
|
// Nothing to do for text-overflow:clip or if 'overflow-x/y:visible'.
|
2015-02-25 17:33:00 +03:00
|
|
|
if (HasClippedOverflow(aBlockFrame) ||
|
2017-04-15 01:31:43 +03:00
|
|
|
IsInlineAxisOverflowVisible(aBlockFrame)) {
|
2011-06-22 22:11:48 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-04-03 22:02:09 +04:00
|
|
|
// Skip ComboboxControlFrame because it would clip the drop-down arrow.
|
|
|
|
// Its anon block inherits 'text-overflow' and does what is expected.
|
2017-04-30 18:30:08 +03:00
|
|
|
if (aBlockFrame->IsComboboxControlFrame()) {
|
2014-04-03 22:02:09 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-06-22 22:11:48 +04:00
|
|
|
// Inhibit the markers if a descendant content owns the caret.
|
2017-11-09 05:00:48 +03:00
|
|
|
RefPtr<nsCaret> caret = aBlockFrame->PresShell()->GetCaret();
|
2014-08-06 09:19:29 +04:00
|
|
|
if (caret && caret->IsVisible()) {
|
2018-05-08 20:52:38 +03:00
|
|
|
RefPtr<dom::Selection> domSelection = caret->GetSelection();
|
2011-06-22 22:11:48 +04:00
|
|
|
if (domSelection) {
|
2018-05-08 20:52:38 +03:00
|
|
|
nsCOMPtr<nsIContent> content =
|
|
|
|
nsIContent::FromNodeOrNull(domSelection->GetFocusNode());
|
2011-06-22 22:11:48 +04:00
|
|
|
if (content && nsContentUtils::ContentIsDescendantOf(content,
|
|
|
|
aBlockFrame->GetContent())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TextOverflow::CreateMarkers(const nsLineBox* aLine,
|
2015-04-24 01:15:32 +03:00
|
|
|
bool aCreateIStart, bool aCreateIEnd,
|
2017-04-15 01:31:44 +03:00
|
|
|
const LogicalRect& aInsideMarkersArea,
|
2017-09-13 22:28:24 +03:00
|
|
|
const LogicalRect& aContentArea,
|
|
|
|
uint32_t aLineNumber)
|
2011-06-22 22:11:48 +04:00
|
|
|
{
|
2015-04-24 01:15:32 +03:00
|
|
|
if (aCreateIStart) {
|
2013-04-04 15:36:45 +04:00
|
|
|
DisplayListClipState::AutoSaveRestore clipState(mBuilder);
|
2013-03-04 13:56:02 +04:00
|
|
|
|
2015-04-24 01:15:32 +03:00
|
|
|
LogicalRect markerLogicalRect(
|
|
|
|
mBlockWM, aInsideMarkersArea.IStart(mBlockWM) - mIStart.mIntrinsicISize,
|
|
|
|
aLine->BStart(), mIStart.mIntrinsicISize, aLine->BSize());
|
|
|
|
nsPoint offset = mBuilder->ToReferenceFrame(mBlock);
|
|
|
|
nsRect markerRect =
|
2015-07-16 12:07:57 +03:00
|
|
|
markerLogicalRect.GetPhysicalRect(mBlockWM, mBlockSize) + offset;
|
2017-04-15 01:31:44 +03:00
|
|
|
ClipMarker(aContentArea.GetPhysicalRect(mBlockWM, mBlockSize) + offset,
|
2013-04-04 15:36:45 +04:00
|
|
|
markerRect, clipState);
|
2018-02-13 03:43:28 +03:00
|
|
|
nsDisplayItem* marker =
|
|
|
|
MakeDisplayItem<nsDisplayTextOverflowMarker>(mBuilder, mBlock, markerRect,
|
|
|
|
aLine->GetLogicalAscent(), mIStart.mStyle,
|
|
|
|
aLineNumber, 0);
|
2017-12-13 20:23:04 +03:00
|
|
|
mMarkerList.AppendToTop(marker);
|
2011-06-22 22:11:48 +04:00
|
|
|
}
|
|
|
|
|
2015-04-24 01:15:32 +03:00
|
|
|
if (aCreateIEnd) {
|
2013-04-04 15:36:45 +04:00
|
|
|
DisplayListClipState::AutoSaveRestore clipState(mBuilder);
|
2013-03-04 13:56:02 +04:00
|
|
|
|
2015-04-24 01:15:32 +03:00
|
|
|
LogicalRect markerLogicalRect(
|
|
|
|
mBlockWM, aInsideMarkersArea.IEnd(mBlockWM), aLine->BStart(),
|
|
|
|
mIEnd.mIntrinsicISize, aLine->BSize());
|
|
|
|
nsPoint offset = mBuilder->ToReferenceFrame(mBlock);
|
|
|
|
nsRect markerRect =
|
2015-07-16 12:07:57 +03:00
|
|
|
markerLogicalRect.GetPhysicalRect(mBlockWM, mBlockSize) + offset;
|
2017-04-15 01:31:44 +03:00
|
|
|
ClipMarker(aContentArea.GetPhysicalRect(mBlockWM, mBlockSize) + offset,
|
2013-04-04 15:36:45 +04:00
|
|
|
markerRect, clipState);
|
2018-02-13 03:43:28 +03:00
|
|
|
nsDisplayItem* marker =
|
|
|
|
MakeDisplayItem<nsDisplayTextOverflowMarker>(mBuilder, mBlock, markerRect,
|
|
|
|
aLine->GetLogicalAscent(), mIEnd.mStyle,
|
|
|
|
aLineNumber, 1);
|
2017-12-13 20:23:04 +03:00
|
|
|
mMarkerList.AppendToTop(marker);
|
2011-06-22 22:11:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TextOverflow::Marker::SetupString(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (mInitialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-08 14:41:31 +04:00
|
|
|
if (mStyle->mType == NS_STYLE_TEXT_OVERFLOW_ELLIPSIS) {
|
|
|
|
gfxTextRun* textRun = GetEllipsisTextRun(aFrame);
|
|
|
|
if (textRun) {
|
2016-03-08 10:56:18 +03:00
|
|
|
mISize = textRun->GetAdvanceWidth();
|
2013-03-08 14:41:31 +04:00
|
|
|
} else {
|
2015-04-24 01:15:32 +03:00
|
|
|
mISize = 0;
|
2013-03-08 14:41:31 +04:00
|
|
|
}
|
|
|
|
} else {
|
2017-06-09 22:14:53 +03:00
|
|
|
RefPtr<gfxContext> rc =
|
2017-11-09 05:00:48 +03:00
|
|
|
aFrame->PresShell()->CreateReferenceRenderingContext();
|
2016-03-17 08:55:48 +03:00
|
|
|
RefPtr<nsFontMetrics> fm =
|
|
|
|
nsLayoutUtils::GetInflatedFontMetricsForFrame(aFrame);
|
2015-04-24 01:15:32 +03:00
|
|
|
mISize = nsLayoutUtils::AppUnitWidthOfStringBidi(mStyle->mString, aFrame,
|
2017-06-09 22:14:53 +03:00
|
|
|
*fm, *rc);
|
2013-03-08 14:41:31 +04:00
|
|
|
}
|
2015-04-24 01:15:32 +03:00
|
|
|
mIntrinsicISize = mISize;
|
2011-06-22 22:11:48 +04:00
|
|
|
mInitialized = true;
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace css
|
|
|
|
} // namespace mozilla
|