window_parenting_client.cc 1.7 KB

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