-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix overflow and clipping issues with 'overflow: auto' and 'overflow:…
… hidden' on nested elements. See #116. Some additional tests added.
- Loading branch information
Showing
8 changed files
with
160 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ | |
namespace Rml { | ||
|
||
// Creates a new block box for rendering a block element. | ||
LayoutBlockBox::LayoutBlockBox(LayoutEngine* _layout_engine, LayoutBlockBox* _parent, Element* _element) : position(0, 0) | ||
LayoutBlockBox::LayoutBlockBox(LayoutEngine* _layout_engine, LayoutBlockBox* _parent, Element* _element) : position(0), visible_outer_width(0) | ||
{ | ||
RMLUI_ZoneScoped; | ||
|
||
|
@@ -211,10 +211,13 @@ LayoutBlockBox::CloseResult LayoutBlockBox::Close() | |
{ | ||
// Calculate the dimensions of the box's *internal* content; this is the tightest-fitting box around all of the | ||
// internal elements, plus this element's padding. | ||
Vector2f content_box(0, 0); | ||
Vector2f content_box = Vector2f(0, 0); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
mikke89
Author
Owner
|
||
|
||
for (size_t i = 0; i < block_boxes.size(); i++) | ||
content_box.x = Math::Max(content_box.x, block_boxes[i]->GetBox().GetSize(Box::MARGIN).x); | ||
{ | ||
// TODO: Only if the containing block is not an ancestor of us (ie. we are the containing block?). | ||
content_box.x = Math::Max(content_box.x, block_boxes[i]->visible_outer_width); | ||
} | ||
|
||
// Check how big our floated area is. | ||
Vector2f space_box = space->GetDimensions(); | ||
|
@@ -246,6 +249,16 @@ LayoutBlockBox::CloseResult LayoutBlockBox::Close() | |
element->SetBox(box); | ||
element->SetContentBox(space->GetOffset(), content_box); | ||
|
||
const float margin_width = GetBox().GetSize(Box::MARGIN).x; | ||
|
||
// Set the visible outer width so that ancestors can catch any overflow produced by us. That is, hiding it or providing a scrolling mechanism. | ||
// If we catch our own overflow here, then just use the normal margin box as that will effectively remove the overflow from our ancestor's perspective. | ||
if (overflow_x_property != Style::Overflow::Visible) | ||
visible_outer_width = margin_width; | ||
else | ||
visible_outer_width = Math::Max(margin_width, space->GetOffset().x + content_box.x + box.GetEdge(Box::MARGIN, Box::LEFT) + box.GetEdge(Box::MARGIN, Box::RIGHT)); | ||
|
||
|
||
// Format any scrollbars which were enabled on this element. | ||
element->GetElementScroll()->FormatScrollbars(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<rml> | ||
<head> | ||
<title>Floats, block formatting contexts</title> | ||
<link type="text/rcss" href="../style.rcss"/> | ||
<link rel="help" href="https://www.w3.org/TR/CSS21/visufx.html#propdef-overflow" /> | ||
<meta name="Description" content="Nesting divs should still hide overflow. Elements whose containing block is located above the 'overflow: hidden' element should be visible." /> | ||
<meta name="See also" content="CSS 2.1 'clipping-' and 'overflow-' tests." /> | ||
<style> | ||
body { | ||
background: #ddd; | ||
color: #444; | ||
} | ||
#content { | ||
width: 200px; | ||
margin: 0 auto; | ||
} | ||
div.float { | ||
float: left; | ||
background-color: #bbb; | ||
border: 1px #333; | ||
width: 100px; | ||
height: 100px; | ||
margin: 5px; | ||
} | ||
.red { | ||
color: red; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<p>This test makes assumptions about the font properties, that is, it depends on the size of the layed-out text.</p> | ||
<div id="content"> | ||
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod. | ||
<div class="float">float: left</div> | ||
<span class="red">This</span> is the first word after the float and should flow next to the float.</p> | ||
<p>This paragraph should flow next to the float.</p> | ||
|
||
<hr/> | ||
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod. | ||
<div class="float">float: left</div> | ||
<span class="red">This</span> is the first word after the float and should flow next to the float.</p> | ||
<p style="clear: left;">This paragraph should be below the float as it clears the float.</p> | ||
|
||
<hr/> | ||
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod. | ||
<div class="float">float: left</div> | ||
<span class="red">This</span> is the first word after the float and should flow next to the float.</p> | ||
<p style="overflow: auto;">This paragraph should establish a new block formatting context. This element's size and position should not overlap with the float, but still be located next to it.</p> | ||
</div> | ||
</body> | ||
</rml> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<rml> | ||
<head> | ||
<title>Floats: overflow</title> | ||
<link type="text/rcss" href="../style.rcss"/> | ||
<link rel="help" href="http://www.w3.org/TR/CSS21/visuren.html#floats" /> | ||
<meta name="Description" content="Floating boxes" /> | ||
<style> | ||
body { | ||
background: #ddd; | ||
color: #444; | ||
} | ||
#content { | ||
width: 200px; | ||
margin: 0 auto; | ||
} | ||
.box { | ||
background-color: #cce; | ||
border: 5px #77b; | ||
} | ||
.float { | ||
float: left; | ||
background-color: #ddda; | ||
border: 1px #333; | ||
width: 200px; | ||
height: 130px; | ||
margin: 5px; | ||
} | ||
|
||
</style> | ||
</head> | ||
|
||
<body> | ||
<div class="box"> | ||
<div class="float">float: left</div> | ||
<p>The float to the left should extend past the background of the containing '.box' element.</p> | ||
</div> | ||
<hr/> | ||
<div class="box" style="overflow:auto"> | ||
<div class="float">float: left</div> | ||
<p>Using 'overflow: auto' on the containing '.box' element. This should establish a new block formatting context (thereby resolving all floats) so that the background wraps around the entire float.</p> | ||
</div> | ||
</body> | ||
</rml> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<rml> | ||
<head> | ||
<title>Nested overflow</title> | ||
<link type="text/rcss" href="../style.rcss"/> | ||
<meta name="Description" content="The deepest element in the tree should catch the overflow." /> | ||
<style> | ||
body { | ||
display: block; | ||
background: #ddd; | ||
color: #444; | ||
} | ||
div.outer { | ||
overflow: auto; | ||
width: 200px; | ||
height: 200px; | ||
} | ||
div.overflow { | ||
border: 1px black; | ||
overflow: auto; | ||
width: 150px; | ||
height: 150px; | ||
} | ||
div.wide { | ||
width: 300px; | ||
height: 20px; | ||
text-align: center; | ||
border: 1px #0a0; | ||
margin: 5px; | ||
background-color: #eee; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<p>There should should only be one scroll bar visible, inside the black border.</p> | ||
<div class="outer"> | ||
<div class="overflow"> | ||
<div class="wide">Wide element</div> | ||
</div> | ||
</div> | ||
</body> | ||
</rml> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Not to nitpick but just curious as to why? :P The old version seems a bit more concise.