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 "DOMWindow.h"
39 #include "DocLoader.h"
40 #include "DocumentType.h"
41 #include "EditingText.h"
42 #include "EditorClient.h"
44 #include "EventNames.h"
45 #include "FloatRect.h"
47 #include "FrameLoader.h"
48 #include "FrameLoadRequest.h"
49 #include "FrameView.h"
50 #include "GraphicsContext.h"
51 #include "HTMLFormElement.h"
52 #include "HTMLFrameElementBase.h"
53 #include "HTMLGenericFormElement.h"
54 #include "HTMLInputElement.h"
55 #include "HTMLNames.h"
56 #include "HTMLObjectElement.h"
57 #include "HitTestRequest.h"
58 #include "HitTestResult.h"
59 #include "IconDatabase.h"
60 #include "IconLoader.h"
61 #include "ImageDocument.h"
62 #include "IndentOutdentCommand.h"
63 #include "MediaFeatureNames.h"
64 #include "MouseEventWithHitTestResults.h"
67 #include "PlatformScrollBar.h"
68 #include "RenderListBox.h"
69 #include "RenderObject.h"
70 #include "RenderPart.h"
71 #include "RenderTextControl.h"
72 #include "RenderTheme.h"
73 #include "RenderView.h"
74 #include "SegmentedString.h"
75 #include "TextIterator.h"
76 #include "TextResourceDecoder.h"
77 #include "TypingCommand.h"
78 #include "XMLTokenizer.h"
79 #include "cssstyleselector.h"
80 #include "htmlediting.h"
81 #include "kjs_proxy.h"
82 #include "kjs_window.h"
84 #include "visible_units.h"
85 #include "xmlhttprequest.h"
87 #include <sys/types.h>
88 #include <wtf/Platform.h>
100 #include "XLinkNames.h"
101 #include "XMLNames.h"
102 #include "SVGDocument.h"
103 #include "SVGDocumentExtensions.h"
111 using KJS::PausedTimeouts;
112 using KJS::SavedProperties;
113 using KJS::SavedBuiltins;
119 using namespace EventNames;
120 using namespace HTMLNames;
122 const double caretBlinkFrequency = 0.5;
123 const double autoscrollInterval = 0.1;
125 class UserStyleSheetLoader : public CachedResourceClient {
127 UserStyleSheetLoader(Frame* frame, const String& url, DocLoader* docLoader)
129 , m_cachedSheet(docLoader->requestCSSStyleSheet(url, ""))
131 m_cachedSheet->ref(this);
133 ~UserStyleSheetLoader()
135 m_cachedSheet->deref(this);
138 virtual void setCSSStyleSheet(const String& /*URL*/, const String& /*charset*/, const String& sheet)
140 m_frame->setUserStyleSheet(sheet);
143 CachedCSSStyleSheet* m_cachedSheet;
147 struct FrameCounter {
149 ~FrameCounter() { if (count != 0) fprintf(stderr, "LEAK: %d Frame\n", count); }
151 int FrameCounter::count = 0;
152 static FrameCounter frameCounter;
155 static inline Frame* parentFromOwnerElement(Element* ownerElement)
159 return ownerElement->document()->frame();
162 Frame::Frame(Page* page, Element* ownerElement, PassRefPtr<EditorClient> client)
163 : d(new FramePrivate(page, parentFromOwnerElement(ownerElement), this, ownerElement, client))
165 AtomicString::init();
168 QualifiedName::init();
169 MediaFeatureNames::init();
178 page->setMainFrame(this);
180 // FIXME: Frames were originally created with a refcount of 1.
181 // Leave this ref call here until we can straighten that out.
183 page->incrementFrameCount();
187 ++FrameCounter::count;
193 // FIXME: We should not be doing all this work inside the destructor
195 ASSERT(!d->m_lifeSupportTimer.isActive());
198 --FrameCounter::count;
201 if (d->m_jscript && d->m_jscript->haveInterpreter())
202 if (Window* w = Window::retrieveWindow(this)) {
203 w->disconnectFrame();
204 // Must clear the window pointer, otherwise we will not
205 // garbage-collect collect the window (inside the call to
210 disconnectOwnerElement();
213 d->m_domWindow->disconnectFrame();
217 d->m_view->m_frame = 0;
220 ASSERT(!d->m_lifeSupportTimer.isActive());
222 delete d->m_userStyleSheetLoader;
227 FrameLoader* Frame::loader() const
232 FrameView* Frame::view() const
234 return d->m_view.get();
237 void Frame::setView(FrameView* view)
239 // Detach the document now, so any onUnload handlers get run - if
240 // we wait until the view is destroyed, then things won't be
241 // hooked up enough for some JavaScript calls to work.
242 if (d->m_doc && view == 0)
248 bool Frame::javaScriptEnabled() const
250 return d->m_bJScriptEnabled;
253 KJSProxy *Frame::scriptProxy()
255 if (!d->m_bJScriptEnabled)
259 d->m_jscript = new KJSProxy(this);
264 bool Frame::javaEnabled() const
266 return d->m_settings->isJavaEnabled();
269 bool Frame::pluginsEnabled() const
271 return d->m_bPluginsEnabled;
274 Document *Frame::document() const
277 return d->m_doc.get();
281 void Frame::setDocument(Document* newDoc)
292 const Settings *Frame::settings() const
294 return d->m_settings;
297 void Frame::setUserStyleSheetLocation(const KURL& url)
299 delete d->m_userStyleSheetLoader;
300 d->m_userStyleSheetLoader = 0;
301 if (d->m_doc && d->m_doc->docLoader())
302 d->m_userStyleSheetLoader = new UserStyleSheetLoader(this, url.url(), d->m_doc->docLoader());
305 void Frame::setUserStyleSheet(const String& styleSheet)
307 delete d->m_userStyleSheetLoader;
308 d->m_userStyleSheetLoader = 0;
310 d->m_doc->setUserStyleSheet(styleSheet);
313 void Frame::setStandardFont(const String& name)
315 d->m_settings->setStdFontName(AtomicString(name));
318 void Frame::setFixedFont(const String& name)
320 d->m_settings->setFixedFontName(AtomicString(name));
323 String Frame::selectedText() const
325 return plainText(selectionController()->toRange().get());
328 SelectionController* Frame::selectionController() const
330 return &d->m_selectionController;
333 Editor* Frame::editor() const
338 TextGranularity Frame::selectionGranularity() const
340 return d->m_selectionGranularity;
343 void Frame::setSelectionGranularity(TextGranularity granularity) const
345 d->m_selectionGranularity = granularity;
348 SelectionController* Frame::dragCaretController() const
350 return d->m_page->dragCaretController();
353 const Selection& Frame::mark() const
358 void Frame::setMark(const Selection& s)
360 ASSERT(!s.base().node() || s.base().node()->document() == document());
361 ASSERT(!s.extent().node() || s.extent().node()->document() == document());
362 ASSERT(!s.start().node() || s.start().node()->document() == document());
363 ASSERT(!s.end().node() || s.end().node()->document() == document());
368 void Frame::notifyRendererOfSelectionChange(bool userTriggered)
370 RenderObject* renderer = 0;
371 if (selectionController()->rootEditableElement())
372 renderer = selectionController()->rootEditableElement()->shadowAncestorNode()->renderer();
374 // If the current selection is in a textfield or textarea, notify the renderer that the selection has changed
375 if (renderer && (renderer->isTextArea() || renderer->isTextField()))
376 static_cast<RenderTextControl*>(renderer)->selectionChanged(userTriggered);
379 void Frame::invalidateSelection()
381 selectionController()->setNeedsLayout();
382 selectionLayoutChanged();
385 void Frame::setCaretVisible(bool flag)
387 if (d->m_caretVisible == flag)
389 clearCaretRectIfNeeded();
391 setFocusNodeIfNeeded();
392 d->m_caretVisible = flag;
393 selectionLayoutChanged();
397 void Frame::clearCaretRectIfNeeded()
399 if (d->m_caretPaint) {
400 d->m_caretPaint = false;
401 selectionController()->invalidateCaretRect();
405 // Helper function that tells whether a particular node is an element that has an entire
406 // Frame and FrameView, a <frame>, <iframe>, or <object>.
407 static bool isFrameElement(const Node *n)
411 RenderObject *renderer = n->renderer();
412 if (!renderer || !renderer->isWidget())
414 Widget* widget = static_cast<RenderWidget*>(renderer)->widget();
415 return widget && widget->isFrameView();
418 void Frame::setFocusNodeIfNeeded()
420 if (!document() || selectionController()->isNone() || !d->m_isActive)
423 Node* target = selectionController()->rootEditableElement();
425 RenderObject* renderer = target->renderer();
427 // Walk up the render tree to search for a node to focus.
428 // Walking up the DOM tree wouldn't work for shadow trees, like those behind the engine-based text fields.
430 // We don't want to set focus on a subframe when selecting in a parent frame,
431 // so add the !isFrameElement check here. There's probably a better way to make this
432 // work in the long term, but this is the safest fix at this time.
433 if (target && target->isMouseFocusable() && !isFrameElement(target)) {
434 document()->setFocusNode(target);
437 renderer = renderer->parent();
439 target = renderer->element();
441 document()->setFocusNode(0);
445 void Frame::selectionLayoutChanged()
447 bool caretRectChanged = selectionController()->recomputeCaretRect();
449 bool shouldBlink = d->m_caretVisible
450 && selectionController()->isCaret() && selectionController()->isContentEditable();
452 // If the caret moved, stop the blink timer so we can restart with a
453 // black caret in the new location.
454 if (caretRectChanged || !shouldBlink)
455 d->m_caretBlinkTimer.stop();
457 // Start blinking with a black caret. Be sure not to restart if we're
458 // already blinking in the right location.
459 if (shouldBlink && !d->m_caretBlinkTimer.isActive()) {
460 d->m_caretBlinkTimer.startRepeating(caretBlinkFrequency);
461 d->m_caretPaint = true;
465 d->m_doc->updateSelection();
468 void Frame::setXPosForVerticalArrowNavigation(int x)
470 d->m_xPosForVerticalArrowNavigation = x;
473 int Frame::xPosForVerticalArrowNavigation() const
475 return d->m_xPosForVerticalArrowNavigation;
478 void Frame::caretBlinkTimerFired(Timer<Frame>*)
480 ASSERT(d->m_caretVisible);
481 ASSERT(selectionController()->isCaret());
482 bool caretPaint = d->m_caretPaint;
483 if (d->m_bMousePressed && caretPaint)
485 d->m_caretPaint = !caretPaint;
486 selectionController()->invalidateCaretRect();
489 void Frame::paintCaret(GraphicsContext* p, const IntRect& rect) const
491 if (d->m_caretPaint && d->m_caretVisible)
492 selectionController()->paintCaret(p, rect);
495 void Frame::paintDragCaret(GraphicsContext* p, const IntRect& rect) const
497 SelectionController* dragCaretController = d->m_page->dragCaretController();
498 assert(dragCaretController->selection().isCaret());
499 if (dragCaretController->selection().start().node()->document()->frame() == this)
500 dragCaretController->paintCaret(p, rect);
503 int Frame::zoomFactor() const
505 return d->m_zoomFactor;
508 void Frame::setZoomFactor(int percent)
510 if (d->m_zoomFactor == percent)
513 d->m_zoomFactor = percent;
516 d->m_doc->recalcStyle(Node::Force);
518 for (Frame* child = tree()->firstChild(); child; child = child->tree()->nextSibling())
519 child->setZoomFactor(d->m_zoomFactor);
521 if (d->m_doc && d->m_doc->renderer() && d->m_doc->renderer()->needsLayout())
525 void Frame::setJSStatusBarText(const String& text)
527 d->m_kjsStatusBarText = text;
528 setStatusBarText(d->m_kjsStatusBarText);
531 void Frame::setJSDefaultStatusBarText(const String& text)
533 d->m_kjsDefaultStatusBarText = text;
534 setStatusBarText(d->m_kjsDefaultStatusBarText);
537 String Frame::jsStatusBarText() const
539 return d->m_kjsStatusBarText;
542 String Frame::jsDefaultStatusBarText() const
544 return d->m_kjsDefaultStatusBarText;
547 void Frame::reparseConfiguration()
550 d->m_doc->docLoader()->setAutoLoadImages(d->m_settings->autoLoadImages());
552 d->m_bJScriptEnabled = d->m_settings->isJavaScriptEnabled();
553 d->m_bJavaEnabled = d->m_settings->isJavaEnabled();
554 d->m_bPluginsEnabled = d->m_settings->isPluginsEnabled();
556 const KURL& userStyleSheetLocation = d->m_settings->userStyleSheetLocation();
557 if (!userStyleSheetLocation.isEmpty())
558 setUserStyleSheetLocation(userStyleSheetLocation);
560 setUserStyleSheet(String());
562 // FIXME: It's not entirely clear why the following is needed.
563 // The document automatically does this as required when you set the style sheet.
564 // But we had problems when this code was removed. Details are in
565 // <http://bugs.webkit.org/show_bug.cgi?id=8079>.
567 d->m_doc->updateStyleSelector();
570 bool Frame::shouldDragAutoNode(Node *node, const IntPoint& point) const
575 void Frame::selectClosestWordFromMouseEvent(const PlatformMouseEvent& mouse, Node *innerNode)
577 Selection newSelection;
579 if (innerNode && innerNode->renderer() && mouseDownMayStartSelect() && innerNode->renderer()->shouldSelect()) {
580 IntPoint vPoint = view()->windowToContents(mouse.pos());
581 VisiblePosition pos(innerNode->renderer()->positionForPoint(vPoint));
582 if (pos.isNotNull()) {
583 newSelection = Selection(pos);
584 newSelection.expandUsingGranularity(WordGranularity);
588 if (newSelection.isRange()) {
589 d->m_selectionGranularity = WordGranularity;
590 d->m_beganSelectingText = true;
593 if (shouldChangeSelection(newSelection))
594 selectionController()->setSelection(newSelection);
597 void Frame::handleMousePressEventDoubleClick(const MouseEventWithHitTestResults& event)
599 if (event.event().button() == LeftButton) {
600 if (selectionController()->isRange())
601 // A double-click when range is already selected
602 // should not change the selection. So, do not call
603 // selectClosestWordFromMouseEvent, but do set
604 // m_beganSelectingText to prevent handleMouseReleaseEvent
605 // from setting caret selection.
606 d->m_beganSelectingText = true;
608 selectClosestWordFromMouseEvent(event.event(), event.targetNode());
612 void Frame::handleMousePressEventTripleClick(const MouseEventWithHitTestResults& event)
614 Node *innerNode = event.targetNode();
616 if (event.event().button() == LeftButton && innerNode && innerNode->renderer() &&
617 mouseDownMayStartSelect() && innerNode->renderer()->shouldSelect()) {
618 Selection newSelection;
619 IntPoint vPoint = view()->windowToContents(event.event().pos());
620 VisiblePosition pos(innerNode->renderer()->positionForPoint(vPoint));
621 if (pos.isNotNull()) {
622 newSelection = Selection(pos);
623 newSelection.expandUsingGranularity(ParagraphGranularity);
625 if (newSelection.isRange()) {
626 d->m_selectionGranularity = ParagraphGranularity;
627 d->m_beganSelectingText = true;
630 if (shouldChangeSelection(newSelection))
631 selectionController()->setSelection(newSelection);
635 void Frame::handleMousePressEventSingleClick(const MouseEventWithHitTestResults& event)
637 Node *innerNode = event.targetNode();
639 if (event.event().button() == LeftButton) {
640 if (innerNode && innerNode->renderer() &&
641 mouseDownMayStartSelect() && innerNode->renderer()->shouldSelect()) {
643 // Extend the selection if the Shift key is down, unless the click is in a link.
644 bool extendSelection = event.event().shiftKey() && !event.isOverLink();
646 // Don't restart the selection when the mouse is pressed on an
647 // existing selection so we can allow for text dragging.
648 IntPoint vPoint = view()->windowToContents(event.event().pos());
649 if (!extendSelection && selectionController()->contains(vPoint))
652 VisiblePosition visiblePos(innerNode->renderer()->positionForPoint(vPoint));
653 if (visiblePos.isNull())
654 visiblePos = VisiblePosition(innerNode, innerNode->caretMinOffset(), DOWNSTREAM);
655 Position pos = visiblePos.deepEquivalent();
657 Selection newSelection = selectionController()->selection();
658 if (extendSelection && newSelection.isCaretOrRange()) {
659 selectionController()->clearModifyBias();
661 // See <rdar://problem/3668157> REGRESSION (Mail): shift-click deselects when selection
662 // was created right-to-left
663 Position start = newSelection.start();
664 Position end = newSelection.end();
665 short before = Range::compareBoundaryPoints(pos.node(), pos.offset(), start.node(), start.offset());
667 newSelection = Selection(pos, end);
669 newSelection = Selection(start, pos);
671 if (d->m_selectionGranularity != CharacterGranularity)
672 newSelection.expandUsingGranularity(d->m_selectionGranularity);
673 d->m_beganSelectingText = true;
675 newSelection = Selection(visiblePos);
676 d->m_selectionGranularity = CharacterGranularity;
679 if (shouldChangeSelection(newSelection))
680 selectionController()->setSelection(newSelection);
685 void Frame::handleMousePressEvent(const MouseEventWithHitTestResults& event)
687 Node *innerNode = event.targetNode();
689 d->m_mousePressNode = innerNode;
690 d->m_dragStartPos = event.event().pos();
692 if (event.event().button() == LeftButton || event.event().button() == MiddleButton) {
693 d->m_bMousePressed = true;
694 d->m_beganSelectingText = false;
696 if (event.event().clickCount() == 2) {
697 handleMousePressEventDoubleClick(event);
700 if (event.event().clickCount() >= 3) {
701 handleMousePressEventTripleClick(event);
704 handleMousePressEventSingleClick(event);
707 setMouseDownMayStartAutoscroll(mouseDownMayStartSelect() ||
708 (d->m_mousePressNode && d->m_mousePressNode->renderer() && d->m_mousePressNode->renderer()->shouldAutoscroll()));
711 void Frame::handleMouseMoveEvent(const MouseEventWithHitTestResults& event)
713 // Mouse not pressed. Do nothing.
714 if (!d->m_bMousePressed)
717 Node *innerNode = event.targetNode();
719 if (event.event().button() != 0 || !innerNode || !innerNode->renderer())
722 ASSERT(mouseDownMayStartSelect() || mouseDownMayStartAutoscroll());
724 setMouseDownMayStartDrag(false);
725 view()->invalidateClick();
727 if (mouseDownMayStartAutoscroll()) {
728 // If the selection is contained in a layer that can scroll, that layer should handle the autoscroll
729 // Otherwise, let the bridge handle it so the view can scroll itself.
730 RenderObject* renderer = innerNode->renderer();
731 while (renderer && !renderer->shouldAutoscroll())
732 renderer = renderer->parent();
734 handleAutoscroll(renderer);
737 if (mouseDownMayStartSelect() && innerNode->renderer()->shouldSelect()) {
738 // handle making selection
739 IntPoint vPoint = view()->windowToContents(event.event().pos());
740 VisiblePosition pos(innerNode->renderer()->positionForPoint(vPoint));
742 updateSelectionForMouseDragOverPosition(pos);
747 void Frame::updateSelectionForMouseDragOverPosition(const VisiblePosition& pos)
749 // Don't modify the selection if we're not on a node.
753 // Restart the selection if this is the first mouse move. This work is usually
754 // done in handleMousePressEvent, but not if the mouse press was on an existing selection.
755 Selection newSelection = selectionController()->selection();
756 selectionController()->clearModifyBias();
758 if (!d->m_beganSelectingText) {
759 d->m_beganSelectingText = true;
760 newSelection = Selection(pos);
763 newSelection.setExtent(pos);
764 if (d->m_selectionGranularity != CharacterGranularity)
765 newSelection.expandUsingGranularity(d->m_selectionGranularity);
767 if (shouldChangeSelection(newSelection))
768 selectionController()->setSelection(newSelection);
771 void Frame::handleMouseReleaseEvent(const MouseEventWithHitTestResults& event)
773 stopAutoscrollTimer();
775 // Used to prevent mouseMoveEvent from initiating a drag before
776 // the mouse is pressed again.
777 d->m_bMousePressed = false;
779 // Clear the selection if the mouse didn't move after the last mouse press.
780 // We do this so when clicking on the selection, the selection goes away.
781 // However, if we are editing, place the caret.
782 if (mouseDownMayStartSelect() && !d->m_beganSelectingText
783 && d->m_dragStartPos == event.event().pos()
784 && selectionController()->isRange()) {
785 Selection newSelection;
786 Node *node = event.targetNode();
787 if (node && node->isContentEditable() && node->renderer()) {
788 IntPoint vPoint = view()->windowToContents(event.event().pos());
789 VisiblePosition pos = node->renderer()->positionForPoint(vPoint);
790 newSelection = Selection(pos);
792 if (shouldChangeSelection(newSelection))
793 selectionController()->setSelection(newSelection);
796 notifyRendererOfSelectionChange(true);
798 selectionController()->selectFrameElementInParentIfFullySelected();
801 bool Frame::shouldChangeSelection(const Selection& newSelection) const
803 return shouldChangeSelection(selectionController()->selection(), newSelection, newSelection.affinity(), false);
806 bool Frame::shouldDeleteSelection(const Selection& newSelection) const
811 bool Frame::isContentEditable() const
815 return d->m_doc->inDesignMode();
818 void Frame::textFieldDidBeginEditing(Element* input)
822 void Frame::textFieldDidEndEditing(Element* input)
826 void Frame::textDidChangeInTextField(Element* input)
830 bool Frame::doTextFieldCommandFromEvent(Element*, KeyboardEvent*)
835 void Frame::textWillBeDeletedInTextField(Element* input)
839 void Frame::textDidChangeInTextArea(Element* input)
843 CSSMutableStyleDeclaration *Frame::typingStyle() const
845 return d->m_typingStyle.get();
848 void Frame::setTypingStyle(CSSMutableStyleDeclaration *style)
850 d->m_typingStyle = style;
853 void Frame::clearTypingStyle()
855 d->m_typingStyle = 0;
858 bool Frame::tabsToLinks(KeyboardEvent*) const
863 bool Frame::tabsToAllControls(KeyboardEvent*) const
868 void Frame::copyToPasteboard()
873 void Frame::cutToPasteboard()
878 void Frame::pasteFromPasteboard()
883 void Frame::pasteAndMatchStyle()
885 issuePasteAndMatchStyleCommand();
888 void Frame::transpose()
890 issueTransposeCommand();
904 void Frame::computeAndSetTypingStyle(CSSStyleDeclaration *style, EditAction editingAction)
906 if (!style || style->length() == 0) {
911 // Calculate the current typing style.
912 RefPtr<CSSMutableStyleDeclaration> mutableStyle = style->makeMutable();
914 typingStyle()->merge(mutableStyle.get());
915 mutableStyle = typingStyle();
918 Node *node = selectionController()->selection().visibleStart().deepEquivalent().node();
919 CSSComputedStyleDeclaration computedStyle(node);
920 computedStyle.diff(mutableStyle.get());
922 // Handle block styles, substracting these from the typing style.
923 RefPtr<CSSMutableStyleDeclaration> blockStyle = mutableStyle->copyBlockProperties();
924 blockStyle->diff(mutableStyle.get());
925 if (document() && blockStyle->length() > 0)
926 applyCommand(new ApplyStyleCommand(document(), blockStyle.get(), editingAction));
928 // Set the remaining style as the typing style.
929 d->m_typingStyle = mutableStyle.release();
932 static void updateState(CSSMutableStyleDeclaration *desiredStyle, CSSComputedStyleDeclaration *computedStyle, bool& atStart, Frame::TriState& state)
934 DeprecatedValueListConstIterator<CSSProperty> end;
935 for (DeprecatedValueListConstIterator<CSSProperty> it = desiredStyle->valuesIterator(); it != end; ++it) {
936 int propertyID = (*it).id();
937 String desiredProperty = desiredStyle->getPropertyValue(propertyID);
938 String computedProperty = computedStyle->getPropertyValue(propertyID);
939 Frame::TriState propertyState = equalIgnoringCase(desiredProperty, computedProperty)
940 ? Frame::trueTriState : Frame::falseTriState;
942 state = propertyState;
944 } else if (state != propertyState) {
945 state = Frame::mixedTriState;
951 Frame::TriState Frame::selectionHasStyle(CSSStyleDeclaration *style) const
954 TriState state = falseTriState;
956 RefPtr<CSSMutableStyleDeclaration> mutableStyle = style->makeMutable();
958 if (!selectionController()->isRange()) {
960 RefPtr<CSSComputedStyleDeclaration> selectionStyle = selectionComputedStyle(nodeToRemove);
962 return falseTriState;
963 updateState(mutableStyle.get(), selectionStyle.get(), atStart, state);
965 ExceptionCode ec = 0;
966 nodeToRemove->remove(ec);
970 for (Node* node = selectionController()->start().node(); node; node = node->traverseNextNode()) {
971 RefPtr<CSSComputedStyleDeclaration> computedStyle = new CSSComputedStyleDeclaration(node);
973 updateState(mutableStyle.get(), computedStyle.get(), atStart, state);
974 if (state == mixedTriState)
976 if (node == selectionController()->end().node())
984 String Frame::selectionStartStylePropertyValue(int stylePropertyID) const
987 RefPtr<CSSStyleDeclaration> selectionStyle = selectionComputedStyle(nodeToRemove);
991 String value = selectionStyle->getPropertyValue(stylePropertyID);
994 ExceptionCode ec = 0;
995 nodeToRemove->remove(ec);
1002 CSSComputedStyleDeclaration *Frame::selectionComputedStyle(Node *&nodeToRemove) const
1009 if (selectionController()->isNone())
1012 RefPtr<Range> range(selectionController()->toRange());
1013 Position pos = range->editingStartPosition();
1015 Element *elem = pos.element();
1019 RefPtr<Element> styleElement = elem;
1020 ExceptionCode ec = 0;
1022 if (d->m_typingStyle) {
1023 styleElement = document()->createElementNS(xhtmlNamespaceURI, "span", ec);
1026 styleElement->setAttribute(styleAttr, d->m_typingStyle->cssText().impl(), ec);
1029 styleElement->appendChild(document()->createEditingTextNode(""), ec);
1032 if (elem->renderer() && elem->renderer()->canHaveChildren()) {
1033 elem->appendChild(styleElement, ec);
1035 Node *parent = elem->parent();
1036 Node *next = elem->nextSibling();
1039 parent->insertBefore(styleElement, next, ec);
1041 parent->appendChild(styleElement, ec);
1046 nodeToRemove = styleElement.get();
1049 return new CSSComputedStyleDeclaration(styleElement);
1052 void Frame::applyEditingStyleToBodyElement() const
1057 RefPtr<NodeList> list = d->m_doc->getElementsByTagName("body");
1058 unsigned len = list->length();
1059 for (unsigned i = 0; i < len; i++) {
1060 applyEditingStyleToElement(static_cast<Element*>(list->item(i)));
1064 void Frame::removeEditingStyleFromBodyElement() const
1069 RefPtr<NodeList> list = d->m_doc->getElementsByTagName("body");
1070 unsigned len = list->length();
1071 for (unsigned i = 0; i < len; i++) {
1072 removeEditingStyleFromElement(static_cast<Element*>(list->item(i)));
1076 void Frame::applyEditingStyleToElement(Element* element) const
1081 CSSStyleDeclaration* style = element->style();
1084 ExceptionCode ec = 0;
1085 style->setProperty(CSS_PROP_WORD_WRAP, "break-word", false, ec);
1087 style->setProperty(CSS_PROP__WEBKIT_NBSP_MODE, "space", false, ec);
1089 style->setProperty(CSS_PROP__WEBKIT_LINE_BREAK, "after-white-space", false, ec);
1093 void Frame::removeEditingStyleFromElement(Element*) const
1097 bool Frame::isCharacterSmartReplaceExempt(UChar, bool)
1104 static HashSet<Frame*> lifeSupportSet;
1107 void Frame::endAllLifeSupport()
1110 HashSet<Frame*> lifeSupportCopy = lifeSupportSet;
1111 HashSet<Frame*>::iterator end = lifeSupportCopy.end();
1112 for (HashSet<Frame*>::iterator it = lifeSupportCopy.begin(); it != end; ++it)
1113 (*it)->endLifeSupport();
1117 void Frame::keepAlive()
1119 if (d->m_lifeSupportTimer.isActive())
1123 lifeSupportSet.add(this);
1125 d->m_lifeSupportTimer.startOneShot(0);
1128 void Frame::endLifeSupport()
1130 if (!d->m_lifeSupportTimer.isActive())
1132 d->m_lifeSupportTimer.stop();
1134 lifeSupportSet.remove(this);
1139 void Frame::lifeSupportTimerFired(Timer<Frame>*)
1142 lifeSupportSet.remove(this);
1147 bool Frame::mouseDownMayStartAutoscroll() const
1149 return d->m_mouseDownMayStartAutoscroll;
1152 void Frame::setMouseDownMayStartAutoscroll(bool b)
1154 d->m_mouseDownMayStartAutoscroll = b;
1157 bool Frame::mouseDownMayStartDrag() const
1159 return d->m_mouseDownMayStartDrag;
1162 void Frame::setMouseDownMayStartDrag(bool b)
1164 d->m_mouseDownMayStartDrag = b;
1167 void Frame::setSettings(Settings *settings)
1169 d->m_settings = settings;
1172 RenderObject *Frame::renderer() const
1174 Document *doc = document();
1175 return doc ? doc->renderer() : 0;
1178 Element* Frame::ownerElement()
1180 return d->m_ownerElement;
1183 RenderPart* Frame::ownerRenderer()
1185 Element* ownerElement = d->m_ownerElement;
1188 return static_cast<RenderPart*>(ownerElement->renderer());
1191 IntRect Frame::selectionRect() const
1193 RenderView *root = static_cast<RenderView*>(renderer());
1197 return root->selectionRect();
1200 // returns FloatRect because going through IntRect would truncate any floats
1201 FloatRect Frame::visibleSelectionRect() const
1206 return intersection(selectionRect(), d->m_view->visibleContentRect());
1209 bool Frame::isFrameSet() const
1211 Document* document = d->m_doc.get();
1212 if (!document || !document->isHTMLDocument())
1214 Node *body = static_cast<HTMLDocument*>(document)->body();
1215 return body && body->renderer() && body->hasTagName(framesetTag);
1218 // Scans logically forward from "start", including any child frames
1219 static HTMLFormElement *scanForForm(Node *start)
1222 for (n = start; n; n = n->traverseNextNode()) {
1223 if (n->hasTagName(formTag))
1224 return static_cast<HTMLFormElement*>(n);
1225 else if (n->isHTMLElement() && static_cast<HTMLElement*>(n)->isGenericFormElement())
1226 return static_cast<HTMLGenericFormElement*>(n)->form();
1227 else if (n->hasTagName(frameTag) || n->hasTagName(iframeTag)) {
1228 Node *childDoc = static_cast<HTMLFrameElementBase*>(n)->contentDocument();
1229 if (HTMLFormElement *frameResult = scanForForm(childDoc))
1236 // We look for either the form containing the current focus, or for one immediately after it
1237 HTMLFormElement *Frame::currentForm() const
1239 // start looking either at the active (first responder) node, or where the selection is
1240 Node *start = d->m_doc ? d->m_doc->focusNode() : 0;
1242 start = selectionController()->start().node();
1244 // try walking up the node tree to find a form element
1246 for (n = start; n; n = n->parentNode()) {
1247 if (n->hasTagName(formTag))
1248 return static_cast<HTMLFormElement*>(n);
1249 else if (n->isHTMLElement()
1250 && static_cast<HTMLElement*>(n)->isGenericFormElement())
1251 return static_cast<HTMLGenericFormElement*>(n)->form();
1254 // try walking forward in the node tree to find a form element
1255 return start ? scanForForm(start) : 0;
1258 // FIXME: should this go in SelectionController?
1259 void Frame::revealSelection(const RenderLayer::ScrollAlignment& alignment) const
1263 switch (selectionController()->state()) {
1264 case Selection::NONE:
1267 case Selection::CARET:
1268 rect = selectionController()->caretRect();
1271 case Selection::RANGE:
1272 rect = selectionRect();
1276 Position start = selectionController()->start();
1277 Position end = selectionController()->end();
1279 ASSERT(start.node());
1280 if (start.node() && start.node()->renderer()) {
1281 RenderLayer *layer = start.node()->renderer()->enclosingLayer();
1283 ASSERT(!end.node() || !end.node()->renderer()
1284 || (end.node()->renderer()->enclosingLayer() == layer));
1285 layer->scrollRectToVisible(rect, alignment, alignment);
1290 void Frame::revealCaret(const RenderLayer::ScrollAlignment& alignment) const
1292 if (selectionController()->isNone())
1295 Position extent = selectionController()->extent();
1296 if (extent.node() && extent.node()->renderer()) {
1297 IntRect extentRect = VisiblePosition(extent).caretRect();
1298 RenderLayer* layer = extent.node()->renderer()->enclosingLayer();
1300 layer->scrollRectToVisible(extentRect, alignment, alignment);
1304 // FIXME: should this be here?
1305 bool Frame::scrollOverflow(ScrollDirection direction, ScrollGranularity granularity)
1311 Node *node = document()->focusNode();
1313 node = d->m_mousePressNode.get();
1317 RenderObject *r = node->renderer();
1318 if (r != 0 && !r->isListBox()) {
1319 return r->scroll(direction, granularity);
1326 void Frame::handleAutoscroll(RenderObject* renderer)
1328 if (d->m_autoscrollTimer.isActive())
1330 setAutoscrollRenderer(renderer);
1331 startAutoscrollTimer();
1334 void Frame::autoscrollTimerFired(Timer<Frame>*)
1336 if (!d->m_bMousePressed){
1337 stopAutoscrollTimer();
1340 if (RenderObject* r = autoscrollRenderer())
1344 RenderObject* Frame::autoscrollRenderer() const
1346 return d->m_autoscrollRenderer;
1349 void Frame::setAutoscrollRenderer(RenderObject* renderer)
1351 d->m_autoscrollRenderer = renderer;
1354 HitTestResult Frame::hitTestResultAtPoint(const IntPoint& point, bool allowShadowContent)
1356 HitTestResult result(point);
1359 renderer()->layer()->hitTest(HitTestRequest(true, true), result);
1361 IntPoint widgetPoint(point);
1363 Node* n = result.innerNode();
1364 if (!n || !n->renderer() || !n->renderer()->isWidget())
1366 Widget* widget = static_cast<RenderWidget*>(n->renderer())->widget();
1367 if (!widget || !widget->isFrameView())
1369 Frame* frame = static_cast<HTMLFrameElementBase*>(n)->contentFrame();
1370 if (!frame || !frame->renderer())
1373 n->renderer()->absolutePosition(absX, absY, true);
1374 FrameView* view = static_cast<FrameView*>(widget);
1375 widgetPoint.move(view->contentsX() - absX, view->contentsY() - absY);
1376 HitTestResult widgetHitTestResult(widgetPoint);
1377 frame->renderer()->layer()->hitTest(HitTestRequest(true, true), widgetHitTestResult);
1378 result = widgetHitTestResult;
1381 if (!allowShadowContent) {
1382 Node* node = result.innerNode();
1384 node = node->shadowAncestorNode();
1385 result.setInnerNode(node);
1386 node = result.innerNonSharedNode();
1388 node = node->shadowAncestorNode();
1389 result.setInnerNonSharedNode(node);
1396 void Frame::startAutoscrollTimer()
1398 d->m_autoscrollTimer.startRepeating(autoscrollInterval);
1401 void Frame::stopAutoscrollTimer(bool rendererIsBeingDestroyed)
1403 if (!rendererIsBeingDestroyed && autoscrollRenderer())
1404 autoscrollRenderer()->stopAutoscroll();
1405 setAutoscrollRenderer(0);
1406 d->m_autoscrollTimer.stop();
1409 // FIXME: why is this here instead of on the FrameView?
1410 void Frame::paint(GraphicsContext* p, const IntRect& rect)
1414 if (!document() || document()->printing())
1415 fillWithRed = false; // Printing, don't fill with red (can't remember why).
1416 else if (document()->ownerElement())
1417 fillWithRed = false; // Subframe, don't fill with red.
1418 else if (view() && view()->isTransparent())
1419 fillWithRed = false; // Transparent, don't fill with red.
1420 else if (d->m_paintRestriction == PaintRestrictionSelectionOnly || d->m_paintRestriction == PaintRestrictionSelectionOnlyWhiteText)
1421 fillWithRed = false; // Selections are transparent, don't fill with red.
1422 else if (d->m_elementToDraw)
1423 fillWithRed = false; // Element images are transparent, don't fill with red.
1428 p->fillRect(rect, Color(0xFF, 0, 0));
1432 // d->m_elementToDraw is used to draw only one element
1433 RenderObject *eltRenderer = d->m_elementToDraw ? d->m_elementToDraw->renderer() : 0;
1434 if (d->m_paintRestriction == PaintRestrictionNone)
1435 renderer()->document()->invalidateRenderedRectsForMarkersInRect(rect);
1436 renderer()->layer()->paint(p, rect, d->m_paintRestriction, eltRenderer);
1439 // Regions may have changed as a result of the visibility/z-index of element changing.
1440 if (renderer()->document()->dashboardRegionsDirty())
1441 renderer()->view()->frameView()->updateDashboardRegions();
1444 LOG_ERROR("called Frame::paint with nil renderer");
1449 void Frame::adjustPageHeight(float *newBottom, float oldTop, float oldBottom, float bottomLimit)
1451 RenderView *root = static_cast<RenderView*>(document()->renderer());
1453 // Use a context with painting disabled.
1454 GraphicsContext context((PlatformGraphicsContext*)0);
1455 root->setTruncatedAt((int)floorf(oldBottom));
1456 IntRect dirtyRect(0, (int)floorf(oldTop), root->docWidth(), (int)ceilf(oldBottom - oldTop));
1457 root->layer()->paint(&context, dirtyRect);
1458 *newBottom = root->bestTruncatedAt();
1459 if (*newBottom == 0)
1460 *newBottom = oldBottom;
1462 *newBottom = oldBottom;
1467 Frame *Frame::frameForWidget(const Widget *widget)
1469 ASSERT_ARG(widget, widget);
1471 Node *node = nodeForWidget(widget);
1473 return frameForNode(node);
1475 // Assume all widgets are either form controls, or FrameViews.
1476 ASSERT(widget->isFrameView());
1477 return static_cast<const FrameView*>(widget)->frame();
1480 Frame *Frame::frameForNode(Node *node)
1482 ASSERT_ARG(node, node);
1483 return node->document()->frame();
1486 Node* Frame::nodeForWidget(const Widget* widget)
1488 ASSERT_ARG(widget, widget);
1489 WidgetClient* client = widget->client();
1492 return client->element(const_cast<Widget*>(widget));
1495 void Frame::clearDocumentFocus(Widget *widget)
1497 Node *node = nodeForWidget(widget);
1499 node->document()->setFocusNode(0);
1502 void Frame::forceLayout()
1504 FrameView *v = d->m_view.get();
1507 // We cannot unschedule a pending relayout, since the force can be called with
1508 // a tiny rectangle from a drawRect update. By unscheduling we in effect
1509 // "validate" and stop the necessary full repaint from occurring. Basically any basic
1510 // append/remove DHTML is broken by this call. For now, I have removed the optimization
1511 // until we have a better invalidation stategy. -dwh
1512 //v->unscheduleRelayout();
1516 void Frame::forceLayoutWithPageWidthRange(float minPageWidth, float maxPageWidth)
1518 // Dumping externalRepresentation(m_frame->renderer()).ascii() is a good trick to see
1519 // the state of things before and after the layout
1520 RenderView *root = static_cast<RenderView*>(document()->renderer());
1522 // This magic is basically copied from khtmlview::print
1523 int pageW = (int)ceilf(minPageWidth);
1524 root->setWidth(pageW);
1525 root->setNeedsLayoutAndMinMaxRecalc();
1528 // If we don't fit in the minimum page width, we'll lay out again. If we don't fit in the
1529 // maximum page width, we will lay out to the maximum page width and clip extra content.
1530 // FIXME: We are assuming a shrink-to-fit printing implementation. A cropping
1531 // implementation should not do this!
1532 int rightmostPos = root->rightmostPosition();
1533 if (rightmostPos > minPageWidth) {
1534 pageW = min(rightmostPos, (int)ceilf(maxPageWidth));
1535 root->setWidth(pageW);
1536 root->setNeedsLayoutAndMinMaxRecalc();
1542 void Frame::sendResizeEvent()
1544 if (Document* doc = document())
1545 doc->dispatchWindowEvent(EventNames::resizeEvent, false, false);
1548 void Frame::sendScrollEvent()
1550 FrameView *v = d->m_view.get();
1552 Document *doc = document();
1555 doc->dispatchHTMLEvent(scrollEvent, true, false);
1559 bool Frame::canMouseDownStartSelect(Node* node)
1561 if (!node || !node->renderer())
1564 // Check to see if -webkit-user-select has been set to none
1565 if (!node->renderer()->canSelect())
1568 // Some controls and images can't start a select on a mouse down.
1569 for (RenderObject* curr = node->renderer(); curr; curr = curr->parent()) {
1570 if (curr->style()->userSelect() == SELECT_IGNORE)
1577 void Frame::clearTimers(FrameView *view)
1580 view->unscheduleRelayout();
1581 if (view->frame()) {
1582 Document* document = view->frame()->document();
1583 if (document && document->renderer() && document->renderer()->layer())
1584 document->renderer()->layer()->suspendMarquees();
1589 void Frame::clearTimers()
1591 clearTimers(d->m_view.get());
1594 RenderStyle *Frame::styleForSelectionStart(Node *&nodeToRemove) const
1600 if (selectionController()->isNone())
1603 Position pos = selectionController()->selection().visibleStart().deepEquivalent();
1604 if (!pos.inRenderedContent())
1606 Node *node = pos.node();
1610 if (!d->m_typingStyle)
1611 return node->renderer()->style();
1613 ExceptionCode ec = 0;
1614 RefPtr<Element> styleElement = document()->createElementNS(xhtmlNamespaceURI, "span", ec);
1617 styleElement->setAttribute(styleAttr, d->m_typingStyle->cssText().impl(), ec);
1620 styleElement->appendChild(document()->createEditingTextNode(""), ec);
1623 node->parentNode()->appendChild(styleElement, ec);
1626 nodeToRemove = styleElement.get();
1627 return styleElement->renderer()->style();
1630 void Frame::setSelectionFromNone()
1632 // Put a caret inside the body if the entire frame is editable (either the
1633 // entire WebView is editable or designMode is on for this document).
1634 Document *doc = document();
1635 if (!doc || !selectionController()->isNone() || !isContentEditable())
1638 Node* node = doc->documentElement();
1639 while (node && !node->hasTagName(bodyTag))
1640 node = node->traverseNextNode();
1642 selectionController()->setSelection(Selection(Position(node, 0), DOWNSTREAM));
1645 bool Frame::isActive() const
1647 return d->m_isActive;
1650 void Frame::setIsActive(bool flag)
1652 if (d->m_isActive == flag)
1655 d->m_isActive = flag;
1657 // This method does the job of updating the view based on whether the view is "active".
1658 // This involves three kinds of drawing updates:
1660 // 1. The background color used to draw behind selected content (active | inactive color)
1662 d->m_view->updateContents(enclosingIntRect(visibleSelectionRect()));
1664 // 2. Caret blinking (blinks | does not blink)
1666 setSelectionFromNone();
1667 setCaretVisible(flag);
1669 // 3. The drawing of a focus ring around links in web pages.
1670 Document *doc = document();
1672 Node *node = doc->focusNode();
1675 if (node->renderer() && node->renderer()->style()->hasAppearance())
1676 theme()->stateChanged(node->renderer(), FocusState);
1680 // 4. Changing the tint of controls from clear to aqua/graphite and vice versa. We
1681 // do a "fake" paint. When the theme gets a paint call, it can then do an invalidate. This is only
1682 // done if the theme supports control tinting.
1683 if (doc && d->m_view && theme()->supportsControlTints() && renderer()) {
1684 doc->updateLayout(); // Ensure layout is up to date.
1685 IntRect visibleRect(enclosingIntRect(d->m_view->visibleContentRect()));
1686 GraphicsContext context((PlatformGraphicsContext*)0);
1687 context.setUpdatingControlTints(true);
1688 paint(&context, visibleRect);
1691 // 5. Enable or disable secure keyboard entry
1692 if ((flag && !isSecureKeyboardEntry() && doc && doc->focusNode() && doc->focusNode()->hasTagName(inputTag) &&
1693 static_cast<HTMLInputElement*>(doc->focusNode())->inputType() == HTMLInputElement::PASSWORD) ||
1694 (!flag && isSecureKeyboardEntry()))
1695 setSecureKeyboardEntry(flag);
1698 void Frame::setWindowHasFocus(bool flag)
1700 if (d->m_windowHasFocus == flag)
1702 d->m_windowHasFocus = flag;
1704 if (Document *doc = document())
1705 doc->dispatchWindowEvent(flag ? focusEvent : blurEvent, false, false);
1708 bool Frame::inViewSourceMode() const
1710 return d->m_inViewSourceMode;
1713 void Frame::setInViewSourceMode(bool mode) const
1715 d->m_inViewSourceMode = mode;
1718 UChar Frame::backslashAsCurrencySymbol() const
1720 Document *doc = document();
1723 TextResourceDecoder *decoder = doc->decoder();
1727 return decoder->encoding().backslashAsCurrencySymbol();
1730 bool Frame::markedTextUsesUnderlines() const
1732 return d->m_markedTextUsesUnderlines;
1735 const Vector<MarkedTextUnderline>& Frame::markedTextUnderlines() const
1737 return d->m_markedTextUnderlines;
1740 // Searches from the beginning of the document if nothing is selected.
1741 bool Frame::findString(const String& target, bool forward, bool caseFlag, bool wrapFlag)
1743 if (target.isEmpty())
1746 // Initially search from the start (if forward) or end (if backward) of the selection, and search to edge of document.
1747 RefPtr<Range> searchRange(rangeOfContents(document()));
1748 Selection selection(selectionController()->selection());
1749 if (!selection.isNone()) {
1751 setStart(searchRange.get(), selection.visibleStart());
1753 setEnd(searchRange.get(), selection.visibleEnd());
1755 RefPtr<Range> resultRange(findPlainText(searchRange.get(), target, forward, caseFlag));
1756 // If the found range is already selected, find again.
1757 // Build a selection with the found range to remove collapsed whitespace.
1758 // Compare ranges instead of selection objects to ignore the way that the current selection was made.
1759 if (!selection.isNone() && *Selection(resultRange.get()).toRange() == *selection.toRange()) {
1760 searchRange = rangeOfContents(document());
1762 setStart(searchRange.get(), selection.visibleEnd());
1764 setEnd(searchRange.get(), selection.visibleStart());
1765 resultRange = findPlainText(searchRange.get(), target, forward, caseFlag);
1770 // If we didn't find anything and we're wrapping, search again in the entire document (this will
1771 // redundantly re-search the area already searched in some cases).
1772 if (resultRange->collapsed(exception) && wrapFlag) {
1773 searchRange = rangeOfContents(document());
1774 resultRange = findPlainText(searchRange.get(), target, forward, caseFlag);
1775 // We used to return false here if we ended up with the same range that we started with
1776 // (e.g., the selection was already the only instance of this text). But we decided that
1777 // this should be a success case instead, so we'll just fall through in that case.
1780 if (resultRange->collapsed(exception))
1783 selectionController()->setSelection(Selection(resultRange.get(), DOWNSTREAM));
1788 unsigned Frame::markAllMatchesForText(const String& target, bool caseFlag, unsigned limit)
1790 if (target.isEmpty())
1793 RefPtr<Range> searchRange(rangeOfContents(document()));
1796 unsigned matchCount = 0;
1798 RefPtr<Range> resultRange(findPlainText(searchRange.get(), target, true, caseFlag));
1799 if (resultRange->collapsed(exception))
1802 // A non-collapsed result range can in some funky whitespace cases still not
1803 // advance the range's start position (4509328). Break to avoid infinite loop.
1804 VisiblePosition newStart = endVisiblePosition(resultRange.get(), DOWNSTREAM);
1805 if (newStart == startVisiblePosition(searchRange.get(), DOWNSTREAM))
1810 document()->addMarker(resultRange.get(), DocumentMarker::TextMatch);
1812 // Stop looking if we hit the specified limit. A limit of 0 means no limit.
1813 if (limit > 0 && matchCount >= limit)
1816 setStart(searchRange.get(), newStart);
1819 // Do a "fake" paint in order to execute the code that computes the rendered rect for
1821 Document* doc = document();
1822 if (doc && d->m_view && renderer()) {
1823 doc->updateLayout(); // Ensure layout is up to date.
1824 IntRect visibleRect(enclosingIntRect(d->m_view->visibleContentRect()));
1825 GraphicsContext context((PlatformGraphicsContext*)0);
1826 context.setPaintingDisabled(true);
1827 paint(&context, visibleRect);
1833 bool Frame::markedTextMatchesAreHighlighted() const
1835 return d->m_highlightTextMatches;
1838 void Frame::setMarkedTextMatchesAreHighlighted(bool flag)
1840 if (flag == d->m_highlightTextMatches)
1843 d->m_highlightTextMatches = flag;
1844 document()->repaintMarkers(DocumentMarker::TextMatch);
1847 Node *Frame::mousePressNode()
1849 return d->m_mousePressNode.get();
1852 FrameTree* Frame::tree() const
1854 return &d->m_treeNode;
1857 DOMWindow* Frame::domWindow() const
1859 if (!d->m_domWindow)
1860 d->m_domWindow = new DOMWindow(const_cast<Frame*>(this));
1862 return d->m_domWindow.get();
1865 Page* Frame::page() const
1870 void Frame::pageDestroyed()
1874 // This will stop any JS timers
1875 if (d->m_jscript && d->m_jscript->haveInterpreter())
1876 if (Window* w = Window::retrieveWindow(this))
1877 w->disconnectFrame();
1880 void Frame::setStatusBarText(const String&)
1884 void Frame::disconnectOwnerElement()
1886 if (d->m_ownerElement && d->m_page)
1887 d->m_page->decrementFrameCount();
1889 d->m_ownerElement = 0;
1892 String Frame::documentTypeString() const
1894 if (Document *doc = document())
1895 if (DocumentType *doctype = doc->realDocType())
1896 return doctype->toString();
1901 bool Frame::prohibitsScrolling() const
1903 return d->m_prohibitsScrolling;
1906 void Frame::setProhibitsScrolling(const bool prohibit)
1908 d->m_prohibitsScrolling = prohibit;
1911 FramePrivate::FramePrivate(Page* page, Frame* parent, Frame* thisFrame, Element* ownerElement, PassRefPtr<EditorClient> client)
1913 , m_treeNode(thisFrame, parent)
1914 , m_ownerElement(ownerElement)
1916 , m_bJScriptEnabled(true)
1917 , m_bJavaEnabled(true)
1918 , m_bPluginsEnabled(true)
1920 , m_zoomFactor(parent ? parent->d->m_zoomFactor : 100)
1921 , m_bMousePressed(false)
1922 , m_beganSelectingText(false)
1923 , m_selectionController(thisFrame)
1924 , m_caretBlinkTimer(thisFrame, &Frame::caretBlinkTimerFired)
1925 , m_editor(thisFrame, client)
1926 , m_caretVisible(false)
1927 , m_caretPaint(true)
1929 , m_lifeSupportTimer(thisFrame, &Frame::lifeSupportTimerFired)
1930 , m_loader(new FrameLoader(thisFrame))
1931 , m_userStyleSheetLoader(0)
1932 , m_autoscrollTimer(thisFrame, &Frame::autoscrollTimerFired)
1933 , m_autoscrollRenderer(0)
1934 , m_mouseDownMayStartAutoscroll(false)
1935 , m_mouseDownMayStartDrag(false)
1936 , m_paintRestriction(PaintRestrictionNone)
1937 , m_markedTextUsesUnderlines(false)
1938 , m_highlightTextMatches(false)
1939 , m_windowHasFocus(false)
1940 , m_inViewSourceMode(false)
1942 , m_prohibitsScrolling(false)
1946 FramePrivate::~FramePrivate()
1952 } // namespace WebCore