Move 'style' from Element to HTMLElement / SVGElement and make it settable
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 8 May 2017 16:50:46 +0000 (16:50 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 8 May 2017 16:50:46 +0000 (16:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=171795

Reviewed by Alex Christensen.

Source/WebCore:

Move 'style' from Element to HTMLElement / SVGElement and make it settable
as per:
- https://drafts.csswg.org/cssom/#the-elementcssinlinestyle-interface

Both Firefox and Chrome already match the specification (both for the
property location and having it settable).

Test: fast/css/Element-style.html

* CMakeLists.txt:
* DerivedSources.make:
* WebCore.xcodeproj/project.pbxproj:
* css/ElementCSSInlineStyle.idl: Added.
* css/PropertySetCSSStyleDeclaration.h:
* css/StyleProperties.cpp:
(WebCore::MutableStyleProperties::ensureCSSStyleDeclaration):
(WebCore::MutableStyleProperties::ensureInlineCSSStyleDeclaration):
* css/StyleProperties.h:
* dom/Attr.cpp:
(WebCore::Attr::style):
* dom/Document.cpp:
(WebCore::Document::createCSSStyleDeclaration):
* dom/Element.cpp:
* dom/Element.h:
* dom/Element.idl:
* dom/StyledElement.cpp:
(WebCore::StyledElement::cssomStyle):
* dom/StyledElement.h:
* editing/Editor.cpp:
(WebCore::Editor::applyEditingStyleToElement):
* editing/ReplaceSelectionCommand.cpp:
(WebCore::ReplaceSelectionCommand::removeRedundantStylesAndKeepStyleSpanInline):
* html/HTMLElement.idl:

* html/ImageInputType.cpp:
(WebCore::ImageInputType::height):
(WebCore::ImageInputType::width):
Fix bug that was found by fast/forms/input-width-height-attributes-without-renderer-loaded-image.html.
That test relied on setting HTMLElement.style which did not work until now. Call updateLayout()
*before* doing the renderer check.

* inspector/InspectorCSSAgent.cpp:
(WebCore::InspectorCSSAgent::getMatchedStylesForNode):
(WebCore::InspectorCSSAgent::getInlineStylesForNode):
(WebCore::InspectorCSSAgent::getComputedStyleForNode):
(WebCore::InspectorCSSAgent::asInspectorStyleSheet):
(WebCore::InspectorCSSAgent::buildObjectForAttributesStyle):
* inspector/InspectorCSSAgent.h:
* inspector/InspectorStyleSheet.cpp:
(WebCore::InspectorStyle::create):
(WebCore::InspectorStyle::InspectorStyle):
(WebCore::InspectorStyle::extractSourceData):
(WebCore::InspectorStyle::setText):
(WebCore::InspectorStyleSheet::inspectorStyleForId):
(WebCore::InspectorStyleSheetForInlineStyle::create):
(WebCore::InspectorStyleSheetForInlineStyle::InspectorStyleSheetForInlineStyle):
(WebCore::InspectorStyleSheetForInlineStyle::didModifyElementAttribute):
(WebCore::InspectorStyleSheetForInlineStyle::setStyleText):
(WebCore::InspectorStyleSheetForInlineStyle::ensureParsedDataReady):
(WebCore::InspectorStyleSheetForInlineStyle::inlineStyle):
* inspector/InspectorStyleSheet.h:
* svg/SVGElement.idl:

Source/WebKit/mac:

Build fix.

* DOM/DOMElement.mm:
(-[DOMElement style]):
* WebCoreSupport/WebEditorClient.mm:
(WebEditorClient::shouldApplyStyle):
* WebView/WebFrame.mm:
(-[WebFrame _typingStyle]):

Source/WebKit2:

Build fix.

* WebProcess/WebCoreSupport/WebEditorClient.cpp:
(WebKit::WebEditorClient::shouldApplyStyle):

LayoutTests:

* accessibility/roles-exposed.html:
Add null check for element.style.

* fast/css/Element-style-expected.txt: Added.
* fast/css/Element-style.html: Added.
Add layout test coverage.

* fast/forms/input-width-height-attributes-without-renderer-loaded-image-expected.txt:
Rebaseline test that was setting HTMLElement.style which was a no-op until this patch. Now that it actually
does something, the input element actually looses its renderer. This found a bug which I fixed in this
patch.

* js/dom/dom-static-property-for-in-iteration-expected.txt:
Rebaseline as property enumeration order has changed.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@216426 268f45cc-cd09-0410-ab3c-d52691b4dbfc

40 files changed:
LayoutTests/ChangeLog
LayoutTests/accessibility/roles-exposed.html
LayoutTests/fast/css/Element-style-expected.txt [new file with mode: 0644]
LayoutTests/fast/css/Element-style.html [new file with mode: 0644]
LayoutTests/fast/forms/input-width-height-attributes-without-renderer-loaded-image-expected.txt
LayoutTests/js/dom/dom-static-property-for-in-iteration-expected.txt
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/DerivedSources.make
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/css/ElementCSSInlineStyle.idl [new file with mode: 0644]
Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp
Source/WebCore/css/PropertySetCSSStyleDeclaration.h
Source/WebCore/css/StyleProperties.cpp
Source/WebCore/css/StyleProperties.h
Source/WebCore/dom/Attr.cpp
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/Element.h
Source/WebCore/dom/Element.idl
Source/WebCore/dom/StyledElement.cpp
Source/WebCore/dom/StyledElement.h
Source/WebCore/editing/Editor.cpp
Source/WebCore/editing/ReplaceSelectionCommand.cpp
Source/WebCore/html/HTMLElement.idl
Source/WebCore/html/ImageInputType.cpp
Source/WebCore/inspector/InspectorCSSAgent.cpp
Source/WebCore/inspector/InspectorCSSAgent.h
Source/WebCore/inspector/InspectorStyleSheet.cpp
Source/WebCore/inspector/InspectorStyleSheet.h
Source/WebCore/svg/SVGElement.idl
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/DOM/DOMElement.mm
Source/WebKit/mac/WebCoreSupport/WebEditorClient.mm
Source/WebKit/mac/WebView/WebFrame.mm
Source/WebKit/mac/WebView/WebView.mm
Source/WebKit/win/DOMCoreClasses.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMElement.cpp
Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp

index 9d9b4dd..052963b 100644 (file)
@@ -1,3 +1,25 @@
+2017-05-08  Chris Dumez  <cdumez@apple.com>
+
+        Move 'style' from Element to HTMLElement / SVGElement and make it settable
+        https://bugs.webkit.org/show_bug.cgi?id=171795
+
+        Reviewed by Alex Christensen.
+
+        * accessibility/roles-exposed.html:
+        Add null check for element.style.
+
+        * fast/css/Element-style-expected.txt: Added.
+        * fast/css/Element-style.html: Added.
+        Add layout test coverage.
+
+        * fast/forms/input-width-height-attributes-without-renderer-loaded-image-expected.txt:
+        Rebaseline test that was setting HTMLElement.style which was a no-op until this patch. Now that it actually
+        does something, the input element actually looses its renderer. This found a bug which I fixed in this
+        patch.
+
+        * js/dom/dom-static-property-for-in-iteration-expected.txt:
+        Rebaseline as property enumeration order has changed.
+
 2017-05-08  Joanmarie Diggs  <jdiggs@igalia.com>
 
         AX: Propagate aria-readonly to grid descendants
index cb73296..4456345 100644 (file)
@@ -431,7 +431,8 @@ if (window.testRunner && window.accessibilityController) {
     examples = document.querySelectorAll('.ex');
     for (var i = 0, c = examples.length; i < c; i++) {
         el = examples[i];
-        el.style.display = 'none';
+        if (el.style)
+            el.style.display = 'none';
     }
 }
 </script>
diff --git a/LayoutTests/fast/css/Element-style-expected.txt b/LayoutTests/fast/css/Element-style-expected.txt
new file mode 100644 (file)
index 0000000..9e24628
--- /dev/null
@@ -0,0 +1,5 @@
+
+PASS 'style' property location 
+PASS 'style' property type 
+PASS style should be settable 
+
diff --git a/LayoutTests/fast/css/Element-style.html b/LayoutTests/fast/css/Element-style.html
new file mode 100644 (file)
index 0000000..02b9bce
--- /dev/null
@@ -0,0 +1,46 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<div id="testDiv" style="background-color: red"></div>
+<svg id="testSVG" style="background-color: red"></div>
+<script>
+test(() => {
+    const testDiv = document.getElementById("testDiv");
+    assert_equals(testDiv.__proto__, HTMLDivElement.prototype, "testDiv is an HTMLDivElement");
+    assert_idl_attribute(testDiv, "style", "HTMLElement has 'style' attribute");
+    assert_own_property(HTMLElement.prototype, "style", "'style' is on HTMLElement prototype");
+
+    const testSVG = document.getElementById("testSVG");
+    assert_equals(testSVG.__proto__, SVGSVGElement.prototype, "testSVG is an SVGSVGElement");
+    assert_idl_attribute(testSVG, "style", "SVGElement has 'style' attribute");
+    assert_own_property(SVGElement.prototype, "style", "'style' is on SVGElement prototype");
+
+    assert_not_exists("Element.prototype", "style", "'style' is not on Element prototype");
+}, "'style' property location");
+
+test(() => {
+    const testDiv = document.getElementById("testDiv");
+    assert_equals(testDiv.style.__proto__, CSSStyleDeclaration.prototype, "HTMLElement.style type");
+
+    const testSVG = document.getElementById("testSVG");
+    assert_equals(testSVG.style.__proto__, CSSStyleDeclaration.prototype, "SVGElement.style type");
+}, "'style' property type");
+
+test(() => {
+    const testDiv = document.getElementById("testDiv");
+    assert_equals(testDiv.style.backgroundColor, "red", "HTMLElement.style getter");
+    assert_readonly(testDiv, "style", "HTMLElement.style is readonly");
+    testDiv.style = "background-color: green";
+    assert_equals(testDiv.style.backgroundColor, "green", "HTMLElement.style setter");
+
+    const testSVG = document.getElementById("testSVG");
+    assert_equals(testSVG.style.backgroundColor, "red", "SVGElement.style getter");
+    assert_readonly(testSVG, "style", "SVGElement.style is readonly");
+    testSVG.style = "background-color: green";
+    assert_equals(testSVG.style.backgroundColor, "green", "SVGElement.style setter");
+}, "style should be settable");
+</script>
+</body>
+</html>
index 076f09c..9b8e27d 100644 (file)
@@ -46,6 +46,7 @@ PASS a["contentEditable"] is inherit
 PASS a["isContentEditable"] is false
 PASS a["spellcheck"] is true
 PASS a["dataset"] is [object DOMStringMap]
+PASS a["style"] is [object CSSStyleDeclaration]
 PASS a["onabort"] is null
 PASS a["onblur"] is null
 PASS a["oncanplay"] is null
@@ -114,7 +115,6 @@ PASS a["classList"] is
 PASS a["slot"] is 
 PASS a["attributes"] is [object NamedNodeMap]
 PASS a["shadowRoot"] is null
-PASS a["style"] is [object CSSStyleDeclaration]
 PASS a["scrollTop"] is 0
 PASS a["scrollLeft"] is 0
 PASS a["scrollWidth"] is 0
index 020ee42..b198d77 100644 (file)
@@ -387,6 +387,7 @@ set(WebCore_NON_SVG_IDL_FILES
     css/DeprecatedCSSOMValue.idl
     css/DeprecatedCSSOMValueList.idl
     css/DOMCSSNamespace.idl
+    css/ElementCSSInlineStyle.idl
     css/FontFace.idl
     css/FontFaceSet.idl
     css/MediaList.idl
index 4b4d709..5ae1a34 100644 (file)
@@ -1,3 +1,73 @@
+2017-05-08  Chris Dumez  <cdumez@apple.com>
+
+        Move 'style' from Element to HTMLElement / SVGElement and make it settable
+        https://bugs.webkit.org/show_bug.cgi?id=171795
+
+        Reviewed by Alex Christensen.
+
+        Move 'style' from Element to HTMLElement / SVGElement and make it settable
+        as per:
+        - https://drafts.csswg.org/cssom/#the-elementcssinlinestyle-interface
+
+        Both Firefox and Chrome already match the specification (both for the
+        property location and having it settable).
+
+        Test: fast/css/Element-style.html
+
+        * CMakeLists.txt:
+        * DerivedSources.make:
+        * WebCore.xcodeproj/project.pbxproj:
+        * css/ElementCSSInlineStyle.idl: Added.
+        * css/PropertySetCSSStyleDeclaration.h:
+        * css/StyleProperties.cpp:
+        (WebCore::MutableStyleProperties::ensureCSSStyleDeclaration):
+        (WebCore::MutableStyleProperties::ensureInlineCSSStyleDeclaration):
+        * css/StyleProperties.h:
+        * dom/Attr.cpp:
+        (WebCore::Attr::style):
+        * dom/Document.cpp:
+        (WebCore::Document::createCSSStyleDeclaration):
+        * dom/Element.cpp:
+        * dom/Element.h:
+        * dom/Element.idl:
+        * dom/StyledElement.cpp:
+        (WebCore::StyledElement::cssomStyle):
+        * dom/StyledElement.h:
+        * editing/Editor.cpp:
+        (WebCore::Editor::applyEditingStyleToElement):
+        * editing/ReplaceSelectionCommand.cpp:
+        (WebCore::ReplaceSelectionCommand::removeRedundantStylesAndKeepStyleSpanInline):
+        * html/HTMLElement.idl:
+
+        * html/ImageInputType.cpp:
+        (WebCore::ImageInputType::height):
+        (WebCore::ImageInputType::width):
+        Fix bug that was found by fast/forms/input-width-height-attributes-without-renderer-loaded-image.html.
+        That test relied on setting HTMLElement.style which did not work until now. Call updateLayout()
+        *before* doing the renderer check.
+
+        * inspector/InspectorCSSAgent.cpp:
+        (WebCore::InspectorCSSAgent::getMatchedStylesForNode):
+        (WebCore::InspectorCSSAgent::getInlineStylesForNode):
+        (WebCore::InspectorCSSAgent::getComputedStyleForNode):
+        (WebCore::InspectorCSSAgent::asInspectorStyleSheet):
+        (WebCore::InspectorCSSAgent::buildObjectForAttributesStyle):
+        * inspector/InspectorCSSAgent.h:
+        * inspector/InspectorStyleSheet.cpp:
+        (WebCore::InspectorStyle::create):
+        (WebCore::InspectorStyle::InspectorStyle):
+        (WebCore::InspectorStyle::extractSourceData):
+        (WebCore::InspectorStyle::setText):
+        (WebCore::InspectorStyleSheet::inspectorStyleForId):
+        (WebCore::InspectorStyleSheetForInlineStyle::create):
+        (WebCore::InspectorStyleSheetForInlineStyle::InspectorStyleSheetForInlineStyle):
+        (WebCore::InspectorStyleSheetForInlineStyle::didModifyElementAttribute):
+        (WebCore::InspectorStyleSheetForInlineStyle::setStyleText):
+        (WebCore::InspectorStyleSheetForInlineStyle::ensureParsedDataReady):
+        (WebCore::InspectorStyleSheetForInlineStyle::inlineStyle):
+        * inspector/InspectorStyleSheet.h:
+        * svg/SVGElement.idl:
+
 2017-05-08  Joanmarie Diggs  <jdiggs@igalia.com>
 
         AX: Propagate aria-readonly to grid descendants
index 0acd29c..0a4526b 100644 (file)
@@ -323,6 +323,7 @@ JS_BINDING_IDLS = \
        $(WebCore)/css/DeprecatedCSSOMValue.idl \
     $(WebCore)/css/DeprecatedCSSOMValueList.idl \
     $(WebCore)/css/DOMCSSNamespace.idl \
+    $(WebCore)/css/ElementCSSInlineStyle.idl \
     $(WebCore)/css/FontFace.idl \
     $(WebCore)/css/FontFaceSet.idl \
     $(WebCore)/css/MediaList.idl \
index ebe6afa..4e64ed1 100644 (file)
                83765F941DAC521800C06537 /* MouseEventInit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MouseEventInit.h; sourceTree = "<group>"; };
                837A80121E1E127300026B9F /* English */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = English; path = English.lproj/Localizable.stringsdict; sourceTree = SOURCE_ROOT; };
                837B7D1F1DC3F54C00D051FC /* ValidationBubbleIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ValidationBubbleIOS.mm; sourceTree = "<group>"; };
+               837DFB341EBFEA7000601385 /* ElementCSSInlineStyle.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ElementCSSInlineStyle.idl; sourceTree = "<group>"; };
                8386A96C19F61B2E00E1EC4A /* StyleBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StyleBuilder.h; sourceTree = "<group>"; };
                8386A96E19F61E4F00E1EC4A /* StyleBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StyleBuilder.cpp; sourceTree = "<group>"; };
                838867341D13BA59003697D0 /* RenderObjectEnums.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderObjectEnums.h; sourceTree = "<group>"; };
                                FD677735195CAB200072E0D3 /* DOMCSSNamespace.cpp */,
                                FC9A0F72164094CF003D6B8D /* DOMCSSNamespace.h */,
                                FC9A0F73164094CF003D6B8D /* DOMCSSNamespace.idl */,
+                               837DFB341EBFEA7000601385 /* ElementCSSInlineStyle.idl */,
                                FBDB619A16D6032A00BB3394 /* ElementRuleCollector.cpp */,
                                FBDB619E16D6036500BB3394 /* ElementRuleCollector.h */,
                                1C66260E1C6E7CA600AB527C /* FontFace.cpp */,
diff --git a/Source/WebCore/css/ElementCSSInlineStyle.idl b/Source/WebCore/css/ElementCSSInlineStyle.idl
new file mode 100644 (file)
index 0000000..cfe7239
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// CSSOM extensions to HTMLElement / SVGElement:
+// https://drafts.csswg.org/cssom/#the-elementcssinlinestyle-interface
+[
+    NoInterfaceObject,
+] interface ElementCSSInlineStyle {
+    [ImplementedAs=cssomStyle, PutForwards=cssText] readonly attribute CSSStyleDeclaration style; // FIXME: Should be [SameObject].
+};
index 6e0e1cf..125a139 100644 (file)
@@ -346,7 +346,7 @@ Ref<MutableStyleProperties> PropertySetCSSStyleDeclaration::copyProperties() con
 }
     
 StyleRuleCSSStyleDeclaration::StyleRuleCSSStyleDeclaration(MutableStyleProperties& propertySet, CSSRule& parentRule)
-    : PropertySetCSSStyleDeclaration(&propertySet)
+    : PropertySetCSSStyleDeclaration(propertySet)
     , m_refCount(1)
     , m_parentRule(&parentRule)
 {
index 564cb1d..650259f 100644 (file)
@@ -43,7 +43,9 @@ class StyledElement;
 
 class PropertySetCSSStyleDeclaration : public CSSStyleDeclaration {
 public:
-    PropertySetCSSStyleDeclaration(MutableStyleProperties* propertySet) : m_propertySet(propertySet) { }
+    explicit PropertySetCSSStyleDeclaration(MutableStyleProperties& propertySet)
+        : m_propertySet(&propertySet)
+    { }
 
     virtual void clearParentElement() { ASSERT_NOT_REACHED(); }
 
@@ -117,9 +119,9 @@ private:
 
 class InlineCSSStyleDeclaration final : public PropertySetCSSStyleDeclaration {
 public:
-    InlineCSSStyleDeclaration(MutableStyleProperties* propertySet, StyledElement* parentElement)
+    InlineCSSStyleDeclaration(MutableStyleProperties& propertySet, StyledElement& parentElement)
         : PropertySetCSSStyleDeclaration(propertySet)
-        , m_parentElement(parentElement) 
+        , m_parentElement(&parentElement)
     {
     }
 
index a3a10a6..98d25e3 100644 (file)
@@ -1325,25 +1325,25 @@ PropertySetCSSStyleDeclaration* MutableStyleProperties::cssStyleDeclaration()
     return m_cssomWrapper.get();
 }
 
-CSSStyleDeclaration* MutableStyleProperties::ensureCSSStyleDeclaration()
+CSSStyleDeclaration& MutableStyleProperties::ensureCSSStyleDeclaration()
 {
     if (m_cssomWrapper) {
         ASSERT(!static_cast<CSSStyleDeclaration*>(m_cssomWrapper.get())->parentRule());
         ASSERT(!m_cssomWrapper->parentElement());
-        return m_cssomWrapper.get();
+        return *m_cssomWrapper;
     }
-    m_cssomWrapper = std::make_unique<PropertySetCSSStyleDeclaration>(this);
-    return m_cssomWrapper.get();
+    m_cssomWrapper = std::make_unique<PropertySetCSSStyleDeclaration>(*this);
+    return *m_cssomWrapper;
 }
 
-CSSStyleDeclaration* MutableStyleProperties::ensureInlineCSSStyleDeclaration(StyledElement* parentElement)
+CSSStyleDeclaration& MutableStyleProperties::ensureInlineCSSStyleDeclaration(StyledElement& parentElement)
 {
     if (m_cssomWrapper) {
-        ASSERT(m_cssomWrapper->parentElement() == parentElement);
-        return m_cssomWrapper.get();
+        ASSERT(m_cssomWrapper->parentElement() == &parentElement);
+        return *m_cssomWrapper;
     }
-    m_cssomWrapper = std::make_unique<InlineCSSStyleDeclaration>(this, parentElement);
-    return m_cssomWrapper.get();
+    m_cssomWrapper = std::make_unique<InlineCSSStyleDeclaration>(*this, parentElement);
+    return *m_cssomWrapper;
 }
 
 unsigned StyleProperties::averageSizeInBytes()
index fd9fca3..06d15df 100644 (file)
@@ -236,8 +236,8 @@ public:
     void clear();
     bool parseDeclaration(const String& styleDeclaration, CSSParserContext);
 
-    WEBCORE_EXPORT CSSStyleDeclaration* ensureCSSStyleDeclaration();
-    CSSStyleDeclaration* ensureInlineCSSStyleDeclaration(StyledElement* parentElement);
+    WEBCORE_EXPORT CSSStyleDeclaration& ensureCSSStyleDeclaration();
+    CSSStyleDeclaration& ensureInlineCSSStyleDeclaration(StyledElement& parentElement);
 
     int findPropertyIndex(CSSPropertyID) const;
     int findCustomPropertyIndex(const String& propertyName) const;
index f045fc8..0a4dc48 100644 (file)
@@ -123,7 +123,7 @@ CSSStyleDeclaration* Attr::style()
         return nullptr;
     m_style = MutableStyleProperties::create();
     downcast<StyledElement>(*m_element).collectStyleForPresentationAttribute(qualifiedName(), value(), *m_style);
-    return m_style->ensureCSSStyleDeclaration();
+    return &m_style->ensureCSSStyleDeclaration();
 }
 
 const AtomicString& Attr::value() const
index 5071bea..ca25fca 100644 (file)
@@ -927,7 +927,7 @@ Ref<Text> Document::createEditingTextNode(const String& text)
 Ref<CSSStyleDeclaration> Document::createCSSStyleDeclaration()
 {
     Ref<MutableStyleProperties> propertySet(MutableStyleProperties::create());
-    return *propertySet->ensureCSSStyleDeclaration();
+    return propertySet->ensureCSSStyleDeclaration();
 }
 
 ExceptionOr<Ref<Node>> Document::importNode(Node& nodeToImport, bool deep)
index a47f6d6..3a165da 100644 (file)
@@ -2367,11 +2367,6 @@ bool Element::hasAttributeNS(const AtomicString& namespaceURI, const AtomicStrin
     return elementData()->findAttributeByName(qName);
 }
 
-CSSStyleDeclaration* Element::cssomStyle()
-{
-    return nullptr;
-}
-
 void Element::focus(bool restorePreviousSelection, FocusDirection direction)
 {
     if (!isConnected())
index 56fadb4..941469b 100644 (file)
@@ -197,8 +197,6 @@ public:
 
     const Vector<RefPtr<Attr>>& attrNodeList();
 
-    virtual CSSStyleDeclaration* cssomStyle();
-
     const QualifiedName& tagQName() const { return m_tagName; }
 #if ENABLE(JIT)
     static ptrdiff_t tagQNameMemoryOffset() { return OBJECT_OFFSETOF(Element, m_tagName); }
index 44d48b3..9e60b9e 100644 (file)
     [CEReactions, MayThrowException] Element? insertAdjacentElement(DOMString where, Element element); // Historical.
     [MayThrowException] void insertAdjacentText(DOMString where, DOMString data); // Historical.
 
-    // FIXME: Should be in a separate ElementCSSInlineStyle and implemented by HTMLElement / SVGElement.
-    // https://drafts.csswg.org/cssom/#the-elementcssinlinestyle-interface
-    [ImplementedAs=cssomStyle] readonly attribute CSSStyleDeclaration style; // FIXME: Should be [SameObject, PutForwards=cssText].
-
     // CSSOM-view extensions (https://drafts.csswg.org/cssom-view/#extension-to-the-element-interface).
     sequence<DOMRect> getClientRects();
     [NewObject] DOMRect getBoundingClientRect();
index 2ee9997..2cbe78e 100644 (file)
@@ -61,9 +61,9 @@ StyledElement::~StyledElement()
         cssomWrapper->clearParentElement();
 }
 
-CSSStyleDeclaration* StyledElement::cssomStyle()
+CSSStyleDeclaration& StyledElement::cssomStyle()
 {
-    return ensureMutableInlineStyle().ensureInlineCSSStyleDeclaration(this);
+    return ensureMutableInlineStyle().ensureInlineCSSStyleDeclaration(*this);
 }
 
 MutableStyleProperties& StyledElement::ensureMutableInlineStyle()
index 442041c..31b8fb3 100644 (file)
@@ -55,7 +55,7 @@ public:
     static void synchronizeStyleAttributeInternal(StyledElement*);
     void synchronizeStyleAttributeInternal() const { StyledElement::synchronizeStyleAttributeInternal(const_cast<StyledElement*>(this)); }
     
-    CSSStyleDeclaration* cssomStyle() final;
+    WEBCORE_EXPORT CSSStyleDeclaration& cssomStyle();
 
     const StyleProperties* presentationAttributeStyle() const;
     virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStyleProperties&) { }
index 3bc7fc7..5259d33 100644 (file)
@@ -3103,10 +3103,10 @@ void Editor::applyEditingStyleToElement(Element* element) const
         return;
 
     // Mutate using the CSSOM wrapper so we get the same event behavior as a script.
-    CSSStyleDeclaration* style = downcast<StyledElement>(*element).cssomStyle();
-    style->setPropertyInternal(CSSPropertyWordWrap, "break-word", false);
-    style->setPropertyInternal(CSSPropertyWebkitNbspMode, "space", false);
-    style->setPropertyInternal(CSSPropertyLineBreak, "after-white-space", false);
+    auto& style = downcast<StyledElement>(*element).cssomStyle();
+    style.setPropertyInternal(CSSPropertyWordWrap, "break-word", false);
+    style.setPropertyInternal(CSSPropertyWebkitNbspMode, "space", false);
+    style.setPropertyInternal(CSSPropertyLineBreak, "after-white-space", false);
 }
 
 bool Editor::findString(const String& target, FindOptions options)
