Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / ash / host / ash_window_tree_host_win.cc
blobe69769ca6a55fe8e3f789ad0bfb5c5252ccd98e4
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/events/event_processor.h"
18 #include "ui/gfx/geometry/insets.h"
19 #include "ui/gfx/transform.h"
21 namespace ash {
22 namespace {
24 class AshWindowTreeHostWin : public AshWindowTreeHost,
25 public aura::WindowTreeHostWin {
26 public:
27 explicit AshWindowTreeHostWin(const gfx::Rect& initial_bounds)
28 : aura::WindowTreeHostWin(initial_bounds),
29 fullscreen_(false),
30 saved_window_style_(0),
31 saved_window_ex_style_(0),
32 transformer_helper_(this) {
33 transformer_helper_.Init();
35 ~AshWindowTreeHostWin() override {}
37 private:
38 // AshWindowTreeHost:
39 void ToggleFullScreen() override {
40 gfx::Rect target_rect;
41 if (!fullscreen_) {
42 fullscreen_ = true;
43 saved_window_style_ = GetWindowLong(hwnd(), GWL_STYLE);
44 saved_window_ex_style_ = GetWindowLong(hwnd(), GWL_EXSTYLE);
45 GetWindowRect(hwnd(), &saved_window_rect_);
46 SetWindowLong(hwnd(),
47 GWL_STYLE,
48 saved_window_style_ & ~(WS_CAPTION | WS_THICKFRAME));
49 SetWindowLong(
50 hwnd(),
51 GWL_EXSTYLE,
52 saved_window_ex_style_ & ~(WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE |
53 WS_EX_CLIENTEDGE | WS_EX_STATICEDGE));
55 MONITORINFO mi;
56 mi.cbSize = sizeof(mi);
57 GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTONEAREST), &mi);
58 target_rect = gfx::Rect(mi.rcMonitor);
59 } else {
60 fullscreen_ = false;
61 SetWindowLong(hwnd(), GWL_STYLE, saved_window_style_);
62 SetWindowLong(hwnd(), GWL_EXSTYLE, saved_window_ex_style_);
63 target_rect = gfx::Rect(saved_window_rect_);
65 SetWindowPos(hwnd(),
66 NULL,
67 target_rect.x(),
68 target_rect.y(),
69 target_rect.width(),
70 target_rect.height(),
71 SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
73 bool ConfineCursorToRootWindow() override { return false; }
74 void UnConfineCursor() override { NOTIMPLEMENTED(); }
75 void SetRootWindowTransformer(
76 scoped_ptr<RootWindowTransformer> transformer) override {
77 transformer_helper_.SetRootWindowTransformer(transformer.Pass());
79 gfx::Insets GetHostInsets() const override {
80 return transformer_helper_.GetHostInsets();
82 aura::WindowTreeHost* AsWindowTreeHost() override { return this; }
84 // WindowTreeHostWin:
85 void SetBounds(const gfx::Rect& bounds) override {
86 if (fullscreen_) {
87 saved_window_rect_.right = saved_window_rect_.left + bounds.width();
88 saved_window_rect_.bottom = saved_window_rect_.top + bounds.height();
89 return;
91 WindowTreeHostWin::SetBounds(bounds);
93 void SetRootTransform(const gfx::Transform& transform) override {
94 transformer_helper_.SetTransform(transform);
96 gfx::Transform GetRootTransform() const override {
97 return transformer_helper_.GetTransform();
99 gfx::Transform GetInverseRootTransform() const override {
100 return transformer_helper_.GetInverseTransform();
102 void UpdateRootWindowSize(const gfx::Size& host_size) override {
103 transformer_helper_.UpdateWindowSize(host_size);
106 // ui::internal::InputMethodDelegate:
107 ui::EventDispatchDetails DispatchKeyEventPostIME(
108 ui::KeyEvent* event) override {
109 input_method_handler()->SetPostIME(true);
110 ui::EventDispatchDetails details =
111 event_processor()->OnEventFromSource(event);
112 if (!details.dispatcher_destroyed)
113 input_method_handler()->SetPostIME(false);
114 return details;
117 bool fullscreen_;
118 RECT saved_window_rect_;
119 DWORD saved_window_style_;
120 DWORD saved_window_ex_style_;
122 TransformerHelper transformer_helper_;
124 DISALLOW_COPY_AND_ASSIGN(AshWindowTreeHostWin);
127 } // namespace
129 AshWindowTreeHost* AshWindowTreeHost::Create(
130 const AshWindowTreeHostInitParams& init_params) {
131 if (base::win::GetVersion() >= base::win::VERSION_WIN7 &&
132 !base::CommandLine::ForCurrentProcess()->HasSwitch(
133 ash::switches::kForceAshToDesktop))
134 return new AshRemoteWindowTreeHostWin(init_params.remote_hwnd);
136 return new AshWindowTreeHostWin(init_params.initial_bounds);
139 } // namespace ash