Changeset 107688 in webkit


Ignore:
Timestamp:
Feb 14, 2012 1:46:48 AM (12 years ago)
Author:
mikelawther@chromium.org
Message:

CSS3 calc: embed calc expressions in CSSPrimitiveValue
https://bugs.webkit.org/show_bug.cgi?id=78446

Source/WebCore:

Reviewed by Ojan Vafai.

Adds calc expressions to CSSPrimitiveValue. This enables simple (ie no mixing of
percents with numbers/lengths) expressions to be evaluated on most properties.

Tests: css3/calc/block-mask-overlay-image-outset-expected.html

css3/calc/css3-radial-gradients-expected.html
css3/calc/gradient-color-stops-expected.html

  • css/CSSCalculationValue.cpp:

(WebCore::CSSCalcValue::computeLengthPx):
(WebCore):
(WebCore::CSSCalcPrimitiveValue::doubleValue):
(CSSCalcPrimitiveValue):
(WebCore::CSSCalcPrimitiveValue::computeLengthPx):
(CSSCalcBinaryOperation):
(WebCore::CSSCalcBinaryOperation::computeLengthPx):

  • css/CSSCalculationValue.h:

(CSSCalcExpressionNode):
(CSSCalcValue):

  • css/CSSParser.cpp:

(WebCore::CSSParser::createPrimitiveNumericValue):
(WebCore::CSSParser::parseValidPrimitive):

  • css/CSSPrimitiveValue.cpp:

(WebCore::isValidCSSUnitTypeForDoubleConversion):
(WebCore::CSSPrimitiveValue::primitiveType):
(WebCore::CSSPrimitiveValue::init):
(WebCore):
(WebCore::CSSPrimitiveValue::cleanup):
(WebCore::CSSPrimitiveValue::computeLengthDouble):
(WebCore::CSSPrimitiveValue::getDoubleValue):
(WebCore::CSSPrimitiveValue::getDoubleValueInternal):
(WebCore::CSSPrimitiveValue::customCssText):

  • css/CSSPrimitiveValue.h:

(WebCore):
(WebCore::CSSPrimitiveValue::isLength):
(WebCore::CSSPrimitiveValue::isNumber):
(WebCore::CSSPrimitiveValue::isPercentage):
(WebCore::CSSPrimitiveValue::isPx):
(WebCore::CSSPrimitiveValue::isCalculated):
(WebCore::CSSPrimitiveValue::isCalculatedPercentageNumber):
(WebCore::CSSPrimitiveValue::isCalculatedPercentageLength):
(CSSPrimitiveValue):
(WebCore::CSSPrimitiveValue::getValue):
(WebCore::CSSPrimitiveValue::cssCalcValue):

  • css/CSSStyleApplyProperty.cpp:

(WebCore::ApplyPropertyBorderRadius::applyValue):

LayoutTests:

Reviewed by Ojan Vafai.

  • css3/calc/block-mask-overlay-image-outset-expected.html: Renamed from LayoutTests/css3/calc/block-mask-overlay-image-outset-expected-mismatch.html.
  • css3/calc/border-expected.txt:
  • css3/calc/calc-errors-expected.txt:
  • css3/calc/css3-radial-gradients-expected.html: Renamed from LayoutTests/css3/calc/css3-radial-gradients-expected-mismatch.html.
  • css3/calc/font-expected.txt:
  • css3/calc/font-monospace-expected.txt:
  • css3/calc/font-size-expected.txt:
  • css3/calc/font-size-fractional-expected.txt:
  • css3/calc/getComputedStyle-margin-percentage-expected.txt:
  • css3/calc/gradient-color-stops-expected.html: Renamed from LayoutTests/css3/calc/gradient-color-stops-expected-mismatch.html.
  • css3/calc/line-height-expected.txt:
  • css3/calc/margin-expected.txt:
  • css3/calc/padding-expected.txt:
  • css3/calc/simple-calcs-expected.txt:
  • css3/calc/table-border-spacing-expected.txt:
