Chromium Code Reviews| 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..0619dc4d975551eb880c22df6a2b8b39dbbca921 100644 |
| --- a/cc/trees/layer_tree_impl.cc |
| +++ b/cc/trees/layer_tree_impl.cc |
| @@ -1666,8 +1666,14 @@ 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())); |
| + if (scrollbar_layer->orientation() == HORIZONTAL) { |
| + element_id_to_scrollbar_layer_ids_[scroll_element_id].horizontal = |
| + scrollbar_layer->id(); |
| + } else { |
| + element_id_to_scrollbar_layer_ids_[scroll_element_id].vertical = |
| + scrollbar_layer->id(); |
| + } |
| + |
| if (IsActiveTree() && scrollbar_layer->is_overlay_scrollbar()) { |
| layer_tree_host_impl_->RegisterScrollbarAnimationController( |
| scroll_element_id, scrollbar_layer->Opacity()); |
| @@ -1684,27 +1690,37 @@ 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; |
| - } |
| + bool no_remaining_scrollbars = false; |
| + auto& scrollbar_ids = element_id_to_scrollbar_layer_ids_[scroll_element_id]; |
| + if (scrollbar_layer->orientation() == HORIZONTAL) { |
| + scrollbar_ids.horizontal = Layer::INVALID_ID; |
| + if (scrollbar_ids.vertical == Layer::INVALID_ID) |
| + no_remaining_scrollbars = true; |
| + } else { |
| + scrollbar_ids.vertical = Layer::INVALID_ID; |
| + if (scrollbar_ids.horizontal == Layer::INVALID_ID) |
|
vmpstr
2017/05/22 16:27:22
not: Instead of no_remaining_scrollbars, you can j
pdr.
2017/05/22 16:43:48
nit/not done
|
| + no_remaining_scrollbars = true; |
| + } |
| - if (IsActiveTree() && |
| - element_id_to_scrollbar_layer_ids_.count(scroll_element_id) == 0) { |
| - layer_tree_host_impl_->UnregisterScrollbarAnimationController( |
| - scroll_element_id); |
| + if (no_remaining_scrollbars) { |
| + element_id_to_scrollbar_layer_ids_.erase(scroll_element_id); |
| + if (IsActiveTree()) { |
| + 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; |
| } |