1/*
2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#ifndef SelectionRect_h
27#define SelectionRect_h
28
29#include "IntRect.h"
30#include "TextDirection.h"
31#include <wtf/FastMalloc.h>
32
33namespace WebCore {
34
35class SelectionRect {
36    WTF_MAKE_FAST_ALLOCATED;
37public:
38    explicit SelectionRect(const IntRect&, bool isHorizontal, int columnNumber);
39
40    // FIXME: We should move some of these arguments to an auxillary struct.
41    SelectionRect(const IntRect&, TextDirection, int, int, int, int, bool, bool, bool, bool, bool, bool, bool, bool, int);
42    SelectionRect();
43    ~SelectionRect() { }
44
45    IntRect rect() const { return m_rect; }
46
47    int logicalLeft() const { return m_isHorizontal ? m_rect.x() : m_rect.y(); }
48    int logicalWidth() const { return m_isHorizontal ? m_rect.width() : m_rect.height(); }
49    int logicalTop() const { return m_isHorizontal ? m_rect.y() : m_rect.x(); }
50    int logicalHeight() const { return m_isHorizontal ? m_rect.height() : m_rect.width(); }
51
52    TextDirection direction() const { return m_direction; }
53    int minX() const { return m_minX; }
54    int maxX() const { return m_maxX; }
55    int maxY() const { return m_maxY; }
56    int lineNumber() const { return m_lineNumber; }
57    bool isLineBreak() const { return m_isLineBreak; }
58    bool isFirstOnLine() const { return m_isFirstOnLine; }
59    bool isLastOnLine() const { return m_isLastOnLine; }
60    bool containsStart() const { return m_containsStart; }
61    bool containsEnd() const { return m_containsEnd; }
62    bool isHorizontal() const { return m_isHorizontal; }
63    bool isInFixedPosition() const { return m_isInFixedPosition; }
64    bool isRubyText() const { return m_isRubyText; }
65    int pageNumber() const { return m_pageNumber; }
66
67    void setRect(const IntRect& rect) { m_rect = rect; }
68
69    void setLogicalLeft(int left)
70    {
71        if (m_isHorizontal)
72            m_rect.setX(left);
73        else
74            m_rect.setY(left);
75    }
76
77    void setLogicalWidth(int width)
78    {
79        if (m_isHorizontal)
80            m_rect.setWidth(width);
81        else
82            m_rect.setHeight(width);
83    }
84
85    void setLogicalTop(int top)
86    {
87        if (m_isHorizontal)
88            m_rect.setY(top);
89        else
90            m_rect.setX(top);
91    }
92
93    void setLogicalHeight(int height)
94    {
95        if (m_isHorizontal)
96            m_rect.setHeight(height);
97        else
98            m_rect.setWidth(height);
99    }
100
101    void setDirection(TextDirection direction) { m_direction = direction; }
102    void setMinX(int minX) { m_minX = minX; }
103    void setMaxX(int maxX) { m_maxX = maxX; }
104    void setMaxY(int maxY) { m_maxY = maxY; }
105    void setLineNumber(int lineNumber) { m_lineNumber = lineNumber; }
106    void setIsLineBreak(bool isLineBreak) { m_isLineBreak = isLineBreak; }
107    void setIsFirstOnLine(bool isFirstOnLine) { m_isFirstOnLine = isFirstOnLine; }
108    void setIsLastOnLine(bool isLastOnLine) { m_isLastOnLine = isLastOnLine; }
109    void setContainsStart(bool containsStart) { m_containsStart = containsStart; }
110    void setContainsEnd(bool containsEnd) { m_containsEnd = containsEnd; }
111    void setIsHorizontal(bool isHorizontal) { m_isHorizontal = isHorizontal; }
112
113private:
114    IntRect m_rect;
115    TextDirection m_direction;
116    int m_minX;
117    int m_maxX;
118    int m_maxY;
119    int m_lineNumber;
120    bool m_isLineBreak;
121    bool m_isFirstOnLine;
122    bool m_isLastOnLine;
123    bool m_containsStart;
124    bool m_containsEnd;
125    bool m_isHorizontal;
126    bool m_isInFixedPosition;
127    bool m_isRubyText;
128    int m_pageNumber;
129};
130
131} // namespace WebCore
132
133#endif // SelectionRect_h
134