OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h" | 5 #include "chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h" |
6 | 6 |
7 #include "app/bidi_line_iterator.h" | 7 #include "app/bidi_line_iterator.h" |
8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
9 #include "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" |
10 #include "app/theme_provider.h" | 10 #include "app/theme_provider.h" |
11 #include "app/text_elider.h" | 11 #include "app/text_elider.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
14 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" | 14 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" |
15 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 15 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
16 #include "chrome/browser/views/bubble_border.h" | 16 #include "chrome/browser/views/bubble_border.h" |
17 #include "chrome/browser/views/location_bar/location_bar_view.h" | 17 #include "chrome/browser/views/location_bar/location_bar_view.h" |
18 #include "gfx/canvas.h" | |
19 #include "gfx/canvas_skia.h" | 18 #include "gfx/canvas_skia.h" |
20 #include "gfx/color_utils.h" | 19 #include "gfx/color_utils.h" |
21 #include "gfx/insets.h" | 20 #include "gfx/insets.h" |
22 #include "gfx/path.h" | 21 #include "gfx/path.h" |
23 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
24 #include "grit/theme_resources.h" | 23 #include "grit/theme_resources.h" |
25 #include "third_party/skia/include/core/SkShader.h" | 24 #include "third_party/skia/include/core/SkShader.h" |
26 #include "third_party/icu/public/common/unicode/ubidi.h" | 25 #include "third_party/icu/public/common/unicode/ubidi.h" |
27 #include "views/widget/widget.h" | 26 #include "views/widget/widget.h" |
28 | 27 |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 width(); | 265 width(); |
267 } | 266 } |
268 } | 267 } |
269 | 268 |
270 AutocompleteResultView::~AutocompleteResultView() { | 269 AutocompleteResultView::~AutocompleteResultView() { |
271 } | 270 } |
272 | 271 |
273 void AutocompleteResultView::Paint(gfx::Canvas* canvas) { | 272 void AutocompleteResultView::Paint(gfx::Canvas* canvas) { |
274 const ResultViewState state = GetState(); | 273 const ResultViewState state = GetState(); |
275 if (state != NORMAL) | 274 if (state != NORMAL) |
276 canvas->drawColor(GetColor(state, BACKGROUND)); | 275 canvas->AsCanvasSkia()->drawColor(GetColor(state, BACKGROUND)); |
277 | 276 |
278 // Paint the icon. | 277 // Paint the icon. |
279 canvas->DrawBitmapInt(*GetIcon(), MirroredLeftPointForRect(icon_bounds_), | 278 canvas->DrawBitmapInt(*GetIcon(), MirroredLeftPointForRect(icon_bounds_), |
280 icon_bounds_.y()); | 279 icon_bounds_.y()); |
281 | 280 |
282 // Paint the text. | 281 // Paint the text. |
283 int x = MirroredLeftPointForRect(text_bounds_); | 282 int x = MirroredLeftPointForRect(text_bounds_); |
284 mirroring_context_->Initialize(x, text_bounds_.width()); | 283 mirroring_context_->Initialize(x, text_bounds_.width()); |
285 x = DrawString(canvas, match_.contents, match_.contents_class, false, x, | 284 x = DrawString(canvas, match_.contents, match_.contents_class, false, x, |
286 text_bounds_.y()); | 285 text_bounds_.y()); |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 // We paint our children in an unconventional way. | 757 // We paint our children in an unconventional way. |
759 // | 758 // |
760 // Because the border of this view creates an anti-aliased round-rect region | 759 // Because the border of this view creates an anti-aliased round-rect region |
761 // for the contents, we need to render our rectangular result child views into | 760 // for the contents, we need to render our rectangular result child views into |
762 // this round rect region. We can't use a simple clip because clipping is | 761 // this round rect region. We can't use a simple clip because clipping is |
763 // 1-bit and we get nasty jagged edges. | 762 // 1-bit and we get nasty jagged edges. |
764 // | 763 // |
765 // Instead, we paint all our children into a second canvas and use that as a | 764 // Instead, we paint all our children into a second canvas and use that as a |
766 // shader to fill a path representing the round-rect clipping region. This | 765 // shader to fill a path representing the round-rect clipping region. This |
767 // yields a nice anti-aliased edge. | 766 // yields a nice anti-aliased edge. |
768 // TODO(beng): Convert to CanvasSkia | 767 gfx::CanvasSkia contents_canvas(width(), height(), true); |
769 gfx::Canvas contents_canvas(width(), height(), true); | |
770 contents_canvas.drawColor(GetColor(NORMAL, BACKGROUND)); | 768 contents_canvas.drawColor(GetColor(NORMAL, BACKGROUND)); |
771 View::PaintChildren(&contents_canvas); | 769 View::PaintChildren(&contents_canvas); |
772 // We want the contents background to be slightly transparent so we can see | 770 // We want the contents background to be slightly transparent so we can see |
773 // the blurry glass effect on DWM systems behind. We do this _after_ we paint | 771 // the blurry glass effect on DWM systems behind. We do this _after_ we paint |
774 // the children since they paint text, and GDI will reset this alpha data if | 772 // the children since they paint text, and GDI will reset this alpha data if |
775 // we paint text after this call. | 773 // we paint text after this call. |
776 MakeCanvasTransparent(&contents_canvas); | 774 MakeCanvasTransparent(&contents_canvas); |
777 | 775 |
778 // Now paint the contents of the contents canvas into the actual canvas. | 776 // Now paint the contents of the contents canvas into the actual canvas. |
779 SkPaint paint; | 777 SkPaint paint; |
780 paint.setAntiAlias(true); | 778 paint.setAntiAlias(true); |
781 | 779 |
782 SkShader* shader = SkShader::CreateBitmapShader( | 780 SkShader* shader = SkShader::CreateBitmapShader( |
783 contents_canvas.getDevice()->accessBitmap(false), | 781 contents_canvas.getDevice()->accessBitmap(false), |
784 SkShader::kClamp_TileMode, | 782 SkShader::kClamp_TileMode, |
785 SkShader::kClamp_TileMode); | 783 SkShader::kClamp_TileMode); |
786 paint.setShader(shader); | 784 paint.setShader(shader); |
787 shader->unref(); | 785 shader->unref(); |
788 | 786 |
789 gfx::Path path; | 787 gfx::Path path; |
790 MakeContentsPath(&path, GetLocalBounds(false)); | 788 MakeContentsPath(&path, GetLocalBounds(false)); |
791 canvas->drawPath(path, paint); | 789 canvas->AsCanvasSkia()->drawPath(path, paint); |
792 | 790 |
793 // Now we paint the border, so it will be alpha-blended atop the contents. | 791 // Now we paint the border, so it will be alpha-blended atop the contents. |
794 // This looks slightly better in the corners than drawing the contents atop | 792 // This looks slightly better in the corners than drawing the contents atop |
795 // the border. | 793 // the border. |
796 PaintBorder(canvas); | 794 PaintBorder(canvas); |
797 } | 795 } |
798 | 796 |
799 void AutocompletePopupContentsView::Layout() { | 797 void AutocompletePopupContentsView::Layout() { |
800 UpdateBlurRegion(); | 798 UpdateBlurRegion(); |
801 | 799 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 bb.hRgnBlur = popup_region.Get(); | 926 bb.hRgnBlur = popup_region.Get(); |
929 DwmEnableBlurBehindWindow(GetWidget()->GetNativeView(), &bb); | 927 DwmEnableBlurBehindWindow(GetWidget()->GetNativeView(), &bb); |
930 #endif | 928 #endif |
931 } | 929 } |
932 | 930 |
933 void AutocompletePopupContentsView::MakeCanvasTransparent( | 931 void AutocompletePopupContentsView::MakeCanvasTransparent( |
934 gfx::Canvas* canvas) { | 932 gfx::Canvas* canvas) { |
935 // Allow the window blur effect to show through the popup background. | 933 // Allow the window blur effect to show through the popup background. |
936 SkAlpha alpha = GetThemeProvider()->ShouldUseNativeFrame() ? | 934 SkAlpha alpha = GetThemeProvider()->ShouldUseNativeFrame() ? |
937 kGlassPopupAlpha : kOpaquePopupAlpha; | 935 kGlassPopupAlpha : kOpaquePopupAlpha; |
938 canvas->drawColor(SkColorSetA(GetColor(NORMAL, BACKGROUND), alpha), | 936 canvas->AsCanvasSkia()->drawColor( |
939 SkXfermode::kDstIn_Mode); | 937 SkColorSetA(GetColor(NORMAL, BACKGROUND), alpha), |
| 938 SkXfermode::kDstIn_Mode); |
940 } | 939 } |
941 | 940 |
942 void AutocompletePopupContentsView::OpenIndex( | 941 void AutocompletePopupContentsView::OpenIndex( |
943 size_t index, | 942 size_t index, |
944 WindowOpenDisposition disposition) { | 943 WindowOpenDisposition disposition) { |
945 if (!HasMatchAt(index)) | 944 if (!HasMatchAt(index)) |
946 return; | 945 return; |
947 | 946 |
948 const AutocompleteMatch& match = model_->result().match_at(index); | 947 const AutocompleteMatch& match = model_->result().match_at(index); |
949 // OpenURL() may close the popup, which will clear the result set and, by | 948 // OpenURL() may close the popup, which will clear the result set and, by |
(...skipping 15 matching lines...) Expand all Loading... |
965 DCHECK(nb_match <= GetChildViewCount()); | 964 DCHECK(nb_match <= GetChildViewCount()); |
966 for (int i = 0; i < nb_match; ++i) { | 965 for (int i = 0; i < nb_match; ++i) { |
967 views::View* child = GetChildViewAt(i); | 966 views::View* child = GetChildViewAt(i); |
968 gfx::Point point_in_child_coords(point); | 967 gfx::Point point_in_child_coords(point); |
969 View::ConvertPointToView(this, child, &point_in_child_coords); | 968 View::ConvertPointToView(this, child, &point_in_child_coords); |
970 if (child->HitTest(point_in_child_coords)) | 969 if (child->HitTest(point_in_child_coords)) |
971 return i; | 970 return i; |
972 } | 971 } |
973 return AutocompletePopupModel::kNoMatch; | 972 return AutocompletePopupModel::kNoMatch; |
974 } | 973 } |
OLD | NEW |