index a4e4863..270f850 100644 (file)
@@ -556,9 +556,9 @@ void ReplaceSelectionCommand::removeRedundantStylesAndKeepStyleSpanInline(Insert
 
             // Mutate using the CSSOM wrapper so we get the same event behavior as a script.
             if (isBlock(element))
-                element->cssomStyle()->setPropertyInternal(CSSPropertyDisplay, "inline", false);
+                element->cssomStyle().setPropertyInternal(CSSPropertyDisplay, "inline", false);
             if (element->renderer() && element->renderer()->style().isFloating())
-                element->cssomStyle()->setPropertyInternal(CSSPropertyFloat, "none", false);
+                element->cssomStyle().setPropertyInternal(CSSPropertyFloat, "none", false);
         }
     }
 }
index ffd7641..59a4504 100644 (file)
@@ -57,4 +57,5 @@
     readonly attribute DOMStringMap dataset;
 };
 
+HTMLElement implements ElementCSSInlineStyle;
 HTMLElement implements GlobalEventHandlers;
index b211be9..e94b174 100644 (file)
@@ -177,6 +177,8 @@ unsigned ImageInputType::height() const
 {
     Ref<HTMLInputElement> element(this->element());
 
+    element->document().updateLayout();
+
     if (!element->renderer()) {
         // Check the attribute first for an explicit pixel value.
         if (auto optionalHeight = parseHTMLNonNegativeInteger(element->attributeWithoutSynchronization(heightAttr)))
@@ -188,8 +190,6 @@ unsigned ImageInputType::height() const
             return imageLoader->image()->imageSizeForRenderer(element->renderer(), 1).height().toUnsigned();
     }
 
-    element->document().updateLayout();
-
     RenderBox* box = element->renderBox();
     return box ? adjustForAbsoluteZoom(box->contentHeight(), *box) : 0;
 }
