diff options
Diffstat (limited to 'Source/WebKit2/UIProcess/win/WebView.cpp')
-rw-r--r-- | Source/WebKit2/UIProcess/win/WebView.cpp | 159 |
1 files changed, 156 insertions, 3 deletions
diff --git a/Source/WebKit2/UIProcess/win/WebView.cpp b/Source/WebKit2/UIProcess/win/WebView.cpp index 62e0c42..1447864 100644 --- a/Source/WebKit2/UIProcess/win/WebView.cpp +++ b/Source/WebKit2/UIProcess/win/WebView.cpp @@ -44,7 +44,9 @@ #include <WebCore/BitmapInfo.h> #include <WebCore/Cursor.h> #include <WebCore/FloatRect.h> +#if PLATFORM(CG) #include <WebCore/GraphicsContextCG.h> +#endif #include <WebCore/IntRect.h> #include <WebCore/SoftLinking.h> #include <WebCore/WebCoreInstanceHandle.h> @@ -149,6 +151,12 @@ LRESULT WebView::wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) case WM_VISTA_MOUSEHWHEEL: lResult = onWheelEvent(hWnd, message, wParam, lParam, handled); break; + case WM_HSCROLL: + lResult = onHorizontalScroll(hWnd, message, wParam, lParam, handled); + break; + case WM_VSCROLL: + lResult = onVerticalScroll(hWnd, message, wParam, lParam, handled); + break; case WM_SYSKEYDOWN: case WM_KEYDOWN: case WM_SYSCHAR: @@ -280,6 +288,20 @@ WebView::~WebView() void WebView::initialize() { ::RegisterDragDrop(m_window, this); + + if (shouldInitializeTrackPointHack()) { + // If we detected a registry key belonging to a TrackPoint driver, then create fake + // scrollbars, so the WebView will receive WM_VSCROLL and WM_HSCROLL messages. + // We create an invisible vertical scrollbar and an invisible horizontal scrollbar to allow + // for receiving both types of messages. + ::CreateWindow(TEXT("SCROLLBAR"), TEXT("FAKETRACKPOINTHSCROLLBAR"), WS_CHILD | WS_VISIBLE | SBS_HORZ, 0, 0, 0, 0, m_window, 0, instanceHandle(), 0); + ::CreateWindow(TEXT("SCROLLBAR"), TEXT("FAKETRACKPOINTVSCROLLBAR"), WS_CHILD | WS_VISIBLE | SBS_VERT, 0, 0, 0, 0, m_window, 0, instanceHandle(), 0); + } +} + +void WebView::initializeUndoClient(const WKViewUndoClient* client) +{ + m_undoClient.initialize(client); } void WebView::setParentWindow(HWND parentWindow) @@ -394,6 +416,70 @@ LRESULT WebView::onWheelEvent(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa return 0; } +LRESULT WebView::onHorizontalScroll(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, bool& handled) +{ + ScrollDirection direction; + ScrollGranularity granularity; + switch (LOWORD(wParam)) { + case SB_LINELEFT: + granularity = ScrollByLine; + direction = ScrollLeft; + break; + case SB_LINERIGHT: + granularity = ScrollByLine; + direction = ScrollRight; + break; + case SB_PAGELEFT: + granularity = ScrollByDocument; + direction = ScrollLeft; + break; + case SB_PAGERIGHT: + granularity = ScrollByDocument; + direction = ScrollRight; + break; + default: + handled = false; + return 0; + } + + m_page->scrollBy(direction, granularity); + + handled = true; + return 0; +} + +LRESULT WebView::onVerticalScroll(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, bool& handled) +{ + ScrollDirection direction; + ScrollGranularity granularity; + switch (LOWORD(wParam)) { + case SB_LINEDOWN: + granularity = ScrollByLine; + direction = ScrollDown; + break; + case SB_LINEUP: + granularity = ScrollByLine; + direction = ScrollUp; + break; + case SB_PAGEDOWN: + granularity = ScrollByDocument; + direction = ScrollDown; + break; + case SB_PAGEUP: + granularity = ScrollByDocument; + direction = ScrollUp; + break; + default: + handled = false; + return 0; + } + + m_page->scrollBy(direction, granularity); + + handled = true; + return 0; +} + LRESULT WebView::onKeyEvent(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, bool& handled) { m_page->handleKeyboardEvent(NativeWebKeyboardEvent(hWnd, message, wParam, lParam)); @@ -490,8 +576,10 @@ LRESULT WebView::onSizeEvent(HWND, UINT, WPARAM, LPARAM lParam, bool& handled) int width = LOWORD(lParam); int height = HIWORD(lParam); - if (m_page && m_page->drawingArea()) - m_page->drawingArea()->setSize(IntSize(width, height), IntSize()); + if (m_page && m_page->drawingArea()) { + m_page->drawingArea()->setSize(IntSize(width, height), m_nextResizeScrollOffset); + m_nextResizeScrollOffset = IntSize(); + } handled = true; return 0; @@ -638,8 +726,39 @@ void WebView::stopTrackingMouseLeave() ::TrackMouseEvent(&trackMouseEvent); } +bool WebView::shouldInitializeTrackPointHack() +{ + static bool shouldCreateScrollbars; + static bool hasRunTrackPointCheck; + + if (hasRunTrackPointCheck) + return shouldCreateScrollbars; + + hasRunTrackPointCheck = true; + const wchar_t* trackPointKeys[] = { + L"Software\\Lenovo\\TrackPoint", + L"Software\\Lenovo\\UltraNav", + L"Software\\Alps\\Apoint\\TrackPoint", + L"Software\\Synaptics\\SynTPEnh\\UltraNavUSB", + L"Software\\Synaptics\\SynTPEnh\\UltraNavPS2" + }; + + for (size_t i = 0; i < WTF_ARRAY_LENGTH(trackPointKeys); ++i) { + HKEY trackPointKey; + int readKeyResult = ::RegOpenKeyExW(HKEY_CURRENT_USER, trackPointKeys[i], 0, KEY_READ, &trackPointKey); + ::RegCloseKey(trackPointKey); + if (readKeyResult == ERROR_SUCCESS) { + shouldCreateScrollbars = true; + return shouldCreateScrollbars; + } + } + + return shouldCreateScrollbars; +} + void WebView::close() { + m_undoClient.initialize(0); ::RevokeDragDrop(m_window); setParentWindow(0); m_page->close(); @@ -789,16 +908,41 @@ void WebView::setInitialFocus(bool forward) m_page->setInitialFocus(forward); } +void WebView::setScrollOffsetOnNextResize(const IntSize& scrollOffset) +{ + // The next time we get a WM_SIZE message, scroll by the specified amount in onSizeEvent(). + m_nextResizeScrollOffset = scrollOffset; +} + void WebView::setViewportArguments(const WebCore::ViewportArguments&) { } -void WebView::registerEditCommand(PassRefPtr<WebEditCommandProxy>, WebPageProxy::UndoOrRedo) +void WebView::registerEditCommand(PassRefPtr<WebEditCommandProxy> prpCommand, WebPageProxy::UndoOrRedo undoOrRedo) { + RefPtr<WebEditCommandProxy> command = prpCommand; + m_undoClient.registerEditCommand(this, command, undoOrRedo); } void WebView::clearAllEditCommands() { + m_undoClient.clearAllEditCommands(this); +} + +void WebView::reapplyEditCommand(WebEditCommandProxy* command) +{ + if (!m_page->isValid() || !m_page->isValidEditCommand(command)) + return; + + command->reapply(); +} + +void WebView::unapplyEditCommand(WebEditCommandProxy* command) +{ + if (!m_page->isValid() || !m_page->isValidEditCommand(command)) + return; + + command->unapply(); } FloatRect WebView::convertToDeviceSpace(const FloatRect& rect) @@ -806,6 +950,11 @@ FloatRect WebView::convertToDeviceSpace(const FloatRect& rect) return rect; } +IntRect WebView::windowToScreen(const IntRect& rect) +{ + return rect; +} + FloatRect WebView::convertToUserSpace(const FloatRect& rect) { return rect; @@ -1105,11 +1254,15 @@ void WebView::setFindIndicator(PassRefPtr<FindIndicator> prpFindIndicator, bool hbmp = CreateDIBSection(0, &bitmapInfo, DIB_RGB_COLORS, static_cast<void**>(&bits), 0, 0); HBITMAP hbmpOld = static_cast<HBITMAP>(SelectObject(hdc, hbmp)); +#if PLATFORM(CG) RetainPtr<CGContextRef> context(AdoptCF, CGBitmapContextCreate(bits, width, height, 8, width * sizeof(RGBQUAD), deviceRGBColorSpaceRef(), kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst)); GraphicsContext graphicsContext(context.get()); contentImage->paint(graphicsContext, IntPoint(), contentImage->bounds()); +#else + // FIXME: Implement! +#endif ::SelectObject(hdc, hbmpOld); ::DeleteDC(hdc); |