Nearest `original_widget` that is compatible with the scrolling API
190741
def scrolling_base_widget(self):
        """"""
        def orig_iter(w):
            while hasattr(w, 'original_widget'):
                w = w.original_widget
                yield w
            yield w

        def is_scrolling_widget(w):
            return hasattr(w, 'get_scrollpos') and hasattr(w, 'rows_max')

        for w in orig_iter(self):
            if is_scrolling_widget(w):
                return w
        raise ValueError('Not compatible to be wrapped by ScrollBar: %r' % w)
358255
def setCentralWidget( self, widget ):
        
        self._scrollArea.takeWidget()
        self._scrollArea.setWidget(widget)
        
        self.adjustSize()
147356
function _scrollHandler(e) {
        // Document scrolls can be updated immediately. Any other scrolls
        // need to be updated on a timer to ensure the layout is correct.
        if (e.target === window.document) {
            redrawHighlights();
        } else {
            if (_remoteHighlight || _localHighlight) {
                window.setTimeout(redrawHighlights, 0);
            }
        }
    }
338343
def scroll_right(self, n, pre_dl=None, post_dl=None):
        
        self.delay(pre_dl)
        self.m.scroll(horizontal=n)
        self.delay(post_dl)
823215
function scrollInterpolator4 (index, carouselProps) {
    const range = [1, 0, -1];
    const inputRange = getInputRangeFromIndexes(range, index, carouselProps);
    const outputRange = range;

    return { inputRange, outputRange };
}
841683
def _scroll_up(self, cli):
        "  "
        info = self.render_info

        if info.vertical_scroll > 0:
            # TODO: not entirely correct yet in case of line wrapping and long lines.
            if info.cursor_position.y >= info.window_height - 1 - info.configured_scroll_offsets.bottom:
                self.content.move_cursor_up(cli)

            self.vertical_scroll -= 1
813984
def _scroll_without_linewrapping(self, ui_content, width, height, cli):
        
        cursor_position = ui_content.cursor_position or Point(0, 0)

        # Without line wrapping, we will never have to scroll vertically inside
        # a single line.
        self.vertical_scroll_2 = 0

        if ui_content.line_count == 0:
            self.vertical_scroll = 0
            self.horizontal_scroll = 0
            return
        else:
            current_line_text = token_list_to_text(ui_content.get_line(cursor_position.y))

        def do_scroll(current_scroll, scroll_offset_start, scroll_offset_end,
                      cursor_pos, window_size, content_size):
            " Scrolling algorithm. Used for both horizontal and vertical scrolling. "
            # Calculate the scroll offset to apply.
            # This can obviously never be more than have the screen size. Also, when the
            # cursor appears at the top or bottom, we don't apply the offset.
            scroll_offset_start = int(min(scroll_offset_start, window_size / 2, cursor_pos))
            scroll_offset_end = int(min(scroll_offset_end, window_size / 2,
                                        content_size - 1 - cursor_pos))

            # Prevent negative scroll offsets.
            if current_scroll < 0:
                current_scroll = 0

            # Scroll back if we scrolled to much and there's still space to show more of the document.
            if (not self.allow_scroll_beyond_bottom(cli) and
                    current_scroll > content_size - window_size):
                current_scroll = max(0, content_size - window_size)

            # Scroll up if cursor is before visible part.
            if current_scroll > cursor_pos - scroll_offset_start:
                current_scroll = max(0, cursor_pos - scroll_offset_start)

            # Scroll down if cursor is after visible part.
            if current_scroll < (cursor_pos + 1) - window_size + scroll_offset_end:
                current_scroll = (cursor_pos + 1) - window_size + scroll_offset_end

            return current_scroll

        # When a preferred scroll is given, take that first into account.
        if self.get_vertical_scroll:
            self.vertical_scroll = self.get_vertical_scroll(self)
            assert isinstance(self.vertical_scroll, int)
        if self.get_horizontal_scroll:
            self.horizontal_scroll = self.get_horizontal_scroll(self)
            assert isinstance(self.horizontal_scroll, int)

        # Update horizontal/vertical scroll to make sure that the cursor
        # remains visible.
        offsets = self.scroll_offsets

        self.vertical_scroll = do_scroll(
            current_scroll=self.vertical_scroll,
            scroll_offset_start=offsets.top,
            scroll_offset_end=offsets.bottom,
            cursor_pos=ui_content.cursor_position.y,
            window_size=height,
            content_size=ui_content.line_count)

        self.horizontal_scroll = do_scroll(
            current_scroll=self.horizontal_scroll,
            scroll_offset_start=offsets.left,
            scroll_offset_end=offsets.right,
            cursor_pos=get_cwidth(current_line_text[:ui_content.cursor_position.x]),
            window_size=width,
            # We can only analyse the current line. Calculating the width off
            # all the lines is too expensive.
            content_size=max(get_cwidth(current_line_text), self.horizontal_scroll + width))
