atom_api_web_contents_mac.mm 762 B

1234567891011121314151617181920212223242526272829303132
  1. // Copyright (c) 2016 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "atom/browser/api/atom_api_web_contents.h"
  5. #import <Cocoa/Cocoa.h>
  6. namespace atom {
  7. namespace api {
  8. bool WebContents::IsFocused() const {
  9. auto* view = web_contents()->GetRenderWidgetHostView();
  10. if (!view)
  11. return false;
  12. if (GetType() != BACKGROUND_PAGE) {
  13. auto window = [web_contents()->GetNativeView() window];
  14. // On Mac the render widget host view does not lose focus when the window
  15. // loses focus so check if the top level window is the key window.
  16. if (window && ![window isKeyWindow])
  17. return false;
  18. }
  19. return view->HasFocus();
  20. }
  21. } // namespace api
  22. } // namespace atom