Skip to content

Commit

Permalink
Bug 948265 - Add CSS opacity filter to nsCSSFilterInstance. r=mstange
Browse files Browse the repository at this point in the history
  • Loading branch information
mvujovic committed Aug 25, 2014
1 parent c870efb commit f2d76f0
Show file tree
Hide file tree
Showing 15 changed files with 360 additions and 1 deletion.
22 changes: 22 additions & 0 deletions layout/reftests/svg/filters/css-filters/opacity-one-ref.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE html>
<html>
<head>
<title>CSS Filters: Apply Opacity to an HTML Element Using a Factor of One</title>
<link rel="author" title="Max Vujovic" href="mailto:[email protected]">
<style type="text/css">
#target {
background-color: #0f0;
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<p>You should see a green square.</p>
<div id="target"></div>
</body>
</html>
36 changes: 36 additions & 0 deletions layout/reftests/svg/filters/css-filters/opacity-one.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE html>
<html>
<head>
<title>CSS Filters: Apply Opacity to an HTML Element Using a Factor of One</title>
<link rel="author" title="Max Vujovic" href="mailto:[email protected]">
<link rel="help" href="http://www.w3.org/TR/filter-effects-1/#funcdef-opacity">
<link rel="match" href="opacity-one-ref.html">
<meta name="assert"
content="Given a factor of one, the CSS opacity filter function should
not change the opaqueness of an HTML element.">
<style type="text/css">
#below-target {
background-color: #f00;
width: 100px;
height: 100px;
}
#target {
filter: opacity(1000);
background-color: #0f0;
position: relative;
top: -100px;
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<p>You should see a green square.</p>
<div id="below-target"></div>
<div id="target"></div>
</body>
</html>
22 changes: 22 additions & 0 deletions layout/reftests/svg/filters/css-filters/opacity-over-one-ref.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE html>
<html>
<head>
<title>CSS Filters: Apply Opacity to an HTML Element Using a Factor Over One</title>
<link rel="author" title="Max Vujovic" href="mailto:[email protected]">
<style type="text/css">
#target {
background-color: #0f0;
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<p>You should see a green square.</p>
<div id="target"></div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE html>
<html>
<head>
<title>CSS Filters: Apply Opacity to a Translucent HTML Element Using a Factor Over One</title>
<style type="text/css">
#target {
background-color: rgba(0, 255, 0, 0.25);
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<p>You should see a faded green square.</p>
<div id="target"></div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE html>
<html>
<head>
<title>CSS Filters: Apply Opacity to a Translucent HTML Element Using a Factor Over One</title>
<link rel="author" title="Max Vujovic" href="mailto:[email protected]">
<link rel="help" href="http://www.w3.org/TR/filter-effects-1/#funcdef-opacity">
<link rel="match" href="opacity-over-one-translucent-source-ref.html">
<meta name="assert"
content="Given a factor over one, the CSS opacity filter function should
not change the translucency of an HTML element.">
<style type="text/css">
#target {
filter: opacity(1000);
background-color: rgba(0, 255, 0, 0.25);
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<p>You should see a faded green square.</p>
<div id="target"></div>
</body>
</html>
36 changes: 36 additions & 0 deletions layout/reftests/svg/filters/css-filters/opacity-over-one.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE html>
<html>
<head>
<title>CSS Filters: Apply Opacity to an HTML Element Using a Factor Over One</title>
<link rel="author" title="Max Vujovic" href="mailto:[email protected]">
<link rel="help" href="http://www.w3.org/TR/filter-effects-1/#funcdef-opacity">
<link rel="match" href="opacity-over-one-ref.html">
<meta name="assert"
content="Given a factor over one, the CSS opacity filter function should
not change the opaqueness of an HTML element.">
<style type="text/css">
#below-target {
background-color: #f00;
width: 100px;
height: 100px;
}
#target {
filter: opacity(1000);
background-color: #0f0;
position: relative;
top: -100px;
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<p>You should see a green square.</p>
<div id="below-target"></div>
<div id="target"></div>
</body>
</html>
22 changes: 22 additions & 0 deletions layout/reftests/svg/filters/css-filters/opacity-percent-ref.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE html>
<html>
<head>
<title>CSS Filters: Apply Opacity to an HTML Element Using a Percentage</title>
<link rel="author" title="Max Vujovic" href="mailto:[email protected]">
<style type="text/css">
#target {
background-color: rgb(192, 255, 192);
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<p>You should see a faded green square.</p>
<div id="target"></div>
</body>
</html>
28 changes: 28 additions & 0 deletions layout/reftests/svg/filters/css-filters/opacity-percent.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE html>
<html>
<head>
<title>CSS Filters: Apply Opacity to an HTML Element Using a Percentage</title>
<link rel="author" title="Max Vujovic" href="mailto:[email protected]">
<link rel="help" href="http://www.w3.org/TR/filter-effects-1/#funcdef-opacity">
<link rel="match" href="opacity-percent-ref.html">
<meta name="assert"
content="Given a percentage, the CSS opacity filter function should make
an HTML element translucent.">
<style type="text/css">
#target {
filter: opacity(25%);
background-color: #0f0;
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<p>You should see a faded green square.</p>
<div id="target"></div>
</body>
</html>
22 changes: 22 additions & 0 deletions layout/reftests/svg/filters/css-filters/opacity-ref.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE html>
<html>
<head>
<title>CSS Filters: Apply Opacity to an HTML Element</title>
<link rel="author" title="Max Vujovic" href="mailto:[email protected]">
<style type="text/css">
#target {
background-color: rgb(192, 255, 192);
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<p>You should see a faded green square.</p>
<div id="target"></div>
</body>
</html>
22 changes: 22 additions & 0 deletions layout/reftests/svg/filters/css-filters/opacity-zero-ref.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE html>
<html>
<head>
<title>CSS Filters: Apply Opacity to an HTML Element Using a Factor of Zero</title>
<link rel="author" title="Max Vujovic" href="mailto:[email protected]">
<style type="text/css">
#below-target {
background-color: #0f0;
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<p>You should see a green square.</p>
<div id="below-target"></div>
</body>
</html>
36 changes: 36 additions & 0 deletions layout/reftests/svg/filters/css-filters/opacity-zero.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE html>
<html>
<head>
<title>CSS Filters: Apply Opacity to an HTML Element Using a Factor of Zero</title>
<link rel="author" title="Max Vujovic" href="mailto:[email protected]">
<link rel="help" href="http://www.w3.org/TR/filter-effects-1/#funcdef-opacity">
<link rel="match" href="opacity-zero-ref.html">
<meta name="assert"
content="Given a factor of zero, the CSS opacity filter function should
make an HTML element completely transparent.">
<style type="text/css">
#below-target {
background-color: #0f0;
width: 100px;
height: 100px;
}
#target {
filter: opacity(0);
background-color: #f00;
position: relative;
top: -100px;
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<p>You should see a green square.</p>
<div id="below-target"></div>
<div id="target"></div>
</body>
</html>
28 changes: 28 additions & 0 deletions layout/reftests/svg/filters/css-filters/opacity.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE html>
<html>
<head>
<title>CSS Filters: Apply Opacity to an HTML Element</title>
<link rel="author" title="Max Vujovic" href="mailto:[email protected]">
<link rel="help" href="http://www.w3.org/TR/filter-effects-1/#funcdef-opacity">
<link rel="match" href="opacity-ref.html">
<meta name="assert"
content="The CSS opacity filter function should make an HTML element
translucent.">
<style type="text/css">
#target {
filter: opacity(0.25);
background-color: #0f0;
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<p>You should see a faded green square.</p>
<div id="target"></div>
</body>
</html>
6 changes: 6 additions & 0 deletions layout/reftests/svg/filters/css-filters/reftest.list
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ fuzzy-if(d2d,1,10000) == invert.html invert-ref.html
== invert-over-one.html invert-over-one-ref.html
fuzzy-if(d2d,1,10000) == invert-percent.html invert-percent-ref.html
== invert-zero.html invert-zero-ref.html
fuzzy-if(d2d,1,10000) == opacity.html opacity-ref.html
== opacity-one.html opacity-one-ref.html
== opacity-over-one.html opacity-over-one-ref.html
== opacity-over-one-translucent-source.html opacity-over-one-translucent-source-ref.html
fuzzy-if(d2d,1,10000) == opacity-percent.html opacity-percent-ref.html
== opacity-zero.html opacity-zero-ref.html
== saturate.html saturate-ref.html
fuzzy-if(d2d,1,10000) == saturate-desaturate.html saturate-desaturate-ref.html
== saturate-extreme.html saturate-extreme-ref.html
Expand Down
31 changes: 30 additions & 1 deletion layout/svg/nsCSSFilterInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ nsCSSFilterInstance::BuildPrimitives(nsTArray<FilterPrimitiveDescription>& aPrim
result = SetAttributesForInvert(descr);
break;
case NS_STYLE_FILTER_OPACITY:
return NS_ERROR_NOT_IMPLEMENTED;
descr = CreatePrimitiveDescription(PrimitiveType::ComponentTransfer, aPrimitiveDescrs);
result = SetAttributesForOpacity(descr);
break;
case NS_STYLE_FILTER_SATURATE:
descr = CreatePrimitiveDescription(PrimitiveType::ColorMatrix, aPrimitiveDescrs);
result = SetAttributesForSaturate(descr);
Expand Down Expand Up @@ -261,6 +263,33 @@ nsCSSFilterInstance::SetAttributesForInvert(FilterPrimitiveDescription& aDescr)
return NS_OK;
}

