📄 khtmlview.cpp.orig
字号:
/* This file is part of the KDE project * * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org> * 1999 Lars Knoll <knoll@kde.org> * 1999 Antti Koivisto <koivisto@kde.org> * 2000-2004 Dirk Mueller <mueller@kde.org> * 2003 Leo Savernik <l.savernik@aon.at> * 2003-2004 Apple Computer, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */#include "khtmlview.moc"#include "khtmlview.h"#include "khtml_part.h"#include "khtml_events.h"#include "html/html_documentimpl.h"#include "html/html_inlineimpl.h"#include "html/html_formimpl.h"#include "rendering/render_arena.h"#include "rendering/render_canvas.h"#include "rendering/render_frames.h"#include "rendering/render_replaced.h"#include "rendering/render_layer.h"#include "rendering/render_line.h"#include "rendering/render_table.h"// removeme#define protected public#include "rendering/render_text.h"#undef protected#include "xml/dom2_eventsimpl.h"#include "css/cssstyleselector.h"#include "css/csshelper.h"#include "misc/htmlhashes.h"#include "misc/helper.h"#include "khtml_settings.h"#include "khtml_printsettings.h"#include "khtmlpart_p.h"#ifndef KHTML_NO_CARET#include "khtml_caret_p.h"#include "xml/dom2_rangeimpl.h"#endif#include <kapplication.h>#include <kcursor.h>#include <kdebug.h>#include <kdialogbase.h>#include <kiconloader.h>#include <kimageio.h>#include <klocale.h>#include <knotifyclient.h>#include <kprinter.h>#include <ksimpleconfig.h>#include <kstandarddirs.h>#include <kstdaccel.h>#include <kstringhandler.h>#include <kurldrag.h>#include <qbitmap.h>#include <qlabel.h>#include <qobjectlist.h>#include <qpaintdevicemetrics.h>#include <qpainter.h>#include <qptrdict.h>#include <qtooltip.h>#include <qstring.h>#include <qstylesheet.h>#include <qtimer.h>#include <qvaluevector.h>//#define DEBUG_NO_PAINT_BUFFER//#define DEBUG_FLICKER//#define DEBUG_PIXEL#ifdef Q_WS_X11#include <X11/Xlib.h>#include <fixx11h.h>#endif#define PAINT_BUFFER_HEIGHT 128#if 0namespace khtml { void dumpLineBoxes(RenderFlow *flow);}#endifusing namespace DOM;using namespace khtml;class KHTMLToolTip;#ifndef QT_NO_TOOLTIPclass KHTMLToolTip : public QToolTip{public: KHTMLToolTip(KHTMLView *view, KHTMLViewPrivate* vp) : QToolTip(view->viewport()) { m_view = view; m_viewprivate = vp; };protected: virtual void maybeTip(const QPoint &);private: KHTMLView *m_view; KHTMLViewPrivate* m_viewprivate;};#endifclass KHTMLViewPrivate { friend class KHTMLToolTip;public: enum PseudoFocusNodes { PFNone, PFTop, PFBottom }; enum CompletedState { CSNone = 0, CSFull, CSActionPending }; KHTMLViewPrivate() : underMouse( 0 ), underMouseNonShared( 0 ) {#ifndef KHTML_NO_CARET m_caretViewContext = 0; m_editorContext = 0;#endif // KHTML_NO_CARET postponed_autorepeat = NULL; reset(); vmode = QScrollView::Auto; hmode = QScrollView::Auto; tp=0; paintBuffer=0; vertPaintBuffer=0; formCompletions=0; prevScrollbarVisible = true; tooltip = 0; possibleTripleClick = false; emitCompletedAfterRepaint = CSNone; cursor_icon_widget = NULL; m_mouseScrollTimer = 0; m_mouseScrollIndicator = 0; } ~KHTMLViewPrivate() { delete formCompletions; delete tp; tp = 0; delete paintBuffer; paintBuffer =0; delete vertPaintBuffer; delete postponed_autorepeat; if (underMouse) underMouse->deref(); if (underMouseNonShared) underMouseNonShared->deref(); delete tooltip;#ifndef KHTML_NO_CARET delete m_caretViewContext; delete m_editorContext;#endif // KHTML_NO_CARET delete cursor_icon_widget; delete m_mouseScrollTimer; delete m_mouseScrollIndicator; } void reset() { if (underMouse) underMouse->deref(); underMouse = 0; if (underMouseNonShared) underMouseNonShared->deref(); underMouseNonShared = 0; linkPressed = false; useSlowRepaints = false; tabMovePending = false; lastTabbingDirection = true; pseudoFocusNode = PFNone;#ifndef KHTML_NO_SCROLLBARS //We don't turn off the toolbars here //since if the user turns them //off, then chances are they want them turned //off always - even after a reset.#else vmode = QScrollView::AlwaysOff; hmode = QScrollView::AlwaysOff;#endif#ifdef DEBUG_PIXEL timer.start(); pixelbooth = 0; repaintbooth = 0;#endif scrollBarMoved = false; contentsMoving = false; ignoreWheelEvents = false; borderX = 30; borderY = 30; paged = false; clickX = -1; clickY = -1; prevMouseX = -1; prevMouseY = -1; clickCount = 0; isDoubleClick = false; scrollingSelf = false; delete postponed_autorepeat; postponed_autorepeat = NULL; layoutTimerId = 0; repaintTimerId = 0; scrollTimerId = 0; scrollSuspended = false; scrollSuspendPreActivate = false; complete = false; firstRelayout = true; needsFullRepaint = true; dirtyLayout = false; layoutSchedulingEnabled = true; painting = false; updateRegion = QRegion(); m_dialogsAllowed = true;#ifndef KHTML_NO_CARET if (m_caretViewContext) { m_caretViewContext->caretMoved = false; m_caretViewContext->keyReleasePending = false; }/*end if*/#endif // KHTML_NO_CARET#ifndef KHTML_NO_TYPE_AHEAD_FIND typeAheadActivated = false;#endif // KHTML_NO_TYPE_AHEAD_FIND accessKeysActivated = false; accessKeysPreActivate = false; // We ref/deref to ensure defaultHTMLSettings is available KHTMLFactory::ref(); accessKeysEnabled = KHTMLFactory::defaultHTMLSettings()->accessKeysEnabled(); KHTMLFactory::deref(); emitCompletedAfterRepaint = CSNone; } void newScrollTimer(QWidget *view, int tid) { //kdDebug(6000) << "newScrollTimer timer " << tid << endl; view->killTimer(scrollTimerId); scrollTimerId = tid; scrollSuspended = false; } enum ScrollDirection { ScrollLeft, ScrollRight, ScrollUp, ScrollDown }; void adjustScroller(QWidget *view, ScrollDirection direction, ScrollDirection oppositedir) { static const struct { int msec, pixels; } timings [] = { {320,1}, {224,1}, {160,1}, {112,1}, {80,1}, {56,1}, {40,1}, {28,1}, {20,1}, {20,2}, {20,3}, {20,4}, {20,6}, {20,8}, {0,0} }; if (!scrollTimerId || (scrollDirection != direction && (scrollDirection != oppositedir || scrollSuspended))) { scrollTiming = 6; scrollBy = timings[scrollTiming].pixels; scrollDirection = direction; newScrollTimer(view, view->startTimer(timings[scrollTiming].msec)); } else if (scrollDirection == direction && timings[scrollTiming+1].msec && !scrollSuspended) { scrollBy = timings[++scrollTiming].pixels; newScrollTimer(view, view->startTimer(timings[scrollTiming].msec)); } else if (scrollDirection == oppositedir) { if (scrollTiming) { scrollBy = timings[--scrollTiming].pixels; newScrollTimer(view, view->startTimer(timings[scrollTiming].msec)); } } scrollSuspended = false; }#ifndef KHTML_NO_CARET /** this function returns an instance of the caret view context. If none * exists, it will be instantiated. */ CaretViewContext *caretViewContext() { if (!m_caretViewContext) m_caretViewContext = new CaretViewContext(); return m_caretViewContext; } /** this function returns an instance of the editor context. If none * exists, it will be instantiated. */ EditorContext *editorContext() { if (!m_editorContext) m_editorContext = new EditorContext(); return m_editorContext; }#endif // KHTML_NO_CARET#ifdef DEBUG_PIXEL QTime timer; unsigned int pixelbooth; unsigned int repaintbooth;#endif QPainter *tp; QPixmap *paintBuffer; QPixmap *vertPaintBuffer; NodeImpl *underMouse; NodeImpl *underMouseNonShared; bool tabMovePending:1; bool lastTabbingDirection:1; PseudoFocusNodes pseudoFocusNode:2; bool scrollBarMoved:1; bool contentsMoving:1; QScrollView::ScrollBarMode vmode; QScrollView::ScrollBarMode hmode; bool prevScrollbarVisible:1; bool linkPressed:1; bool useSlowRepaints:1; bool ignoreWheelEvents:1; int borderX, borderY; KSimpleConfig *formCompletions; bool paged; int clickX, clickY, clickCount; bool isDoubleClick; int prevMouseX, prevMouseY; bool scrollingSelf; int layoutTimerId; QKeyEvent* postponed_autorepeat; int repaintTimerId; int scrollTimerId; int scrollTiming; int scrollBy; ScrollDirection scrollDirection :2; bool scrollSuspended :1; bool scrollSuspendPreActivate :1; bool complete :1; bool firstRelayout :1; bool layoutSchedulingEnabled :1; bool needsFullRepaint :1; bool painting :1; bool possibleTripleClick :1; bool dirtyLayout :1; bool m_dialogsAllowed :1; QRegion updateRegion; KHTMLToolTip *tooltip; QPtrDict<QWidget> visibleWidgets;#ifndef KHTML_NO_CARET CaretViewContext *m_caretViewContext; EditorContext *m_editorContext;#endif // KHTML_NO_CARET#ifndef KHTML_NO_TYPE_AHEAD_FIND QString findString; QTimer timer; bool findLinksOnly; bool typeAheadActivated;#endif // KHTML_NO_TYPE_AHEAD_FIND bool accessKeysEnabled; bool accessKeysActivated; bool accessKeysPreActivate; CompletedState emitCompletedAfterRepaint; QWidget* cursor_icon_widget; // scrolling activated by MMB int m_mouseScroll_byX : 4; int m_mouseScroll_byY : 4; QTimer *m_mouseScrollTimer; QWidget *m_mouseScrollIndicator;};#ifndef QT_NO_TOOLTIP/** calculates the client-side image map rectangle for the given image element * @param img image element * @param scrollOfs scroll offset of viewport in content coordinates * @param p position to be probed in viewport coordinates * @param r returns the bounding rectangle in content coordinates * @param s returns the title string * @return true if an appropriate area was found -- only in this case r and * s are valid, false otherwise */static bool findImageMapRect(HTMLImageElementImpl *img, const QPoint &scrollOfs,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -