OLD | NEW |
---|---|
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.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" |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
599 } | 599 } |
600 | 600 |
601 VisualCursorDirection RenderText::GetVisualDirectionOfLogicalEnd() { | 601 VisualCursorDirection RenderText::GetVisualDirectionOfLogicalEnd() { |
602 return GetTextDirection() == base::i18n::LEFT_TO_RIGHT ? | 602 return GetTextDirection() == base::i18n::LEFT_TO_RIGHT ? |
603 CURSOR_RIGHT : CURSOR_LEFT; | 603 CURSOR_RIGHT : CURSOR_LEFT; |
604 } | 604 } |
605 | 605 |
606 void RenderText::Draw(Canvas* canvas) { | 606 void RenderText::Draw(Canvas* canvas) { |
607 EnsureLayout(); | 607 EnsureLayout(); |
608 | 608 |
609 gfx::Rect clip_rect(display_rect()); | 609 // Normally, always clipping is harmless. However, there is a Skia bug with |
610 clip_rect.Inset(ShadowValue::GetMargin(text_shadows_)); | 610 // the PDF path (http://crbug.com/133548) that results in incorrect clipping |
611 // when drawing to the document margins. Workaround the issue by only clipping | |
612 // when necessary, since the PDF print path does not require clipping. | |
613 // | |
614 // TODO(asvitkine): Remove this logic once http://crbug.com/133548 is fixed | |
615 // on the Skia side. | |
616 const Size size = GetStringSize(); | |
617 const bool need_to_clip = display_rect().width() < size.width() || | |
msw
2012/06/22 19:30:13
This doesn't account for display_offset_ or other
| |
618 display_rect().height() < size.height(); | |
619 if (need_to_clip) { | |
620 gfx::Rect clip_rect(display_rect()); | |
621 clip_rect.Inset(ShadowValue::GetMargin(text_shadows_)); | |
611 | 622 |
612 canvas->Save(); | 623 canvas->Save(); |
613 canvas->ClipRect(clip_rect); | 624 canvas->ClipRect(clip_rect); |
625 } | |
614 | 626 |
615 if (!text().empty()) | 627 if (!text().empty()) |
616 DrawSelection(canvas); | 628 DrawSelection(canvas); |
617 | 629 |
618 DrawCursor(canvas); | 630 DrawCursor(canvas); |
619 | 631 |
620 if (!text().empty()) | 632 if (!text().empty()) |
621 DrawVisualText(canvas); | 633 DrawVisualText(canvas); |
622 canvas->Restore(); | 634 |
635 if (need_to_clip) | |
636 canvas->Restore(); | |
623 } | 637 } |
624 | 638 |
625 Rect RenderText::GetCursorBounds(const SelectionModel& caret, | 639 Rect RenderText::GetCursorBounds(const SelectionModel& caret, |
626 bool insert_mode) { | 640 bool insert_mode) { |
627 EnsureLayout(); | 641 EnsureLayout(); |
628 | 642 |
629 size_t caret_pos = caret.caret_pos(); | 643 size_t caret_pos = caret.caret_pos(); |
630 // In overtype mode, ignore the affinity and always indicate that we will | 644 // In overtype mode, ignore the affinity and always indicate that we will |
631 // overtype the next character. | 645 // overtype the next character. |
632 LogicalCursorDirection caret_affinity = | 646 LogicalCursorDirection caret_affinity = |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
961 if (cursor_enabled() && cursor_visible() && focused()) { | 975 if (cursor_enabled() && cursor_visible() && focused()) { |
962 const Rect& bounds = GetUpdatedCursorBounds(); | 976 const Rect& bounds = GetUpdatedCursorBounds(); |
963 if (bounds.width() != 0) | 977 if (bounds.width() != 0) |
964 canvas->FillRect(bounds, cursor_color_); | 978 canvas->FillRect(bounds, cursor_color_); |
965 else | 979 else |
966 canvas->DrawRect(bounds, cursor_color_); | 980 canvas->DrawRect(bounds, cursor_color_); |
967 } | 981 } |
968 } | 982 } |
969 | 983 |
970 } // namespace gfx | 984 } // namespace gfx |
OLD | NEW |