Index: Source/core/editing/htmlediting.cpp |
diff --git a/Source/core/editing/htmlediting.cpp b/Source/core/editing/htmlediting.cpp |
index b4b945928a199c3acde95cf5b9dceebe9e5939a4..104b4806771553edbada9e3fbd25b156f94ac2c1 100644 |
--- a/Source/core/editing/htmlediting.cpp |
+++ b/Source/core/editing/htmlediting.cpp |
@@ -51,6 +51,7 @@ |
#include "core/html/HTMLUListElement.h" |
#include "core/page/Frame.h" |
#include "core/rendering/RenderObject.h" |
+#include "core/rendering/RenderText.h" |
#include "wtf/Assertions.h" |
#include "wtf/StdLibExtras.h" |
#include "wtf/text/StringBuilder.h" |
@@ -487,7 +488,7 @@ Position positionAfterContainingSpecialElement(const Position& pos, Node **conta |
Node* isFirstPositionAfterTable(const VisiblePosition& visiblePosition) |
{ |
Position upstream(visiblePosition.deepEquivalent().upstream()); |
- if (upstream.deprecatedNode() && upstream.deprecatedNode()->renderer() && upstream.deprecatedNode()->renderer()->isTable() && upstream.atLastEditingPositionForNode()) |
+ if (upstream.deprecatedNode() && upstream.renderer() && upstream.renderer()->isTable() && upstream.atLastEditingPositionForNode()) |
return upstream.deprecatedNode(); |
return 0; |
@@ -496,7 +497,7 @@ Node* isFirstPositionAfterTable(const VisiblePosition& visiblePosition) |
Node* isLastPositionBeforeTable(const VisiblePosition& visiblePosition) |
{ |
Position downstream(visiblePosition.deepEquivalent().downstream()); |
- if (downstream.deprecatedNode() && downstream.deprecatedNode()->renderer() && downstream.deprecatedNode()->renderer()->isTable() && downstream.atFirstEditingPositionForNode()) |
+ if (downstream.deprecatedNode() && downstream.renderer() && downstream.renderer()->isTable() && downstream.atFirstEditingPositionForNode()) |
return downstream.deprecatedNode(); |
return 0; |
@@ -978,7 +979,11 @@ int caretMinOffset(const Node* n) |
{ |
RenderObject* r = n->renderer(); |
ASSERT(!n->isCharacterDataNode() || !r || r->isText()); // FIXME: This was a runtime check that seemingly couldn't fail; changed it to an assertion for now. |
- return r ? r->caretMinOffset() : 0; |
+ if (!r) |
+ return 0; |
+ if (r->isText()) |
+ return r->caretMinOffset() + toRenderText(r)->textStartOffset(); |
+ return r->caretMinOffset(); |
} |
// If a node can contain candidates for VisiblePositions, return the offset of the last candidate, otherwise |
@@ -986,8 +991,9 @@ int caretMinOffset(const Node* n) |
int caretMaxOffset(const Node* n) |
{ |
// For rendered text nodes, return the last position that a caret could occupy. |
- if (n->isTextNode() && n->renderer()) |
- return n->renderer()->caretMaxOffset(); |
+ RenderObject* renderer = n->renderer(); |
+ if (renderer && renderer->isText()) |
+ return renderer->caretMaxOffset() + toRenderText(renderer)->textStartOffset(); |
// For containers return the number of children. For others do the same as above. |
return lastOffsetForEditing(n); |
} |
@@ -1005,10 +1011,10 @@ bool lineBreakExistsAtPosition(const Position& position) |
if (position.anchorNode()->hasTagName(brTag) && position.atFirstEditingPositionForNode()) |
return true; |
- if (!position.anchorNode()->renderer()) |
+ if (!position.renderer()) |
return false; |
- if (!position.anchorNode()->isTextNode() || !position.anchorNode()->renderer()->style()->preserveNewline()) |
+ if (!position.anchorNode()->isTextNode() || !position.renderer()->style()->preserveNewline()) |
return false; |
Text* textNode = toText(position.anchorNode()); |