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

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: 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
« cc/trees/layer_tree_impl.h ('K') | « 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 1201 matching lines...) Expand 10 before | Expand all | Expand 10 after
1461 1461
1462 gfx::Size LayerTreeImpl::DrawViewportSize() const { 1462 gfx::Size LayerTreeImpl::DrawViewportSize() const {
1463 return layer_tree_host_impl_->DrawViewportSize(); 1463 return layer_tree_host_impl_->DrawViewportSize();
1464 } 1464 }
1465 1465
1466 const gfx::Rect LayerTreeImpl::ViewportRectForTilePriority() const { 1466 const gfx::Rect LayerTreeImpl::ViewportRectForTilePriority() const {
1467 return layer_tree_host_impl_->ViewportRectForTilePriority(); 1467 return layer_tree_host_impl_->ViewportRectForTilePriority();
1468 } 1468 }
1469 1469
1470 std::unique_ptr<ScrollbarAnimationController> 1470 std::unique_ptr<ScrollbarAnimationController>
1471 LayerTreeImpl::CreateScrollbarAnimationController(int scroll_layer_id) { 1471 LayerTreeImpl::CreateScrollbarAnimationController(ElementId scroll_element_id) {
1472 DCHECK(!settings().scrollbar_fade_out_delay.is_zero()); 1472 DCHECK(!settings().scrollbar_fade_out_delay.is_zero());
1473 DCHECK(!settings().scrollbar_fade_out_duration.is_zero()); 1473 DCHECK(!settings().scrollbar_fade_out_duration.is_zero());
1474 base::TimeDelta fade_out_delay = settings().scrollbar_fade_out_delay; 1474 base::TimeDelta fade_out_delay = settings().scrollbar_fade_out_delay;
1475 base::TimeDelta fade_out_resize_delay = 1475 base::TimeDelta fade_out_resize_delay =
1476 settings().scrollbar_fade_out_resize_delay; 1476 settings().scrollbar_fade_out_resize_delay;
1477 base::TimeDelta fade_out_duration = settings().scrollbar_fade_out_duration; 1477 base::TimeDelta fade_out_duration = settings().scrollbar_fade_out_duration;
1478 switch (settings().scrollbar_animator) { 1478 switch (settings().scrollbar_animator) {
1479 case LayerTreeSettings::ANDROID_OVERLAY: { 1479 case LayerTreeSettings::ANDROID_OVERLAY: {
1480 return ScrollbarAnimationController:: 1480 return ScrollbarAnimationController::
1481 CreateScrollbarAnimationControllerAndroid( 1481 CreateScrollbarAnimationControllerAndroid(
1482 scroll_layer_id, layer_tree_host_impl_, fade_out_delay, 1482 scroll_element_id, layer_tree_host_impl_, fade_out_delay,
1483 fade_out_resize_delay, fade_out_duration); 1483 fade_out_resize_delay, fade_out_duration);
1484 } 1484 }
1485 case LayerTreeSettings::AURA_OVERLAY: { 1485 case LayerTreeSettings::AURA_OVERLAY: {
1486 DCHECK(!settings().scrollbar_show_delay.is_zero()); 1486 DCHECK(!settings().scrollbar_show_delay.is_zero());
1487 base::TimeDelta show_delay = settings().scrollbar_show_delay; 1487 base::TimeDelta show_delay = settings().scrollbar_show_delay;
1488 base::TimeDelta thinning_duration = 1488 base::TimeDelta thinning_duration =
1489 settings().scrollbar_thinning_duration; 1489 settings().scrollbar_thinning_duration;
1490 return ScrollbarAnimationController:: 1490 return ScrollbarAnimationController::
1491 CreateScrollbarAnimationControllerAuraOverlay( 1491 CreateScrollbarAnimationControllerAuraOverlay(
1492 scroll_layer_id, layer_tree_host_impl_, show_delay, 1492 scroll_element_id, layer_tree_host_impl_, show_delay,
1493 fade_out_delay, fade_out_resize_delay, fade_out_duration, 1493 fade_out_delay, fade_out_resize_delay, fade_out_duration,
1494 thinning_duration); 1494 thinning_duration);
1495 } 1495 }
1496 case LayerTreeSettings::NO_ANIMATOR: 1496 case LayerTreeSettings::NO_ANIMATOR:
1497 NOTREACHED(); 1497 NOTREACHED();
1498 break; 1498 break;
1499 } 1499 }
1500 return nullptr; 1500 return nullptr;
1501 } 1501 }
1502 1502
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1714 } 1714 }
1715 1715
1716 void LayerTreeImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { 1716 void LayerTreeImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) {
1717 std::vector<PictureLayerImpl*>::iterator it = 1717 std::vector<PictureLayerImpl*>::iterator it =
1718 std::find(picture_layers_.begin(), picture_layers_.end(), layer); 1718 std::find(picture_layers_.begin(), picture_layers_.end(), layer);
1719 DCHECK(it != picture_layers_.end()); 1719 DCHECK(it != picture_layers_.end());
1720 picture_layers_.erase(it); 1720 picture_layers_.erase(it);
1721 } 1721 }
1722 1722
1723 void LayerTreeImpl::RegisterScrollbar(ScrollbarLayerImplBase* scrollbar_layer) { 1723 void LayerTreeImpl::RegisterScrollbar(ScrollbarLayerImplBase* scrollbar_layer) {
1724 if (scrollbar_layer->ScrollLayerId() == Layer::INVALID_ID) 1724 ElementId scroll_element_id = scrollbar_layer->scroll_element_id();
1725 if (!scroll_element_id)
1725 return; 1726 return;
1726 1727
1727 scrollbar_map_.insert(std::pair<int, int>(scrollbar_layer->ScrollLayerId(), 1728 scrollbar_map_.insert(
1728 scrollbar_layer->id())); 1729 std::pair<ElementId, int>(scroll_element_id, scrollbar_layer->id()));
1729 if (IsActiveTree() && scrollbar_layer->is_overlay_scrollbar()) { 1730 if (IsActiveTree() && scrollbar_layer->is_overlay_scrollbar()) {
1730 auto scroll_layer_id = scrollbar_layer->ScrollLayerId();
1731 layer_tree_host_impl_->RegisterScrollbarAnimationController( 1731 layer_tree_host_impl_->RegisterScrollbarAnimationController(
1732 scroll_layer_id, scrollbar_layer->scroll_element_id()); 1732 scroll_element_id);
1733 } 1733 }
1734 1734
1735 DidUpdateScrollState(scrollbar_layer->ScrollLayerId()); 1735 DidUpdateScrollState(scrollbar_layer->ScrollLayerId());
1736 } 1736 }
1737 1737
1738 void LayerTreeImpl::UnregisterScrollbar( 1738 void LayerTreeImpl::UnregisterScrollbar(
1739 ScrollbarLayerImplBase* scrollbar_layer) { 1739 ScrollbarLayerImplBase* scrollbar_layer) {
1740 int scroll_layer_id = scrollbar_layer->ScrollLayerId(); 1740 ElementId scroll_element_id = scrollbar_layer->scroll_element_id();
1741 if (scroll_layer_id == Layer::INVALID_ID) 1741 if (!scroll_element_id)
1742 return; 1742 return;
1743 1743
1744 auto scrollbar_range = scrollbar_map_.equal_range(scroll_layer_id); 1744 auto scrollbar_range = scrollbar_map_.equal_range(scroll_element_id);
1745 for (auto i = scrollbar_range.first; i != scrollbar_range.second; ++i) 1745 for (auto i = scrollbar_range.first; i != scrollbar_range.second; ++i)
1746 if (i->second == scrollbar_layer->id()) { 1746 if (i->second == scrollbar_layer->id()) {
1747 scrollbar_map_.erase(i); 1747 scrollbar_map_.erase(i);
1748 break; 1748 break;
1749 } 1749 }
1750 1750
1751 if (IsActiveTree() && scrollbar_map_.count(scroll_layer_id) == 0) { 1751 if (IsActiveTree() && scrollbar_map_.count(scroll_element_id) == 0) {
1752 layer_tree_host_impl_->UnregisterScrollbarAnimationController( 1752 layer_tree_host_impl_->UnregisterScrollbarAnimationController(
1753 scrollbar_layer->scroll_element_id()); 1753 scroll_element_id);
1754 } 1754 }
1755 } 1755 }
1756 1756
1757 ScrollbarSet LayerTreeImpl::ScrollbarsFor(int scroll_layer_id) const { 1757 ScrollbarSet LayerTreeImpl::ScrollbarsFor(ElementId scroll_element_id) const {
1758 ScrollbarSet scrollbars; 1758 ScrollbarSet scrollbars;
1759 auto scrollbar_range = scrollbar_map_.equal_range(scroll_layer_id); 1759 auto scrollbar_range = scrollbar_map_.equal_range(scroll_element_id);
1760 for (auto i = scrollbar_range.first; i != scrollbar_range.second; ++i) 1760 for (auto i = scrollbar_range.first; i != scrollbar_range.second; ++i)
1761 scrollbars.insert(LayerById(i->second)->ToScrollbarLayer()); 1761 scrollbars.insert(LayerById(i->second)->ToScrollbarLayer());
1762 return scrollbars; 1762 return scrollbars;
1763 } 1763 }
1764 1764
1765 void LayerTreeImpl::RegisterScrollLayer(LayerImpl* layer) { 1765 void LayerTreeImpl::RegisterScrollLayer(LayerImpl* layer) {
1766 if (layer->scroll_clip_layer_id() == Layer::INVALID_ID) 1766 if (layer->scroll_clip_layer_id() == Layer::INVALID_ID)
1767 return; 1767 return;
1768 1768
1769 clip_scroll_map_.insert( 1769 clip_scroll_map_.insert(
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
2182 2182
2183 void LayerTreeImpl::ResetAllChangeTracking() { 2183 void LayerTreeImpl::ResetAllChangeTracking() {
2184 layers_that_should_push_properties_.clear(); 2184 layers_that_should_push_properties_.clear();
2185 // Iterate over all layers, including masks. 2185 // Iterate over all layers, including masks.
2186 for (auto& layer : *layers_) 2186 for (auto& layer : *layers_)
2187 layer->ResetChangeTracking(); 2187 layer->ResetChangeTracking();
2188 property_trees_.ResetAllChangeTracking(); 2188 property_trees_.ResetAllChangeTracking();
2189 } 2189 }
2190 2190
2191 } // namespace cc 2191 } // namespace cc
OLDNEW
« cc/trees/layer_tree_impl.h ('K') | « cc/trees/layer_tree_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698