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 "ash/ime/input_method_event_handler.h"
14 #include "base/command_line.h"
15 #include "base/win/windows_version.h"
16 #include "ui/aura/window_tree_host_win.h"
17 #include "ui/gfx/geometry/insets.h"
18 #include "ui/gfx/transform.h"
23 class AshWindowTreeHostWin
: public AshWindowTreeHost
,
24 public aura::WindowTreeHostWin
{
26 explicit AshWindowTreeHostWin(const gfx::Rect
& initial_bounds
)
27 : aura::WindowTreeHostWin(initial_bounds
),
29 saved_window_style_(0),
30 saved_window_ex_style_(0),
31 transformer_helper_(this) {
32 transformer_helper_
.Init();
34 ~AshWindowTreeHostWin() override
{}
38 void ToggleFullScreen() override
{
39 gfx::Rect target_rect
;
42 saved_window_style_
= GetWindowLong(hwnd(), GWL_STYLE
);
43 saved_window_ex_style_
= GetWindowLong(hwnd(), GWL_EXSTYLE
);
44 GetWindowRect(hwnd(), &saved_window_rect_
);
47 saved_window_style_
& ~(WS_CAPTION
| WS_THICKFRAME
));
51 saved_window_ex_style_
& ~(WS_EX_DLGMODALFRAME
| WS_EX_WINDOWEDGE
|
52 WS_EX_CLIENTEDGE
| WS_EX_STATICEDGE
));
55 mi
.cbSize
= sizeof(mi
);
56 GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTONEAREST
), &mi
);
57 target_rect
= gfx::Rect(mi
.rcMonitor
);
60 SetWindowLong(hwnd(), GWL_STYLE
, saved_window_style_
);
61 SetWindowLong(hwnd(), GWL_EXSTYLE
, saved_window_ex_style_
);
62 target_rect
= gfx::Rect(saved_window_rect_
);
70 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_FRAMECHANGED
);
72 bool ConfineCursorToRootWindow() override
{ return false; }
73 void UnConfineCursor() override
{ NOTIMPLEMENTED(); }
74 void SetRootWindowTransformer(
75 scoped_ptr
<RootWindowTransformer
> transformer
) override
{
76 transformer_helper_
.SetRootWindowTransformer(transformer
.Pass());
78 gfx::Insets
GetHostInsets() const override
{
79 return transformer_helper_
.GetHostInsets();
81 aura::WindowTreeHost
* AsWindowTreeHost() override
{ return this; }
84 void SetBounds(const gfx::Rect
& bounds
) override
{
86 saved_window_rect_
.right
= saved_window_rect_
.left
+ bounds
.width();
87 saved_window_rect_
.bottom
= saved_window_rect_
.top
+ bounds
.height();
90 WindowTreeHostWin::SetBounds(bounds
);
92 void SetRootTransform(const gfx::Transform
& transform
) override
{
93 transformer_helper_
.SetTransform(transform
);
95 gfx::Transform
GetRootTransform() const override
{
96 return transformer_helper_
.GetTransform();
98 gfx::Transform
GetInverseRootTransform() const override
{
99 return transformer_helper_
.GetInverseTransform();
101 void UpdateRootWindowSize(const gfx::Size
& host_size
) override
{
102 transformer_helper_
.UpdateWindowSize(host_size
);
105 // ui::internal::InputMethodDelegate:
106 bool DispatchKeyEventPostIME(const ui::KeyEvent
& event
) override
{
107 ui::KeyEvent
event_copy(event
);
108 input_method_handler()->SetPostIME(true);
109 ui::EventSource::DeliverEventToProcessor(&event_copy
);
110 input_method_handler()->SetPostIME(false);
111 return event_copy
.handled();
115 ui::EventDispatchDetails
DeliverEventToProcessor(ui::Event
* event
) override
{
116 return ui::EventSource::DeliverEventToProcessor(event
);
120 RECT saved_window_rect_
;
121 DWORD saved_window_style_
;
122 DWORD saved_window_ex_style_
;
124 TransformerHelper transformer_helper_
;
126 DISALLOW_COPY_AND_ASSIGN(AshWindowTreeHostWin
);
131 AshWindowTreeHost
* AshWindowTreeHost::Create(
132 const AshWindowTreeHostInitParams
& init_params
) {
133 if (base::win::GetVersion() >= base::win::VERSION_WIN7
&&
134 !base::CommandLine::ForCurrentProcess()->HasSwitch(
135 ash::switches::kForceAshToDesktop
))
136 return new AshRemoteWindowTreeHostWin(init_params
.remote_hwnd
);
138 return new AshWindowTreeHostWin(init_params
.initial_bounds
);