1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "movingphoto_layout_algorithm.h" 17 #include "movingphoto_layout_property.h" 18 #include "movingphoto_pattern.h" 19 20 #include "base/geometry/ng/size_t.h" 21 22 namespace OHOS::Ace::NG { 23 Layout(LayoutWrapper * layoutWrapper)24void MovingPhotoLayoutAlgorithm::Layout(LayoutWrapper* layoutWrapper) 25 { 26 BoxLayoutAlgorithm::PerformLayout(layoutWrapper); 27 auto contentOffset = layoutWrapper->GetGeometryNode()->GetContentOffset(); 28 auto host = layoutWrapper->GetHostNode(); 29 CHECK_NULL_VOID(host); 30 auto pattern = DynamicCast<MovingPhotoPattern>(host->GetPattern()); 31 CHECK_NULL_VOID(pattern); 32 for (auto&& child : layoutWrapper->GetAllChildrenWithBuild()) { 33 if (child->GetHostTag() == V2::IMAGE_ETS_TAG || child->GetHostTag() == V2::COLUMN_ETS_TAG) { 34 child->GetGeometryNode()->SetMarginFrameOffset({ contentOffset.GetX(), contentOffset.GetY() }); 35 } 36 child->Layout(); 37 } 38 } 39 Measure(LayoutWrapper * layoutWrapper)40void MovingPhotoLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper) 41 { 42 auto layoutConstraint = layoutWrapper->GetLayoutProperty()->CreateChildConstraint(); 43 auto contentSize = layoutWrapper->GetGeometryNode()->GetContentSize(); 44 auto layoutProperty = DynamicCast<MovingPhotoLayoutProperty>(layoutWrapper->GetLayoutProperty()); 45 auto host = layoutWrapper->GetHostNode(); 46 CHECK_NULL_VOID(host); 47 auto pattern = DynamicCast<MovingPhotoPattern>(host->GetPattern()); 48 CHECK_NULL_VOID(pattern); 49 for (auto&& child : layoutWrapper->GetAllChildrenWithBuild()) { 50 if (child->GetHostTag() == V2::IMAGE_ETS_TAG || child->GetHostTag() == V2::COLUMN_ETS_TAG) { 51 auto layoutConstraintForImage = layoutConstraint; 52 layoutConstraintForImage.UpdateSelfMarginSizeWithCheck(OptionalSizeF(contentSize)); 53 layoutConstraintForImage.UpdateMaxSizeWithCheck(contentSize); 54 layoutConstraintForImage.UpdateMinSizeWithCheck(contentSize); 55 child->Measure(layoutConstraintForImage); 56 } 57 } 58 PerformMeasureSelf(layoutWrapper); 59 } 60 MeasureContent(const LayoutConstraintF & contentConstraint,LayoutWrapper * layoutWrapper)61std::optional<SizeF> MovingPhotoLayoutAlgorithm::MeasureContent( 62 const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper) 63 { 64 auto layoutSize = contentConstraint.selfIdealSize.IsValid() ? contentConstraint.selfIdealSize.ConvertToSizeT() 65 : contentConstraint.maxSize; 66 return layoutSize; 67 } 68 69 } // namespace OHOS::Ace::NG