1 /*
2 * Copyright (c) 2012, Google Inc. 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 Google Inc. 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 #include "third_party/blink/renderer/platform/geometry/layout_rect_outsets.h"
32
33 #include <algorithm>
34 #include "third_party/blink/renderer/platform/wtf/assertions.h"
35 #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
36
37 namespace blink {
38
ClampNegativeToZero()39 void LayoutRectOutsets::ClampNegativeToZero() {
40 top_ = top_.ClampNegativeToZero();
41 right_ = right_.ClampNegativeToZero();
42 bottom_ = bottom_.ClampNegativeToZero();
43 left_ = left_.ClampNegativeToZero();
44 }
45
Unite(const LayoutRectOutsets & other)46 void LayoutRectOutsets::Unite(const LayoutRectOutsets& other) {
47 top_ = std::max(top_, other.top_);
48 right_ = std::max(right_, other.right_);
49 bottom_ = std::max(bottom_, other.bottom_);
50 left_ = std::max(left_, other.left_);
51 }
52
operator <<(std::ostream & ostream,const LayoutRectOutsets & outsets)53 std::ostream& operator<<(std::ostream& ostream,
54 const LayoutRectOutsets& outsets) {
55 return ostream << outsets.ToString();
56 }
57
ToString() const58 String LayoutRectOutsets::ToString() const {
59 return String::Format(
60 "top %s; right %s; bottom %s; left %s", Top().ToString().Ascii().c_str(),
61 Right().ToString().Ascii().c_str(), Bottom().ToString().Ascii().c_str(),
62 Left().ToString().Ascii().c_str());
63 }
64
65 } // namespace blink
66