зеркало из https://github.com/mozilla/gecko-dev.git
Bug 375008 - Clicking a disabled element should not cause a focus change. r=Enn
This commit is contained in:
Родитель
8955d98214
Коммит
f489fdedf7
|
@ -3131,8 +3131,38 @@ nsEventStateManager::PostHandleEvent(nsPresContext* aPresContext,
|
|||
if (mCurrentTarget) {
|
||||
mCurrentTarget->GetContentForEvent(aEvent, getter_AddRefs(newFocus));
|
||||
const nsStyleUserInterface* ui = mCurrentTarget->StyleUserInterface();
|
||||
suppressBlur = (ui->mUserFocus == NS_STYLE_USER_FOCUS_IGNORE);
|
||||
activeContent = mCurrentTarget->GetContent();
|
||||
|
||||
// In some cases, we do not want to even blur the current focused
|
||||
// element. Those cases are:
|
||||
// 1. -moz-user-focus CSS property is set to 'ignore';
|
||||
// 2. Element with NS_EVENT_STATE_DISABLED
|
||||
// (aka :disabled pseudo-class for HTML element);
|
||||
// 3. XUL control element has the disabled property set to 'true'.
|
||||
//
|
||||
// We can't use nsIFrame::IsFocusable() because we want to blur when
|
||||
// we click on a visibility: none element.
|
||||
// We can't use nsIContent::IsFocusable() because we want to blur when
|
||||
// we click on a non-focusable element like a <div>.
|
||||
// We have to use |aEvent->target| to not make sure we do not check an
|
||||
// anonymous node of the targeted element.
|
||||
suppressBlur = (ui->mUserFocus == NS_STYLE_USER_FOCUS_IGNORE);
|
||||
|
||||
if (!suppressBlur) {
|
||||
nsCOMPtr<Element> element = do_QueryInterface(aEvent->target);
|
||||
suppressBlur = element &&
|
||||
element->State().HasState(NS_EVENT_STATE_DISABLED);
|
||||
}
|
||||
|
||||
if (!suppressBlur) {
|
||||
nsCOMPtr<nsIDOMXULControlElement> xulControl =
|
||||
do_QueryInterface(aEvent->target);
|
||||
if (xulControl) {
|
||||
bool disabled;
|
||||
xulControl->GetDisabled(&disabled);
|
||||
suppressBlur = disabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsIFrame* currFrame = mCurrentTarget;
|
||||
|
|
|
@ -101,6 +101,7 @@ MOCHITEST_FILES = \
|
|||
test_dragstart.html \
|
||||
test_bug812744.html \
|
||||
test_addEventListenerExtraArg.html \
|
||||
test_focus_disabled.html \
|
||||
$(NULL)
|
||||
|
||||
MOCHITEST_CHROME_FILES = \
|
||||
|
|
|
@ -0,0 +1,124 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=375008
|
||||
-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test for Bug 375008</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=375008">Mozilla Bug 375008</a>
|
||||
<p id="display"></p>
|
||||
<div id="content">
|
||||
<div>
|
||||
<input id='witness'>
|
||||
</div>
|
||||
|
||||
<div id='not-focusable'>
|
||||
<!-- Disabled elements -->
|
||||
<button hidden disabled>foo</button>
|
||||
<input hidden disabled>
|
||||
<fieldset hidden disabled>foo</fieldset>
|
||||
<select hidden disabled><option>foo</option></select>
|
||||
<textarea hidden disabled></textarea>
|
||||
<optgroup hidden disabled><option>foo</option></optgroup>
|
||||
<option hidden disabled>foo</option>
|
||||
</div>
|
||||
|
||||
<div id='focusable'>
|
||||
<button hidden>foo</button>
|
||||
<input hidden>
|
||||
<select hidden><option>foo</option></select>
|
||||
<textarea hidden></textarea>
|
||||
|
||||
<!-- Those elements are not focusable by default. -->
|
||||
<fieldset tabindex=1 hidden>foo</fieldset>
|
||||
<optgroup tabindex=1 hidden><option>foo</option></optgroup>
|
||||
<option tabindex=1 hidden>foo</option>
|
||||
</div>
|
||||
|
||||
<!-- Hidden elements, they have a frame but focus will go through them. -->
|
||||
<div id='hidden' style='visibility: hidden;'>
|
||||
<button hidden>foo</button>
|
||||
<input hidden>
|
||||
<fieldset hidden>foo</fieldset>
|
||||
<select hidden><option>foo</option></select>
|
||||
<textarea hidden></textarea>
|
||||
<optgroup hidden><option>foo</option></optgroup>
|
||||
<option hidden>foo</option>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script type="application/javascript">
|
||||
|
||||
/** Test for Bug 375008 **/
|
||||
|
||||
/*
|
||||
* This test is divided in three parts:
|
||||
* - cases where focus isn't doable but blur should not happen;
|
||||
* - cases where focus is doable;
|
||||
* - cases where focus isn't doable but blur should still happen.
|
||||
*/
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
SimpleTest.waitForFocus(function() {
|
||||
// On Mac, this preference needs to be turned on to be able to focus all the
|
||||
// form controls we want to focus.
|
||||
SpecialPowers.pushPrefEnv({"set": [[ "accessibility.mouse_focuses_formcontrol", true ]]},
|
||||
runTest);
|
||||
});
|
||||
|
||||
function runTest()
|
||||
{
|
||||
var witness = document.getElementById('witness');
|
||||
witness.focus();
|
||||
|
||||
var notFocusableElements = document.getElementById('not-focusable').children;
|
||||
for (var i=0; i<notFocusableElements.length; ++i) {
|
||||
var element = notFocusableElements[i];
|
||||
element.hidden = false;
|
||||
synthesizeMouseAtCenter(element, {});
|
||||
is(document.activeElement, witness,
|
||||
"[" + element.tagName + "] witness should still be focused");
|
||||
|
||||
// Cleanup.
|
||||
witness.focus();
|
||||
}
|
||||
|
||||
var focusableElements = document.getElementById('focusable').children;
|
||||
for (var i=0; i<focusableElements.length; ++i) {
|
||||
var element = focusableElements[i];
|
||||
element.hidden = false;
|
||||
synthesizeMouseAtCenter(element, {});
|
||||
is(document.activeElement, element, "focus should have moved to " + element);
|
||||
|
||||
// Cleanup.
|
||||
element.hidden = true;
|
||||
witness.focus();
|
||||
}
|
||||
|
||||
var hiddenElements = document.getElementById('hidden').children;
|
||||
for (var i=0; i<hiddenElements.length; ++i) {
|
||||
var element = hiddenElements[i];
|
||||
element.hidden = false;
|
||||
synthesizeMouseAtCenter(element, {});
|
||||
is(document.activeElement, document.body,
|
||||
"focus should have moved to the body");
|
||||
|
||||
// Cleanup.
|
||||
element.hidden = true;
|
||||
witness.focus();
|
||||
}
|
||||
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -18,7 +18,7 @@
|
|||
<div id="t16" tabindex="2" style="overflow: scroll; max-height: 20px;">
|
||||
This is a scrollable area with some sufficiently long text contained within it.
|
||||
</div>
|
||||
<img id="n13" src="happy.png"/>
|
||||
<img id="n5" src="happy.png"/>
|
||||
<img id="t23" tabindex="0" src="happy.png"/>
|
||||
<a id="t17" tabindex="2" accesskey="f">1</a>
|
||||
<a id="t24" tabindex="0" href="#">2</a>
|
||||
|
@ -47,9 +47,9 @@
|
|||
</fieldset>
|
||||
<div id="t30" tabindex="0">abc</div>
|
||||
<input id="o18" accesskey="u" disabled size="3"/>
|
||||
<label id="ag" accesskey="g" for="n14">L</label>
|
||||
<input id="n14" tabindex="-1" type="button"/>
|
||||
<span id="n15" accesskey="t">s</span>
|
||||
<label id="ag" accesskey="g" for="n6">L</label>
|
||||
<input id="n6" tabindex="-1" type="button"/>
|
||||
<span id="n7" accesskey="t">s</span>
|
||||
<img id="image" src="data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%18%00%00%00%18%02%03%00%00%00%9D%19%D5k%00%00%00%04gAMA%00%00%B1%8F%0B%FCa%05%00%00%00%0CPLTE%FF%FF%FF%FF%FF%FF%F7%DC%13%00%00%00%03%80%01X%00%00%00%01tRNS%08N%3DPT%00%00%00%01bKGD%00%88%05%1DH%00%00%00%09pHYs%00%00%0B%11%00%00%0B%11%01%7Fd_%91%00%00%00%07tIME%07%D2%05%0C%14%0C%0D%D8%3F%1FQ%00%00%00%5CIDATx%9C%7D%8E%CB%09%C0%20%10D%07r%B7%20%2F%E9wV0%15h%EA%D9%12D4%BB%C1x%CC%5C%1E%0C%CC%07%C0%9C0%9Dd7()%C0A%D3%8D%E0%B8%10%1DiCHM%D0%AC%D2d%C3M%F1%B4%E7%FF%10%0BY%AC%25%93%CD%CBF%B5%B2%C0%3Alh%CD%AE%13%DF%A5%F7%E0%03byW%09A%B4%F3%E2%00%00%00%00IEND%AEB%60%82"
|
||||
usemap="#map1" ismap>
|
||||
|
||||
|
|
|
@ -22,8 +22,8 @@ var fm = Components.classes["@mozilla.org/focus-manager;1"].
|
|||
const kChildDocumentRootIndex = 13;
|
||||
const kBeforeTabboxIndex = 34;
|
||||
const kTabbableSteps = 38;
|
||||
const kFocusSteps = 18;
|
||||
const kNoFocusSteps = 15;
|
||||
const kFocusSteps = 26;
|
||||
const kNoFocusSteps = 7;
|
||||
const kOverflowElementIndex = 27;
|
||||
|
||||
var gTestStarted = false;
|
||||
|
@ -530,8 +530,8 @@ function startTest()
|
|||
{ ctrlKey : true } : { altKey : true };
|
||||
|
||||
// test accesskeys
|
||||
var keys = ["t26", "t19", "t22", "t29", "t15", "t17", "n14",
|
||||
"t4", "o1", "o9", "n6"];
|
||||
var keys = ["t26", "t19", "t22", "t29", "t15", "t17", "n6",
|
||||
"t4", "o1", "o9", "n4"];
|
||||
for (var k = 0; k < keys.length; k++) {
|
||||
var key = String.fromCharCode(65 + k);
|
||||
|
||||
|
@ -556,19 +556,19 @@ function startTest()
|
|||
expectFocusShift(function () synthesizeMouse(getById("ad"), 2, 2, { }, gChildWindow),
|
||||
null, getById("t29"), true, "mouse on html label with content inside");
|
||||
expectFocusShift(function () synthesizeMouse(getById("ag"), 2, 2, { }, gChildWindow),
|
||||
null, getById("n14"), true, "mouse on html label with for attribute");
|
||||
null, getById("n6"), true, "mouse on html label with for attribute");
|
||||
gLastFocusMethod = 0;
|
||||
expectFocusShift(function () synthesizeMouse(getById("aj"), 2, 2, { }),
|
||||
null, getById("o9"), true, "mouse on xul label with content inside");
|
||||
expectFocusShift(function () synthesizeMouse(getById("ak"), 2, 2, { }),
|
||||
null, getById("n6"), true, "mouse on xul label with control attribute");
|
||||
null, getById("n4"), true, "mouse on xul label with control attribute");
|
||||
|
||||
// test accesskeys that shouldn't work
|
||||
k = "o".charCodeAt(0);
|
||||
while (k++ < "v".charCodeAt(0)) {
|
||||
var key = String.fromCharCode(k);
|
||||
expectFocusShift(function () synthesizeKey(key, accessKeyDetails),
|
||||
window, getById("n6"), false, "non accesskey " + key);
|
||||
window, getById("n4"), false, "non accesskey " + key);
|
||||
}
|
||||
gLastFocusMethod = -1;
|
||||
|
||||
|
@ -1614,7 +1614,7 @@ SimpleTest.waitForFocus(startTest);
|
|||
The elements with ids starting with t are focusable and in the taborder.
|
||||
The elements with ids starting with o are:
|
||||
odd numbered ids - focusable but not part of the tab order
|
||||
even numbered ids - not focusable with -moz-user-focus: ignore
|
||||
even numbered ids - not focusable with -moz-user-focus: ignore or disabled
|
||||
The elements with ids starting with n are:
|
||||
odd numbered ids - not focusable with -moz-user-focus: none
|
||||
even numbered ids - focusable but not part of the tab order
|
||||
|
@ -1647,10 +1647,10 @@ SimpleTest.waitForFocus(startTest);
|
|||
<button style="display: none;" tabindex="2"/> <button style="visibility: collapse;" tabindex="2"/>
|
||||
</hbox>
|
||||
<hbox>
|
||||
<button id="n5" accesskey="s" label="no tabindex" disabled="true"/>
|
||||
<button id="n7" label="tabindex = -1" tabindex="-1" disabled="true"/>
|
||||
<button id="n9" label="tabindex = 0" tabindex="0" disabled="true"/>
|
||||
<button id="n11" label="tabindex = 2" tabindex="2" disabled="true"/>
|
||||
<button id="o20" accesskey="s" label="no tabindex" disabled="true"/>
|
||||
<button id="o22" label="tabindex = -1" tabindex="-1" disabled="true"/>
|
||||
<button id="o24" label="tabindex = 0" tabindex="0" disabled="true"/>
|
||||
<button id="o26" label="tabindex = 2" tabindex="2" disabled="true"/>
|
||||
</hbox>
|
||||
</vbox>
|
||||
<vbox>
|
||||
|
@ -1694,10 +1694,10 @@ SimpleTest.waitForFocus(startTest);
|
|||
<button id="t38"/>
|
||||
<!-- The 't' element tests end here so it doesn't matter that these elements are tabbable -->
|
||||
<label id="aj" value="j" accesskey="j" control="o9"/>
|
||||
<label id="ak" accesskey="k" control="n6">k</label>
|
||||
<label id="ak" accesskey="k" control="n4">k</label>
|
||||
<checkbox id="o5"/><checkbox id="o7"/><hbox><checkbox id="o9"/></hbox>
|
||||
<checkbox id="o13"/><checkbox id="o15"/><checkbox id="o17"/>
|
||||
<checkbox id="n2"/><checkbox id="n4"/><checkbox id="n6"/><checkbox id="n8"/><checkbox id="n10"/><checkbox id="n12"/>
|
||||
<checkbox id="o13"/><checkbox id="o15"/><checkbox id="o17"/><checkbox id="o19"/><checkbox id="o21"/><checkbox id="o23"/><checkbox id="o25"/>
|
||||
<checkbox id="n2"/><checkbox id="n4"/>
|
||||
<listbox id="last" width="20" rows="1"/>
|
||||
|
||||
<iframe id="ifa" width="40" height="60" style="-moz-user-focus: ignore;" type="content"
|
||||
|
|
|
@ -362,7 +362,6 @@ select:disabled:disabled /* Need the pseudo-class twice to have the specificity
|
|||
be at least the same as select[size][multiple] above */
|
||||
{
|
||||
-moz-user-input: disabled;
|
||||
-moz-user-focus: ignore;
|
||||
color: GrayText;
|
||||
background-color: ThreeDFace;
|
||||
cursor: inherit;
|
||||
|
|
Загрузка…
Ссылка в новой задаче