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

Unified Diff: chrome/browser/ui/views/infobars/infobar_view.cc

Issue 6788014: Fix DCHECK() in infobar animation. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 months 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/infobars/infobar_view.cc
===================================================================
--- chrome/browser/ui/views/infobars/infobar_view.cc (revision 80169)
+++ chrome/browser/ui/views/infobars/infobar_view.cc (working copy)
@@ -56,6 +56,8 @@
close_button_(NULL),
ALLOW_THIS_IN_INITIALIZER_LIST(delete_factory_(this)),
target_height_(kDefaultTargetHeight),
+ tab_height_(0),
+ bar_height_(0),
fill_path_(new SkPath),
stroke_path_(new SkPath) {
set_parent_owned(false); // InfoBar deletes itself at the appropriate time.
@@ -245,12 +247,9 @@
//
// gfx::CanvasSkia* canvas_skia = canvas->AsCanvasSkia();
// canvas_skia->clipPath(*fill_path_);
- int tab_height = AnimatedTabHeight();
- int bar_height = AnimatedBarHeight();
- DCHECK_EQ(tab_height + bar_height, height())
- << "Animation progressed between OnBoundsChanged & PaintChildren.";
- canvas->ClipRectInt(0, tab_height, width(), bar_height);
-
+ DCHECK_EQ(tab_height_ + bar_height_, height())
+ << "Infobar piecewise heights do not match overall height";
+ canvas->ClipRectInt(0, tab_height_, width(), bar_height_);
views::View::PaintChildren(canvas);
canvas->Restore();
}
@@ -268,6 +267,13 @@
return 0;
}
+void InfoBarView::SetTargetHeight(int height) {
+ if (target_height_ != height) {
+ target_height_ = height;
+ OnSizeChanged();
+ }
+}
+
int InfoBarView::StartX() const {
// Ensure we don't return a value greater than EndX(), so children can safely
// set something's width to "EndX() - StartX()" without risking that being
@@ -286,8 +292,7 @@
}
int InfoBarView::OffsetY(const gfx::Size prefsize) const {
- return CenterY(prefsize) + AnimatedTabHeight() -
- (target_height_ - AnimatedBarHeight());
+ return CenterY(prefsize) + tab_height_ - (target_height_ - bar_height_);
}
void InfoBarView::PlatformSpecificHide(bool animate) {
@@ -305,41 +310,22 @@
DestroyFocusTracker(restore_focus);
}
-void InfoBarView::GetAccessibleState(ui::AccessibleViewState* state) {
- if (delegate()) {
- state->name = l10n_util::GetStringUTF16(
- (delegate()->GetInfoBarType() == InfoBarDelegate::WARNING_TYPE) ?
- IDS_ACCNAME_INFOBAR_WARNING : IDS_ACCNAME_INFOBAR_PAGE_ACTION);
- }
- state->role = ui::AccessibilityTypes::ROLE_ALERT;
-}
+void InfoBarView::PlatformSpecificOnSizeChanged() {
+ int old_tab_height = tab_height_;
+ int old_bar_height = bar_height_;
+ tab_height_ = static_cast<int>(kTabHeight * animation()->GetCurrentValue());
+ bar_height_ =
+ static_cast<int>(target_height_ * animation()->GetCurrentValue());
+ if ((old_tab_height == tab_height_) && (old_bar_height == bar_height_))
+ return;
-int InfoBarView::AnimatedTabHeight() const {
- return static_cast<int>(kTabHeight * animation()->GetCurrentValue());
-}
-
-int InfoBarView::AnimatedBarHeight() const {
- return static_cast<int>(target_height_ * animation()->GetCurrentValue());
-}
-
-gfx::Size InfoBarView::GetPreferredSize() {
- return gfx::Size(0, AnimatedTabHeight() + AnimatedBarHeight());
-}
-
-void InfoBarView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
- int tab_height = AnimatedTabHeight();
- int bar_height = AnimatedBarHeight();
- int divider_y = tab_height - 1;
- DCHECK_EQ(tab_height + bar_height, height())
- << "Animation progressed between Layout & OnBoundsChanged.";
-
- int mirrored_x = GetMirroredXWithWidthInView(0, kTabWidth);
stroke_path_->rewind();
fill_path_->rewind();
-
- if (tab_height) {
- stroke_path_->moveTo(SkIntToScalar(mirrored_x),
- SkIntToScalar(divider_y));
+ if (tab_height_) {
+ int divider_y = tab_height_ - 1;
+ stroke_path_->moveTo(
+ SkIntToScalar(GetMirroredXWithWidthInView(0, kTabWidth)),
+ SkIntToScalar(divider_y));
stroke_path_->rCubicTo(
SkScalarDiv(kCurveWidth, 2), 0.0,
SkScalarDiv(kCurveWidth, 2),
@@ -372,12 +358,29 @@
// a fill at a very different place than we'd want.
stroke_path_->offset(SK_ScalarHalf, SK_ScalarHalf);
}
- if (bar_height) {
- fill_path_->addRect(0.0, SkIntToScalar(tab_height),
+ if (bar_height_) {
+ fill_path_->addRect(0.0, SkIntToScalar(tab_height_),
SkIntToScalar(width()), SkIntToScalar(height()));
}
+
+ // Ensure that notifying our container of our size change will result in a
+ // re-layout.
+ InvalidateLayout();
Sheridan Rawlins 2011/04/01 18:41:48 InvalidateLayout only needs_layout, but doesn't ca
Peter Kasting 2011/04/01 19:07:15 We will notify the container immediately upon retu
}
+void InfoBarView::GetAccessibleState(ui::AccessibleViewState* state) {
+ if (delegate()) {
+ state->name = l10n_util::GetStringUTF16(
+ (delegate()->GetInfoBarType() == InfoBarDelegate::WARNING_TYPE) ?
+ IDS_ACCNAME_INFOBAR_WARNING : IDS_ACCNAME_INFOBAR_PAGE_ACTION);
+ }
+ state->role = ui::AccessibilityTypes::ROLE_ALERT;
+}
+
+gfx::Size InfoBarView::GetPreferredSize() {
+ return gfx::Size(0, tab_height_ + bar_height_);
+}
+
void InfoBarView::FocusWillChange(View* focused_before, View* focused_now) {
// This will trigger some screen readers to read the entire contents of this
// infobar.
« chrome/browser/ui/views/infobars/infobar.h ('K') | « chrome/browser/ui/views/infobars/infobar_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698