Check document.activeElement in hasFocus

This allows the focus check to be correct when the tree view has focus
but the window does not and a command is triggered from the context menu.