1 // Copyright 2016 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 #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_IMAGE_SLICE_PROPERTY_FUNCTIONS_H_ 6 #define THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_IMAGE_SLICE_PROPERTY_FUNCTIONS_H_ 7 8 #include "third_party/blink/renderer/core/css/css_property_names.h" 9 #include "third_party/blink/renderer/core/style/computed_style.h" 10 #include "third_party/blink/renderer/platform/wtf/allocator/allocator.h" 11 12 namespace blink { 13 14 // This struct doesn't retain ownership of the slices, treat it like a 15 // reference. 16 struct ImageSlice { ImageSliceImageSlice17 ImageSlice(const LengthBox& slices, bool fill) : slices(slices), fill(fill) {} 18 19 const LengthBox& slices; 20 bool fill; 21 }; 22 23 class ImageSlicePropertyFunctions { 24 STATIC_ONLY(ImageSlicePropertyFunctions); 25 26 public: GetInitialImageSlice(const CSSProperty & property)27 static ImageSlice GetInitialImageSlice(const CSSProperty& property) { 28 return GetImageSlice(property, ComputedStyle::InitialStyle()); 29 } 30 GetImageSlice(const CSSProperty & property,const ComputedStyle & style)31 static ImageSlice GetImageSlice(const CSSProperty& property, 32 const ComputedStyle& style) { 33 switch (property.PropertyID()) { 34 default: 35 NOTREACHED(); 36 FALLTHROUGH; 37 case CSSPropertyID::kBorderImageSlice: 38 return ImageSlice(style.BorderImageSlices(), 39 style.BorderImageSlicesFill()); 40 case CSSPropertyID::kWebkitMaskBoxImageSlice: 41 return ImageSlice(style.MaskBoxImageSlices(), 42 style.MaskBoxImageSlicesFill()); 43 } 44 } 45 SetImageSlice(const CSSProperty & property,ComputedStyle & style,const ImageSlice & slice)46 static void SetImageSlice(const CSSProperty& property, 47 ComputedStyle& style, 48 const ImageSlice& slice) { 49 switch (property.PropertyID()) { 50 case CSSPropertyID::kBorderImageSlice: 51 style.SetBorderImageSlices(slice.slices); 52 style.SetBorderImageSlicesFill(slice.fill); 53 break; 54 case CSSPropertyID::kWebkitMaskBoxImageSlice: 55 style.SetMaskBoxImageSlices(slice.slices); 56 style.SetMaskBoxImageSlicesFill(slice.fill); 57 break; 58 default: 59 NOTREACHED(); 60 } 61 } 62 }; 63 64 } // namespace blink 65 66 #endif // THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_IMAGE_SLICE_PROPERTY_FUNCTIONS_H_ 67