Closed Bug 552237 Opened 14 years ago Closed 14 years ago

Move to FocusManager

Categories

(Camino Graveyard :: General, defect)

1.9.2 Branch
All
macOS
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: chris, Assigned: chris)

Details

(Whiteboard: [cm192test])

Attachments

(2 files, 2 obsolete files)

nsIFocusController is out, and nsIFocusManager is in. There are a few places where we need to move to the new paradigm.
Attached patch Fix v1.1 (obsolete) — Splinter Review
Use nsIFocusManager. Pretty much just an API change, with some Gecko macros thrown in for good measure.
Assignee: nobody → trendyhendy2000
Status: NEW → ASSIGNED
Attachment #432485 - Flags: review?(nick.kreeger)
Attachment #432485 - Attachment is patch: true
Attachment #432485 - Attachment mime type: application/octet-stream → text/plain
Attachment #432485 - Flags: review?(nick.kreeger) → review+
Comment on attachment 432485 [details] [diff] [review]
Fix v1.1

Looks straight forward.
Attachment #432485 - Flags: superreview?(stuart.morgan+bugzilla)
Attached patch Fix v1.2 (obsolete) — Splinter Review
Turns out it's easy to hang the browser with Fix v1.1. SRT:

1. Open http://caminobrowser.org/help/
2. Cmd-click on the "Camino forum" link to open it in a new foreground tab
3. When loaded, press spacebar

The problem comes from the fact that GetFocusedWindow() always returns NS_OK, even when the focused window is null. NS_ENSURE_SUCCESS always succeeds, and we end up dereferencing a null pointer. This new patch uses NS_ENSURE_TRUE instead. It also removes the useless check after calling GetDesignMode.
Attachment #432485 - Attachment is obsolete: true
Attachment #432967 - Flags: superreview?(stuart.morgan+bugzilla)
Attachment #432485 - Flags: superreview?(stuart.morgan+bugzilla)
Yeah, that's the sort of thing that has encouraged me to always ignore rv and check pointers instead :P
Comment on attachment 432967 [details] [diff] [review]
Fix v1.2

>+#include "nsServiceManagerUtils.h"

Add this in alphabetical order, like the rest of the includes already are (or is there a broken core header dependency that you are working around?)

>+  nsCOMPtr<nsIDOMElement> focusedElement;
>+  rv = fm->GetFocusedElement(getter_AddRefs(focusedElement));
>+  NS_ENSURE_SUCCESS(rv, nsnull);

Guess what else always returns NS_OK! Although in this case it shouldn't matter it's (currently at least) only used for a do_QI

New rule, now that I've been reminded why I didn't like this style: if you want to have NS_ENSURE_SUCCESS checks on everything for extra debug info, that's fine, but any pointer you are going to dereference must be explicitly checked, because that can never lie. It would be great if you could make a patch for your other recent changes that used this pattern, as I'm now concerned we may have introduced latent or edge-cases crashers.

>+    if (designMode.EqualsLiteral("on"))
>+      isFocused = YES;

It's weird to mix the early-return style you've switched to with an only-return-at-the-end top level structure. I'm fine with the early return, but make it consistent throughout the method: change all other instances of |isFocused = foo;| to |return foo;|, remove the variable, and make the last statement |return NO;|
Attachment #432967 - Flags: superreview?(stuart.morgan+bugzilla) → superreview-
(In reply to comment #5)
> because that can never lie. It would be great if you could make a patch for
> your other recent changes that used this pattern, as I'm now concerned we may
> have introduced latent or edge-cases crashers.

Bug 553864.
Attached patch Fix v1.3Splinter Review
Fix with added macros and sr comments addressed.
Attachment #432967 - Attachment is obsolete: true
Attachment #434091 - Flags: superreview?(stuart.morgan+bugzilla)
Comment on attachment 434091 [details] [diff] [review]
Fix v1.3

sr=smorgan. Thanks for reworking the checks, and sorry I didn't remember some important details when you first asked about the macro use!
Attachment #434091 - Flags: superreview?(stuart.morgan+bugzilla) → superreview+
Actually, one more thing that just occurred to me: have you tested that everything you are ENSURE-ing is an error condition?

For example:
+      nsCOMPtr<nsIEditingSession> editSession = do_GetInterface(docshell, &rv);
+      NS_ENSURE_SUCCESS(rv, NULL);
If there's no edit in progress, can this be NULL without that being an error?

Or
+  fm->GetFocusedElement(getter_AddRefs(focusedElement));
+  NS_ENSURE_TRUE(focusedElement, nsnull);
when nothing is focused?

We don't want error spew every time we check for a condition that just doesn't happen to be true.
The editSession object is fine, but focusedElement can frequently be null. This followup patch just returns nsnull in that case, without logging.
Attachment #434752 - Flags: superreview?(stuart.morgan+bugzilla)
Comment on attachment 434752 [details] [diff] [review]
Followup to deal with focusedElement

sr=smorgan
Attachment #434752 - Flags: superreview?(stuart.morgan+bugzilla) → superreview+
And I forgot to mark I had landed these :(
Whiteboard: [cm192test]
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: