Closed Bug 893201 Opened 11 years ago Closed 11 years ago

Cross chrome/content focus handling

Categories

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

x86_64
Linux
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla25

People

(Reporter: evilpie, Assigned: evilpie)

References

Details

(Whiteboard: [e10s])

Attachments

(1 file)

When you tab from chrome until you end up in content, we highlight the first element there. On the next tab however we start from the first element in chrome, because the FocusManager doesn't know that <browser> has elements in it that are focused. We however already send the right events to content, so that this could in theory work. All this patch does is, it forces the chrome process to ignore the MoveFocus request so that content can do the right thing. The other case is when content is basically at the end of focus-able elements and clears focus. However we should actually go back into chrome and focus the next element there. I am not sure if this is right patch, but I find after typing this out, it does seem to make a certain amount of sense. Only thing that confuses me is that shift+tab from content up to chrome works.
Okay there is at least one remaining problem. When something in content is focused, but the user manually focuses something in chrome, they element in content stays focused. I believe the straight forward fix is to explicitly reset the elements that are focused in content in that case.
(In reply to Tom Schuster [:evilpie] from comment #2)
> Okay there is at least one remaining problem. When something in content is
> focused, but the user manually focuses something in chrome, they element in
> content stays focused. I believe the straight forward fix is to explicitly
> reset the elements that are focused in content in that case.

This is supposed to already work, here:
http://mxr.mozilla.org/mozilla-central/source/dom/base/nsFocusManager.cpp#1563

Is that codepath not being hit for some reason?
Just deactivating is not enough. We still remember the last focused element and continue from there. Just the highlighting is removed.
(In reply to Tom Schuster [:evilpie] from comment #0)
> When you tab from chrome until you end up in content, we highlight the first
> element there. On the next tab however we start from the first element in
> chrome, because the FocusManager doesn't know that <browser> has elements in
> it that are focused.

When the content process has the focus, key events should be sent to the child process and MoveFocus called on its focus manager, so the chrome focus manager shouldn't be doing anything.

Are you sure that the content process is being activated properly? This is done at http://mxr.mozilla.org/mozilla-central/source/dom/base/nsFocusManager.cpp#1785


> We however already send the right events to content, so
> that this could in theory work. All this patch does is, it forces the chrome
> process to ignore the MoveFocus request so that content can do the right
> thing. The other case is when content is basically at the end of focus-able
> elements and clears focus. However we should actually go back into chrome
> and focus the next element there.

The content process focus manager handles this by calling docShell->TabToTreeOwner().

Didn't all this work before? There shouldn't be any need to change anything in the focus manager.
The MoveFocus is obviously ends up in chrome, even when content is focused. Maybe this is related to bug 862519?
Assignee: nobody → evilpies
I now believe that this http://hg.mozilla.org/projects/larch/rev/ee111715a450 is a better fix. When we let content handle the tab event, we shouldn't also in chrome do anything with that event. This fixes the problem and nicely ties in with the existing code that Neil mentioned in comment 5.
Even with the last fix there is something that is bugging me.
1. Focus something in content (better not the last or first focusable item)
2. Click on the something in chrome, eg. the urlbar.
3. We call tabchild->deactivate()
4. Press tab until you end up in content.
5. Problem: we continue tabbing from the last focused item in content instead of the beginning.

I tried solving this by also calling ClearFocus(FocusManager->FocusedWindow()). The log also says <<blur>> Element a has been blurred. Sadly I still see the same behavior.
I hope you can help me out here. Your last hint was already quite helpful.
Flags: needinfo?(enndeakin)
Is this something that used to work?

> I tried solving this by also calling ClearFocus(FocusManager->FocusedWindow()).

Where are you calling this from?
Flags: needinfo?(enndeakin)
(In reply to Neil Deakin from comment #10)
> Is this something that used to work?
What do you mean? I actually don't understand how this ever worked, but I guess the code used to be different. Is there some branch or version I could check out that has this stuff in a working condition?
> 
> > I tried solving this by also calling ClearFocus(FocusManager->FocusedWindow()).
> 
> Where are you calling this from?

Before this.
http://mxr.mozilla.org/mozilla-central/source/dom/base/nsFocusManager.cpp#1564

I was basically sending a message to the child to do the ClearFocus(FocusManager->FocusedWindow()).
I would(In reply to Tom Schuster [:evilpie] from comment #11)
> (In reply to Neil Deakin from comment #10)
> > Is this something that used to work?
> What do you mean? I actually don't understand how this ever worked, but I
> guess the code used to be different. Is there some branch or version I could
> check out that has this stuff in a working condition?
> > 

I don't know. You'd have to ask someone who worked on on that.


> > > I tried solving this by also calling ClearFocus(FocusManager->FocusedWindow()).
> > 
> > Where are you calling this from?
> 
> Before this.
> http://mxr.mozilla.org/mozilla-central/source/dom/base/nsFocusManager.
> cpp#1564
> 
> I was basically sending a message to the child to do the
> ClearFocus(FocusManager->FocusedWindow()).

That should work, but you should clear it before activating the window, and only when moving the focus (for example, by tabbing). This can be determined with the flags/type passed to MoveFocus and elsewhere.

However, clearing the focus isn't what you want to do anyway. You want to, depending on the flags/type, move focus to the first or last element in the child frame.
I found a better fix for this problem. http://hg.mozilla.org/projects/larch/rev/ee111715a450
We don't handle the tab event when we handled it in content. This works without any other code. The problem with not clearing the focus when clicking the urlbar however isn't fixed yet.
Minor nit: please give a more descriptive name to the `dispatched` var as dispatched might have various different meanings in that context. e.g. handledByRemoteProcess, or dispatchedToContentProcess, sentToContentProcess, etc... Take your pick!
Attached patch v1 - basic patchSplinter Review
This is basically the commit that I pushed to large, with better comments and names. I still need to fix the previously mentioned issue, but at least tabbing is usable now.
Attachment #780613 - Flags: review?(felipc)
I think the check+return should be inside the TAB/F6 case, and not unconditional for all keypresses. Unless you found other things that need this?
There is no other code in that case, so I doubt that this a problem.
Yeah I know, but this fix is specifically for the focus handling. If someone adds code afterwards in the keypress case then it might not be applicable anymore
Attachment #780613 - Flags: review?(felipc)
https://hg.mozilla.org/mozilla-central/rev/ebc3baa2b9cb
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla25
Blocks: 862577
Blocks: 904865
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: