Bug 1457804 - Use content size for DevTools highlighter writing mode adjustments. r=gl draft
authorJ. Ryan Stinnett <jryans@gmail.com>
Thu, 03 May 2018 19:06:14 -0500
changeset 791328 4be2084350b3b5148788f8739cf5343a00a79094
parent 791312 ce7072c02389db590c487ca5863b7f00ce22336a
push id108782
push userbmo:jryans@gmail.com
push dateFri, 04 May 2018 00:10:45 +0000
reviewersgl
bugs1457804
milestone61.0a1
Bug 1457804 - Use content size for DevTools highlighter writing mode adjustments. r=gl The writing mode / RTL adjustments performed by `getWritingModeMatrix` needs the element's content size without margins, borders, or padding. MozReview-Commit-ID: LsSfNN4fyDR
devtools/server/actors/highlighters/utils/canvas.js
devtools/shared/layout/dom-matrix-2d.js
--- a/devtools/server/actors/highlighters/utils/canvas.js
+++ b/devtools/server/actors/highlighters/utils/canvas.js
@@ -281,18 +281,22 @@ function getBoundsFromPoints(points) {
  *           The current matrix.
  *         - {Boolean} hasNodeTransformations
  *           true if the node has transformed and false otherwise.
  */
 function getCurrentMatrix(element, window) {
   let computedStyle = getComputedStyle(element);
 
   let paddingTop = parseFloat(computedStyle.paddingTop);
+  let paddingRight = parseFloat(computedStyle.paddingRight);
+  let paddingBottom = parseFloat(computedStyle.paddingBottom);
   let paddingLeft = parseFloat(computedStyle.paddingLeft);
   let borderTop = parseFloat(computedStyle.borderTopWidth);
+  let borderRight = parseFloat(computedStyle.borderRightWidth);
+  let borderBottom = parseFloat(computedStyle.borderBottomWidth);
   let borderLeft = parseFloat(computedStyle.borderLeftWidth);
 
   let nodeMatrix = getNodeTransformationMatrix(element, window.document.documentElement);
 
   let currentMatrix = identity();
   let hasNodeTransformations = false;
 
   // Scale based on the device pixel ratio.
@@ -308,18 +312,18 @@ function getCurrentMatrix(element, windo
   }
 
   // Translate the origin based on the node's padding and border values.
   currentMatrix = multiply(currentMatrix,
     translate(paddingLeft + borderLeft, paddingTop + borderTop));
 
   // Adjust as needed to match the writing mode and text direction of the element.
   let size = {
-    width: element.offsetWidth,
-    height: element.offsetHeight,
+    width: element.offsetWidth - borderLeft - borderRight - paddingLeft - paddingRight,
+    height: element.offsetHeight - borderTop - borderBottom - paddingTop - paddingBottom,
   };
   let writingModeMatrix = getWritingModeMatrix(size, computedStyle);
   if (!isIdentity(writingModeMatrix)) {
     currentMatrix = multiply(currentMatrix, writingModeMatrix);
   }
 
   return { currentMatrix, hasNodeTransformations };
 }
--- a/devtools/shared/layout/dom-matrix-2d.js
+++ b/devtools/shared/layout/dom-matrix-2d.js
@@ -227,17 +227,18 @@ function getNodeTransformationMatrix(nod
 }
 exports.getNodeTransformationMatrix = getNodeTransformationMatrix;
 
 /**
  * Returns the matrix to rotate, translate, and reflect (if needed) from the element's
  * top-left origin into the actual writing mode and text direction applied to the element.
  *
  * @param  {Object} size
- *         An element's untransformed `width` and `height`.
+ *         An element's untransformed content `width` and `height` (excluding any margin,
+ *         borders, or padding).
  * @param  {Object} style
  *         The computed `writingMode` and `direction` properties for the element.
  * @return {Array}
  *         The matrix with adjustments for writing mode and text direction, if any.
  */
 function getWritingModeMatrix(size, style) {
   let currentMatrix = identity();
   let { width, height } = size;