| 
									
										
										
										
											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" | 
					
						
							| 
									
										
										
										
											2020-02-04 12:19:40 -08:00
										 |  |  | #include "shell/browser/api/electron_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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 14:23:04 -07:00
										 |  |  | namespace electron { | 
					
						
							| 
									
										
										
										
											2016-07-13 08:54:40 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace api { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool WebContents::IsFocused() const { | 
					
						
							| 
									
										
										
										
											2018-04-17 15:41:47 -07:00
										 |  |  |   auto* view = web_contents()->GetRenderWidgetHostView(); | 
					
						
							| 
									
										
										
										
											2018-04-20 14:47:04 -04:00
										 |  |  |   if (!view) | 
					
						
							|  |  |  |     return false; | 
					
						
							| 
									
										
										
										
											2016-07-28 15:47:52 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-03 20:11:41 +02:00
										 |  |  |   if (GetType() != Type::BACKGROUND_PAGE) { | 
					
						
							| 
									
										
										
										
											2019-01-09 12:25:19 -08:00
										 |  |  |     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; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-28 15:47:52 -07:00
										 |  |  |   return view->HasFocus(); | 
					
						
							| 
									
										
										
										
											2016-07-13 08:54:40 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }  // namespace api | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 14:23:04 -07:00
										 |  |  | }  // namespace electron |