• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 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. ``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.
24  */
25 
26 #include "config.h"
27 #include "RenderScrollbarPart.h"
28 #include "RenderScrollbar.h"
29 #include "RenderScrollbarTheme.h"
30 
31 using namespace std;
32 
33 namespace WebCore {
34 
RenderScrollbarPart(Node * node,RenderScrollbar * scrollbar,ScrollbarPart part)35 RenderScrollbarPart::RenderScrollbarPart(Node* node, RenderScrollbar* scrollbar, ScrollbarPart part)
36     : RenderBlock(node)
37     , m_scrollbar(scrollbar)
38     , m_part(part)
39 {
40 }
41 
~RenderScrollbarPart()42 RenderScrollbarPart::~RenderScrollbarPart()
43 {
44 }
45 
layout()46 void RenderScrollbarPart::layout()
47 {
48     setLocation(IntPoint()); // We don't worry about positioning ourselves.  We're just determining our minimum width/height.
49     if (m_scrollbar->orientation() == HorizontalScrollbar)
50         layoutHorizontalPart();
51     else
52         layoutVerticalPart();
53 
54     m_overflowWidth = max(width(), m_overflowWidth);
55     m_overflowHeight = max(height(), m_overflowHeight);
56 
57     setNeedsLayout(false);
58 }
59 
layoutHorizontalPart()60 void RenderScrollbarPart::layoutHorizontalPart()
61 {
62     if (m_part == ScrollbarBGPart) {
63         setWidth(m_scrollbar->width());
64         computeScrollbarHeight();
65     } else {
66         computeScrollbarWidth();
67         setHeight(m_scrollbar->height());
68     }
69 }
70 
layoutVerticalPart()71 void RenderScrollbarPart::layoutVerticalPart()
72 {
73     if (m_part == ScrollbarBGPart) {
74         computeScrollbarWidth();
75         setHeight(m_scrollbar->height());
76     } else {
77         setWidth(m_scrollbar->width());
78         computeScrollbarHeight();
79     }
80 }
81 
calcScrollbarThicknessUsing(const Length & l,int containingLength)82 static int calcScrollbarThicknessUsing(const Length& l, int containingLength)
83 {
84     if (l.isIntrinsicOrAuto())
85         return ScrollbarTheme::nativeTheme()->scrollbarThickness();
86     return l.calcMinValue(containingLength);
87 }
88 
computeScrollbarWidth()89 void RenderScrollbarPart::computeScrollbarWidth()
90 {
91     int visibleSize = m_scrollbar->owningRenderer()->width() - m_scrollbar->owningRenderer()->borderLeft() - m_scrollbar->owningRenderer()->borderRight();
92     int w = calcScrollbarThicknessUsing(style()->width(), visibleSize);
93     int minWidth = calcScrollbarThicknessUsing(style()->minWidth(), visibleSize);
94     int maxWidth = style()->maxWidth().isUndefined() ? w : calcScrollbarThicknessUsing(style()->maxWidth(), visibleSize);
95     setWidth(max(minWidth, min(maxWidth, w)));
96 
97     // Buttons and track pieces can all have margins along the axis of the scrollbar.
98     m_marginLeft = style()->marginLeft().calcMinValue(visibleSize);
99     m_marginRight = style()->marginRight().calcMinValue(visibleSize);
100 }
101 
computeScrollbarHeight()102 void RenderScrollbarPart::computeScrollbarHeight()
103 {
104     int visibleSize = m_scrollbar->owningRenderer()->height() -  m_scrollbar->owningRenderer()->borderTop() - m_scrollbar->owningRenderer()->borderBottom();
105     int h = calcScrollbarThicknessUsing(style()->height(), visibleSize);
106     int minHeight = calcScrollbarThicknessUsing(style()->minHeight(), visibleSize);
107     int maxHeight = style()->maxHeight().isUndefined() ? h : calcScrollbarThicknessUsing(style()->maxHeight(), visibleSize);
108     setHeight(max(minHeight, min(maxHeight, h)));
109 
110     // Buttons and track pieces can all have margins along the axis of the scrollbar.
111     m_marginTop = style()->marginTop().calcMinValue(visibleSize);
112     m_marginBottom = style()->marginBottom().calcMinValue(visibleSize);
113 }
114 
calcPrefWidths()115 void RenderScrollbarPart::calcPrefWidths()
116 {
117     if (!prefWidthsDirty())
118         return;
119 
120     m_minPrefWidth = m_maxPrefWidth = 0;
121 
122     setPrefWidthsDirty(false);
123 }
124 
styleWillChange(RenderStyle::Diff diff,const RenderStyle * newStyle)125 void RenderScrollbarPart::styleWillChange(RenderStyle::Diff diff, const RenderStyle* newStyle)
126 {
127     RenderBlock::styleWillChange(diff, newStyle);
128     setInline(false);
129 }
130 
styleDidChange(RenderStyle::Diff diff,const RenderStyle * oldStyle)131 void RenderScrollbarPart::styleDidChange(RenderStyle::Diff diff, const RenderStyle* oldStyle)
132 {
133     RenderBlock::styleDidChange(diff, oldStyle);
134     setInline(false);
135     setPositioned(false);
136     setFloating(false);
137     setHasOverflowClip(false);
138     if (oldStyle && m_scrollbar && m_part != NoPart && diff >= RenderStyle::Repaint)
139         m_scrollbar->theme()->invalidatePart(m_scrollbar, m_part);
140 }
141 
imageChanged(WrappedImagePtr image,const IntRect * rect)142 void RenderScrollbarPart::imageChanged(WrappedImagePtr image, const IntRect* rect)
143 {
144     if (m_scrollbar && m_part != NoPart)
145         m_scrollbar->theme()->invalidatePart(m_scrollbar, m_part);
146     else
147         RenderBlock::imageChanged(image, rect);
148 }
149 
paintIntoRect(GraphicsContext * graphicsContext,int tx,int ty,const IntRect & rect)150 void RenderScrollbarPart::paintIntoRect(GraphicsContext* graphicsContext, int tx, int ty, const IntRect& rect)
151 {
152     // Make sure our dimensions match the rect.
153     setLocation(rect.x() - tx, rect.y() - ty);
154     setWidth(rect.width());
155     setHeight(rect.height());
156     setOverflowWidth(max(rect.width(), overflowWidth()));
157     setOverflowHeight(max(rect.height(), overflowHeight()));
158 
159     if (graphicsContext->paintingDisabled())
160         return;
161 
162     // Now do the paint.
163     RenderObject::PaintInfo paintInfo(graphicsContext, rect, PaintPhaseBlockBackground, false, 0, 0);
164     paint(paintInfo, tx, ty);
165     paintInfo.phase = PaintPhaseChildBlockBackgrounds;
166     paint(paintInfo, tx, ty);
167     paintInfo.phase = PaintPhaseFloat;
168     paint(paintInfo, tx, ty);
169     paintInfo.phase = PaintPhaseForeground;
170     paint(paintInfo, tx, ty);
171     paintInfo.phase = PaintPhaseOutline;
172     paint(paintInfo, tx, ty);
173 }
174 
175 }
176