~ubuntu-branches/ubuntu/maverick/webkit/maverick

« back to all changes in this revision

Viewing changes to WebCore/rendering/RenderPart.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mike Hommey
  • Date: 2007-08-19 15:54:12 UTC
  • Revision ID: james.westby@ubuntu.com-20070819155412-uxxg1h9plpghmtbi
Tags: upstream-0~svn25144
ImportĀ upstreamĀ versionĀ 0~svn25144

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * This file is part of the KDE project.
 
3
 *
 
4
 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
 
5
 *           (C) 2000 Simon Hausmann <hausmann@kde.org>
 
6
 *           (C) 2000 Stefan Schimanski (1Stein@gmx.de)
 
7
 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.
 
8
 *
 
9
 * This library is free software; you can redistribute it and/or
 
10
 * modify it under the terms of the GNU Library General Public
 
11
 * License as published by the Free Software Foundation; either
 
12
 * version 2 of the License, or (at your option) any later version.
 
13
 *
 
14
 * This library is distributed in the hope that it will be useful,
 
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
17
 * Library General Public License for more details.
 
18
 *
 
19
 * You should have received a copy of the GNU Library General Public License
 
20
 * along with this library; see the file COPYING.LIB.  If not, write to
 
21
 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
22
 * Boston, MA 02111-1307, USA.
 
23
 *
 
24
 */
 
25
#include "config.h"
 
26
#include "RenderPart.h"
 
27
 
 
28
#include "Document.h"
 
29
#include "Frame.h"
 
30
#include "FrameTree.h"
 
31
#include "FrameView.h"
 
32
#include "HTMLFrameOwnerElement.h"
 
33
#include "HTMLNames.h"
 
34
#include "Page.h"
 
35
 
 
36
namespace WebCore {
 
37
 
 
38
using namespace HTMLNames;
 
39
 
 
40
RenderPart::RenderPart(HTMLFrameOwnerElement* node)
 
41
    : RenderWidget(node)
 
42
{
 
43
    // init RenderObject attributes
 
44
    setInline(false);
 
45
}
 
46
 
 
47
RenderPart::~RenderPart()
 
48
{
 
49
    // Since deref ends up calling setWidget back on us, need to make sure
 
50
    // that widget is already 0 so it won't do any work.
 
51
    Widget* widget = m_widget;
 
52
    m_widget = 0;
 
53
    if (widget && widget->isFrameView())
 
54
        static_cast<FrameView*>(widget)->deref();
 
55
    else
 
56
        delete widget;
 
57
}
 
58
 
 
59
void RenderPart::setWidget(Widget* widget)
 
60
{
 
61
    if (widget != m_widget) {
 
62
        if (widget && widget->isFrameView())
 
63
            static_cast<FrameView*>(widget)->ref();
 
64
        RenderWidget::setWidget(widget);
 
65
 
 
66
        // make sure the scrollbars are set correctly for restore
 
67
        // ### find better fix
 
68
        viewCleared();
 
69
    }
 
70
}
 
71
 
 
72
void RenderPart::viewCleared()
 
73
{
 
74
}
 
75
 
 
76
void RenderPart::deleteWidget()
 
77
{
 
78
    if (m_widget && m_widget->isFrameView())
 
79
        static_cast<FrameView*>(m_widget)->deref();
 
80
    else
 
81
        delete m_widget;
 
82
}
 
83
 
 
84
// FIXME: This should not be necessary.  Remove this once WebKit knows to properly schedule
 
85
// layouts using WebCore when objects resize.
 
86
void RenderPart::updateWidgetPosition()
 
87
{
 
88
    if (!m_widget)
 
89
        return;
 
90
    
 
91
    int x, y, width, height;
 
92
    absolutePosition(x, y);
 
93
    x += borderLeft() + paddingLeft();
 
94
    y += borderTop() + paddingTop();
 
95
    width = m_width - borderLeft() - borderRight() - paddingLeft() - paddingRight();
 
96
    height = m_height - borderTop() - borderBottom() - paddingTop() - paddingBottom();
 
97
    IntRect newBounds(x,y,width,height);
 
98
    bool boundsChanged = newBounds != m_widget->frameGeometry();
 
99
    if (boundsChanged) {
 
100
        // The widget changed positions.  Update the frame geometry.
 
101
        RenderArena *arena = ref();
 
102
        element()->ref();
 
103
        m_widget->setFrameGeometry(newBounds);
 
104
        element()->deref();
 
105
        deref(arena);
 
106
    }
 
107
 
 
108
    // if the frame bounds got changed, or if view needs layout (possibly indicating
 
109
    // content size is wrong) we have to do a layout to set the right widget size
 
110
    if (m_widget && m_widget->isFrameView()) {
 
111
        FrameView* frameView = static_cast<FrameView*>(m_widget);
 
112
        if (boundsChanged || frameView->needsLayout())
 
113
            frameView->layout();
 
114
    }
 
115
}
 
116
 
 
117
}