324 } |
324 } |
325 } |
325 } |
326 |
326 |
327 static bool webframe_scrollOverflow(WebCore::Frame* frame, int dx, int dy, const QPoint& pos) |
327 static bool webframe_scrollOverflow(WebCore::Frame* frame, int dx, int dy, const QPoint& pos) |
328 { |
328 { |
329 if (!frame || !frame->document() || !frame->eventHandler()) |
329 if (!frame || !frame->document() || !frame->view() || !frame->eventHandler()) |
330 return false; |
330 return false; |
331 |
331 |
332 Node* node = frame->document()->elementFromPoint(pos.x(), pos.y()); |
332 QPoint contentsPos = frame->view()->windowToContents(pos); |
|
333 Node* node = frame->document()->elementFromPoint(contentsPos.x(), contentsPos.y()); |
333 if (!node) |
334 if (!node) |
334 return false; |
335 return false; |
335 |
336 |
336 RenderObject* renderer = node->renderer(); |
337 RenderObject* renderer = node->renderer(); |
337 if (!renderer) |
338 if (!renderer) |
1054 to scroll elements with CSS overflow at position pos, followed by this frame. If this |
1055 to scroll elements with CSS overflow at position pos, followed by this frame. If this |
1055 frame doesn't scroll, attempts to scroll the parent |
1056 frame doesn't scroll, attempts to scroll the parent |
1056 */ |
1057 */ |
1057 void QWEBKIT_EXPORT qtwebkit_webframe_scrollRecursively(QWebFrame* qFrame, int dx, int dy, const QPoint& pos) |
1058 void QWEBKIT_EXPORT qtwebkit_webframe_scrollRecursively(QWebFrame* qFrame, int dx, int dy, const QPoint& pos) |
1058 { |
1059 { |
1059 Frame* frame = QWebFramePrivate::core(qFrame); |
1060 if (!qFrame) |
1060 |
|
1061 if (!frame || !frame->view()) |
|
1062 return; |
1061 return; |
1063 |
1062 |
1064 if (!webframe_scrollOverflow(frame, dx, dy, pos)) { |
1063 if (webframe_scrollOverflow(QWebFramePrivate::core(qFrame), dx, dy, pos)) |
1065 do { |
1064 return; |
1066 bool scrolledHorizontal = false; |
1065 |
1067 bool scrolledVertical = false; |
1066 bool scrollHorizontal = false; |
1068 |
1067 bool scrollVertical = false; |
1069 IntSize scrollOffset = frame->view()->scrollOffset(); |
1068 |
1070 IntPoint maxScrollOffset = frame->view()->maximumScrollPosition(); |
1069 do { |
1071 |
1070 if (dx > 0) // scroll right |
1072 if (dx > 0) // scroll right |
1071 scrollHorizontal = qFrame->scrollBarValue(Qt::Horizontal) < qFrame->scrollBarMaximum(Qt::Horizontal); |
1073 scrolledHorizontal = scrollOffset.width() < maxScrollOffset.x(); |
1072 else if (dx < 0) // scroll left |
1074 else if (dx < 0) // scroll left |
1073 scrollHorizontal = qFrame->scrollBarValue(Qt::Horizontal) > qFrame->scrollBarMinimum(Qt::Horizontal); |
1075 scrolledHorizontal = scrollOffset.width() > 0; |
1074 |
1076 |
1075 if (dy > 0) // scroll down |
1077 if (dy > 0) // scroll down |
1076 scrollVertical = qFrame->scrollBarValue(Qt::Vertical) < qFrame->scrollBarMaximum(Qt::Vertical); |
1078 scrolledVertical = scrollOffset.height() < maxScrollOffset.y(); |
|
1079 else if (dy < 0) //scroll up |
1077 else if (dy < 0) //scroll up |
1080 scrolledVertical = scrollOffset.height() > 0; |
1078 scrollVertical = qFrame->scrollBarValue(Qt::Vertical) > qFrame->scrollBarMinimum(Qt::Vertical); |
1081 |
1079 |
1082 if (scrolledHorizontal || scrolledVertical) { |
1080 if (scrollHorizontal || scrollVertical) { |
1083 frame->view()->scrollBy(IntSize(dx, dy)); |
1081 qFrame->scroll(dx, dy); |
1084 return; |
1082 return; |
1085 } |
1083 } |
1086 |
1084 |
1087 frame = frame->tree()->parent(); |
1085 qFrame = qFrame->parentFrame(); |
1088 } while (frame && frame->view()); |
1086 } while (qFrame); |
1089 } |
|
1090 } |
1087 } |
1091 |
1088 |
1092 /*! |
1089 /*! |
1093 \property QWebFrame::scrollPosition |
1090 \property QWebFrame::scrollPosition |
1094 \since 4.5 |
1091 \since 4.5 |