| 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_ && (layer()->type() == layer_type)) |
| 534 return; | 534 return; |
| 535 | 535 |
| 536 paint_to_layer_ = paint_to_layer; | 536 DestroyLayer(); |
| 537 if (paint_to_layer_ && !layer()) { | 537 CreateLayer(layer_type); |
| 538 CreateLayer(); | 538 paint_to_layer_ = true; |
| 539 } else if (!paint_to_layer_ && layer()) { | 539 } |
| 540 DestroyLayer(); | 540 |
| 541 void View::DestroyLayer() { |
| 542 if (!paint_to_layer_) |
| 543 return; |
| 544 |
| 545 paint_to_layer_ = false; |
| 546 if (!layer()) |
| 547 return; |
| 548 |
| 549 ui::Layer* new_parent = layer()->parent(); |
| 550 std::vector<ui::Layer*> children = layer()->children(); |
| 551 for (size_t i = 0; i < children.size(); ++i) { |
| 552 layer()->Remove(children[i]); |
| 553 if (new_parent) |
| 554 new_parent->Add(children[i]); |
| 541 } | 555 } |
| 556 |
| 557 LayerOwner::DestroyLayer(); |
| 558 |
| 559 if (new_parent) |
| 560 ReorderLayers(); |
| 561 |
| 562 UpdateChildLayerBounds(CalculateOffsetToAncestorWithLayer(NULL)); |
| 563 |
| 564 SchedulePaint(); |
| 565 |
| 566 Widget* widget = GetWidget(); |
| 567 if (widget) |
| 568 widget->UpdateRootLayers(); |
| 542 } | 569 } |
| 543 | 570 |
| 544 std::unique_ptr<ui::Layer> View::RecreateLayer() { | 571 std::unique_ptr<ui::Layer> View::RecreateLayer() { |
| 545 std::unique_ptr<ui::Layer> old_layer = LayerOwner::RecreateLayer(); | 572 std::unique_ptr<ui::Layer> old_layer = LayerOwner::RecreateLayer(); |
| 546 Widget* widget = GetWidget(); | 573 Widget* widget = GetWidget(); |
| 547 if (widget) | 574 if (widget) |
| 548 widget->UpdateRootLayers(); | 575 widget->UpdateRootLayers(); |
| 549 return old_layer; | 576 return old_layer; |
| 550 } | 577 } |
| 551 | 578 |
| (...skipping 1625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2177 bool View::ConvertRectFromAncestor(const View* ancestor, | 2204 bool View::ConvertRectFromAncestor(const View* ancestor, |
| 2178 gfx::RectF* rect) const { | 2205 gfx::RectF* rect) const { |
| 2179 gfx::Transform trans; | 2206 gfx::Transform trans; |
| 2180 bool result = GetTransformRelativeTo(ancestor, &trans); | 2207 bool result = GetTransformRelativeTo(ancestor, &trans); |
| 2181 trans.TransformRectReverse(rect); | 2208 trans.TransformRectReverse(rect); |
| 2182 return result; | 2209 return result; |
| 2183 } | 2210 } |
| 2184 | 2211 |
| 2185 // Accelerated painting -------------------------------------------------------- | 2212 // Accelerated painting -------------------------------------------------------- |
| 2186 | 2213 |
| 2187 void View::CreateLayer() { | 2214 void View::CreateLayer(ui::LayerType layer_type) { |
| 2188 // A new layer is being created for the view. So all the layers of the | 2215 // 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. | 2216 // sub-tree can inherit the visibility of the corresponding view. |
| 2190 { | 2217 { |
| 2191 internal::ScopedChildrenLock lock(this); | 2218 internal::ScopedChildrenLock lock(this); |
| 2192 for (auto* child : children_) | 2219 for (auto* child : children_) |
| 2193 child->UpdateChildLayerVisibility(true); | 2220 child->UpdateChildLayerVisibility(true); |
| 2194 } | 2221 } |
| 2195 | 2222 |
| 2196 SetLayer(base::MakeUnique<ui::Layer>()); | 2223 SetLayer(base::MakeUnique<ui::Layer>(layer_type)); |
| 2197 layer()->set_delegate(this); | 2224 layer()->set_delegate(this); |
| 2198 layer()->set_name(GetClassName()); | 2225 layer()->set_name(GetClassName()); |
| 2199 | 2226 |
| 2200 UpdateParentLayers(); | 2227 UpdateParentLayers(); |
| 2201 UpdateLayerVisibility(); | 2228 UpdateLayerVisibility(); |
| 2202 | 2229 |
| 2203 // The new layer needs to be ordered in the layer tree according | 2230 // 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 | 2231 // to the view tree. Children of this layer were added in order |
| 2205 // in UpdateParentLayers(). | 2232 // in UpdateParentLayers(). |
| 2206 if (parent()) | 2233 if (parent()) |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2253 | 2280 |
| 2254 void View::ReparentLayer(const gfx::Vector2d& offset, ui::Layer* parent_layer) { | 2281 void View::ReparentLayer(const gfx::Vector2d& offset, ui::Layer* parent_layer) { |
| 2255 layer()->SetBounds(GetLocalBounds() + offset); | 2282 layer()->SetBounds(GetLocalBounds() + offset); |
| 2256 DCHECK_NE(layer(), parent_layer); | 2283 DCHECK_NE(layer(), parent_layer); |
| 2257 if (parent_layer) | 2284 if (parent_layer) |
| 2258 parent_layer->Add(layer()); | 2285 parent_layer->Add(layer()); |
| 2259 layer()->SchedulePaint(GetLocalBounds()); | 2286 layer()->SchedulePaint(GetLocalBounds()); |
| 2260 MoveLayerToParent(layer(), gfx::Point()); | 2287 MoveLayerToParent(layer(), gfx::Point()); |
| 2261 } | 2288 } |
| 2262 | 2289 |
| 2263 void View::DestroyLayer() { | |
| 2264 ui::Layer* new_parent = layer()->parent(); | |
| 2265 std::vector<ui::Layer*> children = layer()->children(); | |
| 2266 for (size_t i = 0; i < children.size(); ++i) { | |
| 2267 layer()->Remove(children[i]); | |
| 2268 if (new_parent) | |
| 2269 new_parent->Add(children[i]); | |
| 2270 } | |
| 2271 | |
| 2272 LayerOwner::DestroyLayer(); | |
| 2273 | |
| 2274 if (new_parent) | |
| 2275 ReorderLayers(); | |
| 2276 | |
| 2277 UpdateChildLayerBounds(CalculateOffsetToAncestorWithLayer(NULL)); | |
| 2278 | |
| 2279 SchedulePaint(); | |
| 2280 | |
| 2281 Widget* widget = GetWidget(); | |
| 2282 if (widget) | |
| 2283 widget->UpdateRootLayers(); | |
| 2284 } | |
| 2285 | |
| 2286 // Input ----------------------------------------------------------------------- | 2290 // Input ----------------------------------------------------------------------- |
| 2287 | 2291 |
| 2288 bool View::ProcessMousePressed(const ui::MouseEvent& event) { | 2292 bool View::ProcessMousePressed(const ui::MouseEvent& event) { |
| 2289 int drag_operations = | 2293 int drag_operations = |
| 2290 (enabled_ && event.IsOnlyLeftMouseButton() && | 2294 (enabled_ && event.IsOnlyLeftMouseButton() && |
| 2291 HitTestPoint(event.location())) ? | 2295 HitTestPoint(event.location())) ? |
| 2292 GetDragOperations(event.location()) : 0; | 2296 GetDragOperations(event.location()) : 0; |
| 2293 ContextMenuController* context_menu_controller = event.IsRightMouseButton() ? | 2297 ContextMenuController* context_menu_controller = event.IsRightMouseButton() ? |
| 2294 context_menu_controller_ : 0; | 2298 context_menu_controller_ : 0; |
| 2295 View::DragInfo* drag_info = GetDragInfo(); | 2299 View::DragInfo* drag_info = GetDragInfo(); |
| (...skipping 250 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 | 2550 // 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. | 2551 // the RootView can detect it and avoid calling us back. |
| 2548 gfx::Point widget_location(event.location()); | 2552 gfx::Point widget_location(event.location()); |
| 2549 ConvertPointToWidget(this, &widget_location); | 2553 ConvertPointToWidget(this, &widget_location); |
| 2550 widget->RunShellDrag(this, data, widget_location, drag_operations, source); | 2554 widget->RunShellDrag(this, data, widget_location, drag_operations, source); |
| 2551 // WARNING: we may have been deleted. | 2555 // WARNING: we may have been deleted. |
| 2552 return true; | 2556 return true; |
| 2553 } | 2557 } |
| 2554 | 2558 |
| 2555 } // namespace views | 2559 } // namespace views |
| OLD | NEW |