Bug 54633

Summary: [Gtk] webkit_web_view_popup_menu_handler should call SelectionController::localCaretRect
Product: WebKit Reporter: Ryosuke Niwa <rniwa>
Component: HTML EditingAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: kalman, leviw, mario, mrobinson, rniwa, xan.lopez
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Other   
OS: Linux   
Bug Depends on:    
Bug Blocks: 52099    
Attachments:
Description Flags
Patch
none
Patch with rniwa's suggestions
none
Patch simplifying context menu margin and modifying comment none

Description Ryosuke Niwa 2011-02-17 04:06:49 PST
webkit_web_view_popup_menu_handler currently obtains selection start's coordinates by manually accessing selection start's renderer.  But it should instead call SelectionController::localCaretRect.
Comment 1 Xan Lopez 2011-02-17 04:09:11 PST
The a11y code uses boundsForVisiblePositionRange to get the text extents, Ryosuke says that's likely wrong too. CCing Mario.
Comment 2 Martin Robinson 2011-02-17 12:07:24 PST
Created attachment 82842 [details]
Patch
Comment 3 Martin Robinson 2011-02-17 15:39:37 PST
Ryosuke, Xan asked me to ping you for the review for this issue.
Comment 4 Ryosuke Niwa 2011-03-01 21:24:48 PST
Comment on attachment 82842 [details]
Patch

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

> Source/WebKit/gtk/webkit/webkitwebview.cpp:387
> +    if (!selection->start().node() || !selection->end().node()

You must be using an old checkout.  Position::node() no longer exists.  What you want to do here is probably selection->selection()->isNonOrphanedCaretOrRange() since when start() or end() is orphaned, meaning that they're detached from the document, it doesn't make sense to query the firstRectForRange on that selection.

> Source/WebKit/gtk/webkit/webkitwebview.cpp:397
> +    IntRect firstRect = frame->editor()->firstRectForRange(selection->selection().firstRange().get());

firstRange() will return 0 if selection->isNone().  You probably need to check this condition above as well (fortunately, if isNonOrphanedCaretOrRange returns true, then isNone is false so the suggested change above will fix this as well).

> Source/WebKit/gtk/webkit/webkitwebview.cpp:417
> -    location = view->contentsToWindow(location) + IntSize(0, -1);
> -    if (location.y() < 0)
> -        location.setY(contextMenuMargin);
> -    else if (location.y() > view->height())
> -        location.setY(view->height() - contextMenuMargin);
> -    if (location.x() < 0)
> -        location.setX(contextMenuMargin);
> -    else if (location.x() > view->width())
> -        location.setX(view->width() - contextMenuMargin);
> -    IntPoint global(globalPointForClientPoint(gtk_widget_get_window(widget), location));
> -
> -    PlatformMouseEvent event(location, global, RightButton, MouseEventPressed, 0, false, false, false, false, gtk_get_current_event_time());
> +        return FALSE;
>  
> +    // Never let the context menu abut very edge of the view.
> +    location = view->contentsToWindow(location);
> +    location.setY(max(gContextMenuMargin, location.y()));
> +    location.setY(min(view->height() - gContextMenuMargin, location.y()));
> +    location.setX(max(gContextMenuMargin, location.x()));
> +    location.setX(min(view->width() - gContextMenuMargin, location.x()));
> +    IntPoint globalPoint(globalPointForClientPoint(gtk_widget_get_window(widget), location));
> +    PlatformMouseEvent event(location, globalPoint, RightButton, MouseEventPressed, 0, false, false, false, false, gtk_get_current_event_time());

I can't review these changes.  Xan or someone else should do.
Comment 5 Martin Robinson 2011-03-02 09:25:00 PST
Created attachment 84426 [details]
Patch with rniwa's suggestions
Comment 6 Martin Robinson 2011-03-02 09:26:00 PST
(In reply to comment #4)

Thanks so much for the review!

> (From update of attachment 82842 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=82842&action=review
> 
> > Source/WebKit/gtk/webkit/webkitwebview.cpp:387
> > +    if (!selection->start().node() || !selection->end().node()
> 
> You must be using an old checkout.  Position::node() no longer exists.  What you want to do here is probably selection->selection()->isNonOrphanedCaretOrRange() since when start() or end() is orphaned, meaning that they're detached from the document, it doesn't make sense to query the firstRectForRange on that selection.

This patch was written before the change to ::node, I think. Made the fix you suggested here.

> 
> > Source/WebKit/gtk/webkit/webkitwebview.cpp:397
> > +    IntRect firstRect = frame->editor()->firstRectForRange(selection->selection().firstRange().get());
> 
> firstRange() will return 0 if selection->isNone().  You probably need to check this condition above as well (fortunately, if isNonOrphanedCaretOrRange returns true, then isNone is false so the suggested change above will fix this as well).

Done!
Comment 7 Ryosuke Niwa 2011-03-14 11:25:53 PDT
Comment on attachment 84426 [details]
Patch with rniwa's suggestions

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

Sorry for the delayed response.  I didn't realize you had uploaded a new patch.  The editing part of the change looks good to me.

> Source/WebKit/gtk/webkit/webkitwebview.cpp:388
> +         || (selection->selection().isCaret() && !selection->selection().isContentEditable())) {

Don't you want to avoid doing this check when caret navigation is on?
Comment 8 Ryosuke Niwa 2011-03-14 11:26:28 PDT
Xan, can you review GTK part of it so that Martin can land this patch?
Comment 9 Martin Robinson 2011-03-15 09:02:06 PDT
Comment on attachment 84426 [details]
Patch with rniwa's suggestions

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

> Source/WebKit/gtk/webkit/webkitwebview.cpp:413
> +    // Never let the context menu abut very edge of the view.

I will change this to "Never let the context menu touch the very edge of the view."
Comment 10 Martin Robinson 2011-03-25 16:10:04 PDT
Created attachment 86992 [details]
Patch simplifying context menu margin and modifying comment
Comment 11 Xan Lopez 2011-04-01 15:47:47 PDT
Comment on attachment 86992 [details]
Patch simplifying context menu margin and modifying comment

r=me
Comment 12 Martin Robinson 2011-04-04 07:23:37 PDT
Comment on attachment 86992 [details]
Patch simplifying context menu margin and modifying comment

Clearing flags on attachment: 86992

Committed r82831: <http://trac.webkit.org/changeset/82831>
Comment 13 Martin Robinson 2011-04-04 07:23:51 PDT
All reviewed patches have been landed.  Closing bug.