summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/animation/image_list_property_functions.h
blob: 39071e66c741be3eef5ce75185dee294bd91b7da (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2015 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_LIST_PROPERTY_FUNCTIONS_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_IMAGE_LIST_PROPERTY_FUNCTIONS_H_

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

namespace blink {

using StyleImageList = HeapVector<Member<StyleImage>, 1>;

class ImageListPropertyFunctions {
 public:
  static void GetInitialImageList(const CSSProperty&, StyleImageList* result) {
    result->clear();
  }

  static void GetImageList(const CSSProperty& property,
                           const ComputedStyle& style,
                           StyleImageList* result) {
    const FillLayer* fill_layer = nullptr;
    switch (property.PropertyID()) {
      case CSSPropertyBackgroundImage:
        fill_layer = &style.BackgroundLayers();
        break;
      case CSSPropertyWebkitMaskImage:
        fill_layer = &style.MaskLayers();
        break;
      default:
        NOTREACHED();
        return;
    }

    result->clear();
    while (fill_layer) {
      result->push_back(fill_layer->GetImage());
      fill_layer = fill_layer->Next();
    }
  }

  static void SetImageList(const CSSProperty& property,
                           ComputedStyle& style,
                           const StyleImageList* image_list) {
    FillLayer* fill_layer = nullptr;
    switch (property.PropertyID()) {
      case CSSPropertyBackgroundImage:
        fill_layer = &style.AccessBackgroundLayers();
        break;
      case CSSPropertyWebkitMaskImage:
        fill_layer = &style.AccessMaskLayers();
        break;
      default:
        NOTREACHED();
        return;
    }

    FillLayer* prev = nullptr;
    for (wtf_size_t i = 0; i < image_list->size(); i++) {
      if (!fill_layer)
        fill_layer = prev->EnsureNext();
      fill_layer->SetImage(image_list->at(i));
      prev = fill_layer;
      fill_layer = fill_layer->Next();
    }
    while (fill_layer) {
      fill_layer->ClearImage();
      fill_layer = fill_layer->Next();
    }
  }
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_IMAGE_LIST_PROPERTY_FUNCTIONS_H_