Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Side by Side Diff: ui/views/corewm/window_util.cc

Issue 194843004: Move files from ui/views/corewm to ui/wm/core (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/views/corewm/window_util.h ('k') | ui/views/corewm/wm_state.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 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/views/corewm/window_util.h"
6
7 #include "ui/aura/client/activation_client.h"
8 #include "ui/aura/window.h"
9 #include "ui/aura/window_event_dispatcher.h"
10 #include "ui/compositor/layer.h"
11 #include "ui/compositor/layer_tree_owner.h"
12 #include "ui/views/corewm/transient_window_manager.h"
13
14 namespace {
15
16 // Invokes RecreateLayer() on all the children of |to_clone|, adding the newly
17 // cloned children to |parent|.
18 //
19 // WARNING: It is assumed that |parent| is ultimately owned by a LayerTreeOwner.
20 void CloneChildren(ui::Layer* to_clone, ui::Layer* parent) {
21 typedef std::vector<ui::Layer*> Layers;
22 // Make a copy of the children since RecreateLayer() mutates it.
23 Layers children(to_clone->children());
24 for (Layers::const_iterator i = children.begin(); i != children.end(); ++i) {
25 ui::LayerOwner* owner = (*i)->owner();
26 ui::Layer* clone = owner ? owner->RecreateLayer().release() : NULL;
27 if (clone) {
28 parent->Add(clone);
29 // RecreateLayer() moves the existing children to the new layer. Create a
30 // copy of those.
31 CloneChildren(owner->layer(), clone);
32 }
33 }
34 }
35
36 } // namespace
37
38 namespace views {
39 namespace corewm {
40
41 void ActivateWindow(aura::Window* window) {
42 DCHECK(window);
43 DCHECK(window->GetRootWindow());
44 aura::client::GetActivationClient(window->GetRootWindow())->ActivateWindow(
45 window);
46 }
47
48 void DeactivateWindow(aura::Window* window) {
49 DCHECK(window);
50 DCHECK(window->GetRootWindow());
51 aura::client::GetActivationClient(window->GetRootWindow())->DeactivateWindow(
52 window);
53 }
54
55 bool IsActiveWindow(aura::Window* window) {
56 DCHECK(window);
57 if (!window->GetRootWindow())
58 return false;
59 aura::client::ActivationClient* client =
60 aura::client::GetActivationClient(window->GetRootWindow());
61 return client && client->GetActiveWindow() == window;
62 }
63
64 bool CanActivateWindow(aura::Window* window) {
65 DCHECK(window);
66 if (!window->GetRootWindow())
67 return false;
68 aura::client::ActivationClient* client =
69 aura::client::GetActivationClient(window->GetRootWindow());
70 return client && client->CanActivateWindow(window);
71 }
72
73 aura::Window* GetActivatableWindow(aura::Window* window) {
74 aura::client::ActivationClient* client =
75 aura::client::GetActivationClient(window->GetRootWindow());
76 return client ? client->GetActivatableWindow(window) : NULL;
77 }
78
79 aura::Window* GetToplevelWindow(aura::Window* window) {
80 aura::client::ActivationClient* client =
81 aura::client::GetActivationClient(window->GetRootWindow());
82 return client ? client->GetToplevelWindow(window) : NULL;
83 }
84
85 scoped_ptr<ui::LayerTreeOwner> RecreateLayers(ui::LayerOwner* root) {
86 scoped_ptr<ui::LayerTreeOwner> owner(
87 new ui::LayerTreeOwner(root->RecreateLayer().release()));
88 if (owner->root())
89 CloneChildren(root->layer(), owner->root());
90 return owner.Pass();
91 }
92
93 aura::Window* GetTransientParent(aura::Window* window) {
94 return const_cast<aura::Window*>(GetTransientParent(
95 const_cast<const aura::Window*>(window)));
96 }
97
98 const aura::Window* GetTransientParent(const aura::Window* window) {
99 const TransientWindowManager* manager = TransientWindowManager::Get(window);
100 return manager ? manager->transient_parent() : NULL;
101 }
102
103 const std::vector<aura::Window*>& GetTransientChildren(
104 const aura::Window* window) {
105 const TransientWindowManager* manager = TransientWindowManager::Get(window);
106 if (manager)
107 return manager->transient_children();
108
109 static std::vector<aura::Window*>* shared = new std::vector<aura::Window*>;
110 return *shared;
111 }
112
113 void AddTransientChild(aura::Window* parent, aura::Window* child) {
114 TransientWindowManager::Get(parent)->AddTransientChild(child);
115 }
116
117 void RemoveTransientChild(aura::Window* parent, aura::Window* child) {
118 TransientWindowManager::Get(parent)->RemoveTransientChild(child);
119 }
120
121 bool HasTransientAncestor(const aura::Window* window,
122 const aura::Window* ancestor) {
123 const aura::Window* transient_parent = GetTransientParent(window);
124 if (transient_parent == ancestor)
125 return true;
126 return transient_parent ?
127 HasTransientAncestor(transient_parent, ancestor) : false;
128 }
129
130 } // namespace corewm
131 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/corewm/window_util.h ('k') | ui/views/corewm/wm_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698