| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/aura/window_tree_host.h" | 5 #include "ui/aura/window_tree_host.h" |
| 6 | 6 |
| 7 #include "ui/aura/env.h" | 7 #include "ui/aura/env.h" |
| 8 #include "ui/aura/root_window.h" | 8 #include "ui/aura/root_window.h" |
| 9 #include "ui/aura/root_window_transformer.h" | 9 #include "ui/aura/root_window_transformer.h" |
| 10 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 private: | 63 private: |
| 64 virtual ~SimpleRootWindowTransformer() {} | 64 virtual ~SimpleRootWindowTransformer() {} |
| 65 | 65 |
| 66 const Window* root_window_; | 66 const Window* root_window_; |
| 67 const gfx::Transform transform_; | 67 const gfx::Transform transform_; |
| 68 | 68 |
| 69 DISALLOW_COPY_AND_ASSIGN(SimpleRootWindowTransformer); | 69 DISALLOW_COPY_AND_ASSIGN(SimpleRootWindowTransformer); |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 //////////////////////////////////////////////////////////////////////////////// | 72 //////////////////////////////////////////////////////////////////////////////// |
| 73 // RootWindowHost, public: | 73 // WindowTreeHost, public: |
| 74 | 74 |
| 75 RootWindowHost::~RootWindowHost() { | 75 WindowTreeHost::~WindowTreeHost() { |
| 76 // TODO(beng): this represents an ordering change. In the old code, the | 76 // TODO(beng): this represents an ordering change. In the old code, the |
| 77 // compositor was reset before the window hierarchy was destroyed. | 77 // compositor was reset before the window hierarchy was destroyed. |
| 78 // verify that this has no adverse effects. | 78 // verify that this has no adverse effects. |
| 79 // Make sure to destroy the compositor before terminating so that state is | 79 // Make sure to destroy the compositor before terminating so that state is |
| 80 // cleared and we don't hit asserts. | 80 // cleared and we don't hit asserts. |
| 81 compositor_.reset(); | 81 compositor_.reset(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void RootWindowHost::InitHost() { | 84 void WindowTreeHost::InitHost() { |
| 85 compositor_->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(window()), | 85 compositor_->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(window()), |
| 86 GetBounds().size()); | 86 GetBounds().size()); |
| 87 window()->Init(ui::LAYER_NOT_DRAWN); | 87 window()->Init(ui::LAYER_NOT_DRAWN); |
| 88 compositor_->SetRootLayer(window()->layer()); | 88 compositor_->SetRootLayer(window()->layer()); |
| 89 transformer_.reset( | 89 transformer_.reset( |
| 90 new SimpleRootWindowTransformer(window(), gfx::Transform())); | 90 new SimpleRootWindowTransformer(window(), gfx::Transform())); |
| 91 UpdateRootWindowSize(GetBounds().size()); | 91 UpdateRootWindowSize(GetBounds().size()); |
| 92 Env::GetInstance()->NotifyRootWindowInitialized(delegate_->AsRootWindow()); | 92 Env::GetInstance()->NotifyRootWindowInitialized(delegate_->AsRootWindow()); |
| 93 window()->Show(); | 93 window()->Show(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 aura::Window* RootWindowHost::window() { | 96 aura::Window* WindowTreeHost::window() { |
| 97 return const_cast<Window*>(const_cast<const RootWindowHost*>(this)->window()); | 97 return const_cast<Window*>(const_cast<const WindowTreeHost*>(this)->window()); |
| 98 } | 98 } |
| 99 | 99 |
| 100 const aura::Window* RootWindowHost::window() const { | 100 const aura::Window* WindowTreeHost::window() const { |
| 101 return delegate_->AsRootWindow()->window(); | 101 return delegate_->AsRootWindow()->window(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 void RootWindowHost::SetRootWindowTransformer( | 104 void WindowTreeHost::SetRootWindowTransformer( |
| 105 scoped_ptr<RootWindowTransformer> transformer) { | 105 scoped_ptr<RootWindowTransformer> transformer) { |
| 106 transformer_ = transformer.Pass(); | 106 transformer_ = transformer.Pass(); |
| 107 SetInsets(transformer_->GetHostInsets()); | 107 SetInsets(transformer_->GetHostInsets()); |
| 108 window()->SetTransform(transformer_->GetTransform()); | 108 window()->SetTransform(transformer_->GetTransform()); |
| 109 // If the layer is not animating, then we need to update the root window | 109 // If the layer is not animating, then we need to update the root window |
| 110 // size immediately. | 110 // size immediately. |
| 111 if (!window()->layer()->GetAnimator()->is_animating()) | 111 if (!window()->layer()->GetAnimator()->is_animating()) |
| 112 UpdateRootWindowSize(GetBounds().size()); | 112 UpdateRootWindowSize(GetBounds().size()); |
| 113 } | 113 } |
| 114 | 114 |
| 115 gfx::Transform RootWindowHost::GetRootTransform() const { | 115 gfx::Transform WindowTreeHost::GetRootTransform() const { |
| 116 float scale = ui::GetDeviceScaleFactor(window()->layer()); | 116 float scale = ui::GetDeviceScaleFactor(window()->layer()); |
| 117 gfx::Transform transform; | 117 gfx::Transform transform; |
| 118 transform.Scale(scale, scale); | 118 transform.Scale(scale, scale); |
| 119 transform *= transformer_->GetTransform(); | 119 transform *= transformer_->GetTransform(); |
| 120 return transform; | 120 return transform; |
| 121 } | 121 } |
| 122 | 122 |
| 123 void RootWindowHost::SetTransform(const gfx::Transform& transform) { | 123 void WindowTreeHost::SetTransform(const gfx::Transform& transform) { |
| 124 scoped_ptr<RootWindowTransformer> transformer( | 124 scoped_ptr<RootWindowTransformer> transformer( |
| 125 new SimpleRootWindowTransformer(window(), transform)); | 125 new SimpleRootWindowTransformer(window(), transform)); |
| 126 SetRootWindowTransformer(transformer.Pass()); | 126 SetRootWindowTransformer(transformer.Pass()); |
| 127 } | 127 } |
| 128 | 128 |
| 129 gfx::Transform RootWindowHost::GetInverseRootTransform() const { | 129 gfx::Transform WindowTreeHost::GetInverseRootTransform() const { |
| 130 float scale = ui::GetDeviceScaleFactor(window()->layer()); | 130 float scale = ui::GetDeviceScaleFactor(window()->layer()); |
| 131 gfx::Transform transform; | 131 gfx::Transform transform; |
| 132 transform.Scale(1.0f / scale, 1.0f / scale); | 132 transform.Scale(1.0f / scale, 1.0f / scale); |
| 133 return transformer_->GetInverseTransform() * transform; | 133 return transformer_->GetInverseTransform() * transform; |
| 134 } | 134 } |
| 135 | 135 |
| 136 void RootWindowHost::UpdateRootWindowSize(const gfx::Size& host_size) { | 136 void WindowTreeHost::UpdateRootWindowSize(const gfx::Size& host_size) { |
| 137 window()->SetBounds(transformer_->GetRootWindowBounds(host_size)); | 137 window()->SetBounds(transformer_->GetRootWindowBounds(host_size)); |
| 138 } | 138 } |
| 139 | 139 |
| 140 void RootWindowHost::ConvertPointToNativeScreen(gfx::Point* point) const { | 140 void WindowTreeHost::ConvertPointToNativeScreen(gfx::Point* point) const { |
| 141 ConvertPointToHost(point); | 141 ConvertPointToHost(point); |
| 142 gfx::Point location = GetLocationOnNativeScreen(); | 142 gfx::Point location = GetLocationOnNativeScreen(); |
| 143 point->Offset(location.x(), location.y()); | 143 point->Offset(location.x(), location.y()); |
| 144 } | 144 } |
| 145 | 145 |
| 146 void RootWindowHost::ConvertPointFromNativeScreen(gfx::Point* point) const { | 146 void WindowTreeHost::ConvertPointFromNativeScreen(gfx::Point* point) const { |
| 147 gfx::Point location = GetLocationOnNativeScreen(); | 147 gfx::Point location = GetLocationOnNativeScreen(); |
| 148 point->Offset(-location.x(), -location.y()); | 148 point->Offset(-location.x(), -location.y()); |
| 149 ConvertPointFromHost(point); | 149 ConvertPointFromHost(point); |
| 150 } | 150 } |
| 151 | 151 |
| 152 void RootWindowHost::ConvertPointToHost(gfx::Point* point) const { | 152 void WindowTreeHost::ConvertPointToHost(gfx::Point* point) const { |
| 153 gfx::Point3F point_3f(*point); | 153 gfx::Point3F point_3f(*point); |
| 154 GetRootTransform().TransformPoint(&point_3f); | 154 GetRootTransform().TransformPoint(&point_3f); |
| 155 *point = gfx::ToFlooredPoint(point_3f.AsPointF()); | 155 *point = gfx::ToFlooredPoint(point_3f.AsPointF()); |
| 156 } | 156 } |
| 157 | 157 |
| 158 void RootWindowHost::ConvertPointFromHost(gfx::Point* point) const { | 158 void WindowTreeHost::ConvertPointFromHost(gfx::Point* point) const { |
| 159 gfx::Point3F point_3f(*point); | 159 gfx::Point3F point_3f(*point); |
| 160 GetInverseRootTransform().TransformPoint(&point_3f); | 160 GetInverseRootTransform().TransformPoint(&point_3f); |
| 161 *point = gfx::ToFlooredPoint(point_3f.AsPointF()); | 161 *point = gfx::ToFlooredPoint(point_3f.AsPointF()); |
| 162 } | 162 } |
| 163 | 163 |
| 164 //////////////////////////////////////////////////////////////////////////////// | 164 //////////////////////////////////////////////////////////////////////////////// |
| 165 // RootWindowHost, protected: | 165 // WindowTreeHost, protected: |
| 166 | 166 |
| 167 RootWindowHost::RootWindowHost() | 167 WindowTreeHost::WindowTreeHost() |
| 168 : delegate_(NULL) { | 168 : delegate_(NULL) { |
| 169 } | 169 } |
| 170 | 170 |
| 171 void RootWindowHost::CreateCompositor( | 171 void WindowTreeHost::CreateCompositor( |
| 172 gfx::AcceleratedWidget accelerated_widget) { | 172 gfx::AcceleratedWidget accelerated_widget) { |
| 173 compositor_.reset(new ui::Compositor(GetAcceleratedWidget())); | 173 compositor_.reset(new ui::Compositor(GetAcceleratedWidget())); |
| 174 DCHECK(compositor_.get()); | 174 DCHECK(compositor_.get()); |
| 175 } | 175 } |
| 176 | 176 |
| 177 void RootWindowHost::NotifyHostResized(const gfx::Size& new_size) { | 177 void WindowTreeHost::NotifyHostResized(const gfx::Size& new_size) { |
| 178 // The compositor should have the same size as the native root window host. | 178 // The compositor should have the same size as the native root window host. |
| 179 // Get the latest scale from display because it might have been changed. | 179 // Get the latest scale from display because it might have been changed. |
| 180 compositor_->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(window()), | 180 compositor_->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(window()), |
| 181 new_size); | 181 new_size); |
| 182 | 182 |
| 183 // The layer, and the observers should be notified of the | 183 // The layer, and the observers should be notified of the |
| 184 // transformed size of the root window. | 184 // transformed size of the root window. |
| 185 UpdateRootWindowSize(new_size); | 185 UpdateRootWindowSize(new_size); |
| 186 delegate_->OnHostResized(new_size); | 186 delegate_->OnHostResized(new_size); |
| 187 } | 187 } |
| 188 | 188 |
| 189 } // namespace aura | 189 } // namespace aura |
| OLD | NEW |