Bug 1213895: Part 1 - Correctly support crop="none" in XUL labels. r?neil draft
authorKris Maglione <maglione.k@gmail.com>
Mon, 08 Feb 2016 14:36:04 -0800
changeset 329637 ad45840de6aaed958e866202fc494b4a55c245ff
parent 329349 8abc7cc3c4e68d163d1aeb1f78c57eb402adacdb
child 329638 3fe4d5042ff60cc0566c6de6089423587c93d381
push id10579
push usermaglione.k@gmail.com
push dateMon, 08 Feb 2016 22:37:13 +0000
reviewersneil
bugs1213895
milestone47.0a1
Bug 1213895: Part 1 - Correctly support crop="none" in XUL labels. r?neil
layout/xul/nsTextBoxFrame.cpp
--- a/layout/xul/nsTextBoxFrame.cpp
+++ b/layout/xul/nsTextBoxFrame.cpp
@@ -223,33 +223,34 @@ 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::none, &nsGkAtoms::right, &nsGkAtoms::end, 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;
+            cropType = CropNone;
             break;
+          case 4:
+          case 5:
           default:
-            cropType = CropNone;
+            cropType = CropRight;
             break;
         }
 
         if (cropType != mCropType) {
             aResize = true;
             mCropType = cropType;
         }
     }
@@ -642,35 +643,40 @@ 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 CropNone:
         case CropRight: