提交 befe3932 编写于 作者: M Matt Perry

Expose a Paragraph.getWordBoundary method to dart. (#2675)

* Expose a Paragraph.getWordBoundary method to dart.

Used by text selection to select a word.
上级 694b492b
......@@ -674,6 +674,13 @@ abstract class Paragraph extends NativeFieldWrapperClass2 {
return new TextPosition(offset: encoded[0], affinity: TextAffinity.values[encoded[1]]);
}
List<int> _getPositionForOffset(Offset offset) native "Paragraph_getPositionForOffset";
/// Returns the [start, end] of the word at the given offset. Characters not
/// part of a word, such as spaces, symbols, and punctuation, have word breaks
/// on both sides. In such cases, this method will return [offset, offset+1].
/// Word boundaries are defined more precisely in Unicode Standard Annex #29
/// http://www.unicode.org/reports/tr29/#Word_Boundaries
List<int> getWordBoundary(int offset) native "Paragraph_getWordBoundary";
}
/// Builds a [Paragraph] containing text with the given styling information.
......
......@@ -11,6 +11,7 @@
#include "sky/engine/core/rendering/style/RenderStyle.h"
#include "sky/engine/platform/fonts/FontCache.h"
#include "sky/engine/platform/graphics/GraphicsContext.h"
#include "sky/engine/platform/text/TextBoundaries.h"
#include "sky/engine/public/platform/Platform.h"
#include "sky/engine/tonic/dart_args.h"
#include "sky/engine/tonic/dart_binding_macros.h"
......@@ -29,6 +30,7 @@ IMPLEMENT_WRAPPERTYPEINFO(ui, Paragraph);
V(Paragraph, alphabeticBaseline) \
V(Paragraph, ideographicBaseline) \
V(Paragraph, layout) \
V(Paragraph, getWordBoundary) \
V(Paragraph, getRectsForRange) \
V(Paragraph, getPositionForOffset)
......@@ -153,4 +155,27 @@ Dart_Handle Paragraph::getPositionForOffset(const Offset& offset) {
return result;
}
Dart_Handle Paragraph::getWordBoundary(unsigned offset) {
String text;
int start, end;
for (RenderObject* object = m_renderView.get(); object; object = object->nextInPreOrder()) {
if (!object->isText())
continue;
RenderText* renderText = toRenderText(object);
text.append(renderText->text());
}
TextBreakIterator* it = wordBreakIterator(text, 0, text.length());
end = it->following(offset);
if (end < 0)
end = it->last();
start = it->previous();
Dart_Handle result = Dart_NewList(2);
Dart_ListSetAt(result, 0, ToDart(start));
Dart_ListSetAt(result, 1, ToDart(end));
return result;
}
} // namespace blink
......@@ -37,6 +37,7 @@ public:
std::vector<TextBox> getRectsForRange(unsigned start, unsigned end);
Dart_Handle getPositionForOffset(const Offset& offset);
Dart_Handle getWordBoundary(unsigned offset);
RenderView* renderView() const { return m_renderView.get(); }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册