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

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

Issue 2699393002: Place ellipsis correctly inside inline-blocks (Closed)
Patch Set: bug 133700 Created 3 years, 9 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 * Copyright (C) 2000 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. 3 * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc.
4 * All right reserved. 4 * All right reserved.
5 * Copyright (C) 2010 Google Inc. All rights reserved. 5 * Copyright (C) 2010 Google Inc. 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 2404 matching lines...) Expand 10 before | Expand all | Expand 10 after
2415 // need to see if the line can be truncated. In order for truncation to 2415 // need to see if the line can be truncated. In order for truncation to
2416 // be possible, the line must have sufficient space to accommodate our 2416 // be possible, the line must have sufficient space to accommodate our
2417 // truncation string, and no replaced elements (images, tables) can 2417 // truncation string, and no replaced elements (images, tables) can
2418 // overlap the ellipsis space. 2418 // overlap the ellipsis space.
2419 2419
2420 LayoutUnit width(indentText == IndentText ? firstLineEllipsisWidth 2420 LayoutUnit width(indentText == IndentText ? firstLineEllipsisWidth
2421 : ellipsisWidth); 2421 : ellipsisWidth);
2422 LayoutUnit blockEdge = ltr ? blockRightEdge : blockLeftEdge; 2422 LayoutUnit blockEdge = ltr ? blockRightEdge : blockLeftEdge;
2423 if (curr->lineCanAccommodateEllipsis(ltr, blockEdge, lineBoxEdge, 2423 if (curr->lineCanAccommodateEllipsis(ltr, blockEdge, lineBoxEdge,
2424 width)) { 2424 width)) {
2425 LayoutUnit totalLogicalWidth = curr->placeEllipsis( 2425 LayoutUnit totalLogicalWidth =
2426 selectedEllipsisStr, ltr, blockLeftEdge, blockRightEdge, width); 2426 curr->placeEllipsis(selectedEllipsisStr, ltr, blockLeftEdge,
2427 blockRightEdge, width, LayoutUnit(), false);
2427 LayoutUnit logicalLeft; // We are only interested in the delta from the 2428 LayoutUnit logicalLeft; // We are only interested in the delta from the
2428 // base position. 2429 // base position.
2429 LayoutUnit availableLogicalWidth = blockRightEdge - blockLeftEdge; 2430 LayoutUnit availableLogicalWidth = blockRightEdge - blockLeftEdge;
2430 updateLogicalWidthForAlignment(textAlign, curr, 0, logicalLeft, 2431 updateLogicalWidthForAlignment(textAlign, curr, 0, logicalLeft,
2431 totalLogicalWidth, availableLogicalWidth, 2432 totalLogicalWidth, availableLogicalWidth,
2432 0); 2433 0);
2433 if (ltr) 2434 if (ltr)
2434 curr->moveInInlineDirection(logicalLeft); 2435 curr->moveInInlineDirection(logicalLeft);
2435 else 2436 else
2436 curr->moveInInlineDirection( 2437 curr->moveInInlineDirection(
2437 logicalLeft - (availableLogicalWidth - totalLogicalWidth)); 2438 logicalLeft - (availableLogicalWidth - totalLogicalWidth));
2439 } else {
2440 tryPlacingEllipsisOnAtomicInlines(curr, blockRightEdge, blockLeftEdge,
2441 width, selectedEllipsisStr);
2438 } 2442 }
2439 } 2443 }
2440 indentText = DoNotIndentText; 2444 indentText = DoNotIndentText;
2441 } 2445 }
2442 } 2446 }
2443 2447
2448 void LayoutBlockFlow::tryPlacingEllipsisOnAtomicInlines(
2449 RootInlineBox* root,
2450 LayoutUnit blockRightEdge,
2451 LayoutUnit blockLeftEdge,
2452 LayoutUnit ellipsisWidth,
2453 const AtomicString& selectedEllipsisStr) {
2454 bool ltr = style()->isLeftToRightDirection();
2455 LayoutUnit logicalLeftOffset = blockLeftEdge;
2456
2457 // Each atomic inline block (e.g. a <span>) inside a blockflow is managed by
2458 // an
2459 // InlineBox that allows us to access the lineboxes that live inside the
2460 // atomic
2461 // inline block.
2462 bool foundBox = false;
2463 for (InlineBox* box = ltr ? root->firstChild() : root->lastChild(); box;
2464 box = ltr ? box->nextOnLine() : box->prevOnLine()) {
2465 if (!box->getLineLayoutItem().isAtomicInlineLevel() ||
2466 !box->getLineLayoutItem().isLayoutBlockFlow())
2467 continue;
2468
2469 RootInlineBox* firstRootBox =
2470 LineLayoutBlockFlow(box->getLineLayoutItem()).firstRootBox();
2471 if (!firstRootBox)
2472 continue;
2473
2474 bool placedEllipsis = false;
2475 // Move the right edge of the block in so that we can test it against the
2476 // width of the root line boxes. We don't resize or move the linebox to
2477 // respect text-align because it is the final one of a sequence on the line.
2478 if (ltr) {
2479 for (RootInlineBox* curr = firstRootBox; curr;
2480 curr = curr->nextRootBox()) {
2481 LayoutUnit currLogicalLeft = logicalLeftOffset + curr->logicalLeft();
2482 LayoutUnit ellipsisEdge =
2483 currLogicalLeft + curr->logicalWidth() + ellipsisWidth;
2484 if (ellipsisEdge <= blockRightEdge)
2485 continue;
2486 curr->placeEllipsis(selectedEllipsisStr, ltr, blockLeftEdge,
2487 blockRightEdge, ellipsisWidth, logicalLeftOffset,
2488 foundBox);
2489 placedEllipsis = true;
2490 }
2491 } else {
2492 LayoutUnit maxRootBoxWidth;
2493 for (RootInlineBox* curr = firstRootBox; curr;
2494 curr = curr->nextRootBox()) {
2495 LayoutUnit ellipsisEdge =
2496 box->logicalLeft() + curr->logicalLeft() - ellipsisWidth;
2497 if (ellipsisEdge >= blockLeftEdge)
2498 continue;
2499 // Root boxes can vary in width so move our offset out to allow
2500 // comparison with the right hand edge of the block.
2501 LayoutUnit logicalLeftOffset = box->logicalLeft();
2502 maxRootBoxWidth =
2503 std::max<LayoutUnit>(curr->logicalWidth(), maxRootBoxWidth);
2504 if (logicalLeftOffset < 0)
2505 logicalLeftOffset += maxRootBoxWidth - curr->logicalWidth();
2506 curr->placeEllipsis(selectedEllipsisStr, ltr, blockLeftEdge,
2507 blockRightEdge, ellipsisWidth,
2508 LayoutUnit(logicalLeftOffset.ceil()), foundBox);
2509 placedEllipsis = true;
2510 }
2511 }
2512 foundBox |= placedEllipsis;
2513 logicalLeftOffset += box->logicalWidth();
2514 }
2515 }
2516
2444 void LayoutBlockFlow::markLinesDirtyInBlockRange(LayoutUnit logicalTop, 2517 void LayoutBlockFlow::markLinesDirtyInBlockRange(LayoutUnit logicalTop,
2445 LayoutUnit logicalBottom, 2518 LayoutUnit logicalBottom,
2446 RootInlineBox* highest) { 2519 RootInlineBox* highest) {
2447 if (logicalTop >= logicalBottom) 2520 if (logicalTop >= logicalBottom)
2448 return; 2521 return;
2449 2522
2450 RootInlineBox* lowestDirtyLine = lastRootBox(); 2523 RootInlineBox* lowestDirtyLine = lastRootBox();
2451 RootInlineBox* afterLowest = lowestDirtyLine; 2524 RootInlineBox* afterLowest = lowestDirtyLine;
2452 while (lowestDirtyLine && 2525 while (lowestDirtyLine &&
2453 lowestDirtyLine->lineBottomWithLeading() >= logicalBottom && 2526 lowestDirtyLine->lineBottomWithLeading() >= logicalBottom &&
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2512 2585
2513 bool LayoutBlockFlow::paintedOutputOfObjectHasNoEffectRegardlessOfSize() const { 2586 bool LayoutBlockFlow::paintedOutputOfObjectHasNoEffectRegardlessOfSize() const {
2514 // LayoutBlockFlow is in charge of paint invalidation of the first line. 2587 // LayoutBlockFlow is in charge of paint invalidation of the first line.
2515 if (firstLineBox()) 2588 if (firstLineBox())
2516 return false; 2589 return false;
2517 2590
2518 return LayoutBlock::paintedOutputOfObjectHasNoEffectRegardlessOfSize(); 2591 return LayoutBlock::paintedOutputOfObjectHasNoEffectRegardlessOfSize();
2519 } 2592 }
2520 2593
2521 } // namespace blink 2594 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698