Commit c6c1079a authored by mrobinson@webkit.org's avatar mrobinson@webkit.org
Browse files

2010-09-06 Martin Robinson <mrobinson@igalia.com>

        Reviewed by Gustavo Noronha Silva.

        [GTK] ScrollbarThemeGtk should be enabled for interior frame scrollbars
        https://bugs.webkit.org/show_bug.cgi?id=45046

        Make interior frame scrollbars "fully-fake," which means they do not rely
        at all on GTK+ for painting or behavior, but instead are typical WebCore
        scrollbars drawn according to the GTK+ theme. Move ScrollbarGtk to
        MainFrameScrollbarGtk and remove all logic in that file dealing with interior
        frame scrollbars.

        No new tests, as this is already covered by pixel tests for scrollbars,
        which were added in r66605.

        * GNUmakefile.am: Update sources list.
        * platform/ScrollView.h: Change the adjustment members to be smart pointers.
        * platform/Scrollbar.cpp: Enable THUMB_POSITION_AFFECTS_BUTTONS for GTK+ as well.
        * platform/gtk/MainFrameScrollbarGtk.cpp: Added.
        (MainFrameScrollbarGtk::create): Create a MainFrameScrollbarGtk instead of ScrollbarGtk.
        (MainFrameScrollbarGtk::MainFrameScrollbarGtk):
        (MainFrameScrollbarGtk::~MainFrameScrollbarGtk):
        (MainFrameScrollbarGtk::attachAdjustment):
        (MainFrameScrollbarGtk::detachAdjustment):
        (MainFrameScrollbarGtk::updateThumbPosition):
        (MainFrameScrollbarGtk::updateThumbProportion):
        (MainFrameScrollbarGtk::gtkValueChanged):
        (MainFrameScrollbarGtk::paint):
        * platform/gtk/MainFrameScrollbarGtk.h: Added.
        * platform/gtk/ScrollViewGtk.cpp:
        (WebCore::ScrollView::platformInit): Remove unnecessary initialization
        because of smart pointer change.
        (WebCore::ScrollView::createScrollbar): Instead of creating ScrollbarGtk for
        interior frame scrollbars, create a normal WebCore scrollbar.
        (WebCore::ScrollView::setGtkAdjustments): Added an extra assert which ensures
        that this method is never called with a non-null adjustment on an interior frame
        scrollbar.
        (WebCore::ScrollView::platformAddChild): Remove logic for interior frame scrollbars.
        (WebCore::ScrollView::platformRemoveChild): Remove logic for interior frame scrollbars.
        (WebCore::ScrollView::visibleContentRect): Use a more accurate guard for detecting
        transitionary states when accessing parent widgets. Explcitly guard against interior
        frame ScrollView's trying to determine size based on parent widgets.
        (WebCore::ScrollView::setScrollbarModes): This method was out of sync with the one
        it copy-and-pasted from. Update it and change the logic to do the right thing for
        interior frame scrollbars.
        * platform/gtk/ScrollbarGtk.cpp: Removed.
        * platform/gtk/ScrollbarGtk.h: Removed.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@66848 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 32370f5c
