| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2003, 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2003, 2006, 2008 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
| 6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
| 7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
| 8 * | 8 * |
| 9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 // We have to compute the expansion for annotations over the previous li
ne to see how much we should move. | 275 // We have to compute the expansion for annotations over the previous li
ne to see how much we should move. |
| 276 LayoutUnit lowestAllowedPosition = std::max(prevRootBox()->lineBottom(),
lineTop()) - result; | 276 LayoutUnit lowestAllowedPosition = std::max(prevRootBox()->lineBottom(),
lineTop()) - result; |
| 277 result = prevRootBox()->computeOverAnnotationAdjustment(lowestAllowedPos
ition); | 277 result = prevRootBox()->computeOverAnnotationAdjustment(lowestAllowedPos
ition); |
| 278 } | 278 } |
| 279 | 279 |
| 280 return result; | 280 return result; |
| 281 } | 281 } |
| 282 | 282 |
| 283 GapRects RootInlineBox::lineSelectionGap(const RenderBlock* rootBlock, const Lay
outPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock, Layo
utUnit selTop, LayoutUnit selHeight, const PaintInfo* paintInfo) const | 283 GapRects RootInlineBox::lineSelectionGap(const RenderBlock* rootBlock, const Lay
outPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock, Layo
utUnit selTop, LayoutUnit selHeight, const PaintInfo* paintInfo) const |
| 284 { | 284 { |
| 285 RenderObject::SelectionState lineState = selectionState(); | 285 LayoutObject::SelectionState lineState = selectionState(); |
| 286 | 286 |
| 287 bool leftGap, rightGap; | 287 bool leftGap, rightGap; |
| 288 block().getSelectionGapInfo(lineState, leftGap, rightGap); | 288 block().getSelectionGapInfo(lineState, leftGap, rightGap); |
| 289 | 289 |
| 290 GapRects result; | 290 GapRects result; |
| 291 | 291 |
| 292 InlineBox* firstBox = firstSelectedBox(); | 292 InlineBox* firstBox = firstSelectedBox(); |
| 293 InlineBox* lastBox = lastSelectedBox(); | 293 InlineBox* lastBox = lastSelectedBox(); |
| 294 if (leftGap) { | 294 if (leftGap) { |
| 295 result.uniteLeft(block().logicalLeftSelectionGap(rootBlock, rootBlockPhy
sicalPosition, offsetFromRootBlock, | 295 result.uniteLeft(block().logicalLeftSelectionGap(rootBlock, rootBlockPhy
sicalPosition, offsetFromRootBlock, |
| 296 &firstBox->parent()->renderer(), firstBox->logicalLeft(), selTop, se
lHeight, paintInfo)); | 296 &firstBox->parent()->renderer(), firstBox->logicalLeft(), selTop, se
lHeight, paintInfo)); |
| 297 } | 297 } |
| 298 if (rightGap) { | 298 if (rightGap) { |
| 299 result.uniteRight(block().logicalRightSelectionGap(rootBlock, rootBlockP
hysicalPosition, offsetFromRootBlock, | 299 result.uniteRight(block().logicalRightSelectionGap(rootBlock, rootBlockP
hysicalPosition, offsetFromRootBlock, |
| 300 &lastBox->parent()->renderer(), lastBox->logicalRight(), selTop, sel
Height, paintInfo)); | 300 &lastBox->parent()->renderer(), lastBox->logicalRight(), selTop, sel
Height, paintInfo)); |
| 301 } | 301 } |
| 302 | 302 |
| 303 // When dealing with bidi text, a non-contiguous selection region is possibl
e. | 303 // When dealing with bidi text, a non-contiguous selection region is possibl
e. |
| 304 // e.g. The logical text aaaAAAbbb (capitals denote RTL text and non-capital
s LTR) is layed out | 304 // e.g. The logical text aaaAAAbbb (capitals denote RTL text and non-capital
s LTR) is layed out |
| 305 // visually as 3 text runs |aaa|bbb|AAA| if we select 4 characters from the
start of the text the | 305 // visually as 3 text runs |aaa|bbb|AAA| if we select 4 characters from the
start of the text the |
| 306 // selection will look like (underline denotes selection): | 306 // selection will look like (underline denotes selection): |
| 307 // |aaa|bbb|AAA| | 307 // |aaa|bbb|AAA| |
| 308 // ___ _ | 308 // ___ _ |
| 309 // We can see that the |bbb| run is not part of the selection while the runs
around it are. | 309 // We can see that the |bbb| run is not part of the selection while the runs
around it are. |
| 310 if (firstBox && firstBox != lastBox) { | 310 if (firstBox && firstBox != lastBox) { |
| 311 // Now fill in any gaps on the line that occurred between two selected e
lements. | 311 // Now fill in any gaps on the line that occurred between two selected e
lements. |
| 312 LayoutUnit lastLogicalLeft = firstBox->logicalRight(); | 312 LayoutUnit lastLogicalLeft = firstBox->logicalRight(); |
| 313 bool isPreviousBoxSelected = firstBox->selectionState() != RenderObject:
:SelectionNone; | 313 bool isPreviousBoxSelected = firstBox->selectionState() != LayoutObject:
:SelectionNone; |
| 314 for (InlineBox* box = firstBox->nextLeafChild(); box; box = box->nextLea
fChild()) { | 314 for (InlineBox* box = firstBox->nextLeafChild(); box; box = box->nextLea
fChild()) { |
| 315 if (box->selectionState() != RenderObject::SelectionNone) { | 315 if (box->selectionState() != LayoutObject::SelectionNone) { |
| 316 LayoutRect logicalRect(lastLogicalLeft, selTop, box->logicalLeft
() - lastLogicalLeft, selHeight); | 316 LayoutRect logicalRect(lastLogicalLeft, selTop, box->logicalLeft
() - lastLogicalLeft, selHeight); |
| 317 logicalRect.move(renderer().isHorizontalWritingMode() ? offsetFr
omRootBlock : LayoutSize(offsetFromRootBlock.height(), offsetFromRootBlock.width
())); | 317 logicalRect.move(renderer().isHorizontalWritingMode() ? offsetFr
omRootBlock : LayoutSize(offsetFromRootBlock.height(), offsetFromRootBlock.width
())); |
| 318 LayoutRect gapRect = rootBlock->logicalRectToPhysicalRect(rootBl
ockPhysicalPosition, logicalRect); | 318 LayoutRect gapRect = rootBlock->logicalRectToPhysicalRect(rootBl
ockPhysicalPosition, logicalRect); |
| 319 if (isPreviousBoxSelected && gapRect.width() > 0 && gapRect.heig
ht() > 0) { | 319 if (isPreviousBoxSelected && gapRect.width() > 0 && gapRect.heig
ht() > 0) { |
| 320 if (paintInfo && box->parent()->renderer().style()->visibili
ty() == VISIBLE) | 320 if (paintInfo && box->parent()->renderer().style()->visibili
ty() == VISIBLE) |
| 321 paintInfo->context->fillRect(gapRect, box->parent()->ren
derer().selectionBackgroundColor()); | 321 paintInfo->context->fillRect(gapRect, box->parent()->ren
derer().selectionBackgroundColor()); |
| 322 // VisibleSelection may be non-contiguous, see comment above
. | 322 // VisibleSelection may be non-contiguous, see comment above
. |
| 323 result.uniteCenter(gapRect); | 323 result.uniteCenter(gapRect); |
| 324 } | 324 } |
| 325 lastLogicalLeft = box->logicalRight(); | 325 lastLogicalLeft = box->logicalRight(); |
| 326 } | 326 } |
| 327 if (box == lastBox) | 327 if (box == lastBox) |
| 328 break; | 328 break; |
| 329 isPreviousBoxSelected = box->selectionState() != RenderObject::Selec
tionNone; | 329 isPreviousBoxSelected = box->selectionState() != LayoutObject::Selec
tionNone; |
| 330 } | 330 } |
| 331 } | 331 } |
| 332 | 332 |
| 333 return result; | 333 return result; |
| 334 } | 334 } |
| 335 | 335 |
| 336 RenderObject::SelectionState RootInlineBox::selectionState() const | 336 LayoutObject::SelectionState RootInlineBox::selectionState() const |
| 337 { | 337 { |
| 338 // Walk over all of the selected boxes. | 338 // Walk over all of the selected boxes. |
| 339 RenderObject::SelectionState state = RenderObject::SelectionNone; | 339 LayoutObject::SelectionState state = LayoutObject::SelectionNone; |
| 340 for (InlineBox* box = firstLeafChild(); box; box = box->nextLeafChild()) { | 340 for (InlineBox* box = firstLeafChild(); box; box = box->nextLeafChild()) { |
| 341 RenderObject::SelectionState boxState = box->selectionState(); | 341 LayoutObject::SelectionState boxState = box->selectionState(); |
| 342 if ((boxState == RenderObject::SelectionStart && state == RenderObject::
SelectionEnd) | 342 if ((boxState == LayoutObject::SelectionStart && state == LayoutObject::
SelectionEnd) |
| 343 || (boxState == RenderObject::SelectionEnd && state == RenderObject:
:SelectionStart)) { | 343 || (boxState == LayoutObject::SelectionEnd && state == LayoutObject:
:SelectionStart)) { |
| 344 state = RenderObject::SelectionBoth; | 344 state = LayoutObject::SelectionBoth; |
| 345 } else if (state == RenderObject::SelectionNone || ((boxState == RenderO
bject::SelectionStart || boxState == RenderObject::SelectionEnd) && (state == Re
nderObject::SelectionNone || state == RenderObject::SelectionInside))) { | 345 } else if (state == LayoutObject::SelectionNone || ((boxState == LayoutO
bject::SelectionStart || boxState == LayoutObject::SelectionEnd) && (state == La
youtObject::SelectionNone || state == LayoutObject::SelectionInside))) { |
| 346 state = boxState; | 346 state = boxState; |
| 347 } else if (boxState == RenderObject::SelectionNone && state == RenderObj
ect::SelectionStart) { | 347 } else if (boxState == LayoutObject::SelectionNone && state == LayoutObj
ect::SelectionStart) { |
| 348 // We are past the end of the selection. | 348 // We are past the end of the selection. |
| 349 state = RenderObject::SelectionBoth; | 349 state = LayoutObject::SelectionBoth; |
| 350 } | 350 } |
| 351 if (state == RenderObject::SelectionBoth) | 351 if (state == LayoutObject::SelectionBoth) |
| 352 break; | 352 break; |
| 353 } | 353 } |
| 354 | 354 |
| 355 return state; | 355 return state; |
| 356 } | 356 } |
| 357 | 357 |
| 358 InlineBox* RootInlineBox::firstSelectedBox() const | 358 InlineBox* RootInlineBox::firstSelectedBox() const |
| 359 { | 359 { |
| 360 for (InlineBox* box = firstLeafChild(); box; box = box->nextLeafChild()) { | 360 for (InlineBox* box = firstLeafChild(); box; box = box->nextLeafChild()) { |
| 361 if (box->selectionState() != RenderObject::SelectionNone) | 361 if (box->selectionState() != LayoutObject::SelectionNone) |
| 362 return box; | 362 return box; |
| 363 } | 363 } |
| 364 | 364 |
| 365 return 0; | 365 return 0; |
| 366 } | 366 } |
| 367 | 367 |
| 368 InlineBox* RootInlineBox::lastSelectedBox() const | 368 InlineBox* RootInlineBox::lastSelectedBox() const |
| 369 { | 369 { |
| 370 for (InlineBox* box = lastLeafChild(); box; box = box->prevLeafChild()) { | 370 for (InlineBox* box = lastLeafChild(); box; box = box->prevLeafChild()) { |
| 371 if (box->selectionState() != RenderObject::SelectionNone) | 371 if (box->selectionState() != LayoutObject::SelectionNone) |
| 372 return box; | 372 return box; |
| 373 } | 373 } |
| 374 | 374 |
| 375 return 0; | 375 return 0; |
| 376 } | 376 } |
| 377 | 377 |
| 378 LayoutUnit RootInlineBox::selectionTop() const | 378 LayoutUnit RootInlineBox::selectionTop() const |
| 379 { | 379 { |
| 380 LayoutUnit selectionTop = m_lineTop; | 380 LayoutUnit selectionTop = m_lineTop; |
| 381 | 381 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 398 return selectionTop; | 398 return selectionTop; |
| 399 } | 399 } |
| 400 | 400 |
| 401 return prevBottom; | 401 return prevBottom; |
| 402 } | 402 } |
| 403 | 403 |
| 404 LayoutUnit RootInlineBox::selectionTopAdjustedForPrecedingBlock() const | 404 LayoutUnit RootInlineBox::selectionTopAdjustedForPrecedingBlock() const |
| 405 { | 405 { |
| 406 LayoutUnit top = selectionTop(); | 406 LayoutUnit top = selectionTop(); |
| 407 | 407 |
| 408 RenderObject::SelectionState blockSelectionState = root().block().selectionS
tate(); | 408 LayoutObject::SelectionState blockSelectionState = root().block().selectionS
tate(); |
| 409 if (blockSelectionState != RenderObject::SelectionInside && blockSelectionSt
ate != RenderObject::SelectionEnd) | 409 if (blockSelectionState != LayoutObject::SelectionInside && blockSelectionSt
ate != LayoutObject::SelectionEnd) |
| 410 return top; | 410 return top; |
| 411 | 411 |
| 412 LayoutSize offsetToBlockBefore; | 412 LayoutSize offsetToBlockBefore; |
| 413 if (RenderBlock* block = root().block().blockBeforeWithinSelectionRoot(offse
tToBlockBefore)) { | 413 if (RenderBlock* block = root().block().blockBeforeWithinSelectionRoot(offse
tToBlockBefore)) { |
| 414 if (block->isRenderBlockFlow()) { | 414 if (block->isRenderBlockFlow()) { |
| 415 if (RootInlineBox* lastLine = toRenderBlockFlow(block)->lastRootBox(
)) { | 415 if (RootInlineBox* lastLine = toRenderBlockFlow(block)->lastRootBox(
)) { |
| 416 RenderObject::SelectionState lastLineSelectionState = lastLine->
selectionState(); | 416 LayoutObject::SelectionState lastLineSelectionState = lastLine->
selectionState(); |
| 417 if (lastLineSelectionState != RenderObject::SelectionInside && l
astLineSelectionState != RenderObject::SelectionStart) | 417 if (lastLineSelectionState != LayoutObject::SelectionInside && l
astLineSelectionState != LayoutObject::SelectionStart) |
| 418 return top; | 418 return top; |
| 419 | 419 |
| 420 LayoutUnit lastLineSelectionBottom = lastLine->selectionBottom()
+ offsetToBlockBefore.height(); | 420 LayoutUnit lastLineSelectionBottom = lastLine->selectionBottom()
+ offsetToBlockBefore.height(); |
| 421 top = std::max(top, lastLineSelectionBottom); | 421 top = std::max(top, lastLineSelectionBottom); |
| 422 } | 422 } |
| 423 } | 423 } |
| 424 } | 424 } |
| 425 | 425 |
| 426 return top; | 426 return top; |
| 427 } | 427 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 } | 513 } |
| 514 | 514 |
| 515 return closestLeaf ? closestLeaf : lastLeaf; | 515 return closestLeaf ? closestLeaf : lastLeaf; |
| 516 } | 516 } |
| 517 | 517 |
| 518 BidiStatus RootInlineBox::lineBreakBidiStatus() const | 518 BidiStatus RootInlineBox::lineBreakBidiStatus() const |
| 519 { | 519 { |
| 520 return BidiStatus(static_cast<WTF::Unicode::Direction>(m_lineBreakBidiStatus
Eor), static_cast<WTF::Unicode::Direction>(m_lineBreakBidiStatusLastStrong), sta
tic_cast<WTF::Unicode::Direction>(m_lineBreakBidiStatusLast), m_lineBreakContext
); | 520 return BidiStatus(static_cast<WTF::Unicode::Direction>(m_lineBreakBidiStatus
Eor), static_cast<WTF::Unicode::Direction>(m_lineBreakBidiStatusLastStrong), sta
tic_cast<WTF::Unicode::Direction>(m_lineBreakBidiStatusLast), m_lineBreakContext
); |
| 521 } | 521 } |
| 522 | 522 |
| 523 void RootInlineBox::setLineBreakInfo(RenderObject* obj, unsigned breakPos, const
BidiStatus& status) | 523 void RootInlineBox::setLineBreakInfo(LayoutObject* obj, unsigned breakPos, const
BidiStatus& status) |
| 524 { | 524 { |
| 525 // When setting lineBreakObj, the RenderObject must not be a RenderInline | 525 // When setting lineBreakObj, the LayoutObject must not be a RenderInline |
| 526 // with no line boxes, otherwise all sorts of invariants are broken later. | 526 // with no line boxes, otherwise all sorts of invariants are broken later. |
| 527 // This has security implications because if the RenderObject does not | 527 // This has security implications because if the LayoutObject does not |
| 528 // point to at least one line box, then that RenderInline can be deleted | 528 // point to at least one line box, then that RenderInline can be deleted |
| 529 // later without resetting the lineBreakObj, leading to use-after-free. | 529 // later without resetting the lineBreakObj, leading to use-after-free. |
| 530 ASSERT_WITH_SECURITY_IMPLICATION(!obj || obj->isText() || !(obj->isRenderInl
ine() && obj->isBox() && !toRenderBox(obj)->inlineBoxWrapper())); | 530 ASSERT_WITH_SECURITY_IMPLICATION(!obj || obj->isText() || !(obj->isRenderInl
ine() && obj->isBox() && !toRenderBox(obj)->inlineBoxWrapper())); |
| 531 | 531 |
| 532 m_lineBreakObj = obj; | 532 m_lineBreakObj = obj; |
| 533 m_lineBreakPos = breakPos; | 533 m_lineBreakPos = breakPos; |
| 534 m_lineBreakBidiStatusEor = status.eor; | 534 m_lineBreakBidiStatusEor = status.eor; |
| 535 m_lineBreakBidiStatusLastStrong = status.lastStrong; | 535 m_lineBreakBidiStatusLastStrong = status.lastStrong; |
| 536 m_lineBreakBidiStatusLast = status.last; | 536 m_lineBreakBidiStatusLast = status.last; |
| 537 m_lineBreakContext = status.context; | 537 m_lineBreakContext = status.context; |
| 538 } | 538 } |
| 539 | 539 |
| 540 EllipsisBox* RootInlineBox::ellipsisBox() const | 540 EllipsisBox* RootInlineBox::ellipsisBox() const |
| 541 { | 541 { |
| 542 if (!hasEllipsisBox()) | 542 if (!hasEllipsisBox()) |
| 543 return 0; | 543 return 0; |
| 544 return gEllipsisBoxMap->get(this); | 544 return gEllipsisBoxMap->get(this); |
| 545 } | 545 } |
| 546 | 546 |
| 547 void RootInlineBox::removeLineBoxFromRenderObject() | 547 void RootInlineBox::removeLineBoxFromLayoutObject() |
| 548 { | 548 { |
| 549 block().lineBoxes()->removeLineBox(this); | 549 block().lineBoxes()->removeLineBox(this); |
| 550 } | 550 } |
| 551 | 551 |
| 552 void RootInlineBox::extractLineBoxFromRenderObject() | 552 void RootInlineBox::extractLineBoxFromLayoutObject() |
| 553 { | 553 { |
| 554 block().lineBoxes()->extractLineBox(this); | 554 block().lineBoxes()->extractLineBox(this); |
| 555 } | 555 } |
| 556 | 556 |
| 557 void RootInlineBox::attachLineBoxToRenderObject() | 557 void RootInlineBox::attachLineBoxToLayoutObject() |
| 558 { | 558 { |
| 559 block().lineBoxes()->attachLineBox(this); | 559 block().lineBoxes()->attachLineBox(this); |
| 560 } | 560 } |
| 561 | 561 |
| 562 LayoutRect RootInlineBox::paddedLayoutOverflowRect(LayoutUnit endPadding) const | 562 LayoutRect RootInlineBox::paddedLayoutOverflowRect(LayoutUnit endPadding) const |
| 563 { | 563 { |
| 564 LayoutRect lineLayoutOverflow = layoutOverflowRect(lineTop(), lineBottom()); | 564 LayoutRect lineLayoutOverflow = layoutOverflowRect(lineTop(), lineBottom()); |
| 565 if (!endPadding) | 565 if (!endPadding) |
| 566 return lineLayoutOverflow; | 566 return lineLayoutOverflow; |
| 567 | 567 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 LayoutUnit verticalPosition = verticalPositionCache.get(renderer, baseli
neType()); | 712 LayoutUnit verticalPosition = verticalPositionCache.get(renderer, baseli
neType()); |
| 713 if (verticalPosition != PositionUndefined) | 713 if (verticalPosition != PositionUndefined) |
| 714 return verticalPosition; | 714 return verticalPosition; |
| 715 } | 715 } |
| 716 | 716 |
| 717 LayoutUnit verticalPosition = 0; | 717 LayoutUnit verticalPosition = 0; |
| 718 EVerticalAlign verticalAlign = renderer->style()->verticalAlign(); | 718 EVerticalAlign verticalAlign = renderer->style()->verticalAlign(); |
| 719 if (verticalAlign == TOP || verticalAlign == BOTTOM) | 719 if (verticalAlign == TOP || verticalAlign == BOTTOM) |
| 720 return 0; | 720 return 0; |
| 721 | 721 |
| 722 RenderObject* parent = renderer->parent(); | 722 LayoutObject* parent = renderer->parent(); |
| 723 if (parent->isRenderInline() && parent->style()->verticalAlign() != TOP && p
arent->style()->verticalAlign() != BOTTOM) | 723 if (parent->isRenderInline() && parent->style()->verticalAlign() != TOP && p
arent->style()->verticalAlign() != BOTTOM) |
| 724 verticalPosition = box->parent()->logicalTop(); | 724 verticalPosition = box->parent()->logicalTop(); |
| 725 | 725 |
| 726 if (verticalAlign != BASELINE) { | 726 if (verticalAlign != BASELINE) { |
| 727 const Font& font = parent->style(firstLine)->font(); | 727 const Font& font = parent->style(firstLine)->font(); |
| 728 const FontMetrics& fontMetrics = font.fontMetrics(); | 728 const FontMetrics& fontMetrics = font.fontMetrics(); |
| 729 int fontSize = font.fontDescription().computedPixelSize(); | 729 int fontSize = font.fontDescription().computedPixelSize(); |
| 730 | 730 |
| 731 LineDirectionMode lineDirection = parent->isHorizontalWritingMode() ? Ho
rizontalLine : VerticalLine; | 731 LineDirectionMode lineDirection = parent->isHorizontalWritingMode() ? Ho
rizontalLine : VerticalLine; |
| 732 | 732 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 } | 850 } |
| 851 | 851 |
| 852 #ifndef NDEBUG | 852 #ifndef NDEBUG |
| 853 const char* RootInlineBox::boxName() const | 853 const char* RootInlineBox::boxName() const |
| 854 { | 854 { |
| 855 return "RootInlineBox"; | 855 return "RootInlineBox"; |
| 856 } | 856 } |
| 857 #endif | 857 #endif |
| 858 | 858 |
| 859 } // namespace blink | 859 } // namespace blink |
| OLD | NEW |