Changeset 38186 in webkit


Ignore:
Timestamp:
Nov 6, 2008 10:42:24 AM (15 years ago)
Author:
Simon Fraser
Message:

2008-11-05 Simon Fraser <Simon Fraser>

Reviewed by Dave Hyatt

https://bugs.webkit.org/show_bug.cgi?id=21870

Implement absoluteToLocal() to convert a point from absolute
to local coordinates, optionally taking transforms into account.

Use this to set offsetX/offsetY in mouse events, thus fixing
offsetX/offsetY in events on elements with transforms.

Test: fast/events/offsetX-offsetY.html

Location:
trunk
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r38148 r38186  
     12008-11-05  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Reviewed by Dave Hyatt
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=21870
     6       
     7        Test event.offsetX/offsetY for various types of elements, which
     8        exercises absoluteToLocal() code.
     9
     10        * fast/events/offsetX-offsetY-expected.txt: Added.
     11        * fast/events/offsetX-offsetY.html: Added.
     12
    1132008-11-05  Gavin Barraclough  <barraclough@apple.com>
    214
  • trunk/WebCore/ChangeLog

    r38184 r38186  
     12008-11-05  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Reviewed by Dave Hyatt
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=21870
     6       
     7        Implement absoluteToLocal() to convert a point from absolute
     8        to local coordinates, optionally taking transforms into account.
     9       
     10        Use this to set offsetX/offsetY in mouse events, thus fixing
     11        offsetX/offsetY in events on elements with transforms.
     12
     13        Test: fast/events/offsetX-offsetY.html
     14
     15        * dom/MouseRelatedEvent.cpp:
     16        (WebCore::MouseRelatedEvent::receivedTarget):
     17        * rendering/RenderBox.cpp:
     18        (WebCore::RenderBox::localToAbsolute):
     19        (WebCore::RenderBox::absoluteToLocal):
     20        (WebCore::RenderBox::offsetFromContainer):
     21        * rendering/RenderBox.h:
     22        * rendering/RenderObject.cpp:
     23        (WebCore::RenderObject::absoluteToLocal):
     24        * rendering/RenderObject.h:
     25        * rendering/RenderTableCell.cpp:
     26        (WebCore::RenderTableCell::localToAbsolute):
     27        (WebCore::RenderTableCell::absoluteToLocal):
     28        * rendering/RenderTableCell.h:
     29        * rendering/RenderView.cpp:
     30        (WebCore::RenderView::absoluteToLocal):
     31        * rendering/RenderView.h:
     32
    1332008-11-06  Alp Toker  <alp@nuanti.com>
    234
  • trunk/WebCore/dom/MouseRelatedEvent.cpp

    r38098 r38186  
    134134    if (!isSimulated()) {
    135135        if (RenderObject* r = targ->renderer()) {
    136             // FIXME: This doesn't work correctly with transforms. We need
    137             // an absoluteToLocal() method.
    138             FloatPoint absPos = r->localToAbsolute();
    139             m_offsetX -= absPos.x();
    140             m_offsetY -= absPos.y();
     136            FloatPoint absPos = r->absoluteToLocal(FloatPoint(m_pageX, m_pageY), false, true);
     137            m_offsetX = absPos.x();
     138            m_offsetY = absPos.y();
    141139        }
    142140    }
  • trunk/WebCore/rendering/RenderBox.cpp

    r38098 r38186  
    10151015        }
    10161016
    1017         if (isRelPositioned())
    1018             localPoint += relativePositionOffset();
    1019 
    1020         if (!isInline() || isReplaced()) {
    1021             RenderBlock* cb;
    1022             if (o->isBlockFlow() && style()->position() != AbsolutePosition && style()->position() != FixedPosition
    1023                     && (cb = static_cast<RenderBlock*>(o))->hasColumns()) {
    1024                 IntRect rect(m_x, m_y, 1, 1);
    1025                 cb->adjustRectForColumns(rect);
    1026                 localPoint.move(rect.x(), rect.y());
    1027             } else
    1028                 localPoint.move(m_x, m_y);
    1029         }
    1030 
    1031         if (o->hasOverflowClip())
    1032             localPoint -= o->layer()->scrolledContentOffset();
    1033 
    1034         if (style()->position() == AbsolutePosition)
    1035             localPoint += offsetForPositionedInContainer(o);
     1017        localPoint += offsetFromContainer(o);
    10361018
    10371019        return o->localToAbsoluteForContent(localPoint, fixed, useTransforms);
     
    10391021   
    10401022    return FloatPoint();
     1023}
     1024
     1025FloatPoint RenderBox::absoluteToLocal(FloatPoint containerPoint, bool fixed, bool useTransforms) const
     1026{
     1027    // We don't expect absoluteToLocal() to be called during layout (yet)
     1028    ASSERT(!view() || !view()->layoutState());
     1029   
     1030    if (style()->position() == FixedPosition)
     1031        fixed = true;
     1032
     1033    if (useTransforms && m_layer && m_layer->transform())
     1034        fixed = false;
     1035   
     1036    RenderObject* o = container();
     1037    if (o) {
     1038        FloatPoint localPoint = o->absoluteToLocal(containerPoint, fixed, useTransforms);
     1039
     1040        // Take into account space above a vertically aligned table cell
     1041        // (see localToAbsoluteForContent())
     1042        localPoint.move(0.0f, -static_cast<float>(borderTopExtra()));
     1043
     1044        localPoint -= offsetFromContainer(o);
     1045
     1046        if (useTransforms && m_layer && m_layer->transform())
     1047            localPoint = m_layer->transform()->inverse().mapPoint(localPoint);
     1048       
     1049        return localPoint;
     1050    }
     1051   
     1052    return FloatPoint();
     1053}
     1054
     1055IntSize RenderBox::offsetFromContainer(RenderObject* o) const
     1056{
     1057    ASSERT(o == container());
     1058
     1059    IntSize offset;   
     1060    if (isRelPositioned())
     1061        offset += relativePositionOffset();
     1062
     1063    if (!isInline() || isReplaced()) {
     1064        RenderBlock* cb;
     1065        if (o->isBlockFlow() && style()->position() != AbsolutePosition && style()->position() != FixedPosition
     1066                && (cb = static_cast<RenderBlock*>(o))->hasColumns()) {
     1067            IntRect rect(m_x, m_y, 1, 1);
     1068            cb->adjustRectForColumns(rect);
     1069            offset.expand(rect.x(), rect.y());
     1070        } else
     1071            offset.expand(m_x, m_y);
     1072    }
     1073
     1074    if (o->hasOverflowClip())
     1075        offset -= o->layer()->scrolledContentOffset();
     1076
     1077    if (style()->position() == AbsolutePosition)
     1078        offset += offsetForPositionedInContainer(o);
     1079
     1080    return offset;
    10411081}
    10421082
  • trunk/WebCore/rendering/RenderBox.h

    r38098 r38186  
    5151
    5252    virtual FloatPoint localToAbsolute(FloatPoint localPoint = FloatPoint(), bool fixed = false, bool useTransforms = false) const;
     53    virtual FloatPoint absoluteToLocal(FloatPoint containerPoint, bool fixed = false, bool useTransforms = false) const;
    5354
    5455    virtual int xPos() const { return m_x; }
     
    190191    virtual bool shouldCalculateSizeAsReplaced() const { return isReplaced() && !isInlineBlockOrInlineTable(); }
    191192
     193    IntSize offsetFromContainer(RenderObject*) const;
     194   
    192195private:
    193196    void paintRootBoxDecorations(PaintInfo&, int tx, int ty);
  • trunk/WebCore/rendering/RenderObject.cpp

    r38098 r38186  
    23862386}
    23872387
     2388FloatPoint RenderObject::absoluteToLocal(FloatPoint containerPoint, bool fixed, bool useTransforms) const
     2389{
     2390    RenderObject* o = parent();
     2391    if (o) {
     2392        FloatPoint localPoint = o->absoluteToLocal(containerPoint, fixed, useTransforms);
     2393        localPoint.move(0.0f, -static_cast<float>(o->borderTopExtra()));
     2394        if (o->hasOverflowClip())
     2395            localPoint += o->layer()->scrolledContentOffset();
     2396        return localPoint;
     2397    }
     2398    return FloatPoint();
     2399}
     2400
    23882401IntRect RenderObject::caretRect(InlineBox* inlineBox, int caretOffset, int* extraWidthToEndOfLine)
    23892402{
  • trunk/WebCore/rendering/RenderObject.h

    r38098 r38186  
    584584    // FIXME: Temporary. If useTransforms is true, take transforms into account. Eventually localToAbsolute() will always be transform-aware.
    585585    virtual FloatPoint localToAbsolute(FloatPoint localPoint = FloatPoint(), bool fixed = false, bool useTransforms = false) const;
     586    virtual FloatPoint absoluteToLocal(FloatPoint, bool fixed = false, bool useTransforms = false) const;
    586587
    587588    // This function is used to deal with the extra top space that can occur in table cells (called borderTopExtra).
  • trunk/WebCore/rendering/RenderTableCell.cpp

    r38098 r38186  
    199199FloatPoint RenderTableCell::localToAbsolute(FloatPoint localPoint, bool fixed, bool useTransforms) const
    200200{
    201     FloatPoint result = RenderBlock::localToAbsolute(localPoint, fixed, useTransforms);
    202201    RenderView* v = view();
    203202    if ((!v || !v->layoutState()) && parent()) {
    204203        // Rows are in the same coordinate space, so don't add their offset in.
    205         result.move(-parent()->xPos(), -parent()->yPos());
    206     }
    207     return result;
     204        localPoint.move(-parent()->xPos(), -parent()->yPos());
     205    }
     206    return RenderBlock::localToAbsolute(localPoint, fixed, useTransforms);;
     207}
     208
     209FloatPoint RenderTableCell::absoluteToLocal(FloatPoint containerPoint, bool fixed, bool useTransforms) const
     210{
     211    FloatPoint localPoint = RenderBlock::absoluteToLocal(containerPoint, fixed, useTransforms);
     212    if (parent()) {
     213        // Rows are in the same coordinate space, so add their offset back in.
     214        localPoint.move(parent()->xPos(), parent()->yPos());
     215    }
     216    return localPoint;
    208217}
    209218
  • trunk/WebCore/rendering/RenderTableCell.h

    r38098 r38186  
    103103    virtual void computeAbsoluteRepaintRect(IntRect&, bool fixed = false);
    104104    virtual FloatPoint localToAbsolute(FloatPoint localPoint = FloatPoint(), bool fixed = false, bool useTransforms = false) const;
     105    virtual FloatPoint absoluteToLocal(FloatPoint containerPoint, bool fixed = false, bool useTransforms = false) const;
    105106
    106107    virtual int baselinePosition(bool firstLine = false, bool isRootLineBox = false) const;
  • trunk/WebCore/rendering/RenderView.cpp

    r38098 r38186  
    140140}
    141141
     142FloatPoint RenderView::absoluteToLocal(FloatPoint containerPoint, bool fixed, bool useTransforms) const
     143{
     144    if (fixed && m_frameView)
     145        containerPoint -= m_frameView->scrollOffset();
     146
     147    return containerPoint;
     148}
     149
    142150void RenderView::paint(PaintInfo& paintInfo, int tx, int ty)
    143151{
  • trunk/WebCore/rendering/RenderView.h

    r38098 r38186  
    4646    virtual void calcPrefWidths();
    4747    virtual FloatPoint localToAbsolute(FloatPoint localPoint = FloatPoint(), bool fixed = false, bool useTransforms = false) const;
     48    virtual FloatPoint absoluteToLocal(FloatPoint containerPoint, bool fixed = false, bool useTransforms = false) const;
    4849   
    4950    int docHeight() const;
Note: See TracChangeset for help on using the changeset viewer.