Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(558)

Unified Diff: Source/core/editing/htmlediting.cpp

Issue 20681004: Make first-letter style to work with editing Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 2013-09-20T18:27:32 Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/editing/htmlediting.cpp
diff --git a/Source/core/editing/htmlediting.cpp b/Source/core/editing/htmlediting.cpp
index 858d2e4a51e38575cdd74a96aad6ef3aa0aaad5c..5b6301b067ce55a694b373531cfdce9732f44782 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"
@@ -971,7 +972,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
@@ -979,8 +984,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);
}

Powered by Google App Engine
This is Rietveld 408576698