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.
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"
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"
34
30
#include "EventNames.h"
35
32
#include "FrameView.h"
36
33
#include "HTMLFrameElementBase.h"
37
34
#include "HTMLNames.h"
35
#include "MappedAttribute.h"
36
#include "ScriptEventListener.h"
39
38
namespace WebCore {
41
40
using namespace HTMLNames;
43
HTMLBodyElement::HTMLBodyElement(const QualifiedName& tagName, Document* doc)
44
: HTMLElement(tagName, doc)
42
HTMLBodyElement::HTMLBodyElement(const QualifiedName& tagName, Document* document)
43
: HTMLElement(tagName, document)
46
45
ASSERT(hasTagName(bodyTag));
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));
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);
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));
153
163
HTMLElement::parseMappedAttribute(attr);
240
240
setAttribute(vlinkAttr, value);
243
static int adjustForZoom(int value, FrameView* frameView)
245
float zoomFactor = frameView->frame()->zoomFactor();
248
// Needed because of truncation (rather than rounding) when scaling up.
251
return static_cast<int>(value / zoomFactor);
243
254
int HTMLBodyElement::scrollLeft() const
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;
252
263
void HTMLBodyElement::setScrollLeft(int scrollLeft)
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;
299
310
void HTMLBodyElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const
301
312
HTMLElement::addSubresourceAttributeURLs(urls);
303
addSubresourceURL(urls, document()->completeURL(background()));
314
addSubresourceURL(urls, document()->completeURL(getAttribute(backgroundAttr)));
317
void HTMLBodyElement::didMoveToNewOwnerDocument()
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.
324
m_linkDecl->setParent(document()->elementSheet());
326
HTMLElement::didMoveToNewOwnerDocument();
329
} // namespace WebCore