Title: [90098] trunk/Source/WebCore
Revision
90098
Author
[email protected]
Date
2011-06-30 02:14:17 -0700 (Thu, 30 Jun 2011)

Log Message

2011-06-30  Ryosuke Niwa  <[email protected]>

        Reviewed by Kent Tamura.

        Replace isNodeInTextFormControl(Node*) by enclosingTextFormControl(const Position&)
        https://bugs.webkit.org/show_bug.cgi?id=63672

        Replaced isNodeInTextFormControl(Node*) by enclosingTextFormControl(const Position&).
        Also added a safe toTextFormControl to HTMLFormControlElement.h.

        * editing/DeleteSelectionCommand.cpp:
        (WebCore::DeleteSelectionCommand::doApply): Calls enclosingTextFormControl instead of manually
        checking the tag name of shadowAncestorNode.
        * editing/Editor.cpp:
        (WebCore::Editor::selectionForCommand): Rewritten using enclosingTextFormControl and toTextFormControl.
        (WebCore::Editor::cut): Calls enclosingTextFormControl instead of isNodeInTextFormControl.
        (WebCore::Editor::copy): Ditto.
        (WebCore::Editor::setBaseWritingDirection): Calls toTextFormControl instead of manually checking tag name.
        * editing/FrameSelection.cpp:
        (WebCore::FrameSelection::isInPasswordField): Calls enclosingTextFormControl.
        * editing/ReplaceSelectionCommand.cpp:
        (WebCore::ReplaceSelectionCommand::doApply): Ditto.
        * editing/htmlediting.cpp:
        (WebCore::enclosingTextFormControl): Added.
        * editing/htmlediting.h:
        * html/HTMLFormControlElement.h:
        (WebCore::toTextFormControl): Added.
        * page/DragController.cpp:
        (WebCore::DragController::startDrag): Calls enclosingTextFormControl instead of isNodeInTextFormControl.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (90097 => 90098)


--- trunk/Source/WebCore/ChangeLog	2011-06-30 09:08:07 UTC (rev 90097)
+++ trunk/Source/WebCore/ChangeLog	2011-06-30 09:14:17 UTC (rev 90098)
@@ -1,3 +1,33 @@
+2011-06-30  Ryosuke Niwa  <[email protected]>
+
+        Reviewed by Kent Tamura.
+
+        Replace isNodeInTextFormControl(Node*) by enclosingTextFormControl(const Position&)
+        https://bugs.webkit.org/show_bug.cgi?id=63672
+
+        Replaced isNodeInTextFormControl(Node*) by enclosingTextFormControl(const Position&).
+        Also added a safe toTextFormControl to HTMLFormControlElement.h.
+
+        * editing/DeleteSelectionCommand.cpp:
+        (WebCore::DeleteSelectionCommand::doApply): Calls enclosingTextFormControl instead of manually
+        checking the tag name of shadowAncestorNode.
+        * editing/Editor.cpp:
+        (WebCore::Editor::selectionForCommand): Rewritten using enclosingTextFormControl and toTextFormControl.
+        (WebCore::Editor::cut): Calls enclosingTextFormControl instead of isNodeInTextFormControl.
+        (WebCore::Editor::copy): Ditto.
+        (WebCore::Editor::setBaseWritingDirection): Calls toTextFormControl instead of manually checking tag name.
+        * editing/FrameSelection.cpp:
+        (WebCore::FrameSelection::isInPasswordField): Calls enclosingTextFormControl.
+        * editing/ReplaceSelectionCommand.cpp:
+        (WebCore::ReplaceSelectionCommand::doApply): Ditto.
+        * editing/htmlediting.cpp:
+        (WebCore::enclosingTextFormControl): Added.
+        * editing/htmlediting.h:
+        * html/HTMLFormControlElement.h:
+        (WebCore::toTextFormControl): Added.
+        * page/DragController.cpp:
+        (WebCore::DragController::startDrag): Calls enclosingTextFormControl instead of isNodeInTextFormControl.
+
 2011-06-27  Pavel Podivilov  <[email protected]>
 
         Reviewed by Pavel Feldman.

