Bug 93634 - Speech Input: wrong position was reported for scolled-down elements
Summary: Speech Input: wrong position was reported for scolled-down elements
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Hans Wennborg
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-08-09 11:43 PDT by Hans Wennborg
Modified: 2012-08-14 02:07 PDT (History)
9 users (show)

See Also:


Attachments
Patch (6.24 KB, patch)
2012-08-09 11:50 PDT, Hans Wennborg
no flags Details | Formatted Diff | Diff
Patch (5.85 KB, patch)
2012-08-10 04:15 PDT, Hans Wennborg
no flags Details | Formatted Diff | Diff
Patch (5.85 KB, patch)
2012-08-13 01:42 PDT, Hans Wennborg
no flags Details | Formatted Diff | Diff
Patch (7.75 KB, patch)
2012-08-14 00:43 PDT, Hans Wennborg
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Hans Wennborg 2012-08-09 11:43:18 PDT
Speech Input: wrong position was reported for scolled-down elements
Comment 1 Hans Wennborg 2012-08-09 11:50:27 PDT
Created attachment 157505 [details]
Patch
Comment 2 Hans Wennborg 2012-08-09 11:57:43 PDT
Uploaded as a work-in-progress / call for help.

There are two things I need help with here:

First,

+    FrameView* containingView = renderer()->view()->frameView();
+    FrameView* mainView = document()->page()->mainFrame()->view();
+    IntRect rect = renderer()->absoluteBoundingBoxRect();
+    rect = containingView->contentsToWindow(rect);
+    rect = mainView->rootViewToContents(rect);

This does not really make sense to me. But it does solve the problem: it works when a page is scrolled down, and also when the input element is in a iframe.

It would be great if someone could provide a pointer to how these coordinate systems work.


Second, the layout test doesn't really work. I would expect that the rect that the element passes to WebKit when it is clicked would match the coordinates of the mouse click. I would have thought that the mouse position is relative to the "window" (whatever that means for DumpRenderTree).


Any pointers would be very welcome.
Comment 3 Kent Tamura 2012-08-09 18:36:52 PDT
Comment on attachment 157505 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=157505&action=review

> Source/WebCore/html/shadow/TextControlInnerElements.cpp:624
>      if (speechInput()->startRecognition(m_listenerId, rect, language, grammar, document()->securityOrigin()))

