-
-
Notifications
You must be signed in to change notification settings - Fork 630
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to recognize links to the same page (#16994)
Fixes #141 Summary of the issue: NVDA cannot recognize when link destination points to the same document, and reporting this information is desired by many users. Description of user facing changes NVDA can report if a link destination points to the same document. Description of development approach A new INTERNAL_LINK state has been added to controlTypes.State. NVDA object has a new linkType property, used to report internal (same page) links. If the object is an internal link, the INTERNAL_LINKstate is added in _get_states, in IAccessible/IA2web and in UIA/Chromium. In the gecko_ia2 virtual buffer backend, accValue is exposed for links. In virtualBuffers.gecko_ia2.Gecko_ia2_TextInfo._normalizeControlField, the accValue is used to add the linkType state. A configuration option has been added to enable or disable this feature. This can be changed through gui or with an unassigned gesture. BrowseModeInterceptor object has a new documentUrl property and a new getLinkTypeInDocument method. This method uses a helper function of a new urlUtils submodule to check the provided URL.
- Loading branch information
Showing
17 changed files
with
251 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# A part of NonVisual Desktop Access (NVDA) | ||
# This file is covered by the GNU General Public License. | ||
# See the file COPYING for more details. | ||
# Copyright (C) 2024 NV Access Limited, Noelia Ruiz Martínez, Leonard de Ruijter | ||
|
||
import controlTypes | ||
from urllib.parse import ParseResult, urlparse, urlunparse | ||
from logHandler import log | ||
|
||
|
||
def getLinkType(targetURL: str, rootURL: str) -> controlTypes.State | None: | ||
"""Returns the link type corresponding to a given URL. | ||
:param targetURL: The URL of the link destination | ||
:param rootURL: The root URL of the page | ||
:return: A controlTypes.State corresponding to the link type, or C{None} if the state cannot be determined | ||
""" | ||
if not targetURL or not rootURL: | ||
log.debug(f"getLinkType: Either targetUrl {targetURL} or rootUrl {rootURL} is empty.") | ||
return None | ||
if isSamePageURL(targetURL, rootURL): | ||
log.debug(f"getLinkType: {targetURL} is an internal link.") | ||
return controlTypes.State.INTERNAL_LINK | ||
log.debug(f"getLinkType: {targetURL} type is unknown.") | ||
return None | ||
|
||
|
||
def isSamePageURL(targetURLOnPage: str, rootURL: str) -> bool: | ||
"""Returns whether a given URL belongs to the same page as another URL. | ||
:param targetURLOnPage: The URL that should be on the same page as `rootURL` | ||
:param rootURL: The root URL of the page | ||
:return: Whether `targetURLOnPage` belongs to the same page as `rootURL` | ||
""" | ||
if not targetURLOnPage or not rootURL: | ||
return False | ||
|
||
validSchemes = ("http", "https") | ||
# Parse the URLs | ||
parsedTargetURLOnPage: ParseResult = urlparse(targetURLOnPage) | ||
if parsedTargetURLOnPage.scheme not in validSchemes: | ||
return False | ||
parsedRootURL: ParseResult = urlparse(rootURL) | ||
if parsedRootURL.scheme not in validSchemes: | ||
return False | ||
|
||
# Reconstruct URLs without schemes and without fragments for comparison | ||
targetURLOnPageWithoutFragments = urlunparse(parsedTargetURLOnPage._replace(scheme="", fragment="")) | ||
rootURLWithoutFragments = urlunparse(parsedRootURL._replace(scheme="", fragment="")) | ||
|
||
fragmentInvalidChars: str = "/" # Characters not considered valid in fragments | ||
return targetURLOnPageWithoutFragments == rootURLWithoutFragments and not any( | ||
char in parsedTargetURLOnPage.fragment for char in fragmentInvalidChars | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.