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

Side by Side Diff: cc/trees/layer_tree_impl.cc

Issue 2894673008: Refactor scrollbar maps from multimap & std::set to simpler flat_{map, set} (Closed)
Patch Set: DCHECK_EQ Created 3 years, 7 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
« no previous file with comments | « cc/trees/layer_tree_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 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 "cc/trees/layer_tree_impl.h" 5 #include "cc/trees/layer_tree_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 1648 matching lines...) Expand 10 before | Expand all | Expand 10 after
1659 std::find(picture_layers_.begin(), picture_layers_.end(), layer); 1659 std::find(picture_layers_.begin(), picture_layers_.end(), layer);
1660 DCHECK(it != picture_layers_.end()); 1660 DCHECK(it != picture_layers_.end());
1661 picture_layers_.erase(it); 1661 picture_layers_.erase(it);
1662 } 1662 }
1663 1663
1664 void LayerTreeImpl::RegisterScrollbar(ScrollbarLayerImplBase* scrollbar_layer) { 1664 void LayerTreeImpl::RegisterScrollbar(ScrollbarLayerImplBase* scrollbar_layer) {
1665 ElementId scroll_element_id = scrollbar_layer->scroll_element_id(); 1665 ElementId scroll_element_id = scrollbar_layer->scroll_element_id();
1666 if (!scroll_element_id) 1666 if (!scroll_element_id)
1667 return; 1667 return;
1668 1668
1669 element_id_to_scrollbar_layer_ids_.insert( 1669 auto& scrollbar_ids = element_id_to_scrollbar_layer_ids_[scroll_element_id];
1670 std::pair<ElementId, int>(scroll_element_id, scrollbar_layer->id())); 1670 if (scrollbar_layer->orientation() == HORIZONTAL) {
1671 DCHECK_EQ(scrollbar_ids.horizontal, Layer::INVALID_ID)
1672 << "Existing scrollbar should have been unregistered.";
1673 scrollbar_ids.horizontal = scrollbar_layer->id();
1674 } else {
1675 DCHECK_EQ(scrollbar_ids.vertical, Layer::INVALID_ID)
1676 << "Existing scrollbar should have been unregistered.";
1677 scrollbar_ids.vertical = scrollbar_layer->id();
1678 }
1679
1671 if (IsActiveTree() && scrollbar_layer->is_overlay_scrollbar()) { 1680 if (IsActiveTree() && scrollbar_layer->is_overlay_scrollbar()) {
1672 layer_tree_host_impl_->RegisterScrollbarAnimationController( 1681 layer_tree_host_impl_->RegisterScrollbarAnimationController(
1673 scroll_element_id, scrollbar_layer->Opacity()); 1682 scroll_element_id, scrollbar_layer->Opacity());
1674 } 1683 }
1675 1684
1676 // TODO(pdr): Refactor DidUpdateScrollState to use ElementIds instead of 1685 // TODO(pdr): Refactor DidUpdateScrollState to use ElementIds instead of
1677 // layer ids and remove this use of LayerIdByElementId. 1686 // layer ids and remove this use of LayerIdByElementId.
1678 DidUpdateScrollState(LayerIdByElementId(scroll_element_id)); 1687 DidUpdateScrollState(LayerIdByElementId(scroll_element_id));
1679 } 1688 }
1680 1689
1681 void LayerTreeImpl::UnregisterScrollbar( 1690 void LayerTreeImpl::UnregisterScrollbar(
1682 ScrollbarLayerImplBase* scrollbar_layer) { 1691 ScrollbarLayerImplBase* scrollbar_layer) {
1683 ElementId scroll_element_id = scrollbar_layer->scroll_element_id(); 1692 ElementId scroll_element_id = scrollbar_layer->scroll_element_id();
1684 if (!scroll_element_id) 1693 if (!scroll_element_id)
1685 return; 1694 return;
1686 1695
1687 auto scrollbar_range = 1696 auto& scrollbar_ids = element_id_to_scrollbar_layer_ids_[scroll_element_id];
1688 element_id_to_scrollbar_layer_ids_.equal_range(scroll_element_id); 1697 if (scrollbar_layer->orientation() == HORIZONTAL)
1689 for (auto i = scrollbar_range.first; i != scrollbar_range.second; ++i) 1698 scrollbar_ids.horizontal = Layer::INVALID_ID;
1690 if (i->second == scrollbar_layer->id()) { 1699 else
1691 element_id_to_scrollbar_layer_ids_.erase(i); 1700 scrollbar_ids.vertical = Layer::INVALID_ID;
1692 break; 1701
1702 if (scrollbar_ids.horizontal == Layer::INVALID_ID &&
1703 scrollbar_ids.vertical == Layer::INVALID_ID) {
1704 element_id_to_scrollbar_layer_ids_.erase(scroll_element_id);
1705 if (IsActiveTree()) {
1706 layer_tree_host_impl_->UnregisterScrollbarAnimationController(
1707 scroll_element_id);
1693 } 1708 }
1694
1695 if (IsActiveTree() &&
1696 element_id_to_scrollbar_layer_ids_.count(scroll_element_id) == 0) {
1697 layer_tree_host_impl_->UnregisterScrollbarAnimationController(
1698 scroll_element_id);
1699 } 1709 }
1700 } 1710 }
1701 1711
1702 ScrollbarSet LayerTreeImpl::ScrollbarsFor(ElementId scroll_element_id) const { 1712 ScrollbarSet LayerTreeImpl::ScrollbarsFor(ElementId scroll_element_id) const {
1703 ScrollbarSet scrollbars; 1713 ScrollbarSet scrollbars;
1704 auto scrollbar_range = 1714 auto it = element_id_to_scrollbar_layer_ids_.find(scroll_element_id);
1705 element_id_to_scrollbar_layer_ids_.equal_range(scroll_element_id); 1715 if (it != element_id_to_scrollbar_layer_ids_.end()) {
1706 for (auto i = scrollbar_range.first; i != scrollbar_range.second; ++i) 1716 const ScrollbarLayerIds& layer_ids = it->second;
1707 scrollbars.insert(LayerById(i->second)->ToScrollbarLayer()); 1717 if (layer_ids.horizontal != Layer::INVALID_ID)
1718 scrollbars.insert(LayerById(layer_ids.horizontal)->ToScrollbarLayer());
1719 if (layer_ids.vertical != Layer::INVALID_ID)
1720 scrollbars.insert(LayerById(layer_ids.vertical)->ToScrollbarLayer());
1721 }
1708 return scrollbars; 1722 return scrollbars;
1709 } 1723 }
1710 1724
1711 void LayerTreeImpl::RegisterScrollLayer(LayerImpl* layer) { 1725 void LayerTreeImpl::RegisterScrollLayer(LayerImpl* layer) {
1712 if (layer->scroll_clip_layer_id() == Layer::INVALID_ID) 1726 if (layer->scroll_clip_layer_id() == Layer::INVALID_ID)
1713 return; 1727 return;
1714 1728
1715 clip_scroll_map_.insert( 1729 clip_scroll_map_.insert(
1716 std::pair<int, int>(layer->scroll_clip_layer_id(), layer->id())); 1730 std::pair<int, int>(layer->scroll_clip_layer_id(), layer->id()));
1717 1731
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
2108 2122
2109 void LayerTreeImpl::ResetAllChangeTracking() { 2123 void LayerTreeImpl::ResetAllChangeTracking() {
2110 layers_that_should_push_properties_.clear(); 2124 layers_that_should_push_properties_.clear();
2111 // Iterate over all layers, including masks. 2125 // Iterate over all layers, including masks.
2112 for (auto& layer : *layers_) 2126 for (auto& layer : *layers_)
2113 layer->ResetChangeTracking(); 2127 layer->ResetChangeTracking();
2114 property_trees_.ResetAllChangeTracking(); 2128 property_trees_.ResetAllChangeTracking();
2115 } 2129 }
2116 2130
2117 } // namespace cc 2131 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698