summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/webkit/WebCore/page/Frame.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/webkit/WebCore/page/Frame.cpp')
-rw-r--r--src/3rdparty/webkit/WebCore/page/Frame.cpp193
1 files changed, 93 insertions, 100 deletions
diff --git a/src/3rdparty/webkit/WebCore/page/Frame.cpp b/src/3rdparty/webkit/WebCore/page/Frame.cpp
index 870bd2ae4..2d6a7950e 100644
--- a/src/3rdparty/webkit/WebCore/page/Frame.cpp
+++ b/src/3rdparty/webkit/WebCore/page/Frame.cpp
@@ -42,21 +42,20 @@
#include "EditingText.h"
#include "EditorClient.h"
#include "EventNames.h"
-#include "FocusController.h"
#include "FloatQuad.h"
+#include "FocusController.h"
#include "FrameLoader.h"
#include "FrameLoaderClient.h"
#include "FrameView.h"
#include "GraphicsContext.h"
#include "HTMLDocument.h"
+#include "HTMLFormControlElement.h"
#include "HTMLFormElement.h"
#include "HTMLFrameElementBase.h"
-#include "HTMLFormControlElement.h"
#include "HTMLNames.h"
#include "HTMLTableCellElement.h"
#include "HitTestResult.h"
#include "Logging.h"
-#include "markup.h"
#include "MediaFeatureNames.h"
#include "Navigator.h"
#include "NodeList.h"
@@ -67,12 +66,13 @@
#include "RenderTextControl.h"
#include "RenderTheme.h"
#include "RenderView.h"
+#include "ScriptController.h"
#include "Settings.h"
#include "TextIterator.h"
#include "TextResourceDecoder.h"
#include "XMLNames.h"
-#include "ScriptController.h"
#include "htmlediting.h"
+#include "markup.h"
#include "npruntime_impl.h"
#include "visible_units.h"
#include <wtf/RefCountedLeakCounter.h>
@@ -104,7 +104,7 @@ namespace WebCore {
using namespace HTMLNames;
-#ifndef NDEBUG
+#ifndef NDEBUG
static WTF::RefCountedLeakCounter frameCounter("Frame");
#endif
@@ -115,7 +115,7 @@ static inline Frame* parentFromOwnerElement(HTMLFrameOwnerElement* ownerElement)
return ownerElement->document()->frame();
}
-Frame::Frame(Page* page, HTMLFrameOwnerElement* ownerElement, FrameLoaderClient* frameLoaderClient)
+Frame::Frame(Page* page, HTMLFrameOwnerElement* ownerElement, FrameLoaderClient* frameLoaderClient)
: m_page(page)
, m_treeNode(this, parentFromOwnerElement(ownerElement))
, m_loader(this, frameLoaderClient)
@@ -163,7 +163,7 @@ Frame::Frame(Page* page, HTMLFrameOwnerElement* ownerElement, FrameLoaderClient*
else {
page->incrementFrameCount();
// Make sure we will not end up with two frames referencing the same owner element.
- ASSERT((!(ownerElement->m_contentFrame)) || (ownerElement->m_contentFrame->ownerElement() != ownerElement));
+ ASSERT((!(ownerElement->m_contentFrame)) || (ownerElement->m_contentFrame->ownerElement() != ownerElement));
ownerElement->m_contentFrame = this;
}
@@ -176,7 +176,7 @@ Frame::~Frame()
{
setView(0);
loader()->cancelAndClear();
-
+
// FIXME: We should not be doing all this work inside the destructor
ASSERT(!m_lifeSupportTimer.isActive());
@@ -186,14 +186,14 @@ Frame::~Frame()
#endif
disconnectOwnerElement();
-
+
if (m_domWindow)
m_domWindow->disconnectFrame();
HashSet<DOMWindow*>::iterator end = m_liveFormerWindows.end();
for (HashSet<DOMWindow*>::iterator it = m_liveFormerWindows.begin(); it != end; ++it)
(*it)->disconnectFrame();
-
+
if (m_view) {
m_view->hide();
m_view->clearFrame();
@@ -262,7 +262,7 @@ void Frame::setDocument(PassRefPtr<Document> newDoc)
m_doc = newDoc;
if (m_doc && selection()->isFocusedAndActive())
setUseSecureKeyboardEntry(m_doc->useSecureKeyboardEntryWhenActive());
-
+
if (m_doc && !m_doc->attached())
m_doc->attach();
@@ -307,14 +307,14 @@ IntRect Frame::firstRectForRange(Range* range) const
if (startCaretRect.y() == endCaretRect.y()) {
// start and end are on the same line
- return IntRect(min(startCaretRect.x(), endCaretRect.x()),
- startCaretRect.y(),
+ return IntRect(min(startCaretRect.x(), endCaretRect.x()),
+ startCaretRect.y(),
abs(endCaretRect.x() - startCaretRect.x()),
max(startCaretRect.height(), endCaretRect.height()));
}
-
+
// start and end aren't on the same line, so go from start to the end of its line
- return IntRect(startCaretRect.x(),
+ return IntRect(startCaretRect.x(),
startCaretRect.y(),
startCaretRect.width() + extraWidthToEndOfLine,
startCaretRect.height());
@@ -365,23 +365,21 @@ static RegularExpression* createRegExpForLabels(const Vector<String>& labels)
bool startsWithWordChar = false;
bool endsWithWordChar = false;
- if (label.length() != 0) {
+ if (label.length()) {
startsWithWordChar = wordRegExp.match(label.substring(0, 1)) >= 0;
endsWithWordChar = wordRegExp.match(label.substring(label.length() - 1, 1)) >= 0;
}
-
- if (i != 0)
+
+ if (i)
pattern.append("|");
// Search for word boundaries only if label starts/ends with "word characters".
// If we always searched for word boundaries, this wouldn't work for languages
// such as Japanese.
- if (startsWithWordChar) {
+ if (startsWithWordChar)
pattern.append("\\b");
- }
pattern.append(label);
- if (endsWithWordChar) {
+ if (endsWithWordChar)
pattern.append("\\b");
- }
}
pattern.append(")");
return new RegularExpression(pattern, TextCaseInsensitive);
@@ -462,9 +460,8 @@ String Frame::searchForLabelsBeforeElement(const Vector<String>& labels, Element
// If we started in a cell, but bailed because we found the start of the form or the
// previous element, we still might need to search the row above us for a label.
- if (startingTableCell && !searchedCellAbove) {
+ if (startingTableCell && !searchedCellAbove)
return searchForLabelsAboveCell(regExp.get(), startingTableCell);
- }
return String();
}
@@ -477,7 +474,7 @@ String Frame::matchLabelsAgainstElement(const Vector<String>& labels, Element* e
// Make numbers and _'s in field names behave like word boundaries, e.g., "address2"
replace(name, RegularExpression("\\d", TextCaseSensitive), " ");
name.replace('_', ' ');
-
+
OwnPtr<RegularExpression> regExp(createRegExpForLabels(labels));
// Use the largest match we can find in the whole name string
int pos;
@@ -640,7 +637,7 @@ void Frame::selectionLayoutChanged()
return;
VisibleSelection selection = this->selection()->selection();
-
+
if (!selection.isRange())
view->clearSelection();
else {
@@ -654,7 +651,7 @@ void Frame::selectionLayoutChanged()
Position endPos = selection.end();
if (endPos.upstream().isCandidate())
endPos = endPos.upstream();
-
+
// We can get into a state where the selection endpoints map to the same VisiblePosition when a selection is deleted
// because we don't yet notify the SelectionController of text removal.
if (startPos.isNotNull() && endPos.isNotNull() && selection.visibleStart() != selection.visibleEnd()) {
@@ -729,12 +726,12 @@ bool Frame::shouldApplyPageZoom() const
}
void Frame::setZoomFactor(float percent, bool isTextOnly)
-{
+{
if (m_zoomFactor == percent && isZoomFactorTextOnly() == isTextOnly)
return;
#if ENABLE(SVG)
- // SVG doesn't care if the zoom factor is text only. It will always apply a
+ // SVG doesn't care if the zoom factor is text only. It will always apply a
// zoom to the whole SVG.
if (m_doc->isSVGDocument()) {
if (!static_cast<SVGDocument*>(m_doc.get())->zoomAndPanEnabled())
@@ -827,7 +824,7 @@ void Frame::reapplyStyles()
// FIXME: This call doesn't really make sense in a function called reapplyStyles.
// We should probably eventually move it into its own function.
m_doc->docLoader()->setAutoLoadImages(m_page && m_page->settings()->loadsImagesAutomatically());
-
+
#if FRAME_LOADS_USER_STYLESHEET
const KURL userStyleSheetLocation = m_page ? m_page->settings()->userStyleSheetLocation() : KURL();
if (!userStyleSheetLocation.isEmpty())
@@ -859,7 +856,7 @@ bool Frame::shouldDeleteSelection(const VisibleSelection& selection) const
return editor()->client()->shouldDeleteRange(selection.toNormalizedRange().get());
}
-bool Frame::isContentEditable() const
+bool Frame::isContentEditable() const
{
if (m_editor.clientIsEditable())
return true;
@@ -897,7 +894,7 @@ void Frame::clearTypingStyle()
void Frame::computeAndSetTypingStyle(CSSStyleDeclaration *style, EditAction editingAction)
{
- if (!style || style->length() == 0) {
+ if (!style || !style->length()) {
clearTypingStyle();
return;
}
@@ -933,7 +930,7 @@ void Frame::computeAndSetTypingStyle(CSSStyleDeclaration *style, EditAction edit
blockStyle->diff(mutableStyle.get());
if (blockStyle->length() > 0)
applyCommand(ApplyStyleCommand::create(document(), blockStyle.get(), editingAction));
-
+
// Set the remaining style as the typing style.
m_typingStyle = mutableStyle.release();
}
@@ -950,7 +947,7 @@ String Frame::selectionStartStylePropertyValue(int stylePropertyID) const
if (nodeToRemove) {
ExceptionCode ec = 0;
nodeToRemove->remove(ec);
- ASSERT(ec == 0);
+ ASSERT(!ec);
}
return value;
@@ -969,7 +966,7 @@ PassRefPtr<CSSComputedStyleDeclaration> Frame::selectionComputedStyle(Node*& nod
Element *elem = pos.element();
if (!elem)
return 0;
-
+
RefPtr<Element> styleElement = elem;
ExceptionCode ec = 0;
@@ -977,10 +974,10 @@ PassRefPtr<CSSComputedStyleDeclaration> Frame::selectionComputedStyle(Node*& nod
styleElement = document()->createElement(spanTag, false);
styleElement->setAttribute(styleAttr, m_typingStyle->cssText().impl(), ec);
- ASSERT(ec == 0);
-
+ ASSERT(!ec);
+
styleElement->appendChild(document()->createEditingTextNode(""), ec);
- ASSERT(ec == 0);
+ ASSERT(!ec);
if (elem->renderer() && elem->renderer()->canHaveChildren()) {
elem->appendChild(styleElement, ec);
@@ -988,13 +985,12 @@ PassRefPtr<CSSComputedStyleDeclaration> Frame::selectionComputedStyle(Node*& nod
Node *parent = elem->parent();
Node *next = elem->nextSibling();
- if (next) {
+ if (next)
parent->insertBefore(styleElement, next, ec);
- } else {
+ else
parent->appendChild(styleElement, ec);
- }
}
- ASSERT(ec == 0);
+ ASSERT(!ec);
nodeToRemove = styleElement.get();
}
@@ -1044,18 +1040,16 @@ void Frame::applyEditingStyleToBodyElement() const
{
RefPtr<NodeList> list = m_doc->getElementsByTagName("body");
unsigned len = list->length();
- for (unsigned i = 0; i < len; i++) {
- applyEditingStyleToElement(static_cast<Element*>(list->item(i)));
- }
+ for (unsigned i = 0; i < len; i++)
+ applyEditingStyleToElement(static_cast<Element*>(list->item(i)));
}
void Frame::removeEditingStyleFromBodyElement() const
{
RefPtr<NodeList> list = m_doc->getElementsByTagName("body");
unsigned len = list->length();
- for (unsigned i = 0; i < len; i++) {
- removeEditingStyleFromElement(static_cast<Element*>(list->item(i)));
- }
+ for (unsigned i = 0; i < len; i++)
+ removeEditingStyleFromElement(static_cast<Element*>(list->item(i)));
}
void Frame::applyEditingStyleToElement(Element* element) const
@@ -1068,11 +1062,11 @@ void Frame::applyEditingStyleToElement(Element* element) const
ExceptionCode ec = 0;
style->setProperty(CSSPropertyWordWrap, "break-word", false, ec);
- ASSERT(ec == 0);
+ ASSERT(!ec);
style->setProperty(CSSPropertyWebkitNbspMode, "space", false, ec);
- ASSERT(ec == 0);
+ ASSERT(!ec);
style->setProperty(CSSPropertyWebkitLineBreak, "after-white-space", false, ec);
- ASSERT(ec == 0);
+ ASSERT(!ec);
}
void Frame::removeEditingStyleFromElement(Element*) const
@@ -1189,7 +1183,7 @@ FloatRect Frame::selectionBounds(bool clipToVisibleContent) const
FrameView* view = m_view.get();
if (!root || !view)
return IntRect();
-
+
IntRect selectionRect = root->selectionBounds(clipToVisibleContent);
return clipToVisibleContent ? intersection(selectionRect, view->visibleContentRect()) : selectionRect;
}
@@ -1240,7 +1234,7 @@ HTMLFormElement *Frame::currentForm() const
Node *start = m_doc ? m_doc->focusedNode() : 0;
if (!start)
start = selection()->start().node();
-
+
// try walking up the node tree to find a form element
Node *n;
for (n = start; n; n = n->parentNode()) {
@@ -1249,7 +1243,7 @@ HTMLFormElement *Frame::currentForm() const
else if (n->isHTMLElement() && static_cast<Element*>(n)->isFormControlElement())
return static_cast<HTMLFormControlElement*>(n)->form();
}
-
+
// try walking forward in the node tree to find a form element
return start ? scanForForm(start) : 0;
}
@@ -1259,21 +1253,21 @@ void Frame::revealSelection(const ScrollAlignment& alignment, bool revealExtent)
IntRect rect;
switch (selection()->selectionType()) {
- case VisibleSelection::NoSelection:
- return;
- case VisibleSelection::CaretSelection:
- rect = selection()->absoluteCaretBounds();
- break;
- case VisibleSelection::RangeSelection:
- rect = revealExtent ? VisiblePosition(selection()->extent()).absoluteCaretBounds() : enclosingIntRect(selectionBounds(false));
- break;
+ case VisibleSelection::NoSelection:
+ return;
+ case VisibleSelection::CaretSelection:
+ rect = selection()->absoluteCaretBounds();
+ break;
+ case VisibleSelection::RangeSelection:
+ rect = revealExtent ? VisiblePosition(selection()->extent()).absoluteCaretBounds() : enclosingIntRect(selectionBounds(false));
+ break;
}
Position start = selection()->start();
ASSERT(start.node());
if (start.node() && start.node()->renderer()) {
// FIXME: This code only handles scrolling the startContainer's layer, but
- // the selection rect could intersect more than just that.
+ // the selection rect could intersect more than just that.
// See <rdar://problem/4799899>.
if (RenderLayer* layer = start.node()->renderer()->enclosingLayer())
layer->scrollRectToVisible(rect, false, alignment, alignment);
@@ -1313,46 +1307,46 @@ void Frame::clearTimers()
RenderStyle *Frame::styleForSelectionStart(Node *&nodeToRemove) const
{
nodeToRemove = 0;
-
+
if (selection()->isNone())
return 0;
-
+
Position pos = selection()->selection().visibleStart().deepEquivalent();
if (!pos.isCandidate())
return 0;
Node *node = pos.node();
if (!node)
return 0;
-
+
if (!m_typingStyle)
return node->renderer()->style();
-
+
RefPtr<Element> styleElement = document()->createElement(spanTag, false);
-
+
ExceptionCode ec = 0;
String styleText = m_typingStyle->cssText() + " display: inline";
styleElement->setAttribute(styleAttr, styleText.impl(), ec);
- ASSERT(ec == 0);
-
+ ASSERT(!ec);
+
styleElement->appendChild(document()->createEditingTextNode(""), ec);
- ASSERT(ec == 0);
-
+ ASSERT(!ec);
+
node->parentNode()->appendChild(styleElement, ec);
- ASSERT(ec == 0);
-
- nodeToRemove = styleElement.get();
+ ASSERT(!ec);
+
+ nodeToRemove = styleElement.get();
return styleElement->renderer() ? styleElement->renderer()->style() : 0;
}
void Frame::setSelectionFromNone()
{
- // Put a caret inside the body if the entire frame is editable (either the
+ // Put a caret inside the body if the entire frame is editable (either the
// entire WebView is editable or designMode is on for this document).
Document *doc = document();
bool caretBrowsing = settings() && settings()->caretBrowsingEnabled();
if (!selection()->isNone() || !(isContentEditable() || caretBrowsing))
return;
-
+
Node* node = doc->documentElement();
while (node && !node->hasTagName(bodyTag))
node = node->traverseNextNode();
@@ -1375,10 +1369,10 @@ bool Frame::findString(const String& target, bool forward, bool caseFlag, bool w
{
if (target.isEmpty())
return false;
-
+
if (excludeFromTextSearch())
return false;
-
+
// Start from an edge of the selection, if there's a selection that's not in shadow content. Which edge
// is used depends on whether we're searching forward or backward, and whether startInSelection is set.
RefPtr<Range> searchRange(rangeOfContents(document()));
@@ -1419,7 +1413,7 @@ bool Frame::findString(const String& target, bool forward, bool caseFlag, bool w
resultRange = findPlainText(searchRange.get(), target, forward, caseFlag);
}
-
+
ExceptionCode exception = 0;
// If nothing was found in the shadow tree, search in main content following the shadow tree.
@@ -1432,7 +1426,7 @@ bool Frame::findString(const String& target, bool forward, bool caseFlag, bool w
resultRange = findPlainText(searchRange.get(), target, forward, caseFlag);
}
-
+
if (!editor()->insideVisibleArea(resultRange.get())) {
resultRange = editor()->nextVisibleRange(resultRange.get(), target, forward, caseFlag, wrapFlag);
if (!resultRange)
@@ -1461,9 +1455,9 @@ unsigned Frame::markAllMatchesForText(const String& target, bool caseFlag, unsig
{
if (target.isEmpty())
return 0;
-
+
RefPtr<Range> searchRange(rangeOfContents(document()));
-
+
ExceptionCode exception = 0;
unsigned matchCount = 0;
do {
@@ -1476,7 +1470,7 @@ unsigned Frame::markAllMatchesForText(const String& target, bool caseFlag, unsig
searchRange->setStartAfter(resultRange->startContainer()->shadowAncestorNode(), exception);
continue;
}
-
+
// A non-collapsed result range can in some funky whitespace cases still not
// advance the range's start position (4509328). Break to avoid infinite loop.
VisiblePosition newStart = endVisiblePosition(resultRange.get(), DOWNSTREAM);
@@ -1488,18 +1482,18 @@ unsigned Frame::markAllMatchesForText(const String& target, bool caseFlag, unsig
++matchCount;
document()->addMarker(resultRange.get(), DocumentMarker::TextMatch);
}
-
+
// Stop looking if we hit the specified limit. A limit of 0 means no limit.
if (limit > 0 && matchCount >= limit)
break;
-
+
setStart(searchRange.get(), newStart);
Node* shadowTreeRoot = searchRange->shadowTreeRootNode();
if (searchRange->collapsed(exception) && shadowTreeRoot)
searchRange->setEnd(shadowTreeRoot, shadowTreeRoot->childNodeCount(), exception);
} while (true);
-
- // Do a "fake" paint in order to execute the code that computes the rendered rect for
+
+ // Do a "fake" paint in order to execute the code that computes the rendered rect for
// each text match.
Document* doc = document();
if (m_view && contentRenderer()) {
@@ -1511,7 +1505,7 @@ unsigned Frame::markAllMatchesForText(const String& target, bool caseFlag, unsig
m_view->paintContents(&context, visibleRect);
}
}
-
+
return matchCount;
}
@@ -1524,7 +1518,7 @@ void Frame::setMarkedTextMatchesAreHighlighted(bool flag)
{
if (flag == m_highlightTextMatches)
return;
-
+
m_highlightTextMatches = flag;
document()->repaintMarkers(DocumentMarker::TextMatch);
}
@@ -1553,7 +1547,7 @@ DOMWindow* Frame::domWindow() const
void Frame::clearFormerDOMWindow(DOMWindow* window)
{
- m_liveFormerWindows.remove(window);
+ m_liveFormerWindows.remove(window);
}
Page* Frame::page() const
@@ -1619,7 +1613,7 @@ void Frame::unfocusWindow()
{
if (!page())
return;
-
+
// If we're a top level window, deactivate the window.
if (!tree()->parent())
page()->chrome()->unfocus();
@@ -1680,14 +1674,13 @@ void Frame::respondToChangedSelection(const VisibleSelection& oldSelection, bool
// oldSelection may no longer be in the document.
if (closeTyping && oldSelection.isContentEditable() && oldSelection.start().node() && oldSelection.start().node()->inDocument()) {
VisiblePosition oldStart(oldSelection.visibleStart());
- VisibleSelection oldAdjacentWords = VisibleSelection(startOfWord(oldStart, LeftWordIfOnBoundary), endOfWord(oldStart, RightWordIfOnBoundary));
+ VisibleSelection oldAdjacentWords = VisibleSelection(startOfWord(oldStart, LeftWordIfOnBoundary), endOfWord(oldStart, RightWordIfOnBoundary));
if (oldAdjacentWords != newAdjacentWords) {
if (isContinuousGrammarCheckingEnabled) {
VisibleSelection oldSelectedSentence = VisibleSelection(startOfSentence(oldStart), endOfSentence(oldStart));
editor()->markMisspellingsAndBadGrammar(oldAdjacentWords, oldSelectedSentence != newSelectedSentence, oldSelectedSentence);
- } else {
+ } else
editor()->markMisspellingsAndBadGrammar(oldAdjacentWords, false, oldAdjacentWords);
- }
}
}
@@ -1722,15 +1715,15 @@ VisiblePosition Frame::visiblePositionForPoint(const IntPoint& framePoint)
visiblePos = VisiblePosition(Position(node, 0));
return visiblePos;
}
-
+
Document* Frame::documentAtPoint(const IntPoint& point)
-{
- if (!view())
+{
+ if (!view())
return 0;
-
+
IntPoint pt = view()->windowToContents(point);
HitTestResult result = HitTestResult(pt);
-
+
if (contentRenderer())
result = eventHandler()->hitTestResultAtPoint(pt, false);
return result.innerNode() ? result.innerNode()->document() : 0;