MouseRelatedEvent::MouseRelatedEvent(const AtomicString& eventType, bool canBubble, bool cancelable, PassRefPtr<AbstractView> abstractView, int detail, const IntPoint& screenLocation, const IntPoint& windowLocation, const IntPoint& movementDelta, bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, bool isSimulated) : UIEventWithKeyState(eventType, canBubble, cancelable, abstractView, detail, ctrlKey, altKey, shiftKey, metaKey) , m_screenLocation(screenLocation) , m_movementDelta(movementDelta) , m_isSimulated(isSimulated) { LayoutPoint adjustedPageLocation; LayoutPoint scrollPosition; LocalFrame* frame = view() ? view()->frame() : 0; if (frame && !isSimulated) { if (FrameView* frameView = frame->view()) { scrollPosition = frameView->scrollPosition(); adjustedPageLocation = frameView->windowToContents(windowLocation); float scaleFactor = 1 / frame->pageZoomFactor(); if (scaleFactor != 1.0f) { adjustedPageLocation.scale(scaleFactor, scaleFactor); scrollPosition.scale(scaleFactor, scaleFactor); } } } m_clientLocation = adjustedPageLocation - toLayoutSize(scrollPosition); m_pageLocation = adjustedPageLocation; initCoordinates(); }
Node* TreeScope::nodeFromPoint(const LayoutPoint& clientPoint, LayoutPoint* localPoint) { auto* frame = documentScope().frame(); auto* view = documentScope().view(); if (!frame || !view) return nullptr; float scaleFactor = frame->pageZoomFactor() * frame->frameScaleFactor(); LayoutPoint contentsPoint = clientPoint; contentsPoint.scale(scaleFactor); contentsPoint.moveBy(view->contentsScrollPosition()); LayoutRect visibleRect; #if PLATFORM(IOS) visibleRect = view->unobscuredContentRect(); #else visibleRect = view->visibleContentRect(); #endif if (!visibleRect.contains(contentsPoint)) return nullptr; HitTestResult result(contentsPoint); documentScope().renderView()->hitTest(HitTestRequest(), result); if (localPoint) *localPoint = result.localPoint(); return result.innerNode(); }
MouseRelatedEvent::MouseRelatedEvent(const AtomicString& eventType, bool canBubble, bool cancelable, PassRefPtr<AbstractView> abstractView, int detail, const LayoutPoint& screenLocation, const LayoutPoint& windowLocation, bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, bool isSimulated) : UIEventWithKeyState(eventType, canBubble, cancelable, abstractView, detail, ctrlKey, altKey, shiftKey, metaKey) , m_screenLocation(screenLocation) , m_isSimulated(isSimulated) { LayoutPoint adjustedPageLocation; LayoutPoint scrollPosition; Frame* frame = view() ? view()->frame() : 0; if (frame && !isSimulated) { if (FrameView* frameView = frame->view()) { scrollPosition = frameView->scrollPosition(); adjustedPageLocation = frameView->windowToContents(windowLocation); float pageZoom = frame->pageZoomFactor(); if (pageZoom != 1.0f) { // Adjust our pageX and pageY to account for the page zoom. adjustedPageLocation.scale(1 / pageZoom, 1 / pageZoom); // FIXME: Change this to use float math and proper rounding (or // better yet, use LayoutPoint::scale). scrollPosition.setX(scrollPosition.x() / pageZoom); scrollPosition.setY(scrollPosition.y() / pageZoom); } } } m_clientLocation = adjustedPageLocation - toSize(scrollPosition); m_pageLocation = adjustedPageLocation; initCoordinates(); }
HTMLAreaElement* HitTestResult::imageAreaForImage() const { ASSERT(m_innerNode); HTMLImageElement* imageElement = nullptr; if (isHTMLImageElement(m_innerNode)) { imageElement = toHTMLImageElement(m_innerNode); } else if (m_innerNode->isInShadowTree()) { if (m_innerNode->containingShadowRoot()->type() == ShadowRootType::UserAgent) { if (isHTMLImageElement(m_innerNode->shadowHost())) imageElement = toHTMLImageElement(m_innerNode->shadowHost()); } } if (!imageElement || !imageElement->layoutObject() || !imageElement->layoutObject()->isBox()) return nullptr; HTMLMapElement* map = imageElement->treeScope().getImageMap(imageElement->fastGetAttribute(usemapAttr)); if (!map) return nullptr; LayoutBox* box = toLayoutBox(imageElement->layoutObject()); LayoutRect contentBox = box->contentBoxRect(); float scaleFactor = 1 / box->style()->effectiveZoom(); LayoutPoint location = localPoint(); location.scale(scaleFactor, scaleFactor); return map->areaForPoint(location, contentBox.size()); }
MouseRelatedEvent::MouseRelatedEvent(const AtomicString& eventType, bool canBubble, bool cancelable, double timestamp, PassRefPtr<AbstractView> abstractView, int detail, const IntPoint& screenLocation, const IntPoint& windowLocation, #if ENABLE(POINTER_LOCK) const IntPoint& movementDelta, #endif bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, bool isSimulated) : UIEventWithKeyState(eventType, canBubble, cancelable, timestamp, abstractView, detail, ctrlKey, altKey, shiftKey, metaKey) , m_screenLocation(screenLocation) #if ENABLE(POINTER_LOCK) , m_movementDelta(movementDelta) #endif , m_isSimulated(isSimulated) { LayoutPoint adjustedPageLocation; LayoutPoint scrollPosition; Frame* frame = view() ? view()->frame() : 0; if (frame && !isSimulated) { if (FrameView* frameView = frame->view()) { #if !PLATFORM(IOS) scrollPosition = frameView->scrollPosition(); #else scrollPosition = frameView->actualScrollPosition(); #endif adjustedPageLocation = frameView->windowToContents(windowLocation); float scaleFactor = 1 / (frame->pageZoomFactor() * frame->frameScaleFactor()); if (scaleFactor != 1.0f) { adjustedPageLocation.scale(scaleFactor, scaleFactor); scrollPosition.scale(scaleFactor, scaleFactor); } } } m_clientLocation = adjustedPageLocation - toLayoutSize(scrollPosition); m_pageLocation = adjustedPageLocation; initCoordinates(); }
void MouseRelatedEvent::init(bool isSimulated, const IntPoint& windowLocation) { LayoutPoint adjustedPageLocation; LayoutPoint scrollPosition; Frame* frame = view() ? view()->frame() : nullptr; if (frame && !isSimulated) { if (FrameView* frameView = frame->view()) { scrollPosition = frameView->contentsScrollPosition(); adjustedPageLocation = frameView->windowToContents(windowLocation); float scaleFactor = 1 / (frame->pageZoomFactor() * frame->frameScaleFactor()); if (scaleFactor != 1.0f) { adjustedPageLocation.scale(scaleFactor, scaleFactor); scrollPosition.scale(scaleFactor, scaleFactor); } } } m_clientLocation = adjustedPageLocation - toLayoutSize(scrollPosition); m_pageLocation = adjustedPageLocation; initCoordinates(); }
MouseRelatedEvent::MouseRelatedEvent(const AtomicString& eventType, bool canBubble, bool cancelable, PassRefPtrWillBeRawPtr<AbstractView> abstractView, int detail, const IntPoint& screenLocation, const IntPoint& rootFrameLocation, const IntPoint& movementDelta, PlatformEvent::Modifiers modifiers, double platformTimeStamp, PositionType positionType, InputDeviceCapabilities* sourceCapabilities) : UIEventWithKeyState(eventType, canBubble, cancelable, abstractView, detail, modifiers, platformTimeStamp, sourceCapabilities) , m_screenLocation(screenLocation) , m_movementDelta(movementDelta) , m_positionType(positionType) { LayoutPoint adjustedPageLocation; LayoutPoint scrollPosition; LocalFrame* frame = view() && view()->isLocalDOMWindow() ? toLocalDOMWindow(view())->frame() : nullptr; if (frame && hasPosition()) { if (FrameView* frameView = frame->view()) { scrollPosition = frameView->scrollPosition(); adjustedPageLocation = frameView->rootFrameToContents(rootFrameLocation); float scaleFactor = 1 / frame->pageZoomFactor(); if (scaleFactor != 1.0f) { adjustedPageLocation.scale(scaleFactor, scaleFactor); scrollPosition.scale(scaleFactor, scaleFactor); } } } m_clientLocation = adjustedPageLocation - toLayoutSize(scrollPosition); m_pageLocation = adjustedPageLocation; // Set up initial values for coordinates. // Correct values are computed lazily, see computeRelativePosition. m_layerLocation = m_pageLocation; m_offsetLocation = m_pageLocation; computePageLocation(); m_hasCachedRelativePosition = false; }
AffineTransform SVGSVGElement::localCoordinateSpaceTransform(SVGLocatable::CTMScope mode) const { AffineTransform viewBoxTransform; if (!hasEmptyViewBox()) { FloatSize size = currentViewportSize(); viewBoxTransform = viewBoxToViewTransform(size.width(), size.height()); } AffineTransform transform; if (!isOutermostSVGSVGElement()) { SVGLengthContext lengthContext(this); transform.translate(x().value(lengthContext), y().value(lengthContext)); } else if (mode == SVGLocatable::ScreenScope) { if (auto* renderer = this->renderer()) { FloatPoint location; float zoomFactor = 1; // At the SVG/HTML boundary (aka RenderSVGRoot), we apply the localToBorderBoxTransform // to map an element from SVG viewport coordinates to CSS box coordinates. // RenderSVGRoot's localToAbsolute method expects CSS box coordinates. // We also need to adjust for the zoom level factored into CSS coordinates (bug #96361). if (is<RenderSVGRoot>(*renderer)) { location = downcast<RenderSVGRoot>(*renderer).localToBorderBoxTransform().mapPoint(location); zoomFactor = 1 / renderer->style().effectiveZoom(); } // Translate in our CSS parent coordinate space // FIXME: This doesn't work correctly with CSS transforms. location = renderer->localToAbsolute(location, UseTransforms); location.scale(zoomFactor); // Be careful here! localToBorderBoxTransform() included the x/y offset coming from the viewBoxToViewTransform(), // so we have to subtract it here (original cause of bug #27183) transform.translate(location.x() - viewBoxTransform.e(), location.y() - viewBoxTransform.f()); // Respect scroll offset. if (FrameView* view = document().view()) { LayoutPoint scrollPosition = view->scrollPosition(); scrollPosition.scale(zoomFactor); transform.translate(-scrollPosition.x(), -scrollPosition.y()); } } } return transform.multiply(viewBoxTransform); }
bool RenderImage::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction hitTestAction) { HitTestResult tempResult(result.hitTestLocation()); bool inside = RenderReplaced::nodeAtPoint(request, tempResult, locationInContainer, accumulatedOffset, hitTestAction); if (tempResult.innerNode() && node()) { if (HTMLMapElement* map = imageMap()) { LayoutRect contentBox = contentBoxRect(); float scaleFactor = 1 / style()->effectiveZoom(); LayoutPoint mapLocation = locationInContainer.point() - toLayoutSize(accumulatedOffset) - locationOffset() - toLayoutSize(contentBox.location()); mapLocation.scale(scaleFactor, scaleFactor); if (map->mapMouseEvent(mapLocation, contentBox.size(), tempResult)) tempResult.setInnerNonSharedNode(node()); } } if (!inside && result.isRectBasedTest()) result.append(tempResult); if (inside) result = tempResult; return inside; }