Bug 1553252 - Use cbindgen for text-overflow r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D32285

--HG--
extra : moz-landing-system : lando
This commit is contained in:
violet 2019-05-23 14:02:17 +00:00
Родитель f2f3601226
Коммит 4ab5380719
11 изменённых файлов: 56 добавлений и 178 удалений

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

@ -152,7 +152,7 @@ class nsDisplayTextOverflowMarker final : public nsPaintedDisplayItem {
public:
nsDisplayTextOverflowMarker(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame,
const nsRect& aRect, nscoord aAscent,
nsStyleTextOverflowSide aStyle,
const StyleTextOverflowSide& aStyle,
uint32_t aLineNumber, uint16_t aIndex)
: nsPaintedDisplayItem(aBuilder, aFrame),
mRect(aRect),
@ -203,7 +203,7 @@ class nsDisplayTextOverflowMarker final : public nsPaintedDisplayItem {
NS_DISPLAY_DECL_NAME("TextOverflow", TYPE_TEXT_OVERFLOW)
private:
nsRect mRect; // in reference frame coordinates
const nsStyleTextOverflowSide mStyle;
const StyleTextOverflowSide mStyle;
nscoord mAscent; // baseline for the marker text in mRect
uint16_t mIndex;
};
@ -248,7 +248,7 @@ void nsDisplayTextOverflowMarker::PaintTextToContext(gfxContext* aCtx,
}
pt += aOffsetFromRect;
if (mStyle.mType == NS_STYLE_TEXT_OVERFLOW_ELLIPSIS) {
if (mStyle.IsEllipsis()) {
gfxTextRun* textRun = GetEllipsisTextRun(mFrame);
if (textRun) {
NS_ASSERTION(!textRun->IsRightToLeft(),
@ -260,8 +260,9 @@ void nsDisplayTextOverflowMarker::PaintTextToContext(gfxContext* aCtx,
} else {
RefPtr<nsFontMetrics> fm =
nsLayoutUtils::GetInflatedFontMetricsForFrame(mFrame);
nsLayoutUtils::DrawString(mFrame, *fm, aCtx, mStyle.mString.get(),
mStyle.mString.Length(), pt);
NS_ConvertUTF8toUTF16 str16{mStyle.AsString().AsString()};
nsLayoutUtils::DrawString(mFrame, *fm, aCtx, str16.get(), str16.Length(),
pt);
}
}
@ -330,12 +331,21 @@ TextOverflow::TextOverflow(nsDisplayListBuilder* aBuilder,
}
uint8_t direction = aBlockFrame->StyleVisibility()->mDirection;
const nsStyleTextReset* style = aBlockFrame->StyleTextReset();
const auto& textOverflow = style->mTextOverflow;
bool shouldToggleDirection =
textOverflow.sides_are_logical && (direction == NS_STYLE_DIRECTION_RTL);
const auto& leftSide =
shouldToggleDirection ? textOverflow.second : textOverflow.first;
const auto& rightSide =
shouldToggleDirection ? textOverflow.first : textOverflow.second;
if (mBlockWM.IsBidiLTR()) {
mIStart.Init(style->mTextOverflow.GetLeft(direction));
mIEnd.Init(style->mTextOverflow.GetRight(direction));
mIStart.Init(leftSide);
mIEnd.Init(rightSide);
} else {
mIStart.Init(style->mTextOverflow.GetRight(direction));
mIEnd.Init(style->mTextOverflow.GetLeft(direction));
mIStart.Init(rightSide);
mIEnd.Init(leftSide);
}
// The left/right marker string is setup in ExamineLineFrames when a line
// has overflow on that side.
@ -692,18 +702,16 @@ LogicalRect TextOverflow::ExamineLineFrames(nsLineBox* aLine,
void TextOverflow::ProcessLine(const nsDisplayListSet& aLists, nsLineBox* aLine,
uint32_t aLineNumber) {
if (mIStart.mStyle->mType == NS_STYLE_TEXT_OVERFLOW_CLIP &&
mIEnd.mStyle->mType == NS_STYLE_TEXT_OVERFLOW_CLIP &&
if (mIStart.mStyle->IsClip() && mIEnd.mStyle->IsClip() &&
!aLine->HasLineClampEllipsis()) {
return;
}
mIStart.Reset();
mIStart.mActive = mIStart.mStyle->mType != NS_STYLE_TEXT_OVERFLOW_CLIP;
mIStart.mActive = !mIStart.mStyle->IsClip();
mIEnd.Reset();
mIEnd.mHasBlockEllipsis = aLine->HasLineClampEllipsis();
mIEnd.mActive = mIEnd.mStyle->mType != NS_STYLE_TEXT_OVERFLOW_CLIP ||
aLine->HasLineClampEllipsis();
mIEnd.mActive = !mIEnd.mStyle->IsClip() || aLine->HasLineClampEllipsis();
FrameHashtable framesToHide(64);
AlignmentEdges alignmentEdges;
@ -816,8 +824,8 @@ void TextOverflow::PruneDisplayListContents(
/* static */
bool TextOverflow::HasClippedTextOverflow(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;
return style->mTextOverflow.first.IsClip() &&
style->mTextOverflow.second.IsClip();
}
/* static */
@ -896,7 +904,7 @@ void TextOverflow::CreateMarkers(const nsLineBox* aLine, bool aCreateIStart,
markerRect, clipState);
mMarkerList.AppendNewToTop<nsDisplayTextOverflowMarker>(
mBuilder, mBlock, markerRect, aLine->GetLogicalAscent(),
mIEnd.mHasBlockEllipsis ? nsStyleTextOverflowSide::Ellipsis()
mIEnd.mHasBlockEllipsis ? StyleTextOverflowSide::Ellipsis()
: *mIEnd.mStyle,
aLineNumber, 1);
}
@ -912,8 +920,7 @@ void TextOverflow::Marker::SetupString(nsIFrame* aFrame) {
// don't track the block ellipsis string and the text-overflow marker string
// separately, if both apply to the element, we will always use "…" as the
// string for text-overflow.
if (HasBlockEllipsis(aFrame) ||
mStyle->mType == NS_STYLE_TEXT_OVERFLOW_ELLIPSIS) {
if (HasBlockEllipsis(aFrame) || mStyle->IsEllipsis()) {
gfxTextRun* textRun = GetEllipsisTextRun(aFrame);
if (textRun) {
mISize = textRun->GetAdvanceWidth();
@ -925,8 +932,8 @@ void TextOverflow::Marker::SetupString(nsIFrame* aFrame) {
aFrame->PresShell()->CreateReferenceRenderingContext();
RefPtr<nsFontMetrics> fm =
nsLayoutUtils::GetInflatedFontMetricsForFrame(aFrame);
mISize = nsLayoutUtils::AppUnitWidthOfStringBidi(mStyle->mString, aFrame,
*fm, *rc);
mISize = nsLayoutUtils::AppUnitWidthOfStringBidi(
NS_ConvertUTF8toUTF16(mStyle->AsString().AsString()), aFrame, *fm, *rc);
}
mIntrinsicISize = mISize;
mInitialized = true;

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

@ -250,7 +250,7 @@ class TextOverflow final {
class Marker {
public:
void Init(const nsStyleTextOverflowSide& aStyle) {
void Init(const StyleTextOverflowSide& aStyle) {
mInitialized = false;
mISize = 0;
mStyle = &aStyle;
@ -267,7 +267,7 @@ class TextOverflow final {
void SetupString(nsIFrame* aFrame);
bool IsSuppressed() const {
return !mHasBlockEllipsis && mStyle->mType == NS_STYLE_TEXT_OVERFLOW_CLIP;
return !mHasBlockEllipsis && mStyle->IsClip();
}
bool IsNeeded() const { return mHasOverflow || mHasBlockEllipsis; }
void Reset() {
@ -282,7 +282,7 @@ class TextOverflow final {
nscoord mIntrinsicISize;
// The text-overflow style for this side. Ignored if we're rendering a
// block ellipsis.
const nsStyleTextOverflowSide* mStyle;
const StyleTextOverflowSide* mStyle;
// True if there is visible overflowing inline content on this side.
bool mHasOverflow;
// True if this side has a block ellipsis (from -webkit-line-clamp).

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

@ -427,6 +427,7 @@ cbindgen-types = [
{ gecko = "StyleFloat", servo = "values::computed::Float" },
{ gecko = "StyleOverscrollBehavior", servo = "values::computed::OverscrollBehavior" },
{ gecko = "StyleTextAlign", servo = "values::computed::TextAlign" },
{ gecko = "StyleTextOverflow", servo = "values::computed::TextOverflow" },
{ gecko = "StyleOverflow", servo = "values::computed::Overflow" },
{ gecko = "StyleOverflowAnchor", servo = "values::computed::OverflowAnchor" },
{ gecko = "StyleLength", servo = "values::computed::CSSPixelLength" },

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

@ -376,11 +376,6 @@ const KTableEntry nsCSSProps::kTextEmphasisStyleShapeKTable[] = {
{eCSSKeyword_sesame, NS_STYLE_TEXT_EMPHASIS_STYLE_SESAME},
{eCSSKeyword_UNKNOWN, -1}};
const KTableEntry nsCSSProps::kTextOverflowKTable[] = {
{eCSSKeyword_clip, NS_STYLE_TEXT_OVERFLOW_CLIP},
{eCSSKeyword_ellipsis, NS_STYLE_TEXT_OVERFLOW_ELLIPSIS},
{eCSSKeyword_UNKNOWN, -1}};
// keyword tables for SVG properties
const KTableEntry nsCSSProps::kFilterFunctionKTable[] = {

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

@ -310,7 +310,6 @@ class nsCSSProps {
static const KTableEntry kTextAlignKTable[];
static const KTableEntry kTextDecorationStyleKTable[];
static const KTableEntry kTextEmphasisStyleShapeKTable[];
static const KTableEntry kTextOverflowKTable[];
};
// MOZ_DBG support for nsCSSPropertyID

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

@ -551,11 +551,6 @@ enum class StyleGridTrackBreadth : uint8_t {
#define NS_STYLE_TEXT_DECORATION_STYLE_WAVY 5
#define NS_STYLE_TEXT_DECORATION_STYLE_MAX NS_STYLE_TEXT_DECORATION_STYLE_WAVY
// See nsStyleTextOverflow
#define NS_STYLE_TEXT_OVERFLOW_CLIP 0
#define NS_STYLE_TEXT_OVERFLOW_ELLIPSIS 1
#define NS_STYLE_TEXT_OVERFLOW_STRING 2
// See nsStyleText
#define NS_STYLE_TEXT_TRANSFORM_NONE 0
#define NS_STYLE_TEXT_TRANSFORM_CAPITALIZE 1

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

@ -1247,69 +1247,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStylePosition {
}
};
struct nsStyleTextOverflowSide {
nsStyleTextOverflowSide() : mType(NS_STYLE_TEXT_OVERFLOW_CLIP) {}
static nsStyleTextOverflowSide Ellipsis() {
nsStyleTextOverflowSide side;
side.mType = NS_STYLE_TEXT_OVERFLOW_ELLIPSIS;
return side;
}
bool operator==(const nsStyleTextOverflowSide& aOther) const {
return mType == aOther.mType && (mType != NS_STYLE_TEXT_OVERFLOW_STRING ||
mString == aOther.mString);
}
bool operator!=(const nsStyleTextOverflowSide& aOther) const {
return !(*this == aOther);
}
nsString mString;
uint8_t mType;
};
struct nsStyleTextOverflow {
nsStyleTextOverflow() : mLogicalDirections(true) {}
bool operator==(const nsStyleTextOverflow& aOther) const {
return mLeft == aOther.mLeft && mRight == aOther.mRight;
}
bool operator!=(const nsStyleTextOverflow& aOther) const {
return !(*this == aOther);
}
// Returns the value to apply on the left side.
const nsStyleTextOverflowSide& GetLeft(uint8_t aDirection) const {
NS_ASSERTION(aDirection == NS_STYLE_DIRECTION_LTR ||
aDirection == NS_STYLE_DIRECTION_RTL,
"bad direction");
return !mLogicalDirections || aDirection == NS_STYLE_DIRECTION_LTR ? mLeft
: mRight;
}
// Returns the value to apply on the right side.
const nsStyleTextOverflowSide& GetRight(uint8_t aDirection) const {
NS_ASSERTION(aDirection == NS_STYLE_DIRECTION_LTR ||
aDirection == NS_STYLE_DIRECTION_RTL,
"bad direction");
return !mLogicalDirections || aDirection == NS_STYLE_DIRECTION_LTR ? mRight
: mLeft;
}
// Returns the first value that was specified.
const nsStyleTextOverflowSide* GetFirstValue() const {
return mLogicalDirections ? &mRight : &mLeft;
}
// Returns the second value, or null if there was only one value specified.
const nsStyleTextOverflowSide* GetSecondValue() const {
return mLogicalDirections ? nullptr : &mRight;
}
nsStyleTextOverflowSide mLeft; // start side when mLogicalDirections is true
nsStyleTextOverflowSide mRight; // end side when mLogicalDirections is true
bool mLogicalDirections; // true when only one value was specified
};
struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleTextReset {
explicit nsStyleTextReset(const mozilla::dom::Document&);
nsStyleTextReset(const nsStyleTextReset& aOther);
@ -1327,7 +1264,7 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleTextReset {
nsChangeHint CalcDifference(const nsStyleTextReset& aNewData) const;
nsStyleTextOverflow mTextOverflow; // enum, string
mozilla::StyleTextOverflow mTextOverflow;
mozilla::StyleTextDecorationLine mTextDecorationLine;
uint8_t mTextDecorationStyle; // NS_STYLE_TEXT_DECORATION_STYLE_*

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

@ -3342,83 +3342,7 @@ fn static_assert() {
</%self:impl_trait>
<%self:impl_trait style_struct_name="Text"
skip_longhands="text-overflow initial-letter">
fn clear_overflow_sides_if_string(&mut self) {
use crate::gecko_bindings::structs::nsStyleTextOverflowSide;
fn clear_if_string(side: &mut nsStyleTextOverflowSide) {
if side.mType == structs::NS_STYLE_TEXT_OVERFLOW_STRING as u8 {
side.mString.truncate();
side.mType = structs::NS_STYLE_TEXT_OVERFLOW_CLIP as u8;
}
}
clear_if_string(&mut self.gecko.mTextOverflow.mLeft);
clear_if_string(&mut self.gecko.mTextOverflow.mRight);
}
pub fn set_text_overflow(&mut self, v: longhands::text_overflow::computed_value::T) {
use crate::gecko_bindings::structs::nsStyleTextOverflowSide;
use crate::values::specified::text::TextOverflowSide;
fn set(side: &mut nsStyleTextOverflowSide, value: &TextOverflowSide) {
let ty = match *value {
TextOverflowSide::Clip => structs::NS_STYLE_TEXT_OVERFLOW_CLIP,
TextOverflowSide::Ellipsis => structs::NS_STYLE_TEXT_OVERFLOW_ELLIPSIS,
TextOverflowSide::String(ref s) => {
side.mString.assign_str(s);
structs::NS_STYLE_TEXT_OVERFLOW_STRING
}
};
side.mType = ty as u8;
}
self.clear_overflow_sides_if_string();
self.gecko.mTextOverflow.mLogicalDirections = v.sides_are_logical;
set(&mut self.gecko.mTextOverflow.mLeft, &v.first);
set(&mut self.gecko.mTextOverflow.mRight, &v.second);
}
pub fn copy_text_overflow_from(&mut self, other: &Self) {
use crate::gecko_bindings::structs::nsStyleTextOverflowSide;
fn set(side: &mut nsStyleTextOverflowSide, other: &nsStyleTextOverflowSide) {
if other.mType == structs::NS_STYLE_TEXT_OVERFLOW_STRING as u8 {
side.mString.assign(&*other.mString)
}
side.mType = other.mType
}
self.clear_overflow_sides_if_string();
set(&mut self.gecko.mTextOverflow.mLeft, &other.gecko.mTextOverflow.mLeft);
set(&mut self.gecko.mTextOverflow.mRight, &other.gecko.mTextOverflow.mRight);
self.gecko.mTextOverflow.mLogicalDirections = other.gecko.mTextOverflow.mLogicalDirections;
}
pub fn reset_text_overflow(&mut self, other: &Self) {
self.copy_text_overflow_from(other)
}
pub fn clone_text_overflow(&self) -> longhands::text_overflow::computed_value::T {
use crate::gecko_bindings::structs::nsStyleTextOverflowSide;
use crate::values::specified::text::TextOverflowSide;
fn to_servo(side: &nsStyleTextOverflowSide) -> TextOverflowSide {
match side.mType as u32 {
structs::NS_STYLE_TEXT_OVERFLOW_CLIP => TextOverflowSide::Clip,
structs::NS_STYLE_TEXT_OVERFLOW_ELLIPSIS => TextOverflowSide::Ellipsis,
structs::NS_STYLE_TEXT_OVERFLOW_STRING =>
TextOverflowSide::String(side.mString.to_string().into_boxed_str()),
_ => panic!("Found unexpected value in style struct for text_overflow property"),
}
}
longhands::text_overflow::computed_value::T {
first: to_servo(&self.gecko.mTextOverflow.mLeft),
second: to_servo(&self.gecko.mTextOverflow.mRight),
sides_are_logical: self.gecko.mTextOverflow.mLogicalDirections
}
}
<%self:impl_trait style_struct_name="Text" skip_longhands="initial-letter">
pub fn set_initial_letter(&mut self, v: longhands::initial_letter::computed_value::T) {
use crate::values::generics::text::InitialLetter;
match v {

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

@ -105,6 +105,7 @@ impl ToComputedValue for specified::WordSpacing {
pub type LineHeight = GenericLineHeight<NonNegativeNumber, NonNegativeLength>;
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToResolvedValue)]
#[repr(C)]
/// text-overflow.
/// When the specified value only has one side, that's the "second"
/// side, and the sides are logical, so "second" means "end". The

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

@ -134,14 +134,16 @@ impl ToComputedValue for LineHeight {
}
/// A generic value for the `text-overflow` property.
/// cbindgen:derive-tagged-enum-copy-constructor=true
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)]
#[repr(C, u8)]
pub enum TextOverflowSide {
/// Clip inline content.
Clip,
/// Render ellipsis to represent clipped inline content.
Ellipsis,
/// Render a given string to represent clipped inline content.
String(Box<str>),
String(crate::OwnedStr),
}
impl Parse for TextOverflowSide {
@ -161,7 +163,7 @@ impl Parse for TextOverflowSide {
}
},
Token::QuotedString(ref v) => Ok(TextOverflowSide::String(
v.as_ref().to_owned().into_boxed_str(),
v.as_ref().to_owned().into(),
)),
ref t => Err(location.new_unexpected_token_error(t.clone())),
}

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

@ -114,6 +114,7 @@ include = [
"WillChange",
"TextDecorationLine",
"TextTransform",
"TextOverflow",
"MozListReversed",
"Owned",
"OwnedOrNull",
@ -452,3 +453,19 @@ renaming_overrides_prefixing = true
StyleOffsetPath() {}
public:
"""
"TextOverflowSide" = """
private:
// Private default constructor without initialization so that the helper
// constructor functions still work as expected. They take care of
// initializing the fields properly.
StyleTextOverflowSide() {}
public:
"""
"TextOverflow" = """
StyleTextOverflow()
: first(StyleTextOverflowSide::Clip()),
second(StyleTextOverflowSide::Clip()),
sides_are_logical(true) {}
"""