04-14-2012 02:20 AM
Hi every one,
I am using QNXStageWebView in my app, I need to search the content in the page so I am using findString method for this, its selecting the searching key word but if the search key word is not in the view port its not auto scrolling to key word position,. I thought we have two methods to do this if we know the key word position in pixels they are scrollBy and scrollPosition, but I don't know how to determine the key word position. Any body having any idea about this, please share with me, I am waiting for your reply.
Thanks in advance.
04-16-2012 04:31 PM
Just an idea - Reload the page with your search term but with a regular expression create anchors and highlights on the text that matches. That way the user can go from one match to the next.
04-17-2012 02:24 AM - edited 04-17-2012 02:26 AM
Here's what I've done and it works well.
Add two event listeners, one for TextSelectionChangedEvent.TEXT_SELECTION_CHANGED, and one for FindStringEvent.FIND_STRING.
I handle them both in the same listener and scroll to the appropriate area using something like the following:
event.target.scrollBy(((event as TextSelectionChangedEvent).startRect.x-(event.targ
et as QNXStageWebView).scrollPosition.y), ((event as TextSelectionChangedEvent).startRect.y-(event.targ et as QNXStageWebView).scrollPosition.y)-((stage.stageHe ight/2)-30));
For me, that puts the selection roughly in the middle of the screen just above the keyboard, and below the dialog box that I pop up for text to be input into.
It's a complicated command to look at, try breaking it out into its parts and it should be pretty obvious what is happening there.
The trick is the TextSelectionChangedEvent, it's got the parameters you need for the scrollBy method. Additionally I remove the text selection listener if the find comes back false, and you won't see it fire in that instance.
Hope that helps you out...