[LayoutReloaded] Decouple formatting state and context lifetime.
[WebKit-https.git] / Tools / LayoutReloaded / LayoutState.js
index 4f05333..b241c1d 100644 (file)
@@ -32,7 +32,7 @@ class LayoutState {
     layout(formattingRoot) {
         let formattingState = this._createFormattingState(formattingRoot);
         this.m_formattingStates.set(formattingRoot, formattingState);
-        formattingState.formattingContext().layout();
+        this.formattingContext(formattingState).layout();
     }
 
     _createFormattingState(formattingRoot) {
@@ -45,6 +45,15 @@ class LayoutState {
         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;
     }