Closed Bug 201996 Opened 21 years ago Closed 21 years ago

Caret blinking in field, but focus is somewhere else

Categories

(Core :: DOM: UI Events & Focus Handling, defect)

defect
Not set
normal

Tracking

()

VERIFIED FIXED
mozilla1.4beta

People

(Reporter: emaijala+moz, Assigned: bryner)

References

()

Details

(Keywords: access, regression, topembed+, Whiteboard: edt_a3,edt_d3)

Attachments

(3 files, 1 obsolete file)

Running trunk build 2003041208 on WinXP, although this has been a problem with a
few builds lately (I'm going to see if I find a time frame when this started).

I have a frameset where there is a menu on the left and a form on the right.
When the form is shown, the focus is set to the field using javascript. Caret
blinks happily in the field, but typing initiates find as you instead. A reduced
test case is available at http://atp.fi/~ere/frametest. I'll also attach it.
Press the form link on the left and try typing. If it works, click reload and
try again.
2003040209 works, 2003040308 fails. Brian, could your fix for bug 170811 have
caused this?
seems likely.  and this has nothing to do with 'form manager'.
Assignee: dveditz → bryner
Component: Form Manager → Event Handling
Keywords: topembed
QA Contact: tpreston → desale
Target Milestone: --- → mozilla1.4beta
Oops, sorry. Should have thought about it a little more.
Can't reproduce on a recent Linux build.  I tried reloading several times.  I'll
check Mac and Windows next.
Can't reproduce on windows either :(  (just-pulled cvs build, windows xp)
I can still reproduce, pulled today about 8 hours ago. I just click Form, type
something (works), click Reload and type something (doesn't).
Attached file Zipped testcase
This is the test case zipped.
Happens on Linux too using the latest nightly trunk build. Not every time, but
after a few reloads it always happens.
OS: Windows XP → All
About nsPresShell::CheckForFocus(). The latest version is missing an old check
to see if focusedWindow == domWindow (aOurWindow). Without this check it seems
to steal the focus from somewhere else. Now, the check makes me wonder if the
call to ourWin->Focus() is necessary at all. Everything I tried works fine
without it. Why focus a window that already has focus? The only reason I could
find for this is if focus controller just _thinks_ ourWindow has focus although
it doesn't. I don't know if such a case exists. 

Anyway, having the check in place, or removing the Focus() call altogether,
makes the test case work perfectly and doesn't break tinderbox iframes (bug 170811).
Attached patch Proposed patch (obsolete) — Splinter Review
This patch will restore the check in CheckForFocus() to focus the window only
if it's the active one. This avoids stealing the focus from someone else. I've
tested that scrolling after clicking a link in a tinderbox iframe still works
(bug 170811), my test case works and http login dialog (bug 191896) works.

Btw. the reason Focus() needs to be called is that when suppressed, only focus
controller is updated and the window doesn't really get the focus before this
call. This happens for example when creating the http auth login dialog.
The test case at http://atp.fi/~ere/frametest is improved a bit. Reloading it
with focus in the input field should definitely screw the focus without the patch.
Just for the record: the test case only works if it loads quickly enough, so to
test it should be copied to a local server or disk.
able to repro on mac/nscp, but for some reason cannot (so far) do so on camino.
(both trunk builds from today, 2003.04.18)
Hardware: PC → All
Discussed in edt bug triage.  Plussing.
Keywords: topembedtopembed+
Whiteboard: edt_a3,edt_d3
Comment on attachment 120961 [details] [diff] [review]
Proposed patch

This patch doesn't fix bug 203117 because it's the call to
aFocusController->SetFocusedWindow that's breaking that bug.
That problem is probably bug 201242 then.
Going from the "form" page to mozilla.org, back, forward, lost focus :-(
This patch fixes this bug, bug 200735, bug 203117, and bug 194104.  Summary of
the changes:

- No longer require a frame to be present for all events.  In particular, don't
require one for focus events.  This ensures that focus events get through to
the focus controller even if we haven't reflowed the document yet.

- General cleanup and commenting in nsEventStateManager::PreHandleEvent().  I
fixed some cases where we should be reusing the event struct but aren't.

- In nsHTMLInputElement::SetFocus() and Select(), make sure to set the focused
window as well as the focused element if the focus controller is inactive. 
This fixes setting latent focus to a text input inside an iframe.

- Fixed handling of certain conditions in PresShell's CheckForFocus().	The
previous behavior could be incorrect depending on whether the parent or child
document unsuppressed painting first.

- General cleanup in PresShell::HandleEvent() and HandleEventInternal(). 
Allowed focus events to go through with no frame, updated some comments,
normalized indentation.
Attachment #120961 - Attachment is obsolete: true
Attachment #122184 - Flags: superreview?(jst)
Attachment #122184 - Flags: review?(jkeiser)
Comment on attachment 122185 [details] [diff] [review]
diff -w of the above, for easier reviewing

>@@ -2648,6 +2661,8 @@ static void CheckForFocus(nsPIDOMWindow*
> 
>     nsCOMPtr<nsIDocument> parentDoc;
>     curDoc->GetParentDocument(getter_AddRefs(parentDoc));
>+    if (parentDoc == aDocument)
>+      return;
>     curDoc = parentDoc;
>   }
> 
I can verify that this fixes bug 203117.
Thumbs up for bryner, the patch works great :)
nominating for 1.4beta, as this fixes a bunch of focus issues. in addition to
the ones mentioned in comment 18, bug 202180 also appears to be fixed.
Flags: blocking1.4b?
Comment on attachment 122184 [details] [diff] [review]
fix for a number of focus issues

sr=jst
Attachment #122184 - Flags: superreview?(jst) → superreview+
Flags: blocking1.4b?
Flags: blocking1.4b-
Flags: blocking1.4?
Flags: blocking1.4? → blocking1.4+
Comment on attachment 122184 [details] [diff] [review]
fix for a number of focus issues

r=me if you fix the comment about sending a blur event to the window, which the
NS_GOTFOCUS code doesn't do.  I am a little sad that this fix is restricted to
focus events, but it's a start and won't be hard to remove the restriction :)
Attachment #122184 - Flags: review?(jkeiser) → review+
Comment on attachment 122184 [details] [diff] [review]
fix for a number of focus issues

drivers wants this for 1.4, right?
Attachment #122184 - Flags: approval1.4?
Comment on attachment 122184 [details] [diff] [review]
fix for a number of focus issues

a=sspitzer, as this is a 1.4 blocker
Attachment #122184 - Flags: approval1.4? → approval1.4+
Fix checked in.
Status: NEW → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
vrfy'd fixed with 2003.05.12 comm builds.
Status: RESOLVED → VERIFIED
Component: Event Handling → User events and focus handling
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: