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_win.h" | 5 #include "ui/gfx/render_text_win.h" |
6 | 6 |
7 #include "base/i18n/break_iterator.h" | 7 #include "base/i18n/break_iterator.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 RenderText::ApplyDefaultStyle(); | 93 RenderText::ApplyDefaultStyle(); |
94 ItemizeLogicalText(); | 94 ItemizeLogicalText(); |
95 LayoutVisualText(CreateCompatibleDC(NULL)); | 95 LayoutVisualText(CreateCompatibleDC(NULL)); |
96 } | 96 } |
97 | 97 |
98 int RenderTextWin::GetStringWidth() { | 98 int RenderTextWin::GetStringWidth() { |
99 return string_width_; | 99 return string_width_; |
100 } | 100 } |
101 | 101 |
102 void RenderTextWin::Draw(Canvas* canvas) { | 102 void RenderTextWin::Draw(Canvas* canvas) { |
103 skia::ScopedPlatformPaint scoped_platform_paint(canvas->AsCanvasSkia()); | 103 skia::ScopedPlatformPaint scoped_platform_paint(canvas->GetSkCanvas()); |
104 HDC hdc = scoped_platform_paint.GetPlatformSurface(); | 104 HDC hdc = scoped_platform_paint.GetPlatformSurface(); |
105 int saved_dc = SaveDC(hdc); | 105 int saved_dc = SaveDC(hdc); |
106 DrawSelection(canvas); | 106 DrawSelection(canvas); |
107 DrawVisualText(canvas); | 107 DrawVisualText(canvas); |
108 DrawCursor(canvas); | 108 DrawCursor(canvas); |
109 RestoreDC(hdc, saved_dc); | 109 RestoreDC(hdc, saved_dc); |
110 } | 110 } |
111 | 111 |
112 SelectionModel RenderTextWin::FindCursorPosition(const Point& point) { | 112 SelectionModel RenderTextWin::FindCursorPosition(const Point& point) { |
113 if (text().empty()) | 113 if (text().empty()) |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 GetSubstringBounds(GetSelectionStart(), GetCursorPosition())); | 583 GetSubstringBounds(GetSelectionStart(), GetCursorPosition())); |
584 SkColor color = focused() ? kFocusedSelectionColor : kUnfocusedSelectionColor; | 584 SkColor color = focused() ? kFocusedSelectionColor : kUnfocusedSelectionColor; |
585 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) | 585 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) |
586 canvas->FillRectInt(color, i->x(), i->y(), i->width(), i->height()); | 586 canvas->FillRectInt(color, i->x(), i->y(), i->width(), i->height()); |
587 } | 587 } |
588 | 588 |
589 void RenderTextWin::DrawVisualText(Canvas* canvas) { | 589 void RenderTextWin::DrawVisualText(Canvas* canvas) { |
590 if (text().empty()) | 590 if (text().empty()) |
591 return; | 591 return; |
592 | 592 |
593 CanvasSkia* canvas_skia = canvas->AsCanvasSkia(); | 593 SkCanvas* canvas_skia = canvas->GetSkCanvas(); |
594 skia::ScopedPlatformPaint scoped_platform_paint(canvas_skia); | 594 skia::ScopedPlatformPaint scoped_platform_paint(canvas_skia); |
595 | 595 |
596 Point offset(ToViewPoint(Point())); | 596 Point offset(ToViewPoint(Point())); |
597 // TODO(msw): Establish a vertical baseline for strings of mixed font heights. | 597 // TODO(msw): Establish a vertical baseline for strings of mixed font heights. |
598 size_t height = default_style().font.GetHeight(); | 598 size_t height = default_style().font.GetHeight(); |
599 // Center the text vertically in the display area. | 599 // Center the text vertically in the display area. |
600 offset.Offset(0, (display_rect().height() - height) / 2); | 600 offset.Offset(0, (display_rect().height() - height) / 2); |
601 | 601 |
602 SkPaint paint; | 602 SkPaint paint; |
603 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 603 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 canvas_skia->drawPosText(run->glyphs.get(), byte_length, pos.get(), paint); | 638 canvas_skia->drawPosText(run->glyphs.get(), byte_length, pos.get(), paint); |
639 | 639 |
640 // Draw the strikethrough. | 640 // Draw the strikethrough. |
641 if (run->strike) { | 641 if (run->strike) { |
642 Rect bounds(offset, Size(run->width, run->font.GetHeight())); | 642 Rect bounds(offset, Size(run->width, run->font.GetHeight())); |
643 SkPaint strike; | 643 SkPaint strike; |
644 strike.setAntiAlias(true); | 644 strike.setAntiAlias(true); |
645 strike.setStyle(SkPaint::kFill_Style); | 645 strike.setStyle(SkPaint::kFill_Style); |
646 strike.setColor(run->foreground); | 646 strike.setColor(run->foreground); |
647 strike.setStrokeWidth(kStrikeWidth); | 647 strike.setStrokeWidth(kStrikeWidth); |
648 canvas->AsCanvasSkia()->drawLine(SkIntToScalar(bounds.x()), | 648 canvas->GetSkCanvas()->drawLine(SkIntToScalar(bounds.x()), |
649 SkIntToScalar(bounds.bottom()), | 649 SkIntToScalar(bounds.bottom()), |
650 SkIntToScalar(bounds.right()), | 650 SkIntToScalar(bounds.right()), |
651 SkIntToScalar(bounds.y()), | 651 SkIntToScalar(bounds.y()), |
652 strike); | 652 strike); |
653 } | 653 } |
654 offset.Offset(run->width, 0); | 654 offset.Offset(run->width, 0); |
655 } | 655 } |
656 } | 656 } |
657 | 657 |
658 void RenderTextWin::DrawCursor(Canvas* canvas) { | 658 void RenderTextWin::DrawCursor(Canvas* canvas) { |
659 // Paint cursor. Replace cursor is drawn as rectangle for now. | 659 // Paint cursor. Replace cursor is drawn as rectangle for now. |
660 // TODO(msw): Draw a better cursor with a better indication of association. | 660 // TODO(msw): Draw a better cursor with a better indication of association. |
661 if (cursor_visible() && focused()) { | 661 if (cursor_visible() && focused()) { |
662 Rect r(GetUpdatedCursorBounds()); | 662 Rect r(GetUpdatedCursorBounds()); |
663 canvas->DrawRectInt(kCursorColor, r.x(), r.y(), r.width(), r.height()); | 663 canvas->DrawRectInt(kCursorColor, r.x(), r.y(), r.width(), r.height()); |
664 } | 664 } |
665 } | 665 } |
666 | 666 |
667 RenderText* RenderText::CreateRenderText() { | 667 RenderText* RenderText::CreateRenderText() { |
668 return new RenderTextWin; | 668 return new RenderTextWin; |
669 } | 669 } |
670 | 670 |
671 } // namespace gfx | 671 } // namespace gfx |
OLD | NEW |