Modified: trunk/Source/WebCore/editing/DeleteSelectionCommand.cpp (90097 => 90098)


--- trunk/Source/WebCore/editing/DeleteSelectionCommand.cpp	2011-06-30 09:08:07 UTC (rev 90097)
+++ trunk/Source/WebCore/editing/DeleteSelectionCommand.cpp	2011-06-30 09:14:17 UTC (rev 90098)
@@ -787,12 +787,9 @@
 
     // If the deletion is occurring in a text field, and we're not deleting to replace the selection, then let the frame call across the bridge to notify the form delegate. 
     if (!m_replace) {
-        Node* startNode = m_selectionToDelete.start().deprecatedNode();
-        Node* ancestorNode = startNode ? startNode->shadowAncestorNode() : 0;
-        if (ancestorNode && ancestorNode->hasTagName(inputTag)
-                && static_cast<HTMLInputElement*>(ancestorNode)->isTextField()
-                && ancestorNode->focused())
-            document()->frame()->editor()->textWillBeDeletedInTextField(static_cast<Element*>(ancestorNode));
+        Element* textControl = enclosingTextFormControl(m_selectionToDelete.start());
+        if (textControl && textControl->focused())
+            document()->frame()->editor()->textWillBeDeletedInTextField(textControl);
     }
 
     // save this to later make the selection with

Modified: trunk/Source/WebCore/editing/Editor.cpp (90097 => 90098)


--- trunk/Source/WebCore/editing/Editor.cpp	2011-06-30 09:08:07 UTC (rev 90097)
+++ trunk/Source/WebCore/editing/Editor.cpp	2011-06-30 09:14:17 UTC (rev 90098)
@@ -53,8 +53,8 @@
 #include "FrameTree.h"
 #include "FrameView.h"
 #include "GraphicsContext.h"
+#include "HTMLFormControlElement.h"
 #include "HTMLFrameOwnerElement.h"
-#include "HTMLInputElement.h"
 #include "HTMLNames.h"
 #include "HTMLTextAreaElement.h"
 #include "HitTestResult.h"
@@ -105,16 +105,10 @@
         return selection;
     // If the target is a text control, and the current selection is outside of its shadow tree,
     // then use the saved selection for that text control.
