summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/layout/ng/geometry/ng_margin_strut.cc
blob: 924c5699f1455334233ad142f96010749f44a53f (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
// 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.

#include "third_party/blink/renderer/core/layout/ng/geometry/ng_margin_strut.h"

#include <algorithm>

namespace blink {

LayoutUnit NGMarginStrut::Sum() const {
  return std::max(quirky_positive_margin, positive_margin) + negative_margin;
}

LayoutUnit NGMarginStrut::QuirkyContainerSum() const {
  return positive_margin + negative_margin;
}

void NGMarginStrut::Append(const LayoutUnit& value, bool is_quirky) {
  if (is_quirky_container_start && is_quirky)
    return;

  if (value < 0) {
    negative_margin = std::min(value, negative_margin);
  } else {
    if (is_quirky) {
      DCHECK(value >= 0);

      quirky_positive_margin = std::max(value, quirky_positive_margin);
    } else {
      positive_margin = std::max(value, positive_margin);
    }
  }
}

bool NGMarginStrut::IsEmpty() const {
  return positive_margin == LayoutUnit() && negative_margin == LayoutUnit() &&
         quirky_positive_margin == LayoutUnit();
}

bool NGMarginStrut::operator==(const NGMarginStrut& other) const {
  return positive_margin == other.positive_margin &&
         negative_margin == other.negative_margin &&
         quirky_positive_margin == other.quirky_positive_margin &&
         is_quirky_container_start == other.is_quirky_container_start;
}

}  // namespace blink