Merge pull request #20099 from calixteman/bug1977259

[Editor] Fix the highlighting colors in HCM (bug 1977259)
This commit is contained in:
Tim van der Meij 2025-07-18 22:25:43 +02:00 committed by GitHub
commit ed141970e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 98 additions and 8 deletions

View File

@ -104,7 +104,7 @@
}, },
"highlightEditorColors": { "highlightEditorColors": {
"type": "string", "type": "string",
"default": "yellow=#FFFF98,green=#53FFBC,blue=#80EBFF,pink=#FFCBE6,red=#FF4F5F" "default": "yellow=#FFFF98,green=#53FFBC,blue=#80EBFF,pink=#FFCBE6,red=#FF4F5F,yellow_HCM=#FFFFCC,green_HCM=#53FFBC,blue_HCM=#80EBFF,pink_HCM=#F6B8FF,red_HCM=#C50043"
}, },
"disableRange": { "disableRange": {
"title": "Disable range requests", "title": "Disable range requests",

View File

@ -137,7 +137,7 @@ class HighlightEditor extends AnnotationEditor {
return { return {
action: "added", action: "added",
type: this.#isFreeHighlight ? "free_highlight" : "highlight", type: this.#isFreeHighlight ? "free_highlight" : "highlight",
color: this._uiManager.highlightColorNames.get(this.color), color: this._uiManager.getNonHCMColorName(this.color),
thickness: this.#thickness, thickness: this.#thickness,
methodOfCreation: this.#methodOfCreation, methodOfCreation: this.#methodOfCreation,
}; };
@ -147,7 +147,7 @@ class HighlightEditor extends AnnotationEditor {
get telemetryFinalData() { get telemetryFinalData() {
return { return {
type: "highlight", type: "highlight",
color: this._uiManager.highlightColorNames.get(this.color), color: this._uiManager.getNonHCMColorName(this.color),
}; };
} }
@ -374,7 +374,7 @@ class HighlightEditor extends AnnotationEditor {
this._reportTelemetry( this._reportTelemetry(
{ {
action: "color_changed", action: "color_changed",
color: this._uiManager.highlightColorNames.get(color), color: this._uiManager.getNonHCMColorName(color),
}, },
/* mustWait = */ true /* mustWait = */ true
); );
@ -1024,7 +1024,9 @@ class HighlightEditor extends AnnotationEditor {
} }
const rect = this.getRect(0, 0); const rect = this.getRect(0, 0);
const color = AnnotationEditor._colorManager.convert(this.color); const color = AnnotationEditor._colorManager.convert(
this._uiManager.getNonHCMColor(this.color)
);
const serialized = { const serialized = {
annotationType: AnnotationEditorType.HIGHLIGHT, annotationType: AnnotationEditorType.HIGHLIGHT,

View File

@ -960,10 +960,10 @@ class AnnotationEditorUIManager {
); );
} }
get highlightColors() { get _highlightColors() {
return shadow( return shadow(
this, this,
"highlightColors", "_highlightColors",
this.#highlightColors this.#highlightColors
? new Map( ? new Map(
this.#highlightColors.split(",").map(pair => { this.#highlightColors.split(",").map(pair => {
@ -976,6 +976,26 @@ class AnnotationEditorUIManager {
); );
} }
get highlightColors() {
const { _highlightColors } = this;
if (!_highlightColors) {
return shadow(this, "highlightColors", null);
}
const map = new Map();
const hasHCM = !!this.#pageColors;
for (const [name, color] of _highlightColors) {
const isNameForHCM = name.endsWith("_HCM");
if (hasHCM && isNameForHCM) {
map.set(name.replace("_HCM", ""), color);
continue;
}
if (!hasHCM && !isNameForHCM) {
map.set(name, color);
}
}
return shadow(this, "highlightColors", map);
}
get highlightColorNames() { get highlightColorNames() {
return shadow( return shadow(
this, this,
@ -986,6 +1006,18 @@ class AnnotationEditorUIManager {
); );
} }
getNonHCMColor(color) {
if (!this._highlightColors) {
return color;
}
const colorName = this.highlightColorNames.get(color);
return this._highlightColors.get(colorName) || color;
}
getNonHCMColorName(color) {
return this.highlightColorNames.get(color) || color;
}
/** /**
* Set the current drawing session. * Set the current drawing session.
* @param {AnnotationEditorLayer} layer * @param {AnnotationEditorLayer} layer

View File

@ -2750,4 +2750,55 @@ describe("Highlight Editor", () => {
); );
}); });
}); });
describe("Highlight color in HCM", () => {
let pages;
beforeEach(async () => {
pages = await loadAndWait(
"tracemonkey.pdf",
".annotationEditorLayer",
null,
null,
{
highlightEditorColors: "red=#AB0000,red_HCM=#00AB00",
forcePageColors: true,
pageColorsForeground: "#74ffd0",
pageColorsBackground: "#392a4f",
}
);
});
afterEach(async () => {
await closePages(pages);
});
it("must highlight with red color", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await switchToHighlight(page);
const rect = await getSpanRectFromText(page, 1, "Abstract");
const x = rect.x + rect.width / 2;
const y = rect.y + rect.height / 2;
await page.mouse.click(x, y, { count: 2, delay: 100 });
const editorSelector = getEditorSelector(0);
await page.waitForSelector(editorSelector);
await page.waitForSelector(
`.page[data-page-number = "1"] svg.highlightOutline.selected`
);
await page.waitForSelector(
`.page[data-page-number = "1"] .canvasWrapper > svg.highlight[fill = "#00AB00"]`
);
await waitForSerialized(page, 1);
const serialized = await getSerialized(page);
expect(serialized[0].color)
.withContext(`In ${browserName}`)
.toEqual([0xab, 0x00, 0x00]);
})
);
});
});
}); });

View File

@ -375,6 +375,9 @@ const PDFViewerApplication = {
spreadModeOnLoad: x => parseInt(x), spreadModeOnLoad: x => parseInt(x),
supportsCaretBrowsingMode: x => x === "true", supportsCaretBrowsingMode: x => x === "true",
viewerCssTheme: x => parseInt(x), viewerCssTheme: x => parseInt(x),
forcePageColors: x => x === "true",
pageColorsBackground: x => x,
pageColorsForeground: x => x,
}); });
} }

View File

@ -286,7 +286,9 @@ const defaultOptions = {
}, },
highlightEditorColors: { highlightEditorColors: {
/** @type {string} */ /** @type {string} */
value: "yellow=#FFFF98,green=#53FFBC,blue=#80EBFF,pink=#FFCBE6,red=#FF4F5F", value:
"yellow=#FFFF98,green=#53FFBC,blue=#80EBFF,pink=#FFCBE6,red=#FF4F5F," +
"yellow_HCM=#FFFFCC,green_HCM=#53FFBC,blue_HCM=#80EBFF,pink_HCM=#F6B8FF,red_HCM=#C50043",
kind: OptionKind.VIEWER + OptionKind.PREFERENCE, kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
}, },
historyUpdateUrl: { historyUpdateUrl: {