experimental code: highlighting and scrolling
"corvid" <[email protected]>
| Newsgroups | gmane.comp.web.dillo.devel |
|---|---|
| Message-ID | <20121020084111.GA9786@local> |
I was thinking how unpleasant it is when you are highlighting text and you release the button outside the viewport, and the text doesn't get copied. (Even harder to keep in mind is when the canvas is shorter than the viewport, and you go past the bottom of the canvas.) ..and then I wanted to see whether I could make the page scroll when highlighting outside the viewport like firefox does... _______________________________________________ Dillo-dev mailing list [email protected] http://lists.auriga.wearlab.de/cgi-bin/mailman/listinfo/dillo-dev
highlighting_outside_viewport.diff
(text/plain, 1023 B)
diff -r c1802a602300 dw/layout.cc
--- a/dw/layout.cc Sat Oct 20 01:15:56 2012 +0000
+++ b/dw/layout.cc Sat Oct 20 08:21:08 2012 +0000
@@ -949,7 +949,18 @@
{
Widget *widget;
- for (widget = widgetAtPoint; widget; widget = widget->getParent ()) {
+ if (event->xCanvas < scrollX)
+ event->xCanvas = scrollX;
+ else if (event->xCanvas >= scrollX + viewportWidth - vScrollbarThickness)
+ event->xCanvas = scrollX + viewportWidth - vScrollbarThickness - 1;
+ if (event->yCanvas < scrollY)
+ event->yCanvas = scrollY;
+ else if (event->yCanvas >= scrollY + viewportHeight - hScrollbarThickness)
+ event->yCanvas = scrollY + viewportHeight - hScrollbarThickness - 1;
+
+ 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;
highlighting_scrolling.diff
(text/plain, 2.9 KB)
diff -r c1802a602300 dw/fltkviewport.cc
--- a/dw/fltkviewport.cc Sat Oct 20 01:15:56 2012 +0000
+++ b/dw/fltkviewport.cc Sat Oct 20 08:21:32 2012 +0000
@@ -275,7 +275,9 @@
break;
case FL_DRAG:
- if (dragScrolling && Fl::event_button() == FL_MIDDLE_MOUSE) {
+ if (Fl::event_inside(this))
+ Fl::remove_timeout(highlightScroll);
+ if (dragScrolling) {
scroll(dragX - Fl::event_x(), dragY - Fl::event_y());
dragX = Fl::event_x();
dragY = Fl::event_y();
@@ -286,6 +288,11 @@
} else if (horScrolling) {
hscrollbar->handle(event);
return 1;
+ } else if (!Fl::event_inside(this)) {
+ mouse_x = Fl::event_x();
+ mouse_y = Fl::event_y();
+ if (!Fl::has_timeout(highlightScroll, this))
+ Fl::add_timeout(0.01, highlightScroll, this);
}
break;
@@ -294,6 +301,7 @@
break;
case FL_RELEASE:
+ Fl::remove_timeout(highlightScroll);
if (Fl::event_button() == FL_MIDDLE_MOUSE) {
setCursor (core::style::CURSOR_DEFAULT);
} else if (verScrolling) {
@@ -310,10 +318,6 @@
mouse_y = Fl::event_y();
positionChanged();
break;
-
- case FL_LEAVE:
- mouse_x = mouse_y = -1;
- break;
}
return FltkWidgetView::handle (event);
@@ -332,7 +336,8 @@
*/
void FltkViewport::positionChanged ()
{
- if (mouse_x != -1 && dragScrolling == false)
+ if (!dragScrolling && mouse_x >= x() && mouse_x < x()+w() && mouse_y >= y()
+ && mouse_y < y()+h())
(void)theLayout->motionNotify (this,
translateViewXToCanvasX (mouse_x),
translateViewYToCanvasY (mouse_y),
@@ -425,6 +430,25 @@
}
}
+void FltkViewport::highlightScroll (void *data)
+{
+ FltkViewport *viewport = (FltkViewport *)data;
+ int dx = 0, dy = 0;
+
+ if (viewport->mouse_x < viewport->x())
+ dx = -6;
+ else if (viewport->mouse_x >= viewport->x()+viewport->w())
+ dx = 6;
+ if (viewport->mouse_y < viewport->y())
+ dy = -6;
+ else if (viewport->mouse_y >= viewport->y()+viewport->h())
+ dy = 6;
+ viewport->scroll (dx, dy);
+
+ Fl::repeat_timeout(0.01, highlightScroll, data);
+
+}
+
void FltkViewport::setViewportSize (int width, int height,
int hScrollbarThickness,
int vScrollbarThickness)
diff -r c1802a602300 dw/fltkviewport.hh
--- a/dw/fltkviewport.hh Sat Oct 20 01:15:56 2012 +0000
+++ b/dw/fltkviewport.hh Sat Oct 20 08:21:32 2012 +0000
@@ -64,6 +64,7 @@
void scroll(int dx, int dy);
void scroll(dw::core::ScrollCommand cmd);
void scrollTo (int x, int y);
+ static void highlightScroll(void *vport);
void setViewportSize (int width, int height,
int hScrollbarThickness, int vScrollbarThickness);
void setScrollStep(int step);