blob: 4d4a9eea4cc49be60ee3204ebba2cfab4b0940e5 [file] [log] [blame]
// Copyright 2019 The Cobalt Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef COBALT_LAYOUT_FLEX_LINE_H_
#define COBALT_LAYOUT_FLEX_LINE_H_
#include <vector>
#include "base/logging.h"
#include "cobalt/layout/box.h"
#include "cobalt/layout/flex_item.h"
#include "cobalt/layout/layout_unit.h"
namespace cobalt {
namespace layout {
class FlexLine {
public:
// Disallow Copy and Assign.
FlexLine(const FlexLine&) = delete;
FlexLine& operator=(const FlexLine&) = delete;
FlexLine(const LayoutParams& layout_params, bool main_direction_is_horizontal,
bool direction_is_reversed, LayoutUnit main_size);
// Attempt to add the item to the line. Returns true if the box was
// added to the line.
bool TryAddItem(Box* box, LayoutUnit flex_base_size,
LayoutUnit hypothetical_main_size);
// Add the item to the line.
void AddItem(Box* box, LayoutUnit flex_base_size,
LayoutUnit hypothetical_main_size);
void ResolveFlexibleLengthsAndCrossSize();
void CalculateCrossSize();
void DetermineUsedCrossSizes(LayoutUnit container_cross_size);
void DoMainAxisAlignment();
void DoCrossAxisAlignment(LayoutUnit line_cross_axis_start);
LayoutUnit cross_size() const { return cross_size_; }
void set_cross_size(LayoutUnit value) { cross_size_ = value; }
LayoutUnit GetBaseline();
private:
LayoutUnit GetOuterMainSizeOfBox(Box* box,
LayoutUnit content_main_size) const;
float GetFlexFactor(Box* box);
void SetMainAxisPosition(LayoutUnit pos, FlexItem* item);
const LayoutParams layout_params_;
const bool main_direction_is_horizontal_;
const bool direction_is_reversed_;
const LayoutUnit main_size_;
bool flex_factor_grow_;
LayoutUnit items_outer_main_size_;
LayoutUnit line_cross_axis_start_;
std::vector<std::unique_ptr<FlexItem>> items_;
LayoutUnit cross_size_;
};
} // namespace layout
} // namespace cobalt
#endif // COBALT_LAYOUT_FLEX_LINE_H_