diff options
author | corvid <corvid@lavabit.com> | 2012-11-04 19:20:36 +0000 |
---|---|---|
committer | corvid <corvid@lavabit.com> | 2012-11-04 19:20:36 +0000 |
commit | 694cdacadc33f8fa0cd76afd97487315c210713c (patch) | |
tree | b3057a4f011be4d76d8c6f13068d05b85511f09f /dw | |
parent | 1356e3bacfb69f3902ccffebb15dee97906df60e (diff) |
layout: pretend that mouse events outside the visible canvas are at its edge
This is to make highlighting/copying work somewhat better.
Diffstat (limited to 'dw')
-rw-r--r-- | dw/layout.cc | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/dw/layout.cc b/dw/layout.cc index 9dfd5e9b..2e08a3f8 100644 --- a/dw/layout.cc +++ b/dw/layout.cc @@ -949,7 +949,36 @@ bool Layout::processMouseEvent (MousePositionEvent *event, { Widget *widget; - for (widget = widgetAtPoint; widget; widget = widget->getParent ()) { + /* + * If the event is outside of the visible region of the canvas, treat it + * as occurring at the region's edge. Notably, this helps when selecting + * text. + */ + if (event->xCanvas < scrollX) + event->xCanvas = scrollX; + else { + int actualVScrollbarThickness = + canvasAscent + canvasDescent > viewportHeight ? vScrollbarThickness:0; + int maxX = scrollX + viewportWidth - actualVScrollbarThickness - 1; + + if (event->xCanvas > maxX) + event->xCanvas = maxX; + } + if (event->yCanvas < scrollY) + event->yCanvas = scrollY; + else { + int actualHScrollbarThickness = + (canvasWidth > viewportWidth) ? hScrollbarThickness : 0; + int maxY = misc::min(scrollY + viewportHeight -actualHScrollbarThickness, + canvasAscent + canvasDescent) - 1; + + if (event->yCanvas > maxY) + event->yCanvas = maxY; + } + + widget = getWidgetAtPoint(event->xCanvas, event->yCanvas); + + for (; widget; widget = widget->getParent ()) { if (!mayBeSuppressed || widget->isButtonSensitive ()) { event->xWidget = event->xCanvas - widget->getAllocation()->x; event->yWidget = event->yCanvas - widget->getAllocation()->y; |