| 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 "views/view.h" | 5 #include "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" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "third_party/skia/include/core/SkRect.h" | 15 #include "third_party/skia/include/core/SkRect.h" |
| 16 #include "ui/base/accessibility/accessibility_types.h" | 16 #include "ui/base/accessibility/accessibility_types.h" |
| 17 #include "ui/base/dragdrop/drag_drop_types.h" | 17 #include "ui/base/dragdrop/drag_drop_types.h" |
| 18 #include "ui/gfx/canvas_skia.h" | 18 #include "ui/gfx/canvas_skia.h" |
| 19 #include "ui/gfx/compositor/compositor.h" | 19 #include "ui/gfx/compositor/compositor.h" |
| 20 #include "ui/gfx/compositor/layer.h" | 20 #include "ui/gfx/compositor/layer.h" |
| 21 #include "ui/gfx/compositor/layer_animator.h" |
| 21 #include "ui/gfx/interpolated_transform.h" | 22 #include "ui/gfx/interpolated_transform.h" |
| 22 #include "ui/gfx/path.h" | 23 #include "ui/gfx/path.h" |
| 23 #include "ui/gfx/point3.h" | 24 #include "ui/gfx/point3.h" |
| 24 #include "ui/gfx/transform.h" | 25 #include "ui/gfx/transform.h" |
| 25 #include "views/background.h" | 26 #include "views/background.h" |
| 26 #include "views/context_menu_controller.h" | 27 #include "views/context_menu_controller.h" |
| 27 #include "views/drag_controller.h" | 28 #include "views/drag_controller.h" |
| 28 #include "views/layer_property_setter.h" | |
| 29 #include "views/layout/layout_manager.h" | 29 #include "views/layout/layout_manager.h" |
| 30 #include "views/views_delegate.h" | 30 #include "views/views_delegate.h" |
| 31 #include "views/widget/native_widget_private.h" | 31 #include "views/widget/native_widget_private.h" |
| 32 #include "views/widget/native_widget_views.h" | 32 #include "views/widget/native_widget_views.h" |
| 33 #include "views/widget/root_view.h" | 33 #include "views/widget/root_view.h" |
| 34 #include "views/widget/tooltip_manager.h" | 34 #include "views/widget/tooltip_manager.h" |
| 35 #include "views/widget/widget.h" | 35 #include "views/widget/widget.h" |
| 36 | 36 |
| 37 #if defined(OS_WIN) | 37 #if defined(OS_WIN) |
| 38 #include "base/win/scoped_gdi_object.h" | 38 #include "base/win/scoped_gdi_object.h" |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 // Transformations ------------------------------------------------------------- | 417 // Transformations ------------------------------------------------------------- |
| 418 | 418 |
| 419 const ui::Transform& View::GetTransform() const { | 419 const ui::Transform& View::GetTransform() const { |
| 420 static const ui::Transform* no_op = new ui::Transform; | 420 static const ui::Transform* no_op = new ui::Transform; |
| 421 return layer() ? layer()->transform() : *no_op; | 421 return layer() ? layer()->transform() : *no_op; |
| 422 } | 422 } |
| 423 | 423 |
| 424 void View::SetTransform(const ui::Transform& transform) { | 424 void View::SetTransform(const ui::Transform& transform) { |
| 425 if (!transform.HasChange()) { | 425 if (!transform.HasChange()) { |
| 426 if (layer()) { | 426 if (layer()) { |
| 427 layer_property_setter_->SetTransform(layer(), transform); | 427 layer()->SetTransform(transform); |
| 428 if (!paint_to_layer_) | 428 if (!paint_to_layer_) |
| 429 DestroyLayer(); | 429 DestroyLayer(); |
| 430 } else { | 430 } else { |
| 431 // Nothing. | 431 // Nothing. |
| 432 } | 432 } |
| 433 } else { | 433 } else { |
| 434 if (!layer()) | 434 if (!layer()) |
| 435 CreateLayer(); | 435 CreateLayer(); |
| 436 layer_property_setter_->SetTransform(layer(), transform); | 436 layer()->SetTransform(transform); |
| 437 layer()->ScheduleDraw(); | 437 layer()->ScheduleDraw(); |
| 438 } | 438 } |
| 439 } | 439 } |
| 440 | 440 |
| 441 void View::SetPaintToLayer(bool paint_to_layer) { | 441 void View::SetPaintToLayer(bool paint_to_layer) { |
| 442 paint_to_layer_ = paint_to_layer; | 442 paint_to_layer_ = paint_to_layer; |
| 443 if (paint_to_layer_ && !layer()) { | 443 if (paint_to_layer_ && !layer()) { |
| 444 CreateLayer(); | 444 CreateLayer(); |
| 445 } else if (!paint_to_layer_ && layer()) { | 445 } else if (!paint_to_layer_ && layer()) { |
| 446 DestroyLayer(); | 446 DestroyLayer(); |
| 447 } | 447 } |
| 448 } | 448 } |
| 449 | 449 |
| 450 void View::SetLayerPropertySetter(LayerPropertySetter* setter) { | |
| 451 DCHECK(layer()); | |
| 452 LayerPropertySetter* old_setter = layer_property_setter_.get(); | |
| 453 if (!layer() || (old_setter && old_setter == setter)) | |
| 454 return; | |
| 455 if (!setter) | |
| 456 setter = LayerPropertySetter::CreateDefaultSetter(); | |
| 457 | |
| 458 if (old_setter) | |
| 459 old_setter->Uninstalled(layer()); | |
| 460 layer_property_setter_.reset(setter); | |
| 461 layer_property_setter_->Installed(layer()); | |
| 462 } | |
| 463 | |
| 464 // RTL positioning ------------------------------------------------------------- | 450 // RTL positioning ------------------------------------------------------------- |
| 465 | 451 |
| 466 gfx::Rect View::GetMirroredBounds() const { | 452 gfx::Rect View::GetMirroredBounds() const { |
| 467 gfx::Rect bounds(bounds_); | 453 gfx::Rect bounds(bounds_); |
| 468 bounds.set_x(GetMirroredX()); | 454 bounds.set_x(GetMirroredX()); |
| 469 return bounds; | 455 return bounds; |
| 470 } | 456 } |
| 471 | 457 |
| 472 gfx::Point View::GetMirroredPosition() const { | 458 gfx::Point View::GetMirroredPosition() const { |
| 473 return gfx::Point(GetMirroredX(), y()); | 459 return gfx::Point(GetMirroredX(), y()); |
| (...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1148 if (layer()) { | 1134 if (layer()) { |
| 1149 layer()->SetVisible(ancestor_visible && IsVisible()); | 1135 layer()->SetVisible(ancestor_visible && IsVisible()); |
| 1150 } else { | 1136 } else { |
| 1151 for (int i = 0, count = child_count(); i < count; ++i) | 1137 for (int i = 0, count = child_count(); i < count; ++i) |
| 1152 child_at(i)->UpdateChildLayerVisibility(ancestor_visible && IsVisible()); | 1138 child_at(i)->UpdateChildLayerVisibility(ancestor_visible && IsVisible()); |
| 1153 } | 1139 } |
| 1154 } | 1140 } |
| 1155 | 1141 |
| 1156 void View::UpdateChildLayerBounds(const gfx::Point& offset) { | 1142 void View::UpdateChildLayerBounds(const gfx::Point& offset) { |
| 1157 if (layer()) { | 1143 if (layer()) { |
| 1158 layer_property_setter_->SetBounds(layer(), gfx::Rect(offset.x(), offset.y(), | 1144 layer()->SetBounds(gfx::Rect(offset.x(), offset.y(), width(), height())); |
| 1159 width(), height())); | |
| 1160 } else { | 1145 } else { |
| 1161 for (int i = 0, count = child_count(); i < count; ++i) { | 1146 for (int i = 0, count = child_count(); i < count; ++i) { |
| 1162 gfx::Point new_offset(offset.x() + child_at(i)->x(), | 1147 gfx::Point new_offset(offset.x() + child_at(i)->x(), |
| 1163 offset.y() + child_at(i)->y()); | 1148 offset.y() + child_at(i)->y()); |
| 1164 child_at(i)->UpdateChildLayerBounds(new_offset); | 1149 child_at(i)->UpdateChildLayerBounds(new_offset); |
| 1165 } | 1150 } |
| 1166 } | 1151 } |
| 1167 } | 1152 } |
| 1168 | 1153 |
| 1169 void View::OnPaintLayer(gfx::Canvas* canvas) { | 1154 void View::OnPaintLayer(gfx::Canvas* canvas) { |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1586 bounds_.size() == previous_bounds.size() ? SCHEDULE_PAINT_SIZE_SAME : | 1571 bounds_.size() == previous_bounds.size() ? SCHEDULE_PAINT_SIZE_SAME : |
| 1587 SCHEDULE_PAINT_SIZE_CHANGED); | 1572 SCHEDULE_PAINT_SIZE_CHANGED); |
| 1588 } | 1573 } |
| 1589 | 1574 |
| 1590 if (use_acceleration_when_possible) { | 1575 if (use_acceleration_when_possible) { |
| 1591 if (layer()) { | 1576 if (layer()) { |
| 1592 if (parent_) { | 1577 if (parent_) { |
| 1593 gfx::Point offset; | 1578 gfx::Point offset; |
| 1594 parent_->CalculateOffsetToAncestorWithLayer(&offset, NULL); | 1579 parent_->CalculateOffsetToAncestorWithLayer(&offset, NULL); |
| 1595 offset.Offset(x(), y()); | 1580 offset.Offset(x(), y()); |
| 1596 layer_property_setter_->SetBounds(layer(), gfx::Rect(offset, size())); | 1581 layer()->SetBounds(gfx::Rect(offset, size())); |
| 1597 } else { | 1582 } else { |
| 1598 layer_property_setter_->SetBounds(layer(), bounds_); | 1583 layer()->SetBounds(bounds_); |
| 1599 } | 1584 } |
| 1600 // TODO(beng): this seems redundant with the SchedulePaint at the top of | 1585 // TODO(beng): this seems redundant with the SchedulePaint at the top of |
| 1601 // this function. explore collapsing. | 1586 // this function. explore collapsing. |
| 1602 if (previous_bounds.size() != bounds_.size() && | 1587 if (previous_bounds.size() != bounds_.size() && |
| 1603 !layer()->layer_updated_externally()) { | 1588 !layer()->layer_updated_externally()) { |
| 1604 // If our bounds have changed then we need to update the complete | 1589 // If our bounds have changed then we need to update the complete |
| 1605 // texture. | 1590 // texture. |
| 1606 layer()->SchedulePaint(GetLocalBounds()); | 1591 layer()->SchedulePaint(GetLocalBounds()); |
| 1607 } | 1592 } |
| 1608 } else { | 1593 } else { |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1772 // Accelerated painting -------------------------------------------------------- | 1757 // Accelerated painting -------------------------------------------------------- |
| 1773 | 1758 |
| 1774 void View::CreateLayer() { | 1759 void View::CreateLayer() { |
| 1775 // A new layer is being created for the view. So all the layers of the | 1760 // A new layer is being created for the view. So all the layers of the |
| 1776 // sub-tree can inherit the visibility of the corresponding view. | 1761 // sub-tree can inherit the visibility of the corresponding view. |
| 1777 for (int i = 0, count = child_count(); i < count; ++i) | 1762 for (int i = 0, count = child_count(); i < count; ++i) |
| 1778 child_at(i)->UpdateChildLayerVisibility(true); | 1763 child_at(i)->UpdateChildLayerVisibility(true); |
| 1779 | 1764 |
| 1780 layer_.reset(new ui::Layer(NULL)); | 1765 layer_.reset(new ui::Layer(NULL)); |
| 1781 layer_->set_delegate(this); | 1766 layer_->set_delegate(this); |
| 1782 if (layer_property_setter_.get()) | |
| 1783 layer_property_setter_->Installed(layer()); | |
| 1784 else | |
| 1785 SetLayerPropertySetter(NULL); | |
| 1786 | 1767 |
| 1787 UpdateParentLayers(); | 1768 UpdateParentLayers(); |
| 1788 UpdateLayerVisibility(); | 1769 UpdateLayerVisibility(); |
| 1789 | 1770 |
| 1790 // The new layer needs to be ordered in the layer tree according | 1771 // The new layer needs to be ordered in the layer tree according |
| 1791 // to the view tree. Children of this layer were added in order | 1772 // to the view tree. Children of this layer were added in order |
| 1792 // in UpdateParentLayers(). | 1773 // in UpdateParentLayers(). |
| 1793 if (parent()) | 1774 if (parent()) |
| 1794 parent()->ReorderLayers(); | 1775 parent()->ReorderLayers(); |
| 1795 } | 1776 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1846 | 1827 |
| 1847 void View::DestroyLayer() { | 1828 void View::DestroyLayer() { |
| 1848 ui::Layer* new_parent = layer()->parent(); | 1829 ui::Layer* new_parent = layer()->parent(); |
| 1849 std::vector<ui::Layer*> children = layer()->children(); | 1830 std::vector<ui::Layer*> children = layer()->children(); |
| 1850 for (size_t i = 0; i < children.size(); ++i) { | 1831 for (size_t i = 0; i < children.size(); ++i) { |
| 1851 layer()->Remove(children[i]); | 1832 layer()->Remove(children[i]); |
| 1852 if (new_parent) | 1833 if (new_parent) |
| 1853 new_parent->Add(children[i]); | 1834 new_parent->Add(children[i]); |
| 1854 } | 1835 } |
| 1855 | 1836 |
| 1856 if (layer_property_setter_.get()) | |
| 1857 layer_property_setter_->Uninstalled(layer()); | |
| 1858 | |
| 1859 layer_.reset(); | 1837 layer_.reset(); |
| 1860 | 1838 |
| 1861 if (new_parent) | 1839 if (new_parent) |
| 1862 ReorderLayers(); | 1840 ReorderLayers(); |
| 1863 | 1841 |
| 1864 gfx::Point offset; | 1842 gfx::Point offset; |
| 1865 CalculateOffsetToAncestorWithLayer(&offset, NULL); | 1843 CalculateOffsetToAncestorWithLayer(&offset, NULL); |
| 1866 UpdateChildLayerBounds(offset); | 1844 UpdateChildLayerBounds(offset); |
| 1867 | 1845 |
| 1868 SchedulePaint(); | 1846 SchedulePaint(); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2072 | 2050 |
| 2073 OSExchangeData data; | 2051 OSExchangeData data; |
| 2074 WriteDragData(press_pt, &data); | 2052 WriteDragData(press_pt, &data); |
| 2075 | 2053 |
| 2076 // Message the RootView to do the drag and drop. That way if we're removed | 2054 // Message the RootView to do the drag and drop. That way if we're removed |
| 2077 // the RootView can detect it and avoid calling us back. | 2055 // the RootView can detect it and avoid calling us back. |
| 2078 GetWidget()->RunShellDrag(this, data, drag_operations); | 2056 GetWidget()->RunShellDrag(this, data, drag_operations); |
| 2079 } | 2057 } |
| 2080 | 2058 |
| 2081 } // namespace views | 2059 } // namespace views |
| OLD | NEW |