OLD | NEW |
1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 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/layers/layer.h" | 5 #include "cc/layers/layer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 void Layer::RemoveClipChild(Layer* child) { | 667 void Layer::RemoveClipChild(Layer* child) { |
668 clip_children_->erase(child); | 668 clip_children_->erase(child); |
669 if (clip_children_->empty()) | 669 if (clip_children_->empty()) |
670 clip_children_.reset(); | 670 clip_children_.reset(); |
671 SetNeedsCommit(); | 671 SetNeedsCommit(); |
672 } | 672 } |
673 | 673 |
674 void Layer::SetScrollOffset(gfx::Vector2d scroll_offset) { | 674 void Layer::SetScrollOffset(gfx::Vector2d scroll_offset) { |
675 DCHECK(IsPropertyChangeAllowed()); | 675 DCHECK(IsPropertyChangeAllowed()); |
676 | 676 |
677 if (layer_tree_host()) { | |
678 scroll_offset = layer_tree_host()->DistributeScrollOffsetToViewports( | |
679 scroll_offset, this); | |
680 } | |
681 | |
682 if (scroll_offset_ == scroll_offset) | 677 if (scroll_offset_ == scroll_offset) |
683 return; | 678 return; |
684 scroll_offset_ = scroll_offset; | 679 scroll_offset_ = scroll_offset; |
685 SetNeedsCommit(); | 680 SetNeedsCommit(); |
686 } | 681 } |
687 | 682 |
688 void Layer::SetScrollOffsetFromImplSide(const gfx::Vector2d& scroll_offset) { | 683 void Layer::SetScrollOffsetFromImplSide(const gfx::Vector2d& scroll_offset) { |
689 DCHECK(IsPropertyChangeAllowed()); | 684 DCHECK(IsPropertyChangeAllowed()); |
690 // This function only gets called during a BeginMainFrame, so there | 685 // This function only gets called during a BeginMainFrame, so there |
691 // is no need to call SetNeedsUpdate here. | 686 // is no need to call SetNeedsUpdate here. |
692 DCHECK(layer_tree_host_ && layer_tree_host_->CommitRequested()); | 687 DCHECK(layer_tree_host_ && layer_tree_host_->CommitRequested()); |
693 if (scroll_offset_ == scroll_offset) | 688 if (scroll_offset_ == scroll_offset) |
694 return; | 689 return; |
695 scroll_offset_ = scroll_offset; | 690 scroll_offset_ = scroll_offset; |
696 SetNeedsPushProperties(); | 691 SetNeedsPushProperties(); |
697 if (!did_scroll_callback_.is_null()) | 692 if (!did_scroll_callback_.is_null()) |
698 did_scroll_callback_.Run(); | 693 did_scroll_callback_.Run(); |
699 // The callback could potentially change the layer structure: | 694 // The callback could potentially change the layer structure: |
700 // "this" may have been destroyed during the process. | 695 // "this" may have been destroyed during the process. |
701 } | 696 } |
702 | 697 |
703 // TODO(wjmaclean) We should template this and put it into LayerTreeHostCommon | |
704 // so that both Layer and LayerImpl are using the same code. In order | |
705 // to template it we should avoid calling layer_tree_host() by giving | |
706 // Layer/LayerImpl local accessors for page_scale_layer() and | |
707 // page_scale_factor(). | |
708 gfx::Vector2d Layer::MaxScrollOffset() const { | |
709 if (scroll_clip_layer_id_ == INVALID_ID) | |
710 return gfx::Vector2d(); | |
711 | |
712 gfx::Size scaled_scroll_bounds(bounds()); | |
713 Layer const* current_layer = this; | |
714 Layer const* page_scale_layer = layer_tree_host()->page_scale_layer(); | |
715 float scale_factor = 1.f; | |
716 do { | |
717 if (current_layer == page_scale_layer) { | |
718 scale_factor = layer_tree_host()->page_scale_factor(); | |
719 scaled_scroll_bounds.SetSize( | |
720 scale_factor * scaled_scroll_bounds.width(), | |
721 scale_factor * scaled_scroll_bounds.height()); | |
722 } | |
723 current_layer = current_layer->parent(); | |
724 } while (current_layer && current_layer->id() != scroll_clip_layer_id_); | |
725 DCHECK(current_layer); | |
726 DCHECK(current_layer->id() == scroll_clip_layer_id_); | |
727 | |
728 gfx::Vector2dF max_offset( | |
729 scaled_scroll_bounds.width() - current_layer->bounds().width(), | |
730 scaled_scroll_bounds.height() - current_layer->bounds().height()); | |
731 // We need the final scroll offset to be in CSS coords. | |
732 max_offset.Scale(1.f / scale_factor); | |
733 max_offset.SetToMax(gfx::Vector2dF()); | |
734 return gfx::ToFlooredVector2d(max_offset); | |
735 } | |
736 | |
737 void Layer::SetScrollClipLayerId(int clip_layer_id) { | 698 void Layer::SetScrollClipLayerId(int clip_layer_id) { |
738 DCHECK(IsPropertyChangeAllowed()); | 699 DCHECK(IsPropertyChangeAllowed()); |
739 if (scroll_clip_layer_id_ == clip_layer_id) | 700 if (scroll_clip_layer_id_ == clip_layer_id) |
740 return; | 701 return; |
741 scroll_clip_layer_id_ = clip_layer_id; | 702 scroll_clip_layer_id_ = clip_layer_id; |
742 SetNeedsCommit(); | 703 SetNeedsCommit(); |
743 } | 704 } |
744 | 705 |
745 void Layer::SetUserScrollable(bool horizontal, bool vertical) { | 706 void Layer::SetUserScrollable(bool horizontal, bool vertical) { |
746 DCHECK(IsPropertyChangeAllowed()); | 707 DCHECK(IsPropertyChangeAllowed()); |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1219 if (clip_parent_) | 1180 if (clip_parent_) |
1220 clip_parent_->RemoveClipChild(this); | 1181 clip_parent_->RemoveClipChild(this); |
1221 | 1182 |
1222 clip_parent_ = NULL; | 1183 clip_parent_ = NULL; |
1223 } | 1184 } |
1224 | 1185 |
1225 void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) { | 1186 void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) { |
1226 benchmark->RunOnLayer(this); | 1187 benchmark->RunOnLayer(this); |
1227 } | 1188 } |
1228 } // namespace cc | 1189 } // namespace cc |
OLD | NEW |