diff options
author | Steve Block <steveblock@google.com> | 2010-07-08 12:51:48 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2010-07-09 15:33:40 +0100 |
commit | ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24 (patch) | |
tree | bb45155550ec013adc0ad10f4d7d354c6469b022 /WebCore/css/CSSStyleSelector.cpp | |
parent | d4b24d9a829ed7de70381c8b99fb75a07ab40466 (diff) | |
download | external_webkit-ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24.zip external_webkit-ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24.tar.gz external_webkit-ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24.tar.bz2 |
Merge WebKit at r62496: Initial merge by git
Change-Id: Ie3da0770eca22a70a632e3571f31cfabc80facb2
Diffstat (limited to 'WebCore/css/CSSStyleSelector.cpp')
-rw-r--r-- | WebCore/css/CSSStyleSelector.cpp | 184 |
1 files changed, 100 insertions, 84 deletions
diff --git a/WebCore/css/CSSStyleSelector.cpp b/WebCore/css/CSSStyleSelector.cpp index 3af3291..750988e 100644 --- a/WebCore/css/CSSStyleSelector.cpp +++ b/WebCore/css/CSSStyleSelector.cpp @@ -30,7 +30,6 @@ #include "CSSBorderImageValue.h" #include "CSSCursorImageValue.h" #include "CSSFontFaceRule.h" -#include "CSSHelper.h" #include "CSSImportRule.h" #include "CSSMediaRule.h" #include "CSSPageRule.h" @@ -1373,6 +1372,55 @@ PassRefPtr<RenderStyle> CSSStyleSelector::styleForElement(Element* e, RenderStyl return m_style.release(); } +PassRefPtr<RenderStyle> CSSStyleSelector::styleForKeyframe(const RenderStyle* elementStyle, const WebKitCSSKeyframeRule* keyframeRule, KeyframeList& list) +{ + if (keyframeRule->style()) + addMatchedDeclaration(keyframeRule->style()); + + ASSERT(!m_style); + + // Create the style + m_style = RenderStyle::clone(elementStyle); + + m_lineHeightValue = 0; + + // 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. + if (keyframeRule->style()) + applyDeclarations<true>(false, 0, m_matchedDecls.size() - 1); + + // 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 rest of the properties. + if (keyframeRule->style()) + applyDeclarations<false>(false, 0, m_matchedDecls.size() - 1); + + // 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(); + + // Add all the animating properties to the list + if (keyframeRule->style()) { + CSSMutableStyleDeclaration::const_iterator end = keyframeRule->style()->end(); + for (CSSMutableStyleDeclaration::const_iterator it = keyframeRule->style()->begin(); it != end; ++it) { + int property = (*it).id(); + // Timing-function within keyframes is special, because it is not animated; it just + // describes the timing function between this keyframe and the next. + if (property != CSSPropertyWebkitAnimationTimingFunction) + list.addProperty(property); + } + } + + return m_style.release(); +} + void CSSStyleSelector::keyframeStylesForAnimation(Element* e, const RenderStyle* elementStyle, KeyframeList& list) { list.clear(); @@ -1387,6 +1435,7 @@ void CSSStyleSelector::keyframeStylesForAnimation(Element* e, const RenderStyle* return; const WebKitCSSKeyframesRule* rule = m_keyframesRuleMap.find(list.animationName().impl()).get()->second.get(); + RefPtr<RenderStyle> keyframeStyle; // Construct and populate the style for each keyframe for (unsigned i = 0; i < rule->length(); ++i) { @@ -1394,65 +1443,36 @@ void CSSStyleSelector::keyframeStylesForAnimation(Element* e, const RenderStyle* initElement(e); initForStyleResolve(e); - const WebKitCSSKeyframeRule* kf = rule->item(i); - addMatchedDeclaration(kf->style()); - - ASSERT(!m_style); - - // Create the style - m_style = RenderStyle::clone(elementStyle); - - m_lineHeightValue = 0; + const WebKitCSSKeyframeRule* keyframeRule = rule->item(i); - // 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. - applyDeclarations<true>(false, 0, m_matchedDecls.size() - 1); - - // If our font got dirtied, go ahead and update it now. - if (m_fontDirty) - updateFont(); + keyframeStyle = styleForKeyframe(elementStyle, keyframeRule, list); - // Line-height is set when we are sure we decided on the font-size - if (m_lineHeightValue) - applyProperty(CSSPropertyLineHeight, m_lineHeightValue); - - // Now do rest of the properties. - applyDeclarations<false>(false, 0, m_matchedDecls.size() - 1); - - // 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(); - - // Add all the animating properties to the list - CSSMutableStyleDeclaration::const_iterator end = kf->style()->end(); - for (CSSMutableStyleDeclaration::const_iterator it = kf->style()->begin(); it != end; ++it) { - int property = (*it).id(); - // Timing-function within keyframes is special, because it is not animated; it just - // describes the timing function between this keyframe and the next. - if (property != CSSPropertyWebkitAnimationTimingFunction) - list.addProperty(property); - } - // Add this keyframe style to all the indicated key times Vector<float> keys; - kf->getKeys(keys); + keyframeRule->getKeys(keys); for (size_t keyIndex = 0; keyIndex < keys.size(); ++keyIndex) { float key = keys[keyIndex]; - list.insert(key, m_style); + list.insert(key, keyframeStyle.get()); } - m_style = 0; + keyframeStyle.release(); } - // Make sure there is a 0% and a 100% keyframe - float first = -1; - float last = -1; - if (list.size() >= 2) { - first = list.beginKeyframes()->key(); - last = (list.endKeyframes()-1)->key(); - } - if (first != 0 || last != 1) - list.clear(); + // If the 0% keyframe is missing, create it (but only if there is at least one other keyframe) + int initialListSize = list.size(); + if (initialListSize > 0 && list.beginKeyframes()->key() != 0) { + RefPtr<WebKitCSSKeyframeRule> keyframe = WebKitCSSKeyframeRule::create(); + keyframe->setKeyText("0%"); + keyframeStyle = styleForKeyframe(elementStyle, keyframe.get(), list); + list.insert(0, keyframeStyle.release()); + } + + // If the 100% keyframe is missing, create it (but only if there is at least one other keyframe) + if (initialListSize > 0 && (list.endKeyframes() - 1)->key() != 1) { + RefPtr<WebKitCSSKeyframeRule> keyframe = WebKitCSSKeyframeRule::create(); + keyframe->setKeyText("100%"); + keyframeStyle = styleForKeyframe(elementStyle, keyframe.get(), list); + list.insert(1, keyframeStyle.release()); + } } PassRefPtr<RenderStyle> CSSStyleSelector::pseudoStyleForElement(PseudoId pseudo, Element* e, RenderStyle* parentStyle, bool matchVisitedPseudoClass) @@ -5527,14 +5547,17 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value) void CSSStyleSelector::applyPageSizeProperty(CSSValue* value) { + m_style->resetPageSizeType(); if (!value->isValueList()) return; CSSValueList* valueList = static_cast<CSSValueList*>(value); Length width; Length height; + PageSizeType pageSizeType = PAGE_SIZE_AUTO; switch (valueList->length()) { case 2: { // <length>{2} | <page-size> <orientation> + pageSizeType = PAGE_SIZE_RESOLVED; if (!valueList->item(0)->isPrimitiveValue() || !valueList->item(1)->isPrimitiveValue()) return; CSSPrimitiveValue* primitiveValue0 = static_cast<CSSPrimitiveValue*>(valueList->item(0)); @@ -5563,24 +5586,24 @@ void CSSStyleSelector::applyPageSizeProperty(CSSValue* value) int type = primitiveValue->primitiveType(); if (CSSPrimitiveValue::isUnitTypeLength(type)) { // <length> + pageSizeType = PAGE_SIZE_RESOLVED; width = height = Length(primitiveValue->computeLengthIntForLength(style(), m_rootElementStyle), Fixed); } else { if (type != CSSPrimitiveValue::CSS_IDENT) return; switch (primitiveValue->getIdent()) { case CSSValueAuto: - // auto - if (!pageSizeFromName(0, 0, width, height)) - return; + pageSizeType = PAGE_SIZE_AUTO; break; case CSSValuePortrait: + pageSizeType = PAGE_SIZE_AUTO_PORTRAIT; + break; case CSSValueLandscape: - // <page-size> - if (!pageSizeFromName(0, primitiveValue, width, height)) - return; + pageSizeType = PAGE_SIZE_AUTO_LANDSCAPE; break; default: - // [ portrait | landscape] + // <page-size> + pageSizeType = PAGE_SIZE_RESOLVED; if (!pageSizeFromName(primitiveValue, 0, width, height)) return; } @@ -5590,6 +5613,7 @@ void CSSStyleSelector::applyPageSizeProperty(CSSValue* value) default: return; } + m_style->setPageSizeType(pageSizeType); m_style->setPageSize(LengthSize(width, height)); return; } @@ -5605,31 +5629,10 @@ bool CSSStyleSelector::pageSizeFromName(CSSPrimitiveValue* pageSizeName, CSSPrim static const Length legalWidth = inchLength(8.5), legalHeight = inchLength(14); static const Length ledgerWidth = inchLength(11), ledgerHeight = inchLength(17); - // FIXME: Define UA default page size. Assume letter for now. - int ident = CSSValueLetter; - if (pageSizeName) { - if (pageSizeName->primitiveType() != CSSPrimitiveValue::CSS_IDENT) - return false; - ident = pageSizeName->getIdent(); - } + if (!pageSizeName || pageSizeName->primitiveType() != CSSPrimitiveValue::CSS_IDENT) + return false; - // FIXME: Define UA default page orientation. Assume portrait for now. - bool portrait = true; - if (pageOrientation) { - if (pageOrientation->primitiveType() != CSSPrimitiveValue::CSS_IDENT) - return false; - switch (pageOrientation->getIdent()) { - case CSSValueLandscape: - portrait = false; - break; - case CSSValuePortrait: - portrait = true; - break; - default: - return false; - } - } - switch (ident) { + switch (pageSizeName->getIdent()) { case CSSValueA5: width = a5Width; height = a5Height; @@ -5665,8 +5668,21 @@ bool CSSStyleSelector::pageSizeFromName(CSSPrimitiveValue* pageSizeName, CSSPrim default: return false; } - if (!portrait) - swap(width, height); + + if (pageOrientation) { + if (pageOrientation->primitiveType() != CSSPrimitiveValue::CSS_IDENT) + return false; + switch (pageOrientation->getIdent()) { + case CSSValueLandscape: + std::swap(width, height); + break; + case CSSValuePortrait: + // Nothing to do. + break; + default: + return false; + } + } return true; } |