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

Unified Diff: cc/trees/layer_tree_impl.cc

Issue 2894673008: Refactor scrollbar maps from multimap & std::set to simpler flat_{map, set} (Closed)
Patch Set: Ensure scrollbars are unregistered before registration 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/trees/layer_tree_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/trees/layer_tree_impl.cc
diff --git a/cc/trees/layer_tree_impl.cc b/cc/trees/layer_tree_impl.cc
index ed0fbe49bfeca052c8c62c8780eff48a7d177abb..69e88c8e9b5ca636920854a8e422456f2e10e0d3 100644
--- a/cc/trees/layer_tree_impl.cc
+++ b/cc/trees/layer_tree_impl.cc
@@ -1666,8 +1666,17 @@ void LayerTreeImpl::RegisterScrollbar(ScrollbarLayerImplBase* scrollbar_layer) {
if (!scroll_element_id)
return;
- element_id_to_scrollbar_layer_ids_.insert(
- std::pair<ElementId, int>(scroll_element_id, scrollbar_layer->id()));
+ auto& scrollbar_ids = element_id_to_scrollbar_layer_ids_[scroll_element_id];
+ if (scrollbar_layer->orientation() == HORIZONTAL) {
+ DCHECK(scrollbar_ids.horizontal == Layer::INVALID_ID)
enne (OOO) 2017/05/22 17:35:12 DCHECK_EQ, if you don't mind?
pdr. 2017/05/22 17:38:58 Done We should enforce this with a presubmit chec
+ << "Existing scrollbar should have been unregistered.";
+ scrollbar_ids.horizontal = scrollbar_layer->id();
+ } else {
+ DCHECK(scrollbar_ids.vertical == Layer::INVALID_ID)
+ << "Existing scrollbar should have been unregistered.";
+ scrollbar_ids.vertical = scrollbar_layer->id();
+ }
+
if (IsActiveTree() && scrollbar_layer->is_overlay_scrollbar()) {
layer_tree_host_impl_->RegisterScrollbarAnimationController(
scroll_element_id, scrollbar_layer->Opacity());
@@ -1684,27 +1693,32 @@ void LayerTreeImpl::UnregisterScrollbar(
if (!scroll_element_id)
return;
- auto scrollbar_range =
- element_id_to_scrollbar_layer_ids_.equal_range(scroll_element_id);
- for (auto i = scrollbar_range.first; i != scrollbar_range.second; ++i)
- if (i->second == scrollbar_layer->id()) {
- element_id_to_scrollbar_layer_ids_.erase(i);
- break;
+ auto& scrollbar_ids = element_id_to_scrollbar_layer_ids_[scroll_element_id];
+ if (scrollbar_layer->orientation() == HORIZONTAL)
+ scrollbar_ids.horizontal = Layer::INVALID_ID;
+ else
+ scrollbar_ids.vertical = Layer::INVALID_ID;
+
+ if (scrollbar_ids.horizontal == Layer::INVALID_ID &&
+ scrollbar_ids.vertical == Layer::INVALID_ID) {
+ element_id_to_scrollbar_layer_ids_.erase(scroll_element_id);
+ if (IsActiveTree()) {
+ layer_tree_host_impl_->UnregisterScrollbarAnimationController(
+ scroll_element_id);
}
-
- if (IsActiveTree() &&
- element_id_to_scrollbar_layer_ids_.count(scroll_element_id) == 0) {
- layer_tree_host_impl_->UnregisterScrollbarAnimationController(
- scroll_element_id);
}
}
ScrollbarSet LayerTreeImpl::ScrollbarsFor(ElementId scroll_element_id) const {
ScrollbarSet scrollbars;
- auto scrollbar_range =
- element_id_to_scrollbar_layer_ids_.equal_range(scroll_element_id);
- for (auto i = scrollbar_range.first; i != scrollbar_range.second; ++i)
- scrollbars.insert(LayerById(i->second)->ToScrollbarLayer());
+ auto it = element_id_to_scrollbar_layer_ids_.find(scroll_element_id);
+ if (it != element_id_to_scrollbar_layer_ids_.end()) {
+ const ScrollbarLayerIds& layer_ids = it->second;
+ if (layer_ids.horizontal != Layer::INVALID_ID)
+ scrollbars.insert(LayerById(layer_ids.horizontal)->ToScrollbarLayer());
+ if (layer_ids.vertical != Layer::INVALID_ID)
+ scrollbars.insert(LayerById(layer_ids.vertical)->ToScrollbarLayer());
+ }
return scrollbars;
}
« 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