[LayoutReloaded] Introduce FormattingState (Block/Inline/etc)
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Mar 2018 15:12:33 +0000 (15:12 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Mar 2018 15:12:33 +0000 (15:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=183777

Reviewed by Antti Koivisto.

This is in preparation for moving out states from the formatting contexts.

* LayoutReloaded/FormattingContext/BlockFormatting/BlockFormattingContext.js:
(BlockFormattingContext):
* LayoutReloaded/FormattingContext/FormattingContext.js:
(FormattingContext):
(FormattingContext.prototype.layoutState):
(FormattingContext.prototype.layoutContext):
(FormattingContext.prototype.layout):
* LayoutReloaded/FormattingContext/InlineFormatting/InlineFormattingContext.js:
(InlineFormattingContext):
* LayoutReloaded/FormattingState/BlockFormattingState.js: Copied from Tools/LayoutReloaded/LayoutContext.js.
(BlockFormattingState):
* LayoutReloaded/FormattingState/FormattingState.js: Copied from Tools/LayoutReloaded/LayoutContext.js.
(FormattingState):
(FormattingState.prototype.formattingContext):
(FormattingState.prototype.layoutContext):
(FormattingState.prototype._setFormattingContext):
* LayoutReloaded/FormattingState/InlineFormattingState.js: Copied from Tools/LayoutReloaded/LayoutContext.js.
(InlineFormattingState):
* LayoutReloaded/LayoutContext.js:
(LayoutContext):
(LayoutContext.prototype.layout):
(LayoutContext.prototype._createFormattingState):
(LayoutContext.prototype._createFormattingContext): Deleted.
* LayoutReloaded/LayoutReloaded.xcworkspace/contents.xcworkspacedata:
* LayoutReloaded/test/index.html:

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

Tools/ChangeLog
Tools/LayoutReloaded/FormattingContext/BlockFormatting/BlockFormattingContext.js
Tools/LayoutReloaded/FormattingContext/FormattingContext.js
Tools/LayoutReloaded/FormattingContext/InlineFormatting/InlineFormattingContext.js
Tools/LayoutReloaded/FormattingState/BlockFormattingState.js [new file with mode: 0644]
Tools/LayoutReloaded/FormattingState/FormattingState.js [new file with mode: 0644]
Tools/LayoutReloaded/FormattingState/InlineFormattingState.js [new file with mode: 0644]
Tools/LayoutReloaded/LayoutContext.js
Tools/LayoutReloaded/LayoutReloaded.xcworkspace/contents.xcworkspacedata
Tools/LayoutReloaded/test/index.html

index eaac273..837d608 100644 (file)
@@ -1,3 +1,38 @@
+2018-03-20  Zalan Bujtas  <zalan@apple.com>
+
+        [LayoutReloaded] Introduce FormattingState (Block/Inline/etc)
+        https://bugs.webkit.org/show_bug.cgi?id=183777
+
+        Reviewed by Antti Koivisto.
+
+        This is in preparation for moving out states from the formatting contexts.
+
+        * LayoutReloaded/FormattingContext/BlockFormatting/BlockFormattingContext.js:
+        (BlockFormattingContext):
+        * LayoutReloaded/FormattingContext/FormattingContext.js:
+        (FormattingContext):
+        (FormattingContext.prototype.layoutState):
+        (FormattingContext.prototype.layoutContext):
+        (FormattingContext.prototype.layout):
+        * LayoutReloaded/FormattingContext/InlineFormatting/InlineFormattingContext.js:
+        (InlineFormattingContext):
+        * LayoutReloaded/FormattingState/BlockFormattingState.js: Copied from Tools/LayoutReloaded/LayoutContext.js.
+        (BlockFormattingState):
+        * LayoutReloaded/FormattingState/FormattingState.js: Copied from Tools/LayoutReloaded/LayoutContext.js.
+        (FormattingState):
+        (FormattingState.prototype.formattingContext):
+        (FormattingState.prototype.layoutContext):
+        (FormattingState.prototype._setFormattingContext):
+        * LayoutReloaded/FormattingState/InlineFormattingState.js: Copied from Tools/LayoutReloaded/LayoutContext.js.
+        (InlineFormattingState):
+        * LayoutReloaded/LayoutContext.js:
+        (LayoutContext):
+        (LayoutContext.prototype.layout):
+        (LayoutContext.prototype._createFormattingState):
+        (LayoutContext.prototype._createFormattingContext): Deleted.
+        * LayoutReloaded/LayoutReloaded.xcworkspace/contents.xcworkspacedata:
+        * LayoutReloaded/test/index.html:
+
 2018-03-19  Zalan Bujtas  <zalan@apple.com>
 
         [LayoutReloaded] Layout.Box should not create the formatting context.
index d8ea2f0..10043b7 100644 (file)
@@ -23,8 +23,8 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 class BlockFormattingContext extends FormattingContext {
-    constructor(root, layoutContext) {
-        super(root, layoutContext);
+    constructor(root, layoutState) {
+        super(root, layoutState);
         // New block formatting context always establishes a new floating context.
         this.m_floatingContext = new FloatingContext(this);
     }
index b91d10a..582134c 100644 (file)
@@ -24,9 +24,9 @@
  */
 
 class FormattingContext {
-    constructor(rootContainer, layoutContext) {
+    constructor(rootContainer, layoutState) {
         this.m_rootContainer = rootContainer;
-        this.m_layoutContext = layoutContext;
+        this.m_layoutState = layoutState;
         this.m_floatingContext = null;
         this.m_displayToLayout = new Map();
         this.m_layoutToDisplay = new Map();
@@ -37,15 +37,20 @@ class FormattingContext {
         return this.m_rootContainer;
     }
 
+    layoutState() {
+        return this.m_layoutState;
+    }
+
     layoutContext() {
-        return this.m_layoutContext;
+        return this.layoutState().layoutContext();
     }
 
     floatingContext() {
         return this.m_floatingContext;
     }
 
-    layout(layoutContext) {
+    layout() {
+        ASSERT_NOT_REACHED();
     }
 
     computeWidth(layoutBox) {
index 1b991ee..7191fc3 100644 (file)
@@ -24,8 +24,8 @@
  */
 
 class InlineFormattingContext extends FormattingContext {
-    constructor(root, layoutContext) {
-        super(root, layoutContext);
+    constructor(root, layoutState) {
+        super(root, layoutState);
         // If the block container box that initiates this inline formatting contex also establishes a block context, create a new float for us.
         ASSERT(root.isBlockContainerBox());
         if (root.establishesBlockFormattingContext())
diff --git a/Tools/LayoutReloaded/FormattingState/BlockFormattingState.js b/Tools/LayoutReloaded/FormattingState/BlockFormattingState.js
new file mode 100644 (file)
index 0000000..54e813f
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2018 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. ``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
+ * 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.
+ */
+
+class BlockFormattingState extends FormattingState {
+    constructor(formattingRoot, layoutContext) {
+        super(layoutContext);
+        this._setFormattingContext(new BlockFormattingContext(formattingRoot, this));
+    }
+}
diff --git a/Tools/LayoutReloaded/FormattingState/FormattingState.js b/Tools/LayoutReloaded/FormattingState/FormattingState.js
new file mode 100644 (file)
index 0000000..b97666f
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2018 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. ``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
+ * 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.
+ */
+
+class FormattingState {
+    constructor(layoutContext) {
+        this.m_layoutContext = layoutContext;
+        this.m_formattingContext = null;
+    }
+
+    formattingContext() {
+        return this.m_formattingContext;
+    }
+
+    layoutContext() {
+        return this.m_layoutContext;
+    }
+
+    _setFormattingContext(formattingContext) {
+        this.m_formattingContext = formattingContext;
+    }
+}
diff --git a/Tools/LayoutReloaded/FormattingState/InlineFormattingState.js b/Tools/LayoutReloaded/FormattingState/InlineFormattingState.js
new file mode 100644 (file)
index 0000000..e67a9b9
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2018 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. ``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
+ * 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.
+ */
+
+class InlineFormattingState extends FormattingState {
+    constructor(formattingRoot, layoutContext) {
+        super(layoutContext);
+        this._setFormattingContext(new InlineFormattingContext(formattingRoot, this));
+    }
+}
index a7ce85e..b989a8a 100644 (file)
 
 class LayoutContext {
     constructor() {
+        this.m_layoutStates = new Map();
     }
 
     layout(formattingRoot) {
-        let formattingContext = this._createFormattingContext(formattingRoot);
-        formattingContext.layout();
+        let formattingState = this._createFormattingState(formattingRoot);
+        this.m_layoutStates.set(formattingRoot, formattingState);
+        formattingState.formattingContext().layout();
     }
 
-    _createFormattingContext(formattingRoot) {
+    _createFormattingState(formattingRoot) {
         ASSERT(formattingRoot.establishesFormattingContext());
         if (formattingRoot.establishesBlockFormattingContext())
-            return new BlockFormattingContext(formattingRoot, this);
+            return new BlockFormattingState(formattingRoot, this);
         if (formattingRoot.establishesInlineFormattingContext())
-            return new InlineFormattingContext(formattingRoot, this);
+            return new InlineFormattingState(formattingRoot, this);
         ASSERT_NOT_REACHED();
         return null;
     }
index 6783fbb..78fb1fe 100644 (file)
@@ -5,13 +5,10 @@
       location = "group:DisplayTree">
    </FileRef>
    <FileRef
-      location = "group:test">
-   </FileRef>
-   <FileRef
-      location = "group:misc">
+      location = "group:FormattingContext">
    </FileRef>
    <FileRef
-      location = "group:FormattingContext">
+      location = "group:FormattingState">
    </FileRef>
    <FileRef
       location = "group:LayoutTree">
    <FileRef
       location = "group:TreeBuilder.js">
    </FileRef>
+   <FileRef
+      location = "group:test">
+   </FileRef>
+   <FileRef
+      location = "group:misc">
+   </FileRef>
 </Workspace>
index a2c91a1..a1ac814 100644 (file)
@@ -85,6 +85,9 @@ addJS("../LayoutTree/InitialBlockContainer.js");
 addJS("../LayoutTree/InlineBox.js");
 addJS("../LayoutTree/Text.js");
 addJS("../DisplayTree/Box.js");
+addJS("../FormattingState/FormattingState.js");
+addJS("../FormattingState/BlockFormattingState.js");
+addJS("../FormattingState/InlineFormattingState.js");
 addJS("../FormattingContext/FormattingContext.js");
 addJS("../FormattingContext/FloatingContext.js");
 addJS("../FormattingContext/BlockFormatting/BlockFormattingContext.js");