electron/shell/browser/api/atom_api_web_contents_mac.mm

33 lines
855 B
Text
Raw Normal View History

2016-07-13 08:54:40 -07: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.
2018-04-12 12:46:00 +05:30
#include "content/public/browser/render_widget_host_view.h"
#include "shell/browser/api/atom_api_web_contents.h"
2016-07-13 08:54:40 -07:00
2016-08-23 09:51:54 -07:00
#import <Cocoa/Cocoa.h>
2016-07-13 08:54:40 -07:00
namespace electron {
2016-07-13 08:54:40 -07:00
namespace api {
bool WebContents::IsFocused() const {
auto* view = web_contents()->GetRenderWidgetHostView();
2018-04-20 14:47:04 -04:00
if (!view)
return false;
if (GetType() != Type::BACKGROUND_PAGE) {
auto window = [web_contents()->GetNativeView().GetNativeNSView() window];
2016-07-13 08:54:40 -07: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 08:54:40 -07:00
}
} // namespace api
} // namespace electron