From 1970fb091d17b3b1eb2b0d27e7c9ab758e5a472b Mon Sep 17 00:00:00 2001 From: "zalan@apple.com" Date: Tue, 20 Mar 2018 15:12:33 +0000 Subject: [PATCH] [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: git-svn-id: https://svn.webkit.org/repository/webkit/trunk@229746 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- Tools/ChangeLog | 35 ++++++++++++++++++ .../BlockFormatting/BlockFormattingContext.js | 4 +- .../FormattingContext/FormattingContext.js | 13 +++++-- .../InlineFormatting/InlineFormattingContext.js | 4 +- .../FormattingState/BlockFormattingState.js | 31 ++++++++++++++++ .../FormattingState/FormattingState.js | 43 ++++++++++++++++++++++ .../FormattingState/InlineFormattingState.js | 31 ++++++++++++++++ Tools/LayoutReloaded/LayoutContext.js | 12 +++--- .../contents.xcworkspacedata | 13 ++++--- Tools/LayoutReloaded/test/index.html | 3 ++ 10 files changed, 171 insertions(+), 18 deletions(-) create mode 100644 Tools/LayoutReloaded/FormattingState/BlockFormattingState.js create mode 100644 Tools/LayoutReloaded/FormattingState/FormattingState.js create mode 100644 Tools/LayoutReloaded/FormattingState/InlineFormattingState.js diff --git a/Tools/ChangeLog b/Tools/ChangeLog index eaac273..837d608 100644 --- a/Tools/ChangeLog +++ b/Tools/ChangeLog @@ -1,3 +1,38 @@ +2018-03-20 Zalan Bujtas + + [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 [LayoutReloaded] Layout.Box should not create the formatting context. diff --git a/Tools/LayoutReloaded/FormattingContext/BlockFormatting/BlockFormattingContext.js b/Tools/LayoutReloaded/FormattingContext/BlockFormatting/BlockFormattingContext.js index d8ea2f0..10043b7 100644 --- a/Tools/LayoutReloaded/FormattingContext/BlockFormatting/BlockFormattingContext.js +++ b/Tools/LayoutReloaded/FormattingContext/BlockFormatting/BlockFormattingContext.js @@ -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); } diff --git a/Tools/LayoutReloaded/FormattingContext/FormattingContext.js b/Tools/LayoutReloaded/FormattingContext/FormattingContext.js index b91d10a..582134c 100644 --- a/Tools/LayoutReloaded/FormattingContext/FormattingContext.js +++ b/Tools/LayoutReloaded/FormattingContext/FormattingContext.js @@ -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) { diff --git a/Tools/LayoutReloaded/FormattingContext/InlineFormatting/InlineFormattingContext.js b/Tools/LayoutReloaded/FormattingContext/InlineFormatting/InlineFormattingContext.js index 1b991ee..7191fc3 100644 --- a/Tools/LayoutReloaded/FormattingContext/InlineFormatting/InlineFormattingContext.js +++ b/Tools/LayoutReloaded/FormattingContext/InlineFormatting/InlineFormattingContext.js @@ -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 index 0000000..54e813f --- /dev/null +++ b/Tools/LayoutReloaded/FormattingState/BlockFormattingState.js @@ -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 index 0000000..b97666f --- /dev/null +++ b/Tools/LayoutReloaded/FormattingState/FormattingState.js @@ -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 index 0000000..e67a9b9 --- /dev/null +++ b/Tools/LayoutReloaded/FormattingState/InlineFormattingState.js @@ -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)); + } +} diff --git a/Tools/LayoutReloaded/LayoutContext.js b/Tools/LayoutReloaded/LayoutContext.js index a7ce85e..b989a8a 100644 --- a/Tools/LayoutReloaded/LayoutContext.js +++ b/Tools/LayoutReloaded/LayoutContext.js @@ -25,19 +25,21 @@ 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; } diff --git a/Tools/LayoutReloaded/LayoutReloaded.xcworkspace/contents.xcworkspacedata b/Tools/LayoutReloaded/LayoutReloaded.xcworkspace/contents.xcworkspacedata index 6783fbb..78fb1fe 100644 --- a/Tools/LayoutReloaded/LayoutReloaded.xcworkspace/contents.xcworkspacedata +++ b/Tools/LayoutReloaded/LayoutReloaded.xcworkspace/contents.xcworkspacedata @@ -5,13 +5,10 @@ location = "group:DisplayTree"> - - + location = "group:FormattingContext"> + location = "group:FormattingState"> @@ -31,4 +28,10 @@ + + + + diff --git a/Tools/LayoutReloaded/test/index.html b/Tools/LayoutReloaded/test/index.html index a2c91a1..a1ac814 100644 --- a/Tools/LayoutReloaded/test/index.html +++ b/Tools/LayoutReloaded/test/index.html @@ -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"); -- 1.8.3.1