| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_harfbuzz.h" | 5 #include "ui/gfx/render_text_harfbuzz.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/i18n/bidi_line_iterator.h" | 10 #include "base/i18n/bidi_line_iterator.h" |
| (...skipping 1269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1280 LogicalCursorDirection affinity = caret.caret_affinity(); | 1280 LogicalCursorDirection affinity = caret.caret_affinity(); |
| 1281 internal::TextRunList* run_list = GetRunList(); | 1281 internal::TextRunList* run_list = GetRunList(); |
| 1282 for (size_t i = 0; i < run_list->size(); ++i) { | 1282 for (size_t i = 0; i < run_list->size(); ++i) { |
| 1283 internal::TextRunHarfBuzz* run = run_list->runs()[i]; | 1283 internal::TextRunHarfBuzz* run = run_list->runs()[i]; |
| 1284 if (RangeContainsCaret(run->range, layout_position, affinity)) | 1284 if (RangeContainsCaret(run->range, layout_position, affinity)) |
| 1285 return i; | 1285 return i; |
| 1286 } | 1286 } |
| 1287 return run_list->size(); | 1287 return run_list->size(); |
| 1288 } | 1288 } |
| 1289 | 1289 |
| 1290 int RenderTextHarfBuzz::GetLineContainingYCoord(float text_y) { | |
| 1291 if (text_y < 0) | |
| 1292 return -1; | |
| 1293 | |
| 1294 for (size_t i = 0; i < lines().size(); i++) { | |
| 1295 const internal::Line& line = lines()[i]; | |
| 1296 | |
| 1297 if (text_y <= line.size.height()) | |
| 1298 return i; | |
| 1299 text_y -= line.size.height(); | |
| 1300 } | |
| 1301 | |
| 1302 return lines().size(); | |
| 1303 } | |
| 1304 | |
| 1305 int RenderTextHarfBuzz::GetLineSegmentContainingXCoord( | |
| 1306 const internal::Line& line, | |
| 1307 float line_x, | |
| 1308 float* offset_relative_segment) { | |
| 1309 DCHECK(offset_relative_segment); | |
| 1310 | |
| 1311 *offset_relative_segment = 0; | |
| 1312 if (line_x < 0) | |
| 1313 return -1; | |
| 1314 for (size_t i = 0; i < line.segments.size(); i++) { | |
| 1315 const internal::LineSegment& segment = line.segments[i]; | |
| 1316 | |
| 1317 // segment.x_range is not used because it is in text space. | |
| 1318 if (line_x < segment.width()) { | |
| 1319 *offset_relative_segment = line_x; | |
| 1320 return i; | |
| 1321 } | |
| 1322 line_x -= segment.width(); | |
| 1323 } | |
| 1324 return line.segments.size(); | |
| 1325 } | |
| 1326 | |
| 1327 SelectionModel RenderTextHarfBuzz::FirstSelectionModelInsideRun( | 1290 SelectionModel RenderTextHarfBuzz::FirstSelectionModelInsideRun( |
| 1328 const internal::TextRunHarfBuzz* run) { | 1291 const internal::TextRunHarfBuzz* run) { |
| 1329 size_t position = DisplayIndexToTextIndex(run->range.start()); | 1292 size_t position = DisplayIndexToTextIndex(run->range.start()); |
| 1330 position = IndexOfAdjacentGrapheme(position, CURSOR_FORWARD); | 1293 position = IndexOfAdjacentGrapheme(position, CURSOR_FORWARD); |
| 1331 return SelectionModel(position, CURSOR_BACKWARD); | 1294 return SelectionModel(position, CURSOR_BACKWARD); |
| 1332 } | 1295 } |
| 1333 | 1296 |
| 1334 SelectionModel RenderTextHarfBuzz::LastSelectionModelInsideRun( | 1297 SelectionModel RenderTextHarfBuzz::LastSelectionModelInsideRun( |
| 1335 const internal::TextRunHarfBuzz* run) { | 1298 const internal::TextRunHarfBuzz* run) { |
| 1336 size_t position = DisplayIndexToTextIndex(run->range.end()); | 1299 size_t position = DisplayIndexToTextIndex(run->range.end()); |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1702 | 1665 |
| 1703 attribute.strike = run.strike; | 1666 attribute.strike = run.strike; |
| 1704 attribute.diagonal_strike = run.diagonal_strike; | 1667 attribute.diagonal_strike = run.diagonal_strike; |
| 1705 decorated_text->attributes.push_back(attribute); | 1668 decorated_text->attributes.push_back(attribute); |
| 1706 } | 1669 } |
| 1707 } | 1670 } |
| 1708 return true; | 1671 return true; |
| 1709 } | 1672 } |
| 1710 | 1673 |
| 1711 } // namespace gfx | 1674 } // namespace gfx |
| OLD | NEW |