OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2011 Google 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 * | |
8 * 1. Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * 2. Redistributions in binary form must reproduce the above copyright | |
11 * notice, this list of conditions and the following disclaimer in the | |
12 * documentation and/or other materials provided with the distribution. | |
13 * | |
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | |
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | |
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 */ | |
25 | |
26 #include "config.h" | |
27 #include "web/ScrollbarGroup.h" | |
28 | |
29 #include "core/frame/FrameView.h" | |
30 #include "platform/scroll/Scrollbar.h" | |
31 #include "platform/scroll/ScrollbarTheme.h" | |
32 #include "public/platform/WebRect.h" | |
33 #include "web/WebPluginScrollbarImpl.h" | |
34 | |
35 namespace blink { | |
36 | |
37 ScrollbarGroup::ScrollbarGroup(FrameView* frameView, const IntRect& frameRect) | |
38 : m_frameView(frameView) | |
39 , m_frameRect(frameRect) | |
40 , m_horizontalScrollbar(0) | |
41 , m_verticalScrollbar(0) | |
42 { | |
43 } | |
44 | |
45 ScrollbarGroup::~ScrollbarGroup() | |
46 { | |
47 ASSERT(!m_horizontalScrollbar); | |
48 ASSERT(!m_verticalScrollbar); | |
49 } | |
50 | |
51 void ScrollbarGroup::scrollbarCreated(WebPluginScrollbarImpl* scrollbar) | |
52 { | |
53 bool hadScrollbars = m_horizontalScrollbar || m_verticalScrollbar; | |
54 if (scrollbar->scrollbar()->orientation() == HorizontalScrollbar) { | |
55 ASSERT(!m_horizontalScrollbar); | |
56 m_horizontalScrollbar = scrollbar; | |
57 didAddScrollbar(scrollbar->scrollbar(), HorizontalScrollbar); | |
58 } else { | |
59 ASSERT(!m_verticalScrollbar); | |
60 m_verticalScrollbar = scrollbar; | |
61 didAddScrollbar(scrollbar->scrollbar(), VerticalScrollbar); | |
62 } | |
63 | |
64 if (!hadScrollbars) { | |
65 m_frameView->addScrollableArea(this); | |
66 m_frameView->setNeedsLayout(); | |
67 } | |
68 } | |
69 | |
70 void ScrollbarGroup::scrollbarDestroyed(WebPluginScrollbarImpl* scrollbar) | |
71 { | |
72 if (scrollbar == m_horizontalScrollbar) { | |
73 willRemoveScrollbar(scrollbar->scrollbar(), HorizontalScrollbar); | |
74 m_horizontalScrollbar = 0; | |
75 } else { | |
76 ASSERT(scrollbar == m_verticalScrollbar); | |
77 willRemoveScrollbar(scrollbar->scrollbar(), VerticalScrollbar); | |
78 m_verticalScrollbar = 0; | |
79 } | |
80 | |
81 if (!m_horizontalScrollbar && !m_verticalScrollbar) { | |
82 m_frameView->removeScrollableArea(this); | |
83 m_frameView->setNeedsLayout(); | |
84 } | |
85 } | |
86 | |
87 void ScrollbarGroup::setLastMousePosition(const IntPoint& point) | |
88 { | |
89 m_lastMousePosition = point; | |
90 } | |
91 | |
92 int ScrollbarGroup::scrollSize(ScrollbarOrientation orientation) const | |
93 { | |
94 WebPluginScrollbarImpl* webScrollbar = orientation == HorizontalScrollbar ?
m_horizontalScrollbar : m_verticalScrollbar; | |
95 if (!webScrollbar) | |
96 return 0; | |
97 Scrollbar* scrollbar = webScrollbar->scrollbar(); | |
98 return scrollbar->totalSize() - scrollbar->visibleSize(); | |
99 } | |
100 | |
101 void ScrollbarGroup::setScrollOffset(const IntPoint& offset) | |
102 { | |
103 if (m_horizontalScrollbar && m_horizontalScrollbar->scrollOffset() != offset
.x()) | |
104 m_horizontalScrollbar->setScrollOffset(offset.x()); | |
105 else if (m_verticalScrollbar && m_verticalScrollbar->scrollOffset() != offse
t.y()) | |
106 m_verticalScrollbar->setScrollOffset(offset.y()); | |
107 } | |
108 | |
109 void ScrollbarGroup::invalidateScrollbarRect(Scrollbar* scrollbar, const IntRect
& rect) | |
110 { | |
111 if (m_horizontalScrollbar && scrollbar == m_horizontalScrollbar->scrollbar()
) | |
112 m_horizontalScrollbar->invalidateScrollbarRect(rect); | |
113 else if (m_verticalScrollbar && scrollbar == m_verticalScrollbar->scrollbar(
)) | |
114 m_verticalScrollbar->invalidateScrollbarRect(rect); | |
115 } | |
116 | |
117 void ScrollbarGroup::invalidateScrollCornerRect(const IntRect&) | |
118 { | |
119 } | |
120 | |
121 bool ScrollbarGroup::isActive() const | |
122 { | |
123 return true; | |
124 } | |
125 | |
126 void ScrollbarGroup::setFrameRect(const IntRect& frameRect) | |
127 { | |
128 m_frameRect = frameRect; | |
129 } | |
130 | |
131 IntRect ScrollbarGroup::scrollableAreaBoundingBox() const | |
132 { | |
133 return m_frameRect; | |
134 } | |
135 | |
136 bool ScrollbarGroup::isScrollCornerVisible() const | |
137 { | |
138 return false; | |
139 } | |
140 | |
141 void ScrollbarGroup::getTickmarks(Vector<IntRect>& tickmarks) const | |
142 { | |
143 if (m_verticalScrollbar) | |
144 m_verticalScrollbar->getTickmarks(tickmarks); | |
145 } | |
146 | |
147 IntPoint ScrollbarGroup::convertFromContainingViewToScrollbar(const Scrollbar* s
crollbar, const IntPoint& parentPoint) const | |
148 { | |
149 if (m_horizontalScrollbar && scrollbar == m_horizontalScrollbar->scrollbar()
) | |
150 return m_horizontalScrollbar->convertFromContainingViewToScrollbar(paren
tPoint); | |
151 if (m_verticalScrollbar && scrollbar == m_verticalScrollbar->scrollbar()) | |
152 return m_verticalScrollbar->convertFromContainingViewToScrollbar(parentP
oint); | |
153 BLINK_ASSERT_NOT_REACHED(); | |
154 return IntPoint(); | |
155 } | |
156 | |
157 Scrollbar* ScrollbarGroup::horizontalScrollbar() const | |
158 { | |
159 return m_horizontalScrollbar ? m_horizontalScrollbar->scrollbar() : 0; | |
160 } | |
161 | |
162 Scrollbar* ScrollbarGroup::verticalScrollbar() const | |
163 { | |
164 return m_verticalScrollbar ? m_verticalScrollbar->scrollbar() : 0; | |
165 } | |
166 | |
167 IntPoint ScrollbarGroup::scrollPosition() const | |
168 { | |
169 int x = m_horizontalScrollbar ? m_horizontalScrollbar->scrollOffset() : 0; | |
170 int y = m_verticalScrollbar ? m_verticalScrollbar->scrollOffset() : 0; | |
171 return IntPoint(x, y); | |
172 } | |
173 | |
174 IntPoint ScrollbarGroup::minimumScrollPosition() const | |
175 { | |
176 return IntPoint(); | |
177 } | |
178 | |
179 IntPoint ScrollbarGroup::maximumScrollPosition() const | |
180 { | |
181 return IntPoint(contentsSize().width() - visibleWidth(), contentsSize().heig
ht() - visibleHeight()); | |
182 } | |
183 | |
184 int ScrollbarGroup::visibleHeight() const | |
185 { | |
186 if (m_verticalScrollbar) | |
187 return m_verticalScrollbar->scrollbar()->height(); | |
188 if (m_horizontalScrollbar) | |
189 return m_horizontalScrollbar->scrollbar()->height(); | |
190 BLINK_ASSERT_NOT_REACHED(); | |
191 return 0; | |
192 } | |
193 | |
194 int ScrollbarGroup::visibleWidth() const | |
195 { | |
196 if (m_horizontalScrollbar) | |
197 return m_horizontalScrollbar->scrollbar()->width(); | |
198 if (m_verticalScrollbar) | |
199 return m_verticalScrollbar->scrollbar()->width(); | |
200 BLINK_ASSERT_NOT_REACHED(); | |
201 return 0; | |
202 } | |
203 | |
204 IntSize ScrollbarGroup::contentsSize() const | |
205 { | |
206 IntSize size; | |
207 if (m_horizontalScrollbar) | |
208 size.setWidth(m_horizontalScrollbar->scrollbar()->totalSize()); | |
209 else if (m_verticalScrollbar) { | |
210 size.setWidth(m_verticalScrollbar->scrollbar()->x()); | |
211 if (m_verticalScrollbar->scrollbar()->isOverlayScrollbar()) | |
212 size.expand(WebPluginScrollbar::defaultThickness(), 0); | |
213 } | |
214 if (m_verticalScrollbar) | |
215 size.setHeight(m_verticalScrollbar->scrollbar()->totalSize()); | |
216 else if (m_horizontalScrollbar) { | |
217 size.setHeight(m_horizontalScrollbar->scrollbar()->y()); | |
218 if (m_horizontalScrollbar->scrollbar()->isOverlayScrollbar()) | |
219 size.expand(0, WebPluginScrollbar::defaultThickness()); | |
220 } | |
221 return size; | |
222 } | |
223 | |
224 IntPoint ScrollbarGroup::lastKnownMousePosition() const | |
225 { | |
226 return m_lastMousePosition; | |
227 } | |
228 | |
229 bool ScrollbarGroup::shouldSuspendScrollAnimations() const | |
230 { | |
231 return false; | |
232 } | |
233 | |
234 void ScrollbarGroup::scrollbarStyleChanged() | |
235 { | |
236 if (m_horizontalScrollbar) | |
237 m_horizontalScrollbar->scrollbarStyleChanged(); | |
238 if (m_verticalScrollbar) | |
239 m_verticalScrollbar->scrollbarStyleChanged(); | |
240 } | |
241 | |
242 bool ScrollbarGroup::scrollbarsCanBeActive() const | |
243 { | |
244 return true; | |
245 } | |
246 | |
247 bool ScrollbarGroup::userInputScrollable(ScrollbarOrientation orientation) const | |
248 { | |
249 return orientation == HorizontalScrollbar ? horizontalScrollbar() : vertical
Scrollbar(); | |
250 } | |
251 | |
252 bool ScrollbarGroup::shouldPlaceVerticalScrollbarOnLeft() const | |
253 { | |
254 return false; | |
255 } | |
256 | |
257 int ScrollbarGroup::pageStep(ScrollbarOrientation orientation) const | |
258 { | |
259 int length; | |
260 if (orientation == VerticalScrollbar) { | |
261 if (!m_verticalScrollbar) | |
262 return 0; | |
263 | |
264 length = m_verticalScrollbar->scrollbar()->height(); | |
265 } else { | |
266 if (!m_horizontalScrollbar) | |
267 return 0; | |
268 | |
269 length = m_horizontalScrollbar->scrollbar()->width(); | |
270 } | |
271 | |
272 int pageStep = std::max( | |
273 static_cast<int>(static_cast<float>(length) * ScrollableArea::minFractio
nToStepWhenPaging()), | |
274 length - ScrollableArea::maxOverlapBetweenPages()); | |
275 | |
276 return std::max(pageStep, 1); | |
277 } | |
278 | |
279 } // namespace blink | |
OLD | NEW |