| 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 "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "ui/aura/client/capture_client.h" | 8 #include "ui/aura/client/capture_client.h" |
| 9 #include "ui/aura/client/cursor_client.h" | 9 #include "ui/aura/client/cursor_client.h" |
| 10 #include "ui/aura/env.h" | 10 #include "ui/aura/env.h" |
| 11 #include "ui/aura/root_window_transformer.h" | |
| 12 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
| 13 #include "ui/aura/window_event_dispatcher.h" | 12 #include "ui/aura/window_event_dispatcher.h" |
| 14 #include "ui/aura/window_targeter.h" | 13 #include "ui/aura/window_targeter.h" |
| 15 #include "ui/aura/window_tree_host_observer.h" | 14 #include "ui/aura/window_tree_host_observer.h" |
| 16 #include "ui/base/view_prop.h" | 15 #include "ui/base/view_prop.h" |
| 17 #include "ui/compositor/dip_util.h" | 16 #include "ui/compositor/dip_util.h" |
| 18 #include "ui/compositor/layer.h" | 17 #include "ui/compositor/layer.h" |
| 19 #include "ui/gfx/display.h" | 18 #include "ui/gfx/display.h" |
| 20 #include "ui/gfx/insets.h" | 19 #include "ui/gfx/insets.h" |
| 21 #include "ui/gfx/point.h" | 20 #include "ui/gfx/point.h" |
| 22 #include "ui/gfx/point3_f.h" | 21 #include "ui/gfx/point3_f.h" |
| 23 #include "ui/gfx/point_conversions.h" | 22 #include "ui/gfx/point_conversions.h" |
| 24 #include "ui/gfx/screen.h" | 23 #include "ui/gfx/screen.h" |
| 25 #include "ui/gfx/size_conversions.h" | 24 #include "ui/gfx/size_conversions.h" |
| 26 | 25 |
| 27 namespace aura { | 26 namespace aura { |
| 28 | 27 |
| 29 const char kWindowTreeHostForAcceleratedWidget[] = | 28 const char kWindowTreeHostForAcceleratedWidget[] = |
| 30 "__AURA_WINDOW_TREE_HOST_ACCELERATED_WIDGET__"; | 29 "__AURA_WINDOW_TREE_HOST_ACCELERATED_WIDGET__"; |
| 31 | 30 |
| 32 float GetDeviceScaleFactorFromDisplay(Window* window) { | 31 float GetDeviceScaleFactorFromDisplay(Window* window) { |
| 33 gfx::Display display = gfx::Screen::GetScreenFor(window)-> | 32 gfx::Display display = gfx::Screen::GetScreenFor(window)-> |
| 34 GetDisplayNearestWindow(window); | 33 GetDisplayNearestWindow(window); |
| 35 DCHECK(display.is_valid()); | 34 DCHECK(display.is_valid()); |
| 36 return display.device_scale_factor(); | 35 return display.device_scale_factor(); |
| 37 } | 36 } |
| 38 | 37 |
| 39 class SimpleRootWindowTransformer : public RootWindowTransformer { | |
| 40 public: | |
| 41 SimpleRootWindowTransformer(const Window* root_window, | |
| 42 const gfx::Transform& transform) | |
| 43 : root_window_(root_window), | |
| 44 transform_(transform) { | |
| 45 } | |
| 46 | |
| 47 // RootWindowTransformer overrides: | |
| 48 virtual gfx::Transform GetTransform() const OVERRIDE { | |
| 49 return transform_; | |
| 50 } | |
| 51 | |
| 52 virtual gfx::Transform GetInverseTransform() const OVERRIDE { | |
| 53 gfx::Transform invert; | |
| 54 if (!transform_.GetInverse(&invert)) | |
| 55 return transform_; | |
| 56 return invert; | |
| 57 } | |
| 58 | |
| 59 virtual gfx::Rect GetRootWindowBounds( | |
| 60 const gfx::Size& host_size) const OVERRIDE { | |
| 61 gfx::Rect bounds(host_size); | |
| 62 gfx::RectF new_bounds(ui::ConvertRectToDIP(root_window_->layer(), bounds)); | |
| 63 transform_.TransformRect(&new_bounds); | |
| 64 return gfx::Rect(gfx::ToFlooredSize(new_bounds.size())); | |
| 65 } | |
| 66 | |
| 67 virtual gfx::Insets GetHostInsets() const OVERRIDE { | |
| 68 return gfx::Insets(); | |
| 69 } | |
| 70 | |
| 71 private: | |
| 72 virtual ~SimpleRootWindowTransformer() {} | |
| 73 | |
| 74 const Window* root_window_; | |
| 75 const gfx::Transform transform_; | |
| 76 | |
| 77 DISALLOW_COPY_AND_ASSIGN(SimpleRootWindowTransformer); | |
| 78 }; | |
| 79 | |
| 80 //////////////////////////////////////////////////////////////////////////////// | 38 //////////////////////////////////////////////////////////////////////////////// |
| 81 // WindowTreeHost, public: | 39 // WindowTreeHost, public: |
| 82 | 40 |
| 83 WindowTreeHost::~WindowTreeHost() { | 41 WindowTreeHost::~WindowTreeHost() { |
| 84 DCHECK(!compositor_) << "compositor must be destroyed before root window"; | 42 DCHECK(!compositor_) << "compositor must be destroyed before root window"; |
| 85 } | 43 } |
| 86 | 44 |
| 87 #if defined(OS_ANDROID) | 45 #if defined(OS_ANDROID) |
| 88 // static | 46 // static |
| 89 WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds) { | 47 WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 106 InitCompositor(); | 64 InitCompositor(); |
| 107 UpdateRootWindowSize(GetBounds().size()); | 65 UpdateRootWindowSize(GetBounds().size()); |
| 108 Env::GetInstance()->NotifyHostInitialized(this); | 66 Env::GetInstance()->NotifyHostInitialized(this); |
| 109 window()->Show(); | 67 window()->Show(); |
| 110 } | 68 } |
| 111 | 69 |
| 112 void WindowTreeHost::InitCompositor() { | 70 void WindowTreeHost::InitCompositor() { |
| 113 compositor_->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(window()), | 71 compositor_->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(window()), |
| 114 GetBounds().size()); | 72 GetBounds().size()); |
| 115 compositor_->SetRootLayer(window()->layer()); | 73 compositor_->SetRootLayer(window()->layer()); |
| 116 transformer_.reset( | |
| 117 new SimpleRootWindowTransformer(window(), gfx::Transform())); | |
| 118 } | 74 } |
| 119 | 75 |
| 120 void WindowTreeHost::AddObserver(WindowTreeHostObserver* observer) { | 76 void WindowTreeHost::AddObserver(WindowTreeHostObserver* observer) { |
| 121 observers_.AddObserver(observer); | 77 observers_.AddObserver(observer); |
| 122 } | 78 } |
| 123 | 79 |
| 124 void WindowTreeHost::RemoveObserver(WindowTreeHostObserver* observer) { | 80 void WindowTreeHost::RemoveObserver(WindowTreeHostObserver* observer) { |
| 125 observers_.RemoveObserver(observer); | 81 observers_.RemoveObserver(observer); |
| 126 } | 82 } |
| 127 | 83 |
| 128 ui::EventProcessor* WindowTreeHost::event_processor() { | 84 ui::EventProcessor* WindowTreeHost::event_processor() { |
| 129 return dispatcher(); | 85 return dispatcher(); |
| 130 } | 86 } |
| 131 | 87 |
| 132 void WindowTreeHost::SetRootWindowTransformer( | |
| 133 scoped_ptr<RootWindowTransformer> transformer) { | |
| 134 transformer_ = transformer.Pass(); | |
| 135 SetInsets(transformer_->GetHostInsets()); | |
| 136 window()->SetTransform(transformer_->GetTransform()); | |
| 137 // If the layer is not animating, then we need to update the root window | |
| 138 // size immediately. | |
| 139 if (!window()->layer()->GetAnimator()->is_animating()) | |
| 140 UpdateRootWindowSize(GetBounds().size()); | |
| 141 } | |
| 142 | |
| 143 gfx::Transform WindowTreeHost::GetRootTransform() const { | 88 gfx::Transform WindowTreeHost::GetRootTransform() const { |
| 144 float scale = ui::GetDeviceScaleFactor(window()->layer()); | 89 float scale = ui::GetDeviceScaleFactor(window()->layer()); |
| 145 gfx::Transform transform; | 90 gfx::Transform transform; |
| 146 transform.Scale(scale, scale); | 91 transform.Scale(scale, scale); |
| 147 transform *= transformer_->GetTransform(); | 92 transform *= window()->layer()->transform(); |
| 148 return transform; | 93 return transform; |
| 149 } | 94 } |
| 150 | 95 |
| 151 void WindowTreeHost::SetTransform(const gfx::Transform& transform) { | 96 void WindowTreeHost::SetRootTransform(const gfx::Transform& transform) { |
| 152 scoped_ptr<RootWindowTransformer> transformer( | 97 window()->SetTransform(transform); |
| 153 new SimpleRootWindowTransformer(window(), transform)); | 98 UpdateRootWindowSize(GetBounds().size()); |
| 154 SetRootWindowTransformer(transformer.Pass()); | |
| 155 } | 99 } |
| 156 | 100 |
| 157 gfx::Transform WindowTreeHost::GetInverseRootTransform() const { | 101 gfx::Transform WindowTreeHost::GetInverseRootTransform() const { |
| 158 float scale = ui::GetDeviceScaleFactor(window()->layer()); | 102 gfx::Transform invert; |
| 159 gfx::Transform transform; | 103 gfx::Transform transform = GetRootTransform(); |
| 160 transform.Scale(1.0f / scale, 1.0f / scale); | 104 if (!transform.GetInverse(&invert)) |
| 161 return transformer_->GetInverseTransform() * transform; | 105 return transform; |
| 106 return invert; |
| 162 } | 107 } |
| 163 | 108 |
| 164 void WindowTreeHost::UpdateRootWindowSize(const gfx::Size& host_size) { | 109 void WindowTreeHost::UpdateRootWindowSize(const gfx::Size& host_size) { |
| 165 window()->SetBounds(transformer_->GetRootWindowBounds(host_size)); | 110 gfx::Rect bounds(host_size); |
| 111 gfx::RectF new_bounds(ui::ConvertRectToDIP(window()->layer(), bounds)); |
| 112 GetRootTransform().TransformRect(&new_bounds); |
| 113 window()->SetBounds(gfx::Rect(gfx::ToFlooredSize(new_bounds.size()))); |
| 166 } | 114 } |
| 167 | 115 |
| 168 void WindowTreeHost::ConvertPointToNativeScreen(gfx::Point* point) const { | 116 void WindowTreeHost::ConvertPointToNativeScreen(gfx::Point* point) const { |
| 169 ConvertPointToHost(point); | 117 ConvertPointToHost(point); |
| 170 gfx::Point location = GetLocationOnNativeScreen(); | 118 gfx::Point location = GetLocationOnNativeScreen(); |
| 171 point->Offset(location.x(), location.y()); | 119 point->Offset(location.x(), location.y()); |
| 172 } | 120 } |
| 173 | 121 |
| 174 void WindowTreeHost::ConvertPointFromNativeScreen(gfx::Point* point) const { | 122 void WindowTreeHost::ConvertPointFromNativeScreen(gfx::Point* point) const { |
| 175 gfx::Point location = GetLocationOnNativeScreen(); | 123 gfx::Point location = GetLocationOnNativeScreen(); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 client::CursorClient* cursor_client = client::GetCursorClient(window()); | 261 client::CursorClient* cursor_client = client::GetCursorClient(window()); |
| 314 if (cursor_client) { | 262 if (cursor_client) { |
| 315 const gfx::Display& display = | 263 const gfx::Display& display = |
| 316 gfx::Screen::GetScreenFor(window())->GetDisplayNearestWindow(window()); | 264 gfx::Screen::GetScreenFor(window())->GetDisplayNearestWindow(window()); |
| 317 cursor_client->SetDisplay(display); | 265 cursor_client->SetDisplay(display); |
| 318 } | 266 } |
| 319 dispatcher()->OnCursorMovedToRootLocation(root_location); | 267 dispatcher()->OnCursorMovedToRootLocation(root_location); |
| 320 } | 268 } |
| 321 | 269 |
| 322 } // namespace aura | 270 } // namespace aura |
| OLD | NEW |