Skip to content

Commit

Permalink
Makes construction of (ash)RemoteWindowTreeHostWin explicit
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sky@chromium.org committed May 15, 2014
1 parent 9eab79b commit 1b4c747
Show file tree
Hide file tree
Showing 31 changed files with 240 additions and 117 deletions.
3 changes: 3 additions & 0 deletions ash/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
Expand Down
2 changes: 1 addition & 1 deletion ash/accessibility_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,4 @@ class ASH_EXPORT AccessibilityDelegate {

} // namespace ash

#endif // ASH_ACCESSIBILITYDELEGATE_H_
#endif // ASH_ACCESSIBILITY_DELEGATE_H_
4 changes: 4 additions & 0 deletions ash/ash.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
20 changes: 13 additions & 7 deletions ash/display/display_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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() {
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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++));
Expand Down
10 changes: 7 additions & 3 deletions ash/display/display_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Insets;

namespace ash {
class AshWindowTreeHost;
struct AshWindowTreeHostInitParams;
class CursorWindowController;
class DisplayInfo;
class DisplayManager;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();

Expand Down
6 changes: 4 additions & 2 deletions ash/display/mirror_window_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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++));
Expand Down
6 changes: 4 additions & 2 deletions ash/display/virtual_keyboard_window_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down
28 changes: 5 additions & 23 deletions ash/host/ash_remote_window_tree_host_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}

Expand Down
12 changes: 3 additions & 9 deletions ash/host/ash_remote_window_tree_host_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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:
Expand Down
8 changes: 5 additions & 3 deletions ash/host/ash_window_tree_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
19 changes: 19 additions & 0 deletions ash/host/ash_window_tree_host_init_params.cc
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions ash/host/ash_window_tree_host_init_params.h
Original file line number Diff line number Diff line change
@@ -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_
6 changes: 4 additions & 2 deletions ash/host/ash_window_tree_host_ozone.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
8 changes: 5 additions & 3 deletions ash/host/ash_window_tree_host_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
6 changes: 4 additions & 2 deletions ash/host/ash_window_tree_host_x11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Loading

0 comments on commit 1b4c747

Please sign in to comment.