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 "chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.
h" | 5 #include "chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.
h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" | 9 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" |
10 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 10 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 | 473 |
474 void AutocompletePopupContentsView::OnMouseExited( | 474 void AutocompletePopupContentsView::OnMouseExited( |
475 const views::MouseEvent& event) { | 475 const views::MouseEvent& event) { |
476 model_->SetHoveredLine(AutocompletePopupModel::kNoMatch); | 476 model_->SetHoveredLine(AutocompletePopupModel::kNoMatch); |
477 } | 477 } |
478 | 478 |
479 //////////////////////////////////////////////////////////////////////////////// | 479 //////////////////////////////////////////////////////////////////////////////// |
480 // AutocompletePopupContentsView, protected: | 480 // AutocompletePopupContentsView, protected: |
481 | 481 |
482 void AutocompletePopupContentsView::PaintResultViews(gfx::CanvasSkia* canvas) { | 482 void AutocompletePopupContentsView::PaintResultViews(gfx::CanvasSkia* canvas) { |
483 canvas->drawColor(AutocompleteResultView::GetColor( | 483 canvas->skia_canvas()->drawColor(AutocompleteResultView::GetColor( |
484 AutocompleteResultView::NORMAL, AutocompleteResultView::BACKGROUND)); | 484 AutocompleteResultView::NORMAL, AutocompleteResultView::BACKGROUND)); |
485 View::PaintChildren(canvas); | 485 View::PaintChildren(canvas); |
486 } | 486 } |
487 | 487 |
488 int AutocompletePopupContentsView::CalculatePopupHeight() { | 488 int AutocompletePopupContentsView::CalculatePopupHeight() { |
489 DCHECK_GE(static_cast<size_t>(child_count()), model_->result().size()); | 489 DCHECK_GE(static_cast<size_t>(child_count()), model_->result().size()); |
490 int popup_height = 0; | 490 int popup_height = 0; |
491 for (size_t i = 0; i < model_->result().size(); ++i) | 491 for (size_t i = 0; i < model_->result().size(); ++i) |
492 popup_height += GetChildViewAt(i)->GetPreferredSize().height(); | 492 popup_height += GetChildViewAt(i)->GetPreferredSize().height(); |
493 return popup_height + | 493 return popup_height + |
(...skipping 15 matching lines...) Expand all Loading... |
509 // We paint our children in an unconventional way. | 509 // We paint our children in an unconventional way. |
510 // | 510 // |
511 // Because the border of this view creates an anti-aliased round-rect region | 511 // Because the border of this view creates an anti-aliased round-rect region |
512 // for the contents, we need to render our rectangular result child views into | 512 // for the contents, we need to render our rectangular result child views into |
513 // this round rect region. We can't use a simple clip because clipping is | 513 // this round rect region. We can't use a simple clip because clipping is |
514 // 1-bit and we get nasty jagged edges. | 514 // 1-bit and we get nasty jagged edges. |
515 // | 515 // |
516 // Instead, we paint all our children into a second canvas and use that as a | 516 // Instead, we paint all our children into a second canvas and use that as a |
517 // shader to fill a path representing the round-rect clipping region. This | 517 // shader to fill a path representing the round-rect clipping region. This |
518 // yields a nice anti-aliased edge. | 518 // yields a nice anti-aliased edge. |
519 gfx::CanvasSkia contents_canvas(width(), height(), true); | 519 gfx::CanvasSkia contents_canvas; |
| 520 contents_canvas.Init(width(), height(), true); |
520 PaintResultViews(&contents_canvas); | 521 PaintResultViews(&contents_canvas); |
521 | 522 |
522 // We want the contents background to be slightly transparent so we can see | 523 // We want the contents background to be slightly transparent so we can see |
523 // the blurry glass effect on DWM systems behind. We do this _after_ we paint | 524 // the blurry glass effect on DWM systems behind. We do this _after_ we paint |
524 // the children since they paint text, and GDI will reset this alpha data if | 525 // the children since they paint text, and GDI will reset this alpha data if |
525 // we paint text after this call. | 526 // we paint text after this call. |
526 MakeCanvasTransparent(&contents_canvas); | 527 MakeCanvasTransparent(&contents_canvas); |
527 | 528 |
528 // Now paint the contents of the contents canvas into the actual canvas. | 529 // Now paint the contents of the contents canvas into the actual canvas. |
529 SkPaint paint; | 530 SkPaint paint; |
530 paint.setAntiAlias(true); | 531 paint.setAntiAlias(true); |
531 | 532 |
532 SkShader* shader = SkShader::CreateBitmapShader( | 533 SkShader* shader = SkShader::CreateBitmapShader( |
533 contents_canvas.getDevice()->accessBitmap(false), | 534 contents_canvas.skia_canvas()->getDevice()->accessBitmap(false), |
534 SkShader::kClamp_TileMode, | 535 SkShader::kClamp_TileMode, |
535 SkShader::kClamp_TileMode); | 536 SkShader::kClamp_TileMode); |
536 paint.setShader(shader); | 537 paint.setShader(shader); |
537 shader->unref(); | 538 shader->unref(); |
538 | 539 |
539 gfx::Path path; | 540 gfx::Path path; |
540 MakeContentsPath(&path, GetContentsBounds()); | 541 MakeContentsPath(&path, GetContentsBounds()); |
541 canvas->AsCanvasSkia()->drawPath(path, paint); | 542 canvas->AsCanvasSkia()->skia_canvas()->drawPath(path, paint); |
542 | 543 |
543 // Now we paint the border, so it will be alpha-blended atop the contents. | 544 // Now we paint the border, so it will be alpha-blended atop the contents. |
544 // This looks slightly better in the corners than drawing the contents atop | 545 // This looks slightly better in the corners than drawing the contents atop |
545 // the border. | 546 // the border. |
546 OnPaintBorder(canvas); | 547 OnPaintBorder(canvas); |
547 } | 548 } |
548 | 549 |
549 void AutocompletePopupContentsView::PaintChildren(gfx::Canvas* canvas) { | 550 void AutocompletePopupContentsView::PaintChildren(gfx::Canvas* canvas) { |
550 // We paint our children inside OnPaint(). | 551 // We paint our children inside OnPaint(). |
551 } | 552 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 bb.hRgnBlur = popup_region.Get(); | 602 bb.hRgnBlur = popup_region.Get(); |
602 DwmEnableBlurBehindWindow(GetWidget()->GetNativeView(), &bb); | 603 DwmEnableBlurBehindWindow(GetWidget()->GetNativeView(), &bb); |
603 #endif | 604 #endif |
604 } | 605 } |
605 | 606 |
606 void AutocompletePopupContentsView::MakeCanvasTransparent( | 607 void AutocompletePopupContentsView::MakeCanvasTransparent( |
607 gfx::Canvas* canvas) { | 608 gfx::Canvas* canvas) { |
608 // Allow the window blur effect to show through the popup background. | 609 // Allow the window blur effect to show through the popup background. |
609 SkAlpha alpha = GetThemeProvider()->ShouldUseNativeFrame() ? | 610 SkAlpha alpha = GetThemeProvider()->ShouldUseNativeFrame() ? |
610 kGlassPopupAlpha : kOpaquePopupAlpha; | 611 kGlassPopupAlpha : kOpaquePopupAlpha; |
611 canvas->AsCanvasSkia()->drawColor(SkColorSetA( | 612 canvas->AsCanvasSkia()->skia_canvas()->drawColor(SkColorSetA( |
612 AutocompleteResultView::GetColor(AutocompleteResultView::NORMAL, | 613 AutocompleteResultView::GetColor(AutocompleteResultView::NORMAL, |
613 AutocompleteResultView::BACKGROUND), alpha), SkXfermode::kDstIn_Mode); | 614 AutocompleteResultView::BACKGROUND), alpha), SkXfermode::kDstIn_Mode); |
614 } | 615 } |
615 | 616 |
616 void AutocompletePopupContentsView::OpenIndex( | 617 void AutocompletePopupContentsView::OpenIndex( |
617 size_t index, | 618 size_t index, |
618 WindowOpenDisposition disposition) { | 619 WindowOpenDisposition disposition) { |
619 if (!HasMatchAt(index)) | 620 if (!HasMatchAt(index)) |
620 return; | 621 return; |
621 | 622 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 opt_in_view_ = NULL; | 676 opt_in_view_ = NULL; |
676 PromoCounter* counter = model_->profile()->GetInstantPromoCounter(); | 677 PromoCounter* counter = model_->profile()->GetInstantPromoCounter(); |
677 DCHECK(counter); | 678 DCHECK(counter); |
678 counter->Hide(); | 679 counter->Hide(); |
679 if (opt_in) { | 680 if (opt_in) { |
680 browser::ShowInstantConfirmDialogIfNecessary( | 681 browser::ShowInstantConfirmDialogIfNecessary( |
681 location_bar_->GetWindow()->GetNativeWindow(), model_->profile()); | 682 location_bar_->GetWindow()->GetNativeWindow(), model_->profile()); |
682 } | 683 } |
683 UpdatePopupAppearance(); | 684 UpdatePopupAppearance(); |
684 } | 685 } |
OLD | NEW |