summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/animation/image_slice_property_functions.h
blob: ca090999a94773413a9d3f34a45acec648d6c921 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_IMAGE_SLICE_PROPERTY_FUNCTIONS_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_IMAGE_SLICE_PROPERTY_FUNCTIONS_H_

#include "third_party/blink/renderer/core/css/css_property_names.h"
#include "third_party/blink/renderer/core/style/computed_style.h"

namespace blink {

// This struct doesn't retain ownership of the slices, treat it like a
// reference.
struct ImageSlice {
  ImageSlice(const LengthBox& slices, bool fill) : slices(slices), fill(fill) {}

  const LengthBox& slices;
  bool fill;
};

class ImageSlicePropertyFunctions {
 public:
  static ImageSlice GetInitialImageSlice(const CSSProperty& property) {
    return GetImageSlice(property, ComputedStyle::InitialStyle());
  }

  static ImageSlice GetImageSlice(const CSSProperty& property,
                                  const ComputedStyle& style) {
    switch (property.PropertyID()) {
      default:
        NOTREACHED();
        FALLTHROUGH;
      case CSSPropertyBorderImageSlice:
        return ImageSlice(style.BorderImageSlices(),
                          style.BorderImageSlicesFill());
      case CSSPropertyWebkitMaskBoxImageSlice:
        return ImageSlice(style.MaskBoxImageSlices(),
                          style.MaskBoxImageSlicesFill());
    }
  }

  static void SetImageSlice(const CSSProperty& property,
                            ComputedStyle& style,
                            const ImageSlice& slice) {
    switch (property.PropertyID()) {
      case CSSPropertyBorderImageSlice:
        style.SetBorderImageSlices(slice.slices);
        style.SetBorderImageSlicesFill(slice.fill);
        break;
      case CSSPropertyWebkitMaskBoxImageSlice:
        style.SetMaskBoxImageSlices(slice.slices);
        style.SetMaskBoxImageSlicesFill(slice.fill);
        break;
      default:
        NOTREACHED();
    }
  }
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_IMAGE_SLICE_PROPERTY_FUNCTIONS_H_