Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / devtools / client / fronts / layout.js
blob6f84032ba60856d0e2d6854855bc7c63bd47a9f2
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 "use strict";
7 const {
8 safeAsyncMethod,
9 } = require("resource://devtools/shared/async-utils.js");
10 const {
11 FrontClassWithSpec,
12 registerFront,
13 } = require("resource://devtools/shared/protocol.js");
14 const {
15 flexboxSpec,
16 flexItemSpec,
17 gridSpec,
18 layoutSpec,
19 } = require("resource://devtools/shared/specs/layout.js");
21 class FlexboxFront extends FrontClassWithSpec(flexboxSpec) {
22 form(form) {
23 this._form = form;
26 /**
27 * In some cases, the FlexboxActor already knows the NodeActor ID of the node where the
28 * flexbox is located. In such cases, this getter returns the NodeFront for it.
30 get containerNodeFront() {
31 if (!this._form.containerNodeActorID) {
32 return null;
35 return this.conn.getFrontByID(this._form.containerNodeActorID);
38 /**
39 * Get the WalkerFront instance that owns this FlexboxFront.
41 get walkerFront() {
42 return this.parentFront.walkerFront;
45 /**
46 * Get the computed style properties for the flex container.
48 get properties() {
49 return this._form.properties;
53 class FlexItemFront extends FrontClassWithSpec(flexItemSpec) {
54 form(form) {
55 this._form = form;
58 /**
59 * Get the flex item sizing data.
61 get flexItemSizing() {
62 return this._form.flexItemSizing;
65 /**
66 * In some cases, the FlexItemActor already knows the NodeActor ID of the node where the
67 * flex item is located. In such cases, this getter returns the NodeFront for it.
69 get nodeFront() {
70 if (!this._form.nodeActorID) {
71 return null;
74 return this.conn.getFrontByID(this._form.nodeActorID);
77 /**
78 * Get the WalkerFront instance that owns this FlexItemFront.
80 get walkerFront() {
81 return this.parentFront.walkerFront;
84 /**
85 * Get the computed style properties for the flex item.
87 get computedStyle() {
88 return this._form.computedStyle;
91 /**
92 * Get the style properties for the flex item.
94 get properties() {
95 return this._form.properties;
99 class GridFront extends FrontClassWithSpec(gridSpec) {
100 form(form) {
101 this._form = form;
105 * In some cases, the GridActor already knows the NodeActor ID of the node where the
106 * grid is located. In such cases, this getter returns the NodeFront for it.
108 get containerNodeFront() {
109 if (!this._form.containerNodeActorID) {
110 return null;
113 return this.conn.getFrontByID(this._form.containerNodeActorID);
117 * Get the WalkerFront instance that owns this GridFront.
119 get walkerFront() {
120 return this.parentFront.walkerFront;
124 * Get the text direction of the grid container.
126 get direction() {
127 return this._form.direction;
131 * Getter for the grid fragments data.
133 get gridFragments() {
134 return this._form.gridFragments;
138 * Get whether or not the grid is a subgrid.
140 get isSubgrid() {
141 return !!this._form.isSubgrid;
145 * Get the writing mode of the grid container.
147 get writingMode() {
148 return this._form.writingMode;
152 class LayoutFront extends FrontClassWithSpec(layoutSpec) {
153 constructor(client, targetFront, parentFront) {
154 super(client, targetFront, parentFront);
156 this.getAllGrids = safeAsyncMethod(
157 this.getAllGrids.bind(this),
158 () => this.isDestroyed(),
163 * Get the WalkerFront instance that owns this LayoutFront.
165 get walkerFront() {
166 return this.parentFront;
169 getAllGrids() {
170 if (!this.walkerFront.rootNode) {
171 return [];
173 return this.getGrids(this.walkerFront.rootNode);
177 exports.FlexboxFront = FlexboxFront;
178 registerFront(FlexboxFront);
179 exports.FlexItemFront = FlexItemFront;
180 registerFront(FlexItemFront);
181 exports.GridFront = GridFront;
182 registerFront(GridFront);
183 exports.LayoutFront = LayoutFront;
184 registerFront(LayoutFront);