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

Side by Side Diff: Source/core/css/resolver/StyleAdjuster.cpp

Issue 192373005: Use new is*Element() helper functions in CSS code (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 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) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
(...skipping 18 matching lines...) Expand all
29 #include "config.h" 29 #include "config.h"
30 #include "core/css/resolver/StyleAdjuster.h" 30 #include "core/css/resolver/StyleAdjuster.h"
31 31
32 #include "HTMLNames.h" 32 #include "HTMLNames.h"
33 #include "SVGNames.h" 33 #include "SVGNames.h"
34 #include "core/dom/ContainerNode.h" 34 #include "core/dom/ContainerNode.h"
35 #include "core/dom/Document.h" 35 #include "core/dom/Document.h"
36 #include "core/dom/Element.h" 36 #include "core/dom/Element.h"
37 #include "core/html/HTMLIFrameElement.h" 37 #include "core/html/HTMLIFrameElement.h"
38 #include "core/html/HTMLInputElement.h" 38 #include "core/html/HTMLInputElement.h"
39 #include "core/html/HTMLTableCellElement.h"
39 #include "core/html/HTMLTextAreaElement.h" 40 #include "core/html/HTMLTextAreaElement.h"
40 #include "core/frame/FrameView.h" 41 #include "core/frame/FrameView.h"
41 #include "core/frame/Settings.h" 42 #include "core/frame/Settings.h"
42 #include "core/rendering/RenderTheme.h" 43 #include "core/rendering/RenderTheme.h"
43 #include "core/rendering/style/GridPosition.h" 44 #include "core/rendering/style/GridPosition.h"
44 #include "core/rendering/style/RenderStyle.h" 45 #include "core/rendering/style/RenderStyle.h"
45 #include "core/rendering/style/RenderStyleConstants.h" 46 #include "core/rendering/style/RenderStyleConstants.h"
47 #include "core/svg/SVGSVGElement.h"
46 #include "platform/Length.h" 48 #include "platform/Length.h"
47 #include "platform/transforms/TransformOperations.h" 49 #include "platform/transforms/TransformOperations.h"
48 #include "wtf/Assertions.h" 50 #include "wtf/Assertions.h"
49 51
50 namespace WebCore { 52 namespace WebCore {
51 53
52 using namespace HTMLNames; 54 using namespace HTMLNames;
53 55
54 // FIXME: This is duplicated with StyleResolver.cpp 56 // FIXME: This is duplicated with StyleResolver.cpp
55 // Perhaps this should move onto ElementResolveContext or even Element? 57 // Perhaps this should move onto ElementResolveContext or even Element?
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 198
197 if (style->display() != NONE) { 199 if (style->display() != NONE) {
198 // If we have a <td> that specifies a float property, in quirks mode we just drop the float 200 // If we have a <td> that specifies a float property, in quirks mode we just drop the float
199 // property. 201 // property.
200 // Sites also commonly use display:inline/block on <td>s and <table>s. I n quirks mode we force 202 // Sites also commonly use display:inline/block on <td>s and <table>s. I n quirks mode we force
201 // these tags to retain their display types. 203 // these tags to retain their display types.
202 if (m_useQuirksModeStyles && e) { 204 if (m_useQuirksModeStyles && e) {
203 if (e->hasTagName(tdTag)) { 205 if (e->hasTagName(tdTag)) {
204 style->setDisplay(TABLE_CELL); 206 style->setDisplay(TABLE_CELL);
205 style->setFloating(NoFloat); 207 style->setFloating(NoFloat);
206 } else if (e->hasTagName(tableTag)) { 208 } else if (isHTMLTableElement(*e)) {
207 style->setDisplay(style->isDisplayInlineType() ? INLINE_TABLE : TABLE); 209 style->setDisplay(style->isDisplayInlineType() ? INLINE_TABLE : TABLE);
208 } 210 }
209 } 211 }
210 212
211 if (e && (e->hasTagName(tdTag) || e->hasTagName(thTag))) { 213 if (e && isHTMLTableCellElement(*e)) {
212 if (style->whiteSpace() == KHTML_NOWRAP) { 214 if (style->whiteSpace() == KHTML_NOWRAP) {
213 // Figure out if we are really nowrapping or if we should just 215 // Figure out if we are really nowrapping or if we should just
214 // use normal instead. If the width of the cell is fixed, then 216 // use normal instead. If the width of the cell is fixed, then
215 // we don't actually use NOWRAP. 217 // we don't actually use NOWRAP.
216 if (style->width().isFixed()) 218 if (style->width().isFixed())
217 style->setWhiteSpace(NORMAL); 219 style->setWhiteSpace(NORMAL);
218 else 220 else
219 style->setWhiteSpace(NOWRAP); 221 style->setWhiteSpace(NOWRAP);
220 } 222 }
221 } 223 }
222 224
223 // Tables never support the -webkit-* values for text-align and will res et back to the default. 225 // Tables never support the -webkit-* values for text-align and will res et back to the default.
224 if (e && e->hasTagName(tableTag) && (style->textAlign() == WEBKIT_LEFT | | style->textAlign() == WEBKIT_CENTER || style->textAlign() == WEBKIT_RIGHT)) 226 if (isHTMLTableElement(e) && (style->textAlign() == WEBKIT_LEFT || style ->textAlign() == WEBKIT_CENTER || style->textAlign() == WEBKIT_RIGHT))
225 style->setTextAlign(TASTART); 227 style->setTextAlign(TASTART);
226 228
227 // Frames and framesets never honor position:relative or position:absolu te. This is necessary to 229 // Frames and framesets never honor position:relative or position:absolu te. This is necessary to
228 // fix a crash where a site tries to position these objects. They also n ever honor display. 230 // fix a crash where a site tries to position these objects. They also n ever honor display.
229 if (e && (e->hasTagName(frameTag) || e->hasTagName(framesetTag))) { 231 if (e && (isHTMLFrameElement(*e) || isHTMLFrameSetElement(*e))) {
230 style->setPosition(StaticPosition); 232 style->setPosition(StaticPosition);
231 style->setDisplay(BLOCK); 233 style->setDisplay(BLOCK);
232 } 234 }
233 235
234 // Ruby text does not support float or position. This might change with evolution of the specification. 236 // Ruby text does not support float or position. This might change with evolution of the specification.
235 if (e && e->hasTagName(rtTag)) { 237 if (isHTMLRTElement(e)) {
236 style->setPosition(StaticPosition); 238 style->setPosition(StaticPosition);
237 style->setFloating(NoFloat); 239 style->setFloating(NoFloat);
238 } 240 }
239 241
240 // FIXME: We shouldn't be overriding start/-webkit-auto like this. Do it in html.css instead. 242 // FIXME: We shouldn't be overriding start/-webkit-auto like this. Do it in html.css instead.
241 // Table headers with a text-align of -webkit-auto will change the text- align to center. 243 // Table headers with a text-align of -webkit-auto will change the text- align to center.
242 if (e && e->hasTagName(thTag) && style->textAlign() == TASTART) 244 if (e && e->hasTagName(thTag) && style->textAlign() == TASTART)
243 style->setTextAlign(CENTER); 245 style->setTextAlign(CENTER);
244 246
245 if (e && e->hasTagName(legendTag)) 247 if (isHTMLLegendElement(e))
246 style->setDisplay(BLOCK); 248 style->setDisplay(BLOCK);
247 249
248 // Per the spec, position 'static' and 'relative' in the top layer compu te to 'absolute'. 250 // Per the spec, position 'static' and 'relative' in the top layer compu te to 'absolute'.
249 if (isInTopLayer(e, style) && (style->position() == StaticPosition || st yle->position() == RelativePosition)) 251 if (isInTopLayer(e, style) && (style->position() == StaticPosition || st yle->position() == RelativePosition))
250 style->setPosition(AbsolutePosition); 252 style->setPosition(AbsolutePosition);
251 253
252 // Absolute/fixed positioned elements, floating elements and the documen t element need block-like outside display. 254 // Absolute/fixed positioned elements, floating elements and the documen t element need block-like outside display.
253 if (style->hasOutOfFlowPosition() || style->isFloating() || (e && e->doc ument().documentElement() == e)) 255 if (style->hasOutOfFlowPosition() || style->isFloating() || (e && e->doc ument().documentElement() == e))
254 style->setDisplay(equivalentBlockDisplay(style->display(), style->is Floating(), !m_useQuirksModeStyles)); 256 style->setDisplay(equivalentBlockDisplay(style->display(), style->is Floating(), !m_useQuirksModeStyles));
255 257
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 style->setZIndex(0); 311 style->setZIndex(0);
310 312
311 // will-change:transform should result in the same rendering behavior as hav ing a transform, 313 // will-change:transform should result in the same rendering behavior as hav ing a transform,
312 // including the creation of a containing block for fixed position descendan ts. 314 // including the creation of a containing block for fixed position descendan ts.
313 if (!style->hasTransform() && style->willChangeProperties().contains(CSSProp ertyWebkitTransform)) { 315 if (!style->hasTransform() && style->willChangeProperties().contains(CSSProp ertyWebkitTransform)) {
314 bool makeIdentity = true; 316 bool makeIdentity = true;
315 style->setTransform(TransformOperations(makeIdentity)); 317 style->setTransform(TransformOperations(makeIdentity));
316 } 318 }
317 319
318 // Textarea considers overflow visible as auto. 320 // Textarea considers overflow visible as auto.
319 if (e && e->hasTagName(textareaTag)) { 321 if (isHTMLTextAreaElement(e)) {
320 style->setOverflowX(style->overflowX() == OVISIBLE ? OAUTO : style->over flowX()); 322 style->setOverflowX(style->overflowX() == OVISIBLE ? OAUTO : style->over flowX());
321 style->setOverflowY(style->overflowY() == OVISIBLE ? OAUTO : style->over flowY()); 323 style->setOverflowY(style->overflowY() == OVISIBLE ? OAUTO : style->over flowY());
322 } 324 }
323 325
324 // For now, <marquee> requires an overflow clip to work properly. 326 // For now, <marquee> requires an overflow clip to work properly.
325 if (e && e->hasTagName(marqueeTag)) { 327 if (isHTMLMarqueeElement(e)) {
326 style->setOverflowX(OHIDDEN); 328 style->setOverflowX(OHIDDEN);
327 style->setOverflowY(OHIDDEN); 329 style->setOverflowY(OHIDDEN);
328 } 330 }
329 331
330 if (doesNotInheritTextDecoration(style, e)) 332 if (doesNotInheritTextDecoration(style, e))
331 style->setTextDecorationsInEffect(style->textDecoration()); 333 style->setTextDecorationsInEffect(style->textDecoration());
332 else 334 else
333 style->addToTextDecorationsInEffect(style->textDecoration()); 335 style->addToTextDecorationsInEffect(style->textDecoration());
334 336
335 // If either overflow value is not visible, change to auto. 337 // If either overflow value is not visible, change to auto.
(...skipping 24 matching lines...) Expand all
360 362
361 // Cull out any useless layers and also repeat patterns into additional laye rs. 363 // Cull out any useless layers and also repeat patterns into additional laye rs.
362 style->adjustBackgroundLayers(); 364 style->adjustBackgroundLayers();
363 style->adjustMaskLayers(); 365 style->adjustMaskLayers();
364 366
365 // Important: Intrinsic margins get added to controls before the theme has a djusted the style, since the theme will 367 // Important: Intrinsic margins get added to controls before the theme has a djusted the style, since the theme will
366 // alter fonts and heights/widths. 368 // alter fonts and heights/widths.
367 if (e && e->isFormControlElement() && style->fontSize() >= 11) { 369 if (e && e->isFormControlElement() && style->fontSize() >= 11) {
368 // Don't apply intrinsic margins to image buttons. The designer knows ho w big the images are, 370 // Don't apply intrinsic margins to image buttons. The designer knows ho w big the images are,
369 // so we have to treat all image buttons as though they were explicitly sized. 371 // so we have to treat all image buttons as though they were explicitly sized.
370 if (!e->hasTagName(inputTag) || !toHTMLInputElement(e)->isImageButton()) 372 if (!isHTMLInputElement(*e) || !toHTMLInputElement(e)->isImageButton())
371 addIntrinsicMargins(style); 373 addIntrinsicMargins(style);
372 } 374 }
373 375
374 // Let the theme also have a crack at adjusting the style. 376 // Let the theme also have a crack at adjusting the style.
375 if (style->hasAppearance()) 377 if (style->hasAppearance())
376 RenderTheme::theme().adjustStyle(style, e, m_cachedUAStyle); 378 RenderTheme::theme().adjustStyle(style, e, m_cachedUAStyle);
377 379
378 // If we have first-letter pseudo style, do not share this style. 380 // If we have first-letter pseudo style, do not share this style.
379 if (style->hasPseudoStyle(FIRST_LETTER)) 381 if (style->hasPseudoStyle(FIRST_LETTER))
380 style->setUnique(); 382 style->setUnique();
(...skipping 12 matching lines...) Expand all
393 style->setOverflowY(OHIDDEN); 395 style->setOverflowY(OHIDDEN);
394 else if (style->overflowY() == OAUTO) 396 else if (style->overflowY() == OAUTO)
395 style->setOverflowY(OVISIBLE); 397 style->setOverflowY(OVISIBLE);
396 398
397 if (style->overflowX() == OSCROLL) 399 if (style->overflowX() == OSCROLL)
398 style->setOverflowX(OHIDDEN); 400 style->setOverflowX(OHIDDEN);
399 else if (style->overflowX() == OAUTO) 401 else if (style->overflowX() == OAUTO)
400 style->setOverflowX(OVISIBLE); 402 style->setOverflowX(OVISIBLE);
401 403
402 // Only the root <svg> element in an SVG document fragment tree honors c ss position 404 // Only the root <svg> element in an SVG document fragment tree honors c ss position
403 if (!(e->hasTagName(SVGNames::svgTag) && e->parentNode() && !e->parentNo de()->isSVGElement())) 405 if (!(isSVGSVGElement(*e) && e->parentNode() && !e->parentNode()->isSVGE lement()))
404 style->setPosition(RenderStyle::initialPosition()); 406 style->setPosition(RenderStyle::initialPosition());
405 407
406 // RenderSVGRoot handles zooming for the whole SVG subtree, so foreignOb ject content should 408 // RenderSVGRoot handles zooming for the whole SVG subtree, so foreignOb ject content should
407 // not be scaled again. 409 // not be scaled again.
408 if (e->hasTagName(SVGNames::foreignObjectTag)) 410 if (isSVGForeignObjectElement(*e))
409 style->setEffectiveZoom(RenderStyle::initialZoom()); 411 style->setEffectiveZoom(RenderStyle::initialZoom());
410 412
411 // SVG text layout code expects us to be a block-level style element. 413 // SVG text layout code expects us to be a block-level style element.
412 if ((e->hasTagName(SVGNames::foreignObjectTag) || e->hasTagName(SVGNames ::textTag)) && style->isDisplayInlineType()) 414 if ((isSVGForeignObjectElement(*e) || isSVGTextElement(*e)) && style->is DisplayInlineType())
413 style->setDisplay(BLOCK); 415 style->setDisplay(BLOCK);
414 } 416 }
415 } 417 }
416 418
417 void StyleAdjuster::adjustGridItemPosition(RenderStyle* style, RenderStyle* pare ntStyle) const 419 void StyleAdjuster::adjustGridItemPosition(RenderStyle* style, RenderStyle* pare ntStyle) const
418 { 420 {
419 const GridPosition& columnStartPosition = style->gridColumnStart(); 421 const GridPosition& columnStartPosition = style->gridColumnStart();
420 const GridPosition& columnEndPosition = style->gridColumnEnd(); 422 const GridPosition& columnEndPosition = style->gridColumnEnd();
421 const GridPosition& rowStartPosition = style->gridRowStart(); 423 const GridPosition& rowStartPosition = style->gridRowStart();
422 const GridPosition& rowEndPosition = style->gridRowEnd(); 424 const GridPosition& rowEndPosition = style->gridRowEnd();
(...skipping 16 matching lines...) Expand all
439 if (prop.isNamedGridArea() && !map.contains(prop.namedGridLine())) \ 441 if (prop.isNamedGridArea() && !map.contains(prop.namedGridLine())) \
440 style->setGrid##Prop(GridPosition()); 442 style->setGrid##Prop(GridPosition());
441 443
442 CLEAR_UNKNOWN_NAMED_AREA(columnStartPosition, ColumnStart); 444 CLEAR_UNKNOWN_NAMED_AREA(columnStartPosition, ColumnStart);
443 CLEAR_UNKNOWN_NAMED_AREA(columnEndPosition, ColumnEnd); 445 CLEAR_UNKNOWN_NAMED_AREA(columnEndPosition, ColumnEnd);
444 CLEAR_UNKNOWN_NAMED_AREA(rowStartPosition, RowStart); 446 CLEAR_UNKNOWN_NAMED_AREA(rowStartPosition, RowStart);
445 CLEAR_UNKNOWN_NAMED_AREA(rowEndPosition, RowEnd); 447 CLEAR_UNKNOWN_NAMED_AREA(rowEndPosition, RowEnd);
446 } 448 }
447 449
448 } 450 }
OLDNEW
« no previous file with comments | « Source/core/css/resolver/SharedStyleFinder.cpp ('k') | Source/core/css/resolver/StyleResolver.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698