| 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 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 // | 376 // |
| 377 // Because the border of this view creates an anti-aliased round-rect region | 377 // Because the border of this view creates an anti-aliased round-rect region |
| 378 // for the contents, we need to render our rectangular result child views into | 378 // for the contents, we need to render our rectangular result child views into |
| 379 // this round rect region. We can't use a simple clip because clipping is | 379 // this round rect region. We can't use a simple clip because clipping is |
| 380 // 1-bit and we get nasty jagged edges. | 380 // 1-bit and we get nasty jagged edges. |
| 381 // | 381 // |
| 382 // Instead, we paint all our children into a second canvas and use that as a | 382 // Instead, we paint all our children into a second canvas and use that as a |
| 383 // shader to fill a path representing the round-rect clipping region. This | 383 // shader to fill a path representing the round-rect clipping region. This |
| 384 // yields a nice anti-aliased edge. | 384 // yields a nice anti-aliased edge. |
| 385 gfx::CanvasSkia contents_canvas(width(), height(), true); | 385 gfx::CanvasSkia contents_canvas(width(), height(), true); |
| 386 PaintChildren(&contents_canvas); | 386 PaintResultViews(&contents_canvas); |
| 387 | 387 |
| 388 // We want the contents background to be slightly transparent so we can see | 388 // We want the contents background to be slightly transparent so we can see |
| 389 // the blurry glass effect on DWM systems behind. We do this _after_ we paint | 389 // the blurry glass effect on DWM systems behind. We do this _after_ we paint |
| 390 // the children since they paint text, and GDI will reset this alpha data if | 390 // the children since they paint text, and GDI will reset this alpha data if |
| 391 // we paint text after this call. | 391 // we paint text after this call. |
| 392 MakeCanvasTransparent(&contents_canvas); | 392 MakeCanvasTransparent(&contents_canvas); |
| 393 | 393 |
| 394 // Now paint the contents of the contents canvas into the actual canvas. | 394 // Now paint the contents of the contents canvas into the actual canvas. |
| 395 SkPaint paint; | 395 SkPaint paint; |
| 396 paint.setAntiAlias(true); | 396 paint.setAntiAlias(true); |
| 397 | 397 |
| 398 SkShader* shader = SkShader::CreateBitmapShader( | 398 SkShader* shader = SkShader::CreateBitmapShader( |
| 399 contents_canvas.getDevice()->accessBitmap(false), | 399 contents_canvas.getDevice()->accessBitmap(false), |
| 400 SkShader::kClamp_TileMode, | 400 SkShader::kClamp_TileMode, |
| 401 SkShader::kClamp_TileMode); | 401 SkShader::kClamp_TileMode); |
| 402 paint.setShader(shader); | 402 paint.setShader(shader); |
| 403 shader->unref(); | 403 shader->unref(); |
| 404 | 404 |
| 405 gfx::Path path; | 405 gfx::Path path; |
| 406 MakeContentsPath(&path, GetContentsBounds()); | 406 MakeContentsPath(&path, GetContentsBounds()); |
| 407 canvas->AsCanvasSkia()->drawPath(path, paint); | 407 canvas->AsCanvasSkia()->drawPath(path, paint); |
| 408 | 408 |
| 409 // Now we paint the border, so it will be alpha-blended atop the contents. | 409 // Now we paint the border, so it will be alpha-blended atop the contents. |
| 410 // This looks slightly better in the corners than drawing the contents atop | 410 // This looks slightly better in the corners than drawing the contents atop |
| 411 // the border. | 411 // the border. |
| 412 OnPaintBorder(canvas); | 412 OnPaintBorder(canvas); |
| 413 } | 413 } |
| 414 | 414 |
| 415 void AutocompletePopupContentsView::PaintChildren(gfx::CanvasSkia* canvas) { | 415 void AutocompletePopupContentsView::PaintChildren(gfx::Canvas* canvas) { |
| 416 canvas->drawColor(AutocompleteResultView::GetColor( | 416 // We paint our children inside OnPaint(). |
| 417 AutocompleteResultView::NORMAL, AutocompleteResultView::BACKGROUND)); | |
| 418 View::PaintChildren(canvas); | |
| 419 } | 417 } |
| 420 | 418 |
| 421 void AutocompletePopupContentsView::Layout() { | 419 void AutocompletePopupContentsView::Layout() { |
| 422 UpdateBlurRegion(); | 420 UpdateBlurRegion(); |
| 423 | 421 |
| 424 // Size our children to the available content area. | 422 // Size our children to the available content area. |
| 425 LayoutChildren(); | 423 LayoutChildren(); |
| 426 | 424 |
| 427 // We need to manually schedule a paint here since we are a layered window and | 425 // We need to manually schedule a paint here since we are a layered window and |
| 428 // won't implicitly require painting until we ask for one. | 426 // won't implicitly require painting until we ask for one. |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 views::View* child = views::View::GetViewForPoint(point); | 503 views::View* child = views::View::GetViewForPoint(point); |
| 506 views::View* ancestor = child; | 504 views::View* ancestor = child; |
| 507 while (ancestor && ancestor != opt_in_view_) | 505 while (ancestor && ancestor != opt_in_view_) |
| 508 ancestor = ancestor->parent(); | 506 ancestor = ancestor->parent(); |
| 509 return ancestor ? child : this; | 507 return ancestor ? child : this; |
| 510 } | 508 } |
| 511 | 509 |
| 512 //////////////////////////////////////////////////////////////////////////////// | 510 //////////////////////////////////////////////////////////////////////////////// |
| 513 // AutocompletePopupContentsView, protected: | 511 // AutocompletePopupContentsView, protected: |
| 514 | 512 |
| 513 void AutocompletePopupContentsView::PaintResultViews(gfx::CanvasSkia* canvas) { |
| 514 canvas->drawColor(AutocompleteResultView::GetColor( |
| 515 AutocompleteResultView::NORMAL, AutocompleteResultView::BACKGROUND)); |
| 516 View::PaintChildren(canvas); |
| 517 } |
| 518 |
| 515 int AutocompletePopupContentsView::CalculatePopupHeight() { | 519 int AutocompletePopupContentsView::CalculatePopupHeight() { |
| 516 DCHECK_GE(static_cast<size_t>(child_count()), model_->result().size()); | 520 DCHECK_GE(static_cast<size_t>(child_count()), model_->result().size()); |
| 517 int popup_height = 0; | 521 int popup_height = 0; |
| 518 for (size_t i = 0; i < model_->result().size(); ++i) | 522 for (size_t i = 0; i < model_->result().size(); ++i) |
| 519 popup_height += GetChildViewAt(i)->GetPreferredSize().height(); | 523 popup_height += GetChildViewAt(i)->GetPreferredSize().height(); |
| 520 return popup_height + | 524 return popup_height + |
| 521 (opt_in_view_ ? opt_in_view_->GetPreferredSize().height() : 0); | 525 (opt_in_view_ ? opt_in_view_->GetPreferredSize().height() : 0); |
| 522 } | 526 } |
| 523 | 527 |
| 524 AutocompleteResultView* AutocompletePopupContentsView::CreateResultView( | 528 AutocompleteResultView* AutocompletePopupContentsView::CreateResultView( |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 opt_in_view_ = NULL; | 658 opt_in_view_ = NULL; |
| 655 PromoCounter* counter = model_->profile()->GetInstantPromoCounter(); | 659 PromoCounter* counter = model_->profile()->GetInstantPromoCounter(); |
| 656 DCHECK(counter); | 660 DCHECK(counter); |
| 657 counter->Hide(); | 661 counter->Hide(); |
| 658 if (opt_in) { | 662 if (opt_in) { |
| 659 browser::ShowInstantConfirmDialogIfNecessary( | 663 browser::ShowInstantConfirmDialogIfNecessary( |
| 660 location_bar_->GetWindow()->GetNativeWindow(), model_->profile()); | 664 location_bar_->GetWindow()->GetNativeWindow(), model_->profile()); |
| 661 } | 665 } |
| 662 UpdatePopupAppearance(); | 666 UpdatePopupAppearance(); |
| 663 } | 667 } |
| OLD | NEW |