From b8ea09a2212cb24bd89467f87ecbd1c0f43f6bb3 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Mon, 3 Apr 2017 12:39:51 +0200 Subject: [PATCH] Bug 1117227 part 5 - Render ellipsis in correct orientation. --- gfx/thebes/gfxTextRun.cpp | 7 +++++-- gfx/thebes/gfxTextRun.h | 8 ++++---- layout/base/nsLayoutUtils.cpp | 26 +++++++++++++------------- layout/base/nsLayoutUtils.h | 5 +++++ layout/generic/TextOverflow.cpp | 4 +++- 5 files changed, 30 insertions(+), 20 deletions(-) diff --git a/gfx/thebes/gfxTextRun.cpp b/gfx/thebes/gfxTextRun.cpp index f5ba248bd2..e68cc4a5e0 100644 --- a/gfx/thebes/gfxTextRun.cpp +++ b/gfx/thebes/gfxTextRun.cpp @@ -2542,10 +2542,13 @@ gfxFontGroup::InitScriptRun(gfxContext *aContext, } gfxTextRun * -gfxFontGroup::GetEllipsisTextRun(int32_t aAppUnitsPerDevPixel, +gfxFontGroup::GetEllipsisTextRun(int32_t aAppUnitsPerDevPixel, uint32_t aFlags, LazyReferenceContextGetter& aRefContextGetter) { + MOZ_ASSERT(!(aFlags & ~TEXT_ORIENT_MASK), + "flags here should only be used to specify orientation"); if (mCachedEllipsisTextRun && + (mCachedEllipsisTextRun->GetFlags() & TEXT_ORIENT_MASK) == aFlags && mCachedEllipsisTextRun->GetAppUnitsPerDevUnit() == aAppUnitsPerDevPixel) { return mCachedEllipsisTextRun; } @@ -2565,7 +2568,7 @@ gfxFontGroup::GetEllipsisTextRun(int32_t aAppUnitsPerDevPixel, }; gfxTextRun* textRun = MakeTextRun(ellipsis.get(), ellipsis.Length(), ¶ms, - TEXT_IS_PERSISTENT, nullptr); + aFlags | TEXT_IS_PERSISTENT, nullptr); if (!textRun) { return nullptr; } diff --git a/gfx/thebes/gfxTextRun.h b/gfx/thebes/gfxTextRun.h index 15b3b9dea9..29ffb9d8c7 100644 --- a/gfx/thebes/gfxTextRun.h +++ b/gfx/thebes/gfxTextRun.h @@ -885,10 +885,10 @@ public: }; // The gfxFontGroup keeps ownership of this textrun. // It is only guaranteed to exist until the next call to GetEllipsisTextRun - // (which might use a different appUnitsPerDev value) for the font group, - // or until UpdateUserFonts is called, or the fontgroup is destroyed. + // (which might use a different appUnitsPerDev value or flags) for the font + // group, or until UpdateUserFonts is called, or the fontgroup is destroyed. // Get it/use it/forget it :) - don't keep a reference that might go stale. - gfxTextRun* GetEllipsisTextRun(int32_t aAppUnitsPerDevPixel, + gfxTextRun* GetEllipsisTextRun(int32_t aAppUnitsPerDevPixel, uint32_t aFlags, LazyReferenceContextGetter& aRefContextGetter); // helper method for resolving generic font families @@ -1047,7 +1047,7 @@ protected: gfxTextPerfMetrics *mTextPerf; // Cache a textrun representing an ellipsis (useful for CSS text-overflow) - // at a specific appUnitsPerDevPixel size + // at a specific appUnitsPerDevPixel size and orientation nsAutoPtr mCachedEllipsisTextRun; // cache the most recent pref font to avoid general pref font lookup diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index b719c0acb2..4bffe0a758 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -6412,42 +6412,42 @@ nsLayoutUtils::GetTextRunFlagsForStyle(nsStyleContext* aStyleContext, default: break; } + return result | GetTextRunOrientFlagsForStyle(aStyleContext); +} + +/* static */ uint32_t +nsLayoutUtils::GetTextRunOrientFlagsForStyle(nsStyleContext* aStyleContext) +{ WritingMode wm(aStyleContext); if (wm.IsVertical()) { switch (aStyleContext->StyleVisibility()->mTextOrientation) { case NS_STYLE_TEXT_ORIENTATION_MIXED: - result |= gfxTextRunFactory::TEXT_ORIENT_VERTICAL_MIXED; - break; + return gfxTextRunFactory::TEXT_ORIENT_VERTICAL_MIXED; case NS_STYLE_TEXT_ORIENTATION_UPRIGHT: - result |= gfxTextRunFactory::TEXT_ORIENT_VERTICAL_UPRIGHT; - break; + return gfxTextRunFactory::TEXT_ORIENT_VERTICAL_UPRIGHT; case NS_STYLE_TEXT_ORIENTATION_SIDEWAYS: // This should depend on writing mode vertical-lr vs vertical-rl, // but until we support SIDEWAYS_LEFT, we'll treat this the same // as SIDEWAYS_RIGHT and simply fall through. /* if (wm.IsVerticalLR()) { - result |= gfxTextRunFactory::TEXT_ORIENT_VERTICAL_SIDEWAYS_LEFT; + return gfxTextRunFactory::TEXT_ORIENT_VERTICAL_SIDEWAYS_LEFT; } else { - result |= gfxTextRunFactory::TEXT_ORIENT_VERTICAL_SIDEWAYS_RIGHT; + return gfxTextRunFactory::TEXT_ORIENT_VERTICAL_SIDEWAYS_RIGHT; } - break; */ case NS_STYLE_TEXT_ORIENTATION_SIDEWAYS_RIGHT: - result |= gfxTextRunFactory::TEXT_ORIENT_VERTICAL_SIDEWAYS_RIGHT; - break; + return gfxTextRunFactory::TEXT_ORIENT_VERTICAL_SIDEWAYS_RIGHT; case NS_STYLE_TEXT_ORIENTATION_SIDEWAYS_LEFT: // Not yet supported, so fall through to the default (error) case. /* - result |= gfxTextRunFactory::TEXT_ORIENT_VERTICAL_SIDEWAYS_LEFT; - break; + return gfxTextRunFactory::TEXT_ORIENT_VERTICAL_SIDEWAYS_LEFT; */ default: NS_NOTREACHED("unknown text-orientation"); - break; } } - return result; + return 0; } /* static */ void diff --git a/layout/base/nsLayoutUtils.h b/layout/base/nsLayoutUtils.h index 282b67d1a7..20248abb61 100644 --- a/layout/base/nsLayoutUtils.h +++ b/layout/base/nsLayoutUtils.h @@ -1933,6 +1933,11 @@ public: const nsStyleText* aStyleText, nscoord aLetterSpacing); + /** + * Get orientation flags for textrun construction. + */ + static uint32_t GetTextRunOrientFlagsForStyle(nsStyleContext* aStyleContext); + /** * Takes two rectangles whose origins must be the same, and computes * the difference between their union and their intersection as two diff --git a/layout/generic/TextOverflow.cpp b/layout/generic/TextOverflow.cpp index 8487edd6b5..910d48f6e0 100644 --- a/layout/generic/TextOverflow.cpp +++ b/layout/generic/TextOverflow.cpp @@ -49,7 +49,9 @@ GetEllipsisTextRun(nsIFrame* aFrame) nsLayoutUtils::FontSizeInflationFor(aFrame)); LazyReferenceRenderingContextGetterFromFrame lazyRefContextGetter(aFrame); return fm->GetThebesFontGroup()->GetEllipsisTextRun( - aFrame->PresContext()->AppUnitsPerDevPixel(), lazyRefContextGetter); + aFrame->PresContext()->AppUnitsPerDevPixel(), + nsLayoutUtils::GetTextRunOrientFlagsForStyle(aFrame->StyleContext()), + lazyRefContextGetter); } static nsIFrame*