OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "cc/blink/web_mutable_state_impl.h" |
| 6 |
| 7 #include "cc/animation/layer_tree_mutation.h" |
| 8 #include "cc/layers/layer_impl.h" |
| 9 #include "cc/trees/layer_tree_impl.h" |
| 10 |
| 11 namespace cc_blink { |
| 12 |
| 13 WebMutableStateImpl::WebMutableStateImpl(cc::LayerTreeMutation* mutation, |
| 14 cc::LayerImpl* main_layer, |
| 15 cc::LayerImpl* scroll_layer) |
| 16 : mutation_(mutation), |
| 17 main_layer_(main_layer), |
| 18 scroll_layer_(scroll_layer) {} |
| 19 |
| 20 WebMutableStateImpl::~WebMutableStateImpl() {} |
| 21 |
| 22 double WebMutableStateImpl::getOpacity() const { |
| 23 return main_layer_->opacity(); |
| 24 } |
| 25 |
| 26 void WebMutableStateImpl::setOpacity(double opacity) { |
| 27 if (!main_layer_) |
| 28 return; |
| 29 main_layer_->OnOpacityAnimated(opacity); |
| 30 mutation_->SetOpacity(opacity); |
| 31 } |
| 32 |
| 33 const SkMatrix44& WebMutableStateImpl::getTransform() const { |
| 34 static SkMatrix44 identity; |
| 35 return main_layer_ ? main_layer_->transform().matrix() : identity; |
| 36 } |
| 37 |
| 38 void WebMutableStateImpl::setTransform(const SkMatrix44& matrix) { |
| 39 if (!main_layer_) |
| 40 return; |
| 41 main_layer_->OnTransformAnimated(gfx::Transform(matrix)); |
| 42 mutation_->SetTransform(matrix); |
| 43 } |
| 44 |
| 45 double WebMutableStateImpl::getScrollLeft() const { |
| 46 return scroll_layer_ ? scroll_layer_->CurrentScrollOffset().x() : 0.0; |
| 47 } |
| 48 |
| 49 void WebMutableStateImpl::setScrollLeft(double scroll_left) { |
| 50 if (!scroll_layer_) |
| 51 return; |
| 52 gfx::ScrollOffset offset = scroll_layer_->CurrentScrollOffset(); |
| 53 offset.set_x(scroll_left); |
| 54 scroll_layer_->OnScrollOffsetAnimated(offset); |
| 55 mutation_->SetScrollLeft(scroll_left); |
| 56 } |
| 57 |
| 58 double WebMutableStateImpl::getScrollTop() const { |
| 59 return scroll_layer_ ? scroll_layer_->CurrentScrollOffset().y() : 0.0; |
| 60 } |
| 61 |
| 62 void WebMutableStateImpl::setScrollTop(double scroll_top) { |
| 63 if (!scroll_layer_) |
| 64 return; |
| 65 gfx::ScrollOffset offset = scroll_layer_->CurrentScrollOffset(); |
| 66 offset.set_y(scroll_top); |
| 67 scroll_layer_->OnScrollOffsetAnimated(offset); |
| 68 mutation_->SetScrollTop(scroll_top); |
| 69 } |
| 70 |
| 71 WebMutableStateProviderImpl::WebMutableStateProviderImpl( |
| 72 cc::LayerTreeImpl* state, |
| 73 cc::LayerTreeMutationMap* mutations) |
| 74 : state_(state), mutations_(mutations) {} |
| 75 |
| 76 WebMutableStateProviderImpl::~WebMutableStateProviderImpl() {} |
| 77 |
| 78 blink::WebMutableState* WebMutableStateProviderImpl::getMutableStateFor( |
| 79 uint64_t element_id) { |
| 80 cc::LayerImpl* main_layer = nullptr; |
| 81 cc::LayerImpl* scroll_layer = nullptr; |
| 82 if (!state_->GetMutableLayers(element_id, &main_layer, &scroll_layer)) |
| 83 return nullptr; |
| 84 |
| 85 return new WebMutableStateImpl(&(*mutations_)[element_id], main_layer, |
| 86 scroll_layer); |
| 87 } |
| 88 |
| 89 } // namespace cc_blink |
OLD | NEW |