2 * Copyright (C) 2008 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
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 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.
27 #include "RenderScrollbarPart.h"
29 #include "PaintInfo.h"
30 #include "RenderScrollbar.h"
31 #include "RenderScrollbarTheme.h"
32 #include "RenderView.h"
38 RenderScrollbarPart::RenderScrollbarPart(Node* node, RenderScrollbar* scrollbar, ScrollbarPart part)
40 , m_scrollbar(scrollbar)
45 RenderScrollbarPart::~RenderScrollbarPart()
49 void RenderScrollbarPart::layout()
51 setLocation(LayoutPoint()); // We don't worry about positioning ourselves. We're just determining our minimum width/height.
52 if (m_scrollbar->orientation() == HorizontalScrollbar)
53 layoutHorizontalPart();
57 setNeedsLayout(false);
60 void RenderScrollbarPart::layoutHorizontalPart()
62 if (m_part == ScrollbarBGPart) {
63 setWidth(m_scrollbar->width());
64 computeScrollbarHeight();
66 computeScrollbarWidth();
67 setHeight(m_scrollbar->height());
71 void RenderScrollbarPart::layoutVerticalPart()
73 if (m_part == ScrollbarBGPart) {
74 computeScrollbarWidth();
75 setHeight(m_scrollbar->height());
77 setWidth(m_scrollbar->width());
78 computeScrollbarHeight();
82 static int calcScrollbarThicknessUsing(const Length& l, int containingLength)
84 if (l.isIntrinsicOrAuto())
85 return ScrollbarTheme::nativeTheme()->scrollbarThickness();
86 return l.calcMinValue(containingLength);
89 void RenderScrollbarPart::computeScrollbarWidth()
91 if (!m_scrollbar->owningRenderer())
93 int visibleSize = m_scrollbar->owningRenderer()->width() - m_scrollbar->owningRenderer()->borderLeft() - m_scrollbar->owningRenderer()->borderRight();
94 int w = calcScrollbarThicknessUsing(style()->width(), visibleSize);
95 int minWidth = calcScrollbarThicknessUsing(style()->minWidth(), visibleSize);
96 int maxWidth = style()->maxWidth().isUndefined() ? w : calcScrollbarThicknessUsing(style()->maxWidth(), visibleSize);
97 setWidth(max(minWidth, min(maxWidth, w)));
99 // Buttons and track pieces can all have margins along the axis of the scrollbar.
100 m_marginLeft = style()->marginLeft().calcMinValue(visibleSize);
101 m_marginRight = style()->marginRight().calcMinValue(visibleSize);
104 void RenderScrollbarPart::computeScrollbarHeight()
106 if (!m_scrollbar->owningRenderer())
108 int visibleSize = m_scrollbar->owningRenderer()->height() - m_scrollbar->owningRenderer()->borderTop() - m_scrollbar->owningRenderer()->borderBottom();
109 int h = calcScrollbarThicknessUsing(style()->height(), visibleSize);
110 int minHeight = calcScrollbarThicknessUsing(style()->minHeight(), visibleSize);
111 int maxHeight = style()->maxHeight().isUndefined() ? h : calcScrollbarThicknessUsing(style()->maxHeight(), visibleSize);
112 setHeight(max(minHeight, min(maxHeight, h)));
114 // Buttons and track pieces can all have margins along the axis of the scrollbar.
115 m_marginTop = style()->marginTop().calcMinValue(visibleSize);
116 m_marginBottom = style()->marginBottom().calcMinValue(visibleSize);
119 void RenderScrollbarPart::computePreferredLogicalWidths()
121 if (!preferredLogicalWidthsDirty())
124 m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = 0;
126 setPreferredLogicalWidthsDirty(false);
129 void RenderScrollbarPart::styleWillChange(StyleDifference diff, const RenderStyle* newStyle)
131 RenderBlock::styleWillChange(diff, newStyle);
135 void RenderScrollbarPart::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
137 RenderBlock::styleDidChange(diff, oldStyle);
139 setPositioned(false);
141 setHasOverflowClip(false);
142 if (oldStyle && m_scrollbar && m_part != NoPart && diff >= StyleDifferenceRepaint)
143 m_scrollbar->theme()->invalidatePart(m_scrollbar, m_part);
146 void RenderScrollbarPart::imageChanged(WrappedImagePtr image, const IntRect* rect)
148 if (m_scrollbar && m_part != NoPart)
149 m_scrollbar->theme()->invalidatePart(m_scrollbar, m_part);
151 if (FrameView* frameView = view()->frameView()) {
152 if (frameView->isFrameViewScrollCorner(this)) {
153 frameView->invalidateScrollCorner();
158 RenderBlock::imageChanged(image, rect);
162 void RenderScrollbarPart::paintIntoRect(GraphicsContext* graphicsContext, const LayoutPoint& paintOffset, const LayoutRect& rect)
164 // Make sure our dimensions match the rect.
165 setLocation(rect.location() - toSize(paintOffset));
166 setWidth(rect.width());
167 setHeight(rect.height());
169 if (graphicsContext->paintingDisabled())
173 PaintInfo paintInfo(graphicsContext, rect, PaintPhaseBlockBackground, false, 0, 0);
174 paint(paintInfo, paintOffset);
175 paintInfo.phase = PaintPhaseChildBlockBackgrounds;
176 paint(paintInfo, paintOffset);
177 paintInfo.phase = PaintPhaseFloat;
178 paint(paintInfo, paintOffset);
179 paintInfo.phase = PaintPhaseForeground;
180 paint(paintInfo, paintOffset);
181 paintInfo.phase = PaintPhaseOutline;
182 paint(paintInfo, paintOffset);