Changeset 25057 in webkit


Ignore:
Timestamp:
Aug 13, 2007 12:14:49 PM (17 years ago)
Author:
justing
Message:

LayoutTests:

Reviewed by Darin.


<rdar://problem/5333725> -webkit-user-select: none makes selection difficult

  • editing/selection/5333725-expected.checksum: Added.
  • editing/selection/5333725-expected.png: Added.
  • editing/selection/5333725-expected.txt: Added.
  • editing/selection/5333725.html: Added.


Added a workaround for a bug where -webkit-user-select:none
has no effect on the body if placed on the html element:

  • editing/selection/select-all-user-select-none.html:

WebCore:

Reviewed by Darin.


<rdar://problem/5333725> -webkit-user-select: none makes selection difficult


Let users create selections if they mouse down in a -webkit-user-select:none
region, just (continue to) disallow selection endpoints in those regions, and
don't paint those regions as selected if they are fully enclosed by a selection.
For example, in xxyyyxx where x is -webkit-user-select:none, a user can mouse down
between the first two xs and drag across yyy to the second two xs to create a
selection xxyyyxx.


  • editing/SelectionController.cpp: (WebCore::SelectionController::selectAll): Allow selectAll inside a root that has -webkit-user-select:none, because it may contain content that is selectable (VisiblePosition and Selection creation will keep Selection endpoints out of -webkit-user-select:none regions).
  • page/EventHandler.cpp: (WebCore::EventHandler::selectClosestWordFromMouseEvent): Use canMouseDownStartSelect instead of the ambiguously named shouldSelect(). (WebCore::EventHandler::handleMousePressEventTripleClick): Ditto. (WebCore::EventHandler::handleMousePressEventSingleClick): Ditto. (WebCore::EventHandler::updateSelectionForMouseDrag): Use canMouseDragExtendSelect. (WebCore::EventHandler::selectCursor): Paint an ibeam in -webkit-user-select:none regions, because you can click in those regions to create a selection. (WebCore::EventHandler::canMouseDownStartSelect): Now fires the selectStart event, and returns true in -webkit-user-select: none regions. (WebCore::EventHandler::canMouseDragExtendSelect): This is identical to canMouseDownStartSelect because of 12823, even though it seems strange that we would fire the selectStart event here.
  • page/EventHandler.h:
  • rendering/RenderObject.cpp: (WebCore::RenderObject::draggableNode): Only -webkit-user-select:ignore regions will prevent selection creation.
  • rendering/RenderObject.h:
