OLD | NEW |
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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 } | 190 } |
191 | 191 |
192 void StyleAdjuster::adjustRenderStyle(RenderStyle* style, RenderStyle* parentSty
le, Element *e) | 192 void StyleAdjuster::adjustRenderStyle(RenderStyle* style, RenderStyle* parentSty
le, Element *e) |
193 { | 193 { |
194 ASSERT(parentStyle); | 194 ASSERT(parentStyle); |
195 | 195 |
196 // Cache our original display. | 196 // Cache our original display. |
197 style->setOriginalDisplay(style->display()); | 197 style->setOriginalDisplay(style->display()); |
198 | 198 |
199 if (style->display() != NONE) { | 199 if (style->display() != NONE) { |
200 // If we have a <td> that specifies a float property, in quirks mode we
just drop the float | 200 if (e) |
201 // property. | 201 adjustStyleForTagName(style, parentStyle, *e); |
202 // Sites also commonly use display:inline/block on <td>s and <table>s. I
n quirks mode we force | |
203 // these tags to retain their display types. | |
204 if (m_useQuirksModeStyles && e) { | |
205 if (e->hasTagName(tdTag)) { | |
206 style->setDisplay(TABLE_CELL); | |
207 style->setFloating(NoFloat); | |
208 } else if (isHTMLTableElement(*e)) { | |
209 style->setDisplay(style->isDisplayInlineType() ? INLINE_TABLE :
TABLE); | |
210 } | |
211 } | |
212 | |
213 if (e && isHTMLTableCellElement(*e)) { | |
214 if (style->whiteSpace() == KHTML_NOWRAP) { | |
215 // Figure out if we are really nowrapping or if we should just | |
216 // use normal instead. If the width of the cell is fixed, then | |
217 // we don't actually use NOWRAP. | |
218 if (style->width().isFixed()) | |
219 style->setWhiteSpace(NORMAL); | |
220 else | |
221 style->setWhiteSpace(NOWRAP); | |
222 } | |
223 } | |
224 | |
225 // Tables never support the -webkit-* values for text-align and will res
et back to the default. | |
226 if (isHTMLTableElement(e) && (style->textAlign() == WEBKIT_LEFT || style
->textAlign() == WEBKIT_CENTER || style->textAlign() == WEBKIT_RIGHT)) | |
227 style->setTextAlign(TASTART); | |
228 | |
229 // Frames and framesets never honor position:relative or position:absolu
te. This is necessary to | |
230 // fix a crash where a site tries to position these objects. They also n
ever honor display. | |
231 if (e && (isHTMLFrameElement(*e) || isHTMLFrameSetElement(*e))) { | |
232 style->setPosition(StaticPosition); | |
233 style->setDisplay(BLOCK); | |
234 } | |
235 | |
236 // Ruby text does not support float or position. This might change with
evolution of the specification. | |
237 if (isHTMLRTElement(e)) { | |
238 style->setPosition(StaticPosition); | |
239 style->setFloating(NoFloat); | |
240 } | |
241 | |
242 // FIXME: We shouldn't be overriding start/-webkit-auto like this. Do it
in html.css instead. | |
243 // Table headers with a text-align of -webkit-auto will change the text-
align to center. | |
244 if (e && e->hasTagName(thTag) && style->textAlign() == TASTART) | |
245 style->setTextAlign(CENTER); | |
246 | |
247 if (isHTMLLegendElement(e)) | |
248 style->setDisplay(BLOCK); | |
249 | 202 |
250 // Per the spec, position 'static' and 'relative' in the top layer compu
te to 'absolute'. | 203 // Per the spec, position 'static' and 'relative' in the top layer compu
te to 'absolute'. |
251 if (isInTopLayer(e, style) && (style->position() == StaticPosition || st
yle->position() == RelativePosition)) | 204 if (isInTopLayer(e, style) && (style->position() == StaticPosition || st
yle->position() == RelativePosition)) |
252 style->setPosition(AbsolutePosition); | 205 style->setPosition(AbsolutePosition); |
253 | 206 |
254 // Absolute/fixed positioned elements, floating elements and the documen
t element need block-like outside display. | 207 // Absolute/fixed positioned elements, floating elements and the documen
t element need block-like outside display. |
255 if (style->hasOutOfFlowPosition() || style->isFloating() || (e && e->doc
ument().documentElement() == e)) | 208 if (style->hasOutOfFlowPosition() || style->isFloating() || (e && e->doc
ument().documentElement() == e)) |
256 style->setDisplay(equivalentBlockDisplay(style->display(), style->is
Floating(), !m_useQuirksModeStyles)); | 209 style->setDisplay(equivalentBlockDisplay(style->display(), style->is
Floating(), !m_useQuirksModeStyles)); |
257 | 210 |
258 // FIXME: Don't support this mutation for pseudo styles like first-lette
r or first-line, since it's not completely | 211 // FIXME: Don't support this mutation for pseudo styles like first-lette
r or first-line, since it's not completely |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 )) | 269 )) |
317 style->setZIndex(0); | 270 style->setZIndex(0); |
318 | 271 |
319 // will-change:transform should result in the same rendering behavior as hav
ing a transform, | 272 // will-change:transform should result in the same rendering behavior as hav
ing a transform, |
320 // including the creation of a containing block for fixed position descendan
ts. | 273 // including the creation of a containing block for fixed position descendan
ts. |
321 if (!style->hasTransform() && style->willChangeProperties().contains(CSSProp
ertyWebkitTransform)) { | 274 if (!style->hasTransform() && style->willChangeProperties().contains(CSSProp
ertyWebkitTransform)) { |
322 bool makeIdentity = true; | 275 bool makeIdentity = true; |
323 style->setTransform(TransformOperations(makeIdentity)); | 276 style->setTransform(TransformOperations(makeIdentity)); |
324 } | 277 } |
325 | 278 |
326 // Textarea considers overflow visible as auto. | |
327 if (isHTMLTextAreaElement(e)) { | |
328 style->setOverflowX(style->overflowX() == OVISIBLE ? OAUTO : style->over
flowX()); | |
329 style->setOverflowY(style->overflowY() == OVISIBLE ? OAUTO : style->over
flowY()); | |
330 } | |
331 | |
332 // For now, <marquee> requires an overflow clip to work properly. | |
333 if (isHTMLMarqueeElement(e)) { | |
334 style->setOverflowX(OHIDDEN); | |
335 style->setOverflowY(OHIDDEN); | |
336 } | |
337 | |
338 if (doesNotInheritTextDecoration(style, e)) | 279 if (doesNotInheritTextDecoration(style, e)) |
339 style->setTextDecorationsInEffect(style->textDecoration()); | 280 style->setTextDecorationsInEffect(style->textDecoration()); |
340 else | 281 else |
341 style->addToTextDecorationsInEffect(style->textDecoration()); | 282 style->addToTextDecorationsInEffect(style->textDecoration()); |
342 | 283 |
343 // If either overflow value is not visible, change to auto. | 284 // If either overflow value is not visible, change to auto. |
344 if (style->overflowX() == OVISIBLE && style->overflowY() != OVISIBLE) { | 285 if (style->overflowX() == OVISIBLE && style->overflowY() != OVISIBLE) { |
345 // FIXME: Once we implement pagination controls, overflow-x should defau
lt to hidden | 286 // FIXME: Once we implement pagination controls, overflow-x should defau
lt to hidden |
346 // if overflow-y is set to -webkit-paged-x or -webkit-page-y. For now, w
e'll let it | 287 // if overflow-y is set to -webkit-paged-x or -webkit-page-y. For now, w
e'll let it |
347 // default to auto so we can at least scroll through the pages. | 288 // default to auto so we can at least scroll through the pages. |
(...skipping 15 matching lines...) Expand all Loading... |
363 // Menulists should have visible overflow | 304 // Menulists should have visible overflow |
364 if (style->appearance() == MenulistPart) { | 305 if (style->appearance() == MenulistPart) { |
365 style->setOverflowX(OVISIBLE); | 306 style->setOverflowX(OVISIBLE); |
366 style->setOverflowY(OVISIBLE); | 307 style->setOverflowY(OVISIBLE); |
367 } | 308 } |
368 | 309 |
369 // Cull out any useless layers and also repeat patterns into additional laye
rs. | 310 // Cull out any useless layers and also repeat patterns into additional laye
rs. |
370 style->adjustBackgroundLayers(); | 311 style->adjustBackgroundLayers(); |
371 style->adjustMaskLayers(); | 312 style->adjustMaskLayers(); |
372 | 313 |
373 // Important: Intrinsic margins get added to controls before the theme has a
djusted the style, since the theme will | |
374 // alter fonts and heights/widths. | |
375 if (e && e->isFormControlElement() && style->fontSize() >= 11) { | |
376 // Don't apply intrinsic margins to image buttons. The designer knows ho
w big the images are, | |
377 // so we have to treat all image buttons as though they were explicitly
sized. | |
378 if (!isHTMLInputElement(*e) || !toHTMLInputElement(e)->isImageButton()) | |
379 addIntrinsicMargins(style); | |
380 } | |
381 | |
382 // Let the theme also have a crack at adjusting the style. | 314 // Let the theme also have a crack at adjusting the style. |
383 if (style->hasAppearance()) | 315 if (style->hasAppearance()) |
384 RenderTheme::theme().adjustStyle(style, e, m_cachedUAStyle); | 316 RenderTheme::theme().adjustStyle(style, e, m_cachedUAStyle); |
385 | 317 |
386 // If we have first-letter pseudo style, do not share this style. | 318 // If we have first-letter pseudo style, do not share this style. |
387 if (style->hasPseudoStyle(FIRST_LETTER)) | 319 if (style->hasPseudoStyle(FIRST_LETTER)) |
388 style->setUnique(); | 320 style->setUnique(); |
389 | 321 |
390 // FIXME: when dropping the -webkit prefix on transform-style, we should als
o have opacity < 1 cause flattening. | 322 // FIXME: when dropping the -webkit prefix on transform-style, we should als
o have opacity < 1 cause flattening. |
391 if (style->preserves3D() && (style->overflowX() != OVISIBLE | 323 if (style->preserves3D() && (style->overflowX() != OVISIBLE |
(...skipping 21 matching lines...) Expand all Loading... |
413 // not be scaled again. | 345 // not be scaled again. |
414 if (isSVGForeignObjectElement(*e)) | 346 if (isSVGForeignObjectElement(*e)) |
415 style->setEffectiveZoom(RenderStyle::initialZoom()); | 347 style->setEffectiveZoom(RenderStyle::initialZoom()); |
416 | 348 |
417 // SVG text layout code expects us to be a block-level style element. | 349 // SVG text layout code expects us to be a block-level style element. |
418 if ((isSVGForeignObjectElement(*e) || isSVGTextElement(*e)) && style->is
DisplayInlineType()) | 350 if ((isSVGForeignObjectElement(*e) || isSVGTextElement(*e)) && style->is
DisplayInlineType()) |
419 style->setDisplay(BLOCK); | 351 style->setDisplay(BLOCK); |
420 } | 352 } |
421 } | 353 } |
422 | 354 |
| 355 void StyleAdjuster::adjustStyleForTagName(RenderStyle* style, RenderStyle* paren
tStyle, Element& element) |
| 356 { |
| 357 // <div> and <span> are the most common elements on the web, we skip all the
work for them. |
| 358 if (isHTMLDivElement(element) || isHTMLSpanElement(element)) |
| 359 return; |
| 360 |
| 361 if (isHTMLTableCellElement(element)) { |
| 362 // If we have a <td> that specifies a float property, in quirks mode we
just drop the float property. |
| 363 // FIXME: Why is this only <td> and not <th>? |
| 364 if (element.hasTagName(tdTag) && m_useQuirksModeStyles) { |
| 365 style->setDisplay(TABLE_CELL); |
| 366 style->setFloating(NoFloat); |
| 367 } |
| 368 // FIXME: We shouldn't be overriding start/-webkit-auto like this. Do it
in html.css instead. |
| 369 // Table headers with a text-align of -webkit-auto will change the text-
align to center. |
| 370 if (element.hasTagName(thTag) && style->textAlign() == TASTART) |
| 371 style->setTextAlign(CENTER); |
| 372 if (style->whiteSpace() == KHTML_NOWRAP) { |
| 373 // Figure out if we are really nowrapping or if we should just |
| 374 // use normal instead. If the width of the cell is fixed, then |
| 375 // we don't actually use NOWRAP. |
| 376 if (style->width().isFixed()) |
| 377 style->setWhiteSpace(NORMAL); |
| 378 else |
| 379 style->setWhiteSpace(NOWRAP); |
| 380 } |
| 381 return; |
| 382 } |
| 383 |
| 384 if (isHTMLTableElement(element)) { |
| 385 // Sites commonly use display:inline/block on <td>s and <table>s. In qui
rks mode we force |
| 386 // these tags to retain their display types. |
| 387 if (m_useQuirksModeStyles) |
| 388 style->setDisplay(style->isDisplayInlineType() ? INLINE_TABLE : TABL
E); |
| 389 // Tables never support the -webkit-* values for text-align and will res
et back to the default. |
| 390 if (style->textAlign() == WEBKIT_LEFT || style->textAlign() == WEBKIT_CE
NTER || style->textAlign() == WEBKIT_RIGHT) |
| 391 style->setTextAlign(TASTART); |
| 392 return; |
| 393 } |
| 394 |
| 395 if (isHTMLFrameElement(element) || isHTMLFrameSetElement(element)) { |
| 396 // Frames and framesets never honor position:relative or position:absolu
te. This is necessary to |
| 397 // fix a crash where a site tries to position these objects. They also n
ever honor display. |
| 398 style->setPosition(StaticPosition); |
| 399 style->setDisplay(BLOCK); |
| 400 return; |
| 401 } |
| 402 |
| 403 if (isHTMLRTElement(element)) { |
| 404 // Ruby text does not support float or position. This might change with
evolution of the specification. |
| 405 style->setPosition(StaticPosition); |
| 406 style->setFloating(NoFloat); |
| 407 return; |
| 408 } |
| 409 |
| 410 if (isHTMLLegendElement(element)) { |
| 411 style->setDisplay(BLOCK); |
| 412 return; |
| 413 } |
| 414 |
| 415 if (isHTMLMarqueeElement(element)) { |
| 416 // For now, <marquee> requires an overflow clip to work properly. |
| 417 style->setOverflowX(OHIDDEN); |
| 418 style->setOverflowY(OHIDDEN); |
| 419 return; |
| 420 } |
| 421 |
| 422 if (element.isFormControlElement()) { |
| 423 if (isHTMLTextAreaElement(element)) { |
| 424 // Textarea considers overflow visible as auto. |
| 425 style->setOverflowX(style->overflowX() == OVISIBLE ? OAUTO : style->
overflowX()); |
| 426 style->setOverflowY(style->overflowY() == OVISIBLE ? OAUTO : style->
overflowY()); |
| 427 } |
| 428 |
| 429 // Important: Intrinsic margins get added to controls before the theme h
as adjusted the style, |
| 430 // since the theme will alter fonts and heights/widths. |
| 431 // |
| 432 // Don't apply intrinsic margins to image buttons. The designer knows ho
w big the images are, |
| 433 // so we have to treat all image buttons as though they were explicitly
sized. |
| 434 if (style->fontSize() >= 11 && (!isHTMLInputElement(element) || !toHTMLI
nputElement(element).isImageButton())) |
| 435 addIntrinsicMargins(style); |
| 436 return; |
| 437 } |
| 438 } |
| 439 |
423 } | 440 } |
OLD | NEW |