Add RenderedPosition
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 3 Aug 2011 16:27:35 +0000 (16:27 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 3 Aug 2011 16:27:35 +0000 (16:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=65221

Reviewed by Hajime Morita.

Add the skeleton for RenderedPosition and use it in rootBoxForLine.

* CMakeLists.txt:
* GNUmakefile.list.am:
* WebCore.gypi:
* WebCore.pro:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* editing/EditingAllInOne.cpp:
* editing/RenderedPosition.cpp: Added.
(WebCore::RenderedPosition::RenderedPosition):
* editing/RenderedPosition.h: Added.
(WebCore::RenderedPosition::isNull):
(WebCore::RenderedPosition::rootBox):
(WebCore::RenderedPosition::RenderedPosition):
* editing/visible_units.cpp:
(WebCore::startPositionForLine):
(WebCore::endPositionForLine):
(WebCore::logicalStartPositionForLine):
(WebCore::logicalEndPositionForLine):

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

Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.pro
Source/WebCore/WebCore.vcproj/WebCore.vcproj
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/editing/EditingAllInOne.cpp
Source/WebCore/editing/RenderedPosition.cpp [new file with mode: 0644]
Source/WebCore/editing/RenderedPosition.h [new file with mode: 0644]
Source/WebCore/editing/visible_units.cpp

index 53bedb4b9468974d550532fef9d71a1439eb3826..698ce3b5b6dc14ddda7bb323ccbbae6660e3575c 100644 (file)
@@ -635,6 +635,7 @@ SET(WebCore_SOURCES
     editing/RemoveFormatCommand.cpp
     editing/RemoveNodeCommand.cpp
     editing/RemoveNodePreservingChildrenCommand.cpp
+    editing/RenderedPosition.cpp
     editing/ReplaceNodeWithSpanCommand.cpp
     editing/ReplaceSelectionCommand.cpp
     editing/SetNodeAttributeCommand.cpp
index e075509555eee959819b1e95c6c3d1417acbc486..5514c271ca66899dd4244e0b949a5af17dd01021 100644 (file)
@@ -1,3 +1,31 @@
+2011-08-03  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Add RenderedPosition
+        https://bugs.webkit.org/show_bug.cgi?id=65221
+
+        Reviewed by Hajime Morita.
+
+        Add the skeleton for RenderedPosition and use it in rootBoxForLine.
+
+        * CMakeLists.txt:
+        * GNUmakefile.list.am:
+        * WebCore.gypi:
+        * WebCore.pro:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * editing/EditingAllInOne.cpp:
+        * editing/RenderedPosition.cpp: Added.
+        (WebCore::RenderedPosition::RenderedPosition):
+        * editing/RenderedPosition.h: Added.
+        (WebCore::RenderedPosition::isNull):
+        (WebCore::RenderedPosition::rootBox):
+        (WebCore::RenderedPosition::RenderedPosition):
+        * editing/visible_units.cpp:
+        (WebCore::startPositionForLine):
+        (WebCore::endPositionForLine):
+        (WebCore::logicalStartPositionForLine):
+        (WebCore::logicalEndPositionForLine):
+
 2011-08-03  Roland Steiner  <rolandsteiner@chromium.org>
 
         [V8] V8CSSRuleCustom.cpp: not all enum values are listed in switch statement
index b388a3699db66a6cf4ddf990a9b33bd6544c6fe2..0d14282c89330e0f637433270016e2f8ff185c70 100644 (file)
@@ -1398,6 +1398,8 @@ webcore_sources += \
        Source/WebCore/editing/RemoveNodeCommand.h \
        Source/WebCore/editing/RemoveNodePreservingChildrenCommand.cpp \
        Source/WebCore/editing/RemoveNodePreservingChildrenCommand.h \
+       Source/WebCore/editing/RenderedPosition.cpp \
+       Source/WebCore/editing/RenderedPosition.h \
        Source/WebCore/editing/ReplaceNodeWithSpanCommand.cpp \
        Source/WebCore/editing/ReplaceNodeWithSpanCommand.h \
        Source/WebCore/editing/ReplaceSelectionCommand.cpp \
index b140ad8880abcf9b5849a6da745cdfd40f44b23b..55cb9a8835b4ad3b8edaed8f49b2b52c4fb97b4d 100644 (file)
             'editing/RemoveNodeCommand.h',
             'editing/RemoveNodePreservingChildrenCommand.cpp',
             'editing/RemoveNodePreservingChildrenCommand.h',
+            'editing/RenderedPosition.cpp',
+            'editing/RenderedPosition.h',
             'editing/ReplaceNodeWithSpanCommand.cpp',
             'editing/ReplaceNodeWithSpanCommand.h',
             'editing/ReplaceSelectionCommand.cpp',
index 7a3bef16f576d63bb42458705bf361b86c4c7a1f..a13816be796210b685da6060865a9a5d7736b022 100644 (file)
@@ -598,6 +598,7 @@ SOURCES += \
     editing/RemoveFormatCommand.cpp \
     editing/RemoveNodeCommand.cpp \
     editing/RemoveNodePreservingChildrenCommand.cpp \
+    editing/RenderedPosition.cpp \
     editing/ReplaceNodeWithSpanCommand.cpp \
     editing/ReplaceSelectionCommand.cpp \
     editing/SetNodeAttributeCommand.cpp \
@@ -1586,6 +1587,7 @@ HEADERS += \
     editing/RemoveFormatCommand.h \
     editing/RemoveNodeCommand.h \
     editing/RemoveNodePreservingChildrenCommand.h \
+    editing/RenderedPosition.h \
     editing/ReplaceNodeWithSpanCommand.h \
     editing/ReplaceSelectionCommand.h \
     editing/SetNodeAttributeCommand.h \
index 91f2fa52e3181e7f14a1fc39eae3272410a3efe4..bf356cb12e4319563d35145dfa269589fc1f1b03 100755 (executable)
                                        />
                                </FileConfiguration>
                        </File>
+                       <File
+                               RelativePath="..\editing\RenderedPosition.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\editing\RenderedPosition.cpp"
+                               >
+                               <FileConfiguration
+                                       Name="Debug|Win32"
+                                       ExcludedFromBuild="true"
+                                       >
+                                       <Tool
+                                               Name="VCCLCompilerTool"
+                                       />
+                               </FileConfiguration>
+                               <FileConfiguration
+                                       Name="Release|Win32"
+                                       ExcludedFromBuild="true"
+                                       >
+                                       <Tool
+                                               Name="VCCLCompilerTool"
+                                       />
+                               </FileConfiguration>
+                               <FileConfiguration
+                                       Name="Debug_Cairo_CFLite|Win32"
+                                       ExcludedFromBuild="true"
+                                       >
+                                       <Tool
+                                               Name="VCCLCompilerTool"
+                                       />
+                               </FileConfiguration>
+                               <FileConfiguration
+                                       Name="Release_Cairo_CFLite|Win32"
+                                       ExcludedFromBuild="true"
+                                       >
+                                       <Tool
+                                               Name="VCCLCompilerTool"
+                                       />
+                               </FileConfiguration>
+                               <FileConfiguration
+                                       Name="Debug_All|Win32"
+                                       ExcludedFromBuild="true"
+                                       >
+                                       <Tool
+                                               Name="VCCLCompilerTool"
+                                       />
+                               </FileConfiguration>
+                               <FileConfiguration
+                                       Name="Production|Win32"
+                                       ExcludedFromBuild="true"
+                                       >
+                                       <Tool
+                                               Name="VCCLCompilerTool"
+                                       />
+                               </FileConfiguration>
+                       </File>
                        <File
                                RelativePath="..\editing\RemoveNodePreservingChildrenCommand.h"
                                >
index 682195945a1b8ff11a9111236bdc1fe3fc1e0f2b..70f5803bd02566c6999307148bd6b3e9ceda5a28 100644 (file)
                98CE4326129E00BD005821DC /* LinkLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 98CE4325129E00BD005821DC /* LinkLoader.cpp */; };
                98CE432A129E00E5005821DC /* LinkLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 98CE4329129E00E5005821DC /* LinkLoader.h */; };
                98EB1F951313FE0500D0E1EA /* NotImplemented.h in Headers */ = {isa = PBXBuildFile; fileRef = 98EB1F941313FE0500D0E1EA /* NotImplemented.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               9B32CDA913DF7FA900F34D13 /* RenderedPosition.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B32CDA713DF7FA900F34D13 /* RenderedPosition.h */; };
+               9B32CDAA13DF7FA900F34D13 /* RenderedPosition.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9B32CDA813DF7FA900F34D13 /* RenderedPosition.cpp */; };
                9B417064125662B3006B28FC /* ApplyBlockElementCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B417062125662B3006B28FC /* ApplyBlockElementCommand.h */; settings = {ATTRIBUTES = (Private, ); }; };
                9B417065125662B3006B28FC /* ApplyBlockElementCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9B417063125662B3006B28FC /* ApplyBlockElementCommand.cpp */; };
                9B6C41531344949000085B62 /* StringWithDirection.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B6C41521344949000085B62 /* StringWithDirection.h */; settings = {ATTRIBUTES = (Private, ); }; };
                98CE4325129E00BD005821DC /* LinkLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LinkLoader.cpp; sourceTree = "<group>"; };
                98CE4329129E00E5005821DC /* LinkLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LinkLoader.h; sourceTree = "<group>"; };
                98EB1F941313FE0500D0E1EA /* NotImplemented.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NotImplemented.h; sourceTree = "<group>"; };
+               9B32CDA713DF7FA900F34D13 /* RenderedPosition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderedPosition.h; sourceTree = "<group>"; };
+               9B32CDA813DF7FA900F34D13 /* RenderedPosition.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderedPosition.cpp; sourceTree = "<group>"; };
                9B417062125662B3006B28FC /* ApplyBlockElementCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ApplyBlockElementCommand.h; sourceTree = "<group>"; };
                9B417063125662B3006B28FC /* ApplyBlockElementCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ApplyBlockElementCommand.cpp; sourceTree = "<group>"; };
                9B6C41521344949000085B62 /* StringWithDirection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringWithDirection.h; sourceTree = "<group>"; };
                                93309DB6099E64910056E581 /* RemoveNodeCommand.h */,
                                93309DB7099E64910056E581 /* RemoveNodePreservingChildrenCommand.cpp */,
                                93309DB8099E64910056E581 /* RemoveNodePreservingChildrenCommand.h */,