-    Node* target = event->target()->toNode();
-    Node* selectionStart = selection.start().deprecatedNode();
-    if (target && (!selectionStart || target->shadowAncestorNode() != selectionStart->shadowAncestorNode())) {
-        RefPtr<Range> range;
-        if (target->hasTagName(inputTag) && static_cast<HTMLInputElement*>(target)->isTextField())
-            range = static_cast<HTMLInputElement*>(target)->selection();
-        else if (target->hasTagName(textareaTag))
-            range = static_cast<HTMLTextAreaElement*>(target)->selection();
-
-        if (range)
+    HTMLTextFormControlElement* textFormControlOfSelectionStart = enclosingTextFormControl(selection.start());
+    HTMLTextFormControlElement* textFromControlOfTarget = toTextFormControl(event->target()->toNode());
+    if (textFromControlOfTarget && (selection.start().isNull() || textFromControlOfTarget != textFormControlOfSelectionStart)) {
+        if (RefPtr<Range> range = textFromControlOfTarget->selection())
             return VisibleSelection(range.get());
     }
     return selection;
@@ -1157,7 +1151,7 @@
     RefPtr<Range> selection = selectedRange();
     if (shouldDeleteRange(selection.get())) {
         updateMarkersForWordsAffectedByEditing(true);
-        if (isNodeInTextFormControl(m_frame->selection()->start().deprecatedNode()))
+        if (enclosingTextFormControl(m_frame->selection()->start()))
             Pasteboard::generalPasteboard()->writePlainText(selectedText());
         else
             Pasteboard::generalPasteboard()->writeSelection(selection.get(), canSmartCopyOrDelete(), m_frame);
@@ -1175,7 +1169,7 @@
         return;
     }
 
-    if (isNodeInTextFormControl(m_frame->selection()->start().deprecatedNode()))
+    if (enclosingTextFormControl(m_frame->selection()->start()))
         Pasteboard::generalPasteboard()->writePlainText(selectedText());
     else {
         Document* document = m_frame->document();
@@ -1443,7 +1437,7 @@
 void Editor::setBaseWritingDirection(WritingDirection direction)
 {
     Node* focusedNode = frame()->document()->focusedNode();
-    if (focusedNode && (focusedNode->hasTagName(textareaTag) || (focusedNode->hasTagName(inputTag) && static_cast<HTMLInputElement*>(focusedNode)->isTextField()))) {
+    if (toTextFormControl(focusedNode)) {
         if (direction == NaturalWritingDirection)
             return;
         toHTMLElement(focusedNode)->setAttribute(dirAttr, direction == LeftToRightWritingDirection ? "ltr" : "rtl");

Modified: trunk/Source/WebCore/editing/FrameSelection.cpp (90097 => 90098)


--- trunk/Source/WebCore/editing/FrameSelection.cpp	2011-06-30 09:08:07 UTC (rev 90097)
+++ trunk/Source/WebCore/editing/FrameSelection.cpp	2011-06-30 09:14:17 UTC (rev 90098)
@@ -1484,20 +1484,8 @@
 
 bool FrameSelection::isInPasswordField() const
 {
-    ASSERT(start().isNull() || start().anchorType() == Position::PositionIsOffsetInAnchor
-           || start().containerNode() || !start().anchorNode()->shadowAncestorNode());
-    Node* startNode = start().containerNode();
-    if (!startNode)
-        return false;
-
-    startNode = startNode->shadowAncestorNode();
-    if (!startNode)
-        return false;
-
-    if (!startNode->hasTagName(inputTag))
-        return false;
-    
-    return static_cast<HTMLInputElement*>(startNode)->isPasswordField();
+    HTMLTextFormControlElement* textControl = enclosingTextFormControl(start());
+    return textControl && textControl->hasTagName(inputTag) && static_cast<HTMLInputElement*>(textControl)->isPasswordField();
 }
 
 void FrameSelection::focusedOrActiveStateChanged()

Modified: trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp (90097 => 90098)


--- trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp	2011-06-30 09:08:07 UTC (rev 90097)
+++ trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp	2011-06-30 09:14:17 UTC (rev 90098)
@@ -1105,10 +1105,9 @@
     
     // Add spaces for smart replace.
     if (m_smartReplace && currentRoot) {
-        // Disable smart replace for password fields.
-        Node* start = currentRoot->shadowAncestorNode();
-        if (start->hasTagName(inputTag) && static_cast<HTMLInputElement*>(start)->isPasswordField())
-            m_smartReplace = false;
+        Element* textControl = enclosingTextFormControl(firstPositionInNode(currentRoot));
+        if (textControl && textControl->hasTagName(inputTag) && static_cast<HTMLInputElement*>(textControl)->isPasswordField())
+            m_smartReplace = false; // Disable smart replace for password fields.
     }
     if (m_smartReplace) {
         bool needsTrailingSpace = !isEndOfParagraph(endOfInsertedContent) &&

Modified: trunk/Source/WebCore/editing/htmlediting.cpp (90097 => 90098)


--- trunk/Source/WebCore/editing/htmlediting.cpp	2011-06-30 09:08:07 UTC (rev 90097)
+++ trunk/Source/WebCore/editing/htmlediting.cpp	2011-06-30 09:14:17 UTC (rev 90098)
@@ -31,6 +31,7 @@
 #include "HTMLBRElement.h"
 #include "HTMLDivElement.h"
 #include "HTMLElementFactory.h"
+#include "HTMLFormControlElement.h"
 #include "HTMLInterchange.h"
 #include "HTMLLIElement.h"
 #include "HTMLNames.h"
@@ -856,14 +857,15 @@
     return isTabSpanTextNode(node) ? node->parentNode() : 0;
 }
 
-bool isNodeInTextFormControl(Node* node)
+HTMLTextFormControlElement* enclosingTextFormControl(const Position& position)
 {
-    if (!node)
-        return false;
-    Node* ancestor = node->shadowAncestorNode();
-    if (ancestor == node)
-        return false;
-    return ancestor->isElementNode() && static_cast<Element*>(ancestor)->isTextFormControl();
+    ASSERT(position.isNull() || position.anchorType() == Position::PositionIsOffsetInAnchor
+           || position.containerNode() || !position.anchorNode()->shadowAncestorNode());
+    Node* container = position.containerNode();
+    if (!container)
+        return 0;
+    Node* ancestor = container->shadowAncestorNode();
+    return ancestor != container ? toTextFormControl(ancestor) : 0;
 }
     
 Position positionOutsideTabSpan(const Position& pos)

Modified: trunk/Source/WebCore/editing/htmlediting.h (90097 => 90098)


--- trunk/Source/WebCore/editing/htmlediting.h	2011-06-30 09:08:07 UTC (rev 90097)
+++ trunk/Source/WebCore/editing/htmlediting.h	2011-06-30 09:14:17 UTC (rev 90098)
@@ -37,6 +37,7 @@
 class Document;
 class Element;
 class HTMLElement;
+class HTMLTextFormControlElement;
 class Node;
 class Position;
 class Range;
@@ -106,7 +107,6 @@
 bool isNodeRendered(const Node*);
 bool isNodeVisiblyContainedWithin(Node*, const Range*);
 bool isRenderedAsNonInlineTableImageOrHR(const Node*);
-bool isNodeInTextFormControl(Node* node);
     
 TextDirection directionOfEnclosingBlock(const Position&);
 
@@ -218,6 +218,7 @@
 
 Element* editableRootForPosition(const Position&);
 Element* unsplittableElementForPosition(const Position&);
+HTMLTextFormControlElement* enclosingTextFormControl(const Position&);
 
 // Boolean functions on Element
     

Modified: trunk/Source/WebCore/html/HTMLFormControlElement.h (90097 => 90098)


--- trunk/Source/WebCore/html/HTMLFormControlElement.h	2011-06-30 09:08:07 UTC (rev 90097)
+++ trunk/Source/WebCore/html/HTMLFormControlElement.h	2011-06-30 09:14:17 UTC (rev 90098)
@@ -245,6 +245,12 @@
     String m_textAsOfLastFormControlChangeEvent;
 };
 
+// This function returns 0 when node is an input element and not a text field.
+inline HTMLTextFormControlElement* toTextFormControl(Node* node)
+{
+    return (node && node->isElementNode() && static_cast<Element*>(node)->isTextFormControl()) ? static_cast<HTMLTextFormControlElement*>(node) : 0;
+}
+
 } // namespace
 
 #endif

Modified: trunk/Source/WebCore/page/DragController.cpp (90097 => 90098)


--- trunk/Source/WebCore/page/DragController.cpp	2011-06-30 09:08:07 UTC (rev 90097)
+++ trunk/Source/WebCore/page/DragController.cpp	2011-06-30 09:14:17 UTC (rev 90098)
@@ -701,7 +701,7 @@
     Image* image = getImage(static_cast<Element*>(node));
     if (state.m_dragType == DragSourceActionSelection) {
         if (!clipboard->hasData()) {
-            if (isNodeInTextFormControl(src->selection()->start().deprecatedNode()))
+            if (enclosingTextFormControl(src->selection()->start()))
                 clipboard->writePlainText(src->editor()->selectedText());
             else {
                 RefPtr<Range> selectionRange = src->selection()->toNormalizedRange();
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to