[LayoutReloaded] Decouple formatting state and context lifetime.
[WebKit-https.git] / Tools / LayoutReloaded / LayoutState.js
index 4f05333e9fe32c3a487d4d99d2a1db1b7ae53b4a..b241c1de6fc2ce184a3b0331d0f93454eca6180f 100644 (file)
@@ -32,7 +32,7 @@ class LayoutState {
     layout(formattingRoot) {
         let formattingState = this._createFormattingState(formattingRoot);
         this.m_formattingStates.set(formattingRoot, formattingState);
     layout(formattingRoot) {
         let formattingState = this._createFormattingState(formattingRoot);
         this.m_formattingStates.set(formattingRoot, formattingState);
-        formattingState.formattingContext().layout();
+        this.formattingContext(formattingState).layout();
     }
 
     _createFormattingState(formattingRoot) {
     }
 
     _createFormattingState(formattingRoot) {
@@ -45,6 +45,15 @@ class LayoutState {
         return null;
     }
 
         return null;
     }
 
+    formattingContext(formattingState) {
+        if (formattingState instanceof BlockFormattingState)
+            return new BlockFormattingContext(formattingState);
+        if (formattingState instanceof InlineFormattingState)
+            return new InlineFormattingContext(formattingState);
+        ASSERT_NOT_REACHED();
+        return null;
+    }
+
     formattingStates() {
         return this.m_formattingStates;
     }
     formattingStates() {
         return this.m_formattingStates;
     }