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

Side by Side Diff: ui/aura_shell/always_on_top_controller.cc

Issue 8387043: [Aura] Support always-on-top top level window. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: move always-on-top handling code from shell into a controller Created 9 years, 1 month 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
OLDNEW
(Empty)
1 // Copyright (c) 2011 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_shell/always_on_top_controller.h"
6
7 #include "ui/aura/aura_constants.h"
8 #include "ui/aura/window.h"
9 #include "ui/aura/window_types.h"
10
11 namespace aura_shell {
12 namespace internal {
13
14 AlwaysOnTopController::AlwaysOnTopController()
15 : default_container_(NULL),
16 always_on_top_container_(NULL) {
17 }
18
19 AlwaysOnTopController::~AlwaysOnTopController() {
20 if (default_container_)
21 default_container_->RemoveObserver(this);
22 if (always_on_top_container_)
23 always_on_top_container_->RemoveObserver(this);
24 }
25
26 void AlwaysOnTopController::SetContainers(aura::Window* default_container,
27 aura::Window* always_on_top_container) {
28 // Both containers should be top level window containers.
29 DCHECK(default_container->AsToplevelWindowContainer());
30 DCHECK(always_on_top_container->AsToplevelWindowContainer());
31
32 // Both containers should have no children.
33 DCHECK(default_container->children().size() == 0);
oshima 2011/11/08 23:34:24 empty()
xiyuan 2011/11/09 17:42:18 Done.
34 DCHECK(always_on_top_container->children().size() == 0);
35
36 // We are not handling any containers yet.
37 DCHECK(default_container_ == NULL && always_on_top_container_ == NULL);
38
39 default_container_ = default_container;
40 default_container_->AddObserver(this);
41
42 always_on_top_container_ = always_on_top_container;
43 always_on_top_container_->AddObserver(this);
44 }
45
46 aura::Window* AlwaysOnTopController::GetContainer(aura::Window* window) const {
47 return !window->GetProperty(aura::kAlwaysOnTopKey) ? default_container_ :
48 always_on_top_container_;
49 }
50
51 void AlwaysOnTopController::OnWindowAdded(aura::Window* child) {
52 // Observe direct child of the containers.
53 if (child->parent() == default_container_ ||
54 child->parent() == always_on_top_container_) {
55 child->AddObserver(this);
56 }
57 }
58
59 void AlwaysOnTopController::OnWillRemoveWindow(aura::Window* child) {
60 child->RemoveObserver(this);
61 }
62
63 void AlwaysOnTopController::OnPropertyChanged(aura::Window* window,
64 const char* name,
65 void* old) {
66 if (name == aura::kAlwaysOnTopKey) {
67 DCHECK(window->type() == aura::WINDOW_TYPE_NORMAL ||
68 window->type() == aura::WINDOW_TYPE_POPUP);
69 aura::Window* container = GetContainer(window);
70 if (window->parent() != container)
71 container->AddChild(window);
72 }
73 }
74
75 void AlwaysOnTopController::OnWindowDestroyed(aura::Window* window) {
76 if (window == default_container_)
77 default_container_ = NULL;
78 if (window == always_on_top_container_)
79 always_on_top_container_ = NULL;
80 }
81
82 } // namespace internal
83 } // namespace aura_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698