Skip to content

Commit

Permalink
[Editor] Change the style of the bounding box and the resizers (bug 1…
Browse files Browse the repository at this point in the history
…852897)
  • Loading branch information
calixteman committed Sep 13, 2023
1 parent 920e51a commit 38457ae
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 29 deletions.
26 changes: 23 additions & 3 deletions src/display/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class AnnotationEditor {

#zIndex = AnnotationEditor._zIndex++;

static _borderLineWidth = -1;

static _colorManager = new ColorManager();

static _zIndex = 1;
Expand Down Expand Up @@ -124,7 +126,14 @@ class AnnotationEditor {
* Initialize the l10n stuff for this type of editor.
* @param {Object} _l10n
*/
static initialize(_l10n) {}
static initialize(_l10n) {
if (AnnotationEditor._borderLineWidth !== -1) {
return;
}
const style = getComputedStyle(document.documentElement);
AnnotationEditor._borderLineWidth =
parseFloat(style.getPropertyValue("--outline-width")) || 0;
}

/**
* Update the default parameters for this type of editor.
Expand Down Expand Up @@ -365,8 +374,14 @@ class AnnotationEditor {

// The editor can be moved wherever the user wants, so we don't need to fix
// the position: it'll be done when the user will release the mouse button.
this.div.style.left = `${(100 * this.x).toFixed(2)}%`;
this.div.style.top = `${(100 * this.y).toFixed(2)}%`;

let { x, y } = this;
const { _borderLineWidth } = AnnotationEditor;
x -= _borderLineWidth / parentWidth;
y -= _borderLineWidth / parentHeight;

this.div.style.left = `${(100 * x).toFixed(2)}%`;
this.div.style.top = `${(100 * y).toFixed(2)}%`;
this.div.scrollIntoView({ block: "nearest" });
}

Expand Down Expand Up @@ -400,6 +415,11 @@ class AnnotationEditor {
this.x = x /= pageWidth;
this.y = y /= pageHeight;

const [parentWidth, parentHeight] = this.parentDimensions;
const { _borderLineWidth } = AnnotationEditor;
x -= _borderLineWidth / parentWidth;
y -= _borderLineWidth / parentHeight;

const { style } = this.div;
style.left = `${(100 * x).toFixed(2)}%`;
style.top = `${(100 * y).toFixed(2)}%`;
Expand Down
1 change: 1 addition & 0 deletions src/display/editor/freetext.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class FreeTextEditor extends AnnotationEditor {

/** @inheritdoc */
static initialize(l10n) {
super.initialize(l10n);
this._l10nPromise = new Map(
["free_text2_default_content", "editor_free_text2_aria_label"].map(
str => [str, l10n.get(str)]
Expand Down
1 change: 1 addition & 0 deletions src/display/editor/ink.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class InkEditor extends AnnotationEditor {

/** @inheritdoc */
static initialize(l10n) {
super.initialize(l10n);
this._l10nPromise = new Map(
["editor_ink_canvas_aria_label", "editor_ink2_aria_label"].map(str => [
str,
Expand Down
77 changes: 51 additions & 26 deletions web/annotation_editor_layer_builder.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,22 @@

:root {
--outline-width: 2px;
--outline-color: blue;
--outline-color: #0060df;
--outline-around-width: 1px;
--outline-around-color: #f0f0f4;
--focus-outline: solid var(--outline-width) var(--outline-color);
--unfocus-outline: solid var(--outline-width) transparent;
--focus-outline-around: solid var(--outline-around-width)
var(--outline-around-color);
--hover-outline: dashed var(--outline-width) var(--outline-color);
--freetext-line-height: 1.35;
--freetext-padding: 2px;
--resizer-size: 8px;
--resizer-size: 6px;
--resizer-shift: calc(
0px - var(--outline-width) - var(--resizer-size) / 2 - var(--outline-width) /
2
0px - (var(--outline-width) + var(--resizer-size)) / 2 -
var(--outline-around-width)
);
--resizer-color: white;
--resizer-color: var(--outline-color);
--editorFreeText-editing-cursor: text;
/*#if COMPONENTS*/
--editorInk-editing-cursor: pointer;
Expand All @@ -45,10 +50,9 @@

@media screen and (forced-colors: active) {
:root {
--outline-width: 3px;
--outline-color: ButtonText;
--resizer-size: 12px;
--resizer-color: ButtonFace;
--outline-around-color: ButtonFace;
--resizer-color: ButtonText;
}
}

Expand Down Expand Up @@ -89,15 +93,6 @@
cursor: var(--editorInk-editing-cursor);
}

.annotationEditorLayer
:is(.freeTextEditor, .inkEditor, .stampEditor).draggable.selectedEditor {
cursor: move;
}

.annotationEditorLayer .selectedEditor {
outline: var(--focus-outline);
}

.annotationEditorLayer :is(.freeTextEditor, .inkEditor, .stampEditor) {
position: absolute;
background: transparent;
Expand All @@ -107,6 +102,44 @@
cursor: auto;
max-width: 100%;
max-height: 100%;
border: var(--unfocus-outline);

&.draggable.selectedEditor {
cursor: move;
}

&.selectedEditor {
border: var(--focus-outline);
outline: var(--focus-outline-around);

&::before {
/*
This is a workaround for the lack of support for stripes(...) (see
https://drafts.csswg.org/css-images-4/#stripes).
The outline should be composed of 1px white, 2px blue and 1px white.
This could be achieved in different ways:
- using a linear-gradient;
- using a box-shadow;
- using an outline on the selected element and an outline+border on
the ::before pseudo-element.
All these options lead to incorrect rendering likely due to rounding
issues.
That said it doesn't mean that the current is ideal, but it's the best
we could come up with for the moment.
One drawback of this approach is that we use a border on the selected
element which means that we must take care of it when positioning the
div in js (see AnnotationEditor._borderLineWidth in editor.js).
*/
content: "";
position: absolute;
inset: 0;
border: var(--focus-outline-around);
}
}

&:hover:not(.selectedEditor) {
border: var(--hover-outline);
}
}

.annotationEditorLayer .freeTextEditor {
Expand Down Expand Up @@ -150,11 +183,6 @@
user-select: auto;
}

.annotationEditorLayer
:is(.freeTextEditor, .inkEditor, .stampEditor):hover:not(.selectedEditor) {
outline: var(--hover-outline);
}

.annotationEditorLayer .inkEditor {
width: 100%;
height: 100%;
Expand Down Expand Up @@ -185,8 +213,6 @@
.annotationEditorLayer {
:is(.freeTextEditor, .inkEditor, .stampEditor) {
& > .resizers {
width: 100%;
height: 100%;
position: absolute;
inset: 0;

Expand All @@ -197,9 +223,8 @@
& > .resizer {
width: var(--resizer-size);
height: var(--resizer-size);
border-radius: 50%;
background: var(--resizer-color);
border: var(--focus-outline);
border: var(--focus-outline-around);
position: absolute;

&.topLeft {
Expand Down

0 comments on commit 38457ae

Please sign in to comment.