summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/layout/ng/geometry/ng_physical_size.h
blob: 4ae9473aeccb171b7beb16b9f2c2795c7772dffa (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
// 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.

#ifndef NGPhysicalSize_h
#define NGPhysicalSize_h

#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/platform/layout_unit.h"
#include "third_party/blink/renderer/platform/text/writing_mode.h"

namespace blink {

class LayoutSize;
struct NGLogicalSize;

// NGPhysicalSize is the size of a rect (typically a fragment) in the physical
// coordinate system.
struct CORE_EXPORT NGPhysicalSize {
  NGPhysicalSize() = default;
  NGPhysicalSize(LayoutUnit width, LayoutUnit height)
      : width(width), height(height) {}

  LayoutUnit width;
  LayoutUnit height;

  NGLogicalSize ConvertToLogical(WritingMode mode) const;

  bool operator==(const NGPhysicalSize& other) const;

  bool IsEmpty() const {
    return width == LayoutUnit() || height == LayoutUnit();
  }
  bool IsZero() const {
    return width == LayoutUnit() && height == LayoutUnit();
  }

  // Conversions from/to existing code. New code prefers type safety for
  // logical/physical distinctions.
  LayoutSize ToLayoutSize() const;

  String ToString() const;
};

CORE_EXPORT std::ostream& operator<<(std::ostream&, const NGPhysicalSize&);

}  // namespace blink

#endif  // NGPhysicalSize_h