⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kwqscrollview.cpp

📁 手机浏览器源码程序,功能强大
💻 CPP
字号:
/*
 * Copyright (C) 2003 Apple Computer, Inc.  All rights reserved.
 * Portions Copyright (c) 2005 Nokia Corporation, Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "KWQScrollView.h"

#include "KWQLogging.h"
#include  "KWQExceptions.h"
#include  "KWQKHTMLPart.h"
#include  "KWQLogging.h"
#include  "KWQWindowWidget.h"
#include  "WebCoreBridge.h"
#include  "khtmlview.h"

/*
    This class implementation does NOT actually emulate the Qt QScrollView.
    It does provide an implementation that khtml will use to interact with
    WebKit's WebFrameView documentView and our NSScrollView subclass.

    QScrollView's view is a NSScrollView (or subclass of NSScrollView)
    in most cases. That scrollview is a subview of an
    WebCoreFrameView. The WebCoreFrameView's documentView will also be
    the scroll view's documentView.

    The WebCoreFrameView's size is the frame size.  The WebCoreFrameView's documentView
    corresponds to the frame content size.  The scrollview itself is autosized to the
    WebCoreFrameView's size (see QWidget::resize).
*/

QWidget* QScrollView::viewport() const
{
    return const_cast<QScrollView *>(this);
}

int QScrollView::visibleWidth() const
{
    MWebCoreScrollView* v = static_cast<MWebCoreScrollView*>(getView());
    return v?v->VisibleRect().Width():0;
}

int QScrollView::visibleHeight() const
{
    MWebCoreScrollView* v = static_cast<MWebCoreScrollView*>(getView());
    return v?v->VisibleRect().Height():0;
}

int QScrollView::contentsWidth() const
{
    MWebCoreScrollView* v = static_cast<MWebCoreScrollView*>(getView());
    return v?v->ContentSize().iWidth:0;
}

int QScrollView::contentsHeight() const
{
    MWebCoreScrollView* v = static_cast<MWebCoreScrollView*>(getView());
    return v?v->ContentSize().iHeight:0;
}

int QScrollView::contentsX() const
{
    MWebCoreScrollView* v = static_cast<MWebCoreScrollView*>(getView());
    return v?v->VisibleRect().iTl.iX:0;
}

int QScrollView::contentsY() const
{
    MWebCoreScrollView* v = static_cast<MWebCoreScrollView*>(getView());
    return v?v->VisibleRect().iTl.iY:0;
}

int QScrollView::childX(QWidget* w)
{
    return w->x();
}

int QScrollView::childY(QWidget* w)
{
    return w->y();
}

void QScrollView::scrollBy(int dx, int dy)
{
    setContentsPos(contentsX() + dx, contentsY() + dy);
}

void QScrollView::setContentsPos(int x, int y)
{
    MWebCoreScrollView* v = static_cast<MWebCoreScrollView*>(getView());
    if (v) v->ScrollTo(TPoint(x,y));
}

void QScrollView::setVScrollBarMode(ScrollBarMode vMode)
{
    MWebCoreScrollView* v = static_cast<MWebCoreScrollView*>(getView());
    if (v) v->SetVerticalScrollingMode((TWebCoreScrollBarMode)vMode);
}

void QScrollView::setHScrollBarMode(ScrollBarMode hMode)
{
    MWebCoreScrollView* v = static_cast<MWebCoreScrollView*>(getView());
    if (v) v->SetHorizontalScrollingMode((TWebCoreScrollBarMode)hMode);
}

void QScrollView::setScrollBarsMode(ScrollBarMode mode)
{
    MWebCoreScrollView* v = static_cast<MWebCoreScrollView*>(getView());
    if (v) v->SetScrollingMode((TWebCoreScrollBarMode)mode);
}

QScrollView::ScrollBarMode
QScrollView::vScrollBarMode() const
{
    MWebCoreScrollView* v = static_cast<MWebCoreScrollView*>(getView());
    return v?(QScrollView::ScrollBarMode)v->VerticalScrollingMode():Auto;
}

QScrollView::ScrollBarMode
QScrollView::hScrollBarMode() const
{
    MWebCoreScrollView* v = static_cast<MWebCoreScrollView*>(getView());
    return v?(QScrollView::ScrollBarMode)v->HorizontalScrollingMode():Auto;
}

bool QScrollView::hasVerticalScrollBar() const
{
    MWebCoreScrollView* v = static_cast<MWebCoreScrollView*>(getView());
    return v?v->HasVerticalScrollBar():0;
}

bool QScrollView::hasHorizontalScrollBar() const
{
    MWebCoreScrollView* v = static_cast<MWebCoreScrollView*>(getView());
    return v?v->HasHorizontalScrollBar():0;
}

void QScrollView::suppressScrollBars(bool suppressed,  bool repaintOnUnsuppress)
{
    MWebCoreScrollView* v = static_cast<MWebCoreScrollView*>(getView());
    if (v) v->SetScrollBarsSuppressed(suppressed,repaintOnUnsuppress);
}

