Should have an editing behavior specific for IOS.
authorenrica@apple.com <enrica@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 17 Sep 2014 00:48:01 +0000 (00:48 +0000)
committerenrica@apple.com <enrica@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 17 Sep 2014 00:48:01 +0000 (00:48 +0000)
https://bugs.webkit.org/show_bug.cgi?id=136876

Reviewed by Sam Weinig.

This patch introduces a new editing behavior type to be able
to perform editing tasks that are specific to iOS.
All the existing EditingBehavior methods return the same boolean
value for for Mac and iOS. A new one has been introduced to support
a specific behavior in the DeleteSelectionCommand.

* editing/DeleteSelectionCommand.cpp:
(WebCore::DeleteSelectionCommand::doApply):
* editing/EditingBehavior.h:
(WebCore::EditingBehavior::shouldConsiderSelectionAsDirectional):
(WebCore::EditingBehavior::shouldCenterAlignWhenSelectionIsRevealed):
(WebCore::EditingBehavior::shouldToggleStyleBasedOnStartOfSelection):
(WebCore::EditingBehavior::shouldAlwaysGrowSelectionWhenExtendingToBoundary):
(WebCore::EditingBehavior::shouldSelectOnContextualMenuClick):
(WebCore::EditingBehavior::shouldExtendSelectionByWordOrLineAcrossCaret):
(WebCore::EditingBehavior::shouldRebalanceWhiteSpacesInSecureField):
* editing/EditingBehaviorTypes.h:
* editing/FrameSelection.cpp:
(WebCore::FrameSelection::positionForPlatform):
* page/Settings.cpp:
(WebCore::editingBehaviorTypeForPlatform):
* testing/InternalSettings.cpp:
(WebCore::InternalSettings::setEditingBehavior):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@173682 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/editing/DeleteSelectionCommand.cpp
Source/WebCore/editing/EditingBehavior.h
Source/WebCore/editing/EditingBehaviorTypes.h
Source/WebCore/editing/FrameSelection.cpp
Source/WebCore/page/Settings.cpp
Source/WebCore/testing/InternalSettings.cpp

index d97c849..1bb492d 100644 (file)
@@ -1,3 +1,34 @@
+2014-09-16  Enrica Casucci  <enrica@apple.com>
+
+        Should have an editing behavior specific for IOS.
+        https://bugs.webkit.org/show_bug.cgi?id=136876
+
+        Reviewed by Sam Weinig.
+
+        This patch introduces a new editing behavior type to be able
+        to perform editing tasks that are specific to iOS.
+        All the existing EditingBehavior methods return the same boolean
+        value for for Mac and iOS. A new one has been introduced to support
+        a specific behavior in the DeleteSelectionCommand.
+
+        * editing/DeleteSelectionCommand.cpp:
+        (WebCore::DeleteSelectionCommand::doApply):
+        * editing/EditingBehavior.h:
+        (WebCore::EditingBehavior::shouldConsiderSelectionAsDirectional):
+        (WebCore::EditingBehavior::shouldCenterAlignWhenSelectionIsRevealed):
+        (WebCore::EditingBehavior::shouldToggleStyleBasedOnStartOfSelection):
+        (WebCore::EditingBehavior::shouldAlwaysGrowSelectionWhenExtendingToBoundary):
+        (WebCore::EditingBehavior::shouldSelectOnContextualMenuClick):
+        (WebCore::EditingBehavior::shouldExtendSelectionByWordOrLineAcrossCaret):
+        (WebCore::EditingBehavior::shouldRebalanceWhiteSpacesInSecureField):
+        * editing/EditingBehaviorTypes.h:
+        * editing/FrameSelection.cpp:
+        (WebCore::FrameSelection::positionForPlatform):
+        * page/Settings.cpp:
+        (WebCore::editingBehaviorTypeForPlatform):
+        * testing/InternalSettings.cpp:
+        (WebCore::InternalSettings::setEditingBehavior):
+
 2014-09-16  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r173670.
index 35aa3b9..362619d 100644 (file)
@@ -861,24 +861,17 @@ void DeleteSelectionCommand::doApply()
         insertNodeAt(placeholder.get(), m_endingPosition);
     }
 
