X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fthird_party%2FWebKit%2FSource%2Fcore%2Fcss%2Fresolver%2FStyleResolver.cpp;h=edcebea5a1767097fc33503f849559530ad1c158;hb=1afa4dd80ef85af7c90efaea6959db1d92330844;hp=28550e67db9a5df2dac7e6b32080e76d7740b332;hpb=90762837333c13ccf56f2ad88e4481fc71e8d281;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/third_party/WebKit/Source/core/css/resolver/StyleResolver.cpp b/src/third_party/WebKit/Source/core/css/resolver/StyleResolver.cpp index 28550e6..edcebea 100644 --- a/src/third_party/WebKit/Source/core/css/resolver/StyleResolver.cpp +++ b/src/third_party/WebKit/Source/core/css/resolver/StyleResolver.cpp @@ -81,7 +81,6 @@ #include "core/rendering/style/KeyframeList.h" #include "core/svg/SVGDocumentExtensions.h" #include "core/svg/SVGElement.h" -#include "core/svg/SVGFontFaceElement.h" #include "platform/RuntimeEnabledFeatures.h" #include "wtf/StdLibExtras.h" @@ -147,15 +146,6 @@ StyleResolver::StyleResolver(Document& document) } initWatchedSelectorRules(CSSSelectorWatch::from(document).watchedCallbackSelectors()); - -#if ENABLE(SVG_FONTS) - if (document.svgExtensions()) { - const WillBeHeapHashSet >& svgFontFaceElements = document.svgExtensions()->svgFontFaceElements(); - WillBeHeapHashSet >::const_iterator end = svgFontFaceElements.end(); - for (WillBeHeapHashSet >::const_iterator it = svgFontFaceElements.begin(); it != end; ++it) - addFontFaceRule(&document, document.styleEngine()->fontSelector(), (*it)->fontFaceRule()); - } -#endif } void StyleResolver::initWatchedSelectorRules(const WillBeHeapVector >& watchedSelectors) @@ -193,13 +183,25 @@ void StyleResolver::appendCSSStyleSheet(CSSStyleSheet* cssSheet) ScopedStyleResolver& resolver = treeScope->ensureScopedStyleResolver(); document().styleEngine()->addScopedStyleResolver(&resolver); - resolver.addRulesFromSheet(cssSheet, *m_medium, this); + unsigned index = resolver.appendCSSStyleSheet(cssSheet); + + addRulesFromSheet(cssSheet, treeScope, index); +} + +void StyleResolver::addRulesFromSheet(CSSStyleSheet* cssSheet, TreeScope* treeScope, unsigned index) +{ + StyleSheetContents* sheet = cssSheet->contents(); + AddRuleFlags addRuleFlags = document().securityOrigin()->canRequest(sheet->baseURL()) ? RuleHasDocumentSecurityOrigin : RuleHasNoSpecialState; + const RuleSet& ruleSet = sheet->ensureRuleSet(*m_medium, addRuleFlags); + + addMediaQueryResults(ruleSet.viewportDependentMediaQueryResults()); + processScopedRules(ruleSet, cssSheet, index, treeScope->rootNode()); } void StyleResolver::appendPendingAuthorStyleSheets() { - for (WillBeHeapListHashSet, 16>::iterator it = m_pendingStyleSheets.begin(); it != m_pendingStyleSheets.end(); ++it) - appendCSSStyleSheet(*it); + for (const auto& styleSheet : m_pendingStyleSheets) + appendCSSStyleSheet(styleSheet); m_pendingStyleSheets.clear(); finishAppendAuthorStyleSheets(); @@ -438,23 +440,23 @@ void StyleResolver::matchUARules(ElementRuleCollector& collector) CSSDefaultStyleSheets& defaultStyleSheets = CSSDefaultStyleSheets::instance(); RuleSet* userAgentStyleSheet = m_printMediaType ? defaultStyleSheets.defaultPrintStyle() : defaultStyleSheets.defaultStyle(); - matchUARules(collector, userAgentStyleSheet); + matchRuleSet(collector, userAgentStyleSheet); // In quirks mode, we match rules from the quirks user agent sheet. if (document().inQuirksMode()) - matchUARules(collector, defaultStyleSheets.defaultQuirksStyle()); + matchRuleSet(collector, defaultStyleSheets.defaultQuirksStyle()); // If document uses view source styles (in view source mode or in xml viewer mode), then we match rules from the view source style sheet. if (document().isViewSource()) - matchUARules(collector, defaultStyleSheets.defaultViewSourceStyle()); + matchRuleSet(collector, defaultStyleSheets.defaultViewSourceStyle()); if (document().isTransitionDocument()) - matchUARules(collector, defaultStyleSheets.defaultTransitionStyle()); + matchRuleSet(collector, defaultStyleSheets.defaultTransitionStyle()); collector.setMatchingUARules(false); } -void StyleResolver::matchUARules(ElementRuleCollector& collector, RuleSet* rules) +void StyleResolver::matchRuleSet(ElementRuleCollector& collector, RuleSet* rules) { collector.clearMatchedRules(); collector.matchedResult().ranges.lastUARule = collector.matchedResult().matchedProperties.size() - 1; @@ -578,13 +580,23 @@ PassRefPtr StyleResolver::styleForElement(Element* element, RenderS return sharedStyle.release(); } - if (state.parentStyle()) { - state.setStyle(RenderStyle::create()); - state.style()->inheritFrom(state.parentStyle(), isAtShadowBoundary(element) ? RenderStyle::AtShadowBoundary : RenderStyle::NotAtShadowBoundary); + ActiveAnimations* activeAnimations = element->activeAnimations(); + const RenderStyle* baseRenderStyle = activeAnimations ? activeAnimations->baseRenderStyle() : nullptr; + + if (baseRenderStyle) { + state.setStyle(RenderStyle::clone(baseRenderStyle)); + if (!state.parentStyle()) + state.setParentStyle(defaultStyleForElement()); } else { - state.setStyle(defaultStyleForElement()); - state.setParentStyle(RenderStyle::clone(state.style())); + if (state.parentStyle()) { + state.setStyle(RenderStyle::create()); + state.style()->inheritFrom(state.parentStyle(), isAtShadowBoundary(element) ? RenderStyle::AtShadowBoundary : RenderStyle::NotAtShadowBoundary); + } else { + state.setStyle(defaultStyleForElement()); + state.setParentStyle(RenderStyle::clone(state.style())); + } } + // contenteditable attribute (implemented by -webkit-user-modify) should // be propagated from shadow host to distributed node. if (state.distributedToInsertionPoint()) { @@ -594,8 +606,6 @@ PassRefPtr StyleResolver::styleForElement(Element* element, RenderS } } - state.fontBuilder().initForStyleResolve(state.document(), state.style()); - if (element->isLink()) { state.style()->setIsLink(true); EInsideLink linkState = state.elementLinkState(); @@ -607,12 +617,13 @@ PassRefPtr StyleResolver::styleForElement(Element* element, RenderS state.style()->setInsideLink(linkState); } - bool needsCollection = false; - CSSDefaultStyleSheets::instance().ensureDefaultStyleSheetsForElement(element, needsCollection); - if (needsCollection) - collectFeatures(); + if (!baseRenderStyle) { + + bool needsCollection = false; + CSSDefaultStyleSheets::instance().ensureDefaultStyleSheetsForElement(element, needsCollection); + if (needsCollection) + collectFeatures(); - { ElementRuleCollector collector(state.elementContext(), m_selectorFilter, state.style()); matchAllRules(state, collector, matchingBehavior != MatchAllRulesExcludingSMIL); @@ -621,12 +632,15 @@ PassRefPtr StyleResolver::styleForElement(Element* element, RenderS applyCallbackSelectors(state); addContentAttrValuesToFeatures(state.contentAttrValues(), m_features); - } - // Cache our original display. - state.style()->setOriginalDisplay(state.style()->display()); + // Cache our original display. + state.style()->setOriginalDisplay(state.style()->display()); - adjustRenderStyle(state, element); + adjustRenderStyle(state, element); + + if (activeAnimations) + activeAnimations->updateBaseRenderStyle(state.style()); + } // FIXME: The CSSWG wants to specify that the effects of animations are applied before // important rules, but this currently happens here as we require adjustment to have happened @@ -663,9 +677,6 @@ PassRefPtr StyleResolver::styleForKeyframe(Element& element, const // Create the style state.setStyle(RenderStyle::clone(&elementStyle)); - state.setLineHeightValue(0); - - state.fontBuilder().initForStyleResolve(state.document(), state.style()); // We don't need to bother with !important. Since there is only ever one // decl, there's nothing to override. So just add the first properties. @@ -678,10 +689,6 @@ PassRefPtr StyleResolver::styleForKeyframe(Element& element, const // If our font got dirtied, go ahead and update it now. updateFont(state); - // Line-height is set when we are sure we decided on the font-size - if (state.lineHeightValue()) - StyleBuilder::applyProperty(CSSPropertyLineHeight, state, state.lineHeightValue()); - // Now do rest of the properties. applyMatchedProperties(state, result, false, 0, result.matchedProperties.size() - 1, inheritedOnly); @@ -703,7 +710,6 @@ PassRefPtrWillBeRawPtr StyleResolver::createAnimatableValueSnap style = RenderStyle::create(); StyleResolverState state(element.document(), &element); state.setStyle(style); - state.fontBuilder().initForStyleResolve(state.document(), state.style()); return createAnimatableValueSnapshot(state, property, value); } @@ -758,10 +764,18 @@ bool StyleResolver::pseudoStyleForElementInternal(Element& element, const Pseudo ASSERT(document().frame()); ASSERT(document().settings()); ASSERT(pseudoStyleRequest.pseudoId != FIRST_LINE_INHERITED); + ASSERT(state.parentStyle()); StyleResolverParentScope::ensureParentStackIsPushed(); - if (pseudoStyleRequest.allowsInheritance(state.parentStyle())) { + Element* pseudoElement = element.pseudoElement(pseudoStyleRequest.pseudoId); + + ActiveAnimations* activeAnimations = pseudoElement ? pseudoElement->activeAnimations() : nullptr; + const RenderStyle* baseRenderStyle = activeAnimations ? activeAnimations->baseRenderStyle() : nullptr; + + if (baseRenderStyle) { + state.setStyle(RenderStyle::clone(baseRenderStyle)); + } else if (pseudoStyleRequest.allowsInheritance(state.parentStyle())) { state.setStyle(RenderStyle::create()); state.style()->inheritFrom(state.parentStyle()); } else { @@ -770,12 +784,11 @@ bool StyleResolver::pseudoStyleForElementInternal(Element& element, const Pseudo } state.style()->setStyleType(pseudoStyleRequest.pseudoId); - state.fontBuilder().initForStyleResolve(state.document(), state.style()); // Since we don't use pseudo-elements in any of our quirk/print // user agent rules, don't waste time walking those rules. - { + if (!baseRenderStyle) { // Check UA, user and author rules. ElementRuleCollector collector(state.elementContext(), m_selectorFilter, state.style()); collector.setPseudoStyleRequest(pseudoStyleRequest); @@ -790,19 +803,22 @@ bool StyleResolver::pseudoStyleForElementInternal(Element& element, const Pseudo applyCallbackSelectors(state); addContentAttrValuesToFeatures(state.contentAttrValues(), m_features); - } - // Cache our original display. - state.style()->setOriginalDisplay(state.style()->display()); + // Cache our original display. + state.style()->setOriginalDisplay(state.style()->display()); - // FIXME: Passing 0 as the Element* introduces a lot of complexity - // in the adjustRenderStyle code. - adjustRenderStyle(state, 0); + // FIXME: Passing 0 as the Element* introduces a lot of complexity + // in the adjustRenderStyle code. + adjustRenderStyle(state, 0); + + if (activeAnimations) + activeAnimations->updateBaseRenderStyle(state.style()); + } // FIXME: The CSSWG wants to specify that the effects of animations are applied before // important rules, but this currently happens here as we require adjustment to have happened // before deciding which properties to transition. - if (applyAnimatedProperties(state, element.pseudoElement(pseudoStyleRequest.pseudoId))) + if (applyAnimatedProperties(state, pseudoElement)) adjustRenderStyle(state, 0); didAccess(); @@ -844,8 +860,6 @@ PassRefPtr StyleResolver::styleForPage(int pageIndex) ASSERT(rootElementStyle); state.style()->inheritFrom(rootElementStyle); - state.fontBuilder().initForStyleResolve(state.document(), state.style()); - PageRuleCollector collector(rootElementStyle, pageIndex); collector.matchPageRules(CSSDefaultStyleSheets::instance().defaultPrintStyle()); @@ -853,7 +867,6 @@ PassRefPtr StyleResolver::styleForPage(int pageIndex) if (ScopedStyleResolver* scopedResolver = document().scopedStyleResolver()) scopedResolver->matchPageRules(collector); - state.setLineHeightValue(0); bool inheritedOnly = false; MatchResult& result = collector.matchedResult(); @@ -862,10 +875,6 @@ PassRefPtr StyleResolver::styleForPage(int pageIndex) // If our font got dirtied, go ahead and update it now. updateFont(state); - // Line-height is set when we are sure we decided on the font-size. - if (state.lineHeightValue()) - StyleBuilder::applyProperty(CSSPropertyLineHeight, state, state.lineHeightValue()); - applyMatchedProperties(state, result, false, 0, result.matchedProperties.size() - 1, inheritedOnly); addContentAttrValuesToFeatures(state.contentAttrValues(), m_features); @@ -899,9 +908,6 @@ PassRefPtr StyleResolver::defaultStyleForElement() { StyleResolverState state(document(), 0); state.setStyle(RenderStyle::create()); - state.fontBuilder().initForStyleResolve(document(), state.style()); - state.style()->setLineHeight(RenderStyle::initialLineHeight()); - state.setLineHeightValue(0); state.fontBuilder().setInitial(state.style()->effectiveZoom()); state.style()->font().update(document().styleEngine()->fontSelector()); return state.takeStyle(); @@ -1046,11 +1052,11 @@ void StyleResolver::styleTreeResolveScopedKeyframesRules(const Element* element, template void StyleResolver::applyAnimatedProperties(StyleResolverState& state, const WillBeHeapHashMap >& activeInterpolations) { - for (WillBeHeapHashMap >::const_iterator iter = activeInterpolations.begin(); iter != activeInterpolations.end(); ++iter) { - CSSPropertyID property = iter->key; + for (const auto& interpolationEntry : activeInterpolations) { + CSSPropertyID property = interpolationEntry.key; if (!isPropertyForPass(property)) continue; - const StyleInterpolation* interpolation = toStyleInterpolation(iter->value.get()); + const StyleInterpolation* interpolation = toStyleInterpolation(interpolationEntry.value.get()); interpolation->apply(state); } } @@ -1182,7 +1188,6 @@ static inline bool isValidFirstLetterStyleProperty(CSSPropertyID id) case CSSPropertyWebkitBorderEndColor: case CSSPropertyWebkitBorderEndStyle: case CSSPropertyWebkitBorderEndWidth: - case CSSPropertyWebkitBorderFit: case CSSPropertyWebkitBorderHorizontalSpacing: case CSSPropertyWebkitBorderImage: case CSSPropertyWebkitBorderRadius: @@ -1242,9 +1247,9 @@ template<> CSSPropertyID StyleResolver::firstCSSPropertyId CSSPropertyID StyleResolver::lastCSSPropertyId() { - COMPILE_ASSERT(CSSPropertyLineHeight == CSSPropertyColor + 18, CSS_line_height_is_end_of_high_prioity_property_range); - COMPILE_ASSERT(CSSPropertyZoom == CSSPropertyLineHeight - 1, CSS_zoom_is_before_line_height); - return CSSPropertyLineHeight; + COMPILE_ASSERT(CSSPropertyZoom == CSSPropertyColor + 16, CSS_zoom_is_end_of_high_priority_property_range); + COMPILE_ASSERT(CSSPropertyTextRendering == CSSPropertyZoom - 1, CSS_text_rendering_is_before_zoom); + return CSSPropertyZoom; } // This method returns the first CSSPropertyId of remaining properties, @@ -1255,7 +1260,7 @@ template<> CSSPropertyID StyleResolver::lastCSSPropertyId. template<> CSSPropertyID StyleResolver::firstCSSPropertyId() { - COMPILE_ASSERT(CSSPropertyAlignContent == CSSPropertyLineHeight + 1, CSS_background_is_first_low_priority_property); + COMPILE_ASSERT(CSSPropertyAlignContent == CSSPropertyZoom + 1, CSS_align_content_is_first_low_priority_property); return CSSPropertyAlignContent; } @@ -1284,7 +1289,7 @@ void StyleResolver::applyAllProperty(StyleResolverState& state, CSSValue* allVal CSSPropertyID propertyId = static_cast(i); // StyleBuilder does not allow any expanded shorthands. - if (isExpandedShorthandForAll(propertyId)) + if (isShorthandProperty(propertyId)) continue; // all shorthand spec says: @@ -1324,6 +1329,11 @@ void StyleResolver::applyProperties(StyleResolverState& state, const StyleProper continue; } + if (propertyWhitelistType == PropertyWhitelistCue && !isValidCueStyleProperty(property)) + continue; + if (propertyWhitelistType == PropertyWhitelistFirstLetter && !isValidFirstLetterStyleProperty(property)) + continue; + if (inheritedOnly && !current.isInherited()) { // If the property value is explicitly inherited, we need to apply further non-inherited properties // as they might override the value inherited here. For this reason we don't allow declarations with @@ -1332,16 +1342,10 @@ void StyleResolver::applyProperties(StyleResolverState& state, const StyleProper continue; } - if (propertyWhitelistType == PropertyWhitelistCue && !isValidCueStyleProperty(property)) - continue; - if (propertyWhitelistType == PropertyWhitelistFirstLetter && !isValidFirstLetterStyleProperty(property)) - continue; if (!isPropertyForPass(property)) continue; - if (pass == HighPriorityProperties && property == CSSPropertyLineHeight) - state.setLineHeightValue(current.value()); - else - StyleBuilder::applyProperty(current.id(), state, current.value()); + + StyleBuilder::applyProperty(current.id(), state, current.value()); } } @@ -1424,7 +1428,6 @@ void StyleResolver::applyMatchedProperties(StyleResolverState& state, const Matc // high-priority properties first, i.e., those properties that other properties depend on. // The order is (1) high-priority not important, (2) high-priority important, (3) normal not important // and (4) normal important. - state.setLineHeightValue(0); applyMatchedProperties(state, matchResult, false, 0, matchResult.matchedProperties.size() - 1, applyInheritedOnly); applyMatchedProperties(state, matchResult, true, matchResult.ranges.firstAuthorRule, matchResult.ranges.lastAuthorRule, applyInheritedOnly); applyMatchedProperties(state, matchResult, true, matchResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly); @@ -1448,10 +1451,6 @@ void StyleResolver::applyMatchedProperties(StyleResolverState& state, const Matc // If our font got dirtied, go ahead and update it now. updateFont(state); - // Line-height is set when we are sure we decided on the font-size. - if (state.lineHeightValue()) - StyleBuilder::applyProperty(CSSPropertyLineHeight, state, state.lineHeightValue()); - // Many properties depend on the font. If it changes we just apply all properties. if (cachedMatchedProperties && cachedMatchedProperties->renderStyle->fontDescription() != state.style()->fontDescription()) applyInheritedOnly = false; @@ -1535,8 +1534,6 @@ void StyleResolver::applyPropertiesToStyle(const CSSPropertyValue* properties, s StyleResolverState state(document(), document().documentElement(), style); state.setStyle(style); - state.fontBuilder().initForStyleResolve(document(), style); - for (size_t i = 0; i < count; ++i) { if (properties[i].value) { // As described in BUG66291, setting font-size and line-height on a font may entail a CSSPrimitiveValue::computeLengthDouble call,