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 #include "ui/views/view.h" | 5 #include "ui/views/view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 | 449 |
450 void View::SetPaintToLayer(bool paint_to_layer) { | 450 void View::SetPaintToLayer(bool paint_to_layer) { |
451 paint_to_layer_ = paint_to_layer; | 451 paint_to_layer_ = paint_to_layer; |
452 if (paint_to_layer_ && !layer()) { | 452 if (paint_to_layer_ && !layer()) { |
453 CreateLayer(); | 453 CreateLayer(); |
454 } else if (!paint_to_layer_ && layer()) { | 454 } else if (!paint_to_layer_ && layer()) { |
455 DestroyLayer(); | 455 DestroyLayer(); |
456 } | 456 } |
457 } | 457 } |
458 | 458 |
| 459 ui::Layer* View::RecreateLayer() { |
| 460 ui::Layer* layer = AcquireLayer(); |
| 461 CreateLayer(); |
| 462 return layer; |
| 463 } |
| 464 |
459 // RTL positioning ------------------------------------------------------------- | 465 // RTL positioning ------------------------------------------------------------- |
460 | 466 |
461 gfx::Rect View::GetMirroredBounds() const { | 467 gfx::Rect View::GetMirroredBounds() const { |
462 gfx::Rect bounds(bounds_); | 468 gfx::Rect bounds(bounds_); |
463 bounds.set_x(GetMirroredX()); | 469 bounds.set_x(GetMirroredX()); |
464 return bounds; | 470 return bounds; |
465 } | 471 } |
466 | 472 |
467 gfx::Point View::GetMirroredPosition() const { | 473 gfx::Point View::GetMirroredPosition() const { |
468 return gfx::Point(GetMirroredX(), y()); | 474 return gfx::Point(GetMirroredX(), y()); |
(...skipping 1305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1774 } | 1780 } |
1775 | 1781 |
1776 // Accelerated painting -------------------------------------------------------- | 1782 // Accelerated painting -------------------------------------------------------- |
1777 | 1783 |
1778 void View::CreateLayer() { | 1784 void View::CreateLayer() { |
1779 // A new layer is being created for the view. So all the layers of the | 1785 // A new layer is being created for the view. So all the layers of the |
1780 // sub-tree can inherit the visibility of the corresponding view. | 1786 // sub-tree can inherit the visibility of the corresponding view. |
1781 for (int i = 0, count = child_count(); i < count; ++i) | 1787 for (int i = 0, count = child_count(); i < count; ++i) |
1782 child_at(i)->UpdateChildLayerVisibility(true); | 1788 child_at(i)->UpdateChildLayerVisibility(true); |
1783 | 1789 |
1784 layer_.reset(new ui::Layer()); | 1790 layer_ = new ui::Layer(); |
| 1791 layer_owner_.reset(layer_); |
1785 layer_->set_delegate(this); | 1792 layer_->set_delegate(this); |
1786 #if !defined(NDEBUG) | 1793 #if !defined(NDEBUG) |
1787 layer_->set_name(GetClassName()); | 1794 layer_->set_name(GetClassName()); |
1788 #endif | 1795 #endif |
1789 | 1796 |
1790 UpdateParentLayers(); | 1797 UpdateParentLayers(); |
1791 UpdateLayerVisibility(); | 1798 UpdateLayerVisibility(); |
1792 | 1799 |
1793 // The new layer needs to be ordered in the layer tree according | 1800 // The new layer needs to be ordered in the layer tree according |
1794 // to the view tree. Children of this layer were added in order | 1801 // to the view tree. Children of this layer were added in order |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1849 | 1856 |
1850 void View::DestroyLayer() { | 1857 void View::DestroyLayer() { |
1851 ui::Layer* new_parent = layer()->parent(); | 1858 ui::Layer* new_parent = layer()->parent(); |
1852 std::vector<ui::Layer*> children = layer()->children(); | 1859 std::vector<ui::Layer*> children = layer()->children(); |
1853 for (size_t i = 0; i < children.size(); ++i) { | 1860 for (size_t i = 0; i < children.size(); ++i) { |
1854 layer()->Remove(children[i]); | 1861 layer()->Remove(children[i]); |
1855 if (new_parent) | 1862 if (new_parent) |
1856 new_parent->Add(children[i]); | 1863 new_parent->Add(children[i]); |
1857 } | 1864 } |
1858 | 1865 |
1859 layer_.reset(); | 1866 layer_ = NULL; |
| 1867 layer_owner_.reset(); |
1860 | 1868 |
1861 if (new_parent) | 1869 if (new_parent) |
1862 ReorderLayers(); | 1870 ReorderLayers(); |
1863 | 1871 |
1864 gfx::Point offset; | 1872 gfx::Point offset; |
1865 CalculateOffsetToAncestorWithLayer(&offset, NULL); | 1873 CalculateOffsetToAncestorWithLayer(&offset, NULL); |
1866 UpdateChildLayerBounds(offset); | 1874 UpdateChildLayerBounds(offset); |
1867 | 1875 |
1868 SchedulePaint(); | 1876 SchedulePaint(); |
1869 } | 1877 } |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2069 gfx::Point widget_location(event.location()); | 2077 gfx::Point widget_location(event.location()); |
2070 ConvertPointToWidget(this, &widget_location); | 2078 ConvertPointToWidget(this, &widget_location); |
2071 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations); | 2079 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations); |
2072 return true; | 2080 return true; |
2073 #else | 2081 #else |
2074 return false; | 2082 return false; |
2075 #endif // !defined(OS_MACOSX) | 2083 #endif // !defined(OS_MACOSX) |
2076 } | 2084 } |
2077 | 2085 |
2078 } // namespace views | 2086 } // namespace views |
OLD | NEW |