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.
|
|
|
|
|
2018-04-12 07:16:00 +00:00
|
|
|
#include "content/public/browser/render_widget_host_view.h"
|
2020-02-04 20:19:40 +00:00
|
|
|
#include "shell/browser/api/electron_api_web_contents.h"
|
2016-07-13 15:54:40 +00:00
|
|
|
|
2016-08-23 16:51:54 +00:00
|
|
|
#import <Cocoa/Cocoa.h>
|
2016-07-13 15:54:40 +00:00
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2016-07-13 15:54:40 +00:00
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
|
|
|
bool WebContents::IsFocused() const {
|
2018-04-17 22:41:47 +00:00
|
|
|
auto* view = web_contents()->GetRenderWidgetHostView();
|
2018-04-20 18:47:04 +00:00
|
|
|
if (!view)
|
|
|
|
return false;
|
2016-07-28 22:47:52 +00:00
|
|
|
|
2019-05-03 18:11:41 +00:00
|
|
|
if (GetType() != Type::BACKGROUND_PAGE) {
|
2019-01-09 20:25:19 +00:00
|
|
|
auto window = [web_contents()->GetNativeView().GetNativeNSView() 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;
|
|
|
|
}
|
|
|
|
|
2016-07-28 22:47:52 +00:00
|
|
|
return view->HasFocus();
|
2016-07-13 15:54:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|