2010-09-06 Martin Robinson <mrobinson@igalia.com>
Reviewed by Gustavo Noronha Silva.
[GTK] ScrollbarThemeGtk should be enabled for interior frame scrollbars
https://bugs.webkit.org/show_bug.cgi?id=45046
Make interior frame scrollbars "fully-fake," which means they do not rely
at all on GTK+ for painting or behavior, but instead are typical WebCore
scrollbars drawn according to the GTK+ theme. Move ScrollbarGtk to
MainFrameScrollbarGtk and remove all logic in that file dealing with interior
frame scrollbars.
No new tests, as this is already covered by pixel tests for scrollbars,
which were added in r66605.
* GNUmakefile.am: Update sources list.
* platform/ScrollView.h: Change the adjustment members to be smart pointers.
* platform/Scrollbar.cpp: Enable THUMB_POSITION_AFFECTS_BUTTONS for GTK+ as well.
* platform/gtk/MainFrameScrollbarGtk.cpp: Added.
(MainFrameScrollbarGtk::create): Create a MainFrameScrollbarGtk instead of ScrollbarGtk.
(MainFrameScrollbarGtk::MainFrameScrollbarGtk):
(MainFrameScrollbarGtk::~MainFrameScrollbarGtk):
(MainFrameScrollbarGtk::attachAdjustment):
(MainFrameScrollbarGtk::detachAdjustment):
(MainFrameScrollbarGtk::updateThumbPosition):
(MainFrameScrollbarGtk::updateThumbProportion):
(MainFrameScrollbarGtk::gtkValueChanged):
(MainFrameScrollbarGtk::paint):
* platform/gtk/MainFrameScrollbarGtk.h: Added.
* platform/gtk/ScrollViewGtk.cpp:
(WebCore::ScrollView::platformInit): Remove unnecessary initialization
because of smart pointer change.
(WebCore::ScrollView::createScrollbar): Instead of creating ScrollbarGtk for
interior frame scrollbars, create a normal WebCore scrollbar.
(WebCore::ScrollView::setGtkAdjustments): Added an extra assert which ensures
that this method is never called with a non-null adjustment on an interior frame
scrollbar.
(WebCore::ScrollView::platformAddChild): Remove logic for interior frame scrollbars.
(WebCore::ScrollView::platformRemoveChild): Remove logic for interior frame scrollbars.
(WebCore::ScrollView::visibleContentRect): Use a more accurate guard for detecting
transitionary states when accessing parent widgets. Explcitly guard against interior
frame ScrollView's trying to determine size based on parent widgets.
(WebCore::ScrollView::setScrollbarModes): This method was out of sync with the one
it copy-and-pasted from. Update it and change the logic to do the right thing for
interior frame scrollbars.
* platform/gtk/ScrollbarGtk.cpp: Removed.
* platform/gtk/ScrollbarGtk.h: Removed.
2010-09-06 Justin Schuh <jschuh@chromium.org>
 
