Commit 1936e884 authored by Joey Arhar's avatar Joey Arhar Committed by Chromium LUCI CQ

Prevent contenteditable anchors from being stuck :active

Without this patch, anchors can be stuck in the :active state if
contenteditable is enabled before :active is removed.

The special logic for anchors and contenteditable was added a long time
ago [1], and the purpose was to prevent anchors from being clicked and
navigating the page while in contenteditable.

This patch makes SetActive capable of removing :active during
contenteditable, which preserves the original intention of preventing
anchors from navigating during contenteditable.

[1] http://crrev.com/1d651243ad5b85bac9ebc8611a991a23d72d2f95

Fixed: 1007941
Change-Id: Ib51b846e99fd212a478f1278b3568bda4e5886a0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2595978
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Reviewed-by: default avatarMason Freed <masonfreed@chromium.org>
Cr-Commit-Position: refs/heads/master@{#838208}
parent 45e7154d
......@@ -204,7 +204,7 @@ bool HTMLAnchorElement::HasActivationBehavior() const {
}
void HTMLAnchorElement::SetActive(bool active) {
if (HasEditableStyle(*this))
if (active && HasEditableStyle(*this))
return;
HTMLElement::SetActive(active);
......
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="author" title="Joey Arhar" href="mailto:jarhar@chromium.org">
<link rel="help" href="http://crbug.com/1007941">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<!-- This behavior is not explicitly specified. -->
<a id=anchorid href="nonexistant">anchor</a>
<script>
anchorid.addEventListener('mousedown', () => {
anchorid.contentEditable = true;
});
promise_test(async () => {
await test_driver.click(anchorid);
assert_equals(document.querySelector(':active'), null);
}, 'Anchor elements should not stay :active when contentEditable is enabled.');
</script>
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="author" title="Joey Arhar" href="mailto:jarhar@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<!-- This behavior is not explicitly specified. -->
<a id=anchorid href="javascript:window.anchornavigated = true;">anchor</a>
<script>
promise_test(async () => {
window.anchornavigated = false;
anchorid.contentEditable = true;
await test_driver.click(anchorid);
assert_false(window.anchornavigated, "Anchor's javascript: url was run.");
}, 'Anchor elements should not be able to navigate if they have contentEditable.');
</script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment