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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 RenderBlock* newRun = staticCreateRubyRun(ruby); | 136 RenderBlock* newRun = staticCreateRubyRun(ruby); |
137 ruby->addChild(newRun, nextSibling()); | 137 ruby->addChild(newRun, nextSibling()); |
138 // Add the new ruby text and move the old one to the new run | 138 // Add the new ruby text and move the old one to the new run |
139 // Note: Doing it in this order and not using RenderRubyRun's method
s, | 139 // Note: Doing it in this order and not using RenderRubyRun's method
s, |
140 // in order to avoid automatic removal of the ruby run in case there
is no | 140 // in order to avoid automatic removal of the ruby run in case there
is no |
141 // other child besides the old ruby text. | 141 // other child besides the old ruby text. |
142 RenderBlock::addChild(child, beforeChild); | 142 RenderBlock::addChild(child, beforeChild); |
143 RenderBlock::removeChild(beforeChild); | 143 RenderBlock::removeChild(beforeChild); |
144 newRun->addChild(beforeChild); | 144 newRun->addChild(beforeChild); |
145 } else { | 145 } else { |
146 ASSERT(hasRubyBase()); // Otherwise beforeChild would be borked. | 146 if (hasRubyBase()) { |
147 // Insertion before a ruby base object. | 147 // Insertion before a ruby base object. |
148 // In this case we need insert a new run before the current one and
split the base. | 148 // In this case we need insert a new run before the current one
and split the base. |
149 RenderObject* ruby = parent(); | 149 RenderObject* ruby = parent(); |
150 RenderRubyRun* newRun = staticCreateRubyRun(ruby); | 150 RenderRubyRun* newRun = staticCreateRubyRun(ruby); |
151 ruby->addChild(newRun, this); | 151 ruby->addChild(newRun, this); |
152 newRun->addChild(child); | 152 newRun->addChild(child); |
153 rubyBaseSafe()->moveChildren(newRun->rubyBaseSafe(), beforeChild); | 153 rubyBaseSafe()->moveChildren(newRun->rubyBaseSafe(), beforeChild
); |
| 154 } |
154 } | 155 } |
155 } else { | 156 } else { |
156 // child is not a text -> insert it into the base | 157 // child is not a text -> insert it into the base |
157 // (append it instead if beforeChild is the ruby text) | 158 // (append it instead if beforeChild is the ruby text) |
158 if (beforeChild && beforeChild->isRubyText()) | 159 if (beforeChild && beforeChild->isRubyText()) |
159 beforeChild = 0; | 160 beforeChild = 0; |
160 rubyBaseSafe()->addChild(child, beforeChild); | 161 rubyBaseSafe()->addChild(child, beforeChild); |
161 } | 162 } |
162 } | 163 } |
163 | 164 |
164 void RenderRubyRun::removeChild(RenderObject* child) | 165 void RenderRubyRun::removeChild(RenderObject* child) |
165 { | 166 { |
166 // If the child is a ruby text, then merge the ruby base with the base of | 167 // If the child is a ruby text, then merge the ruby base with the base of |
167 // the right sibling run, if possible. | 168 // the right sibling run, if possible. |
168 if (!m_beingDestroyed && !documentBeingDestroyed() && child->isRubyText()) { | 169 if (!m_beingDestroyed && !documentBeingDestroyed() && child->isRubyText()) { |
169 RenderRubyBase* base = rubyBase(); | 170 RenderRubyBase* base = rubyBase(); |
170 RenderObject* rightNeighbour = nextSibling(); | 171 RenderObject* rightNeighbour = nextSibling(); |
171 if (base && rightNeighbour && rightNeighbour->isRubyRun()) { | 172 if (base && rightNeighbour && rightNeighbour->isRubyRun()) { |
172 // Ruby run without a base can happen only at the first run. | 173 // Ruby run without a base can happen only at the first run. |
173 RenderRubyRun* rightRun = static_cast<RenderRubyRun*>(rightNeighbour
); | 174 RenderRubyRun* rightRun = static_cast<RenderRubyRun*>(rightNeighbour
); |
174 ASSERT(rightRun->hasRubyBase()); | 175 if (rightRun->hasRubyBase()) { |
175 RenderRubyBase* rightBase = rightRun->rubyBaseSafe(); | 176 RenderRubyBase* rightBase = rightRun->rubyBaseSafe(); |
176 // Collect all children in a single base, then swap the bases. | 177 // Collect all children in a single base, then swap the bases. |
177 rightBase->moveChildren(base); | 178 rightBase->moveChildren(base); |
178 moveChildTo(rightRun, rightRun->children(), base); | 179 moveChildTo(rightRun, rightRun->children(), base); |
179 rightRun->moveChildTo(this, children(), rightBase); | 180 rightRun->moveChildTo(this, children(), rightBase); |
180 // The now empty ruby base will be removed below. | 181 // The now empty ruby base will be removed below. |
| 182 } |
181 } | 183 } |
182 } | 184 } |
183 | 185 |
184 RenderBlock::removeChild(child); | 186 RenderBlock::removeChild(child); |
185 | 187 |
186 if (!m_beingDestroyed && !documentBeingDestroyed()) { | 188 if (!m_beingDestroyed && !documentBeingDestroyed()) { |
187 // Check if our base (if any) is now empty. If so, destroy it. | 189 // Check if our base (if any) is now empty. If so, destroy it. |
188 RenderBlock* base = rubyBase(); | 190 RenderBlock* base = rubyBase(); |
189 if (base && !base->firstChild()) { | 191 if (base && !base->firstChild()) { |
190 RenderBlock::removeChild(base); | 192 RenderBlock::removeChild(base); |
(...skipping 28 matching lines...) Expand all Loading... |
219 RefPtr<RenderStyle> newStyle = RenderStyle::create(); | 221 RefPtr<RenderStyle> newStyle = RenderStyle::create(); |
220 newStyle->inheritFrom(parentRuby->style()); | 222 newStyle->inheritFrom(parentRuby->style()); |
221 newStyle->setDisplay(INLINE_BLOCK); | 223 newStyle->setDisplay(INLINE_BLOCK); |
222 rr->setStyle(newStyle.release()); | 224 rr->setStyle(newStyle.release()); |
223 return rr; | 225 return rr; |
224 } | 226 } |
225 | 227 |
226 } // namespace WebCore | 228 } // namespace WebCore |
227 | 229 |
228 #endif // ENABLE(RUBY) | 230 #endif // ENABLE(RUBY) |
OLD | NEW |