1153459
def is_widget_with_placeholder(widget):
    
    return isinstance(
        widget, (TextInput, Textarea, NumberInput, EmailInput, URLInput, PasswordInput)
    )
1249734
def updateGeometry(self):
        
        WIDGET_BORDER_MARGIN = 5
        SCROLLBAR_WIDTH = 30  # just a guess

        sizeHint = self.sizeHint()
        width = sizeHint.width()
        height = sizeHint.height()

        cursorRect = self._qpart.cursorRect()
        parentSize = self.parentWidget().size()

        spaceBelow = parentSize.height() - cursorRect.bottom() - WIDGET_BORDER_MARGIN
        spaceAbove = cursorRect.top() - WIDGET_BORDER_MARGIN

        if height <= spaceBelow or \
           spaceBelow > spaceAbove:
            yPos = cursorRect.bottom()
            if height > spaceBelow and \
               spaceBelow > self.minimumHeight():
                height = spaceBelow
                width = width + SCROLLBAR_WIDTH
        else:
            if height > spaceAbove and \
               spaceAbove > self.minimumHeight():
                height = spaceAbove
                width = width + SCROLLBAR_WIDTH
            yPos = max(3, cursorRect.top() - height)

        xPos = cursorRect.right() - self._horizontalShift()

        if xPos + width + WIDGET_BORDER_MARGIN > parentSize.width():
            xPos = max(3, parentSize.width() - WIDGET_BORDER_MARGIN - width)

        self.setGeometry(xPos, yPos, width, height)
        self._closeIfNotUpdatedTimer.stop()
116144
def _auto_scroll(self, *args):
        
        adj = self['scrollable'].get_vadjustment()
        adj.set_value(adj.get_upper() - adj.get_page_size())
200632
public static FlowPanel wrapScrollable(Widget widget) {

        FlowPanel wrapper = new FlowPanel();
        wrapper.add(widget);
        makeScrollable(wrapper);
        return wrapper;
    }
575509
def takeAt( self, index ):
        
        layout = self.widget().layout()
        item = layout.takeAt(index)
        if ( not item ):
            return None
        
        return item.widget().widget()
473971
function scrollInterpolator3 (index, carouselProps) {
    const range = [2, 1, 0, -1];
    const inputRange = getInputRangeFromIndexes(range, index, carouselProps);
    const outputRange = range;

    return { inputRange, outputRange };
}
448122
def make_onmousewheel_cb(widget, orient, factor = 1):
        
        _os = platform.system()
        view_command = getattr(widget, orient+'view')
        if _os in ('Linux', 'OpenBSD', 'FreeBSD'):
            def on_mousewheel(event):
                if event.num == 4:
                    view_command('scroll', (-1)*factor, 'units')
                elif event.num == 5:
                    view_command('scroll', factor, 'units') 
        
        elif _os == 'Windows':
            def on_mousewheel(event):        
                view_command('scroll', (-1)*int((event.delta/120)*factor), 'units') 
        
        elif _os == 'Darwin':
            def on_mousewheel(event):        
                view_command('scroll', event.delta, 'units')
        else:
            # FIXME: unknown platform scroll method
            def on_mousewheel(event):
                pass
        
        return on_mousewheel
1160652
@Override
	public void scrollTo() throws WidgetException {
		WebElement we = findElement();	
		Locatable l = ((Locatable)we);
		l.getCoordinates().inViewPort();
	}
591334
def visualRect(self, index):
        
        rect = super(XTreeWidget, self).visualRect(index)
        item = self.itemFromIndex(index)
        if not rect.isNull() and item and item.isFirstColumnSpanned():
            vpos = self.viewport().mapFromParent(QtCore.QPoint(0, 0))
            rect.setX(vpos.x())
            rect.setWidth(self.width())
            return rect
        return rect
807545
def browserWidget( self ):
        
        from projexui.widgets.xorbbrowserwidget import XOrbBrowserWidget
        return projexui.ancestor(self, XOrbBrowserWidget)