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 DestroyLayerImpl(LayerChangeNotifyBehavior::DONT_NOTIFY); | 540 DestroyLayer(); |
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(); | |
546 } | 543 } |
547 | 544 |
548 void View::DestroyLayer() { | 545 void View::DestroyLayer() { |
549 DestroyLayerImpl(LayerChangeNotifyBehavior::NOTIFY); | 546 if (!paint_to_layer_) |
| 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(); |
550 } | 573 } |
551 | 574 |
552 std::unique_ptr<ui::Layer> View::RecreateLayer() { | 575 std::unique_ptr<ui::Layer> View::RecreateLayer() { |
553 std::unique_ptr<ui::Layer> old_layer = LayerOwner::RecreateLayer(); | 576 std::unique_ptr<ui::Layer> old_layer = LayerOwner::RecreateLayer(); |
554 Widget* widget = GetWidget(); | 577 Widget* widget = GetWidget(); |
555 if (widget) | 578 if (widget) |
556 widget->LayerTreeChanged(); | 579 widget->LayerTreeChanged(); |
557 return old_layer; | 580 return old_layer; |
558 } | 581 } |
559 | 582 |
(...skipping 1038 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1598 void View::UpdateChildLayerVisibility(bool ancestor_visible) { | 1621 void View::UpdateChildLayerVisibility(bool ancestor_visible) { |
1599 if (layer()) { | 1622 if (layer()) { |
1600 layer()->SetVisible(ancestor_visible && visible_); | 1623 layer()->SetVisible(ancestor_visible && visible_); |
1601 } else { | 1624 } else { |
1602 internal::ScopedChildrenLock lock(this); | 1625 internal::ScopedChildrenLock lock(this); |
1603 for (auto* child : children_) | 1626 for (auto* child : children_) |
1604 child->UpdateChildLayerVisibility(ancestor_visible && visible_); | 1627 child->UpdateChildLayerVisibility(ancestor_visible && visible_); |
1605 } | 1628 } |
1606 } | 1629 } |
1607 | 1630 |
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 | |
1651 void View::UpdateChildLayerBounds(const gfx::Vector2d& offset) { | 1631 void View::UpdateChildLayerBounds(const gfx::Vector2d& offset) { |
1652 if (layer()) { | 1632 if (layer()) { |
1653 SetLayerBounds(GetLocalBounds() + offset); | 1633 SetLayerBounds(GetLocalBounds() + offset); |
1654 } else { | 1634 } else { |
1655 internal::ScopedChildrenLock lock(this); | 1635 internal::ScopedChildrenLock lock(this); |
1656 for (auto* child : children_) { | 1636 for (auto* child : children_) { |
1657 child->UpdateChildLayerBounds( | 1637 child->UpdateChildLayerBounds( |
1658 offset + gfx::Vector2d(child->GetMirroredX(), child->y())); | 1638 offset + gfx::Vector2d(child->GetMirroredX(), child->y())); |
1659 } | 1639 } |
1660 } | 1640 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1709 // Iterate backwards through the children so that a child with a layer | 1689 // Iterate backwards through the children so that a child with a layer |
1710 // which is further to the back is stacked above one which is further to | 1690 // which is further to the back is stacked above one which is further to |
1711 // the front. | 1691 // the front. |
1712 View::Views children = GetChildrenInZOrder(); | 1692 View::Views children = GetChildrenInZOrder(); |
1713 DCHECK_EQ(child_count(), static_cast<int>(children.size())); | 1693 DCHECK_EQ(child_count(), static_cast<int>(children.size())); |
1714 for (auto* child : base::Reversed(children)) | 1694 for (auto* child : base::Reversed(children)) |
1715 child->ReorderChildLayers(parent_layer); | 1695 child->ReorderChildLayers(parent_layer); |
1716 } | 1696 } |
1717 } | 1697 } |
1718 | 1698 |
1719 void View::OnChildLayerChanged(View* child) {} | |
1720 | |
1721 // Input ----------------------------------------------------------------------- | 1699 // Input ----------------------------------------------------------------------- |
1722 | 1700 |
1723 View::DragInfo* View::GetDragInfo() { | 1701 View::DragInfo* View::GetDragInfo() { |
1724 return parent_ ? parent_->GetDragInfo() : NULL; | 1702 return parent_ ? parent_->GetDragInfo() : NULL; |
1725 } | 1703 } |
1726 | 1704 |
1727 // Focus ----------------------------------------------------------------------- | 1705 // Focus ----------------------------------------------------------------------- |
1728 | 1706 |
1729 void View::OnFocus() { | 1707 void View::OnFocus() { |
1730 // TODO(beng): Investigate whether it's possible for us to move this to | 1708 // 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... |
2662 // Message the RootView to do the drag and drop. That way if we're removed | 2640 // Message the RootView to do the drag and drop. That way if we're removed |
2663 // the RootView can detect it and avoid calling us back. | 2641 // the RootView can detect it and avoid calling us back. |
2664 gfx::Point widget_location(event.location()); | 2642 gfx::Point widget_location(event.location()); |
2665 ConvertPointToWidget(this, &widget_location); | 2643 ConvertPointToWidget(this, &widget_location); |
2666 widget->RunShellDrag(this, data, widget_location, drag_operations, source); | 2644 widget->RunShellDrag(this, data, widget_location, drag_operations, source); |
2667 // WARNING: we may have been deleted. | 2645 // WARNING: we may have been deleted. |
2668 return true; | 2646 return true; |
2669 } | 2647 } |
2670 | 2648 |
2671 } // namespace views | 2649 } // namespace views |
OLD | NEW |