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