Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[api-minor] Move annotation DOM manipulation logic to src/display/annotation_layer.js #6714

Merged
merged 6 commits into from
Dec 15, 2015

Conversation

timvandermeij
Copy link
Contributor

Fixes #6689 (as the testing part is tracked in #6673). It is also another part of #5218.

I have tested this PR with a set of 20 PDF files with various kinds of annotations (Link, Text, Widget, et cetera) and found no changes in rendering, behavior or printing.

Note that I intentionally used multiple commits to make reviewing easier and to split renaming code and moving code as much as possible.

Naming it this way makes more sense when compared to the core
annoatation code. That code also uses `data` for the annotation
properties.
Additionally simplify the div creation logic (it needs to happen only
once, so it should not be in the for-loop) and remove/rename variables
for shorter code.
container.style.left = data.rect[0] + 'px';
container.style.top = data.rect[1] + 'px';

// Size
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove trivial comment such as "Size", "Border" or "Border color". If we can, let's add a sentence about what we are planing to do instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in b1937e7, also for the existing border style code. The code is indeed very readable already without these comments.


self.div = document.createElement('div');
self.div.className = 'annotationLayer';
self.pageDiv.appendChild(self.div);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can create two functions "updateAnnotations" and "renderAnnotations" for PDFJS.AnnotationUtils that accept div, annotations, etc. and move logic of this if branches there. We can keep logic of the div creation and annotations.length check here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 7e15034.

@yurydelendik
Copy link
Contributor

Looks good after comments are addressed.

@timvandermeij timvandermeij changed the title Move most annotation rendering logic to src/display/annotation_layer.js [api-minor] Move most annotation rendering logic to src/display/annotation_layer.js Dec 15, 2015
@timvandermeij timvandermeij changed the title [api-minor] Move most annotation rendering logic to src/display/annotation_layer.js [api-minor] Move annotation DOM manipulation logic to src/display/annotation_layer.js Dec 15, 2015
@timvandermeij
Copy link
Contributor Author

/botio-linux preview

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

Command cmd_preview from @timvandermeij received. Current queue size: 0

Live output at: http://107.21.233.14:8877/b0ca424f1f902ed/output.txt

@timvandermeij
Copy link
Contributor Author

/botio test

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

Command cmd_test from @timvandermeij received. Current queue size: 0

Live output at: http://107.21.233.14:8877/6f2fc4f4d1c7ee3/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_test from @timvandermeij received. Current queue size: 0

Live output at: http://107.22.172.223:8877/5d2c0c873f5dd05/output.txt

PDFJS.AnnotationLayer.render(viewport, self.div, annotations,
self.pdfPage, self.linkService);
if (typeof mozL10n !== 'undefined') {
mozL10n.translate(self.div);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this line actually do the same thing as before, since the current code attempts to translate the individual annotation elements, and not the entire annotationLayerdiv?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but we don't want to move mozL10n dependency to the src/display/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have verified that mozL10n.translate() does work on the entire div too instead of only on individual annotation elements. I have tested this with PDFs with only one or multiple annotations per page and each annotation was properly translated. Therefore this seems to do the same thing as before. As Yury mentioned, it's nicer to keep localization in the web folder as it does not belong in the core code.

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/5d2c0c873f5dd05/output.txt

Total script time: 19.23 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: Passed

@pdfjsbot
Copy link

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/6f2fc4f4d1c7ee3/output.txt

Total script time: 20.16 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: Passed

@timvandermeij
Copy link
Contributor Author

Merging with r=yurydelendik and r=me.

timvandermeij added a commit that referenced this pull request Dec 15, 2015
[api-minor] Move annotation DOM manipulation logic to src/display/annotation_layer.js
@timvandermeij timvandermeij merged commit 1b5940e into mozilla:master Dec 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants