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

Side by Side Diff: ui/gfx/render_text.h

Issue 25039002: Always aligns text at vertically center (Textfield, Label). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Synced. Created 7 years, 1 month 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/platform_font_pango.cc ('k') | ui/gfx/render_text.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 #ifndef UI_GFX_RENDER_TEXT_H_ 5 #ifndef UI_GFX_RENDER_TEXT_H_
6 #define UI_GFX_RENDER_TEXT_H_ 6 #define UI_GFX_RENDER_TEXT_H_
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <cstring> 9 #include <cstring>
10 #include <string> 10 #include <string>
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 static RenderText* CreateInstance(); 160 static RenderText* CreateInstance();
161 161
162 const base::string16& text() const { return text_; } 162 const base::string16& text() const { return text_; }
163 void SetText(const base::string16& text); 163 void SetText(const base::string16& text);
164 164
165 HorizontalAlignment horizontal_alignment() const { 165 HorizontalAlignment horizontal_alignment() const {
166 return horizontal_alignment_; 166 return horizontal_alignment_;
167 } 167 }
168 void SetHorizontalAlignment(HorizontalAlignment alignment); 168 void SetHorizontalAlignment(HorizontalAlignment alignment);
169 169
170 VerticalAlignment vertical_alignment() const {
171 return vertical_alignment_;
172 }
173 void SetVerticalAlignment(VerticalAlignment alignment);
174
175 const FontList& font_list() const { return font_list_; } 170 const FontList& font_list() const { return font_list_; }
176 void SetFontList(const FontList& font_list); 171 void SetFontList(const FontList& font_list);
177 void SetFont(const Font& font); 172 void SetFont(const Font& font);
178 173
179 // Set the font size to |size| in pixels. 174 // Set the font size to |size| in pixels.
180 void SetFontSize(int size); 175 void SetFontSize(int size);
181 176
182 // Get the first font in |font_list_|. 177 // Get the first font in |font_list_|.
183 const Font& GetPrimaryFont() const; 178 const Font& GetPrimaryFont() const;
184 179
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 // The default implementation is same as GetStringSize. Certain platforms that 326 // The default implementation is same as GetStringSize. Certain platforms that
332 // compute the text size as floating-point values, like Mac, will override 327 // compute the text size as floating-point values, like Mac, will override
333 // this method. 328 // this method.
334 // See comment in Canvas::GetStringWidthF for its usage. 329 // See comment in Canvas::GetStringWidthF for its usage.
335 virtual SizeF GetStringSizeF(); 330 virtual SizeF GetStringSizeF();
336 331
337 // Returns the width of the content (which is the wrapped width in multiline 332 // Returns the width of the content (which is the wrapped width in multiline
338 // mode). Reserves room for the cursor if |cursor_enabled_| is true. 333 // mode). Reserves room for the cursor if |cursor_enabled_| is true.
339 int GetContentWidth(); 334 int GetContentWidth();
340 335
341 // Returns the common baseline of the text. The returned value is the vertical 336 // Returns the common baseline of the text. The return value is the vertical
342 // offset from the top of |display_rect| to the text baseline, in pixels. 337 // offset from the top of |display_rect_| to the text baseline, in pixels.
343 virtual int GetBaseline() = 0; 338 // The baseline is determined from the font list and display rect, and does
339 // not depend on the text.
340 int GetBaseline();
344 341
345 void Draw(Canvas* canvas); 342 void Draw(Canvas* canvas);
346 343
347 // Draws a cursor at |position|. 344 // Draws a cursor at |position|.
348 void DrawCursor(Canvas* canvas, const SelectionModel& position); 345 void DrawCursor(Canvas* canvas, const SelectionModel& position);
349 346
350 // Draw the selected text without a cursor or selection highlight. Subpixel 347 // Draw the selected text without a cursor or selection highlight. Subpixel
351 // antialiasing is disabled and foreground color is forced to black. 348 // antialiasing is disabled and foreground color is forced to black.
352 void DrawSelectedTextForDrag(Canvas* canvas); 349 void DrawSelectedTextForDrag(Canvas* canvas);
353 350
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 388
392 protected: 389 protected:
393 RenderText(); 390 RenderText();
394 391
395 const BreakList<SkColor>& colors() const { return colors_; } 392 const BreakList<SkColor>& colors() const { return colors_; }
396 const std::vector<BreakList<bool> >& styles() const { return styles_; } 393 const std::vector<BreakList<bool> >& styles() const { return styles_; }
397 394
398 const std::vector<internal::Line>& lines() const { return lines_; } 395 const std::vector<internal::Line>& lines() const { return lines_; }
399 void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); } 396 void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); }
400 397
398 // Returns the baseline of the current text. The return value depends on
399 // the text and its layout while the return value of GetBaseline() doesn't.
400 // GetAlignmentOffset() takes into account the difference between them.
401 //
402 // We'd like a RenderText to show the text always on the same baseline
403 // regardless of the text, so the text does not jump up or down depending
404 // on the text. However, underlying layout engines return different baselines
405 // depending on the text. In general, layout engines determine the minimum
406 // bounding box for the text and return the baseline from the top of the
407 // bounding box. So the baseline changes depending on font metrics used to
408 // layout the text.
409 //
410 // For example, suppose there are FontA and FontB and the baseline of FontA
411 // is smaller than the one of FontB. If the text is laid out only with FontA,
412 // then the baseline of FontA may be returned. If the text includes some
413 // characters which are laid out with FontB, then the baseline of FontB may
414 // be returned.
415 //
416 // GetBaseline() returns the fixed baseline regardless of the text.
417 // GetLayoutTextBaseline() returns the baseline determined by the underlying
418 // layout engine, and it changes depending on the text. GetAlignmentOffset()
419 // returns the difference between them.
420 virtual int GetLayoutTextBaseline() = 0;
421
401 const Vector2d& GetUpdatedDisplayOffset(); 422 const Vector2d& GetUpdatedDisplayOffset();
402 423
403 void set_cached_bounds_and_offset_valid(bool valid) { 424 void set_cached_bounds_and_offset_valid(bool valid) {
404 cached_bounds_and_offset_valid_ = valid; 425 cached_bounds_and_offset_valid_ = valid;
405 } 426 }
406 427
407 // Get the selection model that visually neighbors |position| by |break_type|. 428 // Get the selection model that visually neighbors |position| by |break_type|.
408 // The returned value represents a cursor/caret position without a selection. 429 // The returned value represents a cursor/caret position without a selection.
409 SelectionModel GetAdjacentSelectionModel(const SelectionModel& current, 430 SelectionModel GetAdjacentSelectionModel(const SelectionModel& current,
410 BreakType break_type, 431 BreakType break_type,
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 // Draw the selection. 556 // Draw the selection.
536 void DrawSelection(Canvas* canvas); 557 void DrawSelection(Canvas* canvas);
537 558
538 // Logical UTF-16 string data to be drawn. 559 // Logical UTF-16 string data to be drawn.
539 base::string16 text_; 560 base::string16 text_;
540 561
541 // Horizontal alignment of the text with respect to |display_rect_|. The 562 // Horizontal alignment of the text with respect to |display_rect_|. The
542 // default is to align left if the application UI is LTR and right if RTL. 563 // default is to align left if the application UI is LTR and right if RTL.
543 HorizontalAlignment horizontal_alignment_; 564 HorizontalAlignment horizontal_alignment_;
544 565
545 // Vertical alignment of the text with respect to |display_rect_|. The
546 // default is to align vertically centered.
547 VerticalAlignment vertical_alignment_;
548
549 // The text directionality mode, defaults to DIRECTIONALITY_FROM_TEXT. 566 // The text directionality mode, defaults to DIRECTIONALITY_FROM_TEXT.
550 DirectionalityMode directionality_mode_; 567 DirectionalityMode directionality_mode_;
551 568
552 // The cached text direction, potentially computed from the text or UI locale. 569 // The cached text direction, potentially computed from the text or UI locale.
553 // Use GetTextDirection(), do not use this potentially invalid value directly! 570 // Use GetTextDirection(), do not use this potentially invalid value directly!
554 base::i18n::TextDirection text_direction_; 571 base::i18n::TextDirection text_direction_;
555 572
556 // A list of fonts used to render |text_|. 573 // A list of fonts used to render |text_|.
557 FontList font_list_; 574 FontList font_list_;
558 575
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 // Flag to work around a Skia bug with the PDF path (http://crbug.com/133548) 641 // Flag to work around a Skia bug with the PDF path (http://crbug.com/133548)
625 // that results in incorrect clipping when drawing to the document margins. 642 // that results in incorrect clipping when drawing to the document margins.
626 // This field allows disabling clipping to work around the issue. 643 // This field allows disabling clipping to work around the issue.
627 // TODO(asvitkine): Remove this when the underlying Skia bug is fixed. 644 // TODO(asvitkine): Remove this when the underlying Skia bug is fixed.
628 bool clip_to_display_rect_; 645 bool clip_to_display_rect_;
629 646
630 // The offset for the text to be drawn, relative to the display area. 647 // The offset for the text to be drawn, relative to the display area.
631 // Get this point with GetUpdatedDisplayOffset (or risk using a stale value). 648 // Get this point with GetUpdatedDisplayOffset (or risk using a stale value).
632 Vector2d display_offset_; 649 Vector2d display_offset_;
633 650
651 // The baseline of the text. This is determined from the height of the
652 // display area and the cap height of the font list so the text is vertically
653 // centered.
654 int baseline_;
655
634 // The cached bounds and offset are invalidated by changes to the cursor, 656 // The cached bounds and offset are invalidated by changes to the cursor,
635 // selection, font, and other operations that adjust the visible text bounds. 657 // selection, font, and other operations that adjust the visible text bounds.
636 bool cached_bounds_and_offset_valid_; 658 bool cached_bounds_and_offset_valid_;
637 659
638 // Text shadows to be drawn. 660 // Text shadows to be drawn.
639 ShadowValues text_shadows_; 661 ShadowValues text_shadows_;
640 662
641 // A list of valid layout text line break positions. 663 // A list of valid layout text line break positions.
642 BreakList<size_t> line_breaks_; 664 BreakList<size_t> line_breaks_;
643 665
644 // Lines computed by EnsureLayout. These should be invalidated with 666 // Lines computed by EnsureLayout. These should be invalidated with
645 // ResetLayout and on |display_rect_| changes. 667 // ResetLayout and on |display_rect_| changes.
646 std::vector<internal::Line> lines_; 668 std::vector<internal::Line> lines_;
647 669
648 DISALLOW_COPY_AND_ASSIGN(RenderText); 670 DISALLOW_COPY_AND_ASSIGN(RenderText);
649 }; 671 };
650 672
651 } // namespace gfx 673 } // namespace gfx
652 674
653 #endif // UI_GFX_RENDER_TEXT_H_ 675 #endif // UI_GFX_RENDER_TEXT_H_
OLDNEW
« no previous file with comments | « ui/gfx/platform_font_pango.cc ('k') | ui/gfx/render_text.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698