| 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/cursor_client.h" | 9 #include "ui/aura/client/cursor_client.h" |
| 9 #include "ui/aura/env.h" | 10 #include "ui/aura/env.h" |
| 10 #include "ui/aura/root_window_transformer.h" | 11 #include "ui/aura/root_window_transformer.h" |
| 11 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
| 12 #include "ui/aura/window_event_dispatcher.h" | 13 #include "ui/aura/window_event_dispatcher.h" |
| 13 #include "ui/aura/window_targeter.h" | 14 #include "ui/aura/window_targeter.h" |
| 14 #include "ui/aura/window_tree_host_delegate.h" | |
| 15 #include "ui/aura/window_tree_host_observer.h" | 15 #include "ui/aura/window_tree_host_observer.h" |
| 16 #include "ui/base/view_prop.h" | 16 #include "ui/base/view_prop.h" |
| 17 #include "ui/compositor/dip_util.h" | 17 #include "ui/compositor/dip_util.h" |
| 18 #include "ui/compositor/layer.h" | 18 #include "ui/compositor/layer.h" |
| 19 #include "ui/gfx/display.h" | 19 #include "ui/gfx/display.h" |
| 20 #include "ui/gfx/insets.h" | 20 #include "ui/gfx/insets.h" |
| 21 #include "ui/gfx/point.h" | 21 #include "ui/gfx/point.h" |
| 22 #include "ui/gfx/point3_f.h" | 22 #include "ui/gfx/point3_f.h" |
| 23 #include "ui/gfx/point_conversions.h" | 23 #include "ui/gfx/point_conversions.h" |
| 24 #include "ui/gfx/screen.h" | 24 #include "ui/gfx/screen.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 DISALLOW_COPY_AND_ASSIGN(SimpleRootWindowTransformer); | 77 DISALLOW_COPY_AND_ASSIGN(SimpleRootWindowTransformer); |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 //////////////////////////////////////////////////////////////////////////////// | 80 //////////////////////////////////////////////////////////////////////////////// |
| 81 // WindowTreeHost, public: | 81 // WindowTreeHost, public: |
| 82 | 82 |
| 83 WindowTreeHost::~WindowTreeHost() { | 83 WindowTreeHost::~WindowTreeHost() { |
| 84 DCHECK(!compositor_) << "compositor must be destroyed before root window"; | 84 DCHECK(!compositor_) << "compositor must be destroyed before root window"; |
| 85 } | 85 } |
| 86 | 86 |
| 87 #if defined(OS_ANDROID) |
| 88 // static |
| 89 WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds) { |
| 90 // This is only hit for tests and ash, right now these aren't an issue so |
| 91 // adding the CHECK. |
| 92 // TODO(sky): decide if we want a factory. |
| 93 CHECK(false); |
| 94 return NULL; |
| 95 } |
| 96 #endif |
| 97 |
| 87 // static | 98 // static |
| 88 WindowTreeHost* WindowTreeHost::GetForAcceleratedWidget( | 99 WindowTreeHost* WindowTreeHost::GetForAcceleratedWidget( |
| 89 gfx::AcceleratedWidget widget) { | 100 gfx::AcceleratedWidget widget) { |
| 90 return reinterpret_cast<WindowTreeHost*>( | 101 return reinterpret_cast<WindowTreeHost*>( |
| 91 ui::ViewProp::GetValue(widget, kWindowTreeHostForAcceleratedWidget)); | 102 ui::ViewProp::GetValue(widget, kWindowTreeHostForAcceleratedWidget)); |
| 92 } | 103 } |
| 93 | 104 |
| 94 void WindowTreeHost::InitHost() { | 105 void WindowTreeHost::InitHost() { |
| 95 InitCompositor(); | 106 InitCompositor(); |
| 96 UpdateRootWindowSize(GetBounds().size()); | 107 UpdateRootWindowSize(GetBounds().size()); |
| 97 Env::GetInstance()->NotifyRootWindowInitialized(delegate_->AsDispatcher()); | 108 Env::GetInstance()->NotifyRootWindowInitialized(dispatcher()); |
| 98 window()->Show(); | 109 window()->Show(); |
| 99 } | 110 } |
| 100 | 111 |
| 101 void WindowTreeHost::InitCompositor() { | 112 void WindowTreeHost::InitCompositor() { |
| 102 compositor_->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(window()), | 113 compositor_->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(window()), |
| 103 GetBounds().size()); | 114 GetBounds().size()); |
| 104 compositor_->SetRootLayer(window()->layer()); | 115 compositor_->SetRootLayer(window()->layer()); |
| 105 transformer_.reset( | 116 transformer_.reset( |
| 106 new SimpleRootWindowTransformer(window(), gfx::Transform())); | 117 new SimpleRootWindowTransformer(window(), gfx::Transform())); |
| 107 } | 118 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 // so just pass everything along to the host. | 191 // so just pass everything along to the host. |
| 181 SetCursorNative(cursor); | 192 SetCursorNative(cursor); |
| 182 } | 193 } |
| 183 | 194 |
| 184 void WindowTreeHost::OnCursorVisibilityChanged(bool show) { | 195 void WindowTreeHost::OnCursorVisibilityChanged(bool show) { |
| 185 // Clear any existing mouse hover effects when the cursor becomes invisible. | 196 // Clear any existing mouse hover effects when the cursor becomes invisible. |
| 186 // Note we do not need to dispatch a mouse enter when the cursor becomes | 197 // Note we do not need to dispatch a mouse enter when the cursor becomes |
| 187 // visible because that can only happen in response to a mouse event, which | 198 // visible because that can only happen in response to a mouse event, which |
| 188 // will trigger its own mouse enter. | 199 // will trigger its own mouse enter. |
| 189 if (!show) { | 200 if (!show) { |
| 190 delegate_->AsDispatcher()->DispatchMouseExitAtPoint( | 201 dispatcher()->DispatchMouseExitAtPoint( |
| 191 delegate_->AsDispatcher()->GetLastMouseLocationInRoot()); | 202 dispatcher()->GetLastMouseLocationInRoot()); |
| 192 } | 203 } |
| 193 | 204 |
| 194 OnCursorVisibilityChangedNative(show); | 205 OnCursorVisibilityChangedNative(show); |
| 195 } | 206 } |
| 196 | 207 |
| 197 void WindowTreeHost::MoveCursorTo(const gfx::Point& location_in_dip) { | 208 void WindowTreeHost::MoveCursorTo(const gfx::Point& location_in_dip) { |
| 198 gfx::Point host_location(location_in_dip); | 209 gfx::Point host_location(location_in_dip); |
| 199 ConvertPointToHost(&host_location); | 210 ConvertPointToHost(&host_location); |
| 200 MoveCursorToInternal(location_in_dip, host_location); | 211 MoveCursorToInternal(location_in_dip, host_location); |
| 201 } | 212 } |
| 202 | 213 |
| 203 void WindowTreeHost::MoveCursorToHostLocation(const gfx::Point& host_location) { | 214 void WindowTreeHost::MoveCursorToHostLocation(const gfx::Point& host_location) { |
| 204 gfx::Point root_location(host_location); | 215 gfx::Point root_location(host_location); |
| 205 ConvertPointFromHost(&root_location); | 216 ConvertPointFromHost(&root_location); |
| 206 MoveCursorToInternal(root_location, host_location); | 217 MoveCursorToInternal(root_location, host_location); |
| 207 } | 218 } |
| 208 | 219 |
| 209 WindowEventDispatcher* WindowTreeHost::GetDispatcher() { | |
| 210 return delegate_->AsDispatcher(); | |
| 211 } | |
| 212 | |
| 213 //////////////////////////////////////////////////////////////////////////////// | 220 //////////////////////////////////////////////////////////////////////////////// |
| 214 // WindowTreeHost, protected: | 221 // WindowTreeHost, protected: |
| 215 | 222 |
| 216 WindowTreeHost::WindowTreeHost() | 223 WindowTreeHost::WindowTreeHost() |
| 217 : delegate_(NULL), | 224 : window_(new Window(NULL)), |
| 218 window_(new Window(NULL)), | |
| 219 last_cursor_(ui::kCursorNull) { | 225 last_cursor_(ui::kCursorNull) { |
| 220 } | 226 } |
| 221 | 227 |
| 222 void WindowTreeHost::DestroyCompositor() { | 228 void WindowTreeHost::DestroyCompositor() { |
| 223 DCHECK(GetAcceleratedWidget()); | 229 DCHECK(GetAcceleratedWidget()); |
| 224 compositor_.reset(); | 230 compositor_.reset(); |
| 225 } | 231 } |
| 226 | 232 |
| 227 void WindowTreeHost::DestroyDispatcher() { | 233 void WindowTreeHost::DestroyDispatcher() { |
| 228 // An observer may have been added by an animation on the | |
| 229 // WindowEventDispatcher. | |
| 230 window()->layer()->GetAnimator()->RemoveObserver(dispatcher()); | |
| 231 | |
| 232 delete window_; | 234 delete window_; |
| 233 window_ = NULL; | 235 window_ = NULL; |
| 234 dispatcher_.reset(); | 236 dispatcher_.reset(); |
| 235 | 237 |
| 236 // TODO(beng): this comment is no longer quite valid since this function | 238 // TODO(beng): this comment is no longer quite valid since this function |
| 237 // isn't called from WED, and WED isn't a subclass of Window. So it seems | 239 // isn't called from WED, and WED isn't a subclass of Window. So it seems |
| 238 // like we could just rely on ~Window now. | 240 // like we could just rely on ~Window now. |
| 239 // Destroy child windows while we're still valid. This is also done by | 241 // Destroy child windows while we're still valid. This is also done by |
| 240 // ~Window, but by that time any calls to virtual methods overriden here (such | 242 // ~Window, but by that time any calls to virtual methods overriden here (such |
| 241 // as GetRootWindow()) result in Window's implementation. By destroying here | 243 // as GetRootWindow()) result in Window's implementation. By destroying here |
| (...skipping 11 matching lines...) Expand all Loading... |
| 253 window()->Init(WINDOW_LAYER_NOT_DRAWN); | 255 window()->Init(WINDOW_LAYER_NOT_DRAWN); |
| 254 window()->set_host(this); | 256 window()->set_host(this); |
| 255 window()->SetName("RootWindow"); | 257 window()->SetName("RootWindow"); |
| 256 window()->SetEventTargeter( | 258 window()->SetEventTargeter( |
| 257 scoped_ptr<ui::EventTargeter>(new WindowTargeter())); | 259 scoped_ptr<ui::EventTargeter>(new WindowTargeter())); |
| 258 prop_.reset(new ui::ViewProp(GetAcceleratedWidget(), | 260 prop_.reset(new ui::ViewProp(GetAcceleratedWidget(), |
| 259 kWindowTreeHostForAcceleratedWidget, | 261 kWindowTreeHostForAcceleratedWidget, |
| 260 this)); | 262 this)); |
| 261 dispatcher_.reset(new WindowEventDispatcher(this)); | 263 dispatcher_.reset(new WindowEventDispatcher(this)); |
| 262 } | 264 } |
| 263 delegate_ = dispatcher(); | |
| 264 } | 265 } |
| 265 | 266 |
| 266 void WindowTreeHost::OnHostMoved(const gfx::Point& new_location) { | 267 void WindowTreeHost::OnHostMoved(const gfx::Point& new_location) { |
| 267 TRACE_EVENT1("ui", "WindowTreeHost::OnHostMoved", | 268 TRACE_EVENT1("ui", "WindowTreeHost::OnHostMoved", |
| 268 "origin", new_location.ToString()); | 269 "origin", new_location.ToString()); |
| 269 | 270 |
| 270 FOR_EACH_OBSERVER(WindowTreeHostObserver, observers_, | 271 FOR_EACH_OBSERVER(WindowTreeHostObserver, observers_, |
| 271 OnHostMoved(this, new_location)); | 272 OnHostMoved(this, new_location)); |
| 272 } | 273 } |
| 273 | 274 |
| 274 void WindowTreeHost::OnHostResized(const gfx::Size& new_size) { | 275 void WindowTreeHost::OnHostResized(const gfx::Size& new_size) { |
| 275 // The compositor should have the same size as the native root window host. | 276 // The compositor should have the same size as the native root window host. |
| 276 // Get the latest scale from display because it might have been changed. | 277 // Get the latest scale from display because it might have been changed. |
| 277 compositor_->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(window()), | 278 compositor_->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(window()), |
| 278 new_size); | 279 new_size); |
| 279 | 280 |
| 280 gfx::Size layer_size = GetBounds().size(); | 281 gfx::Size layer_size = GetBounds().size(); |
| 281 // The layer, and the observers should be notified of the | 282 // The layer, and the observers should be notified of the |
| 282 // transformed size of the root window. | 283 // transformed size of the root window. |
| 283 UpdateRootWindowSize(layer_size); | 284 UpdateRootWindowSize(layer_size); |
| 284 FOR_EACH_OBSERVER(WindowTreeHostObserver, observers_, OnHostResized(this)); | 285 FOR_EACH_OBSERVER(WindowTreeHostObserver, observers_, OnHostResized(this)); |
| 285 delegate_->OnHostResized(layer_size); | 286 dispatcher()->OnHostResized(layer_size); |
| 286 } | 287 } |
| 287 | 288 |
| 288 void WindowTreeHost::OnHostCloseRequested() { | 289 void WindowTreeHost::OnHostCloseRequested() { |
| 289 FOR_EACH_OBSERVER(WindowTreeHostObserver, observers_, | 290 FOR_EACH_OBSERVER(WindowTreeHostObserver, observers_, |
| 290 OnHostCloseRequested(this)); | 291 OnHostCloseRequested(this)); |
| 291 } | 292 } |
| 292 | 293 |
| 294 void WindowTreeHost::OnHostActivated() { |
| 295 Env::GetInstance()->RootWindowActivated(dispatcher()); |
| 296 } |
| 297 |
| 298 void WindowTreeHost::OnHostLostWindowCapture() { |
| 299 Window* capture_window = client::GetCaptureWindow(window()); |
| 300 if (capture_window && capture_window->GetRootWindow() == window()) |
| 301 capture_window->ReleaseCapture(); |
| 302 } |
| 303 |
| 304 //////////////////////////////////////////////////////////////////////////////// |
| 305 // WindowTreeHost, private: |
| 306 |
| 293 void WindowTreeHost::MoveCursorToInternal(const gfx::Point& root_location, | 307 void WindowTreeHost::MoveCursorToInternal(const gfx::Point& root_location, |
| 294 const gfx::Point& host_location) { | 308 const gfx::Point& host_location) { |
| 295 MoveCursorToNative(host_location); | 309 MoveCursorToNative(host_location); |
| 296 client::CursorClient* cursor_client = client::GetCursorClient(window()); | 310 client::CursorClient* cursor_client = client::GetCursorClient(window()); |
| 297 if (cursor_client) { | 311 if (cursor_client) { |
| 298 const gfx::Display& display = | 312 const gfx::Display& display = |
| 299 gfx::Screen::GetScreenFor(window())->GetDisplayNearestWindow(window()); | 313 gfx::Screen::GetScreenFor(window())->GetDisplayNearestWindow(window()); |
| 300 cursor_client->SetDisplay(display); | 314 cursor_client->SetDisplay(display); |
| 301 } | 315 } |
| 302 delegate_->OnCursorMovedToRootLocation(root_location); | 316 dispatcher()->OnCursorMovedToRootLocation(root_location); |
| 303 } | 317 } |
| 304 | 318 |
| 305 #if defined(OS_ANDROID) | |
| 306 // static | |
| 307 WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds) { | |
| 308 // This is only hit for tests and ash, right now these aren't an issue so | |
| 309 // adding the CHECK. | |
| 310 // TODO(sky): decide if we want a factory. | |
| 311 CHECK(false); | |
| 312 return NULL; | |
| 313 } | |
| 314 #endif | |
| 315 | |
| 316 } // namespace aura | 319 } // namespace aura |
| OLD | NEW |