OLD | NEW |
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. | 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. |
5 * All rights reserved. | 5 * All rights reserved. |
6 * | 6 * |
7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 // Criteria for full truncation: | 376 // Criteria for full truncation: |
377 // LTR: the left edge of the ellipsis is to the left of our text run. | 377 // LTR: the left edge of the ellipsis is to the left of our text run. |
378 // RTL: the right edge of the ellipsis is to the right of our text run. | 378 // RTL: the right edge of the ellipsis is to the right of our text run. |
379 LayoutUnit adjusted_logical_left = logical_left_offset + LogicalLeft(); | 379 LayoutUnit adjusted_logical_left = logical_left_offset + LogicalLeft(); |
380 | 380 |
381 // For LTR this is the left edge of the box, for RTL, the right edge in parent | 381 // For LTR this is the left edge of the box, for RTL, the right edge in parent |
382 // coordinates. | 382 // coordinates. |
383 LayoutUnit ellipsis_x = flow_is_ltr ? visible_right_edge - ellipsis_width | 383 LayoutUnit ellipsis_x = flow_is_ltr ? visible_right_edge - ellipsis_width |
384 : visible_left_edge + ellipsis_width; | 384 : visible_left_edge + ellipsis_width; |
385 | 385 |
386 if (IsLeftToRightDirection() == flow_is_ltr && !flow_is_ltr && | |
387 logical_left_offset < 0) | |
388 ellipsis_x -= logical_left_offset; | |
389 | |
390 bool ltr_full_truncation = flow_is_ltr && ellipsis_x <= adjusted_logical_left; | 386 bool ltr_full_truncation = flow_is_ltr && ellipsis_x <= adjusted_logical_left; |
391 bool rtl_full_truncation = | 387 bool rtl_full_truncation = |
392 !flow_is_ltr && | 388 !flow_is_ltr && ellipsis_x > adjusted_logical_left + LogicalWidth(); |
393 ellipsis_x > adjusted_logical_left + LogicalWidth() + ellipsis_width; | |
394 if (ltr_full_truncation || rtl_full_truncation) { | 389 if (ltr_full_truncation || rtl_full_truncation) { |
395 // Too far. Just set full truncation, but return -1 and let the ellipsis | 390 // Too far. Just set full truncation, but return -1 and let the ellipsis |
396 // just be placed at the edge of the box. | 391 // just be placed at the edge of the box. |
397 SetTruncation(kCFullTruncation); | 392 SetTruncation(kCFullTruncation); |
398 found_box = true; | 393 found_box = true; |
399 return LayoutUnit(-1); | 394 return LayoutUnit(-1); |
400 } | 395 } |
401 | 396 |
402 bool ltr_ellipsis_within_box = | 397 bool ltr_ellipsis_within_box = |
403 flow_is_ltr && ellipsis_x < adjusted_logical_left + LogicalWidth(); | 398 flow_is_ltr && ellipsis_x < adjusted_logical_left + LogicalWidth(); |
404 bool rtl_ellipsis_within_box = | 399 bool rtl_ellipsis_within_box = |
405 !flow_is_ltr && ellipsis_x > adjusted_logical_left; | 400 !flow_is_ltr && ellipsis_x > adjusted_logical_left; |
406 if (ltr_ellipsis_within_box || rtl_ellipsis_within_box) { | 401 if (ltr_ellipsis_within_box || rtl_ellipsis_within_box) { |
407 found_box = true; | 402 found_box = true; |
408 | 403 |
409 // The inline box may have different directionality than it's parent. Since | 404 // The inline box may have different directionality than it's parent. Since |
410 // truncation behavior depends both on both the parent and the inline | 405 // truncation behavior depends both on both the parent and the inline |
411 // block's directionality, we must keep track of these separately. | 406 // block's directionality, we must keep track of these separately. |
412 bool ltr = IsLeftToRightDirection(); | 407 bool ltr = IsLeftToRightDirection(); |
413 if (ltr != flow_is_ltr) { | 408 if (ltr != flow_is_ltr) { |
414 // Width in pixels of the visible portion of the box, excluding the | 409 // Width in pixels of the visible portion of the box, excluding the |
415 // ellipsis. | 410 // ellipsis. |
416 LayoutUnit visible_box_width = | 411 LayoutUnit visible_box_width = |
417 visible_right_edge - visible_left_edge - ellipsis_width; | 412 visible_right_edge - visible_left_edge - ellipsis_width; |
418 ellipsis_x = flow_is_ltr ? adjusted_logical_left + visible_box_width | 413 ellipsis_x = flow_is_ltr ? adjusted_logical_left + visible_box_width |
419 : LogicalRight() - visible_box_width; | 414 : LogicalRight() - visible_box_width; |
420 } | 415 } |
421 | 416 |
| 417 // OffsetForPosition() expects the position relative to the root box. |
| 418 if (ltr == flow_is_ltr && !flow_is_ltr && logical_left_offset < 0) |
| 419 ellipsis_x -= logical_left_offset; |
| 420 |
422 // We measure the text using the second half of the previous character and | 421 // We measure the text using the second half of the previous character and |
423 // the first half of the current one when the text is rtl. This gives a | 422 // the first half of the current one when the text is rtl. This gives a |
424 // more accurate position in rtl text. | 423 // more accurate position in rtl text. |
| 424 // TODO(crbug.com/722043: This doesn't always give the best results. |
425 int offset = OffsetForPosition(ellipsis_x, !ltr); | 425 int offset = OffsetForPosition(ellipsis_x, !ltr); |
426 // Full truncation is only necessary when we're flowing left-to-right. | 426 // Full truncation is only necessary when we're flowing left-to-right. |
427 if (flow_is_ltr && offset == 0 && ltr == flow_is_ltr) { | 427 if (flow_is_ltr && offset == 0 && ltr == flow_is_ltr) { |
428 // No characters should be laid out. Set ourselves to full truncation and | 428 // No characters should be laid out. Set ourselves to full truncation and |
429 // place the ellipsis at the min of our start and the ellipsis edge. | 429 // place the ellipsis at the min of our start and the ellipsis edge. |
430 SetTruncation(kCFullTruncation); | 430 SetTruncation(kCFullTruncation); |
431 truncated_width += ellipsis_width; | 431 truncated_width += ellipsis_width; |
432 return std::min(ellipsis_x, LogicalLeft()); | 432 return std::min(ellipsis_x, LogicalLeft()); |
433 } | 433 } |
434 | 434 |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 for (; printed_characters < kLayoutObjectCharacterOffset; | 760 for (; printed_characters < kLayoutObjectCharacterOffset; |
761 printed_characters++) | 761 printed_characters++) |
762 fputc(' ', stderr); | 762 fputc(' ', stderr); |
763 fprintf(stderr, "(%d,%d) \"%s\"\n", Start(), Start() + Len(), | 763 fprintf(stderr, "(%d,%d) \"%s\"\n", Start(), Start() + Len(), |
764 value.Utf8().data()); | 764 value.Utf8().data()); |
765 } | 765 } |
766 | 766 |
767 #endif | 767 #endif |
768 | 768 |
769 } // namespace blink | 769 } // namespace blink |
OLD | NEW |