OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "ash/host/ash_window_tree_host.h" |
| 6 |
| 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/root_window_transformer.h" |
| 11 #include "ash/host/transformer_helper.h" |
| 12 #include "base/command_line.h" |
| 13 #include "base/win/windows_version.h" |
| 14 #include "ui/aura/window_tree_host_win.h" |
| 15 #include "ui/gfx/geometry/insets.h" |
| 16 #include "ui/gfx/transform.h" |
| 17 |
| 18 namespace ash { |
| 19 namespace { |
| 20 |
| 21 class ASH_EXPORT AshWindowTreeHostWin : public AshWindowTreeHost, |
| 22 public aura::WindowTreeHostWin { |
| 23 public: |
| 24 explicit AshWindowTreeHostWin(const gfx::Rect& initial_bounds) |
| 25 : aura::WindowTreeHostWin(initial_bounds), |
| 26 fullscreen_(false), |
| 27 saved_window_style_(0), |
| 28 saved_window_ex_style_(0), |
| 29 transformer_helper_(this) {} |
| 30 virtual ~AshWindowTreeHostWin() {} |
| 31 |
| 32 private: |
| 33 // AshWindowTreeHost: |
| 34 virtual void ToggleFullScreen() OVERRIDE { |
| 35 gfx::Rect target_rect; |
| 36 if (!fullscreen_) { |
| 37 fullscreen_ = true; |
| 38 saved_window_style_ = GetWindowLong(hwnd(), GWL_STYLE); |
| 39 saved_window_ex_style_ = GetWindowLong(hwnd(), GWL_EXSTYLE); |
| 40 GetWindowRect(hwnd(), &saved_window_rect_); |
| 41 SetWindowLong(hwnd(), |
| 42 GWL_STYLE, |
| 43 saved_window_style_ & ~(WS_CAPTION | WS_THICKFRAME)); |
| 44 SetWindowLong( |
| 45 hwnd(), |
| 46 GWL_EXSTYLE, |
| 47 saved_window_ex_style_ & ~(WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE | |
| 48 WS_EX_CLIENTEDGE | WS_EX_STATICEDGE)); |
| 49 |
| 50 MONITORINFO mi; |
| 51 mi.cbSize = sizeof(mi); |
| 52 GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTONEAREST), &mi); |
| 53 target_rect = gfx::Rect(mi.rcMonitor); |
| 54 } else { |
| 55 fullscreen_ = false; |
| 56 SetWindowLong(hwnd(), GWL_STYLE, saved_window_style_); |
| 57 SetWindowLong(hwnd(), GWL_EXSTYLE, saved_window_ex_style_); |
| 58 target_rect = gfx::Rect(saved_window_rect_); |
| 59 } |
| 60 SetWindowPos(hwnd(), |
| 61 NULL, |
| 62 target_rect.x(), |
| 63 target_rect.y(), |
| 64 target_rect.width(), |
| 65 target_rect.height(), |
| 66 SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED); |
| 67 } |
| 68 virtual bool ConfineCursorToRootWindow() OVERRIDE { return false; } |
| 69 virtual void UnConfineCursor() OVERRIDE { NOTIMPLEMENTED(); } |
| 70 virtual void SetRootWindowTransformer( |
| 71 scoped_ptr<RootWindowTransformer> transformer) { |
| 72 transformer_helper_.SetRootWindowTransformer(transformer.Pass()); |
| 73 } |
| 74 virtual aura::WindowTreeHost* AsWindowTreeHost() OVERRIDE { return this; } |
| 75 |
| 76 // WindowTreeHostWin: |
| 77 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE { |
| 78 if (fullscreen_) { |
| 79 saved_window_rect_.right = saved_window_rect_.left + bounds.width(); |
| 80 saved_window_rect_.bottom = saved_window_rect_.top + bounds.height(); |
| 81 return; |
| 82 } |
| 83 WindowTreeHostWin::SetBounds(bounds); |
| 84 } |
| 85 virtual void SetRootTransform(const gfx::Transform& transform) OVERRIDE { |
| 86 transformer_helper_.SetTransform(transform); |
| 87 } |
| 88 gfx::Transform GetRootTransform() const { |
| 89 return transformer_helper_.GetTransform(); |
| 90 } |
| 91 virtual gfx::Transform GetInverseRootTransform() const OVERRIDE { |
| 92 return transformer_helper_.GetInverseTransform(); |
| 93 } |
| 94 virtual void UpdateRootWindowSize(const gfx::Size& host_size) OVERRIDE { |
| 95 transformer_helper_.UpdateWindowSize(host_size); |
| 96 } |
| 97 |
| 98 bool fullscreen_; |
| 99 RECT saved_window_rect_; |
| 100 DWORD saved_window_style_; |
| 101 DWORD saved_window_ex_style_; |
| 102 |
| 103 TransformerHelper transformer_helper_; |
| 104 |
| 105 DISALLOW_COPY_AND_ASSIGN(AshWindowTreeHostWin); |
| 106 }; |
| 107 |
| 108 } // namespace |
| 109 |
| 110 AshWindowTreeHost* AshWindowTreeHost::Create(const gfx::Rect& initial_bounds) { |
| 111 if (base::win::GetVersion() >= base::win::VERSION_WIN8 && |
| 112 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 113 ash::switches::kForceAshToDesktop)) |
| 114 return AshRemoteWindowTreeHostWin::GetInstance(); |
| 115 |
| 116 return new AshWindowTreeHostWin(initial_bounds); |
| 117 } |
| 118 |
| 119 } // namespace ash |
OLD | NEW |