@@ -198,6 +198,8 @@ unsigned ImageInputType::width() const
 {
     Ref<HTMLInputElement> element(this->element());
 
+    element->document().updateLayout();
+
     if (!element->renderer()) {
         // Check the attribute first for an explicit pixel value.
         if (auto optionalWidth = parseHTMLNonNegativeInteger(element->attributeWithoutSynchronization(widthAttr)))
@@ -209,8 +211,6 @@ unsigned ImageInputType::width() const
             return imageLoader->image()->imageSizeForRenderer(element->renderer(), 1).width().toUnsigned();
     }
 
-    element->document().updateLayout();
-
     RenderBox* box = element->renderBox();
     return box ? adjustForAbsoluteZoom(box->contentWidth(), *box) : 0;
 }
index 7c1992f..a7c13b8 100644 (file)
@@ -606,9 +606,9 @@ void InspectorCSSAgent::getMatchedStylesForNode(ErrorString& errorString, int no
                 auto entry = Inspector::Protocol::CSS::InheritedStyleEntry::create()
                     .setMatchedCSSRules(buildArrayForMatchedRuleList(parentMatchedRules, styleResolver, *parentElement, NOPSEUDO))
                     .release();
-                if (parentElement->cssomStyle() && parentElement->cssomStyle()->length()) {
-                    if (InspectorStyleSheetForInlineStyle* styleSheet = asInspectorStyleSheet(parentElement))
-                        entry->setInlineStyle(styleSheet->buildObjectForStyle(styleSheet->styleForId(InspectorCSSId(styleSheet->id(), 0))));
+                if (is<StyledElement>(*parentElement) && downcast<StyledElement>(*parentElement).cssomStyle().length()) {
+                    auto& styleSheet = asInspectorStyleSheet(downcast<StyledElement>(*parentElement));
+                    entry->setInlineStyle(styleSheet.buildObjectForStyle(styleSheet.styleForId(InspectorCSSId(styleSheet.id(), 0))));
                 }
 
                 entries->addItem(WTFMove(entry));
@@ -622,16 +622,14 @@ void InspectorCSSAgent::getMatchedStylesForNode(ErrorString& errorString, int no
 
 void InspectorCSSAgent::getInlineStylesForNode(ErrorString& errorString, int nodeId, RefPtr<Inspector::Protocol::CSS::CSSStyle>& inlineStyle, RefPtr<Inspector::Protocol::CSS::CSSStyle>& attributesStyle)
 {
-    Element* element = elementForId(errorString, nodeId);
-    if (!element)
-        return;
-
-    InspectorStyleSheetForInlineStyle* styleSheet = asInspectorStyleSheet(element);
-    if (!styleSheet)
+    auto* element = elementForId(errorString, nodeId);
+    if (!is<StyledElement>(element))
         return;
 
-    inlineStyle = styleSheet->buildObjectForStyle(element->cssomStyle());
-    if (auto attributes = buildObjectForAttributesStyle(element))
+    auto& styledElement = downcast<StyledElement>(*element);
+    auto& styleSheet = asInspectorStyleSheet(styledElement);
+    inlineStyle = styleSheet.buildObjectForStyle(&styledElement.cssomStyle());
+    if (auto attributes = buildObjectForAttributesStyle(styledElement))
         attributesStyle = WTFMove(attributes);
     else
         attributesStyle = nullptr;
@@ -639,12 +637,12 @@ void InspectorCSSAgent::getInlineStylesForNode(ErrorString& errorString, int nod
 
 void InspectorCSSAgent::getComputedStyleForNode(ErrorString& errorString, int nodeId, RefPtr<Inspector::Protocol::Array<Inspector::Protocol::CSS::CSSComputedStyleProperty>>& style)
 {
-    Element* element = elementForId(errorString, nodeId);
+    auto* element = elementForId(errorString, nodeId);
     if (!element)
         return;
 
-    RefPtr<CSSComputedStyleDeclaration> computedStyleInfo = CSSComputedStyleDeclaration::create(*element, true);
-    Ref<InspectorStyle> inspectorStyle = InspectorStyle::create(InspectorCSSId(), computedStyleInfo, nullptr);
+    auto computedStyleInfo = CSSComputedStyleDeclaration::create(*element, true);
+    auto inspectorStyle = InspectorStyle::create(InspectorCSSId(), WTFMove(computedStyleInfo), nullptr);
     style = inspectorStyle->buildArrayForComputedStyle();
 }
 
@@ -920,22 +918,19 @@ void InspectorCSSAgent::getNamedFlowCollection(ErrorString& errorString, int doc
     result = WTFMove(namedFlows);
 }
 
-InspectorStyleSheetForInlineStyle* InspectorCSSAgent::asInspectorStyleSheet(Element* element)
+InspectorStyleSheetForInlineStyle& InspectorCSSAgent::asInspectorStyleSheet(StyledElement& element)
 {
-    NodeToInspectorStyleSheet::iterator it = m_nodeToInspectorStyleSheet.find(element);
+    auto it = m_nodeToInspectorStyleSheet.find(&element);
     if (it == m_nodeToInspectorStyleSheet.end()) {
-        CSSStyleDeclaration* style = element->cssomStyle();
-        if (!style)
-            return nullptr;
-
         String newStyleSheetId = String::number(m_lastStyleSheetId++);
-        RefPtr<InspectorStyleSheetForInlineStyle> inspectorStyleSheet = InspectorStyleSheetForInlineStyle::create(m_domAgent->pageAgent(), newStyleSheetId, element, Inspector::Protocol::CSS::StyleSheetOrigin::Regular, this);
-        m_idToInspectorStyleSheet.set(newStyleSheetId, inspectorStyleSheet);
-        m_nodeToInspectorStyleSheet.set(element, inspectorStyleSheet);
-        return inspectorStyleSheet.get();
+        auto inspectorStyleSheet = InspectorStyleSheetForInlineStyle::create(m_domAgent->pageAgent(), newStyleSheetId, element, Inspector::Protocol::CSS::StyleSheetOrigin::Regular, this);
+        auto& inspectorStyleSheetRef = inspectorStyleSheet.get();
+        m_idToInspectorStyleSheet.set(newStyleSheetId, inspectorStyleSheet.copyRef());
+        m_nodeToInspectorStyleSheet.set(&element, WTFMove(inspectorStyleSheet));
+        return inspectorStyleSheetRef;
     }
 
-    return it->value.get();
+    return *it->value;
 }
 
 Element* InspectorCSSAgent::elementForId(ErrorString& errorString, int nodeId)
@@ -1085,21 +1080,15 @@ RefPtr<Inspector::Protocol::Array<Inspector::Protocol::CSS::RuleMatch>> Inspecto
     return WTFMove(result);
 }
 
-RefPtr<Inspector::Protocol::CSS::CSSStyle> InspectorCSSAgent::buildObjectForAttributesStyle(Element* element)
+RefPtr<Inspector::Protocol::CSS::CSSStyle> InspectorCSSAgent::buildObjectForAttributesStyle(StyledElement& element)
 {
-    ASSERT(element);
-    if (!is<StyledElement>(*element))
-        return nullptr;
-
     // FIXME: Ugliness below.
-    StyleProperties* attributeStyle = const_cast<StyleProperties*>(downcast<StyledElement>(element)->presentationAttributeStyle());
+    auto* attributeStyle = const_cast<StyleProperties*>(element.presentationAttributeStyle());
     if (!attributeStyle)
         return nullptr;
 
-    ASSERT_WITH_SECURITY_IMPLICATION(attributeStyle->isMutable());
-    MutableStyleProperties* mutableAttributeStyle = static_cast<MutableStyleProperties*>(attributeStyle);
-
-    Ref<InspectorStyle> inspectorStyle = InspectorStyle::create(InspectorCSSId(), mutableAttributeStyle->ensureCSSStyleDeclaration(), nullptr);
+    auto& mutableAttributeStyle = downcast<MutableStyleProperties>(*attributeStyle);
+    auto inspectorStyle = InspectorStyle::create(InspectorCSSId(), mutableAttributeStyle.ensureCSSStyleDeclaration(), nullptr);
     return inspectorStyle->buildObjectForStyle();
 }
 
index 78ebca7..687700a 100644 (file)
@@ -135,7 +135,7 @@ private:
     typedef HashMap<int, unsigned> NodeIdToForcedPseudoState;
 
     void resetNonPersistentData();
-    InspectorStyleSheetForInlineStyle* asInspectorStyleSheet(Element* element);
+    InspectorStyleSheetForInlineStyle& asInspectorStyleSheet(StyledElement&);
     Element* elementForId(ErrorString&, int nodeId);
     int documentNodeWithRequestedFlowsId(Document*);
 
@@ -153,7 +153,7 @@ private:
     RefPtr<Inspector::Protocol::CSS::CSSRule> buildObjectForRule(StyleRule*, StyleResolver&, Element&);
     RefPtr<Inspector::Protocol::CSS::CSSRule> buildObjectForRule(CSSStyleRule*);
     RefPtr<Inspector::Protocol::Array<Inspector::Protocol::CSS::RuleMatch>> buildArrayForMatchedRuleList(const Vector<RefPtr<StyleRule>>&, StyleResolver&, Element&, PseudoId);
-    RefPtr<Inspector::Protocol::CSS::CSSStyle> buildObjectForAttributesStyle(Element*);
+    RefPtr<Inspector::Protocol::CSS::CSSStyle> buildObjectForAttributesStyle(StyledElement&);
     RefPtr<Inspector::Protocol::Array<Inspector::Protocol::CSS::Region>> buildArrayForRegions(ErrorString&, RefPtr<NodeList>&&, int documentNodeId);
     RefPtr<Inspector::Protocol::CSS::NamedFlow> buildObjectForNamedFlow(ErrorString&, WebKitNamedFlow*, int documentNodeId);
 
index 6b0a8ee..63c448d 100644 (file)
@@ -518,17 +518,16 @@ static void fillMediaListChain(CSSRule* rule, Array<Inspector::Protocol::CSS::CS
     }
 }
 
-Ref<InspectorStyle> InspectorStyle::create(const InspectorCSSId& styleId, RefPtr<CSSStyleDeclaration>&& style, InspectorStyleSheet* parentStyleSheet)
+Ref<InspectorStyle> InspectorStyle::create(const InspectorCSSId& styleId, Ref<CSSStyleDeclaration>&& style, InspectorStyleSheet* parentStyleSheet)
 {
     return adoptRef(*new InspectorStyle(styleId, WTFMove(style), parentStyleSheet));
 }
 
-InspectorStyle::InspectorStyle(const InspectorCSSId& styleId, RefPtr<CSSStyleDeclaration>&& style, InspectorStyleSheet* parentStyleSheet)
+InspectorStyle::InspectorStyle(const InspectorCSSId& styleId, Ref<CSSStyleDeclaration>&& style, InspectorStyleSheet* parentStyleSheet)
     : m_styleId(styleId)
-    , m_style(style)
+    , m_style(WTFMove(style))
     , m_parentStyleSheet(parentStyleSheet)
 {
-    ASSERT(m_style);
 }
 
 InspectorStyle::~InspectorStyle()
@@ -745,12 +744,12 @@ RefPtr<CSSRuleSourceData> InspectorStyle::extractSourceData() const
 {
     if (!m_parentStyleSheet || !m_parentStyleSheet->ensureParsedDataReady())
         return nullptr;
-    return m_parentStyleSheet->ruleSourceDataFor(m_style.get());
+    return m_parentStyleSheet->ruleSourceDataFor(m_style.ptr());
 }
 
 ExceptionOr<void> InspectorStyle::setText(const String& text)
 {
-    return m_parentStyleSheet->setStyleText(m_style.get(), text);
+    return m_parentStyleSheet->setStyleText(m_style.ptr(), text);
 }
 
 String InspectorStyle::shorthandValue(const String& shorthandProperty) const
@@ -1257,7 +1256,7 @@ RefPtr<InspectorStyle> InspectorStyleSheet::inspectorStyleForId(const InspectorC
     if (!style)
         return nullptr;
 
-    return InspectorStyle::create(id, style, this);
+    return InspectorStyle::create(id, *style, this);
 }
 
 InspectorCSSId InspectorStyleSheet::ruleOrStyleId(CSSStyleDeclaration* style) const
@@ -1472,26 +1471,25 @@ void InspectorStyleSheet::collectFlatRules(RefPtr<CSSRuleList>&& ruleList, CSSSt
     }
 }
 
-Ref<InspectorStyleSheetForInlineStyle> InspectorStyleSheetForInlineStyle::create(InspectorPageAgent* pageAgent, const String& id, RefPtr<Element>&& element, Inspector::Protocol::CSS::StyleSheetOrigin origin, Listener* listener)
+Ref<InspectorStyleSheetForInlineStyle> InspectorStyleSheetForInlineStyle::create(InspectorPageAgent* pageAgent, const String& id, Ref<StyledElement>&& element, Inspector::Protocol::CSS::StyleSheetOrigin origin, Listener* listener)
 {
     return adoptRef(*new InspectorStyleSheetForInlineStyle(pageAgent, id, WTFMove(element), origin, listener));
 }
 
-InspectorStyleSheetForInlineStyle::InspectorStyleSheetForInlineStyle(InspectorPageAgent* pageAgent, const String& id, RefPtr<Element>&& element, Inspector::Protocol::CSS::StyleSheetOrigin origin, Listener* listener)
+InspectorStyleSheetForInlineStyle::InspectorStyleSheetForInlineStyle(InspectorPageAgent* pageAgent, const String& id, Ref<StyledElement>&& element, Inspector::Protocol::CSS::StyleSheetOrigin origin, Listener* listener)
     : InspectorStyleSheet(pageAgent, id, nullptr, origin, String(), listener)
     , m_element(WTFMove(element))
     , m_ruleSourceData(nullptr)
     , m_isStyleTextValid(false)
 {
-    ASSERT(m_element);
     m_inspectorStyle = InspectorStyle::create(InspectorCSSId(id, 0), inlineStyle(), this);
-    m_styleText = m_element->isStyledElement() ? m_element->getAttribute("style").string() : String();
+    m_styleText = m_element->getAttribute("style").string();
 }
 
 void InspectorStyleSheetForInlineStyle::didModifyElementAttribute()
 {
     m_isStyleTextValid = false;
-    if (m_element->isStyledElement() && m_element->cssomStyle() != m_inspectorStyle->cssStyle())
+    if (&m_element->cssomStyle() != &m_inspectorStyle->cssStyle())
         m_inspectorStyle = InspectorStyle::create(InspectorCSSId(id(), 0), inlineStyle(), this);
     m_ruleSourceData = nullptr;
 }
@@ -1507,7 +1505,7 @@ ExceptionOr<String> InspectorStyleSheetForInlineStyle::text() const
 
 ExceptionOr<void> InspectorStyleSheetForInlineStyle::setStyleText(CSSStyleDeclaration* style, const String& text)
 {
-    ASSERT_UNUSED(style, style == inlineStyle());
+    ASSERT_UNUSED(style, style == &inlineStyle());
 
     {
         InspectorCSSAgent::InlineStyleOverrideScope overrideScope(m_element->document());
@@ -1544,9 +1542,6 @@ bool InspectorStyleSheetForInlineStyle::ensureParsedDataReady()
     if (m_ruleSourceData)
         return true;
 
-    if (!m_element->isStyledElement())
-        return false;
-
     m_ruleSourceData = ruleSourceData();
     return true;
 }
@@ -1557,7 +1552,7 @@ RefPtr<InspectorStyle> InspectorStyleSheetForInlineStyle::inspectorStyleForId(co
     return m_inspectorStyle.copyRef();
 }
 
-CSSStyleDeclaration* InspectorStyleSheetForInlineStyle::inlineStyle() const
+CSSStyleDeclaration& InspectorStyleSheetForInlineStyle::inlineStyle() const
 {
     return m_element->cssomStyle();
 }
index df95d1c..2f31f30 100644 (file)
@@ -122,10 +122,10 @@ struct InspectorStyleProperty {
 
 class InspectorStyle final : public RefCounted<InspectorStyle> {
 public:
-    static Ref<InspectorStyle> create(const InspectorCSSId& styleId, RefPtr<CSSStyleDeclaration>&&, InspectorStyleSheet* parentStyleSheet);
+    static Ref<InspectorStyle> create(const InspectorCSSId& styleId, Ref<CSSStyleDeclaration>&&, InspectorStyleSheet* parentStyleSheet);
     ~InspectorStyle();
 
-    CSSStyleDeclaration* cssStyle() const { return m_style.get(); }
+    CSSStyleDeclaration& cssStyle() const { return m_style.get(); }
     RefPtr<Inspector::Protocol::CSS::CSSStyle> buildObjectForStyle() const;
     Ref<Inspector::Protocol::Array<Inspector::Protocol::CSS::CSSComputedStyleProperty>> buildArrayForComputedStyle() const;
 
@@ -133,7 +133,7 @@ public:
     ExceptionOr<void> setText(const String&);
 
 private:
-    InspectorStyle(const InspectorCSSId& styleId, RefPtr<CSSStyleDeclaration>&&, InspectorStyleSheet* parentStyleSheet);
+    InspectorStyle(const InspectorCSSId& styleId, Ref<CSSStyleDeclaration>&&, InspectorStyleSheet* parentStyleSheet);
 
     void populateAllProperties(Vector<InspectorStyleProperty>* result) const;
     Ref<Inspector::Protocol::CSS::CSSStyle> styleWithProperties() const;
@@ -143,7 +143,7 @@ private:
     Vector<String> longhandProperties(const String& shorthandProperty) const;
 
     InspectorCSSId m_styleId;
-    RefPtr<CSSStyleDeclaration> m_style;
+    Ref<CSSStyleDeclaration> m_style;
     InspectorStyleSheet* m_parentStyleSheet;
 };
 
@@ -229,17 +229,17 @@ private:
 
 class InspectorStyleSheetForInlineStyle final : public InspectorStyleSheet {
 public:
-    static Ref<InspectorStyleSheetForInlineStyle> create(InspectorPageAgent*, const String& id, RefPtr<Element>&&, Inspector::Protocol::CSS::StyleSheetOrigin, Listener*);
+    static Ref<InspectorStyleSheetForInlineStyle> create(InspectorPageAgent*, const String& id, Ref<StyledElement>&&, Inspector::Protocol::CSS::StyleSheetOrigin, Listener*);
 
     void didModifyElementAttribute();
     ExceptionOr<String> text() const final;
-    CSSStyleDeclaration* styleForId(const InspectorCSSId& id) const final { ASSERT_UNUSED(id, !id.ordinal()); return inlineStyle(); }
+    CSSStyleDeclaration* styleForId(const InspectorCSSId& id) const final { ASSERT_UNUSED(id, !id.ordinal()); return &inlineStyle(); }
 
 protected:
-    InspectorStyleSheetForInlineStyle(InspectorPageAgent*, const String& id, RefPtr<Element>&&, Inspector::Protocol::CSS::StyleSheetOrigin, Listener*);
+    InspectorStyleSheetForInlineStyle(InspectorPageAgent*, const String& id, Ref<StyledElement>&&, Inspector::Protocol::CSS::StyleSheetOrigin, Listener*);
 
     Document* ownerDocument() const final;
-    RefPtr<CSSRuleSourceData> ruleSourceDataFor(CSSStyleDeclaration* style) const final { ASSERT_UNUSED(style, style == inlineStyle()); return m_ruleSourceData; }
+    RefPtr<CSSRuleSourceData> ruleSourceDataFor(CSSStyleDeclaration* style) const final { ASSERT_UNUSED(style, style == &inlineStyle()); return m_ruleSourceData; }
     unsigned ruleIndexByStyle(CSSStyleDeclaration*) const final { return 0; }
     bool ensureParsedDataReady() final;
     RefPtr<InspectorStyle> inspectorStyleForId(const InspectorCSSId&) final;
@@ -249,11 +249,11 @@ protected:
     std::unique_ptr<Vector<size_t>> lineEndings() const final;
 
 private:
-    CSSStyleDeclaration* inlineStyle() const;
+    CSSStyleDeclaration& inlineStyle() const;
     const String& elementStyleText() const;
     Ref<CSSRuleSourceData> ruleSourceData() const;
 
-    RefPtr<Element> m_element;
+    Ref<StyledElement> m_element;
     RefPtr<CSSRuleSourceData> m_ruleSourceData;
     RefPtr<InspectorStyle> m_inspectorStyle;
 
index fcb64ae..42e20fe 100644 (file)
@@ -30,7 +30,6 @@
     attribute DOMString xmlspace;
 
     readonly attribute SVGAnimatedString className;
-    [ImplementedAs=cssomStyle] readonly attribute CSSStyleDeclaration style;
 
     attribute long tabIndex;
 
@@ -44,4 +43,5 @@
     readonly attribute DOMStringMap dataset;
 };
 
+SVGElement implements ElementCSSInlineStyle;
 SVGElement implements GlobalEventHandlers;
index 1e79a57..364c90e 100644 (file)
@@ -1,3 +1,19 @@
+2017-05-08  Chris Dumez  <cdumez@apple.com>
+
+        Move 'style' from Element to HTMLElement / SVGElement and make it settable
+        https://bugs.webkit.org/show_bug.cgi?id=171795
+
+        Reviewed by Alex Christensen.
+
+        Build fix.
+
+        * DOM/DOMElement.mm:
+        (-[DOMElement style]):
+        * WebCoreSupport/WebEditorClient.mm:
+        (WebEditorClient::shouldApplyStyle):
+        * WebView/WebFrame.mm:
+        (-[WebFrame _typingStyle]):
+
 2017-05-06  Chris Dumez  <cdumez@apple.com>
 
         Align our IDL files with the latest DOM specification
index 6d183c9..e7aae7d 100644 (file)
@@ -41,6 +41,7 @@
 #import <WebCore/NameNodeList.h>
 #import <WebCore/NodeList.h>
 #import <WebCore/StyleProperties.h>
+#import <WebCore/StyledElement.h>
 #import <WebCore/ThreadCheck.h>
 #import <WebCore/WebScriptObjectPrivate.h>
 
@@ -72,7 +73,8 @@ DOMElement *kit(WebCore::Element* value)
 - (DOMCSSStyleDeclaration *)style
 {
     WebCore::JSMainThreadNullState state;
-    return kit(unwrap(*self).cssomStyle());
+    auto& element = unwrap(*self);
+    return is<WebCore::StyledElement>(element) ? kit(&downcast<WebCore::StyledElement>(element).cssomStyle()) : nullptr;
 }
 
 - (int)offsetLeft
index 266db49..249f950 100644 (file)
@@ -254,7 +254,7 @@ bool WebEditorClient::shouldApplyStyle(StyleProperties* style, Range* range)
 {
     Ref<MutableStyleProperties> mutableStyle(style->isMutable() ? Ref<MutableStyleProperties>(static_cast<MutableStyleProperties&>(*style)) : style->mutableCopy());
     return [[m_webView _editingDelegateForwarder] webView:m_webView
-        shouldApplyStyle:kit(mutableStyle->ensureCSSStyleDeclaration()) toElementsInDOMRange:kit(range)];
+        shouldApplyStyle:kit(&mutableStyle->ensureCSSStyleDeclaration()) toElementsInDOMRange:kit(range)];
 }
 
 static void updateFontPanel(WebView *webView)
index 58195ee..3685e2c 100644 (file)
@@ -921,7 +921,7 @@ static inline WebDataSource *dataSource(DocumentLoader* loader)
     RefPtr<MutableStyleProperties> typingStyle = _private->coreFrame->selection().copyTypingStyle();
     if (!typingStyle)
         return nil;
-    return kit(typingStyle->ensureCSSStyleDeclaration());
+    return kit(&typingStyle->ensureCSSStyleDeclaration());
 }
 
 - (void)_setTypingStyle:(DOMCSSStyleDeclaration *)style withUndoAction:(EditAction)undoAction
index 95e0eee..f0b3ced 100644 (file)
@@ -2105,7 +2105,7 @@ static NSMutableSet *knownPluginMIMETypes()
     auto* style = editingStyle->style();
     if (!style)
         return nil;
-    return kit(style->ensureCSSStyleDeclaration());
+    return kit(&style->ensureCSSStyleDeclaration());
 }
 
 - (NSUInteger)_renderTreeSize
index 91fe364..1e7130e 100644 (file)
@@ -54,6 +54,7 @@
 #include <WebCore/Range.h>
 #include <WebCore/RenderElement.h>
 #include <WebCore/RenderTreeAsText.h>
+#include <WebCore/StyledElement.h>
 
 #include <initguid.h>
 // {3B0C0EFF-478B-4b0b-8290-D2321E08E23E}
@@ -1350,14 +1351,10 @@ HRESULT DOMElement::style(_COM_Outptr_opt_ IDOMCSSStyleDeclaration** result)
     if (!result)
         return E_POINTER;
     *result = nullptr;
-    if (!m_element)
-        return E_FAIL;
-
-    WebCore::CSSStyleDeclaration* style = m_element->cssomStyle();
-    if (!style)
+    if (!is<WebCore::StyledElement>(m_element))
         return E_FAIL;
 
-    *result = DOMCSSStyleDeclaration::createInstance(style);
+    *result = DOMCSSStyleDeclaration::createInstance(&downcast<WebCore::StyledElement>(*m_element).cssomStyle());
     return *result ? S_OK : E_FAIL;
 }
 
