<commit_before>#!/usr/bin/env python

'''Single view of a document.

Responsible for maintaining frame and style trees.
'''

__docformat__ = 'restructuredtext'
__version__ = '$Id$'

from pyglet.layout.content import *
from pyglet.layout.frame import *

class DocumentView(DocumentListener):
    def __init__(self, render_device, document):
        self.render_device = render_device
        self.document = document
        self.document.add_listener(self)
        self.frame_builder = FrameBuilder(self.document, self.render_device)

        self._root_frame = None

        self._require_reconstruct = False # Temporary HACK

        # Position of viewport on canvas (+ve Y is down).  Size of viewport
        # determines the initial containing block.
        self.viewport_x = 0
        self.viewport_y = 0
        self._viewport_width = 0 
        self._viewport_height = 0

    def on_set_root(self, element):
        self._require_reconstruct = True

    def on_element_modified(self, element):
        self._require_reconstruct = True

    def on_element_style_modified(self, element):
        frame = element.frame
        if frame:
            frame.style = self.frame_builder.get_style_node(element)
            frame.purge_style_cache()
            frame.mark_flow_dirty()

    def reflow_resize(self):
        self._root_frame.containing_block = self.initial_containing_block()
        self._root_frame.mark_flow_dirty()

    def update_flow(self):
        if self._require_reconstruct:
            self._root_frame = self.frame_builder.build_frame(self.document.root)
            self._root_frame.containing_block = self.initial_containing_block()
        if self._root_frame.flow_dirty:
            self._root_frame.flow()
            self._root_frame.resolve_bounding_box(0, 0)<commit_msg>Don't reconstruct frame hierarchy after mouse scroll ;-)<commit_after>#!/usr/bin/env python

'''Single view of a document.

Responsible for maintaining frame and style trees.
'''

__docformat__ = 'restructuredtext'
__version__ = '$Id$'

from pyglet.layout.content import *
from pyglet.layout.frame import *

class DocumentView(DocumentListener):
    def __init__(self, render_device, document):
        self.render_device = render_device
        self.document = document
        self.document.add_listener(self)
        self.frame_builder = FrameBuilder(self.document, self.render_device)

        self._root_frame = None

        self._require_reconstruct = False # Temporary HACK

        # Position of viewport on canvas (+ve Y is down).  Size of viewport
        # determines the initial containing block.
        self.viewport_x = 0
        self.viewport_y = 0
        self._viewport_width = 0 
        self._viewport_height = 0

    def on_set_root(self, element):
        self._require_reconstruct = True

    def on_element_modified(self, element):
        self._require_reconstruct = True

    def on_element_style_modified(self, element):
        frame = element.frame
        if frame:
            frame.style = self.frame_builder.get_style_node(element)
            frame.purge_style_cache()
            frame.mark_flow_dirty()

    def reflow_resize(self):
        self._root_frame.containing_block = self.initial_containing_block()
        self._root_frame.mark_flow_dirty()

    def update_flow(self):
        if self._require_reconstruct:
            self._root_frame = self.frame_builder.build_frame(self.document.root)
            self._root_frame.containing_block = self.initial_containing_block()
            self._require_reconstruct = False
        if self._root_frame.flow_dirty:
            self._root_frame.flow()
            self._root_frame.resolve_bounding_box(0, 0)
{'fraction_non_alphanumeric': 0.08164368748310354, 'fraction_numerical': 0.0032441200324412004, 'mean_word_length': 2.8662486938349008, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '315238', 'n_tokens_mistral': 1088, 'n_tokens_neox': 1046, 'n_words': 224}