+                               9B32CDA713DF7FA900F34D13 /* RenderedPosition.h */,
+                               9B32CDA813DF7FA900F34D13 /* RenderedPosition.cpp */,
                                A89CCC500F44E98100B5DA10 /* ReplaceNodeWithSpanCommand.cpp */,
                                A89CCC510F44E98100B5DA10 /* ReplaceNodeWithSpanCommand.h */,
                                93309DBA099E64910056E581 /* ReplaceSelectionCommand.cpp */,
                                BCEA4868097D93020094C9E4 /* RenderView.h in Headers */,
                                A871DFE40A15376B00B12A68 /* RenderWidget.h in Headers */,
                                93799EF90BF2743600D0F230 /* RenderWordBreak.h in Headers */,
+                               9B32CDA913DF7FA900F34D13 /* RenderedPosition.h in Headers */,
                                A89CCC530F44E98100B5DA10 /* ReplaceNodeWithSpanCommand.h in Headers */,
                                93309E0A099E64920056E581 /* ReplaceSelectionCommand.h in Headers */,
                                F55B3DD01251F12D003EF269 /* ResetInputType.h in Headers */,
                                BCEA4867097D93020094C9E4 /* RenderView.cpp in Sources */,
                                A871DFE50A15376B00B12A68 /* RenderWidget.cpp in Sources */,
                                93799EF80BF2743600D0F230 /* RenderWordBreak.cpp in Sources */,
