2006-03-10 Eric Seidel <eseidel@apple.com>
authoreseidel <eseidel@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Mar 2006 07:05:29 +0000 (07:05 +0000)
committereseidel <eseidel@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Mar 2006 07:05:29 +0000 (07:05 +0000)
        Reviewed by hyatt.

        Add scrolling support into Spinneret.

        * Spinneret/Spinneret/WebFrame.cpp:
        (WebKit::WebFrame::paint):
        * Spinneret/Spinneret/WebView.cpp:
        (WebKit::WebView::createWebView):
        (WebKit::calculateScrollDelta):
        (WebKit::scrollMessageForKey):
        (WebKit::WebViewWndProc):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@13280 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKitTools/ChangeLog
WebKitTools/Spinneret/Spinneret/WebFrame.cpp
WebKitTools/Spinneret/Spinneret/WebView.cpp

index b99bd0aace20207928ea6a698f693b9c5f18bcfd..a3e9fa0451e2094fa280f89d6d9c6678d5401f56 100644 (file)
@@ -1,3 +1,17 @@
+2006-03-10  Eric Seidel  <eseidel@apple.com>
+
+        Reviewed by hyatt.
+
+        Add scrolling support into Spinneret.
+
+        * Spinneret/Spinneret/WebFrame.cpp:
+        (WebKit::WebFrame::paint):
+        * Spinneret/Spinneret/WebView.cpp:
+        (WebKit::WebView::createWebView):
+        (WebKit::calculateScrollDelta):
+        (WebKit::scrollMessageForKey):
+        (WebKit::WebViewWndProc):
+
 2006-03-13  Eric Seidel  <eseidel@apple.com>
 
         Reviewed by mjs.
index 635a8857be35f5c22fe03f4752443151c4ace722..617aedb996de566b69420d8d47b92c558713650e 100755 (executable)
@@ -140,7 +140,16 @@ void WebFrame::paint()
     cairo_t* context = cairo_create(surface);
     GraphicsContext gc(context);
     
-    d->frame->paint(&gc, ps.rcPaint);
+    IntRect documentDirtyRect = ps.rcPaint;
+    documentDirtyRect.move(d->frameView->contentsX(), d->frameView->contentsY());
+
+    // FIXME: We have to set the transform using both cairo and GDI until we use cairo for text.
+    HDC surfaceDC = cairo_win32_surface_get_dc(surface);
+    SaveDC(surfaceDC);
+    OffsetViewportOrgEx(surfaceDC, -d->frameView->contentsX(), -d->frameView->contentsY(), 0);
+    cairo_translate(context, -d->frameView->contentsX(), -d->frameView->contentsY());
+    d->frame->paint(&gc, documentDirtyRect);
+    RestoreDC(surfaceDC, -1);
 
     cairo_destroy(context);
     context = cairo_create(finalSurface);
index 39711cf3b2ea1560b29d46057e0f947aaee2bfd9..8d05951afea20ed2769af4c13ad18544670fb902 100755 (executable)
@@ -87,7 +87,7 @@ WebView* WebView::createWebView(HINSTANCE hInstance, HWND parent)
 
     registerWebViewWithInstance(hInstance);
 
-    HWND hWnd = CreateWindow(kWebViewWindowClassName, 0, WS_CHILD,
+    HWND hWnd = CreateWindow(kWebViewWindowClassName, 0, WS_CHILD | WS_HSCROLL | WS_VSCROLL,
        CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, parent, 0, hInstance, 0);
 
     if (!hWnd)
@@ -145,6 +145,44 @@ void WebView::mouseDoubleClick(HWND hWnd, WPARAM wParam, LPARAM lParam)
     d->mainFrame->viewImpl()->viewportMouseReleaseEvent(&mouseEvent);
 }
 
+#define LINE_SCROLL_SIZE 30
+
+static int calculateScrollDelta(WPARAM wParam, int oldPosition, int pageSize)
+{
+    switch (LOWORD(wParam)) {
+        case SB_PAGEUP: 
+            return -(pageSize - LINE_SCROLL_SIZE); 
+         case SB_PAGEDOWN: 
+            return (pageSize - LINE_SCROLL_SIZE); 
+        case SB_LINEUP: 
+            return -LINE_SCROLL_SIZE;
+        case SB_LINEDOWN: 
+            return LINE_SCROLL_SIZE;
+        case SB_THUMBPOSITION: 
+            return HIWORD(wParam) - oldPosition; 
+    }
+    return 0;
+}
+
+static int scrollMessageForKey(WPARAM keyCode)
+{
+    switch (keyCode) {
+    case VK_UP:
+        return SB_LINEUP;
+    case VK_PRIOR: 
+        return SB_PAGEUP;
+    case VK_NEXT:
+        return SB_PAGEDOWN;
+    case VK_DOWN:
+        return SB_LINEDOWN;
+    case VK_HOME:
+        return SB_TOP;
+    case VK_END:
+        return SB_BOTTOM;
+    }
+    return -1;
+}
+
 LRESULT CALLBACK WebViewWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 {
     int wmId, wmEvent;
@@ -175,8 +213,22 @@ LRESULT CALLBACK WebViewWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM l
     case WM_RBUTTONDBLCLK:
         webview->mouseDoubleClick(hWnd, wParam, lParam);
         break;
-    case WM_SIZE:
-        // FIXME: not sure if we need anything here...
+    case WM_HSCROLL: {
+        ScrollView* view = webview->mainFrame()->impl()->view();
+        view->scrollBy(calculateScrollDelta(wParam, view->contentsX(), view->visibleWidth()), 0);
+        break;
+    }
+    case WM_VSCROLL: {
+        ScrollView* view = webview->mainFrame()->impl()->view();
+        view->scrollBy(0, calculateScrollDelta(wParam, view->contentsY(), view->visibleHeight()));
+        break;
+    }
+    case WM_KEYDOWN: {
+        WORD wScrollNotify = scrollMessageForKey(wParam);
+        if (wScrollNotify != -1)
+            SendMessage(hWnd, WM_VSCROLL, MAKELONG(wScrollNotify, 0), 0L);
+        break;
+    }
     default:
         return DefWindowProc(hWnd, message, wParam, lParam);
     }