Reviewed by Nikolas Zimmermann.
......@@ -2503,6 +2503,8 @@ webcoregtk_sources += \
WebCore/platform/gtk/Language.cpp \
WebCore/platform/gtk/LocalizedStringsGtk.cpp \
WebCore/platform/gtk/LoggingGtk.cpp \
WebCore/platform/gtk/MainFrameScrollbarGtk.cpp \
WebCore/platform/gtk/MainFrameScrollbarGtk.h \
WebCore/platform/gtk/MIMETypeRegistryGtk.cpp \
WebCore/platform/gtk/MouseEventGtk.cpp \
WebCore/platform/gtk/PasteboardGtk.cpp \
......@@ -2513,8 +2515,6 @@ webcoregtk_sources += \
WebCore/platform/gtk/PopupMenuGtk.h \
WebCore/platform/gtk/RenderThemeGtk.cpp \
WebCore/platform/gtk/RenderThemeGtk.h \
WebCore/platform/gtk/ScrollbarGtk.cpp \
WebCore/platform/gtk/ScrollbarGtk.h \
WebCore/platform/gtk/ScrollbarThemeGtk.cpp \
WebCore/platform/gtk/ScrollbarThemeGtk.h \
WebCore/platform/gtk/ScrollViewGtk.cpp \
......
......@@ -40,6 +40,7 @@
#endif
#if PLATFORM(GTK)
#include "GRefPtrGtk.h"
typedef struct _GtkAdjustment GtkAdjustment;
#endif
......@@ -333,9 +334,11 @@ private:
#if PLATFORM(GTK)
public:
void setGtkAdjustments(GtkAdjustment* hadj, GtkAdjustment* vadj, bool resetValues = true);
GtkAdjustment* m_horizontalAdjustment;
GtkAdjustment* m_verticalAdjustment;
void setScrollOffset(const IntSize& offset) { m_scrollOffset = offset; }
private:
PlatformRefPtr<GtkAdjustment> m_horizontalAdjustment;
PlatformRefPtr<GtkAdjustment> m_verticalAdjustment;
#endif
#if PLATFORM(WX)
......
......@@ -40,7 +40,7 @@
using namespace std;
#if PLATFORM(CHROMIUM) && OS(LINUX)
#if PLATFORM(CHROMIUM) && OS(LINUX) || PLATFORM(GTK)
// The position of the scrollbar thumb affects the appearance of the steppers, so
// when the thumb moves, we have to invalidate them for painting.
#define THUMB_POSITION_AFFECTS_BUTTONS
......@@ -48,7 +48,7 @@ using namespace std;
namespace WebCore {
#if !PLATFORM(GTK) && !PLATFORM(EFL)
#if !PLATFORM(EFL)
PassRefPtr<Scrollbar> Scrollbar::createNativeScrollbar(ScrollbarClient* client, ScrollbarOrientation orientation, ScrollbarControlSize size)
{
return adoptRef(new Scrollbar(client, orientation, size));
......
/*
* Copyright (C) 2007, 2009 Holger Hans Peter Freyther zecke@selfish.org
* Copyright (C) 2010 Gustavo Noronha Silva <gns@gnome.org>
* Copyright (C) 2010 Collabora Ltd.
* Copyright (C) 2010 Igalia S.L.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "config.h"
#include "MainFrameScrollbarGtk.h"
#include "GraphicsContext.h"
#include "GtkVersioning.h"
#include "IntRect.h"
#include <gtk/gtk.h>
using namespace WebCore;
PassRefPtr<MainFrameScrollbarGtk> MainFrameScrollbarGtk::create(ScrollbarClient* client, ScrollbarOrientation orientation, GtkAdjustment* adj)
{
return adoptRef(new MainFrameScrollbarGtk(client, orientation, adj));
}
// Main frame scrollbars are slaves to a GtkAdjustment. If a main frame
// scrollbar has an m_adjustment, it belongs to the container (a GtkWidget such
// as GtkScrolledWindow). The adjustment may also be null, in which case there
// is no containing view or the parent ScrollView is in some sort of transition
// state. These scrollbars are never painted, as the container takes care of
// that. They exist only to shuttle data from the GtkWidget container into
// WebCore and vice-versa.
MainFrameScrollbarGtk::MainFrameScrollbarGtk(ScrollbarClient* client, ScrollbarOrientation orientation, GtkAdjustment* adjustment)
: Scrollbar(client, orientation, RegularScrollbar)
, m_adjustment(0)
{
attachAdjustment(adjustment);
// We have nothing to show as we are solely operating on the GtkAdjustment.
resize(0, 0);
}
MainFrameScrollbarGtk::~MainFrameScrollbarGtk()
{
if (m_adjustment)
detachAdjustment();
}
void MainFrameScrollbarGtk::attachAdjustment(GtkAdjustment* adjustment)
{
if (m_adjustment)
detachAdjustment();
m_adjustment = adjustment;
if (!m_adjustment)
return;
g_signal_connect(m_adjustment.get(), "value-changed", G_CALLBACK(MainFrameScrollbarGtk::gtkValueChanged), this);
updateThumbProportion();
updateThumbPosition();
}
void MainFrameScrollbarGtk::detachAdjustment()
{
if (!m_adjustment)
return;
g_signal_handlers_disconnect_by_func(G_OBJECT(m_adjustment.get()), (gpointer)MainFrameScrollbarGtk::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.
gtk_adjustment_configure(m_adjustment.get(), 0, 0, 0, 0, 0, 0);
m_adjustment = 0;
}
void MainFrameScrollbarGtk::updateThumbPosition()
{
if (!m_adjustment || gtk_adjustment_get_value(m_adjustment.get()) == m_currentPos)
return;
gtk_adjustment_set_value(m_adjustment.get(), m_currentPos);
}
void MainFrameScrollbarGtk::updateThumbProportion()
{
if (!m_adjustment)
return;
gtk_adjustment_configure(m_adjustment.get(),
gtk_adjustment_get_value(m_adjustment.get()),
gtk_adjustment_get_lower(m_adjustment.get()),
m_totalSize,
m_lineStep,
m_pageStep,
m_visibleSize);
}
void MainFrameScrollbarGtk::gtkValueChanged(GtkAdjustment*, MainFrameScrollbarGtk* that)
{
that->setValue(static_cast<int>(gtk_adjustment_get_value(that->m_adjustment.get())));
}
void MainFrameScrollbarGtk::paint(GraphicsContext* context, const IntRect& rect)
{
// Main frame scrollbars are not painted by WebCore.
return;
}
/*
* Copyright (C) 2010 Igalia S.L.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef MainFrameScrollbarGtk_h
#define MainFrameScrollbarGtk_h
#include "GRefPtrGtk.h"
#include "Scrollbar.h"
#include <wtf/PassRefPtr.h>
typedef struct _GtkAdjustment GtkAdjustment;
namespace WebCore {
class MainFrameScrollbarGtk : public Scrollbar {
public:
~MainFrameScrollbarGtk();
virtual void paint(GraphicsContext*, const IntRect&);
void detachAdjustment();
void attachAdjustment(GtkAdjustment*);
static PassRefPtr<MainFrameScrollbarGtk> create(ScrollbarClient*, ScrollbarOrientation, GtkAdjustment*);
protected:
virtual void updateThumbPosition();
virtual void updateThumbProportion();
private:
MainFrameScrollbarGtk(ScrollbarClient*, ScrollbarOrientation, GtkAdjustment*);
static void gtkValueChanged(GtkAdjustment*, MainFrameScrollbarGtk*);
PlatformRefPtr<GtkAdjustment> m_adjustment;
};
}
#endif // ScrollbarGtk_h
......@@ -39,10 +39,10 @@
#include "GtkVersioning.h"
#include "HostWindow.h"
#include "IntRect.h"
#include "MainFrameScrollbarGtk.h"
#include "Page.h"
#include "PlatformMouseEvent.h"
#include "PlatformWheelEvent.h"
#include "ScrollbarGtk.h"
#include "ScrollbarTheme.h"
#include <gtk/gtk.h>
......@@ -53,8 +53,6 @@ namespace WebCore {
void ScrollView::platformInit()
{
m_horizontalAdjustment = 0;
m_verticalAdjustment = 0;
}
void ScrollView::platformDestroy()
......@@ -65,9 +63,8 @@ void ScrollView::platformDestroy()
PassRefPtr<Scrollbar> ScrollView::createScrollbar(ScrollbarOrientation orientation)
{
// If this is an interior frame scrollbar, we want to create a scrollbar without
// passing a GtkAdjustment. This will cause the Scrollbar to create a native GTK+
// scrollbar.
// If this is an interior frame scrollbar, we want to create a totally fake
// scrollbar with no GtkAdjustment backing it.
if (parent())
return Scrollbar::createNativeScrollbar(this, orientation, RegularScrollbar);
......@@ -75,10 +72,10 @@ PassRefPtr<Scrollbar> ScrollView::createScrollbar(ScrollbarOrientation orientati
// and defers to our GtkAdjustment for all of its state. Note that the GtkAdjustment
// may be null here.
if (orientation == HorizontalScrollbar)
return ScrollbarGtk::createScrollbar(this, orientation, m_horizontalAdjustment);
return MainFrameScrollbarGtk::create(this, orientation, m_horizontalAdjustment.get());
// VerticalScrollbar
return ScrollbarGtk::createScrollbar(this, orientation, m_verticalAdjustment);
return MainFrameScrollbarGtk::create(this, orientation, m_verticalAdjustment.get());
}
/*
......@@ -89,15 +86,21 @@ void ScrollView::setGtkAdjustments(GtkAdjustment* hadj, GtkAdjustment* vadj, boo
{
ASSERT(!hadj == !vadj);
// If this is a non-main frame ScrollView, we do not want to set the
// m_horizontalAdjustments & m_verticalAdjustments members. At the same
// time we want to to allow FrameLoaderClientGtk.cpp to call
// ScrollView::setGtkAdjustments(0, 0) unconditionally.
ASSERT(!parent() || !hadj);
m_horizontalAdjustment = hadj;
m_verticalAdjustment = vadj;
if (!m_horizontalAdjustment) {
ScrollbarGtk* hScrollbar = reinterpret_cast<ScrollbarGtk*>(horizontalScrollbar());
MainFrameScrollbarGtk* hScrollbar = reinterpret_cast<MainFrameScrollbarGtk*>(horizontalScrollbar());
if (hScrollbar)
hScrollbar->detachAdjustment();
ScrollbarGtk* vScrollbar = reinterpret_cast<ScrollbarGtk*>(verticalScrollbar());
MainFrameScrollbarGtk* vScrollbar = reinterpret_cast<MainFrameScrollbarGtk*>(verticalScrollbar());
if (vScrollbar)
vScrollbar->detachAdjustment();
......@@ -109,11 +112,11 @@ void ScrollView::setGtkAdjustments(GtkAdjustment* hadj, GtkAdjustment* vadj, boo
setHasVerticalScrollbar(true);
setHasHorizontalScrollbar(true);
ScrollbarGtk* hScrollbar = reinterpret_cast<ScrollbarGtk*>(horizontalScrollbar());
hScrollbar->attachAdjustment(m_horizontalAdjustment);
MainFrameScrollbarGtk* hScrollbar = reinterpret_cast<MainFrameScrollbarGtk*>(horizontalScrollbar());
hScrollbar->attachAdjustment(m_horizontalAdjustment.get());
ScrollbarGtk* vScrollbar = reinterpret_cast<ScrollbarGtk*>(verticalScrollbar());
vScrollbar->attachAdjustment(m_verticalAdjustment);
MainFrameScrollbarGtk* vScrollbar = reinterpret_cast<MainFrameScrollbarGtk*>(verticalScrollbar());
vScrollbar->attachAdjustment(m_verticalAdjustment.get());
// We used to reset everything to 0 here, but when page cache
// is enabled we reuse FrameViews that are cached. Since their
......@@ -124,7 +127,7 @@ void ScrollView::setGtkAdjustments(GtkAdjustment* hadj, GtkAdjustment* vadj, boo
// able to report correct values.
int horizontalPageStep = max(max<int>(frameRect().width() * Scrollbar::minFractionToStepWhenPaging(), frameRect().width() - Scrollbar::maxOverlapBetweenPages()), 1);
gtk_adjustment_configure(m_horizontalAdjustment,
gtk_adjustment_configure(m_horizontalAdjustment.get(),
resetValues ? 0 : scrollOffset().width(), 0,
resetValues ? 0 : contentsSize().width(),
resetValues ? 0 : Scrollbar::pixelsPerLineStep(),
......@@ -132,7 +135,7 @@ void ScrollView::setGtkAdjustments(GtkAdjustment* hadj, GtkAdjustment* vadj, boo
resetValues ? 0 : frameRect().width());
int verticalPageStep = max(max<int>(frameRect().height() * Scrollbar::minFractionToStepWhenPaging(), frameRect().height() - Scrollbar::maxOverlapBetweenPages()), 1);
gtk_adjustment_configure(m_verticalAdjustment,
gtk_adjustment_configure(m_verticalAdjustment.get(),
resetValues ? 0 : scrollOffset().height(), 0,
resetValues ? 0 : contentsSize().height(),
resetValues ? 0 : Scrollbar::pixelsPerLineStep(),
......@@ -142,72 +145,73 @@ void ScrollView::setGtkAdjustments(GtkAdjustment* hadj, GtkAdjustment* vadj, boo
void ScrollView::platformAddChild(Widget* child)
{
if (!GTK_IS_SOCKET(child->platformWidget()))
gtk_container_add(GTK_CONTAINER(hostWindow()->platformPageClient()), child->platformWidget());
}
void ScrollView::platformRemoveChild(Widget* child)
{
GtkWidget* parent;
// HostWindow can be NULL here. If that's the case
// let's grab the child's parent instead.
if (hostWindow())
parent = GTK_WIDGET(hostWindow()->platformPageClient());
else
parent = GTK_WIDGET(gtk_widget_get_parent(child->platformWidget()));
if (GTK_IS_CONTAINER(parent) && parent == gtk_widget_get_parent(child->platformWidget()))
gtk_container_remove(GTK_CONTAINER(parent), child->platformWidget());
}
IntRect ScrollView::visibleContentRect(bool includeScrollbars) const
{
if (!m_horizontalAdjustment)
// If we are an interior frame scrollbar or are in some sort of transition
// state, just calculate our size based on what the GTK+ theme says the
// scrollbar width should be.
if (parent() || !hostWindow() || !hostWindow()->platformPageClient()) {
return IntRect(IntPoint(m_scrollOffset.width(), m_scrollOffset.height()),
IntSize(max(0, width() - (verticalScrollbar() && !includeScrollbars ? verticalScrollbar()->width() : 0)),
max(0, height() - (horizontalScrollbar() && !includeScrollbars ? horizontalScrollbar()->height() : 0))));
}
// Main frame.
// We don't have a parent, so we are the main frame and thus have
// a parent widget which we can use to measure the visible region.
GtkWidget* measuredWidget = hostWindow()->platformPageClient();
GtkWidget* parent = gtk_widget_get_parent(measuredWidget);
GtkWidget* parentWidget = gtk_widget_get_parent(measuredWidget);
// We may not be in a widget that displays scrollbars, but we may
// have other kinds of decoration that make us smaller.
if (parent && includeScrollbars)
measuredWidget = parent;
if (parentWidget && includeScrollbars)
measuredWidget = parentWidget;
GtkAllocation allocation;
#if GTK_CHECK_VERSION(2, 18, 0)
gtk_widget_get_allocation(measuredWidget, &allocation);
#else
allocation = measuredWidget->allocation;
#endif
return IntRect(IntPoint(m_scrollOffset.width(), m_scrollOffset.height()),
IntSize(allocation.width, allocation.height));
}
void ScrollView::setScrollbarModes(ScrollbarMode horizontalMode, ScrollbarMode verticalMode, bool, bool)
void ScrollView::setScrollbarModes(ScrollbarMode horizontalMode, ScrollbarMode verticalMode, bool horizontalLock, bool verticalLock)
{
if (horizontalMode == m_horizontalScrollbarMode && verticalMode == m_verticalScrollbarMode)
return;
// FIXME: Restructure the ScrollView abstraction so that we do not have to
// copy this verbatim from ScrollView.cpp. Until then, we should make sure this
// is kept in sync.
bool needsUpdate = false;
if (horizontalMode != horizontalScrollbarMode() && !m_horizontalScrollbarLock) {
m_horizontalScrollbarMode = horizontalMode;
needsUpdate = true;
}
if (verticalMode != verticalScrollbarMode() && !m_verticalScrollbarLock) {
m_verticalScrollbarMode = verticalMode;
needsUpdate = true;
}
m_horizontalScrollbarMode = horizontalMode;
m_verticalScrollbarMode = verticalMode;
if (horizontalLock)
setHorizontalScrollbarLock();
// We don't really care about reporting policy changes on frames
// that have no adjustments attached to them.
if (!m_horizontalAdjustment) {
if (verticalLock)
setVerticalScrollbarLock();
if (needsUpdate)
updateScrollbars(scrollOffset());
return;
}
if (!isFrameView())
// We don't need to report policy changes on ScrollView's unless this
// one has an adjustment attached and it is a main frame.
if (!m_horizontalAdjustment || parent() || !isFrameView())
return;
// For frames that do have adjustments attached, we want to report
// policy changes, so that they may be applied to the widget to
// which the WebView has been added, for instance.
// which the WebView's container (e.g. GtkScrolledWindow).
if (hostWindow())
hostWindow()->scrollbarsModeDidChange();
}
......
/*
* Copyright (C) 2007, 2009 Holger Hans Peter Freyther zecke@selfish.org
* Copyright (C) 2010 Gustavo Noronha Silva <gns@gnome.org>
* Copyright (C) 2010 Collabora Ltd.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "config.h"
#include "ScrollbarGtk.h"
#include "FrameView.h"
#include "GraphicsContext.h"
#include "GtkVersioning.h"
#include "IntRect.h"
#include "ScrollbarTheme.h"
#include <gtk/gtk.h>
using namespace WebCore;
PassRefPtr<Scrollbar> Scrollbar::createNativeScrollbar(ScrollbarClient* client, ScrollbarOrientation orientation, ScrollbarControlSize size)
{
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
* this is that we want the main frame to scroll when we move the mouse
* wheel over a child scrollbar in most cases. */
return gtk_widget_event(gtk_widget_get_parent(widget), reinterpret_cast<GdkEvent*>(event));
}
ScrollbarGtk::ScrollbarGtk(ScrollbarClient* client, ScrollbarOrientation orientation,
ScrollbarControlSize controlSize)
: Scrollbar(client, orientation, controlSize)
, m_adjustment(GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)))
{
GtkWidget* scrollBar = orientation == HorizontalScrollbar ?
gtk_hscrollbar_new(m_adjustment):
gtk_vscrollbar_new(m_adjustment);
gtk_widget_show(scrollBar);
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);
/*
* assign a sane default width and height to the Scrollbar, otherwise
* we will end up with a 0 width scrollbar.
*/
resize(ScrollbarTheme::nativeTheme()->scrollbarThickness(),
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)
{
if (m_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()
{
if (m_adjustment)
detachAdjustment();
}
void ScrollbarGtk::attachAdjustment(GtkAdjustment* adjustment)
{
if (platformWidget())
return;
if (m_adjustment)
detachAdjustment();
m_adjustment = adjustment;
if (m_adjustment) {
g_object_ref(m_adjustment);
g_signal_connect(m_adjustment, "value-changed", G_CALLBACK(ScrollbarGtk::gtkValueChanged), this);
}
updateThumbProportion();
updateThumbPosition();
}
void ScrollbarGtk::detachAdjustment()