| // 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 NGFloatingObject_h |
| #define NGFloatingObject_h |
| |
| #include "core/layout/ng/geometry/ng_box_strut.h" |
| #include "core/layout/ng/geometry/ng_logical_size.h" |
| #include "core/layout/ng/ng_block_node.h" |
| #include "core/layout/ng/ng_exclusion.h" |
| #include "core/layout/ng/ng_physical_fragment.h" |
| #include "core/style/ComputedStyle.h" |
| #include "core/style/ComputedStyleConstants.h" |
| #include "platform/wtf/Optional.h" |
| #include "platform/wtf/RefPtr.h" |
| |
| namespace blink { |
| |
| // Struct that keeps all information needed to position floats in LayoutNG. |
| struct CORE_EXPORT NGFloatingObject : public RefCounted<NGFloatingObject> { |
| public: |
| static RefPtr<NGFloatingObject> Create(const ComputedStyle& style, |
| NGWritingMode writing_mode, |
| NGLogicalSize available_size, |
| NGLogicalOffset origin_offset, |
| NGLogicalOffset from_offset, |
| NGBoxStrut margins, |
| NGPhysicalFragment* fragment) { |
| return AdoptRef(new NGFloatingObject(style, margins, available_size, |
| origin_offset, from_offset, |
| writing_mode, fragment)); |
| } |
| |
| NGExclusion::Type exclusion_type; |
| EClear clear_type; |
| NGBoxStrut margins; |
| // Available size of the constraint space that will be used by |
| // NGLayoutOpportunityIterator to position this floating object. |
| NGLogicalSize available_size; |
| |
| // To correctly **position** a float we need 2 offsets: |
| // - origin_offset which represents the layout point for this float. |
| // - from_offset which represents the point from where we need to calculate |
| // the relative logical offset for this float. |
| // Layout details: |
| // At the time when this float is created only *inline* offsets are known. |
| // Block offset will be set when we are about to place this float, i.e. when |
| // we resolved MarginStrut, adjusted the offset to clearance line etc. |
| NGLogicalOffset origin_offset; |
| NGLogicalOffset from_offset; |
| |
| // To correctly **paint** a float we need to know the BFC offset of the |
| // container to which we are attaching this float. It's used to calculate |
| // {@code paint_offset}. |
| // In most situations {@code paint_offset} equals to float's logical |
| // offset except the cases where a float needs to be re-attached to a non-zero |
| // height parent. |
| // |
| // Example: |
| // <body> |
| // <p style="height: 60px">Example</p> |
| // <div id="zero-height-div"><float></div> |
| // |
| // Here the float's logical offset is 0 relative to its #zero-height-div |
| // parent. Because of the "zero height" div this float is re-attached to the |
| // 1st non-empty parent => body. To paint this float correctly we provide the |
| // modified {@code paint_offset} which is relative to the float's new |
| // parent. |
| // I.e. for our example {@code paint_offset.top} == |
| // #zero-height-div's BFC offset |
| // - body's BFC offset + float's logical offset |
| // |
| // For code safety reasons {@code parent_bfc_block_offset} is Optional here |
| // because the block's offset can be only determined before the actual float's |
| // placement event. |
| WTF::Optional<LayoutUnit> parent_bfc_block_offset; |
| |
| // Writing mode of the float's constraint space. |
| NGWritingMode writing_mode; |
| |
| RefPtr<NGPhysicalFragment> fragment; |
| |
| bool IsLeft() const { return exclusion_type == NGExclusion::kFloatLeft; } |
| |
| bool IsRight() const { return exclusion_type == NGExclusion::kFloatRight; } |
| |
| String ToString() const { |
| return String::Format("Type: '%d'", exclusion_type); |
| } |
| |
| private: |
| NGFloatingObject(const ComputedStyle& style, |
| const NGBoxStrut& margins, |
| const NGLogicalSize& available_size, |
| const NGLogicalOffset& origin_offset, |
| const NGLogicalOffset& from_offset, |
| NGWritingMode writing_mode, |
| NGPhysicalFragment* fragment) |
| : margins(margins), |
| available_size(available_size), |
| origin_offset(origin_offset), |
| from_offset(from_offset), |
| writing_mode(writing_mode), |
| fragment(fragment) { |
| exclusion_type = NGExclusion::kFloatLeft; |
| if (style.Floating() == EFloat::kRight) |
| exclusion_type = NGExclusion::kFloatRight; |
| clear_type = style.Clear(); |
| } |
| }; |
| |
| } // namespace blink |
| |
| #endif // NGFloatingObject_h |