OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2006, 2007, 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 COMPUTER, 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. | |
24 */ | |
25 | |
26 #include "config.h" | |
27 #include "core/platform/ScrollView.h" | |
28 | |
29 #include "core/platform/ScrollbarTheme.h" | |
30 #include "core/platform/graphics/GraphicsContextStateSaver.h" | |
31 #include "core/platform/graphics/GraphicsLayer.h" | |
32 #include "platform/HostWindow.h" | |
33 #include "wtf/StdLibExtras.h" | |
34 | |
35 using namespace std; | |
36 | |
37 namespace WebCore { | |
38 | |
39 ScrollView::ScrollView() | |
40 : m_horizontalScrollbarMode(ScrollbarAuto) | |
41 , m_verticalScrollbarMode(ScrollbarAuto) | |
42 , m_horizontalScrollbarLock(false) | |
43 , m_verticalScrollbarLock(false) | |
44 , m_canBlitOnScroll(true) | |
45 , m_scrollbarsAvoidingResizer(0) | |
46 , m_scrollbarsSuppressed(false) | |
47 , m_inUpdateScrollbars(false) | |
48 , m_updateScrollbarsPass(0) | |
49 , m_drawPanScrollIcon(false) | |
50 , m_paintsEntireContents(false) | |
51 , m_clipsRepaints(true) | |
52 { | |
53 } | |
54 | |
55 ScrollView::~ScrollView() | |
56 { | |
57 } | |
58 | |
59 void ScrollView::addChild(PassRefPtr<Widget> prpChild) | |
60 { | |
61 Widget* child = prpChild.get(); | |
62 ASSERT(child != this && !child->parent()); | |
63 child->setParent(this); | |
64 m_children.add(prpChild); | |
65 } | |
66 | |
67 void ScrollView::removeChild(Widget* child) | |
68 { | |
69 ASSERT(child->parent() == this); | |
70 child->setParent(0); | |
71 m_children.remove(child); | |
72 } | |
73 | |
74 void ScrollView::setHasHorizontalScrollbar(bool hasBar) | |
75 { | |
76 if (hasBar && !m_horizontalScrollbar) { | |
77 m_horizontalScrollbar = createScrollbar(HorizontalScrollbar); | |
78 addChild(m_horizontalScrollbar.get()); | |
79 didAddScrollbar(m_horizontalScrollbar.get(), HorizontalScrollbar); | |
80 m_horizontalScrollbar->styleChanged(); | |
81 } else if (!hasBar && m_horizontalScrollbar) { | |
82 willRemoveScrollbar(m_horizontalScrollbar.get(), HorizontalScrollbar); | |
83 removeChild(m_horizontalScrollbar.get()); | |
84 m_horizontalScrollbar = 0; | |
85 } | |
86 } | |
87 | |
88 void ScrollView::setHasVerticalScrollbar(bool hasBar) | |
89 { | |
90 if (hasBar && !m_verticalScrollbar) { | |
91 m_verticalScrollbar = createScrollbar(VerticalScrollbar); | |
92 addChild(m_verticalScrollbar.get()); | |
93 didAddScrollbar(m_verticalScrollbar.get(), VerticalScrollbar); | |
94 m_verticalScrollbar->styleChanged(); | |
95 } else if (!hasBar && m_verticalScrollbar) { | |
96 willRemoveScrollbar(m_verticalScrollbar.get(), VerticalScrollbar); | |
97 removeChild(m_verticalScrollbar.get()); | |
98 m_verticalScrollbar = 0; | |
99 } | |
100 } | |
101 | |
102 PassRefPtr<Scrollbar> ScrollView::createScrollbar(ScrollbarOrientation orientati
on) | |
103 { | |
104 return Scrollbar::create(this, orientation, RegularScrollbar); | |
105 } | |
106 | |
107 void ScrollView::setScrollbarModes(ScrollbarMode horizontalMode, ScrollbarMode v
erticalMode, | |
108 bool horizontalLock, bool verticalLock) | |
109 { | |
110 bool needsUpdate = false; | |
111 | |
112 if (horizontalMode != horizontalScrollbarMode() && !m_horizontalScrollbarLoc
k) { | |
113 m_horizontalScrollbarMode = horizontalMode; | |
114 needsUpdate = true; | |
115 } | |
116 | |
117 if (verticalMode != verticalScrollbarMode() && !m_verticalScrollbarLock) { | |
118 m_verticalScrollbarMode = verticalMode; | |
119 needsUpdate = true; | |
120 } | |
121 | |
122 if (horizontalLock) | |
123 setHorizontalScrollbarLock(); | |
124 | |
125 if (verticalLock) | |
126 setVerticalScrollbarLock(); | |
127 | |
128 if (!needsUpdate) | |
129 return; | |
130 | |
131 updateScrollbars(scrollOffset()); | |
132 } | |
133 | |
134 void ScrollView::scrollbarModes(ScrollbarMode& horizontalMode, ScrollbarMode& ve
rticalMode) const | |
135 { | |
136 horizontalMode = m_horizontalScrollbarMode; | |
137 verticalMode = m_verticalScrollbarMode; | |
138 } | |
139 | |
140 void ScrollView::setCanHaveScrollbars(bool canScroll) | |
141 { | |
142 ScrollbarMode newHorizontalMode; | |
143 ScrollbarMode newVerticalMode; | |
144 | |
145 scrollbarModes(newHorizontalMode, newVerticalMode); | |
146 | |
147 if (canScroll && newVerticalMode == ScrollbarAlwaysOff) | |
148 newVerticalMode = ScrollbarAuto; | |
149 else if (!canScroll) | |
150 newVerticalMode = ScrollbarAlwaysOff; | |
151 | |
152 if (canScroll && newHorizontalMode == ScrollbarAlwaysOff) | |
153 newHorizontalMode = ScrollbarAuto; | |
154 else if (!canScroll) | |
155 newHorizontalMode = ScrollbarAlwaysOff; | |
156 | |
157 setScrollbarModes(newHorizontalMode, newVerticalMode); | |
158 } | |
159 | |
160 void ScrollView::setCanBlitOnScroll(bool b) | |
161 { | |
162 m_canBlitOnScroll = b; | |
163 } | |
164 | |
165 bool ScrollView::canBlitOnScroll() const | |
166 { | |
167 return m_canBlitOnScroll; | |
168 } | |
169 | |
170 void ScrollView::setPaintsEntireContents(bool paintsEntireContents) | |
171 { | |
172 m_paintsEntireContents = paintsEntireContents; | |
173 } | |
174 | |
175 void ScrollView::setClipsRepaints(bool clipsRepaints) | |
176 { | |
177 m_clipsRepaints = clipsRepaints; | |
178 } | |
179 | |
180 IntSize ScrollView::unscaledVisibleContentSize(IncludeScrollbarsInRect scrollbar
Inclusion) const | |
181 { | |
182 return scrollbarInclusion == ExcludeScrollbars ? excludeScrollbars(frameRect
().size()) : frameRect().size(); | |
183 } | |
184 | |
185 IntSize ScrollView::excludeScrollbars(const IntSize& size) const | |
186 { | |
187 int verticalScrollbarWidth = 0; | |
188 int horizontalScrollbarHeight = 0; | |
189 | |
190 if (Scrollbar* verticalBar = verticalScrollbar()) | |
191 verticalScrollbarWidth = !verticalBar->isOverlayScrollbar() ? verticalBa
r->width() : 0; | |
192 if (Scrollbar* horizontalBar = horizontalScrollbar()) | |
193 horizontalScrollbarHeight = !horizontalBar->isOverlayScrollbar() ? horiz
ontalBar->height() : 0; | |
194 | |
195 return IntSize(max(0, size.width() - verticalScrollbarWidth), | |
196 max(0, size.height() - horizontalScrollbarHeight)); | |
197 | |
198 } | |
199 | |
200 IntRect ScrollView::visibleContentRect(IncludeScrollbarsInRect scollbarInclusion
) const | |
201 { | |
202 FloatSize visibleContentSize = unscaledVisibleContentSize(scollbarInclusion)
; | |
203 visibleContentSize.scale(1 / visibleContentScaleFactor()); | |
204 return IntRect(IntPoint(m_scrollOffset), expandedIntSize(visibleContentSize)
); | |
205 } | |
206 | |
207 IntSize ScrollView::contentsSize() const | |
208 { | |
209 return m_contentsSize; | |
210 } | |
211 | |
212 void ScrollView::setContentsSize(const IntSize& newSize) | |
213 { | |
214 if (contentsSize() == newSize) | |
215 return; | |
216 m_contentsSize = newSize; | |
217 updateScrollbars(scrollOffset()); | |
218 updateOverhangAreas(); | |
219 } | |
220 | |
221 IntPoint ScrollView::maximumScrollPosition() const | |
222 { | |
223 IntPoint maximumOffset(contentsWidth() - visibleWidth() - scrollOrigin().x()
, contentsHeight() - visibleHeight() - scrollOrigin().y()); | |
224 maximumOffset.clampNegativeToZero(); | |
225 return maximumOffset; | |
226 } | |
227 | |
228 IntPoint ScrollView::minimumScrollPosition() const | |
229 { | |
230 return IntPoint(-scrollOrigin().x(), -scrollOrigin().y()); | |
231 } | |
232 | |
233 IntPoint ScrollView::adjustScrollPositionWithinRange(const IntPoint& scrollPoint
) const | |
234 { | |
235 if (!constrainsScrollingToContentEdge()) | |
236 return scrollPoint; | |
237 | |
238 IntPoint newScrollPosition = scrollPoint.shrunkTo(maximumScrollPosition()); | |
239 newScrollPosition = newScrollPosition.expandedTo(minimumScrollPosition()); | |
240 return newScrollPosition; | |
241 } | |
242 | |
243 int ScrollView::scrollSize(ScrollbarOrientation orientation) const | |
244 { | |
245 Scrollbar* scrollbar = ((orientation == HorizontalScrollbar) ? m_horizontalS
crollbar : m_verticalScrollbar).get(); | |
246 | |
247 // If no scrollbars are present, the content may still be scrollable. | |
248 if (!scrollbar) { | |
249 IntSize scrollSize = m_contentsSize - visibleContentRect().size(); | |
250 scrollSize.clampNegativeToZero(); | |
251 return orientation == HorizontalScrollbar ? scrollSize.width() : scrollS
ize.height(); | |
252 } | |
253 | |
254 return scrollbar->totalSize() - scrollbar->visibleSize(); | |
255 } | |
256 | |
257 void ScrollView::notifyPageThatContentAreaWillPaint() const | |
258 { | |
259 } | |
260 | |
261 void ScrollView::setScrollOffset(const IntPoint& offset) | |
262 { | |
263 scrollTo(toIntSize(adjustScrollPositionWithinRange(offset))); | |
264 } | |
265 | |
266 void ScrollView::scrollTo(const IntSize& newOffset) | |
267 { | |
268 IntSize scrollDelta = newOffset - m_scrollOffset; | |
269 if (scrollDelta == IntSize()) | |
270 return; | |
271 m_scrollOffset = newOffset; | |
272 | |
273 if (scrollbarsSuppressed()) | |
274 return; | |
275 | |
276 repaintFixedElementsAfterScrolling(); | |
277 scrollContents(scrollDelta); | |
278 updateFixedElementsAfterScrolling(); | |
279 } | |
280 | |
281 void ScrollView::setScrollPosition(const IntPoint& scrollPoint) | |
282 { | |
283 IntPoint newScrollPosition = adjustScrollPositionWithinRange(scrollPoint); | |
284 | |
285 if (newScrollPosition == scrollPosition()) | |
286 return; | |
287 | |
288 updateScrollbars(IntSize(newScrollPosition.x(), newScrollPosition.y())); | |
289 } | |
290 | |
291 bool ScrollView::logicalScroll(ScrollLogicalDirection direction, ScrollGranulari
ty granularity) | |
292 { | |
293 return scroll(logicalToPhysical(direction, isVerticalDocument(), isFlippedDo
cument()), granularity); | |
294 } | |
295 | |
296 IntSize ScrollView::overhangAmount() const | |
297 { | |
298 IntSize stretch; | |
299 | |
300 int physicalScrollY = scrollPosition().y() + scrollOrigin().y(); | |
301 if (physicalScrollY < 0) | |
302 stretch.setHeight(physicalScrollY); | |
303 else if (contentsHeight() && physicalScrollY > contentsHeight() - visibleHei
ght()) | |
304 stretch.setHeight(physicalScrollY - (contentsHeight() - visibleHeight())
); | |
305 | |
306 int physicalScrollX = scrollPosition().x() + scrollOrigin().x(); | |
307 if (physicalScrollX < 0) | |
308 stretch.setWidth(physicalScrollX); | |
309 else if (contentsWidth() && physicalScrollX > contentsWidth() - visibleWidth
()) | |
310 stretch.setWidth(physicalScrollX - (contentsWidth() - visibleWidth())); | |
311 | |
312 return stretch; | |
313 } | |
314 | |
315 void ScrollView::windowResizerRectChanged() | |
316 { | |
317 updateScrollbars(scrollOffset()); | |
318 } | |
319 | |
320 static const unsigned cMaxUpdateScrollbarsPass = 2; | |
321 | |
322 void ScrollView::updateScrollbars(const IntSize& desiredOffset) | |
323 { | |
324 if (m_inUpdateScrollbars) | |
325 return; | |
326 | |
327 // If we came in here with the view already needing a layout, then go ahead
and do that | |
328 // first. (This will be the common case, e.g., when the page changes due to
window resizing for example). | |
329 // This layout will not re-enter updateScrollbars and does not count towards
our max layout pass total. | |
330 if (!m_scrollbarsSuppressed) { | |
331 m_inUpdateScrollbars = true; | |
332 scrollbarExistenceDidChange(); | |
333 m_inUpdateScrollbars = false; | |
334 } | |
335 | |
336 IntRect oldScrollCornerRect = scrollCornerRect(); | |
337 | |
338 bool hasHorizontalScrollbar = m_horizontalScrollbar; | |
339 bool hasVerticalScrollbar = m_verticalScrollbar; | |
340 | |
341 bool newHasHorizontalScrollbar = hasHorizontalScrollbar; | |
342 bool newHasVerticalScrollbar = hasVerticalScrollbar; | |
343 | |
344 ScrollbarMode hScroll = m_horizontalScrollbarMode; | |
345 ScrollbarMode vScroll = m_verticalScrollbarMode; | |
346 | |
347 if (hScroll != ScrollbarAuto) | |
348 newHasHorizontalScrollbar = (hScroll == ScrollbarAlwaysOn); | |
349 if (vScroll != ScrollbarAuto) | |
350 newHasVerticalScrollbar = (vScroll == ScrollbarAlwaysOn); | |
351 | |
352 if (m_scrollbarsSuppressed || (hScroll != ScrollbarAuto && vScroll != Scroll
barAuto)) { | |
353 if (hasHorizontalScrollbar != newHasHorizontalScrollbar) | |
354 setHasHorizontalScrollbar(newHasHorizontalScrollbar); | |
355 if (hasVerticalScrollbar != newHasVerticalScrollbar) | |
356 setHasVerticalScrollbar(newHasVerticalScrollbar); | |
357 } else { | |
358 bool scrollbarExistenceChanged = false; | |
359 | |
360 IntSize docSize = contentsSize(); | |
361 IntSize fullVisibleSize = visibleContentRect(IncludeScrollbars).size(); | |
362 | |
363 bool scrollbarsAreOverlay = ScrollbarTheme::theme()->usesOverlayScrollba
rs(); | |
364 | |
365 if (hScroll == ScrollbarAuto) { | |
366 newHasHorizontalScrollbar = docSize.width() > visibleWidth(); | |
367 if (!scrollbarsAreOverlay && newHasHorizontalScrollbar && !m_updateS
crollbarsPass && docSize.width() <= fullVisibleSize.width() && docSize.height()
<= fullVisibleSize.height()) | |
368 newHasHorizontalScrollbar = false; | |
369 } | |
370 if (vScroll == ScrollbarAuto) { | |
371 newHasVerticalScrollbar = docSize.height() > visibleHeight(); | |
372 if (!scrollbarsAreOverlay && newHasVerticalScrollbar && !m_updateScr
ollbarsPass && docSize.width() <= fullVisibleSize.width() && docSize.height() <=
fullVisibleSize.height()) | |
373 newHasVerticalScrollbar = false; | |
374 } | |
375 | |
376 if (!scrollbarsAreOverlay) { | |
377 // If we ever turn one scrollbar off, always turn the other one off
too. Never ever | |
378 // try to both gain/lose a scrollbar in the same pass. | |
379 if (!newHasHorizontalScrollbar && hasHorizontalScrollbar && vScroll
!= ScrollbarAlwaysOn) | |
380 newHasVerticalScrollbar = false; | |
381 if (!newHasVerticalScrollbar && hasVerticalScrollbar && hScroll != S
crollbarAlwaysOn) | |
382 newHasHorizontalScrollbar = false; | |
383 } | |
384 | |
385 if (hasHorizontalScrollbar != newHasHorizontalScrollbar) { | |
386 scrollbarExistenceChanged = true; | |
387 if (scrollOrigin().y() && !newHasHorizontalScrollbar && !scrollbarsA
reOverlay) | |
388 ScrollableArea::setScrollOrigin(IntPoint(scrollOrigin().x(), scr
ollOrigin().y() - m_horizontalScrollbar->height())); | |
389 if (hasHorizontalScrollbar) | |
390 m_horizontalScrollbar->invalidate(); | |
391 setHasHorizontalScrollbar(newHasHorizontalScrollbar); | |
392 } | |
393 | |
394 if (hasVerticalScrollbar != newHasVerticalScrollbar) { | |
395 scrollbarExistenceChanged = true; | |
396 if (scrollOrigin().x() && !newHasVerticalScrollbar && !scrollbarsAre
Overlay) | |
397 ScrollableArea::setScrollOrigin(IntPoint(scrollOrigin().x() - m_
verticalScrollbar->width(), scrollOrigin().y())); | |
398 if (hasVerticalScrollbar) | |
399 m_verticalScrollbar->invalidate(); | |
400 setHasVerticalScrollbar(newHasVerticalScrollbar); | |
401 } | |
402 | |
403 if (scrollbarExistenceChanged) { | |
404 if (scrollbarsAreOverlay) { | |
405 // Synchronize status of scrollbar layers if necessary. | |
406 m_inUpdateScrollbars = true; | |
407 scrollbarExistenceDidChange(); | |
408 m_inUpdateScrollbars = false; | |
409 } else if (m_updateScrollbarsPass < cMaxUpdateScrollbarsPass) { | |
410 m_updateScrollbarsPass++; | |
411 contentsResized(); | |
412 scrollbarExistenceDidChange(); | |
413 IntSize newDocSize = contentsSize(); | |
414 if (newDocSize == docSize) { | |
415 // The layout with the new scroll state had no impact on | |
416 // the document's overall size, so updateScrollbars didn't g
et called. | |
417 // Recur manually. | |
418 updateScrollbars(desiredOffset); | |
419 } | |
420 m_updateScrollbarsPass--; | |
421 } | |
422 } | |
423 } | |
424 | |
425 // Set up the range, but only do this if we're not in a nested call (to avoi
d | |
426 // doing it multiple times). | |
427 if (m_updateScrollbarsPass) | |
428 return; | |
429 | |
430 m_inUpdateScrollbars = true; | |
431 | |
432 if (m_horizontalScrollbar) { | |
433 int clientWidth = visibleWidth(); | |
434 IntRect oldRect(m_horizontalScrollbar->frameRect()); | |
435 IntRect hBarRect((shouldPlaceVerticalScrollbarOnLeft() && m_verticalScro
llbar) ? m_verticalScrollbar->width() : 0, | |
436 height() - m_horizontalScrollbar->height(), | |
437 width() - (m_verticalScrollbar ? m_verticalScrollbar->wi
dth() : 0), | |
438 m_horizontalScrollbar->height()); | |
439 m_horizontalScrollbar->setFrameRect(hBarRect); | |
440 if (!m_scrollbarsSuppressed && oldRect != m_horizontalScrollbar->frameRe
ct()) | |
441 m_horizontalScrollbar->invalidate(); | |
442 | |
443 if (m_scrollbarsSuppressed) | |
444 m_horizontalScrollbar->setSuppressInvalidation(true); | |
445 m_horizontalScrollbar->setEnabled(contentsWidth() > clientWidth); | |
446 m_horizontalScrollbar->setProportion(clientWidth, contentsWidth()); | |
447 if (m_scrollbarsSuppressed) | |
448 m_horizontalScrollbar->setSuppressInvalidation(false); | |
449 } | |
450 | |
451 if (m_verticalScrollbar) { | |
452 int clientHeight = visibleHeight(); | |
453 IntRect oldRect(m_verticalScrollbar->frameRect()); | |
454 IntRect vBarRect(shouldPlaceVerticalScrollbarOnLeft() ? 0 : (width() - m
_verticalScrollbar->width()), | |
455 0, | |
456 m_verticalScrollbar->width(), | |
457 height() - (m_horizontalScrollbar ? m_horizontalScrollb
ar->height() : 0)); | |
458 m_verticalScrollbar->setFrameRect(vBarRect); | |
459 if (!m_scrollbarsSuppressed && oldRect != m_verticalScrollbar->frameRect
()) | |
460 m_verticalScrollbar->invalidate(); | |
461 | |
462 if (m_scrollbarsSuppressed) | |
463 m_verticalScrollbar->setSuppressInvalidation(true); | |
464 m_verticalScrollbar->setEnabled(contentsHeight() > clientHeight); | |
465 m_verticalScrollbar->setProportion(clientHeight, contentsHeight()); | |
466 if (m_scrollbarsSuppressed) | |
467 m_verticalScrollbar->setSuppressInvalidation(false); | |
468 } | |
469 | |
470 if (hasHorizontalScrollbar != newHasHorizontalScrollbar || hasVerticalScroll
bar != newHasVerticalScrollbar) { | |
471 // FIXME: Is frameRectsChanged really necessary here? Have any frame rec
ts changed? | |
472 frameRectsChanged(); | |
473 positionScrollbarLayers(); | |
474 updateScrollCorner(); | |
475 if (!m_horizontalScrollbar && !m_verticalScrollbar) | |
476 invalidateScrollCornerRect(oldScrollCornerRect); | |
477 } | |
478 | |
479 IntPoint adjustedScrollPosition = IntPoint(desiredOffset); | |
480 if (!isRubberBandInProgress()) | |
481 adjustedScrollPosition = adjustScrollPositionWithinRange(adjustedScrollP
osition); | |
482 | |
483 if (adjustedScrollPosition != scrollPosition() || scrollOriginChanged()) { | |
484 ScrollableArea::scrollToOffsetWithoutAnimation(adjustedScrollPosition); | |
485 resetScrollOriginChanged(); | |
486 } | |
487 | |
488 // Make sure the scrollbar offsets are up to date. | |
489 if (m_horizontalScrollbar) | |
490 m_horizontalScrollbar->offsetDidChange(); | |
491 if (m_verticalScrollbar) | |
492 m_verticalScrollbar->offsetDidChange(); | |
493 | |
494 m_inUpdateScrollbars = false; | |
495 } | |
496 | |
497 const int panIconSizeLength = 16; | |
498 | |
499 IntRect ScrollView::rectToCopyOnScroll() const | |
500 { | |
501 IntRect scrollViewRect = convertToRootView(IntRect((shouldPlaceVerticalScrol
lbarOnLeft() && verticalScrollbar()) ? verticalScrollbar()->width() : 0, 0, visi
bleWidth(), visibleHeight())); | |
502 if (hasOverlayScrollbars()) { | |
503 int verticalScrollbarWidth = (verticalScrollbar() && !hasLayerForVertica
lScrollbar()) ? verticalScrollbar()->width() : 0; | |
504 int horizontalScrollbarHeight = (horizontalScrollbar() && !hasLayerForHo
rizontalScrollbar()) ? horizontalScrollbar()->height() : 0; | |
505 | |
506 scrollViewRect.setWidth(scrollViewRect.width() - verticalScrollbarWidth)
; | |
507 scrollViewRect.setHeight(scrollViewRect.height() - horizontalScrollbarHe
ight); | |
508 } | |
509 return scrollViewRect; | |
510 } | |
511 | |
512 void ScrollView::scrollContents(const IntSize& scrollDelta) | |
513 { | |
514 HostWindow* window = hostWindow(); | |
515 if (!window) | |
516 return; | |
517 | |
518 // Since scrolling is double buffered, we will be blitting the scroll view's
intersection | |
519 // with the clip rect every time to keep it smooth. | |
520 IntRect clipRect = windowClipRect(); | |
521 IntRect scrollViewRect = rectToCopyOnScroll(); | |
522 IntRect updateRect = clipRect; | |
523 updateRect.intersect(scrollViewRect); | |
524 | |
525 if (m_drawPanScrollIcon) { | |
526 // FIXME: the pan icon is broken when accelerated compositing is on, sin
ce it will draw under the compositing layers. | |
527 // https://bugs.webkit.org/show_bug.cgi?id=47837 | |
528 int panIconDirtySquareSizeLength = 2 * (panIconSizeLength + max(abs(scro
llDelta.width()), abs(scrollDelta.height()))); // We only want to repaint what's
necessary | |
529 IntPoint panIconDirtySquareLocation = IntPoint(m_panScrollIconPoint.x()
- (panIconDirtySquareSizeLength / 2), m_panScrollIconPoint.y() - (panIconDirtySq
uareSizeLength / 2)); | |
530 IntRect panScrollIconDirtyRect = IntRect(panIconDirtySquareLocation, Int
Size(panIconDirtySquareSizeLength, panIconDirtySquareSizeLength)); | |
531 panScrollIconDirtyRect.intersect(clipRect); | |
532 window->invalidateContentsAndRootView(panScrollIconDirtyRect); | |
533 } | |
534 | |
535 if (canBlitOnScroll()) { // The main frame can just blit the WebView window | |
536 // FIXME: Find a way to scroll subframes with this faster path | |
537 if (!scrollContentsFastPath(-scrollDelta, scrollViewRect, clipRect)) | |
538 scrollContentsSlowPath(updateRect); | |
539 } else { | |
540 // We need to go ahead and repaint the entire backing store. Do it now b
efore moving the | |
541 // windowed plugins. | |
542 scrollContentsSlowPath(updateRect); | |
543 } | |
544 | |
545 // Invalidate the overhang areas if they are visible. | |
546 updateOverhangAreas(); | |
547 | |
548 // This call will move children with native widgets (plugins) and invalidate
them as well. | |
549 frameRectsChanged(); | |
550 } | |
551 | |
552 bool ScrollView::scrollContentsFastPath(const IntSize& scrollDelta, const IntRec
t& rectToScroll, const IntRect& clipRect) | |
553 { | |
554 hostWindow()->scroll(scrollDelta, rectToScroll, clipRect); | |
555 return true; | |
556 } | |
557 | |
558 void ScrollView::scrollContentsSlowPath(const IntRect& updateRect) | |
559 { | |
560 hostWindow()->invalidateContentsForSlowScroll(updateRect); | |
561 } | |
562 | |
563 IntPoint ScrollView::rootViewToContents(const IntPoint& rootViewPoint) const | |
564 { | |
565 IntPoint viewPoint = convertFromRootView(rootViewPoint); | |
566 return viewPoint + scrollOffset(); | |
567 } | |
568 | |
569 IntPoint ScrollView::contentsToRootView(const IntPoint& contentsPoint) const | |
570 { | |
571 IntPoint viewPoint = contentsPoint - scrollOffset(); | |
572 return convertToRootView(viewPoint); | |
573 } | |
574 | |
575 IntRect ScrollView::rootViewToContents(const IntRect& rootViewRect) const | |
576 { | |
577 IntRect viewRect = convertFromRootView(rootViewRect); | |
578 viewRect.move(scrollOffset()); | |
579 return viewRect; | |
580 } | |
581 | |
582 IntRect ScrollView::contentsToRootView(const IntRect& contentsRect) const | |
583 { | |
584 IntRect viewRect = contentsRect; | |
585 viewRect.move(-scrollOffset()); | |
586 return convertToRootView(viewRect); | |
587 } | |
588 | |
589 IntPoint ScrollView::windowToContents(const IntPoint& windowPoint) const | |
590 { | |
591 IntPoint viewPoint = convertFromContainingWindow(windowPoint); | |
592 return viewPoint + scrollOffset(); | |
593 } | |
594 | |
595 IntPoint ScrollView::contentsToWindow(const IntPoint& contentsPoint) const | |
596 { | |
597 IntPoint viewPoint = contentsPoint - scrollOffset(); | |
598 return convertToContainingWindow(viewPoint); | |
599 } | |
600 | |
601 IntRect ScrollView::windowToContents(const IntRect& windowRect) const | |
602 { | |
603 IntRect viewRect = convertFromContainingWindow(windowRect); | |
604 viewRect.move(scrollOffset()); | |
605 return viewRect; | |
606 } | |
607 | |
608 IntRect ScrollView::contentsToWindow(const IntRect& contentsRect) const | |
609 { | |
610 IntRect viewRect = contentsRect; | |
611 viewRect.move(-scrollOffset()); | |
612 return convertToContainingWindow(viewRect); | |
613 } | |
614 | |
615 IntRect ScrollView::contentsToScreen(const IntRect& rect) const | |
616 { | |
617 HostWindow* window = hostWindow(); | |
618 if (!window) | |
619 return IntRect(); | |
620 return window->rootViewToScreen(contentsToRootView(rect)); | |
621 } | |
622 | |
623 IntPoint ScrollView::screenToContents(const IntPoint& point) const | |
624 { | |
625 HostWindow* window = hostWindow(); | |
626 if (!window) | |
627 return IntPoint(); | |
628 return rootViewToContents(window->screenToRootView(point)); | |
629 } | |
630 | |
631 bool ScrollView::containsScrollbarsAvoidingResizer() const | |
632 { | |
633 return !m_scrollbarsAvoidingResizer; | |
634 } | |
635 | |
636 void ScrollView::adjustScrollbarsAvoidingResizerCount(int overlapDelta) | |
637 { | |
638 int oldCount = m_scrollbarsAvoidingResizer; | |
639 m_scrollbarsAvoidingResizer += overlapDelta; | |
640 if (parent()) | |
641 toScrollView(parent())->adjustScrollbarsAvoidingResizerCount(overlapDelt
a); | |
642 else if (!scrollbarsSuppressed()) { | |
643 // If we went from n to 0 or from 0 to n and we're the outermost view, | |
644 // we need to invalidate the windowResizerRect(), since it will now need
to paint | |
645 // differently. | |
646 if ((oldCount > 0 && m_scrollbarsAvoidingResizer == 0) || | |
647 (oldCount == 0 && m_scrollbarsAvoidingResizer > 0)) | |
648 invalidateRect(windowResizerRect()); | |
649 } | |
650 } | |
651 | |
652 void ScrollView::setParent(Widget* parentView) | |
653 { | |
654 if (parentView == parent()) | |
655 return; | |
656 | |
657 if (m_scrollbarsAvoidingResizer && parent()) | |
658 toScrollView(parent())->adjustScrollbarsAvoidingResizerCount(-m_scrollba
rsAvoidingResizer); | |
659 | |
660 Widget::setParent(parentView); | |
661 | |
662 if (m_scrollbarsAvoidingResizer && parent()) | |
663 toScrollView(parent())->adjustScrollbarsAvoidingResizerCount(m_scrollbar
sAvoidingResizer); | |
664 } | |
665 | |
666 void ScrollView::setScrollbarsSuppressed(bool suppressed, bool repaintOnUnsuppre
ss) | |
667 { | |
668 if (suppressed == m_scrollbarsSuppressed) | |
669 return; | |
670 | |
671 m_scrollbarsSuppressed = suppressed; | |
672 | |
673 if (repaintOnUnsuppress && !suppressed) { | |
674 if (m_horizontalScrollbar) | |
675 m_horizontalScrollbar->invalidate(); | |
676 if (m_verticalScrollbar) | |
677 m_verticalScrollbar->invalidate(); | |
678 | |
679 // Invalidate the scroll corner too on unsuppress. | |
680 invalidateRect(scrollCornerRect()); | |
681 } | |
682 } | |
683 | |
684 Scrollbar* ScrollView::scrollbarAtPoint(const IntPoint& windowPoint) | |
685 { | |
686 IntPoint viewPoint = convertFromContainingWindow(windowPoint); | |
687 if (m_horizontalScrollbar && m_horizontalScrollbar->shouldParticipateInHitTe
sting() && m_horizontalScrollbar->frameRect().contains(viewPoint)) | |
688 return m_horizontalScrollbar.get(); | |
689 if (m_verticalScrollbar && m_verticalScrollbar->shouldParticipateInHitTestin
g() && m_verticalScrollbar->frameRect().contains(viewPoint)) | |
690 return m_verticalScrollbar.get(); | |
691 return 0; | |
692 } | |
693 | |
694 void ScrollView::setFrameRect(const IntRect& newRect) | |
695 { | |
696 IntRect oldRect = frameRect(); | |
697 | |
698 if (newRect == oldRect) | |
699 return; | |
700 | |
701 Widget::setFrameRect(newRect); | |
702 | |
703 updateScrollbars(scrollOffset()); | |
704 | |
705 frameRectsChanged(); | |
706 } | |
707 | |
708 void ScrollView::frameRectsChanged() | |
709 { | |
710 HashSet<RefPtr<Widget> >::const_iterator end = m_children.end(); | |
711 for (HashSet<RefPtr<Widget> >::const_iterator current = m_children.begin();
current != end; ++current) | |
712 (*current)->frameRectsChanged(); | |
713 } | |
714 | |
715 void ScrollView::clipRectChanged() | |
716 { | |
717 HashSet<RefPtr<Widget> >::const_iterator end = m_children.end(); | |
718 for (HashSet<RefPtr<Widget> >::const_iterator current = m_children.begin();
current != end; ++current) | |
719 (*current)->clipRectChanged(); | |
720 } | |
721 | |
722 static void positionScrollbarLayer(GraphicsLayer* graphicsLayer, Scrollbar* scro
llbar) | |
723 { | |
724 if (!graphicsLayer || !scrollbar) | |
725 return; | |
726 | |
727 IntRect scrollbarRect = scrollbar->frameRect(); | |
728 graphicsLayer->setPosition(scrollbarRect.location()); | |
729 | |
730 if (scrollbarRect.size() == graphicsLayer->size()) | |
731 return; | |
732 | |
733 graphicsLayer->setSize(scrollbarRect.size()); | |
734 | |
735 if (graphicsLayer->hasContentsLayer()) { | |
736 graphicsLayer->setContentsRect(IntRect(0, 0, scrollbarRect.width(), scro
llbarRect.height())); | |
737 return; | |
738 } | |
739 | |
740 graphicsLayer->setDrawsContent(true); | |
741 graphicsLayer->setNeedsDisplay(); | |
742 } | |
743 | |
744 static void positionScrollCornerLayer(GraphicsLayer* graphicsLayer, const IntRec
t& cornerRect) | |
745 { | |
746 if (!graphicsLayer) | |
747 return; | |
748 graphicsLayer->setDrawsContent(!cornerRect.isEmpty()); | |
749 graphicsLayer->setPosition(cornerRect.location()); | |
750 if (cornerRect.size() != graphicsLayer->size()) | |
751 graphicsLayer->setNeedsDisplay(); | |
752 graphicsLayer->setSize(cornerRect.size()); | |
753 } | |
754 | |
755 void ScrollView::positionScrollbarLayers() | |
756 { | |
757 positionScrollbarLayer(layerForHorizontalScrollbar(), horizontalScrollbar())
; | |
758 positionScrollbarLayer(layerForVerticalScrollbar(), verticalScrollbar()); | |
759 positionScrollCornerLayer(layerForScrollCorner(), scrollCornerRect()); | |
760 } | |
761 | |
762 bool ScrollView::userInputScrollable(ScrollbarOrientation orientation) const | |
763 { | |
764 ScrollbarMode mode = (orientation == HorizontalScrollbar) ? | |
765 m_horizontalScrollbarMode : m_verticalScrollbarMode; | |
766 | |
767 return mode == ScrollbarAuto || mode == ScrollbarAlwaysOn; | |
768 } | |
769 | |
770 bool ScrollView::shouldPlaceVerticalScrollbarOnLeft() const | |
771 { | |
772 return false; | |
773 } | |
774 | |
775 void ScrollView::repaintContentRectangle(const IntRect& rect) | |
776 { | |
777 IntRect paintRect = rect; | |
778 if (clipsRepaints() && !paintsEntireContents()) | |
779 paintRect.intersect(visibleContentRect()); | |
780 if (paintRect.isEmpty()) | |
781 return; | |
782 | |
783 if (HostWindow* window = hostWindow()) | |
784 window->invalidateContentsAndRootView(contentsToWindow(paintRect)); | |
785 } | |
786 | |
787 IntRect ScrollView::scrollCornerRect() const | |
788 { | |
789 IntRect cornerRect; | |
790 | |
791 if (hasOverlayScrollbars()) | |
792 return cornerRect; | |
793 | |
794 if (m_horizontalScrollbar && width() - m_horizontalScrollbar->width() > 0) { | |
795 cornerRect.unite(IntRect(shouldPlaceVerticalScrollbarOnLeft() ? 0 : m_ho
rizontalScrollbar->width(), | |
796 height() - m_horizontalScrollbar->height(), | |
797 width() - m_horizontalScrollbar->width(), | |
798 m_horizontalScrollbar->height())); | |
799 } | |
800 | |
801 if (m_verticalScrollbar && height() - m_verticalScrollbar->height() > 0) { | |
802 cornerRect.unite(IntRect(shouldPlaceVerticalScrollbarOnLeft() ? 0 : (wid
th() - m_verticalScrollbar->width()), | |
803 m_verticalScrollbar->height(), | |
804 m_verticalScrollbar->width(), | |
805 height() - m_verticalScrollbar->height())); | |
806 } | |
807 | |
808 return cornerRect; | |
809 } | |
810 | |
811 bool ScrollView::isScrollCornerVisible() const | |
812 { | |
813 return !scrollCornerRect().isEmpty(); | |
814 } | |
815 | |
816 void ScrollView::scrollbarStyleChanged(int, bool forceUpdate) | |
817 { | |
818 if (!forceUpdate) | |
819 return; | |
820 | |
821 contentsResized(); | |
822 updateScrollbars(scrollOffset()); | |
823 positionScrollbarLayers(); | |
824 } | |
825 | |
826 void ScrollView::updateScrollCorner() | |
827 { | |
828 } | |
829 | |
830 void ScrollView::paintScrollCorner(GraphicsContext* context, const IntRect& corn
erRect) | |
831 { | |
832 ScrollbarTheme::theme()->paintScrollCorner(context, cornerRect); | |
833 } | |
834 | |
835 void ScrollView::paintScrollbar(GraphicsContext* context, Scrollbar* bar, const
IntRect& rect) | |
836 { | |
837 bar->paint(context, rect); | |
838 } | |
839 | |
840 void ScrollView::invalidateScrollCornerRect(const IntRect& rect) | |
841 { | |
842 invalidateRect(rect); | |
843 } | |
844 | |
845 void ScrollView::paintScrollbars(GraphicsContext* context, const IntRect& rect) | |
846 { | |
847 if (m_horizontalScrollbar && !layerForHorizontalScrollbar()) | |
848 paintScrollbar(context, m_horizontalScrollbar.get(), rect); | |
849 if (m_verticalScrollbar && !layerForVerticalScrollbar()) | |
850 paintScrollbar(context, m_verticalScrollbar.get(), rect); | |
851 | |
852 if (layerForScrollCorner()) | |
853 return; | |
854 paintScrollCorner(context, scrollCornerRect()); | |
855 } | |
856 | |
857 void ScrollView::paintPanScrollIcon(GraphicsContext* context) | |
858 { | |
859 DEFINE_STATIC_REF(Image, panScrollIcon, (Image::loadPlatformResource("panIco
n"))); | |
860 IntPoint iconGCPoint = m_panScrollIconPoint; | |
861 if (parent()) | |
862 iconGCPoint = toScrollView(parent())->windowToContents(iconGCPoint); | |
863 context->drawImage(panScrollIcon, iconGCPoint); | |
864 } | |
865 | |
866 void ScrollView::paint(GraphicsContext* context, const IntRect& rect) | |
867 { | |
868 if (context->paintingDisabled() && !context->updatingControlTints()) | |
869 return; | |
870 | |
871 notifyPageThatContentAreaWillPaint(); | |
872 | |
873 IntRect documentDirtyRect = rect; | |
874 if (!paintsEntireContents()) { | |
875 IntRect visibleAreaWithoutScrollbars(location(), visibleContentRect().si
ze()); | |
876 documentDirtyRect.intersect(visibleAreaWithoutScrollbars); | |
877 } | |
878 | |
879 if (!documentDirtyRect.isEmpty()) { | |
880 GraphicsContextStateSaver stateSaver(*context); | |
881 | |
882 context->translate(x(), y()); | |
883 documentDirtyRect.moveBy(-location()); | |
884 | |
885 if (!paintsEntireContents()) { | |
886 context->translate(-scrollX(), -scrollY()); | |
887 documentDirtyRect.moveBy(scrollPosition()); | |
888 | |
889 context->clip(visibleContentRect()); | |
890 } | |
891 | |
892 paintContents(context, documentDirtyRect); | |
893 } | |
894 | |
895 calculateAndPaintOverhangAreas(context, rect); | |
896 | |
897 // Now paint the scrollbars. | |
898 if (!m_scrollbarsSuppressed && (m_horizontalScrollbar || m_verticalScrollbar
)) { | |
899 GraphicsContextStateSaver stateSaver(*context); | |
900 IntRect scrollViewDirtyRect = rect; | |
901 IntRect visibleAreaWithScrollbars(location(), visibleContentRect(Include
Scrollbars).size()); | |
902 scrollViewDirtyRect.intersect(visibleAreaWithScrollbars); | |
903 context->translate(x(), y()); | |
904 scrollViewDirtyRect.moveBy(-location()); | |
905 | |
906 paintScrollbars(context, scrollViewDirtyRect); | |
907 } | |
908 | |
909 // Paint the panScroll Icon | |
910 if (m_drawPanScrollIcon) | |
911 paintPanScrollIcon(context); | |
912 } | |
913 | |
914 void ScrollView::calculateOverhangAreasForPainting(IntRect& horizontalOverhangRe
ct, IntRect& verticalOverhangRect) | |
915 { | |
916 int verticalScrollbarWidth = (verticalScrollbar() && !verticalScrollbar()->i
sOverlayScrollbar()) | |
917 ? verticalScrollbar()->width() : 0; | |
918 int horizontalScrollbarHeight = (horizontalScrollbar() && !horizontalScrollb
ar()->isOverlayScrollbar()) | |
919 ? horizontalScrollbar()->height() : 0; | |
920 | |
921 int physicalScrollY = scrollPosition().y() + scrollOrigin().y(); | |
922 if (physicalScrollY < 0) { | |
923 horizontalOverhangRect = frameRect(); | |
924 horizontalOverhangRect.setHeight(-physicalScrollY); | |
925 horizontalOverhangRect.setWidth(horizontalOverhangRect.width() - vertica
lScrollbarWidth); | |
926 } else if (contentsHeight() && physicalScrollY > contentsHeight() - visibleH
eight()) { | |
927 int height = physicalScrollY - (contentsHeight() - visibleHeight()); | |
928 horizontalOverhangRect = frameRect(); | |
929 horizontalOverhangRect.setY(frameRect().maxY() - height - horizontalScro
llbarHeight); | |
930 horizontalOverhangRect.setHeight(height); | |
931 horizontalOverhangRect.setWidth(horizontalOverhangRect.width() - vertica
lScrollbarWidth); | |
932 } | |
933 | |
934 int physicalScrollX = scrollPosition().x() + scrollOrigin().x(); | |
935 if (physicalScrollX < 0) { | |
936 verticalOverhangRect.setWidth(-physicalScrollX); | |
937 verticalOverhangRect.setHeight(frameRect().height() - horizontalOverhang
Rect.height() - horizontalScrollbarHeight); | |
938 verticalOverhangRect.setX(frameRect().x()); | |
939 if (horizontalOverhangRect.y() == frameRect().y()) | |
940 verticalOverhangRect.setY(frameRect().y() + horizontalOverhangRect.h
eight()); | |
941 else | |
942 verticalOverhangRect.setY(frameRect().y()); | |
943 } else if (contentsWidth() && physicalScrollX > contentsWidth() - visibleWid
th()) { | |
944 int width = physicalScrollX - (contentsWidth() - visibleWidth()); | |
945 verticalOverhangRect.setWidth(width); | |
946 verticalOverhangRect.setHeight(frameRect().height() - horizontalOverhang
Rect.height() - horizontalScrollbarHeight); | |
947 verticalOverhangRect.setX(frameRect().maxX() - width - verticalScrollbar
Width); | |
948 if (horizontalOverhangRect.y() == frameRect().y()) | |
949 verticalOverhangRect.setY(frameRect().y() + horizontalOverhangRect.h
eight()); | |
950 else | |
951 verticalOverhangRect.setY(frameRect().y()); | |
952 } | |
953 } | |
954 | |
955 void ScrollView::updateOverhangAreas() | |
956 { | |
957 HostWindow* window = hostWindow(); | |
958 if (!window) | |
959 return; | |
960 | |
961 IntRect horizontalOverhangRect; | |
962 IntRect verticalOverhangRect; | |
963 calculateOverhangAreasForPainting(horizontalOverhangRect, verticalOverhangRe
ct); | |
964 if (!horizontalOverhangRect.isEmpty()) | |
965 window->invalidateContentsAndRootView(horizontalOverhangRect); | |
966 if (!verticalOverhangRect.isEmpty()) | |
967 window->invalidateContentsAndRootView(verticalOverhangRect); | |
968 } | |
969 | |
970 void ScrollView::paintOverhangAreas(GraphicsContext* context, const IntRect& hor
izontalOverhangRect, const IntRect& verticalOverhangRect, const IntRect& dirtyRe
ct) | |
971 { | |
972 ScrollbarTheme::theme()->paintOverhangBackground(context, horizontalOverhang
Rect, verticalOverhangRect, dirtyRect); | |
973 ScrollbarTheme::theme()->paintOverhangShadows(context, scrollOffset(), horiz
ontalOverhangRect, verticalOverhangRect, dirtyRect); | |
974 } | |
975 | |
976 void ScrollView::calculateAndPaintOverhangAreas(GraphicsContext* context, const
IntRect& dirtyRect) | |
977 { | |
978 IntRect horizontalOverhangRect; | |
979 IntRect verticalOverhangRect; | |
980 calculateOverhangAreasForPainting(horizontalOverhangRect, verticalOverhangRe
ct); | |
981 | |
982 if (dirtyRect.intersects(horizontalOverhangRect) || dirtyRect.intersects(ver
ticalOverhangRect)) | |
983 paintOverhangAreas(context, horizontalOverhangRect, verticalOverhangRect
, dirtyRect); | |
984 } | |
985 | |
986 void ScrollView::calculateAndPaintOverhangBackground(GraphicsContext* context, c
onst IntRect& dirtyRect) | |
987 { | |
988 IntRect horizontalOverhangRect; | |
989 IntRect verticalOverhangRect; | |
990 calculateOverhangAreasForPainting(horizontalOverhangRect, verticalOverhangRe
ct); | |
991 | |
992 if (dirtyRect.intersects(horizontalOverhangRect) || dirtyRect.intersects(ver
ticalOverhangRect)) | |
993 ScrollbarTheme::theme()->paintOverhangBackground(context, horizontalOver
hangRect, verticalOverhangRect, dirtyRect); | |
994 } | |
995 | |
996 bool ScrollView::isPointInScrollbarCorner(const IntPoint& windowPoint) | |
997 { | |
998 if (!scrollbarCornerPresent()) | |
999 return false; | |
1000 | |
1001 IntPoint viewPoint = convertFromContainingWindow(windowPoint); | |
1002 | |
1003 if (m_horizontalScrollbar) { | |
1004 int horizontalScrollbarYMin = m_horizontalScrollbar->frameRect().y(); | |
1005 int horizontalScrollbarYMax = m_horizontalScrollbar->frameRect().y() + m
_horizontalScrollbar->frameRect().height(); | |
1006 int horizontalScrollbarXMin = m_horizontalScrollbar->frameRect().x() + m
_horizontalScrollbar->frameRect().width(); | |
1007 | |
1008 return viewPoint.y() > horizontalScrollbarYMin && viewPoint.y() < horizo
ntalScrollbarYMax && viewPoint.x() > horizontalScrollbarXMin; | |
1009 } | |
1010 | |
1011 int verticalScrollbarXMin = m_verticalScrollbar->frameRect().x(); | |
1012 int verticalScrollbarXMax = m_verticalScrollbar->frameRect().x() + m_vertica
lScrollbar->frameRect().width(); | |
1013 int verticalScrollbarYMin = m_verticalScrollbar->frameRect().y() + m_vertica
lScrollbar->frameRect().height(); | |
1014 | |
1015 return viewPoint.x() > verticalScrollbarXMin && viewPoint.x() < verticalScro
llbarXMax && viewPoint.y() > verticalScrollbarYMin; | |
1016 } | |
1017 | |
1018 bool ScrollView::scrollbarCornerPresent() const | |
1019 { | |
1020 return (m_horizontalScrollbar && width() - m_horizontalScrollbar->width() >
0) | |
1021 || (m_verticalScrollbar && height() - m_verticalScrollbar->height() > 0)
; | |
1022 } | |
1023 | |
1024 IntRect ScrollView::convertFromScrollbarToContainingView(const Scrollbar* scroll
bar, const IntRect& localRect) const | |
1025 { | |
1026 // Scrollbars won't be transformed within us | |
1027 IntRect newRect = localRect; | |
1028 newRect.moveBy(scrollbar->location()); | |
1029 return newRect; | |
1030 } | |
1031 | |
1032 IntRect ScrollView::convertFromContainingViewToScrollbar(const Scrollbar* scroll
bar, const IntRect& parentRect) const | |
1033 { | |
1034 IntRect newRect = parentRect; | |
1035 // Scrollbars won't be transformed within us | |
1036 newRect.moveBy(-scrollbar->location()); | |
1037 return newRect; | |
1038 } | |
1039 | |
1040 // FIXME: test these on windows | |
1041 IntPoint ScrollView::convertFromScrollbarToContainingView(const Scrollbar* scrol
lbar, const IntPoint& localPoint) const | |
1042 { | |
1043 // Scrollbars won't be transformed within us | |
1044 IntPoint newPoint = localPoint; | |
1045 newPoint.moveBy(scrollbar->location()); | |
1046 return newPoint; | |
1047 } | |
1048 | |
1049 IntPoint ScrollView::convertFromContainingViewToScrollbar(const Scrollbar* scrol
lbar, const IntPoint& parentPoint) const | |
1050 { | |
1051 IntPoint newPoint = parentPoint; | |
1052 // Scrollbars won't be transformed within us | |
1053 newPoint.moveBy(-scrollbar->location()); | |
1054 return newPoint; | |
1055 } | |
1056 | |
1057 void ScrollView::setParentVisible(bool visible) | |
1058 { | |
1059 if (isParentVisible() == visible) | |
1060 return; | |
1061 | |
1062 Widget::setParentVisible(visible); | |
1063 | |
1064 if (!isSelfVisible()) | |
1065 return; | |
1066 | |
1067 HashSet<RefPtr<Widget> >::iterator end = m_children.end(); | |
1068 for (HashSet<RefPtr<Widget> >::iterator it = m_children.begin(); it != end;
++it) | |
1069 (*it)->setParentVisible(visible); | |
1070 } | |
1071 | |
1072 void ScrollView::show() | |
1073 { | |
1074 if (!isSelfVisible()) { | |
1075 setSelfVisible(true); | |
1076 if (isParentVisible()) { | |
1077 HashSet<RefPtr<Widget> >::iterator end = m_children.end(); | |
1078 for (HashSet<RefPtr<Widget> >::iterator it = m_children.begin(); it
!= end; ++it) | |
1079 (*it)->setParentVisible(true); | |
1080 } | |
1081 } | |
1082 | |
1083 Widget::show(); | |
1084 } | |
1085 | |
1086 void ScrollView::hide() | |
1087 { | |
1088 if (isSelfVisible()) { | |
1089 if (isParentVisible()) { | |
1090 HashSet<RefPtr<Widget> >::iterator end = m_children.end(); | |
1091 for (HashSet<RefPtr<Widget> >::iterator it = m_children.begin(); it
!= end; ++it) | |
1092 (*it)->setParentVisible(false); | |
1093 } | |
1094 setSelfVisible(false); | |
1095 } | |
1096 | |
1097 Widget::hide(); | |
1098 } | |
1099 | |
1100 bool ScrollView::isOffscreen() const | |
1101 { | |
1102 return !isVisible(); | |
1103 } | |
1104 | |
1105 | |
1106 void ScrollView::addPanScrollIcon(const IntPoint& iconPosition) | |
1107 { | |
1108 HostWindow* window = hostWindow(); | |
1109 if (!window) | |
1110 return; | |
1111 m_drawPanScrollIcon = true; | |
1112 m_panScrollIconPoint = IntPoint(iconPosition.x() - panIconSizeLength / 2 , i
conPosition.y() - panIconSizeLength / 2) ; | |
1113 window->invalidateContentsAndRootView(IntRect(m_panScrollIconPoint, IntSize(
panIconSizeLength, panIconSizeLength))); | |
1114 } | |
1115 | |
1116 void ScrollView::removePanScrollIcon() | |
1117 { | |
1118 HostWindow* window = hostWindow(); | |
1119 if (!window) | |
1120 return; | |
1121 m_drawPanScrollIcon = false; | |
1122 window->invalidateContentsAndRootView(IntRect(m_panScrollIconPoint, IntSize(
panIconSizeLength, panIconSizeLength))); | |
1123 } | |
1124 | |
1125 void ScrollView::setScrollOrigin(const IntPoint& origin, bool updatePositionAtAl
l, bool updatePositionSynchronously) | |
1126 { | |
1127 if (scrollOrigin() == origin) | |
1128 return; | |
1129 | |
1130 ScrollableArea::setScrollOrigin(origin); | |
1131 | |
1132 // Update if the scroll origin changes, since our position will be different
if the content size did not change. | |
1133 if (updatePositionAtAll && updatePositionSynchronously) | |
1134 updateScrollbars(scrollOffset()); | |
1135 } | |
1136 | |
1137 int ScrollView::pageStep(ScrollbarOrientation orientation) const | |
1138 { | |
1139 int length = (orientation == HorizontalScrollbar) ? visibleWidth() : visible
Height(); | |
1140 int minPageStep = static_cast<float>(length) * minFractionToStepWhenPaging()
; | |
1141 int pageStep = std::max(minPageStep, length - maxOverlapBetweenPages()); | |
1142 | |
1143 return std::max(pageStep, 1); | |
1144 } | |
1145 | |
1146 } // namespace WebCore | |
OLD | NEW |