1 /*
2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Antti Koivisto (koivisto@kde.org)
4 * (C) 2000 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2003, 2005, 2006, 2007, 2008, 2013 Apple Inc. All rights
6 * reserved.
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 *
23 */
24
25 #include "third_party/blink/renderer/core/style/nine_piece_image.h"
26
27 #include "third_party/blink/renderer/core/style/data_equivalency.h"
28
29 namespace blink {
30
DefaultData()31 static DataRef<NinePieceImageData>& DefaultData() {
32 static DataRef<NinePieceImageData>* data = new DataRef<NinePieceImageData>;
33 if (!data->Get())
34 data->Init();
35 return *data;
36 }
37
NinePieceImage()38 NinePieceImage::NinePieceImage() : data_(DefaultData()) {}
39
NinePieceImage(StyleImage * image,LengthBox image_slices,bool fill,const BorderImageLengthBox & border_slices,const BorderImageLengthBox & outset,ENinePieceImageRule horizontal_rule,ENinePieceImageRule vertical_rule)40 NinePieceImage::NinePieceImage(StyleImage* image,
41 LengthBox image_slices,
42 bool fill,
43 const BorderImageLengthBox& border_slices,
44 const BorderImageLengthBox& outset,
45 ENinePieceImageRule horizontal_rule,
46 ENinePieceImageRule vertical_rule) {
47 data_.Init();
48 data_.Access()->image = image;
49 data_.Access()->image_slices = image_slices;
50 data_.Access()->border_slices = border_slices;
51 data_.Access()->outset = outset;
52 data_.Access()->fill = fill;
53 data_.Access()->horizontal_rule = horizontal_rule;
54 data_.Access()->vertical_rule = vertical_rule;
55 }
56
NinePieceImageData()57 NinePieceImageData::NinePieceImageData()
58 : fill(false),
59 horizontal_rule(kStretchImageRule),
60 vertical_rule(kStretchImageRule),
61 image(nullptr),
62 image_slices(Length::Percent(100),
63 Length::Percent(100),
64 Length::Percent(100),
65 Length::Percent(100)),
66 border_slices(1.0, 1.0, 1.0, 1.0),
67 outset(0, 0, 0, 0) {}
68
operator ==(const NinePieceImageData & other) const69 bool NinePieceImageData::operator==(const NinePieceImageData& other) const {
70 return DataEquivalent(image, other.image) &&
71 image_slices == other.image_slices && fill == other.fill &&
72 border_slices == other.border_slices && outset == other.outset &&
73 horizontal_rule == other.horizontal_rule &&
74 vertical_rule == other.vertical_rule;
75 }
76
77 } // namespace blink
78