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
3 // found in the LICENSE file.
4
5 #include "ui/aura/client/window_parenting_client.h"
6
7 #include "ui/aura/env.h"
8 #include "ui/aura/window.h"
9 #include "ui/aura/window_event_dispatcher.h"
10 #include "ui/base/class_property.h"
11
12 DEFINE_UI_CLASS_PROPERTY_TYPE(aura::client::WindowParentingClient*)
13
14 namespace aura {
15 namespace client {
16
DEFINE_UI_CLASS_PROPERTY_KEY(WindowParentingClient *,kRootWindowWindowParentingClientKey,NULL)17 DEFINE_UI_CLASS_PROPERTY_KEY(WindowParentingClient*,
18 kRootWindowWindowParentingClientKey,
19 NULL)
20
21 void SetWindowParentingClient(Window* window,
22 WindowParentingClient* window_tree_client) {
23 DCHECK(window);
24
25 Window* root_window = window->GetRootWindow();
26 DCHECK(root_window);
27 root_window->SetProperty(kRootWindowWindowParentingClientKey,
28 window_tree_client);
29 }
30
GetWindowParentingClient(Window * window)31 WindowParentingClient* GetWindowParentingClient(Window* window) {
32 DCHECK(window);
33 Window* root_window = window->GetRootWindow();
34 DCHECK(root_window);
35 WindowParentingClient* client =
36 root_window->GetProperty(kRootWindowWindowParentingClientKey);
37 DCHECK(client);
38 return client;
39 }
40
ParentWindowWithContext(Window * window,Window * context,const gfx::Rect & screen_bounds)41 void ParentWindowWithContext(Window* window,
42 Window* context,
43 const gfx::Rect& screen_bounds) {
44 DCHECK(context);
45
46 // |context| must be attached to a hierarchy with a WindowParentingClient.
47 WindowParentingClient* client = GetWindowParentingClient(context);
48 DCHECK(client);
49 Window* default_parent = client->GetDefaultParent(window, screen_bounds);
50 default_parent->AddChild(window);
51 }
52
53 } // namespace client
54 } // namespace aura
55