Bug 1026164, improve focus handling in shadow dom, r=wchen

--HG--
extra : rebase_source : 026b9ee49cdce82a703700593d7a1f0e5d27969f
Bug 1049010, layout should use composed doc, not current doc in many cases, r=wchen

--HG--
extra : rebase_source : 42ce2eebfd38ea2e6dbe5711954c601f19d72467