Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(631)

Side by Side Diff: third_party/WebKit/Source/core/layout/line/InlineTextBox.cpp

Issue 1916943002: Show correct part of truncated text before ellipsis in contrary flow (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@604144
Patch Set: Updated Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * (C) 1999 Lars Knoll (knoll@kde.org) 2 * (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Dirk Mueller (mueller@kde.org) 3 * (C) 2000 Dirk Mueller (mueller@kde.org)
4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved. 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 bool rtlEllipsisWithinBox = !flowIsLTR && (ellipsisX > logicalLeft()); 335 bool rtlEllipsisWithinBox = !flowIsLTR && (ellipsisX > logicalLeft());
336 if (ltrEllipsisWithinBox || rtlEllipsisWithinBox) { 336 if (ltrEllipsisWithinBox || rtlEllipsisWithinBox) {
337 foundBox = true; 337 foundBox = true;
338 338
339 // The inline box may have different directionality than it's parent. S ince truncation 339 // The inline box may have different directionality than it's parent. S ince truncation
340 // behavior depends both on both the parent and the inline block's direc tionality, we 340 // behavior depends both on both the parent and the inline block's direc tionality, we
341 // must keep track of these separately. 341 // must keep track of these separately.
342 bool ltr = isLeftToRightDirection(); 342 bool ltr = isLeftToRightDirection();
343 if (ltr != flowIsLTR) { 343 if (ltr != flowIsLTR) {
344 // Width in pixels of the visible portion of the box, excluding the ellipsis. 344 // Width in pixels of the visible portion of the box, excluding the ellipsis.
345 int visibleBoxWidth = visibleRightEdge - visibleLeftEdge - ellipsis Width; 345 int visibleBoxWidth = visibleRightEdge - visibleLeftEdge - ellipsisW idth;
346 ellipsisX = ltr ? logicalLeft() + visibleBoxWidth : logicalRight() - visibleBoxWidth; 346 ellipsisX = flowIsLTR ? logicalLeft() + visibleBoxWidth : logicalRig ht() - visibleBoxWidth;
347 } 347 }
348 348
349 int offset = offsetForPosition(ellipsisX, false); 349 int offset = offsetForPosition(ellipsisX, false);
350 if (offset == 0) { 350 if (offset == 0) {
351 // No characters should be laid out. Set ourselves to full truncati on and place the ellipsis at the min of our start 351 // No characters should be laid out. Set ourselves to full truncati on and place the ellipsis at the min of our start
352 // and the ellipsis edge. 352 // and the ellipsis edge.
353 setTruncation(cFullTruncation); 353 setTruncation(cFullTruncation);
354 truncatedWidth += ellipsisWidth; 354 truncatedWidth += ellipsisWidth;
355 return std::min(ellipsisX, logicalLeft()); 355 return std::min(ellipsisX, logicalLeft());
356 } 356 }
357 357
358 // Set the truncation index on the text run. 358 // Set the truncation index on the text run.
359 setTruncation(offset); 359 setTruncation(offset);
360 360
361 // If we got here that means that we were only partially truncated and w e need to return the pixel offset at which 361 // If we got here that means that we were only partially truncated and w e need to return the pixel offset at which
362 // to place the ellipsis. 362 // to place the ellipsis. Where the text and its flow have opposite dire ctions then our offset into the text is at
363 LayoutUnit widthOfVisibleText(getLineLayoutItem().width(m_start, offset, textPos(), flowIsLTR ? LTR : RTL, isFirstLineStyle())); 363 // the start of the part that will be visible.
364 LayoutUnit widthOfVisibleText(getLineLayoutItem().width(ltr == flowIsLTR ? m_start : offset, ltr == flowIsLTR ? offset : m_len - offset, textPos(), flow IsLTR ? LTR : RTL, isFirstLineStyle()));
364 365
365 // The ellipsis needs to be placed just after the last visible character . 366 // The ellipsis needs to be placed just after the last visible character .
366 // Where "after" is defined by the flow directionality, not the inline 367 // Where "after" is defined by the flow directionality, not the inline
367 // box directionality. 368 // box directionality.
368 // e.g. In the case of an LTR inline box truncated in an RTL flow then w e can 369 // e.g. In the case of an LTR inline box truncated in an RTL flow then w e can
369 // have a situation such as |Hello| -> |...He| 370 // have a situation such as |Hello| -> |...He|
370 truncatedWidth += widthOfVisibleText + ellipsisWidth; 371 truncatedWidth += widthOfVisibleText + ellipsisWidth;
371 if (flowIsLTR) 372 if (flowIsLTR)
372 return logicalLeft() + widthOfVisibleText; 373 return logicalLeft() + widthOfVisibleText;
373 return logicalRight() - widthOfVisibleText - ellipsisWidth; 374 return logicalRight() - widthOfVisibleText - ellipsisWidth;
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 printedCharacters = fprintf(stderr, "\t%s %p", obj.name(), obj.debugPointer( )); 626 printedCharacters = fprintf(stderr, "\t%s %p", obj.name(), obj.debugPointer( ));
626 const int layoutObjectCharacterOffset = 75; 627 const int layoutObjectCharacterOffset = 75;
627 for (; printedCharacters < layoutObjectCharacterOffset; printedCharacters++) 628 for (; printedCharacters < layoutObjectCharacterOffset; printedCharacters++)
628 fputc(' ', stderr); 629 fputc(' ', stderr);
629 fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), value.utf8().d ata()); 630 fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), value.utf8().d ata());
630 } 631 }
631 632
632 #endif 633 #endif
633 634
634 } // namespace blink 635 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698