| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 // The only place where a ruby base can be is in the last position | 54 // The only place where a ruby base can be is in the last position |
| 55 // Note: As anonymous blocks, ruby runs do not have ':before' or ':after' | 55 // Note: As anonymous blocks, ruby runs do not have ':before' or ':after' |
| 56 // content themselves. | 56 // content themselves. |
| 57 return lastChild() && lastChild()->isRubyBase(); | 57 return lastChild() && lastChild()->isRubyBase(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 LayoutRubyText* LayoutRubyRun::rubyText() const { | 60 LayoutRubyText* LayoutRubyRun::rubyText() const { |
| 61 LayoutObject* child = firstChild(); | 61 LayoutObject* child = firstChild(); |
| 62 // If in future it becomes necessary to support floating or positioned ruby | 62 // If in future it becomes necessary to support floating or positioned ruby |
| 63 // text, layout will have to be changed to handle them properly. | 63 // text, layout will have to be changed to handle them properly. |
| 64 ASSERT(!child || !child->isRubyText() || | 64 DCHECK(!child || !child->isRubyText() || |
| 65 !child->isFloatingOrOutOfFlowPositioned()); | 65 !child->isFloatingOrOutOfFlowPositioned()); |
| 66 return child && child->isRubyText() ? static_cast<LayoutRubyText*>(child) : 0; | 66 return child && child->isRubyText() ? static_cast<LayoutRubyText*>(child) : 0; |
| 67 } | 67 } |
| 68 | 68 |
| 69 LayoutRubyBase* LayoutRubyRun::rubyBase() const { | 69 LayoutRubyBase* LayoutRubyRun::rubyBase() const { |
| 70 LayoutObject* child = lastChild(); | 70 LayoutObject* child = lastChild(); |
| 71 return child && child->isRubyBase() ? static_cast<LayoutRubyBase*>(child) : 0; | 71 return child && child->isRubyBase() ? static_cast<LayoutRubyBase*>(child) : 0; |
| 72 } | 72 } |
| 73 | 73 |
| 74 LayoutRubyBase* LayoutRubyRun::rubyBaseSafe() { | 74 LayoutRubyBase* LayoutRubyRun::rubyBaseSafe() { |
| 75 LayoutRubyBase* base = rubyBase(); | 75 LayoutRubyBase* base = rubyBase(); |
| 76 if (!base) { | 76 if (!base) { |
| 77 base = createRubyBase(); | 77 base = createRubyBase(); |
| 78 LayoutBlockFlow::addChild(base); | 78 LayoutBlockFlow::addChild(base); |
| 79 } | 79 } |
| 80 return base; | 80 return base; |
| 81 } | 81 } |
| 82 | 82 |
| 83 bool LayoutRubyRun::isChildAllowed(LayoutObject* child, | 83 bool LayoutRubyRun::isChildAllowed(LayoutObject* child, |
| 84 const ComputedStyle&) const { | 84 const ComputedStyle&) const { |
| 85 return child->isRubyText() || child->isInline(); | 85 return child->isRubyText() || child->isInline(); |
| 86 } | 86 } |
| 87 | 87 |
| 88 void LayoutRubyRun::addChild(LayoutObject* child, LayoutObject* beforeChild) { | 88 void LayoutRubyRun::addChild(LayoutObject* child, LayoutObject* beforeChild) { |
| 89 ASSERT(child); | 89 DCHECK(child); |
| 90 | 90 |
| 91 if (child->isRubyText()) { | 91 if (child->isRubyText()) { |
| 92 if (!beforeChild) { | 92 if (!beforeChild) { |
| 93 // LayoutRuby has already ascertained that we can add the child here. | 93 // LayoutRuby has already ascertained that we can add the child here. |
| 94 ASSERT(!hasRubyText()); | 94 DCHECK(!hasRubyText()); |
| 95 // prepend ruby texts as first child | 95 // prepend ruby texts as first child |
| 96 LayoutBlockFlow::addChild(child, firstChild()); | 96 LayoutBlockFlow::addChild(child, firstChild()); |
| 97 } else if (beforeChild->isRubyText()) { | 97 } else if (beforeChild->isRubyText()) { |
| 98 // New text is inserted just before another. | 98 // New text is inserted just before another. |
| 99 // In this case the new text takes the place of the old one, and | 99 // In this case the new text takes the place of the old one, and |
| 100 // the old text goes into a new run that is inserted as next sibling. | 100 // the old text goes into a new run that is inserted as next sibling. |
| 101 ASSERT(beforeChild->parent() == this); | 101 DCHECK_EQ(beforeChild->parent(), this); |
| 102 LayoutObject* ruby = parent(); | 102 LayoutObject* ruby = parent(); |
| 103 ASSERT(ruby->isRuby()); | 103 DCHECK(ruby->isRuby()); |
| 104 LayoutBlock* newRun = staticCreateRubyRun(ruby); | 104 LayoutBlock* newRun = staticCreateRubyRun(ruby); |
| 105 ruby->addChild(newRun, nextSibling()); | 105 ruby->addChild(newRun, nextSibling()); |
| 106 // Add the new ruby text and move the old one to the new run | 106 // Add the new ruby text and move the old one to the new run |
| 107 // Note: Doing it in this order and not using LayoutRubyRun's methods, | 107 // Note: Doing it in this order and not using LayoutRubyRun's methods, |
| 108 // in order to avoid automatic removal of the ruby run in case there is no | 108 // in order to avoid automatic removal of the ruby run in case there is no |
| 109 // other child besides the old ruby text. | 109 // other child besides the old ruby text. |
| 110 LayoutBlockFlow::addChild(child, beforeChild); | 110 LayoutBlockFlow::addChild(child, beforeChild); |
| 111 LayoutBlockFlow::removeChild(beforeChild); | 111 LayoutBlockFlow::removeChild(beforeChild); |
| 112 newRun->addChild(beforeChild); | 112 newRun->addChild(beforeChild); |
| 113 } else if (hasRubyBase()) { | 113 } else if (hasRubyBase()) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 126 rubyBaseSafe()->moveChildren(newRun->rubyBaseSafe(), beforeChild); | 126 rubyBaseSafe()->moveChildren(newRun->rubyBaseSafe(), beforeChild); |
| 127 } | 127 } |
| 128 } else { | 128 } else { |
| 129 // child is not a text -> insert it into the base | 129 // child is not a text -> insert it into the base |
| 130 // (append it instead if beforeChild is the ruby text) | 130 // (append it instead if beforeChild is the ruby text) |
| 131 LayoutRubyBase* base = rubyBaseSafe(); | 131 LayoutRubyBase* base = rubyBaseSafe(); |
| 132 if (beforeChild == base) | 132 if (beforeChild == base) |
| 133 beforeChild = base->firstChild(); | 133 beforeChild = base->firstChild(); |
| 134 if (beforeChild && beforeChild->isRubyText()) | 134 if (beforeChild && beforeChild->isRubyText()) |
| 135 beforeChild = 0; | 135 beforeChild = 0; |
| 136 ASSERT(!beforeChild || beforeChild->isDescendantOf(base)); | 136 DCHECK(!beforeChild || beforeChild->isDescendantOf(base)); |
| 137 base->addChild(child, beforeChild); | 137 base->addChild(child, beforeChild); |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 | 140 |
| 141 void LayoutRubyRun::removeChild(LayoutObject* child) { | 141 void LayoutRubyRun::removeChild(LayoutObject* child) { |
| 142 // If the child is a ruby text, then merge the ruby base with the base of | 142 // If the child is a ruby text, then merge the ruby base with the base of |
| 143 // the right sibling run, if possible. | 143 // the right sibling run, if possible. |
| 144 if (!beingDestroyed() && !documentBeingDestroyed() && child->isRubyText()) { | 144 if (!beingDestroyed() && !documentBeingDestroyed() && child->isRubyText()) { |
| 145 LayoutRubyBase* base = rubyBase(); | 145 LayoutRubyBase* base = rubyBase(); |
| 146 LayoutObject* rightNeighbour = nextSibling(); | 146 LayoutObject* rightNeighbour = nextSibling(); |
| 147 if (base && rightNeighbour && rightNeighbour->isRubyRun()) { | 147 if (base && rightNeighbour && rightNeighbour->isRubyRun()) { |
| 148 // Ruby run without a base can happen only at the first run. | 148 // Ruby run without a base can happen only at the first run. |
| 149 LayoutRubyRun* rightRun = toLayoutRubyRun(rightNeighbour); | 149 LayoutRubyRun* rightRun = toLayoutRubyRun(rightNeighbour); |
| 150 if (rightRun->hasRubyBase()) { | 150 if (rightRun->hasRubyBase()) { |
| 151 LayoutRubyBase* rightBase = rightRun->rubyBaseSafe(); | 151 LayoutRubyBase* rightBase = rightRun->rubyBaseSafe(); |
| 152 // Collect all children in a single base, then swap the bases. | 152 // Collect all children in a single base, then swap the bases. |
| 153 rightBase->moveChildren(base); | 153 rightBase->moveChildren(base); |
| 154 moveChildTo(rightRun, base); | 154 moveChildTo(rightRun, base); |
| 155 rightRun->moveChildTo(this, rightBase); | 155 rightRun->moveChildTo(this, rightBase); |
| 156 // The now empty ruby base will be removed below. | 156 // The now empty ruby base will be removed below. |
| 157 ASSERT(!rubyBase()->firstChild()); | 157 DCHECK(!rubyBase()->firstChild()); |
| 158 } | 158 } |
| 159 } | 159 } |
| 160 } | 160 } |
| 161 | 161 |
| 162 LayoutBlockFlow::removeChild(child); | 162 LayoutBlockFlow::removeChild(child); |
| 163 | 163 |
| 164 if (!beingDestroyed() && !documentBeingDestroyed()) { | 164 if (!beingDestroyed() && !documentBeingDestroyed()) { |
| 165 // Check if our base (if any) is now empty. If so, destroy it. | 165 // Check if our base (if any) is now empty. If so, destroy it. |
| 166 LayoutBlockFlow* base = rubyBase(); | 166 LayoutBlockFlow* base = rubyBase(); |
| 167 if (base && !base->firstChild()) { | 167 if (base && !base->firstChild()) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 183 RefPtr<ComputedStyle> newStyle = | 183 RefPtr<ComputedStyle> newStyle = |
| 184 ComputedStyle::createAnonymousStyleWithDisplay(styleRef(), | 184 ComputedStyle::createAnonymousStyleWithDisplay(styleRef(), |
| 185 EDisplay::kBlock); | 185 EDisplay::kBlock); |
| 186 newStyle->setTextAlign(ETextAlign::kCenter); // FIXME: use WEBKIT_CENTER? | 186 newStyle->setTextAlign(ETextAlign::kCenter); // FIXME: use WEBKIT_CENTER? |
| 187 layoutObject->setStyle(std::move(newStyle)); | 187 layoutObject->setStyle(std::move(newStyle)); |
| 188 return layoutObject; | 188 return layoutObject; |
| 189 } | 189 } |
| 190 | 190 |
| 191 LayoutRubyRun* LayoutRubyRun::staticCreateRubyRun( | 191 LayoutRubyRun* LayoutRubyRun::staticCreateRubyRun( |
| 192 const LayoutObject* parentRuby) { | 192 const LayoutObject* parentRuby) { |
| 193 ASSERT(parentRuby && parentRuby->isRuby()); | 193 DCHECK(parentRuby); |
| 194 DCHECK(parentRuby->isRuby()); |
| 194 LayoutRubyRun* rr = new LayoutRubyRun(); | 195 LayoutRubyRun* rr = new LayoutRubyRun(); |
| 195 rr->setDocumentForAnonymous(&parentRuby->document()); | 196 rr->setDocumentForAnonymous(&parentRuby->document()); |
| 196 RefPtr<ComputedStyle> newStyle = | 197 RefPtr<ComputedStyle> newStyle = |
| 197 ComputedStyle::createAnonymousStyleWithDisplay(parentRuby->styleRef(), | 198 ComputedStyle::createAnonymousStyleWithDisplay(parentRuby->styleRef(), |
| 198 EDisplay::kInlineBlock); | 199 EDisplay::kInlineBlock); |
| 199 rr->setStyle(std::move(newStyle)); | 200 rr->setStyle(std::move(newStyle)); |
| 200 return rr; | 201 return rr; |
| 201 } | 202 } |
| 202 | 203 |
| 203 LayoutObject* LayoutRubyRun::layoutSpecialExcludedChild( | 204 LayoutObject* LayoutRubyRun::layoutSpecialExcludedChild( |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 | 259 |
| 259 // Update our overflow to account for the new LayoutRubyText position. | 260 // Update our overflow to account for the new LayoutRubyText position. |
| 260 computeOverflow(clientLogicalBottom()); | 261 computeOverflow(clientLogicalBottom()); |
| 261 } | 262 } |
| 262 | 263 |
| 263 void LayoutRubyRun::getOverhang(bool firstLine, | 264 void LayoutRubyRun::getOverhang(bool firstLine, |
| 264 LayoutObject* startLayoutObject, | 265 LayoutObject* startLayoutObject, |
| 265 LayoutObject* endLayoutObject, | 266 LayoutObject* endLayoutObject, |
| 266 int& startOverhang, | 267 int& startOverhang, |
| 267 int& endOverhang) const { | 268 int& endOverhang) const { |
| 268 ASSERT(!needsLayout()); | 269 DCHECK(!needsLayout()); |
| 269 | 270 |
| 270 startOverhang = 0; | 271 startOverhang = 0; |
| 271 endOverhang = 0; | 272 endOverhang = 0; |
| 272 | 273 |
| 273 LayoutRubyBase* rubyBase = this->rubyBase(); | 274 LayoutRubyBase* rubyBase = this->rubyBase(); |
| 274 LayoutRubyText* rubyText = this->rubyText(); | 275 LayoutRubyText* rubyText = this->rubyText(); |
| 275 | 276 |
| 276 if (!rubyBase || !rubyText) | 277 if (!rubyBase || !rubyText) |
| 277 return; | 278 return; |
| 278 | 279 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 case U_LB_GLUE: | 344 case U_LB_GLUE: |
| 344 case U_LB_OPEN_PUNCTUATION: | 345 case U_LB_OPEN_PUNCTUATION: |
| 345 return false; | 346 return false; |
| 346 default: | 347 default: |
| 347 break; | 348 break; |
| 348 } | 349 } |
| 349 return true; | 350 return true; |
| 350 } | 351 } |
| 351 | 352 |
| 352 } // namespace blink | 353 } // namespace blink |
| OLD | NEW |