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

Side by Side Diff: ui/aura/desktop.cc

Issue 8253001: aura: Some changes in Window and Desktop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 2 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 (c) 2011 The Chromium Authors. All rights reserved. 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 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/aura/desktop.h" 5 #include "ui/aura/desktop.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "ui/aura/desktop_delegate.h" 10 #include "ui/aura/desktop_delegate.h"
11 #include "ui/aura/desktop_host.h" 11 #include "ui/aura/desktop_host.h"
12 #include "ui/aura/desktop_observer.h"
12 #include "ui/aura/focus_manager.h" 13 #include "ui/aura/focus_manager.h"
13 #include "ui/aura/root_window.h" 14 #include "ui/aura/root_window.h"
14 #include "ui/aura/screen_aura.h" 15 #include "ui/aura/screen_aura.h"
15 #include "ui/aura/toplevel_window_container.h" 16 #include "ui/aura/toplevel_window_container.h"
16 #include "ui/aura/window.h" 17 #include "ui/aura/window.h"
17 #include "ui/aura/window_delegate.h" 18 #include "ui/aura/window_delegate.h"
18 #include "ui/gfx/compositor/compositor.h" 19 #include "ui/gfx/compositor/compositor.h"
19 #include "ui/gfx/compositor/layer.h" 20 #include "ui/gfx/compositor/layer.h"
20 21
21 namespace aura { 22 namespace aura {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 } 92 }
92 93
93 bool Desktop::OnKeyEvent(const KeyEvent& event) { 94 bool Desktop::OnKeyEvent(const KeyEvent& event) {
94 return window_->HandleKeyEvent(event); 95 return window_->HandleKeyEvent(event);
95 } 96 }
96 97
97 void Desktop::OnHostResized(const gfx::Size& size) { 98 void Desktop::OnHostResized(const gfx::Size& size) {
98 gfx::Rect bounds(0, 0, size.width(), size.height()); 99 gfx::Rect bounds(0, 0, size.width(), size.height());
99 compositor_->WidgetSizeChanged(size); 100 compositor_->WidgetSizeChanged(size);
100 window_->SetBounds(bounds); 101 window_->SetBounds(bounds);
102 FOR_EACH_OBSERVER(DesktopObserver, observers_, OnDesktopResized(size));
101 } 103 }
102 104
103 void Desktop::ScheduleDraw() { 105 void Desktop::ScheduleDraw() {
104 if (!schedule_paint_factory_.HasWeakPtrs()) { 106 if (!schedule_paint_factory_.HasWeakPtrs()) {
105 MessageLoop::current()->PostTask( 107 MessageLoop::current()->PostTask(
106 FROM_HERE, 108 FROM_HERE,
107 base::Bind(&Desktop::Draw, schedule_paint_factory_.GetWeakPtr())); 109 base::Bind(&Desktop::Draw, schedule_paint_factory_.GetWeakPtr()));
108 } 110 }
109 } 111 }
110 112
111 void Desktop::SetActiveWindow(Window* window, Window* to_focus) { 113 void Desktop::SetActiveWindow(Window* window, Window* to_focus) {
112 // We only allow top level windows to be active. 114 // We only allow top level windows to be active.
113 if (window && window != window->GetToplevelWindow()) { 115 if (window && window != window->GetToplevelWindow()) {
114 // Ignore requests to activate windows that aren't in a top level window. 116 // Ignore requests to activate windows that aren't in a top level window.
115 return; 117 return;
116 } 118 }
117 119
118 if (active_window_ == window) 120 if (active_window_ == window)
119 return; 121 return;
120 if (active_window_ && active_window_->delegate()) 122 if (active_window_ && active_window_->delegate())
121 active_window_->delegate()->OnLostActive(); 123 active_window_->delegate()->OnLostActive();
122 active_window_ = window; 124 active_window_ = window;
123 if (active_window_) { 125 if (active_window_) {
124 active_window_->parent()->MoveChildToFront(active_window_); 126 active_window_->parent()->MoveChildToFront(active_window_);
125 if (active_window_->delegate()) 127 if (active_window_->delegate())
126 active_window_->delegate()->OnActivated(); 128 active_window_->delegate()->OnActivated();
127 active_window_->GetFocusManager()->SetFocusedWindow( 129 active_window_->GetFocusManager()->SetFocusedWindow(
128 to_focus ? to_focus : active_window_); 130 to_focus ? to_focus : active_window_);
129 } 131 }
132 FOR_EACH_OBSERVER(DesktopObserver, observers_,
133 OnActiveWindowChanged(active_window_));
130 } 134 }
131 135
132 void Desktop::ActivateTopmostWindow() { 136 void Desktop::ActivateTopmostWindow() {
133 SetActiveWindow(delegate_->GetTopmostWindowToActivate(NULL), NULL); 137 SetActiveWindow(delegate_->GetTopmostWindowToActivate(NULL), NULL);
134 } 138 }
135 139
136 void Desktop::Deactivate(Window* window) { 140 void Desktop::Deactivate(Window* window) {
137 if (!window) 141 if (!window)
138 return; 142 return;
139 143
(...skipping 17 matching lines...) Expand all
157 // Reset active_window_ before invoking SetActiveWindow so that we don't 161 // Reset active_window_ before invoking SetActiveWindow so that we don't
158 // attempt to notify it while running its destructor. 162 // attempt to notify it while running its destructor.
159 active_window_ = NULL; 163 active_window_ = NULL;
160 SetActiveWindow(delegate_->GetTopmostWindowToActivate(window), NULL); 164 SetActiveWindow(delegate_->GetTopmostWindowToActivate(window), NULL);
161 } 165 }
162 166
163 MessageLoop::Dispatcher* Desktop::GetDispatcher() { 167 MessageLoop::Dispatcher* Desktop::GetDispatcher() {
164 return host_.get(); 168 return host_.get();
165 } 169 }
166 170
171 void Desktop::AddObserver(DesktopObserver* observer) {
172 observers_.AddObserver(observer);
173 }
174
175 void Desktop::RemoveObserver(DesktopObserver* observer) {
176 observers_.RemoveObserver(observer);
177 }
178
167 // static 179 // static
168 Desktop* Desktop::GetInstance() { 180 Desktop* Desktop::GetInstance() {
169 if (!instance_) { 181 if (!instance_) {
170 instance_ = new Desktop; 182 instance_ = new Desktop;
171 instance_->Init(); 183 instance_->Init();
172 } 184 }
173 return instance_; 185 return instance_;
174 } 186 }
175 187
176 } // namespace aura 188 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/desktop.h ('k') | ui/aura/desktop_host_linux.cc » ('j') | ui/aura/desktop_observer.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698