Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc

Issue 385041: Merge crash fix to 3.0.... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/195/src/
Patch Set: Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Deleted: svn:mergeinfo
Reverse-merged /branches/chrome_webkit_merge_branch/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc:r69-2775
Reverse-merged /trunk/src/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc:r21322,25494,25568
OLDNEW
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 <objidl.h> 7 #include <objidl.h>
8 #include <commctrl.h> 8 #include <commctrl.h>
9 #include <dwmapi.h> 9 #include <dwmapi.h>
10 10
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 674
675 //////////////////////////////////////////////////////////////////////////////// 675 ////////////////////////////////////////////////////////////////////////////////
676 // AutocompletePopupContentsView, public: 676 // AutocompletePopupContentsView, public:
677 677
678 AutocompletePopupContentsView::AutocompletePopupContentsView( 678 AutocompletePopupContentsView::AutocompletePopupContentsView(
679 const gfx::Font& font, 679 const gfx::Font& font,
680 AutocompleteEditViewWin* edit_view, 680 AutocompleteEditViewWin* edit_view,
681 AutocompleteEditModel* edit_model, 681 AutocompleteEditModel* edit_model,
682 Profile* profile, 682 Profile* profile,
683 AutocompletePopupPositioner* popup_positioner) 683 AutocompletePopupPositioner* popup_positioner)
684 : popup_(new AutocompletePopupWin(this)), 684 : model_(new AutocompletePopupModel(this, edit_model, profile)),
685 model_(new AutocompletePopupModel(this, edit_model, profile)),
686 edit_view_(edit_view), 685 edit_view_(edit_view),
687 popup_positioner_(popup_positioner), 686 popup_positioner_(popup_positioner),
688 result_font_(font.DeriveFont(kEditFontAdjust)), 687 result_font_(font.DeriveFont(kEditFontAdjust)),
689 ALLOW_THIS_IN_INITIALIZER_LIST(size_animation_(this)) { 688 ALLOW_THIS_IN_INITIALIZER_LIST(size_animation_(this)) {
690 set_border(new PopupBorder); 689 set_border(new PopupBorder);
691 } 690 }
692 691
693 gfx::Rect AutocompletePopupContentsView::GetPopupBounds() const { 692 gfx::Rect AutocompletePopupContentsView::GetPopupBounds() const {
694 if (!size_animation_.IsAnimating()) 693 if (!size_animation_.IsAnimating())
695 return target_bounds_; 694 return target_bounds_;
696 695
697 gfx::Rect current_frame_bounds = start_bounds_; 696 gfx::Rect current_frame_bounds = start_bounds_;
698 int total_height_delta = target_bounds_.height() - start_bounds_.height(); 697 int total_height_delta = target_bounds_.height() - start_bounds_.height();
699 // Round |current_height_delta| instead of truncating so we won't leave single 698 // Round |current_height_delta| instead of truncating so we won't leave single
700 // white pixels at the bottom of the popup as long when animating very small 699 // white pixels at the bottom of the popup as long when animating very small
701 // height differences. 700 // height differences.
702 int current_height_delta = static_cast<int>( 701 int current_height_delta = static_cast<int>(
703 size_animation_.GetCurrentValue() * total_height_delta - 0.5); 702 size_animation_.GetCurrentValue() * total_height_delta - 0.5);
704 current_frame_bounds.set_height( 703 current_frame_bounds.set_height(
705 current_frame_bounds.height() + current_height_delta); 704 current_frame_bounds.height() + current_height_delta);
706 return current_frame_bounds; 705 return current_frame_bounds;
707 } 706 }
708 707
709 //////////////////////////////////////////////////////////////////////////////// 708 ////////////////////////////////////////////////////////////////////////////////
710 // AutocompletePopupContentsView, AutocompletePopupView overrides: 709 // AutocompletePopupContentsView, AutocompletePopupView overrides:
711 710
712 bool AutocompletePopupContentsView::IsOpen() const { 711 bool AutocompletePopupContentsView::IsOpen() const {
713 return popup_->IsWindow() && popup_->IsVisible(); 712 return (popup_ != NULL);
714 } 713 }
715 714
716 void AutocompletePopupContentsView::InvalidateLine(size_t line) { 715 void AutocompletePopupContentsView::InvalidateLine(size_t line) {
717 GetChildViewAt(static_cast<int>(line))->SchedulePaint(); 716 GetChildViewAt(static_cast<int>(line))->SchedulePaint();
718 } 717 }
719 718
720 void AutocompletePopupContentsView::UpdatePopupAppearance() { 719 void AutocompletePopupContentsView::UpdatePopupAppearance() {
721 if (model_->result().empty()) { 720 if (model_->result().empty()) {
722 // No matches, close any existing popup. 721 // No matches, close any existing popup.
723 if (popup_->IsWindow()) { 722 if (popup_ != NULL) {
724 size_animation_.Stop(); 723 size_animation_.Stop();
725 popup_->Hide(); 724 popup_->CloseNow();
725 popup_.reset();
726 } 726 }
727 return; 727 return;
728 } 728 }
729 729
730 // Update the match cached by each row, in the process of doing so make sure 730 // Update the match cached by each row, in the process of doing so make sure
731 // we have enough row views. 731 // we have enough row views.
732 int total_child_height = 0; 732 int total_child_height = 0;
733 size_t child_view_count = GetChildViewCount(); 733 size_t child_view_count = GetChildViewCount();
734 for (size_t i = 0; i < model_->result().size(); ++i) { 734 for (size_t i = 0; i < model_->result().size(); ++i) {
735 AutocompleteResultView* result_view; 735 AutocompleteResultView* result_view;
(...skipping 16 matching lines...) Expand all
752 -insets.bottom()); 752 -insets.bottom());
753 753
754 // If we're animating and our target height changes, reset the animation. 754 // If we're animating and our target height changes, reset the animation.
755 // NOTE: If we just reset blindly on _every_ update, then when the user types 755 // NOTE: If we just reset blindly on _every_ update, then when the user types
756 // rapidly we could get "stuck" trying repeatedly to animate shrinking by the 756 // rapidly we could get "stuck" trying repeatedly to animate shrinking by the
757 // last few pixels to get to one visible result. 757 // last few pixels to get to one visible result.
758 if (new_target_bounds.height() != target_bounds_.height()) 758 if (new_target_bounds.height() != target_bounds_.height())
759 size_animation_.Reset(); 759 size_animation_.Reset();
760 target_bounds_ = new_target_bounds; 760 target_bounds_ = new_target_bounds;
761 761
762 if (!popup_->IsWindow()) { 762 if (popup_ == NULL) {
763 // If we've never been shown, we need to create the window. 763 // If the popup is currently closed, we need to create it.
764 popup_->Init(edit_view_, this); 764 popup_.reset(new AutocompletePopupClass(edit_view_, this));
765 } else { 765 } else {
766 // Animate the popup shrinking, but don't animate growing larger (or 766 // Animate the popup shrinking, but don't animate growing larger since that
767 // appearing for the first time) since that would make the popup feel less 767 // would make the popup feel less responsive.
768 // responsive.
769 GetWidget()->GetBounds(&start_bounds_, true); 768 GetWidget()->GetBounds(&start_bounds_, true);
770 if (popup_->IsVisible() && 769 if (target_bounds_.height() < start_bounds_.height())
771 (target_bounds_.height() < start_bounds_.height()))
772 size_animation_.Show(); 770 size_animation_.Show();
773 else 771 else
774 start_bounds_ = target_bounds_; 772 start_bounds_ = target_bounds_;
775 popup_->Show(); 773 popup_->SetBounds(GetPopupBounds());
776 } 774 }
777 775
778 SchedulePaint(); 776 SchedulePaint();
779 } 777 }
780 778
781 void AutocompletePopupContentsView::OnHoverEnabledOrDisabled(bool disabled) { 779 void AutocompletePopupContentsView::OnHoverEnabledOrDisabled(bool disabled) {
782 // TODO(beng): remove this from the interface. 780 // TODO(beng): remove this from the interface.
783 } 781 }
784 782
785 void AutocompletePopupContentsView::PaintUpdatesNow() { 783 void AutocompletePopupContentsView::PaintUpdatesNow() {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 bool revert_to_default) { 821 bool revert_to_default) {
824 if (HasMatchAt(index)) 822 if (HasMatchAt(index))
825 model_->SetSelectedLine(index, revert_to_default); 823 model_->SetSelectedLine(index, revert_to_default);
826 } 824 }
827 825
828 //////////////////////////////////////////////////////////////////////////////// 826 ////////////////////////////////////////////////////////////////////////////////
829 // AutocompletePopupContentsView, AnimationDelegate implementation: 827 // AutocompletePopupContentsView, AnimationDelegate implementation:
830 828
831 void AutocompletePopupContentsView::AnimationProgressed( 829 void AutocompletePopupContentsView::AnimationProgressed(
832 const Animation* animation) { 830 const Animation* animation) {
833 popup_->Show(); 831 // We should only be running the animation when the popup is already visible.
832 DCHECK(popup_ != NULL);
833 popup_->SetBounds(GetPopupBounds());
834 } 834 }
835 835
836 //////////////////////////////////////////////////////////////////////////////// 836 ////////////////////////////////////////////////////////////////////////////////
837 // AutocompletePopupContentsView, views::View overrides: 837 // AutocompletePopupContentsView, views::View overrides:
838 838
839 void AutocompletePopupContentsView::Paint(gfx::Canvas* canvas) { 839 void AutocompletePopupContentsView::Paint(gfx::Canvas* canvas) {
840 // We paint our children in an unconventional way. 840 // We paint our children in an unconventional way.
841 // 841 //
842 // Because the border of this view creates an anti-aliased round-rect region 842 // Because the border of this view creates an anti-aliased round-rect region
843 // for the contents, we need to render our rectangular result child views into 843 // for the contents, we need to render our rectangular result child views into
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 } 948 }
949 949
950 void AutocompletePopupContentsView::MakeCanvasTransparent( 950 void AutocompletePopupContentsView::MakeCanvasTransparent(
951 gfx::Canvas* canvas) { 951 gfx::Canvas* canvas) {
952 // Allow the window blur effect to show through the popup background. 952 // Allow the window blur effect to show through the popup background.
953 SkAlpha alpha = GetThemeProvider()->ShouldUseNativeFrame() ? 953 SkAlpha alpha = GetThemeProvider()->ShouldUseNativeFrame() ?
954 kGlassPopupAlpha : kOpaquePopupAlpha; 954 kGlassPopupAlpha : kOpaquePopupAlpha;
955 canvas->drawColor(SkColorSetA(GetColor(NORMAL, BACKGROUND), alpha), 955 canvas->drawColor(SkColorSetA(GetColor(NORMAL, BACKGROUND), alpha),
956 SkXfermode::kDstIn_Mode); 956 SkXfermode::kDstIn_Mode);
957 } 957 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698