mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Ensure that various URL-related options are applied in the xfaLayer
too
Note how both the annotationLayer and the document outline will apply various URL-related options when creating the link-elements. For consistency the `xfaLayer`-rendering should obviously use the same options, to ensure that the existing options are indeed applied to all URLs regardless of where they originate.
This commit is contained in:
parent
284d259054
commit
bb9c905c5d
7 changed files with 53 additions and 9 deletions
|
@ -1094,7 +1094,6 @@ class Button extends XFAObject {
|
|||
if (!href) {
|
||||
continue;
|
||||
}
|
||||
const target = jsURL.newWindow ? "_blank" : undefined;
|
||||
|
||||
// we've an url so generate a <a>
|
||||
htmlButton.children.push({
|
||||
|
@ -1102,7 +1101,7 @@ class Button extends XFAObject {
|
|||
attributes: {
|
||||
id: "link" + this[$uid],
|
||||
href,
|
||||
target,
|
||||
newWindow: jsURL.newWindow,
|
||||
class: ["xfaLink"],
|
||||
style: {},
|
||||
},
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { addLinkAttributes, LinkTarget } from "./display_utils.js";
|
||||
import { XfaText } from "./xfa_text.js";
|
||||
|
||||
class XfaLayer {
|
||||
|
@ -84,8 +85,10 @@ class XfaLayer {
|
|||
}
|
||||
}
|
||||
|
||||
static setAttributes(html, element, storage, intent) {
|
||||
static setAttributes({ html, element, storage = null, intent, linkService }) {
|
||||
const { attributes } = element;
|
||||
const isHTMLAnchorElement = html instanceof HTMLAnchorElement;
|
||||
|
||||
if (attributes.type === "radio") {
|
||||
// Avoid to have a radio group when printing with the same as one
|
||||
// already displayed.
|
||||
|
@ -105,6 +108,9 @@ class XfaLayer {
|
|||
} else if (key === "class") {
|
||||
html.setAttribute(key, value.join(" "));
|
||||
} else {
|
||||
if (isHTMLAnchorElement && (key === "href" || key === "newWindow")) {
|
||||
continue; // Handled below.
|
||||
}
|
||||
html.setAttribute(key, value);
|
||||
}
|
||||
} else {
|
||||
|
@ -112,6 +118,17 @@ class XfaLayer {
|
|||
}
|
||||
}
|
||||
|
||||
if (isHTMLAnchorElement) {
|
||||
addLinkAttributes(html, {
|
||||
url: attributes.href,
|
||||
target: attributes.newWindow
|
||||
? LinkTarget.BLANK
|
||||
: linkService.externalLinkTarget,
|
||||
rel: linkService.externalLinkRel,
|
||||
enabled: linkService.externalLinkEnabled,
|
||||
});
|
||||
}
|
||||
|
||||
// Set the value after the others to be sure overwrite
|
||||
// any other values.
|
||||
if (storage && attributes.dataId) {
|
||||
|
@ -121,11 +138,17 @@ class XfaLayer {
|
|||
|
||||
static render(parameters) {
|
||||
const storage = parameters.annotationStorage;
|
||||
const linkService = parameters.linkService;
|
||||
const root = parameters.xfa;
|
||||
const intent = parameters.intent || "display";
|
||||
const rootHtml = document.createElement(root.name);
|
||||
if (root.attributes) {
|
||||
this.setAttributes(rootHtml, root);
|
||||
this.setAttributes({
|
||||
html: rootHtml,
|
||||
element: root,
|
||||
intent,
|
||||
linkService,
|
||||
});
|
||||
}
|
||||
const stack = [[root, -1, rootHtml]];
|
||||
|
||||
|
@ -169,7 +192,13 @@ class XfaLayer {
|
|||
|
||||
html.appendChild(childHtml);
|
||||
if (child.attributes) {
|
||||
this.setAttributes(childHtml, child, storage, intent);
|
||||
this.setAttributes({
|
||||
html: childHtml,
|
||||
element: child,
|
||||
storage,
|
||||
intent,
|
||||
linkService,
|
||||
});
|
||||
}
|
||||
|
||||
if (child.children && child.children.length > 0) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue