Commit 7b733cde authored by mukai@chromium.org's avatar mukai@chromium.org

Removes the dependency to WMTestHelper from app shell.

Also ShellDesktopController has its own logic to initialize the
window manager, and its subclass (like Athena) can initialize
its own window management logic.

R=jamescook@chromium.org, oshima@chromium.org
TEST=no logic changes, confirmed athena_main running
BUG=

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274263 0039d316-1c4b-4281-b951-d872f2087c98
parent e8732dcf
......@@ -88,7 +88,6 @@
'<(DEPTH)/skia/skia.gyp:skia',
'<(DEPTH)/third_party/WebKit/public/blink.gyp:blink',
'<(DEPTH)/ui/wm/wm.gyp:wm',
'<(DEPTH)/ui/wm/wm.gyp:wm_test_support',
'<(DEPTH)/v8/tools/gyp/v8.gyp:v8',
],
'include_dirs': [
......
......@@ -4,6 +4,7 @@
#include "apps/shell/browser/default_shell_browser_main_delegate.h"
#include "apps/shell/browser/shell_desktop_controller.h"
#include "apps/shell/browser/shell_extension_system.h"
#include "base/command_line.h"
#include "base/file_util.h"
......@@ -37,4 +38,9 @@ void DefaultShellBrowserMainDelegate::Start(
void DefaultShellBrowserMainDelegate::Shutdown() {
}
ShellDesktopController*
DefaultShellBrowserMainDelegate::CreateDesktopController() {
return new ShellDesktopController();
}
} // namespace apps
......@@ -21,6 +21,7 @@ class DefaultShellBrowserMainDelegate : public ShellBrowserMainDelegate {
// ShellBrowserMainDelegate:
virtual void Start(content::BrowserContext* context) OVERRIDE;
virtual void Shutdown() OVERRIDE;
virtual ShellDesktopController* CreateDesktopController() OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(DefaultShellBrowserMainDelegate);
......
......@@ -11,6 +11,8 @@ class BrowserContext;
namespace apps {
class ShellDesktopController;
class ShellBrowserMainDelegate {
public:
virtual ~ShellBrowserMainDelegate() {}
......@@ -22,6 +24,11 @@ class ShellBrowserMainDelegate {
// Called after the main message looop has stopped, but before
// other services such as BrowserContext / extension system are shut down.
virtual void Shutdown() = 0;
// Creates the ShellDesktopController instance to initialize the root window
// and window manager. Subclass may return its subclass to customize the
// windo manager.
virtual ShellDesktopController* CreateDesktopController() = 0;
};
} // namespace apps
......
......@@ -81,8 +81,8 @@ void ShellBrowserMainParts::PreMainMessageLoopRun() {
// Initialize our "profile" equivalent.
browser_context_.reset(new ShellBrowserContext);
desktop_controller_.reset(new ShellDesktopController);
desktop_controller_->GetWindowTreeHost()->AddObserver(this);
desktop_controller_.reset(browser_main_delegate_->CreateDesktopController());
desktop_controller_->CreateRootWindow();
// NOTE: Much of this is culled from chrome/test/base/chrome_test_suite.cc
// TODO(jamescook): Initialize chromeos::UserManager.
......@@ -136,7 +136,6 @@ void ShellBrowserMainParts::PostMainMessageLoopRun() {
extensions_browser_client_.reset();
browser_context_.reset();
desktop_controller_->GetWindowTreeHost()->RemoveObserver(this);
desktop_controller_.reset();
}
......@@ -147,13 +146,6 @@ void ShellBrowserMainParts::PostDestroyThreads() {
#endif
}
void ShellBrowserMainParts::OnHostCloseRequested(
const aura::WindowTreeHost* host) {
desktop_controller_->CloseAppWindow();
base::MessageLoop::current()->PostTask(FROM_HERE,
base::MessageLoop::QuitClosure());
}
void ShellBrowserMainParts::CreateExtensionSystem() {
DCHECK(browser_context_);
extension_system_ = static_cast<ShellExtensionSystem*>(
......
......@@ -43,8 +43,7 @@ class ShellNetworkController;
#endif
// Handles initialization of AppShell.
class ShellBrowserMainParts : public content::BrowserMainParts,
public aura::WindowTreeHostObserver {
class ShellBrowserMainParts : public content::BrowserMainParts {
public:
ShellBrowserMainParts(const content::MainFunctionParams& parameters,
ShellBrowserMainDelegate* browser_main_delegate);
......@@ -68,9 +67,6 @@ class ShellBrowserMainParts : public content::BrowserMainParts,
virtual void PostMainMessageLoopRun() OVERRIDE;
virtual void PostDestroyThreads() OVERRIDE;
// aura::WindowTreeHostObserver overrides:
virtual void OnHostCloseRequested(const aura::WindowTreeHost* host) OVERRIDE;
private:
// Creates and initializes the ExtensionSystem.
void CreateExtensionSystem();
......
......@@ -7,6 +7,7 @@
#include "apps/shell/browser/shell_app_window.h"
#include "content/public/browser/context_factory.h"
#include "ui/aura/client/cursor_client.h"
#include "ui/aura/client/default_capture_client.h"
#include "ui/aura/env.h"
#include "ui/aura/layout_manager.h"
#include "ui/aura/test/test_screen.h"
......@@ -18,11 +19,15 @@
#include "ui/base/ime/input_method_initializer.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/screen.h"
#include "ui/wm/core/base_focus_rules.h"
#include "ui/wm/core/compound_event_filter.h"
#include "ui/wm/core/cursor_manager.h"
#include "ui/wm/core/default_activation_client.h"
#include "ui/wm/core/focus_controller.h"
#include "ui/wm/core/input_method_event_filter.h"
#include "ui/wm/core/native_cursor_manager.h"
#include "ui/wm/core/native_cursor_manager_delegate.h"
#include "ui/wm/core/user_activity_detector.h"
#include "ui/wm/test/wm_test_helper.h"
#if defined(OS_CHROMEOS)
#include "ui/chromeos/user_activity_power_manager_notifier.h"
......@@ -138,6 +143,19 @@ class ShellNativeCursorManager : public wm::NativeCursorManager {
DISALLOW_COPY_AND_ASSIGN(ShellNativeCursorManager);
};
class AppsFocusRules : public wm::BaseFocusRules {
public:
AppsFocusRules() {}
virtual ~AppsFocusRules() {}
virtual bool SupportsChildActivation(aura::Window* window) const OVERRIDE {
return true;
}
private:
DISALLOW_COPY_AND_ASSIGN(AppsFocusRules);
};
ShellDesktopController* g_instance = NULL;
} // namespace
......@@ -149,24 +167,8 @@ ShellDesktopController::ShellDesktopController() {
display_configurator_->ForceInitialConfigure(0);
display_configurator_->AddObserver(this);
#endif
CreateRootWindow();
cursor_manager_.reset(
new wm::CursorManager(scoped_ptr<wm::NativeCursorManager>(
new ShellNativeCursorManager(GetWindowTreeHost()))));
cursor_manager_->SetDisplay(
gfx::Screen::GetNativeScreen()->GetPrimaryDisplay());
cursor_manager_->SetCursor(ui::kCursorPointer);
aura::client::SetCursorClient(
GetWindowTreeHost()->window(), cursor_manager_.get());
user_activity_detector_.reset(new wm::UserActivityDetector);
GetWindowTreeHost()->event_processor()->GetRootTarget()->AddPreTargetHandler(
user_activity_detector_.get());
#if defined(OS_CHROMEOS)
user_activity_notifier_.reset(
new ui::UserActivityPowerManagerNotifier(user_activity_detector_.get()));
#endif
aura::Env::CreateInstance(true);
aura::Env::GetInstance()->set_context_factory(content::GetContextFactory());
g_instance = this;
}
......@@ -175,8 +177,6 @@ ShellDesktopController::~ShellDesktopController() {
// The app window must be explicitly closed before desktop teardown.
DCHECK(!app_window_);
g_instance = NULL;
GetWindowTreeHost()->event_processor()->GetRootTarget()
->RemovePreTargetHandler(user_activity_detector_.get());
DestroyRootWindow();
aura::Env::DeleteInstance();
}
......@@ -188,7 +188,7 @@ ShellDesktopController* ShellDesktopController::instance() {
ShellAppWindow* ShellDesktopController::CreateAppWindow(
content::BrowserContext* context) {
aura::Window* root_window = GetWindowTreeHost()->window();
aura::Window* root_window = host_->window();
app_window_.reset(new ShellAppWindow);
app_window_->Init(context, root_window->bounds().size());
......@@ -203,8 +203,11 @@ ShellAppWindow* ShellDesktopController::CreateAppWindow(
void ShellDesktopController::CloseAppWindow() { app_window_.reset(); }
aura::WindowTreeHost* ShellDesktopController::GetWindowTreeHost() {
return wm_test_helper_->host();
aura::Window* ShellDesktopController::GetDefaultParent(
aura::Window* context,
aura::Window* window,
const gfx::Rect& bounds) {
return host_->window();
}
#if defined(OS_CHROMEOS)
......@@ -212,10 +215,18 @@ void ShellDesktopController::OnDisplayModeChanged(
const std::vector<ui::DisplayConfigurator::DisplayState>& displays) {
gfx::Size size = GetPrimaryDisplaySize();
if (!size.IsEmpty())
wm_test_helper_->host()->UpdateRootWindowSize(size);
host_->UpdateRootWindowSize(size);
}
#endif
void ShellDesktopController::OnHostCloseRequested(
const aura::WindowTreeHost* host) {
DCHECK_EQ(host_.get(), host);
CloseAppWindow();
base::MessageLoop::current()->PostTask(FROM_HERE,
base::MessageLoop::QuitClosure());
}
void ShellDesktopController::CreateRootWindow() {
test_screen_.reset(aura::TestScreen::Create());
// TODO(jamescook): Replace this with a real Screen implementation.
......@@ -227,19 +238,72 @@ void ShellDesktopController::CreateRootWindow() {
gfx::Size size = GetPrimaryDisplaySize();
if (size.IsEmpty())
size = gfx::Size(800, 600);
wm_test_helper_.reset(
new wm::WMTestHelper(size, content::GetContextFactory()));
// Ensure new windows fill the display.
aura::WindowTreeHost* host = wm_test_helper_->host();
host->window()->SetLayoutManager(new FillLayout);
host_.reset(aura::WindowTreeHost::Create(gfx::Rect(size)));
host_->InitHost();
aura::client::SetWindowTreeClient(host_->window(), this);
root_window_event_filter_.reset(new wm::CompoundEventFilter);
host_->window()->AddPreTargetHandler(root_window_event_filter_.get());
InitWindowManager();
host_->AddObserver(this);
// Ensure the X window gets mapped.
host->Show();
host_->Show();
}
void ShellDesktopController::InitWindowManager() {
focus_client_.reset(new wm::FocusController(new AppsFocusRules()));
aura::client::SetFocusClient(host_->window(), focus_client_.get());
input_method_filter_.reset(
new wm::InputMethodEventFilter(host_->GetAcceleratedWidget()));
input_method_filter_->SetInputMethodPropertyInRootWindow(host_->window());
root_window_event_filter_->AddHandler(input_method_filter_.get());
new wm::DefaultActivationClient(host_->window());
capture_client_.reset(
new aura::client::DefaultCaptureClient(host_->window()));
// Ensure new windows fill the display.
host_->window()->SetLayoutManager(new FillLayout);
cursor_manager_.reset(
new wm::CursorManager(scoped_ptr<wm::NativeCursorManager>(
new ShellNativeCursorManager(host_.get()))));
cursor_manager_->SetDisplay(
gfx::Screen::GetNativeScreen()->GetPrimaryDisplay());
cursor_manager_->SetCursor(ui::kCursorPointer);
aura::client::SetCursorClient(host_->window(), cursor_manager_.get());
user_activity_detector_.reset(new wm::UserActivityDetector);
host_->event_processor()->GetRootTarget()->AddPreTargetHandler(
user_activity_detector_.get());
#if defined(OS_CHROMEOS)
user_activity_notifier_.reset(
new ui::UserActivityPowerManagerNotifier(user_activity_detector_.get()));
#endif
}
void ShellDesktopController::DestroyRootWindow() {
wm_test_helper_.reset();
host_->RemoveObserver(this);
if (input_method_filter_)
root_window_event_filter_->RemoveHandler(input_method_filter_.get());
if (user_activity_detector_) {
host_->event_processor()->GetRootTarget()->RemovePreTargetHandler(
user_activity_detector_.get());
}
root_window_event_filter_.reset();
capture_client_.reset();
input_method_filter_.reset();
focus_client_.reset();
cursor_manager_.reset();
#if defined(OS_CHROMEOS)
user_activity_notifier_.reset();
#endif
user_activity_detector_.reset();
host_.reset();
ui::ShutdownInputMethodForTesting();
}
......
......@@ -8,8 +8,8 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "ui/aura/client/window_tree_client.h"
#include "ui/aura/window_tree_host_observer.h"
#include "ui/gfx/geometry/size.h"
#if defined(OS_CHROMEOS)
#include "ui/display/chromeos/display_configurator.h"
......@@ -17,13 +17,22 @@
namespace aura {
class TestScreen;
class Window;
class WindowTreeHost;
namespace client {
class DefaultCaptureClient;
class FocusClient;
}
}
namespace content {
class BrowserContext;
}
namespace gfx {
class Size;
}
#if defined(OS_CHROMEOS)
namespace ui {
class UserActivityPowerManagerNotifier;
......@@ -31,9 +40,10 @@ class UserActivityPowerManagerNotifier;
#endif
namespace wm {
class CompoundEventFilter;
class CursorManager;
class InputMethodEventFilter;
class UserActivityDetector;
class WMTestHelper;
}
namespace apps {
......@@ -41,11 +51,13 @@ namespace apps {
class ShellAppWindow;
// Handles desktop-related tasks for app_shell.
class ShellDesktopController
class ShellDesktopController : public aura::client::WindowTreeClient,
public aura::WindowTreeHostObserver
#if defined(OS_CHROMEOS)
: public ui::DisplayConfigurator::Observer
,
public ui::DisplayConfigurator::Observer
#endif
{
{
public:
ShellDesktopController();
virtual ~ShellDesktopController();
......@@ -55,6 +67,11 @@ class ShellDesktopController
// we need a singleton somewhere).
static ShellDesktopController* instance();
aura::WindowTreeHost* host() { return host_.get(); }
// Creates the window that hosts the app.
void CreateRootWindow();
// Creates a new app window and adds it to the desktop. The desktop maintains
// ownership of the window.
ShellAppWindow* CreateAppWindow(content::BrowserContext* context);
......@@ -62,8 +79,10 @@ class ShellDesktopController
// Closes and destroys the app window.
void CloseAppWindow();
// Returns the host for the Aura window tree.
aura::WindowTreeHost* GetWindowTreeHost();
// Overridden from aura::client::WindowTreeClient:
virtual aura::Window* GetDefaultParent(aura::Window* context,
aura::Window* window,
const gfx::Rect& bounds) OVERRIDE;
#if defined(OS_CHROMEOS)
// ui::DisplayConfigurator::Observer overrides.
......@@ -71,10 +90,15 @@ class ShellDesktopController
ui::DisplayConfigurator::DisplayState>& displays) OVERRIDE;
#endif
private:
// Creates the window that hosts the app.
void CreateRootWindow();
// aura::WindowTreeHostObserver overrides:
virtual void OnHostCloseRequested(const aura::WindowTreeHost* host) OVERRIDE;
protected:
// Creates and sets the aura clients and window manager stuff. Subclass may
// initialize different sets of the clients.
virtual void InitWindowManager();
private:
// Closes and destroys the root window hosting the app.
void DestroyRootWindow();
......@@ -86,11 +110,18 @@ class ShellDesktopController
scoped_ptr<ui::DisplayConfigurator> display_configurator_;
#endif
// Enable a minimal set of views::corewm to be initialized.
scoped_ptr<wm::WMTestHelper> wm_test_helper_;
scoped_ptr<aura::TestScreen> test_screen_;
scoped_ptr<aura::WindowTreeHost> host_;
scoped_ptr<wm::CompoundEventFilter> root_window_event_filter_;
scoped_ptr<aura::client::DefaultCaptureClient> capture_client_;
scoped_ptr<wm::InputMethodEventFilter> input_method_filter_;
scoped_ptr<aura::client::FocusClient> focus_client_;
scoped_ptr<wm::CursorManager> cursor_manager_;
scoped_ptr<wm::UserActivityDetector> user_activity_detector_;
......
......@@ -19,15 +19,20 @@ class AthenaBrowserMainDelegate : public apps::ShellBrowserMainDelegate {
// apps::ShellBrowserMainDelegate:
virtual void Start(content::BrowserContext* context) OVERRIDE {
athena::StartAthena(apps::ShellDesktopController::instance()
->GetWindowTreeHost()
->window());
athena::StartAthena(
apps::ShellDesktopController::instance()->host()->window());
CreateTestWindows();
CreateTestPages(context);
}
virtual void Shutdown() OVERRIDE { athena::ShutdownAthena(); }
virtual apps::ShellDesktopController* CreateDesktopController() OVERRIDE {
// TODO(mukai): create Athena's own ShellDesktopController subclass so that
// it can initialize its own window manager logic.
return new apps::ShellDesktopController();
}
private:
DISALLOW_COPY_AND_ASSIGN(AthenaBrowserMainDelegate);
};
......
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