The thing I had to check most carefully during this review was whether this code was guaranteed to run before setFocusMode() was called.  The patch would be easier to understand if this code was in setFocusMode(), or if the setFocusMode() code was here.