From 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Tue, 27 Jun 2017 06:07:23 +0000 Subject: webkitgtk-2.16.5 --- Source/WebCore/html/HTMLBodyElement.cpp | 306 +++++++++++++++++++------------- 1 file changed, 185 insertions(+), 121 deletions(-) (limited to 'Source/WebCore/html/HTMLBodyElement.cpp') diff --git a/Source/WebCore/html/HTMLBodyElement.cpp b/Source/WebCore/html/HTMLBodyElement.cpp index 9da1410fe..b1ee9c4c2 100644 --- a/Source/WebCore/html/HTMLBodyElement.cpp +++ b/Source/WebCore/html/HTMLBodyElement.cpp @@ -3,7 +3,7 @@ * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Simon Hausmann (hausmann@kde.org) * (C) 2001 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. + * Copyright (C) 2004-2017 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -24,18 +24,20 @@ #include "config.h" #include "HTMLBodyElement.h" -#include "Attribute.h" #include "CSSImageValue.h" #include "CSSParser.h" #include "CSSValueKeywords.h" +#include "DOMWindow.h" +#include "DOMWrapperWorld.h" #include "EventNames.h" #include "Frame.h" #include "FrameView.h" -#include "HTMLFrameElementBase.h" +#include "HTMLFrameElement.h" +#include "HTMLIFrameElement.h" #include "HTMLNames.h" #include "HTMLParserIdioms.h" -#include "Page.h" #include "StyleProperties.h" +#include namespace WebCore { @@ -47,14 +49,21 @@ HTMLBodyElement::HTMLBodyElement(const QualifiedName& tagName, Document& documen ASSERT(hasTagName(bodyTag)); } -PassRefPtr HTMLBodyElement::create(Document& document) +bool HTMLBodyElement::isFirstBodyElementOfDocument() const { - return adoptRef(new HTMLBodyElement(bodyTag, document)); + // By spec http://dev.w3.org/csswg/cssom-view/#the-html-body-element + // "The HTML body element is the first body HTML element child of the root HTML element html." + return document().body() == this; } -PassRefPtr HTMLBodyElement::create(const QualifiedName& tagName, Document& document) +Ref HTMLBodyElement::create(Document& document) { - return adoptRef(new HTMLBodyElement(tagName, document)); + return adoptRef(*new HTMLBodyElement(bodyTag, document)); +} + +Ref HTMLBodyElement::create(const QualifiedName& tagName, Document& document) +{ + return adoptRef(*new HTMLBodyElement(tagName, document)); } HTMLBodyElement::~HTMLBodyElement() @@ -73,9 +82,9 @@ void HTMLBodyElement::collectStyleForPresentationAttribute(const QualifiedName& if (name == backgroundAttr) { String url = stripLeadingAndTrailingHTMLSpaces(value); if (!url.isEmpty()) { - auto imageValue = CSSImageValue::create(document().completeURL(url).string()); + auto imageValue = CSSImageValue::create(document().completeURL(url)); imageValue.get().setInitiator(localName()); - style.setProperty(CSSProperty(CSSPropertyBackgroundImage, std::move(imageValue))); + style.setProperty(CSSProperty(CSSPropertyBackgroundImage, WTFMove(imageValue))); } } else if (name == marginwidthAttr || name == leftmarginAttr) { addHTMLLengthToStyle(style, CSSPropertyMarginRight, value); @@ -88,12 +97,56 @@ void HTMLBodyElement::collectStyleForPresentationAttribute(const QualifiedName& } else if (name == textAttr) { addHTMLColorToStyle(style, CSSPropertyColor, value); } else if (name == bgpropertiesAttr) { - if (equalIgnoringCase(value, "fixed")) + if (equalLettersIgnoringASCIICase(value, "fixed")) addPropertyToPresentationAttributeStyle(style, CSSPropertyBackgroundAttachment, CSSValueFixed); } else HTMLElement::collectStyleForPresentationAttribute(name, value, style); } +HTMLElement::EventHandlerNameMap HTMLBodyElement::createWindowEventHandlerNameMap() +{ + static const QualifiedName* const table[] = { + &onbeforeunloadAttr, + &onblurAttr, + &onerrorAttr, + &onfocusAttr, + &onfocusinAttr, + &onfocusoutAttr, + &onhashchangeAttr, + &onlanguagechangeAttr, + &onloadAttr, + &onmessageAttr, + &onofflineAttr, + &ononlineAttr, + &onorientationchangeAttr, + &onpagehideAttr, + &onpageshowAttr, + &onpopstateAttr, + &onresizeAttr, + &onscrollAttr, + &onstorageAttr, + &onunloadAttr, + &onwebkitmouseforcechangedAttr, + &onwebkitmouseforcedownAttr, + &onwebkitmouseforceupAttr, + &onwebkitmouseforcewillbeginAttr, + &onwebkitwillrevealbottomAttr, + &onwebkitwillrevealleftAttr, + &onwebkitwillrevealrightAttr, + &onwebkitwillrevealtopAttr, + }; + + EventHandlerNameMap map; + populateEventHandlerNameMap(map, table); + return map; +} + +const AtomicString& HTMLBodyElement::eventNameForWindowEventHandlerAttribute(const QualifiedName& attributeName) +{ + static NeverDestroyed map = createWindowEventHandlerNameMap(); + return eventNameForEventHandlerAttribute(attributeName, map.get()); +} + void HTMLBodyElement::parseAttribute(const QualifiedName& name, const AtomicString& value) { if (name == vlinkAttr || name == alinkAttr || name == linkAttr) { @@ -105,8 +158,8 @@ void HTMLBodyElement::parseAttribute(const QualifiedName& name, const AtomicStri else document().resetActiveLinkColor(); } else { - RGBA32 color; - if (CSSParser::parseColor(color, value, !document().inQuirksMode())) { + Color color = CSSParser::parseColor(value, !document().inQuirksMode()); + if (color.isValid()) { if (name == linkAttr) document().setLinkColor(color); else if (name == vlinkAttr) @@ -116,64 +169,48 @@ void HTMLBodyElement::parseAttribute(const QualifiedName& name, const AtomicStri } } - setNeedsStyleRecalc(); - } else if (name == onloadAttr) - document().setWindowAttributeEventListener(eventNames().loadEvent, name, value); - else if (name == onbeforeunloadAttr) - document().setWindowAttributeEventListener(eventNames().beforeunloadEvent, name, value); - else if (name == onunloadAttr) - document().setWindowAttributeEventListener(eventNames().unloadEvent, name, value); - else if (name == onpagehideAttr) - document().setWindowAttributeEventListener(eventNames().pagehideEvent, name, value); - else if (name == onpageshowAttr) - document().setWindowAttributeEventListener(eventNames().pageshowEvent, name, value); - else if (name == onpopstateAttr) - document().setWindowAttributeEventListener(eventNames().popstateEvent, name, value); - else if (name == onblurAttr) - document().setWindowAttributeEventListener(eventNames().blurEvent, name, value); - else if (name == onfocusAttr) - document().setWindowAttributeEventListener(eventNames().focusEvent, name, value); -#if ENABLE(ORIENTATION_EVENTS) - else if (name == onorientationchangeAttr) - document().setWindowAttributeEventListener(eventNames().orientationchangeEvent, name, value); -#endif - else if (name == onhashchangeAttr) - document().setWindowAttributeEventListener(eventNames().hashchangeEvent, name, value); - else if (name == onresizeAttr) - document().setWindowAttributeEventListener(eventNames().resizeEvent, name, value); - else if (name == onscrollAttr) - document().setWindowAttributeEventListener(eventNames().scrollEvent, name, value); - else if (name == onselectionchangeAttr) - document().setAttributeEventListener(eventNames().selectionchangeEvent, name, value); - else if (name == onstorageAttr) - document().setWindowAttributeEventListener(eventNames().storageEvent, name, value); - else if (name == ononlineAttr) - document().setWindowAttributeEventListener(eventNames().onlineEvent, name, value); - else if (name == onofflineAttr) - document().setWindowAttributeEventListener(eventNames().offlineEvent, name, value); - else - HTMLElement::parseAttribute(name, value); + invalidateStyleForSubtree(); + return; + } + + if (name == onselectionchangeAttr) { + document().setAttributeEventListener(eventNames().selectionchangeEvent, name, value, mainThreadNormalWorld()); + return; + } + + auto& eventName = eventNameForWindowEventHandlerAttribute(name); + if (!eventName.isNull()) { + document().setWindowAttributeEventListener(eventName, name, value, mainThreadNormalWorld()); + return; + } + + HTMLElement::parseAttribute(name, value); } Node::InsertionNotificationRequest HTMLBodyElement::insertedInto(ContainerNode& insertionPoint) { HTMLElement::insertedInto(insertionPoint); - if (!insertionPoint.inDocument()) + if (!insertionPoint.isConnected()) return InsertionDone; // FIXME: It's surprising this is web compatible since it means a marginwidth and marginheight attribute can // magically appear on the of all documents embedded through