CSSStyleSelector::pseudoStyleForElement(RenderStyle::PseudoId pseudo, Element* e, RenderStyle* parentStyle)
{
if (!e)
return 0;
initElementAndPseudoState(e);
initForStyleResolve(e, parentStyle, pseudo);
m_style = parentStyle;
// Since we don't use pseudo-elements in any of our quirk/print user agent rules, don't waste time walking
// those rules.
// Check UA, user and author rules.
int firstUARule = -1, lastUARule = -1, firstUserRule = -1, lastUserRule = -1, firstAuthorRule = -1, lastAuthorRule = -1;
matchUARules(firstUARule, lastUARule);
if (m_matchAuthorAndUserStyles) {
matchRules(m_userStyle, firstUserRule, lastUserRule);
matchRules(m_authorStyle, firstAuthorRule, lastAuthorRule);
}
if (m_matchedDecls.isEmpty())
return 0;
m_style = RenderStyle::create();
if (parentStyle)
m_style->inheritFrom(parentStyle);
m_style->noninherited_flags._styleType = pseudo;
m_lineHeightValue = 0;
// High-priority properties.
applyDeclarations(true, false, 0, m_matchedDecls.size() - 1);
applyDeclarations(true, true, firstAuthorRule, lastAuthorRule);
applyDeclarations(true, true, firstUserRule, lastUserRule);
applyDeclarations(true, true, firstUARule, lastUARule);
// If our font got dirtied, go ahead and update it now.
if (m_fontDirty)
updateFont();
// Line-height is set when we are sure we decided on the font-size
if (m_lineHeightValue)
applyProperty(CSSPropertyLineHeight, m_lineHeightValue);
// Now do the normal priority properties.
applyDeclarations(false, false, firstUARule, lastUARule);
// Cache our border and background so that we can examine them later.
cacheBorderAndBackground();
applyDeclarations(false, false, lastUARule + 1, m_matchedDecls.size() - 1);
applyDeclarations(false, true, firstAuthorRule, lastAuthorRule);
applyDeclarations(false, true, firstUserRule, lastUserRule);
applyDeclarations(false, true, firstUARule, lastUARule);
// If our font got dirtied by one of the non-essential font props,
// go ahead and update it a second time.
if (m_fontDirty)
updateFont();
// Clean up our style object's display and text decorations (among other fixups).
adjustRenderStyle(style(), 0);
// Now return the style.
return m_style.release();
}
static void addIntrinsicMargins(RenderStyle* style)
{
// Intrinsic margin value.
const int intrinsicMargin = 2 * style->effectiveZoom();
// FIXME: Using width/height alone and not also dealing with min-width/max-width is flawed.
// FIXME: Using "quirk" to decide the margin wasn't set is kind of lame.
if (style->width().isIntrinsicOrAuto()) {
if (style->marginLeft().quirk())
style->setMarginLeft(Length(intrinsicMargin, Fixed));
if (style->marginRight().quirk())
style->setMarginRight(Length(intrinsicMargin, Fixed));
}
if (style->height().isAuto()) {
if (style->marginTop().quirk())
style->setMarginTop(Length(intrinsicMargin, Fixed));
if (style->marginBottom().quirk())
style->setMarginBottom(Length(intrinsicMargin, Fixed));
}
}
void CSSStyleSelector::adjustRenderStyle(RenderStyle* style, Element *e)
{
// Cache our original display.
style->setOriginalDisplay(style->display());
if (style->display() != NONE) {
// If we have a that specifies a float property, in quirks mode we just drop the float
// property.
// Sites also commonly use display:inline/block on | s and s. In quirks mode we force
// these tags to retain their display types.
if (!m_checker.m_strictParsing && e) {
if (e->hasTagName(tdTag)) {
style->setDisplay(TABLE_CELL);
style->setFloating(FNONE);
}
else if (e->hasTagName(tableTag))
style->setDisplay(style->isDisplayInlineType() ? INLINE_TABLE : TABLE);
}
if (e && (e->hasTagName(tdTag) || e->hasTagName(thTag))) {
if (style->whiteSpace() == KHTML_NOWRAP) {
// Figure out if we are really nowrapping or if we should just
// use normal instead. If the width of the cell is fixed, then
// we don't actually use NOWRAP.
if (style->width().isFixed())
style->setWhiteSpace(NORMAL);
else
style->setWhiteSpace(NOWRAP);
}
}
// Tables never support the -webkit-* values for text-align and will reset back to the default.
if (e && e->hasTagName(tableTag) && (style->textAlign() == WEBKIT_LEFT || style->textAlign() == WEBKIT_CENTER || style->textAlign() == WEBKIT_RIGHT))
style->setTextAlign(TAAUTO);
// Frames and framesets never honor position:relative or position:absolute. This is necessary to
// fix a crash where a site tries to position these objects. They also never honor display.
if (e && (e->hasTagName(frameTag) || e->hasTagName(framesetTag))) {
style->setPosition(StaticPosition);
style->setDisplay(BLOCK);
}
// Table headers with a text-align of auto will change the text-align to center.
if (e && e->hasTagName(thTag) && style->textAlign() == TAAUTO)
style->setTextAlign(CENTER);
// Mutate the display to BLOCK or TABLE for certain cases, e.g., if someone attempts to
// position or float an inline, compact, or run-in. Cache the original display, since it
// may be needed for positioned elements that have to compute their static normal flow
// positions. We also force inline-level roots to be block-level.
if (style->display() != BLOCK && style->display() != TABLE && style->display() != BOX &&
(style->position() == AbsolutePosition || style->position() == FixedPosition || style->floating() != FNONE ||
(e && e->document()->documentElement() == e))) {
if (style->display() == INLINE_TABLE)
style->setDisplay(TABLE);
else if (style->display() == INLINE_BOX)
style->setDisplay(BOX);
else if (style->display() == LIST_ITEM) {
// It is a WinIE bug that floated list items lose their bullets, so we'll emulate the quirk,
// but only in quirks mode.
if (!m_checker.m_strictParsing && style->floating() != FNONE)
style->setDisplay(BLOCK);
}
else
style->setDisplay(BLOCK);
}
// After performing the display mutation, check table rows. We do not honor position:relative on
// table rows or cells. This has been established in CSS2.1 (and caused a crash in containingBlock()
// on some sites).
if ((style->display() == TABLE_HEADER_GROUP || style->display() == TABLE_ROW_GROUP ||
style->display() == TABLE_FOOTER_GROUP || style->display() == TABLE_ROW || style->display() == TABLE_CELL) &&
style->position() == RelativePosition)
style->setPosition(StaticPosition);
}
// Make sure our z-index value is only applied if the object is positioned.
if (style->position() == StaticPosition)
style->setHasAutoZIndex();
// Auto z-index becomes 0 for the root element and transparent objects. This prevents
// cases where objects that should be blended as a single unit end up with a non-transparent
// object wedged in between them. Auto z-index also becomes 0 for objects that specify transforms/masks/reflections.
if (style->hasAutoZIndex() && ((e && e->document()->documentElement() == e) || style->opacity() < 1.0f ||
style->hasTransform() || style->hasMask() || style->boxReflect()))
style->setZIndex(0);
// Button, legend, input, select and textarea all consider width values of 'auto' to be 'intrinsic'.
// This will be important when we use block flows for all form controls.
if (e && (e->hasTagName(legendTag) || e->hasTagName(buttonTag) || e->hasTagName(inputTag) ||
e->hasTagName(selectTag) || e->hasTagName(textareaTag)
#if ENABLE(WML)
|| e->hasTagName(WMLNames::insertedLegendTag)
|| e->hasTagName(WMLNames::inputTag)
#endif
)) {
if (style->width().isAuto())
style->setWidth(Length(Intrinsic));
}
// Finally update our text decorations in effect, but don't allow text-decoration to percolate through
// tables, inline blocks, inline tables, or run-ins.
if (style->display() == TABLE || style->display() == INLINE_TABLE || style->display() == RUN_IN
|| style->display() == INLINE_BLOCK || style->display() == INLINE_BOX)
style->setTextDecorationsInEffect(style->textDecoration());
else
style->addToTextDecorationsInEffect(style->textDecoration());
// If either overflow value is not visible, change to auto.
if (style->overflowX() == OMARQUEE && style->overflowY() != OMARQUEE)
style->setOverflowY(OMARQUEE);
else if (style->overflowY() == OMARQUEE && style->overflowX() != OMARQUEE)
style->setOverflowX(OMARQUEE);
else if (style->overflowX() == OVISIBLE && style->overflowY() != OVISIBLE)
style->setOverflowX(OAUTO);
else if (style->overflowY() == OVISIBLE && style->overflowX() != OVISIBLE)
style->setOverflowY(OAUTO);
// Table rows, sections and the table itself will support overflow:hidden and will ignore scroll/auto.
// FIXME: Eventually table sections will support auto and scroll.
if (style->display() == TABLE || style->display() == INLINE_TABLE ||
style->display() == TABLE_ROW_GROUP || style->display() == TABLE_ROW) {
if (style->overflowX() != OVISIBLE && style->overflowX() != OHIDDEN)
style->setOverflowX(OVISIBLE);
if (style->overflowY() != OVISIBLE && style->overflowY() != OHIDDEN)
style->setOverflowY(OVISIBLE);
}
// Menulists should have visible overflow
if (style->appearance() == MenulistPart) {
style->setOverflowX(OVISIBLE);
style->setOverflowY(OVISIBLE);
}
// Cull out any useless layers and also repeat patterns into additional layers.
style->adjustBackgroundLayers();
style->adjustMaskLayers();
// Do the same for animations and transitions.
style->adjustAnimations();
style->adjustTransitions();
// Important: Intrinsic margins get added to controls before the theme has adjusted the style, since the theme will
// alter fonts and heights/widths.
if (e && e->isControl() && style->fontSize() >= 11) {
// Don't apply intrinsic margins to image buttons. The designer knows how big the images are,
// so we have to treat all image buttons as though they were explicitly sized.
if (!e->hasTagName(inputTag) || static_cast(e)->inputType() != HTMLInputElement::IMAGE)
addIntrinsicMargins(style);
}
// Let the theme also have a crack at adjusting the style.
if (style->hasAppearance())
theme()->adjustStyle(this, style, e, m_hasUAAppearance, m_borderData, m_backgroundData, m_backgroundColor);
#if ENABLE(SVG)
if (e && e->isSVGElement()) {
// Spec: http://www.w3.org/TR/SVG/masking.html#OverflowProperty
if (style->overflowY() == OSCROLL)
style->setOverflowY(OHIDDEN);
else if (style->overflowY() == OAUTO)
style->setOverflowY(OVISIBLE);
if (style->overflowX() == OSCROLL)
style->setOverflowX(OHIDDEN);
else if (style->overflowX() == OAUTO)
style->setOverflowX(OVISIBLE);
// Only the root |