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 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 // | 380 // |
381 // Because the border of this view creates an anti-aliased round-rect region | 381 // Because the border of this view creates an anti-aliased round-rect region |
382 // for the contents, we need to render our rectangular result child views into | 382 // for the contents, we need to render our rectangular result child views into |
383 // this round rect region. We can't use a simple clip because clipping is | 383 // this round rect region. We can't use a simple clip because clipping is |
384 // 1-bit and we get nasty jagged edges. | 384 // 1-bit and we get nasty jagged edges. |
385 // | 385 // |
386 // Instead, we paint all our children into a second canvas and use that as a | 386 // Instead, we paint all our children into a second canvas and use that as a |
387 // shader to fill a path representing the round-rect clipping region. This | 387 // shader to fill a path representing the round-rect clipping region. This |
388 // yields a nice anti-aliased edge. | 388 // yields a nice anti-aliased edge. |
389 gfx::CanvasSkia contents_canvas(width(), height(), true); | 389 gfx::CanvasSkia contents_canvas(width(), height(), true); |
390 contents_canvas.drawColor(AutocompleteResultView::GetColor( | 390 PaintChildren(&contents_canvas); |
391 AutocompleteResultView::NORMAL, AutocompleteResultView::BACKGROUND)); | 391 |
392 View::PaintChildren(&contents_canvas); | |
393 // We want the contents background to be slightly transparent so we can see | 392 // We want the contents background to be slightly transparent so we can see |
394 // the blurry glass effect on DWM systems behind. We do this _after_ we paint | 393 // the blurry glass effect on DWM systems behind. We do this _after_ we paint |
395 // the children since they paint text, and GDI will reset this alpha data if | 394 // the children since they paint text, and GDI will reset this alpha data if |
396 // we paint text after this call. | 395 // we paint text after this call. |
397 MakeCanvasTransparent(&contents_canvas); | 396 MakeCanvasTransparent(&contents_canvas); |
398 | 397 |
399 // Now paint the contents of the contents canvas into the actual canvas. | 398 // Now paint the contents of the contents canvas into the actual canvas. |
400 SkPaint paint; | 399 SkPaint paint; |
401 paint.setAntiAlias(true); | 400 paint.setAntiAlias(true); |
402 | 401 |
403 SkShader* shader = SkShader::CreateBitmapShader( | 402 SkShader* shader = SkShader::CreateBitmapShader( |
404 contents_canvas.getDevice()->accessBitmap(false), | 403 contents_canvas.getDevice()->accessBitmap(false), |
405 SkShader::kClamp_TileMode, | 404 SkShader::kClamp_TileMode, |
406 SkShader::kClamp_TileMode); | 405 SkShader::kClamp_TileMode); |
407 paint.setShader(shader); | 406 paint.setShader(shader); |
408 shader->unref(); | 407 shader->unref(); |
409 | 408 |
410 gfx::Path path; | 409 gfx::Path path; |
411 MakeContentsPath(&path, GetContentsBounds()); | 410 MakeContentsPath(&path, GetContentsBounds()); |
412 canvas->AsCanvasSkia()->drawPath(path, paint); | 411 canvas->AsCanvasSkia()->drawPath(path, paint); |
413 | 412 |
414 // Now we paint the border, so it will be alpha-blended atop the contents. | 413 // Now we paint the border, so it will be alpha-blended atop the contents. |
415 // This looks slightly better in the corners than drawing the contents atop | 414 // This looks slightly better in the corners than drawing the contents atop |
416 // the border. | 415 // the border. |
417 OnPaintBorder(canvas); | 416 OnPaintBorder(canvas); |
418 } | 417 } |
419 | 418 |
| 419 void AutocompletePopupContentsView::PaintChildren(gfx::CanvasSkia* canvas) { |
| 420 canvas->drawColor(AutocompleteResultView::GetColor( |
| 421 AutocompleteResultView::NORMAL, AutocompleteResultView::BACKGROUND)); |
| 422 View::PaintChildren(canvas); |
| 423 } |
| 424 |
420 void AutocompletePopupContentsView::Layout() { | 425 void AutocompletePopupContentsView::Layout() { |
421 UpdateBlurRegion(); | 426 UpdateBlurRegion(); |
422 | 427 |
423 // Size our children to the available content area. | 428 // Size our children to the available content area. |
| 429 LayoutChildren(); |
| 430 |
| 431 // We need to manually schedule a paint here since we are a layered window and |
| 432 // won't implicitly require painting until we ask for one. |
| 433 SchedulePaint(); |
| 434 } |
| 435 |
| 436 void AutocompletePopupContentsView::LayoutChildren() { |
424 gfx::Rect contents_rect = GetContentsBounds(); | 437 gfx::Rect contents_rect = GetContentsBounds(); |
425 int top = contents_rect.y(); | 438 int top = contents_rect.y(); |
426 for (int i = 0; i < child_count(); ++i) { | 439 for (int i = 0; i < child_count(); ++i) { |
427 View* v = GetChildViewAt(i); | 440 View* v = GetChildViewAt(i); |
428 if (v->IsVisible()) { | 441 if (v->IsVisible()) { |
429 v->SetBounds(contents_rect.x(), top, contents_rect.width(), | 442 v->SetBounds(contents_rect.x(), top, contents_rect.width(), |
430 v->GetPreferredSize().height()); | 443 v->GetPreferredSize().height()); |
431 top = v->bounds().bottom(); | 444 top = v->bounds().bottom(); |
432 } | 445 } |
433 } | 446 } |
434 | |
435 // We need to manually schedule a paint here since we are a layered window and | |
436 // won't implicitly require painting until we ask for one. | |
437 SchedulePaint(); | |
438 } | 447 } |
439 | 448 |
440 | |
441 void AutocompletePopupContentsView::OnMouseEntered( | 449 void AutocompletePopupContentsView::OnMouseEntered( |
442 const views::MouseEvent& event) { | 450 const views::MouseEvent& event) { |
443 model_->SetHoveredLine(GetIndexForPoint(event.location())); | 451 model_->SetHoveredLine(GetIndexForPoint(event.location())); |
444 } | 452 } |
445 | 453 |
446 void AutocompletePopupContentsView::OnMouseMoved( | 454 void AutocompletePopupContentsView::OnMouseMoved( |
447 const views::MouseEvent& event) { | 455 const views::MouseEvent& event) { |
448 model_->SetHoveredLine(GetIndexForPoint(event.location())); | 456 model_->SetHoveredLine(GetIndexForPoint(event.location())); |
449 } | 457 } |
450 | 458 |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 opt_in_view_ = NULL; | 658 opt_in_view_ = NULL; |
651 PromoCounter* counter = model_->profile()->GetInstantPromoCounter(); | 659 PromoCounter* counter = model_->profile()->GetInstantPromoCounter(); |
652 DCHECK(counter); | 660 DCHECK(counter); |
653 counter->Hide(); | 661 counter->Hide(); |
654 if (opt_in) { | 662 if (opt_in) { |
655 browser::ShowInstantConfirmDialogIfNecessary( | 663 browser::ShowInstantConfirmDialogIfNecessary( |
656 location_bar_->GetWindow()->GetNativeWindow(), model_->profile()); | 664 location_bar_->GetWindow()->GetNativeWindow(), model_->profile()); |
657 } | 665 } |
658 UpdatePopupAppearance(); | 666 UpdatePopupAppearance(); |
659 } | 667 } |
OLD | NEW |