void MouseRelatedEvent::computeRelativePosition() { Node* targetNode = target() ? target()->toNode() : nullptr; if (!targetNode) return; // Compute coordinates that are based on the target. m_layerLocation = m_pageLocation; m_offsetLocation = m_pageLocation; // Must have an updated layout tree for this math to work correctly. targetNode->document().updateLayoutIgnorePendingStylesheets(); // Adjust offsetLocation to be relative to the target's padding box. if (LayoutObject* r = targetNode->layoutObject()) { FloatPoint localPos = r->absoluteToLocal(FloatPoint(absoluteLocation()), UseTransforms); // Adding this here to address crbug.com/570666. Basically we'd like to // find the local coordinates relative to the padding box not the border box. if (r->isBoxModelObject()) { LayoutBoxModelObject* layoutBox = toLayoutBoxModelObject(r); localPos.move(-layoutBox->borderLeft(), -layoutBox->borderTop()); } 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: event.layerX and event.layerY are poorly defined, // and probably don't always correspond to PaintLayer offsets. // https://bugs.webkit.org/show_bug.cgi?id=21868 Node* n = targetNode; while (n && !n->layoutObject()) n = n->parentNode(); if (n) { // FIXME: This logic is a wrong implementation of convertToLayerCoords. for (PaintLayer* layer = n->layoutObject()->enclosingLayer(); layer; layer = layer->parent()) m_layerLocation -= toLayoutSize(layer->location()); } m_hasCachedRelativePosition = true; }
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(); } } }
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().updateLayoutIgnorePendingStylesheets(); // Adjust offsetLocation to be relative to the target's position. if (RenderObject* r = targetNode->renderer()) { FloatPoint localPos = r->absoluteToLocal(absoluteLocation(), UseTransforms); m_offsetLocation = roundedLayoutPoint(localPos); float scaleFactor = 1 / (pageZoomFactor(this) * frameScaleFactor(this)); if (scaleFactor != 1.0f) m_offsetLocation.scale(scaleFactor, scaleFactor); } // Adjust layerLocation to be relative to the layer. // FIXME: event.layerX and event.layerY are poorly defined, // and probably don't always correspond to RenderLayer offsets. // https://bugs.webkit.org/show_bug.cgi?id=21868 Node* n = targetNode; while (n && !n->renderer()) n = n->parentNode(); RenderLayer* layer; if (n && (layer = n->renderer()->enclosingLayer())) { for (; layer; layer = layer->parent()) { m_layerLocation -= toLayoutSize(layer->location()); } } m_hasCachedRelativePosition = true; }
void MouseRelatedEvent::computePageLocation() { float zoomFactor = pageZoomFactor(this); setAbsoluteLocation(roundedLayoutPoint(FloatPoint(pageX() * zoomFactor, pageY() * zoomFactor))); }
void MouseRelatedEvent::computePageLocation() { float scaleFactor = pageZoomFactor(this) * frameScaleFactor(this); setAbsoluteLocation(LayoutPoint(pageX() * scaleFactor, pageY() * scaleFactor)); }