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

Side by Side Diff: Source/core/dom/FirstLetterPseudoElement.cpp

Issue 977113003: Rename renderer() to layoutObject(). (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase to master Created 5 years, 9 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
OLDNEW
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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 return (obj->isBR() || (obj->isText() && toLayoutText(obj)->isWordBreak())); 94 return (obj->isBR() || (obj->isText() && toLayoutText(obj)->isWordBreak()));
95 } 95 }
96 96
97 LayoutObject* FirstLetterPseudoElement::firstLetterTextRenderer(const Element& e lement) 97 LayoutObject* FirstLetterPseudoElement::firstLetterTextRenderer(const Element& e lement)
98 { 98 {
99 LayoutObject* parentRenderer = 0; 99 LayoutObject* parentRenderer = 0;
100 100
101 // If we are looking at a first letter element then we need to find the 101 // If we are looking at a first letter element then we need to find the
102 // first letter text renderer from the parent node, and not ourselves. 102 // first letter text renderer from the parent node, and not ourselves.
103 if (element.isFirstLetterPseudoElement()) 103 if (element.isFirstLetterPseudoElement())
104 parentRenderer = element.parentOrShadowHostElement()->renderer(); 104 parentRenderer = element.parentOrShadowHostElement()->layoutObject();
Julien - ping for review 2015/03/05 16:19:15 s/parentRenderer/parentLayoutObject/
105 else 105 else
106 parentRenderer = element.renderer(); 106 parentRenderer = element.layoutObject();
107 107
108 if (!parentRenderer 108 if (!parentRenderer
109 || !parentRenderer->style()->hasPseudoStyle(FIRST_LETTER) 109 || !parentRenderer->style()->hasPseudoStyle(FIRST_LETTER)
110 || !parentRenderer->canHaveGeneratedChildren() 110 || !parentRenderer->canHaveGeneratedChildren()
111 || !(parentRenderer->isLayoutBlockFlow() || parentRenderer->isLayoutButt on())) 111 || !(parentRenderer->isLayoutBlockFlow() || parentRenderer->isLayoutButt on()))
112 return nullptr; 112 return nullptr;
113 113
114 // Drill down into our children and look for our first text child. 114 // Drill down into our children and look for our first text child.
115 LayoutObject* firstLetterTextRenderer = parentRenderer->slowFirstChild(); 115 LayoutObject* firstLetterTextRenderer = parentRenderer->slowFirstChild();
116 while (firstLetterTextRenderer) { 116 while (firstLetterTextRenderer) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 172
173 void FirstLetterPseudoElement::updateTextFragments() 173 void FirstLetterPseudoElement::updateTextFragments()
174 { 174 {
175 String oldText = m_remainingTextRenderer->completeText(); 175 String oldText = m_remainingTextRenderer->completeText();
176 ASSERT(oldText.impl()); 176 ASSERT(oldText.impl());
177 177
178 unsigned length = FirstLetterPseudoElement::firstLetterLength(oldText); 178 unsigned length = FirstLetterPseudoElement::firstLetterLength(oldText);
179 m_remainingTextRenderer->setTextFragment(oldText.impl()->substring(length, o ldText.length()), length, oldText.length() - length); 179 m_remainingTextRenderer->setTextFragment(oldText.impl()->substring(length, o ldText.length()), length, oldText.length() - length);
180 m_remainingTextRenderer->dirtyLineBoxes(); 180 m_remainingTextRenderer->dirtyLineBoxes();
181 181
182 for (auto child = renderer()->slowFirstChild(); child; child = child->nextSi bling()) { 182 for (auto child = layoutObject()->slowFirstChild(); child; child = child->ne xtSibling()) {
183 if (!child->isText() || !toLayoutText(child)->isTextFragment()) 183 if (!child->isText() || !toLayoutText(child)->isTextFragment())
184 continue; 184 continue;
185 LayoutTextFragment* childFragment = toLayoutTextFragment(child); 185 LayoutTextFragment* childFragment = toLayoutTextFragment(child);
186 if (childFragment->firstLetterPseudoElement() != this) 186 if (childFragment->firstLetterPseudoElement() != this)
187 continue; 187 continue;
188 188
189 childFragment->setTextFragment(oldText.impl()->substring(0, length), 0, length); 189 childFragment->setTextFragment(oldText.impl()->substring(0, length), 0, length);
190 childFragment->dirtyLineBoxes(); 190 childFragment->dirtyLineBoxes();
191 break; 191 break;
192 } 192 }
(...skipping 28 matching lines...) Expand all
221 } 221 }
222 m_remainingTextRenderer = nullptr; 222 m_remainingTextRenderer = nullptr;
223 223
224 PseudoElement::detach(context); 224 PseudoElement::detach(context);
225 } 225 }
226 226
227 LayoutStyle* FirstLetterPseudoElement::styleForFirstLetter(LayoutObject* rendere rContainer) 227 LayoutStyle* FirstLetterPseudoElement::styleForFirstLetter(LayoutObject* rendere rContainer)
228 { 228 {
229 ASSERT(rendererContainer); 229 ASSERT(rendererContainer);
230 230
231 LayoutObject* styleContainer = parentOrShadowHostElement()->renderer(); 231 LayoutObject* styleContainer = parentOrShadowHostElement()->layoutObject();
232 ASSERT(styleContainer); 232 ASSERT(styleContainer);
233 233
234 // We always force the pseudo style to recompute as the first-letter style 234 // We always force the pseudo style to recompute as the first-letter style
235 // computed by the style container may not have taken the renderers styles 235 // computed by the style container may not have taken the renderers styles
236 // into account. 236 // into account.
237 styleContainer->style()->removeCachedPseudoStyle(FIRST_LETTER); 237 styleContainer->style()->removeCachedPseudoStyle(FIRST_LETTER);
238 238
239 LayoutStyle* pseudoStyle = styleContainer->getCachedPseudoStyle(FIRST_LETTER , rendererContainer->firstLineStyle()); 239 LayoutStyle* pseudoStyle = styleContainer->getCachedPseudoStyle(FIRST_LETTER , rendererContainer->firstLineStyle());
240 ASSERT(pseudoStyle); 240 ASSERT(pseudoStyle);
241 241
242 return pseudoStyle; 242 return pseudoStyle;
243 } 243 }
244 244
245 void FirstLetterPseudoElement::attachFirstLetterTextRenderers() 245 void FirstLetterPseudoElement::attachFirstLetterTextRenderers()
246 { 246 {
247 LayoutObject* nextRenderer = FirstLetterPseudoElement::firstLetterTextRender er(*this); 247 LayoutObject* nextRenderer = FirstLetterPseudoElement::firstLetterTextRender er(*this);
248 ASSERT(nextRenderer); 248 ASSERT(nextRenderer);
249 ASSERT(nextRenderer->isText()); 249 ASSERT(nextRenderer->isText());
250 250
251 // The original string is going to be either a generated content string or a DOM node's 251 // The original string is going to be either a generated content string or a DOM node's
252 // string. We want the original string before it got transformed in case fir st-letter has 252 // string. We want the original string before it got transformed in case fir st-letter has
253 // no text-transform or a different text-transform applied to it. 253 // no text-transform or a different text-transform applied to it.
254 String oldText = toLayoutText(nextRenderer)->isTextFragment() ? toLayoutText Fragment(nextRenderer)->completeText() : toLayoutText(nextRenderer)->originalTex t(); 254 String oldText = toLayoutText(nextRenderer)->isTextFragment() ? toLayoutText Fragment(nextRenderer)->completeText() : toLayoutText(nextRenderer)->originalTex t();
255 ASSERT(oldText.impl()); 255 ASSERT(oldText.impl());
256 256
257 LayoutStyle* pseudoStyle = styleForFirstLetter(nextRenderer->parent()); 257 LayoutStyle* pseudoStyle = styleForFirstLetter(nextRenderer->parent());
258 renderer()->setStyle(pseudoStyle); 258 layoutObject()->setStyle(pseudoStyle);
259 259
260 // FIXME: This would already have been calculated in firstLetterRenderer. Ca n we pass the length through? 260 // FIXME: This would already have been calculated in firstLetterRenderer. Ca n we pass the length through?
261 unsigned length = FirstLetterPseudoElement::firstLetterLength(oldText); 261 unsigned length = FirstLetterPseudoElement::firstLetterLength(oldText);
262 262
263 // Construct a text fragment for the text after the first letter. 263 // Construct a text fragment for the text after the first letter.
264 // This text fragment might be empty. 264 // This text fragment might be empty.
265 LayoutTextFragment* remainingText = 265 LayoutTextFragment* remainingText =
266 new LayoutTextFragment(nextRenderer->node() ? nextRenderer->node() : &ne xtRenderer->document(), oldText.impl(), length, oldText.length() - length); 266 new LayoutTextFragment(nextRenderer->node() ? nextRenderer->node() : &ne xtRenderer->document(), oldText.impl(), length, oldText.length() - length);
267 remainingText->setFirstLetterPseudoElement(this); 267 remainingText->setFirstLetterPseudoElement(this);
268 remainingText->setIsRemainingTextRenderer(true); 268 remainingText->setIsRemainingTextRenderer(true);
269 remainingText->setStyle(nextRenderer->style()); 269 remainingText->setStyle(nextRenderer->style());
270 270
271 if (remainingText->node()) 271 if (remainingText->node())
272 remainingText->node()->setRenderer(remainingText); 272 remainingText->node()->setRenderer(remainingText);
273 273
274 m_remainingTextRenderer = remainingText; 274 m_remainingTextRenderer = remainingText;
275 275
276 LayoutObject* nextSibling = renderer()->nextSibling(); 276 LayoutObject* nextSibling = layoutObject()->nextSibling();
277 renderer()->parent()->addChild(remainingText, nextSibling); 277 layoutObject()->parent()->addChild(remainingText, nextSibling);
278 278
279 // Construct text fragment for the first letter. 279 // Construct text fragment for the first letter.
280 LayoutTextFragment* letter = new LayoutTextFragment(&nextRenderer->document( ), oldText.impl(), 0, length); 280 LayoutTextFragment* letter = new LayoutTextFragment(&nextRenderer->document( ), oldText.impl(), 0, length);
281 letter->setFirstLetterPseudoElement(this); 281 letter->setFirstLetterPseudoElement(this);
282 letter->setStyle(pseudoStyle); 282 letter->setStyle(pseudoStyle);
283 renderer()->addChild(letter); 283 layoutObject()->addChild(letter);
284 284
285 nextRenderer->destroy(); 285 nextRenderer->destroy();
286 } 286 }
287 287
288 void FirstLetterPseudoElement::didRecalcStyle(StyleRecalcChange) 288 void FirstLetterPseudoElement::didRecalcStyle(StyleRecalcChange)
289 { 289 {
290 if (!renderer()) 290 if (!layoutObject())
291 return; 291 return;
292 292
293 // The renderers inside pseudo elements are anonymous so they don't get noti fied of recalcStyle and must have 293 // The renderers inside pseudo elements are anonymous so they don't get noti fied of recalcStyle and must have
294 // the style propagated downward manually similar to LayoutObject::propagate StyleToAnonymousChildren. 294 // the style propagated downward manually similar to LayoutObject::propagate StyleToAnonymousChildren.
295 LayoutObject* renderer = this->renderer(); 295 LayoutObject* renderer = this->layoutObject();
Julien - ping for review 2015/03/05 16:19:15 s/renderer/layoutObject/
296 for (LayoutObject* child = renderer->nextInPreOrder(renderer); child; child = child->nextInPreOrder(renderer)) { 296 for (LayoutObject* child = renderer->nextInPreOrder(renderer); child; child = child->nextInPreOrder(renderer)) {
297 // We need to re-calculate the correct style for the first letter elemen t 297 // We need to re-calculate the correct style for the first letter elemen t
298 // and then apply that to the container and the text fragment inside. 298 // and then apply that to the container and the text fragment inside.
299 if (child->style()->styleType() == FIRST_LETTER && m_remainingTextRender er) { 299 if (child->style()->styleType() == FIRST_LETTER && m_remainingTextRender er) {
300 if (LayoutStyle* pseudoStyle = styleForFirstLetter(m_remainingTextRe nderer->parent())) 300 if (LayoutStyle* pseudoStyle = styleForFirstLetter(m_remainingTextRe nderer->parent()))
301 child->setPseudoStyle(pseudoStyle); 301 child->setPseudoStyle(pseudoStyle);
302 continue; 302 continue;
303 } 303 }
304 304
305 // We only manage the style for the generated content items. 305 // We only manage the style for the generated content items.
306 if (!child->isText() && !child->isQuote() && !child->isImage()) 306 if (!child->isText() && !child->isQuote() && !child->isImage())
307 continue; 307 continue;
308 308
309 child->setPseudoStyle(renderer->style()); 309 child->setPseudoStyle(renderer->style());
310 } 310 }
311 } 311 }
312 312
313 } // namespace blink 313 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698