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

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

Issue 342112: Try to add more sanity checking to help track down a crash.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/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
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 "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"
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 const BubblePositioner* bubble_positioner) 584 const BubblePositioner* bubble_positioner)
585 #if defined(OS_WIN) 585 #if defined(OS_WIN)
586 : popup_(new AutocompletePopupWin(this)), 586 : popup_(new AutocompletePopupWin(this)),
587 #else 587 #else
588 : popup_(new AutocompletePopupGtk(this)), 588 : popup_(new AutocompletePopupGtk(this)),
589 #endif 589 #endif
590 model_(new AutocompletePopupModel(this, edit_model, profile)), 590 model_(new AutocompletePopupModel(this, edit_model, profile)),
591 edit_view_(edit_view), 591 edit_view_(edit_view),
592 bubble_positioner_(bubble_positioner), 592 bubble_positioner_(bubble_positioner),
593 result_font_(font.DeriveFont(kEditFontAdjust)), 593 result_font_(font.DeriveFont(kEditFontAdjust)),
594 ALLOW_THIS_IN_INITIALIZER_LIST(size_animation_(this)) { 594 ALLOW_THIS_IN_INITIALIZER_LIST(size_animation_(this)),
595 is_open_(false) {
595 // The following little dance is required because set_border() requires a 596 // The following little dance is required because set_border() requires a
596 // pointer to a non-const object. 597 // pointer to a non-const object.
597 BubbleBorder* bubble_border = new BubbleBorder; 598 BubbleBorder* bubble_border = new BubbleBorder;
598 bubble_border_ = bubble_border; 599 bubble_border_ = bubble_border;
599 set_border(bubble_border); 600 set_border(bubble_border);
600 } 601 }
601 602
602 gfx::Rect AutocompletePopupContentsView::GetPopupBounds() const { 603 gfx::Rect AutocompletePopupContentsView::GetPopupBounds() const {
603 if (!size_animation_.IsAnimating()) 604 if (!size_animation_.IsAnimating())
604 return target_bounds_; 605 return target_bounds_;
605 606
606 gfx::Rect current_frame_bounds = start_bounds_; 607 gfx::Rect current_frame_bounds = start_bounds_;
607 int total_height_delta = target_bounds_.height() - start_bounds_.height(); 608 int total_height_delta = target_bounds_.height() - start_bounds_.height();
608 // Round |current_height_delta| instead of truncating so we won't leave single 609 // Round |current_height_delta| instead of truncating so we won't leave single
609 // white pixels at the bottom of the popup as long when animating very small 610 // white pixels at the bottom of the popup as long when animating very small
610 // height differences. 611 // height differences.
611 int current_height_delta = static_cast<int>( 612 int current_height_delta = static_cast<int>(
612 size_animation_.GetCurrentValue() * total_height_delta - 0.5); 613 size_animation_.GetCurrentValue() * total_height_delta - 0.5);
613 current_frame_bounds.set_height( 614 current_frame_bounds.set_height(
614 current_frame_bounds.height() + current_height_delta); 615 current_frame_bounds.height() + current_height_delta);
615 return current_frame_bounds; 616 return current_frame_bounds;
616 } 617 }
617 618
618 //////////////////////////////////////////////////////////////////////////////// 619 ////////////////////////////////////////////////////////////////////////////////
619 // AutocompletePopupContentsView, AutocompletePopupView overrides: 620 // AutocompletePopupContentsView, AutocompletePopupView overrides:
620 621
621 bool AutocompletePopupContentsView::IsOpen() const { 622 bool AutocompletePopupContentsView::IsOpen() const {
622 return popup_->IsOpen(); 623 const bool is_open = popup_->IsOpen();
624 CHECK(is_open == is_open_);
625 return is_open;
623 } 626 }
624 627
625 void AutocompletePopupContentsView::InvalidateLine(size_t line) { 628 void AutocompletePopupContentsView::InvalidateLine(size_t line) {
626 GetChildViewAt(static_cast<int>(line))->SchedulePaint(); 629 GetChildViewAt(static_cast<int>(line))->SchedulePaint();
627 } 630 }
628 631
629 void AutocompletePopupContentsView::UpdatePopupAppearance() { 632 void AutocompletePopupContentsView::UpdatePopupAppearance() {
630 if (model_->result().empty()) { 633 if (model_->result().empty()) {
631 // No matches, close any existing popup. 634 // No matches, close any existing popup.
632 if (popup_->IsCreated()) { 635 if (popup_->IsCreated()) {
633 size_animation_.Stop(); 636 size_animation_.Stop();
634 popup_->Hide(); 637 popup_->Hide();
635 } 638 }
639 is_open_ = false;
636 return; 640 return;
637 } 641 }
638 642
639 // Update the match cached by each row, in the process of doing so make sure 643 // Update the match cached by each row, in the process of doing so make sure
640 // we have enough row views. 644 // we have enough row views.
641 int total_child_height = 0; 645 int total_child_height = 0;
642 size_t child_view_count = GetChildViewCount(); 646 size_t child_view_count = GetChildViewCount();
643 for (size_t i = 0; i < model_->result().size(); ++i) { 647 for (size_t i = 0; i < model_->result().size(); ++i) {
644 AutocompleteResultView* result_view; 648 AutocompleteResultView* result_view;
645 if (i >= child_view_count) { 649 if (i >= child_view_count) {
(...skipping 28 matching lines...) Expand all
674 // appearing for the first time) since that would make the popup feel less 678 // appearing for the first time) since that would make the popup feel less
675 // responsive. 679 // responsive.
676 GetWidget()->GetBounds(&start_bounds_, true); 680 GetWidget()->GetBounds(&start_bounds_, true);
677 if (popup_->IsVisible() && 681 if (popup_->IsVisible() &&
678 (target_bounds_.height() < start_bounds_.height())) 682 (target_bounds_.height() < start_bounds_.height()))
679 size_animation_.Show(); 683 size_animation_.Show();
680 else 684 else
681 start_bounds_ = target_bounds_; 685 start_bounds_ = target_bounds_;
682 popup_->Show(); 686 popup_->Show();
683 } 687 }
688 is_open_ = true;
684 689
685 SchedulePaint(); 690 SchedulePaint();
686 } 691 }
687 692
688 void AutocompletePopupContentsView::PaintUpdatesNow() { 693 void AutocompletePopupContentsView::PaintUpdatesNow() {
689 // TODO(beng): remove this from the interface. 694 // TODO(beng): remove this from the interface.
690 } 695 }
691 696
692 AutocompletePopupModel* AutocompletePopupContentsView::GetModel() { 697 AutocompletePopupModel* AutocompletePopupContentsView::GetModel() {
693 return model_.get(); 698 return model_.get();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 bool revert_to_default) { 735 bool revert_to_default) {
731 if (HasMatchAt(index)) 736 if (HasMatchAt(index))
732 model_->SetSelectedLine(index, revert_to_default); 737 model_->SetSelectedLine(index, revert_to_default);
733 } 738 }
734 739
735 //////////////////////////////////////////////////////////////////////////////// 740 ////////////////////////////////////////////////////////////////////////////////
736 // AutocompletePopupContentsView, AnimationDelegate implementation: 741 // AutocompletePopupContentsView, AnimationDelegate implementation:
737 742
738 void AutocompletePopupContentsView::AnimationProgressed( 743 void AutocompletePopupContentsView::AnimationProgressed(
739 const Animation* animation) { 744 const Animation* animation) {
740 popup_->Show(); 745 popup_->Show();
sky 2009/11/04 00:27:47 Do you need to set is_open_ here?
Peter Kasting 2009/11/04 00:59:58 No; this should only be called when the popup is a
741 } 746 }
742 747
743 //////////////////////////////////////////////////////////////////////////////// 748 ////////////////////////////////////////////////////////////////////////////////
744 // AutocompletePopupContentsView, views::View overrides: 749 // AutocompletePopupContentsView, views::View overrides:
745 750
746 void AutocompletePopupContentsView::Paint(gfx::Canvas* canvas) { 751 void AutocompletePopupContentsView::Paint(gfx::Canvas* canvas) {
747 // We paint our children in an unconventional way. 752 // We paint our children in an unconventional way.
748 // 753 //
749 // Because the border of this view creates an anti-aliased round-rect region 754 // Because the border of this view creates an anti-aliased round-rect region
750 // for the contents, we need to render our rectangular result child views into 755 // for the contents, we need to render our rectangular result child views into
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 // static 873 // static
869 AutocompletePopupView* AutocompletePopupView::CreatePopupView( 874 AutocompletePopupView* AutocompletePopupView::CreatePopupView(
870 const gfx::Font& font, 875 const gfx::Font& font,
871 AutocompleteEditView* edit_view, 876 AutocompleteEditView* edit_view,
872 AutocompleteEditModel* edit_model, 877 AutocompleteEditModel* edit_model,
873 Profile* profile, 878 Profile* profile,
874 const BubblePositioner* bubble_positioner) { 879 const BubblePositioner* bubble_positioner) {
875 return new AutocompletePopupContentsView(font, edit_view, edit_model, 880 return new AutocompletePopupContentsView(font, edit_view, edit_model,
876 profile, bubble_positioner); 881 profile, bubble_positioner);
877 } 882 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698