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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 { | 84 { |
85 RenderObject* child = lastChild(); | 85 RenderObject* child = lastChild(); |
86 return child && child->isRubyBase() ? static_cast<RenderRubyBase*>(child) :
0; | 86 return child && child->isRubyBase() ? static_cast<RenderRubyBase*>(child) :
0; |
87 } | 87 } |
88 | 88 |
89 RenderRubyBase* RenderRubyRun::rubyBaseSafe() | 89 RenderRubyBase* RenderRubyRun::rubyBaseSafe() |
90 { | 90 { |
91 RenderRubyBase* base = rubyBase(); | 91 RenderRubyBase* base = rubyBase(); |
92 if (!base) { | 92 if (!base) { |
93 base = createRubyBase(); | 93 base = createRubyBase(); |
94 RenderBlock::addChild(base); | 94 RenderBlockFlow::addChild(base); |
95 } | 95 } |
96 return base; | 96 return base; |
97 } | 97 } |
98 | 98 |
99 RenderBlock* RenderRubyRun::firstLineBlock() const | 99 RenderBlock* RenderRubyRun::firstLineBlock() const |
100 { | 100 { |
101 return 0; | 101 return 0; |
102 } | 102 } |
103 | 103 |
104 void RenderRubyRun::updateFirstLetter() | 104 void RenderRubyRun::updateFirstLetter() |
105 { | 105 { |
106 } | 106 } |
107 | 107 |
108 bool RenderRubyRun::isChildAllowed(RenderObject* child, RenderStyle*) const | 108 bool RenderRubyRun::isChildAllowed(RenderObject* child, RenderStyle*) const |
109 { | 109 { |
110 return child->isRubyText() || child->isInline(); | 110 return child->isRubyText() || child->isInline(); |
111 } | 111 } |
112 | 112 |
113 void RenderRubyRun::addChild(RenderObject* child, RenderObject* beforeChild) | 113 void RenderRubyRun::addChild(RenderObject* child, RenderObject* beforeChild) |
114 { | 114 { |
115 ASSERT(child); | 115 ASSERT(child); |
116 | 116 |
117 if (child->isRubyText()) { | 117 if (child->isRubyText()) { |
118 if (!beforeChild) { | 118 if (!beforeChild) { |
119 // RenderRuby has already ascertained that we can add the child here
. | 119 // RenderRuby has already ascertained that we can add the child here
. |
120 ASSERT(!hasRubyText()); | 120 ASSERT(!hasRubyText()); |
121 // prepend ruby texts as first child | 121 // prepend ruby texts as first child |
122 RenderBlock::addChild(child, firstChild()); | 122 RenderBlockFlow::addChild(child, firstChild()); |
123 } else if (beforeChild->isRubyText()) { | 123 } else if (beforeChild->isRubyText()) { |
124 // New text is inserted just before another. | 124 // New text is inserted just before another. |
125 // In this case the new text takes the place of the old one, and | 125 // In this case the new text takes the place of the old one, and |
126 // the old text goes into a new run that is inserted as next sibling
. | 126 // the old text goes into a new run that is inserted as next sibling
. |
127 ASSERT(beforeChild->parent() == this); | 127 ASSERT(beforeChild->parent() == this); |
128 RenderObject* ruby = parent(); | 128 RenderObject* ruby = parent(); |
129 ASSERT(ruby->isRuby()); | 129 ASSERT(ruby->isRuby()); |
130 RenderBlock* newRun = staticCreateRubyRun(ruby); | 130 RenderBlock* newRun = staticCreateRubyRun(ruby); |
131 ruby->addChild(newRun, nextSibling()); | 131 ruby->addChild(newRun, nextSibling()); |
132 // Add the new ruby text and move the old one to the new run | 132 // Add the new ruby text and move the old one to the new run |
133 // Note: Doing it in this order and not using RenderRubyRun's method
s, | 133 // Note: Doing it in this order and not using RenderRubyRun's method
s, |
134 // in order to avoid automatic removal of the ruby run in case there
is no | 134 // in order to avoid automatic removal of the ruby run in case there
is no |
135 // other child besides the old ruby text. | 135 // other child besides the old ruby text. |
136 RenderBlock::addChild(child, beforeChild); | 136 RenderBlockFlow::addChild(child, beforeChild); |
137 RenderBlock::removeChild(beforeChild); | 137 RenderBlockFlow::removeChild(beforeChild); |
138 newRun->addChild(beforeChild); | 138 newRun->addChild(beforeChild); |
139 } else if (hasRubyBase()) { | 139 } else if (hasRubyBase()) { |
140 // Insertion before a ruby base object. | 140 // Insertion before a ruby base object. |
141 // In this case we need insert a new run before the current one and
split the base. | 141 // In this case we need insert a new run before the current one and
split the base. |
142 RenderObject* ruby = parent(); | 142 RenderObject* ruby = parent(); |
143 RenderRubyRun* newRun = staticCreateRubyRun(ruby); | 143 RenderRubyRun* newRun = staticCreateRubyRun(ruby); |
144 ruby->addChild(newRun, this); | 144 ruby->addChild(newRun, this); |
145 newRun->addChild(child); | 145 newRun->addChild(child); |
146 rubyBaseSafe()->moveChildren(newRun->rubyBaseSafe(), beforeChild); | 146 rubyBaseSafe()->moveChildren(newRun->rubyBaseSafe(), beforeChild); |
147 } | 147 } |
(...skipping 21 matching lines...) Expand all Loading... |
169 // Collect all children in a single base, then swap the bases. | 169 // Collect all children in a single base, then swap the bases. |
170 rightBase->moveChildren(base); | 170 rightBase->moveChildren(base); |
171 moveChildTo(rightRun, base); | 171 moveChildTo(rightRun, base); |
172 rightRun->moveChildTo(this, rightBase); | 172 rightRun->moveChildTo(this, rightBase); |
173 // The now empty ruby base will be removed below. | 173 // The now empty ruby base will be removed below. |
174 ASSERT(!rubyBase()->firstChild()); | 174 ASSERT(!rubyBase()->firstChild()); |
175 } | 175 } |
176 } | 176 } |
177 } | 177 } |
178 | 178 |
179 RenderBlock::removeChild(child); | 179 RenderBlockFlow::removeChild(child); |
180 | 180 |
181 if (!beingDestroyed() && !documentBeingDestroyed()) { | 181 if (!beingDestroyed() && !documentBeingDestroyed()) { |
182 // Check if our base (if any) is now empty. If so, destroy it. | 182 // Check if our base (if any) is now empty. If so, destroy it. |
183 RenderBlock* base = rubyBase(); | 183 RenderBlock* base = rubyBase(); |
184 if (base && !base->firstChild()) { | 184 if (base && !base->firstChild()) { |
185 RenderBlock::removeChild(base); | 185 RenderBlockFlow::removeChild(base); |
186 base->deleteLineBoxTree(); | 186 base->deleteLineBoxTree(); |
187 base->destroy(); | 187 base->destroy(); |
188 } | 188 } |
189 | 189 |
190 // If any of the above leaves the run empty, destroy it as well. | 190 // If any of the above leaves the run empty, destroy it as well. |
191 if (isEmpty()) { | 191 if (isEmpty()) { |
192 parent()->removeChild(this); | 192 parent()->removeChild(this); |
193 deleteLineBoxTree(); | 193 deleteLineBoxTree(); |
194 destroy(); | 194 destroy(); |
195 } | 195 } |
(...skipping 27 matching lines...) Expand all Loading... |
223 return 0; | 223 return 0; |
224 if (relayoutChildren) | 224 if (relayoutChildren) |
225 layoutScope.setChildNeedsLayout(rt); | 225 layoutScope.setChildNeedsLayout(rt); |
226 rt->layoutIfNeeded(); | 226 rt->layoutIfNeeded(); |
227 return rt; | 227 return rt; |
228 } | 228 } |
229 | 229 |
230 void RenderRubyRun::layout() | 230 void RenderRubyRun::layout() |
231 { | 231 { |
232 LayoutRectRecorder recorder(*this); | 232 LayoutRectRecorder recorder(*this); |
233 RenderBlock::layout(); | 233 RenderBlockFlow::layout(); |
234 | 234 |
235 RenderRubyText* rt = rubyText(); | 235 RenderRubyText* rt = rubyText(); |
236 if (!rt) | 236 if (!rt) |
237 return; | 237 return; |
238 | 238 |
239 rt->setLogicalLeft(0); | 239 rt->setLogicalLeft(0); |
240 | 240 |
241 // Place the RenderRubyText such that its bottom is flush with the lineTop o
f the first line of the RenderRubyBase. | 241 // Place the RenderRubyText such that its bottom is flush with the lineTop o
f the first line of the RenderRubyBase. |
242 LayoutUnit lastLineRubyTextBottom = rt->logicalHeight(); | 242 LayoutUnit lastLineRubyTextBottom = rt->logicalHeight(); |
243 LayoutUnit firstLineRubyTextTop = 0; | 243 LayoutUnit firstLineRubyTextTop = 0; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 // We can overhang the ruby by no more than half the width of the neighborin
g text | 311 // We can overhang the ruby by no more than half the width of the neighborin
g text |
312 // and no more than half the font size. | 312 // and no more than half the font size. |
313 int halfWidthOfFontSize = rubyText->style(firstLine)->fontSize() / 2; | 313 int halfWidthOfFontSize = rubyText->style(firstLine)->fontSize() / 2; |
314 if (startOverhang) | 314 if (startOverhang) |
315 startOverhang = min<int>(startOverhang, min<int>(toRenderText(startRende
rer)->minLogicalWidth(), halfWidthOfFontSize)); | 315 startOverhang = min<int>(startOverhang, min<int>(toRenderText(startRende
rer)->minLogicalWidth(), halfWidthOfFontSize)); |
316 if (endOverhang) | 316 if (endOverhang) |
317 endOverhang = min<int>(endOverhang, min<int>(toRenderText(endRenderer)->
minLogicalWidth(), halfWidthOfFontSize)); | 317 endOverhang = min<int>(endOverhang, min<int>(toRenderText(endRenderer)->
minLogicalWidth(), halfWidthOfFontSize)); |
318 } | 318 } |
319 | 319 |
320 } // namespace WebCore | 320 } // namespace WebCore |
OLD | NEW |