Updated WebKit from /home/shausman/src/webkit/trunk to qtwebkit-4.6-snapshot-29062009...
[qt-netbsd.git] / src / 3rdparty / webkit / WebCore / rendering / RenderDataGrid.cpp
blobb207a316973c334de814afb8ed5a8ee26ede8947
1 /*
2 * Copyright (C) 2009 Apple Inc. All rights reserved.
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.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #include "config.h"
27 #include "RenderDataGrid.h"
29 #include "FocusController.h"
30 #include "Frame.h"
31 #include "GraphicsContext.h"
32 #include "Page.h"
33 #include "Scrollbar.h"
35 using std::min;
37 namespace WebCore {
39 static const int cDefaultWidth = 300;
41 RenderDataGrid::RenderDataGrid(Element* elt)
42 : RenderBlock(elt)
46 RenderDataGrid::~RenderDataGrid()
50 void RenderDataGrid::calcPrefWidths()
52 m_minPrefWidth = 0;
53 m_maxPrefWidth = 0;
55 if (style()->width().isFixed() && style()->width().value() > 0)
56 m_minPrefWidth = m_maxPrefWidth = calcContentBoxWidth(style()->width().value());
57 else
58 m_maxPrefWidth = calcContentBoxWidth(cDefaultWidth);
60 if (style()->minWidth().isFixed() && style()->minWidth().value() > 0) {
61 m_maxPrefWidth = max(m_maxPrefWidth, calcContentBoxWidth(style()->minWidth().value()));
62 m_minPrefWidth = max(m_minPrefWidth, calcContentBoxWidth(style()->minWidth().value()));
63 } else if (style()->width().isPercent() || (style()->width().isAuto() && style()->height().isPercent()))
64 m_minPrefWidth = 0;
65 else
66 m_minPrefWidth = m_maxPrefWidth;
68 if (style()->maxWidth().isFixed() && style()->maxWidth().value() != undefinedLength) {
69 m_maxPrefWidth = min(m_maxPrefWidth, calcContentBoxWidth(style()->maxWidth().value()));
70 m_minPrefWidth = min(m_minPrefWidth, calcContentBoxWidth(style()->maxWidth().value()));
73 int toAdd = paddingLeft() + paddingRight() + borderLeft() + borderRight();
74 m_minPrefWidth += toAdd;
75 m_maxPrefWidth += toAdd;
77 setPrefWidthsDirty(false);
80 void RenderDataGrid::paintObject(PaintInfo& paintInfo, int tx, int ty)
82 if (style()->visibility() != VISIBLE)
83 return;
85 // Paint our background and border.
86 RenderBlock::paintObject(paintInfo, tx, ty);
88 if (paintInfo.phase != PaintPhaseForeground)
89 return;
91 // Paint our column headers first.
92 paintColumnHeaders(paintInfo, tx, ty);
95 void RenderDataGrid::paintColumnHeaders(PaintInfo&, int, int)
97 gridElement()->columns();
101 void RenderDataGrid::rebuildColumns()
105 // Scrolling implementation functions
106 void RenderDataGrid::valueChanged(Scrollbar*)
108 // FIXME: Implement.
111 void RenderDataGrid::invalidateScrollbarRect(Scrollbar*, const IntRect&)
113 // FIXME: Implement.
116 bool RenderDataGrid::isActive() const
118 Page* page = document()->frame()->page();
119 return page && page->focusController()->isActive();