Bug 132200 - Add a selection overlay
Summary: Add a selection overlay
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: 528+ (Nightly build)
Hardware: Macintosh All
: P2 Normal
Assignee: Brady Eidson
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-04-25 11:42 PDT by Brady Eidson
Modified: 2014-04-25 15:22 PDT (History)
5 users (show)

See Also:


Attachments
Patch v1 (31.99 KB, patch)
2014-04-25 12:01 PDT, Brady Eidson
no flags Details | Formatted Diff | Diff
Patch v2 (31.63 KB, patch)
2014-04-25 13:08 PDT, Brady Eidson
hyatt: review-
hyatt: commit-queue-
Details | Formatted Diff | Diff
Patch v3 with Hyatt's suggestion (42.49 KB, patch)
2014-04-25 14:17 PDT, Brady Eidson
beidson: review-
beidson: commit-queue-
Details | Formatted Diff | Diff
Patch v4 (41.98 KB, patch)
2014-04-25 14:23 PDT, Brady Eidson
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brady Eidson 2014-04-25 11:42:37 PDT
Add a basic (non-functional) selection overlay that tracks the rects for the current selection.

<rdar://problem/16727797>
Comment 1 Brady Eidson 2014-04-25 12:01:54 PDT
Created attachment 230189 [details]
Patch v1
Comment 2 WebKit Commit Bot 2014-04-25 12:03:25 PDT
Attachment 230189 [details] did not pass style-queue:


ERROR: Source/WebCore/rendering/RenderView.cpp:772:  Missing space inside { }.  [whitespace/braces] [5]
Total errors found: 1 in 13 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 Tim Horton 2014-04-25 12:14:45 PDT
Comment on attachment 230189 [details]
Patch v1

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

> Source/WebCore/rendering/RenderView.cpp:776
> +            m_view->view().frame().editor().client()->selectionRectsDidChange(m_view->m_currentSelectionRects);

What if client is null?

> Source/WebCore/rendering/RenderView.cpp:779
> +        RenderView* m_view;

reference

> Source/WebKit2/WebProcess/WebPage/SelectionOverlayController.cpp:81
> +    m_selectionOverlay = 0;

nullptr. And, remind me why you don't hold a reference to your overlay?

> Source/WebKit2/WebProcess/WebPage/SelectionOverlayController.h:34
> +#if PLATFORM(MAC)

