chromium/ui/views/layout/normalized_geometry.h

// Copyright 2018 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_NORMALIZED_GEOMETRY_H_
#define UI_VIEWS_LAYOUT_NORMALIZED_GEOMETRY_H_

#include <string>
#include <utility>

#include "ui/views/layout/flex_layout_types.h"
#include "ui/views/views_export.h"

namespace gfx {
class Insets;
class Point;
class Rect;
class Size;
}  // namespace gfx

namespace views {

class SizeBounds;

// Represents a point in layout space - that is, a point on the main and cross
// axes of the layout (regardless of whether it is vertically or horizontally
// oriented.
class VIEWS_EXPORT NormalizedPoint {};

// Represents a size in layout space - that is, a size on the main and cross
// axes of the layout (regardless of whether it is vertically or horizontally
// oriented.
class VIEWS_EXPORT NormalizedSize {};

// Represents insets in layout space - that is, insets on the main and cross
// axes of the layout (regardless of whether it is vertically or horizontally
// oriented.
class VIEWS_EXPORT NormalizedInsets {};

// Represents size bounds in layout space - that is, a set of size bounds using
// the main and cross axes of the layout (regardless of whether it is vertically
// or horizontally oriented).
class VIEWS_EXPORT NormalizedSizeBounds {};

// Represents a rectangle in layout space - that is, a rectangle whose
// dimensions align with the main and cross axis of the layout (regardless of
// whether the layout is vertically or horizontally oriented).
class VIEWS_EXPORT NormalizedRect {};

// Normalization and Denormalization -------------------------------------------

NormalizedPoint VIEWS_EXPORT Normalize(LayoutOrientation orientation,
                                       const gfx::Point& point);
gfx::Point VIEWS_EXPORT Denormalize(LayoutOrientation orientation,
                                    const NormalizedPoint& point);

NormalizedSize VIEWS_EXPORT Normalize(LayoutOrientation orientation,
                                      const gfx::Size& size);
gfx::Size VIEWS_EXPORT Denormalize(LayoutOrientation orientation,
                                   const NormalizedSize& size);

NormalizedSizeBounds VIEWS_EXPORT Normalize(LayoutOrientation orientation,
                                            const SizeBounds& bounds);
SizeBounds VIEWS_EXPORT Denormalize(LayoutOrientation orientation,
                                    const NormalizedSizeBounds& bounds);

NormalizedInsets VIEWS_EXPORT Normalize(LayoutOrientation orientation,
                                        const gfx::Insets& insets);
gfx::Insets VIEWS_EXPORT Denormalize(LayoutOrientation orientation,
                                     const NormalizedInsets& insets);

NormalizedRect VIEWS_EXPORT Normalize(LayoutOrientation orientation,
                                      const gfx::Rect& rect);
gfx::Rect VIEWS_EXPORT Denormalize(LayoutOrientation orientation,
                                   const NormalizedRect& rect);

// Convenience methods to get and set main and cross-axis elements of
// denormalized geometry elements.
int VIEWS_EXPORT GetMainAxis(LayoutOrientation orientation,
                             const gfx::Size& size);
int VIEWS_EXPORT GetCrossAxis(LayoutOrientation orientation,
                              const gfx::Size& size);
SizeBound VIEWS_EXPORT GetMainAxis(LayoutOrientation orientation,
                                   const SizeBounds& size);
SizeBound VIEWS_EXPORT GetCrossAxis(LayoutOrientation orientation,
                                    const SizeBounds& size);
void VIEWS_EXPORT SetMainAxis(gfx::Size* size,
                              LayoutOrientation orientation,
                              int main);
void VIEWS_EXPORT SetCrossAxis(gfx::Size* size,
                               LayoutOrientation orientation,
                               int cross);
void VIEWS_EXPORT SetMainAxis(SizeBounds* size,
                              LayoutOrientation orientation,
                              SizeBound main);
void VIEWS_EXPORT SetCrossAxis(SizeBounds* size,
                               LayoutOrientation orientation,
                               SizeBound cross);

}  // namespace views

#endif  // UI_VIEWS_LAYOUT_NORMALIZED_GEOMETRY_H_