Bug 618907, focus frame when mousedown event on content is cancelled and chrome is currently focused, fixes focus issues with docs.google.com, r=smaug,a=blocking

This commit is contained in:
Neil Deakin 2011-01-24 09:50:37 -05:00
Родитель e7488cf19d
Коммит a9b9616616
2 изменённых файлов: 53 добавлений и 2 удалений

Просмотреть файл

@ -2961,6 +2961,24 @@ nsEventStateManager::PostHandleEvent(nsPresContext* aPresContext,
// if we're here, the event handler returned false, so stop // if we're here, the event handler returned false, so stop
// any of our own processing of a drag. Workaround for bug 43258. // any of our own processing of a drag. Workaround for bug 43258.
StopTrackingDragGesture(); StopTrackingDragGesture();
// When the event was cancelled, there is currently a chrome document
// focused and a mousedown just occurred on a content document, ensure
// that the window that was clicked is focused.
EnsureDocument(mPresContext);
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (mDocument && fm) {
nsCOMPtr<nsIDOMWindow> currentWindow;
fm->GetFocusedWindow(getter_AddRefs(currentWindow));
if (currentWindow && currentWindow != mDocument->GetWindow() &&
!nsContentUtils::IsChromeDoc(mDocument)) {
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(currentWindow);
nsCOMPtr<nsIDocument> currentDoc = do_QueryInterface(win->GetExtantDocument());
if (nsContentUtils::IsChromeDoc(currentDoc)) {
fm->SetFocusedWindow(mDocument->GetWindow());
}
}
}
} }
SetActiveManager(this, activeContent); SetActiveManager(this, activeContent);
} }

Просмотреть файл

@ -803,6 +803,39 @@ function startTest()
expectFocusShift(function () synthesizeKey("VK_TAB", { shiftKey: true }), expectFocusShift(function () synthesizeKey("VK_TAB", { shiftKey: true }),
null, textbox1.inputField, true, "shift+tab on textbox with tabindex set"); null, textbox1.inputField, true, "shift+tab on textbox with tabindex set");
// ---- test for bug 618907 which ensures that canceling the mousedown event still focuses the
// right frame
var childContentFrame = document.getElementById("ifa")
childContentFrame.style.MozUserFocus = "";
var frab = childContentFrame.contentDocument.getElementById("fra-b");
var mouseDownListener = function(event) event.preventDefault();
frab.addEventListener("mousedown", mouseDownListener, false);
var childElementToFocus = childContentFrame.contentDocument.getElementById("fra");
gLastFocus = childElementToFocus;
gLastFocusWindow = childContentFrame.contentWindow;
gLastFocus.focus();
gEvents = "";
setFocusTo("t1", window);
gLastFocusMethod = -1;
expectFocusShift(function () synthesizeMouse(frab, 5, 5, { }, childContentFrame.contentWindow),
null, childElementToFocus, true,
"mousedown event canceled - chrome to content");
frab.removeEventListener("mousedown", mouseDownListener, false);
var t5 = getById("t5");
t5.addEventListener("mousedown", mouseDownListener, false);
synthesizeMouse(t5, 10, 10, { })
t5.removeEventListener("mousedown", mouseDownListener, false);
is(fm.focusedElement, childElementToFocus,
"mousedown event cancelled - content to chrome - element");
is(fm.focusedWindow, childContentFrame.contentWindow, "mousedown event cancelled - content to chrome - window");
// ---- test to check that refocusing an element during a blur event doesn't succeed // ---- test to check that refocusing an element during a blur event doesn't succeed
var t1 = getById("t1"); var t1 = getById("t1");
@ -1667,8 +1700,8 @@ SimpleTest.waitForFocus(startTest);
<checkbox id="n2"/><checkbox id="n4"/><checkbox id="n6"/><checkbox id="n8"/><checkbox id="n10"/><checkbox id="n12"/> <checkbox id="n2"/><checkbox id="n4"/><checkbox id="n6"/><checkbox id="n8"/><checkbox id="n10"/><checkbox id="n12"/>
<listbox id="last" width="20" rows="1"/> <listbox id="last" width="20" rows="1"/>
<iframe id="ifa" width="20" height="20" style="-moz-user-focus: ignore;" <iframe id="ifa" width="40" height="60" style="-moz-user-focus: ignore;" type="content"
src="data:text/html,&lt;input id=fra&gt; src="data:text/html,&lt;input id=fra size='2'&gt;&lt;input id='fra-b' size='2'&gt;
&lt;iframe src='data:text/html,&lt;input id=frc&gt;&lt;iframe src=&quot;data:text/html,&lt;input id=frd&gt;&quot;&gt;&lt;/iframe&gt;'&gt;&lt;/iframe&gt;"/> &lt;iframe src='data:text/html,&lt;input id=frc&gt;&lt;iframe src=&quot;data:text/html,&lt;input id=frd&gt;&quot;&gt;&lt;/iframe&gt;'&gt;&lt;/iframe&gt;"/>
<iframe id="ifb" width="20" height="20" style="-moz-user-focus: ignore;" <iframe id="ifb" width="20" height="20" style="-moz-user-focus: ignore;"
src="data:text/html,&lt;input id=frd&gt;&lt;/iframe&gt;"/> src="data:text/html,&lt;input id=frd&gt;&lt;/iframe&gt;"/>