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" | |
22 #include "ui/gfx/interpolated_transform.h" | 21 #include "ui/gfx/interpolated_transform.h" |
23 #include "ui/gfx/path.h" | 22 #include "ui/gfx/path.h" |
24 #include "ui/gfx/point3.h" | 23 #include "ui/gfx/point3.h" |
25 #include "ui/gfx/transform.h" | 24 #include "ui/gfx/transform.h" |
26 #include "views/background.h" | 25 #include "views/background.h" |
27 #include "views/context_menu_controller.h" | 26 #include "views/context_menu_controller.h" |
28 #include "views/drag_controller.h" | 27 #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()->SetTransform(transform); | 427 layer_property_setter_->SetTransform(layer(), 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()->SetTransform(transform); | 436 layer_property_setter_->SetTransform(layer(), 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 |
450 // RTL positioning ------------------------------------------------------------- | 464 // RTL positioning ------------------------------------------------------------- |
451 | 465 |
452 gfx::Rect View::GetMirroredBounds() const { | 466 gfx::Rect View::GetMirroredBounds() const { |
453 gfx::Rect bounds(bounds_); | 467 gfx::Rect bounds(bounds_); |
454 bounds.set_x(GetMirroredX()); | 468 bounds.set_x(GetMirroredX()); |
455 return bounds; | 469 return bounds; |
456 } | 470 } |
457 | 471 |
458 gfx::Point View::GetMirroredPosition() const { | 472 gfx::Point View::GetMirroredPosition() const { |
459 return gfx::Point(GetMirroredX(), y()); | 473 return gfx::Point(GetMirroredX(), y()); |
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1136 if (layer()) { | 1150 if (layer()) { |
1137 layer()->SetVisible(ancestor_visible && IsVisible()); | 1151 layer()->SetVisible(ancestor_visible && IsVisible()); |
1138 } else { | 1152 } else { |
1139 for (int i = 0, count = child_count(); i < count; ++i) | 1153 for (int i = 0, count = child_count(); i < count; ++i) |
1140 child_at(i)->UpdateChildLayerVisibility(ancestor_visible && IsVisible()); | 1154 child_at(i)->UpdateChildLayerVisibility(ancestor_visible && IsVisible()); |
1141 } | 1155 } |
1142 } | 1156 } |
1143 | 1157 |
1144 void View::UpdateChildLayerBounds(const gfx::Point& offset) { | 1158 void View::UpdateChildLayerBounds(const gfx::Point& offset) { |
1145 if (layer()) { | 1159 if (layer()) { |
1146 layer()->SetBounds(gfx::Rect(offset.x(), offset.y(), width(), height())); | 1160 layer_property_setter_->SetBounds(layer(), gfx::Rect(offset.x(), offset.y(), |
| 1161 width(), height())); |
1147 } else { | 1162 } else { |
1148 for (int i = 0, count = child_count(); i < count; ++i) { | 1163 for (int i = 0, count = child_count(); i < count; ++i) { |
1149 gfx::Point new_offset(offset.x() + child_at(i)->x(), | 1164 gfx::Point new_offset(offset.x() + child_at(i)->x(), |
1150 offset.y() + child_at(i)->y()); | 1165 offset.y() + child_at(i)->y()); |
1151 child_at(i)->UpdateChildLayerBounds(new_offset); | 1166 child_at(i)->UpdateChildLayerBounds(new_offset); |
1152 } | 1167 } |
1153 } | 1168 } |
1154 } | 1169 } |
1155 | 1170 |
1156 void View::OnPaintLayer(gfx::Canvas* canvas) { | 1171 void View::OnPaintLayer(gfx::Canvas* canvas) { |
1157 if (!layer() || !layer()->fills_bounds_opaquely()) | 1172 if (!layer() || !layer()->fills_bounds_opaquely()) |
1158 canvas->GetSkCanvas()->drawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); | 1173 canvas->GetSkCanvas()->drawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); |
1159 PaintCommon(canvas); | 1174 PaintCommon(canvas); |
1160 } | 1175 } |
1161 | 1176 |
1162 void View::OnLayerAnimationEnded(const ui::LayerAnimationSequence* animation) { | 1177 void View::OnLayerAnimationEnded(const ui::Animation* animation) { |
1163 } | 1178 } |
1164 | 1179 |
1165 void View::ReorderLayers() { | 1180 void View::ReorderLayers() { |
1166 View* v = this; | 1181 View* v = this; |
1167 while (v && !v->layer()) | 1182 while (v && !v->layer()) |
1168 v = v->parent(); | 1183 v = v->parent(); |
1169 | 1184 |
1170 // Forward to widget in case we're in a NativeWidgetView. | 1185 // Forward to widget in case we're in a NativeWidgetView. |
1171 if (!v) { | 1186 if (!v) { |
1172 if (GetWidget()) | 1187 if (GetWidget()) |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1577 bounds_.size() == previous_bounds.size() ? SCHEDULE_PAINT_SIZE_SAME : | 1592 bounds_.size() == previous_bounds.size() ? SCHEDULE_PAINT_SIZE_SAME : |
1578 SCHEDULE_PAINT_SIZE_CHANGED); | 1593 SCHEDULE_PAINT_SIZE_CHANGED); |
1579 } | 1594 } |
1580 | 1595 |
1581 if (use_acceleration_when_possible) { | 1596 if (use_acceleration_when_possible) { |
1582 if (layer()) { | 1597 if (layer()) { |
1583 if (parent_) { | 1598 if (parent_) { |
1584 gfx::Point offset; | 1599 gfx::Point offset; |
1585 parent_->CalculateOffsetToAncestorWithLayer(&offset, NULL); | 1600 parent_->CalculateOffsetToAncestorWithLayer(&offset, NULL); |
1586 offset.Offset(x(), y()); | 1601 offset.Offset(x(), y()); |
1587 layer()->SetBounds(gfx::Rect(offset, size())); | 1602 layer_property_setter_->SetBounds(layer(), gfx::Rect(offset, size())); |
1588 } else { | 1603 } else { |
1589 layer()->SetBounds(bounds_); | 1604 layer_property_setter_->SetBounds(layer(), bounds_); |
1590 } | 1605 } |
1591 // TODO(beng): this seems redundant with the SchedulePaint at the top of | 1606 // TODO(beng): this seems redundant with the SchedulePaint at the top of |
1592 // this function. explore collapsing. | 1607 // this function. explore collapsing. |
1593 if (previous_bounds.size() != bounds_.size() && | 1608 if (previous_bounds.size() != bounds_.size() && |
1594 !layer()->layer_updated_externally()) { | 1609 !layer()->layer_updated_externally()) { |
1595 // If our bounds have changed then we need to update the complete | 1610 // If our bounds have changed then we need to update the complete |
1596 // texture. | 1611 // texture. |
1597 layer()->SchedulePaint(GetLocalBounds()); | 1612 layer()->SchedulePaint(GetLocalBounds()); |
1598 } | 1613 } |
1599 } else { | 1614 } else { |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1763 // Accelerated painting -------------------------------------------------------- | 1778 // Accelerated painting -------------------------------------------------------- |
1764 | 1779 |
1765 void View::CreateLayer() { | 1780 void View::CreateLayer() { |
1766 // A new layer is being created for the view. So all the layers of the | 1781 // A new layer is being created for the view. So all the layers of the |
1767 // sub-tree can inherit the visibility of the corresponding view. | 1782 // sub-tree can inherit the visibility of the corresponding view. |
1768 for (int i = 0, count = child_count(); i < count; ++i) | 1783 for (int i = 0, count = child_count(); i < count; ++i) |
1769 child_at(i)->UpdateChildLayerVisibility(true); | 1784 child_at(i)->UpdateChildLayerVisibility(true); |
1770 | 1785 |
1771 layer_.reset(new ui::Layer(NULL)); | 1786 layer_.reset(new ui::Layer(NULL)); |
1772 layer_->set_delegate(this); | 1787 layer_->set_delegate(this); |
| 1788 if (layer_property_setter_.get()) |
| 1789 layer_property_setter_->Installed(layer()); |
| 1790 else |
| 1791 SetLayerPropertySetter(NULL); |
1773 | 1792 |
1774 UpdateParentLayers(); | 1793 UpdateParentLayers(); |
1775 UpdateLayerVisibility(); | 1794 UpdateLayerVisibility(); |
1776 | 1795 |
1777 // The new layer needs to be ordered in the layer tree according | 1796 // The new layer needs to be ordered in the layer tree according |
1778 // to the view tree. Children of this layer were added in order | 1797 // to the view tree. Children of this layer were added in order |
1779 // in UpdateParentLayers(). | 1798 // in UpdateParentLayers(). |
1780 if (parent()) | 1799 if (parent()) |
1781 parent()->ReorderLayers(); | 1800 parent()->ReorderLayers(); |
1782 } | 1801 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1833 | 1852 |
1834 void View::DestroyLayer() { | 1853 void View::DestroyLayer() { |
1835 ui::Layer* new_parent = layer()->parent(); | 1854 ui::Layer* new_parent = layer()->parent(); |
1836 std::vector<ui::Layer*> children = layer()->children(); | 1855 std::vector<ui::Layer*> children = layer()->children(); |
1837 for (size_t i = 0; i < children.size(); ++i) { | 1856 for (size_t i = 0; i < children.size(); ++i) { |
1838 layer()->Remove(children[i]); | 1857 layer()->Remove(children[i]); |
1839 if (new_parent) | 1858 if (new_parent) |
1840 new_parent->Add(children[i]); | 1859 new_parent->Add(children[i]); |
1841 } | 1860 } |
1842 | 1861 |
| 1862 if (layer_property_setter_.get()) |
| 1863 layer_property_setter_->Uninstalled(layer()); |
| 1864 |
1843 layer_.reset(); | 1865 layer_.reset(); |
1844 | 1866 |
1845 if (new_parent) | 1867 if (new_parent) |
1846 ReorderLayers(); | 1868 ReorderLayers(); |
1847 | 1869 |
1848 gfx::Point offset; | 1870 gfx::Point offset; |
1849 CalculateOffsetToAncestorWithLayer(&offset, NULL); | 1871 CalculateOffsetToAncestorWithLayer(&offset, NULL); |
1850 UpdateChildLayerBounds(offset); | 1872 UpdateChildLayerBounds(offset); |
1851 | 1873 |
1852 SchedulePaint(); | 1874 SchedulePaint(); |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2056 | 2078 |
2057 OSExchangeData data; | 2079 OSExchangeData data; |
2058 WriteDragData(press_pt, &data); | 2080 WriteDragData(press_pt, &data); |
2059 | 2081 |
2060 // Message the RootView to do the drag and drop. That way if we're removed | 2082 // Message the RootView to do the drag and drop. That way if we're removed |
2061 // the RootView can detect it and avoid calling us back. | 2083 // the RootView can detect it and avoid calling us back. |
2062 GetWidget()->RunShellDrag(this, data, drag_operations); | 2084 GetWidget()->RunShellDrag(this, data, drag_operations); |
2063 } | 2085 } |
2064 | 2086 |
2065 } // namespace views | 2087 } // namespace views |
OLD | NEW |