1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
/*
* 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())), NotFromScrollAnimator);
}
void MainFrameScrollbarGtk::paint(GraphicsContext* context, const IntRect& rect)
{
// Main frame scrollbars are not painted by WebCore.
return;
}
|