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.h" | 5 #include "ui/gfx/render_text.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/i18n/break_iterator.h" | 9 #include "base/i18n/break_iterator.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "ui/gfx/canvas.h" | 12 #include "ui/gfx/canvas.h" |
13 #include "ui/gfx/canvas_skia.h" | 13 #include "ui/gfx/canvas_skia.h" |
14 #include "unicode/uchar.h" | 14 #include "unicode/uchar.h" |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
| 18 // Color settings for text, backgrounds and cursor. |
| 19 // These are tentative, and should be derived from theme, system |
| 20 // settings and current settings. |
| 21 // TODO(oshima): Change this to match the standard chrome |
| 22 // before dogfooding textfield views. |
| 23 const SkColor kSelectedTextColor = SK_ColorWHITE; |
| 24 const SkColor kFocusedSelectionColor = SkColorSetRGB(30, 144, 255); |
| 25 const SkColor kUnfocusedSelectionColor = SK_ColorLTGRAY; |
| 26 const SkColor kCursorColor = SK_ColorBLACK; |
| 27 |
18 #ifndef NDEBUG | 28 #ifndef NDEBUG |
19 // Check StyleRanges invariant conditions: sorted and non-overlapping ranges. | 29 // Check StyleRanges invariant conditions: sorted and non-overlapping ranges. |
20 void CheckStyleRanges(const gfx::StyleRanges& style_ranges, size_t length) { | 30 void CheckStyleRanges(const gfx::StyleRanges& style_ranges, size_t length) { |
21 if (length == 0) { | 31 if (length == 0) { |
22 DCHECK(style_ranges.empty()) << "Style ranges exist for empty text."; | 32 DCHECK(style_ranges.empty()) << "Style ranges exist for empty text."; |
23 return; | 33 return; |
24 } | 34 } |
25 for (gfx::StyleRanges::size_type i = 0; i < style_ranges.size() - 1; i++) { | 35 for (gfx::StyleRanges::size_type i = 0; i < style_ranges.size() - 1; i++) { |
26 const ui::Range& former = style_ranges[i].range; | 36 const ui::Range& former = style_ranges[i].range; |
27 const ui::Range& latter = style_ranges[i + 1].range; | 37 const ui::Range& latter = style_ranges[i + 1].range; |
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 void RenderText::DrawCursor(Canvas* canvas) { | 622 void RenderText::DrawCursor(Canvas* canvas) { |
613 // Paint cursor. Replace cursor is drawn as rectangle for now. | 623 // Paint cursor. Replace cursor is drawn as rectangle for now. |
614 // TODO(msw): Draw a better cursor with a better indication of association. | 624 // TODO(msw): Draw a better cursor with a better indication of association. |
615 if (cursor_visible() && focused()) { | 625 if (cursor_visible() && focused()) { |
616 Rect r(GetUpdatedCursorBounds()); | 626 Rect r(GetUpdatedCursorBounds()); |
617 canvas->DrawRectInt(kCursorColor, r.x(), r.y(), r.width(), r.height()); | 627 canvas->DrawRectInt(kCursorColor, r.x(), r.y(), r.width(), r.height()); |
618 } | 628 } |
619 } | 629 } |
620 | 630 |
621 } // namespace gfx | 631 } // namespace gfx |
OLD | NEW |