Changeset 107719 in webkit


Ignore:
Timestamp:
Feb 14, 2012 11:39:58 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

[BlackBerry] Dragging a selection handle outside of the content bounding box does not update the selection range correctly
https://bugs.webkit.org/show_bug.cgi?id=78608

Ensure that when selection handles leave the content bounding box that
the handle not being dragged remains fixed. Do not applying padding to
a direction that would cause the selection to shrink when performing
the handle direction detection.

Patch by Ed Baker <edbaker@rim.com> on 2012-02-14
Reviewed by Rob Buis.

  • blackberry/WebKitSupport/SelectionHandler.cpp:

(BlackBerry::WebKit::directionOfPointRelativeToRect):
(BlackBerry::WebKit::SelectionHandler::extendSelectionToFieldBoundary):
(BlackBerry::WebKit::SelectionHandler::clipPointToFocusNode):
(BlackBerry::WebKit::SelectionHandler::setSelection):

  • blackberry/WebKitSupport/SelectionHandler.h:
Location:
trunk/Source/WebKit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r107716 r107719  
     12012-02-14  Ed Baker  <edbaker@rim.com>
     2
     3        [BlackBerry] Dragging a selection handle outside of the content bounding box does not update the selection range correctly
     4        https://bugs.webkit.org/show_bug.cgi?id=78608
     5
     6        Ensure that when selection handles leave the content bounding box that
     7        the handle not being dragged remains fixed. Do not applying padding to
     8        a direction that would cause the selection to shrink when performing
     9        the handle direction detection.
     10
     11        Reviewed by Rob Buis.
     12
     13        * blackberry/WebKitSupport/SelectionHandler.cpp:
     14        (BlackBerry::WebKit::directionOfPointRelativeToRect):
     15        (BlackBerry::WebKit::SelectionHandler::extendSelectionToFieldBoundary):
     16        (BlackBerry::WebKit::SelectionHandler::clipPointToFocusNode):
     17        (BlackBerry::WebKit::SelectionHandler::setSelection):
     18        * blackberry/WebKitSupport/SelectionHandler.h:
     19
    1202012-02-14  Rob Buis  <rbuis@rim.com>
    221
  • trunk/Source/WebKit/blackberry/WebKitSupport/SelectionHandler.cpp

    r107674 r107719  
    171171}
    172172
    173 static unsigned short directionOfPointRelativeToRect(const IntPoint& point, const IntRect& rect)
     173static unsigned short directionOfPointRelativeToRect(const IntPoint& point, const IntRect& rect, const bool useTopPadding = true, const bool useBottomPadding = true)
    174174{
    175175    ASSERT(!rect.contains(point));
     
    180180    // Do height movement check first but add padding. We may be off on both x & y axis and only
    181181    // want to move in one direction at a time.
    182     if (point.y() + verticalPadding < rect.y())
     182    if (point.y() + (useTopPadding ? verticalPadding : 0) < rect.y())
    183183        return KEYCODE_UP;
    184     if (point.y() > rect.maxY() + verticalPadding)
     184    if (point.y() > rect.maxY() + (useBottomPadding ? verticalPadding : 0))
    185185        return KEYCODE_DOWN;
    186186    if (point.x() < rect.location().x())
     
    343343
    344344    IntRect nodeBoundingBox = focusedFrame->document()->focusedNode()->renderer()->absoluteBoundingBoxRect();
     345    nodeBoundingBox.inflate(-1);
    345346
    346347    // Start handle is outside of the field. Treat it as the changed handle and move
    347348    // relative to the start caret rect.
    348     unsigned short character = directionOfPointRelativeToRect(selectionPoint, caretRect);
     349    unsigned short character = directionOfPointRelativeToRect(selectionPoint, caretRect, isStartHandle /*useTopPadding*/, !isStartHandle /*useBottomPadding*/);
    349350
    350351    // Prevent incorrect movement, handles can only extend the selection this way
     
    354355        character = 0;
    355356
    356     VisiblePosition newVisiblePosition = controller->selection().start();
     357    VisiblePosition newVisiblePosition = isStartHandle ? controller->selection().extent() : controller->selection().base();
    357358    // Extend the selection to the bounds of the box before doing incremental scroll if the point is outside the node.
    358359    // Don't extend selection and handle the character at the same time.
     
    361362
    362363    if (isStartHandle)
    363         newSelection = VisibleSelection(newVisiblePosition, newSelection.visibleEnd(), true /*isDirectional*/);
     364        newSelection = VisibleSelection(newVisiblePosition, newSelection.extent(), true /*isDirectional*/);
    364365    else
    365         newSelection = VisibleSelection(newSelection.visibleStart(), newVisiblePosition, true /*isDirectional*/);
     366        newSelection = VisibleSelection(newSelection.base(), newVisiblePosition, true /*isDirectional*/);
    366367
    367368    // If no selection will be changed, return the character to extend using navigation.
     
    433434}
    434435
     436IntPoint SelectionHandler::clipPointToFocusNode(const IntPoint& point)
     437{
     438    Frame* focusedFrame = m_webPage->focusedOrMainFrame();
     439    FrameSelection* controller = focusedFrame->selection();
     440
     441    if (!focusedFrame->document()->focusedNode() || !focusedFrame->document()->focusedNode()->renderer())
     442        return point;
     443
     444    IntRect focusedNodeBoundingBox = focusedFrame->document()->focusedNode()->renderer()->absoluteBoundingBoxRect();
     445    focusedNodeBoundingBox.inflate(-1);
     446
     447    IntPoint clippedPoint = point;
     448    if (!focusedNodeBoundingBox.contains(clippedPoint))
     449        clippedPoint = IntPoint(
     450            point.x() < focusedNodeBoundingBox.x() ? focusedNodeBoundingBox.x() : std::min(focusedNodeBoundingBox.maxX(), point.x()),
     451            point.y() < focusedNodeBoundingBox.y() ? focusedNodeBoundingBox.y() : std::min(focusedNodeBoundingBox.maxY(), point.y()));
     452
     453    return clippedPoint;
     454}
     455
    435456void SelectionHandler::setSelection(const IntPoint& start, const IntPoint& end)
    436457{
     
    467488
    468489        // Set the selection with validation.
    469         newSelection.setBase(visiblePositionForPointIgnoringClipping(*focusedFrame, relativeStart));
     490        newSelection.setBase(visiblePositionForPointIgnoringClipping(*focusedFrame, clipPointToFocusNode(relativeStart)));
    470491
    471492        // Reset the selection using the existing extent without validation.
     
    477498
    478499        // Set the selection with validation.
    479         newSelection.setExtent(visiblePositionForPointIgnoringClipping(*focusedFrame, relativeEnd));
     500        newSelection.setExtent(visiblePositionForPointIgnoringClipping(*focusedFrame, clipPointToFocusNode(relativeEnd)));
    480501
    481502        // Reset the selection using the existing base without validation.
  • trunk/Source/WebKit/blackberry/WebKitSupport/SelectionHandler.h

    r107674 r107719  
    7878    bool shouldUpdateSelectionOrCaretForPoint(const WebCore::IntPoint&, const WebCore::IntRect&, bool startCaret = true) const;
    7979    unsigned short extendSelectionToFieldBoundary(bool isStartHandle, const WebCore::IntPoint& selectionPoint, WebCore::VisibleSelection& newSelection);
     80    WebCore::IntPoint clipPointToFocusNode(const WebCore::IntPoint&);
    8081
    8182    WebPagePrivate* m_webPage;
Note: See TracChangeset for help on using the changeset viewer.