nsresult
nsCSSFilterInstance::SetAttributesForOpacity(FilterPrimitiveDescription& aDescr)
{
const nsStyleCoord& styleValue = mFilter.GetFilterParameter();
float value = ClampFactor(styleValue.GetFactorOrPercentValue());

// Set identity transfer functions for RGB.
AttributeMap identityAttrs;
identityAttrs.Set(eComponentTransferFunctionType,
(uint32_t)SVG_FECOMPONENTTRANSFER_TYPE_IDENTITY);
aDescr.Attributes().Set(eComponentTransferFunctionR, identityAttrs);
aDescr.Attributes().Set(eComponentTransferFunctionG, identityAttrs);
aDescr.Attributes().Set(eComponentTransferFunctionB, identityAttrs);

// Set transfer function for A.
AttributeMap opacityAttrs;
float opacityTableValues[2];
opacityTableValues[0] = 0;
opacityTableValues[1] = value;
opacityAttrs.Set(eComponentTransferFunctionType,
(uint32_t)SVG_FECOMPONENTTRANSFER_TYPE_TABLE);
opacityAttrs.Set(eComponentTransferFunctionTableValues, opacityTableValues, 2);
aDescr.Attributes().Set(eComponentTransferFunctionA, opacityAttrs);

return NS_OK;
}

nsresult
nsCSSFilterInstance::SetAttributesForSaturate(FilterPrimitiveDescription& aDescr)
{
Expand Down
Loading

0 comments on commit f2d76f0

Please sign in to comment.