1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ash/host/ash_window_tree_host.h"
7 #include "ash/ash_export.h"
8 #include "ash/ash_switches.h"
9 #include "ash/host/ash_remote_window_tree_host_win.h"
10 #include "ash/host/ash_window_tree_host_init_params.h"
11 #include "ash/host/root_window_transformer.h"
12 #include "ash/host/transformer_helper.h"
13 #include "base/command_line.h"
14 #include "base/win/windows_version.h"
15 #include "ui/aura/window_tree_host_win.h"
16 #include "ui/gfx/geometry/insets.h"
17 #include "ui/gfx/transform.h"
22 class AshWindowTreeHostWin
: public AshWindowTreeHost
,
23 public aura::WindowTreeHostWin
{
25 explicit AshWindowTreeHostWin(const gfx::Rect
& initial_bounds
)
26 : aura::WindowTreeHostWin(initial_bounds
),
28 saved_window_style_(0),
29 saved_window_ex_style_(0),
30 transformer_helper_(this) {}
31 virtual ~AshWindowTreeHostWin() {}
35 virtual void ToggleFullScreen() override
{
36 gfx::Rect target_rect
;
39 saved_window_style_
= GetWindowLong(hwnd(), GWL_STYLE
);
40 saved_window_ex_style_
= GetWindowLong(hwnd(), GWL_EXSTYLE
);
41 GetWindowRect(hwnd(), &saved_window_rect_
);
44 saved_window_style_
& ~(WS_CAPTION
| WS_THICKFRAME
));
48 saved_window_ex_style_
& ~(WS_EX_DLGMODALFRAME
| WS_EX_WINDOWEDGE
|
49 WS_EX_CLIENTEDGE
| WS_EX_STATICEDGE
));
52 mi
.cbSize
= sizeof(mi
);
53 GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTONEAREST
), &mi
);
54 target_rect
= gfx::Rect(mi
.rcMonitor
);
57 SetWindowLong(hwnd(), GWL_STYLE
, saved_window_style_
);
58 SetWindowLong(hwnd(), GWL_EXSTYLE
, saved_window_ex_style_
);
59 target_rect
= gfx::Rect(saved_window_rect_
);
67 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_FRAMECHANGED
);
69 virtual bool ConfineCursorToRootWindow() override
{ return false; }
70 virtual void UnConfineCursor() override
{ NOTIMPLEMENTED(); }
71 virtual void SetRootWindowTransformer(
72 scoped_ptr
<RootWindowTransformer
> transformer
) {
73 transformer_helper_
.SetRootWindowTransformer(transformer
.Pass());
75 virtual gfx::Insets
GetHostInsets() const override
{
76 return transformer_helper_
.GetHostInsets();
78 virtual aura::WindowTreeHost
* AsWindowTreeHost() override
{ return this; }
81 virtual void SetBounds(const gfx::Rect
& bounds
) override
{
83 saved_window_rect_
.right
= saved_window_rect_
.left
+ bounds
.width();
84 saved_window_rect_
.bottom
= saved_window_rect_
.top
+ bounds
.height();
87 WindowTreeHostWin::SetBounds(bounds
);
89 virtual void SetRootTransform(const gfx::Transform
& transform
) override
{
90 transformer_helper_
.SetTransform(transform
);
92 gfx::Transform
GetRootTransform() const {
93 return transformer_helper_
.GetTransform();
95 virtual gfx::Transform
GetInverseRootTransform() const override
{
96 return transformer_helper_
.GetInverseTransform();
98 virtual void UpdateRootWindowSize(const gfx::Size
& host_size
) override
{
99 transformer_helper_
.UpdateWindowSize(host_size
);
103 RECT saved_window_rect_
;
104 DWORD saved_window_style_
;
105 DWORD saved_window_ex_style_
;
107 TransformerHelper transformer_helper_
;
109 DISALLOW_COPY_AND_ASSIGN(AshWindowTreeHostWin
);
114 AshWindowTreeHost
* AshWindowTreeHost::Create(
115 const AshWindowTreeHostInitParams
& init_params
) {
116 if (base::win::GetVersion() >= base::win::VERSION_WIN7
&&
117 !base::CommandLine::ForCurrentProcess()->HasSwitch(
118 ash::switches::kForceAshToDesktop
))
119 return new AshRemoteWindowTreeHostWin(init_params
.remote_hwnd
);
121 return new AshWindowTreeHostWin(init_params
.initial_bounds
);