Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/gfx/render_text_linux.h" | 5 #include "ui/gfx/render_text_linux.h" |
| 6 | 6 |
| 7 #include <pango/pangocairo.h> | 7 #include <pango/pangocairo.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 bounds = GetUpdatedCursorBounds(); | 116 bounds = GetUpdatedCursorBounds(); |
| 117 if (cursor_visible() && focused()) | 117 if (cursor_visible() && focused()) |
| 118 canvas->DrawRectInt(kCursorColor, | 118 canvas->DrawRectInt(kCursorColor, |
| 119 bounds.x(), | 119 bounds.x(), |
| 120 bounds.y(), | 120 bounds.y(), |
| 121 bounds.width(), | 121 bounds.width(), |
| 122 bounds.height()); | 122 bounds.height()); |
| 123 } | 123 } |
| 124 | 124 |
| 125 SelectionModel RenderTextLinux::FindCursorPosition(const Point& point) { | 125 SelectionModel RenderTextLinux::FindCursorPosition(const Point& point) { |
| 126 // TODO(xji): when points outside of text, return HOME/END position. | |
| 127 PangoLayout* layout = EnsureLayout(); | 126 PangoLayout* layout = EnsureLayout(); |
| 128 | 127 |
| 129 if (text().empty()) | 128 if (text().empty()) |
| 130 return SelectionModel(0, 0, SelectionModel::LEADING); | 129 return SelectionModel(0, 0, SelectionModel::LEADING); |
| 131 | 130 |
| 132 Point p(ToTextPoint(point)); | 131 Point p(ToTextPoint(point)); |
| 132 | |
| 133 // 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.
| |
| 134 if (p.x() < 0) | |
| 135 return LeftEndSelectionModel(); | |
| 136 else if (p.x() > GetStringWidth()) | |
| 137 return RightEndSelectionModel(); | |
| 138 | |
| 133 int caret_pos, trailing; | 139 int caret_pos, trailing; |
| 134 pango_layout_xy_to_index(layout, p.x() * PANGO_SCALE, p.y() * PANGO_SCALE, | 140 pango_layout_xy_to_index(layout, p.x() * PANGO_SCALE, p.y() * PANGO_SCALE, |
| 135 &caret_pos, &trailing); | 141 &caret_pos, &trailing); |
| 136 | 142 |
| 137 size_t selection_end = caret_pos; | 143 size_t selection_end = caret_pos; |
| 138 if (trailing > 0) { | 144 if (trailing > 0) { |
| 139 const char* ch = g_utf8_offset_to_pointer(layout_text_ + caret_pos, | 145 const char* ch = g_utf8_offset_to_pointer(layout_text_ + caret_pos, |
| 140 trailing); | 146 trailing); |
| 141 DCHECK_GE(ch, layout_text_); | 147 DCHECK_GE(ch, layout_text_); |
| 142 DCHECK_LE(ch, layout_text_ + layout_text_len_); | 148 DCHECK_LE(ch, layout_text_ + layout_text_len_); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 168 int h = std::min(display_rect().height(), PANGO_PIXELS(pos.height)); | 174 int h = std::min(display_rect().height(), PANGO_PIXELS(pos.height)); |
| 169 Rect bounds(x, (display_rect().height() - h) / 2, 0, h); | 175 Rect bounds(x, (display_rect().height() - h) / 2, 0, h); |
| 170 bounds.set_origin(ToViewPoint(bounds.origin())); | 176 bounds.set_origin(ToViewPoint(bounds.origin())); |
| 171 | 177 |
| 172 if (!insert_mode) | 178 if (!insert_mode) |
| 173 bounds.set_width(std::abs(pos.width)); | 179 bounds.set_width(std::abs(pos.width)); |
| 174 | 180 |
| 175 return bounds; | 181 return bounds; |
| 176 } | 182 } |
| 177 | 183 |
| 184 size_t RenderTextLinux::GetIndexOfNextGrapheme(size_t position) { | |
| 185 EnsureLayout(); | |
| 186 size_t index = Utf16IndexToUtf8Index(position); | |
| 187 return Utf16IndexOfAdjacentGrapheme(index, NEXT); | |
| 188 } | |
| 189 | |
| 178 SelectionModel RenderTextLinux::GetLeftSelectionModel( | 190 SelectionModel RenderTextLinux::GetLeftSelectionModel( |
| 179 const SelectionModel& current, | 191 const SelectionModel& current, |
| 180 BreakType break_type) { | 192 BreakType break_type) { |
| 181 EnsureLayout(); | 193 EnsureLayout(); |
| 182 | 194 |
| 183 if (break_type == LINE_BREAK || text().empty()) | 195 if (break_type == LINE_BREAK || text().empty()) |
| 184 return LeftEndSelectionModel(); | 196 return LeftEndSelectionModel(); |
| 185 if (break_type == CHARACTER_BREAK) | 197 if (break_type == CHARACTER_BREAK) |
| 186 return LeftSelectionModel(current); | 198 return LeftSelectionModel(current); |
| 187 // TODO(xji): not implemented yet. | 199 // TODO(xji): not implemented yet. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 } | 249 } |
| 238 return SelectionModel(0, 0, SelectionModel::LEADING); | 250 return SelectionModel(0, 0, SelectionModel::LEADING); |
| 239 } | 251 } |
| 240 | 252 |
| 241 size_t RenderTextLinux::GetIndexOfPreviousGrapheme(size_t position) { | 253 size_t RenderTextLinux::GetIndexOfPreviousGrapheme(size_t position) { |
| 242 EnsureLayout(); | 254 EnsureLayout(); |
| 243 size_t index = Utf16IndexToUtf8Index(position); | 255 size_t index = Utf16IndexToUtf8Index(position); |
| 244 return Utf16IndexOfAdjacentGrapheme(index, PREVIOUS); | 256 return Utf16IndexOfAdjacentGrapheme(index, PREVIOUS); |
| 245 } | 257 } |
| 246 | 258 |
| 247 size_t RenderTextLinux::GetIndexOfNextGrapheme(size_t position) { | 259 bool RenderTextLinux::IsCursorablePosition(size_t position) { |
| 260 if (position == 0 && text().empty()) | |
| 261 return true; | |
| 262 | |
| 248 EnsureLayout(); | 263 EnsureLayout(); |
| 249 size_t index = Utf16IndexToUtf8Index(position); | 264 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.
| |
| 250 return Utf16IndexOfAdjacentGrapheme(index, NEXT); | 265 log_attrs_[position].is_cursor_position); |
| 251 } | 266 } |
| 252 | 267 |
| 253 GSList* RenderTextLinux::GetRunContainingPosition(size_t position) const { | 268 GSList* RenderTextLinux::GetRunContainingPosition(size_t position) const { |
| 254 GSList* run = current_line_->runs; | 269 GSList* run = current_line_->runs; |
| 255 while (run) { | 270 while (run) { |
| 256 PangoItem* item = reinterpret_cast<PangoLayoutRun*>(run->data)->item; | 271 PangoItem* item = reinterpret_cast<PangoLayoutRun*>(run->data)->item; |
| 257 size_t run_start = Utf8IndexToUtf16Index(item->offset); | 272 size_t run_start = Utf8IndexToUtf16Index(item->offset); |
| 258 size_t run_end = Utf8IndexToUtf16Index(item->offset + item->length); | 273 size_t run_end = Utf8IndexToUtf16Index(item->offset + item->length); |
| 259 | 274 |
| 260 if (position >= run_start && position < run_end) | 275 if (position >= run_start && position < run_end) |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 581 size_t RenderTextLinux::Utf8IndexToUtf16Index(size_t index) const { | 596 size_t RenderTextLinux::Utf8IndexToUtf16Index(size_t index) const { |
| 582 int32_t utf16_index = 0; | 597 int32_t utf16_index = 0; |
| 583 UErrorCode ec = U_ZERO_ERROR; | 598 UErrorCode ec = U_ZERO_ERROR; |
| 584 u_strFromUTF8(NULL, 0, &utf16_index, layout_text_, index, &ec); | 599 u_strFromUTF8(NULL, 0, &utf16_index, layout_text_, index, &ec); |
| 585 DCHECK(ec == U_BUFFER_OVERFLOW_ERROR || | 600 DCHECK(ec == U_BUFFER_OVERFLOW_ERROR || |
| 586 ec == U_STRING_NOT_TERMINATED_WARNING); | 601 ec == U_STRING_NOT_TERMINATED_WARNING); |
| 587 return utf16_index; | 602 return utf16_index; |
| 588 } | 603 } |
| 589 | 604 |
| 590 } // namespace gfx | 605 } // namespace gfx |
| OLD | NEW |