+                               9B32CDAA13DF7FA900F34D13 /* RenderedPosition.cpp in Sources */,
                                A89CCC520F44E98100B5DA10 /* ReplaceNodeWithSpanCommand.cpp in Sources */,
                                93309E09099E64920056E581 /* ReplaceSelectionCommand.cpp in Sources */,
                                F55B3DCF1251F12D003EF269 /* ResetInputType.cpp in Sources */,
index 6260749babd545cfbd81d2967812608f5b15e8a4..d863097418d44fb0c536953d73e2d2f4e1f8adff 100644 (file)
@@ -57,6 +57,7 @@
 #include <RemoveFormatCommand.cpp>
 #include <RemoveNodeCommand.cpp>
 #include <RemoveNodePreservingChildrenCommand.cpp>
+#include <RenderedPosition.cpp>
 #include <ReplaceNodeWithSpanCommand.cpp>
 #include <ReplaceSelectionCommand.cpp>
 #include <SetNodeAttributeCommand.cpp>
diff --git a/Source/WebCore/editing/RenderedPosition.cpp b/Source/WebCore/editing/RenderedPosition.cpp
new file mode 100644 (file)
index 0000000..6bedf84
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "RenderedPosition.h"
+
+#include "InlineBox.h"
+#include "Position.h"
+#include "VisiblePosition.h"
+
+namespace WebCore {
+
+RenderedPosition::RenderedPosition(const VisiblePosition& position)
+    : m_renderer(0)
+    , m_inlineBox(0)
+    , m_offset(0)
+{
+    if (position.isNull())
+        return;
+    position.getInlineBoxAndOffset(m_inlineBox, m_offset);
+    if (m_inlineBox)
+        m_renderer = m_inlineBox->renderer();
+}
+
+};
diff --git a/Source/WebCore/editing/RenderedPosition.h b/Source/WebCore/editing/RenderedPosition.h
new file mode 100644 (file)
index 0000000..7a02d8d
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef RenderedPosition_h
+#define RenderedPosition_h
+
+#include "InlineBox.h"
+#include "TextAffinity.h"
+
+namespace WebCore {
+
+class Position;
+class RenderObject;
+class VisiblePosition;
+
+class RenderedPosition {
+public:
+    RenderedPosition();
+    explicit RenderedPosition(const VisiblePosition&);
+
+    bool isNull() { return !m_renderer; }
+    RootInlineBox* rootBox() { return m_inlineBox ? m_inlineBox->root() : 0; }
+
+private:
+    RenderObject* m_renderer;
+    InlineBox* m_inlineBox;
+    int m_offset;
+};
+
+inline RenderedPosition::RenderedPosition()
+    : m_renderer(0)
+    , m_inlineBox(0)
+    , m_offset(0)
+{
+}
+
+};
+
+#endif // RenderedPosition_h
index ef7b6f9c4dabb309695e0a6f27e201d172327bd1..66118ddbb332fcdf3cc42257971175c0a3e2943a 100644 (file)
@@ -34,6 +34,7 @@
 #include "RenderBlock.h"
 #include "RenderLayer.h"
 #include "RenderObject.h"
