Chromium Code Reviews

Side by Side Diff: chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc

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

Powered by Google App Engine