What coordination do you need here? RootView, window, or screen?
Comment 4 Hans Wennborg 2012-08-09 23:43:42 PDT
(In reply to comment #3)
> (From update of attachment 157505 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=157505&action=review
> 
> > Source/WebCore/html/shadow/TextControlInnerElements.cpp:624
> >      if (speechInput()->startRecognition(m_listenerId, rect, language, grammar, document()->securityOrigin()))
> 
> What coordination do you need here? RootView, window, or screen?

I think I need window.

I know, the code above doesn't make sense, so any pointers to how these coordinate systems work would be great. E.g. what exactly is the RootView coordinate system?
Comment 5 Kent Tamura 2012-08-10 00:45:21 PDT
Comment on attachment 157505 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=157505&action=review

>>> Source/WebCore/html/shadow/TextControlInnerElements.cpp:624
>>>      if (speechInput()->startRecognition(m_listenerId, rect, language, grammar, document()->securityOrigin()))
>> 
>> What coordination do you need here? RootView, window, or screen?
> 
> I think I need window.
> 
> I know, the code above doesn't make sense, so any pointers to how these coordinate systems work would be great. E.g. what exactly is the RootView coordinate system?

* Contents: offset from the top-left corner of a rendered Document.  "absolute" in WebCore means this.
* FrameView: offset from the top-left corner of a visible rectangle for a Document.
   FrameView coordinate = contents coordinate + scroll offset
* RootView:  offset from the top-left corner of the content area of your browser tab. RootView is equivalent to FrameView if a Document is a top-level document. For <frame> or <iframe>, its FrameView is different from RootView.
* Window: offset from the top-left corner of a window containing RootView. The window might be a same area with RootView, might be a rectangle containing the tab content + tab decorations, might be a whole 
browser window.

InputTagSpeechDispatcher::startRecognition() in Chromium subtracts scroll offsets from the rect.  It looks wrong.

My recommendation:
We're eliminating window coordinate system in WebCore (Bug 71945).  So the argument of startRecognition() should be in the RootView coordinate system. In this case,
  IntRect rect = document()->view()->contentsToRootView(getPixelSnappedRect());
should work.  See WebCore/html/ColorInputType.cpp and WebCore/html/shadow/CalendarPickerElement.cpp.
  In Chromium WebKit layer, convert the position in RootView coordination system to the screen coordination system by Chrome::rootViewToScreen().
Chromium code should do nothing against the rect.
Comment 6 Hans Wennborg 2012-08-10 04:15:13 PDT
(In reply to comment #5)
> InputTagSpeechDispatcher::startRecognition() in Chromium subtracts scroll offsets from the rect.  It looks wrong.

Ah! This explains a lot of the brokenness :) Thanks for finding it, I'm removing this from the Chromium side.

> My recommendation:
> We're eliminating window coordinate system in WebCore (Bug 71945).  So the argument of startRecognition() should be in the RootView coordinate system. In this case,
>   IntRect rect = document()->view()->contentsToRootView(getPixelSnappedRect());
> should work.  See WebCore/html/ColorInputType.cpp and WebCore/html/shadow/CalendarPickerElement.cpp.
>   In Chromium WebKit layer, convert the position in RootView coordination system to the screen coordination system by Chrome::rootViewToScreen().
> Chromium code should do nothing against the rect.

Thank you so much for the pointers! This fixes everything. Uploading new patch.
Comment 7 Hans Wennborg 2012-08-10 04:15:31 PDT
Created attachment 157700 [details]
Patch
Comment 8 Satish Sampath 2012-08-10 06:00:09 PDT
Comment on attachment 157700 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=157700&action=review

> LayoutTests/fast/speech/bubble-position-scrolled.html:37
> +    window.scrollAmount = 100;

this variable doesn't seem to be used outside this function. make it a local var?
Comment 9 Hans Wennborg 2012-08-13 01:42:13 PDT
(In reply to comment #8)
> (From update of attachment 157700 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=157700&action=review
> 
> > LayoutTests/fast/speech/bubble-position-scrolled.html:37
> > +    window.scrollAmount = 100;
> 
> this variable doesn't seem to be used outside this function. make it a local var?
Done.

tkent: does the patch look OK to you?
Comment 10 Hans Wennborg 2012-08-13 01:42:35 PDT
Created attachment 157940 [details]
Patch
Comment 11 Kent Tamura 2012-08-13 18:09:52 PDT
Comment on attachment 157940 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=157940&action=review

> Source/WebCore/html/shadow/TextControlInnerElements.cpp:620
> +    IntRect rect = document()->view()->contentsToRootView(getPixelSnappedRect());
>      if (speechInput()->startRecognition(m_listenerId, rect, language, grammar, document()->securityOrigin()))

Let's update the comments for startRecognition()s in WebCore/page/SpeechInputClient.h and WebKit/chromium/public/WebSpeechInputController.h so that they mentions the coordinate system for elementRect.
Comment 12 Hans Wennborg 2012-08-14 00:43:31 PDT
(In reply to comment #11)
> Let's update the comments for startRecognition()s in WebCore/page/SpeechInputClient.h and WebKit/chromium/public/WebSpeechInputController.h so that they mentions the coordinate system for elementRect.
Done.
Comment 13 Hans Wennborg 2012-08-14 00:43:47 PDT
Created attachment 158247 [details]
Patch
Comment 14 WebKit Review Bot 2012-08-14 00:45:57 PDT
Please wait for approval from abarth@webkit.org, dglazkov@chromium.org, fishd@chromium.org, jamesr@chromium.org or tkent@chromium.org before submitting, as this patch contains changes to the Chromium public API. See also https://trac.webkit.org/wiki/ChromiumWebKitAPI.
Comment 15 Kent Tamura 2012-08-14 01:47:37 PDT
Comment on attachment 158247 [details]
Patch

ok
Comment 16 WebKit Review Bot 2012-08-14 02:07:09 PDT
Comment on attachment 158247 [details]
Patch

Clearing flags on attachment: 158247

Committed r125529: <http://trac.webkit.org/changeset/125529>
Comment 17 WebKit Review Bot 2012-08-14 02:07:14 PDT
All reviewed patches have been landed.  Closing bug.