| 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 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. | 5 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. |
| 6 | 6 |
| 7 #include "ui/views/view.h" | 7 #include "ui/views/view.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 if (transform.IsIdentity()) { | 516 if (transform.IsIdentity()) { |
| 517 if (layer()) { | 517 if (layer()) { |
| 518 layer()->SetTransform(transform); | 518 layer()->SetTransform(transform); |
| 519 if (!paint_to_layer_) | 519 if (!paint_to_layer_) |
| 520 DestroyLayer(); | 520 DestroyLayer(); |
| 521 } else { | 521 } else { |
| 522 // Nothing. | 522 // Nothing. |
| 523 } | 523 } |
| 524 } else { | 524 } else { |
| 525 if (!layer()) | 525 if (!layer()) |
| 526 CreateLayer(); | 526 CreateLayer(ui::LAYER_TEXTURED); |
| 527 layer()->SetTransform(transform); | 527 layer()->SetTransform(transform); |
| 528 layer()->ScheduleDraw(); | 528 layer()->ScheduleDraw(); |
| 529 } | 529 } |
| 530 } | 530 } |
| 531 | 531 |
| 532 void View::SetPaintToLayer(bool paint_to_layer) { | 532 void View::SetPaintToLayer(ui::LayerType layer_type) { |
| 533 if (paint_to_layer_ == paint_to_layer) | 533 if (paint_to_layer_) |
| 534 return; | 534 return; |
| 535 | 535 |
| 536 paint_to_layer_ = paint_to_layer; | 536 paint_to_layer_ = true; |
| 537 if (paint_to_layer_ && !layer()) { | 537 if (!layer()) |
| 538 CreateLayer(); | 538 CreateLayer(layer_type); |
| 539 } else if (!paint_to_layer_ && layer()) { | 539 } |
| 540 |
| 541 void View::DetachLayer() { |
| 542 if (!paint_to_layer_) |
| 543 return; |
| 544 |
| 545 paint_to_layer_ = false; |
| 546 if (layer()) |
| 540 DestroyLayer(); | 547 DestroyLayer(); |
| 541 } | |
| 542 } | 548 } |
| 543 | 549 |
| 544 std::unique_ptr<ui::Layer> View::RecreateLayer() { | 550 std::unique_ptr<ui::Layer> View::RecreateLayer() { |
| 545 std::unique_ptr<ui::Layer> old_layer = LayerOwner::RecreateLayer(); | 551 std::unique_ptr<ui::Layer> old_layer = LayerOwner::RecreateLayer(); |
| 546 Widget* widget = GetWidget(); | 552 Widget* widget = GetWidget(); |
| 547 if (widget) | 553 if (widget) |
| 548 widget->UpdateRootLayers(); | 554 widget->UpdateRootLayers(); |
| 549 return old_layer; | 555 return old_layer; |
| 550 } | 556 } |
| 551 | 557 |
| (...skipping 1625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2177 bool View::ConvertRectFromAncestor(const View* ancestor, | 2183 bool View::ConvertRectFromAncestor(const View* ancestor, |
| 2178 gfx::RectF* rect) const { | 2184 gfx::RectF* rect) const { |
| 2179 gfx::Transform trans; | 2185 gfx::Transform trans; |
| 2180 bool result = GetTransformRelativeTo(ancestor, &trans); | 2186 bool result = GetTransformRelativeTo(ancestor, &trans); |
| 2181 trans.TransformRectReverse(rect); | 2187 trans.TransformRectReverse(rect); |
| 2182 return result; | 2188 return result; |
| 2183 } | 2189 } |
| 2184 | 2190 |
| 2185 // Accelerated painting -------------------------------------------------------- | 2191 // Accelerated painting -------------------------------------------------------- |
| 2186 | 2192 |
| 2187 void View::CreateLayer() { | 2193 void View::CreateLayer(ui::LayerType layer_type) { |
| 2188 // A new layer is being created for the view. So all the layers of the | 2194 // A new layer is being created for the view. So all the layers of the |
| 2189 // sub-tree can inherit the visibility of the corresponding view. | 2195 // sub-tree can inherit the visibility of the corresponding view. |
| 2190 { | 2196 { |
| 2191 internal::ScopedChildrenLock lock(this); | 2197 internal::ScopedChildrenLock lock(this); |
| 2192 for (auto* child : children_) | 2198 for (auto* child : children_) |
| 2193 child->UpdateChildLayerVisibility(true); | 2199 child->UpdateChildLayerVisibility(true); |
| 2194 } | 2200 } |
| 2195 | 2201 |
| 2196 SetLayer(base::MakeUnique<ui::Layer>()); | 2202 SetLayer(base::MakeUnique<ui::Layer>(layer_type)); |
| 2197 layer()->set_delegate(this); | 2203 layer()->set_delegate(this); |
| 2198 layer()->set_name(GetClassName()); | 2204 layer()->set_name(GetClassName()); |
| 2199 | 2205 |
| 2200 UpdateParentLayers(); | 2206 UpdateParentLayers(); |
| 2201 UpdateLayerVisibility(); | 2207 UpdateLayerVisibility(); |
| 2202 | 2208 |
| 2203 // The new layer needs to be ordered in the layer tree according | 2209 // The new layer needs to be ordered in the layer tree according |
| 2204 // to the view tree. Children of this layer were added in order | 2210 // to the view tree. Children of this layer were added in order |
| 2205 // in UpdateParentLayers(). | 2211 // in UpdateParentLayers(). |
| 2206 if (parent()) | 2212 if (parent()) |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2546 // Message the RootView to do the drag and drop. That way if we're removed | 2552 // Message the RootView to do the drag and drop. That way if we're removed |
| 2547 // the RootView can detect it and avoid calling us back. | 2553 // the RootView can detect it and avoid calling us back. |
| 2548 gfx::Point widget_location(event.location()); | 2554 gfx::Point widget_location(event.location()); |
| 2549 ConvertPointToWidget(this, &widget_location); | 2555 ConvertPointToWidget(this, &widget_location); |
| 2550 widget->RunShellDrag(this, data, widget_location, drag_operations, source); | 2556 widget->RunShellDrag(this, data, widget_location, drag_operations, source); |
| 2551 // WARNING: we may have been deleted. | 2557 // WARNING: we may have been deleted. |
| 2552 return true; | 2558 return true; |
| 2553 } | 2559 } |
| 2554 | 2560 |
| 2555 } // namespace views | 2561 } // namespace views |
| OLD | NEW |