Changeset 12514 in webkit


Ignore:
Timestamp:
Feb 1, 2006 2:36:00 PM (18 years ago)
Author:
bdakin
Message:

Patch by Darin. Reviewed by Beth.

Fix for <rdar://problem/4424126> REGRESSION(412-420+): yellow
highlight fails to follow cursor when mousing over star rating
(6232)

Event coordinates cannot be calculated until there is a target.
This patch restructures the code so that the coordinates are
initialized when the mouse event is created but are not calculated
until the target is set.

Location:
trunk/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r12513 r12514  
     12006-02-01  Darin Adler  <darin@apple.com>
     2
     3        Reviewed by Beth.
     4
     5        Fix for <rdar://problem/4424126> REGRESSION(412-420+): yellow
     6        highlight fails to follow cursor when mousing over star rating
     7        (6232)
     8
     9        Event coordinates cannot be calculated until there is a target.
     10        This patch restructures the code so that the coordinates are
     11        initialized when the mouse event is created but are not calculated
     12        until the target is set.
     13
     14        * khtml/xml/dom2_eventsimpl.cpp:
     15        (WebCore::EventImpl::setTarget): Now calls receievdTarget() if the
     16        target is not nil.
     17        (WebCore::EventImpl::receivedTarget): virtual receivedTarget()
     18        (WebCore::MouseRelatedEventImpl::MouseRelatedEventImpl): Call
     19        initCoordinates()
     20        (WebCore::MouseRelatedEventImpl::initCoordinates): Formerly called
     21        computePositions(), this now only initializes the coordinates and
     22        lets receivedTarget() take care of the computations.
     23        (WebCore::MouseRelatedEventImpl::receivedTarget): Takes care of
     24        computing the coordinates.
     25        (WebCore::MouseEventImpl::initMouseEvent): Call initCoordinates()
     26        * khtml/xml/dom2_eventsimpl.h:
     27        (WebCore::EventImpl::target): Fix spacing.
     28        (WebCore::EventImpl::currentTarget): Same.
     29        (WebCore::EventImpl::setCurrentTarget): Same.
     30
    1312006-01-31  Maciej Stachowiak  <mjs@apple.com>
    232
  • trunk/WebCore/khtml/xml/dom2_eventsimpl.cpp

    r12474 r12514  
    123123}
    124124
     125void EventImpl::setTarget(NodeImpl* target)
     126{
     127    m_target = target;
     128    if (target)
     129        receivedTarget();
     130}
     131
     132void EventImpl::receivedTarget()
     133{
     134}
     135
    125136// -----------------------------------------------------------------------------
    126137
     
    219230    , m_clientX(clientXArg), m_clientY(clientYArg)
    220231{
    221     computePositions();
    222 }
    223 
    224 void MouseRelatedEventImpl::computePositions()
    225 {
     232    initCoordinates();
     233}
     234
     235void MouseRelatedEventImpl::initCoordinates()
     236{
     237    // Set up initial values for coordinates.
     238    // Correct values can't be computed until we have at target, so receivedTarget
     239    // does the "real" computation.
    226240    m_pageX = m_clientX;
    227241    m_pageY = m_clientY;
    228 
    229242    m_layerX = m_pageX;
    230243    m_layerY = m_pageY;
    231 
    232244    m_offsetX = m_pageX;
    233245    m_offsetY = m_pageY;
    234 
    235     AbstractViewImpl* av = view();
    236     if (!av)
    237         return;
    238     DocumentImpl* doc = av->document();
     246}
     247
     248void MouseRelatedEventImpl::receivedTarget()
     249{
     250    // Compute coordinates that are based on the target.
     251    m_offsetX = m_pageX;
     252    m_offsetY = m_pageY;
     253    m_layerX = m_pageX;   
     254    m_layerY = m_pageY;   
     255
     256    // Can't do anything if the target is not in a document.
     257    NodeImpl* targ = target();
     258    ASSERT(targ);
     259    DocumentImpl* doc = targ->getDocument();
    239260    if (!doc)
    240261        return;
    241     FrameView* kv = doc->view();
    242     if (!kv)
    243         return;
    244 
     262
     263    // Must have an updated render tree for this math to work correctly.
    245264    doc->updateRendering();
    246265
     
    251270    // pageX and pageY here.
    252271
    253     // Compute offset position.
    254     // FIXME: This won't work because setTarget wasn't called yet!
    255     m_offsetX = m_pageX;
    256     m_offsetY = m_pageY;
     272    // Adjust offsetX/Y to be relative to the target's position.
    257273    if (!isSimulated()) {
    258         if (NodeImpl *n = target())
    259             if (RenderObject *r = n->renderer()) {
    260                 int rx, ry;
    261                 if (r->absolutePosition(rx, ry)) {
    262                     m_offsetX -= rx;
    263                     m_offsetY -= ry;
    264                 }
     274        if (RenderObject* r = targ->renderer()) {
     275            int rx, ry;
     276            if (r->absolutePosition(rx, ry)) {
     277                m_offsetX -= rx;
     278                m_offsetY -= ry;
    265279            }
     280        }
    266281    }
    267282
    268     // Compute layer position.
    269     m_layerX = m_pageX;
    270     m_layerY = m_pageY;
    271     if (RenderObject* docRenderer = doc->renderer()) {
    272         // FIXME: Should we use the target node instead of hit testing?
    273         // If we want to, then we'll have to wait until setTarget is called.
    274         RenderObject::NodeInfo hitTestResult(true, false);
    275         docRenderer->layer()->hitTest(hitTestResult, m_pageX, m_pageY);
    276         NodeImpl* n = hitTestResult.innerNonSharedNode();
    277         while (n && !n->renderer())
    278             n = n->parent();
    279         if (n) {
    280             n->renderer()->enclosingLayer()->updateLayerPosition();   
    281             for (RenderLayer* layer = n->renderer()->enclosingLayer(); layer; layer = layer->parent()) {
    282                 m_layerX -= layer->xPos();
    283                 m_layerY -= layer->yPos();
    284             }
     283    // Adjust layerX/Y to be relative to the layer.
     284    // FIXME: We're pretty sure this is the wrong defintion of "layer."
     285    // Our RenderLayer is a more modern concept, and layerX/Y is some
     286    // other notion about groups of elements; we should test and fix this.
     287    NodeImpl* n = targ;
     288    while (n && !n->renderer())
     289        n = n->parent();
     290    if (n) {
     291        RenderLayer* layer = n->renderer()->enclosingLayer();
     292        layer->updateLayerPosition();
     293        for (; layer; layer = layer->parent()) {
     294            m_layerX -= layer->xPos();
     295            m_layerY -= layer->yPos();
    285296        }
    286297    }
     
    381392    m_relatedTarget = relatedTargetArg;
    382393
    383     computePositions();
     394    initCoordinates();
    384395}
    385396
  • trunk/WebCore/khtml/xml/dom2_eventsimpl.h

    r12492 r12514  
    4646public:
    4747    EventImpl();
    48     EventImpl(const AtomicString &type, bool canBubbleArg, bool cancelableArg);
     48    EventImpl(const AtomicString& type, bool canBubbleArg, bool cancelableArg);
    4949    virtual ~EventImpl();
    5050
    5151    const AtomicString &type() const { return m_type; }
    52     NodeImpl *target() const { return m_target.get(); }
    53     void setTarget(NodeImpl *target) { m_target = target; }
    54     NodeImpl *currentTarget() const { return m_currentTarget; }
    55     void setCurrentTarget(NodeImpl *currentTarget) { m_currentTarget = currentTarget; }
     52    NodeImpl* target() const { return m_target.get(); }
     53    void setTarget(NodeImpl*);
     54    NodeImpl* currentTarget() const { return m_currentTarget; }
     55    void setCurrentTarget(NodeImpl* currentTarget) { m_currentTarget = currentTarget; }
    5656    unsigned short eventPhase() const { return m_eventPhase; }
    5757    void setEventPhase(unsigned short eventPhase) { m_eventPhase = eventPhase; }
     
    8585
    8686protected:
     87    virtual void receivedTarget();
    8788    bool dispatched() const { return m_target; }
    8889
     
    9798    bool m_cancelBubble;
    9899
    99     NodeImpl *m_currentTarget; // ref > 0 maintained externally
     100    NodeImpl* m_currentTarget; // ref > 0 maintained externally
    100101    unsigned short m_eventPhase;
    101102    RefPtr<NodeImpl> m_target;
     
    193194    int m_clientX;
    194195    int m_clientY;
    195     void computePositions();
     196    void initCoordinates();
     197    virtual void receivedTarget();
    196198private:
    197199    int m_pageX;
Note: See TracChangeset for help on using the changeset viewer.