electron/atom/browser/api/atom_api_web_contents_mac.mm

32 lines
762 B
Text
Raw Normal View History

2016-07-13 15:54:40 +00:00
// Copyright (c) 2016 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "atom/browser/api/atom_api_web_contents.h"
2016-08-23 16:51:54 +00:00
#import <Cocoa/Cocoa.h>
2016-07-13 15:54:40 +00:00
namespace atom {
namespace api {
bool WebContents::IsFocused() const {
auto* view = web_contents()->GetRenderWidgetHostView();
2018-04-20 18:47:04 +00:00
if (!view)
return false;
2016-07-13 15:54:40 +00:00
if (GetType() != BACKGROUND_PAGE) {
2016-08-23 16:51:54 +00:00
auto window = [web_contents()->GetNativeView() window];
2016-07-13 15:54:40 +00:00
// On Mac the render widget host view does not lose focus when the window
// loses focus so check if the top level window is the key window.
if (window && ![window isKeyWindow])
return false;
}
return view->HasFocus();
2016-07-13 15:54:40 +00:00
}
} // namespace api
} // namespace atom