Skip to content

Commit

Permalink
Refactor the toolbar html & css to improve its overall accessibility …
Browse files Browse the repository at this point in the history
…(bug 1171799, bug 1855695)

The first goal of this patch was to remove the tabindex because it helps
to improve overall a11y. That led to move some html elements associated
with the buttons which helped to position these elements relatively to their
buttons.
Consequently it was easy to change the toolbar height (configurable in Firefox
with the pref browser.uidensity): it's the second goal of this patch.
For a11y reasons we want to be able to change the height of the toolbar to make
the buttons larger.
  • Loading branch information
calixteman committed Sep 18, 2024
1 parent 19151fe commit 220416c
Show file tree
Hide file tree
Showing 7 changed files with 1,001 additions and 880 deletions.
2 changes: 1 addition & 1 deletion test/integration/find_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe("find bar", () => {
await page.click("#viewFindButton");
await page.waitForSelector("#viewFindButton", { hidden: false });
await page.type("#findInput", "a");
await page.click("#findHighlightAll");
await page.click("#findHighlightAll + label");
await page.waitForSelector(".textLayer .highlight");

// The PDF file contains the text 'AB BA' in a monospace font on a
Expand Down
15 changes: 3 additions & 12 deletions web/annotation_editor_layer_builder.css
Original file line number Diff line number Diff line change
Expand Up @@ -1226,18 +1226,9 @@
}

#highlightParamsToolbarContainer {
height: auto;
padding-inline: 10px;
padding-block: 10px 16px;
gap: 16px;
display: flex;
flex-direction: column;
box-sizing: border-box;

.editorParamsLabel {
width: fit-content;
inset-inline-start: 0;
}
padding-inline: 10px;
padding-block-end: 12px;

.colorPicker {
display: flex;
Expand All @@ -1261,6 +1252,7 @@
align-items: center;
background: none;
flex: 0 0 auto;
padding: 0;

.swatch {
width: 24px;
Expand Down Expand Up @@ -1290,7 +1282,6 @@
align-self: stretch;

.editorParamsLabel {
width: 100%;
height: auto;
align-self: stretch;
}
Expand Down
29 changes: 0 additions & 29 deletions web/pdf_find_bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ const MATCHES_COUNT_LIMIT = 1000;
* is done by PDFFindController.
*/
class PDFFindBar {
#resizeObserver = new ResizeObserver(this.#resizeObserverCallback.bind(this));

constructor(options, eventBus) {
this.opened = false;

Expand Down Expand Up @@ -166,13 +164,6 @@ class PDFFindBar {

open() {
if (!this.opened) {
// Potentially update the findbar layout, row vs column, when:
// - The width of the viewer itself changes.
// - The width of the findbar changes, by toggling the visibility
// (or localization) of find count/status messages.
this.#resizeObserver.observe(this.bar.parentNode);
this.#resizeObserver.observe(this.bar);

this.opened = true;
toggleExpandedBtn(this.toggleButton, true, this.bar);
}
Expand All @@ -184,7 +175,6 @@ class PDFFindBar {
if (!this.opened) {
return;
}
this.#resizeObserver.disconnect();

this.opened = false;
toggleExpandedBtn(this.toggleButton, false, this.bar);
Expand All @@ -199,25 +189,6 @@ class PDFFindBar {
this.open();
}
}

#resizeObserverCallback(entries) {
const { bar } = this;
// The find bar has an absolute position and thus the browser extends
// its width to the maximum possible width once the find bar does not fit
// entirely within the window anymore (and its elements are automatically
// wrapped). Here we detect and fix that.
bar.classList.remove("wrapContainers");

const findbarHeight = bar.clientHeight;
const inputContainerHeight = bar.firstElementChild.clientHeight;

if (findbarHeight > inputContainerHeight) {
// The findbar is taller than the input container, which means that
// the browser wrapped some of the elements. For a consistent look,
// wrap all of them to adjust the width of the find bar.
bar.classList.add("wrapContainers");
}
}
}

export { PDFFindBar };
21 changes: 12 additions & 9 deletions web/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
DEFAULT_SCALE_VALUE,
MAX_SCALE,
MIN_SCALE,
toggleCheckedBtn,
toggleExpandedBtn,
} from "./ui_utils.js";

/**
Expand Down Expand Up @@ -180,6 +180,9 @@ class Toolbar {
for (const { element, eventName, eventDetails, telemetry } of buttons) {
element.addEventListener("click", evt => {
if (eventName !== null) {
if (evt.target !== element) {
return;
}
eventBus.dispatch(eventName, {
source: this,
...eventDetails,
Expand Down Expand Up @@ -270,32 +273,32 @@ class Toolbar {
editorStampParamsToolbar,
} = this.#opts;

toggleCheckedBtn(
toggleExpandedBtn(
editorFreeTextButton,
mode === AnnotationEditorType.FREETEXT,
editorFreeTextParamsToolbar
);
toggleCheckedBtn(
toggleExpandedBtn(
editorHighlightButton,
mode === AnnotationEditorType.HIGHLIGHT,
editorHighlightParamsToolbar
);
toggleCheckedBtn(
toggleExpandedBtn(
editorInkButton,
mode === AnnotationEditorType.INK,
editorInkParamsToolbar
);
toggleCheckedBtn(
toggleExpandedBtn(
editorStampButton,
mode === AnnotationEditorType.STAMP,
editorStampParamsToolbar
);

const isDisable = mode === AnnotationEditorType.DISABLE;
editorFreeTextButton.disabled = isDisable;
editorHighlightButton.disabled = isDisable;
editorInkButton.disabled = isDisable;
editorStampButton.disabled = isDisable;
editorFreeTextButton.toggleAttribute("disabled", isDisable);
editorHighlightButton.toggleAttribute("disabled", isDisable);
editorInkButton.toggleAttribute("disabled", isDisable);
editorStampButton.toggleAttribute("disabled", isDisable);
}

#updateUIState(resetNumPages = false) {
Expand Down
4 changes: 2 additions & 2 deletions web/viewer-geckoview.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@

</head>

<body tabindex="1">
<body tabindex="0">
<div id="outerContainer">

<div id="mainContainer">

<div id="floatingToolbar">
<button id="download" class="toolbarButton" type="button" title="Download" tabindex="31" data-l10n-id="pdfjs-download-button">
<button id="download" class="toolbarButton" type="button" title="Download" tabindex="0" data-l10n-id="pdfjs-download-button">
<span data-l10n-id="pdfjs-download-button-label">Download</span>
</button>
</div>
Expand Down
Loading

0 comments on commit 220416c

Please sign in to comment.