diff options
Diffstat (limited to 'WebCore/platform/gtk/ScrollbarGtk.cpp')
-rw-r--r-- | WebCore/platform/gtk/ScrollbarGtk.cpp | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/WebCore/platform/gtk/ScrollbarGtk.cpp b/WebCore/platform/gtk/ScrollbarGtk.cpp index 7543e23..d7f6d26 100644 --- a/WebCore/platform/gtk/ScrollbarGtk.cpp +++ b/WebCore/platform/gtk/ScrollbarGtk.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007 Holger Hans Peter Freyther zecke@selfish.org + * Copyright (C) 2007, 2009 Holger Hans Peter Freyther zecke@selfish.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -22,7 +22,6 @@ #include "IntRect.h" #include "GraphicsContext.h" #include "FrameView.h" -#include "NotImplemented.h" #include "ScrollbarTheme.h" #include "gtkdrawing.h" @@ -35,6 +34,11 @@ PassRefPtr<Scrollbar> Scrollbar::createNativeScrollbar(ScrollbarClient* client, return adoptRef(new ScrollbarGtk(client, orientation, size)); } +PassRefPtr<ScrollbarGtk> ScrollbarGtk::createScrollbar(ScrollbarClient* client, ScrollbarOrientation orientation, GtkAdjustment* adj) +{ + return adoptRef(new ScrollbarGtk(client, orientation, adj)); +} + static gboolean gtkScrollEventCallback(GtkWidget* widget, GdkEventScroll* event, ScrollbarGtk*) { /* Scroll only if our parent rejects the scroll event. The rationale for @@ -52,7 +56,8 @@ ScrollbarGtk::ScrollbarGtk(ScrollbarClient* client, ScrollbarOrientation orienta gtk_hscrollbar_new(m_adjustment): gtk_vscrollbar_new(m_adjustment); gtk_widget_show(scrollBar); - g_signal_connect(scrollBar, "value-changed", G_CALLBACK(ScrollbarGtk::gtkValueChanged), this); + g_object_ref(m_adjustment); + g_signal_connect(m_adjustment, "value-changed", G_CALLBACK(ScrollbarGtk::gtkValueChanged), this); g_signal_connect(scrollBar, "scroll-event", G_CALLBACK(gtkScrollEventCallback), this); setPlatformWidget(scrollBar); @@ -65,6 +70,37 @@ ScrollbarGtk::ScrollbarGtk(ScrollbarClient* client, ScrollbarOrientation orienta ScrollbarTheme::nativeTheme()->scrollbarThickness()); } +// Create a ScrollbarGtk on top of an existing GtkAdjustment but do not create a +// GtkScrollbar on top of this adjustment. The goal is to have a WebCore::Scrollbar +// that will manipulate the GtkAdjustment properties, will react to the changed +// value but will not consume any space on the screen and will not be painted +// at all. It is achieved by not calling setPlatformWidget. +ScrollbarGtk::ScrollbarGtk(ScrollbarClient* client, ScrollbarOrientation orientation, GtkAdjustment* adjustment) + : Scrollbar(client, orientation, RegularScrollbar) + , m_adjustment(adjustment) +{ + g_object_ref(m_adjustment); + g_signal_connect(m_adjustment, "value-changed", G_CALLBACK(ScrollbarGtk::gtkValueChanged), this); + + // We have nothing to show as we are solely operating on the GtkAdjustment + resize(0, 0); +} + +ScrollbarGtk::~ScrollbarGtk() +{ + g_signal_handlers_disconnect_by_func(G_OBJECT(m_adjustment), (gpointer)ScrollbarGtk::gtkValueChanged, this); + + // For the case where we only operate on the GtkAdjustment it is best to + // reset the values so that the surrounding scrollbar gets updated, or + // e.g. for a GtkScrolledWindow the scrollbar gets hidden. + m_adjustment->lower = 0; + m_adjustment->upper = 0; + m_adjustment->value = 0; + gtk_adjustment_changed(m_adjustment); + gtk_adjustment_value_changed(m_adjustment); + g_object_unref(m_adjustment); +} + IntPoint ScrollbarGtk::getLocationInParentWindow(const IntRect& rect) { IntPoint loc; @@ -79,7 +115,7 @@ IntPoint ScrollbarGtk::getLocationInParentWindow(const IntRect& rect) void ScrollbarGtk::frameRectsChanged() { - if (!parent()) + if (!parent() || !platformWidget()) return; IntPoint loc = getLocationInParentWindow(frameRect()); |