Bug 1435749 - Cut out justify-content areas using the correct flex items in the flexbox highlighter; r=gl draft
authorPatrick Brosset <pbrosset@mozilla.com>
Wed, 07 Mar 2018 09:19:30 +0100
changeset 764773 67e1b6b331756a7beb7ee4db39678552a66ab38a
parent 764770 a6a32fb286fa9e5d5f6d5b3b77423ab6b96c9502
child 764849 9837a91ff3723f0721a78f2a81602b67e5fb71ba
push id101842
push userbmo:pbrosset@mozilla.com
push dateThu, 08 Mar 2018 08:41:23 +0000
reviewersgl
bugs1435749
milestone60.0a1
Bug 1435749 - Cut out justify-content areas using the correct flex items in the flexbox highlighter; r=gl MozReview-Commit-ID: 6v9TrdRARlI
devtools/server/actors/highlighters/flexbox.js
--- a/devtools/server/actors/highlighters/flexbox.js
+++ b/devtools/server/actors/highlighters/flexbox.js
@@ -456,23 +456,23 @@ class FlexboxHighlighter extends AutoRef
     this.ctx.save();
     this.ctx.translate(offset - canvasX, offset - canvasY);
     this.ctx.lineWidth = lineWidth;
     this.ctx.strokeStyle = DEFAULT_COLOR;
 
     let { bounds } = this.currentQuads.content[0];
     let flexLines = this.currentNode.getAsFlexContainer().getLines();
     let computedStyle = getComputedStyle(this.currentNode);
-    let direction = computedStyle.getPropertyValue("flex-direction");
+    let isColumn = computedStyle.getPropertyValue("flex-direction").startsWith("column");
     let options = { matrix: this.currentMatrix };
 
     for (let flexLine of flexLines) {
       let { crossStart, crossSize } = flexLine;
 
-      if (direction.startsWith("column")) {
+      if (isColumn) {
         clearRect(this.ctx, crossStart, 0, crossStart + crossSize, bounds.height,
           this.currentMatrix);
 
         // Avoid drawing the start flex line when they overlap with the flex container.
         if (crossStart != 0) {
           drawLine(this.ctx, crossStart, 0, crossStart, bounds.height, options);
           this.ctx.stroke();
         }
@@ -506,81 +506,69 @@ class FlexboxHighlighter extends AutoRef
   }
 
   renderJustifyContent() {
     if (!this.currentQuads.content || !this.currentQuads.content[0]) {
       return;
     }
 
     let { bounds } = this.currentQuads.content[0];
-    let flexItems = this.currentNode.children;
     let flexLines = this.currentNode.getAsFlexContainer().getLines();
     let computedStyle = getComputedStyle(this.currentNode);
-    let direction = computedStyle.getPropertyValue("flex-direction");
+    let isColumn = computedStyle.getPropertyValue("flex-direction").startsWith("column");
 
     // Render the justify-content area by first highlighting all the content, and
     // clearing the occupied and margin areas of the flex item.
 
     // First, highlight all the content.
     for (let flexLine of flexLines) {
       let { crossStart, crossSize } = flexLine;
 
-      if (direction.startsWith("column")) {
+      if (isColumn) {
         this.drawJustifyContent(crossStart, 0, crossStart + crossSize, bounds.height);
       } else {
         this.drawJustifyContent(0, crossStart, bounds.width, crossStart + crossSize);
       }
     }
 
-    for (let flexItem of flexItems) {
-      let quads = getAdjustedQuads(this.win, flexItem, "border");
+    // Then, cut all the items out of this content area.
+    for (let flexLine of flexLines) {
+      let flexItems = flexLine.getItems();
 
-      if (!quads.length) {
-        continue;
-      }
+      for (let flexItem of flexItems) {
+        let { node } = flexItem;
+
+        let quads = getAdjustedQuads(this.win, node, "margin");
 
-      // Adjust the flex item bounds relative to the current quads.
-      let { bounds: flexItemBounds } = quads[0];
-      let left = Math.round(flexItemBounds.left - bounds.left);
-      let top = Math.round(flexItemBounds.top - bounds.top);
-      let right = Math.round(flexItemBounds.right - bounds.left);
-      let bottom = Math.round(flexItemBounds.bottom - bounds.top);
-      let flexItemComputedStyle = getComputedStyle(flexItem);
+        if (!quads.length) {
+          continue;
+        }
 
-      // Clear the occupied and margin areas of the flex item.
-      for (let flexLine of flexLines) {
+        // Adjust the flex item bounds relative to the current quads.
+        let { bounds: flexItemBounds } = quads[0];
+        let left = Math.round(flexItemBounds.left - bounds.left);
+        let top = Math.round(flexItemBounds.top - bounds.top);
+        let right = Math.round(flexItemBounds.right - bounds.left);
+        let bottom = Math.round(flexItemBounds.bottom - bounds.top);
+
+        // Clear the occupied and margin areas of the flex item.
         let { crossStart, crossSize } = flexLine;
         crossSize = Math.round(crossSize);
         crossStart = Math.round(crossStart);
 
-        if (direction.startsWith("column") &&
-            crossStart <= left &&
-            left <= right &&
-            right <= crossSize + crossStart) {
-          // Remove the margin area for justify-content
-          let marginTop = Math.round(parseFloat(
-            flexItemComputedStyle.getPropertyValue("margin-top")));
-          let marginBottom = Math.round(parseFloat(
-            flexItemComputedStyle.getPropertyValue("margin-bottom")));
-          clearRect(this.ctx, crossStart, top - marginTop, crossSize + crossStart,
-            bottom + marginBottom, this.currentMatrix);
-          break;
-        } else if (crossStart <= top &&
-                   top <= bottom &&
-                   bottom <= crossSize + crossStart) {
-          let marginLeft = Math.round(parseFloat(
-            flexItemComputedStyle.getPropertyValue("margin-left")));
-          let marginRight = Math.round(parseFloat(
-            flexItemComputedStyle.getPropertyValue("margin-right")));
-          clearRect(this.ctx, left - marginLeft, crossStart, right + marginRight,
-            crossSize + crossStart, this.currentMatrix);
-          break;
+        if (isColumn) {
+          clearRect(this.ctx, crossStart, top, crossSize + crossStart, bottom,
+            this.currentMatrix);
+        } else {
+          clearRect(this.ctx, left, crossStart, right, crossSize + crossStart,
+            this.currentMatrix);
         }
       }
     }
+
     this.ctx.restore();
   }
 
   _update() {
     setIgnoreLayoutChanges(true);
 
     let root = this.getElement("root");