index 4de3f65..b7bfc05 100644 (file)
@@ -1,3 +1,15 @@
+2017-05-08  Chris Dumez  <cdumez@apple.com>
+
+        Move 'style' from Element to HTMLElement / SVGElement and make it settable
+        https://bugs.webkit.org/show_bug.cgi?id=171795
+
+        Reviewed by Alex Christensen.
+
+        Build fix.
+
+        * WebProcess/WebCoreSupport/WebEditorClient.cpp:
+        (WebKit::WebEditorClient::shouldApplyStyle):
+
 2017-05-07  Simon Fraser  <simon.fraser@apple.com>
 
         [iOS] REGRESSION (r209409): getBoundingClientRect is wrong for fixed-position elements in resize/orientationchange
index 59a15d3..b5675a0 100644 (file)
@@ -29,6 +29,7 @@
 #include "GObjectEventListener.h"
 #include <WebCore/HTMLNames.h>
 #include <WebCore/JSMainThreadExecState.h>
+#include <WebCore/StyledElement.h>
 #include "WebKitDOMAttrPrivate.h"
 #include "WebKitDOMCSSStyleDeclarationPrivate.h"
 #include "WebKitDOMClientRectListPrivate.h"
@@ -1049,9 +1050,10 @@ WebKitDOMCSSStyleDeclaration* webkit_dom_element_get_style(WebKitDOMElement* sel
 {
     WebCore::JSMainThreadNullState state;
     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
-    WebCore::Element* item = WebKit::core(self);
-    RefPtr<WebCore::CSSStyleDeclaration> gobjectResult = WTF::getPtr(item->cssomStyle());
-    return WebKit::kit(gobjectResult.get());
+    auto& item = *WebKit::core(self);
+    if (!is<WebCore::StyledElement>(item))
+        return nullptr;
+    return WebKit::kit(&downcast<WebCore::StyledElement>(item).cssomStyle());
 }
 
 gchar* webkit_dom_element_get_id(WebKitDOMElement* self)
index c999eff..3faee19 100644 (file)
@@ -151,7 +151,7 @@ bool WebEditorClient::shouldChangeSelectedRange(Range* fromRange, Range* toRange
 bool WebEditorClient::shouldApplyStyle(StyleProperties* style, Range* range)
 {
     Ref<MutableStyleProperties> mutableStyle(style->isMutable() ? Ref<MutableStyleProperties>(static_cast<MutableStyleProperties&>(*style)) : style->mutableCopy());
-    bool result = m_page->injectedBundleEditorClient().shouldApplyStyle(*m_page, mutableStyle->ensureCSSStyleDeclaration(), range);
+    bool result = m_page->injectedBundleEditorClient().shouldApplyStyle(*m_page, &mutableStyle->ensureCSSStyleDeclaration(), range);
     notImplemented();
     return result;
 }