Skip to content

Commit

Permalink
Fix autoscroll.
Browse files Browse the repository at this point in the history
Use the webviews scrolledwindow vadjustments changed and value-changed events
to properly distinguish between user and program originated scrolling events.
  • Loading branch information
Erik Soehnel committed Apr 28, 2012
1 parent 6c4806d commit f20a860
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions schirm/webkit_wrapper.py
Expand Up @@ -403,8 +403,8 @@ class EmbeddedWebView():
wires the searchframe.
"""
def __init__(self):
# when True, automatically scroll to bottom when the WebView
# size changes
# when True, automatically scroll to the bottom when the
# WebView size changes
self.autoscroll = True
self._search_forward = False

Expand All @@ -431,20 +431,32 @@ def __init__(self):

# enable automatic scrolling when we are at the bottom of the
# terminal
ignore_adjustment = [False]
last_adjustment = [0]
last_upper = [0]
def value_changed_cb(adjustment, *user_data):
if adjustment.value >= (adjustment.get_upper() - adjustment.page_size - 10):
self.autoscroll = True
else:
self.autoscroll = False
d_value = adjustment.value - last_adjustment[0]
d_upper = adjustment.get_upper() - last_upper[0]

last_adjustment[0] = adjustment.value
last_upper[0] = adjustment.get_upper()

if d_upper == 0.0:
if d_value > 0:
if adjustment.value >= (adjustment.get_upper() - adjustment.page_size - 5):
# scrolled to (within 5px of) bottom
self.autoscroll = True
elif d_value < 0:
# scrolled up
self.autoscroll = False
elif d_upper > 0:
# webview grows bigger
if self.autoscroll:
adjustment.set_value(adjustment.get_upper() - adjustment.page_size)

va = scrollview.get_vadjustment()
# use both events to track upper-bound and value changes
va.connect('value-changed', value_changed_cb)

def scroll_to_bottom_cb(widget, req, *user_data):
if self.autoscroll:
va = scrollview.get_vadjustment()
va.set_value(va.get_upper() - va.page_size)
browser.connect('size-request', scroll_to_bottom_cb)
va.connect('changed', value_changed_cb)

box.pack_start(scrollview, expand=True, fill=True, padding=0)

Expand Down

0 comments on commit f20a860

Please sign in to comment.