Location:
trunk
Files:
4 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r25056 r25057  
     12007-08-13  Justin Garcia  <justin.garcia@apple.com>
     2
     3        Reviewed by Darin.
     4       
     5        <rdar://problem/5333725> -webkit-user-select: none makes selection difficult
     6
     7        * editing/selection/5333725-expected.checksum: Added.
     8        * editing/selection/5333725-expected.png: Added.
     9        * editing/selection/5333725-expected.txt: Added.
     10        * editing/selection/5333725.html: Added.
     11       
     12        Added a workaround for a bug where -webkit-user-select:none
     13        has no effect on the body if placed on the html element:
     14        * editing/selection/select-all-user-select-none.html:
     15
    1162007-08-13  Anders Carlsson  <andersca@apple.com>
    217
  • trunk/LayoutTests/editing/selection/select-all-user-select-none.html

    r18338 r25057  
    22    <head>
    33        <style>
    4         html {
     4        body {
    55            -webkit-user-select: none;
    66        }
  • trunk/WebCore/ChangeLog

    r25056 r25057  
     12007-08-13  Justin Garcia  <justin.garcia@apple.com>
     2
     3        Reviewed by Darin.
     4       
     5        <rdar://problem/5333725> -webkit-user-select: none makes selection difficult
     6       
     7        Let users create selections if they mouse down in a -webkit-user-select:none
     8        region, just (continue to) disallow selection endpoints in those regions, and
     9        don't paint those regions as selected if they are fully enclosed by a selection.
     10        For example, in xxyyyxx where x is -webkit-user-select:none, a user can mouse down
     11        between the first two xs and drag across yyy to the second two xs to create a
     12        selection xx^yyy^xx.
     13       
     14        * editing/SelectionController.cpp:
     15        (WebCore::SelectionController::selectAll): Allow selectAll inside a root
     16        that has -webkit-user-select:none, because it may contain content that
     17        is selectable (VisiblePosition and Selection creation will keep Selection
     18        endpoints out of -webkit-user-select:none regions).
     19        * page/EventHandler.cpp:
     20        (WebCore::EventHandler::selectClosestWordFromMouseEvent): Use canMouseDownStartSelect
     21        instead of the ambiguously named shouldSelect().
     22        (WebCore::EventHandler::handleMousePressEventTripleClick): Ditto.
     23        (WebCore::EventHandler::handleMousePressEventSingleClick): Ditto.
     24        (WebCore::EventHandler::updateSelectionForMouseDrag): Use canMouseDragExtendSelect.
     25        (WebCore::EventHandler::selectCursor): Paint an ibeam in -webkit-user-select:none regions,
     26        because you can click in those regions to create a selection.
     27        (WebCore::EventHandler::canMouseDownStartSelect): Now fires the selectStart event, and
     28        returns true in -webkit-user-select: none regions.
     29        (WebCore::EventHandler::canMouseDragExtendSelect): This is identical to
     30        canMouseDownStartSelect because of 12823, even though it seems strange that we would fire
     31        the selectStart event here.
     32        * page/EventHandler.h:
     33        * rendering/RenderObject.cpp:
     34        (WebCore::RenderObject::draggableNode): Only -webkit-user-select:ignore regions will
     35        prevent selection creation.
     36        * rendering/RenderObject.h:
     37
    1382007-08-13  Anders Carlsson  <andersca@apple.com>
    239
  • trunk/WebCore/editing/SelectionController.cpp

    r24974 r25057  
    11721172   
    11731173    Node* root = isContentEditable() ? highestEditableRoot(m_sel.start()) : document->documentElement();
    1174     if (!root || !root->renderer() || !root->renderer()->canSelect())
     1174    if (!root)
    11751175        return;
    11761176    Selection newSelection(Selection::selectionFromContentsOfNode(root));
  • trunk/WebCore/page/EventHandler.cpp

    r24957 r25057  
    153153    Selection newSelection;
    154154
    155     if (innerNode && innerNode->renderer() && m_mouseDownMayStartSelect && innerNode->renderer()->shouldSelect()) {
     155    if (innerNode && innerNode->renderer() && m_mouseDownMayStartSelect) {
    156156        VisiblePosition pos(innerNode->renderer()->positionForPoint(result.localPoint()));
    157157        if (pos.isNotNull()) {
     
    194194   
    195195    Node* innerNode = event.targetNode();
    196     if (!(innerNode && innerNode->renderer() && m_mouseDownMayStartSelect
    197           && innerNode->renderer()->shouldSelect()))
     196    if (!(innerNode && innerNode->renderer() && m_mouseDownMayStartSelect))
    198197        return false;
    199198
     
    221220   
    222221    Node* innerNode = event.targetNode();
    223     if (!(innerNode && innerNode->renderer() && m_mouseDownMayStartSelect
    224           && innerNode->renderer()->shouldSelect()))
     222    if (!(innerNode && innerNode->renderer() && m_mouseDownMayStartSelect))
    225223        return false;
    226224
     
    409407    if (!targetRenderer)
    410408        return;
    411 
    412     if (!targetRenderer->shouldSelect())
     409       
     410    if (!canMouseDragExtendSelect(targetNode))
    413411        return;
    414412
     
    728726            if (m_frame->view() && layer && layer->isPointInResizeControl(m_frame->view()->windowToContents(event.event().pos())))
    729727                inResizer = true;
    730             if ((editable || (renderer && renderer->isText() && renderer->canSelect())) && !inResizer && !scrollbar)
     728            if ((editable || (renderer && renderer->isText() && renderer->style()->userSelect() != SELECT_IGNORE)) && !inResizer && !scrollbar)
    731729                return iBeamCursor();
    732730            return pointerCursor();
     
    13611359}
    13621360
     1361// Whether or not a mouse down can begin the creation of a selection.  Fires the selectStart event.
    13631362bool EventHandler::canMouseDownStartSelect(Node* node)
    13641363{
    13651364    if (!node || !node->renderer())
    13661365        return true;
    1367    
    1368     // Check to see if -webkit-user-select has been set to none
    1369     if (!node->renderer()->canSelect())
    1370         return false;
    13711366   
    13721367    // Some controls and images can't start a select on a mouse down.
     
    13741369        if (curr->style()->userSelect() == SELECT_IGNORE)
    13751370            return false;
     1371           
     1372    for (RenderObject* curr = node->renderer(); curr; curr = curr->parent())   
     1373        if (Node* node = curr->element())
     1374            return EventTargetNodeCast(node)->dispatchHTMLEvent(selectstartEvent, true, true);
    13761375   
    13771376    return true;
     1377}
     1378
     1379bool EventHandler::canMouseDragExtendSelect(Node* node)
     1380{
     1381    return canMouseDownStartSelect(node);
    13781382}
    13791383
  • trunk/WebCore/page/EventHandler.h

    r24957 r25057  
    196196
    197197    static bool canMouseDownStartSelect(Node*);
     198    static bool canMouseDragExtendSelect(Node*);
    198199
    199200    void handleAutoscroll(RenderObject*);
  • trunk/WebCore/rendering/RenderObject.cpp

    r24970 r25057  
    20122012#endif // NDEBUG
    20132013
    2014 static Node* selectStartNode(const RenderObject* object)
    2015 {
    2016     Node* node = 0;
    2017     bool forcedOn = false;
    2018 
    2019     for (const RenderObject* curr = object; curr; curr = curr->parent()) {
    2020         if (curr->style()->userSelect() == SELECT_TEXT)
    2021             forcedOn = true;
    2022         if (!forcedOn && curr->style()->userSelect() == SELECT_NONE)
    2023             return 0;
    2024 
    2025         if (!node)
    2026             node = curr->element();
    2027     }
    2028 
    2029     // somewhere up the render tree there must be an element!
    2030     ASSERT(node);
    2031 
    2032     return node;
    2033 }
    2034 
    2035 bool RenderObject::canSelect() const
    2036 {
    2037     return selectStartNode(this) != 0;
    2038 }
    2039 
    2040 bool RenderObject::shouldSelect() const
    2041 {
    2042     if (Node* node = selectStartNode(this))
    2043         return EventTargetNodeCast(node)->dispatchHTMLEvent(selectstartEvent, true, true);
    2044 
    2045     return false;
    2046 }
    2047 
    20482014Color RenderObject::selectionBackgroundColor() const
    20492015{
     
    20942060                return curr->node();
    20952061            }
    2096             if (curr->shouldSelect())
     2062            if (curr->style()->userSelect() != SELECT_IGNORE)
    20972063                // In this case we have a click in the unselected portion of text.  If this text is
    20982064                // selectable, we want to start the selection process instead of looking for a parent
  • trunk/WebCore/rendering/RenderObject.h

    r24907 r25057  
    755755    virtual bool hasSelectedChildren() const { return false; }
    756756
    757     // Whether or not a selection can be attempted on this object.
    758     bool canSelect() const;
    759 
    760     // Whether or not a selection can be attempted on this object.  Should only be called right before actually beginning a selection,
    761     // since it fires the selectstart DOM event.
    762     bool shouldSelect() const;
    763 
    764757    // Obtains the selection colors that should be used when painting a selection.
    765758    Color selectionBackgroundColor() const;
Note: See TracChangeset for help on using the changeset viewer.