Skip to content

Commit

Permalink
Fix the drawing order of fixed boxes
Browse files Browse the repository at this point in the history
Cherry-picked from 568e0ae

Conflicts:
	weasyprint/layout/blocks.py
	weasyprint/layout/inlines.py
  • Loading branch information
liZe authored and SimonSapin committed Jun 19, 2012
1 parent 4c8b3f7 commit f9e7c40
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 27 deletions.
2 changes: 1 addition & 1 deletion weasyprint/document.py
Expand Up @@ -23,7 +23,7 @@ class Document(object):
"""Abstract output document."""
def __init__(self, backend, dom, user_stylesheets, user_agent_stylesheets):
self.backend = backend
self.fixed_boxes = []
self.current_page = None
self.surface = backend.get_dummy_surface()
self.dom = dom #: lxml HtmlElement object
self.user_stylesheets = user_stylesheets
Expand Down
1 change: 1 addition & 0 deletions weasyprint/formatting_structure/boxes.py
Expand Up @@ -568,6 +568,7 @@ def __init__(self, page_type, style):
# Page boxes are not linked to any element.
super(PageBox, self).__init__(
element_tag=None, sourceline=None, style=style, children=[])
self.fixed_boxes = []

def __repr__(self):
return '<%s %s>' % (type(self).__name__, self.page_type)
Expand Down
21 changes: 14 additions & 7 deletions weasyprint/layout/__init__.py
Expand Up @@ -25,6 +25,15 @@
from .pages import make_all_pages, make_margin_boxes


def layout_fixed_boxes(document, pages):
"""Lay out and yield the fixed boxes of ``pages``."""
for page in pages:
for fixed_box in page.fixed_boxes:
fixed_box_for_page = fixed_box.copy()
absolute_layout(document, fixed_box_for_page, page)
yield fixed_box_for_page


def layout_document(document, root_box):
"""Lay out the whole document.
Expand All @@ -38,14 +47,12 @@ def layout_document(document, root_box):
pages = list(make_all_pages(document, root_box))
page_counter = [1]
counter_values = {'page': page_counter, 'pages': [len(pages)]}
for page in pages:
for i, page in enumerate(pages):
root_children = []
root, = page.children
root_children = list(root.children)
for fixed_box in document.fixed_boxes:
fixed_box_for_page = fixed_box.copy()
absolute_layout(document, fixed_box_for_page, page)
root_children.append(fixed_box_for_page)

root_children.extend(layout_fixed_boxes(document, pages[:i]))
root_children.extend(root.children)
root_children.extend(layout_fixed_boxes(document, pages[i+1:]))
root = root.copy_with_children(root_children)
page.children = (root,) + tuple(
make_margin_boxes(document, page, counter_values))
Expand Down
19 changes: 11 additions & 8 deletions weasyprint/layout/blocks.py
Expand Up @@ -240,16 +240,16 @@ def block_container_layout(document, box, max_position_y, skip_stack,
child.position_y = position_y

if not child.is_in_normal_flow():
if child.style.position in ('absolute', 'fixed'):
if child.is_absolutely_positioned():
child.position_y += collapse_margin(adjoining_margins)
placeholder = AbsolutePlaceholder(child)
if child.style.position == 'absolute':
absolute_boxes.append(placeholder)
new_children.append(placeholder)
else:
document.fixed_boxes.append(placeholder)
else:
new_children.append(placeholder)
absolute_boxes.append(placeholder)
if child.style.position == 'fixed':
document.current_page.fixed_boxes.append(placeholder)
elif child.is_floated():
# TODO: Floats
assert 0
new_children.append(child)
continue

Expand Down Expand Up @@ -426,7 +426,10 @@ def block_container_layout(document, box, max_position_y, skip_stack,
if new_box.style.position == 'relative':
# New containing block, resolve the layout of the absolute descendants
for absolute_box in absolute_boxes:
absolute_layout(document, absolute_box, new_box)
if absolute_box.style.position == 'absolute':
absolute_layout(document, absolute_box, new_box)
else:
absolute_layout(document, absolute_box, document.current_page)

for child in new_box.children:
relative_positioning(child, (new_box.width, new_box.height))
Expand Down
19 changes: 11 additions & 8 deletions weasyprint/layout/inlines.py
Expand Up @@ -543,17 +543,17 @@ def split_inline_box(document, box, position_x, max_x, skip_stack,
for index, child in box.enumerate_skip(skip):
child.position_y = box.position_y
if not child.is_in_normal_flow():
if child.style.position in ('absolute', 'fixed'):
if child.is_absolutely_positioned():
child.position_x = position_x
placeholder = AbsolutePlaceholder(child)
line_placeholders.append(placeholder)
if child.style.position == 'absolute':
absolute_boxes.append(placeholder)
children.append(placeholder)
else:
document.fixed_boxes.append(placeholder)
else:
children.append(placeholder)
absolute_boxes.append(placeholder)
if child.style.position == 'fixed':
document.current_page.fixed_boxes.append(placeholder)
elif child.style.float in ('left', 'right'):
# TODO: Floats
assert 0
children.append(child)
continue

Expand Down Expand Up @@ -616,7 +616,10 @@ def split_inline_box(document, box, position_x, max_x, skip_stack,

if new_box.style.position == 'relative':
for absolute_box in absolute_boxes:
absolute_layout(document, absolute_box, new_box)
if absolute_box.style.position == 'absolute':
absolute_layout(document, absolute_box, new_box)
else:
absolute_layout(document, absolute_box, document.current_page)
return new_box, resume_at, preserved_line_break


Expand Down
6 changes: 3 additions & 3 deletions weasyprint/layout/pages.py
Expand Up @@ -466,7 +466,7 @@ def make_page(document, root_box, page_type, resume_at, content_empty):
style = document.style_for(page_type)
# Propagated from the root or <body>.
style.overflow = root_box.viewport_overflow
page = boxes.PageBox(page_type, style)
document.current_page = page = boxes.PageBox(page_type, style)

device_size = page.style.size
page.outer_width, page.outer_height = device_size
Expand Down Expand Up @@ -504,11 +504,11 @@ def make_page(document, root_box, page_type, resume_at, content_empty):
for absolute_box in absolute_boxes:
absolute_layout(document, absolute_box, page)

page = page.copy_with_children(children)
document.current_page = page.copy_with_children(children)

if content_empty:
resume_at = previous_resume_at
return page, resume_at, next_page
return document.current_page, resume_at, next_page


def make_all_pages(document, root_box):
Expand Down

0 comments on commit f9e7c40

Please sign in to comment.