import from UXP: Issue #2104 - Part 1: Implement "clip" attribute value for XUL string cropping (60c344a5)

This commit is contained in:
2023-02-08 17:36:20 +08:00
parent 18b9607846
commit 729323e8d9
2 changed files with 10 additions and 3 deletions
+9 -2
View File
@@ -233,7 +233,8 @@ nsTextBoxFrame::UpdateAttributes(nsIAtom* aAttribute,
if (aAttribute == nullptr || aAttribute == nsGkAtoms::crop) {
static nsIContent::AttrValuesArray strings[] =
{&nsGkAtoms::left, &nsGkAtoms::start, &nsGkAtoms::center,
&nsGkAtoms::right, &nsGkAtoms::end, &nsGkAtoms::none, nullptr};
&nsGkAtoms::right, &nsGkAtoms::end, &nsGkAtoms::none,
&nsGkAtoms::clip, nullptr};
CroppingStyle cropType;
switch (mContent->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::crop,
strings, eCaseMatters)) {
@@ -251,6 +252,9 @@ nsTextBoxFrame::UpdateAttributes(nsIAtom* aAttribute,
case 5:
cropType = CropNone;
break;
case 6:
cropType = CropClip;
break;
default:
cropType = CropAuto;
break;
@@ -650,7 +654,9 @@ nsTextBoxFrame::CalculateTitleForWidth(nsRenderingContext& aRenderingContext,
}
const nsDependentString& kEllipsis = nsContentUtils::GetLocalizedEllipsis();
if (mCropType != CropNone) {
if (mCropType == CropClip) {
mCroppedTitle.Truncate();
} else if (mCropType != CropNone) {
// start with an ellipsis
mCroppedTitle.Assign(kEllipsis);
@@ -684,6 +690,7 @@ nsTextBoxFrame::CalculateTitleForWidth(nsRenderingContext& aRenderingContext,
case CropAuto:
case CropNone:
case CropRight:
case CropClip:
{
ClusterIterator iter(mTitle.Data(), mTitle.Length());
const char16_t* dataBegin = iter;
+1 -1
View File
@@ -25,7 +25,7 @@ public:
NS_IMETHOD DoXULLayout(nsBoxLayoutState& aBoxLayoutState) override;
virtual void MarkIntrinsicISizesDirty() override;
enum CroppingStyle { CropNone, CropLeft, CropRight, CropCenter, CropAuto };
enum CroppingStyle { CropNone, CropLeft, CropRight, CropCenter, CropClip, CropAuto };
friend nsIFrame* NS_NewTextBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);