void QScrollView::addChild(QWidget* child, int x, int y)
{
    MWebCoreScrollView* v = static_cast<MWebCoreScrollView*>(getView());
    if (v) v->AddChild(child->getView(), x, y);
}

void QScrollView::removeChild(QWidget* child)
{
   /* KWQ_BLOCK_EXCEPTIONS;
    [child->getOuterView() removeFromSuperview];
    KWQ_UNBLOCK_EXCEPTIONS;
    */
}

void QScrollView::resizeContents(int w, int h)
{

    //LOG(Frames, "%p %@ at w %d h %d\n", getView(), [(id)[getView() class] className], w, h);

    if (w < 0)
        w = 0;
    if (h < 0)
        h = 0;

    MWebCoreScrollView* v = static_cast<MWebCoreScrollView*>(getView());
    if (v) v->ResizeContent(TSize(w,h));
}

void QScrollView::updateContents(int x, int y, int w, int h, bool now)
{
    updateContents(QRect(x, y, w, h), now);
}

void QScrollView::updateContents(const QRect &rect, bool now)
{
    MWebCoreScrollView* v = static_cast<MWebCoreScrollView*>(getView());
    if (v) v->InvalidateRect(rect.Rect(), now);
}

void QScrollView::repaintContents(int x, int y, int w, int h, bool erase)
{
    LOG(Frames, "%p at (%d,%d) w %d h %d\n", getView(), x, y, w, h);
}

QPoint QScrollView::contentsToViewport(const QPoint &p)
{
    int vx, vy;
    contentsToViewport(p.x(), p.y(), vx, vy);
    return QPoint(vx, vy);
}

void QScrollView::contentsToViewport(int x, int y, int& vx, int& vy)
{
    MWebCoreScrollView* v = static_cast<MWebCoreScrollView*>(getView());
    TPoint p;
    if (v) p = v->ConvertContentToView(TPoint(x,y));
    vx = p.iX;
    vy = p.iY;
    return;
}

void QScrollView::viewportToContents(int vx, int vy, int& x, int& y)
{
    MWebCoreScrollView* v = static_cast<MWebCoreScrollView*>(getView());
    TPoint p;
    if (v) p = v->ConvertViewToContent(TPoint(vx,vy));
    x = p.iX;
    y = p.iY;
    return;
}

void QScrollView::setStaticBackground(bool b)
{
    MWebCoreScrollView* v = static_cast<MWebCoreScrollView*>(getView());
    if (v) v->SetMayUseCopyScroll(!b);
}

void QScrollView::resizeEvent(QResizeEvent *)
{
}

void QScrollView::setContentsPosRecursive(int x, int y)
{
    MWebCoreScrollView* v = static_cast<MWebCoreScrollView*>(getView());
    if (v) v->ScrollTo( TPoint( x, y ) );
}

void QScrollView::ensureVisible(int x, int y)
{
    // Note that the definition of ensureVisible in trolltech documentation says:
    // "Scrolls the content so that the point (x, y) is visible with at least
    // 50-pixel margins (if possible, otherwise centered).", which is
    // not what we're doing here.
    /*KWQ_BLOCK_EXCEPTIONS;
    [getDocumentView() scrollRectToVisible:NSMakeRect(x, y, 0, 0)];
    KWQ_UNBLOCK_EXCEPTIONS;
    */
}

void QScrollView::ensureVisible(int x, int y, int xmargin, int ymargin)
{
    // Note that the definition of ensureVisible in trolltech documentation says:
    // "Scrolls the content so that the point (x, y) is visible with at least the
    // xmargin and ymargin margins (if possible, otherwise centered).", which is
    // not what we're doing here.
    /*KWQ_BLOCK_EXCEPTIONS;
    [getDocumentView() scrollRectToVisible:NSMakeRect(x, y, xmargin, ymargin)];
    KWQ_UNBLOCK_EXCEPTIONS;
    */
}

void QScrollView::ensureRectVisibleCentered(const QRect &rect)
{
    /*KWQ_BLOCK_EXCEPTIONS;
    [getDocumentView() _KWQ_scrollRectToVisible:NSMakeRect(rect.x(), rect.y(), rect.width(), rect.height())];
    KWQ_UNBLOCK_EXCEPTIONS;
    */
}

int QScrollView::scalingFactor() const
{
    return _scalingFactor;
}

void QScrollView::setScalingFactor(int factor)
{
    _scalingFactor = factor;
}


MWebCoreScrollView& QScrollView::GetDocumentView() const
{
    /*id view = getView();

    KWQ_BLOCK_EXCEPTIONS;
    if ([view respondsToSelector:@selector(documentView)])
    return [view documentView];
    KWQ_UNBLOCK_EXCEPTIONS;

    return nil;
    */
    return *static_cast<MWebCoreScrollView*>(getView());
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -