1 /* This file is part of the KDE project
3 * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
4 * 1999 Lars Knoll <knoll@kde.org>
5 * 1999 Antti Koivisto <koivisto@kde.org>
6 * 2000 Simon Hausmann <hausmann@kde.org>
7 * 2000 Stefan Schimanski <1Stein@gmx.de>
8 * 2001 George Staikos <staikos@kde.org>
9 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.
10 * Copyright (C) 2005 Alexey Proskuryakov <ap@nypop.com>
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Library General Public
14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public License
23 * along with this library; see the file COPYING.LIB. If not, write to
24 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 * Boston, MA 02111-1307, USA.
30 #include "FramePrivate.h"
32 #include "ApplyStyleCommand.h"
33 #include "CSSComputedStyleDeclaration.h"
34 #include "CSSProperty.h"
35 #include "CSSPropertyNames.h"
37 #include "CachedCSSStyleSheet.h"
38 #include "DOMImplementation.h"
39 #include "DOMWindow.h"
41 #include "DocLoader.h"
42 #include "DocumentType.h"
43 #include "EditingText.h"
45 #include "EventNames.h"
46 #include "FloatRect.h"
48 #include "GraphicsContext.h"
49 #include "HTMLFormElement.h"
50 #include "HTMLFrameElement.h"
51 #include "HTMLGenericFormElement.h"
52 #include "HTMLInputElement.h"
53 #include "HTMLNames.h"
54 #include "HTMLObjectElement.h"
55 #include "HTMLViewSourceDocument.h"
56 #include "ImageDocument.h"
57 #include "MediaFeatureNames.h"
58 #include "MouseEventWithHitTestResults.h"
61 #include "PlatformScrollBar.h"
62 #include "PlugInInfoStore.h"
64 #include "PluginDocument.h"
65 #include "RenderPart.h"
66 #include "RenderTextControl.h"
67 #include "RenderTheme.h"
68 #include "RenderView.h"
69 #include "SegmentedString.h"
70 #include "TextDocument.h"
71 #include "TextIterator.h"
72 #include "TypingCommand.h"
73 #include "XMLTokenizer.h"
74 #include "cssstyleselector.h"
75 #include "htmlediting.h"
76 #include "kjs_window.h"
78 #include "visible_units.h"
79 #include "xmlhttprequest.h"
81 #include <sys/types.h>
82 #include <wtf/Platform.h>
90 #include "XLinkNames.h"
92 #include "SVGDocument.h"
93 #include "SVGDocumentExtensions.h"
101 using KJS::PausedTimeouts;
102 using KJS::SavedProperties;
103 using KJS::SavedBuiltins;
109 using namespace EventNames;
110 using namespace HTMLNames;
112 const double caretBlinkFrequency = 0.5;
113 const double autoscrollInterval = 0.1;
115 class UserStyleSheetLoader : public CachedResourceClient {
117 UserStyleSheetLoader(Frame* frame, const String& url, DocLoader* dl)
119 , m_cachedSheet(Cache::requestStyleSheet(dl, url, false, 0, ""))
121 m_cachedSheet->ref(this);
123 ~UserStyleSheetLoader()
125 m_cachedSheet->deref(this);
128 virtual void setStyleSheet(const String& /*URL*/, const String& sheet)
130 m_frame->setUserStyleSheet(sheet);
133 CachedCSSStyleSheet* m_cachedSheet;
137 struct FrameCounter {
139 ~FrameCounter() { if (count != 0) fprintf(stderr, "LEAK: %d Frame\n", count); }
141 int FrameCounter::count = 0;
142 static FrameCounter frameCounter;
145 static inline Frame* parentFromOwnerElement(Element* ownerElement)
149 return ownerElement->document()->frame();
152 Frame::Frame(Page* page, Element* ownerElement)
153 : d(new FramePrivate(page, parentFromOwnerElement(ownerElement), this, ownerElement))
155 AtomicString::init();
159 QualifiedName::init();
160 MediaFeatureNames::init();
168 if (d->m_ownerElement)
169 d->m_page->incrementFrameCount();
171 // FIXME: Frames were originally created with a refcount of 1, leave this
172 // ref call here until we can straighten that out.
175 ++FrameCounter::count;
181 ASSERT(!d->m_lifeSupportTimer.isActive());
184 --FrameCounter::count;
194 if (d->m_jscript && d->m_jscript->haveInterpreter())
195 if (Window* w = Window::retrieveWindow(this)) {
196 w->disconnectFrame();
197 // Must clear the window pointer, otherwise we will not
198 // garbage-collect collect the window (inside the call to
203 disconnectOwnerElement();
206 d->m_domWindow->disconnectFrame();
209 HashSet<Frame*> openedBy = d->m_openedFrames;
210 HashSet<Frame*>::iterator end = openedBy.end();
211 for (HashSet<Frame*>::iterator it = openedBy.begin(); it != end; ++it)
216 d->m_view->m_frame = 0;
219 ASSERT(!d->m_lifeSupportTimer.isActive());
221 delete d->m_userStyleSheetLoader;
226 bool Frame::didOpenURL(const KURL& url)
228 if (d->m_scheduledRedirection == locationChangeScheduledDuringLoad) {
229 // A redirect was shceduled before the document was created. This can happen
230 // when one frame changes another frame's location.
236 // clear last edit command
237 d->m_lastEditCommand = 0;
241 d->m_bComplete = false;
242 d->m_bLoadingMainResource = true;
243 d->m_bLoadEventEmitted = false;
245 d->m_kjsStatusBarText = String();
246 d->m_kjsDefaultStatusBarText = String();
248 d->m_bJScriptEnabled = d->m_settings->isJavaScriptEnabled();
249 d->m_bJavaEnabled = d->m_settings->isJavaEnabled();
250 d->m_bPluginsEnabled = d->m_settings->isPluginsEnabled();
252 // initializing d->m_url to the new url breaks relative links when opening such a link after this call and _before_ begin() is called (when the first
253 // data arrives) (Simon)
255 if (d->m_url.protocol().startsWith("http") && !d->m_url.host().isEmpty() && d->m_url.path().isEmpty())
256 d->m_url.setPath("/");
257 d->m_workingURL = d->m_url;
264 void Frame::didExplicitOpen()
266 d->m_bComplete = false;
267 d->m_bLoadEventEmitted = false;
269 // Prevent window.open(url) -- eg window.open("about:blank") -- from blowing away results
270 // from a subsequent window.document.open / window.document.write call.
271 // Cancelling redirection here works for all cases because document.open
272 // implicitly precedes document.write.
274 d->m_url = d->m_doc->URL();
277 void Frame::stopLoading(bool sendUnload)
279 if (d->m_doc && d->m_doc->tokenizer())
280 d->m_doc->tokenizer()->stopParsing();
282 d->m_metaData.clear();
286 if (d->m_bLoadEventEmitted && !d->m_bUnloadEventEmitted) {
287 Node* currentFocusNode = d->m_doc->focusNode();
288 if (currentFocusNode)
289 currentFocusNode->aboutToUnload();
290 d->m_doc->dispatchWindowEvent(unloadEvent, false, false);
292 d->m_doc->updateRendering();
293 d->m_bUnloadEventEmitted = true;
297 if (d->m_doc && !d->m_doc->inPageCache())
298 d->m_doc->removeAllEventListenersFromAllNodes();
301 d->m_bComplete = true; // to avoid calling completed() in finishedParsing() (David)
302 d->m_bLoadingMainResource = false;
303 d->m_bLoadEventEmitted = true; // don't want that one either
304 d->m_cachePolicy = CachePolicyVerify; // Why here?
306 if (d->m_doc && d->m_doc->parsing()) {
308 d->m_doc->setParsing(false);
311 d->m_workingURL = KURL();
313 if (Document *doc = d->m_doc.get()) {
314 if (DocLoader *docLoader = doc->docLoader())
315 Cache::loader()->cancelRequests(docLoader);
316 XMLHttpRequest::cancelRequests(doc);
319 // tell all subframes to stop as well
320 for (Frame* child = tree()->firstChild(); child; child = child->tree()->nextSibling())
321 child->stopLoading(sendUnload);
323 d->m_bPendingChildRedirection = false;
328 BrowserExtension *Frame::browserExtension() const
330 return d->m_extension;
333 FrameView* Frame::view() const
335 return d->m_view.get();
338 void Frame::setView(FrameView* view)
343 bool Frame::jScriptEnabled() const
345 return d->m_bJScriptEnabled;
348 KJSProxy *Frame::jScript()
350 if (!d->m_bJScriptEnabled)
354 d->m_jscript = new KJSProxy(this);
359 static bool getString(JSValue* result, String& string)
365 if (!result->getString(ustring))
371 void Frame::replaceContentsWithScriptResult(const KURL& url)
373 JSValue* ret = executeScript(0, KURL::decode_string(url.url().mid(strlen("javascript:"))));
375 if (getString(ret, scriptResult)) {
382 JSValue* Frame::executeScript(Node* n, const String& script, bool forceUserGesture)
384 KJSProxy *proxy = jScript();
389 d->m_runningScripts++;
390 // If forceUserGesture is true, then make the script interpreter
391 // treat it as if triggered by a user gesture even if there is no
392 // current DOM event being processed.
393 JSValue* ret = proxy->evaluate(forceUserGesture ? DeprecatedString::null : d->m_url.url(), 0, script, n);
394 d->m_runningScripts--;
396 if (!d->m_runningScripts)
399 Document::updateDocumentsRendering();
404 bool Frame::javaEnabled() const
406 return d->m_settings->isJavaEnabled();
409 bool Frame::pluginsEnabled() const
411 return d->m_bPluginsEnabled;
414 void Frame::setAutoloadImages(bool enable)
416 if (d->m_doc && d->m_doc->docLoader()->autoloadImages() == enable)
420 d->m_doc->docLoader()->setAutoloadImages(enable);
423 bool Frame::autoloadImages() const
426 return d->m_doc->docLoader()->autoloadImages();
431 void Frame::clear(bool clearWindowProperties)
435 d->m_bCleared = true;
436 d->m_mousePressNode = 0;
439 d->m_doc->cancelParsing();
443 // Moving past doc so that onUnload works.
444 if (clearWindowProperties && d->m_jscript)
445 d->m_jscript->clear();
450 // do not drop the document before the jscript and view are cleared, as some destructors
451 // might still try to access the document.
455 d->m_plugins.clear();
456 cleanupPluginObjects();
458 d->m_scheduledRedirection = noRedirectionScheduled;
459 d->m_delayRedirect = 0;
460 d->m_redirectURL = DeprecatedString::null;
461 d->m_redirectReferrer = String();
462 d->m_redirectLockHistory = true;
463 d->m_redirectUserGesture = false;
464 d->m_bHTTPRefresh = false;
465 d->m_bFirstData = true;
467 d->m_bMousePressed = false;
469 if (!d->m_haveEncoding)
470 d->m_encoding = String();
473 Document *Frame::document() const
476 return d->m_doc.get();
480 void Frame::setDocument(Document* newDoc)
491 void Frame::receivedFirstData()
493 begin(d->m_workingURL);
495 d->m_doc->docLoader()->setCachePolicy(d->m_cachePolicy);
496 d->m_workingURL = KURL();
498 // When the first data arrives, the metadata has just been made available
499 DeprecatedString qData;
501 // Support for http-refresh
502 qData = d->m_metaData.get("http-refresh").deprecatedString();
503 if (!qData.isEmpty()) {
505 int pos = qData.find(';');
507 pos = qData.find(',');
510 delay = qData.stripWhiteSpace().toDouble();
511 // We want a new history item if the refresh timeout > 1 second
512 scheduleRedirection(delay, d->m_url.url(), delay <= 1);
514 int end_pos = qData.length();
515 delay = qData.left(pos).stripWhiteSpace().toDouble();
516 while (qData[++pos] == ' ');
517 if (qData.find("url", pos, false) == pos) {
519 while (qData[pos] == ' ' || qData[pos] == '=')
521 if (qData[pos] == '"') {
523 int index = end_pos-1;
524 while (index > pos) {
525 if (qData[index] == '"')
533 // We want a new history item if the refresh timeout > 1 second
534 scheduleRedirection(delay, d->m_doc->completeURL(qData.mid(pos, end_pos)), delay <= 1);
536 d->m_bHTTPRefresh = true;
539 // Support for http last-modified
540 d->m_lastModified = d->m_metaData.get("modified");
543 void Frame::childBegin()
545 // We need to do this when the child is created so as to avoid the parent thining the child
546 // is complete before it has even started loading.
547 // FIXME: do we really still need this?
548 d->m_bComplete = false;
551 void Frame::setResourceRequest(const ResourceRequest& request)
553 d->m_request = request;
556 const ResourceRequest& Frame::resourceRequest() const
561 void Frame::begin(const KURL& url)
563 if (d->m_workingURL.isEmpty())
564 createEmptyDocument(); // Creates an empty document if we don't have one already
567 partClearedInBegin();
569 d->m_bCleared = false;
570 d->m_bComplete = false;
571 d->m_bLoadEventEmitted = false;
572 d->m_bLoadingMainResource = true;
575 ref.setUser(DeprecatedString());
576 ref.setPass(DeprecatedString());
577 ref.setRef(DeprecatedString());
578 d->m_referrer = ref.url();
582 // We don't need KDE chained URI handling or window caption setting
583 if (!d->m_url.isEmpty())
587 if (d->m_request.m_responseMIMEType == "image/svg+xml")
588 d->m_doc = DOMImplementation::instance()->createSVGDocument(d->m_view.get());
591 if (DOMImplementation::isXMLMIMEType(d->m_request.m_responseMIMEType))
592 d->m_doc = DOMImplementation::instance()->createDocument(d->m_view.get());
593 else if (DOMImplementation::isTextMIMEType(d->m_request.m_responseMIMEType))
594 d->m_doc = new TextDocument(DOMImplementation::instance(), d->m_view.get());
595 else if ((d->m_request.m_responseMIMEType == "application/pdf" || d->m_request.m_responseMIMEType == "text/pdf") && PlugInInfoStore::supportsMIMEType(d->m_request.m_responseMIMEType))
596 d->m_doc = new PluginDocument(DOMImplementation::instance(), d->m_view.get());
597 else if (Image::supportsType(d->m_request.m_responseMIMEType))
598 d->m_doc = new ImageDocument(DOMImplementation::instance(), d->m_view.get());
599 else if (PlugInInfoStore::supportsMIMEType(d->m_request.m_responseMIMEType))
600 d->m_doc = new PluginDocument(DOMImplementation::instance(), d->m_view.get());
601 else if (inViewSourceMode())
602 d->m_doc = new HTMLViewSourceDocument(DOMImplementation::instance(), d->m_view.get());
604 d->m_doc = DOMImplementation::instance()->createHTMLDocument(d->m_view.get());
606 if (!d->m_doc->attached())
608 d->m_doc->setURL(d->m_url.url());
609 // We prefer m_baseURL over d->m_url because d->m_url changes when we are
610 // about to load a new page.
611 d->m_doc->setBaseURL(baseurl.url());
613 d->m_doc->setDecoder(d->m_decoder.get());
615 updatePolicyBaseURL();
617 setAutoloadImages(d->m_settings->autoLoadImages());
618 const KURL& userStyleSheet = d->m_settings->userStyleSheetLocation();
620 if (!userStyleSheet.isEmpty())
621 setUserStyleSheetLocation(KURL(userStyleSheet));
623 restoreDocumentState();
625 d->m_doc->implicitOpen();
628 d->m_view->resizeContents(0, 0);
631 void Frame::write(const char* str, int len)
639 if (Tokenizer* t = d->m_doc->tokenizer()) {
640 if (t->wantsRawData()) {
641 t->writeRawData(str, len);
647 d->m_decoder = new Decoder(d->m_request.m_responseMIMEType, settings()->encoding());
648 if (!d->m_encoding.isNull())
649 d->m_decoder->setEncoding(d->m_encoding,
650 d->m_haveEncoding ? Decoder::UserChosenEncoding : Decoder::EncodingFromHTTPHeader);
652 d->m_doc->setDecoder(d->m_decoder.get());
655 String decoded = d->m_decoder->decode(str, len);
657 if (decoded.isEmpty())
660 if (d->m_bFirstData) {
661 d->m_bFirstData = false;
662 d->m_doc->determineParseMode(decoded);
663 if (d->m_decoder->encoding().usesVisualOrdering())
664 d->m_doc->setVisuallyOrdered();
665 d->m_doc->recalcStyle(Node::Force);
668 if (Tokenizer* t = d->m_doc->tokenizer()) {
669 ASSERT(!t->wantsRawData());
670 t->write(decoded, true);
674 void Frame::write(const String& str)
679 if (d->m_bFirstData) {
680 // determine the parse mode
681 d->m_doc->setParseMode(Document::Strict);
682 d->m_bFirstData = false;
684 Tokenizer* t = d->m_doc->tokenizer();
691 d->m_bLoadingMainResource = false;
695 void Frame::endIfNotLoading()
697 if (d->m_bLoadingMainResource)
700 // make sure nothing's left in there...
703 String decoded = d->m_decoder->flush();
704 if (d->m_bFirstData) {
705 d->m_bFirstData = false;
706 d->m_doc->determineParseMode(decoded);
710 d->m_doc->finishParsing();
712 // WebKit partially uses WebCore when loading non-HTML docs. In these cases doc==nil, but
713 // WebCore is enough involved that we need to checkCompleted() in order for m_bComplete to
714 // become true. An example is when a subframe is a pure text doc, and that subframe is the
715 // last one to complete.
722 if (d->m_doc->tokenizer())
723 d->m_doc->tokenizer()->stopParsing();
724 d->m_doc->finishParsing();
726 // WebKit partially uses WebCore when loading non-HTML docs. In these cases doc==nil, but
727 // WebCore is enough involved that we need to checkCompleted() in order for m_bComplete to
728 // become true. An example is when a subframe is a pure text doc, and that subframe is the
729 // last one to complete.
733 void Frame::gotoAnchor()
735 // If our URL has no ref, then we have no place we need to jump to.
736 if (!d->m_url.hasRef())
739 DeprecatedString ref = d->m_url.encodedHtmlRef();
740 if (!gotoAnchor(ref)) {
741 // Can't use htmlRef() here because it doesn't know which encoding to use to decode.
742 // Decoding here has to match encoding in completeURL, which means it has to use the
743 // page's encoding rather than UTF-8.
745 gotoAnchor(KURL::decode_string(ref, d->m_decoder->encoding()));
749 void Frame::finishedParsing()
751 RefPtr<Frame> protector(this);
755 return; // We are being destroyed by something checkCompleted called.
757 // check if the scrollbars are really needed for the content
758 // if not, remove them, relayout, and repaint
760 d->m_view->restoreScrollBar();
764 void Frame::loadDone()
770 void Frame::checkCompleted()
772 // Any frame that hasn't completed yet ?
773 for (Frame* child = tree()->firstChild(); child; child = child->tree()->nextSibling())
774 if (!child->d->m_bComplete)
777 // Have we completed before?
781 // Are we still parsing?
782 if (d->m_doc && d->m_doc->parsing())
785 // Still waiting for images/scripts from the loader ?
787 if (d->m_doc && d->m_doc->docLoader())
788 requests = Cache::loader()->numRequests(d->m_doc->docLoader());
794 // Now do what should be done when we are really completed.
795 d->m_bComplete = true;
797 checkEmitLoadEvent(); // if we didn't do it before
799 if (d->m_scheduledRedirection != noRedirectionScheduled) {
800 // Do not start redirection for frames here! That action is
801 // deferred until the parent emits a completed signal.
802 if (!tree()->parent())
803 startRedirectionTimer();
807 completed(d->m_bPendingChildRedirection);
811 void Frame::checkEmitLoadEvent()
813 if (d->m_bLoadEventEmitted || !d->m_doc || d->m_doc->parsing())
816 for (Frame* child = tree()->firstChild(); child; child = child->tree()->nextSibling())
817 if (!child->d->m_bComplete) // still got a frame running -> too early
820 // All frames completed -> set their domain to the frameset's domain
821 // This must only be done when loading the frameset initially (#22039),
822 // not when following a link in a frame (#44162).
824 String domain = d->m_doc->domain();
825 for (Frame* child = tree()->firstChild(); child; child = child->tree()->nextSibling())
827 child->d->m_doc->setDomain(domain);
830 d->m_bLoadEventEmitted = true;
831 d->m_bUnloadEventEmitted = false;
833 d->m_doc->implicitClose();
836 const Settings *Frame::settings() const
838 return d->m_settings;
841 KURL Frame::baseURL() const
845 return d->m_doc->baseURL();
848 String Frame::baseTarget() const
852 return d->m_doc->baseTarget();
855 KURL Frame::completeURL(const DeprecatedString& url)
860 return KURL(d->m_doc->completeURL(url));
863 void Frame::scheduleRedirection(double delay, const DeprecatedString& url, bool doLockHistory)
865 if (delay < 0 || delay > INT_MAX / 1000)
867 if (d->m_scheduledRedirection == noRedirectionScheduled || delay <= d->m_delayRedirect)
869 d->m_scheduledRedirection = redirectionScheduled;
870 d->m_delayRedirect = delay;
871 d->m_redirectURL = url;
872 d->m_redirectReferrer = String();
873 d->m_redirectLockHistory = doLockHistory;
874 d->m_redirectUserGesture = false;
876 stopRedirectionTimer();
878 startRedirectionTimer();
882 void Frame::scheduleLocationChange(const DeprecatedString& url, const String& referrer, bool lockHistory, bool userGesture)
886 // If the URL we're going to navigate to is the same as the current one, except for the
887 // fragment part, we don't need to schedule the location change.
888 if (u.hasRef() && equalIgnoringRef(d->m_url, u)) {
889 changeLocation(url, referrer, lockHistory, userGesture);
893 // Handle a location change of a page with no document as a special case.
894 // This may happen when a frame changes the location of another frame.
895 d->m_scheduledRedirection = d->m_doc ? locationChangeScheduled : locationChangeScheduledDuringLoad;
897 // If a redirect was scheduled during a load, then stop the current load.
898 // Otherwise when the current load transitions from a provisional to a
899 // committed state, pending redirects may be cancelled.
900 if (d->m_scheduledRedirection == locationChangeScheduledDuringLoad) {
904 d->m_delayRedirect = 0;
905 d->m_redirectURL = url;
906 d->m_redirectReferrer = referrer;
907 d->m_redirectLockHistory = lockHistory;
908 d->m_redirectUserGesture = userGesture;
909 stopRedirectionTimer();
911 startRedirectionTimer();
914 void Frame::scheduleRefresh(bool userGesture)
916 // Handle a location change of a page with no document as a special case.
917 // This may happen when a frame requests a refresh of another frame.
918 d->m_scheduledRedirection = d->m_doc ? locationChangeScheduled : locationChangeScheduledDuringLoad;
920 // If a refresh was scheduled during a load, then stop the current load.
921 // Otherwise when the current load transitions from a provisional to a
922 // committed state, pending redirects may be cancelled.
923 if (d->m_scheduledRedirection == locationChangeScheduledDuringLoad)
926 d->m_delayRedirect = 0;
927 d->m_redirectURL = url().url();
928 d->m_redirectReferrer = referrer();
929 d->m_redirectLockHistory = true;
930 d->m_redirectUserGesture = userGesture;
931 d->m_cachePolicy = CachePolicyRefresh;
932 stopRedirectionTimer();
934 startRedirectionTimer();
937 bool Frame::isScheduledLocationChangePending() const
939 switch (d->m_scheduledRedirection) {
940 case noRedirectionScheduled:
941 case redirectionScheduled:
943 case historyNavigationScheduled:
944 case locationChangeScheduled:
945 case locationChangeScheduledDuringLoad:
951 void Frame::scheduleHistoryNavigation(int steps)
953 // navigation will always be allowed in the 0 steps case, which is OK because
954 // that's supposed to force a reload.
955 if (!canGoBackOrForward(steps)) {
960 // If the URL we're going to navigate to is the same as the current one, except for the
961 // fragment part, we don't need to schedule the navigation.
962 if (d->m_extension) {
963 KURL u = d->m_extension->historyURL(steps);
965 if (equalIgnoringRef(d->m_url, u)) {
966 d->m_extension->goBackOrForward(steps);
971 d->m_scheduledRedirection = historyNavigationScheduled;
972 d->m_delayRedirect = 0;
973 d->m_redirectURL = DeprecatedString::null;
974 d->m_redirectReferrer = String();
975 d->m_scheduledHistoryNavigationSteps = steps;
976 stopRedirectionTimer();
978 startRedirectionTimer();
981 void Frame::cancelRedirection(bool cancelWithLoadInProgress)
984 d->m_cancelWithLoadInProgress = cancelWithLoadInProgress;
985 d->m_scheduledRedirection = noRedirectionScheduled;
986 stopRedirectionTimer();
990 void Frame::changeLocation(const DeprecatedString& URL, const String& referrer, bool lockHistory, bool userGesture)
992 if (URL.find("javascript:", 0, false) == 0) {
993 String script = KURL::decode_string(URL.mid(11));
994 JSValue* result = executeScript(0, script, userGesture);
996 if (getString(result, scriptResult)) {
1004 ResourceRequest request(completeURL(URL));
1005 request.setLockHistory(lockHistory);
1006 if (!referrer.isEmpty())
1007 request.setReferrer(referrer);
1009 request.reload = (d->m_cachePolicy == CachePolicyReload) || (d->m_cachePolicy == CachePolicyRefresh);
1011 urlSelected(request, "_self");
1014 void Frame::redirectionTimerFired(Timer<Frame>*)
1016 if (d->m_scheduledRedirection == historyNavigationScheduled) {
1017 d->m_scheduledRedirection = noRedirectionScheduled;
1019 // Special case for go(0) from a frame -> reload only the frame
1020 // go(i!=0) from a frame navigates into the history of the frame only,
1021 // in both IE and NS (but not in Mozilla).... we can't easily do that
1023 if (d->m_scheduledHistoryNavigationSteps == 0) // add && parent() to get only frames, but doesn't matter
1024 openURL(url()); /// ## need args.reload=true?
1026 if (d->m_extension) {
1027 d->m_extension->goBackOrForward(d->m_scheduledHistoryNavigationSteps);
1033 DeprecatedString URL = d->m_redirectURL;
1034 String referrer = d->m_redirectReferrer;
1035 bool lockHistory = d->m_redirectLockHistory;
1036 bool userGesture = d->m_redirectUserGesture;
1038 d->m_scheduledRedirection = noRedirectionScheduled;
1039 d->m_delayRedirect = 0;
1040 d->m_redirectURL = DeprecatedString::null;
1041 d->m_redirectReferrer = String();
1043 changeLocation(URL, referrer, lockHistory, userGesture);
1046 String Frame::encoding() const
1048 if (d->m_haveEncoding && !d->m_encoding.isEmpty())
1049 return d->m_encoding;
1050 if (d->m_decoder && d->m_decoder->encoding().isValid())
1051 return d->m_decoder->encoding().name();
1052 return settings()->encoding();
1055 void Frame::setUserStyleSheetLocation(const KURL& url)
1057 delete d->m_userStyleSheetLoader;
1058 d->m_userStyleSheetLoader = 0;
1059 if (d->m_doc && d->m_doc->docLoader())
1060 d->m_userStyleSheetLoader = new UserStyleSheetLoader(this, url.url(), d->m_doc->docLoader());
1063 void Frame::setUserStyleSheet(const String& styleSheet)
1065 delete d->m_userStyleSheetLoader;
1066 d->m_userStyleSheetLoader = 0;
1068 d->m_doc->setUserStyleSheet(styleSheet);
1071 bool Frame::gotoAnchor(const String& name)
1076 Node *n = d->m_doc->getElementById(AtomicString(name));
1078 n = d->m_doc->anchors()->namedItem(name, !d->m_doc->inCompatMode());
1080 d->m_doc->setCSSTarget(n); // Setting to null will clear the current target.
1082 // Implement the rule that "" and "top" both mean top of page as in other browsers.
1083 if (!n && !(name.isEmpty() || name.lower() == "top"))
1086 // We need to update the layout before scrolling, otherwise we could
1087 // really mess things up if an anchor scroll comes at a bad moment.
1089 d->m_doc->updateRendering();
1090 // Only do a layout if changes have occurred that make it necessary.
1091 if (d->m_view && d->m_doc->renderer() && d->m_doc->renderer()->needsLayout()) {
1092 d->m_view->layout();
1096 // Scroll nested layers and frames to reveal the anchor.
1097 RenderObject *renderer;
1100 renderer = n->renderer();
1101 rect = n->getRect();
1103 // If there's no node, we should scroll to the top of the document.
1104 renderer = d->m_doc->renderer();
1109 // Align to the top and to the closest side (this matches other browsers).
1110 renderer->enclosingLayer()->scrollRectToVisible(rect, RenderLayer::gAlignToEdgeIfNeeded, RenderLayer::gAlignTopAlways);
1116 void Frame::setStandardFont(const String& name)
1118 d->m_settings->setStdFontName(AtomicString(name));
1121 void Frame::setFixedFont(const String& name)
1123 d->m_settings->setFixedFontName(AtomicString(name));
1126 String Frame::selectedText() const
1128 return plainText(selectionController()->toRange().get());
1131 bool Frame::hasSelection() const
1133 return selectionController()->isCaretOrRange();
1136 SelectionController* Frame::selectionController() const
1138 return &(d->m_selectionController);
1141 TextGranularity Frame::selectionGranularity() const
1143 return d->m_selectionGranularity;
1146 void Frame::setSelectionGranularity(TextGranularity granularity) const
1148 d->m_selectionGranularity = granularity;
1151 SelectionController* Frame::dragCaretController() const
1153 return d->m_page->dragCaretController();
1156 const Selection& Frame::mark() const
1161 void Frame::setMark(const Selection& s)
1163 ASSERT(!s.base().node() || s.base().node()->document() == document());
1164 ASSERT(!s.extent().node() || s.extent().node()->document() == document());
1165 ASSERT(!s.start().node() || s.start().node()->document() == document());
1166 ASSERT(!s.end().node() || s.end().node()->document() == document());
1171 void Frame::notifyRendererOfSelectionChange(bool userTriggered)
1173 RenderObject* renderer = 0;
1174 if (selectionController()->rootEditableElement())
1175 renderer = selectionController()->rootEditableElement()->shadowAncestorNode()->renderer();
1177 // If the current selection is in a textfield or textarea, notify the renderer that the selection has changed
1178 if (renderer && (renderer->isTextArea() || renderer->isTextField()))
1179 static_cast<RenderTextControl*>(renderer)->selectionChanged(userTriggered);
1182 void Frame::invalidateSelection()
1184 clearCaretRectIfNeeded();
1185 selectionController()->setNeedsLayout();
1186 selectionLayoutChanged();
1189 void Frame::setCaretVisible(bool flag)
1191 if (d->m_caretVisible == flag)
1193 clearCaretRectIfNeeded();
1195 setFocusNodeIfNeeded();
1196 d->m_caretVisible = flag;
1197 selectionLayoutChanged();
1201 void Frame::clearCaretRectIfNeeded()
1203 if (d->m_caretPaint) {
1204 d->m_caretPaint = false;
1205 selectionController()->needsCaretRepaint();
1209 // Helper function that tells whether a particular node is an element that has an entire
1210 // Frame and FrameView, a <frame>, <iframe>, or <object>.
1211 static bool isFrameElement(const Node *n)
1215 RenderObject *renderer = n->renderer();
1216 if (!renderer || !renderer->isWidget())
1218 Widget* widget = static_cast<RenderWidget*>(renderer)->widget();
1219 return widget && widget->isFrameView();
1222 void Frame::setFocusNodeIfNeeded()
1224 if (!document() || selectionController()->isNone() || !d->m_isActive)
1227 Node* target = selectionController()->rootEditableElement();
1229 RenderObject* renderer = target->renderer();
1231 // Walk up the render tree to search for a node to focus.
1232 // Walking up the DOM tree wouldn't work for shadow trees, like those behind the engine-based text fields.
1234 // We don't want to set focus on a subframe when selecting in a parent frame,
1235 // so add the !isFrameElement check here. There's probably a better way to make this
1236 // work in the long term, but this is the safest fix at this time.
1237 if (target && target->isMouseFocusable() && !isFrameElement(target)) {
1238 document()->setFocusNode(target);
1241 renderer = renderer->parent();
1243 target = renderer->element();
1245 document()->setFocusNode(0);
1249 void Frame::selectionLayoutChanged()
1251 // kill any caret blink timer now running
1252 d->m_caretBlinkTimer.stop();
1254 // see if a new caret blink timer needs to be started
1255 if (d->m_caretVisible && d->m_caretBlinks &&
1256 selectionController()->isCaret() && selectionController()->start().node()->isContentEditable()) {
1257 d->m_caretBlinkTimer.startRepeating(caretBlinkFrequency);
1258 d->m_caretPaint = true;
1259 selectionController()->needsCaretRepaint();
1263 d->m_doc->updateSelection();
1266 void Frame::setXPosForVerticalArrowNavigation(int x)
1268 d->m_xPosForVerticalArrowNavigation = x;
1271 int Frame::xPosForVerticalArrowNavigation() const
1273 return d->m_xPosForVerticalArrowNavigation;
1276 void Frame::caretBlinkTimerFired(Timer<Frame>*)
1278 // Might be better to turn the timer off during some of these circumstances
1279 // and assert rather then letting the timer fire and do nothing here.
1280 // Could do that in selectionLayoutChanged.
1282 if (!d->m_caretVisible)
1284 if (!d->m_caretBlinks)
1286 if (!selectionController()->isCaret())
1288 bool caretPaint = d->m_caretPaint;
1289 if (d->m_bMousePressed && caretPaint)
1291 d->m_caretPaint = !caretPaint;
1292 selectionController()->needsCaretRepaint();
1295 void Frame::paintCaret(GraphicsContext* p, const IntRect& rect) const
1297 if (d->m_caretPaint)
1298 selectionController()->paintCaret(p, rect);
1301 void Frame::paintDragCaret(GraphicsContext* p, const IntRect& rect) const
1303 SelectionController* dragCaretController = d->m_page->dragCaretController();
1304 assert(dragCaretController->selection().isCaret());
1305 if (dragCaretController->selection().start().node()->document()->frame() == this)
1306 dragCaretController->paintCaret(p, rect);
1309 void Frame::urlSelected(const DeprecatedString& url, const String& target)
1311 urlSelected(ResourceRequest(completeURL(url)), target);
1314 void Frame::urlSelected(const ResourceRequest& request, const String& _target)
1316 String target = _target;
1317 if (target.isEmpty() && d->m_doc)
1318 target = d->m_doc->baseTarget();
1320 const KURL& url = request.url();
1322 if (url.url().startsWith("javascript:", false)) {
1323 executeScript(0, KURL::decode_string(url.url().mid(11)), true);
1328 // ### ERROR HANDLING
1331 ResourceRequest requestCopy = request;
1332 requestCopy.frameName = target;
1334 if (d->m_bHTTPRefresh)
1335 d->m_bHTTPRefresh = false;
1337 if (!d->m_referrer.isEmpty())
1338 requestCopy.setReferrer(d->m_referrer);
1340 urlSelected(requestCopy);
1343 bool Frame::requestFrame(Element* ownerElement, const String& urlParam, const AtomicString& frameName)
1345 DeprecatedString _url = urlParam.deprecatedString();
1346 // Support for <frame src="javascript:string">
1349 if (_url.startsWith("javascript:", false)) {
1351 url = "about:blank";
1353 url = completeURL(_url);
1355 Frame* frame = tree()->child(frameName);
1357 ResourceRequest request(url);
1358 request.setReferrer(d->m_referrer);
1359 request.reload = (d->m_cachePolicy == CachePolicyReload) || (d->m_cachePolicy == CachePolicyRefresh);
1360 frame->openURLRequest(request);
1362 frame = loadSubframe(ownerElement, url, frameName, d->m_referrer);
1367 if (!scriptURL.isEmpty())
1368 frame->replaceContentsWithScriptResult(scriptURL);
1373 bool Frame::requestObject(RenderPart* renderer, const String& url, const AtomicString& frameName,
1374 const String& mimeType, const Vector<String>& paramNames, const Vector<String>& paramValues)
1378 completedURL = completeURL(url.deprecatedString());
1380 if (url.isEmpty() && mimeType.isEmpty())
1384 if (shouldUsePlugin(renderer->element(), completedURL, mimeType, renderer->hasFallbackContent(), useFallback))
1385 return loadPlugin(renderer, completedURL, mimeType, paramNames, paramValues, useFallback);
1387 ASSERT(renderer->node()->hasTagName(objectTag) || renderer->node()->hasTagName(embedTag));
1388 AtomicString uniqueFrameName = tree()->uniqueChildName(frameName);
1389 static_cast<HTMLPlugInElement*>(renderer->node())->setFrameName(uniqueFrameName);
1391 // FIXME: ok to always make a new one? when does the old frame get removed?
1392 return loadSubframe(static_cast<Element*>(renderer->node()), completedURL, uniqueFrameName, d->m_referrer);
1395 bool Frame::shouldUsePlugin(Node* element, const KURL& url, const String& mimeType, bool hasFallback, bool& useFallback)
1397 useFallback = false;
1398 ObjectContentType objectType = objectContentType(url, mimeType);
1400 // if an object's content can't be handled and it has no fallback, let
1401 // it be handled as a plugin to show the broken plugin icon
1402 if (objectType == ObjectContentNone && hasFallback)
1405 return objectType == ObjectContentNone || objectType == ObjectContentPlugin;
1409 bool Frame::loadPlugin(RenderPart *renderer, const KURL& url, const String& mimeType,
1410 const Vector<String>& paramNames, const Vector<String>& paramValues, bool useFallback)
1413 checkEmitLoadEvent();
1417 Element *pluginElement;
1418 if (renderer && renderer->node() && renderer->node()->isElementNode())
1419 pluginElement = static_cast<Element*>(renderer->node());
1423 Plugin* plugin = createPlugin(pluginElement, url, paramNames, paramValues, mimeType);
1425 checkEmitLoadEvent();
1428 d->m_plugins.append(plugin);
1430 if (renderer && plugin->view())
1431 renderer->setWidget(plugin->view());
1433 checkEmitLoadEvent();
1438 Frame* Frame::loadSubframe(Element* ownerElement, const KURL& url, const String& name, const String& referrer)
1440 Frame* frame = createFrame(url, name, ownerElement, referrer);
1442 checkEmitLoadEvent();
1446 frame->childBegin();
1448 if (ownerElement->renderer() && frame->view())
1449 static_cast<RenderWidget*>(ownerElement->renderer())->setWidget(frame->view());
1451 checkEmitLoadEvent();
1453 // In these cases, the synchronous load would have finished
1454 // before we could connect the signals, so make sure to send the
1455 // completed() signal for the child by hand
1456 // FIXME: In this case the Frame will have finished loading before
1457 // it's being added to the child list. It would be a good idea to
1458 // create the child first, then invoke the loader separately.
1459 if (url.isEmpty() || url == "about:blank") {
1460 frame->completed(false);
1461 frame->checkCompleted();
1467 void Frame::clearRecordedFormValues()
1469 d->m_formAboutToBeSubmitted = 0;
1470 d->m_formValuesAboutToBeSubmitted.clear();
1473 void Frame::recordFormValue(const String& name, const String& value, PassRefPtr<HTMLFormElement> element)
1475 d->m_formAboutToBeSubmitted = element;
1476 d->m_formValuesAboutToBeSubmitted.set(name, value);
1479 void Frame::submitFormAgain()
1481 FramePrivate::SubmitForm* form = d->m_submitForm;
1482 d->m_submitForm = 0;
1483 if (d->m_doc && !d->m_doc->parsing() && form)
1484 submitForm(form->submitAction, form->submitUrl, form->submitFormData,
1485 form->target, form->submitContentType, form->submitBoundary);
1489 void Frame::submitForm(const char *action, const String& url, const FormData& formData, const String& _target, const String& contentType, const String& boundary)
1491 KURL u = completeURL(url.deprecatedString());
1494 // ### ERROR HANDLING!
1497 DeprecatedString urlstring = u.url();
1498 if (urlstring.startsWith("javascript:", false)) {
1499 urlstring = KURL::decode_string(urlstring);
1500 d->m_executingJavaScriptFormAction = true;
1501 executeScript(0, urlstring.mid(11));
1502 d->m_executingJavaScriptFormAction = false;
1506 ResourceRequest request;
1508 if (!d->m_referrer.isEmpty())
1509 request.setReferrer(d->m_referrer);
1511 request.frameName = _target.isEmpty() ? d->m_doc->baseTarget() : _target ;
1513 // Handle mailto: forms
1514 if (u.protocol() == "mailto") {
1515 // 1) Check for attach= and strip it
1516 DeprecatedString q = u.query().mid(1);
1517 DeprecatedStringList nvps = DeprecatedStringList::split("&", q);
1518 bool triedToAttach = false;
1520 for (DeprecatedStringList::Iterator nvp = nvps.begin(); nvp != nvps.end(); ++nvp) {
1521 DeprecatedStringList pair = DeprecatedStringList::split("=", *nvp);
1522 if (pair.count() >= 2) {
1523 if (pair.first().lower() == "attach") {
1524 nvp = nvps.remove(nvp);
1525 triedToAttach = true;
1532 DeprecatedString bodyEnc;
1533 if (contentType.lower() == "multipart/form-data")
1534 // FIXME: is this correct? I suspect not
1535 bodyEnc = KURL::encode_string(formData.flattenToString().deprecatedString());
1536 else if (contentType.lower() == "text/plain") {
1537 // Convention seems to be to decode, and s/&/\n/
1538 DeprecatedString tmpbody = formData.flattenToString().deprecatedString();
1539 tmpbody.replace('&', '\n');
1540 tmpbody.replace('+', ' ');
1541 tmpbody = KURL::decode_string(tmpbody); // Decode the rest of it
1542 bodyEnc = KURL::encode_string(tmpbody); // Recode for the URL
1544 bodyEnc = KURL::encode_string(formData.flattenToString().deprecatedString());
1546 nvps.append(String::sprintf("body=%s", bodyEnc.latin1()).deprecatedString());
1551 if (strcmp(action, "get") == 0) {
1552 if (u.protocol() != "mailto")
1553 u.setQuery(formData.flattenToString().deprecatedString());
1554 request.setDoPost(false);
1556 request.postData = formData;
1557 request.setDoPost(true);
1559 // construct some user headers if necessary
1560 if (contentType.isNull() || contentType == "application/x-www-form-urlencoded")
1561 request.setContentType("Content-Type: application/x-www-form-urlencoded");
1562 else // contentType must be "multipart/form-data"
1563 request.setContentType("Content-Type: " + contentType + "; boundary=" + boundary);
1566 if (d->m_doc->parsing() || d->m_runningScripts > 0) {
1567 if (d->m_submitForm)
1569 d->m_submitForm = new FramePrivate::SubmitForm;
1570 d->m_submitForm->submitAction = action;
1571 d->m_submitForm->submitUrl = url;
1572 d->m_submitForm->submitFormData = formData;
1573 d->m_submitForm->target = _target;
1574 d->m_submitForm->submitContentType = contentType;
1575 d->m_submitForm->submitBoundary = boundary;
1578 submitForm(request);
1582 void Frame::parentCompleted()
1584 if (d->m_scheduledRedirection != noRedirectionScheduled && !d->m_redirectionTimer.isActive())
1585 startRedirectionTimer();
1588 void Frame::childCompleted(bool complete)
1590 if (complete && !tree()->parent())
1591 d->m_bPendingChildRedirection = true;
1595 int Frame::zoomFactor() const
1597 return d->m_zoomFactor;
1600 void Frame::setZoomFactor(int percent)
1602 if (d->m_zoomFactor == percent)
1605 d->m_zoomFactor = percent;
1608 d->m_doc->recalcStyle(Node::Force);
1610 for (Frame* child = tree()->firstChild(); child; child = child->tree()->nextSibling())
1611 child->setZoomFactor(d->m_zoomFactor);
1613 if (d->m_doc && d->m_doc->renderer() && d->m_doc->renderer()->needsLayout())
1617 void Frame::setJSStatusBarText(const String& text)
1619 d->m_kjsStatusBarText = text;
1620 setStatusBarText(d->m_kjsStatusBarText);
1623 void Frame::setJSDefaultStatusBarText(const String& text)
1625 d->m_kjsDefaultStatusBarText = text;
1626 setStatusBarText(d->m_kjsDefaultStatusBarText);
1629 String Frame::jsStatusBarText() const
1631 return d->m_kjsStatusBarText;
1634 String Frame::jsDefaultStatusBarText() const
1636 return d->m_kjsDefaultStatusBarText;
1639 String Frame::referrer() const
1641 return d->m_referrer;
1644 String Frame::lastModified() const
1646 return d->m_lastModified;
1649 void Frame::reparseConfiguration()
1651 setAutoloadImages(d->m_settings->autoLoadImages());
1653 d->m_bJScriptEnabled = d->m_settings->isJavaScriptEnabled();
1654 d->m_bJavaEnabled = d->m_settings->isJavaEnabled();
1655 d->m_bPluginsEnabled = d->m_settings->isPluginsEnabled();
1657 const KURL& userStyleSheetLocation = d->m_settings->userStyleSheetLocation();
1658 if (!userStyleSheetLocation.isEmpty())
1659 setUserStyleSheetLocation(userStyleSheetLocation);
1661 setUserStyleSheet(String());
1663 // FIXME: It's not entirely clear why the following is needed.
1664 // The document automatically does this as required when you set the style sheet.
1665 // But we had problems when this code was removed. Details are in
1666 // <http://bugzilla.opendarwin.org/show_bug.cgi?id=8079>.
1668 d->m_doc->updateStyleSelector();
1671 bool Frame::shouldDragAutoNode(Node *node, const IntPoint& point) const
1677 bool Frame::isPointInsideSelection(const IntPoint& point)
1679 // Treat a collapsed selection like no selection.
1680 if (!selectionController()->isRange())
1682 if (!document()->renderer())
1685 RenderObject::NodeInfo nodeInfo(true, true);
1686 document()->renderer()->layer()->hitTest(nodeInfo, point);
1687 Node *innerNode = nodeInfo.innerNode();
1688 if (!innerNode || !innerNode->renderer())
1691 Position pos(innerNode->renderer()->positionForPoint(point).deepEquivalent());
1695 Node *n = selectionController()->start().node();
1697 if (n == pos.node()) {
1698 if ((n == selectionController()->start().node() && pos.offset() < selectionController()->start().offset()) ||
1699 (n == selectionController()->end().node() && pos.offset() > selectionController()->end().offset())) {
1704 if (n == selectionController()->end().node())
1706 n = n->traverseNextNode();
1712 void Frame::selectClosestWordFromMouseEvent(const PlatformMouseEvent& mouse, Node *innerNode)
1714 Selection newSelection;
1716 if (innerNode && innerNode->renderer() && mouseDownMayStartSelect() && innerNode->renderer()->shouldSelect()) {
1717 IntPoint vPoint = view()->viewportToContents(mouse.pos());
1718 VisiblePosition pos(innerNode->renderer()->positionForPoint(vPoint));
1719 if (pos.isNotNull()) {
1720 newSelection = Selection(pos);
1721 newSelection.expandUsingGranularity(WordGranularity);
1725 if (newSelection.isRange()) {
1726 d->m_selectionGranularity = WordGranularity;
1727 d->m_beganSelectingText = true;
1730 if (shouldChangeSelection(newSelection))
1731 selectionController()->setSelection(newSelection);
1734 void Frame::handleMousePressEventDoubleClick(const MouseEventWithHitTestResults& event)
1736 if (event.event().button() == LeftButton) {
1737 if (selectionController()->isRange())
1738 // A double-click when range is already selected
1739 // should not change the selection. So, do not call
1740 // selectClosestWordFromMouseEvent, but do set
1741 // m_beganSelectingText to prevent handleMouseReleaseEvent
1742 // from setting caret selection.
1743 d->m_beganSelectingText = true;
1745 selectClosestWordFromMouseEvent(event.event(), event.targetNode());
1749 void Frame::handleMousePressEventTripleClick(const MouseEventWithHitTestResults& event)
1751 Node *innerNode = event.targetNode();
1753 if (event.event().button() == LeftButton && innerNode && innerNode->renderer() &&
1754 mouseDownMayStartSelect() && innerNode->renderer()->shouldSelect()) {
1755 Selection newSelection;
1756 IntPoint vPoint = view()->viewportToContents(event.event().pos());
1757 VisiblePosition pos(innerNode->renderer()->positionForPoint(vPoint));
1758 if (pos.isNotNull()) {
1759 newSelection = Selection(pos);
1760 newSelection.expandUsingGranularity(ParagraphGranularity);
1762 if (newSelection.isRange()) {
1763 d->m_selectionGranularity = ParagraphGranularity;
1764 d->m_beganSelectingText = true;
1767 if (shouldChangeSelection(newSelection))
1768 selectionController()->setSelection(newSelection);
1772 void Frame::handleMousePressEventSingleClick(const MouseEventWithHitTestResults& event)
1774 Node *innerNode = event.targetNode();
1776 if (event.event().button() == LeftButton) {
1777 if (innerNode && innerNode->renderer() &&
1778 mouseDownMayStartSelect() && innerNode->renderer()->shouldSelect()) {
1780 // Extend the selection if the Shift key is down, unless the click is in a link.
1781 bool extendSelection = event.event().shiftKey() && !event.isOverLink();
1783 // Don't restart the selection when the mouse is pressed on an
1784 // existing selection so we can allow for text dragging.
1785 IntPoint vPoint = view()->viewportToContents(event.event().pos());
1786 if (!extendSelection && isPointInsideSelection(vPoint))
1789 VisiblePosition visiblePos(innerNode->renderer()->positionForPoint(vPoint));
1790 if (visiblePos.isNull())
1791 visiblePos = VisiblePosition(innerNode, innerNode->caretMinOffset(), DOWNSTREAM);
1792 Position pos = visiblePos.deepEquivalent();
1794 Selection newSelection = selectionController()->selection();
1795 if (extendSelection && newSelection.isCaretOrRange()) {
1796 selectionController()->clearModifyBias();
1798 // See <rdar://problem/3668157> REGRESSION (Mail): shift-click deselects when selection
1799 // was created right-to-left
1800 Position start = newSelection.start();
1801 Position end = newSelection.end();
1802 short before = Range::compareBoundaryPoints(pos.node(), pos.offset(), start.node(), start.offset());
1804 newSelection = Selection(pos, end);
1806 newSelection = Selection(start, pos);
1808 if (d->m_selectionGranularity != CharacterGranularity)
1809 newSelection.expandUsingGranularity(d->m_selectionGranularity);
1810 d->m_beganSelectingText = true;
1812 newSelection = Selection(visiblePos);
1813 d->m_selectionGranularity = CharacterGranularity;
1816 if (shouldChangeSelection(newSelection))
1817 selectionController()->setSelection(newSelection);
1822 void Frame::handleMousePressEvent(const MouseEventWithHitTestResults& event)
1824 Node *innerNode = event.targetNode();
1826 d->m_mousePressNode = innerNode;
1827 d->m_dragStartPos = event.event().pos();
1829 if (event.event().button() == LeftButton || event.event().button() == MiddleButton) {
1830 d->m_bMousePressed = true;
1831 d->m_beganSelectingText = false;
1833 if (event.event().clickCount() == 2) {
1834 handleMousePressEventDoubleClick(event);
1837 if (event.event().clickCount() >= 3) {
1838 handleMousePressEventTripleClick(event);
1841 handleMousePressEventSingleClick(event);
1845 void Frame::handleMouseMoveEvent(const MouseEventWithHitTestResults& event)
1847 // Mouse not pressed. Do nothing.
1848 if (!d->m_bMousePressed)
1851 Node *innerNode = event.targetNode();
1853 if (event.event().button() != 0 || !innerNode || !innerNode->renderer() || !mouseDownMayStartSelect() || !innerNode->renderer()->shouldSelect())
1856 // handle making selection
1857 IntPoint vPoint = view()->viewportToContents(event.event().pos());
1858 VisiblePosition pos(innerNode->renderer()->positionForPoint(vPoint));
1860 // Don't modify the selection if we're not on a node.
1864 // Restart the selection if this is the first mouse move. This work is usually
1865 // done in handleMousePressEvent, but not if the mouse press was on an existing selection.
1866 Selection newSelection = selectionController()->selection();
1867 selectionController()->clearModifyBias();
1869 if (!d->m_beganSelectingText) {
1870 d->m_beganSelectingText = true;
1871 newSelection = Selection(pos);
1874 newSelection.setExtent(pos);
1875 if (d->m_selectionGranularity != CharacterGranularity)
1876 newSelection.expandUsingGranularity(d->m_selectionGranularity);
1878 if (shouldChangeSelection(newSelection))
1879 selectionController()->setSelection(newSelection);
1882 void Frame::handleMouseReleaseEvent(const MouseEventWithHitTestResults& event)
1884 stopAutoscrollTimer();
1886 // Used to prevent mouseMoveEvent from initiating a drag before
1887 // the mouse is pressed again.
1888 d->m_bMousePressed = false;
1890 // Clear the selection if the mouse didn't move after the last mouse press.
1891 // We do this so when clicking on the selection, the selection goes away.
1892 // However, if we are editing, place the caret.
1893 if (mouseDownMayStartSelect() && !d->m_beganSelectingText
1894 && d->m_dragStartPos == event.event().pos()
1895 && selectionController()->isRange()) {
1896 Selection newSelection;
1897 Node *node = event.targetNode();
1898 if (node && node->isContentEditable() && node->renderer()) {
1899 IntPoint vPoint = view()->viewportToContents(event.event().pos());
1900 VisiblePosition pos = node->renderer()->positionForPoint(vPoint);
1901 newSelection = Selection(pos);
1903 if (shouldChangeSelection(newSelection))
1904 selectionController()->setSelection(newSelection);
1907 notifyRendererOfSelectionChange(true);
1909 selectFrameElementInParentIfFullySelected();
1912 void Frame::selectAll()
1917 Node* root = selectionController()->isContentEditable() ? selectionController()->rootEditableElement() : d->m_doc->documentElement();
1918 selectContentsOfNode(root);
1919 selectFrameElementInParentIfFullySelected();
1920 notifyRendererOfSelectionChange(true);
1923 bool Frame::selectContentsOfNode(Node* node)
1925 Selection newSelection(Selection::selectionFromContentsOfNode(node));
1926 if (shouldChangeSelection(newSelection)) {
1927 selectionController()->setSelection(newSelection);
1933 bool Frame::shouldChangeSelection(const Selection& newSelection) const
1935 return shouldChangeSelection(selectionController()->selection(), newSelection, newSelection.affinity(), false);
1938 bool Frame::shouldDeleteSelection(const Selection& newSelection) const
1943 bool Frame::shouldBeginEditing(const Range *range) const
1948 bool Frame::shouldEndEditing(const Range *range) const
1953 bool Frame::isContentEditable() const
1957 return d->m_doc->inDesignMode();
1960 void Frame::textFieldDidBeginEditing(Element* input)
1964 void Frame::textFieldDidEndEditing(Element* input)
1968 void Frame::textDidChangeInTextField(Element* input)
1972 bool Frame::doTextFieldCommandFromEvent(Element* input, const PlatformKeyboardEvent* evt)
1977 void Frame::textWillBeDeletedInTextField(Element* input)
1981 void Frame::textDidChangeInTextArea(Element* input)
1985 bool Frame::isSelectionInPasswordField()
1987 Node* startNode = selectionController()->start().node();
1989 startNode = startNode->shadowAncestorNode();
1990 return startNode && startNode->hasTagName(inputTag) && static_cast<HTMLInputElement*>(startNode)->inputType() == HTMLInputElement::PASSWORD;
1993 EditCommand* Frame::lastEditCommand()
1995 return d->m_lastEditCommand.get();
1998 static void dispatchEditableContentChangedEvents(const EditCommand& command)
2000 Element* startRoot = command.startingRootEditableElement();
2001 Element* endRoot = command.endingRootEditableElement();
2004 startRoot->dispatchEvent(new Event(khtmlEditableContentChangedEvent, false, false), ec, true);
2005 if (endRoot && endRoot != startRoot)
2006 endRoot->dispatchEvent(new Event(khtmlEditableContentChangedEvent, false, false), ec, true);
2009 void Frame::appliedEditing(PassRefPtr<EditCommand> cmd)
2011 dispatchEditableContentChangedEvents(*cmd);
2013 Selection newSelection(cmd->endingSelection());
2014 if (shouldChangeSelection(newSelection))
2015 selectionController()->setSelection(newSelection, false);
2017 // Now set the typing style from the command. Clear it when done.
2018 // This helps make the case work where you completely delete a piece
2019 // of styled text and then type a character immediately after.
2020 // That new character needs to take on the style of the just-deleted text.
2021 // FIXME: Improve typing style.
2022 // See this bug: <rdar://problem/3769899> Implementation of typing style needs improvement
2023 if (cmd->typingStyle()) {
2024 setTypingStyle(cmd->typingStyle());
2025 cmd->setTypingStyle(0);
2028 // Command will be equal to last edit command only in the case of typing
2029 if (d->m_lastEditCommand == cmd)
2030 assert(cmd->isTypingCommand());
2032 // Only register a new undo command if the command passed in is
2033 // different from the last command
2034 d->m_lastEditCommand = cmd.get();
2035 registerCommandForUndo(cmd);
2037 respondToChangedContents(newSelection);
2040 void Frame::unappliedEditing(PassRefPtr<EditCommand> cmd)
2042 dispatchEditableContentChangedEvents(*cmd);
2044 Selection newSelection(cmd->startingSelection());
2045 if (shouldChangeSelection(newSelection))
2046 selectionController()->setSelection(newSelection, true);
2048 d->m_lastEditCommand = 0;
2049 registerCommandForRedo(cmd);
2050 respondToChangedContents(newSelection);
2053 void Frame::reappliedEditing(PassRefPtr<EditCommand> cmd)
2055 dispatchEditableContentChangedEvents(*cmd);
2057 Selection newSelection(cmd->endingSelection());
2058 if (shouldChangeSelection(newSelection))
2059 selectionController()->setSelection(newSelection, true);
2061 d->m_lastEditCommand = 0;
2062 registerCommandForUndo(cmd);
2063 respondToChangedContents(newSelection);
2066 CSSMutableStyleDeclaration *Frame::typingStyle() const
2068 return d->m_typingStyle.get();
2071 void Frame::setTypingStyle(CSSMutableStyleDeclaration *style)
2073 d->m_typingStyle = style;
2076 void Frame::clearTypingStyle()
2078 d->m_typingStyle = 0;
2081 JSValue* Frame::executeScript(const String& filename, int baseLine, Node* n, const String& script)
2083 // FIXME: This is missing stuff that the other executeScript has.
2084 // --> d->m_runningScripts and submitFormAgain.
2086 KJSProxy* proxy = jScript();
2089 JSValue* ret = proxy->evaluate(filename, baseLine, script, n);
2090 Document::updateDocumentsRendering();
2094 Frame *Frame::opener()
2099 void Frame::setOpener(Frame* opener)
2102 d->m_opener->d->m_openedFrames.remove(this);
2104 opener->d->m_openedFrames.add(this);
2105 d->m_opener = opener;
2108 bool Frame::openedByJS()
2110 return d->m_openedByJS;
2113 void Frame::setOpenedByJS(bool _openedByJS)
2115 d->m_openedByJS = _openedByJS;
2118 bool Frame::tabsToLinks() const
2123 bool Frame::tabsToAllControls() const
2128 void Frame::copyToPasteboard()
2133 void Frame::cutToPasteboard()
2138 void Frame::pasteFromPasteboard()
2140 issuePasteCommand();
2143 void Frame::pasteAndMatchStyle()
2145 issuePasteAndMatchStyleCommand();
2148 bool Frame::mayCopy()
2150 return !isSelectionInPasswordField();
2153 void Frame::transpose()
2155 issueTransposeCommand();
2169 void Frame::computeAndSetTypingStyle(CSSStyleDeclaration *style, EditAction editingAction)
2171 if (!style || style->length() == 0) {
2176 // Calculate the current typing style.
2177 RefPtr<CSSMutableStyleDeclaration> mutableStyle = style->makeMutable();
2178 if (typingStyle()) {
2179 typingStyle()->merge(mutableStyle.get());
2180 mutableStyle = typingStyle();
2183 Node *node = selectionController()->selection().visibleStart().deepEquivalent().node();
2184 CSSComputedStyleDeclaration computedStyle(node);
2185 computedStyle.diff(mutableStyle.get());
2187 // Handle block styles, substracting these from the typing style.
2188 RefPtr<CSSMutableStyleDeclaration> blockStyle = mutableStyle->copyBlockProperties();
2189 blockStyle->diff(mutableStyle.get());
2190 if (document() && blockStyle->length() > 0)
2191 applyCommand(new ApplyStyleCommand(document(), blockStyle.get(), editingAction));
2193 // Set the remaining style as the typing style.
2194 d->m_typingStyle = mutableStyle.release();
2197 void Frame::applyStyle(CSSStyleDeclaration *style, EditAction editingAction)
2199 switch (selectionController()->state()) {
2200 case Selection::NONE:
2203 case Selection::CARET: {
2204 computeAndSetTypingStyle(style, editingAction);
2207 case Selection::RANGE:
2208 if (document() && style)
2209 applyCommand(new ApplyStyleCommand(document(), style, editingAction));
2214 void Frame::applyParagraphStyle(CSSStyleDeclaration *style, EditAction editingAction)
2216 switch (selectionController()->state()) {
2217 case Selection::NONE:
2220 case Selection::CARET:
2221 case Selection::RANGE:
2222 if (document() && style)
2223 applyCommand(new ApplyStyleCommand(document(), style, editingAction, ApplyStyleCommand::ForceBlockProperties));
2228 static void updateState(CSSMutableStyleDeclaration *desiredStyle, CSSComputedStyleDeclaration *computedStyle, bool& atStart, Frame::TriState& state)
2230 DeprecatedValueListConstIterator<CSSProperty> end;
2231 for (DeprecatedValueListConstIterator<CSSProperty> it = desiredStyle->valuesIterator(); it != end; ++it) {
2232 int propertyID = (*it).id();
2233 String desiredProperty = desiredStyle->getPropertyValue(propertyID);
2234 String computedProperty = computedStyle->getPropertyValue(propertyID);
2235 Frame::TriState propertyState = equalIgnoringCase(desiredProperty, computedProperty)
2236 ? Frame::trueTriState : Frame::falseTriState;
2238 state = propertyState;
2240 } else if (state != propertyState) {
2241 state = Frame::mixedTriState;
2247 Frame::TriState Frame::selectionListState() const
2249 TriState state = falseTriState;
2251 if (!selectionController()->isRange()) {
2252 Node* selectionNode = selectionController()->selection().start().node();
2253 if (enclosingList(selectionNode))
2254 return trueTriState;
2256 //FIXME: Support ranges
2262 Frame::TriState Frame::selectionHasStyle(CSSStyleDeclaration *style) const
2264 bool atStart = true;
2265 TriState state = falseTriState;
2267 RefPtr<CSSMutableStyleDeclaration> mutableStyle = style->makeMutable();
2269 if (!selectionController()->isRange()) {
2271 RefPtr<CSSComputedStyleDeclaration> selectionStyle = selectionComputedStyle(nodeToRemove);
2272 if (!selectionStyle)
2273 return falseTriState;
2274 updateState(mutableStyle.get(), selectionStyle.get(), atStart, state);
2276 ExceptionCode ec = 0;
2277 nodeToRemove->remove(ec);
2281 for (Node* node = selectionController()->start().node(); node; node = node->traverseNextNode()) {
2282 RefPtr<CSSComputedStyleDeclaration> computedStyle = new CSSComputedStyleDeclaration(node);
2284 updateState(mutableStyle.get(), computedStyle.get(), atStart, state);
2285 if (state == mixedTriState)
2287 if (node == selectionController()->end().node())
2295 bool Frame::selectionStartHasStyle(CSSStyleDeclaration *style) const
2298 RefPtr<CSSStyleDeclaration> selectionStyle = selectionComputedStyle(nodeToRemove);
2299 if (!selectionStyle)
2302 RefPtr<CSSMutableStyleDeclaration> mutableStyle = style->makeMutable();
2305 DeprecatedValueListConstIterator<CSSProperty> end;
2306 for (DeprecatedValueListConstIterator<CSSProperty> it = mutableStyle->valuesIterator(); it != end; ++it) {
2307 int propertyID = (*it).id();
2308 if (!equalIgnoringCase(mutableStyle->getPropertyValue(propertyID), selectionStyle->getPropertyValue(propertyID))) {
2315 ExceptionCode ec = 0;
2316 nodeToRemove->remove(ec);
2323 String Frame::selectionStartStylePropertyValue(int stylePropertyID) const
2326 RefPtr<CSSStyleDeclaration> selectionStyle = selectionComputedStyle(nodeToRemove);
2327 if (!selectionStyle)
2330 String value = selectionStyle->getPropertyValue(stylePropertyID);
2333 ExceptionCode ec = 0;
2334 nodeToRemove->remove(ec);
2341 CSSComputedStyleDeclaration *Frame::selectionComputedStyle(Node *&nodeToRemove) const
2348 if (selectionController()->isNone())
2351 RefPtr<Range> range(selectionController()->toRange());
2352 Position pos = range->editingStartPosition();
2354 Element *elem = pos.element();
2358 RefPtr<Element> styleElement = elem;
2359 ExceptionCode ec = 0;
2361 if (d->m_typingStyle) {
2362 styleElement = document()->createElementNS(xhtmlNamespaceURI, "span", ec);
2365 styleElement->setAttribute(styleAttr, d->m_typingStyle->cssText().impl(), ec);
2368 styleElement->appendChild(document()->createEditingTextNode(""), ec);
2371 if (elem->renderer() && elem->renderer()->canHaveChildren()) {
2372 elem->appendChild(styleElement, ec);
2374 Node *parent = elem->parent();
2375 Node *next = elem->nextSibling();
2378 parent->insertBefore(styleElement, next, ec);
2380 parent->appendChild(styleElement, ec);
2385 nodeToRemove = styleElement.get();
2388 return new CSSComputedStyleDeclaration(styleElement);
2391 void Frame::applyEditingStyleToBodyElement() const
2396 RefPtr<NodeList> list = d->m_doc->getElementsByTagName("body");
2397 unsigned len = list->length();
2398 for (unsigned i = 0; i < len; i++) {
2399 applyEditingStyleToElement(static_cast<Element*>(list->item(i)));
2403 void Frame::removeEditingStyleFromBodyElement() const
2408 RefPtr<NodeList> list = d->m_doc->getElementsByTagName("body");
2409 unsigned len = list->length();
2410 for (unsigned i = 0; i < len; i++) {
2411 removeEditingStyleFromElement(static_cast<Element*>(list->item(i)));
2415 void Frame::applyEditingStyleToElement(Element* element) const
2420 CSSStyleDeclaration* style = element->style();
2423 ExceptionCode ec = 0;
2424 style->setProperty(CSS_PROP_WORD_WRAP, "break-word", false, ec);
2426 style->setProperty(CSS_PROP__WEBKIT_NBSP_MODE, "space", false, ec);
2428 style->setProperty(CSS_PROP__WEBKIT_LINE_BREAK, "after-white-space", false, ec);
2432 void Frame::removeEditingStyleFromElement(Element*) const
2436 bool Frame::isCharacterSmartReplaceExempt(UChar, bool)
2443 static HashSet<Frame*> lifeSupportSet;
2446 void Frame::endAllLifeSupport()
2449 HashSet<Frame*> lifeSupportCopy = lifeSupportSet;
2450 HashSet<Frame*>::iterator end = lifeSupportCopy.end();
2451 for (HashSet<Frame*>::iterator it = lifeSupportCopy.begin(); it != end; ++it)
2452 (*it)->endLifeSupport();
2456 void Frame::keepAlive()
2458 if (d->m_lifeSupportTimer.isActive())
2462 lifeSupportSet.add(this);
2464 d->m_lifeSupportTimer.startOneShot(0);
2467 void Frame::endLifeSupport()
2469 if (!d->m_lifeSupportTimer.isActive())
2471 d->m_lifeSupportTimer.stop();
2473 lifeSupportSet.remove(this);
2478 void Frame::lifeSupportTimerFired(Timer<Frame>*)
2481 lifeSupportSet.remove(this);
2486 // Workaround for the fact that it's hard to delete a frame.
2487 // Call this after doing user-triggered selections to make it easy to delete the frame you entirely selected.
2488 // Can't do this implicitly as part of every setSelection call because in some contexts it might not be good
2489 // for the focus to move to another frame. So instead we call it from places where we are selecting with the
2490 // mouse or the keyboard after setting the selection.
2491 void Frame::selectFrameElementInParentIfFullySelected()
2493 // Find the parent frame; if there is none, then we have nothing to do.
2494 Frame *parent = tree()->parent();
2497 FrameView *parentView = parent->view();
2501 // Check if the selection contains the entire frame contents; if not, then there is nothing to do.
2502 if (!selectionController()->isRange())
2504 if (!isStartOfDocument(selectionController()->selection().visibleStart()))
2506 if (!isEndOfDocument(selectionController()->selection().visibleEnd()))
2509 // Get to the <iframe> or <frame> (or even <object>) element in the parent frame.
2510 Document *doc = document();
2513 Element *ownerElement = doc->ownerElement();
2516 Node *ownerElementParent = ownerElement->parentNode();
2517 if (!ownerElementParent)
2520 // This method's purpose is it to make it easier to select iframes (in order to delete them). Don't do anything if the iframe isn't deletable.
2521 if (!ownerElementParent->isContentEditable())
2524 // Create compute positions before and after the element.
2525 unsigned ownerElementNodeIndex = ownerElement->nodeIndex();
2526 VisiblePosition beforeOwnerElement(VisiblePosition(ownerElementParent, ownerElementNodeIndex, SEL_DEFAULT_AFFINITY));
2527 VisiblePosition afterOwnerElement(VisiblePosition(ownerElementParent, ownerElementNodeIndex + 1, VP_UPSTREAM_IF_POSSIBLE));
2529 // Focus on the parent frame, and then select from before this element to after.
2530 Selection newSelection(beforeOwnerElement, afterOwnerElement);
2531 if (parent->shouldChangeSelection(newSelection)) {
2532 parentView->setFocus();
2533 parent->selectionController()->setSelection(newSelection);
2537 void Frame::handleFallbackContent()
2539 Element* owner = ownerElement();
2540 if (!owner || !owner->hasTagName(objectTag))
2542 static_cast<HTMLObjectElement*>(owner)->renderFallbackContent();
2545 void Frame::setSettings(Settings *settings)
2547 d->m_settings = settings;
2550 void Frame::provisionalLoadStarted()
2552 // we don't want to wait until we get an actual http response back
2553 // to cancel pending redirects, otherwise they might fire before
2555 cancelRedirection(true);
2558 bool Frame::userGestureHint()
2560 Frame *rootFrame = this;
2561 while (rootFrame->tree()->parent())
2562 rootFrame = rootFrame->tree()->parent();
2564 if (rootFrame->jScript())
2565 return rootFrame->jScript()->interpreter()->wasRunByUserGesture();
2567 return true; // If JavaScript is disabled, a user gesture must have initiated the navigation
2570 RenderObject *Frame::renderer() const
2572 Document *doc = document();
2573 return doc ? doc->renderer() : 0;
2576 Element* Frame::ownerElement()
2578 return d->m_ownerElement;
2581 RenderPart* Frame::ownerRenderer()
2583 Element* ownerElement = d->m_ownerElement;
2586 return static_cast<RenderPart*>(ownerElement->renderer());
2589 IntRect Frame::selectionRect() const
2591 RenderView *root = static_cast<RenderView*>(renderer());
2595 return root->selectionRect();
2598 // returns FloatRect because going through IntRect would truncate any floats
2599 FloatRect Frame::visibleSelectionRect() const
2604 return intersection(selectionRect(), d->m_view->visibleContentRect());
2607 bool Frame::isFrameSet() const
2609 Document* document = d->m_doc.get();
2610 if (!document || !document->isHTMLDocument())
2612 Node *body = static_cast<HTMLDocument*>(document)->body();
2613 return body && body->renderer() && body->hasTagName(framesetTag);
2616 bool Frame::openURL(const KURL& URL)
2618 ASSERT_NOT_REACHED();
2622 void Frame::didNotOpenURL(const KURL& URL)
2624 if (d->m_submittedFormURL == URL)
2625 d->m_submittedFormURL = KURL();
2628 // Scans logically forward from "start", including any child frames
2629 static HTMLFormElement *scanForForm(Node *start)
2632 for (n = start; n; n = n->traverseNextNode()) {
2633 if (n->hasTagName(formTag))
2634 return static_cast<HTMLFormElement*>(n);
2635 else if (n->isHTMLElement() && static_cast<HTMLElement*>(n)->isGenericFormElement())
2636 return static_cast<HTMLGenericFormElement*>(n)->form();
2637 else if (n->hasTagName(frameTag) || n->hasTagName(iframeTag)) {
2638 Node *childDoc = static_cast<HTMLFrameElement*>(n)->contentDocument();
2639 if (HTMLFormElement *frameResult = scanForForm(childDoc))
2646 // We look for either the form containing the current focus, or for one immediately after it
2647 HTMLFormElement *Frame::currentForm() const
2649 // start looking either at the active (first responder) node, or where the selection is
2650 Node *start = d->m_doc ? d->m_doc->focusNode() : 0;
2652 start = selectionController()->start().node();
2654 // try walking up the node tree to find a form element
2656 for (n = start; n; n = n->parentNode()) {
2657 if (n->hasTagName(formTag))
2658 return static_cast<HTMLFormElement*>(n);
2659 else if (n->isHTMLElement()
2660 && static_cast<HTMLElement*>(n)->isGenericFormElement())
2661 return static_cast<HTMLGenericFormElement*>(n)->form();
2664 // try walking forward in the node tree to find a form element
2665 return start ? scanForForm(start) : 0;
2668 void Frame::setEncoding(const String& name, bool userChosen)
2670 if (!d->m_workingURL.isEmpty())
2671 receivedFirstData();
2672 d->m_encoding = name;
2673 d->m_haveEncoding = userChosen;
2676 void Frame::addData(const char *bytes, int length)
2678 ASSERT(d->m_workingURL.isEmpty());
2680 ASSERT(d->m_doc->parsing());
2681 write(bytes, length);
2684 // FIXME: should this go in SelectionController?
2685 void Frame::revealSelection()
2689 switch (selectionController()->state()) {
2690 case Selection::NONE:
2693 case Selection::CARET:
2694 rect = selectionController()->caretRect();
2697 case Selection::RANGE:
2698 rect = selectionRect();
2702 Position start = selectionController()->start();
2703 Position end = selectionController()->end();
2704 ASSERT(start.node());
2705 if (start.node() && start.node()->renderer()) {
2706 RenderLayer *layer = start.node()->renderer()->enclosingLayer();
2708 ASSERT(!end.node() || !end.node()->renderer()
2709 || (end.node()->renderer()->enclosingLayer() == layer));
2710 layer->scrollRectToVisible(rect);
2715 // FIXME: should this be here?
2716 bool Frame::scrollOverflow(ScrollDirection direction, ScrollGranularity granularity)
2722 Node *node = document()->focusNode();
2724 node = d->m_mousePressNode.get();
2728 RenderObject *r = node->renderer();
2730 return r->scroll(direction, granularity);
2737 void Frame::handleAutoscroll(RenderLayer* layer)
2739 if (d->m_autoscrollTimer.isActive())
2741 d->m_autoscrollLayer = layer;
2742 startAutoscrollTimer();
2745 void Frame::autoscrollTimerFired(Timer<Frame>*)
2747 if (!d->m_bMousePressed){
2748 stopAutoscrollTimer();
2751 if (d->m_autoscrollLayer) {
2752 d->m_autoscrollLayer->autoscroll();
2756 RenderObject::NodeInfo Frame::nodeInfoAtPoint(const IntPoint& point, bool allowShadowContent)
2758 RenderObject::NodeInfo nodeInfo(true, true);
2759 renderer()->layer()->hitTest(nodeInfo, point);
2763 IntPoint widgetPoint(point);
2766 n = nodeInfo.innerNode();
2767 if (!n || !n->renderer() || !n->renderer()->isWidget())
2769 widget = static_cast<RenderWidget*>(n->renderer())->widget();
2770 if (!widget || !widget->isFrameView())
2772 Frame* frame = static_cast<HTMLFrameElement*>(n)->contentFrame();
2773 if (!frame || !frame->renderer())
2776 n->renderer()->absolutePosition(absX, absY, true);
2777 FrameView *view = static_cast<FrameView*>(widget);
2778 widgetPoint.setX(widgetPoint.x() - absX + view->contentsX());
2779 widgetPoint.setY(widgetPoint.y() - absY + view->contentsY());
2781 RenderObject::NodeInfo widgetNodeInfo(true, true);
2782 frame->renderer()->layer()->hitTest(widgetNodeInfo, widgetPoint);
2783 nodeInfo = widgetNodeInfo;
2786 if (!allowShadowContent) {
2787 Node* node = nodeInfo.innerNode();
2789 node = node->shadowAncestorNode();
2790 nodeInfo.setInnerNode(node);
2791 node = nodeInfo.innerNonSharedNode();
2793 node = node->shadowAncestorNode();
2794 nodeInfo.setInnerNonSharedNode(node);
2799 bool Frame::hasSelection()
2801 if (selectionController()->isNone())
2804 // If a part has a selection, it should also have a document.
2810 void Frame::startAutoscrollTimer()
2812 d->m_autoscrollTimer.startRepeating(autoscrollInterval);
2815 void Frame::stopAutoscrollTimer()
2817 d->m_autoscrollLayer = 0;
2818 d->m_autoscrollTimer.stop();
2821 // FIXME: why is this here instead of on the FrameView?
2822 void Frame::paint(GraphicsContext* p, const IntRect& rect)
2826 if (!document() || document()->printing())
2827 fillWithRed = false; // Printing, don't fill with red (can't remember why).
2828 else if (document()->ownerElement())
2829 fillWithRed = false; // Subframe, don't fill with red.
2830 else if (view() && view()->isTransparent())
2831 fillWithRed = false; // Transparent, don't fill with red.
2832 else if (d->m_paintRestriction == PaintRestrictionSelectionOnly || d->m_paintRestriction == PaintRestrictionSelectionOnlyWhiteText)
2833 fillWithRed = false; // Selections are transparent, don't fill with red.
2834 else if (d->m_elementToDraw)
2835 fillWithRed = false; // Element images are transparent, don't fill with red.
2840 p->fillRect(rect, Color(0xFF, 0, 0));
2844 // d->m_elementToDraw is used to draw only one element
2845 RenderObject *eltRenderer = d->m_elementToDraw ? d->m_elementToDraw->renderer() : 0;
2846 if (d->m_paintRestriction == PaintRestrictionNone)
2847 renderer()->document()->invalidateRenderedRectsForMarkersInRect(rect);
2848 renderer()->layer()->paint(p, rect, d->m_paintRestriction, eltRenderer);
2851 // Regions may have changed as a result of the visibility/z-index of element changing.
2852 if (renderer()->document()->dashboardRegionsDirty())
2853 renderer()->view()->frameView()->updateDashboardRegions();
2856 LOG_ERROR("called Frame::paint with nil renderer");
2861 void Frame::adjustPageHeight(float *newBottom, float oldTop, float oldBottom, float bottomLimit)
2863 RenderView *root = static_cast<RenderView*>(document()->renderer());
2865 // Use a context with painting disabled.
2866 GraphicsContext context(0);
2867 root->setTruncatedAt((int)floorf(oldBottom));
2868 IntRect dirtyRect(0, (int)floorf(oldTop), root->docWidth(), (int)ceilf(oldBottom - oldTop));
2869 root->layer()->paint(&context, dirtyRect);
2870 *newBottom = root->bestTruncatedAt();
2871 if (*newBottom == 0)
2872 *newBottom = oldBottom;
2874 *newBottom = oldBottom;
2879 PausedTimeouts *Frame::pauseTimeouts()
2882 if (d->m_doc && d->m_doc->svgExtensions())
2883 d->m_doc->accessSVGExtensions()->pauseAnimations();
2886 if (d->m_doc && d->m_jscript) {
2887 if (Window* w = Window::retrieveWindow(this))
2888 return w->pauseTimeouts();
2893 void Frame::resumeTimeouts(PausedTimeouts* t)
2896 if (d->m_doc && d->m_doc->svgExtensions())
2897 d->m_doc->accessSVGExtensions()->unpauseAnimations();
2900 if (d->m_doc && d->m_jscript && d->m_bJScriptEnabled) {
2901 if (Window* w = Window::retrieveWindow(this))
2902 w->resumeTimeouts(t);
2906 bool Frame::canCachePage()
2908 // Only save page state if:
2909 // 1. We're not a frame or frameset.
2910 // 2. The page has no unload handler.
2911 // 3. The page has no password fields.
2912 // 4. The URL for the page is not https.
2913 // 5. The page has no applets.
2914 if (tree()->childCount() || d->m_plugins.size() ||
2916 d->m_url.protocol().startsWith("https") ||
2917 (d->m_doc && (d->m_doc->applets()->length() != 0 ||
2918 d->m_doc->hasWindowEventListener(unloadEvent) ||
2919 d->m_doc->hasPasswordField()))) {
2925 void Frame::saveWindowProperties(KJS::SavedProperties *windowProperties)
2927 Window *window = Window::retrieveWindow(this);
2929 window->saveProperties(*windowProperties);
2932 void Frame::saveLocationProperties(SavedProperties *locationProperties)
2934 Window *window = Window::retrieveWindow(this);
2937 Location *location = window->location();
2938 location->saveProperties(*locationProperties);
2942 void Frame::restoreWindowProperties(SavedProperties *windowProperties)
2944 Window *window = Window::retrieveWindow(this);
2946 window->restoreProperties(*windowProperties);
2949 void Frame::restoreLocationProperties(SavedProperties *locationProperties)
2951 Window *window = Window::retrieveWindow(this);
2954 Location *location = window->location();
2955 location->restoreProperties(*locationProperties);
2959 void Frame::saveInterpreterBuiltins(SavedBuiltins& interpreterBuiltins)
2962 jScript()->interpreter()->saveBuiltins(interpreterBuiltins);
2965 void Frame::restoreInterpreterBuiltins(const SavedBuiltins& interpreterBuiltins)
2968 jScript()->interpreter()->restoreBuiltins(interpreterBuiltins);
2971 Frame *Frame::frameForWidget(const Widget *widget)
2973 ASSERT_ARG(widget, widget);
2975 Node *node = nodeForWidget(widget);
2977 return frameForNode(node);
2979 // Assume all widgets are either form controls, or FrameViews.
2980 ASSERT(widget->isFrameView());
2981 return static_cast<const FrameView*>(widget)->frame();
2984 Frame *Frame::frameForNode(Node *node)
2986 ASSERT_ARG(node, node);
2987 return node->document()->frame();
2990 Node* Frame::nodeForWidget(const Widget* widget)
2992 ASSERT_ARG(widget, widget);
2993 WidgetClient* client = widget->client();
2996 return client->element(const_cast<Widget*>(widget));
2999 void Frame::clearDocumentFocus(Widget *widget)
3001 Node *node = nodeForWidget(widget);
3003 node->document()->setFocusNode(0);
3006 void Frame::updatePolicyBaseURL()
3008 if (tree()->parent() && tree()->parent()->document())
3009 setPolicyBaseURL(tree()->parent()->document()->policyBaseURL());
3011 setPolicyBaseURL(d->m_url.url());
3014 void Frame::setPolicyBaseURL(const String& s)
3017 document()->setPolicyBaseURL(s);
3018 for (Frame* child = tree()->firstChild(); child; child = child->tree()->nextSibling())
3019 child->setPolicyBaseURL(s);
3022 void Frame::forceLayout()
3024 FrameView *v = d->m_view.get();
3027 // We cannot unschedule a pending relayout, since the force can be called with
3028 // a tiny rectangle from a drawRect update. By unscheduling we in effect
3029 // "validate" and stop the necessary full repaint from occurring. Basically any basic
3030 // append/remove DHTML is broken by this call. For now, I have removed the optimization
3031 // until we have a better invalidation stategy. -dwh
3032 //v->unscheduleRelayout();
3036 void Frame::forceLayoutWithPageWidthRange(float minPageWidth, float maxPageWidth)
3038 // Dumping externalRepresentation(m_frame->renderer()).ascii() is a good trick to see
3039 // the state of things before and after the layout
3040 RenderView *root = static_cast<RenderView*>(document()->renderer());
3042 // This magic is basically copied from khtmlview::print
3043 int pageW = (int)ceilf(minPageWidth);
3044 root->setWidth(pageW);
3045 root->setNeedsLayoutAndMinMaxRecalc();
3048 // If we don't fit in the minimum page width, we'll lay out again. If we don't fit in the
3049 // maximum page width, we will lay out to the maximum page width and clip extra content.
3050 // FIXME: We are assuming a shrink-to-fit printing implementation. A cropping
3051 // implementation should not do this!
3052 int rightmostPos = root->rightmostPosition();
3053 if (rightmostPos > minPageWidth) {
3054 pageW = min(rightmostPos, (int)ceilf(maxPageWidth));
3055 root->setWidth(pageW);
3056 root->setNeedsLayoutAndMinMaxRecalc();
3062 void Frame::sendResizeEvent()
3064 if (Document* doc = document())
3065 doc->dispatchWindowEvent(EventNames::resizeEvent, false, false);
3068 void Frame::sendScrollEvent()
3070 FrameView *v = d->m_view.get();
3072 Document *doc = document();
3075 doc->dispatchHTMLEvent(scrollEvent, true, false);
3079 bool Frame::scrollbarsVisible()
3084 if (view()->hScrollBarMode() == ScrollBarAlwaysOff || view()->vScrollBarMode() == ScrollBarAlwaysOff)
3090 void Frame::addMetaData(const String& key, const String& value)
3092 d->m_metaData.set(key, value);
3095 // This does the same kind of work that Frame::openURL does, except it relies on the fact
3096 // that a higher level already checked that the URLs match and the scrolling is the right thing to do.
3097 void Frame::scrollToAnchor(const KURL& URL)
3104 // It's important to model this as a load that starts and immediately finishes.
3105 // Otherwise, the parent frame may think we never finished loading.
3106 d->m_bComplete = false;
3110 bool Frame::closeURL()
3112 saveDocumentState();
3114 clearUndoRedoOperations();
3118 bool Frame::canMouseDownStartSelect(Node* node)
3120 if (!node || !node->renderer())
3123 // Check to see if -webkit-user-select has been set to none
3124 if (!node->renderer()->canSelect())
3127 // Some controls and images can't start a select on a mouse down.
3128 for (RenderObject* curr = node->renderer(); curr; curr = curr->parent()) {
3129 if (curr->style()->userSelect() == SELECT_IGNORE)
3136 void Frame::handleMouseReleaseDoubleClickEvent(const MouseEventWithHitTestResults& event)
3138 passWidgetMouseDownEventToWidget(event, true);
3141 bool Frame::passWidgetMouseDownEventToWidget(const MouseEventWithHitTestResults& event, bool isDoubleClick)
3143 // Figure out which view to send the event to.
3144 RenderObject *target = event.targetNode() ? event.targetNode()->renderer() : 0;
3148 Widget* widget = RenderLayer::gScrollBar;
3150 if (!target->isWidget())
3152 widget = static_cast<RenderWidget*>(target)->widget();
3155 // Doubleclick events don't exist in Cocoa. Since passWidgetMouseDownEventToWidget will
3156 // just pass _currentEvent down to the widget, we don't want to call it for events that
3157 // don't correspond to Cocoa events. The mousedown/ups will have already been passed on as
3158 // part of the pressed/released handling.
3160 return passMouseDownEventToWidget(widget);
3164 bool Frame::passWidgetMouseDownEventToWidget(RenderWidget *renderWidget)
3166 return passMouseDownEventToWidget(renderWidget->widget());
3169 void Frame::clearTimers(FrameView *view)
3172 view->unscheduleRelayout();
3173 if (view->frame()) {
3174 Document* document = view->frame()->document();
3175 if (document && document->renderer() && document->renderer()->layer())
3176 document->renderer()->layer()->suspendMarquees();
3181 void Frame::clearTimers()
3183 clearTimers(d->m_view.get());
3186 // FIXME: selection controller?
3187 void Frame::centerSelectionInVisibleArea() const
3191 switch (selectionController()->state()) {
3192 case Selection::NONE:
3195 case Selection::CARET:
3196 rect = selectionController()->caretRect();
3199 case Selection::RANGE:
3200 rect = selectionRect();
3204 Position start = selectionController()->start();
3205 Position end = selectionController()->end();
3206 ASSERT(start.node());
3207 if (start.node() && start.node()->renderer()) {
3208 RenderLayer *layer = start.node()->renderer()->enclosingLayer();
3210 ASSERT(!end.node() || !end.node()->renderer()
3211 || (end.node()->renderer()->enclosingLayer() == layer));
3212 layer->scrollRectToVisible(rect, RenderLayer::gAlignCenterAlways, RenderLayer::gAlignCenterAlways);
3217 RenderStyle *Frame::styleForSelectionStart(Node *&nodeToRemove) const
3223 if (selectionController()->isNone())
3226 Position pos = selectionController()->selection().visibleStart().deepEquivalent();
3227 if (!pos.inRenderedContent())
3229 Node *node = pos.node();
3233 if (!d->m_typingStyle)
3234 return node->renderer()->style();
3236 ExceptionCode ec = 0;
3237 RefPtr<Element> styleElement = document()->createElementNS(xhtmlNamespaceURI, "span", ec);
3240 styleElement->setAttribute(styleAttr, d->m_typingStyle->cssText().impl(), ec);
3243 styleElement->appendChild(document()->createEditingTextNode(""), ec);
3246 node->parentNode()->appendChild(styleElement, ec);
3249 nodeToRemove = styleElement.get();
3250 return styleElement->renderer()->style();
3253 void Frame::setMediaType(const String& type)
3256 d->m_view->setMediaType(type);
3259 void Frame::setSelectionFromNone()
3261 // Put a caret inside the body if the entire frame is editable (either the
3262 // entire WebView is editable or designMode is on for this document).
3263 Document *doc = document();
3264 if (!doc || !selectionController()->isNone() || !isContentEditable())
3267 Node* node = doc->documentElement();
3268 while (node && !node->hasTagName(bodyTag))
3269 node = node->traverseNextNode();
3271 selectionController()->setSelection(Selection(Position(node, 0), DOWNSTREAM));
3274 bool Frame::isActive() const
3276 return d->m_isActive;
3279 void Frame::setIsActive(bool flag)
3281 if (d->m_isActive == flag)
3284 d->m_isActive = flag;
3286 // This method does the job of updating the view based on whether the view is "active".
3287 // This involves three kinds of drawing updates:
3289 // 1. The background color used to draw behind selected content (active | inactive color)
3291 d->m_view->updateContents(enclosingIntRect(visibleSelectionRect()));
3293 // 2. Caret blinking (blinks | does not blink)
3295 setSelectionFromNone();
3296 setCaretVisible(flag);
3298 // 3. The drawing of a focus ring around links in web pages.
3299 Document *doc = document();
3301 Node *node = doc->focusNode();
3304 if (node->renderer() && node->renderer()->style()->hasAppearance())
3305 theme()->stateChanged(node->renderer(), FocusState);
3309 // 4. Changing the tint of controls from clear to aqua/graphite and vice versa. We
3310 // do a "fake" paint. When the theme gets a paint call, it can then do an invalidate. This is only
3311 // done if the theme supports control tinting.
3312 if (doc && d->m_view && theme()->supportsControlTints() && renderer()) {
3313 doc->updateLayout(); // Ensure layout is up to date.
3314 IntRect visibleRect(enclosingIntRect(d->m_view->visibleContentRect()));
3315 GraphicsContext context((PlatformGraphicsContext*)0);
3316 context.setUpdatingControlTints(true);
3317 paint(&context, visibleRect);
3320 // 5. Enable or disable secure keyboard entry
3321 if ((flag && !isSecureKeyboardEntry() && doc && doc->focusNode() && doc->focusNode()->hasTagName(inputTag) &&
3322 static_cast<HTMLInputElement*>(doc->focusNode())->inputType() == HTMLInputElement::PASSWORD) ||
3323 (!flag && isSecureKeyboardEntry()))
3324 setSecureKeyboardEntry(flag);
3327 void Frame::setWindowHasFocus(bool flag)
3329 if (d->m_windowHasFocus == flag)
3331 d->m_windowHasFocus = flag;
3333 if (Document *doc = document())
3334 doc->dispatchWindowEvent(flag ? focusEvent : blurEvent, false, false);
3337 bool Frame::inViewSourceMode() const
3339 return d->m_inViewSourceMode;
3342 void Frame::setInViewSourceMode(bool mode) const
3344 d->m_inViewSourceMode = mode;
3347 UChar Frame::backslashAsCurrencySymbol() const
3349 Document *doc = document();
3352 Decoder *decoder = doc->decoder();
3356 return decoder->encoding().backslashAsCurrencySymbol();
3359 bool Frame::markedTextUsesUnderlines() const
3361 return d->m_markedTextUsesUnderlines;
3364 const Vector<MarkedTextUnderline>& Frame::markedTextUnderlines() const
3366 return d->m_markedTextUnderlines;
3369 // Searches from the beginning of the document if nothing is selected.
3370 bool Frame::findString(const String& target, bool forward, bool caseFlag, bool wrapFlag)
3372 if (target.isEmpty())
3375 // Initially search from the start (if forward) or end (if backward) of the selection, and search to edge of document.
3376 RefPtr<Range> searchRange(rangeOfContents(document()));
3377 Selection selection(selectionController()->selection());
3378 if (!selection.isNone()) {
3380 setStart(searchRange.get(), selection.visibleStart());
3382 setEnd(searchRange.get(), selection.visibleEnd());
3384 RefPtr<Range> resultRange(findPlainText(searchRange.get(), target, forward, caseFlag));
3385 // If the found range is already selected, find again.
3386 // Build a selection with the found range to remove collapsed whitespace.
3387 // Compare ranges instead of selection objects to ignore the way that the current selection was made.
3388 if (!selection.isNone() && *Selection(resultRange.get()).toRange() == *selection.toRange()) {
3389 searchRange = rangeOfContents(document());
3391 setStart(searchRange.get(), selection.visibleEnd());
3393 setEnd(searchRange.get(), selection.visibleStart());
3394 resultRange = findPlainText(searchRange.get(), target, forward, caseFlag);
3399 // If we didn't find anything and we're wrapping, search again in the entire document (this will
3400 // redundantly re-search the area already searched in some cases).
3401 if (resultRange->collapsed(exception) && wrapFlag) {
3402 searchRange = rangeOfContents(document());
3403 resultRange = findPlainText(searchRange.get(), target, forward, caseFlag);
3404 // We used to return false here if we ended up with the same range that we started with
3405 // (e.g., the selection was already the only instance of this text). But we decided that
3406 // this should be a success case instead, so we'll just fall through in that case.
3409 if (resultRange->collapsed(exception))
3412 selectionController()->setSelection(Selection(resultRange.get(), DOWNSTREAM));
3417 unsigned Frame::markAllMatchesForText(const String& target, bool caseFlag)
3419 if (target.isEmpty())
3422 RefPtr<Range> searchRange(rangeOfContents(document()));
3425 unsigned matchCount = 0;
3427 RefPtr<Range> resultRange(findPlainText(searchRange.get(), target, true, caseFlag));
3428 if (resultRange->collapsed(exception))
3431 // A non-collapsed result range can in some funky whitespace cases still not
3432 // advance the range's start position (4509328). Break to avoid infinite loop.
3433 VisiblePosition newStart = endVisiblePosition(resultRange.get(), DOWNSTREAM);
3434 if (newStart == startVisiblePosition(searchRange.get(), DOWNSTREAM))
3438 document()->addMarker(resultRange.get(), DocumentMarker::TextMatch);
3440 setStart(searchRange.get(), newStart);
3443 // Do a "fake" paint in order to execute the code that computes the rendered rect for
3445 Document* doc = document();
3446 if (doc && d->m_view && renderer()) {
3447 doc->updateLayout(); // Ensure layout is up to date.
3448 IntRect visibleRect(enclosingIntRect(d->m_view->visibleContentRect()));
3449 GraphicsContext context((PlatformGraphicsContext*)0);
3450 context.setPaintingDisabled(true);
3451 paint(&context, visibleRect);
3457 bool Frame::markedTextMatchesAreHighlighted() const
3459 return d->m_highlightTextMatches;
3462 void Frame::setMarkedTextMatchesAreHighlighted(bool flag)
3464 if (flag == d->m_highlightTextMatches)
3467 d->m_highlightTextMatches = flag;
3468 document()->repaintMarkers(DocumentMarker::TextMatch);
3471 void Frame::prepareForUserAction()
3473 // Reset the multiple form submission protection code.
3474 // We'll let you submit the same form twice if you do two separate user actions.
3475 d->m_submittedFormURL = KURL();
3478 Node *Frame::mousePressNode()
3480 return d->m_mousePressNode.get();
3483 bool Frame::isComplete() const
3485 return d->m_bComplete;
3488 bool Frame::isLoadingMainResource() const
3490 return d->m_bLoadingMainResource;
3493 FrameTree* Frame::tree() const
3495 return &d->m_treeNode;
3498 DOMWindow* Frame::domWindow() const
3500 if (!d->m_domWindow)
3501 d->m_domWindow = new DOMWindow(const_cast<Frame*>(this));
3503 return d->m_domWindow.get();
3506 KURL Frame::url() const
3511 void Frame::startRedirectionTimer()
3513 d->m_redirectionTimer.startOneShot(d->m_delayRedirect);
3516 void Frame::stopRedirectionTimer()
3518 d->m_redirectionTimer.stop();
3521 void Frame::frameDetached()
3525 void Frame::updateBaseURLForEmptyDocument()
3527 Element* owner = ownerElement();
3528 // FIXME: Should embed be included?
3529 if (owner && (owner->hasTagName(iframeTag) || owner->hasTagName(objectTag) || owner->hasTagName(embedTag)))
3530 d->m_doc->setBaseURL(tree()->parent()->d->m_doc->baseURL());
3533 Page* Frame::page() const
3538 void Frame::pageDestroyed()
3542 // This will stop any JS timers
3543 if (d->m_jscript && d->m_jscript->haveInterpreter())
3544 if (Window* w = Window::retrieveWindow(this))
3545 w->disconnectFrame();
3548 void Frame::completed(bool complete)
3551 for (Frame* child = tree()->firstChild(); child; child = child->tree()->nextSibling())
3552 child->parentCompleted();
3553 if (Frame* parent = tree()->parent())
3554 parent->childCompleted(complete);
3559 void Frame::setStatusBarText(const String&)
3563 void Frame::started()
3565 for (Frame* frame = this; frame; frame = frame->tree()->parent())
3566 frame->d->m_bComplete = false;
3569 void Frame::disconnectOwnerElement()
3571 if (d->m_ownerElement)
3572 d->m_page->decrementFrameCount();
3574 d->m_ownerElement = 0;
3577 String Frame::documentTypeString() const
3579 if (Document *doc = document())
3580 if (DocumentType *doctype = doc->realDocType())
3581 return doctype->toString();
3586 bool Frame::containsPlugins() const
3588 return d->m_plugins.size() != 0;
3591 bool Frame::prohibitsScrolling() const
3593 return d->m_prohibitsScrolling;
3596 void Frame::setProhibitsScrolling(const bool prohibit)
3598 d->m_prohibitsScrolling = prohibit;
3601 } // namespace WebCore