| 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 "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 STLDeleteElements(&transient_children); | 71 STLDeleteElements(&transient_children); |
| 72 DCHECK(transient_children_.empty()); | 72 DCHECK(transient_children_.empty()); |
| 73 | 73 |
| 74 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowDestroyed(this)); | 74 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowDestroyed(this)); |
| 75 } | 75 } |
| 76 | 76 |
| 77 void Window::Init(ui::Layer::LayerType layer_type) { | 77 void Window::Init(ui::Layer::LayerType layer_type) { |
| 78 layer_.reset(new ui::Layer(layer_type)); | 78 layer_.reset(new ui::Layer(layer_type)); |
| 79 layer_->SetVisible(false); | 79 layer_->SetVisible(false); |
| 80 layer_->set_delegate(this); | 80 layer_->set_delegate(this); |
| 81 |
| 81 #if !defined(NDEBUG) | 82 #if !defined(NDEBUG) |
| 82 std::string layer_name(name_); | 83 std::string layer_name(name_); |
| 83 if (layer_name.empty()) | 84 if (layer_name.empty()) |
| 84 layer_name.append("Unnamed Window"); | 85 layer_name.append("Unnamed Window"); |
| 85 | 86 |
| 86 if (id_ != -1) { | 87 if (id_ != -1) { |
| 87 char id_buf[10]; | 88 char id_buf[10]; |
| 88 base::snprintf(id_buf, sizeof(id_buf), " %d", id_); | 89 base::snprintf(id_buf, sizeof(id_buf), " %d", id_); |
| 89 layer_name.append(id_buf); | 90 layer_name.append(id_buf); |
| 90 } | 91 } |
| 91 layer_->set_name(layer_name); | 92 layer_->set_name(layer_name); |
| 92 #endif | 93 #endif |
| 94 |
| 95 Desktop::GetInstance()->WindowInitialized(this); |
| 93 } | 96 } |
| 94 | 97 |
| 95 void Window::SetType(WindowType type) { | 98 void Window::SetType(WindowType type) { |
| 96 // Cannot change type after the window is initialized. | 99 // Cannot change type after the window is initialized. |
| 97 DCHECK(!layer()); | 100 DCHECK(!layer()); |
| 98 type_ = type; | 101 type_ = type; |
| 99 } | 102 } |
| 100 | 103 |
| 101 void Window::Show() { | 104 void Window::Show() { |
| 102 SetVisible(true); | 105 SetVisible(true); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 // 'child'. | 214 // 'child'. |
| 212 Window* last_transient = child; | 215 Window* last_transient = child; |
| 213 for (Windows::iterator i = child->transient_children_.begin(); | 216 for (Windows::iterator i = child->transient_children_.begin(); |
| 214 i != child->transient_children_.end(); ++i) { | 217 i != child->transient_children_.end(); ++i) { |
| 215 Window* transient_child = *i; | 218 Window* transient_child = *i; |
| 216 if (transient_child->parent_ == this) { | 219 if (transient_child->parent_ == this) { |
| 217 MoveChildAbove(transient_child, last_transient); | 220 MoveChildAbove(transient_child, last_transient); |
| 218 last_transient = transient_child; | 221 last_transient = transient_child; |
| 219 } | 222 } |
| 220 } | 223 } |
| 224 |
| 225 child->OnStackingChanged(); |
| 221 } | 226 } |
| 222 | 227 |
| 223 bool Window::CanActivate() const { | 228 bool Window::CanActivate() const { |
| 224 return IsVisible() && (!delegate_ || delegate_->ShouldActivate(NULL)); | 229 return IsVisible() && (!delegate_ || delegate_->ShouldActivate(NULL)); |
| 225 } | 230 } |
| 226 | 231 |
| 227 void Window::AddChild(Window* child) { | 232 void Window::AddChild(Window* child) { |
| 228 DCHECK(std::find(children_.begin(), children_.end(), child) == | 233 DCHECK(std::find(children_.begin(), children_.end(), child) == |
| 229 children_.end()); | 234 children_.end()); |
| 230 if (child->parent()) | 235 if (child->parent()) |
| 231 child->parent()->RemoveChild(child); | 236 child->parent()->RemoveChild(child); |
| 232 child->parent_ = this; | 237 child->parent_ = this; |
| 238 |
| 233 layer_->Add(child->layer_.get()); | 239 layer_->Add(child->layer_.get()); |
| 240 |
| 234 children_.push_back(child); | 241 children_.push_back(child); |
| 235 if (layout_manager_.get()) | 242 if (layout_manager_.get()) |
| 236 layout_manager_->OnWindowAddedToLayout(child); | 243 layout_manager_->OnWindowAddedToLayout(child); |
| 237 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowAdded(child)); | 244 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowAdded(child)); |
| 245 child->OnParentChanged(); |
| 238 } | 246 } |
| 239 | 247 |
| 240 void Window::AddTransientChild(Window* child) { | 248 void Window::AddTransientChild(Window* child) { |
| 241 if (child->transient_parent_) | 249 if (child->transient_parent_) |
| 242 child->transient_parent_->RemoveTransientChild(child); | 250 child->transient_parent_->RemoveTransientChild(child); |
| 243 DCHECK(std::find(transient_children_.begin(), transient_children_.end(), | 251 DCHECK(std::find(transient_children_.begin(), transient_children_.end(), |
| 244 child) == transient_children_.end()); | 252 child) == transient_children_.end()); |
| 245 transient_children_.push_back(child); | 253 transient_children_.push_back(child); |
| 246 child->transient_parent_ = this; | 254 child->transient_parent_ = this; |
| 247 } | 255 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 260 DCHECK(i != children_.end()); | 268 DCHECK(i != children_.end()); |
| 261 if (layout_manager_.get()) | 269 if (layout_manager_.get()) |
| 262 layout_manager_->OnWillRemoveWindowFromLayout(child); | 270 layout_manager_->OnWillRemoveWindowFromLayout(child); |
| 263 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWillRemoveWindow(child)); | 271 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWillRemoveWindow(child)); |
| 264 aura::Window* desktop = child->GetDesktop(); | 272 aura::Window* desktop = child->GetDesktop(); |
| 265 child->parent_ = NULL; | 273 child->parent_ = NULL; |
| 266 if (desktop) | 274 if (desktop) |
| 267 desktop->WindowDetachedFromDesktop(child); | 275 desktop->WindowDetachedFromDesktop(child); |
| 268 layer_->Remove(child->layer_.get()); | 276 layer_->Remove(child->layer_.get()); |
| 269 children_.erase(i); | 277 children_.erase(i); |
| 278 child->OnParentChanged(); |
| 270 } | 279 } |
| 271 | 280 |
| 272 Window* Window::GetChildById(int id) { | 281 Window* Window::GetChildById(int id) { |
| 273 return const_cast<Window*>(const_cast<const Window*>(this)->GetChildById(id)); | 282 return const_cast<Window*>(const_cast<const Window*>(this)->GetChildById(id)); |
| 274 } | 283 } |
| 275 | 284 |
| 276 const Window* Window::GetChildById(int id) const { | 285 const Window* Window::GetChildById(int id) const { |
| 277 Windows::const_iterator i; | 286 Windows::const_iterator i; |
| 278 for (i = children_.begin(); i != children_.end(); ++i) { | 287 for (i = children_.begin(); i != children_.end(); ++i) { |
| 279 if ((*i)->id() == id) | 288 if ((*i)->id() == id) |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 | 452 |
| 444 // If we're not changing the effective bounds, then we can bail early and skip | 453 // If we're not changing the effective bounds, then we can bail early and skip |
| 445 // notifying our listeners. | 454 // notifying our listeners. |
| 446 if (old_bounds == actual_new_bounds) | 455 if (old_bounds == actual_new_bounds) |
| 447 return; | 456 return; |
| 448 | 457 |
| 449 if (layout_manager_.get()) | 458 if (layout_manager_.get()) |
| 450 layout_manager_->OnWindowResized(); | 459 layout_manager_->OnWindowResized(); |
| 451 if (delegate_) | 460 if (delegate_) |
| 452 delegate_->OnBoundsChanged(old_bounds, actual_new_bounds); | 461 delegate_->OnBoundsChanged(old_bounds, actual_new_bounds); |
| 462 FOR_EACH_OBSERVER(WindowObserver, |
| 463 observers_, |
| 464 OnWindowBoundsChanged(this, actual_new_bounds)); |
| 453 } | 465 } |
| 454 | 466 |
| 455 void Window::SetVisible(bool visible) { | 467 void Window::SetVisible(bool visible) { |
| 456 if (visible == layer_->visible()) | 468 if (visible == layer_->visible()) |
| 457 return; // No change. | 469 return; // No change. |
| 458 | 470 |
| 459 bool was_visible = IsVisible(); | 471 bool was_visible = IsVisible(); |
| 460 layer_->SetVisible(visible); | 472 layer_->SetVisible(visible); |
| 461 bool is_visible = IsVisible(); | 473 bool is_visible = IsVisible(); |
| 462 if (was_visible != is_visible) { | 474 if (was_visible != is_visible) { |
| 463 SchedulePaint(); | 475 SchedulePaint(); |
| 464 if (delegate_) | 476 if (delegate_) |
| 465 delegate_->OnWindowVisibilityChanged(is_visible); | 477 delegate_->OnWindowVisibilityChanged(is_visible); |
| 466 } | 478 } |
| 479 |
| 467 if (parent_ && parent_->layout_manager_.get()) | 480 if (parent_ && parent_->layout_manager_.get()) |
| 468 parent_->layout_manager_->OnChildWindowVisibilityChanged(this, visible); | 481 parent_->layout_manager_->OnChildWindowVisibilityChanged(this, visible); |
| 469 FOR_EACH_OBSERVER(WindowObserver, observers_, | 482 FOR_EACH_OBSERVER(WindowObserver, observers_, |
| 470 OnWindowVisibilityChanged(this, visible)); | 483 OnWindowVisibilityChanged(this, visible)); |
| 471 } | 484 } |
| 472 | 485 |
| 473 void Window::SchedulePaint() { | 486 void Window::SchedulePaint() { |
| 474 SchedulePaintInRect(gfx::Rect(0, 0, bounds().width(), bounds().height())); | 487 SchedulePaintInRect(gfx::Rect(0, 0, bounds().width(), bounds().height())); |
| 475 } | 488 } |
| 476 | 489 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 505 if (match) | 518 if (match) |
| 506 return match; | 519 return match; |
| 507 | 520 |
| 508 if (for_event_handling && child->StopsEventPropagation()) | 521 if (for_event_handling && child->StopsEventPropagation()) |
| 509 break; | 522 break; |
| 510 } | 523 } |
| 511 | 524 |
| 512 return delegate_ ? this : NULL; | 525 return delegate_ ? this : NULL; |
| 513 } | 526 } |
| 514 | 527 |
| 528 void Window::OnParentChanged() { |
| 529 FOR_EACH_OBSERVER( |
| 530 WindowObserver, observers_, OnWindowParentChanged(this, parent_)); |
| 531 } |
| 532 |
| 533 void Window::OnStackingChanged() { |
| 534 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowStackingChanged(this)); |
| 535 } |
| 536 |
| 515 void Window::OnPaintLayer(gfx::Canvas* canvas) { | 537 void Window::OnPaintLayer(gfx::Canvas* canvas) { |
| 516 if (delegate_) | 538 if (delegate_) |
| 517 delegate_->OnPaint(canvas); | 539 delegate_->OnPaint(canvas); |
| 518 } | 540 } |
| 519 | 541 |
| 520 } // namespace aura | 542 } // namespace aura |
| OLD | NEW |