summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/metro_viewer/metro_viewer_process_host_win.cc7
-rw-r--r--chrome/browser/metro_viewer/metro_viewer_process_host_win.h1
-rw-r--r--chrome/browser/ui/aura/active_desktop_monitor.cc65
-rw-r--r--chrome/browser/ui/aura/active_desktop_monitor.h40
-rw-r--r--chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.cc3
-rw-r--r--chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h3
-rw-r--r--chrome/browser/ui/host_desktop.cc30
-rw-r--r--chrome/browser/ui/host_desktop.h2
-rw-r--r--chrome/chrome_browser_ui.gypi2
9 files changed, 138 insertions, 15 deletions
diff --git a/chrome/browser/metro_viewer/metro_viewer_process_host_win.cc b/chrome/browser/metro_viewer/metro_viewer_process_host_win.cc
index 23dc1dd..a1b411e 100644
--- a/chrome/browser/metro_viewer/metro_viewer_process_host_win.cc
+++ b/chrome/browser/metro_viewer/metro_viewer_process_host_win.cc
@@ -40,6 +40,8 @@ bool MetroViewerProcessHost::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(MetroViewerHostMsg_KeyDown, OnKeyDown)
IPC_MESSAGE_HANDLER(MetroViewerHostMsg_KeyUp, OnKeyUp)
IPC_MESSAGE_HANDLER(MetroViewerHostMsg_Character, OnChar)
+ IPC_MESSAGE_HANDLER(MetroViewerHostMsg_VisibilityChanged,
+ OnVisibilityChanged)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
@@ -99,3 +101,8 @@ void MetroViewerProcessHost::OnChar(uint32 key_code,
aura::RemoteRootWindowHostWin::Instance()->OnChar(
key_code, repeat_count, scan_code, flags);
}
+
+void MetroViewerProcessHost::OnVisibilityChanged(bool visible) {
+ aura::RemoteRootWindowHostWin::Instance()->OnVisibilityChanged(
+ visible);
+}
diff --git a/chrome/browser/metro_viewer/metro_viewer_process_host_win.h b/chrome/browser/metro_viewer/metro_viewer_process_host_win.h
index 9d71524..f63a93d 100644
--- a/chrome/browser/metro_viewer/metro_viewer_process_host_win.h
+++ b/chrome/browser/metro_viewer/metro_viewer_process_host_win.h
@@ -49,6 +49,7 @@ class MetroViewerProcessHost : public IPC::Listener,
uint32 repeat_count,
uint32 scan_code,
uint32 flags);
+ void OnVisibilityChanged(bool visible);
scoped_ptr<IPC::ChannelProxy> channel_;
diff --git a/chrome/browser/ui/aura/active_desktop_monitor.cc b/chrome/browser/ui/aura/active_desktop_monitor.cc
new file mode 100644
index 0000000..65fee36
--- /dev/null
+++ b/chrome/browser/ui/aura/active_desktop_monitor.cc
@@ -0,0 +1,65 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/aura/active_desktop_monitor.h"
+
+#include "ui/aura/env.h"
+#include "ui/aura/root_window.h"
+
+#if defined(OS_LINUX)
+#include "ui/views/widget/desktop_aura/desktop_root_window_host_linux.h"
+#elif defined(OS_WIN)
+#include "ui/views/widget/desktop_aura/desktop_root_window_host_win.h"
+#endif
+
+// static
+ActiveDesktopMonitor* ActiveDesktopMonitor::g_instance_ = NULL;
+
+ActiveDesktopMonitor::ActiveDesktopMonitor()
+ : last_activated_desktop_(chrome::HOST_DESKTOP_TYPE_NATIVE) {
+ DCHECK(!g_instance_);
+ g_instance_ = this;
+ aura::Env::GetInstance()->AddObserver(this);
+}
+
+ActiveDesktopMonitor::~ActiveDesktopMonitor() {
+ DCHECK_EQ(g_instance_, this);
+ aura::Env::GetInstance()->RemoveObserver(this);
+ g_instance_ = NULL;
+}
+
+// static
+chrome::HostDesktopType ActiveDesktopMonitor::GetLastActivatedDesktopType() {
+ return g_instance_->last_activated_desktop_;
+}
+
+// static
+bool ActiveDesktopMonitor::IsDesktopWindow(aura::RootWindow* root_window) {
+ // Only windows hosted by a DesktopRootWindowHost implementation can be mapped
+ // back to a content Window. All others, therefore, must be the root window
+ // for an Ash display.
+#if defined(OS_WIN)
+ return views::DesktopRootWindowHostWin::GetContentWindowForHWND(
+ root_window->GetAcceleratedWidget()) != NULL;
+#elif defined(OS_LINUX)
+ return views::DesktopRootWindowHostLinux::GetContentWindowForXID(
+ root_window->GetAcceleratedWidget()) != NULL;
+#else
+ NOTREACHED();
+ return true;
+#endif
+}
+
+void ActiveDesktopMonitor::OnWindowInitialized(aura::Window* window) {}
+
+void ActiveDesktopMonitor::OnRootWindowActivated(
+ aura::RootWindow* root_window) {
+ if (IsDesktopWindow(root_window))
+ last_activated_desktop_ = chrome::HOST_DESKTOP_TYPE_NATIVE;
+ else
+ last_activated_desktop_ = chrome::HOST_DESKTOP_TYPE_ASH;
+ DVLOG(1) << __FUNCTION__
+ << (last_activated_desktop_ == chrome::HOST_DESKTOP_TYPE_NATIVE ?
+ " native" : " ash") << " desktop activated.";
+}
diff --git a/chrome/browser/ui/aura/active_desktop_monitor.h b/chrome/browser/ui/aura/active_desktop_monitor.h
new file mode 100644
index 0000000..ff63984
--- /dev/null
+++ b/chrome/browser/ui/aura/active_desktop_monitor.h
@@ -0,0 +1,40 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_UI_AURA_ACTIVE_DESKTOP_MONITOR_H_
+#define CHROME_BROWSER_UI_AURA_ACTIVE_DESKTOP_MONITOR_H_
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "chrome/browser/ui/host_desktop.h"
+#include "ui/aura/env_observer.h"
+
+// Tracks the most-recently activated host desktop type by observing
+// RootWindowHost activations.
+class ActiveDesktopMonitor : public aura::EnvObserver {
+ public:
+ ActiveDesktopMonitor();
+ virtual ~ActiveDesktopMonitor();
+
+ // Returns the host desktop type of the most-recently activated
+ // RootWindowHost. This desktop type may no longer exist (e.g., the Ash
+ // desktop may have closed since being active, and no RWHs on the native
+ // desktop have yet been activated).
+ static chrome::HostDesktopType GetLastActivatedDesktopType();
+
+ private:
+ // Returns true if |root_window| is hosted by a DesktopRootWindowHost.
+ static bool IsDesktopWindow(aura::RootWindow* root_window);
+
+ // aura::EnvObserver methods.
+ virtual void OnWindowInitialized(aura::Window* window) OVERRIDE;
+ virtual void OnRootWindowActivated(aura::RootWindow* root_window) OVERRIDE;
+
+ static ActiveDesktopMonitor* g_instance_;
+ chrome::HostDesktopType last_activated_desktop_;
+
+ DISALLOW_COPY_AND_ASSIGN(ActiveDesktopMonitor);
+};
+
+#endif // CHROME_BROWSER_UI_AURA_ACTIVE_DESKTOP_MONITOR_H_
diff --git a/chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.cc b/chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.cc
index 4c5dff5..21387c8 100644
--- a/chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.cc
+++ b/chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.cc
@@ -6,6 +6,7 @@
#include "chrome/browser/chrome_browser_main.h"
#include "chrome/browser/toolkit_extra_parts.h"
+#include "chrome/browser/ui/aura/active_desktop_monitor.h"
#include "chrome/browser/ui/aura/stacking_client_aura.h"
#include "ui/aura/env.h"
#include "ui/gfx/screen.h"
@@ -32,6 +33,7 @@ ChromeBrowserMainExtraPartsAura::~ChromeBrowserMainExtraPartsAura() {
void ChromeBrowserMainExtraPartsAura::PreProfileInit() {
#if !defined(OS_CHROMEOS)
#if defined(USE_ASH)
+ active_desktop_monitor_.reset(new ActiveDesktopMonitor);
if (!chrome::ShouldOpenAshOnStartup())
#endif
{
@@ -50,6 +52,7 @@ void ChromeBrowserMainExtraPartsAura::PreProfileInit() {
void ChromeBrowserMainExtraPartsAura::PostMainMessageLoopRun() {
stacking_client_.reset();
+ active_desktop_monitor_.reset();
// aura::Env instance is deleted in BrowserProcessImpl::StartTearDown
// after the metrics service is deleted.
diff --git a/chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h b/chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h
index 3f0784a..4bb8cfe 100644
--- a/chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h
+++ b/chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h
@@ -16,6 +16,8 @@ class StackingClient;
}
}
+class ActiveDesktopMonitor;
+
class ChromeBrowserMainExtraPartsAura : public ChromeBrowserMainExtraParts {
public:
ChromeBrowserMainExtraPartsAura();
@@ -27,6 +29,7 @@ class ChromeBrowserMainExtraPartsAura : public ChromeBrowserMainExtraParts {
private:
scoped_ptr<aura::client::StackingClient> stacking_client_;
+ scoped_ptr<ActiveDesktopMonitor> active_desktop_monitor_;
DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainExtraPartsAura);
};
diff --git a/chrome/browser/ui/host_desktop.cc b/chrome/browser/ui/host_desktop.cc
index e2c34bb..f7f7c65 100644
--- a/chrome/browser/ui/host_desktop.cc
+++ b/chrome/browser/ui/host_desktop.cc
@@ -8,14 +8,11 @@
#include <windows.h>
#endif
+#include "ash/shell.h"
#include "chrome/browser/ui/ash/ash_util.h"
+#include "chrome/browser/ui/aura/active_desktop_monitor.h"
#include "chrome/browser/ui/browser_list_impl.h"
-#if defined(OS_WIN)
-#include "ash/shell.h"
-#include "ui/aura/root_window.h"
-#endif
-
namespace chrome {
namespace {
@@ -79,16 +76,19 @@ HostDesktopType GetHostDesktopTypeForBrowser(const Browser* browser) {
}
HostDesktopType GetActiveDesktop() {
-#if defined(OS_WIN) && defined(USE_ASH)
- if (ash::Shell::HasInstance()) {
- HWND active_window = GetActiveWindow();
- typedef ash::Shell::RootWindowList RootWindowList;
- RootWindowList roots(ash::Shell::GetAllRootWindows());
- for (RootWindowList::const_iterator i = roots.begin(); i != roots.end();
- ++i) {
- if ((*i)->GetAcceleratedWidget() == active_window)
- return HOST_DESKTOP_TYPE_ASH;
- }
+#if defined(USE_ASH) && !defined(OS_CHROMEOS)
+ // The Ash desktop is considered active if a non-desktop RootWindow was last
+ // activated and the Ash desktop is still open. As it is, the Ash desktop
+ // will be considered the last active if a user switches from metro Chrome to
+ // the Windows desktop but doesn't activate any Chrome windows there (e.g.,
+ // by clicking on one or otherwise giving one focus). Consider finding a way
+ // to detect that the Windows desktop has been activated so that the native
+ // desktop can be considered active once the user switches to it if its
+ // BrowserList isn't empty.
+ if ((ActiveDesktopMonitor::GetLastActivatedDesktopType() ==
+ chrome::HOST_DESKTOP_TYPE_ASH) &&
+ ash::Shell::HasInstance()) {
+ return HOST_DESKTOP_TYPE_ASH;
}
#endif
return HOST_DESKTOP_TYPE_NATIVE;
diff --git a/chrome/browser/ui/host_desktop.h b/chrome/browser/ui/host_desktop.h
index b0f188b..9b2dc75 100644
--- a/chrome/browser/ui/host_desktop.h
+++ b/chrome/browser/ui/host_desktop.h
@@ -47,6 +47,8 @@ HostDesktopType GetHostDesktopTypeForNativeWindow(
gfx::NativeWindow native_window);
HostDesktopType GetHostDesktopTypeForBrowser(const Browser* browser);
+// Returns the type of host desktop most likely to be in use. This is the one
+// most recently activated by the user.
HostDesktopType GetActiveDesktop();
} // namespace chrome
diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi
index 489e3cf..e3104ce 100644
--- a/chrome/chrome_browser_ui.gypi
+++ b/chrome/chrome_browser_ui.gypi
@@ -168,6 +168,8 @@
'browser/ui/ash/volume_controller_chromeos.h',
'browser/ui/ash/window_positioner.cc',
'browser/ui/ash/window_positioner.h',
+ 'browser/ui/aura/active_desktop_monitor.cc',
+ 'browser/ui/aura/active_desktop_monitor.h',
'browser/ui/aura/chrome_browser_main_extra_parts_aura.cc',
'browser/ui/aura/chrome_browser_main_extra_parts_aura.h',
'browser/ui/aura/stacking_client_aura.cc',