Bug 1213895: Part 1 - Correctly support crop="none" in XUL labels. r=neil
authorKris Maglione <maglione.k@gmail.com>
Wed, 10 Feb 2016 20:12:00 -0800
changeset 321303 62cc4b503870cf7be4ae0c530a3d7ab99c8585b9
parent 321302 ba617d51a0fdc41e619302fd750376aeaabf86ad
child 321304 48a7a7615da812d4adca2d9aa4e9a10ac259bebc
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersneil
bugs1213895
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1213895: Part 1 - Correctly support crop="none" in XUL labels. r=neil MozReview-Commit-ID: 9OiVjcJy99g
layout/xul/nsTextBoxFrame.cpp
layout/xul/nsTextBoxFrame.h
--- a/layout/xul/nsTextBoxFrame.cpp
+++ b/layout/xul/nsTextBoxFrame.cpp
@@ -223,33 +223,36 @@ nsTextBoxFrame::UpdateAttributes(nsIAtom
 {
     bool doUpdateTitle = false;
     aResize = false;
     aRedraw = false;
 
     if (aAttribute == nullptr || aAttribute == nsGkAtoms::crop) {
         static nsIContent::AttrValuesArray strings[] =
           {&nsGkAtoms::left, &nsGkAtoms::start, &nsGkAtoms::center,
-           &nsGkAtoms::right, &nsGkAtoms::end, nullptr};
+           &nsGkAtoms::right, &nsGkAtoms::end, &nsGkAtoms::none, nullptr};
         CroppingStyle cropType;
         switch (mContent->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::crop,
                                           strings, eCaseMatters)) {
           case 0:
           case 1:
             cropType = CropLeft;
             break;
           case 2:
             cropType = CropCenter;
             break;
           case 3:
           case 4:
             cropType = CropRight;
             break;
+          case 5:
+            cropType = CropNone;
+            break;
           default:
-            cropType = CropNone;
+            cropType = CropAuto;
             break;
         }
 
         if (cropType != mCropType) {
             aResize = true;
             mCropType = cropType;
         }
     }
@@ -642,41 +645,47 @@ nsTextBoxFrame::CalculateTitleForWidth(n
         if (HasRTLChars(mTitle) ||
             StyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL) {
             mState |= NS_FRAME_IS_BIDI;
         }
         return titleWidth;  // fits, done.
     }
 
     const nsDependentString& kEllipsis = nsContentUtils::GetLocalizedEllipsis();
-    // start with an ellipsis
-    mCroppedTitle.Assign(kEllipsis);
+    if (mCropType != CropNone) {
+      // start with an ellipsis
+      mCroppedTitle.Assign(kEllipsis);
 
-    // see if the width is even smaller than the ellipsis
-    // if so, clear the text (XXX set as many '.' as we can?).
-    fm->SetTextRunRTL(false);
-    titleWidth = nsLayoutUtils::AppUnitWidthOfString(kEllipsis, *fm,
-                                                     drawTarget);
+      // see if the width is even smaller than the ellipsis
+      // if so, clear the text (XXX set as many '.' as we can?).
+      fm->SetTextRunRTL(false);
+      titleWidth = nsLayoutUtils::AppUnitWidthOfString(kEllipsis, *fm,
+                                                       drawTarget);
 
-    if (titleWidth > aWidth) {
-        mCroppedTitle.SetLength(0);
-        return 0;
-    }
+      if (titleWidth > aWidth) {
+          mCroppedTitle.SetLength(0);
+          return 0;
+      }
 
-    // if the ellipsis fits perfectly, no use in trying to insert
-    if (titleWidth == aWidth)
-        return titleWidth;
+      // if the ellipsis fits perfectly, no use in trying to insert
+      if (titleWidth == aWidth)
+          return titleWidth;
 
-    aWidth -= titleWidth;
+      aWidth -= titleWidth;
+    } else {
+      mCroppedTitle.Truncate(0);
+      titleWidth = 0;
+    }
 
     // XXX: This whole block should probably take surrogates into account
     // XXX and clusters!
     // ok crop things
     switch (mCropType)
     {
+        case CropAuto:
         case CropNone:
         case CropRight:
         {
             nscoord cwidth;
             nscoord twidth = 0;
             int length = mTitle.Length();
             int i;
             for (i = 0; i < length; ++i) {
@@ -1121,17 +1130,17 @@ nsSize
 nsTextBoxFrame::GetMinSize(nsBoxLayoutState& aBoxLayoutState)
 {
     CalcTextSize(aBoxLayoutState);
 
     nsSize size = mTextSize;
     DISPLAY_MIN_SIZE(this, size);
 
     // if there is cropping our min width becomes our border and padding
-    if (mCropType != CropNone) {
+    if (mCropType != CropNone && mCropType != CropAuto) {
         if (GetWritingMode().IsVertical()) {
             size.height = 0;
         } else {
             size.width = 0;
         }
     }
 
     AddBorderAndPadding(size);
--- a/layout/xul/nsTextBoxFrame.h
+++ b/layout/xul/nsTextBoxFrame.h
@@ -21,17 +21,17 @@ public:
   NS_DECL_FRAMEARENA_HELPERS
 
   virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState) override;
   virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) override;
   virtual nscoord GetBoxAscent(nsBoxLayoutState& aBoxLayoutState) override;
   NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState) override;
   virtual void MarkIntrinsicISizesDirty() override;
 
-  enum CroppingStyle { CropNone, CropLeft, CropRight, CropCenter };
+  enum CroppingStyle { CropNone, CropLeft, CropRight, CropCenter, CropAuto };
 
   friend nsIFrame* NS_NewTextBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
 
   virtual void Init(nsIContent*       aContent,
                     nsContainerFrame* aParent,
                     nsIFrame*         asPrevInFlow) override;
 
   virtual void DestroyFrom(nsIFrame* aDestructRoot) override;