~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/3rdparty/webkit/WebCore/html/HTMLBodyElement.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-11-02 18:30:08 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (15.2.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 88.
  • Revision ID: james.westby@ubuntu.com-20091102183008-b6a4gcs128mvfb3m
Tags: upstream-4.6.0~beta1
ImportĀ upstreamĀ versionĀ 4.6.0~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
4
4
 *           (C) 2000 Simon Hausmann (hausmann@kde.org)
5
5
 *           (C) 2001 Dirk Mueller (mueller@kde.org)
6
 
 * Copyright (C) 2004, 2006, 2007, 2008 Apple Inc. All rights reserved.
 
6
 * Copyright (C) 2004, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
7
7
 *
8
8
 * This library is free software; you can redistribute it and/or
9
9
 * modify it under the terms of the GNU Library General Public
24
24
#include "config.h"
25
25
#include "HTMLBodyElement.h"
26
26
 
27
 
#include "CSSHelper.h"
28
 
#include "CSSMutableStyleDeclaration.h"
29
 
#include "CSSPropertyNames.h"
30
27
#include "CSSStyleSelector.h"
31
28
#include "CSSStyleSheet.h"
32
29
#include "CSSValueKeywords.h"
33
 
#include "Document.h"
34
30
#include "EventNames.h"
 
31
#include "Frame.h"
35
32
#include "FrameView.h"
36
33
#include "HTMLFrameElementBase.h"
37
34
#include "HTMLNames.h"
 
35
#include "MappedAttribute.h"
 
36
#include "ScriptEventListener.h"
38
37
 
39
38
namespace WebCore {
40
39
 
41
40
using namespace HTMLNames;
42
41
 
43
 
HTMLBodyElement::HTMLBodyElement(const QualifiedName& tagName, Document* doc)
44
 
    : HTMLElement(tagName, doc)
 
42
HTMLBodyElement::HTMLBodyElement(const QualifiedName& tagName, Document* document)
 
43
    : HTMLElement(tagName, document)
45
44
{
46
45
    ASSERT(hasTagName(bodyTag));
47
46
}
86
85
void HTMLBodyElement::parseMappedAttribute(MappedAttribute *attr)
87
86
{
88
87
    if (attr->name() == backgroundAttr) {
89
 
        String url = parseURL(attr->value());
 
88
        String url = deprecatedParseURL(attr->value());
90
89
        if (!url.isEmpty())
91
90
            addCSSImageProperty(attr, CSSPropertyBackgroundImage, document()->completeURL(url).string());
92
91
    } else if (attr->name() == marginwidthAttr || attr->name() == leftmarginAttr) {
131
130
        if (attached())
132
131
            document()->recalcStyle(Force);
133
132
    } else if (attr->name() == onloadAttr)
134
 
        document()->setWindowInlineEventListenerForTypeAndAttribute(eventNames().loadEvent, attr);
 
133
        document()->setWindowAttributeEventListener(eventNames().loadEvent, createAttributeEventListener(document()->frame(), attr));
135
134
    else if (attr->name() == onbeforeunloadAttr)
136
 
        document()->setWindowInlineEventListenerForTypeAndAttribute(eventNames().beforeunloadEvent, attr);
 
135
        document()->setWindowAttributeEventListener(eventNames().beforeunloadEvent, createAttributeEventListener(document()->frame(), attr));
137
136
    else if (attr->name() == onunloadAttr)
138
 
        document()->setWindowInlineEventListenerForTypeAndAttribute(eventNames().unloadEvent, attr);
 
137
        document()->setWindowAttributeEventListener(eventNames().unloadEvent, createAttributeEventListener(document()->frame(), attr));
 
138
    else if (attr->name() == onpagehideAttr)
 
139
        document()->setWindowAttributeEventListener(eventNames().pagehideEvent, createAttributeEventListener(document()->frame(), attr));
 
140
    else if (attr->name() == onpageshowAttr)
 
141
        document()->setWindowAttributeEventListener(eventNames().pageshowEvent, createAttributeEventListener(document()->frame(), attr));
139
142
    else if (attr->name() == onblurAttr)
140
 
        document()->setWindowInlineEventListenerForTypeAndAttribute(eventNames().blurEvent, attr);
 
143
        document()->setWindowAttributeEventListener(eventNames().blurEvent, createAttributeEventListener(document()->frame(), attr));
141
144
    else if (attr->name() == onfocusAttr)
142
 
        document()->setWindowInlineEventListenerForTypeAndAttribute(eventNames().focusEvent, attr);
 
145
        document()->setWindowAttributeEventListener(eventNames().focusEvent, createAttributeEventListener(document()->frame(), attr));
 
146
#if ENABLE(ORIENTATION_EVENTS)
 
147
    else if (attr->name() == onorientationchangeAttr)
 
148
        document()->setWindowAttributeEventListener(eventNames().orientationchangeEvent, createAttributeEventListener(document()->frame(), attr));
 
149
#endif
 
150
    else if (attr->name() == onhashchangeAttr)
 
151
        document()->setWindowAttributeEventListener(eventNames().hashchangeEvent, createAttributeEventListener(document()->frame(), attr));
143
152
    else if (attr->name() == onresizeAttr)
144
 
        document()->setWindowInlineEventListenerForTypeAndAttribute(eventNames().resizeEvent, attr);
 
153
        document()->setWindowAttributeEventListener(eventNames().resizeEvent, createAttributeEventListener(document()->frame(), attr));
145
154
    else if (attr->name() == onscrollAttr)
146
 
        document()->setWindowInlineEventListenerForTypeAndAttribute(eventNames().scrollEvent, attr);
147
 
    else if (attr->name() == onstorageAttr) {
148
 
        // The HTML5 spec currently specifies that storage events are fired only at the body element of
149
 
        // an HTMLDocument, which is why the onstorage attribute differs from the ones before it.
150
 
        // The spec might change on this, and then so should we!
151
 
        setInlineEventListenerForTypeAndAttribute(eventNames().storageEvent, attr);
152
 
    } else
 
155
        document()->setWindowAttributeEventListener(eventNames().scrollEvent, createAttributeEventListener(document()->frame(), attr));
 
156
    else if (attr->name() == onstorageAttr)
 
157
        document()->setWindowAttributeEventListener(eventNames().storageEvent, createAttributeEventListener(document()->frame(), attr));
 
158
    else if (attr->name() == ononlineAttr)
 
159
        document()->setWindowAttributeEventListener(eventNames().onlineEvent, createAttributeEventListener(document()->frame(), attr));
 
160
    else if (attr->name() == onofflineAttr)
 
161
        document()->setWindowAttributeEventListener(eventNames().offlineEvent, createAttributeEventListener(document()->frame(), attr));
 
162
    else
153
163
        HTMLElement::parseMappedAttribute(attr);
154
164
}
155
165
 
190
200
    setAttribute(alinkAttr, value);
191
201
}
192
202
 
193
 
String HTMLBodyElement::background() const
194
 
{
195
 
    return getAttribute(backgroundAttr);
196
 
}
197
 
 
198
 
void HTMLBodyElement::setBackground(const String& value)
199
 
{
200
 
    setAttribute(backgroundAttr, value);
201
 
}
202
 
 
203
203
String HTMLBodyElement::bgColor() const
204
204
{
205
205
    return getAttribute(bgcolorAttr);
240
240
    setAttribute(vlinkAttr, value);
241
241
}
242
242
 
 
243
static int adjustForZoom(int value, FrameView* frameView)
 
244
{
 
245
    float zoomFactor = frameView->frame()->zoomFactor();
 
246
    if (zoomFactor == 1)
 
247
        return value;
 
248
    // Needed because of truncation (rather than rounding) when scaling up.
 
249
    if (zoomFactor > 1)
 
250
        value++;
 
251
    return static_cast<int>(value / zoomFactor);
 
252
}
 
253
 
243
254
int HTMLBodyElement::scrollLeft() const
244
255
{
245
256
    // Update the document's layout.
246
257
    Document* doc = document();
247
258
    doc->updateLayoutIgnorePendingStylesheets();
248
259
    FrameView* view = doc->view();
249
 
    return view ? view->scrollX() : 0;
 
260
    return view ? adjustForZoom(view->scrollX(), view) : 0;
250
261
}
251
262
 
252
263
void HTMLBodyElement::setScrollLeft(int scrollLeft)
255
266
    if (sview) {
256
267
        // Update the document's layout
257
268
        document()->updateLayoutIgnorePendingStylesheets();
258
 
        sview->setScrollPosition(IntPoint(scrollLeft, sview->scrollY()));
 
269
        sview->setScrollPosition(IntPoint(static_cast<int>(scrollLeft * sview->frame()->zoomFactor()), sview->scrollY()));
259
270
    }    
260
271
}
261
272
 
