chromium/ui/views/layout/layout_types.h

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_VIEWS_LAYOUT_LAYOUT_TYPES_H_
#define UI_VIEWS_LAYOUT_LAYOUT_TYPES_H_

#include <algorithm>
#include <optional>
#include <ostream>
#include <string>
#include <tuple>
#include <utility>

#include "base/check.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/size.h"
#include "ui/views/views_export.h"

namespace views {

// Describes how elements should be aligned within a layout.  Baseline alignment
// only makes sense on the vertical axis and is unsupported by most layout
// managers.
enum class LayoutAlignment {};

// Whether a layout is oriented horizontally or vertically.
enum class LayoutOrientation {};

// A value used to bound a View during layout.  May be a finite bound or
// "unbounded", which is treated as larger than any finite value.
class VIEWS_EXPORT SizeBound {};
constexpr SizeBound::SizeBound() = default;
constexpr SizeBound::SizeBound(int bound) :{}
constexpr SizeBound::SizeBound(const SizeBound&) = default;
constexpr SizeBound::SizeBound(SizeBound&&) = default;
VIEWS_EXPORT SizeBound operator+(const SizeBound& lhs, const SizeBound& rhs);
VIEWS_EXPORT SizeBound operator-(const SizeBound& lhs, const SizeBound& rhs);
// Note: These comparisons treat unspecified values similar to infinity, that
// is, larger than any specified value and equal to any other unspecified value.
// While one can argue that two unspecified values can't be compared (and thus
// all comparisons should return false), this isn't what any callers want and
// breaks things in subtle ways, e.g. "a = b; DCHECK(a == b)" may fail.
constexpr bool operator<(const SizeBound& lhs, const SizeBound& rhs) {}
constexpr bool operator>(const SizeBound& lhs, const SizeBound& rhs) {}
constexpr bool operator<=(const SizeBound& lhs, const SizeBound& rhs) {}
constexpr bool operator>=(const SizeBound& lhs, const SizeBound& rhs) {}
constexpr bool operator==(const SizeBound& lhs, const SizeBound& rhs) {}
constexpr bool operator!=(const SizeBound& lhs, const SizeBound& rhs) {}

// Stores an optional width and height upper bound. Used when calculating the
// preferred size of a layout pursuant to a maximum available size.
class VIEWS_EXPORT SizeBounds {};
constexpr SizeBounds::SizeBounds() = default;
constexpr SizeBounds::SizeBounds(SizeBound width, SizeBound height)
    :{}
constexpr SizeBounds::SizeBounds(const gfx::Size& size)
    :{}
constexpr SizeBounds::SizeBounds(const SizeBounds&) = default;
constexpr SizeBounds::SizeBounds(SizeBounds&&) = default;
constexpr bool operator==(const SizeBounds& lhs, const SizeBounds& rhs) {}
constexpr bool operator!=(const SizeBounds& lhs, const SizeBounds& rhs) {}
constexpr bool operator<(const SizeBounds& lhs, const SizeBounds& rhs) {}

// Returns true if the specified |size| can fit in the specified |bounds|.
// Returns false if either the width or height of |bounds| is specified and is
// smaller than the corresponding element of |size|.
VIEWS_EXPORT bool CanFitInBounds(const gfx::Size& size,
                                 const SizeBounds& bounds);

// These are declared here for use in gtest-based unit tests but is defined in
// the views_test_support target. Depend on that to use this in your unit test.
// This should not be used in production code - call ToString() instead.
void PrintTo(const SizeBounds& size_bounds, ::std::ostream* os);
void PrintTo(LayoutOrientation layout_orientation, ::std::ostream* os);

}  // namespace views

#endif  // UI_VIEWS_LAYOUT_LAYOUT_TYPES_H_