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

Viewer: enable find functionality for small devices #8132

Merged
merged 3 commits into from
Mar 9, 2017

Conversation

timvandermeij
Copy link
Contributor

@timvandermeij timvandermeij commented Mar 4, 2017

The commit messages provide more information about the intent of each patch.

This PR is a re-do of #6274, so please refer to that PR for previous discussion on this subject. This patch aims to resolve the issues mentioned there while keeping the code changes minimal.

Fixes #6191.
Supersedes #6274.

Reviewing is easier with https://github.com/mozilla/pdf.js/pull/8132/files?w=1.

@Snuffleupagus
Copy link
Collaborator

Snuffleupagus commented Mar 4, 2017

This looks a lot cleaner than the previous solution, which is really nice!
A couple of quick things that I noticed here, based on an initial look/test, if you don't mind:

  • One thing I couldn't help notice about this patch though, is that it (in my testing) unfortunately doesn't seem to address the issue described in the screen-shot in Enabling find functionality on small devices #6274 (comment).

  • The split toolbar button margin has been decreased slightly to prevent the issue described in Enabling find functionality on small devices #6274 where the "Phrase not found" text would be positioned below the "Highlight all" checkbox.

    Without having tested this in detail, to me this sounds a bit too "magical" on its own and I'd worry that it's perhaps not guaranteed to work well on all platforms (since e.g. checkboxes can have different sizes).
    Hence I would really recommend enforcing a height: 32px; for the new findbar "container" div elements to try and prevent any issues here!

@timvandermeij
Copy link
Contributor Author

timvandermeij commented Mar 4, 2017

One thing I couldn't help notice about this patch though, is that it (in my testing) unfortunately doesn't seem to address the issue described in the screen-shot in #6274 (comment).

I did look into that, but I really think there is nothing we can do about that. It looks like it's because the find dialog has an absolute position, in which case the browser attempts to use the full width unless a fixed width is specified, which we don't want for the reponsiveness. As you said in #6274 (comment), I also think we need to live with that, and I personally don't find it too much of an issue because usually the space is used reasonably well by all elements.

Without having tested this in detail, to me this sounds a bit too "magical" on its own and I'd worry that it's perhaps not guaranteed to work well on all platforms (since e.g. checkboxes can have different sizes).

You're right. I reverted that changed and enforced a 32 pixel height for all findbar container divs instead, which solves the issue as well and ensures that we don't have to touch the existing split toolbar buttons.

@timvandermeij
Copy link
Contributor Author

/botio-linux preview

@Snuffleupagus
Copy link
Collaborator

I have looked into that, but I really think there is nothing we can do about that.

Well, if we just use a little bit of JavaScript that runs only when the findbar is opened (and when the viewer resizes while the findbar is open), then I think that could actually be doable :-)

@timvandermeij
Copy link
Contributor Author

timvandermeij commented Mar 4, 2017

Do you mean something like https://github.com/mozilla/pdf.js/blob/master/web/secondary_toolbar.js#L225, but then for the find bar width? If so, I think that should be fine. I do wonder what width we would set in this case, because the width has to be determined automatically based on the contents. Do you have an idea how to do that?

@Snuffleupagus
Copy link
Collaborator

A very quick proof-of-concept idea: https://gist.github.com/Snuffleupagus/f8640bb3a742fc8f9bed26c6b7c98e5d.

<label for="findHighlightAll" class="toolbarLabel" data-l10n-id="find_highlight">Highlight all</label>
<input type="checkbox" id="findMatchCase" class="toolbarField" tabindex="95">
<label for="findMatchCase" class="toolbarLabel" data-l10n-id="find_match_case_label">Match case</label>
<span id="findResultsCount" class="toolbarLabel hidden"></span>
Copy link
Collaborator

@Snuffleupagus Snuffleupagus Mar 5, 2017

Choose a reason for hiding this comment

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

Perhaps it'd make sense to place this in the findbarMessageContainer instead?
Especially since I seem to recall a WIP PR that wanted to add a checkbox for toggling "phrase/word" search, in which case the resultsCount might not fit here any more.

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 think you're right. I'll change that.

web/viewer.html Outdated
</button>
<div class="findbar hidden doorHanger" id="findbar">
<div id="findbarLabelContainer">
<label for="findInput" class="toolbarLabel" data-l10n-id="find_label">Find:</label>
Copy link
Collaborator

@Snuffleupagus Snuffleupagus Mar 5, 2017

Choose a reason for hiding this comment

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

I'm not sure that I understand why the label is in it's own container here, would you mind explaining why it's not just placed in the findInputContainer instead?

Ninja edit: Oh, I suppose that you may be worried about the different lengths of the label depending on the locale and that it might not fit inside of the min-width otherwise?

One way to solve that, inspired by e.g. the Firefox built-in findbar, and the fact that we don't use labels in the main UI (i.e. not for e.g. the pageNumber nor the zoomDropdown), could be to replace the label with a placeholder in the input instead.

