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