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

move hasHtml to AnnotationElement #6856

Merged
merged 1 commit into from
Feb 13, 2016

Conversation

xlc
Copy link
Contributor

@xlc xlc commented Jan 12, 2016

Required by #6172

@@ -199,6 +199,16 @@ var AnnotationElement = (function AnnotationElementClosure() {
},

/**
* Check does this annotation need HTML element.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This sentence sounds a bit strange, how about e.g. Check if the annotation needs a HTML element. instead?

@timvandermeij
Copy link
Contributor

I agree with the comments above. Aside from that, I think it's quite a lot of code compared to the current situation, with no clear advantage. We need to find a way to only call render on the element if it exists, meaning that in case of https://github.com/mozilla/pdf.js/pull/6856/files#diff-18ca06e2bd5be4c9132b51f78388b8f0L793 we should not create the annotation in the first place.

@xlc
Copy link
Contributor Author

xlc commented Jan 12, 2016

It is AnnotationElement's responsibility to check is render needed to be called. If hasHtml() returns false, render won't be called. The main advantage for this PR is hasHtml code moved from model (Annotation and its data object) to renderer (AnnotationElement). It is the renderer's responsibility to decide it want's to render anything or not.
Another way is simply let render return null if it doesn't want to render anything.
If you want to avoid create 'AnnotationElement' at first place, then you need a big complicated function hasHtml(parameter) to make the decision that contains multiple switch cases.

@xlc xlc force-pushed the remove-has-html branch 2 times, most recently from ed5003a to b0f8492 Compare January 12, 2016 22:04
@@ -199,6 +199,16 @@ var AnnotationElement = (function AnnotationElementClosure() {
},

/**
* Check if the annotation needs a HTML element.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: an HTML element (here and below).

@Snuffleupagus
Copy link
Collaborator

Aside from that, I think it's quite a lot of code compared to the current situation, with no clear advantage.

I agree with this sentiment. It seems like a lot of code to add, and I think that a "shorter" solution would be preferable.

@timvandermeij
Copy link
Contributor

How about, instead of a method, use a member variable for this instead? I think hasHtml is a slightly bad name because each annotation element has associated HTML, it's just a matter of if we want to show it or not, so I think we should call it something like isRenderable instead. We can set isRenderable in the constructor for the base class, overwrite it for subclasses after https://github.com/mozilla/pdf.js/pull/6856/files#diff-1097e3b131ba22f8e8a6c2f20e3ab5ecR710 and change https://github.com/mozilla/pdf.js/pull/6856/files#diff-1097e3b131ba22f8e8a6c2f20e3ab5ecR852 to if (element.isRenderable) {. That should give us the same functionality but with much less code (much more like how it is right now, just one line per subclass).

@Snuffleupagus
Copy link
Collaborator

@timvandermeij I was actually thinking something similar, but preferably I'd also avoid creating the container in this case. Similar to your idea, but could we maybe do something along these lines https://gist.github.com/Snuffleupagus/206b52763a250f6ba811?

@timvandermeij
Copy link
Contributor

Yes, that looks like a clean solution to me!

@xlc
Copy link
Contributor Author

xlc commented Jan 15, 2016

Updated per @Snuffleupagus's suggestion.

@@ -310,7 +314,9 @@ var LinkAnnotationElement = (function LinkAnnotationElementClosure() {
*/
var TextAnnotationElement = (function TextAnnotationElementClosure() {
function TextAnnotationElement(parameters) {
AnnotationElement.call(this, parameters);
var isRenderable = !!(parameters.data.hasPopup||
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: add a space after hasPopup and before ||

@xlc xlc force-pushed the remove-has-html branch 2 times, most recently from 5a274e4 to 89ebcbd Compare January 17, 2016 21:31
@timvandermeij
Copy link
Contributor

@Snuffleupagus Do you have any ideas to further improve this code (regarding the above)?

@timvandermeij
Copy link
Contributor

@Snuffleupagus Ping for the above as I think this comment got lost in the pile of GitHub messages.

This looks good as-is, but perhaps you have an idea to improve this even further (see above, about returning in the constructor).

@@ -86,7 +86,8 @@ AnnotationElementFactory.prototype =
return new StrikeOutAnnotationElement(parameters);

default:
throw new Error('Unimplemented annotation type "' + subtype + '"');
warn('Unimplemented annotation type "' + parameters.data.subtype + '"');
return null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we already warn in annotation.js for this case, I think that we can avoid duplicate warnings here.
Would return AnnotationElement(parameters); make sense here, instead of returning null?

@Snuffleupagus
Copy link
Collaborator

Ping for the above as I think this comment got lost in the pile of GitHub messages.

Yeah, unfortunately that happened here (the problem with getting notified about everything), sorry for the lag!
This seems OK to me, with two minor comments, provided the tests pass.

@xlc
Copy link
Contributor Author

xlc commented Feb 11, 2016

@timvandermeij @Snuffleupagus Updated.

@timvandermeij
Copy link
Contributor

/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/af7bec038130b4c/output.txt

@timvandermeij
Copy link
Contributor

/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/7d57e20a57e6ddf/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/33aa3d9766f82fc/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/33aa3d9766f82fc/output.txt

Total script time: 20.17 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/7d57e20a57e6ddf/output.txt

Total script time: 21.66 mins

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

timvandermeij added a commit that referenced this pull request Feb 13, 2016
move hasHtml to AnnotationElement
@timvandermeij timvandermeij merged commit addc4a3 into mozilla:master Feb 13, 2016
@timvandermeij
Copy link
Contributor

Looks good, thank you!

@xlc xlc deleted the remove-has-html branch February 14, 2016 21:09
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.

4 participants