103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)/*
203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) *
403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * Redistribution and use in source and binary forms, with or without
503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * modification, are permitted provided that the following conditions
603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * are met:
703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) *
803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * 1. Redistributions of source code must retain the above
903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) *    copyright notice, this list of conditions and the following
1003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) *    disclaimer.
1103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * 2. Redistributions in binary form must reproduce the above
1203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) *    copyright notice, this list of conditions and the following
1303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) *    disclaimer in the documentation and/or other materials
1403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) *    provided with the distribution.
1503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) *
1603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
2103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
2303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
2503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
2703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * OF THE POSSIBILITY OF SUCH DAMAGE.
2803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) */
291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
3003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#ifndef LineWidth_h
3103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#define LineWidth_h
3203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
3303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "platform/LayoutUnit.h"
3403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
3503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)namespace blink {
3603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
3703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)class FloatingObject;
3803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)class RenderObject;
3903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)class RenderRubyRun;
4003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)class RenderBlockFlow;
4103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
4203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)enum IndentTextOrNot { DoNotIndentText, IndentText };
4303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)enum WhitespaceTreatment { ExcludeWhitespace, IncludeWhitespace };
4403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
4503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)class LineWidth {
4603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)public:
4703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    LineWidth(RenderBlockFlow&, bool isFirstLine, IndentTextOrNot shouldIndentText);
4803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
4903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    bool fitsOnLine() const { return currentWidth() <= (m_availableWidth + LayoutUnit::epsilon()); }
5003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    bool fitsOnLine(float extra) const { return currentWidth() + extra <= (m_availableWidth + LayoutUnit::epsilon()); }
5103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    bool fitsOnLine(float extra, WhitespaceTreatment whitespaceTreatment) const
5203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    {
5303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)        return currentWidth() - (whitespaceTreatment == ExcludeWhitespace ? trailingWhitespaceWidth() : 0) + extra <= (m_availableWidth + LayoutUnit::epsilon());
5403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    }
5503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
5603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    float currentWidth() const { return m_committedWidth + m_uncommittedWidth; }
5703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    // FIXME: We should eventually replace these three functions by ones that work on a higher abstraction.
5803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    float uncommittedWidth() const { return m_uncommittedWidth; }
5903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    float committedWidth() const { return m_committedWidth; }
6003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    float availableWidth() const { return m_availableWidth; }
6103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    float trailingWhitespaceWidth() const { return m_trailingWhitespaceWidth; }
6203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
6303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    void updateAvailableWidth(LayoutUnit minimumHeight = 0);
6403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    void shrinkAvailableWidthForNewFloatIfNeeded(FloatingObject*);
6503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    void addUncommittedWidth(float delta) { m_uncommittedWidth += delta; }
6603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    void commit();
6703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    void applyOverhang(RenderRubyRun*, RenderObject* startRenderer, RenderObject* endRenderer);
6803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    void fitBelowFloats(bool isFirstLine = false);
6903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    void setTrailingWhitespaceWidth(float width) { m_trailingWhitespaceWidth = width; }
7003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
7103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    bool shouldIndentText() const { return m_shouldIndentText == IndentText; }
7203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
7303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)private:
741320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    void computeAvailableWidthFromLeftAndRight();
7503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    void updateLineDimension(LayoutUnit newLineTop, LayoutUnit newLineWidth, const float& newLineLeft, const float& newLineRight);
7603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    void wrapNextToShapeOutside(bool isFirstLine);
7703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
7803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    RenderBlockFlow& m_block;
7903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    float m_uncommittedWidth;
8003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    float m_committedWidth;
8103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    float m_overhangWidth; // The amount by which |m_availableWidth| has been inflated to account for possible contraction due to ruby overhang.
8203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    float m_trailingWhitespaceWidth;
8303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    float m_left;
8403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    float m_right;
8503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    float m_availableWidth;
8603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    bool m_isFirstLine;
8703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    IndentTextOrNot m_shouldIndentText;
8803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)};
8903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
9003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)}
9103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
9203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#endif // LineWidth_h
9303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)