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

Side by Side Diff: ui/gfx/render_text_linux.cc

Issue 23769011: Move a bunch of windows stuff from ui/base/win to ui/gfx/win (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moar bustage. Created 7 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gfx/render_text.cc ('k') | ui/gfx/render_text_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include <algorithm> 8 #include <algorithm>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/i18n/break_iterator.h" 12 #include "base/i18n/break_iterator.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "third_party/skia/include/core/SkTypeface.h" 14 #include "third_party/skia/include/core/SkTypeface.h"
15 #include "ui/base/text/utf16_indexing.h"
16 #include "ui/gfx/canvas.h" 15 #include "ui/gfx/canvas.h"
17 #include "ui/gfx/font.h" 16 #include "ui/gfx/font.h"
18 #include "ui/gfx/font_render_params_linux.h" 17 #include "ui/gfx/font_render_params_linux.h"
19 #include "ui/gfx/pango_util.h" 18 #include "ui/gfx/pango_util.h"
19 #include "ui/gfx/utf16_indexing.h"
20 20
21 namespace gfx { 21 namespace gfx {
22 22
23 namespace { 23 namespace {
24 24
25 // Returns the preceding element in a GSList (O(n)). 25 // Returns the preceding element in a GSList (O(n)).
26 GSList* GSListPrevious(GSList* head, GSList* item) { 26 GSList* GSListPrevious(GSList* head, GSList* item) {
27 GSList* prev = NULL; 27 GSList* prev = NULL;
28 for (GSList* cur = head; cur != item; cur = cur->next) { 28 for (GSList* cur = head; cur != item; cur = cur->next) {
29 DCHECK(cur); 29 DCHECK(cur);
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 Rect rect(x, 0, width, height); 245 Rect rect(x, 0, width, height);
246 rect.set_origin(ToViewPoint(rect.origin())); 246 rect.set_origin(ToViewPoint(rect.origin()));
247 bounds.push_back(rect); 247 bounds.push_back(rect);
248 } 248 }
249 g_free(ranges); 249 g_free(ranges);
250 return bounds; 250 return bounds;
251 } 251 }
252 252
253 size_t RenderTextLinux::TextIndexToLayoutIndex(size_t index) const { 253 size_t RenderTextLinux::TextIndexToLayoutIndex(size_t index) const {
254 DCHECK(layout_); 254 DCHECK(layout_);
255 ptrdiff_t offset = ui::UTF16IndexToOffset(text(), 0, index); 255 ptrdiff_t offset = gfx::UTF16IndexToOffset(text(), 0, index);
256 // Clamp layout indices to the length of the text actually used for layout. 256 // Clamp layout indices to the length of the text actually used for layout.
257 offset = std::min<size_t>(offset, g_utf8_strlen(layout_text_, -1)); 257 offset = std::min<size_t>(offset, g_utf8_strlen(layout_text_, -1));
258 const char* layout_pointer = g_utf8_offset_to_pointer(layout_text_, offset); 258 const char* layout_pointer = g_utf8_offset_to_pointer(layout_text_, offset);
259 return (layout_pointer - layout_text_); 259 return (layout_pointer - layout_text_);
260 } 260 }
261 261
262 size_t RenderTextLinux::LayoutIndexToTextIndex(size_t index) const { 262 size_t RenderTextLinux::LayoutIndexToTextIndex(size_t index) const {
263 DCHECK(layout_); 263 DCHECK(layout_);
264 const char* layout_pointer = layout_text_ + index; 264 const char* layout_pointer = layout_text_ + index;
265 const long offset = g_utf8_pointer_to_offset(layout_text_, layout_pointer); 265 const long offset = g_utf8_pointer_to_offset(layout_text_, layout_pointer);
266 return ui::UTF16OffsetToIndex(text(), 0, offset); 266 return gfx::UTF16OffsetToIndex(text(), 0, offset);
267 } 267 }
268 268
269 bool RenderTextLinux::IsCursorablePosition(size_t position) { 269 bool RenderTextLinux::IsCursorablePosition(size_t position) {
270 if (position == 0 && text().empty()) 270 if (position == 0 && text().empty())
271 return true; 271 return true;
272 if (position >= text().length()) 272 if (position >= text().length())
273 return position == text().length(); 273 return position == text().length();
274 if (!ui::IsValidCodePointIndex(text(), position)) 274 if (!gfx::IsValidCodePointIndex(text(), position))
275 return false; 275 return false;
276 276
277 EnsureLayout(); 277 EnsureLayout();
278 ptrdiff_t offset = ui::UTF16IndexToOffset(text(), 0, position); 278 ptrdiff_t offset = gfx::UTF16IndexToOffset(text(), 0, position);
279 // Check that the index corresponds with a valid text code point, that it is 279 // Check that the index corresponds with a valid text code point, that it is
280 // marked as a legitimate cursor position by Pango, and that it is not 280 // marked as a legitimate cursor position by Pango, and that it is not
281 // truncated from layout text (its glyph is shown on screen). 281 // truncated from layout text (its glyph is shown on screen).
282 return (offset < num_log_attrs_ && log_attrs_[offset].is_cursor_position && 282 return (offset < num_log_attrs_ && log_attrs_[offset].is_cursor_position &&
283 offset < g_utf8_strlen(layout_text_, -1)); 283 offset < g_utf8_strlen(layout_text_, -1));
284 } 284 }
285 285
286 void RenderTextLinux::ResetLayout() { 286 void RenderTextLinux::ResetLayout() {
287 // set_cached_bounds_and_offset_valid(false) is done in RenderText for every 287 // set_cached_bounds_and_offset_valid(false) is done in RenderText for every
288 // operation that triggers ResetLayout(). 288 // operation that triggers ResetLayout().
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 int glyph_index) const { 504 int glyph_index) const {
505 return LayoutIndexToTextIndex(run->item->offset + 505 return LayoutIndexToTextIndex(run->item->offset +
506 run->glyphs->log_clusters[glyph_index]); 506 run->glyphs->log_clusters[glyph_index]);
507 } 507 }
508 508
509 RenderText* RenderText::CreateInstance() { 509 RenderText* RenderText::CreateInstance() {
510 return new RenderTextLinux; 510 return new RenderTextLinux;
511 } 511 }
512 512
513 } // namespace gfx 513 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/render_text.cc ('k') | ui/gfx/render_text_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698