summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-04 20:49:27 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-04 20:49:27 +0000
commit72dc92dc4f37783ba4aedae7d2d9c1750fac999e (patch)
treefae398d84993b53309f1d59aeade3d9f8445e869 /chrome
parent645557348e69a6f1ef392ade038bee8c83e183da (diff)
downloadchromium_src-72dc92dc4f37783ba4aedae7d2d9c1750fac999e.zip
chromium_src-72dc92dc4f37783ba4aedae7d2d9c1750fac999e.tar.gz
chromium_src-72dc92dc4f37783ba4aedae7d2d9c1750fac999e.tar.bz2
Fix a couple of aesthetic nits about infobars that have been broken since I redid them a few months back.
- close button is properly centered horizontally - animation looks correct - layout no longer dependent on current frame height http://crbug.com/11389 Review URL: http://codereview.chromium.org/99332 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15237 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/views/infobars/infobars.cc28
-rw-r--r--chrome/browser/views/infobars/infobars.h8
2 files changed, 30 insertions, 6 deletions
diff --git a/chrome/browser/views/infobars/infobars.cc b/chrome/browser/views/infobars/infobars.cc
index 66a95c4..3ea0421 100644
--- a/chrome/browser/views/infobars/infobars.cc
+++ b/chrome/browser/views/infobars/infobars.cc
@@ -21,7 +21,8 @@
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
-const double kInfoBarHeight = 37.0;
+// static
+const double InfoBar::kTargetHeight = 37.0;
static const int kVerticalPadding = 3;
static const int kHorizontalPadding = 3;
@@ -36,8 +37,20 @@ static const int kSeparatorLineHeight = 1;
static const SkColor kSeparatorColor = SkColorSetRGB(165, 165, 165);
namespace {
+// Returns a centered y-position of a control of height specified in |prefsize|
+// within the standard InfoBar height. Stable during an animation.
+int CenterY(const gfx::Size prefsize) {
+ return std::max((static_cast<int>(InfoBar::kTargetHeight) -
+ prefsize.height()) / 2, 0);
+}
+
+// Returns a centered y-position of a control of height specified in |prefsize|
+// within the standard InfoBar height, adjusted according to the current amount
+// of animation offset the |parent| InfoBar currently has. Changes during an
+// animation.
int OffsetY(views::View* parent, const gfx::Size prefsize) {
- return std::max((parent->height() - prefsize.height()) / 2, 0);
+ return CenterY(prefsize) -
+ (static_cast<int>(InfoBar::kTargetHeight) - parent->height());
}
}
@@ -124,16 +137,15 @@ void InfoBar::Close() {
// InfoBar, views::View overrides: ---------------------------------------------
gfx::Size InfoBar::GetPreferredSize() {
- int height = static_cast<int>(kInfoBarHeight * animation_->GetCurrentValue());
+ int height = static_cast<int>(kTargetHeight * animation_->GetCurrentValue());
return gfx::Size(0, height);
}
void InfoBar::Layout() {
gfx::Size button_ps = close_button_->GetPreferredSize();
- close_button_->SetBounds(width() - kHorizontalPadding - button_ps.width(),
+ close_button_->SetBounds(width() - CloseButtonSpacing() - button_ps.width(),
OffsetY(this, button_ps), button_ps.width(),
button_ps.height());
-
}
void InfoBar::ViewHierarchyChanged(bool is_add, views::View* parent,
@@ -150,13 +162,17 @@ void InfoBar::ViewHierarchyChanged(bool is_add, views::View* parent,
// InfoBar, protected: ---------------------------------------------------------
int InfoBar::GetAvailableWidth() const {
- return close_button_->x() - kIconLabelSpacing;
+ return close_button_->x() - CloseButtonSpacing();
}
void InfoBar::RemoveInfoBar() const {
container_->RemoveDelegate(delegate());
}
+int InfoBar::CloseButtonSpacing() const {
+ return CenterY(close_button_->GetPreferredSize());
+}
+
// InfoBar, views::ButtonListener implementation: ------------------
void InfoBar::ButtonPressed(views::Button* sender) {
diff --git a/chrome/browser/views/infobars/infobars.h b/chrome/browser/views/infobars/infobars.h
index 85388bd..7b5feae 100644
--- a/chrome/browser/views/infobars/infobars.h
+++ b/chrome/browser/views/infobars/infobars.h
@@ -52,6 +52,10 @@ class InfoBar : public views::View,
// is called.
void Close();
+ // The target height of the infobar, regardless of what its current height
+ // is (due to animation).
+ static const double kTargetHeight;
+
// Overridden from views::View:
virtual gfx::Size GetPreferredSize();
virtual void Layout();
@@ -70,6 +74,10 @@ class InfoBar : public views::View,
// (Will lead to this InfoBar being closed).
void RemoveInfoBar() const;
+ // Returns the spacing required between the close button and any adjacent
+ // control.
+ int CloseButtonSpacing() const;
+
// Overridden from views::ButtonListener:
virtual void ButtonPressed(views::Button* sender);