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

Unified Diff: ui/gfx/render_text_pango.cc

Issue 252563003: Fix Views inline autocomplete with multi-char graphemes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Extrapolate on the comment. Created 6 years, 8 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
« no previous file with comments | « ui/gfx/render_text_pango.h ('k') | ui/gfx/render_text_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/render_text_pango.cc
diff --git a/ui/gfx/render_text_pango.cc b/ui/gfx/render_text_pango.cc
index fdf3d59e1e0a6ee556208ec21fc703eb34e0f065..bda684be1fbf73c0cc1009fd5fc32ead5ae1ff67 100644
--- a/ui/gfx/render_text_pango.cc
+++ b/ui/gfx/render_text_pango.cc
@@ -40,8 +40,7 @@ bool IsForwardMotion(VisualCursorDirection direction, const PangoItem* item) {
}
// Checks whether |range| contains |index|. This is not the same as calling
-// |range.Contains(gfx::Range(index))| - as that would return true when
-// |index| == |range.end()|.
+// range.Contains(Range(index)), which returns true if |index| == |range.end()|.
bool IndexInRange(const Range& range, size_t index) {
return index >= range.start() && index < range.end();
}
@@ -249,7 +248,7 @@ std::vector<Rect> RenderTextPango::GetSubstringBounds(const Range& range) {
size_t RenderTextPango::TextIndexToLayoutIndex(size_t index) const {
DCHECK(layout_);
- ptrdiff_t offset = gfx::UTF16IndexToOffset(text(), 0, index);
+ ptrdiff_t offset = UTF16IndexToOffset(text(), 0, index);
// Clamp layout indices to the length of the text actually used for layout.
offset = std::min<size_t>(offset, g_utf8_strlen(layout_text_, -1));
const char* layout_pointer = g_utf8_offset_to_pointer(layout_text_, offset);
@@ -260,24 +259,19 @@ size_t RenderTextPango::LayoutIndexToTextIndex(size_t index) const {
DCHECK(layout_);
const char* layout_pointer = layout_text_ + index;
const long offset = g_utf8_pointer_to_offset(layout_text_, layout_pointer);
- return gfx::UTF16OffsetToIndex(text(), 0, offset);
+ return UTF16OffsetToIndex(text(), 0, offset);
}
-bool RenderTextPango::IsCursorablePosition(size_t position) {
- if (position == 0 && text().empty())
+bool RenderTextPango::IsValidCursorIndex(size_t index) {
+ if (index == 0 || index == text().length())
return true;
- if (position >= text().length())
- return position == text().length();
- if (!gfx::IsValidCodePointIndex(text(), position))
+ if (!IsValidLogicalIndex(index))
return false;
EnsureLayout();
- ptrdiff_t offset = gfx::UTF16IndexToOffset(text(), 0, position);
- // Check that the index corresponds with a valid text code point, that it is
- // marked as a legitimate cursor position by Pango, and that it is not
- // truncated from layout text (its glyph is shown on screen).
- return (offset < num_log_attrs_ && log_attrs_[offset].is_cursor_position &&
- offset < g_utf8_strlen(layout_text_, -1));
+ ptrdiff_t offset = UTF16IndexToOffset(text(), 0, index);
+ // Check that the index is marked as a legitimate cursor position by Pango.
+ return offset < num_log_attrs_ && log_attrs_[offset].is_cursor_position;
}
void RenderTextPango::ResetLayout() {
@@ -391,11 +385,10 @@ void RenderTextPango::DrawVisualText(Canvas* canvas) {
ApplyTextShadows(&renderer);
// TODO(derat): Use font-specific params: http://crbug.com/125235
- const gfx::FontRenderParams& render_params =
- gfx::GetDefaultFontRenderParams();
+ const FontRenderParams& render_params = GetDefaultFontRenderParams();
const bool use_subpixel_rendering =
render_params.subpixel_rendering !=
- gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE;
+ FontRenderParams::SUBPIXEL_RENDERING_NONE;
renderer.SetFontSmoothingSettings(
render_params.antialiasing,
use_subpixel_rendering && !background_is_transparent(),
@@ -403,16 +396,16 @@ void RenderTextPango::DrawVisualText(Canvas* canvas) {
SkPaint::Hinting skia_hinting = SkPaint::kNormal_Hinting;
switch (render_params.hinting) {
- case gfx::FontRenderParams::HINTING_NONE:
+ case FontRenderParams::HINTING_NONE:
skia_hinting = SkPaint::kNo_Hinting;
break;
- case gfx::FontRenderParams::HINTING_SLIGHT:
+ case FontRenderParams::HINTING_SLIGHT:
skia_hinting = SkPaint::kSlight_Hinting;
break;
- case gfx::FontRenderParams::HINTING_MEDIUM:
+ case FontRenderParams::HINTING_MEDIUM:
skia_hinting = SkPaint::kNormal_Hinting;
break;
- case gfx::FontRenderParams::HINTING_FULL:
+ case FontRenderParams::HINTING_FULL:
skia_hinting = SkPaint::kFull_Hinting;
break;
}
« no previous file with comments | « ui/gfx/render_text_pango.h ('k') | ui/gfx/render_text_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698