--- a/src/eric7/WebBrowser/Tools/WebHitTestResult.py Wed Jul 13 11:16:20 2022 +0200 +++ b/src/eric7/WebBrowser/Tools/WebHitTestResult.py Wed Jul 13 14:55:47 2022 +0200 @@ -19,10 +19,11 @@ """ Class implementing an object for testing certain aspects of a web page. """ + def __init__(self, page, pos): """ Constructor - + @param page reference to the web page @type WebBrowserPage @param pos position to be tested @@ -43,7 +44,7 @@ self.__mediaUrl = QUrl() self.__tagName = "" self.__viewportPos = page.mapToViewport(pos) - + script = """ (function() {{ var e = document.elementFromPoint({0}, {1}); @@ -106,176 +107,176 @@ }} return res; }})() - """.format(self.__viewportPos.x(), self.__viewportPos.y()) + """.format( + self.__viewportPos.x(), self.__viewportPos.y() + ) self.__populate(page.url(), page.execJavaScript(script)) - + def updateWithContextMenuData(self, data): """ Public method to update the hit test data with data from the context menu event. - + @param data context menu data @type QWebEngineContextMenuRequest """ from PyQt6.QtWebEngineCore import QWebEngineContextMenuRequest + if data.position() != self.__pos: return - + self.__linkTitle = data.linkText() self.__linkUrl = data.linkUrl() self.__isContentEditable = data.isContentEditable() self.__isContentSelected = bool(data.selectedText()) - - if ( - data.mediaType() == - QWebEngineContextMenuRequest.MediaType.MediaTypeImage - ): + + if data.mediaType() == QWebEngineContextMenuRequest.MediaType.MediaTypeImage: self.__imageUrl = data.mediaUrl() elif data.mediaType() in [ QWebEngineContextMenuRequest.MediaType.MediaTypeAudio, - QWebEngineContextMenuRequest.MediaType.MediaTypeVideo + QWebEngineContextMenuRequest.MediaType.MediaTypeVideo, ]: self.__mediaUrl = data.mediaUrl() - + def baseUrl(self): """ Public method to get the base URL of the page. - + @return base URL @rtype QUrl """ return self.__baseUrl - + def alternateText(self): """ Public method to get the alternate text. - + @return alternate text @rtype str """ return self.__alternateText - + def boundingRect(self): """ Public method to get the bounding rectangle. - + @return bounding rectangle @rtype QRect """ return QRect(self.__boundingRect) - + def imageUrl(self): """ Public method to get the URL of an image. - + @return image URL @rtype QUrl """ return self.__imageUrl - + def isContentEditable(self): """ Public method to check for editable content. - + @return flag indicating editable content @rtype bool """ return self.__isContentEditable - + def isContentSelected(self): """ Public method to check for selected content. - + @return flag indicating selected content @rtype bool """ return self.__isContentSelected - + def isNull(self): """ Public method to test, if the hit test is empty. - + @return flag indicating an empty object @rtype bool """ return self.__isNull - + def linkTitle(self): """ Public method to get the title for a link element. - + @return title for a link element @rtype str """ return self.__linkTitle - + def linkUrl(self): """ Public method to get the URL for a link element. - + @return URL for a link element @rtype QUrl """ return self.__linkUrl - + def mediaUrl(self): """ Public method to get the URL for a media element. - + @return URL for a media element @rtype QUrl """ return self.__mediaUrl - + def mediaPaused(self): """ Public method to check, if a media element is paused. - + @return flag indicating a paused media element @rtype bool """ return self.__isMediaPaused - + def mediaMuted(self): """ Public method to check, if a media element is muted. - + @return flag indicating a muted media element @rtype bool """ return self.__isMediaMuted - + def pos(self): """ Public method to get the position of the hit test. - + @return position of hit test @rtype QPoint """ return QPoint(self.__pos) - + def viewportPos(self): """ Public method to get the viewport position. - + @return viewport position @rtype QPoint """ return QPoint(self.__viewportPos) - + def tagName(self): """ Public method to get the name of the tested tag. - + @return name of the tested tag @rtype str """ return self.__tagName - + def __populate(self, url, res): """ Private method to populate the object. - + @param url URL of the tested page @type QUrl @param res dictionary with result data from JavaScript @@ -283,7 +284,7 @@ """ if not res: return - + self.__baseUrl = QUrl(res["baseUrl"]) self.__alternateText = res["alternateText"] self.__imageUrl = QUrl(res["imageUrl"]) @@ -295,12 +296,13 @@ self.__isMediaPaused = res["mediaPaused"] self.__isMediaMuted = res["mediaMuted"] self.__tagName = res["tagName"] - + rect = res["boundingRect"] if len(rect) == 4: - self.__boundingRect = QRect(int(rect[0]), int(rect[1]), - int(rect[2]), int(rect[3])) - + self.__boundingRect = QRect( + int(rect[0]), int(rect[1]), int(rect[2]), int(rect[3]) + ) + if not self.__imageUrl.isEmpty(): self.__imageUrl = url.resolved(self.__imageUrl) if not self.__linkUrl.isEmpty():