265
276
    Document* doc = document();
266
277
    doc->updateLayoutIgnorePendingStylesheets();
267
278
    FrameView* view = doc->view();
268
 
    return view ? view->scrollY() : 0;
 
279
    return view ? adjustForZoom(view->scrollY(), view) : 0;
269
280
}
270
281
 
271
282
void HTMLBodyElement::setScrollTop(int scrollTop)
274
285
    if (sview) {
275
286
        // Update the document's layout
276
287
        document()->updateLayoutIgnorePendingStylesheets();
277
 
        sview->setScrollPosition(IntPoint(sview->scrollX(), scrollTop));
 
288
        sview->setScrollPosition(IntPoint(sview->scrollX(), static_cast<int>(scrollTop * sview->frame()->zoomFactor())));
278
289
    }        
279
290
}
280
291
 
284
295
    Document* doc = document();
285
296
    doc->updateLayoutIgnorePendingStylesheets();
286
297
    FrameView* view = doc->view();
287
 
    return view ? view->contentsHeight() : 0;    
 
298
    return view ? adjustForZoom(view->contentsHeight(), view) : 0;    
288
299
}
289
300
 
290
301
int HTMLBodyElement::scrollWidth() const
293
304
    Document* doc = document();
294
305
    doc->updateLayoutIgnorePendingStylesheets();
295
306
    FrameView* view = doc->view();
296
 
    return view ? view->contentsWidth() : 0;    
 
307
    return view ? adjustForZoom(view->contentsWidth(), view) : 0;    
297
308
}
298
309
 
299
310
void HTMLBodyElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const
300
311
{
301
312
    HTMLElement::addSubresourceAttributeURLs(urls);
302
313
 
303
 
    addSubresourceURL(urls, document()->completeURL(background()));
304
 
}
305
 
 
306
 
}
 
314
    addSubresourceURL(urls, document()->completeURL(getAttribute(backgroundAttr)));
 
315
}
 
316
 
 
317
void HTMLBodyElement::didMoveToNewOwnerDocument()
 
318
{
 
319
    // When moving body elements between documents, we should have to reset the parent sheet for any
 
320
    // link style declarations.  If we don't we might crash later.
 
321
    // In practice I can't reproduce this theoretical problem.
 
322
    // webarchive/adopt-attribute-styled-body-webarchive.html tries to make sure this crash won't surface.
 
323
    if (m_linkDecl)
 
324
        m_linkDecl->setParent(document()->elementSheet());
 
325
    
 
326
    HTMLElement::didMoveToNewOwnerDocument();
 
327
}
 
328
 
 
329
} // namespace WebCore