OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2007 David Smith (catfish.man@gmail.com) | 4 * (C) 2007 David Smith (catfish.man@gmail.com) |
5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc.
All rights reserved. | 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc.
All rights reserved. |
6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
(...skipping 1340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1351 gDelayedUpdateScrollInfoSet->add(this); | 1351 gDelayedUpdateScrollInfoSet->add(this); |
1352 else | 1352 else |
1353 layer()->scrollableArea()->updateAfterLayout(); | 1353 layer()->scrollableArea()->updateAfterLayout(); |
1354 } | 1354 } |
1355 } | 1355 } |
1356 | 1356 |
1357 void RenderBlock::layout() | 1357 void RenderBlock::layout() |
1358 { | 1358 { |
1359 OverflowEventDispatcher dispatcher(this); | 1359 OverflowEventDispatcher dispatcher(this); |
1360 | 1360 |
| 1361 // Update our first letter info now. |
| 1362 updateFirstLetter(); |
| 1363 |
1361 // Table cells call layoutBlock directly, so don't add any logic here. Put
code into | 1364 // Table cells call layoutBlock directly, so don't add any logic here. Put
code into |
1362 // layoutBlock(). | 1365 // layoutBlock(). |
1363 layoutBlock(false); | 1366 layoutBlock(false); |
1364 | 1367 |
1365 // It's safe to check for control clip here, since controls can never be tab
le cells. | 1368 // It's safe to check for control clip here, since controls can never be tab
le cells. |
1366 // If we have a lightweight clip, there can never be any overflow from child
ren. | 1369 // If we have a lightweight clip, there can never be any overflow from child
ren. |
1367 if (hasControlClip() && m_overflow) | 1370 if (hasControlClip() && m_overflow) |
1368 clearLayoutOverflow(); | 1371 clearLayoutOverflow(); |
1369 | 1372 |
1370 invalidateBackgroundObscurationStatus(); | 1373 invalidateBackgroundObscurationStatus(); |
(...skipping 1790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3161 | 3164 |
3162 int scrollbarWidth = instrinsicScrollbarLogicalWidth(); | 3165 int scrollbarWidth = instrinsicScrollbarLogicalWidth(); |
3163 maxLogicalWidth += scrollbarWidth; | 3166 maxLogicalWidth += scrollbarWidth; |
3164 minLogicalWidth += scrollbarWidth; | 3167 minLogicalWidth += scrollbarWidth; |
3165 } | 3168 } |
3166 | 3169 |
3167 void RenderBlock::computePreferredLogicalWidths() | 3170 void RenderBlock::computePreferredLogicalWidths() |
3168 { | 3171 { |
3169 ASSERT(preferredLogicalWidthsDirty()); | 3172 ASSERT(preferredLogicalWidthsDirty()); |
3170 | 3173 |
| 3174 updateFirstLetter(); |
| 3175 |
3171 m_minPreferredLogicalWidth = 0; | 3176 m_minPreferredLogicalWidth = 0; |
3172 m_maxPreferredLogicalWidth = 0; | 3177 m_maxPreferredLogicalWidth = 0; |
3173 | 3178 |
3174 // FIXME: The isFixed() calls here should probably be checking for isSpecifi
ed since you | 3179 // FIXME: The isFixed() calls here should probably be checking for isSpecifi
ed since you |
3175 // should be able to use percentage, calc or viewport relative values for wi
dth. | 3180 // should be able to use percentage, calc or viewport relative values for wi
dth. |
3176 RenderStyle* styleToUse = style(); | 3181 RenderStyle* styleToUse = style(); |
3177 if (!isTableCell() && styleToUse->logicalWidth().isFixed() && styleToUse->lo
gicalWidth().value() >= 0 | 3182 if (!isTableCell() && styleToUse->logicalWidth().isFixed() && styleToUse->lo
gicalWidth().value() >= 0 |
3178 && !(isDeprecatedFlexItem() && !styleToUse->logicalWidth().intValue())) | 3183 && !(isDeprecatedFlexItem() && !styleToUse->logicalWidth().intValue())) |
3179 m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = adjustContentB
oxLogicalWidthForBoxSizing(styleToUse->logicalWidth().value()); | 3184 m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = adjustContentB
oxLogicalWidthForBoxSizing(styleToUse->logicalWidth().value()); |
3180 else | 3185 else |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3516 break; | 3521 break; |
3517 firstLineBlock = toRenderBlock(parentBlock); | 3522 firstLineBlock = toRenderBlock(parentBlock); |
3518 } | 3523 } |
3519 | 3524 |
3520 if (!hasPseudo) | 3525 if (!hasPseudo) |
3521 return 0; | 3526 return 0; |
3522 | 3527 |
3523 return firstLineBlock; | 3528 return firstLineBlock; |
3524 } | 3529 } |
3525 | 3530 |
| 3531 static RenderStyle* styleForFirstLetter(RenderObject* firstLetterBlock, RenderOb
ject* firstLetterContainer) |
| 3532 { |
| 3533 RenderStyle* pseudoStyle = firstLetterBlock->getCachedPseudoStyle(FIRST_LETT
ER, firstLetterContainer->firstLineStyle()); |
| 3534 // Force inline display (except for floating first-letters). |
| 3535 pseudoStyle->setDisplay(pseudoStyle->isFloating() ? BLOCK : INLINE); |
| 3536 // CSS2 says first-letter can't be positioned. |
| 3537 pseudoStyle->setPosition(StaticPosition); |
| 3538 return pseudoStyle; |
| 3539 } |
| 3540 |
| 3541 // CSS 2.1 http://www.w3.org/TR/CSS21/selector.html#first-letter |
| 3542 // "Punctuation (i.e, characters defined in Unicode [UNICODE] in the "open" (Ps)
, "close" (Pe), |
| 3543 // "initial" (Pi). "final" (Pf) and "other" (Po) punctuation classes), that prec
edes or follows the first letter should be included" |
| 3544 static inline bool isPunctuationForFirstLetter(UChar c) |
| 3545 { |
| 3546 CharCategory charCategory = category(c); |
| 3547 return charCategory == Punctuation_Open |
| 3548 || charCategory == Punctuation_Close |
| 3549 || charCategory == Punctuation_InitialQuote |
| 3550 || charCategory == Punctuation_FinalQuote |
| 3551 || charCategory == Punctuation_Other; |
| 3552 } |
| 3553 |
| 3554 static inline bool isSpaceForFirstLetter(UChar c) |
| 3555 { |
| 3556 return isSpaceOrNewline(c) || c == noBreakSpace; |
| 3557 } |
| 3558 |
| 3559 static inline RenderObject* findFirstLetterBlock(RenderBlock* start) |
| 3560 { |
| 3561 RenderObject* firstLetterBlock = start; |
| 3562 while (true) { |
| 3563 bool canHaveFirstLetterRenderer = firstLetterBlock->style()->hasPseudoSt
yle(FIRST_LETTER) |
| 3564 && firstLetterBlock->canHaveGeneratedChildren() |
| 3565 && isRenderBlockFlowOrRenderButton(firstLetterBlock); |
| 3566 if (canHaveFirstLetterRenderer) |
| 3567 return firstLetterBlock; |
| 3568 |
| 3569 RenderObject* parentBlock = firstLetterBlock->parent(); |
| 3570 if (firstLetterBlock->isReplaced() || !parentBlock |
| 3571 || !isRenderBlockFlowOrRenderButton(parentBlock)) { |
| 3572 return 0; |
| 3573 } |
| 3574 ASSERT(parentBlock->isRenderBlock()); |
| 3575 if (toRenderBlock(parentBlock)->firstChild() != firstLetterBlock) |
| 3576 return 0; |
| 3577 firstLetterBlock = parentBlock; |
| 3578 } |
| 3579 |
| 3580 return 0; |
| 3581 } |
| 3582 |
| 3583 void RenderBlock::updateFirstLetterStyle(RenderObject* firstLetterBlock, RenderO
bject* currentChild) |
| 3584 { |
| 3585 RenderObject* firstLetter = currentChild->parent(); |
| 3586 RenderObject* firstLetterContainer = firstLetter->parent(); |
| 3587 RenderStyle* pseudoStyle = styleForFirstLetter(firstLetterBlock, firstLetter
Container); |
| 3588 ASSERT(firstLetter->isFloating() || firstLetter->isInline()); |
| 3589 |
| 3590 if (RenderStyle::stylePropagationDiff(firstLetter->style(), pseudoStyle) ==
Reattach) { |
| 3591 // The first-letter renderer needs to be replaced. Create a new renderer
of the right type. |
| 3592 RenderBoxModelObject* newFirstLetter; |
| 3593 if (pseudoStyle->display() == INLINE) |
| 3594 newFirstLetter = RenderInline::createAnonymous(&document()); |
| 3595 else |
| 3596 newFirstLetter = RenderBlockFlow::createAnonymous(&document()); |
| 3597 newFirstLetter->setStyle(pseudoStyle); |
| 3598 |
| 3599 // Move the first letter into the new renderer. |
| 3600 while (RenderObject* child = firstLetter->slowFirstChild()) { |
| 3601 if (child->isText()) |
| 3602 toRenderText(child)->removeAndDestroyTextBoxes(); |
| 3603 firstLetter->removeChild(child); |
| 3604 newFirstLetter->addChild(child, 0); |
| 3605 } |
| 3606 |
| 3607 RenderObject* nextSibling = firstLetter->nextSibling(); |
| 3608 if (RenderTextFragment* remainingText = toRenderBoxModelObject(firstLett
er)->firstLetterRemainingText()) { |
| 3609 ASSERT(remainingText->isAnonymous() || remainingText->node()->render
er() == remainingText); |
| 3610 // Replace the old renderer with the new one. |
| 3611 remainingText->setFirstLetter(newFirstLetter); |
| 3612 newFirstLetter->setFirstLetterRemainingText(remainingText); |
| 3613 } |
| 3614 // To prevent removal of single anonymous block in RenderBlock::removeCh
ild and causing |
| 3615 // |nextSibling| to go stale, we remove the old first letter using remov
eChildNode first. |
| 3616 firstLetterContainer->virtualChildren()->removeChildNode(firstLetterCont
ainer, firstLetter); |
| 3617 firstLetter->destroy(); |
| 3618 firstLetter = newFirstLetter; |
| 3619 firstLetterContainer->addChild(firstLetter, nextSibling); |
| 3620 } else { |
| 3621 firstLetter->setStyle(pseudoStyle); |
| 3622 } |
| 3623 |
| 3624 for (RenderObject* genChild = firstLetter->slowFirstChild(); genChild; genCh
ild = genChild->nextSibling()) { |
| 3625 if (genChild->isText()) |
| 3626 genChild->setStyle(pseudoStyle); |
| 3627 } |
| 3628 } |
| 3629 |
| 3630 static inline unsigned firstLetterLength(const String& text) |
| 3631 { |
| 3632 unsigned length = 0; |
| 3633 unsigned textLength = text.length(); |
| 3634 |
| 3635 // Account for leading spaces first. |
| 3636 while (length < textLength && isSpaceForFirstLetter(text[length])) |
| 3637 length++; |
| 3638 |
| 3639 // Now account for leading punctuation. |
| 3640 while (length < textLength && isPunctuationForFirstLetter(text[length])) |
| 3641 length++; |
| 3642 |
| 3643 // Bail if we didn't find a letter before the end of the text or before a sp
ace. |
| 3644 if (isSpaceForFirstLetter(text[length]) || (textLength && length == textLeng
th)) |
| 3645 return 0; |
| 3646 |
| 3647 // Account the next character for first letter. |
| 3648 length++; |
| 3649 |
| 3650 // Keep looking allowed punctuation for the :first-letter. |
| 3651 for (unsigned scanLength = length; scanLength < textLength; ++scanLength) { |
| 3652 UChar c = text[scanLength]; |
| 3653 |
| 3654 if (!isPunctuationForFirstLetter(c)) |
| 3655 break; |
| 3656 |
| 3657 length = scanLength + 1; |
| 3658 } |
| 3659 |
| 3660 // FIXME: If textLength is 0, length may still be 1! |
| 3661 return length; |
| 3662 } |
| 3663 |
| 3664 void RenderBlock::createFirstLetterRenderer(RenderObject* firstLetterBlock, Rend
erText& currentChild, unsigned length) |
| 3665 { |
| 3666 ASSERT(length); |
| 3667 |
| 3668 RenderObject* firstLetterContainer = currentChild.parent(); |
| 3669 RenderStyle* pseudoStyle = styleForFirstLetter(firstLetterBlock, firstLetter
Container); |
| 3670 RenderBoxModelObject* firstLetter = 0; |
| 3671 if (pseudoStyle->display() == INLINE) |
| 3672 firstLetter = RenderInline::createAnonymous(&document()); |
| 3673 else |
| 3674 firstLetter = RenderBlockFlow::createAnonymous(&document()); |
| 3675 firstLetter->setStyle(pseudoStyle); |
| 3676 |
| 3677 // FIXME: The first letter code should not modify the render tree during |
| 3678 // layout. crbug.com/370458 |
| 3679 DeprecatedDisableModifyRenderTreeStructureAsserts disabler; |
| 3680 |
| 3681 firstLetterContainer->addChild(firstLetter, ¤tChild); |
| 3682 |
| 3683 // The original string is going to be either a generated content string or a
DOM node's |
| 3684 // string. We want the original string before it got transformed in case fi
rst-letter has |
| 3685 // no text-transform or a different text-transform applied to it. |
| 3686 String oldText = currentChild.originalText(); |
| 3687 ASSERT(oldText.impl()); |
| 3688 |
| 3689 // Construct a text fragment for the text after the first letter. |
| 3690 // This text fragment might be empty. |
| 3691 RenderTextFragment* remainingText = |
| 3692 new RenderTextFragment(currentChild.node() ? currentChild.node() : &curr
entChild.document(), oldText.impl(), length, oldText.length() - length); |
| 3693 remainingText->setStyle(currentChild.style()); |
| 3694 if (remainingText->node()) |
| 3695 remainingText->node()->setRenderer(remainingText); |
| 3696 |
| 3697 firstLetterContainer->addChild(remainingText, ¤tChild); |
| 3698 firstLetterContainer->removeChild(¤tChild); |
| 3699 remainingText->setFirstLetter(firstLetter); |
| 3700 firstLetter->setFirstLetterRemainingText(remainingText); |
| 3701 |
| 3702 // construct text fragment for the first letter |
| 3703 RenderTextFragment* letter = |
| 3704 new RenderTextFragment(remainingText->node() ? remainingText->node() : &
remainingText->document(), oldText.impl(), 0, length); |
| 3705 letter->setStyle(pseudoStyle); |
| 3706 firstLetter->addChild(letter); |
| 3707 |
| 3708 currentChild.destroy(); |
| 3709 } |
| 3710 |
| 3711 void RenderBlock::updateFirstLetter() |
| 3712 { |
| 3713 if (!document().styleEngine()->usesFirstLetterRules()) |
| 3714 return; |
| 3715 // Don't recur |
| 3716 if (style()->styleType() == FIRST_LETTER) |
| 3717 return; |
| 3718 |
| 3719 // FIXME: We need to destroy the first-letter object if it is no longer the
first child. Need to find |
| 3720 // an efficient way to check for that situation though before implementing a
nything. |
| 3721 RenderObject* firstLetterBlock = findFirstLetterBlock(this); |
| 3722 if (!firstLetterBlock) |
| 3723 return; |
| 3724 |
| 3725 // Drill into inlines looking for our first text child. |
| 3726 RenderObject* currChild = firstLetterBlock->slowFirstChild(); |
| 3727 unsigned length = 0; |
| 3728 while (currChild) { |
| 3729 if (currChild->isText()) { |
| 3730 // FIXME: If there is leading punctuation in a different RenderText
than |
| 3731 // the first letter, we'll not apply the correct style to it. |
| 3732 length = firstLetterLength(toRenderText(currChild)->originalText()); |
| 3733 if (length) |
| 3734 break; |
| 3735 currChild = currChild->nextSibling(); |
| 3736 } else if (currChild->isListMarker()) { |
| 3737 currChild = currChild->nextSibling(); |
| 3738 } else if (currChild->isFloatingOrOutOfFlowPositioned()) { |
| 3739 if (currChild->style()->styleType() == FIRST_LETTER) { |
| 3740 currChild = currChild->slowFirstChild(); |
| 3741 break; |
| 3742 } |
| 3743 currChild = currChild->nextSibling(); |
| 3744 } else if (currChild->isReplaced() || currChild->isRenderButton() || cur
rChild->isMenuList()) { |
| 3745 break; |
| 3746 } else if (currChild->style()->hasPseudoStyle(FIRST_LETTER) && currChild
->canHaveGeneratedChildren()) { |
| 3747 // We found a lower-level node with first-letter, which supersedes t
he higher-level style |
| 3748 firstLetterBlock = currChild; |
| 3749 currChild = currChild->slowFirstChild(); |
| 3750 } else { |
| 3751 currChild = currChild->slowFirstChild(); |
| 3752 } |
| 3753 } |
| 3754 |
| 3755 if (!currChild || !isRenderBlockFlowOrRenderButton(firstLetterBlock)) |
| 3756 return; |
| 3757 |
| 3758 // If the child already has style, then it has already been created, so we j
ust want |
| 3759 // to update it. |
| 3760 if (currChild->parent()->style()->styleType() == FIRST_LETTER) { |
| 3761 updateFirstLetterStyle(firstLetterBlock, currChild); |
| 3762 return; |
| 3763 } |
| 3764 |
| 3765 // FIXME: This black-list of disallowed RenderText subclasses is fragile. |
| 3766 // Should counter be on this list? What about RenderTextFragment? |
| 3767 if (!currChild->isText() || currChild->isBR() || toRenderText(currChild)->is
WordBreak()) |
| 3768 return; |
| 3769 |
| 3770 createFirstLetterRenderer(firstLetterBlock, toRenderText(*currChild), length
); |
| 3771 } |
| 3772 |
3526 // Helper methods for obtaining the last line, computing line counts and heights
for line counts | 3773 // Helper methods for obtaining the last line, computing line counts and heights
for line counts |
3527 // (crawling into blocks). | 3774 // (crawling into blocks). |
3528 static bool shouldCheckLines(RenderObject* obj) | 3775 static bool shouldCheckLines(RenderObject* obj) |
3529 { | 3776 { |
3530 return !obj->isFloatingOrOutOfFlowPositioned() | 3777 return !obj->isFloatingOrOutOfFlowPositioned() |
3531 && obj->isRenderBlock() && obj->style()->height().isAuto() | 3778 && obj->isRenderBlock() && obj->style()->height().isAuto() |
3532 && (!obj->isDeprecatedFlexibleBox() || obj->style()->boxOrient() == VERT
ICAL); | 3779 && (!obj->isDeprecatedFlexibleBox() || obj->style()->boxOrient() == VERT
ICAL); |
3533 } | 3780 } |
3534 | 3781 |
3535 static int getHeightForLineCount(RenderBlock* block, int l, bool includeBottom,
int& count) | 3782 static int getHeightForLineCount(RenderBlock* block, int l, bool includeBottom,
int& count) |
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4112 void RenderBlock::showLineTreeAndMark(const InlineBox* markedBox1, const char* m
arkedLabel1, const InlineBox* markedBox2, const char* markedLabel2, const Render
Object* obj) const | 4359 void RenderBlock::showLineTreeAndMark(const InlineBox* markedBox1, const char* m
arkedLabel1, const InlineBox* markedBox2, const char* markedLabel2, const Render
Object* obj) const |
4113 { | 4360 { |
4114 showRenderObject(); | 4361 showRenderObject(); |
4115 for (const RootInlineBox* root = firstRootBox(); root; root = root->nextRoot
Box()) | 4362 for (const RootInlineBox* root = firstRootBox(); root; root = root->nextRoot
Box()) |
4116 root->showLineTreeAndMark(markedBox1, markedLabel1, markedBox2, markedLa
bel2, obj, 1); | 4363 root->showLineTreeAndMark(markedBox1, markedLabel1, markedBox2, markedLa
bel2, obj, 1); |
4117 } | 4364 } |
4118 | 4365 |
4119 #endif | 4366 #endif |
4120 | 4367 |
4121 } // namespace blink | 4368 } // namespace blink |
OLD | NEW |