11e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved.
21e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
31e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// found in the LICENSE file.
41e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
51e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ui/aura/client/window_tree_client.h"
61e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
71e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ui/aura/env.h"
8a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/aura/window_event_dispatcher.h"
91e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ui/aura/window_property.h"
101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)DECLARE_WINDOW_PROPERTY_TYPE(aura::client::WindowTreeClient*)
121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)namespace aura {
141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)namespace client {
151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)DEFINE_WINDOW_PROPERTY_KEY(
171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    WindowTreeClient*, kRootWindowWindowTreeClientKey, NULL);
181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)void SetWindowTreeClient(Window* window, WindowTreeClient* window_tree_client) {
201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  DCHECK(window);
211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  Window* root_window = window->GetRootWindow();
231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  DCHECK(root_window);
241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  root_window->SetProperty(kRootWindowWindowTreeClientKey, window_tree_client);
251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)WindowTreeClient* GetWindowTreeClient(Window* window) {
281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  DCHECK(window);
291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  Window* root_window = window->GetRootWindow();
301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  DCHECK(root_window);
311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  WindowTreeClient* client =
321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      root_window->GetProperty(kRootWindowWindowTreeClientKey);
331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  DCHECK(client);
341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  return client;
351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)void ParentWindowWithContext(Window* window,
381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                             Window* context,
391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                             const gfx::Rect& screen_bounds) {
401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  DCHECK(context);
411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // |context| must be attached to a hierarchy with a WindowTreeClient.
431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  WindowTreeClient* client = GetWindowTreeClient(context);
441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  DCHECK(client);
451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  Window* default_parent =
461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      client->GetDefaultParent(context, window, screen_bounds);
471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  default_parent->AddChild(window);
481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}  // namespace client
511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}  // namespace aura
52