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 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
289 // Add it in the specified index now. | 289 // Add it in the specified index now. |
290 InitFocusSiblings(view, index); | 290 InitFocusSiblings(view, index); |
291 children_.insert(children_.begin() + index, view); | 291 children_.insert(children_.begin() + index, view); |
292 | 292 |
293 for (ViewObserver& observer : observers_) | 293 for (ViewObserver& observer : observers_) |
294 observer.OnChildViewReordered(this, view); | 294 observer.OnChildViewReordered(this, view); |
295 | 295 |
296 ReorderLayers(); | 296 ReorderLayers(); |
297 } | 297 } |
298 | 298 |
299 void View::OnChildLayerChanged(View* child) {} | |
300 | |
299 void View::RemoveChildView(View* view) { | 301 void View::RemoveChildView(View* view) { |
300 DoRemoveChildView(view, true, true, false, NULL); | 302 DoRemoveChildView(view, true, true, false, NULL); |
301 } | 303 } |
302 | 304 |
303 void View::RemoveAllChildViews(bool delete_children) { | 305 void View::RemoveAllChildViews(bool delete_children) { |
304 while (!children_.empty()) | 306 while (!children_.empty()) |
305 DoRemoveChildView(children_.front(), false, false, delete_children, NULL); | 307 DoRemoveChildView(children_.front(), false, false, delete_children, NULL); |
306 UpdateTooltip(); | 308 UpdateTooltip(); |
307 } | 309 } |
308 | 310 |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
530 CreateLayer(ui::LAYER_TEXTURED); | 532 CreateLayer(ui::LAYER_TEXTURED); |
531 layer()->SetTransform(transform); | 533 layer()->SetTransform(transform); |
532 layer()->ScheduleDraw(); | 534 layer()->ScheduleDraw(); |
533 } | 535 } |
534 } | 536 } |
535 | 537 |
536 void View::SetPaintToLayer(ui::LayerType layer_type) { | 538 void View::SetPaintToLayer(ui::LayerType layer_type) { |
537 if (paint_to_layer_ && (layer()->type() == layer_type)) | 539 if (paint_to_layer_ && (layer()->type() == layer_type)) |
538 return; | 540 return; |
539 | 541 |
540 DestroyLayer(); | 542 DestroyLayer(); |
sky
2017/04/18 15:35:48
When called from here DestroyLayer() should not ca
ananta
2017/04/18 22:22:39
Done.
| |
541 CreateLayer(layer_type); | 543 CreateLayer(layer_type); |
542 paint_to_layer_ = true; | 544 paint_to_layer_ = true; |
545 | |
546 // Notify the parent chain about the layer change. | |
547 NotifyParentsOfLayerChange(); | |
543 } | 548 } |
544 | 549 |
545 void View::DestroyLayer() { | 550 void View::DestroyLayer() { |
546 if (!paint_to_layer_) | 551 if (!paint_to_layer_) |
547 return; | 552 return; |
548 | 553 |
549 paint_to_layer_ = false; | 554 paint_to_layer_ = false; |
550 if (!layer()) | 555 if (!layer()) |
551 return; | 556 return; |
552 | 557 |
553 ui::Layer* new_parent = layer()->parent(); | 558 ui::Layer* new_parent = layer()->parent(); |
554 std::vector<ui::Layer*> children = layer()->children(); | 559 std::vector<ui::Layer*> children = layer()->children(); |
555 for (size_t i = 0; i < children.size(); ++i) { | 560 for (size_t i = 0; i < children.size(); ++i) { |
556 layer()->Remove(children[i]); | 561 layer()->Remove(children[i]); |
557 if (new_parent) | 562 if (new_parent) |
558 new_parent->Add(children[i]); | 563 new_parent->Add(children[i]); |
559 } | 564 } |
560 | 565 |
561 LayerOwner::DestroyLayer(); | 566 LayerOwner::DestroyLayer(); |
562 | 567 |
563 if (new_parent) | 568 if (new_parent) |
564 ReorderLayers(); | 569 ReorderLayers(); |
565 | 570 |
566 UpdateChildLayerBounds(CalculateOffsetToAncestorWithLayer(NULL)); | 571 UpdateChildLayerBounds(CalculateOffsetToAncestorWithLayer(NULL)); |
567 | 572 |
568 SchedulePaint(); | 573 SchedulePaint(); |
569 | 574 |
575 // Notify the parent chain about the layer change. | |
576 NotifyParentsOfLayerChange(); | |
577 | |
570 Widget* widget = GetWidget(); | 578 Widget* widget = GetWidget(); |
571 if (widget) | 579 if (widget) |
572 widget->LayerTreeChanged(); | 580 widget->LayerTreeChanged(); |
573 } | 581 } |
574 | 582 |
575 std::unique_ptr<ui::Layer> View::RecreateLayer() { | 583 std::unique_ptr<ui::Layer> View::RecreateLayer() { |
576 std::unique_ptr<ui::Layer> old_layer = LayerOwner::RecreateLayer(); | 584 std::unique_ptr<ui::Layer> old_layer = LayerOwner::RecreateLayer(); |
577 Widget* widget = GetWidget(); | 585 Widget* widget = GetWidget(); |
578 if (widget) | 586 if (widget) |
579 widget->LayerTreeChanged(); | 587 widget->LayerTreeChanged(); |
(...skipping 2063 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2643 | 2651 |
2644 // Message the RootView to do the drag and drop. That way if we're removed | 2652 // Message the RootView to do the drag and drop. That way if we're removed |
2645 // the RootView can detect it and avoid calling us back. | 2653 // the RootView can detect it and avoid calling us back. |
2646 gfx::Point widget_location(event.location()); | 2654 gfx::Point widget_location(event.location()); |
2647 ConvertPointToWidget(this, &widget_location); | 2655 ConvertPointToWidget(this, &widget_location); |
2648 widget->RunShellDrag(this, data, widget_location, drag_operations, source); | 2656 widget->RunShellDrag(this, data, widget_location, drag_operations, source); |
2649 // WARNING: we may have been deleted. | 2657 // WARNING: we may have been deleted. |
2650 return true; | 2658 return true; |
2651 } | 2659 } |
2652 | 2660 |
2661 void View::NotifyParentsOfLayerChange() { | |
2662 // Notify the parent chain about the layer change. | |
2663 View* view_parent = parent(); | |
2664 while (view_parent) { | |
2665 view_parent->OnChildLayerChanged(this); | |
2666 view_parent = view_parent->parent(); | |
2667 } | |
2668 } | |
2669 | |
2653 } // namespace views | 2670 } // namespace views |
OLD | NEW |