Location:
trunk
Files:
20 edited
3 moved

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r107686 r107688  
     12012-02-14  Mike Lawther  <mikelawther@chromium.org>
     2
     3        CSS3 calc: embed calc expressions in CSSPrimitiveValue
     4        https://bugs.webkit.org/show_bug.cgi?id=78446
     5
     6        Reviewed by Ojan Vafai.
     7
     8        * css3/calc/block-mask-overlay-image-outset-expected.html: Renamed from LayoutTests/css3/calc/block-mask-overlay-image-outset-expected-mismatch.html.
     9        * css3/calc/border-expected.txt:
     10        * css3/calc/calc-errors-expected.txt:
     11        * css3/calc/css3-radial-gradients-expected.html: Renamed from LayoutTests/css3/calc/css3-radial-gradients-expected-mismatch.html.
     12        * css3/calc/font-expected.txt:
     13        * css3/calc/font-monospace-expected.txt:
     14        * css3/calc/font-size-expected.txt:
     15        * css3/calc/font-size-fractional-expected.txt:
     16        * css3/calc/getComputedStyle-margin-percentage-expected.txt:
     17        * css3/calc/gradient-color-stops-expected.html: Renamed from LayoutTests/css3/calc/gradient-color-stops-expected-mismatch.html.
     18        * css3/calc/line-height-expected.txt:
     19        * css3/calc/margin-expected.txt:
     20        * css3/calc/padding-expected.txt:
     21        * css3/calc/simple-calcs-expected.txt:
     22        * css3/calc/table-border-spacing-expected.txt:
     23
    1242012-02-14  Philippe Normand  <pnormand@igalia.com>
    225
  • trunk/LayoutTests/css3/calc/border-expected.txt

    r104428 r107688  
    1 This element should have an overall border of 25 pixels. => FAIL: wrong width, wrong height
     1This element should have an overall border of 25 pixels. => PASS
    22
    3 This element should have a left border of 25 pixels. => FAIL: wrong width
     3This element should have a left border of 25 pixels. => PASS
    44
    5 This element should have a right border of 25 pixels. => FAIL: wrong width
     5This element should have a right border of 25 pixels. => PASS
    66
    7 This element should have a top border of 25 pixels. => FAIL: wrong height
     7This element should have a top border of 25 pixels. => PASS
    88
    9 This element should have a bottom border of 25 pixels. => FAIL: wrong height
     9This element should have a bottom border of 25 pixels. => PASS
  • trunk/LayoutTests/css3/calc/calc-errors-expected.txt

    r83415 r107688  
    44unclosed calc with garbage => PASS
    55garbage => PASS
    6 zero division => PASS
     6zero division => FAIL: expected width of 100, but was 0
    77non length => PASS
    88number + length => PASS
  • trunk/LayoutTests/css3/calc/font-expected.txt

    r107420 r107688  
    44
    55
    6 FAIL getComputedStyle(document.getElementById("calc-size"), null).lineHeight should be 63px. Was normal.
    7 FAIL getComputedStyle(document.getElementById("calc-size"), null).fontSize should be 24px. Was 16px.
    8 FAIL getComputedStyle(document.getElementById("calc-height"), null).lineHeight should be 63px. Was normal.
     6PASS getComputedStyle(document.getElementById("calc-size"), null).lineHeight is "63px"
     7PASS getComputedStyle(document.getElementById("calc-size"), null).fontSize is "24px"
     8PASS getComputedStyle(document.getElementById("calc-height"), null).lineHeight is "63px"
    99PASS getComputedStyle(document.getElementById("calc-height"), null).fontSize is "24px"
    10 FAIL getComputedStyle(document.getElementById("calc-both"), null).lineHeight should be 63px. Was normal.
    11 FAIL getComputedStyle(document.getElementById("calc-both"), null).fontSize should be 24px. Was 16px.
    12 FAIL getComputedStyle(document.getElementById("calc-percent-size"), null).lineHeight should be 63px. Was normal.
     10PASS getComputedStyle(document.getElementById("calc-both"), null).lineHeight is "63px"
     11PASS getComputedStyle(document.getElementById("calc-both"), null).fontSize is "24px"
     12PASS getComputedStyle(document.getElementById("calc-percent-size"), null).lineHeight is "63px"
    1313FAIL getComputedStyle(document.getElementById("calc-percent-size"), null).fontSize should be 24px. Was 16px.
    1414PASS successfullyParsed is true
  • trunk/LayoutTests/css3/calc/font-monospace-expected.txt

    r104431 r107688  
    11The font size and line height of these lines should be identical
    22The font size and line height of these lines should be identical
    3 FAIL
    4 Line heights do not match
    5 
    6 Font sizes do not match
     3PASS
  • trunk/LayoutTests/css3/calc/font-size-expected.txt

    r107425 r107688  
    44
    55
    6 FAIL getComputedStyle(document.getElementById("calc-percent"), null).fontSize should be 40px. Was 20px.
     6PASS getComputedStyle(document.getElementById("calc-percent"), null).fontSize is "40px"
    77FAIL getComputedStyle(document.getElementById("calc-percent-pixels"), null).fontSize should be 40px. Was 20px.
    88PASS successfullyParsed is true
  • trunk/LayoutTests/css3/calc/font-size-fractional-expected.txt

    r107464 r107688  
    44
    55
    6 FAIL getComputedStyle(document.getElementById("calc-reduce"), null).lineHeight should be 24px. Was normal.
    7 FAIL getComputedStyle(document.getElementById("calc-reduce"), null).fontSize should be 10px. Was 12px.
     6PASS getComputedStyle(document.getElementById("calc-reduce"), null).lineHeight is "24px"
     7PASS getComputedStyle(document.getElementById("calc-reduce"), null).fontSize is "10px"
    88PASS successfullyParsed is true
    99
  • trunk/LayoutTests/css3/calc/getComputedStyle-margin-percentage-expected.txt

    r105647 r107688  
    44
    55
    6 FAIL getComputedStyle(document.getElementById('calc'), null).getPropertyValue('margin-left') should be 253px. Was 0px.
    7 FAIL getComputedStyle(document.getElementById('calc'), null).getPropertyValue('margin-top') should be 76px. Was 0px.
    8 FAIL getComputedStyle(document.getElementById('calc'), null).getPropertyValue('margin-right') should be 346px. Was 0px.
    9 FAIL getComputedStyle(document.getElementById('calc'), null).getPropertyValue('margin-bottom') should be 530px. Was 0px.
     6PASS getComputedStyle(document.getElementById('calc'), null).getPropertyValue('margin-left') is getComputedStyle(document.getElementById('control', null)).getPropertyValue('margin-left')
     7PASS getComputedStyle(document.getElementById('calc'), null).getPropertyValue('margin-top') is getComputedStyle(document.getElementById('control', null)).getPropertyValue('margin-top')
     8PASS getComputedStyle(document.getElementById('calc'), null).getPropertyValue('margin-right') is getComputedStyle(document.getElementById('control', null)).getPropertyValue('margin-right')
     9PASS getComputedStyle(document.getElementById('calc'), null).getPropertyValue('margin-bottom') is getComputedStyle(document.getElementById('control', null)).getPropertyValue('margin-bottom')
    1010PASS successfullyParsed is true
    1111
  • trunk/LayoutTests/css3/calc/line-height-expected.txt

    r104752 r107688  
    44
    55
    6 FAIL getComputedStyle(document.getElementById("calc-percent"), null).lineHeight should be 32px. Was normal.
     6PASS getComputedStyle(document.getElementById("calc-percent"), null).lineHeight is getComputedStyle(document.getElementById("control"), null).lineHeight
    77FAIL getComputedStyle(document.getElementById("calc-percent-pixels"), null).lineHeight should be 32px. Was normal.
    88PASS successfullyParsed is true
  • trunk/LayoutTests/css3/calc/margin-expected.txt

    r104783 r107688  
    1 FAIL document.getElementById("simple-all").parentNode.offsetWidth should be 250. Was 200.
    2 FAIL document.getElementById("simple-all").parentNode.offsetHeight should be 170. Was 120.
    3 FAIL document.getElementById("simple-left").parentNode.offsetWidth should be 225. Was 200.
     1PASS document.getElementById("simple-all").parentNode.offsetWidth is 250
     2PASS document.getElementById("simple-all").parentNode.offsetHeight is 170
     3PASS document.getElementById("simple-left").parentNode.offsetWidth is 225
    44PASS document.getElementById("simple-left").parentNode.offsetHeight is 120
    5 FAIL document.getElementById("simple-right").parentNode.offsetWidth should be 225. Was 200.
     5PASS document.getElementById("simple-right").parentNode.offsetWidth is 225
    66PASS document.getElementById("simple-right").parentNode.offsetHeight is 120
    77PASS document.getElementById("simple-top").parentNode.offsetWidth is 200
    8 FAIL document.getElementById("simple-top").parentNode.offsetHeight should be 145. Was 120.
     8PASS document.getElementById("simple-top").parentNode.offsetHeight is 145
    99PASS document.getElementById("simple-bottom").parentNode.offsetWidth is 200
    10 FAIL document.getElementById("simple-bottom").parentNode.offsetHeight should be 145. Was 120.
     10PASS document.getElementById("simple-bottom").parentNode.offsetHeight is 145
    1111FAIL document.getElementById("percent-all").parentNode.offsetWidth should be 250. Was 200.
    1212FAIL document.getElementById("percent-all").parentNode.offsetHeight should be 170. Was 120.
  • trunk/LayoutTests/css3/calc/padding-expected.txt

    r104653 r107688  
    1 This element should have an overall padding of 25 pixels. => FAIL: wrong width, wrong height
     1This element should have an overall padding of 25 pixels. => PASS
    22
    3 This element should have a left padding of 25 pixels. => FAIL: wrong width
     3This element should have a left padding of 25 pixels. => PASS
    44
    5 This element should have a right padding of 25 pixels. => FAIL: wrong width
     5This element should have a right padding of 25 pixels. => PASS
    66
    7 This element should have a top padding of 25 pixels. => FAIL: wrong height
     7This element should have a top padding of 25 pixels. => PASS
    88
    9 This element should have a bottom padding of 25 pixels. => FAIL: wrong height
     9This element should have a bottom padding of 25 pixels. => PASS
    1010
    1111This element should have an overall padding of 25 pixels (10% of parent width of 300px minus 5px). => FAIL: wrong width, wrong height
  • trunk/LayoutTests/css3/calc/simple-calcs-expected.txt

    r107259 r107688  
    22
    33control => PASS
    4 50px + 50px => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    5 150px - 50px => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    6 50px + 50px (2 spaces around operator) => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    7 150px - 50px (2 spaces around operator) => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    8 50px*2 => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    9 50px *2 => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    10 50px* 2 => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    11 200px/2 => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    12 200px /2 => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    13 200px/ 2 => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    14 50px*(2) => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    15 50px *(2) => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    16 50px* (2) => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    17 50px*(1 + 1) => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    18 50px*(12 - 10) => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    19 50px*(10 / 5) => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    20 10px* (5 * 2) => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    21 50px + 10px * 5 (operation order) => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    22 100%/2 (where 100% is 200px) => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
     450px + 50px => PASS
     5150px - 50px => PASS
     650px + 50px (2 spaces around operator) => PASS
     7150px - 50px (2 spaces around operator) => PASS
     850px*2 => PASS
     950px *2 => PASS
     1050px* 2 => PASS
     11200px/2 => PASS
     12200px /2 => PASS
     13200px/ 2 => PASS
     1450px*(2) => PASS
     1550px *(2) => PASS
     1650px* (2) => PASS
     1750px*(1 + 1) => PASS
     1850px*(12 - 10) => PASS
     1950px*(10 / 5) => PASS
     2010px* (5 * 2) => PASS
     2150px + 10px * 5 (operation order) => PASS
     22100%/2 (where 100% is 200px) => PASS
    2323100% + -100px (where 100% is 200px) => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    242480% - 60px (where 100% is 200px) => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    2525300px - 100% (where 100% is 200px) => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    2626-100px + 100% (where 100% is 200px) => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    27 20% + 30% (where 100% is 200px) => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    28 80% - 30% (where 100% is 200px) => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    29 10% * 5 (where 100% is 200px) => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    30 5 * 10% (where 100% is 200px) => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    31 (100px) => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    32 (50px + 50px) => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    33 (50px) + 50px => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    34 50px + (50px) => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    35 50px + 50px => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    36 50px + 25px * 2 => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    37 (25px + 25px) * 2 => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    38 2 * 50px => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    39 2 * 100px / 2 => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    40 (1em - 1em) + 100px => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    41 50px + +50px => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    42 -50px + 150px => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    43 -50px - -150px => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    44 (((((((100px))))))) => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 256
    45 100px => FAIL: @zoom=1 expected height of 100, but was 50; @zoom=1.2 expected height of 100, but was 50; @zoom=2 expected height of 100, but was 50
    46 100% * 2 => FAIL: @zoom=1 expected height of 100, but was 50; @zoom=1.2 expected height of 100, but was 50; @zoom=2 expected height of 100, but was 50
     2720% + 30% (where 100% is 200px) => PASS
     2880% - 30% (where 100% is 200px) => PASS
     2910% * 5 (where 100% is 200px) => PASS
     305 * 10% (where 100% is 200px) => PASS
     31(100px) => PASS
     32(50px + 50px) => PASS
     33(50px) + 50px => PASS
     3450px + (50px) => PASS
     3550px + 50px => PASS
     3650px + 25px * 2 => PASS
     37(25px + 25px) * 2 => PASS
     382 * 50px => PASS
     392 * 100px / 2 => PASS
     40(1em - 1em) + 100px => PASS
     4150px + +50px => PASS
     42-50px + 150px => PASS
     43-50px - -150px => PASS
     44(((((((100px))))))) => PASS
     45100px => PASS
     46100% * 2 => PASS
  • trunk/LayoutTests/css3/calc/table-border-spacing-expected.txt

    r105869 r107688  
    1 FAIL document.getElementById("stimulus").offsetWidth should be 416. Was 278.
    2 FAIL document.getElementById("stimulus").offsetHeight should be 205. Was 136.
     1PASS document.getElementById("stimulus").offsetWidth is 416
     2PASS document.getElementById("stimulus").offsetHeight is 205
    33PASS successfullyParsed is true
    44
  • trunk/Source/WebCore/ChangeLog

    r107687 r107688  
     12012-02-14  Mike Lawther  <mikelawther@chromium.org>
     2
     3        CSS3 calc: embed calc expressions in CSSPrimitiveValue
     4        https://bugs.webkit.org/show_bug.cgi?id=78446
     5
     6        Reviewed by Ojan Vafai.
     7       
     8        Adds calc expressions to CSSPrimitiveValue. This enables simple (ie no mixing of
     9        percents with numbers/lengths) expressions to be evaluated on most properties.
     10
     11        Tests: css3/calc/block-mask-overlay-image-outset-expected.html
     12               css3/calc/css3-radial-gradients-expected.html
     13               css3/calc/gradient-color-stops-expected.html
     14
     15        * css/CSSCalculationValue.cpp:
     16        (WebCore::CSSCalcValue::computeLengthPx):
     17        (WebCore):
     18        (WebCore::CSSCalcPrimitiveValue::doubleValue):
     19        (CSSCalcPrimitiveValue):
     20        (WebCore::CSSCalcPrimitiveValue::computeLengthPx):
     21        (CSSCalcBinaryOperation):
     22        (WebCore::CSSCalcBinaryOperation::computeLengthPx):
     23        * css/CSSCalculationValue.h:
     24        (CSSCalcExpressionNode):
     25        (CSSCalcValue):
     26        * css/CSSParser.cpp:
     27        (WebCore::CSSParser::createPrimitiveNumericValue):
     28        (WebCore::CSSParser::parseValidPrimitive):
     29        * css/CSSPrimitiveValue.cpp:
     30        (WebCore::isValidCSSUnitTypeForDoubleConversion):
     31        (WebCore::CSSPrimitiveValue::primitiveType):
     32        (WebCore::CSSPrimitiveValue::init):
     33        (WebCore):
     34        (WebCore::CSSPrimitiveValue::cleanup):
     35        (WebCore::CSSPrimitiveValue::computeLengthDouble):
     36        (WebCore::CSSPrimitiveValue::getDoubleValue):
     37        (WebCore::CSSPrimitiveValue::getDoubleValueInternal):
     38        (WebCore::CSSPrimitiveValue::customCssText):
     39        * css/CSSPrimitiveValue.h:
     40        (WebCore):
     41        (WebCore::CSSPrimitiveValue::isLength):
     42        (WebCore::CSSPrimitiveValue::isNumber):
     43        (WebCore::CSSPrimitiveValue::isPercentage):
     44        (WebCore::CSSPrimitiveValue::isPx):
     45        (WebCore::CSSPrimitiveValue::isCalculated):
     46        (WebCore::CSSPrimitiveValue::isCalculatedPercentageNumber):
     47        (WebCore::CSSPrimitiveValue::isCalculatedPercentageLength):
     48        (CSSPrimitiveValue):
     49        (WebCore::CSSPrimitiveValue::getValue):
     50        (WebCore::CSSPrimitiveValue::cssCalcValue):
     51        * css/CSSStyleApplyProperty.cpp:
     52        (WebCore::ApplyPropertyBorderRadius::applyValue):
     53
    1542012-02-14  Pavel Feldman  <pfeldman@chromium.org>
    255
  • trunk/Source/WebCore/css/CSSCalculationValue.cpp

    r107259 r107688  
    11/*
    2  * Copyright (C) 2011 Google Inc. All rights reserved.
     2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    8383}
    8484   
     85double CSSCalcValue::computeLengthPx(RenderStyle* currentStyle, RenderStyle* rootStyle, double multiplier, bool computingFontSize) const
     86{
     87    return m_expression->computeLengthPx(currentStyle, rootStyle, multiplier, computingFontSize);
     88}
     89   
    8590CSSCalcExpressionNode::~CSSCalcExpressionNode()
    8691{
     
    114119        }
    115120        return 0;
    116     }   
     121    }
     122   
     123    virtual double computeLengthPx(RenderStyle* currentStyle, RenderStyle* rootStyle, double multiplier, bool computingFontSize) const
     124    {
     125        switch (m_category) {
     126        case CalcLength:
     127            return m_value->computeLength<double>(currentStyle, rootStyle, multiplier, computingFontSize);
     128        case CalcPercent:
     129        case CalcNumber:
     130            return m_value->getDoubleValue();
     131        case CalcPercentLength:
     132        case CalcPercentNumber:
     133        case CalcOther:
     134            ASSERT_NOT_REACHED();
     135            break;
     136        }
     137        return 0;       
     138    }
     139   
    117140private:
    118141    explicit CSSCalcPrimitiveValue(CSSPrimitiveValue* value, bool isInteger)
     
    175198        return evaluate(m_leftSide->doubleValue(), m_rightSide->doubleValue());
    176199    }
     200   
     201    virtual double computeLengthPx(RenderStyle* currentStyle, RenderStyle* rootStyle, double multiplier, bool computingFontSize) const
     202    {
     203        const double leftValue = m_leftSide->computeLengthPx(currentStyle, rootStyle, multiplier, computingFontSize);
     204        const double rightValue = m_rightSide->computeLengthPx(currentStyle, rootStyle, multiplier, computingFontSize);
     205        return evaluate(leftValue, rightValue);
     206    }
    177207
    178208private:
  • trunk/Source/WebCore/css/CSSCalculationValue.h

    r107030 r107688  
    11/*
    2  * Copyright (C) 2011 Google Inc. All rights reserved.
     2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    6161    virtual ~CSSCalcExpressionNode() = 0; 
    6262    virtual double doubleValue() const = 0; 
     63    virtual double computeLengthPx(RenderStyle* currentStyle, RenderStyle* rootStyle, double multiplier = 1.0, bool computingFontSize = false) const = 0;
    6364   
    6465    CalculationCategory category() const { return m_category; }   
     
    8485    bool isInt() const { return m_expression->isInteger(); }   
    8586    double doubleValue() const;
     87    double computeLengthPx(RenderStyle* currentStyle, RenderStyle* rootStyle, double multiplier = 1.0, bool computingFontSize = false) const;
    8688       
    8789    String customCssText() const;
  • trunk/Source/WebCore/css/CSSParser.cpp

    r107516 r107688  
    801801    if (m_parsedCalculation) {
    802802        ASSERT(isCalculation(value));
    803         // FIXME calc() http://webkit.org/b/16662: create a CSSPrimitiveValue here, ie
    804         // return CSSPrimitiveValue::create(m_parsedCalculation.release());
    805         m_parsedCalculation.release();
    806         return 0;
     803        return CSSPrimitiveValue::create(m_parsedCalculation.release());
    807804    }
    808805               
     
    905902        return CSSPrimitiveValue::createAllowingMarginQuirk(value->fValue, CSSPrimitiveValue::CSS_EMS);
    906903    if (isCalculation(value))
    907         // FIXME calc()  http://webkit.org/b/16662: create a primitive value here, ie
    908         // return CSSPrimitiveValue::create(m_parsedCalculation.release());
    909         m_parsedCalculation.release();
     904        return CSSPrimitiveValue::create(m_parsedCalculation.release());
    910905
    911906    return 0;
  • trunk/Source/WebCore/css/CSSPrimitiveValue.cpp

    r106251 r107688  
    2222#include "CSSPrimitiveValue.h"
    2323
     24#include "CSSCalculationValue.h"
    2425#include "CSSHelper.h"
    2526#include "CSSParser.h"
     
    2829#include "CSSValueKeywords.h"
    2930#include "CSSWrapShapes.h"
     31#include "CalculationValue.h"
    3032#include "Color.h"
    3133#include "Counter.h"
     
    5355{
    5456    switch (unitType) {
     57    case CSSPrimitiveValue:: CSS_CALC:
     58    case CSSPrimitiveValue:: CSS_CALC_PERCENTAGE_WITH_NUMBER:
     59    case CSSPrimitiveValue:: CSS_CALC_PERCENTAGE_WITH_LENGTH:
    5560    case CSSPrimitiveValue:: CSS_CM:
    5661    case CSSPrimitiveValue:: CSS_DEG:
     
    138143}
    139144
     145unsigned short CSSPrimitiveValue::primitiveType() const
     146{
     147    if (m_primitiveUnitType != CSSPrimitiveValue::CSS_CALC)
     148        return m_primitiveUnitType;
     149   
     150    switch (m_value.calc->category()) {
     151    case CalcNumber:
     152        return CSSPrimitiveValue::CSS_NUMBER;
     153    case CalcPercent:
     154        return CSSPrimitiveValue::CSS_PERCENTAGE;
     155    case CalcLength:
     156        return CSSPrimitiveValue::CSS_PX;
     157    case CalcPercentNumber:
     158        return CSSPrimitiveValue::CSS_CALC_PERCENTAGE_WITH_NUMBER;
     159    case CalcPercentLength:
     160        return CSSPrimitiveValue::CSS_CALC_PERCENTAGE_WITH_LENGTH;
     161    case CalcOther:
     162        return CSSPrimitiveValue::CSS_UNKNOWN;
     163    }
     164    return CSSPrimitiveValue::CSS_UNKNOWN;
     165}
    140166static const AtomicString& valueOrPropertyName(int valueOrPropertyID)
    141167{
     
    283309    m_hasCachedCSSText = false;
    284310    m_value.pair = p.leakRef();
     311}
     312
     313void CSSPrimitiveValue::init(PassRefPtr<CSSCalcValue> c)
     314{
     315    m_primitiveUnitType = CSS_CALC;
     316    m_hasCachedCSSText = false;
     317    m_value.calc = c.leakRef();
    285318}
    286319
     
    325358            break;
    326359#endif
     360        case CSS_CALC:
     361            m_value.calc->deref();
     362            break;
    327363        case CSS_SHAPE:
    328364            m_value.shape->deref();
     
    438474            factor = cssPixelsPerInch * 12.0 / 72.0;
    439475            break;
     476        case CSS_CALC_PERCENTAGE_WITH_LENGTH:
     477        case CSS_CALC_PERCENTAGE_WITH_NUMBER:
     478            ASSERT_NOT_REACHED();
     479            return -1.0;
    440480        default:
    441481            ASSERT_NOT_REACHED();
     
    443483    }
    444484
    445     double result = getDoubleValue() * factor;
     485    double computedValue;
     486    if (m_primitiveUnitType == CSS_CALC)
     487        // The multiplier is passed in as 1.0 here to ensure it is only applied once
     488        computedValue = m_value.calc->computeLengthPx(style, rootStyle, 1.0, computingFontSize);
     489    else
     490        computedValue = getDoubleValue();
     491   
     492    double result = computedValue * factor;
    446493    if (!applyZoomMultiplier || multiplier == 1.0f)
    447494        return result;
     
    527574    getDoubleValueInternal(static_cast<UnitTypes>(unitType), &result);
    528575    return result;
     576}
     577
     578double CSSPrimitiveValue::getDoubleValue() const
     579{
     580    return m_primitiveUnitType != CSS_CALC ? m_value.num : m_value.calc->doubleValue();
    529581}
    530582
     
    555607    if (!isValidCSSUnitTypeForDoubleConversion(static_cast<UnitTypes>(m_primitiveUnitType)) || !isValidCSSUnitTypeForDoubleConversion(requestedUnitType))
    556608        return false;
    557     if (requestedUnitType == static_cast<UnitTypes>(m_primitiveUnitType) || requestedUnitType == CSS_DIMENSION) {
    558         *result = m_value.num;
     609
     610    UnitTypes sourceUnitType = static_cast<UnitTypes>(primitiveType());
     611    if (requestedUnitType == sourceUnitType || requestedUnitType == CSS_DIMENSION) {
     612        *result = getDoubleValue();
    559613        return true;
    560614    }
    561615
    562     UnitTypes sourceUnitType = static_cast<UnitTypes>(m_primitiveUnitType);
    563616    UnitCategory sourceCategory = unitCategory(sourceUnitType);
    564617    ASSERT(sourceCategory != UOther);
     
    586639    }
    587640
    588     double convertedValue = m_value.num;
     641    double convertedValue = getDoubleValue();
    589642
    590643    // First convert the value from m_primitiveUnitType to canonical type.
     
    9591012            text = quoteCSSStringIfNeeded(m_value.string);
    9601013            break;
     1014        case CSS_CALC:
     1015            text = m_value.calc->cssText();
     1016            break;
    9611017        case CSS_SHAPE:
    9621018            text = m_value.shape->cssText();
  • trunk/Source/WebCore/css/CSSPrimitiveValue.h

    r105693 r107688  
    3131namespace WebCore {
    3232
     33class CSSCalcValue;
    3334class Counter;
    3435class DashboardRegion;
     
    103104
    104105        // Used by border images.
    105         CSS_QUAD = 111
     106        CSS_QUAD = 111,
     107
     108        CSS_CALC = 112,
     109        CSS_CALC_PERCENTAGE_WITH_NUMBER = 113,
     110        CSS_CALC_PERCENTAGE_WITH_LENGTH = 114
    106111    };
    107112
     
    134139    bool isLength() const
    135140    {
    136         return (m_primitiveUnitType >= CSS_EMS && m_primitiveUnitType <= CSS_PC)
    137                || m_primitiveUnitType == CSS_REMS;
    138     }
    139     bool isNumber() const { return m_primitiveUnitType == CSS_NUMBER; }
    140     bool isPercentage() const { return m_primitiveUnitType == CSS_PERCENTAGE; }
    141     bool isPx() const { return m_primitiveUnitType == CSS_PX; }
     141        unsigned short type = primitiveType();
     142        return (type >= CSS_EMS && type <= CSS_PC) || type == CSS_REMS;
     143    }
     144    bool isNumber() const { return primitiveType() == CSS_NUMBER; }
     145    bool isPercentage() const { return primitiveType() == CSS_PERCENTAGE; }
     146    bool isPx() const { return primitiveType() == CSS_PX; }
    142147    bool isRect() const { return m_primitiveUnitType == CSS_RECT; }
    143148    bool isRGBColor() const { return m_primitiveUnitType == CSS_RGBCOLOR; }
     
    146151    bool isTime() const { return m_primitiveUnitType == CSS_S || m_primitiveUnitType == CSS_MS; }
    147152    bool isURI() const { return m_primitiveUnitType == CSS_URI; }
    148 
     153    bool isCalculated() const { return m_primitiveUnitType == CSS_CALC; }
     154    bool isCalculatedPercentageWithNumber() const { return primitiveType() == CSS_CALC_PERCENTAGE_WITH_NUMBER; }
     155    bool isCalculatedPercentageWithLength() const { return primitiveType() == CSS_CALC_PERCENTAGE_WITH_LENGTH; }
    149156
    150157    static PassRefPtr<CSSPrimitiveValue> createIdentifier(int identifier) { return adoptRef(new CSSPrimitiveValue(identifier)); }
     
    173180    void cleanup();
    174181
    175     unsigned short primitiveType() const { return m_primitiveUnitType; }
     182    unsigned short primitiveType() const;
    176183
    177184    double computeDegrees();
     
    212219    double getDoubleValue(unsigned short unitType, ExceptionCode&) const;
    213220    double getDoubleValue(unsigned short unitType) const;
    214     double getDoubleValue() const { return m_value.num; }
     221    double getDoubleValue() const;
    215222
    216223    void setFloatValue(unsigned short unitType, double floatValue, ExceptionCode&);
     
    225232    template<typename T> inline T getValue(unsigned short unitType, ExceptionCode& ec) const { return clampTo<T>(getDoubleValue(unitType, ec)); }
    226233    template<typename T> inline T getValue(unsigned short unitType) const { return clampTo<T>(getDoubleValue(unitType)); }
    227     template<typename T> inline T getValue() const { return clampTo<T>(m_value.num); }
     234    template<typename T> inline T getValue() const { return clampTo<T>(getDoubleValue()); }
    228235
    229236    void setStringValue(unsigned short stringType, const String& stringValue, ExceptionCode&);
     
    249256
    250257    CSSWrapShape* getShapeValue() const { return m_primitiveUnitType != CSS_SHAPE ? 0 : m_value.shape; }
     258   
     259    CSSCalcValue* cssCalcValue() const { return m_primitiveUnitType != CSS_CALC ? 0 : m_value.calc; }
    251260
    252261    int getIdent() const { return m_primitiveUnitType == CSS_IDENT ? m_value.ident : 0; }
     
    302311    void init(PassRefPtr<DashboardRegion>); // FIXME: Dashboard region should not be a primitive value.
    303312    void init(PassRefPtr<CSSWrapShape>);
    304 
     313    void init(PassRefPtr<CSSCalcValue>);
    305314    bool getDoubleValueInternal(UnitTypes targetUnitType, double* result) const;
    306315
     
    318327        DashboardRegion* region;
    319328        CSSWrapShape* shape;
     329        CSSCalcValue* calc;
    320330    } m_value;
    321331};
  • trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp

    r107528 r107688  
    441441        if (pair->first()->isPercentage())
    442442            radiusWidth = Length(pair->first()->getDoubleValue(), Percent);
    443         else
     443        else if (pair->first()->isCalculatedPercentageWithLength()) {
     444            // FIXME calc(): http://webkit.org/b/16662
     445            // handle this case
     446            return;
     447        } else
    444448            radiusWidth = Length(max(intMinForLength, min(intMaxForLength, pair->first()->computeLength<int>(selector->style(), selector->rootElementStyle(), selector->style()->effectiveZoom()))), Fixed);
    445449        if (pair->second()->isPercentage())
    446450            radiusHeight = Length(pair->second()->getDoubleValue(), Percent);
    447         else
     451        else if (pair->second()->isCalculatedPercentageWithLength()) {
     452            // FIXME calc(): http://webkit.org/b/16662
     453            // handle this case
     454            return;
     455        } else
    448456            radiusHeight = Length(max(intMinForLength, min(intMaxForLength, pair->second()->computeLength<int>(selector->style(), selector->rootElementStyle(), selector->style()->effectiveZoom()))), Fixed);
    449457        int width = radiusWidth.value();
Note: See TracChangeset for help on using the changeset viewer.