OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "config.h" | 26 #include "config.h" |
27 #include "core/rendering/RenderScrollbarPart.h" | 27 #include "core/layout/LayoutScrollbarPart.h" |
28 | 28 |
29 #include "core/frame/UseCounter.h" | 29 #include "core/frame/UseCounter.h" |
| 30 #include "core/layout/LayoutScrollbar.h" |
| 31 #include "core/layout/LayoutScrollbarTheme.h" |
30 #include "core/layout/PaintInfo.h" | 32 #include "core/layout/PaintInfo.h" |
31 #include "core/rendering/RenderScrollbar.h" | |
32 #include "core/rendering/RenderScrollbarTheme.h" | |
33 #include "core/rendering/RenderView.h" | 33 #include "core/rendering/RenderView.h" |
34 #include "platform/LengthFunctions.h" | 34 #include "platform/LengthFunctions.h" |
35 | 35 |
36 namespace blink { | 36 namespace blink { |
37 | 37 |
38 RenderScrollbarPart::RenderScrollbarPart(RenderScrollbar* scrollbar, ScrollbarPa
rt part) | 38 LayoutScrollbarPart::LayoutScrollbarPart(LayoutScrollbar* scrollbar, ScrollbarPa
rt part) |
39 : RenderBlock(0) | 39 : RenderBlock(0) |
40 , m_scrollbar(scrollbar) | 40 , m_scrollbar(scrollbar) |
41 , m_part(part) | 41 , m_part(part) |
42 { | 42 { |
43 } | 43 } |
44 | 44 |
45 RenderScrollbarPart::~RenderScrollbarPart() | 45 LayoutScrollbarPart::~LayoutScrollbarPart() |
46 { | 46 { |
47 } | 47 } |
48 | 48 |
49 static void recordScrollbarPartStats(Document& document, ScrollbarPart part) | 49 static void recordScrollbarPartStats(Document& document, ScrollbarPart part) |
50 { | 50 { |
51 switch (part) { | 51 switch (part) { |
52 case BackButtonStartPart: | 52 case BackButtonStartPart: |
53 case ForwardButtonStartPart: | 53 case ForwardButtonStartPart: |
54 case BackButtonEndPart: | 54 case BackButtonEndPart: |
55 case ForwardButtonEndPart: | 55 case ForwardButtonEndPart: |
(...skipping 11 matching lines...) Expand all Loading... |
67 break; | 67 break; |
68 case ScrollbarBGPart: | 68 case ScrollbarBGPart: |
69 UseCounter::count(document, UseCounter::CSSSelectorPseudoScrollbar); | 69 UseCounter::count(document, UseCounter::CSSSelectorPseudoScrollbar); |
70 break; | 70 break; |
71 case NoPart: | 71 case NoPart: |
72 case AllParts: | 72 case AllParts: |
73 break; | 73 break; |
74 } | 74 } |
75 } | 75 } |
76 | 76 |
77 RenderScrollbarPart* RenderScrollbarPart::createAnonymous(Document* document, Re
nderScrollbar* scrollbar, ScrollbarPart part) | 77 LayoutScrollbarPart* LayoutScrollbarPart::createAnonymous(Document* document, La
youtScrollbar* scrollbar, ScrollbarPart part) |
78 { | 78 { |
79 RenderScrollbarPart* renderer = new RenderScrollbarPart(scrollbar, part); | 79 LayoutScrollbarPart* renderer = new LayoutScrollbarPart(scrollbar, part); |
80 recordScrollbarPartStats(*document, part); | 80 recordScrollbarPartStats(*document, part); |
81 renderer->setDocumentForAnonymous(document); | 81 renderer->setDocumentForAnonymous(document); |
82 return renderer; | 82 return renderer; |
83 } | 83 } |
84 | 84 |
85 void RenderScrollbarPart::layout() | 85 void LayoutScrollbarPart::layout() |
86 { | 86 { |
87 setLocation(LayoutPoint()); // We don't worry about positioning ourselves. W
e're just determining our minimum width/height. | 87 setLocation(LayoutPoint()); // We don't worry about positioning ourselves. W
e're just determining our minimum width/height. |
88 if (m_scrollbar->orientation() == HorizontalScrollbar) | 88 if (m_scrollbar->orientation() == HorizontalScrollbar) |
89 layoutHorizontalPart(); | 89 layoutHorizontalPart(); |
90 else | 90 else |
91 layoutVerticalPart(); | 91 layoutVerticalPart(); |
92 | 92 |
93 clearNeedsLayout(); | 93 clearNeedsLayout(); |
94 } | 94 } |
95 | 95 |
96 void RenderScrollbarPart::layoutHorizontalPart() | 96 void LayoutScrollbarPart::layoutHorizontalPart() |
97 { | 97 { |
98 if (m_part == ScrollbarBGPart) { | 98 if (m_part == ScrollbarBGPart) { |
99 setWidth(m_scrollbar->width()); | 99 setWidth(m_scrollbar->width()); |
100 computeScrollbarHeight(); | 100 computeScrollbarHeight(); |
101 } else { | 101 } else { |
102 computeScrollbarWidth(); | 102 computeScrollbarWidth(); |
103 setHeight(m_scrollbar->height()); | 103 setHeight(m_scrollbar->height()); |
104 } | 104 } |
105 } | 105 } |
106 | 106 |
107 void RenderScrollbarPart::layoutVerticalPart() | 107 void LayoutScrollbarPart::layoutVerticalPart() |
108 { | 108 { |
109 if (m_part == ScrollbarBGPart) { | 109 if (m_part == ScrollbarBGPart) { |
110 computeScrollbarWidth(); | 110 computeScrollbarWidth(); |
111 setHeight(m_scrollbar->height()); | 111 setHeight(m_scrollbar->height()); |
112 } else { | 112 } else { |
113 setWidth(m_scrollbar->width()); | 113 setWidth(m_scrollbar->width()); |
114 computeScrollbarHeight(); | 114 computeScrollbarHeight(); |
115 } | 115 } |
116 } | 116 } |
117 | 117 |
118 static int calcScrollbarThicknessUsing(SizeType sizeType, const Length& length,
int containingLength) | 118 static int calcScrollbarThicknessUsing(SizeType sizeType, const Length& length,
int containingLength) |
119 { | 119 { |
120 if (!length.isIntrinsicOrAuto() || (sizeType == MinSize && length.isAuto())) | 120 if (!length.isIntrinsicOrAuto() || (sizeType == MinSize && length.isAuto())) |
121 return minimumValueForLength(length, containingLength); | 121 return minimumValueForLength(length, containingLength); |
122 return ScrollbarTheme::theme()->scrollbarThickness(); | 122 return ScrollbarTheme::theme()->scrollbarThickness(); |
123 } | 123 } |
124 | 124 |
125 void RenderScrollbarPart::computeScrollbarWidth() | 125 void LayoutScrollbarPart::computeScrollbarWidth() |
126 { | 126 { |
127 if (!m_scrollbar->owningRenderer()) | 127 if (!m_scrollbar->owningRenderer()) |
128 return; | 128 return; |
129 // FIXME: We are querying layout information but nothing guarantees that it'
s up-to-date, especially since we are called at style change. | 129 // FIXME: We are querying layout information but nothing guarantees that it'
s up-to-date, especially since we are called at style change. |
130 // FIXME: Querying the style's border information doesn't work on table cell
s with collapsing borders. | 130 // FIXME: Querying the style's border information doesn't work on table cell
s with collapsing borders. |
131 int visibleSize = m_scrollbar->owningRenderer()->size().width() - m_scrollba
r->owningRenderer()->style()->borderLeftWidth() - m_scrollbar->owningRenderer()-
>style()->borderRightWidth(); | 131 int visibleSize = m_scrollbar->owningRenderer()->size().width() - m_scrollba
r->owningRenderer()->style()->borderLeftWidth() - m_scrollbar->owningRenderer()-
>style()->borderRightWidth(); |
132 int w = calcScrollbarThicknessUsing(MainOrPreferredSize, style()->width(), v
isibleSize); | 132 int w = calcScrollbarThicknessUsing(MainOrPreferredSize, style()->width(), v
isibleSize); |
133 int minWidth = calcScrollbarThicknessUsing(MinSize, style()->minWidth(), vis
ibleSize); | 133 int minWidth = calcScrollbarThicknessUsing(MinSize, style()->minWidth(), vis
ibleSize); |
134 int maxWidth = style()->maxWidth().isMaxSizeNone() ? w : calcScrollbarThickn
essUsing(MaxSize, style()->maxWidth(), visibleSize); | 134 int maxWidth = style()->maxWidth().isMaxSizeNone() ? w : calcScrollbarThickn
essUsing(MaxSize, style()->maxWidth(), visibleSize); |
135 setWidth(std::max(minWidth, std::min(maxWidth, w))); | 135 setWidth(std::max(minWidth, std::min(maxWidth, w))); |
136 | 136 |
137 // Buttons and track pieces can all have margins along the axis of the scrol
lbar. | 137 // Buttons and track pieces can all have margins along the axis of the scrol
lbar. |
138 setMarginLeft(minimumValueForLength(style()->marginLeft(), visibleSize)); | 138 setMarginLeft(minimumValueForLength(style()->marginLeft(), visibleSize)); |
139 setMarginRight(minimumValueForLength(style()->marginRight(), visibleSize)); | 139 setMarginRight(minimumValueForLength(style()->marginRight(), visibleSize)); |
140 } | 140 } |
141 | 141 |
142 void RenderScrollbarPart::computeScrollbarHeight() | 142 void LayoutScrollbarPart::computeScrollbarHeight() |
143 { | 143 { |
144 if (!m_scrollbar->owningRenderer()) | 144 if (!m_scrollbar->owningRenderer()) |
145 return; | 145 return; |
146 // FIXME: We are querying layout information but nothing guarantees that it'
s up-to-date, especially since we are called at style change. | 146 // FIXME: We are querying layout information but nothing guarantees that it'
s up-to-date, especially since we are called at style change. |
147 // FIXME: Querying the style's border information doesn't work on table cell
s with collapsing borders. | 147 // FIXME: Querying the style's border information doesn't work on table cell
s with collapsing borders. |
148 int visibleSize = m_scrollbar->owningRenderer()->size().height() - m_scroll
bar->owningRenderer()->style()->borderTopWidth() - m_scrollbar->owningRenderer()
->style()->borderBottomWidth(); | 148 int visibleSize = m_scrollbar->owningRenderer()->size().height() - m_scroll
bar->owningRenderer()->style()->borderTopWidth() - m_scrollbar->owningRenderer()
->style()->borderBottomWidth(); |
149 int h = calcScrollbarThicknessUsing(MainOrPreferredSize, style()->height(),
visibleSize); | 149 int h = calcScrollbarThicknessUsing(MainOrPreferredSize, style()->height(),
visibleSize); |
150 int minHeight = calcScrollbarThicknessUsing(MinSize, style()->minHeight(), v
isibleSize); | 150 int minHeight = calcScrollbarThicknessUsing(MinSize, style()->minHeight(), v
isibleSize); |
151 int maxHeight = style()->maxHeight().isMaxSizeNone() ? h : calcScrollbarThic
knessUsing(MaxSize, style()->maxHeight(), visibleSize); | 151 int maxHeight = style()->maxHeight().isMaxSizeNone() ? h : calcScrollbarThic
knessUsing(MaxSize, style()->maxHeight(), visibleSize); |
152 setHeight(std::max(minHeight, std::min(maxHeight, h))); | 152 setHeight(std::max(minHeight, std::min(maxHeight, h))); |
153 | 153 |
154 // Buttons and track pieces can all have margins along the axis of the scrol
lbar. | 154 // Buttons and track pieces can all have margins along the axis of the scrol
lbar. |
155 setMarginTop(minimumValueForLength(style()->marginTop(), visibleSize)); | 155 setMarginTop(minimumValueForLength(style()->marginTop(), visibleSize)); |
156 setMarginBottom(minimumValueForLength(style()->marginBottom(), visibleSize))
; | 156 setMarginBottom(minimumValueForLength(style()->marginBottom(), visibleSize))
; |
157 } | 157 } |
158 | 158 |
159 void RenderScrollbarPart::computePreferredLogicalWidths() | 159 void LayoutScrollbarPart::computePreferredLogicalWidths() |
160 { | 160 { |
161 if (!preferredLogicalWidthsDirty()) | 161 if (!preferredLogicalWidthsDirty()) |
162 return; | 162 return; |
163 | 163 |
164 m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = 0; | 164 m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = 0; |
165 | 165 |
166 clearPreferredLogicalWidthsDirty(); | 166 clearPreferredLogicalWidthsDirty(); |
167 } | 167 } |
168 | 168 |
169 void RenderScrollbarPart::styleWillChange(StyleDifference diff, const LayoutStyl
e& newStyle) | 169 void LayoutScrollbarPart::styleWillChange(StyleDifference diff, const LayoutStyl
e& newStyle) |
170 { | 170 { |
171 RenderBlock::styleWillChange(diff, newStyle); | 171 RenderBlock::styleWillChange(diff, newStyle); |
172 setInline(false); | 172 setInline(false); |
173 } | 173 } |
174 | 174 |
175 void RenderScrollbarPart::styleDidChange(StyleDifference diff, const LayoutStyle
* oldStyle) | 175 void LayoutScrollbarPart::styleDidChange(StyleDifference diff, const LayoutStyle
* oldStyle) |
176 { | 176 { |
177 RenderBlock::styleDidChange(diff, oldStyle); | 177 RenderBlock::styleDidChange(diff, oldStyle); |
178 setInline(false); | 178 setInline(false); |
179 clearPositionedState(); | 179 clearPositionedState(); |
180 setFloating(false); | 180 setFloating(false); |
181 setHasOverflowClip(false); | 181 setHasOverflowClip(false); |
182 if (oldStyle && m_scrollbar && m_part != NoPart && (diff.needsPaintInvalidat
ion() || diff.needsLayout())) | 182 if (oldStyle && m_scrollbar && m_part != NoPart && (diff.needsPaintInvalidat
ion() || diff.needsLayout())) |
183 m_scrollbar->theme()->invalidatePart(m_scrollbar, m_part); | 183 m_scrollbar->theme()->invalidatePart(m_scrollbar, m_part); |
184 } | 184 } |
185 | 185 |
186 void RenderScrollbarPart::imageChanged(WrappedImagePtr image, const IntRect* rec
t) | 186 void LayoutScrollbarPart::imageChanged(WrappedImagePtr image, const IntRect* rec
t) |
187 { | 187 { |
188 if (m_scrollbar && m_part != NoPart) | 188 if (m_scrollbar && m_part != NoPart) { |
189 m_scrollbar->theme()->invalidatePart(m_scrollbar, m_part); | 189 m_scrollbar->theme()->invalidatePart(m_scrollbar, m_part); |
190 else { | 190 } else { |
191 if (FrameView* frameView = view()->frameView()) { | 191 if (FrameView* frameView = view()->frameView()) { |
192 if (frameView->isFrameViewScrollCorner(this)) { | 192 if (frameView->isFrameViewScrollCorner(this)) { |
193 frameView->invalidateScrollCorner(frameView->scrollCornerRect())
; | 193 frameView->invalidateScrollCorner(frameView->scrollCornerRect())
; |
194 return; | 194 return; |
195 } | 195 } |
196 } | 196 } |
197 | 197 |
198 RenderBlock::imageChanged(image, rect); | 198 RenderBlock::imageChanged(image, rect); |
199 } | 199 } |
200 } | 200 } |
201 | 201 |
202 LayoutObject* RenderScrollbarPart::rendererOwningScrollbar() const | 202 LayoutObject* LayoutScrollbarPart::rendererOwningScrollbar() const |
203 { | 203 { |
204 if (!m_scrollbar) | 204 if (!m_scrollbar) |
205 return 0; | 205 return 0; |
206 return m_scrollbar->owningRenderer(); | 206 return m_scrollbar->owningRenderer(); |
207 } | 207 } |
208 | 208 |
209 } | 209 } |
OLD | NEW |