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 332762 62cc4b503870cf7be4ae0c530a3d7ab99c8585b9
parent 332761 ba617d51a0fdc41e619302fd750376aeaabf86ad
child 332763 48a7a7615da812d4adca2d9aa4e9a10ac259bebc
push id11232
push useratolfsen@mozilla.com
push dateSun, 21 Feb 2016 12:02:10 +0000
reviewersneil
bugs1213895
milestone47.0a1
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;