📄 scrollview.cpp
字号:
// We need to go ahead and repaint the entire backing store. Do it now before moving the // plugins. hostWindow()->repaint(updateRect, true, false, true); // Invalidate the backing store and repaint it synchronously } // This call will move children with native widgets (plugins) and invalidate them as well. frameRectsChanged(); // Now update the window (which should do nothing but a blit of the backing store's updateRect and so should // be very fast). hostWindow()->paint();}IntPoint ScrollView::windowToContents(const IntPoint& windowPoint) const{ IntPoint viewPoint = convertFromContainingWindow(windowPoint); return viewPoint + scrollOffset();}IntPoint ScrollView::contentsToWindow(const IntPoint& contentsPoint) const{ IntPoint viewPoint = contentsPoint - scrollOffset(); return convertToContainingWindow(viewPoint); }IntRect ScrollView::windowToContents(const IntRect& windowRect) const{ IntRect viewRect = convertFromContainingWindow(windowRect); viewRect.move(scrollOffset()); return viewRect;}IntRect ScrollView::contentsToWindow(const IntRect& contentsRect) const{ IntRect viewRect = contentsRect; viewRect.move(-scrollOffset()); return convertToContainingWindow(viewRect);}IntRect ScrollView::contentsToScreen(const IntRect& rect) const{ if (platformWidget()) return platformContentsToScreen(rect); return hostWindow()->windowToScreen(contentsToWindow(rect));}IntPoint ScrollView::screenToContents(const IntPoint& point) const{ if (platformWidget()) return platformScreenToContents(point); return windowToContents(hostWindow()->screenToWindow(point));}bool ScrollView::containsScrollbarsAvoidingResizer() const{ return !m_scrollbarsAvoidingResizer;}void ScrollView::adjustScrollbarsAvoidingResizerCount(int overlapDelta){ int oldCount = m_scrollbarsAvoidingResizer; m_scrollbarsAvoidingResizer += overlapDelta; if (parent()) parent()->adjustScrollbarsAvoidingResizerCount(overlapDelta); else if (!scrollbarsSuppressed()) { // If we went from n to 0 or from 0 to n and we're the outermost view, // we need to invalidate the windowResizerRect(), since it will now need to paint // differently. if (oldCount > 0 && m_scrollbarsAvoidingResizer == 0 || oldCount == 0 && m_scrollbarsAvoidingResizer > 0) invalidateRect(windowResizerRect()); }}void ScrollView::setParent(ScrollView* parentView){ if (parentView == parent()) return; if (m_scrollbarsAvoidingResizer && parent()) parent()->adjustScrollbarsAvoidingResizerCount(-m_scrollbarsAvoidingResizer); Widget::setParent(parentView); if (m_scrollbarsAvoidingResizer && parent()) parent()->adjustScrollbarsAvoidingResizerCount(m_scrollbarsAvoidingResizer);}void ScrollView::setScrollbarsSuppressed(bool suppressed, bool repaintOnUnsuppress){ if (suppressed == m_scrollbarsSuppressed) return; m_scrollbarsSuppressed = suppressed; if (platformWidget()) platformSetScrollbarsSuppressed(repaintOnUnsuppress); else if (repaintOnUnsuppress && !suppressed) { if (m_horizontalScrollbar) m_horizontalScrollbar->invalidate(); if (m_verticalScrollbar) m_verticalScrollbar->invalidate(); // Invalidate the scroll corner too on unsuppress. IntRect hCorner; if (m_horizontalScrollbar && width() - m_horizontalScrollbar->width() > 0) { hCorner = IntRect(m_horizontalScrollbar->width(), height() - m_horizontalScrollbar->height(), width() - m_horizontalScrollbar->width(), m_horizontalScrollbar->height()); invalidateRect(hCorner); } if (m_verticalScrollbar && height() - m_verticalScrollbar->height() > 0) { IntRect vCorner(width() - m_verticalScrollbar->width(), m_verticalScrollbar->height(), m_verticalScrollbar->width(), height() - m_verticalScrollbar->height()); if (vCorner != hCorner) invalidateRect(vCorner); } }}Scrollbar* ScrollView::scrollbarUnderMouse(const PlatformMouseEvent& mouseEvent){ if (platformWidget()) return 0; IntPoint viewPoint = convertFromContainingWindow(mouseEvent.pos()); if (m_horizontalScrollbar && m_horizontalScrollbar->frameRect().contains(viewPoint)) return m_horizontalScrollbar.get(); if (m_verticalScrollbar && m_verticalScrollbar->frameRect().contains(viewPoint)) return m_verticalScrollbar.get(); return 0;}void ScrollView::wheelEvent(PlatformWheelEvent& e){ // We don't allow mouse wheeling to happen in a ScrollView that has had its scrollbars explicitly disabled. if (!canHaveScrollbars() || platformWidget()) return; // Determine how much we want to scroll. If we can move at all, we will accept the event. IntSize maxScrollDelta = maximumScrollPosition() - scrollPosition(); if ((e.deltaX() < 0 && maxScrollDelta.width() > 0) || (e.deltaX() > 0 && scrollOffset().width() > 0) || (e.deltaY() < 0 && maxScrollDelta.height() > 0) || (e.deltaY() > 0 && scrollOffset().height() > 0)) { e.accept(); float deltaX = e.deltaX(); float deltaY = e.deltaY(); if (e.granularity() == ScrollByPageWheelEvent) { ASSERT(deltaX == 0); bool negative = deltaY < 0; deltaY = max(0, visibleHeight() - cAmountToKeepWhenPaging); if (negative) deltaY = -deltaY; } scrollBy(IntSize(-deltaX, -deltaY)); }}void ScrollView::setFrameRect(const IntRect& newRect){ IntRect oldRect = frameRect(); if (newRect == oldRect) return; Widget::setFrameRect(newRect); if (platformWidget()) return; if (newRect.width() != oldRect.width() || newRect.height() != oldRect.height()) { updateScrollbars(m_scrollOffset); contentsResized(); } frameRectsChanged();}void ScrollView::frameRectsChanged(){ if (platformWidget()) return; HashSet<Widget*>::const_iterator end = m_children.end(); for (HashSet<Widget*>::const_iterator current = m_children.begin(); current != end; ++current) (*current)->frameRectsChanged();}void ScrollView::repaintContentRectangle(const IntRect& rect, bool now){ if (rect.isEmpty()) return; if (platformWidget()) { platformRepaintContentRectangle(rect, now); return; } hostWindow()->repaint(contentsToWindow(rect), true, now);}void ScrollView::paint(GraphicsContext* context, const IntRect& rect){ if (platformWidget()) { Widget::paint(context, rect); return; } if (context->paintingDisabled() && !context->updatingControlTints()) return; IntRect documentDirtyRect = rect; documentDirtyRect.intersect(frameRect()); context->save(); context->translate(x(), y()); documentDirtyRect.move(-x(), -y()); context->translate(-scrollX(), -scrollY()); documentDirtyRect.move(scrollX(), scrollY()); context->clip(visibleContentRect()); paintContents(context, documentDirtyRect); context->restore(); // Now paint the scrollbars. if (!m_scrollbarsSuppressed && (m_horizontalScrollbar || m_verticalScrollbar)) { context->save(); IntRect scrollViewDirtyRect = rect; scrollViewDirtyRect.intersect(frameRect()); context->translate(x(), y()); scrollViewDirtyRect.move(-x(), -y()); if (m_horizontalScrollbar) m_horizontalScrollbar->paint(context, scrollViewDirtyRect); if (m_verticalScrollbar) m_verticalScrollbar->paint(context, scrollViewDirtyRect); IntRect hCorner; if (m_horizontalScrollbar && width() - m_horizontalScrollbar->width() > 0) { hCorner = IntRect(m_horizontalScrollbar->width(), height() - m_horizontalScrollbar->height(), width() - m_horizontalScrollbar->width(), m_horizontalScrollbar->height()); if (hCorner.intersects(scrollViewDirtyRect)) ScrollbarTheme::nativeTheme()->paintScrollCorner(this, context, hCorner); } if (m_verticalScrollbar && height() - m_verticalScrollbar->height() > 0) { IntRect vCorner(width() - m_verticalScrollbar->width(), m_verticalScrollbar->height(), m_verticalScrollbar->width(), height() - m_verticalScrollbar->height()); if (vCorner != hCorner && vCorner.intersects(scrollViewDirtyRect)) ScrollbarTheme::nativeTheme()->paintScrollCorner(this, context, vCorner); } context->restore(); } // Paint the panScroll Icon if (m_drawPanScrollIcon) { DEFINE_STATIC_LOCAL(RefPtr<Image>, panScrollIcon, (Image::loadPlatformResource("panIcon"))); context->drawImage(panScrollIcon.get(), m_panScrollIconPoint); }}bool ScrollView::scrollbarCornerPresent() const{ return (m_horizontalScrollbar && width() - m_horizontalScrollbar->width() > 0) || (m_verticalScrollbar && height() - m_verticalScrollbar->height() > 0);}void ScrollView::setParentVisible(bool visible){ if (isParentVisible() == visible) return; Widget::setParentVisible(visible); if (!isSelfVisible()) return; HashSet<Widget*>::iterator end = m_children.end(); for (HashSet<Widget*>::iterator it = m_children.begin(); it != end; ++it) (*it)->setParentVisible(visible);}void ScrollView::show(){ if (!isSelfVisible()) { setSelfVisible(true); if (isParentVisible()) { HashSet<Widget*>::iterator end = m_children.end(); for (HashSet<Widget*>::iterator it = m_children.begin(); it != end; ++it) (*it)->setParentVisible(true); } } Widget::show();}void ScrollView::hide(){ if (isSelfVisible()) { if (isParentVisible()) { HashSet<Widget*>::iterator end = m_children.end(); for (HashSet<Widget*>::iterator it = m_children.begin(); it != end; ++it) (*it)->setParentVisible(false); } setSelfVisible(false); } Widget::hide();}bool ScrollView::isOffscreen() const{ if (platformWidget()) return platformIsOffscreen(); if (!isVisible()) return true; // FIXME: Add a HostWindow::isOffscreen method here. Since only Mac implements this method // currently, we can add the method when the other platforms decide to implement this concept. return false;}void ScrollView::addPanScrollIcon(const IntPoint& iconPosition){ m_drawPanScrollIcon = true; m_panScrollIconPoint = IntPoint(iconPosition.x() - panIconSizeLength / 2 , iconPosition.y() - panIconSizeLength / 2) ; hostWindow()->repaint(IntRect(m_panScrollIconPoint, IntSize(panIconSizeLength,panIconSizeLength)), true, true); }void ScrollView::removePanScrollIcon(){ m_drawPanScrollIcon = false; hostWindow()->repaint(IntRect(m_panScrollIconPoint, IntSize(panIconSizeLength, panIconSizeLength)), true, true);}#if !PLATFORM(WX) && !PLATFORM(GTK) && !PLATFORM(QT)void ScrollView::platformInit(){}void ScrollView::platformDestroy(){}#endif#if !PLATFORM(WX) && !PLATFORM(GTK) && !PLATFORM(QT) && !PLATFORM(MAC)void ScrollView::platformAddChild(Widget*){}void ScrollView::platformRemoveChild(Widget*){}#endif#if !PLATFORM(MAC)void ScrollView::platformSetScrollbarsSuppressed(bool repaintOnUnsuppress){}#endif#if !PLATFORM(MAC) && !PLATFORM(WX)void ScrollView::platformSetScrollbarModes(){}void ScrollView::platformScrollbarModes(ScrollbarMode& horizontal, ScrollbarMode& vertical) const{}void ScrollView::platformSetCanBlitOnScroll(bool){}bool ScrollView::platformCanBlitOnScroll() const{ return false;}IntRect ScrollView::platformVisibleContentRect(bool) const{ return IntRect();}IntSize ScrollView::platformContentsSize() const{ return IntSize();}void ScrollView::platformSetContentsSize(){}IntRect ScrollView::platformContentsToScreen(const IntRect& rect) const{ return rect;}IntPoint ScrollView::platformScreenToContents(const IntPoint& point) const{ return point;}void ScrollView::platformSetScrollPosition(const IntPoint&){}bool ScrollView::platformScroll(ScrollDirection, ScrollGranularity){ return true;}void ScrollView::platformRepaintContentRectangle(const IntRect&, bool now){}bool ScrollView::platformIsOffscreen() const{ return false;}#endif#if !PLATFORM(GTK)bool ScrollView::platformHandleHorizontalAdjustment(const IntSize&){ return false;}bool ScrollView::platformHandleVerticalAdjustment(const IntSize&){ return false;}bool ScrollView::platformHasHorizontalAdjustment() const{ return false;}bool ScrollView::platformHasVerticalAdjustment() const{ return false;}#endif}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -