Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: ui/views/view.cc

Issue 2813353002: Ensure that the focus ring in the bookmarks bar does not paint outside the parent view. (Closed)
Patch Set: Fix compile failures Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 CreateLayer(ui::LAYER_TEXTURED); 530 CreateLayer(ui::LAYER_TEXTURED);
531 layer()->SetTransform(transform); 531 layer()->SetTransform(transform);
532 layer()->ScheduleDraw(); 532 layer()->ScheduleDraw();
533 } 533 }
534 } 534 }
535 535
536 void View::SetPaintToLayer(ui::LayerType layer_type) { 536 void View::SetPaintToLayer(ui::LayerType layer_type) {
537 if (paint_to_layer_ && (layer()->type() == layer_type)) 537 if (paint_to_layer_ && (layer()->type() == layer_type))
538 return; 538 return;
539 539
540 DestroyLayer(); 540 DestroyLayerImpl(LayerChangeNotifyBehavior::DONT_NOTIFY);
541 CreateLayer(layer_type); 541 CreateLayer(layer_type);
542 paint_to_layer_ = true; 542 paint_to_layer_ = true;
543
544 // Notify the parent chain about the layer change.
545 NotifyParentsOfLayerChange();
543 } 546 }
544 547
545 void View::DestroyLayer() { 548 void View::DestroyLayer() {
546 if (!paint_to_layer_) 549 DestroyLayerImpl(LayerChangeNotifyBehavior::NOTIFY);
547 return;
548
549 paint_to_layer_ = false;
550 if (!layer())
551 return;
552
553 ui::Layer* new_parent = layer()->parent();
554 std::vector<ui::Layer*> children = layer()->children();
555 for (size_t i = 0; i < children.size(); ++i) {
556 layer()->Remove(children[i]);
557 if (new_parent)
558 new_parent->Add(children[i]);
559 }
560
561 LayerOwner::DestroyLayer();
562
563 if (new_parent)
564 ReorderLayers();
565
566 UpdateChildLayerBounds(CalculateOffsetToAncestorWithLayer(NULL));
567
568 SchedulePaint();
569
570 Widget* widget = GetWidget();
571 if (widget)
572 widget->LayerTreeChanged();
573 } 550 }
574 551
575 std::unique_ptr<ui::Layer> View::RecreateLayer() { 552 std::unique_ptr<ui::Layer> View::RecreateLayer() {
576 std::unique_ptr<ui::Layer> old_layer = LayerOwner::RecreateLayer(); 553 std::unique_ptr<ui::Layer> old_layer = LayerOwner::RecreateLayer();
577 Widget* widget = GetWidget(); 554 Widget* widget = GetWidget();
578 if (widget) 555 if (widget)
579 widget->LayerTreeChanged(); 556 widget->LayerTreeChanged();
580 return old_layer; 557 return old_layer;
581 } 558 }
582 559
(...skipping 1110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1693 // Iterate backwards through the children so that a child with a layer 1670 // Iterate backwards through the children so that a child with a layer
1694 // which is further to the back is stacked above one which is further to 1671 // which is further to the back is stacked above one which is further to
1695 // the front. 1672 // the front.
1696 View::Views children = GetChildrenInZOrder(); 1673 View::Views children = GetChildrenInZOrder();
1697 DCHECK_EQ(child_count(), static_cast<int>(children.size())); 1674 DCHECK_EQ(child_count(), static_cast<int>(children.size()));
1698 for (auto* child : base::Reversed(children)) 1675 for (auto* child : base::Reversed(children))
1699 child->ReorderChildLayers(parent_layer); 1676 child->ReorderChildLayers(parent_layer);
1700 } 1677 }
1701 } 1678 }
1702 1679
1680 void View::OnChildLayerChanged(View* child) {}
1681
1682 void View::DestroyLayerImpl(LayerChangeNotifyBehavior notify_parents) {
1683 if (!paint_to_layer_)
1684 return;
1685
1686 paint_to_layer_ = false;
1687 if (!layer())
1688 return;
1689
1690 ui::Layer* new_parent = layer()->parent();
1691 std::vector<ui::Layer*> children = layer()->children();
1692 for (size_t i = 0; i < children.size(); ++i) {
1693 layer()->Remove(children[i]);
1694 if (new_parent)
1695 new_parent->Add(children[i]);
1696 }
1697
1698 LayerOwner::DestroyLayer();
1699
1700 if (new_parent)
1701 ReorderLayers();
1702
1703 UpdateChildLayerBounds(CalculateOffsetToAncestorWithLayer(NULL));
1704
1705 SchedulePaint();
1706
1707 // Notify the parent chain about the layer change.
1708 if (notify_parents == LayerChangeNotifyBehavior::NOTIFY)
1709 NotifyParentsOfLayerChange();
1710
1711 Widget* widget = GetWidget();
1712 if (widget)
1713 widget->LayerTreeChanged();
1714 }
1715
1716 void View::NotifyParentsOfLayerChange() {
1717 // Notify the parent chain about the layer change.
1718 View* view_parent = parent();
1719 while (view_parent) {
1720 view_parent->OnChildLayerChanged(this);
1721 view_parent = view_parent->parent();
1722 }
1723 }
1724
1703 // Input ----------------------------------------------------------------------- 1725 // Input -----------------------------------------------------------------------
1704 1726
1705 View::DragInfo* View::GetDragInfo() { 1727 View::DragInfo* View::GetDragInfo() {
1706 return parent_ ? parent_->GetDragInfo() : NULL; 1728 return parent_ ? parent_->GetDragInfo() : NULL;
1707 } 1729 }
1708 1730
1709 // Focus ----------------------------------------------------------------------- 1731 // Focus -----------------------------------------------------------------------
1710 1732
1711 void View::OnFocus() { 1733 void View::OnFocus() {
1712 // TODO(beng): Investigate whether it's possible for us to move this to 1734 // TODO(beng): Investigate whether it's possible for us to move this to
(...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after
2644 // Message the RootView to do the drag and drop. That way if we're removed 2666 // 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. 2667 // the RootView can detect it and avoid calling us back.
2646 gfx::Point widget_location(event.location()); 2668 gfx::Point widget_location(event.location());
2647 ConvertPointToWidget(this, &widget_location); 2669 ConvertPointToWidget(this, &widget_location);
2648 widget->RunShellDrag(this, data, widget_location, drag_operations, source); 2670 widget->RunShellDrag(this, data, widget_location, drag_operations, source);
2649 // WARNING: we may have been deleted. 2671 // WARNING: we may have been deleted.
2650 return true; 2672 return true;
2651 } 2673 }
2652 2674
2653 } // namespace views 2675 } // namespace views
OLDNEW
« ui/views/view.h ('K') | « ui/views/view.h ('k') | ui/views/view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698