1 /*
2  * Copyright (c) 2013, Opera Software ASA. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Opera Software ASA nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_STYLE_BORDER_IMAGE_LENGTH_BOX_H_
32 #define THIRD_PARTY_BLINK_RENDERER_CORE_STYLE_BORDER_IMAGE_LENGTH_BOX_H_
33 
34 #include "third_party/blink/renderer/core/style/border_image_length.h"
35 #include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
36 
37 namespace blink {
38 
39 // Represents a computed border image width or outset.
40 //
41 // http://www.w3.org/TR/css3-background/#border-image-width
42 // http://www.w3.org/TR/css3-background/#border-image-outset
43 class BorderImageLengthBox {
44   DISALLOW_NEW();
45 
46  public:
BorderImageLengthBox(Length length)47   BorderImageLengthBox(Length length)
48       : left_(length), right_(length), top_(length), bottom_(length) {}
49 
BorderImageLengthBox(double number)50   BorderImageLengthBox(double number)
51       : left_(number), right_(number), top_(number), bottom_(number) {}
52 
BorderImageLengthBox(const BorderImageLength & top,const BorderImageLength & right,const BorderImageLength & bottom,const BorderImageLength & left)53   BorderImageLengthBox(const BorderImageLength& top,
54                        const BorderImageLength& right,
55                        const BorderImageLength& bottom,
56                        const BorderImageLength& left)
57       : left_(left), right_(right), top_(top), bottom_(bottom) {}
58 
Left()59   const BorderImageLength& Left() const { return left_; }
Right()60   const BorderImageLength& Right() const { return right_; }
Top()61   const BorderImageLength& Top() const { return top_; }
Bottom()62   const BorderImageLength& Bottom() const { return bottom_; }
63 
64   bool operator==(const BorderImageLengthBox& other) const {
65     return left_ == other.left_ && right_ == other.right_ &&
66            top_ == other.top_ && bottom_ == other.bottom_;
67   }
68 
69   bool operator!=(const BorderImageLengthBox& other) const {
70     return !(*this == other);
71   }
72 
NonZero()73   bool NonZero() const {
74     return !(left_.IsZero() && right_.IsZero() && top_.IsZero() &&
75              bottom_.IsZero());
76   }
77 
78  private:
79   BorderImageLength left_;
80   BorderImageLength right_;
81   BorderImageLength top_;
82   BorderImageLength bottom_;
83 };
84 
85 }  // namespace blink
86 
87 #endif  // THIRD_PARTY_BLINK_RENDERER_CORE_STYLE_BORDER_IMAGE_LENGTH_BOX_H_
88