summaryrefslogtreecommitdiff
path: root/addons/web_editor/static/src/js
diff options
context:
space:
mode:
authorSamuel Degueldre <sad@odoo.com>2020-10-30 09:15:13 +0000
committerSamuel Degueldre <sad@odoo.com>2020-11-02 07:04:01 +0000
commit42b3ad10e0b32b7fc72f801e2c67d6baf938c566 (patch)
tree5ee7680ccfd9f9f7b2e309cb92e1cab53b9976e4 /addons/web_editor/static/src/js
parenta39e94f7e4dc74e850650ac90bbc5f85af130bc8 (diff)
[FIX] web_editor: fix gap between transformed shape and next section
Previously, when flipping some shapes vertically on chrome, and vertically or horizontally on firefox, there was a gap of 1px or less at some screen widths. This is caused by the way these browsers render backgrounds on transformed elements. It seems like firefox will round the size of the element to render the background image on it if the element is transformed, while chrome will always render the background at the correct size (or render it at a larger size and clip it to the correct size after the fact), but will round the coordinates of the symmetry point, causing only the vertical flip to have this issue, and only if the background image would not extend beyond the bounds of the element (on firefox, even shapes that would extend beyond the bounds of the element would showcase a gap, eg origins 1) This commit fixes that by applying the transform to the SVG rather than to the element, by use of the shapes controller. task-2369560 closes odoo/odoo#61114 Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
Diffstat (limited to 'addons/web_editor/static/src/js')
-rw-r--r--addons/web_editor/static/src/js/editor/snippets.options.js45
1 files changed, 34 insertions, 11 deletions
diff --git a/addons/web_editor/static/src/js/editor/snippets.options.js b/addons/web_editor/static/src/js/editor/snippets.options.js
index 5050a622bd6..051ab4111b2 100644
--- a/addons/web_editor/static/src/js/editor/snippets.options.js
+++ b/addons/web_editor/static/src/js/editor/snippets.options.js
@@ -3846,10 +3846,14 @@ registry.BackgroundShape = SnippetOptionWidget.extend({
return color || '';
}
case 'flipX': {
- return this.$target.find('> .o_we_shape.o_we_flip_x').length !== 0;
+ // Compat: flip classes are no longer used but may be present in client db
+ const hasFlipClass = this.$target.find('> .o_we_shape.o_we_flip_x').length !== 0;
+ return hasFlipClass || this._getShapeData().flip.includes('x');
}
case 'flipY': {
- return this.$target.find('> .o_we_shape.o_we_flip_y').length !== 0;
+ // Compat: flip classes are no longer used but may be present in client db
+ const hasFlipClass = this.$target.find('> .o_we_shape.o_we_flip_y').length !== 0;
+ return hasFlipClass || this._getShapeData().flip.includes('y');
}
}
return this._super(...arguments);
@@ -3955,11 +3959,27 @@ registry.BackgroundShape = SnippetOptionWidget.extend({
target.style.position = 'relative';
}
shapeContainer.className = `o_we_shape o_${shape.replace(/\//g, '_')}`;
- flip.forEach(dir => {
- shapeContainer.classList.add(`o_we_flip_${dir}`);
- });
- // Custom colors, overwrite shape that is set by the class
- $(shapeContainer).css('background-image', colors ? `url("${this._getShapeSrc()}")` : '');
+ // Compat: remove old flip classes as flipping is now done inside the svg
+ shapeContainer.classList.remove('o_we_flip_x', 'o_we_flip_y');
+
+ if (colors || flip.length) {
+ // Custom colors/flip, overwrite shape that is set by the class
+ $(shapeContainer).css('background-image', `url("${this._getShapeSrc()}")`);
+ shapeContainer.style.backgroundPosition = '';
+ if (flip.length) {
+ let [xPos, yPos] = $(shapeContainer)
+ .css('background-position')
+ .split(' ')
+ .map(p => parseFloat(p));
+ // -X + 2*Y is a symmetry of X around Y, this is a symmetry around 50%
+ xPos = flip.includes('x') ? -xPos + 100 : xPos;
+ yPos = flip.includes('y') ? -yPos + 100 : yPos;
+ shapeContainer.style.backgroundPosition = `${xPos}% ${yPos}%`;
+ }
+ } else {
+ // Remove custom bg image and let the shape class set the bg shape
+ $(shapeContainer).css('background-image', '');
+ }
},
/**
* Overwrites shape properties with the specified data.
@@ -3998,16 +4018,19 @@ registry.BackgroundShape = SnippetOptionWidget.extend({
* @private
*/
_getShapeSrc() {
- const {shape, colors} = this._getShapeData();
+ const {shape, colors, flip} = this._getShapeData();
if (!shape) {
return '';
}
- const queryString = Object.entries(colors)
+ const searchParams = Object.entries(colors)
.map(([colorName, colorValue]) => {
const encodedCol = encodeURIComponent(colorValue);
return `${colorName}=${encodedCol}`;
- }).join('&');
- return `/web_editor/shape/${shape}.svg?${queryString}`;
+ });
+ if (flip.length) {
+ searchParams.push(`flip=${flip.sort().join('')}`);
+ }
+ return `/web_editor/shape/${shape}.svg?${searchParams.join('&')}`;
},
/**
* Retrieves current shape data from the target's dataset.