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

Side by Side Diff: ui/aura/window.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/window.h" 5 #include "ui/aura/window.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "ui/aura/desktop.h" 10 #include "ui/aura/desktop.h"
11 #include "ui/aura/desktop_delegate.h" 11 #include "ui/aura/desktop_delegate.h"
12 #include "ui/aura/event.h" 12 #include "ui/aura/event.h"
13 #include "ui/aura/event_filter.h" 13 #include "ui/aura/event_filter.h"
14 #include "ui/aura/layout_manager.h" 14 #include "ui/aura/layout_manager.h"
15 #include "ui/aura/window_delegate.h" 15 #include "ui/aura/window_delegate.h"
16 #include "ui/aura/window_observer.h"
16 #include "ui/aura/window_types.h" 17 #include "ui/aura/window_types.h"
17 #include "ui/base/animation/multi_animation.h" 18 #include "ui/base/animation/multi_animation.h"
18 #include "ui/gfx/canvas_skia.h" 19 #include "ui/gfx/canvas_skia.h"
19 #include "ui/gfx/compositor/compositor.h" 20 #include "ui/gfx/compositor/compositor.h"
20 #include "ui/gfx/compositor/layer.h" 21 #include "ui/gfx/compositor/layer.h"
21 #include "ui/gfx/screen.h" 22 #include "ui/gfx/screen.h"
22 23
23 namespace aura { 24 namespace aura {
24 25
25 using internal::RootWindow; 26 using internal::RootWindow;
26 27
27 Window::Window(WindowDelegate* delegate) 28 Window::Window(WindowDelegate* delegate)
28 : type_(kWindowType_Toplevel), 29 : type_(kWindowType_Toplevel),
29 delegate_(delegate), 30 delegate_(delegate),
30 show_state_(ui::SHOW_STATE_NORMAL), 31 show_state_(ui::SHOW_STATE_NORMAL),
31 parent_(NULL), 32 parent_(NULL),
32 id_(-1), 33 id_(-1),
33 user_data_(NULL), 34 user_data_(NULL),
34 stops_event_propagation_(false) { 35 stops_event_propagation_(false) {
35 } 36 }
36 37
37 Window::~Window() { 38 Window::~Window() {
39 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowClosing(this));
40
38 // Let the delegate know we're in the processing of destroying. 41 // Let the delegate know we're in the processing of destroying.
39 if (delegate_) 42 if (delegate_)
40 delegate_->OnWindowDestroying(); 43 delegate_->OnWindowDestroying();
41 44
42 // Let the root know so that it can remove any references to us. 45 // Let the root know so that it can remove any references to us.
43 RootWindow* root = GetRoot(); 46 RootWindow* root = GetRoot();
44 if (root) 47 if (root)
45 root->WindowDestroying(this); 48 root->WindowDestroying(this);
46 49
47 // Then destroy the children. 50 // Then destroy the children.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 if (show_state_ != ui::SHOW_STATE_NORMAL) { 110 if (show_state_ != ui::SHOW_STATE_NORMAL) {
108 show_state_ = ui::SHOW_STATE_NORMAL; 111 show_state_ = ui::SHOW_STATE_NORMAL;
109 SetBounds(restore_bounds_); 112 SetBounds(restore_bounds_);
110 restore_bounds_.SetRect(0, 0, 0, 0); 113 restore_bounds_.SetRect(0, 0, 0, 0);
111 } 114 }
112 } 115 }
113 116
114 void Window::Activate() { 117 void Window::Activate() {
115 // If we support minimization need to ensure this restores the window first. 118 // If we support minimization need to ensure this restores the window first.
116 aura::Desktop::GetInstance()->SetActiveWindow(this, this); 119 aura::Desktop::GetInstance()->SetActiveWindow(this, this);
120 FOR_EACH_OBSERVER(WindowObserver, observers_,
sky 2011/10/12 22:05:38 This should be up in the Desktop, not here (there
sadrul 2011/10/12 22:59:58 Removed this, added DesktopObserver::OnActiveWindo
121 OnWindowActivationChanged(this, true));
117 } 122 }
118 123
119 void Window::Deactivate() { 124 void Window::Deactivate() {
120 aura::Desktop::GetInstance()->Deactivate(this); 125 aura::Desktop::GetInstance()->Deactivate(this);
126 FOR_EACH_OBSERVER(WindowObserver, observers_,
sky 2011/10/12 22:05:38 Same comment, this should be in Desktop.
sadrul 2011/10/12 22:59:58 Done.
127 OnWindowActivationChanged(this, false));
121 } 128 }
122 129
123 bool Window::IsActive() const { 130 bool Window::IsActive() const {
124 return aura::Desktop::GetInstance()->active_window() == this; 131 return aura::Desktop::GetInstance()->active_window() == this;
125 } 132 }
126 133
127 ToplevelWindowContainer* Window::AsToplevelWindowContainer() { 134 ToplevelWindowContainer* Window::AsToplevelWindowContainer() {
128 return NULL; 135 return NULL;
129 } 136 }
130 137
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 if (!parent_->event_filter_.get()) 259 if (!parent_->event_filter_.get())
253 parent_->SetEventFilter(new EventFilter(parent_)); 260 parent_->SetEventFilter(new EventFilter(parent_));
254 return parent_->event_filter_->OnMouseEvent(this, event) || 261 return parent_->event_filter_->OnMouseEvent(this, event) ||
255 delegate_->OnMouseEvent(event); 262 delegate_->OnMouseEvent(event);
256 } 263 }
257 264
258 bool Window::OnKeyEvent(KeyEvent* event) { 265 bool Window::OnKeyEvent(KeyEvent* event) {
259 return IsVisible() && delegate_->OnKeyEvent(event); 266 return IsVisible() && delegate_->OnKeyEvent(event);
260 } 267 }
261 268
269 void Window::AddObserver(WindowObserver* observer) {
270 observers_.AddObserver(observer);
271 }
272
273 void Window::RemoveObserver(WindowObserver* observer) {
274 observers_.RemoveObserver(observer);
275 }
276
262 bool Window::HitTest(const gfx::Point& point) { 277 bool Window::HitTest(const gfx::Point& point) {
263 gfx::Rect local_bounds(gfx::Point(), bounds().size()); 278 gfx::Rect local_bounds(gfx::Point(), bounds().size());
264 // TODO(beng): hittest masks. 279 // TODO(beng): hittest masks.
265 return local_bounds.Contains(point); 280 return local_bounds.Contains(point);
266 } 281 }
267 282
268 Window* Window::GetEventHandlerForPoint(const gfx::Point& point) { 283 Window* Window::GetEventHandlerForPoint(const gfx::Point& point) {
269 Windows::const_reverse_iterator i = children_.rbegin(); 284 Windows::const_reverse_iterator i = children_.rbegin();
270 for (; i != children_.rend(); ++i) { 285 for (; i != children_.rend(); ++i) {
271 Window* child = *i; 286 Window* child = *i;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 379
365 void Window::SetVisible(bool visible) { 380 void Window::SetVisible(bool visible) {
366 bool was_visible = IsVisible(); 381 bool was_visible = IsVisible();
367 layer_->SetVisible(visible); 382 layer_->SetVisible(visible);
368 bool is_visible = IsVisible(); 383 bool is_visible = IsVisible();
369 if (was_visible != is_visible) { 384 if (was_visible != is_visible) {
370 SchedulePaint(); 385 SchedulePaint();
371 if (delegate_) 386 if (delegate_)
372 delegate_->OnWindowVisibilityChanged(is_visible); 387 delegate_->OnWindowVisibilityChanged(is_visible);
373 } 388 }
389
390 FOR_EACH_OBSERVER(WindowObserver, observers_,
391 OnWindowVisibilityChanged(this, visible));
374 } 392 }
375 393
376 void Window::SchedulePaint() { 394 void Window::SchedulePaint() {
377 SchedulePaintInRect(gfx::Rect(0, 0, bounds().width(), bounds().height())); 395 SchedulePaintInRect(gfx::Rect(0, 0, bounds().width(), bounds().height()));
378 } 396 }
379 397
380 bool Window::StopsEventPropagation() const { 398 bool Window::StopsEventPropagation() const {
381 return stops_event_propagation_ && !children_.empty(); 399 return stops_event_propagation_ && !children_.empty();
382 } 400 }
383 401
384 bool Window::UpdateShowStateAndRestoreBounds( 402 bool Window::UpdateShowStateAndRestoreBounds(
385 ui::WindowShowState new_show_state) { 403 ui::WindowShowState new_show_state) {
386 if (show_state_ == new_show_state) 404 if (show_state_ == new_show_state)
387 return false; 405 return false;
388 show_state_ = new_show_state; 406 show_state_ = new_show_state;
389 if (restore_bounds_.IsEmpty()) 407 if (restore_bounds_.IsEmpty())
390 restore_bounds_ = bounds(); 408 restore_bounds_ = bounds();
391 return true; 409 return true;
392 } 410 }
393 411
394 void Window::OnPaintLayer(gfx::Canvas* canvas) { 412 void Window::OnPaintLayer(gfx::Canvas* canvas) {
395 delegate_->OnPaint(canvas); 413 delegate_->OnPaint(canvas);
396 } 414 }
397 415
398 } // namespace aura 416 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698