summaryrefslogtreecommitdiffstats
path: root/Source/WebCore/manual-tests/style-keypress-events.html
blob: b0d27703372a849ee539db1a08a6ff19482f2dcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<body onload="setup()">
<p>cmd+b and cmd+i should generate a keydown event in contentEditable fields.  Also, calling
preventDefault() in the keydown event should cancel the text styling.</p>

<div contentEditable id="test" style="border: 1px solid; padding: 4px;">
This is some sample text.<br><br><br><br>
</div>
<div>
<input type="checkbox" id="disable"><label for="disable">preventDefault() in keydown</label>
</div>
<div id="log"></div>

<script>
function setup()
{
    var test = document.getElementById("test");
    test.addEventListener("keydown", keydown, false);

    var selection = window.getSelection();
    selection.setPosition(test, 0);
    selection.modify("extend", "forward", "sentence");
    test.focus();
}

function log(msg)
{
    var log = document.getElementById("log");
    log.innerHTML += "<br>" + msg;
}

function keydown(event)
{
    log("keydown");
    if (document.getElementById("disable").checked)
        event.preventDefault();
}
</script>
</body>