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

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

Issue 2824693002: Refactor LayerTreeImpl's scrollbar map to be keyed on element ids (Closed)
Patch Set: rebase 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
« 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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 current_offset += InnerViewportScrollLayer()->CurrentScrollOffset(); 239 current_offset += InnerViewportScrollLayer()->CurrentScrollOffset();
240 if (OuterViewportContainerLayer()) 240 if (OuterViewportContainerLayer())
241 clip_size.SetToMin(OuterViewportContainerLayer()->BoundsForScrolling()); 241 clip_size.SetToMin(OuterViewportContainerLayer()->BoundsForScrolling());
242 clip_size.Scale(1 / current_page_scale_factor()); 242 clip_size.Scale(1 / current_page_scale_factor());
243 } 243 }
244 244
245 bool scrollbar_needs_animation = false; 245 bool scrollbar_needs_animation = false;
246 bool clip_layer_size_did_change = false; 246 bool clip_layer_size_did_change = false;
247 bool scroll_layer_size_did_change = false; 247 bool scroll_layer_size_did_change = false;
248 bool y_offset_did_change = false; 248 bool y_offset_did_change = false;
249 for (ScrollbarLayerImplBase* scrollbar : ScrollbarsFor(scroll_layer_id)) { 249 for (auto* scrollbar : ScrollbarsFor(scroll_layer->element_id())) {
250 if (scrollbar->orientation() == HORIZONTAL) { 250 if (scrollbar->orientation() == HORIZONTAL) {
251 scrollbar_needs_animation |= scrollbar->SetCurrentPos(current_offset.x()); 251 scrollbar_needs_animation |= scrollbar->SetCurrentPos(current_offset.x());
252 clip_layer_size_did_change |= 252 clip_layer_size_did_change |=
253 scrollbar->SetClipLayerLength(clip_size.width()); 253 scrollbar->SetClipLayerLength(clip_size.width());
254 scroll_layer_size_did_change |= 254 scroll_layer_size_did_change |=
255 scrollbar->SetScrollLayerLength(scroll_size.width()); 255 scrollbar->SetScrollLayerLength(scroll_size.width());
256 } else { 256 } else {
257 scrollbar_needs_animation |= y_offset_did_change |= 257 scrollbar_needs_animation |= y_offset_did_change |=
258 scrollbar->SetCurrentPos(current_offset.y()); 258 scrollbar->SetCurrentPos(current_offset.y());
259 clip_layer_size_did_change |= 259 clip_layer_size_did_change |=
(...skipping 1200 matching lines...) Expand 10 before | Expand all | Expand 10 after
1460 1460
1461 gfx::Size LayerTreeImpl::DrawViewportSize() const { 1461 gfx::Size LayerTreeImpl::DrawViewportSize() const {
1462 return layer_tree_host_impl_->DrawViewportSize(); 1462 return layer_tree_host_impl_->DrawViewportSize();
1463 } 1463 }
1464 1464
1465 const gfx::Rect LayerTreeImpl::ViewportRectForTilePriority() const { 1465 const gfx::Rect LayerTreeImpl::ViewportRectForTilePriority() const {
1466 return layer_tree_host_impl_->ViewportRectForTilePriority(); 1466 return layer_tree_host_impl_->ViewportRectForTilePriority();
1467 } 1467 }
1468 1468
1469 std::unique_ptr<ScrollbarAnimationController> 1469 std::unique_ptr<ScrollbarAnimationController>
1470 LayerTreeImpl::CreateScrollbarAnimationController(int scroll_layer_id) { 1470 LayerTreeImpl::CreateScrollbarAnimationController(ElementId scroll_element_id) {
1471 DCHECK(!settings().scrollbar_fade_out_delay.is_zero()); 1471 DCHECK(!settings().scrollbar_fade_out_delay.is_zero());
1472 DCHECK(!settings().scrollbar_fade_out_duration.is_zero()); 1472 DCHECK(!settings().scrollbar_fade_out_duration.is_zero());
1473 base::TimeDelta fade_out_delay = settings().scrollbar_fade_out_delay; 1473 base::TimeDelta fade_out_delay = settings().scrollbar_fade_out_delay;
1474 base::TimeDelta fade_out_resize_delay = 1474 base::TimeDelta fade_out_resize_delay =
1475 settings().scrollbar_fade_out_resize_delay; 1475 settings().scrollbar_fade_out_resize_delay;
1476 base::TimeDelta fade_out_duration = settings().scrollbar_fade_out_duration; 1476 base::TimeDelta fade_out_duration = settings().scrollbar_fade_out_duration;
1477 switch (settings().scrollbar_animator) { 1477 switch (settings().scrollbar_animator) {
1478 case LayerTreeSettings::ANDROID_OVERLAY: { 1478 case LayerTreeSettings::ANDROID_OVERLAY: {
1479 return ScrollbarAnimationController:: 1479 return ScrollbarAnimationController::
1480 CreateScrollbarAnimationControllerAndroid( 1480 CreateScrollbarAnimationControllerAndroid(
1481 scroll_layer_id, layer_tree_host_impl_, fade_out_delay, 1481 scroll_element_id, layer_tree_host_impl_, fade_out_delay,
1482 fade_out_resize_delay, fade_out_duration); 1482 fade_out_resize_delay, fade_out_duration);
1483 } 1483 }
1484 case LayerTreeSettings::AURA_OVERLAY: { 1484 case LayerTreeSettings::AURA_OVERLAY: {
1485 DCHECK(!settings().scrollbar_show_delay.is_zero()); 1485 DCHECK(!settings().scrollbar_show_delay.is_zero());
1486 base::TimeDelta show_delay = settings().scrollbar_show_delay; 1486 base::TimeDelta show_delay = settings().scrollbar_show_delay;
1487 base::TimeDelta thinning_duration = 1487 base::TimeDelta thinning_duration =
1488 settings().scrollbar_thinning_duration; 1488 settings().scrollbar_thinning_duration;
1489 return ScrollbarAnimationController:: 1489 return ScrollbarAnimationController::
1490 CreateScrollbarAnimationControllerAuraOverlay( 1490 CreateScrollbarAnimationControllerAuraOverlay(
1491 scroll_layer_id, layer_tree_host_impl_, show_delay, 1491 scroll_element_id, layer_tree_host_impl_, show_delay,
1492 fade_out_delay, fade_out_resize_delay, fade_out_duration, 1492 fade_out_delay, fade_out_resize_delay, fade_out_duration,
1493 thinning_duration); 1493 thinning_duration);
1494 } 1494 }
1495 case LayerTreeSettings::NO_ANIMATOR: 1495 case LayerTreeSettings::NO_ANIMATOR:
1496 NOTREACHED(); 1496 NOTREACHED();
1497 break; 1497 break;
1498 } 1498 }
1499 return nullptr; 1499 return nullptr;
1500 } 1500 }
1501 1501
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1713 } 1713 }
1714 1714
1715 void LayerTreeImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { 1715 void LayerTreeImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) {
1716 std::vector<PictureLayerImpl*>::iterator it = 1716 std::vector<PictureLayerImpl*>::iterator it =
1717 std::find(picture_layers_.begin(), picture_layers_.end(), layer); 1717 std::find(picture_layers_.begin(), picture_layers_.end(), layer);
1718 DCHECK(it != picture_layers_.end()); 1718 DCHECK(it != picture_layers_.end());
1719 picture_layers_.erase(it); 1719 picture_layers_.erase(it);
1720 } 1720 }
1721 1721
1722 void LayerTreeImpl::RegisterScrollbar(ScrollbarLayerImplBase* scrollbar_layer) { 1722 void LayerTreeImpl::RegisterScrollbar(ScrollbarLayerImplBase* scrollbar_layer) {
1723 if (scrollbar_layer->ScrollLayerId() == Layer::INVALID_ID) 1723 ElementId scroll_element_id = scrollbar_layer->scroll_element_id();
1724 if (!scroll_element_id)
1724 return; 1725 return;
1725 1726
1726 scrollbar_map_.insert(std::pair<int, int>(scrollbar_layer->ScrollLayerId(), 1727 element_id_to_scrollbar_layer_ids_.insert(
1727 scrollbar_layer->id())); 1728 std::pair<ElementId, int>(scroll_element_id, scrollbar_layer->id()));
1728 if (IsActiveTree() && scrollbar_layer->is_overlay_scrollbar()) { 1729 if (IsActiveTree() && scrollbar_layer->is_overlay_scrollbar()) {
1729 auto scroll_layer_id = scrollbar_layer->ScrollLayerId();
1730 layer_tree_host_impl_->RegisterScrollbarAnimationController( 1730 layer_tree_host_impl_->RegisterScrollbarAnimationController(
1731 scroll_layer_id, scrollbar_layer->scroll_element_id()); 1731 scroll_element_id);
1732 } 1732 }
1733 1733
1734 DidUpdateScrollState(scrollbar_layer->ScrollLayerId()); 1734 DidUpdateScrollState(scrollbar_layer->ScrollLayerId());
1735 } 1735 }
1736 1736
1737 void LayerTreeImpl::UnregisterScrollbar( 1737 void LayerTreeImpl::UnregisterScrollbar(
1738 ScrollbarLayerImplBase* scrollbar_layer) { 1738 ScrollbarLayerImplBase* scrollbar_layer) {
1739 int scroll_layer_id = scrollbar_layer->ScrollLayerId(); 1739 ElementId scroll_element_id = scrollbar_layer->scroll_element_id();
1740 if (scroll_layer_id == Layer::INVALID_ID) 1740 if (!scroll_element_id)
1741 return; 1741 return;
1742 1742
1743 auto scrollbar_range = scrollbar_map_.equal_range(scroll_layer_id); 1743 auto scrollbar_range =
1744 element_id_to_scrollbar_layer_ids_.equal_range(scroll_element_id);
1744 for (auto i = scrollbar_range.first; i != scrollbar_range.second; ++i) 1745 for (auto i = scrollbar_range.first; i != scrollbar_range.second; ++i)
1745 if (i->second == scrollbar_layer->id()) { 1746 if (i->second == scrollbar_layer->id()) {
1746 scrollbar_map_.erase(i); 1747 element_id_to_scrollbar_layer_ids_.erase(i);
1747 break; 1748 break;
1748 } 1749 }
1749 1750
1750 if (IsActiveTree() && scrollbar_map_.count(scroll_layer_id) == 0) { 1751 if (IsActiveTree() &&
1752 element_id_to_scrollbar_layer_ids_.count(scroll_element_id) == 0) {
1751 layer_tree_host_impl_->UnregisterScrollbarAnimationController( 1753 layer_tree_host_impl_->UnregisterScrollbarAnimationController(
1752 scrollbar_layer->scroll_element_id()); 1754 scroll_element_id);
1753 } 1755 }
1754 } 1756 }
1755 1757
1756 ScrollbarSet LayerTreeImpl::ScrollbarsFor(int scroll_layer_id) const { 1758 ScrollbarSet LayerTreeImpl::ScrollbarsFor(ElementId scroll_element_id) const {
1757 ScrollbarSet scrollbars; 1759 ScrollbarSet scrollbars;
1758 auto scrollbar_range = scrollbar_map_.equal_range(scroll_layer_id); 1760 auto scrollbar_range =
1761 element_id_to_scrollbar_layer_ids_.equal_range(scroll_element_id);
1759 for (auto i = scrollbar_range.first; i != scrollbar_range.second; ++i) 1762 for (auto i = scrollbar_range.first; i != scrollbar_range.second; ++i)
1760 scrollbars.insert(LayerById(i->second)->ToScrollbarLayer()); 1763 scrollbars.insert(LayerById(i->second)->ToScrollbarLayer());
1761 return scrollbars; 1764 return scrollbars;
1762 } 1765 }
1763 1766
1764 void LayerTreeImpl::RegisterScrollLayer(LayerImpl* layer) { 1767 void LayerTreeImpl::RegisterScrollLayer(LayerImpl* layer) {
1765 if (layer->scroll_clip_layer_id() == Layer::INVALID_ID) 1768 if (layer->scroll_clip_layer_id() == Layer::INVALID_ID)
1766 return; 1769 return;
1767 1770
1768 clip_scroll_map_.insert( 1771 clip_scroll_map_.insert(
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
2181 2184
2182 void LayerTreeImpl::ResetAllChangeTracking() { 2185 void LayerTreeImpl::ResetAllChangeTracking() {
2183 layers_that_should_push_properties_.clear(); 2186 layers_that_should_push_properties_.clear();
2184 // Iterate over all layers, including masks. 2187 // Iterate over all layers, including masks.
2185 for (auto& layer : *layers_) 2188 for (auto& layer : *layers_)
2186 layer->ResetChangeTracking(); 2189 layer->ResetChangeTracking();
2187 property_trees_.ResetAllChangeTracking(); 2190 property_trees_.ResetAllChangeTracking();
2188 } 2191 }
2189 2192
2190 } // namespace cc 2193 } // 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