Skip to content

Commit

Permalink
CSS: Add the 'visibility' property.
Browse files Browse the repository at this point in the history
http://www.w3.org/TR/CSS21/visufx.html#visibility

'visibility: collapse' is not supported yet because tables are not, either.

This fixes #1329.
  • Loading branch information
SimonSapin committed Dec 4, 2013
1 parent b26fe9a commit 7a4c809
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/components/main/layout/box.rs
Expand Up @@ -28,7 +28,8 @@ use std::unstable::raw::Box;
use style::ComputedValues;
use style::computed_values::{
border_style, clear, float, font_family, font_style, line_height,
position, text_align, text_decoration, vertical_align, LengthOrPercentage, overflow};
position, text_align, text_decoration, vertical_align, LengthOrPercentage,
overflow, visibility};

use css::node_style::StyledNode;
use layout::display_list_builder::{DisplayListBuilder, ExtraDisplayListData, ToGfxColor};
Expand Down Expand Up @@ -1032,6 +1033,10 @@ impl RenderBoxUtils for @RenderBox {
box_bounds, absolute_box_bounds, self.debug_str());
debug!("RenderBox::build_display_list: dirty={}, offset={}", *dirty, *offset);

if base.nearest_ancestor_element().style().Box.visibility != visibility::visible {
return;
}

if absolute_box_bounds.intersects(dirty) {
debug!("RenderBox::build_display_list: intersected. Adding display item...");
} else {
Expand Down
3 changes: 3 additions & 0 deletions src/components/style/properties.rs.mako
Expand Up @@ -373,6 +373,9 @@ pub mod longhands {
// CSS 2.1, Section 11 - Visual effects
${single_keyword("overflow", "visible hidden", inherited=False)} // TODO: scroll auto

// TODO: collapse. Well, do tables first.
${single_keyword("visibility", "visible hidden", inherited=True)}

// CSS 2.1, Section 12 - Generated content, automatic numbering, and lists

// CSS 2.1, Section 13 - Paged media
Expand Down
1 change: 1 addition & 0 deletions src/test/ref/basic.list
Expand Up @@ -12,3 +12,4 @@
== first_of_type_pseudo_a.html first_of_type_pseudo_b.html
== last_of_type_pseudo_a.html last_of_type_pseudo_b.html
== only_of_type_pseudo_a.html only_of_type_pseudo_b.html
== visibility_hidden.html visibility_hidden_ref.html
18 changes: 18 additions & 0 deletions src/test/ref/visibility_hidden.html
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<title>'visibility: hidden' test</title>
<style type="text/css">
body { color: black; background: white }
.hidden { visibility: hidden; }
.visible { visibility: visible; }
</style>
</head>
<body>
<p>This should be visible.</p>
<div class="hidden">
<p>This should NOT be visible.</p>
<p class="visible">This should be visible.</p>
</div>
</body>
</html>
17 changes: 17 additions & 0 deletions src/test/ref/visibility_hidden_ref.html
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<title>'visibility: hidden' test</title>
<style type="text/css">
body { color: black; background: white }
</style>
</head>
<body>
<p>This should be visible.</p>
<div>
<!-- Use the same markup so that this test is not affected by broken margin collapsing. -->
<p>&nbsp;</p>
<p>This should be visible.</p>
</div>
</body>
</html>

5 comments on commit 7a4c809

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from pcwalton
at SimonSapin@7a4c809

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging SimonSapin/servo/visibility = 7a4c809 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SimonSapin/servo/visibility = 7a4c809 merged ok, testing candidate = a92d430

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = a92d430

Please sign in to comment.