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

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: sync, move AlwaysOnTonController from Shell to StackingController 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/client/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 have no children.
29 DCHECK(default_container->children().empty());
30 DCHECK(always_on_top_container->children().empty());
31
32 // We are not handling any containers yet.
33 DCHECK(default_container_ == NULL && always_on_top_container_ == NULL);
34
35 default_container_ = default_container;
36 default_container_->AddObserver(this);
37
38 always_on_top_container_ = always_on_top_container;
39 always_on_top_container_->AddObserver(this);
40 }
41
42 aura::Window* AlwaysOnTopController::GetContainer(aura::Window* window) const {
43 DCHECK(default_container_ && always_on_top_container_);
44 return !window->GetProperty(aura::kAlwaysOnTopKey) ? default_container_ :
45 always_on_top_container_;
46 }
47
48 void AlwaysOnTopController::OnWindowAdded(aura::Window* child) {
49 // Observe direct child of the containers.
50 if (child->parent() == default_container_ ||
51 child->parent() == always_on_top_container_) {
52 child->AddObserver(this);
53 }
54 }
55
56 void AlwaysOnTopController::OnWillRemoveWindow(aura::Window* child) {
57 child->RemoveObserver(this);
58 }
59
60 void AlwaysOnTopController::OnPropertyChanged(aura::Window* window,
61 const char* name,
62 void* old) {
63 if (name == aura::kAlwaysOnTopKey) {
64 DCHECK(window->type() == aura::WINDOW_TYPE_NORMAL ||
65 window->type() == aura::WINDOW_TYPE_POPUP);
66 aura::Window* container = GetContainer(window);
67 if (window->parent() != container)
68 container->AddChild(window);
69 }
70 }
71
72 void AlwaysOnTopController::OnWindowDestroyed(aura::Window* window) {
73 if (window == default_container_)
74 default_container_ = NULL;
75 if (window == always_on_top_container_)
76 always_on_top_container_ = NULL;
77 }
78
79 } // namespace internal
80 } // namespace aura_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698