diff options
author | kirr <kirr@yandex-team.ru> | 2016-03-02 02:39:41 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-02 10:41:10 +0000 |
commit | 8573bdaa3b8d2573d7e04b4607cf776289b9bd11 (patch) | |
tree | fce96380a6055a20cf45ae970e1cdafc7fd74b29 | |
parent | d91075970aa81e6d3a9ce9744248575947436507 (diff) | |
download | chromium_src-8573bdaa3b8d2573d7e04b4607cf776289b9bd11.zip chromium_src-8573bdaa3b8d2573d7e04b4607cf776289b9bd11.tar.gz chromium_src-8573bdaa3b8d2573d7e04b4607cf776289b9bd11.tar.bz2 |
Mac: Move NSWindow key status handling inside content module.
It is needed for MacViews, because handling window key status
(using windowDidBecomeKey/windowDidResignKey) was only in cocoa code.
So RWHV was not be informed about window key status changes.
On Aura it is done in a similar way, inside RenderWidgetHostViewAura.
BUG=521433
Review URL: https://codereview.chromium.org/1751703003
Cr-Commit-Position: refs/heads/master@{#378720}
4 files changed, 40 insertions, 73 deletions
diff --git a/chrome/browser/ui/cocoa/apps/native_app_window_cocoa.mm b/chrome/browser/ui/cocoa/apps/native_app_window_cocoa.mm index bad78a5..9e191fd 100644 --- a/chrome/browser/ui/cocoa/apps/native_app_window_cocoa.mm +++ b/chrome/browser/ui/cocoa/apps/native_app_window_cocoa.mm @@ -18,7 +18,6 @@ #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" #include "chrome/common/chrome_switches.h" #include "content/public/browser/native_web_keyboard_event.h" -#include "content/public/browser/render_widget_host_view.h" #include "content/public/browser/web_contents.h" #include "extensions/common/extension.h" #include "skia/ext/skia_utils_mac.h" @@ -735,10 +734,6 @@ void NativeAppWindowCocoa::WindowWillClose() { } void NativeAppWindowCocoa::WindowDidBecomeKey() { - content::RenderWidgetHostView* rwhv = - WebContents()->GetRenderWidgetHostView(); - if (rwhv) - rwhv->SetActive(true); app_window_->OnNativeWindowActivated(); WebContents()->RestoreFocus(); @@ -753,11 +748,6 @@ void NativeAppWindowCocoa::WindowDidResignKey() { return; WebContents()->StoreFocus(); - - content::RenderWidgetHostView* rwhv = - WebContents()->GetRenderWidgetHostView(); - if (rwhv) - rwhv->SetActive(false); } void NativeAppWindowCocoa::WindowDidFinishResize() { diff --git a/chrome/browser/ui/cocoa/browser_window_controller.mm b/chrome/browser/ui/cocoa/browser_window_controller.mm index d1a4734..5056d79 100644 --- a/chrome/browser/ui/cocoa/browser_window_controller.mm +++ b/chrome/browser/ui/cocoa/browser_window_controller.mm @@ -655,53 +655,6 @@ void SetUpBrowserWindowCommandHandler(NSWindow* window) { ->set_registry_for_active_window(nullptr); } -// Called when we are activated (when we gain focus). -- (void)windowDidBecomeKey:(NSNotification*)notification { - // We need to activate the controls (in the "WebView"). To do this, get the - // selected WebContents's RenderWidgetHostView and tell it to activate. - if (WebContents* contents = [self webContents]) { - WebContents* devtools = DevToolsWindow::GetInTabWebContents( - contents, NULL); - if (devtools) { - RenderWidgetHostView* devtoolsView = devtools->GetRenderWidgetHostView(); - if (devtoolsView && devtoolsView->HasFocus()) { - devtoolsView->SetActive(true); - return; - } - } - - if (RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView()) - rwhv->SetActive(true); - } -} - -// Called when we are deactivated (when we lose focus). -- (void)windowDidResignKey:(NSNotification*)notification { - // If our app is still active and we're still the key window, ignore this - // message, since it just means that a menu extra (on the "system status bar") - // was activated; we'll get another |-windowDidResignKey| if we ever really - // lose key window status. - if ([NSApp isActive] && ([NSApp keyWindow] == [self window])) - return; - - // We need to deactivate the controls (in the "WebView"). To do this, get the - // selected WebContents's RenderWidgetHostView and tell it to deactivate. - if (WebContents* contents = [self webContents]) { - WebContents* devtools = DevToolsWindow::GetInTabWebContents( - contents, NULL); - if (devtools) { - RenderWidgetHostView* devtoolsView = devtools->GetRenderWidgetHostView(); - if (devtoolsView && devtoolsView->HasFocus()) { - devtoolsView->SetActive(false); - return; - } - } - - if (RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView()) - rwhv->SetActive(false); - } -} - // Called when we have been minimized. - (void)windowDidMiniaturize:(NSNotification *)notification { [self saveWindowPositionIfNeeded]; diff --git a/chrome/browser/ui/cocoa/panels/panel_window_controller_cocoa.mm b/chrome/browser/ui/cocoa/panels/panel_window_controller_cocoa.mm index 53cb9db..dc51ed7 100644 --- a/chrome/browser/ui/cocoa/panels/panel_window_controller_cocoa.mm +++ b/chrome/browser/ui/cocoa/panels/panel_window_controller_cocoa.mm @@ -569,14 +569,6 @@ const double kWidthOfMouseResizeArea = 15.0; // whether it's refactoring more things into BrowserWindowUtils or making a // common base controller for browser windows. - (void)windowDidBecomeKey:(NSNotification*)notification { - // We need to activate the controls (in the "WebView"). To do this, get the - // selected WebContents's RenderWidgetHostView and tell it to activate. - if (WebContents* contents = windowShim_->panel()->GetWebContents()) { - if (content::RenderWidgetHostView* rwhv = - contents->GetRenderWidgetHostView()) - rwhv->SetActive(true); - } - windowShim_->panel()->OnActiveStateChanged(true); // Make the window user-resizable when it gains the focus. @@ -730,14 +722,6 @@ const double kWidthOfMouseResizeArea = 15.0; } - (void)onWindowDidResignKey { - // We need to deactivate the controls (in the "WebView"). To do this, get the - // selected WebContents's RenderWidgetHostView and tell it to deactivate. - if (WebContents* contents = windowShim_->panel()->GetWebContents()) { - if (content::RenderWidgetHostView* rwhv = - contents->GetRenderWidgetHostView()) - rwhv->SetActive(false); - } - windowShim_->panel()->OnActiveStateChanged(false); // Make the window not user-resizable when it loses the focus. This is to diff --git a/content/browser/renderer_host/render_widget_host_view_mac.mm b/content/browser/renderer_host/render_widget_host_view_mac.mm index 0532cb0..15f1ac2 100644 --- a/content/browser/renderer_host/render_widget_host_view_mac.mm +++ b/content/browser/renderer_host/render_widget_host_view_mac.mm @@ -178,6 +178,8 @@ static BOOL SupportsBackingPropertiesChangedNotification() { - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv; - (void)windowDidChangeBackingProperties:(NSNotification*)notification; - (void)windowChangedGlobalFrame:(NSNotification*)notification; +- (void)windowDidBecomeKey:(NSNotification*)notification; +- (void)windowDidResignKey:(NSNotification*)notification; - (void)checkForPluginImeCancellation; - (void)updateScreenProperties; - (void)setResponderDelegate: @@ -2564,6 +2566,14 @@ void RenderWidgetHostViewMac::OnDisplayMetricsChanged( removeObserver:self name:NSWindowDidEndLiveResizeNotification object:oldWindow]; + [notificationCenter + removeObserver:self + name:NSWindowDidBecomeKeyNotification + object:oldWindow]; + [notificationCenter + removeObserver:self + name:NSWindowDidResignKeyNotification + object:oldWindow]; } if (newWindow) { if (supportsBackingPropertiesNotification) { @@ -2583,6 +2593,14 @@ void RenderWidgetHostViewMac::OnDisplayMetricsChanged( selector:@selector(windowChangedGlobalFrame:) name:NSWindowDidEndLiveResizeNotification object:newWindow]; + [notificationCenter addObserver:self + selector:@selector(windowDidBecomeKey:) + name:NSWindowDidBecomeKeyNotification + object:newWindow]; + [notificationCenter addObserver:self + selector:@selector(windowDidResignKey:) + name:NSWindowDidResignKeyNotification + object:newWindow]; } } @@ -2649,6 +2667,28 @@ void RenderWidgetHostViewMac::OnDisplayMetricsChanged( return canBeKeyView_; } +- (void)windowDidBecomeKey:(NSNotification*)notification { + DCHECK([self window]); + DCHECK_EQ([self window], [notification object]); + if ([[self window] firstResponder] == self) + renderWidgetHostView_->SetActive(true); +} + +- (void)windowDidResignKey:(NSNotification*)notification { + DCHECK([self window]); + DCHECK_EQ([self window], [notification object]); + + // If our app is still active and we're still the key window, ignore this + // message, since it just means that a menu extra (on the "system status bar") + // was activated; we'll get another |-windowDidResignKey| if we ever really + // lose key window status. + if ([NSApp isActive] && ([NSApp keyWindow] == [self window])) + return; + + if ([[self window] firstResponder] == self) + renderWidgetHostView_->SetActive(false); +} + - (BOOL)becomeFirstResponder { if (!renderWidgetHostView_->render_widget_host_) return NO; |