OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. | 5 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. |
6 | 6 |
7 #include "ui/views/view.h" | 7 #include "ui/views/view.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 CreateLayer(ui::LAYER_TEXTURED); | 530 CreateLayer(ui::LAYER_TEXTURED); |
531 layer()->SetTransform(transform); | 531 layer()->SetTransform(transform); |
532 layer()->ScheduleDraw(); | 532 layer()->ScheduleDraw(); |
533 } | 533 } |
534 } | 534 } |
535 | 535 |
536 void View::SetPaintToLayer(ui::LayerType layer_type) { | 536 void View::SetPaintToLayer(ui::LayerType layer_type) { |
537 if (paint_to_layer_ && (layer()->type() == layer_type)) | 537 if (paint_to_layer_ && (layer()->type() == layer_type)) |
538 return; | 538 return; |
539 | 539 |
540 DestroyLayer(); | 540 DestroyLayerImpl(LayerChangeNotifyBehavior::DONT_NOTIFY); |
541 CreateLayer(layer_type); | 541 CreateLayer(layer_type); |
542 paint_to_layer_ = true; | 542 paint_to_layer_ = true; |
| 543 |
| 544 // Notify the parent chain about the layer change. |
| 545 NotifyParentsOfLayerChange(); |
543 } | 546 } |
544 | 547 |
545 void View::DestroyLayer() { | 548 void View::DestroyLayer() { |
546 if (!paint_to_layer_) | 549 DestroyLayerImpl(LayerChangeNotifyBehavior::NOTIFY); |
547 return; | |
548 | |
549 paint_to_layer_ = false; | |
550 if (!layer()) | |
551 return; | |
552 | |
553 ui::Layer* new_parent = layer()->parent(); | |
554 std::vector<ui::Layer*> children = layer()->children(); | |
555 for (size_t i = 0; i < children.size(); ++i) { | |
556 layer()->Remove(children[i]); | |
557 if (new_parent) | |
558 new_parent->Add(children[i]); | |
559 } | |
560 | |
561 LayerOwner::DestroyLayer(); | |
562 | |
563 if (new_parent) | |
564 ReorderLayers(); | |
565 | |
566 UpdateChildLayerBounds(CalculateOffsetToAncestorWithLayer(NULL)); | |
567 | |
568 SchedulePaint(); | |
569 | |
570 Widget* widget = GetWidget(); | |
571 if (widget) | |
572 widget->LayerTreeChanged(); | |
573 } | 550 } |
574 | 551 |
575 std::unique_ptr<ui::Layer> View::RecreateLayer() { | 552 std::unique_ptr<ui::Layer> View::RecreateLayer() { |
576 std::unique_ptr<ui::Layer> old_layer = LayerOwner::RecreateLayer(); | 553 std::unique_ptr<ui::Layer> old_layer = LayerOwner::RecreateLayer(); |
577 Widget* widget = GetWidget(); | 554 Widget* widget = GetWidget(); |
578 if (widget) | 555 if (widget) |
579 widget->LayerTreeChanged(); | 556 widget->LayerTreeChanged(); |
580 return old_layer; | 557 return old_layer; |
581 } | 558 } |
582 | 559 |
(...skipping 1038 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1621 void View::UpdateChildLayerVisibility(bool ancestor_visible) { | 1598 void View::UpdateChildLayerVisibility(bool ancestor_visible) { |
1622 if (layer()) { | 1599 if (layer()) { |
1623 layer()->SetVisible(ancestor_visible && visible_); | 1600 layer()->SetVisible(ancestor_visible && visible_); |
1624 } else { | 1601 } else { |
1625 internal::ScopedChildrenLock lock(this); | 1602 internal::ScopedChildrenLock lock(this); |
1626 for (auto* child : children_) | 1603 for (auto* child : children_) |
1627 child->UpdateChildLayerVisibility(ancestor_visible && visible_); | 1604 child->UpdateChildLayerVisibility(ancestor_visible && visible_); |
1628 } | 1605 } |
1629 } | 1606 } |
1630 | 1607 |
| 1608 void View::DestroyLayerImpl(LayerChangeNotifyBehavior notify_parents) { |
| 1609 if (!paint_to_layer_) |
| 1610 return; |
| 1611 |
| 1612 paint_to_layer_ = false; |
| 1613 if (!layer()) |
| 1614 return; |
| 1615 |
| 1616 ui::Layer* new_parent = layer()->parent(); |
| 1617 std::vector<ui::Layer*> children = layer()->children(); |
| 1618 for (size_t i = 0; i < children.size(); ++i) { |
| 1619 layer()->Remove(children[i]); |
| 1620 if (new_parent) |
| 1621 new_parent->Add(children[i]); |
| 1622 } |
| 1623 |
| 1624 LayerOwner::DestroyLayer(); |
| 1625 |
| 1626 if (new_parent) |
| 1627 ReorderLayers(); |
| 1628 |
| 1629 UpdateChildLayerBounds(CalculateOffsetToAncestorWithLayer(NULL)); |
| 1630 |
| 1631 SchedulePaint(); |
| 1632 |
| 1633 // Notify the parent chain about the layer change. |
| 1634 if (notify_parents == LayerChangeNotifyBehavior::NOTIFY) |
| 1635 NotifyParentsOfLayerChange(); |
| 1636 |
| 1637 Widget* widget = GetWidget(); |
| 1638 if (widget) |
| 1639 widget->LayerTreeChanged(); |
| 1640 } |
| 1641 |
| 1642 void View::NotifyParentsOfLayerChange() { |
| 1643 // Notify the parent chain about the layer change. |
| 1644 View* view_parent = parent(); |
| 1645 while (view_parent) { |
| 1646 view_parent->OnChildLayerChanged(this); |
| 1647 view_parent = view_parent->parent(); |
| 1648 } |
| 1649 } |
| 1650 |
1631 void View::UpdateChildLayerBounds(const gfx::Vector2d& offset) { | 1651 void View::UpdateChildLayerBounds(const gfx::Vector2d& offset) { |
1632 if (layer()) { | 1652 if (layer()) { |
1633 SetLayerBounds(GetLocalBounds() + offset); | 1653 SetLayerBounds(GetLocalBounds() + offset); |
1634 } else { | 1654 } else { |
1635 internal::ScopedChildrenLock lock(this); | 1655 internal::ScopedChildrenLock lock(this); |
1636 for (auto* child : children_) { | 1656 for (auto* child : children_) { |
1637 child->UpdateChildLayerBounds( | 1657 child->UpdateChildLayerBounds( |
1638 offset + gfx::Vector2d(child->GetMirroredX(), child->y())); | 1658 offset + gfx::Vector2d(child->GetMirroredX(), child->y())); |
1639 } | 1659 } |
1640 } | 1660 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1689 // Iterate backwards through the children so that a child with a layer | 1709 // Iterate backwards through the children so that a child with a layer |
1690 // which is further to the back is stacked above one which is further to | 1710 // which is further to the back is stacked above one which is further to |
1691 // the front. | 1711 // the front. |
1692 View::Views children = GetChildrenInZOrder(); | 1712 View::Views children = GetChildrenInZOrder(); |
1693 DCHECK_EQ(child_count(), static_cast<int>(children.size())); | 1713 DCHECK_EQ(child_count(), static_cast<int>(children.size())); |
1694 for (auto* child : base::Reversed(children)) | 1714 for (auto* child : base::Reversed(children)) |
1695 child->ReorderChildLayers(parent_layer); | 1715 child->ReorderChildLayers(parent_layer); |
1696 } | 1716 } |
1697 } | 1717 } |
1698 | 1718 |
| 1719 void View::OnChildLayerChanged(View* child) {} |
| 1720 |
1699 // Input ----------------------------------------------------------------------- | 1721 // Input ----------------------------------------------------------------------- |
1700 | 1722 |
1701 View::DragInfo* View::GetDragInfo() { | 1723 View::DragInfo* View::GetDragInfo() { |
1702 return parent_ ? parent_->GetDragInfo() : NULL; | 1724 return parent_ ? parent_->GetDragInfo() : NULL; |
1703 } | 1725 } |
1704 | 1726 |
1705 // Focus ----------------------------------------------------------------------- | 1727 // Focus ----------------------------------------------------------------------- |
1706 | 1728 |
1707 void View::OnFocus() { | 1729 void View::OnFocus() { |
1708 // TODO(beng): Investigate whether it's possible for us to move this to | 1730 // TODO(beng): Investigate whether it's possible for us to move this to |
(...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2640 // Message the RootView to do the drag and drop. That way if we're removed | 2662 // Message the RootView to do the drag and drop. That way if we're removed |
2641 // the RootView can detect it and avoid calling us back. | 2663 // the RootView can detect it and avoid calling us back. |
2642 gfx::Point widget_location(event.location()); | 2664 gfx::Point widget_location(event.location()); |
2643 ConvertPointToWidget(this, &widget_location); | 2665 ConvertPointToWidget(this, &widget_location); |
2644 widget->RunShellDrag(this, data, widget_location, drag_operations, source); | 2666 widget->RunShellDrag(this, data, widget_location, drag_operations, source); |
2645 // WARNING: we may have been deleted. | 2667 // WARNING: we may have been deleted. |
2646 return true; | 2668 return true; |
2647 } | 2669 } |
2648 | 2670 |
2649 } // namespace views | 2671 } // namespace views |
OLD | NEW |