Commit 4f6c51fe authored by rniwa@webkit.org's avatar rniwa@webkit.org

2011-06-30 Ryosuke Niwa <rniwa@webkit.org>

        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.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@90098 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 7253b5ed
2011-06-30 Ryosuke Niwa <rniwa@webkit.org>
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 <podivilov@chromium.org>
Reviewed by Pavel Feldman.
......
......@@ -787,12 +787,9 @@ void DeleteSelectionCommand::doApply()
// 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
......
......@@ -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 @@ VisibleSelection Editor::selectionForCommand(Event* event)
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 @@ void Editor::cut()
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 @@ void Editor::copy()
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::toggleUnderline()
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");
......
......@@ -1484,20 +1484,8 @@ bool FrameSelection::setSelectedRange(Range* range, EAffinity affinity, bool clo
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()
......
......@@ -1105,10 +1105,9 @@ void ReplaceSelectionCommand::doApply()
// 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) &&
......
......@@ -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 @@ Node *tabSpanNode(const Node *node)
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)
......
......@@ -37,6 +37,7 @@ namespace WebCore {
class Document;
class Element;
class HTMLElement;
class HTMLTextFormControlElement;
class Node;
class Position;
class Range;
......@@ -106,7 +107,6 @@ bool isListItem(Node*);
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 @@ PassRefPtr<Element> createBlockPlaceholderElement(Document*);
Element* editableRootForPosition(const Position&);
Element* unsplittableElementForPosition(const Position&);
HTMLTextFormControlElement* enclosingTextFormControl(const Position&);
// Boolean functions on Element
......
......@@ -245,6 +245,12 @@ private:
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
......@@ -701,7 +701,7 @@ bool DragController::startDrag(Frame* src, const DragState& state, DragOperation
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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment