diff options
Diffstat (limited to 'WebCore/css')
-rw-r--r-- | WebCore/css/CSSParser.cpp | 45 | ||||
-rw-r--r-- | WebCore/css/CSSStyleSelector.cpp | 184 | ||||
-rw-r--r-- | WebCore/css/CSSStyleSelector.h | 3 | ||||
-rw-r--r-- | WebCore/css/CSSStyleSheet.cpp | 3 | ||||
-rw-r--r-- | WebCore/css/html.css | 13 |
5 files changed, 152 insertions, 96 deletions
diff --git a/WebCore/css/CSSParser.cpp b/WebCore/css/CSSParser.cpp index 57c42d3..087018b 100644 --- a/WebCore/css/CSSParser.cpp +++ b/WebCore/css/CSSParser.cpp @@ -3717,7 +3717,8 @@ bool CSSParser::parseFontFaceUnicodeRange() if (failed) break; } - values->append(CSSUnicodeRangeValue::create(from, to)); + if (from <= to) + values->append(CSSUnicodeRangeValue::create(from, to)); m_valueList->next(); } if (failed || !values->length()) @@ -3731,7 +3732,7 @@ static inline bool isCSSWhitespace(UChar c) return c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\f'; } -static inline bool parseInt(const UChar*& string, const UChar* end, UChar terminator, int& value) +static inline bool parseColorInt(const UChar*& string, const UChar* end, UChar terminator, int& value) { const UChar* current = string; int localValue = 0; @@ -3744,8 +3745,17 @@ static inline bool parseInt(const UChar*& string, const UChar* end, UChar termin } if (current == end || !isASCIIDigit(*current)) return false; - while (current != end && isASCIIDigit(*current)) - localValue = localValue * 10 + *current++ - '0'; + while (current != end && isASCIIDigit(*current)) { + int newValue = localValue * 10 + *current++ - '0'; + if (newValue >= 255) { + // Clamp values at 255. + localValue = 255; + while (current != end && isASCIIDigit(*current)) + ++current; + break; + } + localValue = newValue; + } while (current != end && isCSSWhitespace(*current)) current++; if (current == end || *current++ != terminator) @@ -3768,11 +3778,11 @@ bool CSSParser::parseColor(const String &name, RGBA32& rgb, bool strict) int red; int green; int blue; - if (!parseInt(current, end, ',', red)) + if (!parseColorInt(current, end, ',', red)) return false; - if (!parseInt(current, end, ',', green)) + if (!parseColorInt(current, end, ',', green)) return false; - if (!parseInt(current, end, ')', blue)) + if (!parseColorInt(current, end, ')', blue)) return false; if (current != end) return false; @@ -3789,6 +3799,23 @@ bool CSSParser::parseColor(const String &name, RGBA32& rgb, bool strict) return false; } +static inline int colorIntFromValue(CSSParserValue* v) +{ + if (v->fValue <= 0.0) + return 0; + + if (v->unit == CSSPrimitiveValue::CSS_PERCENTAGE) { + if (v->fValue >= 100.0) + return 255; + return static_cast<int>(v->fValue * 256.0 / 100.0); + } + + if (v->fValue >= 255.0) + return 255; + + return static_cast<int>(v->fValue); +} + bool CSSParser::parseColorParameters(CSSParserValue* value, int* colorArray, bool parseAlpha) { CSSParserValueList* args = value->function->args; @@ -3801,7 +3828,7 @@ bool CSSParser::parseColorParameters(CSSParserValue* value, int* colorArray, boo unitType = FPercent; else return false; - colorArray[0] = static_cast<int>(v->fValue * (v->unit == CSSPrimitiveValue::CSS_PERCENTAGE ? 256.0 / 100.0 : 1.0)); + colorArray[0] = colorIntFromValue(v); for (int i = 1; i < 3; i++) { v = args->next(); if (v->unit != CSSParserValue::Operator && v->iValue != ',') @@ -3809,7 +3836,7 @@ bool CSSParser::parseColorParameters(CSSParserValue* value, int* colorArray, boo v = args->next(); if (!validUnit(v, unitType, true)) return false; - colorArray[i] = static_cast<int>(v->fValue * (v->unit == CSSPrimitiveValue::CSS_PERCENTAGE ? 256.0 / 100.0 : 1.0)); + colorArray[i] = colorIntFromValue(v); } if (parseAlpha) { v = args->next(); 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; } diff --git a/WebCore/css/CSSStyleSelector.h b/WebCore/css/CSSStyleSelector.h index f0de83b..dca6c1c 100644 --- a/WebCore/css/CSSStyleSelector.h +++ b/WebCore/css/CSSStyleSelector.h @@ -64,6 +64,7 @@ class StyleImage; class StyleSheet; class StyleSheetList; class StyledElement; +class WebKitCSSKeyframeRule; class WebKitCSSKeyframesRule; class MediaQueryResult : public Noncopyable { @@ -111,6 +112,8 @@ public: RenderStyle* style() const { return m_style.get(); } + PassRefPtr<RenderStyle> styleForKeyframe(const RenderStyle*, const WebKitCSSKeyframeRule*, KeyframeList&); + public: // These methods will give back the set of rules that matched for a given element (or a pseudo-element). PassRefPtr<CSSRuleList> styleRulesForElement(Element*, bool authorOnly); diff --git a/WebCore/css/CSSStyleSheet.cpp b/WebCore/css/CSSStyleSheet.cpp index 40bb0de..227d37c 100644 --- a/WebCore/css/CSSStyleSheet.cpp +++ b/WebCore/css/CSSStyleSheet.cpp @@ -207,7 +207,8 @@ void CSSStyleSheet::checkLoaded() if (parent()) parent()->checkLoaded(); - // Avoid |this| being deleted by scripts that run via LegacyHTMLDocumentParser::executeScriptsWaitingForStylesheets(). + // Avoid |this| being deleted by scripts that run via + // ScriptableDocumentParser::executeScriptsWaitingForStylesheets(). // See <rdar://problem/6622300>. RefPtr<CSSStyleSheet> protector(this); m_loadCompleted = ownerNode() ? ownerNode()->sheetLoaded() : true; diff --git a/WebCore/css/html.css b/WebCore/css/html.css index dc27ff8..d65acb0 100644 --- a/WebCore/css/html.css +++ b/WebCore/css/html.css @@ -584,10 +584,12 @@ progress { height: 1em; width: 10em; vertical-align: -0.2em; + background-color: gray; } -progress::-webkit-progress-bar { +progress::-webkit-progress-bar-value { -webkit-appearance: progress-bar; + background-color: green; } /* datagrid */ @@ -629,6 +631,11 @@ pre, xmp, plaintext, listing { margin: 1__qem 0 } +mark { + background-color: yellow; + color: black +} + big { font-size: larger } @@ -733,7 +740,9 @@ iframe { @page { /* FIXME: Define the right default values for page properties. */ size: auto; - margin: 1in; + margin: auto; + padding: 0px; + border-width: 0px; } /* noscript is handled internally, as it depends on settings */ |