don't think there's any reason for this (or any of the other PLATFORM(MAC)s. Isn't ENABLE(SERVICE_CONTROLS) already pretty PLATFORM(MAC) specific?

> Source/WebKit2/WebProcess/WebPage/mac/SelectionOverlayControllerMac.mm:76
> +        // FIXME: We need to do the following, but SOFT_LINK isn't working for this method.
> +//        if (m_mouseIsOverHighlight && onButton && m_mouseDownPosition != IntPoint())
> +//            DDHighlightSetButtonPressed(m_currentHighlight.get(), true);

get rid of this for now? at least put the // in the right place

> Source/WebKit2/WebProcess/WebPage/mac/SelectionOverlayControllerMac.mm:151
> +            // DDHighlightSetButtonPressed(m_currentHighlight.get(), true);

:|

> Source/WebKit2/WebProcess/WebPage/mac/SelectionOverlayControllerMac.mm:170
> +    m_mouseDownPosition = IntPoint();

that is a valid mouse position. what makes 0,0 special? is there any reason to do this? should you be setting a bool regarding its validity instead?
Comment 4 Brady Eidson 2014-04-25 12:51:18 PDT
(In reply to comment #3)
> (From update of attachment 230189 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=230189&action=review
> 
> > Source/WebCore/rendering/RenderView.cpp:776
> > +            m_view->view().frame().editor().client()->selectionRectsDidChange(m_view->m_currentSelectionRects);
> 
> What if client is null?

There's some spots in the project where EditorClient is null checked, and some where it's not.  Appears to be about 50/50.

What a mess.

I'll null check just for giggles.
 
> > Source/WebCore/rendering/RenderView.cpp:779
> > +        RenderView* m_view;
> 
> reference

Sure.

> > Source/WebKit2/WebProcess/WebPage/SelectionOverlayController.cpp:81
> > +    m_selectionOverlay = 0;
> 
> nullptr. And, remind me why you don't hold a reference to your overlay?

Find, WebInspector, and Telephone number overlays are also raw pointers.

Not sure why the first of those didn't hold a ref, but none of the clients truly own their overlays.

> 
> > Source/WebKit2/WebProcess/WebPage/SelectionOverlayController.h:34
> > +#if PLATFORM(MAC)
> 
> don't think there's any reason for this (or any of the other PLATFORM(MAC)s. Isn't ENABLE(SERVICE_CONTROLS) already pretty PLATFORM(MAC) specific?

I removed some of them, but not all of them.

> > Source/WebKit2/WebProcess/WebPage/mac/SelectionOverlayControllerMac.mm:76
> > +        // FIXME: We need to do the following, but SOFT_LINK isn't working for this method.
> > +//        if (m_mouseIsOverHighlight && onButton && m_mouseDownPosition != IntPoint())
> > +//            DDHighlightSetButtonPressed(m_currentHighlight.get(), true);
> 
> get rid of this for now? at least put the // in the right place

I'll put the // in the right place.

If the comment and code is completely removed, it's *much* more likely to be forgotten even in the short term.

> > Source/WebKit2/WebProcess/WebPage/mac/SelectionOverlayControllerMac.mm:170
> > +    m_mouseDownPosition = IntPoint();
> 
> that is a valid mouse position. what makes 0,0 special? is there any reason to do this? should you be setting a bool regarding its validity instead?

You didn't catch this in the telephone number version!  :)

There's definitely a reason to track the mouse down position.  I'll add a bool.
Comment 5 Brady Eidson 2014-04-25 12:54:38 PDT
(In reply to comment #4)
> > > Source/WebKit2/WebProcess/WebPage/mac/SelectionOverlayControllerMac.mm:170
> > > +    m_mouseDownPosition = IntPoint();
> > 
> > that is a valid mouse position. what makes 0,0 special? is there any reason to do this? should you be setting a bool regarding its validity instead?
> 
> You didn't catch this in the telephone number version!  :)
> 
> There's definitely a reason to track the mouse down position.  I'll add a bool.

Actually, just the bool is good enough.  sweet.
Comment 6 Brady Eidson 2014-04-25 13:08:01 PDT
Created attachment 230194 [details]
Patch v2
Comment 7 Dave Hyatt 2014-04-25 13:12:06 PDT
Comment on attachment 230194 [details]
Patch v2

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

r-

> Source/WebCore/rendering/RenderView.cpp:784
> +#if ENABLE(SERVICE_CONTROLS)
> +    m_currentSelectionRects.clear();
> +
> +    // Always notify the EditorClient of the new selection rects, no matter what they are.
> +    struct SelectionRectNotifier {
> +        SelectionRectNotifier(RenderView& view)
> +            : m_view(view)
> +        { }
> +
> +        ~SelectionRectNotifier()
> +        {
> +            if (EditorClient* client =  m_view.view().frame().editor().client())
> +                client->selectionRectsDidChange(m_view.m_currentSelectionRects);
> +        }
> +
> +        RenderView& m_view;
> +    };
> +
> +    SelectionRectNotifier notifier(*this);
> +#endif // ENABLE(SERVICE_CONTROLS)

It's gross to have this big block of code right in RenderView::setSelection. I would put this in a helper. I'd even define SelectionRectNotifier in a header and get it out of here too.

> Source/WebCore/rendering/RenderView.cpp:967
> +#if ENABLE(SERVICE_CONTROLS)
> +            LayoutRect rect = selectionInfo->rect();
> +            if (!rect.isEmpty())
> +                m_currentSelectionRects.append(rect);
> +#endif
> +
> +            newSelectedObjects.set(o, std::move(selectionInfo));

Beef up SelectionRectNotifier into some kind of controller class and move the currentSelectionRects there. Then this becomes one call on the new class.

> Source/WebCore/rendering/RenderView.cpp:985
> +#if ENABLE(SERVICE_CONTROLS)
> +                GapRects rects = blockInfo->rects();
> +                if (!rects.left().isEmpty())
> +                    m_currentSelectionRects.append(rects.left());
> +                if (!rects.right().isEmpty())
> +                    m_currentSelectionRects.append(rects.right());
> +                if (!rects.center().isEmpty())
> +                    m_currentSelectionRects.append(rects.center());
> +#endif

Same here. You could make this a single function call on a separate object.

> Source/WebCore/rendering/RenderView.h:360
> +#if ENABLE(SERVICE_CONTROLS)
> +    Vector<LayoutRect> m_currentSelectionRects;
> +#endif

Have a separate class here instead (similar to how we keep flow thread controller logic in a separate class).
Comment 8 Brady Eidson 2014-04-25 14:17:48 PDT
Created attachment 230198 [details]
Patch v3 with Hyatt's suggestion
Comment 9 Brady Eidson 2014-04-25 14:18:21 PDT
Comment on attachment 230198 [details]
Patch v3 with Hyatt's suggestion

Nevermind
Comment 10 Brady Eidson 2014-04-25 14:23:09 PDT
Created attachment 230200 [details]
Patch v4
Comment 11 Dave Hyatt 2014-04-25 14:25:27 PDT
Comment on attachment 230200 [details]
Patch v4

r=me
Comment 12 WebKit Commit Bot 2014-04-25 15:22:46 PDT
Comment on attachment 230200 [details]
Patch v4

Clearing flags on attachment: 230200

Committed r167830: <http://trac.webkit.org/changeset/167830>
Comment 13 WebKit Commit Bot 2014-04-25 15:22:49 PDT
All reviewed patches have been landed.  Closing bug.