Changeset 85377 in webkit


Ignore:
Timestamp:
Apr 29, 2011 6:13:28 PM (13 years ago)
Author:
rniwa@webkit.org
Message:

2011-04-29 Ryosuke Niwa <rniwa@webkit.org>

Reviewed by Eric Seidel.

Extract a function to obtain VisiblePosition from RenderText::positionForPoint
https://bugs.webkit.org/show_bug.cgi?id=59811

Extracted lineDirectionPointFitsInBox from positionForPoint.

  • rendering/RenderText.cpp: (WebCore::lineDirectionPointFitsInBox): (WebCore::RenderText::positionForPoint):
Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r85375 r85377  
     12011-04-29  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        Extract a function to obtain VisiblePosition from RenderText::positionForPoint
     6        https://bugs.webkit.org/show_bug.cgi?id=59811
     7
     8        Extracted lineDirectionPointFitsInBox from positionForPoint.
     9
     10        * rendering/RenderText.cpp:
     11        (WebCore::lineDirectionPointFitsInBox):
     12        (WebCore::RenderText::positionForPoint):
     13
    1142011-04-29  Geoffrey Garen  <ggaren@apple.com>
    215
  • trunk/Source/WebCore/rendering/RenderText.cpp

    r85036 r85377  
    435435}
    436436
     437static bool lineDirectionPointFitsInBox(int pointLineDirection, InlineTextBox* box, int offset, EAffinity& affinity)
     438{
     439    affinity = DOWNSTREAM;
     440
     441    // the x coordinate is equal to the left edge of this box
     442    // the affinity must be downstream so the position doesn't jump back to the previous line
     443    if (pointLineDirection == box->logicalLeft())
     444        return true;
     445
     446    // and the x coordinate is to the left of the right edge of this box
     447    // check to see if position goes in this box
     448    if (pointLineDirection < box->logicalRight()) {
     449        affinity = offset > 0 ? VP_UPSTREAM_IF_POSSIBLE : DOWNSTREAM;
     450        return true;
     451    }
     452
     453    // box is first on line
     454    // and the x coordinate is to the left of the first text box left edge
     455    if (!box->prevOnLine() && pointLineDirection < box->logicalLeft())
     456        return true;
     457
     458    if (!box->nextOnLine()) {
     459        // box is last on line
     460        // and the x coordinate is to the right of the last text box right edge
     461        // generate VisiblePosition, use UPSTREAM affinity if possible
     462        affinity = offset > 0 ? VP_UPSTREAM_IF_POSSIBLE : DOWNSTREAM;
     463        return true;
     464    }
     465
     466    return false;
     467}
     468
    437469VisiblePosition RenderText::positionForPoint(const IntPoint& point)
    438470{
     
    467499            if (rootBox->nextRootBox())
    468500                bottom = min(bottom, rootBox->nextRootBox()->lineTop());
     501
    469502            if (pointBlockDirection < bottom) {
    470                 offset = box->offsetForPosition(pointLineDirection);
    471 
    472                 if (pointLineDirection == box->logicalLeft())
    473                     // the x coordinate is equal to the left edge of this box
    474                     // the affinity must be downstream so the position doesn't jump back to the previous line
    475                     return createVisiblePosition(offset + box->start(), DOWNSTREAM);
    476 
    477                 if (pointLineDirection < box->logicalRight())
    478                     // and the x coordinate is to the left of the right edge of this box
    479                     // check to see if position goes in this box
    480                     return createVisiblePosition(offset + box->start(), offset > 0 ? VP_UPSTREAM_IF_POSSIBLE : DOWNSTREAM);
    481 
    482                 if (!box->prevOnLine() && pointLineDirection < box->logicalLeft())
    483                     // box is first on line
    484                     // and the x coordinate is to the left of the first text box left edge
    485                     return createVisiblePosition(offset + box->start(), DOWNSTREAM);
    486 
    487                 if (!box->nextOnLine())
    488                     // box is last on line
    489                     // and the x coordinate is to the right of the last text box right edge
    490                     // generate VisiblePosition, use UPSTREAM affinity if possible
    491                     return createVisiblePosition(offset + box->start(), offset > 0 ? VP_UPSTREAM_IF_POSSIBLE : DOWNSTREAM);
     503                EAffinity affinity;
     504                int offset = box->offsetForPosition(pointLineDirection);
     505                if (lineDirectionPointFitsInBox(pointLineDirection, box, offset, affinity))
     506                    return createVisiblePosition(offset + box->start(), affinity);
    492507            }
    493508            lastBoxAbove = box;
Note: See TracChangeset for help on using the changeset viewer.