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

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

Issue 132013004: Moves transient window observer methods out of WindowObserver (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments and update gyp Created 6 years, 11 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/corewm/transient_window_manager.h" 5 #include "ui/views/corewm/transient_window_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "ui/aura/window.h" 12 #include "ui/aura/window.h"
13 #include "ui/aura/window_property.h" 13 #include "ui/aura/window_property.h"
14 #include "ui/views/corewm/transient_window_observer.h"
14 #include "ui/views/corewm/transient_window_stacking_client.h" 15 #include "ui/views/corewm/transient_window_stacking_client.h"
15 #include "ui/views/corewm/window_util.h" 16 #include "ui/views/corewm/window_util.h"
16 17
17 using aura::Window; 18 using aura::Window;
18 19
19 namespace views { 20 namespace views {
20 namespace corewm { 21 namespace corewm {
21 22
22 DEFINE_OWNED_WINDOW_PROPERTY_KEY(TransientWindowManager, kPropertyKey, NULL); 23 DEFINE_OWNED_WINDOW_PROPERTY_KEY(TransientWindowManager, kPropertyKey, NULL);
23 24
24 TransientWindowManager::~TransientWindowManager() { 25 TransientWindowManager::~TransientWindowManager() {
25 } 26 }
26 27
27 // static 28 // static
28 TransientWindowManager* TransientWindowManager::Get(Window* window) { 29 TransientWindowManager* TransientWindowManager::Get(Window* window) {
29 TransientWindowManager* manager = window->GetProperty(kPropertyKey); 30 TransientWindowManager* manager = window->GetProperty(kPropertyKey);
30 if (!manager) { 31 if (!manager) {
31 manager = new TransientWindowManager(window); 32 manager = new TransientWindowManager(window);
32 window->SetProperty(kPropertyKey, manager); 33 window->SetProperty(kPropertyKey, manager);
33 } 34 }
34 return manager; 35 return manager;
35 } 36 }
36 37
37 // static 38 // static
38 const TransientWindowManager* TransientWindowManager::Get( 39 const TransientWindowManager* TransientWindowManager::Get(
39 const Window* window) { 40 const Window* window) {
40 return window->GetProperty(kPropertyKey); 41 return window->GetProperty(kPropertyKey);
41 } 42 }
42 43
44 void TransientWindowManager::AddObserver(TransientWindowObserver* observer) {
45 observers_.AddObserver(observer);
46 }
47
48 void TransientWindowManager::RemoveObserver(TransientWindowObserver* observer) {
49 observers_.RemoveObserver(observer);
50 }
51
43 void TransientWindowManager::AddTransientChild(Window* child) { 52 void TransientWindowManager::AddTransientChild(Window* child) {
44 // TransientWindowStackingClient does the stacking of transient windows. If it 53 // TransientWindowStackingClient does the stacking of transient windows. If it
45 // isn't installed stacking is going to be wrong. 54 // isn't installed stacking is going to be wrong.
46 DCHECK(TransientWindowStackingClient::instance_); 55 DCHECK(TransientWindowStackingClient::instance_);
47 56
48 TransientWindowManager* child_manager = Get(child); 57 TransientWindowManager* child_manager = Get(child);
49 if (child_manager->transient_parent_) 58 if (child_manager->transient_parent_)
50 Get(child_manager->transient_parent_)->RemoveTransientChild(child); 59 Get(child_manager->transient_parent_)->RemoveTransientChild(child);
51 DCHECK(std::find(transient_children_.begin(), transient_children_.end(), 60 DCHECK(std::find(transient_children_.begin(), transient_children_.end(),
52 child) == transient_children_.end()); 61 child) == transient_children_.end());
53 transient_children_.push_back(child); 62 transient_children_.push_back(child);
54 child_manager->transient_parent_ = window_; 63 child_manager->transient_parent_ = window_;
55 FOR_EACH_OBSERVER(WindowObserver, window_->observers_, 64 FOR_EACH_OBSERVER(TransientWindowObserver, observers_,
56 OnAddTransientChild(window_, child)); 65 OnTransientChildAdded(window_, child));
57 } 66 }
58 67
59 void TransientWindowManager::RemoveTransientChild(Window* child) { 68 void TransientWindowManager::RemoveTransientChild(Window* child) {
60 Windows::iterator i = 69 Windows::iterator i =
61 std::find(transient_children_.begin(), transient_children_.end(), child); 70 std::find(transient_children_.begin(), transient_children_.end(), child);
62 DCHECK(i != transient_children_.end()); 71 DCHECK(i != transient_children_.end());
63 transient_children_.erase(i); 72 transient_children_.erase(i);
64 TransientWindowManager* child_manager = Get(child); 73 TransientWindowManager* child_manager = Get(child);
65 DCHECK_EQ(window_, child_manager->transient_parent_); 74 DCHECK_EQ(window_, child_manager->transient_parent_);
66 child_manager->transient_parent_ = NULL; 75 child_manager->transient_parent_ = NULL;
67 FOR_EACH_OBSERVER(WindowObserver, window_->observers_, 76 FOR_EACH_OBSERVER(TransientWindowObserver, observers_,
68 OnRemoveTransientChild(window_, child)); 77 OnTransientChildRemoved(window_, child));
69 } 78 }
70 79
71 bool TransientWindowManager::IsStackingTransient( 80 bool TransientWindowManager::IsStackingTransient(
72 const aura::Window* child, 81 const aura::Window* child,
73 const aura::Window* target) const { 82 const aura::Window* target) const {
74 return stacking_pair_ && stacking_pair_->child == child && 83 return stacking_pair_ && stacking_pair_->child == child &&
75 stacking_pair_->target == target; 84 stacking_pair_->target == target;
76 } 85 }
77 86
78 TransientWindowManager::TransientWindowManager(Window* window) 87 TransientWindowManager::TransientWindowManager(Window* window)
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 // parent, as destroying an active transient child may otherwise attempt to 147 // parent, as destroying an active transient child may otherwise attempt to
139 // refocus us. 148 // refocus us.
140 // NOTE: this use to be after removed from parent, now its before. 149 // NOTE: this use to be after removed from parent, now its before.
141 Windows transient_children(transient_children_); 150 Windows transient_children(transient_children_);
142 STLDeleteElements(&transient_children); 151 STLDeleteElements(&transient_children);
143 DCHECK(transient_children_.empty()); 152 DCHECK(transient_children_.empty());
144 } 153 }
145 154
146 } // namespace corewm 155 } // namespace corewm
147 } // namespace views 156 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698