?? cssstyleselector.cpp
字號:
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 <td> that specifies a float property, in quirks mode we just drop the float // property. // Sites also commonly use display:inline/block on <td>s and <table>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); if (e && e->hasTagName(legendTag)) style->setDisplay(BLOCK); // 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->hasTransformRelatedProperty() || 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->isFormControlElement() && 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<HTMLInputElement*>(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 <svg> element in an SVG document fragment tree honors css position if (!(e->hasTagName(SVGNames::svgTag) && e->parentNode() && !e->parentNode()->isSVGElement())) style->setPosition(RenderStyle::initialPosition()); }#endif}void CSSStyleSelector::updateFont(){ checkForTextSizeAdjust(); checkForGenericFamilyChange(style(), m_parentStyle); checkForZoomChange(style(), m_parentStyle); m_style->font().update(m_fontSelector); m_fontDirty = false;}void CSSStyleSelector::cacheBorderAndBackground(){ m_hasUAAppearance = m_style->hasAppearance(); if (m_hasUAAppearance) { m_borderData = m_style->border(); m_backgroundData = *m_style->backgroundLayers(); m_backgroundColor = m_style->backgroundColor(); }}PassRefPtr<CSSRuleList> CSSStyleSelector::styleRulesForElement(Element* e, bool authorOnly){ if (!e || !e->document()->haveStylesheetsLoaded()) return 0; m_checker.m_collectRulesOnly = true; initElementAndPseudoState(e); initForStyleResolve(e); if (!authorOnly) { int firstUARule = -1, lastUARule = -1; // First we match rules from the user agent sheet. matchUARules(firstUARule, lastUARule); // Now we check user sheet rules. if (m_matchAuthorAndUserStyles) { int firstUserRule = -1, lastUserRule = -1; matchRules(m_userStyle, firstUserRule, lastUserRule); } } if (m_matchAuthorAndUserStyles) { // Check the rules in author sheets. int firstAuthorRule = -1, lastAuthorRule = -1; matchRules(m_authorStyle, firstAuthorRule, lastAuthorRule); } m_checker.m_collectRulesOnly = false; return m_ruleList.release();}PassRefPtr<CSSRuleList> CSSStyleSelector::pseudoStyleRulesForElement(Element*, const String&, bool){ // FIXME: Implement this. return 0;}bool CSSStyleSelector::checkSelector(CSSSelector* sel){ m_dynamicPseudo = NOPSEUDO; // Check the selector SelectorMatch match = m_checker.checkSelector(sel, m_element, &m_selectorAttrs, m_dynamicPseudo, true, false, style(), m_parentStyle); if (match != SelectorMatches) return false; if (m_checker.m_pseudoStyle != NOPSEUDO && m_checker.m_pseudoStyle != m_dynamicPseudo) return false; return true;}// Recursive check of selectors and combinators// It can return 3 different values:// * SelectorMatches - the selector matches the element e// * SelectorFailsLocally - the selector fails for the element e// * SelectorFailsCompletely - the selector fails for e and any sibling or ancestor of eCSSStyleSelector::SelectorMatch CSSStyleSelector::SelectorChecker::checkSelector(CSSSelector* sel, Element* e, HashSet<AtomicStringImpl*>* selectorAttrs, PseudoId& dynamicPseudo, bool isAncestor, bool isSubSelector, RenderStyle* elementStyle, RenderStyle* elementParentStyle) const{#if ENABLE(SVG) // Spec: CSS2 selectors cannot be applied to the (conceptually) cloned DOM tree // because its contents are not part of the formal document structure. if (e->isSVGElement() && e->isShadowNode()) return SelectorFailsCompletely;#endif // first selector has to match if (!checkOneSelector(sel, e, selectorAttrs, dynamicPseudo, isAncestor, isSubSelector, elementStyle, elementParentStyle)) return SelectorFailsLocally; // The rest of the selectors has to match CSSSelector::Relation relation = sel->relation(); // Prepare next sel sel = sel->tagHistory(); if (!sel) return SelectorMatches; if (relation != CSSSelector::SubSelector) // Bail-out if this selector is irrelevant for the pseudoStyle if (m_pseudoStyle != NOPSEUDO && m_pseudoS
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -