diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-15 18:32:23 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-15 18:32:23 +0000 |
commit | 1b4c747749bc8cc46ed2b9006d2f82b6c511e7c4 (patch) | |
tree | dadc320dc0f37c5dd756aaee193a72b8697c09b8 | |
parent | 9eab79b4434f1f4346767257af80f066116706f5 (diff) | |
download | chromium_src-1b4c747749bc8cc46ed2b9006d2f82b6c511e7c4.zip chromium_src-1b4c747749bc8cc46ed2b9006d2f82b6c511e7c4.tar.gz chromium_src-1b4c747749bc8cc46ed2b9006d2f82b6c511e7c4.tar.bz2 |
Makes construction of (ash)RemoteWindowTreeHostWin explicit
I need to do this as I need to pass in state to the constructor and I
can't do that with lazy construction. This makes creation a little
saner anyway.
I'm not happy about the static setting the HWND. I'll see if I can
clean that up later.
BUG=none
TEST=none
R=ananta@chromium.org
Review URL: https://codereview.chromium.org/277753002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270747 0039d316-1c4b-4281-b951-d872f2087c98
31 files changed, 240 insertions, 117 deletions
@@ -21,6 +21,9 @@ specific_include_rules = { "root_window_controller\.*": [ "+ash/host" ], + "shell.cc": [ + "+ash/host/ash_window_tree_host_init_params.h" + ], "touch_transformer_controller\.*": [ "+ash/host" ], diff --git a/ash/accessibility_delegate.h b/ash/accessibility_delegate.h index 05fb051..7dc2826 100644 --- a/ash/accessibility_delegate.h +++ b/ash/accessibility_delegate.h @@ -98,4 +98,4 @@ class ASH_EXPORT AccessibilityDelegate { } // namespace ash -#endif // ASH_ACCESSIBILITYDELEGATE_H_ +#endif // ASH_ACCESSIBILITY_DELEGATE_H_ diff --git a/ash/ash.gyp b/ash/ash.gyp index d23db52..0b0f11a 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -188,6 +188,8 @@ 'host/ash_remote_window_tree_host_win.cc', 'host/ash_remote_window_tree_host_win.h', 'host/ash_window_tree_host.h', + 'host/ash_window_tree_host_init_params.cc', + 'host/ash_window_tree_host_init_params.h', 'host/ash_window_tree_host_ozone.cc', 'host/ash_window_tree_host_win.cc', 'host/ash_window_tree_host_x11.cc', @@ -292,6 +294,8 @@ 'shell.h', 'shell_delegate.h', 'shell_factory.h', + 'shell_init_params.cc', + 'shell_init_params.h', 'shell_window_ids.h', 'sticky_keys/sticky_keys_state.h', 'sticky_keys/sticky_keys_controller.cc', diff --git a/ash/display/display_controller.cc b/ash/display/display_controller.cc index 0530533..35ae9d3 100644 --- a/ash/display/display_controller.cc +++ b/ash/display/display_controller.cc @@ -16,6 +16,7 @@ #include "ash/display/root_window_transformers.h" #include "ash/display/virtual_keyboard_window_controller.h" #include "ash/host/ash_window_tree_host.h" +#include "ash/host/ash_window_tree_host_init_params.h" #include "ash/host/root_window_transformer.h" #include "ash/root_window_controller.h" #include "ash/root_window_settings.h" @@ -273,11 +274,12 @@ void DisplayController::Shutdown() { } } -void DisplayController::CreatePrimaryHost() { +void DisplayController::CreatePrimaryHost( + const AshWindowTreeHostInitParams& init_params) { const gfx::Display& primary_candidate = GetDisplayManager()->GetPrimaryDisplayCandidate(); primary_display_id = primary_candidate.id(); - AddWindowTreeHostForDisplay(primary_candidate); + AddWindowTreeHostForDisplay(primary_candidate, init_params); } void DisplayController::InitDisplays() { @@ -288,7 +290,8 @@ void DisplayController::InitDisplays() { for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { const gfx::Display& display = display_manager->GetDisplayAt(i); if (primary_display_id != display.id()) { - AshWindowTreeHost* ash_host = AddWindowTreeHostForDisplay(display); + AshWindowTreeHost* ash_host = AddWindowTreeHostForDisplay( + display, AshWindowTreeHostInitParams()); RootWindowController::CreateForSecondaryDisplay(ash_host); } } @@ -570,7 +573,8 @@ void DisplayController::OnDisplayAdded(const gfx::Display& display) { if (primary_display_id == gfx::Display::kInvalidDisplayID) primary_display_id = display.id(); DCHECK(!window_tree_hosts_.empty()); - AshWindowTreeHost* ash_host = AddWindowTreeHostForDisplay(display); + AshWindowTreeHost* ash_host = AddWindowTreeHostForDisplay( + display, AshWindowTreeHostInitParams()); RootWindowController::CreateForSecondaryDisplay(ash_host); } } @@ -701,12 +705,14 @@ void DisplayController::PostDisplayConfigurationChange() { } AshWindowTreeHost* DisplayController::AddWindowTreeHostForDisplay( - const gfx::Display& display) { + const gfx::Display& display, + const AshWindowTreeHostInitParams& init_params) { static int host_count = 0; const DisplayInfo& display_info = GetDisplayManager()->GetDisplayInfo(display.id()); - const gfx::Rect& bounds_in_native = display_info.bounds_in_native(); - AshWindowTreeHost* ash_host = AshWindowTreeHost::Create(bounds_in_native); + AshWindowTreeHostInitParams params_with_bounds(init_params); + params_with_bounds.initial_bounds = display_info.bounds_in_native(); + AshWindowTreeHost* ash_host = AshWindowTreeHost::Create(params_with_bounds); aura::WindowTreeHost* host = ash_host->AsWindowTreeHost(); host->window()->SetName(base::StringPrintf("RootWindow-%d", host_count++)); diff --git a/ash/display/display_controller.h b/ash/display/display_controller.h index fb61b84..00c1ac6 100644 --- a/ash/display/display_controller.h +++ b/ash/display/display_controller.h @@ -38,6 +38,7 @@ class Insets; namespace ash { class AshWindowTreeHost; +struct AshWindowTreeHostInitParams; class CursorWindowController; class DisplayInfo; class DisplayManager; @@ -92,8 +93,9 @@ class ASH_EXPORT DisplayController : public gfx::DisplayObserver, return virtual_keyboard_window_controller_.get(); } - // Create a WindowTreeHost for the primary display. - void CreatePrimaryHost(); + // Create a WindowTreeHost for the primary display. This replaces + // |initial_bounds| in |init_params|. + void CreatePrimaryHost(const AshWindowTreeHostInitParams& init_params); // Initializes all displays. void InitDisplays(); @@ -169,7 +171,9 @@ class ASH_EXPORT DisplayController : public gfx::DisplayObserver, // Creates a WindowTreeHost for |display| and stores it in the // |window_tree_hosts_| map. - AshWindowTreeHost* AddWindowTreeHostForDisplay(const gfx::Display& display); + AshWindowTreeHost* AddWindowTreeHostForDisplay( + const gfx::Display& display, + const AshWindowTreeHostInitParams& params); void OnFadeOutForSwapDisplayFinished(); diff --git a/ash/display/mirror_window_controller.cc b/ash/display/mirror_window_controller.cc index 37dcf3b..32d9229 100644 --- a/ash/display/mirror_window_controller.cc +++ b/ash/display/mirror_window_controller.cc @@ -17,6 +17,7 @@ #include "ash/display/display_manager.h" #include "ash/display/root_window_transformers.h" #include "ash/host/ash_window_tree_host.h" +#include "ash/host/ash_window_tree_host_init_params.h" #include "ash/host/root_window_transformer.h" #include "ash/root_window_settings.h" #include "ash/shell.h" @@ -81,8 +82,9 @@ MirrorWindowController::~MirrorWindowController() { void MirrorWindowController::UpdateWindow(const DisplayInfo& display_info) { static int mirror_host_count = 0; if (!ash_host_.get()) { - const gfx::Rect& bounds_in_native = display_info.bounds_in_native(); - ash_host_.reset(AshWindowTreeHost::Create(bounds_in_native)); + AshWindowTreeHostInitParams init_params; + init_params.initial_bounds = display_info.bounds_in_native(); + ash_host_.reset(AshWindowTreeHost::Create(init_params)); aura::WindowTreeHost* host = ash_host_->AsWindowTreeHost(); host->window()->SetName( base::StringPrintf("MirrorRootWindow-%d", mirror_host_count++)); diff --git a/ash/display/virtual_keyboard_window_controller.cc b/ash/display/virtual_keyboard_window_controller.cc index 1cec588..b75854a 100644 --- a/ash/display/virtual_keyboard_window_controller.cc +++ b/ash/display/virtual_keyboard_window_controller.cc @@ -9,6 +9,7 @@ #include "ash/display/display_manager.h" #include "ash/display/root_window_transformers.h" #include "ash/host/ash_window_tree_host.h" +#include "ash/host/ash_window_tree_host_init_params.h" #include "ash/host/root_window_transformer.h" #include "ash/root_window_controller.h" #include "ash/root_window_settings.h" @@ -42,8 +43,9 @@ void VirtualKeyboardWindowController::UpdateWindow( const DisplayInfo& display_info) { static int virtual_keyboard_host_count = 0; if (!root_window_controller_.get()) { - const gfx::Rect& bounds_in_native = display_info.bounds_in_native(); - AshWindowTreeHost* ash_host = AshWindowTreeHost::Create(bounds_in_native); + AshWindowTreeHostInitParams init_params; + init_params.initial_bounds = display_info.bounds_in_native(); + AshWindowTreeHost* ash_host = AshWindowTreeHost::Create(init_params); aura::WindowTreeHost* host = ash_host->AsWindowTreeHost(); host->window()->SetName(base::StringPrintf("VirtualKeyboardRootWindow-%d", diff --git a/ash/host/ash_remote_window_tree_host_win.cc b/ash/host/ash_remote_window_tree_host_win.cc index ff8c8df..67d3aaa 100644 --- a/ash/host/ash_remote_window_tree_host_win.cc +++ b/ash/host/ash_remote_window_tree_host_win.cc @@ -9,32 +9,14 @@ #include "ui/gfx/transform.h" namespace ash { -namespace { -AshRemoteWindowTreeHostWin* g_instance = NULL; -} - -// static -void AshRemoteWindowTreeHostWin::Init() { - DCHECK(!g_instance); - g_instance = new AshRemoteWindowTreeHostWin(); - aura::RemoteWindowTreeHostWin::SetInstance(g_instance); - CHECK_EQ(g_instance, aura::RemoteWindowTreeHostWin::Instance()); -} - -// static -AshRemoteWindowTreeHostWin* AshRemoteWindowTreeHostWin::GetInstance() { - if (!g_instance) - Init(); - CHECK_EQ(g_instance, aura::RemoteWindowTreeHostWin::Instance()); - return g_instance; -} -AshRemoteWindowTreeHostWin::AshRemoteWindowTreeHostWin() - : aura::RemoteWindowTreeHostWin(gfx::Rect()), transformer_helper_(this) { - g_instance = this; +AshRemoteWindowTreeHostWin::AshRemoteWindowTreeHostWin(HWND remote_hwnd) + : aura::RemoteWindowTreeHostWin(), + transformer_helper_(this) { + SetRemoteWindowHandle(remote_hwnd); } -AshRemoteWindowTreeHostWin::~AshRemoteWindowTreeHostWin() { g_instance = NULL; } +AshRemoteWindowTreeHostWin::~AshRemoteWindowTreeHostWin() {} void AshRemoteWindowTreeHostWin::ToggleFullScreen() {} diff --git a/ash/host/ash_remote_window_tree_host_win.h b/ash/host/ash_remote_window_tree_host_win.h index 25cdb34..63017f2d 100644 --- a/ash/host/ash_remote_window_tree_host_win.h +++ b/ash/host/ash_remote_window_tree_host_win.h @@ -5,6 +5,8 @@ #ifndef ASH_HOST_REMOTE_WINDOW_TREE_HOST_WIN_H_ #define ASH_HOST_REMOTE_WINDOW_TREE_HOST_WIN_H_ +#include <windows.h> + #include "ash/ash_export.h" #include "ash/host/ash_window_tree_host.h" #include "ash/host/transformer_helper.h" @@ -16,17 +18,9 @@ class ASH_EXPORT AshRemoteWindowTreeHostWin : public AshWindowTreeHost, public aura::RemoteWindowTreeHostWin { public: - // Creates an instance of AshRemoteWindowTreeHostWin - // and sets it to RemoteWindowTreeHostWin::SetInstance. - static void Init(); - - // Returns the instance created in Init() method above. - // This also performs an extra check if the instance is same - // one that aura::RemoteWindowTreeHostWin::Instance() returns. - static AshRemoteWindowTreeHostWin* GetInstance(); + explicit AshRemoteWindowTreeHostWin(HWND remote_hwnd); private: - AshRemoteWindowTreeHostWin(); virtual ~AshRemoteWindowTreeHostWin(); // AshWindowTreeHost: diff --git a/ash/host/ash_window_tree_host.h b/ash/host/ash_window_tree_host.h index 00626db..1d1513b 100644 --- a/ash/host/ash_window_tree_host.h +++ b/ash/host/ash_window_tree_host.h @@ -19,15 +19,17 @@ class Rect; } namespace ash { +struct AshWindowTreeHostInitParams; class RootWindowTransformer; class ASH_EXPORT AshWindowTreeHost { public: - // Creates a new AshWindowTreeHost. The caller owns the returned value. - static AshWindowTreeHost* Create(const gfx::Rect& initial_bounds); - virtual ~AshWindowTreeHost() {} + // Creates a new AshWindowTreeHost. The caller owns the returned value. + static AshWindowTreeHost* Create( + const AshWindowTreeHostInitParams& init_params); + // Toggles the host's full screen state. virtual void ToggleFullScreen() = 0; diff --git a/ash/host/ash_window_tree_host_init_params.cc b/ash/host/ash_window_tree_host_init_params.cc new file mode 100644 index 0000000..55d15c0 --- /dev/null +++ b/ash/host/ash_window_tree_host_init_params.cc @@ -0,0 +1,19 @@ +// Copyright 2014 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 "ash/host/ash_window_tree_host_init_params.h" + +namespace ash { + +#if defined(OS_WIN) +AshWindowTreeHostInitParams::AshWindowTreeHostInitParams() : remote_hwnd(NULL) { +#else +AshWindowTreeHostInitParams::AshWindowTreeHostInitParams() { +#endif +} + +AshWindowTreeHostInitParams::~AshWindowTreeHostInitParams() { +} + +} // namespace ash diff --git a/ash/host/ash_window_tree_host_init_params.h b/ash/host/ash_window_tree_host_init_params.h new file mode 100644 index 0000000..d9bb7de --- /dev/null +++ b/ash/host/ash_window_tree_host_init_params.h @@ -0,0 +1,32 @@ +// Copyright 2014 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 ASH_HOST_WINDOW_TREE_HOST_INIT_PARAMS_H_ +#define ASH_HOST_WINDOW_TREE_HOST_INIT_PARAMS_H_ + +#include "build/build_config.h" + +#if defined(OS_WIN) +#include <windows.h> +#endif + +#include "ash/ash_export.h" +#include "ui/gfx/geometry/rect.h" + +namespace ash { + +struct ASH_EXPORT AshWindowTreeHostInitParams { + AshWindowTreeHostInitParams(); + ~AshWindowTreeHostInitParams(); + + gfx::Rect initial_bounds; + +#if defined(OS_WIN) + HWND remote_hwnd; +#endif +}; + +} // namespace ash + +#endif // ASH_HOST_WINDOW_TREE_HOST_INIT_PARAMS_H_ diff --git a/ash/host/ash_window_tree_host_ozone.cc b/ash/host/ash_window_tree_host_ozone.cc index 8fe2ba5..5bbf06b 100644 --- a/ash/host/ash_window_tree_host_ozone.cc +++ b/ash/host/ash_window_tree_host_ozone.cc @@ -4,6 +4,7 @@ #include "ash/host/ash_window_tree_host.h" +#include "ash/host/ash_window_tree_host_init_params.h" #include "ash/host/root_window_transformer.h" #include "ash/host/transformer_helper.h" #include "base/command_line.h" @@ -88,8 +89,9 @@ void AshWindowTreeHostOzone::UpdateRootWindowSize(const gfx::Size& host_size) { } // namespace -AshWindowTreeHost* AshWindowTreeHost::Create(const gfx::Rect& initial_bounds) { - return new AshWindowTreeHostOzone(initial_bounds); +AshWindowTreeHost* AshWindowTreeHost::Create( + const AshWindowTreeHostInitParams& init_params) { + return new AshWindowTreeHostOzone(intial_params.initial_bounds); } } // namespace ash diff --git a/ash/host/ash_window_tree_host_win.cc b/ash/host/ash_window_tree_host_win.cc index 642501a..30f98f6 100644 --- a/ash/host/ash_window_tree_host_win.cc +++ b/ash/host/ash_window_tree_host_win.cc @@ -7,6 +7,7 @@ #include "ash/ash_export.h" #include "ash/ash_switches.h" #include "ash/host/ash_remote_window_tree_host_win.h" +#include "ash/host/ash_window_tree_host_init_params.h" #include "ash/host/root_window_transformer.h" #include "ash/host/transformer_helper.h" #include "base/command_line.h" @@ -110,13 +111,14 @@ class ASH_EXPORT AshWindowTreeHostWin : public AshWindowTreeHost, } // namespace -AshWindowTreeHost* AshWindowTreeHost::Create(const gfx::Rect& initial_bounds) { +AshWindowTreeHost* AshWindowTreeHost::Create( + const AshWindowTreeHostInitParams& init_params) { if (base::win::GetVersion() >= base::win::VERSION_WIN7 && !CommandLine::ForCurrentProcess()->HasSwitch( ash::switches::kForceAshToDesktop)) - return AshRemoteWindowTreeHostWin::GetInstance(); + return new AshRemoteWindowTreeHostWin(init_params.remote_hwnd); - return new AshWindowTreeHostWin(initial_bounds); + return new AshWindowTreeHostWin(init_params.initial_bounds); } } // namespace ash diff --git a/ash/host/ash_window_tree_host_x11.cc b/ash/host/ash_window_tree_host_x11.cc index b9f33f1..a050a34 100644 --- a/ash/host/ash_window_tree_host_x11.cc +++ b/ash/host/ash_window_tree_host_x11.cc @@ -12,6 +12,7 @@ #include <string> #include <vector> +#include "ash/host/ash_window_tree_host_init_params.h" #include "ash/host/root_window_transformer.h" #include "base/basictypes.h" #include "base/sys_info.h" @@ -281,8 +282,9 @@ void AshWindowTreeHostX11::SetCrOSTapPaused(bool state) { } } -AshWindowTreeHost* AshWindowTreeHost::Create(const gfx::Rect& initial_bounds) { - return new AshWindowTreeHostX11(initial_bounds); +AshWindowTreeHost* AshWindowTreeHost::Create( + const AshWindowTreeHostInitParams& init_params) { + return new AshWindowTreeHostX11(init_params.initial_bounds); } } // namespace ash diff --git a/ash/shell.cc b/ash/shell.cc index 7c0773f..d2322d8 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -30,6 +30,7 @@ #include "ash/frame/custom_frame_view_ash.h" #include "ash/gpu_support.h" #include "ash/high_contrast/high_contrast_controller.h" +#include "ash/host/ash_window_tree_host_init_params.h" #include "ash/keyboard_uma_event_filter.h" #include "ash/magnifier/magnification_controller.h" #include "ash/magnifier/partial_magnification_controller.h" @@ -47,6 +48,7 @@ #include "ash/shelf/shelf_window_watcher.h" #include "ash/shell_delegate.h" #include "ash/shell_factory.h" +#include "ash/shell_init_params.h" #include "ash/shell_window_ids.h" #include "ash/system/locale/locale_notification_controller.h" #include "ash/system/status_area_widget.h" @@ -163,6 +165,15 @@ class AshVisibilityController : public ::wm::VisibilityController { DISALLOW_COPY_AND_ASSIGN(AshVisibilityController); }; +AshWindowTreeHostInitParams ShellInitParamsToAshWindowTreeHostInitParams( + const ShellInitParams& shell_init_params) { + AshWindowTreeHostInitParams ash_init_params; +#if defined(OS_WIN) + ash_init_params.remote_hwnd = shell_init_params.remote_hwnd; +#endif + return ash_init_params; +} + } // namespace // static @@ -174,10 +185,10 @@ bool Shell::initially_hide_cursor_ = false; // Shell, public: // static -Shell* Shell::CreateInstance(ShellDelegate* delegate) { +Shell* Shell::CreateInstance(const ShellInitParams& init_params) { CHECK(!instance_); - instance_ = new Shell(delegate); - instance_->Init(); + instance_ = new Shell(init_params.delegate); + instance_->Init(init_params); return instance_; } @@ -797,7 +808,7 @@ Shell::~Shell() { instance_ = NULL; } -void Shell::Init() { +void Shell::Init(const ShellInitParams& init_params) { delegate_->PreInit(); if (keyboard::IsKeyboardUsabilityExperimentEnabled()) { display_manager_->SetSecondDisplayMode(DisplayManager::VIRTUAL_KEYBOARD); @@ -858,7 +869,8 @@ void Shell::Init() { screen_position_controller_.reset(new ScreenPositionController); display_controller_->Start(); - display_controller_->CreatePrimaryHost(); + display_controller_->CreatePrimaryHost( + ShellInitParamsToAshWindowTreeHostInitParams(init_params)); aura::Window* root_window = display_controller_->GetPrimaryRootWindow(); target_root_window_ = root_window; diff --git a/ash/shell.h b/ash/shell.h index df906c2..e889131 100644 --- a/ash/shell.h +++ b/ash/shell.h @@ -126,6 +126,7 @@ class ShelfItemDelegateManager; class ShelfModel; class ShelfWindowWatcher; class ShellDelegate; +struct ShellInitParams; class ShellObserver; class SlowAnimationEventFilter; class StatusAreaWidget; @@ -174,7 +175,7 @@ class ASH_EXPORT Shell : public SystemModalContainerEventFilterDelegate, // A shell must be explicitly created so that it can call |Init()| with the // delegate set. |delegate| can be NULL (if not required for initialization). // Takes ownership of |delegate|. - static Shell* CreateInstance(ShellDelegate* delegate); + static Shell* CreateInstance(const ShellInitParams& init_params); // Should never be called before |CreateInstance()|. static Shell* GetInstance(); @@ -581,7 +582,7 @@ class ASH_EXPORT Shell : public SystemModalContainerEventFilterDelegate, explicit Shell(ShellDelegate* delegate); virtual ~Shell(); - void Init(); + void Init(const ShellInitParams& init_params); // Initializes virtual keyboard controller. void InitKeyboard(); diff --git a/ash/shell/content_client/shell_browser_main_parts.cc b/ash/shell/content_client/shell_browser_main_parts.cc index 7223920..8c2a37a 100644 --- a/ash/shell/content_client/shell_browser_main_parts.cc +++ b/ash/shell/content_client/shell_browser_main_parts.cc @@ -9,6 +9,7 @@ #include "ash/shell.h" #include "ash/shell/shell_delegate_impl.h" #include "ash/shell/window_watcher.h" +#include "ash/shell_init_params.h" #include "ash/system/user/login_status.h" #include "base/bind.h" #include "base/command_line.h" @@ -121,7 +122,9 @@ void ShellBrowserMainParts::PreMainMessageLoopRun() { chromeos::CrasAudioHandler::InitializeForTesting(); #endif - ash::Shell::CreateInstance(delegate_); + ash::ShellInitParams init_params; + init_params.delegate = delegate_; + ash::Shell::CreateInstance(init_params); delegate_->set_browser_context(browser_context_.get()); ash::Shell::GetInstance()->CreateShelf(); ash::Shell::GetInstance()->UpdateAfterLoginStatusChange( diff --git a/ash/shell/window_watcher_unittest.cc b/ash/shell/window_watcher_unittest.cc index 90ed407..dd5ea40 100644 --- a/ash/shell/window_watcher_unittest.cc +++ b/ash/shell/window_watcher_unittest.cc @@ -5,8 +5,9 @@ #include "ash/shell/window_watcher.h" #include "ash/shell.h" -#include "ash/shell_delegate.h" #include "ash/shell/shell_delegate_impl.h" +#include "ash/shell_delegate.h" +#include "ash/shell_init_params.h" #include "ash/system/user/login_status.h" #include "ash/test/ash_test_base.h" #include "ui/aura/window_tree_host.h" @@ -23,7 +24,9 @@ TEST_F(WindowWatcherTest, ShellDeleteInstance) { Shell::DeleteInstance(); shell::ShellDelegateImpl* delegate = new ash::shell::ShellDelegateImpl; - Shell::CreateInstance(delegate); + ash::ShellInitParams init_params; + init_params.delegate = delegate; + Shell::CreateInstance(init_params); Shell::GetPrimaryRootWindow()->GetHost()->Show(); Shell::GetInstance()->CreateShelf(); Shell::GetInstance()->UpdateAfterLoginStatusChange( diff --git a/ash/shell_init_params.cc b/ash/shell_init_params.cc new file mode 100644 index 0000000..87e5be8 --- /dev/null +++ b/ash/shell_init_params.cc @@ -0,0 +1,19 @@ +// Copyright 2014 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 "ash/shell_init_params.h" + +#include "ash/shell_delegate.h" + +namespace ash { + +#if defined(OS_WIN) +ShellInitParams::ShellInitParams() : delegate(NULL), remote_hwnd(NULL) {} +#else +ShellInitParams::ShellInitParams() : delegate(NULL) {} +#endif + +ShellInitParams::~ShellInitParams() {} + +} // namespace ash diff --git a/ash/shell_init_params.h b/ash/shell_init_params.h new file mode 100644 index 0000000..52b894e --- /dev/null +++ b/ash/shell_init_params.h @@ -0,0 +1,33 @@ +// Copyright 2014 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 ASH_SHELL_INIT_PARAMS_H_ +#define ASH_SHELL_INIT_PARAMS_H_ + +#include "build/build_config.h" + +#if defined(OS_WIN) +#include <windows.h> +#endif + +#include "ash/ash_export.h" + +namespace ash { + +class ShellDelegate; + +struct ASH_EXPORT ShellInitParams { + ShellInitParams(); + ~ShellInitParams(); + + ShellDelegate* delegate; + +#if defined(OS_WIN) + HWND remote_hwnd; +#endif +}; + +} // namespace ash + +#endif // ASH_SHELL_INIT_PARAMS_H_ diff --git a/ash/test/ash_test_helper.cc b/ash/test/ash_test_helper.cc index a59019b..3dd9455 100644 --- a/ash/test/ash_test_helper.cc +++ b/ash/test/ash_test_helper.cc @@ -7,6 +7,7 @@ #include "ash/accelerators/accelerator_controller.h" #include "ash/ash_switches.h" #include "ash/shell.h" +#include "ash/shell_init_params.h" #include "ash/test/ash_test_views_delegate.h" #include "ash/test/display_manager_test_api.h" #include "ash/test/shell_test_api.h" @@ -84,7 +85,9 @@ void AshTestHelper::SetUp(bool start_session) { // created in AshTestBase tests. chromeos::CrasAudioHandler::InitializeForTesting(); #endif - ash::Shell::CreateInstance(test_shell_delegate_); + ShellInitParams init_params; + init_params.delegate = test_shell_delegate_; + ash::Shell::CreateInstance(init_params); aura::test::EnvTestHelper(aura::Env::GetInstance()).SetInputStateLookup( scoped_ptr<aura::InputStateLookup>()); diff --git a/ash/test/test_metro_viewer_process_host.cc b/ash/test/test_metro_viewer_process_host.cc index 5dd448c..85df3e2 100644 --- a/ash/test/test_metro_viewer_process_host.cc +++ b/ash/test/test_metro_viewer_process_host.cc @@ -8,13 +8,15 @@ #include "base/logging.h" #include "ui/aura/remote_window_tree_host_win.h" +#include "ui/gfx/win/dpi.h" namespace ash { namespace test { TestMetroViewerProcessHost::TestMetroViewerProcessHost( base::SingleThreadTaskRunner* ipc_task_runner) - : MetroViewerProcessHost(ipc_task_runner), closed_unexpectedly_(false) { + : MetroViewerProcessHost(ipc_task_runner), + closed_unexpectedly_(false) { } TestMetroViewerProcessHost::~TestMetroViewerProcessHost() { @@ -30,8 +32,8 @@ void TestMetroViewerProcessHost::OnSetTargetSurface( float device_scale) { DLOG(INFO) << __FUNCTION__ << ", target_surface = " << target_surface; HWND hwnd = reinterpret_cast<HWND>(target_surface); - aura::RemoteWindowTreeHostWin::Instance()-> - InitializeRemoteWindowAndScaleFactor(hwnd, device_scale); + gfx::InitDeviceScaleFactor(device_scale); + aura::RemoteWindowTreeHostWin::Instance()->SetRemoteWindowHandle(hwnd); aura::RemoteWindowTreeHostWin::Instance()->Connected(this); } diff --git a/chrome/browser/metro_viewer/chrome_metro_viewer_process_host_aurawin.cc b/chrome/browser/metro_viewer/chrome_metro_viewer_process_host_aurawin.cc index 374f300..277a5aa 100644 --- a/chrome/browser/metro_viewer/chrome_metro_viewer_process_host_aurawin.cc +++ b/chrome/browser/metro_viewer/chrome_metro_viewer_process_host_aurawin.cc @@ -120,14 +120,10 @@ void ChromeMetroViewerProcessHost::OnSetTargetSurface( float device_scale) { HWND hwnd = reinterpret_cast<HWND>(target_surface); - // Make hwnd available as early as possible for proper InputMethod - // initialization. - ash::AshRemoteWindowTreeHostWin::Init(); - aura::RemoteWindowTreeHostWin::Instance()-> - InitializeRemoteWindowAndScaleFactor(hwnd, device_scale); - - // Now start the Ash shell environment. - chrome::OpenAsh(); + gfx::InitDeviceScaleFactor(device_scale); + chrome::OpenAsh(hwnd); + DCHECK(aura::RemoteWindowTreeHostWin::Instance()); + DCHECK_EQ(hwnd, aura::RemoteWindowTreeHostWin::Instance()->remote_window()); ash::Shell::GetInstance()->CreateShelf(); ash::Shell::GetInstance()->ShowShelf(); diff --git a/chrome/browser/ui/ash/ash_init.cc b/chrome/browser/ui/ash/ash_init.cc index c3a8b51..06ab94e 100644 --- a/chrome/browser/ui/ash/ash_init.cc +++ b/chrome/browser/ui/ash/ash_init.cc @@ -11,6 +11,7 @@ #include "ash/magnifier/magnification_controller.h" #include "ash/magnifier/partial_magnification_controller.h" #include "ash/shell.h" +#include "ash/shell_init_params.h" #include "base/command_line.h" #include "chrome/browser/browser_shutdown.h" #include "chrome/browser/lifetime/application_lifetime.h" @@ -42,7 +43,7 @@ bool ShouldOpenAshOnStartup() { return CommandLine::ForCurrentProcess()->HasSwitch(switches::kOpenAsh); } -void OpenAsh() { +void OpenAsh(gfx::AcceleratedWidget remote_window) { #if defined(OS_CHROMEOS) #if defined(USE_X11) if (base::SysInfo::IsRunningOnChromeOS()) { @@ -58,8 +59,14 @@ void OpenAsh() { ash::Shell::set_initially_hide_cursor(true); #endif + ash::ShellInitParams shell_init_params; // Shell takes ownership of ChromeShellDelegate. - ash::Shell* shell = ash::Shell::CreateInstance(new ChromeShellDelegate); + shell_init_params.delegate = new ChromeShellDelegate; +#if defined(OS_WIN) + shell_init_params.remote_hwnd = remote_window; +#endif + + ash::Shell* shell = ash::Shell::CreateInstance(shell_init_params); shell->accelerator_controller()->SetScreenshotDelegate( scoped_ptr<ash::ScreenshotDelegate>(new ScreenshotTaker).Pass()); // TODO(flackr): Investigate exposing a blocking pool task runner to chromeos. diff --git a/chrome/browser/ui/ash/ash_init.h b/chrome/browser/ui/ash/ash_init.h index 6ed1a0f..b1141bd 100644 --- a/chrome/browser/ui/ash/ash_init.h +++ b/chrome/browser/ui/ash/ash_init.h @@ -5,13 +5,16 @@ #ifndef CHROME_BROWSER_UI_ASH_ASH_INIT_H_ #define CHROME_BROWSER_UI_ASH_ASH_INIT_H_ +#include "ui/gfx/native_widget_types.h" + namespace chrome { // Returns true if Ash should be run at startup. bool ShouldOpenAshOnStartup(); -// Creates the Ash Shell and opens the Ash window. -void OpenAsh(); +// Creates the Ash Shell and opens the Ash window. |remote_window| is only used +// on windows. It provides the HWND to the remote window. +void OpenAsh(gfx::AcceleratedWidget remote_window); // Closes the Ash window and destroys the Ash Shell. void CloseAsh(); diff --git a/chrome/browser/ui/ash/ash_util.cc b/chrome/browser/ui/ash/ash_util.cc index 0b3bdcc..f2670de 100644 --- a/chrome/browser/ui/ash/ash_util.cc +++ b/chrome/browser/ui/ash/ash_util.cc @@ -41,7 +41,7 @@ void ToggleAshDesktop() { return; if (!ash::Shell::HasInstance()) - OpenAsh(); + OpenAsh(gfx::kNullAcceleratedWidget); else CloseAsh(); } diff --git a/chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.cc b/chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.cc index 6b858b7..f1c3b62 100644 --- a/chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.cc +++ b/chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.cc @@ -67,7 +67,7 @@ ChromeBrowserMainExtraPartsAsh::~ChromeBrowserMainExtraPartsAsh() { void ChromeBrowserMainExtraPartsAsh::PreProfileInit() { if (chrome::ShouldOpenAshOnStartup()) { - chrome::OpenAsh(); + chrome::OpenAsh(gfx::kNullAcceleratedWidget); } else { #if !defined(OS_CHROMEOS) gfx::Screen::SetScreenTypeDelegate(new ScreenTypeDelegateWin); diff --git a/chrome/test/base/view_event_test_base.cc b/chrome/test/base/view_event_test_base.cc index bdba76a..2d64c5d 100644 --- a/chrome/test/base/view_event_test_base.cc +++ b/chrome/test/base/view_event_test_base.cc @@ -29,6 +29,7 @@ #if defined(USE_ASH) #include "ash/shell.h" +#include "ash/shell_init_params.h" #include "ash/test/test_session_state_delegate.h" #include "ash/test/test_shell_delegate.h" #endif @@ -128,7 +129,9 @@ void ViewEventTestBase::SetUp() { #endif // OS_CHROMEOS ash::test::TestShellDelegate* shell_delegate = new ash::test::TestShellDelegate(); - ash::Shell::CreateInstance(shell_delegate); + ash::ShellInitParams init_params; + init_params.delegate = shell_delegate; + ash::Shell::CreateInstance(init_params); shell_delegate->test_session_state_delegate() ->SetActiveUserSessionStarted(true); context = ash::Shell::GetPrimaryRootWindow(); diff --git a/ui/aura/remote_window_tree_host_win.cc b/ui/aura/remote_window_tree_host_win.cc index 31aa551..2dbc0e7 100644 --- a/ui/aura/remote_window_tree_host_win.cc +++ b/ui/aura/remote_window_tree_host_win.cc @@ -151,23 +151,17 @@ RemoteWindowTreeHostWin* g_instance = NULL; // static RemoteWindowTreeHostWin* RemoteWindowTreeHostWin::Instance() { - if (!g_instance) - g_instance = new RemoteWindowTreeHostWin(gfx::Rect()); return g_instance; } -// static -void RemoteWindowTreeHostWin::SetInstance(RemoteWindowTreeHostWin* instance) { - CHECK(!g_instance); - g_instance = instance; -} - -RemoteWindowTreeHostWin::RemoteWindowTreeHostWin(const gfx::Rect& bounds) +RemoteWindowTreeHostWin::RemoteWindowTreeHostWin() : remote_window_(NULL), host_(NULL), ignore_mouse_moves_until_set_cursor_ack_(false), event_flags_(0), window_size_(aura::WindowTreeHost::GetNativeScreenSize()) { + CHECK(!g_instance); + g_instance = this; prop_.reset(new ui::ViewProp(NULL, kWindowTreeHostWinKey, this)); CreateCompositor(GetAcceleratedWidget()); } @@ -175,6 +169,7 @@ RemoteWindowTreeHostWin::RemoteWindowTreeHostWin(const gfx::Rect& bounds) RemoteWindowTreeHostWin::~RemoteWindowTreeHostWin() { DestroyCompositor(); DestroyDispatcher(); + DCHECK_EQ(g_instance, this); g_instance = NULL; } @@ -183,13 +178,8 @@ bool RemoteWindowTreeHostWin::IsValid() { return Instance()->remote_window_ != NULL; } -void RemoteWindowTreeHostWin::InitializeRemoteWindowAndScaleFactor( - HWND remote_window, - float device_scale) { +void RemoteWindowTreeHostWin::SetRemoteWindowHandle(HWND remote_window) { remote_window_ = remote_window; - gfx::InitDeviceScaleFactor(device_scale); - // Do not create compositor here, but in Connected() below. - // See http://crbug.com/330179 and http://crbug.com/334380. } void RemoteWindowTreeHostWin::Connected(IPC::Sender* host) { diff --git a/ui/aura/remote_window_tree_host_win.h b/ui/aura/remote_window_tree_host_win.h index 0ff913e..9cc7439 100644 --- a/ui/aura/remote_window_tree_host_win.h +++ b/ui/aura/remote_window_tree_host_win.h @@ -106,27 +106,19 @@ class AURA_EXPORT RemoteWindowTreeHostWin public ui::EventSource, public ui::internal::RemoteInputMethodDelegateWin { public: - // Returns the only RemoteWindowTreeHostWin, if this is the first time - // this function is called and the instance have never set by SetInstance, - // it will call Create() wiht empty bounds. + // Returns the current RemoteWindowTreeHostWin. This does *not* create a + // RemoteWindowTreeHostWin. static RemoteWindowTreeHostWin* Instance(); - // Manually sets the instance to be used as a return value of |Instance()| - // method above. This should not be called if the instance has already - // been set or created, and doing so will result in CHECK failure. - static void SetInstance(RemoteWindowTreeHostWin* instance); - // Returns true if there is a RemoteWindowTreeHostWin and it has a valid // HWND. A return value of false typically indicates we're not in metro mode. static bool IsValid(); - // Sets the handle to the remote window and the scale factor. The - // |remote_window| is the actual window owned by the viewer process. Call - // this before Connected() for some customers like input method - // initialization which needs the handle. - // |device_scale| indicates the Windows 8 dpi scale. - void InitializeRemoteWindowAndScaleFactor(HWND remote_window, - float device_scale); + // Sets the handle to the remote window. The |remote_window| is the actual + // window owned by the viewer process. Call this before Connected() for some + // customers like input method initialization which needs the handle. + void SetRemoteWindowHandle(HWND remote_window); + HWND remote_window() { return remote_window_; } // The |host| can be used when we need to send a message to it. void Connected(IPC::Sender* host); @@ -180,7 +172,7 @@ class AURA_EXPORT RemoteWindowTreeHostWin bool IsForegroundWindow(); protected: - explicit RemoteWindowTreeHostWin(const gfx::Rect& bounds); + RemoteWindowTreeHostWin(); virtual ~RemoteWindowTreeHostWin(); private: |