| OLD | NEW |
| 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" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 : type_(kWindowType_Toplevel), | 28 : type_(kWindowType_Toplevel), |
| 29 delegate_(delegate), | 29 delegate_(delegate), |
| 30 show_state_(ui::SHOW_STATE_NORMAL), | 30 show_state_(ui::SHOW_STATE_NORMAL), |
| 31 parent_(NULL), | 31 parent_(NULL), |
| 32 id_(-1), | 32 id_(-1), |
| 33 user_data_(NULL), | 33 user_data_(NULL), |
| 34 stops_event_propagation_(false) { | 34 stops_event_propagation_(false) { |
| 35 } | 35 } |
| 36 | 36 |
| 37 Window::~Window() { | 37 Window::~Window() { |
| 38 FOR_EACH_OBSERVER(Observer, observers_, OnWindowClosing(this)); |
| 39 |
| 38 // Let the delegate know we're in the processing of destroying. | 40 // Let the delegate know we're in the processing of destroying. |
| 39 if (delegate_) | 41 if (delegate_) |
| 40 delegate_->OnWindowDestroying(); | 42 delegate_->OnWindowDestroying(); |
| 41 | 43 |
| 42 // Let the root know so that it can remove any references to us. | 44 // Let the root know so that it can remove any references to us. |
| 43 RootWindow* root = GetRoot(); | 45 RootWindow* root = GetRoot(); |
| 44 if (root) | 46 if (root) |
| 45 root->WindowDestroying(this); | 47 root->WindowDestroying(this); |
| 46 | 48 |
| 47 // Then destroy the children. | 49 // Then destroy the children. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 if (show_state_ != ui::SHOW_STATE_NORMAL) { | 109 if (show_state_ != ui::SHOW_STATE_NORMAL) { |
| 108 show_state_ = ui::SHOW_STATE_NORMAL; | 110 show_state_ = ui::SHOW_STATE_NORMAL; |
| 109 SetBounds(restore_bounds_); | 111 SetBounds(restore_bounds_); |
| 110 restore_bounds_.SetRect(0, 0, 0, 0); | 112 restore_bounds_.SetRect(0, 0, 0, 0); |
| 111 } | 113 } |
| 112 } | 114 } |
| 113 | 115 |
| 114 void Window::Activate() { | 116 void Window::Activate() { |
| 115 // If we support minimization need to ensure this restores the window first. | 117 // If we support minimization need to ensure this restores the window first. |
| 116 aura::Desktop::GetInstance()->SetActiveWindow(this, this); | 118 aura::Desktop::GetInstance()->SetActiveWindow(this, this); |
| 119 FOR_EACH_OBSERVER(Observer, observers_, |
| 120 OnWindowActivationChanged(this, true)); |
| 117 } | 121 } |
| 118 | 122 |
| 119 void Window::Deactivate() { | 123 void Window::Deactivate() { |
| 120 aura::Desktop::GetInstance()->Deactivate(this); | 124 aura::Desktop::GetInstance()->Deactivate(this); |
| 125 FOR_EACH_OBSERVER(Observer, observers_, |
| 126 OnWindowActivationChanged(this, false)); |
| 121 } | 127 } |
| 122 | 128 |
| 123 bool Window::IsActive() const { | 129 bool Window::IsActive() const { |
| 124 return aura::Desktop::GetInstance()->active_window() == this; | 130 return aura::Desktop::GetInstance()->active_window() == this; |
| 125 } | 131 } |
| 126 | 132 |
| 127 ToplevelWindowContainer* Window::AsToplevelWindowContainer() { | 133 ToplevelWindowContainer* Window::AsToplevelWindowContainer() { |
| 128 return NULL; | 134 return NULL; |
| 129 } | 135 } |
| 130 | 136 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 if (!parent_->event_filter_.get()) | 258 if (!parent_->event_filter_.get()) |
| 253 parent_->SetEventFilter(new EventFilter(parent_)); | 259 parent_->SetEventFilter(new EventFilter(parent_)); |
| 254 return parent_->event_filter_->OnMouseEvent(this, event) || | 260 return parent_->event_filter_->OnMouseEvent(this, event) || |
| 255 delegate_->OnMouseEvent(event); | 261 delegate_->OnMouseEvent(event); |
| 256 } | 262 } |
| 257 | 263 |
| 258 bool Window::OnKeyEvent(KeyEvent* event) { | 264 bool Window::OnKeyEvent(KeyEvent* event) { |
| 259 return IsVisible() && delegate_->OnKeyEvent(event); | 265 return IsVisible() && delegate_->OnKeyEvent(event); |
| 260 } | 266 } |
| 261 | 267 |
| 268 void Window::AddObserver(Window::Observer* observer) { |
| 269 observers_.AddObserver(observer); |
| 270 } |
| 271 |
| 272 void Window::RemoveObserver(Window::Observer* observer) { |
| 273 observers_.RemoveObserver(observer); |
| 274 } |
| 275 |
| 276 bool Window::HasObserver(Window::Observer* observer) { |
| 277 return observers_.HasObserver(observer); |
| 278 } |
| 279 |
| 262 bool Window::HitTest(const gfx::Point& point) { | 280 bool Window::HitTest(const gfx::Point& point) { |
| 263 gfx::Rect local_bounds(gfx::Point(), bounds().size()); | 281 gfx::Rect local_bounds(gfx::Point(), bounds().size()); |
| 264 // TODO(beng): hittest masks. | 282 // TODO(beng): hittest masks. |
| 265 return local_bounds.Contains(point); | 283 return local_bounds.Contains(point); |
| 266 } | 284 } |
| 267 | 285 |
| 268 Window* Window::GetEventHandlerForPoint(const gfx::Point& point) { | 286 Window* Window::GetEventHandlerForPoint(const gfx::Point& point) { |
| 269 Windows::const_reverse_iterator i = children_.rbegin(); | 287 Windows::const_reverse_iterator i = children_.rbegin(); |
| 270 for (; i != children_.rend(); ++i) { | 288 for (; i != children_.rend(); ++i) { |
| 271 Window* child = *i; | 289 Window* child = *i; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 | 382 |
| 365 void Window::SetVisible(bool visible) { | 383 void Window::SetVisible(bool visible) { |
| 366 bool was_visible = IsVisible(); | 384 bool was_visible = IsVisible(); |
| 367 layer_->SetVisible(visible); | 385 layer_->SetVisible(visible); |
| 368 bool is_visible = IsVisible(); | 386 bool is_visible = IsVisible(); |
| 369 if (was_visible != is_visible) { | 387 if (was_visible != is_visible) { |
| 370 SchedulePaint(); | 388 SchedulePaint(); |
| 371 if (delegate_) | 389 if (delegate_) |
| 372 delegate_->OnWindowVisibilityChanged(is_visible); | 390 delegate_->OnWindowVisibilityChanged(is_visible); |
| 373 } | 391 } |
| 392 |
| 393 FOR_EACH_OBSERVER(Observer, observers_, |
| 394 OnWindowVisibilityChanged(this, visible)); |
| 374 } | 395 } |
| 375 | 396 |
| 376 void Window::SchedulePaint() { | 397 void Window::SchedulePaint() { |
| 377 SchedulePaintInRect(gfx::Rect(0, 0, bounds().width(), bounds().height())); | 398 SchedulePaintInRect(gfx::Rect(0, 0, bounds().width(), bounds().height())); |
| 378 } | 399 } |
| 379 | 400 |
| 380 bool Window::StopsEventPropagation() const { | 401 bool Window::StopsEventPropagation() const { |
| 381 return stops_event_propagation_ && !children_.empty(); | 402 return stops_event_propagation_ && !children_.empty(); |
| 382 } | 403 } |
| 383 | 404 |
| 384 bool Window::UpdateShowStateAndRestoreBounds( | 405 bool Window::UpdateShowStateAndRestoreBounds( |
| 385 ui::WindowShowState new_show_state) { | 406 ui::WindowShowState new_show_state) { |
| 386 if (show_state_ == new_show_state) | 407 if (show_state_ == new_show_state) |
| 387 return false; | 408 return false; |
| 388 show_state_ = new_show_state; | 409 show_state_ = new_show_state; |
| 389 if (restore_bounds_.IsEmpty()) | 410 if (restore_bounds_.IsEmpty()) |
| 390 restore_bounds_ = bounds(); | 411 restore_bounds_ = bounds(); |
| 391 return true; | 412 return true; |
| 392 } | 413 } |
| 393 | 414 |
| 394 void Window::OnPaintLayer(gfx::Canvas* canvas) { | 415 void Window::OnPaintLayer(gfx::Canvas* canvas) { |
| 395 delegate_->OnPaint(canvas); | 416 delegate_->OnPaint(canvas); |
| 396 } | 417 } |
| 397 | 418 |
| 398 } // namespace aura | 419 } // namespace aura |
| OLD | NEW |