-#if PLATFORM(IOS)
-    // This checking is due to iphone shows the last entered character momentarily, removing and adding back the 
-    // space when deleting password cause space been showed insecurely.
-    bool isSecure = NO;
-    Node* node = m_endingPosition.deprecatedNode();
-    if (node && node->isTextNode()) {
-        Text* textNode = static_cast<Text*>(node);    
-        if (textNode->length() > 0) {
-            RenderObject* renderer = textNode->renderer();
-            isSecure = renderer->style().textSecurity() != TSNONE;
-        }
+    bool shouldRebalaceWhiteSpace = true;
+    if (!frame().editor().behavior().shouldRebalanceWhiteSpacesInSecureField()) {
+        Node* node = m_endingPosition.deprecatedNode();
+        if (node && node->isTextNode()) {
+            Text* textNode = toText(node);
+            if (textNode->length())
+                shouldRebalaceWhiteSpace = textNode->renderer()->style().textSecurity() == TSNONE;
+        }        
     }
-        
-    if (!isSecure)
+    if (shouldRebalaceWhiteSpace)
         rebalanceWhitespaceAt(m_endingPosition);
-#else
-    rebalanceWhitespaceAt(m_endingPosition);
-#endif
 
     calculateTypingStyleAfterDelete();
 
index cff6cab..cfed2bc 100644 (file)
@@ -46,22 +46,22 @@ public:
 
     // On Windows, selections should always be considered as directional, regardless if it is
     // mouse-based or keyboard-based.
-    bool shouldConsiderSelectionAsDirectional() const { return m_type != EditingMacBehavior; }
+    bool shouldConsiderSelectionAsDirectional() const { return m_type != EditingMacBehavior && m_type != EditingIOSBehavior; }
 
     // On Mac, when revealing a selection (for example as a result of a Find operation on the Browser),
     // content should be scrolled such that the selection gets certer aligned.
-    bool shouldCenterAlignWhenSelectionIsRevealed() const { return m_type == EditingMacBehavior; }
+    bool shouldCenterAlignWhenSelectionIsRevealed() const { return m_type == EditingMacBehavior || m_type == EditingIOSBehavior; }
 
     // On Mac, style is considered present when present at the beginning of selection. On other platforms,
     // style has to be present throughout the selection.
-    bool shouldToggleStyleBasedOnStartOfSelection() const { return m_type == EditingMacBehavior; }
+    bool shouldToggleStyleBasedOnStartOfSelection() const { return m_type == EditingMacBehavior || m_type == EditingIOSBehavior; }
 
     // Standard Mac behavior when extending to a boundary is grow the selection rather than leaving the base
     // in place and moving the extent. Matches NSTextView.
-    bool shouldAlwaysGrowSelectionWhenExtendingToBoundary() const { return m_type == EditingMacBehavior; }
+    bool shouldAlwaysGrowSelectionWhenExtendingToBoundary() const { return m_type == EditingMacBehavior || m_type == EditingIOSBehavior; }
 
     // On Mac, when processing a contextual click, the object being clicked upon should be selected.
-    bool shouldSelectOnContextualMenuClick() const { return m_type == EditingMacBehavior; }
+    bool shouldSelectOnContextualMenuClick() const { return m_type == EditingMacBehavior || m_type == EditingIOSBehavior; }
 
     // On Linux, should be able to get and insert spelling suggestions without selecting the misspelled word.
     bool shouldAllowSpellingSuggestionsWithoutSelection() const
@@ -78,13 +78,17 @@ public:
     // On Mac, selecting backwards by word/line from the middle of a word/line, and then going
     // forward leaves the caret back in the middle with no selection, instead of directly selecting
     // to the other end of the line/word (Unix/Windows behavior).
-    bool shouldExtendSelectionByWordOrLineAcrossCaret() const { return m_type != EditingMacBehavior; }
+    bool shouldExtendSelectionByWordOrLineAcrossCaret() const { return m_type != EditingMacBehavior && m_type != EditingIOSBehavior; }
 
     // Based on native behavior, when using ctrl(alt)+arrow to move caret by word, ctrl(alt)+left arrow moves caret to
     // immediately before the word in all platforms, for example, the word break positions are: "|abc |def |hij |opq".
     // But ctrl+right arrow moves caret to "abc |def |hij |opq" on Windows and "abc| def| hij| opq|" on Mac and Linux.
     bool shouldSkipSpaceWhenMovingRight() const { return m_type == EditingWindowsBehavior; }
 
+    // On iOS the last entered character in a secure filed is shown momentarily, removing and adding back the
+    // space when deleting password cause space been showed insecurely.
+    bool shouldRebalanceWhiteSpacesInSecureField() const { return m_type != EditingIOSBehavior; }
+
 private:
     EditingBehaviorType m_type;
 };
index 11345da..234f50a 100644 (file)
@@ -39,7 +39,8 @@ namespace WebCore {
 enum EditingBehaviorType {
     EditingMacBehavior,
     EditingWindowsBehavior,
-    EditingUnixBehavior
+    EditingUnixBehavior,
+    EditingIOSBehavior
 };
 
 } // WebCore namespace
index fa6ebfa..86c55ba 100644 (file)
@@ -616,7 +616,7 @@ void FrameSelection::willBeModified(EAlteration alter, SelectionDirection direct
 
 VisiblePosition FrameSelection::positionForPlatform(bool isGetStart) const
 {
-    if (m_frame && m_frame->settings().editingBehaviorType() == EditingMacBehavior)
+    if (m_frame && (m_frame->settings().editingBehaviorType() == EditingMacBehavior || m_frame->settings().editingBehaviorType() == EditingIOSBehavior))
         return isGetStart ? m_selection.visibleStart() : m_selection.visibleEnd();
     // Linux and Windows always extend selections from the extent endpoint.
     // FIXME: VisibleSelection should be fixed to ensure as an invariant that
index d713412..fe5a3d5 100644 (file)
@@ -107,7 +107,9 @@ bool Settings::gManageAudioSession = false;
 static EditingBehaviorType editingBehaviorTypeForPlatform()
 {
     return
-#if OS(DARWIN)
+#if PLATFORM(IOS)
+    EditingIOSBehavior
+#elif OS(DARWIN)
     EditingMacBehavior
 #elif OS(WINDOWS)
     EditingWindowsBehavior
index 0c2e861..dbff5dc 100644 (file)
@@ -349,6 +349,8 @@ void InternalSettings::setEditingBehavior(const String& editingBehavior, Excepti
         settings()->setEditingBehaviorType(EditingMacBehavior);
     else if (equalIgnoringCase(editingBehavior, "unix"))
         settings()->setEditingBehaviorType(EditingUnixBehavior);
+    else if (equalIgnoringCase(editingBehavior, "ios"))
+        settings()->setEditingBehaviorType(EditingIOSBehavior);
     else
         ec = SYNTAX_ERR;
 }