root/trunk/WebCore/platform/gtk/ScrollViewGtk.cpp

Revision 37447, 6.5 KB (checked in by alp@webkit.org, 8 weeks ago)

2008-10-09 Jan Michael Alonzo <jmalonzo@webkit.org>

Reviewed by Alp Toker.

https://bugs.webkit.org/show_bug.cgi?id=21390
[Gtk] Linux/Gtk: GtkLauncher crashes on Acid3 (but after test 80 this time)

  • platform/gtk/ScrollViewGtk.cpp: (WebCore::ScrollView::platformRemoveChild):
  • Property svn:eol-style set to native
Line 
1/*
2 * Copyright (C) 2006, 2007, 2008 Apple Computer, Inc. All rights reserved.
3 * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com
4 * Copyright (C) 2007 Holger Hans Peter Freyther
5 * Copyright (C) 2008 Collabora Ltd.
6 *
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 *    notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in the
16 *    documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include "config.h"
32#include "ScrollView.h"
33
34#include "FloatRect.h"
35#include "GraphicsContext.h"
36#include "HostWindow.h"
37#include "IntRect.h"
38#include "NotImplemented.h"
39#include "PlatformMouseEvent.h"
40#include "PlatformWheelEvent.h"
41#include "ScrollbarGtk.h"
42#include "ScrollbarTheme.h"
43
44#include <gtk/gtk.h>
45
46using namespace std;
47
48namespace WebCore {
49
50static void adjustmentChanged(GtkAdjustment* adjustment, gpointer _that)
51{
52    ScrollView* that = reinterpret_cast<ScrollView*>(_that);
53
54    // Figure out if we really moved.
55    IntSize newOffset = that->scrollOffset();
56    if (adjustment == that->m_horizontalAdjustment)
57        newOffset.setWidth(static_cast<int>(gtk_adjustment_get_value(adjustment)));
58    else if (adjustment == that->m_verticalAdjustment)
59        newOffset.setHeight(static_cast<int>(gtk_adjustment_get_value(adjustment)));
60
61    IntSize scrollDelta = newOffset - that->scrollOffset();
62    if (scrollDelta == IntSize())
63        return;
64    that->setScrollOffset(newOffset);
65
66    if (that->scrollbarsSuppressed())
67        return;
68
69    that->scrollContents(scrollDelta);
70}
71
72void ScrollView::platformInit()
73{
74    m_horizontalAdjustment = 0;
75    m_verticalAdjustment = 0;
76}
77
78void ScrollView::platformDestroy()
79{
80    if (m_horizontalAdjustment) {
81        g_signal_handlers_disconnect_by_func(G_OBJECT(m_horizontalAdjustment), (gpointer)adjustmentChanged, this);
82        g_object_unref(m_horizontalAdjustment);
83    }
84
85    if (m_verticalAdjustment) {
86        g_signal_handlers_disconnect_by_func(G_OBJECT(m_verticalAdjustment), (gpointer)adjustmentChanged, this);
87        g_object_unref(m_verticalAdjustment);
88    }
89}
90
91/*
92 * The following is assumed:
93 *   (hadj && vadj) || (!hadj && !vadj)
94 */
95void ScrollView::setGtkAdjustments(GtkAdjustment* hadj, GtkAdjustment* vadj)
96{
97    ASSERT(!hadj == !vadj);
98
99    if (m_horizontalAdjustment) {
100        g_signal_handlers_disconnect_by_func(G_OBJECT(m_horizontalAdjustment), (gpointer)adjustmentChanged, this);
101        g_signal_handlers_disconnect_by_func(G_OBJECT(m_verticalAdjustment), (gpointer)adjustmentChanged, this);
102        g_object_unref(m_horizontalAdjustment);
103        g_object_unref(m_verticalAdjustment);
104    }
105
106    m_horizontalAdjustment = hadj;
107    m_verticalAdjustment = vadj;
108
109    if (m_horizontalAdjustment) {
110        g_signal_connect(m_horizontalAdjustment, "value-changed", G_CALLBACK(adjustmentChanged), this);
111        g_signal_connect(m_verticalAdjustment, "value-changed", G_CALLBACK(adjustmentChanged), this);
112
113        /*
114         * disable the scrollbars (if we have any) as the GtkAdjustment over
115         */
116        setHasVerticalScrollbar(false);
117        setHasHorizontalScrollbar(false);
118
119        g_object_ref(m_horizontalAdjustment);
120        g_object_ref(m_verticalAdjustment);
121    }
122
123    updateScrollbars(m_scrollOffset);
124}
125
126void ScrollView::platformAddChild(Widget* child)
127{
128    if (!GTK_IS_SOCKET(child->platformWidget()))
129        gtk_container_add(GTK_CONTAINER(hostWindow()->platformWindow()), child->platformWidget());
130}
131
132void ScrollView::platformRemoveChild(Widget* child)
133{
134    GtkWidget* parent;
135
136    // HostWindow can be NULL here. If that's the case
137    // let's grab the child's parent instead.
138    if (hostWindow())
139        parent = GTK_WIDGET(hostWindow()->platformWindow());
140    else
141        parent = GTK_WIDGET(child->platformWidget()->parent);
142
143    if (GTK_IS_CONTAINER(parent) && parent == child->platformWidget()->parent)
144        gtk_container_remove(GTK_CONTAINER(parent), child->platformWidget());
145}
146
147bool ScrollView::platformHandleHorizontalAdjustment(const IntSize& scroll)
148{
149    if (m_horizontalAdjustment) {
150        m_horizontalAdjustment->page_size = visibleWidth();
151        m_horizontalAdjustment->step_increment = visibleWidth() / 10.0;
152        m_horizontalAdjustment->page_increment = visibleWidth() * 0.9;
153        m_horizontalAdjustment->lower = 0;
154        m_horizontalAdjustment->upper = contentsWidth();
155        gtk_adjustment_changed(m_horizontalAdjustment);
156
157        if (m_scrollOffset.width() != scroll.width()) {
158            m_horizontalAdjustment->value = scroll.width();
159            gtk_adjustment_value_changed(m_horizontalAdjustment);
160        }
161        return true;
162    }
163    return false;
164}
165
166bool ScrollView::platformHandleVerticalAdjustment(const IntSize& scroll)
167{
168    if (m_verticalAdjustment) {
169        m_verticalAdjustment->page_size = visibleHeight();
170        m_verticalAdjustment->step_increment = visibleHeight() / 10.0;
171        m_verticalAdjustment->page_increment = visibleHeight() * 0.9;
172        m_verticalAdjustment->lower = 0;
173        m_verticalAdjustment->upper = contentsHeight();
174        gtk_adjustment_changed(m_verticalAdjustment);
175
176        if (m_scrollOffset.height() != scroll.height()) {
177            m_verticalAdjustment->value = scroll.height();
178            gtk_adjustment_value_changed(m_verticalAdjustment);
179        }
180        return true;
181    } 
182    return false;
183}
184
185bool ScrollView::platformHasHorizontalAdjustment() const
186{
187    return m_horizontalAdjustment != 0;
188}
189
190bool ScrollView::platformHasVerticalAdjustment() const
191{
192    return m_verticalAdjustment != 0;
193}
194
195}
Note: See TracBrowser for help on using the browser.