+#include "RenderedPosition.h"
 #include "Text.h"
 #include "TextBoundaries.h"
 #include "TextBreakIterator.h"
@@ -323,24 +324,6 @@ bool isStartOfWord(const VisiblePosition& p)
 
 // ---------
 
-static RootInlineBox *rootBoxForLine(const VisiblePosition &c)
-{
-    Position p = c.deepEquivalent();
-    Node* node = p.deprecatedNode();
-    if (!node)
-        return 0;
-
-    RenderObject *renderer = node->renderer();
-    if (!renderer)
-        return 0;
-
-    InlineBox* box;
-    int offset;
-    c.getInlineBoxAndOffset(box, offset);
-    
-    return box ? box->root() : 0;
-}
-
 static VisiblePosition positionAvoidingFirstPositionInTable(const VisiblePosition& c)
 {
     // return table offset 0 instead of the first VisiblePosition inside the table
@@ -356,7 +339,7 @@ static VisiblePosition startPositionForLine(const VisiblePosition& c)
     if (c.isNull())
         return VisiblePosition();
 
-    RootInlineBox *rootBox = rootBoxForLine(c);
+    RootInlineBox* rootBox = RenderedPosition(c).rootBox();
     if (!rootBox) {
         // There are VisiblePositions at offset 0 in blocks without
         // RootInlineBoxes, like empty editable blocks and bordered blocks.
@@ -404,7 +387,7 @@ static VisiblePosition endPositionForLine(const VisiblePosition& c)
     if (c.isNull())
         return VisiblePosition();
 
-    RootInlineBox *rootBox = rootBoxForLine(c);
+    RootInlineBox* rootBox = RenderedPosition(c).rootBox();
     if (!rootBox) {
         // There are VisiblePositions at offset 0 in blocks without
         // RootInlineBoxes, like empty editable blocks and bordered blocks.
@@ -1063,7 +1046,7 @@ static VisiblePosition logicalStartPositionForLine(const VisiblePosition& c)
     if (c.isNull())
         return VisiblePosition();
 
-    RootInlineBox* rootBox = rootBoxForLine(c);
+    RootInlineBox* rootBox = RenderedPosition(c).rootBox();
     if (!rootBox) {
         // There are VisiblePositions at offset 0 in blocks without
         // RootInlineBoxes, like empty editable blocks and bordered blocks.
@@ -1103,7 +1086,7 @@ static VisiblePosition logicalEndPositionForLine(const VisiblePosition& c)
     if (c.isNull())
         return VisiblePosition();
 
-    RootInlineBox* rootBox = rootBoxForLine(c);
+    RootInlineBox* rootBox = RenderedPosition(c).rootBox();
     if (!rootBox) {
         // There are VisiblePositions at offset 0 in blocks without
         // RootInlineBoxes, like empty editable blocks and bordered blocks.