Commit cf8643d4 authored by tapted's avatar tapted Committed by Commit bot

MacViews: Change TOOLKIT_VIEWS to !OS_MACOSX in extensions::WindowsEventRouter

WindowsEventRouter needs to broadcast when no Chrome window has focus.

When toolkit_views first flips on Mac, nothing should actually change in
the release.

Until Chrome on Mac *only* makes Windows with toolkit-views,
WindowsEventRouter on Mac should still use
NSWindowDidBecomeKeyNotification + NOTIFICATION_NO_KEY_WINDOW.

This works both for windows created with toolkit-views and those created
natively.

BUG=439882

Review URL: https://codereview.chromium.org/773303005

Cr-Commit-Position: refs/heads/master@{#308452}
parent cb955cd0
......@@ -30,19 +30,26 @@ WindowsEventRouter::WindowsEventRouter(Profile* profile)
DCHECK(!profile->IsOffTheRecord());
WindowControllerList::GetInstance()->AddObserver(this);
#if defined(TOOLKIT_VIEWS)
views::WidgetFocusManager::GetInstance()->AddFocusChangeListener(this);
#elif defined(OS_MACOSX)
// Needed for when no suitable window can be passed to an extension as the
// currently focused window.
// currently focused window. On Mac (even in a toolkit-views build) always
// rely on the notification sent by AppControllerMac after AppKit sends
// NSWindowDidBecomeKeyNotification and there is no [NSApp keyWindow]. This
// allows windows not created by toolkit-views to be tracked.
// TODO(tapted): Remove the ifdefs (and NOTIFICATION_NO_KEY_WINDOW) when
// Chrome on Mac only makes windows with toolkit-views.
#if defined(OS_MACOSX)
registrar_.Add(this, chrome::NOTIFICATION_NO_KEY_WINDOW,
content::NotificationService::AllSources());
#elif defined(TOOLKIT_VIEWS)
views::WidgetFocusManager::GetInstance()->AddFocusChangeListener(this);
#else
#error Unsupported
#endif
}
WindowsEventRouter::~WindowsEventRouter() {
WindowControllerList::GetInstance()->RemoveObserver(this);
#if defined(TOOLKIT_VIEWS)
#if !defined(OS_MACOSX)
views::WidgetFocusManager::GetInstance()->RemoveFocusChangeListener(this);
#endif
}
......@@ -73,7 +80,7 @@ void WindowsEventRouter::OnWindowControllerRemoved(
args.Pass());
}
#if defined(TOOLKIT_VIEWS)
#if !defined(OS_MACOSX)
void WindowsEventRouter::OnNativeFocusChange(
gfx::NativeView focused_before,
gfx::NativeView focused_now) {
......
......@@ -12,7 +12,8 @@
#include "chrome/browser/extensions/window_controller_list_observer.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#if defined(TOOLKIT_VIEWS)
#if !defined(OS_MACOSX)
#include "ui/views/focus/widget_focus_manager.h"
#endif
......@@ -26,10 +27,10 @@ namespace extensions {
// The WindowsEventRouter sends chrome.windows.* events to listeners
// inside extension process renderers. The router listens to *all* events,
// but will only route eventes within a profile to extension processes in the
// but will only route events within a profile to extension processes in the
// same profile.
class WindowsEventRouter : public WindowControllerListObserver,
#if defined(TOOLKIT_VIEWS)
#if !defined(OS_MACOSX)
public views::WidgetFocusChangeListener,
#endif
public content::NotificationObserver {
......@@ -41,7 +42,7 @@ class WindowsEventRouter : public WindowControllerListObserver,
void OnWindowControllerAdded(WindowController* window_controller) override;
void OnWindowControllerRemoved(WindowController* window) override;
#if defined(TOOLKIT_VIEWS)
#if !defined(OS_MACOSX)
void OnNativeFocusChange(gfx::NativeView focused_before,
gfx::NativeView focused_now) override;
#endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment