| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. | 3 // 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/gfx/canvas.h" | 7 #include "app/gfx/canvas.h" |
| 8 #include "app/gfx/color_utils.h" | 8 #include "app/gfx/color_utils.h" |
| 9 #include "app/gfx/insets.h" | 9 #include "app/gfx/insets.h" |
| 10 #include "app/gfx/path.h" | 10 #include "app/gfx/path.h" |
| 11 #include "app/l10n_util.h" | 11 #include "app/l10n_util.h" |
| 12 #include "app/resource_bundle.h" | 12 #include "app/resource_bundle.h" |
| 13 #include "app/theme_provider.h" | 13 #include "app/theme_provider.h" |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" | 15 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" |
| 16 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 16 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
| 17 #include "chrome/browser/bubble_positioner.h" |
| 17 #include "chrome/browser/views/bubble_border.h" | 18 #include "chrome/browser/views/bubble_border.h" |
| 18 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 19 #include "grit/theme_resources.h" | 20 #include "grit/theme_resources.h" |
| 20 #include "third_party/skia/include/core/SkShader.h" | 21 #include "third_party/skia/include/core/SkShader.h" |
| 21 #include "third_party/icu/public/common/unicode/ubidi.h" | 22 #include "third_party/icu/public/common/unicode/ubidi.h" |
| 22 #include "views/widget/widget.h" | 23 #include "views/widget/widget.h" |
| 23 | 24 |
| 24 #if defined(OS_WIN) | 25 #if defined(OS_WIN) |
| 25 #include <objidl.h> | 26 #include <objidl.h> |
| 26 #include <commctrl.h> | 27 #include <commctrl.h> |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 } | 576 } |
| 576 | 577 |
| 577 //////////////////////////////////////////////////////////////////////////////// | 578 //////////////////////////////////////////////////////////////////////////////// |
| 578 // AutocompletePopupContentsView, public: | 579 // AutocompletePopupContentsView, public: |
| 579 | 580 |
| 580 AutocompletePopupContentsView::AutocompletePopupContentsView( | 581 AutocompletePopupContentsView::AutocompletePopupContentsView( |
| 581 const gfx::Font& font, | 582 const gfx::Font& font, |
| 582 AutocompleteEditView* edit_view, | 583 AutocompleteEditView* edit_view, |
| 583 AutocompleteEditModel* edit_model, | 584 AutocompleteEditModel* edit_model, |
| 584 Profile* profile, | 585 Profile* profile, |
| 585 AutocompletePopupPositioner* popup_positioner) | 586 const BubblePositioner* bubble_positioner) |
| 586 #if defined(OS_WIN) | 587 #if defined(OS_WIN) |
| 587 : popup_(new AutocompletePopupWin(this)), | 588 : popup_(new AutocompletePopupWin(this)), |
| 588 #else | 589 #else |
| 589 : popup_(new AutocompletePopupGtk(this)), | 590 : popup_(new AutocompletePopupGtk(this)), |
| 590 #endif | 591 #endif |
| 591 model_(new AutocompletePopupModel(this, edit_model, profile)), | 592 model_(new AutocompletePopupModel(this, edit_model, profile)), |
| 592 edit_view_(edit_view), | 593 edit_view_(edit_view), |
| 593 popup_positioner_(popup_positioner), | 594 bubble_positioner_(bubble_positioner), |
| 594 result_font_(font.DeriveFont(kEditFontAdjust)), | 595 result_font_(font.DeriveFont(kEditFontAdjust)), |
| 595 ALLOW_THIS_IN_INITIALIZER_LIST(size_animation_(this)) { | 596 ALLOW_THIS_IN_INITIALIZER_LIST(size_animation_(this)) { |
| 596 set_border(new BubbleBorder); | 597 // The following little dance is required because set_border() requires a |
| 598 // pointer to a non-const object. |
| 599 BubbleBorder* bubble_border = new BubbleBorder; |
| 600 bubble_border_ = bubble_border; |
| 601 set_border(bubble_border); |
| 597 } | 602 } |
| 598 | 603 |
| 599 gfx::Rect AutocompletePopupContentsView::GetPopupBounds() const { | 604 gfx::Rect AutocompletePopupContentsView::GetPopupBounds() const { |
| 600 if (!size_animation_.IsAnimating()) | 605 if (!size_animation_.IsAnimating()) |
| 601 return target_bounds_; | 606 return target_bounds_; |
| 602 | 607 |
| 603 gfx::Rect current_frame_bounds = start_bounds_; | 608 gfx::Rect current_frame_bounds = start_bounds_; |
| 604 int total_height_delta = target_bounds_.height() - start_bounds_.height(); | 609 int total_height_delta = target_bounds_.height() - start_bounds_.height(); |
| 605 // Round |current_height_delta| instead of truncating so we won't leave single | 610 // Round |current_height_delta| instead of truncating so we won't leave single |
| 606 // white pixels at the bottom of the popup as long when animating very small | 611 // white pixels at the bottom of the popup as long when animating very small |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 result_view = new AutocompleteResultView(this, i, result_font_); | 648 result_view = new AutocompleteResultView(this, i, result_font_); |
| 644 AddChildView(result_view); | 649 AddChildView(result_view); |
| 645 } else { | 650 } else { |
| 646 result_view = static_cast<AutocompleteResultView*>(GetChildViewAt(i)); | 651 result_view = static_cast<AutocompleteResultView*>(GetChildViewAt(i)); |
| 647 } | 652 } |
| 648 result_view->set_match(GetMatchAtIndex(i)); | 653 result_view->set_match(GetMatchAtIndex(i)); |
| 649 total_child_height += result_view->GetPreferredSize().height(); | 654 total_child_height += result_view->GetPreferredSize().height(); |
| 650 } | 655 } |
| 651 | 656 |
| 652 // Calculate desired bounds. | 657 // Calculate desired bounds. |
| 653 gfx::Rect new_target_bounds = popup_positioner_->GetPopupBounds(); | 658 gfx::Rect location_stack_bounds = |
| 654 new_target_bounds.set_height(total_child_height); | 659 bubble_positioner_->GetLocationStackBounds(); |
| 655 gfx::Insets insets; | 660 gfx::Rect new_target_bounds(bubble_border_->GetBounds(location_stack_bounds, |
| 656 border()->GetInsets(&insets); | 661 gfx::Size(location_stack_bounds.width(), total_child_height))); |
| 657 new_target_bounds.Inset(-insets.left(), -insets.top(), -insets.right(), | |
| 658 -insets.bottom()); | |
| 659 | 662 |
| 660 // If we're animating and our target height changes, reset the animation. | 663 // If we're animating and our target height changes, reset the animation. |
| 661 // NOTE: If we just reset blindly on _every_ update, then when the user types | 664 // NOTE: If we just reset blindly on _every_ update, then when the user types |
| 662 // rapidly we could get "stuck" trying repeatedly to animate shrinking by the | 665 // rapidly we could get "stuck" trying repeatedly to animate shrinking by the |
| 663 // last few pixels to get to one visible result. | 666 // last few pixels to get to one visible result. |
| 664 if (new_target_bounds.height() != target_bounds_.height()) | 667 if (new_target_bounds.height() != target_bounds_.height()) |
| 665 size_animation_.Reset(); | 668 size_animation_.Reset(); |
| 666 target_bounds_ = new_target_bounds; | 669 target_bounds_ = new_target_bounds; |
| 667 | 670 |
| 668 if (!popup_->IsCreated()) { | 671 if (!popup_->IsCreated()) { |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 canvas->drawColor(SkColorSetA(GetColor(NORMAL, BACKGROUND), alpha), | 866 canvas->drawColor(SkColorSetA(GetColor(NORMAL, BACKGROUND), alpha), |
| 864 SkXfermode::kDstIn_Mode); | 867 SkXfermode::kDstIn_Mode); |
| 865 } | 868 } |
| 866 | 869 |
| 867 // static | 870 // static |
| 868 AutocompletePopupView* AutocompletePopupView::CreatePopupView( | 871 AutocompletePopupView* AutocompletePopupView::CreatePopupView( |
| 869 const gfx::Font& font, | 872 const gfx::Font& font, |
| 870 AutocompleteEditView* edit_view, | 873 AutocompleteEditView* edit_view, |
| 871 AutocompleteEditModel* edit_model, | 874 AutocompleteEditModel* edit_model, |
| 872 Profile* profile, | 875 Profile* profile, |
| 873 AutocompletePopupPositioner* popup_positioner) { | 876 const BubblePositioner* bubble_positioner) { |
| 874 return new AutocompletePopupContentsView(font, edit_view, edit_model, | 877 return new AutocompletePopupContentsView(font, edit_view, edit_model, |
| 875 profile, popup_positioner); | 878 profile, bubble_positioner); |
| 876 } | 879 } |
| OLD | NEW |