Copy link
Collaborator

@Snuffleupagus Snuffleupagus Mar 5, 2017

Choose a reason for hiding this comment

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

Looking through my local patches/diffs, I actually found this https://gist.github.com/Snuffleupagus/cbba3a6823c3a02a59a1a1d8bcbe6059. As far as I can tell I never submitted a PR for that, but if memory serves it worked just fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I put that in its own label because of the length of the "Search" label in different locales. I actually really like the placeholder idea, so I'll check if that works.

@timvandermeij
Copy link
Contributor Author

I have included your two patches to convert the label to a placeholder/tootip and to fix the problem of find bar width being too large. Moreover, I added a bit of CSS to prevent issues with long find messages on small screens (especially for the Dutch locale with its long strings). The only thing I couldn't do is move the find count to the find message container as that gives some strange wrapping when the screen becomes smaller (at least for the Dutch locale). This may be addressed in a follow-up patch though for when additional checkboxes are added.

@timvandermeij
Copy link
Contributor Author

/botio-linux preview

@timvandermeij
Copy link
Contributor Author

/botio-linux preview

@Snuffleupagus
Copy link
Collaborator

Snuffleupagus commented Mar 6, 2017

I've done some quick testing in Firefox, Chrome and IE (on Windows) with the latest version of the PR, and everything seems to work as it should. I also tested RTL a bit, and couldn't find any issues there either.
So this is looking really nice, and a very good improvement overall :-)

The only other thing that we might want to consider (as mentioned on IRC), now that the variability of the "Find" label is gone, is to maybe increase the width of the Find input a bit!?
At least in Firefox it looks too narrow compared to the rest of the findbar, and I'm not sure if the placeholders (in some locales) will realistically fit given the current width of the input.


Another question (adding it here since using inline comments just marked it as "outdated"):
Is it too much of a hassle to move the "placeholder" commit such that it's the first one in the series, since then you'd not need to first add the findbarLabelContainer and the immediately remove it in the next commit thus reducing the churn slightly in this code?

var inputContainerHeight = this.bar.firstElementChild.clientHeight;

if (findbarHeight > inputContainerHeight) {
// The findbar is higher than the input container, which means that
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: I think you want to use taller (instead of higher).


// 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 needs to be wrapped). Here we
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Maybe ... (and parts/all of it is automatically wrapped)... or something instead, since the wrapping is automatic based on the CSS.

@timvandermeij
Copy link
Contributor Author

/botio-linux preview

Snuffleupagus and others added 3 commits March 8, 2017 23:54
This is common in the rest of the UI and helps us prevent responsiveness
issues for different length strings in different locales.
The find functionality is currently not available for small devices
because the find dialog is not responsive. This patch fixes that.

To achieve this goal, the HTML is changed to always show the find
button. To prevent issues because of the addition of an extra button for
small views, the previous/next page buttons are hidden if the view
becomes small. These buttons are not useful anyway because on small
devices navigation is usually done via scrolling. The find functionality
is much more useful to have in this case. Moreover, we wrap the existing
elements into separate `div`s so that the browser can position the
elements itself when the view becomes smaller and logically connected
elements stay together when this happens.

In the CSS, extra rules for the find bar have been added to ensure that
the dialog's doorhanger is always below the find button. All findbar
`div`s are forced to be 32 pixels high to prevent the find message text
being aligned under the checkboxes. Finally, the find message is only
visible when there is actually text to display. This prevents wrapping
issues because, by default, the label has padding and margin even if
there is no text.
This patch ensures that the find bar is not extended to the window width
when element wrapping occurs on small screens.
@timvandermeij
Copy link
Contributor Author

/botio-linux preview

@pdfjsbot
Copy link

pdfjsbot commented Mar 8, 2017

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/00208934cb71170/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Mar 8, 2017

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/00208934cb71170/output.txt

Total script time: 2.16 mins

Published

Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a comment

Choose a reason for hiding this comment

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

(This should have been type "approved" instead of "comment", but it doesn't seem that can be changed.)

Snuffleupagus
Snuffleupagus previously approved these changes Mar 8, 2017
Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a comment

Choose a reason for hiding this comment

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

This looks much better than the current unresponsive findbar; thanks for seeing this work through!

I obviously cannot review the parts I helped write, but the rest looks good to me :-)
Should we just land this, or do we want to wait until e.g. tomorrow to have a bit more time to play with the PR before merging?

@timvandermeij timvandermeij merged commit 6908f14 into mozilla:master Mar 9, 2017
@timvandermeij timvandermeij deleted the findbar-responsiveness branch March 9, 2017 22:03
movsb pushed a commit to movsb/pdf.js that referenced this pull request Jul 14, 2018
…ness

Viewer: enable find functionality for small devices
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Search/Find is not visible in Mobile Devices
3 participants