2011-06-22 11:11:48 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
|
2012-05-21 04:12:37 -07: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 11:11:48 -07:00
|
|
|
|
|
|
|
#include "TextOverflow.h"
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2011-06-22 11:11:48 -07:00
|
|
|
|
|
|
|
// Please maintain alphabetical order below
|
|
|
|
#include "nsBlockFrame.h"
|
|
|
|
#include "nsCaret.h"
|
|
|
|
#include "nsContentUtils.h"
|
2013-03-02 16:31:48 -08:00
|
|
|
#include "nsCSSAnonBoxes.h"
|
2012-01-27 19:35:59 -08:00
|
|
|
#include "nsGfxScrollFrame.h"
|
2011-06-22 11:11:48 -07:00
|
|
|
#include "nsIScrollableFrame.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsRect.h"
|
|
|
|
#include "nsRenderingContext.h"
|
|
|
|
#include "nsTextFrame.h"
|
2013-10-01 14:00:38 -07:00
|
|
|
#include "nsIFrameInlines.h"
|
2013-12-08 18:52:54 -08:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2012-10-26 06:32:10 -07:00
|
|
|
#include "mozilla/Likely.h"
|
2011-06-22 11:11:48 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
|
|
|
|
2013-03-08 02:41:31 -08:00
|
|
|
class LazyReferenceRenderingContextGetterFromFrame MOZ_FINAL :
|
|
|
|
public gfxFontGroup::LazyReferenceContextGetter {
|
|
|
|
public:
|
|
|
|
LazyReferenceRenderingContextGetterFromFrame(nsIFrame* aFrame)
|
|
|
|
: mFrame(aFrame) {}
|
|
|
|
virtual already_AddRefed<gfxContext> GetRefContext() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
nsRefPtr<nsRenderingContext> rc =
|
2014-04-14 21:30:25 -07:00
|
|
|
mFrame->PresContext()->PresShell()->CreateReferenceRenderingContext();
|
2013-03-08 02:41:31 -08:00
|
|
|
nsRefPtr<gfxContext> ctx = rc->ThebesContext();
|
|
|
|
return ctx.forget();
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
nsIFrame* mFrame;
|
|
|
|
};
|
2011-06-22 11:11:48 -07:00
|
|
|
|
2013-03-08 02:41:31 -08:00
|
|
|
static gfxTextRun*
|
|
|
|
GetEllipsisTextRun(nsIFrame* aFrame)
|
2011-06-22 11:11:48 -07:00
|
|
|
{
|
2013-03-08 02:41:31 -08:00
|
|
|
nsRefPtr<nsFontMetrics> fm;
|
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(aFrame, getter_AddRefs(fm),
|
|
|
|
nsLayoutUtils::FontSizeInflationFor(aFrame));
|
|
|
|
LazyReferenceRenderingContextGetterFromFrame lazyRefContextGetter(aFrame);
|
|
|
|
return fm->GetThebesFontGroup()->GetEllipsisTextRun(
|
|
|
|
aFrame->PresContext()->AppUnitsPerDevPixel(), lazyRefContextGetter);
|
2011-06-22 11:11:48 -07: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
|
|
|
|
IsAtomicElement(nsIFrame* aFrame, const nsIAtom* aFrameType)
|
|
|
|
{
|
2011-07-19 05:20:32 -07:00
|
|
|
NS_PRECONDITION(!nsLayoutUtils::GetAsBlock(aFrame) ||
|
2012-08-02 04:38:51 -07:00
|
|
|
!aFrame->IsBlockOutside(),
|
2011-06-22 11:11:48 -07:00
|
|
|
"unexpected block frame");
|
2011-07-03 22:47:59 -07:00
|
|
|
NS_PRECONDITION(aFrameType != nsGkAtoms::placeholderFrame,
|
|
|
|
"unexpected placeholder frame");
|
|
|
|
return !aFrame->IsFrameOfType(nsIFrame::eLineParticipant);
|
2011-06-22 11:11:48 -07: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-23 18:48:23 -08:00
|
|
|
return !aFrame->MeasureCharClippedText(aLeft, aRight,
|
|
|
|
aSnappedLeft, aSnappedRight);
|
2011-06-22 11:11:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
IsHorizontalOverflowVisible(nsIFrame* aFrame)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_PRECONDITION(nsLayoutUtils::GetAsBlock(aFrame) != nullptr,
|
2011-06-22 11:11:48 -07:00
|
|
|
"expected a block frame");
|
|
|
|
|
|
|
|
nsIFrame* f = aFrame;
|
2013-02-23 02:38:15 -08:00
|
|
|
while (f && f->StyleContext()->GetPseudo() &&
|
|
|
|
f->GetType() != nsGkAtoms::scrollFrame) {
|
2011-06-22 11:11:48 -07:00
|
|
|
f = f->GetParent();
|
|
|
|
}
|
2013-02-16 13:51:02 -08:00
|
|
|
return !f || f->StyleDisplay()->mOverflowX == NS_STYLE_OVERFLOW_VISIBLE;
|
2011-06-22 11:11:48 -07:00
|
|
|
}
|
|
|
|
|
2013-03-04 01:56:02 -08:00
|
|
|
static void
|
2013-04-04 04:36:45 -07:00
|
|
|
ClipMarker(const nsRect& aContentArea,
|
|
|
|
const nsRect& aMarkerRect,
|
|
|
|
DisplayListClipState::AutoSaveRestore& aClipState)
|
2011-06-22 11:11:48 -07:00
|
|
|
{
|
2013-03-04 01:56:02 -08:00
|
|
|
nscoord rightOverflow = aMarkerRect.XMost() - aContentArea.XMost();
|
|
|
|
nsRect markerRect = aMarkerRect;
|
2011-06-22 11:11:48 -07:00
|
|
|
if (rightOverflow > 0) {
|
|
|
|
// Marker overflows on the right side (content width < marker width).
|
2013-03-04 01:56:02 -08:00
|
|
|
markerRect.width -= rightOverflow;
|
2013-04-04 04:36:45 -07:00
|
|
|
aClipState.ClipContentDescendants(markerRect);
|
2011-06-22 11:11:48 -07:00
|
|
|
} else {
|
2013-03-04 01:56:02 -08:00
|
|
|
nscoord leftOverflow = aContentArea.x - aMarkerRect.x;
|
2011-06-22 11:11:48 -07:00
|
|
|
if (leftOverflow > 0) {
|
|
|
|
// Marker overflows on the left side
|
2013-03-04 01:56:02 -08:00
|
|
|
markerRect.width -= leftOverflow;
|
|
|
|
markerRect.x += leftOverflow;
|
2013-04-04 04:36:45 -07:00
|
|
|
aClipState.ClipContentDescendants(markerRect);
|
2011-06-22 11:11:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-12-19 06:48:30 -08:00
|
|
|
InflateLeft(nsRect* aRect, nscoord aDelta)
|
2011-06-22 11:11:48 -07:00
|
|
|
{
|
|
|
|
nscoord xmost = aRect->XMost();
|
2011-12-19 06:48:30 -08:00
|
|
|
aRect->x -= aDelta;
|
2013-01-15 04:22:03 -08:00
|
|
|
aRect->width = std::max(xmost - aRect->x, 0);
|
2011-06-22 11:11:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-12-19 06:48:30 -08:00
|
|
|
InflateRight(nsRect* aRect, nscoord aDelta)
|
2011-06-22 11:11:48 -07:00
|
|
|
{
|
2013-01-15 04:22:03 -08:00
|
|
|
aRect->width = std::max(aRect->width + aDelta, 0);
|
2011-06-22 11:11:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
IsFrameDescendantOfAny(nsIFrame* aChild,
|
|
|
|
const TextOverflow::FrameHashtable& aSetOfFrames,
|
|
|
|
nsIFrame* aCommonAncestor)
|
|
|
|
{
|
2011-06-24 12:12:52 -07:00
|
|
|
for (nsIFrame* f = aChild; f && f != aCommonAncestor;
|
2011-06-22 11:11:48 -07:00
|
|
|
f = nsLayoutUtils::GetCrossDocParentFrame(f)) {
|
|
|
|
if (aSetOfFrames.GetEntry(f)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
class nsDisplayTextOverflowMarker : public nsDisplayItem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsDisplayTextOverflowMarker(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame,
|
|
|
|
const nsRect& aRect, nscoord aAscent,
|
2013-03-08 02:41:31 -08:00
|
|
|
const nsStyleTextOverflowSide* aStyle,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aIndex)
|
2013-03-08 02:41:31 -08:00
|
|
|
: nsDisplayItem(aBuilder, aFrame), mRect(aRect),
|
|
|
|
mStyle(aStyle), mAscent(aAscent), mIndex(aIndex) {
|
2011-06-22 11:11:48 -07:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayTextOverflowMarker);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayTextOverflowMarker() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayTextOverflowMarker);
|
|
|
|
}
|
|
|
|
#endif
|
2014-02-24 06:41:56 -08:00
|
|
|
virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder,
|
|
|
|
bool* aSnap) MOZ_OVERRIDE {
|
2012-04-10 04:24:18 -07:00
|
|
|
*aSnap = false;
|
2011-06-30 23:43:11 -07:00
|
|
|
nsRect shadowRect =
|
|
|
|
nsLayoutUtils::GetTextShadowRectsUnion(mRect, mFrame);
|
|
|
|
return mRect.Union(shadowRect);
|
2011-06-22 11:11:48 -07:00
|
|
|
}
|
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2014-02-24 06:41:56 -08:00
|
|
|
nsRenderingContext* aCtx) MOZ_OVERRIDE;
|
2012-03-01 00:26:09 -08:00
|
|
|
|
2014-02-24 06:41:56 -08:00
|
|
|
virtual uint32_t GetPerFrameKey() MOZ_OVERRIDE {
|
2012-03-01 00:26:09 -08:00
|
|
|
return (mIndex << nsDisplayItem::TYPE_BITS) | nsDisplayItem::GetPerFrameKey();
|
|
|
|
}
|
2011-06-30 23:43:11 -07:00
|
|
|
void PaintTextToContext(nsRenderingContext* aCtx,
|
|
|
|
nsPoint aOffsetFromRect);
|
2011-06-22 11:11:48 -07:00
|
|
|
NS_DISPLAY_DECL_NAME("TextOverflow", TYPE_TEXT_OVERFLOW)
|
|
|
|
private:
|
|
|
|
nsRect mRect; // in reference frame coordinates
|
2013-03-08 02:41:31 -08:00
|
|
|
const nsStyleTextOverflowSide* mStyle;
|
2011-06-22 11:11:48 -07:00
|
|
|
nscoord mAscent; // baseline for the marker text in mRect
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mIndex;
|
2011-06-22 11:11:48 -07:00
|
|
|
};
|
|
|
|
|
2011-06-30 23:43:11 -07:00
|
|
|
static void
|
|
|
|
PaintTextShadowCallback(nsRenderingContext* aCtx,
|
|
|
|
nsPoint aShadowOffset,
|
|
|
|
const nscolor& aShadowColor,
|
|
|
|
void* aData)
|
|
|
|
{
|
|
|
|
reinterpret_cast<nsDisplayTextOverflowMarker*>(aData)->
|
|
|
|
PaintTextToContext(aCtx, aShadowOffset);
|
|
|
|
}
|
|
|
|
|
2011-06-22 11:11:48 -07:00
|
|
|
void
|
|
|
|
nsDisplayTextOverflowMarker::Paint(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRenderingContext* aCtx)
|
2011-06-30 23:43:11 -07:00
|
|
|
{
|
2011-08-09 08:14:36 -07:00
|
|
|
nscolor foregroundColor =
|
|
|
|
nsLayoutUtils::GetColor(mFrame, eCSSProperty_color);
|
2011-06-30 23:43:11 -07:00
|
|
|
|
|
|
|
// Paint the text-shadows for the overflow marker
|
|
|
|
nsLayoutUtils::PaintTextShadow(mFrame, aCtx, mRect, mVisibleRect,
|
|
|
|
foregroundColor, PaintTextShadowCallback,
|
|
|
|
(void*)this);
|
|
|
|
aCtx->SetColor(foregroundColor);
|
|
|
|
PaintTextToContext(aCtx, nsPoint(0, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplayTextOverflowMarker::PaintTextToContext(nsRenderingContext* aCtx,
|
|
|
|
nsPoint aOffsetFromRect)
|
2011-06-22 11:11:48 -07:00
|
|
|
{
|
2011-07-03 22:47:59 -07:00
|
|
|
gfxFloat y = nsLayoutUtils::GetSnappedBaselineY(mFrame, aCtx->ThebesContext(),
|
|
|
|
mRect.y, mAscent);
|
|
|
|
nsPoint baselinePt(mRect.x, NSToCoordFloor(y));
|
2013-03-08 02:41:31 -08:00
|
|
|
nsPoint pt = baselinePt + aOffsetFromRect;
|
|
|
|
|
|
|
|
if (mStyle->mType == NS_STYLE_TEXT_OVERFLOW_ELLIPSIS) {
|
|
|
|
gfxTextRun* textRun = GetEllipsisTextRun(mFrame);
|
|
|
|
if (textRun) {
|
|
|
|
NS_ASSERTION(!textRun->IsRightToLeft(),
|
|
|
|
"Ellipsis textruns should always be LTR!");
|
|
|
|
gfxPoint gfxPt(pt.x, pt.y);
|
2013-10-01 14:02:16 -07:00
|
|
|
textRun->Draw(aCtx->ThebesContext(), gfxPt, DrawMode::GLYPH_FILL,
|
2013-03-08 02:41:31 -08:00
|
|
|
0, textRun->GetLength(), nullptr, nullptr, nullptr);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nsRefPtr<nsFontMetrics> fm;
|
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(mFrame, getter_AddRefs(fm),
|
|
|
|
nsLayoutUtils::FontSizeInflationFor(mFrame));
|
|
|
|
aCtx->SetFont(fm);
|
|
|
|
nsLayoutUtils::DrawString(mFrame, aCtx, mStyle->mString.get(),
|
|
|
|
mStyle->mString.Length(), pt);
|
|
|
|
}
|
2011-06-22 11:11:48 -07:00
|
|
|
}
|
|
|
|
|
2012-01-27 19:35:59 -08:00
|
|
|
void
|
|
|
|
TextOverflow::Init(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aBlockFrame)
|
|
|
|
{
|
|
|
|
mBuilder = aBuilder;
|
|
|
|
mBlock = aBlockFrame;
|
|
|
|
mContentArea = aBlockFrame->GetContentRectRelativeToSelf();
|
|
|
|
mScrollableFrame = nsLayoutUtils::GetScrollableFrameFor(aBlockFrame);
|
2013-02-16 13:51:02 -08:00
|
|
|
uint8_t direction = aBlockFrame->StyleVisibility()->mDirection;
|
2012-01-27 19:35:59 -08:00
|
|
|
mBlockIsRTL = direction == NS_STYLE_DIRECTION_RTL;
|
|
|
|
mAdjustForPixelSnapping = false;
|
|
|
|
#ifdef MOZ_XUL
|
|
|
|
if (!mScrollableFrame) {
|
2013-02-15 21:38:33 -08:00
|
|
|
nsIAtom* pseudoType = aBlockFrame->StyleContext()->GetPseudo();
|
2012-01-27 19:35:59 -08:00
|
|
|
if (pseudoType == nsCSSAnonBoxes::mozXULAnonymousBlock) {
|
|
|
|
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.
|
|
|
|
mAdjustForPixelSnapping = mBlockIsRTL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
mCanHaveHorizontalScrollbar = false;
|
|
|
|
if (mScrollableFrame) {
|
|
|
|
mCanHaveHorizontalScrollbar =
|
|
|
|
mScrollableFrame->GetScrollbarStyles().mHorizontal != NS_STYLE_OVERFLOW_HIDDEN;
|
|
|
|
if (!mAdjustForPixelSnapping) {
|
|
|
|
// Scrolling to the end position can leave some text still overflowing due
|
|
|
|
// to pixel snapping behaviour in our scrolling code.
|
|
|
|
mAdjustForPixelSnapping = mCanHaveHorizontalScrollbar;
|
|
|
|
}
|
|
|
|
mContentArea.MoveBy(mScrollableFrame->GetScrollPosition());
|
|
|
|
nsIFrame* scrollFrame = do_QueryFrame(mScrollableFrame);
|
|
|
|
scrollFrame->AddStateBits(NS_SCROLLFRAME_INVALIDATE_CONTENTS_ON_SCROLL);
|
|
|
|
}
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleTextReset* style = aBlockFrame->StyleTextReset();
|
2012-01-27 19:35:59 -08:00
|
|
|
mLeft.Init(style->mTextOverflow.GetLeft(direction));
|
|
|
|
mRight.Init(style->mTextOverflow.GetRight(direction));
|
|
|
|
// The left/right marker string is setup in ExamineLineFrames when a line
|
|
|
|
// has overflow on that side.
|
|
|
|
}
|
|
|
|
|
2011-06-22 11:11:48 -07:00
|
|
|
/* static */ TextOverflow*
|
|
|
|
TextOverflow::WillProcessLines(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aBlockFrame)
|
|
|
|
{
|
|
|
|
if (!CanHaveTextOverflow(aBuilder, aBlockFrame)) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-06-22 11:11:48 -07:00
|
|
|
}
|
|
|
|
nsAutoPtr<TextOverflow> textOverflow(new TextOverflow);
|
2012-07-22 23:08:24 -07:00
|
|
|
textOverflow->Init(aBuilder, aBlockFrame);
|
2011-06-22 11:11:48 -07:00
|
|
|
return textOverflow.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TextOverflow::ExamineFrameSubtree(nsIFrame* aFrame,
|
|
|
|
const nsRect& aContentArea,
|
|
|
|
const nsRect& aInsideMarkersArea,
|
|
|
|
FrameHashtable* aFramesToHide,
|
2011-12-19 06:48:31 -08:00
|
|
|
AlignmentEdges* aAlignmentEdges,
|
2011-12-19 06:48:31 -08:00
|
|
|
bool* aFoundVisibleTextOrAtomic,
|
|
|
|
InnerClipEdges* aClippedMarkerEdges)
|
2011-06-22 11:11:48 -07:00
|
|
|
{
|
|
|
|
const nsIAtom* frameType = aFrame->GetType();
|
2011-07-03 22:47:59 -07:00
|
|
|
if (frameType == nsGkAtoms::brFrame ||
|
|
|
|
frameType == nsGkAtoms::placeholderFrame) {
|
2011-06-22 11:11:48 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const bool isAtomic = IsAtomicElement(aFrame, frameType);
|
2013-02-16 13:51:02 -08:00
|
|
|
if (aFrame->StyleVisibility()->IsVisible()) {
|
2011-06-22 11:11:48 -07:00
|
|
|
nsRect childRect = aFrame->GetScrollableOverflowRect() +
|
|
|
|
aFrame->GetOffsetTo(mBlock);
|
|
|
|
bool overflowLeft = childRect.x < aContentArea.x;
|
|
|
|
bool overflowRight = childRect.XMost() > aContentArea.XMost();
|
|
|
|
if (overflowLeft) {
|
|
|
|
mLeft.mHasOverflow = true;
|
|
|
|
}
|
|
|
|
if (overflowRight) {
|
|
|
|
mRight.mHasOverflow = true;
|
|
|
|
}
|
2011-12-19 06:48:30 -08:00
|
|
|
if (isAtomic && ((mLeft.mActive && overflowLeft) ||
|
|
|
|
(mRight.mActive && overflowRight))) {
|
2011-06-22 11:11:48 -07:00
|
|
|
aFramesToHide->PutEntry(aFrame);
|
|
|
|
} else if (isAtomic || frameType == nsGkAtoms::textFrame) {
|
|
|
|
AnalyzeMarkerEdges(aFrame, frameType, aInsideMarkersArea,
|
2011-12-19 06:48:31 -08:00
|
|
|
aFramesToHide, aAlignmentEdges,
|
2011-12-19 06:48:31 -08:00
|
|
|
aFoundVisibleTextOrAtomic,
|
|
|
|
aClippedMarkerEdges);
|
2011-06-22 11:11:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isAtomic) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-24 13:54:30 -07:00
|
|
|
nsIFrame* child = aFrame->GetFirstPrincipalChild();
|
2011-06-22 11:11:48 -07:00
|
|
|
while (child) {
|
|
|
|
ExamineFrameSubtree(child, aContentArea, aInsideMarkersArea,
|
2011-12-19 06:48:31 -08:00
|
|
|
aFramesToHide, aAlignmentEdges,
|
2011-12-19 06:48:31 -08:00
|
|
|
aFoundVisibleTextOrAtomic,
|
|
|
|
aClippedMarkerEdges);
|
2011-06-22 11:11:48 -07:00
|
|
|
child = child->GetNextSibling();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TextOverflow::AnalyzeMarkerEdges(nsIFrame* aFrame,
|
|
|
|
const nsIAtom* aFrameType,
|
|
|
|
const nsRect& aInsideMarkersArea,
|
|
|
|
FrameHashtable* aFramesToHide,
|
2011-12-19 06:48:31 -08:00
|
|
|
AlignmentEdges* aAlignmentEdges,
|
2011-12-19 06:48:31 -08:00
|
|
|
bool* aFoundVisibleTextOrAtomic,
|
|
|
|
InnerClipEdges* aClippedMarkerEdges)
|
2011-06-22 11:11:48 -07:00
|
|
|
{
|
|
|
|
nsRect borderRect(aFrame->GetOffsetTo(mBlock), aFrame->GetSize());
|
|
|
|
nscoord leftOverlap =
|
2013-01-15 04:22:03 -08:00
|
|
|
std::max(aInsideMarkersArea.x - borderRect.x, 0);
|
2011-06-22 11:11:48 -07:00
|
|
|
nscoord rightOverlap =
|
2013-01-15 04:22:03 -08:00
|
|
|
std::max(borderRect.XMost() - aInsideMarkersArea.XMost(), 0);
|
2011-06-22 11:11:48 -07:00
|
|
|
bool insideLeftEdge = aInsideMarkersArea.x <= borderRect.XMost();
|
|
|
|
bool insideRightEdge = borderRect.x <= aInsideMarkersArea.XMost();
|
|
|
|
|
2011-12-19 06:48:31 -08:00
|
|
|
if (leftOverlap > 0) {
|
|
|
|
aClippedMarkerEdges->AccumulateLeft(borderRect);
|
|
|
|
if (!mLeft.mActive) {
|
|
|
|
leftOverlap = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rightOverlap > 0) {
|
|
|
|
aClippedMarkerEdges->AccumulateRight(borderRect);
|
|
|
|
if (!mRight.mActive) {
|
|
|
|
rightOverlap = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-22 11:11:48 -07:00
|
|
|
if ((leftOverlap > 0 && insideLeftEdge) ||
|
|
|
|
(rightOverlap > 0 && insideRightEdge)) {
|
2011-12-19 06:48:31 -08:00
|
|
|
if (aFrameType == nsGkAtoms::textFrame) {
|
|
|
|
if (aInsideMarkersArea.x < aInsideMarkersArea.XMost()) {
|
|
|
|
// a clipped text frame and there is some room between the markers
|
|
|
|
nscoord snappedLeft, snappedRight;
|
|
|
|
bool isFullyClipped =
|
|
|
|
IsFullyClipped(static_cast<nsTextFrame*>(aFrame),
|
|
|
|
leftOverlap, rightOverlap, &snappedLeft, &snappedRight);
|
|
|
|
if (!isFullyClipped) {
|
|
|
|
nsRect snappedRect = borderRect;
|
|
|
|
if (leftOverlap > 0) {
|
|
|
|
snappedRect.x += snappedLeft;
|
|
|
|
snappedRect.width -= snappedLeft;
|
|
|
|
}
|
|
|
|
if (rightOverlap > 0) {
|
|
|
|
snappedRect.width -= snappedRight;
|
|
|
|
}
|
|
|
|
aAlignmentEdges->Accumulate(snappedRect);
|
|
|
|
*aFoundVisibleTextOrAtomic = true;
|
2011-06-22 11:11:48 -07:00
|
|
|
}
|
2011-12-19 06:48:30 -08:00
|
|
|
}
|
2011-12-19 06:48:31 -08:00
|
|
|
} else {
|
|
|
|
aFramesToHide->PutEntry(aFrame);
|
2011-06-22 11:11:48 -07:00
|
|
|
}
|
|
|
|
} else if (!insideLeftEdge || !insideRightEdge) {
|
|
|
|
// frame is outside
|
|
|
|
if (IsAtomicElement(aFrame, aFrameType)) {
|
|
|
|
aFramesToHide->PutEntry(aFrame);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// frame is inside
|
|
|
|
aAlignmentEdges->Accumulate(borderRect);
|
2011-12-19 06:48:31 -08:00
|
|
|
*aFoundVisibleTextOrAtomic = true;
|
2011-06-22 11:11:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TextOverflow::ExamineLineFrames(nsLineBox* aLine,
|
|
|
|
FrameHashtable* aFramesToHide,
|
|
|
|
AlignmentEdges* aAlignmentEdges)
|
|
|
|
{
|
2011-10-12 09:20:46 -07:00
|
|
|
// No ellipsing for 'clip' style.
|
|
|
|
bool suppressLeft = mLeft.mStyle->mType == NS_STYLE_TEXT_OVERFLOW_CLIP;
|
|
|
|
bool suppressRight = mRight.mStyle->mType == NS_STYLE_TEXT_OVERFLOW_CLIP;
|
2011-10-12 09:20:46 -07:00
|
|
|
if (mCanHaveHorizontalScrollbar) {
|
2012-01-27 19:35:59 -08:00
|
|
|
nsPoint pos = mScrollableFrame->GetScrollPosition();
|
|
|
|
nsRect scrollRange = mScrollableFrame->GetScrollRange();
|
2011-10-12 09:20:46 -07:00
|
|
|
// No ellipsing when nothing to scroll to on that side (this includes
|
|
|
|
// overflow:auto that doesn't trigger a horizontal scrollbar).
|
|
|
|
if (pos.x <= scrollRange.x) {
|
|
|
|
suppressLeft = true;
|
|
|
|
}
|
|
|
|
if (pos.x >= scrollRange.XMost()) {
|
|
|
|
suppressRight = true;
|
|
|
|
}
|
|
|
|
}
|
2011-10-12 09:20:46 -07:00
|
|
|
|
2011-06-22 11:11:48 -07:00
|
|
|
nsRect contentArea = mContentArea;
|
2012-01-27 19:35:59 -08:00
|
|
|
const nscoord scrollAdjust = mAdjustForPixelSnapping ?
|
2011-06-22 11:11:48 -07:00
|
|
|
mBlock->PresContext()->AppUnitsPerDevPixel() : 0;
|
2011-12-19 06:48:30 -08:00
|
|
|
InflateLeft(&contentArea, scrollAdjust);
|
|
|
|
InflateRight(&contentArea, scrollAdjust);
|
2011-06-22 11:11:48 -07:00
|
|
|
nsRect lineRect = aLine->GetScrollableOverflowArea();
|
2011-10-12 09:20:46 -07:00
|
|
|
const bool leftOverflow =
|
|
|
|
!suppressLeft && lineRect.x < contentArea.x;
|
|
|
|
const bool rightOverflow =
|
|
|
|
!suppressRight && lineRect.XMost() > contentArea.XMost();
|
2011-06-22 11:11:48 -07:00
|
|
|
if (!leftOverflow && !rightOverflow) {
|
2011-10-12 09:20:46 -07:00
|
|
|
// The line does not overflow on a side we should ellipsize.
|
2011-06-22 11:11:48 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-19 06:48:31 -08:00
|
|
|
int pass = 0;
|
|
|
|
bool retryEmptyLine = true;
|
2011-10-12 09:20:46 -07:00
|
|
|
bool guessLeft = leftOverflow;
|
|
|
|
bool guessRight = rightOverflow;
|
2011-12-19 06:48:30 -08:00
|
|
|
mLeft.mActive = leftOverflow;
|
|
|
|
mRight.mActive = rightOverflow;
|
2011-12-19 06:48:31 -08:00
|
|
|
bool clippedLeftMarker = false;
|
|
|
|
bool clippedRightMarker = false;
|
2011-06-22 11:11:48 -07:00
|
|
|
do {
|
|
|
|
// Setup marker strings as needed.
|
2011-08-20 13:41:39 -07:00
|
|
|
if (guessLeft) {
|
2011-06-22 11:11:48 -07:00
|
|
|
mLeft.SetupString(mBlock);
|
2011-08-20 13:41:39 -07:00
|
|
|
}
|
|
|
|
if (guessRight) {
|
|
|
|
mRight.SetupString(mBlock);
|
2011-06-22 11:11:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// If there is insufficient space for both markers then keep the one on the
|
|
|
|
// end side per the block's 'direction'.
|
2011-12-19 06:48:31 -08:00
|
|
|
nscoord rightMarkerWidth = mRight.mActive ? mRight.mWidth : 0;
|
|
|
|
nscoord leftMarkerWidth = mLeft.mActive ? mLeft.mWidth : 0;
|
|
|
|
if (leftMarkerWidth && rightMarkerWidth &&
|
2011-06-22 11:11:48 -07:00
|
|
|
leftMarkerWidth + rightMarkerWidth > contentArea.width) {
|
|
|
|
if (mBlockIsRTL) {
|
|
|
|
rightMarkerWidth = 0;
|
|
|
|
} else {
|
|
|
|
leftMarkerWidth = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate the area between the potential markers aligned at the
|
|
|
|
// block's edge.
|
|
|
|
nsRect insideMarkersArea = mContentArea;
|
2011-12-19 06:48:30 -08:00
|
|
|
if (guessLeft) {
|
|
|
|
InflateLeft(&insideMarkersArea, -leftMarkerWidth);
|
|
|
|
}
|
|
|
|
if (guessRight) {
|
|
|
|
InflateRight(&insideMarkersArea, -rightMarkerWidth);
|
|
|
|
}
|
2011-06-22 11:11:48 -07: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 06:48:31 -08:00
|
|
|
bool foundVisibleTextOrAtomic = false;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t n = aLine->GetChildCount();
|
2011-06-22 11:11:48 -07:00
|
|
|
nsIFrame* child = aLine->mFirstChild;
|
2011-12-19 06:48:31 -08:00
|
|
|
InnerClipEdges clippedMarkerEdges;
|
2011-06-22 11:11:48 -07:00
|
|
|
for (; n-- > 0; child = child->GetNextSibling()) {
|
|
|
|
ExamineFrameSubtree(child, contentArea, insideMarkersArea,
|
2011-12-19 06:48:31 -08:00
|
|
|
aFramesToHide, aAlignmentEdges,
|
2011-12-19 06:48:31 -08:00
|
|
|
&foundVisibleTextOrAtomic,
|
|
|
|
&clippedMarkerEdges);
|
|
|
|
}
|
|
|
|
if (!foundVisibleTextOrAtomic && retryEmptyLine) {
|
|
|
|
aAlignmentEdges->mAssigned = false;
|
|
|
|
aFramesToHide->Clear();
|
|
|
|
pass = -1;
|
|
|
|
if (mLeft.IsNeeded() && mLeft.mActive && !clippedLeftMarker) {
|
|
|
|
if (clippedMarkerEdges.mAssignedLeft &&
|
|
|
|
clippedMarkerEdges.mLeft - mContentArea.X() > 0) {
|
|
|
|
mLeft.mWidth = clippedMarkerEdges.mLeft - mContentArea.X();
|
|
|
|
NS_ASSERTION(mLeft.mWidth < mLeft.mIntrinsicWidth,
|
|
|
|
"clipping a marker should make it strictly smaller");
|
|
|
|
clippedLeftMarker = true;
|
|
|
|
} else {
|
|
|
|
mLeft.mActive = guessLeft = false;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (mRight.IsNeeded() && mRight.mActive && !clippedRightMarker) {
|
|
|
|
if (clippedMarkerEdges.mAssignedRight &&
|
|
|
|
mContentArea.XMost() - clippedMarkerEdges.mRight > 0) {
|
|
|
|
mRight.mWidth = mContentArea.XMost() - clippedMarkerEdges.mRight;
|
|
|
|
NS_ASSERTION(mRight.mWidth < mRight.mIntrinsicWidth,
|
|
|
|
"clipping a marker should make it strictly smaller");
|
|
|
|
clippedRightMarker = true;
|
|
|
|
} else {
|
|
|
|
mRight.mActive = guessRight = false;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// The line simply has no visible content even without markers,
|
|
|
|
// so examine the line again without suppressing markers.
|
|
|
|
retryEmptyLine = false;
|
|
|
|
mLeft.mWidth = mLeft.mIntrinsicWidth;
|
|
|
|
mLeft.mActive = guessLeft = leftOverflow;
|
|
|
|
mRight.mWidth = mRight.mIntrinsicWidth;
|
|
|
|
mRight.mActive = guessRight = rightOverflow;
|
|
|
|
continue;
|
2011-06-22 11:11:48 -07:00
|
|
|
}
|
2011-12-19 06:48:31 -08:00
|
|
|
if (guessLeft == (mLeft.mActive && mLeft.IsNeeded()) &&
|
|
|
|
guessRight == (mRight.mActive && mRight.IsNeeded())) {
|
2011-06-22 11:11:48 -07:00
|
|
|
break;
|
|
|
|
} else {
|
2011-12-29 05:21:00 -08:00
|
|
|
guessLeft = mLeft.mActive && mLeft.IsNeeded();
|
|
|
|
guessRight = mRight.mActive && mRight.IsNeeded();
|
2011-06-22 11:11:48 -07:00
|
|
|
mLeft.Reset();
|
|
|
|
mRight.Reset();
|
|
|
|
aFramesToHide->Clear();
|
|
|
|
}
|
|
|
|
NS_ASSERTION(pass == 0, "2nd pass should never guess wrong");
|
|
|
|
} while (++pass != 2);
|
2011-12-19 06:48:31 -08:00
|
|
|
if (!leftOverflow || !mLeft.mActive) {
|
2011-12-19 06:48:30 -08:00
|
|
|
mLeft.Reset();
|
|
|
|
}
|
2011-12-19 06:48:31 -08:00
|
|
|
if (!rightOverflow || !mRight.mActive) {
|
2011-12-19 06:48:30 -08:00
|
|
|
mRight.Reset();
|
|
|
|
}
|
2011-06-22 11:11:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TextOverflow::ProcessLine(const nsDisplayListSet& aLists,
|
|
|
|
nsLineBox* aLine)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mLeft.mStyle->mType != NS_STYLE_TEXT_OVERFLOW_CLIP ||
|
|
|
|
mRight.mStyle->mType != NS_STYLE_TEXT_OVERFLOW_CLIP,
|
|
|
|
"TextOverflow with 'clip' for both sides");
|
|
|
|
mLeft.Reset();
|
2011-12-19 06:48:30 -08:00
|
|
|
mLeft.mActive = mLeft.mStyle->mType != NS_STYLE_TEXT_OVERFLOW_CLIP;
|
2011-06-22 11:11:48 -07:00
|
|
|
mRight.Reset();
|
2011-12-19 06:48:30 -08:00
|
|
|
mRight.mActive = mRight.mStyle->mType != NS_STYLE_TEXT_OVERFLOW_CLIP;
|
|
|
|
|
2013-09-02 01:41:57 -07:00
|
|
|
FrameHashtable framesToHide(100);
|
2011-06-22 11:11:48 -07:00
|
|
|
AlignmentEdges alignmentEdges;
|
|
|
|
ExamineLineFrames(aLine, &framesToHide, &alignmentEdges);
|
|
|
|
bool needLeft = mLeft.IsNeeded();
|
|
|
|
bool needRight = mRight.IsNeeded();
|
|
|
|
if (!needLeft && !needRight) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
NS_ASSERTION(mLeft.mStyle->mType != NS_STYLE_TEXT_OVERFLOW_CLIP ||
|
|
|
|
!needLeft, "left marker for 'clip'");
|
|
|
|
NS_ASSERTION(mRight.mStyle->mType != NS_STYLE_TEXT_OVERFLOW_CLIP ||
|
|
|
|
!needRight, "right marker for 'clip'");
|
|
|
|
|
|
|
|
// If there is insufficient space for both markers then keep the one on the
|
|
|
|
// end side per the block's 'direction'.
|
|
|
|
if (needLeft && needRight &&
|
|
|
|
mLeft.mWidth + mRight.mWidth > mContentArea.width) {
|
|
|
|
if (mBlockIsRTL) {
|
|
|
|
needRight = false;
|
|
|
|
} else {
|
|
|
|
needLeft = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nsRect insideMarkersArea = mContentArea;
|
|
|
|
if (needLeft) {
|
2011-12-19 06:48:30 -08:00
|
|
|
InflateLeft(&insideMarkersArea, -mLeft.mWidth);
|
2011-06-22 11:11:48 -07:00
|
|
|
}
|
|
|
|
if (needRight) {
|
2011-12-19 06:48:30 -08:00
|
|
|
InflateRight(&insideMarkersArea, -mRight.mWidth);
|
2011-06-22 11:11:48 -07:00
|
|
|
}
|
|
|
|
if (!mCanHaveHorizontalScrollbar && alignmentEdges.mAssigned) {
|
|
|
|
nsRect alignmentRect = nsRect(alignmentEdges.x, insideMarkersArea.y,
|
|
|
|
alignmentEdges.Width(), 1);
|
|
|
|
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 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < ArrayLength(lists); ++i) {
|
2011-06-22 11:11:48 -07:00
|
|
|
PruneDisplayListContents(lists[i], framesToHide, insideMarkersArea);
|
|
|
|
}
|
|
|
|
CreateMarkers(aLine, needLeft, needRight, insideMarkersArea);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TextOverflow::PruneDisplayListContents(nsDisplayList* aList,
|
|
|
|
const FrameHashtable& aFramesToHide,
|
|
|
|
const nsRect& aInsideMarkersArea)
|
|
|
|
{
|
|
|
|
nsDisplayList saved;
|
|
|
|
nsDisplayItem* item;
|
|
|
|
while ((item = aList->RemoveBottom())) {
|
2013-04-19 05:02:13 -07:00
|
|
|
nsIFrame* itemFrame = item->Frame();
|
2013-04-19 05:01:41 -07:00
|
|
|
if (IsFrameDescendantOfAny(itemFrame, aFramesToHide, mBlock)) {
|
2011-06-22 11:11:48 -07:00
|
|
|
item->~nsDisplayItem();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-11-02 05:59:03 -07:00
|
|
|
nsDisplayList* wrapper = item->GetSameCoordinateSystemChildren();
|
2011-06-22 11:11:48 -07:00
|
|
|
if (wrapper) {
|
|
|
|
if (!itemFrame || GetSelfOrNearestBlock(itemFrame) == mBlock) {
|
|
|
|
PruneDisplayListContents(wrapper, aFramesToHide, aInsideMarkersArea);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCharClipDisplayItem* charClip = itemFrame ?
|
2012-07-30 07:20:58 -07:00
|
|
|
nsCharClipDisplayItem::CheckCast(item) : nullptr;
|
2011-06-22 11:11:48 -07:00
|
|
|
if (charClip && GetSelfOrNearestBlock(itemFrame) == mBlock) {
|
|
|
|
nsRect rect = itemFrame->GetScrollableOverflowRect() +
|
|
|
|
itemFrame->GetOffsetTo(mBlock);
|
|
|
|
if (mLeft.IsNeeded() && rect.x < aInsideMarkersArea.x) {
|
2011-07-11 13:18:26 -07:00
|
|
|
nscoord left = aInsideMarkersArea.x - rect.x;
|
2012-10-26 06:32:10 -07:00
|
|
|
if (MOZ_UNLIKELY(left < 0)) {
|
2011-07-11 13:18:26 -07:00
|
|
|
item->~nsDisplayItem();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
charClip->mLeftEdge = left;
|
2011-06-22 11:11:48 -07:00
|
|
|
}
|
|
|
|
if (mRight.IsNeeded() && rect.XMost() > aInsideMarkersArea.XMost()) {
|
2011-07-11 13:18:26 -07:00
|
|
|
nscoord right = rect.XMost() - aInsideMarkersArea.XMost();
|
2012-10-26 06:32:10 -07:00
|
|
|
if (MOZ_UNLIKELY(right < 0)) {
|
2011-07-11 13:18:26 -07:00
|
|
|
item->~nsDisplayItem();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
charClip->mRightEdge = right;
|
2011-06-22 11:11:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
saved.AppendToTop(item);
|
|
|
|
}
|
|
|
|
aList->AppendToTop(&saved);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ bool
|
|
|
|
TextOverflow::CanHaveTextOverflow(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aBlockFrame)
|
|
|
|
{
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleTextReset* style = aBlockFrame->StyleTextReset();
|
2011-06-22 11:11:48 -07:00
|
|
|
// Nothing to do for text-overflow:clip or if 'overflow-x:visible'
|
|
|
|
// or if we're just building items for event processing.
|
2011-08-20 13:41:39 -07:00
|
|
|
if ((style->mTextOverflow.mLeft.mType == NS_STYLE_TEXT_OVERFLOW_CLIP &&
|
|
|
|
style->mTextOverflow.mRight.mType == NS_STYLE_TEXT_OVERFLOW_CLIP) ||
|
2011-06-22 11:11:48 -07:00
|
|
|
IsHorizontalOverflowVisible(aBlockFrame) ||
|
|
|
|
aBuilder->IsForEventDelivery()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-04-03 11:02:09 -07:00
|
|
|
// Skip ComboboxControlFrame because it would clip the drop-down arrow.
|
|
|
|
// Its anon block inherits 'text-overflow' and does what is expected.
|
|
|
|
if (aBlockFrame->GetType() == nsGkAtoms::comboboxControlFrame) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-06-22 11:11:48 -07:00
|
|
|
// Inhibit the markers if a descendant content owns the caret.
|
|
|
|
nsRefPtr<nsCaret> caret = aBlockFrame->PresContext()->PresShell()->GetCaret();
|
2011-09-28 23:19:26 -07:00
|
|
|
bool visible = false;
|
2011-06-22 11:11:48 -07:00
|
|
|
if (caret && NS_SUCCEEDED(caret->GetCaretVisible(&visible)) && visible) {
|
|
|
|
nsCOMPtr<nsISelection> domSelection = caret->GetCaretDOMSelection();
|
|
|
|
if (domSelection) {
|
|
|
|
nsCOMPtr<nsIDOMNode> node;
|
|
|
|
domSelection->GetFocusNode(getter_AddRefs(node));
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(node);
|
|
|
|
if (content && nsContentUtils::ContentIsDescendantOf(content,
|
|
|
|
aBlockFrame->GetContent())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TextOverflow::CreateMarkers(const nsLineBox* aLine,
|
|
|
|
bool aCreateLeft,
|
|
|
|
bool aCreateRight,
|
2012-07-22 23:08:20 -07:00
|
|
|
const nsRect& aInsideMarkersArea)
|
2011-06-22 11:11:48 -07:00
|
|
|
{
|
|
|
|
if (aCreateLeft) {
|
2013-04-04 04:36:45 -07:00
|
|
|
DisplayListClipState::AutoSaveRestore clipState(mBuilder);
|
2013-03-04 01:56:02 -08:00
|
|
|
|
2011-12-19 06:48:31 -08:00
|
|
|
nsRect markerRect = nsRect(aInsideMarkersArea.x - mLeft.mIntrinsicWidth,
|
2011-06-22 11:11:48 -07:00
|
|
|
aLine->mBounds.y,
|
2011-12-19 06:48:31 -08:00
|
|
|
mLeft.mIntrinsicWidth, aLine->mBounds.height);
|
2011-06-22 11:11:48 -07:00
|
|
|
markerRect += mBuilder->ToReferenceFrame(mBlock);
|
2013-04-04 04:36:45 -07:00
|
|
|
ClipMarker(mContentArea + mBuilder->ToReferenceFrame(mBlock),
|
|
|
|
markerRect, clipState);
|
2011-06-22 11:11:48 -07:00
|
|
|
nsDisplayItem* marker = new (mBuilder)
|
|
|
|
nsDisplayTextOverflowMarker(mBuilder, mBlock, markerRect,
|
2013-03-08 02:41:31 -08:00
|
|
|
aLine->GetAscent(), mLeft.mStyle, 0);
|
2012-07-22 23:08:20 -07:00
|
|
|
mMarkerList.AppendNewToTop(marker);
|
2011-06-22 11:11:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aCreateRight) {
|
2013-04-04 04:36:45 -07:00
|
|
|
DisplayListClipState::AutoSaveRestore clipState(mBuilder);
|
2013-03-04 01:56:02 -08:00
|
|
|
|
2011-06-22 11:11:48 -07:00
|
|
|
nsRect markerRect = nsRect(aInsideMarkersArea.XMost(),
|
|
|
|
aLine->mBounds.y,
|
2011-12-19 06:48:31 -08:00
|
|
|
mRight.mIntrinsicWidth, aLine->mBounds.height);
|
2011-06-22 11:11:48 -07:00
|
|
|
markerRect += mBuilder->ToReferenceFrame(mBlock);
|
2013-04-04 04:36:45 -07:00
|
|
|
ClipMarker(mContentArea + mBuilder->ToReferenceFrame(mBlock),
|
|
|
|
markerRect, clipState);
|
2011-06-22 11:11:48 -07:00
|
|
|
nsDisplayItem* marker = new (mBuilder)
|
|
|
|
nsDisplayTextOverflowMarker(mBuilder, mBlock, markerRect,
|
2013-03-08 02:41:31 -08:00
|
|
|
aLine->GetAscent(), mRight.mStyle, 1);
|
2012-07-22 23:08:20 -07:00
|
|
|
mMarkerList.AppendNewToTop(marker);
|
2011-06-22 11:11:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TextOverflow::Marker::SetupString(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (mInitialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-08 02:41:31 -08:00
|
|
|
if (mStyle->mType == NS_STYLE_TEXT_OVERFLOW_ELLIPSIS) {
|
|
|
|
gfxTextRun* textRun = GetEllipsisTextRun(aFrame);
|
|
|
|
if (textRun) {
|
|
|
|
mWidth = textRun->GetAdvanceWidth(0, textRun->GetLength(), nullptr);
|
|
|
|
} else {
|
|
|
|
mWidth = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nsRefPtr<nsRenderingContext> rc =
|
2014-04-14 21:30:25 -07:00
|
|
|
aFrame->PresContext()->PresShell()->CreateReferenceRenderingContext();
|
2013-03-08 02:41:31 -08:00
|
|
|
nsRefPtr<nsFontMetrics> fm;
|
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(aFrame, getter_AddRefs(fm),
|
|
|
|
nsLayoutUtils::FontSizeInflationFor(aFrame));
|
|
|
|
rc->SetFont(fm);
|
|
|
|
mWidth = nsLayoutUtils::GetStringWidth(aFrame, rc, mStyle->mString.get(),
|
|
|
|
mStyle->mString.Length());
|
|
|
|
}
|
2011-12-19 06:48:31 -08:00
|
|
|
mIntrinsicWidth = mWidth;
|
2011-06-22 11:11:48 -07:00
|
|
|
mInitialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace css
|
|
|
|
} // namespace mozilla
|