| 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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 //////////////////////////////////////////////////////////////////////////////// | 200 //////////////////////////////////////////////////////////////////////////////// |
| 201 // AutocompletePopupContentsView, public: | 201 // AutocompletePopupContentsView, public: |
| 202 | 202 |
| 203 AutocompletePopupContentsView::AutocompletePopupContentsView( | 203 AutocompletePopupContentsView::AutocompletePopupContentsView( |
| 204 const gfx::Font& font, | 204 const gfx::Font& font, |
| 205 AutocompleteEditView* edit_view, | 205 AutocompleteEditView* edit_view, |
| 206 AutocompleteEditModel* edit_model, | 206 AutocompleteEditModel* edit_model, |
| 207 Profile* profile, | 207 Profile* profile, |
| 208 const views::View* location_bar) | 208 const views::View* location_bar) |
| 209 : model_(new AutocompletePopupModel(this, edit_model, profile)), | 209 : model_(new AutocompletePopupModel(this, edit_model, profile)), |
| 210 opt_in_view_(NULL), |
| 210 edit_view_(edit_view), | 211 edit_view_(edit_view), |
| 211 location_bar_(location_bar), | 212 location_bar_(location_bar), |
| 212 result_font_(font.DeriveFont(kEditFontAdjust)), | 213 result_font_(font.DeriveFont(kEditFontAdjust)), |
| 213 result_bold_font_(result_font_.DeriveFont(0, gfx::Font::BOLD)), | 214 result_bold_font_(result_font_.DeriveFont(0, gfx::Font::BOLD)), |
| 214 ignore_mouse_drag_(false), | 215 ignore_mouse_drag_(false), |
| 215 ALLOW_THIS_IN_INITIALIZER_LIST(size_animation_(this)), | 216 ALLOW_THIS_IN_INITIALIZER_LIST(size_animation_(this)) { |
| 216 opt_in_view_(NULL) { | |
| 217 // The following little dance is required because set_border() requires a | 217 // The following little dance is required because set_border() requires a |
| 218 // pointer to a non-const object. | 218 // pointer to a non-const object. |
| 219 BubbleBorder* bubble_border = new BubbleBorder(BubbleBorder::NONE); | 219 BubbleBorder* bubble_border = new BubbleBorder(BubbleBorder::NONE); |
| 220 bubble_border_ = bubble_border; | 220 bubble_border_ = bubble_border; |
| 221 set_border(bubble_border); | 221 set_border(bubble_border); |
| 222 } | 222 } |
| 223 | 223 |
| 224 AutocompletePopupContentsView::~AutocompletePopupContentsView() { | 224 AutocompletePopupContentsView::~AutocompletePopupContentsView() { |
| 225 // We don't need to do anything with |popup_| here. The OS either has already | 225 // We don't need to do anything with |popup_| here. The OS either has already |
| 226 // closed the window, in which case it's been deleted, or it will soon, in | 226 // closed the window, in which case it's been deleted, or it will soon, in |
| (...skipping 149 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 contents_canvas.drawColor(AutocompleteResultView::GetColor( | 386 PaintChildren(&contents_canvas); |
| 387 AutocompleteResultView::NORMAL, AutocompleteResultView::BACKGROUND)); | 387 |
| 388 View::PaintChildren(&contents_canvas); | |
| 389 // 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 |
| 390 // 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 |
| 391 // 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 |
| 392 // we paint text after this call. | 391 // we paint text after this call. |
| 393 MakeCanvasTransparent(&contents_canvas); | 392 MakeCanvasTransparent(&contents_canvas); |
| 394 | 393 |
| 395 // 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. |
| 396 SkPaint paint; | 395 SkPaint paint; |
| 397 paint.setAntiAlias(true); | 396 paint.setAntiAlias(true); |
| 398 | 397 |
| 399 SkShader* shader = SkShader::CreateBitmapShader( | 398 SkShader* shader = SkShader::CreateBitmapShader( |
| 400 contents_canvas.getDevice()->accessBitmap(false), | 399 contents_canvas.getDevice()->accessBitmap(false), |
| 401 SkShader::kClamp_TileMode, | 400 SkShader::kClamp_TileMode, |
| 402 SkShader::kClamp_TileMode); | 401 SkShader::kClamp_TileMode); |
| 403 paint.setShader(shader); | 402 paint.setShader(shader); |
| 404 shader->unref(); | 403 shader->unref(); |
| 405 | 404 |
| 406 gfx::Path path; | 405 gfx::Path path; |
| 407 MakeContentsPath(&path, GetContentsBounds()); | 406 MakeContentsPath(&path, GetContentsBounds()); |
| 408 canvas->AsCanvasSkia()->drawPath(path, paint); | 407 canvas->AsCanvasSkia()->drawPath(path, paint); |
| 409 | 408 |
| 410 // 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. |
| 411 // 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 |
| 412 // the border. | 411 // the border. |
| 413 OnPaintBorder(canvas); | 412 OnPaintBorder(canvas); |
| 414 } | 413 } |
| 415 | 414 |
| 415 void AutocompletePopupContentsView::PaintChildren(gfx::CanvasSkia* canvas) { |
| 416 canvas->drawColor(AutocompleteResultView::GetColor( |
| 417 AutocompleteResultView::NORMAL, AutocompleteResultView::BACKGROUND)); |
| 418 View::PaintChildren(canvas); |
| 419 } |
| 420 |
| 416 void AutocompletePopupContentsView::Layout() { | 421 void AutocompletePopupContentsView::Layout() { |
| 417 UpdateBlurRegion(); | 422 UpdateBlurRegion(); |
| 418 | 423 |
| 419 // Size our children to the available content area. | 424 // Size our children to the available content area. |
| 425 LayoutChildren(); |
| 426 |
| 427 // 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. |
| 429 SchedulePaint(); |
| 430 } |
| 431 |
| 432 void AutocompletePopupContentsView::LayoutChildren() { |
| 420 gfx::Rect contents_rect = GetContentsBounds(); | 433 gfx::Rect contents_rect = GetContentsBounds(); |
| 421 int top = contents_rect.y(); | 434 int top = contents_rect.y(); |
| 422 for (int i = 0; i < child_count(); ++i) { | 435 for (int i = 0; i < child_count(); ++i) { |
| 423 View* v = GetChildViewAt(i); | 436 View* v = GetChildViewAt(i); |
| 424 if (v->IsVisible()) { | 437 if (v->IsVisible()) { |
| 425 v->SetBounds(contents_rect.x(), top, contents_rect.width(), | 438 v->SetBounds(contents_rect.x(), top, contents_rect.width(), |
| 426 v->GetPreferredSize().height()); | 439 v->GetPreferredSize().height()); |
| 427 top = v->bounds().bottom(); | 440 top = v->bounds().bottom(); |
| 428 } | 441 } |
| 429 } | 442 } |
| 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 } | 443 } |
| 435 | 444 |
| 436 | |
| 437 void AutocompletePopupContentsView::OnMouseEntered( | 445 void AutocompletePopupContentsView::OnMouseEntered( |
| 438 const views::MouseEvent& event) { | 446 const views::MouseEvent& event) { |
| 439 model_->SetHoveredLine(GetIndexForPoint(event.location())); | 447 model_->SetHoveredLine(GetIndexForPoint(event.location())); |
| 440 } | 448 } |
| 441 | 449 |
| 442 void AutocompletePopupContentsView::OnMouseMoved( | 450 void AutocompletePopupContentsView::OnMouseMoved( |
| 443 const views::MouseEvent& event) { | 451 const views::MouseEvent& event) { |
| 444 model_->SetHoveredLine(GetIndexForPoint(event.location())); | 452 model_->SetHoveredLine(GetIndexForPoint(event.location())); |
| 445 } | 453 } |
| 446 | 454 |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 opt_in_view_ = NULL; | 654 opt_in_view_ = NULL; |
| 647 PromoCounter* counter = model_->profile()->GetInstantPromoCounter(); | 655 PromoCounter* counter = model_->profile()->GetInstantPromoCounter(); |
| 648 DCHECK(counter); | 656 DCHECK(counter); |
| 649 counter->Hide(); | 657 counter->Hide(); |
| 650 if (opt_in) { | 658 if (opt_in) { |
| 651 browser::ShowInstantConfirmDialogIfNecessary( | 659 browser::ShowInstantConfirmDialogIfNecessary( |
| 652 location_bar_->GetWindow()->GetNativeWindow(), model_->profile()); | 660 location_bar_->GetWindow()->GetNativeWindow(), model_->profile()); |
| 653 } | 661 } |
| 654 UpdatePopupAppearance(); | 662 UpdatePopupAppearance(); |
| 655 } | 663 } |
| OLD | NEW |