From b090eb7500d9ae2ccda648a395deea1b090dcf72 Mon Sep 17 00:00:00 2001 From: Alp Toker Date: Tue, 30 Oct 2007 12:52:43 +0000 Subject: [PATCH] Frame scrolling and invalidation fixes Make upward scroll events have a positive delta to match other ports. Fix the invalidation rect offset for frames so that scrolling works properly. Avoid allocating negative sizes to widgets to avoid GTK+ warnings. Allow tabbing to all widgets and links. Fix event returns, improving the focus situation and correcting scroll wheel behavior. --- WebCore/page/gtk/EventHandlerGtk.cpp | 15 +++++++++++---- WebCore/platform/gtk/ScrollViewGtk.cpp | 20 ++++++++++++-------- WebCore/platform/gtk/WheelEventGtk.cpp | 25 ++++++++++++++++--------- WebKit/gtk/Api/webkitgtkpage.cpp | 16 +++++----------- WebKit/gtk/WebCoreSupport/ChromeClientGtk.cpp | 3 +-- 5 files changed, 45 insertions(+), 34 deletions(-) diff --git a/WebCore/page/gtk/EventHandlerGtk.cpp b/WebCore/page/gtk/EventHandlerGtk.cpp index ab01471..5f69fe6 100644 --- a/WebCore/page/gtk/EventHandlerGtk.cpp +++ b/WebCore/page/gtk/EventHandlerGtk.cpp @@ -54,7 +54,11 @@ static bool isKeyboardOptionTab(KeyboardEvent* event) bool EventHandler::tabsToAllControls(KeyboardEvent* event) const { - return isKeyboardOptionTab(event); + // Some platforms do not support this key combination + //return isKeyboardOptionTab(event); + + // So we always allow tabs to all controls + return true; } void EventHandler::focusDocumentView() @@ -93,10 +97,13 @@ bool EventHandler::eventActivatedView(const PlatformMouseEvent&) const return false; } -bool EventHandler::passWheelEventToWidget(PlatformWheelEvent&, Widget* widget) +bool EventHandler::passWheelEventToWidget(PlatformWheelEvent& event, Widget* widget) { - notImplemented(); - return false; + ASSERT(widget); + if (!widget->isFrameView()) + return false; + + return static_cast(widget)->frame()->eventHandler()->handleWheelEvent(event); } Clipboard* EventHandler::createDraggingClipboard() const diff --git a/WebCore/platform/gtk/ScrollViewGtk.cpp b/WebCore/platform/gtk/ScrollViewGtk.cpp index 5fded5c..209c08f 100644 --- a/WebCore/platform/gtk/ScrollViewGtk.cpp +++ b/WebCore/platform/gtk/ScrollViewGtk.cpp @@ -126,8 +126,13 @@ void ScrollViewScrollbar::geometryChanged() ASSERT(parent()->isFrameView()); FrameView* frameView = static_cast(parent()); - IntRect windowRect = IntRect(frameView->convertToContainingWindow(frameGeometry().location()), frameGeometry().size()); - GtkAllocation allocation = { windowRect.x(), windowRect.y(), windowRect.width(), windowRect.height() }; + IntPoint loc = frameView->convertToContainingWindow(frameGeometry().location()); + + // Don't allow the allocation size to be negative + IntSize sz = frameGeometry().size(); + sz.clampNegativeToZero(); + + GtkAllocation allocation = { loc.x(), loc.y(), sz.width(), sz.height() }; gtk_widget_size_allocate(gtkWidget(), &allocation); } @@ -292,10 +297,7 @@ void ScrollView::updateContents(const IntRect& updateRect, bool now) IntRect containingWindowRect = updateRect; containingWindowRect.setLocation(windowPoint); - GdkRectangle rect = { containingWindowRect.x(), - containingWindowRect.y(), - containingWindowRect.width(), - containingWindowRect.height() }; + GdkRectangle rect = containingWindowRect; GdkWindow* window = GTK_WIDGET(containingWindow())->window; if (window) @@ -312,7 +314,7 @@ void ScrollView::update() { ASSERT(containingWindow()); - GdkRectangle rect = { 0, 0, m_data->contentsSize.width(), m_data->contentsSize.height() }; + GdkRectangle rect = frameGeometry(); gdk_window_invalidate_rect(GTK_WIDGET(containingWindow())->window, &rect, true); } @@ -505,7 +507,7 @@ void ScrollView::wheelEvent(PlatformWheelEvent& e) (e.deltaY() > 0 && scrollOffset().height() > 0)) e.accept(); - scrollBy(e.deltaX() * LINE_STEP, e.deltaY() * LINE_STEP); + scrollBy(-e.deltaX() * LINE_STEP, -e.deltaY() * LINE_STEP); } void ScrollView::updateScrollbars(const IntSize& desiredOffset) @@ -574,6 +576,7 @@ void ScrollView::updateScrollbars(const IntSize& desiredOffset) m_data->horizontalAdjustment->page_size = visibleWidth(); m_data->horizontalAdjustment->step_increment = visibleWidth() / 10.0; m_data->horizontalAdjustment->page_increment = visibleWidth() * 0.9; + m_data->horizontalAdjustment->lower = 0; m_data->horizontalAdjustment->upper = contentsWidth(); gtk_adjustment_changed(m_data->horizontalAdjustment); @@ -608,6 +611,7 @@ void ScrollView::updateScrollbars(const IntSize& desiredOffset) m_data->verticalAdjustment->page_size = visibleHeight(); m_data->verticalAdjustment->step_increment = visibleHeight() / 10.0; m_data->verticalAdjustment->page_increment = visibleHeight() * 0.9; + m_data->verticalAdjustment->lower = 0; m_data->verticalAdjustment->upper = contentsHeight(); gtk_adjustment_changed(m_data->verticalAdjustment); diff --git a/WebCore/platform/gtk/WheelEventGtk.cpp b/WebCore/platform/gtk/WheelEventGtk.cpp index 6ca981f..f219ad3 100644 --- a/WebCore/platform/gtk/WheelEventGtk.cpp +++ b/WebCore/platform/gtk/WheelEventGtk.cpp @@ -34,19 +34,26 @@ namespace WebCore { PlatformWheelEvent::PlatformWheelEvent(GdkEventScroll* event) { - static const float delta = 0.25f; + static const float delta = 1; m_deltaX = 0; m_deltaY = 0; - if (event->direction == GDK_SCROLL_UP) - m_deltaY = -delta; - else if (event->direction == GDK_SCROLL_LEFT) - m_deltaX = -delta; - else if (event->direction == GDK_SCROLL_RIGHT) - m_deltaX = delta; - else - m_deltaY = delta; + // Docs say an upwards scroll (away from the user) has a positive delta + switch (event->direction) { + case GDK_SCROLL_UP: + m_deltaY = delta; + break; + case GDK_SCROLL_DOWN: + m_deltaY = -delta; + break; + case GDK_SCROLL_LEFT: + m_deltaX = -delta; + break; + case GDK_SCROLL_RIGHT: + m_deltaX = delta; + break; + } m_position = IntPoint((int)event->x, (int)event->y); m_globalPosition = IntPoint((int)event->x_root, (int)event->y_root); diff --git a/WebKit/gtk/Api/webkitgtkpage.cpp b/WebKit/gtk/Api/webkitgtkpage.cpp index c92ef77..b484806 100644 --- a/WebKit/gtk/Api/webkitgtkpage.cpp +++ b/WebKit/gtk/Api/webkitgtkpage.cpp @@ -92,8 +92,7 @@ static gboolean webkit_page_expose_event(GtkWidget* widget, GdkEventExpose* even static gboolean webkit_page_key_event(GtkWidget* widget, GdkEventKey* event) { Frame* frame = core(getFrameFromPage(WEBKIT_PAGE(widget))); - frame->eventHandler()->keyEvent(PlatformKeyboardEvent(event)); - return FALSE; + return frame->eventHandler()->keyEvent(PlatformKeyboardEvent(event)); } static gboolean webkit_page_button_event(GtkWidget* widget, GdkEventButton* event) @@ -101,22 +100,18 @@ static gboolean webkit_page_button_event(GtkWidget* widget, GdkEventButton* even Frame* frame = core(getFrameFromPage(WEBKIT_PAGE(widget))); if (event->type == GDK_BUTTON_RELEASE) - frame->eventHandler()->handleMouseReleaseEvent(PlatformMouseEvent(event)); + return frame->eventHandler()->handleMouseReleaseEvent(PlatformMouseEvent(event)); else { - frame->eventHandler()->handleMousePressEvent(PlatformMouseEvent(event)); - //FIXME need to keep track of subframe focus for key events! gtk_widget_grab_focus(GTK_WIDGET(widget)); + return frame->eventHandler()->handleMousePressEvent(PlatformMouseEvent(event)); } - - return FALSE; } static gboolean webkit_page_motion_event(GtkWidget* widget, GdkEventMotion* event) { Frame* frame = core(getFrameFromPage(WEBKIT_PAGE(widget))); - frame->eventHandler()->mouseMoved(PlatformMouseEvent(event)); - return FALSE; + return frame->eventHandler()->mouseMoved(PlatformMouseEvent(event)); } static gboolean webkit_page_scroll_event(GtkWidget* widget, GdkEventScroll* event) @@ -124,8 +119,7 @@ static gboolean webkit_page_scroll_event(GtkWidget* widget, GdkEventScroll* even Frame* frame = core(getFrameFromPage(WEBKIT_PAGE(widget))); PlatformWheelEvent wheelEvent(event); - frame->eventHandler()->handleWheelEvent(wheelEvent); - return FALSE; + return frame->eventHandler()->handleWheelEvent(wheelEvent); } static void webkit_page_size_allocate(GtkWidget* widget, GtkAllocation* allocation) diff --git a/WebKit/gtk/WebCoreSupport/ChromeClientGtk.cpp b/WebKit/gtk/WebCoreSupport/ChromeClientGtk.cpp index b922b8a..2a7e583 100644 --- a/WebKit/gtk/WebCoreSupport/ChromeClientGtk.cpp +++ b/WebKit/gtk/WebCoreSupport/ChromeClientGtk.cpp @@ -245,8 +245,7 @@ bool ChromeClient::shouldInterruptJavaScript() bool ChromeClient::tabsToLinks() const { - notImplemented(); - return false; + return true; } IntRect ChromeClient::windowResizerRect() const -- 1.5.3.4.395.g85b0