void MouseRelatedEvent::computeRelativePosition() { Node* targetNode = target() ? target()->toNode() : 0; if (!targetNode) return; // Compute coordinates that are based on the target. m_layerLocation = m_pageLocation; m_offsetLocation = m_pageLocation; // Must have an updated render tree for this math to work correctly. targetNode->document()->updateStyleIfNeeded(); // Adjust offsetLocation to be relative to the target's position. if (!isSimulated()) { if (RenderObject* r = targetNode->renderer()) { FloatPoint localPos = r->absoluteToLocal(absoluteLocation(), false, true); m_offsetLocation = roundedLayoutPoint(localPos); float scaleFactor = 1 / pageZoomFactor(this); if (scaleFactor != 1.0f) m_offsetLocation.scale(scaleFactor, scaleFactor); } } // Adjust layerLocation to be relative to the layer. // FIXME: We're pretty sure this is the wrong definition of "layer." // Our RenderLayer is a more modern concept, and layerX/Y is some // other notion about groups of elements (left over from the Netscape 4 days?); // we should test and fix this. Node* n = targetNode; while (n && !n->renderer()) n = n->parentNode(); RenderLayer* layer; if (n && (layer = n->renderer()->enclosingLayer())) { layer->updateLayerPosition(); for (; layer; layer = layer->parent()) { m_layerLocation -= toSize(layer->location()); } } m_hasCachedRelativePosition = true; }
void MouseRelatedEvent::receivedTarget() { ASSERT(target()); Node* targ = target()->toNode(); if (!targ) return; // Compute coordinates that are based on the target. m_layerX = m_pageX; m_layerY = m_pageY; m_offsetX = m_pageX; m_offsetY = m_pageY; // Must have an updated render tree for this math to work correctly. targ->document()->updateStyleIfNeeded(); // Adjust offsetX/Y to be relative to the target's position. if (!isSimulated()) { if (RenderObject* r = targ->renderer()) { FloatPoint localPos = r->absoluteToLocal(absoluteLocation(), false, true); float zoomFactor = pageZoomFactor(this); m_offsetX = lroundf(localPos.x() / zoomFactor); m_offsetY = lroundf(localPos.y() / zoomFactor); } } // Adjust layerX/Y to be relative to the layer. // FIXME: We're pretty sure this is the wrong definition of "layer." // Our RenderLayer is a more modern concept, and layerX/Y is some // other notion about groups of elements (left over from the Netscape 4 days?); // we should test and fix this. Node* n = targ; while (n && !n->renderer()) n = n->parentNode(); if (n) { RenderLayer* layer = n->renderer()->enclosingLayer(); layer->updateLayerPosition(); for (; layer; layer = layer->parent()) { m_layerX -= layer->x(); m_layerY -= layer->y(); } } }