Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: Source/core/layout/LayoutRuby.cpp

Issue 899163003: Move rendering/RenderObject to layout/LayoutObject. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/layout/LayoutRuby.h ('k') | Source/core/layout/LayoutRubyBase.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 23 matching lines...) Expand all
34 34
35 #include "core/frame/UseCounter.h" 35 #include "core/frame/UseCounter.h"
36 #include "core/layout/LayoutRubyRun.h" 36 #include "core/layout/LayoutRubyRun.h"
37 #include "core/rendering/style/RenderStyle.h" 37 #include "core/rendering/style/RenderStyle.h"
38 #include "wtf/RefPtr.h" 38 #include "wtf/RefPtr.h"
39 39
40 namespace blink { 40 namespace blink {
41 41
42 // === generic helper functions to avoid excessive code duplication === 42 // === generic helper functions to avoid excessive code duplication ===
43 43
44 static inline bool isAnonymousRubyInlineBlock(const RenderObject* object) 44 static inline bool isAnonymousRubyInlineBlock(const LayoutObject* object)
45 { 45 {
46 ASSERT(!object 46 ASSERT(!object
47 || !object->parent()->isRuby() 47 || !object->parent()->isRuby()
48 || object->isRubyRun() 48 || object->isRubyRun()
49 || (object->isInline() && (object->isBeforeContent() || object->isAfterC ontent())) 49 || (object->isInline() && (object->isBeforeContent() || object->isAfterC ontent()))
50 || (object->isAnonymous() && object->isRenderBlock() && object->style()- >display() == INLINE_BLOCK)); 50 || (object->isAnonymous() && object->isRenderBlock() && object->style()- >display() == INLINE_BLOCK));
51 51
52 return object 52 return object
53 && object->parent()->isRuby() 53 && object->parent()->isRuby()
54 && object->isRenderBlock() 54 && object->isRenderBlock()
55 && !object->isRubyRun(); 55 && !object->isRubyRun();
56 } 56 }
57 57
58 static inline bool isRubyBeforeBlock(const RenderObject* object) 58 static inline bool isRubyBeforeBlock(const LayoutObject* object)
59 { 59 {
60 return isAnonymousRubyInlineBlock(object) 60 return isAnonymousRubyInlineBlock(object)
61 && !object->previousSibling() 61 && !object->previousSibling()
62 && toRenderBlock(object)->firstChild() 62 && toRenderBlock(object)->firstChild()
63 && toRenderBlock(object)->firstChild()->style()->styleType() == BEFORE; 63 && toRenderBlock(object)->firstChild()->style()->styleType() == BEFORE;
64 } 64 }
65 65
66 static inline bool isRubyAfterBlock(const RenderObject* object) 66 static inline bool isRubyAfterBlock(const LayoutObject* object)
67 { 67 {
68 return isAnonymousRubyInlineBlock(object) 68 return isAnonymousRubyInlineBlock(object)
69 && !object->nextSibling() 69 && !object->nextSibling()
70 && toRenderBlock(object)->firstChild() 70 && toRenderBlock(object)->firstChild()
71 && toRenderBlock(object)->firstChild()->style()->styleType() == AFTER; 71 && toRenderBlock(object)->firstChild()->style()->styleType() == AFTER;
72 } 72 }
73 73
74 static inline RenderBlock* rubyBeforeBlock(const RenderObject* ruby) 74 static inline RenderBlock* rubyBeforeBlock(const LayoutObject* ruby)
75 { 75 {
76 RenderObject* child = ruby->slowFirstChild(); 76 LayoutObject* child = ruby->slowFirstChild();
77 return isRubyBeforeBlock(child) ? toRenderBlock(child) : 0; 77 return isRubyBeforeBlock(child) ? toRenderBlock(child) : 0;
78 } 78 }
79 79
80 static inline RenderBlock* rubyAfterBlock(const RenderObject* ruby) 80 static inline RenderBlock* rubyAfterBlock(const LayoutObject* ruby)
81 { 81 {
82 RenderObject* child = ruby->slowLastChild(); 82 LayoutObject* child = ruby->slowLastChild();
83 return isRubyAfterBlock(child) ? toRenderBlock(child) : 0; 83 return isRubyAfterBlock(child) ? toRenderBlock(child) : 0;
84 } 84 }
85 85
86 static RenderBlockFlow* createAnonymousRubyInlineBlock(RenderObject* ruby) 86 static RenderBlockFlow* createAnonymousRubyInlineBlock(LayoutObject* ruby)
87 { 87 {
88 RefPtr<RenderStyle> newStyle = RenderStyle::createAnonymousStyleWithDisplay( ruby->style(), INLINE_BLOCK); 88 RefPtr<RenderStyle> newStyle = RenderStyle::createAnonymousStyleWithDisplay( ruby->style(), INLINE_BLOCK);
89 RenderBlockFlow* newBlock = RenderBlockFlow::createAnonymous(&ruby->document ()); 89 RenderBlockFlow* newBlock = RenderBlockFlow::createAnonymous(&ruby->document ());
90 newBlock->setStyle(newStyle.release()); 90 newBlock->setStyle(newStyle.release());
91 return newBlock; 91 return newBlock;
92 } 92 }
93 93
94 static LayoutRubyRun* lastRubyRun(const RenderObject* ruby) 94 static LayoutRubyRun* lastRubyRun(const LayoutObject* ruby)
95 { 95 {
96 RenderObject* child = ruby->slowLastChild(); 96 LayoutObject* child = ruby->slowLastChild();
97 if (child && !child->isRubyRun()) 97 if (child && !child->isRubyRun())
98 child = child->previousSibling(); 98 child = child->previousSibling();
99 ASSERT(!child || child->isRubyRun() || child->isBeforeContent() || child == rubyBeforeBlock(ruby)); 99 ASSERT(!child || child->isRubyRun() || child->isBeforeContent() || child == rubyBeforeBlock(ruby));
100 return child && child->isRubyRun() ? toLayoutRubyRun(child) : 0; 100 return child && child->isRubyRun() ? toLayoutRubyRun(child) : 0;
101 } 101 }
102 102
103 static inline LayoutRubyRun* findRubyRunParent(RenderObject* child) 103 static inline LayoutRubyRun* findRubyRunParent(LayoutObject* child)
104 { 104 {
105 while (child && !child->isRubyRun()) 105 while (child && !child->isRubyRun())
106 child = child->parent(); 106 child = child->parent();
107 return toLayoutRubyRun(child); 107 return toLayoutRubyRun(child);
108 } 108 }
109 109
110 // === ruby as inline object === 110 // === ruby as inline object ===
111 111
112 LayoutRubyAsInline::LayoutRubyAsInline(Element* element) 112 LayoutRubyAsInline::LayoutRubyAsInline(Element* element)
113 : RenderInline(element) 113 : RenderInline(element)
114 { 114 {
115 UseCounter::count(document(), UseCounter::RenderRuby); 115 UseCounter::count(document(), UseCounter::RenderRuby);
116 } 116 }
117 117
118 LayoutRubyAsInline::~LayoutRubyAsInline() 118 LayoutRubyAsInline::~LayoutRubyAsInline()
119 { 119 {
120 } 120 }
121 121
122 void LayoutRubyAsInline::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle) 122 void LayoutRubyAsInline::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
123 { 123 {
124 RenderInline::styleDidChange(diff, oldStyle); 124 RenderInline::styleDidChange(diff, oldStyle);
125 propagateStyleToAnonymousChildren(); 125 propagateStyleToAnonymousChildren();
126 } 126 }
127 127
128 void LayoutRubyAsInline::addChild(RenderObject* child, RenderObject* beforeChild ) 128 void LayoutRubyAsInline::addChild(LayoutObject* child, LayoutObject* beforeChild )
129 { 129 {
130 // Insert :before and :after content before/after the LayoutRubyRun(s) 130 // Insert :before and :after content before/after the LayoutRubyRun(s)
131 if (child->isBeforeContent()) { 131 if (child->isBeforeContent()) {
132 if (child->isInline()) { 132 if (child->isInline()) {
133 // Add generated inline content normally 133 // Add generated inline content normally
134 RenderInline::addChild(child, firstChild()); 134 RenderInline::addChild(child, firstChild());
135 } else { 135 } else {
136 // Wrap non-inline content with an anonymous inline-block. 136 // Wrap non-inline content with an anonymous inline-block.
137 RenderBlock* beforeBlock = rubyBeforeBlock(this); 137 RenderBlock* beforeBlock = rubyBeforeBlock(this);
138 if (!beforeBlock) { 138 if (!beforeBlock) {
(...skipping 21 matching lines...) Expand all
160 } 160 }
161 161
162 // If the child is a ruby run, just add it normally. 162 // If the child is a ruby run, just add it normally.
163 if (child->isRubyRun()) { 163 if (child->isRubyRun()) {
164 RenderInline::addChild(child, beforeChild); 164 RenderInline::addChild(child, beforeChild);
165 return; 165 return;
166 } 166 }
167 167
168 if (beforeChild && !isAfterContent(beforeChild)) { 168 if (beforeChild && !isAfterContent(beforeChild)) {
169 // insert child into run 169 // insert child into run
170 RenderObject* run = beforeChild; 170 LayoutObject* run = beforeChild;
171 while (run && !run->isRubyRun()) 171 while (run && !run->isRubyRun())
172 run = run->parent(); 172 run = run->parent();
173 if (run) { 173 if (run) {
174 if (beforeChild == run) 174 if (beforeChild == run)
175 beforeChild = toLayoutRubyRun(beforeChild)->firstChild(); 175 beforeChild = toLayoutRubyRun(beforeChild)->firstChild();
176 ASSERT(!beforeChild || beforeChild->isDescendantOf(run)); 176 ASSERT(!beforeChild || beforeChild->isDescendantOf(run));
177 run->addChild(child, beforeChild); 177 run->addChild(child, beforeChild);
178 return; 178 return;
179 } 179 }
180 ASSERT_NOT_REACHED(); // beforeChild should always have a run as parent! 180 ASSERT_NOT_REACHED(); // beforeChild should always have a run as parent!
181 // Emergency fallback: fall through and just append. 181 // Emergency fallback: fall through and just append.
182 } 182 }
183 183
184 // If the new child would be appended, try to add the child to the previous run 184 // If the new child would be appended, try to add the child to the previous run
185 // if possible, or create a new run otherwise. 185 // if possible, or create a new run otherwise.
186 // (The LayoutRubyRun object will handle the details) 186 // (The LayoutRubyRun object will handle the details)
187 LayoutRubyRun* lastRun = lastRubyRun(this); 187 LayoutRubyRun* lastRun = lastRubyRun(this);
188 if (!lastRun || lastRun->hasRubyText()) { 188 if (!lastRun || lastRun->hasRubyText()) {
189 lastRun = LayoutRubyRun::staticCreateRubyRun(this); 189 lastRun = LayoutRubyRun::staticCreateRubyRun(this);
190 RenderInline::addChild(lastRun, beforeChild); 190 RenderInline::addChild(lastRun, beforeChild);
191 } 191 }
192 lastRun->addChild(child); 192 lastRun->addChild(child);
193 } 193 }
194 194
195 void LayoutRubyAsInline::removeChild(RenderObject* child) 195 void LayoutRubyAsInline::removeChild(LayoutObject* child)
196 { 196 {
197 // If the child's parent is *this (must be a ruby run or generated content o r anonymous block), 197 // If the child's parent is *this (must be a ruby run or generated content o r anonymous block),
198 // just use the normal remove method. 198 // just use the normal remove method.
199 if (child->parent() == this) { 199 if (child->parent() == this) {
200 ASSERT(child->isRubyRun() || child->isBeforeContent() || child->isAfterC ontent() || isAnonymousRubyInlineBlock(child)); 200 ASSERT(child->isRubyRun() || child->isBeforeContent() || child->isAfterC ontent() || isAnonymousRubyInlineBlock(child));
201 RenderInline::removeChild(child); 201 RenderInline::removeChild(child);
202 return; 202 return;
203 } 203 }
204 // If the child's parent is an anoymous block (must be generated :before/:af ter content) 204 // If the child's parent is an anoymous block (must be generated :before/:af ter content)
205 // just use the block's remove method. 205 // just use the block's remove method.
(...skipping 21 matching lines...) Expand all
227 LayoutRubyAsBlock::~LayoutRubyAsBlock() 227 LayoutRubyAsBlock::~LayoutRubyAsBlock()
228 { 228 {
229 } 229 }
230 230
231 void LayoutRubyAsBlock::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle) 231 void LayoutRubyAsBlock::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
232 { 232 {
233 RenderBlockFlow::styleDidChange(diff, oldStyle); 233 RenderBlockFlow::styleDidChange(diff, oldStyle);
234 propagateStyleToAnonymousChildren(); 234 propagateStyleToAnonymousChildren();
235 } 235 }
236 236
237 void LayoutRubyAsBlock::addChild(RenderObject* child, RenderObject* beforeChild) 237 void LayoutRubyAsBlock::addChild(LayoutObject* child, LayoutObject* beforeChild)
238 { 238 {
239 // Insert :before and :after content before/after the LayoutRubyRun(s) 239 // Insert :before and :after content before/after the LayoutRubyRun(s)
240 if (child->isBeforeContent()) { 240 if (child->isBeforeContent()) {
241 if (child->isInline()) { 241 if (child->isInline()) {
242 // Add generated inline content normally 242 // Add generated inline content normally
243 RenderBlockFlow::addChild(child, firstChild()); 243 RenderBlockFlow::addChild(child, firstChild());
244 } else { 244 } else {
245 // Wrap non-inline content with an anonymous inline-block. 245 // Wrap non-inline content with an anonymous inline-block.
246 RenderBlock* beforeBlock = rubyBeforeBlock(this); 246 RenderBlock* beforeBlock = rubyBeforeBlock(this);
247 if (!beforeBlock) { 247 if (!beforeBlock) {
(...skipping 21 matching lines...) Expand all
269 } 269 }
270 270
271 // If the child is a ruby run, just add it normally. 271 // If the child is a ruby run, just add it normally.
272 if (child->isRubyRun()) { 272 if (child->isRubyRun()) {
273 RenderBlockFlow::addChild(child, beforeChild); 273 RenderBlockFlow::addChild(child, beforeChild);
274 return; 274 return;
275 } 275 }
276 276
277 if (beforeChild && !isAfterContent(beforeChild)) { 277 if (beforeChild && !isAfterContent(beforeChild)) {
278 // insert child into run 278 // insert child into run
279 RenderObject* run = beforeChild; 279 LayoutObject* run = beforeChild;
280 while (run && !run->isRubyRun()) 280 while (run && !run->isRubyRun())
281 run = run->parent(); 281 run = run->parent();
282 if (run) { 282 if (run) {
283 if (beforeChild == run) 283 if (beforeChild == run)
284 beforeChild = toLayoutRubyRun(beforeChild)->firstChild(); 284 beforeChild = toLayoutRubyRun(beforeChild)->firstChild();
285 ASSERT(!beforeChild || beforeChild->isDescendantOf(run)); 285 ASSERT(!beforeChild || beforeChild->isDescendantOf(run));
286 run->addChild(child, beforeChild); 286 run->addChild(child, beforeChild);
287 return; 287 return;
288 } 288 }
289 ASSERT_NOT_REACHED(); // beforeChild should always have a run as parent! 289 ASSERT_NOT_REACHED(); // beforeChild should always have a run as parent!
290 // Emergency fallback: fall through and just append. 290 // Emergency fallback: fall through and just append.
291 } 291 }
292 292
293 // If the new child would be appended, try to add the child to the previous run 293 // If the new child would be appended, try to add the child to the previous run
294 // if possible, or create a new run otherwise. 294 // if possible, or create a new run otherwise.
295 // (The LayoutRubyRun object will handle the details) 295 // (The LayoutRubyRun object will handle the details)
296 LayoutRubyRun* lastRun = lastRubyRun(this); 296 LayoutRubyRun* lastRun = lastRubyRun(this);
297 if (!lastRun || lastRun->hasRubyText()) { 297 if (!lastRun || lastRun->hasRubyText()) {
298 lastRun = LayoutRubyRun::staticCreateRubyRun(this); 298 lastRun = LayoutRubyRun::staticCreateRubyRun(this);
299 RenderBlockFlow::addChild(lastRun, beforeChild); 299 RenderBlockFlow::addChild(lastRun, beforeChild);
300 } 300 }
301 lastRun->addChild(child); 301 lastRun->addChild(child);
302 } 302 }
303 303
304 void LayoutRubyAsBlock::removeChild(RenderObject* child) 304 void LayoutRubyAsBlock::removeChild(LayoutObject* child)
305 { 305 {
306 // If the child's parent is *this (must be a ruby run or generated content o r anonymous block), 306 // If the child's parent is *this (must be a ruby run or generated content o r anonymous block),
307 // just use the normal remove method. 307 // just use the normal remove method.
308 if (child->parent() == this) { 308 if (child->parent() == this) {
309 ASSERT(child->isRubyRun() || child->isBeforeContent() || child->isAfterC ontent() || isAnonymousRubyInlineBlock(child)); 309 ASSERT(child->isRubyRun() || child->isBeforeContent() || child->isAfterC ontent() || isAnonymousRubyInlineBlock(child));
310 RenderBlockFlow::removeChild(child); 310 RenderBlockFlow::removeChild(child);
311 return; 311 return;
312 } 312 }
313 // If the child's parent is an anoymous block (must be generated :before/:af ter content) 313 // If the child's parent is an anoymous block (must be generated :before/:af ter content)
314 // just use the block's remove method. 314 // just use the block's remove method.
315 if (isAnonymousRubyInlineBlock(child->parent())) { 315 if (isAnonymousRubyInlineBlock(child->parent())) {
316 ASSERT(child->isBeforeContent() || child->isAfterContent()); 316 ASSERT(child->isBeforeContent() || child->isAfterContent());
317 child->parent()->removeChild(child); 317 child->parent()->removeChild(child);
318 removeChild(child->parent()); 318 removeChild(child->parent());
319 return; 319 return;
320 } 320 }
321 321
322 // Otherwise find the containing run and remove it from there. 322 // Otherwise find the containing run and remove it from there.
323 LayoutRubyRun* run = findRubyRunParent(child); 323 LayoutRubyRun* run = findRubyRunParent(child);
324 ASSERT(run); 324 ASSERT(run);
325 run->removeChild(child); 325 run->removeChild(child);
326 } 326 }
327 327
328 } // namespace blink 328 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/layout/LayoutRuby.h ('k') | Source/core/layout/LayoutRubyBase.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698