Skip to content

Commit

Permalink
Implement clear for floats
Browse files Browse the repository at this point in the history
  • Loading branch information
sanxiyn authored and metajack committed Aug 15, 2013
1 parent 034536e commit 425e837
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 11 deletions.
11 changes: 1 addition & 10 deletions src/components/main/layout/block.rs
Expand Up @@ -12,8 +12,6 @@ use layout::inline::InlineLayout;
use layout::model::{MaybeAuto, Specified, Auto};
use layout::float_context::{FloatContext, Invalid};

use newcss::values::{CSSClearNone, CSSClearLeft, CSSClearRight, CSSClearBoth};
use layout::float_context::{ClearLeft, ClearRight, ClearBoth};
use std::cell::Cell;
use geom::point::Point2D;
use geom::rect::Rect;
Expand Down Expand Up @@ -281,14 +279,7 @@ impl BlockFlowData {
let mut float_ctx = Invalid;

for self.box.iter().advance |&box| {
let style = box.style();
let clear = match style.clear() {
CSSClearNone => None,
CSSClearLeft => Some(ClearLeft),
CSSClearRight => Some(ClearRight),
CSSClearBoth => Some(ClearBoth)
};
clearance = match clear {
clearance = match box.clear() {
None => Au(0),
Some(clear) => {
self.common.floats_in.clearance(clear)
Expand Down
12 changes: 12 additions & 0 deletions src/components/main/layout/box.rs
Expand Up @@ -7,6 +7,7 @@
use css::node_style::StyledNode;
use layout::context::LayoutContext;
use layout::display_list_builder::{DisplayListBuilder, ExtraDisplayListData, ToGfxColor};
use layout::float_context::{ClearType, ClearLeft, ClearRight, ClearBoth};
use layout::flow::FlowContext;
use layout::model::{BoxModel, MaybeAuto};
use layout::text;
Expand All @@ -27,6 +28,7 @@ use gfx::text::text_run::TextRun;
use newcss::color::rgb;
use newcss::complete::CompleteStyle;
use newcss::units::{Cursive, Em, Fantasy, Monospace, Pt, Px, SansSerif, Serif};
use newcss::values::{CSSClearNone, CSSClearLeft, CSSClearRight, CSSClearBoth};
use newcss::values::{CSSFontFamilyFamilyName, CSSFontFamilyGenericFamily};
use newcss::values::{CSSFontSizeLength, CSSFontStyleItalic, CSSFontStyleNormal};
use newcss::values::{CSSFontStyleOblique, CSSTextAlign, CSSTextDecoration, CSSLineHeight};
Expand Down Expand Up @@ -761,6 +763,16 @@ impl RenderBox {
}
}

pub fn clear(&self) -> Option<ClearType> {
let style = self.style();
match style.clear() {
CSSClearNone => None,
CSSClearLeft => Some(ClearLeft),
CSSClearRight => Some(ClearRight),
CSSClearBoth => Some(ClearBoth)
}
}

/// Converts this node's computed style to a font style used for rendering.
pub fn font_style(&self) -> FontStyle {
let my_style = self.nearest_ancestor_element().style();
Expand Down
9 changes: 8 additions & 1 deletion src/components/main/layout/float.rs
Expand Up @@ -183,13 +183,20 @@ impl FloatFlowData {
// so this is well-defined

let mut height = Au(0);
let mut clearance = Au(0);
let mut full_noncontent_width = Au(0);
let mut full_noncontent_height = Au(0);

self.box.map(|&box| {
height = do box.with_base |base| {
base.position.size.height
};
clearance = match box.clear() {
None => Au(0),
Some(clear) => {
self.common.floats_in.clearance(clear)
}
};

do box.with_base |base| {

Expand All @@ -208,7 +215,7 @@ impl FloatFlowData {
let info = PlacementInfo {
width: self.common.position.size.width + full_noncontent_width,
height: height + full_noncontent_height,
ceiling: Au(0),
ceiling: clearance,
max_width: self.containing_width,
f_type: self.float_type,
};
Expand Down
43 changes: 43 additions & 0 deletions src/test/html/test_clear_float.html
@@ -0,0 +1,43 @@
<html>
<head>
<style>
#container {
width: 300px;
}
#left {
float: left;
width: 100px;
height: 100px;
background: red;
}
#right {
float: right;
width: 100px;
height: 150px;
background: blue;
}
#clear1 {
float: left;
clear: left;
width: 50px;
height: 50px;
background: green;
}
#clear2 {
float: right;
clear: right;
width: 50px;
height: 50px;
background: green;
}
</style>
</head>
<body>
<div id="container">
<div id="left"></div>
<div id="right"></div>
<div id="clear1"></div>
<div id="clear2"></div>
</div>
</body>
</html>

8 comments on commit 425e837

@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 metajack
at metajack@425e837

@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 metajack/servo/clear-float = 425e837 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.

metajack/servo/clear-float = 425e837 merged ok, testing candidate = 0787d76

@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.

No active merge of candidate 425e837 found, likely manual push to master

@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 metajack/servo/clear-float = 425e837 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.

metajack/servo/clear-float = 425e837 merged ok, testing candidate = c0fed8f

@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 = c0fed8f

Please sign in to comment.