1 /* This file is part of the KDE project 2 * 3 * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org> 4 * 1999-2001 Lars Knoll <knoll@kde.org> 5 * 1999-2001 Antti Koivisto <koivisto@kde.org> 6 * 2000-2001 Simon Hausmann <hausmann@kde.org> 7 * 2000-2001 Dirk Mueller <mueller@kde.org> 8 * 2000 Stefan Schimanski <1Stein@gmx.de> 9 * 10 * This library is free software; you can redistribute it and/or 11 * modify it under the terms of the GNU Library General Public 12 * License as published by the Free Software Foundation; either 13 * version 2 of the License, or (at your option) any later version. 14 * 15 * This library is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 * Library General Public License for more details. 19 * 20 * You should have received a copy of the GNU Library General Public License 21 * along with this library; see the file COPYING.LIB. If not, write to 22 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 23 * Boston, MA 02110-1301, USA. 24 */ 25 #ifndef __khtml_part_h__ 26 #define __khtml_part_h__ 27 28 #include "dom/dom_doc.h" 29 #include "dom/dom2_range.h" 30 31 #include <kparts/readonlypart.h> 32 #include <kparts/browserextension.h> 33 #include <kparts/browserhostextension.h> 34 #include <kfind.h> 35 #include <kfinddialog.h> 36 #include <klocalizedstring.h> 37 #include <kencodingdetector.h> 38 #include <kencodingprober.h> 39 #include <QRegExp> 40 #include <QUrl> 41 42 class KHTMLPartPrivate; 43 class KHTMLPartBrowserExtension; 44 class KJSProxy; 45 class KHTMLView; 46 class KHTMLViewBar; 47 class KHTMLFindBar; 48 class KHTMLSettings; 49 class KJavaAppletContext; 50 class KJSErrorDlg; 51 52 namespace DOM 53 { 54 class HTMLDocument; 55 class HTMLDocumentImpl; 56 class DocumentImpl; 57 class Document; 58 class XMLDocumentImpl; 59 class HTMLTitleElementImpl; 60 class HTMLFrameElementImpl; 61 class HTMLIFrameElementImpl; 62 class HTMLObjectElementImpl; 63 class HTMLFormElementImpl; 64 class HTMLAnchorElementImpl; 65 class HTMLMetaElementImpl; 66 class NodeImpl; 67 class ElementImpl; 68 class Node; 69 class HTMLEventListener; 70 class EventListener; 71 class HTMLPartContainerElementImpl; 72 class HTMLObjectBaseElementImpl; 73 class Position; 74 class Selection; 75 class Range; 76 class Editor; 77 } 78 79 namespace WebCore 80 { 81 class SVGDocumentExtensions; 82 } 83 84 namespace KJS 85 { 86 class Interpreter; 87 class HTMLElement; 88 } 89 90 namespace khtml 91 { 92 class DocLoader; 93 class RenderPart; 94 class ChildFrame; 95 class MousePressEvent; 96 class MouseDoubleClickEvent; 97 class MouseMoveEvent; 98 class MouseReleaseEvent; 99 class DrawContentsEvent; 100 class CachedObject; 101 class RenderWidget; 102 class RenderBlock; 103 class CSSStyleSelector; 104 class HTMLTokenizer; 105 class XMLTokenizer; 106 struct EditorContext; 107 class EditCommandImpl; 108 class KHTMLPartAccessor; 109 } 110 111 namespace KJS 112 { 113 class Window; 114 class WindowFunc; 115 class ExternalFunc; 116 class JSEventListener; 117 class JSLazyEventListener; 118 class JSNodeFilter; 119 class DOMDocument; 120 class SourceFile; 121 class ScheduledAction; 122 class DOMSelection; 123 class DOMSelectionProtoFunc; 124 class KHTMLPartScriptable; 125 } 126 127 namespace KParts 128 { 129 class PartManager; 130 class ScriptableExtension; 131 } 132 133 namespace KWallet 134 { 135 class Wallet; 136 } 137 138 /** 139 * This class is khtml's main class. It features an almost complete 140 * web browser, and html renderer. 141 * 142 * The easiest way to use this class (if you just want to display an HTML 143 * page at some URL) is the following: 144 * 145 * \code 146 * QUrl url = "https://www.kde.org"; 147 * KHTMLPart *w = new KHTMLPart(); 148 * w->openUrl(url); 149 * w->view()->resize(500, 400); 150 * w->show(); 151 * \endcode 152 * 153 * Java and JavaScript are enabled by default depending on the user's 154 * settings. If you do not need them, and especially if you display 155 * unfiltered data from untrusted sources, it is strongly recommended to 156 * turn them off. In that case, you should also turn off the automatic 157 * redirect and plugins: 158 * 159 * \code 160 * w->setJScriptEnabled(false); 161 * w->setJavaEnabled(false); 162 * w->setMetaRefreshEnabled(false); 163 * w->setPluginsEnabled(false); 164 * \endcode 165 * 166 * You may also wish to disable external references. This will prevent KHTML 167 * from loading images, frames, etc, or redirecting to external sites. 168 * 169 * \code 170 * w->setOnlyLocalReferences(true); 171 * \endcode 172 * 173 * Some apps want to write their HTML code directly into the widget instead of 174 * opening an url. You can do this in the following way: 175 * 176 * \code 177 * QString myHTMLCode = ...; 178 * KHTMLPart *w = new KHTMLPart(); 179 * w->begin(); 180 * w->write(myHTMLCode); 181 * ... 182 * w->end(); 183 * \endcode 184 * 185 * You can do as many calls to write() as you wish. There are two 186 * write() methods, one accepting a QString and one accepting a 187 * @p char @p * argument. You should use one or the other 188 * (but not both) since the method using 189 * the @p char @p * argument does an additional decoding step to convert the 190 * written data to Unicode. 191 * 192 * It is also possible to write content to the HTML part using the 193 * standard streaming API from KParts::ReadOnlyPart. The usage of 194 * the API is similar to that of the begin(), write(), end() process 195 * described above as the following example shows: 196 * 197 * \code 198 * KHTMLPart *doc = new KHTMLPart(); 199 * doc->openStream( "text/html", QUrl() ); 200 * doc->writeStream( QCString( "<html><body><p>KHTML Rocks!</p></body></html>" ) ); 201 * doc->closeStream(); 202 * \endcode 203 * 204 * @short HTML Browser Widget 205 * @author Lars Knoll (knoll@kde.org) 206 * 207 */ 208 class KHTML_EXPORT KHTMLPart : public KParts::ReadOnlyPart 209 { 210 Q_OBJECT 211 friend class KHTMLView; 212 friend class DOM::HTMLTitleElementImpl; 213 friend class DOM::HTMLFrameElementImpl; 214 friend class DOM::HTMLIFrameElementImpl; 215 friend class DOM::HTMLObjectBaseElementImpl; 216 friend class DOM::HTMLObjectElementImpl; 217 friend class DOM::HTMLAnchorElementImpl; 218 friend class DOM::HTMLMetaElementImpl; 219 friend class DOM::NodeImpl; 220 friend class DOM::ElementImpl; 221 friend class KHTMLRun; 222 friend class DOM::HTMLFormElementImpl; 223 friend class KJS::Window; 224 friend class KJS::ScheduledAction; 225 friend class KJS::JSNodeFilter; 226 friend class KJS::WindowFunc; 227 friend class KJS::ExternalFunc; 228 friend class KJS::JSEventListener; 229 friend class KJS::JSLazyEventListener; 230 friend class KJS::DOMDocument; 231 friend class KJS::HTMLElement; 232 friend class KJS::SourceFile; 233 friend class KJS::DOMSelection; 234 friend class KJS::DOMSelectionProtoFunc; 235 friend class KJS::KHTMLPartScriptable; 236 friend class KJSProxy; 237 friend class KHTMLPartBrowserExtension; 238 friend class DOM::DocumentImpl; 239 friend class DOM::HTMLDocumentImpl; 240 friend class DOM::Selection; 241 friend class DOM::Editor; 242 friend class KHTMLPartBrowserHostExtension; 243 friend class khtml::HTMLTokenizer; 244 friend class khtml::XMLTokenizer; 245 friend class khtml::RenderWidget; 246 friend class khtml::RenderBlock; 247 friend class khtml::CSSStyleSelector; 248 friend class khtml::EditCommandImpl; 249 friend class khtml::KHTMLPartAccessor; 250 friend class KHTMLPartIface; 251 friend class KHTMLPartFunction; 252 friend class KHTMLPopupGUIClient; 253 friend class KHTMLFind; 254 friend class StorePass; 255 friend class WebCore::SVGDocumentExtensions; 256 257 Q_PROPERTY(bool javaScriptEnabled READ jScriptEnabled WRITE setJScriptEnabled) 258 Q_PROPERTY(bool javaEnabled READ javaEnabled WRITE setJavaEnabled) 259 Q_PROPERTY(bool dndEnabled READ dndEnabled WRITE setDNDEnabled) 260 Q_PROPERTY(bool pluginsEnabled READ pluginsEnabled WRITE setPluginsEnabled) 261 Q_PROPERTY(DNSPrefetch dnsPrefetch READ dnsPrefetch WRITE setDNSPrefetch) 262 263 /* 264 * 265 * Don't add setOnlyLocalReferences here. It shouldn't be accessible via DBus. 266 * 267 **/ 268 Q_PROPERTY(bool modified READ isModified) 269 Q_PROPERTY(QString encoding READ encoding WRITE setEncoding) 270 Q_PROPERTY(QString lastModified READ lastModified) 271 Q_PROPERTY(bool metaRefreshEnabled READ metaRefreshEnabled WRITE setMetaRefreshEnabled) 272 273 public: 274 enum GUIProfile { DefaultGUI, BrowserViewGUI /* ... */ }; 275 276 /** 277 * DNS Prefetching Mode enumeration 278 * @li DNSPrefetchDisabled do not prefetch hostnames 279 * @li DNSPrefetchEnabled always prefetch hostnames 280 * @li DNSPrefetchOnlyWWWAndSLD only do DNS prefetching for bare SLD and www sub-domain 281 */ 282 283 enum DNSPrefetch { 284 DNSPrefetchDisabled = 0, 285 DNSPrefetchEnabled, 286 DNSPrefetchOnlyWWWAndSLD 287 }; 288 289 /** 290 * Constructs a new KHTMLPart. 291 * 292 * KHTML basically consists of two objects: The KHTMLPart itself, 293 * holding the document data (DOM document), and the KHTMLView, 294 * derived from QScrollArea, in which the document content is 295 * rendered in. You can specify two different parent objects for a 296 * KHTMLPart, one parent for the KHTMLPart document and one parent 297 * for the KHTMLView. If the second @p parent argument is 0L, then 298 * @p parentWidget is used as parent for both objects, the part and 299 * the view. 300 */ 301 KHTMLPart(QWidget *parentWidget = nullptr, 302 QObject *parent = nullptr, GUIProfile prof = DefaultGUI); 303 /** 304 * Constructs a new KHTMLPart. 305 * 306 * This constructor is useful if you wish to subclass KHTMLView. 307 * If the @p view passed as first argument to the constructor was built with a 308 * null KHTMLPart pointer, then the newly created KHTMLPart will be assigned as the view's part. 309 * 310 * Therefore, you might either initialize the view as part of the initialization list of 311 * your derived KHTMLPart class constructor: 312 * \code 313 * MyKHTMLPart() : KHTMLPart( new MyKHTMLView( this ), ... 314 * \endcode 315 * Or separately build the KHTMLView beforehand: 316 * \code 317 * KHTMLView * v = KHTMLView( 0L, parentWidget()); 318 * KHTMLPart * p = KHTMLPart( v ); // p will be assigned to v, so that v->part() == p 319 * \endcode 320 */ 321 KHTMLPart(KHTMLView *view, QObject *parent = nullptr, GUIProfile prof = DefaultGUI); 322 323 /** 324 * Destructor. 325 */ 326 virtual ~KHTMLPart(); 327 328 /** 329 * Opens the specified URL @p url. 330 * 331 * Reimplemented from KParts::ReadOnlyPart::openUrl . 332 */ 333 bool openUrl(const QUrl &url) override; 334 335 /** 336 * Stops loading the document and kills all data requests (for images, etc.) 337 */ 338 bool closeUrl() override; 339 340 /** 341 * Called when a certain error situation (i.e. connection timed out) occurred. 342 * The default implementation either shows a KIO error dialog or loads a more 343 * verbose error description a as page, depending on the users configuration. 344 * @p job is the job that signaled the error situation 345 */ 346 virtual void showError(KJob *job); 347 348 /** 349 * Returns a reference to the DOM HTML document (for non-HTML documents, returns null) 350 */ 351 DOM::HTMLDocument htmlDocument() const; 352 353 /** 354 * Returns a reference to the DOM document. 355 */ 356 DOM::Document document() const; 357 358 /** 359 * Returns the content of the source document. 360 */ 361 QString documentSource() const; 362 363 /** 364 * Returns the node that has the keyboard focus. 365 */ 366 DOM::Node activeNode() const; 367 368 /** 369 * Returns a pointer to the KParts::BrowserExtension. 370 */ 371 KParts::BrowserExtension *browserExtension() const; 372 KParts::BrowserHostExtension *browserHostExtension() const; 373 374 /** 375 * Returns a pointer to the HTML document's view. 376 */ 377 KHTMLView *view() const; 378 379 /** 380 * Enable/disable Javascript support. Note that this will 381 * in either case permanently override the default usersetting. 382 * If you want to have the default UserSettings, don't call this 383 * method. 384 */ 385 void setJScriptEnabled(bool enable); 386 387 /** 388 * Returns @p true if Javascript support is enabled or @p false 389 * otherwise. 390 */ 391 bool jScriptEnabled() const; 392 393 /** 394 * Returns the JavaScript interpreter the part is using. This method is 395 * mainly intended for applications which embed and extend the part and 396 * provides a mechanism for adding additional native objects to the 397 * interpreter (or removing the built-ins). 398 * 399 * One thing people using this method to add things to the interpreter must 400 * consider, is that when you start writing new content to the part, the 401 * interpreter is cleared. This includes both use of the 402 * begin( const QUrl &, int, int ) method, and the openUrl( const QUrl & ) 403 * method. If you want your objects to have a longer lifespan, then you must 404 * retain a KJS::Object yourself to ensure that the reference count of your 405 * custom objects never reaches 0. You will also need to re-add your 406 * bindings every time this happens - one way to detect the need for this is 407 * to connect to the docCreated() signal, another is to reimplement the 408 * begin() method. 409 */ 410 KJS::Interpreter *jScriptInterpreter(); 411 412 /** 413 * Enable/disable statusbar messages. 414 * When this class wants to set the statusbar text, it emits 415 * setStatusBarText(const QString & text) 416 * If you want to catch this for your own statusbar, note that it returns 417 * back a rich text string, starting with "<qt>". This you need to 418 * either pass this into your own QLabel or to strip out the tags 419 * before passing it to QStatusBar::message(const QString & message) 420 * 421 * @see KParts::Part::setStatusBarText( const QString & text ) 422 */ 423 void setStatusMessagesEnabled(bool enable); 424 425 /** 426 * Returns @p true if status messages are enabled. 427 */ 428 bool statusMessagesEnabled() const; 429 430 /** 431 * Enable/disable automatic forwarding by <meta http-equiv="refresh" ....> 432 */ 433 void setMetaRefreshEnabled(bool enable); 434 435 /** 436 * Returns @p true if automatic forwarding is enabled. 437 */ 438 bool metaRefreshEnabled() const; 439 440 /** 441 * Same as executeScript( const QString & ) except with the Node parameter 442 * specifying the 'this' value. 443 */ 444 QVariant executeScript(const DOM::Node &n, const QString &script); 445 446 /** 447 * Enables or disables Drag'n'Drop support. A drag operation is started if 448 * the users drags a link. 449 */ 450 void setDNDEnabled(bool b); 451 452 /** 453 * Returns whether Dragn'n'Drop support is enabled or not. 454 */ 455 bool dndEnabled() const; 456 457 /** 458 * Enables/disables Java applet support. Note that calling this function 459 * will permanently override the User settings about Java applet support. 460 * Not calling this function is the only way to let the default settings 461 * apply. 462 */ 463 void setJavaEnabled(bool enable); 464 465 /** 466 * Return @p true if Java applet support is enabled, @p false if disabled 467 */ 468 bool javaEnabled() const; 469 470 /** 471 * Enables or disables plugins, default is enabled 472 */ 473 void setPluginsEnabled(bool enable); 474 475 /** 476 * Returns @p true if plugins are enabled, @p false if disabled. 477 */ 478 bool pluginsEnabled() const; 479 480 /** 481 * Specifies whether images contained in the document should be loaded 482 * automatically or not. 483 * 484 * @note Request will be ignored if called before begin(). 485 */ 486 void setAutoloadImages(bool enable); 487 /** 488 * Returns whether images contained in the document are loaded automatically 489 * or not. 490 * @note that the returned information is unrelieable as long as no begin() 491 * was called. 492 */ 493 bool autoloadImages() const; 494 495 /** 496 * Security option. 497 * 498 * Specify whether only file:/ or data:/ urls are allowed to be loaded without 499 * user confirmation by KHTML. 500 * ( for example referenced by stylesheets, images, scripts, subdocuments, embedded elements ). 501 * 502 * This option is mainly intended for enabling the "mail reader mode", where you load untrusted 503 * content with a file:/ url. 504 * 505 * Please note that enabling this option currently automatically disables Javascript, 506 * Java and Plugins support. This might change in the future if the security model 507 * is becoming more sophisticated, so don't rely on this behaviour. 508 * 509 * ( default @p false - everything is loaded unless forbidden by KApplication::authorizeURLAction). 510 */ 511 void setOnlyLocalReferences(bool enable); 512 513 /** 514 * Security option. If this is set to true, content loaded from external URLs 515 * will be permitted to access images on disk regardless of of the Kiosk policy. 516 * You should be careful in enabling this, as it may make it easier to fake 517 * any HTML-based chrome or to perform other such user-confusion attack. 518 * @p false by default. 519 * 520 * @since 4.6 521 */ 522 void setForcePermitLocalImages(bool enable); 523 524 /** 525 * Sets whether DNS Names found in loaded documents'anchors should be pre-fetched (pre-resolved). 526 * Note that calling this function will permanently override the User settings about 527 * DNS prefetch support. 528 * Not calling this function is the only way to let the default settings apply. 529 * 530 * @note This setting has no effect if @ref setOnlyLocalReferences() mode is enabled. 531 * 532 * @param pmode the mode to set. See @ref DNSPrefetch enum for explanation of values. 533 * 534 * @since 4.2 535 */ 536 void setDNSPrefetch(DNSPrefetch pmode); 537 538 /** 539 * Returns currently set DNS prefetching mode. 540 * See @p DNSPrefetch enum for explanation of values. 541 * 542 * @note Always returns @p DNSPrefetchDisabled if @ref setOnlyLocalReferences() mode is enabled. 543 * 544 * @since 4.2 545 */ 546 DNSPrefetch dnsPrefetch() const; 547 548 /** 549 * Returns whether only file:/ or data:/ references are allowed 550 * to be loaded ( default @p false ). See setOnlyLocalReferences. 551 **/ 552 bool onlyLocalReferences() const; 553 554 /** 555 * If true, local image files will be loaded even when forbidden by the 556 * Kiosk/KAuthorized policies ( default @p false ). See @ref setForcePermitLocalImages. 557 * 558 * @since 4.6 559 **/ 560 bool forcePermitLocalImages() const; 561 562 /** Returns whether caret mode is on/off. 563 */ 564 bool isCaretMode() const; 565 566 /** 567 * Returns @p true if the document is editable, @p false otherwise. 568 */ 569 bool isEditable() const; 570 571 /** 572 * Sets the caret to the given position. 573 * 574 * If the given location is invalid, it will snap to the nearest valid 575 * location. Immediately afterwards a @p caretPositionChanged signal 576 * containing the effective position is emitted 577 * @param node node to set to 578 * @param offset zero-based offset within the node 579 * @param extendSelection If @p true, a selection will be spanned from the 580 * last caret position to the given one. Otherwise, any existing selection 581 * will be deselected. 582 */ 583 void setCaretPosition(DOM::Node node, long offset, bool extendSelection = false); 584 585 /** 586 * Enumeration for displaying the caret. 587 */ 588 enum CaretDisplayPolicy { 589 CaretVisible, /**< caret is displayed */ 590 CaretInvisible, /**< caret is not displayed */ 591 CaretBlink /**< caret toggles between visible and invisible */ 592 }; 593 594 /** 595 * Returns the current caret policy when the view is not focused. 596 */ 597 CaretDisplayPolicy caretDisplayPolicyNonFocused() const; 598 599 /** 600 * Sets the caret display policy when the view is not focused. 601 * 602 * Whenever the caret is in use, this property determines how the 603 * caret should be displayed when the document view is not focused. 604 * 605 * The default policy is CaretInvisible. 606 * @param policy new display policy 607 */ 608 void setCaretDisplayPolicyNonFocused(CaretDisplayPolicy policy); 609 610 #ifndef KDE_NO_COMPAT 611 QUrl baseURL() const; 612 #endif 613 614 /** 615 * Returns the URL for the background Image (used by save background) 616 */ 617 QUrl backgroundURL() const; 618 619 /** 620 * Schedules a redirection after @p delay seconds. 621 */ 622 void scheduleRedirection(int delay, const QString &url, bool lockHistory = true); 623 624 /** 625 * Clears the widget and prepares it for new content. 626 * 627 * If you want url() to return 628 * for example "file:/tmp/test.html", you can use the following code: 629 * \code 630 * view->begin( QUrl("file:/tmp/test.html" ) ); 631 * \endcode 632 * 633 * @param url is the url of the document to be displayed. Even if you 634 * are generating the HTML on the fly, it may be useful to specify 635 * a directory so that any pixmaps are found. 636 * 637 * @param xOffset is the initial horizontal scrollbar value. Usually 638 * you don't want to use this. 639 * 640 * @param yOffset is the initial vertical scrollbar value. Usually 641 * you don't want to use this. 642 * 643 * All child frames and the old document are removed if you call 644 * this method. 645 */ 646 virtual void begin(const QUrl &url = QUrl(), int xOffset = 0, int yOffset = 0); 647 648 /** 649 * Writes another part of the HTML code to the widget. 650 * 651 * You may call 652 * this function many times in sequence. But remember: The fewer calls 653 * you make, the faster the widget will be. 654 * 655 * The HTML code is send through a decoder which decodes the stream to 656 * Unicode. 657 * 658 * The @p len parameter is needed for streams encoded in utf-16, 659 * since these can have \\0 chars in them. In case the encoding 660 * you're using isn't utf-16, you can safely leave out the length 661 * parameter. 662 * 663 * Attention: Don't mix calls to write( const char *) with calls 664 * to write( const QString & ). 665 * 666 * The result might not be what you want. 667 */ 668 virtual void write(const char *str, int len = -1); 669 670 /** 671 * Writes another part of the HTML code to the widget. 672 * 673 * You may call 674 * this function many times in sequence. But remember: The fewer calls 675 * you make, the faster the widget will be. 676 * 677 * For historic and backward compatibility reasons, this method will force 678 * the use of strict mode for the document, unless setAlwaysHonourDoctype() 679 * has been called previously. 680 */ 681 // FIXME KDE5: always honour doctype, remove setAlwaysHonourDoctype() 682 virtual void write(const QString &str); 683 684 /** 685 * Call this after your last call to write(). 686 */ 687 virtual void end(); 688 689 /* 690 * Prints the current HTML page laid out for the printer. 691 * 692 * (not implemented at the moment) 693 */ 694 // void print(QPainter *, int pageHeight, int pageWidth); 695 696 /** 697 * Paints the HTML page to a QPainter. See KHTMLView::paint for details 698 */ 699 void paint(QPainter *, const QRect &, int = 0, bool * = nullptr); 700 701 /** 702 * Sets the encoding the page uses. 703 * 704 * This can be different from the charset. The widget will try to reload the current page in the new 705 * encoding, if url() is not empty. 706 */ 707 bool setEncoding(const QString &name, bool override = false); 708 709 /** 710 * Returns the encoding the page currently uses. 711 * 712 * Note that the encoding might be different from the charset. 713 */ 714 QString encoding() const; 715 716 /** 717 * Sets a user defined style sheet to be used on top of the HTML 4 718 * default style sheet. 719 * 720 * This gives a wide range of possibilities to 721 * change the layout of the page. 722 * 723 * To have an effect this function has to be called after calling begin(). 724 */ 725 void setUserStyleSheet(const QUrl &url); 726 727 /** 728 * Sets a user defined style sheet to be used on top of the HTML 4 729 * default style sheet. 730 * 731 * This gives a wide range of possibilities to 732 * change the layout of the page. 733 * 734 * To have an effect this function has to be called after calling begin(). 735 */ 736 void setUserStyleSheet(const QString &styleSheet); 737 738 public: 739 740 /** 741 * Sets the standard font style. 742 * 743 * @param name The font name to use for standard text. 744 */ 745 void setStandardFont(const QString &name); 746 747 /** 748 * Sets the fixed font style. 749 * 750 * @param name The font name to use for fixed text, e.g. 751 * the <tt><pre></tt> tag. 752 */ 753 void setFixedFont(const QString &name); 754 755 /** 756 * Finds the anchor named @p name. 757 * 758 * If the anchor is found, the widget 759 * scrolls to the closest position. Returns @p if the anchor has 760 * been found. 761 */ 762 bool gotoAnchor(const QString &name); 763 764 /** 765 * Go to the next anchor 766 * 767 * This is useful to navigate from outside the navigator 768 */ 769 bool nextAnchor(); 770 771 /** 772 * Go to previous anchor 773 */ 774 bool prevAnchor(); 775 776 /** 777 * Sets the cursor to use when the cursor is on a link. 778 */ 779 void setURLCursor(const QCursor &c); 780 781 /** 782 * Returns the cursor which is used when the cursor is on a link. 783 */ 784 QCursor urlCursor() const; 785 786 /** 787 * Extra Find options that can be used when calling the extended findText(). 788 */ 789 enum FindOptions { 790 FindLinksOnly = 1 * KFind::MinimumUserOption, 791 FindNoPopups = 2 * KFind::MinimumUserOption 792 //FindIncremental = 4 * KFind::MinimumUserOption 793 }; 794 795 /** 796 * Starts a new search by popping up a dialog asking the user what he wants to 797 * search for. 798 */ 799 void findText(); 800 801 /** 802 * Starts a new search, but bypasses the user dialog. 803 * @param str The string to search for. 804 * @param options Find options. 805 * @param parent Parent used for centering popups like "string not found". 806 * @param findDialog Optionally, you can supply your own dialog. 807 */ 808 void findText(const QString &str, long options, QWidget *parent = nullptr, 809 KFindDialog *findDialog = nullptr); 810 811 /** 812 * Initiates a text search. 813 */ 814 void findTextBegin(); 815 816 /** 817 * Finds the next occurrence of a string set by @ref findText() 818 * @param reverse if @p true, revert seach direction (only if no find dialog is used) 819 * @return @p true if a new match was found. 820 */ 821 bool findTextNext(bool reverse = false); 822 823 /** 824 * Sets the Zoom factor. The value is given in percent, larger values mean a 825 * generally larger font and larger page contents. 826 * 827 * The given value should be in the range of 20..300, values outside that 828 * range are not guaranteed to work. A value of 100 will disable all zooming 829 * and show the page with the sizes determined via the given lengths in the 830 * stylesheets. 831 */ 832 void setZoomFactor(int percent); 833 834 /** 835 * Returns the current zoom factor. 836 */ 837 int zoomFactor() const; 838 839 /** 840 * Sets the scale factor to be applied to fonts. The value is given in percent, 841 * larger values mean generally larger fonts. 842 * 843 * The given value should be in the range of 20..300, values outside that 844 * range are not guaranteed to work. A value of 100 will disable all scaling of font sizes 845 * and show the page with the sizes determined via the given lengths in the 846 * stylesheets. 847 */ 848 void setFontScaleFactor(int percent); 849 850 /** 851 * Returns the current font scale factor. 852 */ 853 int fontScaleFactor() const; 854 855 /** 856 * Returns the text the user has marked. 857 */ 858 virtual QString selectedText() const; 859 860 /** 861 * Return the text the user has marked. This is guaranteed to be valid xml, 862 * and to contain the \<html> and \<body> tags. 863 * 864 * FIXME probably should make virtual for 4.0 ? 865 */ 866 QString selectedTextAsHTML() const; 867 868 /** 869 * Returns the selected part of the HTML. 870 */ 871 DOM::Range selection() const; 872 873 /** 874 * Returns the selected part of the HTML by returning the starting and end 875 * position. 876 * 877 * If there is no selection, both nodes and offsets are equal. 878 * @param startNode returns node selection starts in 879 * @param startOffset returns offset within starting node 880 * @param endNode returns node selection ends in 881 * @param endOffset returns offset within end node. 882 */ 883 void selection(DOM::Node &startNode, long &startOffset, 884 DOM::Node &endNode, long &endOffset) const; 885 886 /** 887 * Sets the current selection. 888 */ 889 void setSelection(const DOM::Range &); 890 891 /** 892 * Has the user selected anything? 893 * 894 * Call selectedText() to 895 * retrieve the selected text. 896 * 897 * @return @p true if there is text selected. 898 */ 899 bool hasSelection() const; 900 901 /** 902 * Returns the instance of the attached html editor interface. 903 * 904 */ 905 DOM::Editor *editor() const; 906 907 /** 908 * Marks all text in the document as selected. 909 */ 910 void selectAll(); 911 912 /** 913 * Convenience method to show the document's view. 914 * 915 * Equivalent to widget()->show() or view()->show() . 916 */ 917 void show(); 918 919 /** 920 * Convenience method to hide the document's view. 921 * 922 * Equivalent to widget()->hide() or view()->hide(). 923 */ 924 void hide(); 925 926 /** 927 * Returns a reference to the partmanager instance which 928 * manages html frame objects. 929 */ 930 KParts::PartManager *partManager(); 931 932 /** 933 * Saves the KHTMLPart's complete state (including child frame 934 * objects) to the provided QDataStream. 935 * 936 * This is called from the saveState() method of the 937 * browserExtension(). 938 */ 939 virtual void saveState(QDataStream &stream); 940 /** 941 * Restores the KHTMLPart's previously saved state (including 942 * child frame objects) from the provided QDataStream. 943 * 944 * @see saveState() 945 * 946 * This is called from the restoreState() method of the 947 * browserExtension() . 948 **/ 949 virtual void restoreState(QDataStream &stream); 950 951 /** 952 * Returns the @p Node currently under the mouse. 953 * 954 * The returned node may be a shared node (e. g. an \<area> node if the 955 * mouse is hovering over an image map). 956 */ 957 DOM::Node nodeUnderMouse() const; 958 959 /** 960 * Returns the @p Node currently under the mouse that is not shared. 961 * 962 * The returned node is always the node that is physically under the mouse 963 * pointer (irrespective of logically overlying elements like, e. g., 964 * \<area> on image maps). 965 */ 966 DOM::Node nonSharedNodeUnderMouse() const; 967 968 /** 969 * @internal 970 */ 971 const KHTMLSettings *settings() const; 972 973 /** 974 * Returns a pointer to the parent KHTMLPart if the part is a frame 975 * in an HTML frameset. 976 * 977 * Returns 0L otherwise. 978 */ 979 // ### KDE5 make const 980 KHTMLPart *parentPart(); 981 982 /** 983 * Returns a list of names of all frame (including iframe) objects of 984 * the current document. Note that this method is not working recursively 985 * for sub-frames. 986 */ 987 QStringList frameNames() const; 988 989 QList<KParts::ReadOnlyPart *> frames() const; 990 991 /** 992 * Finds a frame by name. Returns 0L if frame can't be found. 993 */ 994 KHTMLPart *findFrame(const QString &f); 995 996 /** 997 * Recursively finds the part containing the frame with name @p f 998 * and checks if it is accessible by @p callingPart 999 * Returns 0L if no suitable frame can't be found. 1000 * Returns parent part if a suitable frame was found and 1001 * frame info in @p *childFrame 1002 */ 1003 KHTMLPart *findFrameParent(KParts::ReadOnlyPart *callingPart, const QString &f, khtml::ChildFrame **childFrame = nullptr); 1004 1005 /** 1006 * Return the current frame (the one that has focus) 1007 * Not necessarily a direct child of ours, framesets can be nested. 1008 * Returns "this" if this part isn't a frameset. 1009 */ 1010 KParts::ReadOnlyPart *currentFrame() const; 1011 1012 /** 1013 * Returns whether a frame with the specified name is exists or not. 1014 * In contrast to the findFrame method this one also returns @p true 1015 * if the frame is defined but no displaying component has been 1016 * found/loaded, yet. 1017 */ 1018 bool frameExists(const QString &frameName); 1019 1020 /** 1021 * Returns child frame framePart its script interpreter 1022 */ 1023 KJSProxy *framejScript(KParts::ReadOnlyPart *framePart); 1024 1025 /** 1026 * Finds a frame by name. Returns 0L if frame can't be found. 1027 */ 1028 KParts::ReadOnlyPart *findFramePart(const QString &f); 1029 /** 1030 * Called by KJS. 1031 * Sets the StatusBarText assigned 1032 * via window.status 1033 */ 1034 void setJSStatusBarText(const QString &text); 1035 1036 /** 1037 * Called by KJS. 1038 * Sets the DefaultStatusBarText assigned 1039 * via window.defaultStatus 1040 */ 1041 void setJSDefaultStatusBarText(const QString &text); 1042 1043 /** 1044 * Called by KJS. 1045 * Returns the StatusBarText assigned 1046 * via window.status 1047 */ 1048 QString jsStatusBarText() const; 1049 1050 /** 1051 * Called by KJS. 1052 * Returns the DefaultStatusBarText assigned 1053 * via window.defaultStatus 1054 */ 1055 QString jsDefaultStatusBarText() const; 1056 1057 /** 1058 * Referrer used for links in this page. 1059 */ 1060 QString referrer() const; 1061 1062 /** 1063 * Referrer used to obtain this page. 1064 */ 1065 QString pageReferrer() const; 1066 1067 /** 1068 * Last-modified date (in raw string format), if received in the [HTTP] headers. 1069 */ 1070 QString lastModified() const; 1071 1072 /** 1073 * Loads a style sheet into the stylesheet cache. 1074 */ 1075 void preloadStyleSheet(const QString &url, const QString &stylesheet); 1076 1077 /** 1078 * Loads a script into the script cache. 1079 */ 1080 void preloadScript(const QString &url, const QString &script); 1081 1082 /** 1083 * Returns whether the given point is inside the current selection. 1084 * 1085 * The coordinates are content-coordinates. 1086 */ 1087 bool isPointInsideSelection(int x, int y); 1088 1089 /** 1090 * @internal 1091 */ 1092 bool restored() const; 1093 1094 /** 1095 * Sets whether the document's Doctype should always be used 1096 * to determine the parsing mode for the document. 1097 * 1098 * Without this, parsing will be forced to 1099 * strict mode when using the write( const QString &str ) 1100 * method for backward compatibility reasons. 1101 * 1102 */ 1103 // ### KDE5 remove - fix write( const QString &str ) instead 1104 void setAlwaysHonourDoctype(bool b = true); 1105 1106 // ### KDE5 remove me 1107 enum FormNotification { NoNotification = 0, Before, Only, Unused = 255 }; 1108 /** 1109 * Determine if signal should be emitted before, instead or never when a 1110 * submitForm() happens. 1111 * ### KDE5 remove me 1112 */ 1113 void setFormNotification(FormNotification fn); 1114 1115 /** 1116 * Determine if signal should be emitted before, instead or never when a 1117 * submitForm() happens. 1118 * ### KDE5 remove me 1119 */ 1120 FormNotification formNotification() const; 1121 1122 /** 1123 * Returns the toplevel (origin) URL of this document, even if this 1124 * part is a frame or an iframe. 1125 * 1126 * @return the actual original url. 1127 */ 1128 QUrl toplevelURL(); 1129 1130 /** 1131 * Checks whether the page contains unsubmitted form changes. 1132 * 1133 * @return @p true if form changes exist 1134 */ 1135 bool isModified() const; 1136 1137 /** 1138 * Shows or hides the suppressed popup indicator 1139 */ 1140 void setSuppressedPopupIndicator(bool enable, KHTMLPart *originPart = nullptr); 1141 1142 /** 1143 * @internal 1144 */ 1145 bool inProgress() const; 1146 1147 Q_SIGNALS: 1148 /** 1149 * Emitted if the cursor is moved over an URL. 1150 */ 1151 void onURL(const QString &url); 1152 1153 /** 1154 * Emitted when the user clicks the right mouse button on the document. 1155 * See KParts::BrowserExtension for two more popupMenu signals emitted by khtml, 1156 * with much more information in the signal. 1157 */ 1158 void popupMenu(const QString &url, const QPoint &point); 1159 1160 /** 1161 * This signal is emitted when the selection changes. 1162 */ 1163 void selectionChanged(); 1164 1165 /** 1166 * This signal is emitted when an element retrieves the 1167 * keyboard focus. Note that the signal argument can be 1168 * a null node if no element is active, meaning a node 1169 * has explicitly been deactivated without a new one 1170 * becoming active. 1171 */ 1172 void nodeActivated(const DOM::Node &); 1173 1174 /** 1175 * @internal */ 1176 void docCreated(); 1177 1178 /** 1179 * This signal is emitted whenever the caret position has been changed. 1180 * 1181 * The signal transmits the position the DOM::Range way, the node and 1182 * the zero-based offset within this node. 1183 * @param node node which the caret is in. This can be null if the caret 1184 * has been deactivated. 1185 * @param offset offset within the node. If the node is null, the offset 1186 * is meaningless. 1187 */ 1188 void caretPositionChanged(const DOM::Node &node, long offset); 1189 1190 /** 1191 * If form notification is on, this will be emitted either for a form 1192 * submit or before the form submit according to the setting. 1193 */ 1194 // TODO: remove/deprecate? 1195 void formSubmitNotification(const char *action, const QString &url, 1196 const QByteArray &formData, const QString &target, 1197 const QString &contentType, const QString &boundary); 1198 1199 /** 1200 * Emitted whenever the configuration has changed 1201 */ 1202 void configurationChanged(); 1203 1204 protected: 1205 1206 /** 1207 * returns a QUrl object for the given url. Use when 1208 * you know what you're doing. 1209 */ 1210 QUrl completeURL(const QString &url); 1211 1212 /** 1213 * presents a detailed error message to the user. 1214 * @p errorCode kio error code, eg KIO::ERR_SERVER_TIMEOUT. 1215 * @p text kio additional information text. 1216 * @p url the url that triggered the error. 1217 */ 1218 void htmlError(int errorCode, const QString &text, const QUrl &reqUrl); 1219 1220 void customEvent(QEvent *event) override; 1221 1222 /** 1223 * Eventhandler of the khtml::MousePressEvent. 1224 */ 1225 virtual void khtmlMousePressEvent(khtml::MousePressEvent *event); 1226 /** 1227 * Eventhandler for the khtml::MouseDoubleClickEvent. 1228 */ 1229 virtual void khtmlMouseDoubleClickEvent(khtml::MouseDoubleClickEvent *); 1230 /** 1231 * Eventhandler for the khtml::MouseMouseMoveEvent. 1232 */ 1233 virtual void khtmlMouseMoveEvent(khtml::MouseMoveEvent *event); 1234 /** 1235 * Eventhandler for the khtml::MouseMouseReleaseEvent. 1236 */ 1237 virtual void khtmlMouseReleaseEvent(khtml::MouseReleaseEvent *event); 1238 /** 1239 * Eventhandler for the khtml::DrawContentsEvent. 1240 */ 1241 virtual void khtmlDrawContentsEvent(khtml::DrawContentsEvent *); 1242 1243 /** 1244 * Internal reimplementation of KParts::Part::guiActivateEvent . 1245 */ 1246 void guiActivateEvent(KParts::GUIActivateEvent *event) override; 1247 1248 /** 1249 * Internal empty reimplementation of KParts::ReadOnlyPart::openFile . 1250 */ 1251 bool openFile() override; 1252 1253 virtual bool urlSelected(const QString &url, int button, int state, 1254 const QString &_target, 1255 const KParts::OpenUrlArguments &args = KParts::OpenUrlArguments(), 1256 const KParts::BrowserArguments &browserArgs = KParts::BrowserArguments()); 1257 1258 /** 1259 * This method is called when a new embedded object (include html frames) is to be created. 1260 * Reimplement it if you want to add support for certain embeddable objects without registering 1261 * them in the KDE wide registry system (KSyCoCa) . Another reason for re-implementing this 1262 * method could be if you want to derive from KTHMLPart and also want all html frame objects 1263 * to be a object of your derived type, in which case you should return a new instance for 1264 * the mimetype 'text/html' . 1265 */ 1266 virtual KParts::ReadOnlyPart *createPart(QWidget *parentWidget, 1267 QObject *parent, 1268 const QString &mimetype, QString &serviceName, 1269 QStringList &serviceTypes, const QStringList ¶ms); 1270 1271 // This is for RenderPartObject. We want to ask the 'download plugin?' 1272 // question only once per mimetype 1273 bool pluginPageQuestionAsked(const QString &mimetype) const; 1274 void setPluginPageQuestionAsked(const QString &mimetype); 1275 1276 enum PageSecurity { NotCrypted, Encrypted, Mixed }; 1277 void setPageSecurity(PageSecurity sec); 1278 1279 /** 1280 * Implements the streaming API of KParts::ReadOnlyPart. 1281 */ 1282 bool doOpenStream(const QString &mimeType) override; 1283 1284 /** 1285 * Implements the streaming API of KParts::ReadOnlyPart. 1286 */ 1287 bool doWriteStream(const QByteArray &data) override; 1288 1289 /** 1290 * Implements the streaming API of KParts::ReadOnlyPart. 1291 */ 1292 bool doCloseStream() override; 1293 1294 /** 1295 * @internal 1296 */ 1297 void timerEvent(QTimerEvent *) override; 1298 1299 /** 1300 * Will pre-resolve @p name according to dnsPrefetch current settings 1301 * Returns @p true if the name will be pre-resolved. 1302 * Otherwise returns false. 1303 */ 1304 1305 bool mayPrefetchHostname(const QString &name); 1306 1307 /** 1308 * @internal 1309 */ 1310 void updateZoomFactor(); 1311 1312 public Q_SLOTS: 1313 1314 /** 1315 * Sets the focused node of the document to the specified node. If the node is a form control, the control will 1316 * receive focus in the same way that it would if the user had clicked on it or tabbed to it with the keyboard. For 1317 * most other types of elements, there is no visual indication of whether or not they are focused. 1318 * 1319 * See activeNode 1320 * 1321 * @param node The node to focus 1322 */ 1323 void setActiveNode(const DOM::Node &node); 1324 1325 /** 1326 * Stops all animated images on the current and child pages 1327 */ 1328 void stopAnimations(); 1329 1330 /** 1331 * Execute the specified snippet of JavaScript code. 1332 * 1333 * Returns @p true if JavaScript was enabled, no error occurred 1334 * and the code returned @p true itself or @p false otherwise. 1335 * @deprecated, use executeString( DOM::Node(), script) 1336 */ 1337 QVariant executeScript(const QString &script); 1338 1339 /** 1340 * Enables/disables caret mode. 1341 * 1342 * Enabling caret mode displays a caret which can be used to navigate 1343 * the document using the keyboard only. Caret mode is switched off by 1344 * default. 1345 * 1346 * @param enable @p true to enable, @p false to disable caret mode. 1347 */ 1348 void setCaretMode(bool enable); 1349 1350 /** 1351 * Makes the document editable. 1352 * 1353 * Setting this property to @p true makes the document, and its 1354 * subdocuments (such as frames, iframes, objects) editable as a whole. 1355 * FIXME: insert more information about navigation, features etc. as seen fit 1356 * 1357 * @param enable @p true to set document editable, @p false to set it 1358 * read-only. 1359 */ 1360 void setEditable(bool enable); 1361 1362 /** 1363 * Sets the visibility of the caret. 1364 * 1365 * This methods displays or hides the caret regardless of the current 1366 * caret display policy (see setCaretDisplayNonFocused), and regardless 1367 * of focus. 1368 * 1369 * The caret will be shown/hidden only under at least one of 1370 * the following conditions: 1371 * @li the document is editable 1372 * @li the document is in caret mode 1373 * @li the document's currently focused element is editable 1374 * 1375 * @param show @p true to make visible, @p false to hide. 1376 */ 1377 void setCaretVisible(bool show); 1378 1379 // ### FIXME: 1380 // Remove this and make the one below protected+virtual slot. 1381 // Warning: this is effectively "internal". Be careful. 1382 void submitFormProxy(const char *action, const QString &url, 1383 const QByteArray &formData, 1384 const QString &target, 1385 const QString &contentType = QString(), 1386 const QString &boundary = QString()); 1387 1388 protected Q_SLOTS: 1389 1390 /** 1391 * Called when the job downloading the page is finished. 1392 * Can be reimplemented, for instance to get metadata out of the job, 1393 * but make sure to call KHTMLPart::slotFinished() too. 1394 */ 1395 virtual void slotFinished(KJob *); 1396 1397 protected: 1398 /** 1399 * Hook for adding code before a job is started. 1400 * This can be used to add metadata, like job->addMetaData("PropagateHttpHeader", "true") 1401 * to get the HTTP headers. 1402 */ startingJob(KIO::Job *)1403 virtual void startingJob(KIO::Job *) {} 1404 1405 private Q_SLOTS: 1406 1407 /** 1408 * @internal 1409 */ 1410 void reparseConfiguration(); 1411 1412 /** 1413 * @internal 1414 */ 1415 void slotData(KIO::Job *, const QByteArray &data); 1416 /** 1417 * @internal 1418 */ 1419 void slotInfoMessage(KJob *, const QString &msg); 1420 /** 1421 * @internal 1422 */ 1423 void slotRestoreData(const QByteArray &data); 1424 /** 1425 * @internal 1426 */ 1427 void slotFinishedParsing(); 1428 /** 1429 * @internal 1430 */ 1431 void slotRedirect(); 1432 /** 1433 * @internal 1434 */ 1435 void slotRedirection(KIO::Job *, const QUrl &); 1436 /** 1437 * @internal 1438 */ 1439 void slotDebugScript(); 1440 /** 1441 * @internal 1442 */ 1443 void slotDebugDOMTree(); 1444 /** 1445 * @internal 1446 */ 1447 void slotDebugRenderTree(); 1448 1449 void slotDebugFrameTree(); 1450 1451 /** 1452 * @internal 1453 */ 1454 void slotStopAnimations(); 1455 /** 1456 * @internal 1457 */ 1458 virtual void slotViewDocumentSource(); 1459 /** 1460 * @internal 1461 */ 1462 virtual void slotViewFrameSource(); 1463 /** 1464 * @internal 1465 */ 1466 void slotViewPageInfo(); 1467 /** 1468 * @internal 1469 */ 1470 virtual void slotSaveBackground(); 1471 /** 1472 * @internal 1473 */ 1474 virtual void slotSaveDocument(); 1475 /** 1476 * @internal 1477 */ 1478 virtual void slotSaveFrame(); 1479 /** 1480 * @internal 1481 */ 1482 virtual void slotSecurity(); 1483 /** 1484 * @internal 1485 */ 1486 virtual void slotSetEncoding(const QString &); 1487 1488 /** 1489 * @internal 1490 */ 1491 virtual void slotUseStylesheet(); 1492 1493 virtual void slotFind(); 1494 virtual void slotFindDone(); // ### remove me 1495 virtual void slotFindDialogDestroyed(); // ### remove me 1496 void slotFindNext(); 1497 void slotFindPrev(); 1498 void slotFindAheadText(); 1499 void slotFindAheadLink(); 1500 1501 void slotIncZoom(); 1502 void slotDecZoom(); 1503 void slotIncZoomFast(); 1504 void slotDecZoomFast(); 1505 1506 void slotIncFontSize(); 1507 void slotDecFontSize(); 1508 void slotIncFontSizeFast(); 1509 void slotDecFontSizeFast(); 1510 1511 void slotLoadImages(); 1512 void slotWalletClosed(); 1513 void launchWalletManager(); 1514 void walletMenu(); 1515 void delNonPasswordStorableSite(); 1516 void removeStoredPasswordForm(QAction *action); 1517 void addWalletFormKey(const QString &walletFormKey); 1518 1519 /** 1520 * @internal 1521 */ 1522 void submitFormAgain(); 1523 1524 /** 1525 * @internal 1526 */ 1527 void updateActions(); 1528 /** 1529 * @internal 1530 */ 1531 void slotPartRemoved(KParts::Part *part); 1532 /** 1533 * @internal 1534 */ 1535 void slotActiveFrameChanged(KParts::Part *part); 1536 /** 1537 * @internal 1538 */ 1539 void slotChildStarted(KIO::Job *job); 1540 /** 1541 * @internal 1542 */ 1543 void slotChildCompleted(); 1544 /** 1545 * @internal 1546 */ 1547 void slotChildCompleted(bool); 1548 /** 1549 * @internal 1550 */ 1551 void slotParentCompleted(); 1552 /** 1553 * @internal 1554 */ 1555 void slotChildURLRequest(const QUrl &url, const KParts::OpenUrlArguments &, const KParts::BrowserArguments &args); 1556 /** 1557 * @internal 1558 */ 1559 void slotChildDocCreated(); 1560 /** 1561 * @internal 1562 */ 1563 void slotRequestFocus(KParts::ReadOnlyPart *); 1564 void slotLoaderRequestStarted(khtml::DocLoader *, khtml::CachedObject *obj); 1565 void slotLoaderRequestDone(khtml::DocLoader *, khtml::CachedObject *obj); 1566 void checkCompleted(); 1567 1568 /** 1569 * @internal 1570 */ 1571 void slotAutoScroll(); 1572 1573 void slotPrintFrame(); 1574 1575 void slotSelectAll(); 1576 1577 /** 1578 * @internal 1579 */ 1580 void slotProgressUpdate(); 1581 1582 /* 1583 * @internal 1584 */ 1585 void slotJobPercent(KJob *, unsigned long); 1586 1587 /* 1588 * @internal 1589 */ 1590 void slotJobDone(KJob *); 1591 1592 /* 1593 * @internal 1594 */ 1595 void slotUserSheetStatDone(KJob *); 1596 1597 /* 1598 * @internal 1599 */ 1600 void slotJobSpeed(KJob *, unsigned long); 1601 1602 /** 1603 * @internal 1604 */ 1605 void slotClearSelection(); 1606 1607 /** 1608 * @internal 1609 */ 1610 void slotZoomView(int); 1611 1612 /** 1613 * @internal 1614 */ 1615 void slotAutomaticDetectionLanguage(KEncodingProber::ProberType scri); 1616 1617 /** 1618 * @internal 1619 */ 1620 void slotToggleCaretMode(); 1621 1622 /** 1623 * @internal 1624 */ 1625 void suppressedPopupMenu(); 1626 1627 /** 1628 * @internal 1629 */ 1630 void togglePopupPassivePopup(); 1631 1632 /** 1633 * @internal 1634 */ 1635 void showSuppressedPopups(); 1636 1637 /** 1638 * @internal 1639 */ 1640 void launchJSConfigDialog(); 1641 1642 /** 1643 * @internal 1644 */ 1645 void launchJSErrorDialog(); 1646 1647 /** 1648 * @internal 1649 */ 1650 void removeJSErrorExtension(); 1651 1652 /** 1653 * @internal 1654 */ 1655 void disableJSErrorExtension(); 1656 1657 /** 1658 * @internal 1659 */ 1660 void jsErrorDialogContextMenu(); 1661 1662 /** 1663 * @internal 1664 * used to restore or reset the view's scroll position (including positioning on anchors) 1665 * once a sufficient portion of the document as been laid out. 1666 */ 1667 void restoreScrollPosition(); 1668 1669 void walletOpened(KWallet::Wallet *); 1670 1671 private: 1672 1673 KJSErrorDlg *jsErrorExtension(); 1674 1675 enum StatusBarPriority { BarDefaultText, BarHoverText, BarOverrideText }; 1676 void setStatusBarText(const QString &text, StatusBarPriority p); 1677 1678 bool restoreURL(const QUrl &url); 1679 void clearCaretRectIfNeeded(); 1680 void setFocusNodeIfNeeded(const DOM::Selection &); 1681 void selectionLayoutChanged(); 1682 void notifySelectionChanged(bool closeTyping = true); 1683 void resetFromScript(); 1684 void emitSelectionChanged(); 1685 void onFirstData(); 1686 // Returns whether callingHtmlPart may access this part 1687 bool checkFrameAccess(KHTMLPart *callingHtmlPart); 1688 bool openUrlInFrame(const QUrl &url, const KParts::OpenUrlArguments &arguments, const KParts::BrowserArguments &browserArguments); 1689 void startAutoScroll(); 1690 void stopAutoScroll(); 1691 void overURL(const QString &url, const QString &target, bool shiftPressed = false); 1692 void resetHoverText(); // Undo overURL and reset HoverText 1693 1694 KParts::ScriptableExtension *scriptableExtension(const DOM::NodeImpl *); 1695 1696 KWallet::Wallet *wallet(); 1697 1698 void openWallet(DOM::HTMLFormElementImpl *); 1699 void saveToWallet(const QString &key, const QMap<QString, QString> &data); 1700 void dequeueWallet(DOM::HTMLFormElementImpl *); 1701 void saveLoginInformation(const QString &host, const QString &key, const QMap<QString, QString> &walletMap); 1702 1703 void enableFindAheadActions(bool); 1704 1705 /** 1706 * Returns a pointer to the top view bar. 1707 */ 1708 KHTMLViewBar *pTopViewBar() const; 1709 1710 /** 1711 * Returns a pointer to the bottom view bar. 1712 */ 1713 KHTMLViewBar *pBottomViewBar() const; 1714 1715 /** 1716 * @internal 1717 */ 1718 bool pFindTextNextInThisFrame(bool reverse); 1719 1720 /** 1721 * @internal 1722 */ 1723 // ### FIXME: 1724 // It is desirable to be able to filter form submissions as well. 1725 // For instance, forms can have a target and an inheriting class 1726 // might want to filter based on the target. Make this protected 1727 // and virtual, or provide a better solution. 1728 // See the web_module for the sidebar for an example where this is 1729 // necessary. 1730 void submitForm(const char *action, const QString &url, const QByteArray &formData, 1731 const QString &target, const QString &contentType = QString(), 1732 const QString &boundary = QString()); 1733 1734 void popupMenu(const QString &url); 1735 1736 void init(KHTMLView *view, GUIProfile prof); 1737 1738 void clear(); 1739 1740 QVariant crossFrameExecuteScript(const QString &target, const QString &script); 1741 1742 /** 1743 * @internal returns a name for a frame without a name. 1744 * This function returns a sequence of names. 1745 * All names in a sequence are different but the sequence is 1746 * always the same. 1747 * The sequence is reset in clear(). 1748 */ 1749 QString requestFrameName(); 1750 1751 // Requests loading of a frame or iframe element 1752 void loadFrameElement(DOM::HTMLPartContainerElementImpl *frame, const QString &url, const QString &frameName, 1753 const QStringList &args = QStringList(), bool isIFrame = false); 1754 1755 // Requests loading of an object or embed element. Returns true if 1756 // loading succeeded. 1757 bool loadObjectElement(DOM::HTMLPartContainerElementImpl *frame, const QString &url, const QString &serviceType, 1758 const QStringList &args = QStringList()); 1759 1760 // Tries an open a URL in given ChildFrame with all known navigation information 1761 // like mimetype and the like in the KParts arguments. 1762 // 1763 // Returns true if it's done -- which excludes the case when it's still resolving 1764 // the mimetype. 1765 // ### refine comment wrt to error case 1766 bool requestObject(khtml::ChildFrame *child, const QUrl &url, 1767 const KParts::OpenUrlArguments &args = KParts::OpenUrlArguments(), 1768 const KParts::BrowserArguments &browserArgs = KParts::BrowserArguments()); 1769 1770 // This method does the loading inside a ChildFrame once we know what mimetype to 1771 // load it as 1772 bool processObjectRequest(khtml::ChildFrame *child, const QUrl &url, const QString &mimetype); 1773 1774 // helper for reporting ChildFrame load failure 1775 void childLoadFailure(khtml::ChildFrame *child); 1776 1777 // Updates the ChildFrame to use the particular part, hooking up the various 1778 // signals, connections, etc. 1779 void connectToChildPart(khtml::ChildFrame *child, KParts::ReadOnlyPart *part, 1780 const QString &mimetype); 1781 1782 // Low-level navigation of the part itself --- this doesn't ask the user 1783 // to save things or such, and assumes that all the ChildFrame info is already 1784 // filed in with things like the mimetype and so on 1785 // 1786 // Returns if successful or not 1787 bool navigateChild(khtml::ChildFrame *child, const QUrl &url); 1788 1789 // Helper for executing javascript: or about: protocols 1790 bool navigateLocalProtocol(khtml::ChildFrame *child, KParts::ReadOnlyPart *part, 1791 const QUrl &url); 1792 1793 DOM::EventListener *createHTMLEventListener(QString code, QString name, DOM::NodeImpl *node, bool svg = false); 1794 1795 DOM::HTMLDocumentImpl *docImpl() const; 1796 DOM::DocumentImpl *xmlDocImpl() const; 1797 khtml::ChildFrame *frame(const QObject *obj); 1798 1799 khtml::ChildFrame *recursiveFrameRequest(KHTMLPart *callingHtmlPart, const QUrl &url, 1800 const KParts::OpenUrlArguments &args, const KParts::BrowserArguments &browserArgs, 1801 bool callParent = true); 1802 1803 bool checkLinkSecurity(const QUrl &linkURL, const KLocalizedString &message = KLocalizedString(), const QString &button = QString()); 1804 QVariant executeScript(const QString &filename, int baseLine, const DOM::Node &n, const QString &script); 1805 1806 KJSProxy *jScript(); 1807 1808 KHTMLPart *opener(); 1809 long cacheId() const; 1810 void setOpener(KHTMLPart *_opener); 1811 bool openedByJS(); 1812 void setOpenedByJS(bool _openedByJS); 1813 1814 void checkEmitLoadEvent(); 1815 void emitLoadEvent(); 1816 1817 bool initFindNode(bool selection, bool reverse, bool fromCursor); 1818 1819 /** extends the current selection to the given content-coordinates @p x, @p y 1820 * @param x content x-coordinate 1821 * @param y content y-coordinate 1822 * @param absX absolute x-coordinate of @p innerNode 1823 * @param absY absolute y-coordinate of @p innerNode 1824 * @param innerNode node from which to start extending the selection. The 1825 * caller has to ensure that the node has a renderer. 1826 * @internal 1827 */ 1828 void extendSelectionTo(int x, int y, const DOM::Node &innerNode); 1829 /** checks whether a selection is extended. 1830 * @return @p true if a selection is extended by the mouse. 1831 */ 1832 bool isExtendingSelection() const; 1833 KEncodingDetector *createDecoder(); 1834 QString defaultEncoding() const; 1835 1836 /** .html, .xhtml or .xml */ 1837 QString defaultExtension() const; 1838 1839 /** @internal 1840 * generic zoom in 1841 */ 1842 void zoomIn(const int stepping[], int count); 1843 /** @internal 1844 * generic zoom out 1845 */ 1846 void zoomOut(const int stepping[], int count); 1847 1848 void incFontSize(const int stepping[], int count); 1849 1850 void decFontSize(const int stepping[], int count); 1851 1852 void emitCaretPositionChanged(const DOM::Position &pos); 1853 1854 void setDebugScript(bool enable); 1855 1856 void runAdFilter(); 1857 1858 khtml::EditorContext *editorContext() const; 1859 1860 /** 1861 * initialises the caret if it hasn't been used yet. 1862 * @internal 1863 */ 1864 void initCaret(); 1865 1866 /** 1867 * Returns the selected part of the HTML. 1868 */ 1869 const DOM::Selection &caret() const; 1870 1871 /** 1872 * Returns the drag caret of the HTML. 1873 */ 1874 const DOM::Selection &dragCaret() const; 1875 1876 /** 1877 * Sets the current caret to the given selection. 1878 */ 1879 void setCaret(const DOM::Selection &, bool closeTyping = true); 1880 1881 /** 1882 * Sets the current drag caret. 1883 */ 1884 void setDragCaret(const DOM::Selection &); 1885 1886 /** 1887 * Clears the current selection. 1888 */ 1889 void clearSelection(); 1890 1891 /** 1892 * Invalidates the current selection. 1893 */ 1894 void invalidateSelection(); 1895 1896 /** 1897 * Controls the visibility of the selection. 1898 */ 1899 void setSelectionVisible(bool flag = true); 1900 1901 /** 1902 * Paints the caret. 1903 */ 1904 void paintCaret(QPainter *p, const QRect &rect) const; 1905 1906 /** 1907 * Paints the drag caret. 1908 */ 1909 void paintDragCaret(QPainter *p, const QRect &rect) const; 1910 1911 /** 1912 * Returns selectedText without any leading or trailing whitespace, 1913 * and with non-breaking-spaces turned into normal spaces. 1914 * 1915 * Note that hasSelection can return true and yet simplifiedSelectedText can be empty, 1916 * e.g. when selecting a single space. 1917 */ 1918 QString simplifiedSelectedText() const; 1919 1920 bool handleMouseMoveEventDrag(khtml::MouseMoveEvent *event); 1921 bool handleMouseMoveEventOver(khtml::MouseMoveEvent *event); 1922 void handleMouseMoveEventSelection(khtml::MouseMoveEvent *event); 1923 1924 void handleMousePressEventSingleClick(khtml::MousePressEvent *event); 1925 void handleMousePressEventDoubleClick(khtml::MouseDoubleClickEvent *event); 1926 void handleMousePressEventTripleClick(khtml::MouseDoubleClickEvent *event); 1927 1928 KHTMLPartPrivate *d; 1929 friend class KHTMLPartPrivate; 1930 1931 public: // So we don't end up having to add 50 more friends 1932 1933 /** @internal Access to internal APIs. Don't use outside */ impl()1934 KHTMLPartPrivate *impl() 1935 { 1936 return d; 1937 } 1938 }; 1939 1940 #endif 1941