Chromium Code Reviews| Index: ui/gfx/render_text_linux.cc |
| =================================================================== |
| --- ui/gfx/render_text_linux.cc (revision 100008) |
| +++ ui/gfx/render_text_linux.cc (working copy) |
| @@ -123,13 +123,19 @@ |
| } |
| SelectionModel RenderTextLinux::FindCursorPosition(const Point& point) { |
| - // TODO(xji): when points outside of text, return HOME/END position. |
| PangoLayout* layout = EnsureLayout(); |
| if (text().empty()) |
| return SelectionModel(0, 0, SelectionModel::LEADING); |
| Point p(ToTextPoint(point)); |
| + |
| + // When points outside of text, return HOME/END position. |
|
msw
2011/09/09 23:03:24
"When *the point is* outside" or "*For* points out
xji
2011/09/12 21:31:48
Done.
|
| + if (p.x() < 0) |
| + return LeftEndSelectionModel(); |
| + else if (p.x() > GetStringWidth()) |
| + return RightEndSelectionModel(); |
| + |
| int caret_pos, trailing; |
| pango_layout_xy_to_index(layout, p.x() * PANGO_SCALE, p.y() * PANGO_SCALE, |
| &caret_pos, &trailing); |
| @@ -175,6 +181,12 @@ |
| return bounds; |
| } |
| +size_t RenderTextLinux::GetIndexOfNextGrapheme(size_t position) { |
| + EnsureLayout(); |
| + size_t index = Utf16IndexToUtf8Index(position); |
| + return Utf16IndexOfAdjacentGrapheme(index, NEXT); |
| +} |
| + |
| SelectionModel RenderTextLinux::GetLeftSelectionModel( |
| const SelectionModel& current, |
| BreakType break_type) { |
| @@ -244,10 +256,13 @@ |
| return Utf16IndexOfAdjacentGrapheme(index, PREVIOUS); |
| } |
| -size_t RenderTextLinux::GetIndexOfNextGrapheme(size_t position) { |
| +bool RenderTextLinux::IsCursorablePosition(size_t position) { |
| + if (position == 0 && text().empty()) |
| + return true; |
| + |
| EnsureLayout(); |
| - size_t index = Utf16IndexToUtf8Index(position); |
| - return Utf16IndexOfAdjacentGrapheme(index, NEXT); |
| + return (position >= 0 && position < (size_t)num_log_attrs_ && |
|
msw
2011/09/09 23:03:24
Use c++ style static_cast.
xji
2011/09/12 21:31:48
Done.
|
| + log_attrs_[position].is_cursor_position); |
| } |
| GSList* RenderTextLinux::GetRunContainingPosition(size_t position) const { |