1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723
|
/*
* Copyright (C) 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "RenderTextLineBoxes.h"
#include "EllipsisBox.h"
#include "InlineTextBox.h"
#include "RenderBlock.h"
#include "RenderStyle.h"
#include "RootInlineBox.h"
namespace WebCore {
RenderTextLineBoxes::RenderTextLineBoxes()
: m_first(nullptr)
, m_last(nullptr)
{
}
InlineTextBox* RenderTextLineBoxes::createAndAppendLineBox(RenderText& renderText)
{
auto textBox = renderText.createTextBox();
if (!m_first) {
m_first = textBox.get();
m_last = textBox.get();
} else {
m_last->setNextTextBox(textBox.get());
textBox->setPreviousTextBox(m_last);
m_last = textBox.get();
}
return textBox.release();
}
void RenderTextLineBoxes::extract(InlineTextBox& box)
{
checkConsistency();
m_last = box.prevTextBox();
if (&box == m_first)
m_first = nullptr;
if (box.prevTextBox())
box.prevTextBox()->setNextTextBox(nullptr);
box.setPreviousTextBox(nullptr);
for (auto current = &box; current; current = current->nextTextBox())
current->setExtracted();
checkConsistency();
}
void RenderTextLineBoxes::attach(InlineTextBox& box)
{
checkConsistency();
if (m_last) {
m_last->setNextTextBox(&box);
box.setPreviousTextBox(m_last);
} else
m_first = &box;
InlineTextBox* last = nullptr;
for (auto current = &box; current; current = current->nextTextBox()) {
current->setExtracted(false);
last = current;
}
m_last = last;
checkConsistency();
}
void RenderTextLineBoxes::remove(InlineTextBox& box)
{
checkConsistency();
if (&box == m_first)
m_first = box.nextTextBox();
if (&box == m_last)
m_last = box.prevTextBox();
if (box.nextTextBox())
box.nextTextBox()->setPreviousTextBox(box.prevTextBox());
if (box.prevTextBox())
box.prevTextBox()->setNextTextBox(box.nextTextBox());
checkConsistency();
}
void RenderTextLineBoxes::removeAllFromParent(RenderText& renderer)
{
if (!m_first) {
if (renderer.parent())
renderer.parent()->dirtyLinesFromChangedChild(&renderer);
return;
}
for (auto box = m_first; box; box = box->nextTextBox())
box->removeFromParent();
}
void RenderTextLineBoxes::deleteAll()
{
if (!m_first)
return;
InlineTextBox* next;
for (auto current = m_first; current; current = next) {
next = current->nextTextBox();
delete current;
}
m_first = nullptr;
m_last = nullptr;
}
InlineTextBox* RenderTextLineBoxes::findNext(int offset, int& position) const
{
if (!m_first)
return nullptr;
// FIXME: This looks buggy. The function is only used for debugging purposes.
auto current = m_first;
int currentOffset = current->len();
while (offset > currentOffset && current->nextTextBox()) {
current = current->nextTextBox();
currentOffset = current->start() + current->len();
}
// we are now in the correct text run
position = (offset > currentOffset ? current->len() : current->len() - (currentOffset - offset));
return current;
}
IntRect RenderTextLineBoxes::boundingBox(const RenderText& renderer) const
{
if (!m_first)
return IntRect();
// Return the width of the minimal left side and the maximal right side.
float logicalLeftSide = 0;
float logicalRightSide = 0;
for (auto current = m_first; current; current = current->nextTextBox()) {
if (current == m_first || current->logicalLeft() < logicalLeftSide)
logicalLeftSide = current->logicalLeft();
if (current == m_first || current->logicalRight() > logicalRightSide)
logicalRightSide = current->logicalRight();
}
bool isHorizontal = renderer.style().isHorizontalWritingMode();
float x = isHorizontal ? logicalLeftSide : m_first->x();
float y = isHorizontal ? m_first->y() : logicalLeftSide;
float width = isHorizontal ? logicalRightSide - logicalLeftSide : m_last->logicalBottom() - x;
float height = isHorizontal ? m_last->logicalBottom() - y : logicalRightSide - logicalLeftSide;
return enclosingIntRect(FloatRect(x, y, width, height));
}
IntPoint RenderTextLineBoxes::firstRunLocation() const
{
if (!m_first)
return IntPoint();
return IntPoint(m_first->topLeft());
}
LayoutRect RenderTextLineBoxes::visualOverflowBoundingBox(const RenderText& renderer) const
{
if (!m_first)
return LayoutRect();
// Return the width of the minimal left side and the maximal right side.
auto logicalLeftSide = LayoutUnit::max();
auto logicalRightSide = LayoutUnit::min();
for (auto current = m_first; current; current = current->nextTextBox()) {
logicalLeftSide = std::min(logicalLeftSide, current->logicalLeftVisualOverflow());
logicalRightSide = std::max(logicalRightSide, current->logicalRightVisualOverflow());
}
auto logicalTop = m_first->logicalTopVisualOverflow();
auto logicalWidth = logicalRightSide - logicalLeftSide;
auto logicalHeight = m_last->logicalBottomVisualOverflow() - logicalTop;
LayoutRect rect(logicalLeftSide, logicalTop, logicalWidth, logicalHeight);
if (!renderer.style().isHorizontalWritingMode())
rect = rect.transposedRect();
return rect;
}
bool RenderTextLineBoxes::hasRenderedText() const
{
for (auto box = m_first; box; box = box->nextTextBox()) {
if (box->len())
return true;
}
return false;
}
int RenderTextLineBoxes::caretMinOffset() const
{
auto box = m_first;
if (!box)
return 0;
int minOffset = box->start();
for (box = box->nextTextBox(); box; box = box->nextTextBox())
minOffset = std::min<int>(minOffset, box->start());
return minOffset;
}
int RenderTextLineBoxes::caretMaxOffset(const RenderText& renderer) const
{
auto box = m_last;
if (!box)
return renderer.textLength();
int maxOffset = box->start() + box->len();
for (box = box->prevTextBox(); box; box = box->prevTextBox())
maxOffset = std::max<int>(maxOffset, box->start() + box->len());
return maxOffset;
}
bool RenderTextLineBoxes::containsOffset(const RenderText& renderer, unsigned offset, OffsetType type) const
{
for (auto box = m_first; box; box = box->nextTextBox()) {
if (offset < box->start() && !renderer.containsReversedText())
return false;
unsigned boxEnd = box->start() + box->len();
if (offset >= box->start() && offset <= boxEnd) {
if (offset == boxEnd && (type == CharacterOffset || box->isLineBreak()))
continue;
if (type == CharacterOffset)
return true;
// Return false for offsets inside composed characters.
return !offset || offset == static_cast<unsigned>(renderer.nextOffset(renderer.previousOffset(offset)));
}
}
return false;
}
unsigned RenderTextLineBoxes::countCharacterOffsetsUntil(unsigned offset) const
{
unsigned result = 0;
for (auto box = m_first; box; box = box->nextTextBox()) {
if (offset < box->start())
return result;
if (offset <= box->start() + box->len()) {
result += offset - box->start();
return result;
}
result += box->len();
}
return result;
}
enum ShouldAffinityBeDownstream { AlwaysDownstream, AlwaysUpstream, UpstreamIfPositionIsNotAtStart };
static bool lineDirectionPointFitsInBox(int pointLineDirection, const InlineTextBox& box, ShouldAffinityBeDownstream& shouldAffinityBeDownstream)
{
shouldAffinityBeDownstream = AlwaysDownstream;
// the x coordinate is equal to the left edge of this box
// the affinity must be downstream so the position doesn't jump back to the previous line
// except when box is the first box in the line
if (pointLineDirection <= box.logicalLeft()) {
shouldAffinityBeDownstream = !box.prevLeafChild() ? UpstreamIfPositionIsNotAtStart : AlwaysDownstream;
return true;
}
#if !PLATFORM(IOS)
// and the x coordinate is to the left of the right edge of this box
// check to see if position goes in this box
if (pointLineDirection < box.logicalRight()) {
shouldAffinityBeDownstream = UpstreamIfPositionIsNotAtStart;
return true;
}
#endif
// box is first on line
// and the x coordinate is to the left of the first text box left edge
if (!box.prevLeafChildIgnoringLineBreak() && pointLineDirection < box.logicalLeft())
return true;
if (!box.nextLeafChildIgnoringLineBreak()) {
// box is last on line
// and the x coordinate is to the right of the last text box right edge
// generate VisiblePosition, use UPSTREAM affinity if possible
shouldAffinityBeDownstream = UpstreamIfPositionIsNotAtStart;
return true;
}
return false;
}
static VisiblePosition createVisiblePositionForBox(const InlineBox& box, int offset, ShouldAffinityBeDownstream shouldAffinityBeDownstream)
{
EAffinity affinity = VP_DEFAULT_AFFINITY;
switch (shouldAffinityBeDownstream) {
case AlwaysDownstream:
affinity = DOWNSTREAM;
break;
case AlwaysUpstream:
affinity = VP_UPSTREAM_IF_POSSIBLE;
break;
case UpstreamIfPositionIsNotAtStart:
affinity = offset > box.caretMinOffset() ? VP_UPSTREAM_IF_POSSIBLE : DOWNSTREAM;
break;
}
return box.renderer().createVisiblePosition(offset, affinity);
}
static VisiblePosition createVisiblePositionAfterAdjustingOffsetForBiDi(const InlineTextBox& box, int offset, ShouldAffinityBeDownstream shouldAffinityBeDownstream)
{
ASSERT(offset >= 0);
if (offset && static_cast<unsigned>(offset) < box.len())
return createVisiblePositionForBox(box, box.start() + offset, shouldAffinityBeDownstream);
bool positionIsAtStartOfBox = !offset;
if (positionIsAtStartOfBox == box.isLeftToRightDirection()) {
// offset is on the left edge
const InlineBox* prevBox = box.prevLeafChildIgnoringLineBreak();
if ((prevBox && prevBox->bidiLevel() == box.bidiLevel())
|| box.renderer().containingBlock()->style().direction() == box.direction()) // FIXME: left on 12CBA
return createVisiblePositionForBox(box, box.caretLeftmostOffset(), shouldAffinityBeDownstream);
if (prevBox && prevBox->bidiLevel() > box.bidiLevel()) {
// e.g. left of B in aDC12BAb
const InlineBox* leftmostBox;
do {
leftmostBox = prevBox;
prevBox = leftmostBox->prevLeafChildIgnoringLineBreak();
} while (prevBox && prevBox->bidiLevel() > box.bidiLevel());
return createVisiblePositionForBox(*leftmostBox, leftmostBox->caretRightmostOffset(), shouldAffinityBeDownstream);
}
if (!prevBox || prevBox->bidiLevel() < box.bidiLevel()) {
// e.g. left of D in aDC12BAb
const InlineBox* rightmostBox;
const InlineBox* nextBox = &box;
do {
rightmostBox = nextBox;
nextBox = rightmostBox->nextLeafChildIgnoringLineBreak();
} while (nextBox && nextBox->bidiLevel() >= box.bidiLevel());
return createVisiblePositionForBox(*rightmostBox,
box.isLeftToRightDirection() ? rightmostBox->caretMaxOffset() : rightmostBox->caretMinOffset(), shouldAffinityBeDownstream);
}
return createVisiblePositionForBox(box, box.caretRightmostOffset(), shouldAffinityBeDownstream);
}
const InlineBox* nextBox = box.nextLeafChildIgnoringLineBreak();
if ((nextBox && nextBox->bidiLevel() == box.bidiLevel())
|| box.renderer().containingBlock()->style().direction() == box.direction())
return createVisiblePositionForBox(box, box.caretRightmostOffset(), shouldAffinityBeDownstream);
// offset is on the right edge
if (nextBox && nextBox->bidiLevel() > box.bidiLevel()) {
// e.g. right of C in aDC12BAb
const InlineBox* rightmostBox;
do {
rightmostBox = nextBox;
nextBox = rightmostBox->nextLeafChildIgnoringLineBreak();
} while (nextBox && nextBox->bidiLevel() > box.bidiLevel());
return createVisiblePositionForBox(*rightmostBox, rightmostBox->caretLeftmostOffset(), shouldAffinityBeDownstream);
}
if (!nextBox || nextBox->bidiLevel() < box.bidiLevel()) {
// e.g. right of A in aDC12BAb
const InlineBox* leftmostBox;
const InlineBox* prevBox = &box;
do {
leftmostBox = prevBox;
prevBox = leftmostBox->prevLeafChildIgnoringLineBreak();
} while (prevBox && prevBox->bidiLevel() >= box.bidiLevel());
return createVisiblePositionForBox(*leftmostBox,
box.isLeftToRightDirection() ? leftmostBox->caretMinOffset() : leftmostBox->caretMaxOffset(), shouldAffinityBeDownstream);
}
return createVisiblePositionForBox(box, box.caretLeftmostOffset(), shouldAffinityBeDownstream);
}
VisiblePosition RenderTextLineBoxes::positionForPoint(const RenderText& renderer, const LayoutPoint& point) const
{
if (!m_first || !renderer.textLength())
return renderer.createVisiblePosition(0, DOWNSTREAM);
LayoutUnit pointLineDirection = m_first->isHorizontal() ? point.x() : point.y();
LayoutUnit pointBlockDirection = m_first->isHorizontal() ? point.y() : point.x();
bool blocksAreFlipped = renderer.style().isFlippedBlocksWritingMode();
InlineTextBox* lastBox = nullptr;
for (auto box = m_first; box; box = box->nextTextBox()) {
if (box->isLineBreak() && !box->prevLeafChild() && box->nextLeafChild() && !box->nextLeafChild()->isLineBreak())
box = box->nextTextBox();
auto& rootBox = box->root();
LayoutUnit top = std::min(rootBox.selectionTop(), rootBox.lineTop());
if (pointBlockDirection > top || (!blocksAreFlipped && pointBlockDirection == top)) {
LayoutUnit bottom = rootBox.selectionBottom();
if (rootBox.nextRootBox())
bottom = std::min(bottom, rootBox.nextRootBox()->lineTop());
if (pointBlockDirection < bottom || (blocksAreFlipped && pointBlockDirection == bottom)) {
ShouldAffinityBeDownstream shouldAffinityBeDownstream;
#if PLATFORM(IOS)
if (pointLineDirection != box->logicalLeft() && point.x() < box->x() + box->logicalWidth()) {
int half = box->x() + box->logicalWidth() / 2;
EAffinity affinity = point.x() < half ? DOWNSTREAM : VP_UPSTREAM_IF_POSSIBLE;
return renderer.createVisiblePosition(box->offsetForPosition(pointLineDirection) + box->start(), affinity);
}
#endif
if (lineDirectionPointFitsInBox(pointLineDirection, *box, shouldAffinityBeDownstream))
return createVisiblePositionAfterAdjustingOffsetForBiDi(*box, box->offsetForPosition(pointLineDirection), shouldAffinityBeDownstream);
}
}
lastBox = box;
}
if (lastBox) {
ShouldAffinityBeDownstream shouldAffinityBeDownstream;
lineDirectionPointFitsInBox(pointLineDirection, *lastBox, shouldAffinityBeDownstream);
return createVisiblePositionAfterAdjustingOffsetForBiDi(*lastBox, lastBox->offsetForPosition(pointLineDirection) + lastBox->start(), shouldAffinityBeDownstream);
}
return renderer.createVisiblePosition(0, DOWNSTREAM);
}
void RenderTextLineBoxes::setSelectionState(RenderText& renderer, RenderObject::SelectionState state)
{
if (state == RenderObject::SelectionInside || state == RenderObject::SelectionNone) {
for (auto box = m_first; box; box = box->nextTextBox())
box->root().setHasSelectedChildren(state == RenderObject::SelectionInside);
return;
}
int start, end;
renderer.selectionStartEnd(start, end);
if (state == RenderObject::SelectionStart) {
end = renderer.textLength();
// to handle selection from end of text to end of line
if (start && start == end)
start = end - 1;
} else if (state == RenderObject::SelectionEnd)
start = 0;
for (auto box = m_first; box; box = box->nextTextBox()) {
if (box->isSelected(start, end))
box->root().setHasSelectedChildren(true);
}
}
static IntRect ellipsisRectForBox(const InlineTextBox& box, unsigned start, unsigned end)
{
unsigned short truncation = box.truncation();
if (truncation == cNoTruncation)
return IntRect();
auto ellipsis = box.root().ellipsisBox();
if (!ellipsis)
return IntRect();
IntRect rect;
int ellipsisStartPosition = std::max<int>(start - box.start(), 0);
int ellipsisEndPosition = std::min<int>(end - box.start(), box.len());
// The ellipsis should be considered to be selected if the end of
// the selection is past the beginning of the truncation and the
// beginning of the selection is before or at the beginning of the truncation.
if (ellipsisEndPosition < truncation && ellipsisStartPosition > truncation)
return IntRect();
return ellipsis->selectionRect();
}
LayoutRect RenderTextLineBoxes::selectionRectForRange(unsigned start, unsigned end)
{
LayoutRect rect;
for (auto box = m_first; box; box = box->nextTextBox()) {
rect.unite(box->localSelectionRect(start, end));
rect.unite(ellipsisRectForBox(*box, start, end));
}
return rect;
}
void RenderTextLineBoxes::collectSelectionRectsForRange(unsigned start, unsigned end, Vector<LayoutRect>& rects)
{
for (auto box = m_first; box; box = box->nextTextBox()) {
LayoutRect rect;
rect.unite(box->localSelectionRect(start, end));
rect.unite(ellipsisRectForBox(*box, start, end));
if (!rect.size().isEmpty())
rects.append(rect);
}
}
Vector<IntRect> RenderTextLineBoxes::absoluteRects(const LayoutPoint& accumulatedOffset) const
{
Vector<IntRect> rects;
for (auto box = m_first; box; box = box->nextTextBox())
rects.append(enclosingIntRect(FloatRect(accumulatedOffset + box->topLeft(), box->size())));
return rects;
}
static FloatRect localQuadForTextBox(const InlineTextBox& box, unsigned start, unsigned end, bool useSelectionHeight)
{
unsigned realEnd = std::min(box.end() + 1, end);
LayoutRect boxSelectionRect = box.localSelectionRect(start, realEnd);
if (!boxSelectionRect.height())
return FloatRect();
if (useSelectionHeight)
return boxSelectionRect;
// Change the height and y position (or width and x for vertical text)
// because selectionRect uses selection-specific values.
if (box.isHorizontal()) {
boxSelectionRect.setHeight(box.height());
boxSelectionRect.setY(box.y());
} else {
boxSelectionRect.setWidth(box.width());
boxSelectionRect.setX(box.x());
}
return boxSelectionRect;
}
Vector<IntRect> RenderTextLineBoxes::absoluteRectsForRange(const RenderText& renderer, unsigned start, unsigned end, bool useSelectionHeight, bool* wasFixed) const
{
Vector<IntRect> rects;
for (auto box = m_first; box; box = box->nextTextBox()) {
// Note: box->end() returns the index of the last character, not the index past it
if (start <= box->start() && box->end() < end) {
FloatRect boundaries = box->calculateBoundaries();
if (useSelectionHeight) {
LayoutRect selectionRect = box->localSelectionRect(start, end);
if (box->isHorizontal()) {
boundaries.setHeight(selectionRect.height());
boundaries.setY(selectionRect.y());
} else {
boundaries.setWidth(selectionRect.width());
boundaries.setX(selectionRect.x());
}
}
rects.append(renderer.localToAbsoluteQuad(boundaries, 0, wasFixed).enclosingBoundingBox());
continue;
}
// FIXME: This code is wrong. It's converting local to absolute twice. http://webkit.org/b/65722
FloatRect rect = localQuadForTextBox(*box, start, end, useSelectionHeight);
if (!rect.isZero())
rects.append(renderer.localToAbsoluteQuad(rect, 0, wasFixed).enclosingBoundingBox());
}
return rects;
}
Vector<FloatQuad> RenderTextLineBoxes::absoluteQuads(const RenderText& renderer, bool* wasFixed, ClippingOption option) const
{
Vector<FloatQuad> quads;
for (auto box = m_first; box; box = box->nextTextBox()) {
FloatRect boundaries = box->calculateBoundaries();
// Shorten the width of this text box if it ends in an ellipsis.
// FIXME: ellipsisRectForBox should switch to return FloatRect soon with the subpixellayout branch.
IntRect ellipsisRect = (option == ClipToEllipsis) ? ellipsisRectForBox(*box, 0, renderer.textLength()) : IntRect();
if (!ellipsisRect.isEmpty()) {
if (renderer.style().isHorizontalWritingMode())
boundaries.setWidth(ellipsisRect.maxX() - boundaries.x());
else
boundaries.setHeight(ellipsisRect.maxY() - boundaries.y());
}
quads.append(renderer.localToAbsoluteQuad(boundaries, 0, wasFixed));
}
return quads;
}
Vector<FloatQuad> RenderTextLineBoxes::absoluteQuadsForRange(const RenderText& renderer, unsigned start, unsigned end, bool useSelectionHeight, bool* wasFixed) const
{
Vector<FloatQuad> quads;
for (auto box = m_first; box; box = box->nextTextBox()) {
// Note: box->end() returns the index of the last character, not the index past it
if (start <= box->start() && box->end() < end) {
FloatRect boundaries = box->calculateBoundaries();
if (useSelectionHeight) {
LayoutRect selectionRect = box->localSelectionRect(start, end);
if (box->isHorizontal()) {
boundaries.setHeight(selectionRect.height());
boundaries.setY(selectionRect.y());
} else {
boundaries.setWidth(selectionRect.width());
boundaries.setX(selectionRect.x());
}
}
quads.append(renderer.localToAbsoluteQuad(boundaries, 0, wasFixed));
continue;
}
FloatRect rect = localQuadForTextBox(*box, start, end, useSelectionHeight);
if (!rect.isZero())
quads.append(renderer.localToAbsoluteQuad(rect, 0, wasFixed));
}
return quads;
}
void RenderTextLineBoxes::dirtyAll()
{
for (auto box = m_first; box; box = box->nextTextBox())
box->dirtyLineBoxes();
}
bool RenderTextLineBoxes::dirtyRange(RenderText& renderer, unsigned start, unsigned end, int lengthDelta)
{
RootInlineBox* firstRootBox = nullptr;
RootInlineBox* lastRootBox = nullptr;
// Dirty all text boxes that include characters in between offset and offset+len.
bool dirtiedLines = false;
for (auto current = m_first; current; current = current->nextTextBox()) {
// FIXME: This shouldn't rely on the end of a dirty line box. See https://bugs.webkit.org/show_bug.cgi?id=97264
// Text run is entirely before the affected range.
if (current->end() < start)
continue;
// Text run is entirely after the affected range.
if (current->start() > end) {
current->offsetRun(lengthDelta);
auto& rootBox = current->root();
if (!firstRootBox) {
firstRootBox = &rootBox;
if (!dirtiedLines) {
// The affected area was in between two runs. Go ahead and mark the root box of
// the run after the affected area as dirty.
firstRootBox->markDirty();
dirtiedLines = true;
}
}
lastRootBox = &rootBox;
continue;
}
if (current->end() >= start && current->end() <= end) {
// Text run overlaps with the left end of the affected range.
current->dirtyLineBoxes();
dirtiedLines = true;
continue;
}
if (current->start() <= start && current->end() >= end) {
// Text run subsumes the affected range.
current->dirtyLineBoxes();
dirtiedLines = true;
continue;
}
if (current->start() <= end && current->end() >= end) {
// Text run overlaps with right end of the affected range.
current->dirtyLineBoxes();
dirtiedLines = true;
continue;
}
}
// Now we have to walk all of the clean lines and adjust their cached line break information
// to reflect our updated offsets.
if (lastRootBox)
lastRootBox = lastRootBox->nextRootBox();
if (firstRootBox) {
auto previousRootBox = firstRootBox->prevRootBox();
if (previousRootBox)
firstRootBox = previousRootBox;
} else if (m_last) {
ASSERT(!lastRootBox);
firstRootBox = &m_last->root();
firstRootBox->markDirty();
dirtiedLines = true;
}
for (auto current = firstRootBox; current && current != lastRootBox; current = current->nextRootBox()) {
if (current->lineBreakObj() == &renderer && current->lineBreakPos() > end)
current->setLineBreakPos(current->lineBreakPos() + lengthDelta);
}
// If the text node is empty, dirty the line where new text will be inserted.
if (!m_first && renderer.parent()) {
renderer.parent()->dirtyLinesFromChangedChild(&renderer);
dirtiedLines = true;
}
return dirtiedLines;
}
inline void RenderTextLineBoxes::checkConsistency() const
{
#if !ASSERT_DISABLED
#ifdef CHECK_CONSISTENCY
const InlineTextBox* prev = nullptr;
for (auto child = m_first; child; child = child->nextTextBox()) {
ASSERT(child->renderer() == this);
ASSERT(child->prevTextBox() == prev);
prev = child;
}
ASSERT(prev == m_last);
#endif
#endif
}
#if !ASSERT_DISABLED
RenderTextLineBoxes::~RenderTextLineBoxes()
{
ASSERT(!m_first);
ASSERT(!m_last);
}
#endif
#if !ASSERT_WITH_SECURITY_IMPLICATION_DISABLED
void RenderTextLineBoxes::invalidateParentChildLists()
{
for (auto box = m_first; box; box = box->nextTextBox())
box->invalidateParentChildList();
}
#endif
}
|