summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-15 01:37:06 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-15 01:37:06 +0000
commitee1208717f1e931175c81f63a5a8ef6338091dee (patch)
treea0c5fcf888b22f959e91a82f7d242d362bf7e11c
parentd5e45a0d81b8d21962034c48fe026c23745a600f (diff)
downloadchromium_src-ee1208717f1e931175c81f63a5a8ef6338091dee.zip
chromium_src-ee1208717f1e931175c81f63a5a8ef6338091dee.tar.gz
chromium_src-ee1208717f1e931175c81f63a5a8ef6338091dee.tar.bz2
Revert unspoofable infobar appearance to use an arrow pointing to the omnibox, rather than a tab on the left edge. This does not yet change the arrow height when the bookmark bar is open.
BUG=76388 TEST=Infobar "unspoofable" UI looks like an arrow, not a tab Review URL: http://codereview.chromium.org/6854028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81689 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/external_tab_container_win.cc4
-rw-r--r--chrome/browser/external_tab_container_win.h1
-rw-r--r--chrome/browser/ui/views/frame/browser_view.cc19
-rw-r--r--chrome/browser/ui/views/frame/browser_view.h6
-rw-r--r--chrome/browser/ui/views/infobars/infobar.cc27
-rw-r--r--chrome/browser/ui/views/infobars/infobar.h21
-rw-r--r--chrome/browser/ui/views/infobars/infobar_container.cc6
-rw-r--r--chrome/browser/ui/views/infobars/infobar_container.h9
-rw-r--r--chrome/browser/ui/views/infobars/infobar_container_view.cc2
-rw-r--r--chrome/browser/ui/views/infobars/infobar_view.cc64
-rw-r--r--chrome/browser/ui/views/infobars/infobar_view.h4
11 files changed, 80 insertions, 83 deletions
diff --git a/chrome/browser/external_tab_container_win.cc b/chrome/browser/external_tab_container_win.cc
index 2f45201..1bb2917 100644
--- a/chrome/browser/external_tab_container_win.cc
+++ b/chrome/browser/external_tab_container_win.cc
@@ -918,6 +918,10 @@ void ExternalTabContainer::InfoBarContainerHeightChanged(bool is_animating) {
external_tab_view_->Layout();
}
+bool ExternalTabContainer::DrawInfoBarArrows(int* x) const {
+ return false;
+}
+
// ExternalTabContainer instances do not have a window.
views::Window* ExternalTabContainer::GetWindow() {
return NULL;
diff --git a/chrome/browser/external_tab_container_win.h b/chrome/browser/external_tab_container_win.h
index 4bf35b5..617b84d 100644
--- a/chrome/browser/external_tab_container_win.h
+++ b/chrome/browser/external_tab_container_win.h
@@ -207,6 +207,7 @@ class ExternalTabContainer : public TabContentsDelegate,
// InfoBarContainer::Delegate overrides
virtual void InfoBarContainerHeightChanged(bool is_animating) OVERRIDE;
+ virtual bool DrawInfoBarArrows(int* x) const OVERRIDE;
virtual void TabContentsCreated(TabContents* new_contents);
diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc
index 2bcc9c1..b7c7662 100644
--- a/chrome/browser/ui/views/frame/browser_view.cc
+++ b/chrome/browser/ui/views/frame/browser_view.cc
@@ -1657,6 +1657,16 @@ void BrowserView::InfoBarContainerHeightChanged(bool is_animating) {
SelectedTabToolbarSizeChanged(is_animating);
}
+bool BrowserView::DrawInfoBarArrows(int* x) const {
+ const LocationIconView* location_icon_view =
+ toolbar_->location_bar()->location_icon_view();
+ gfx::Rect icon_bounds = location_icon_view->GetLocalBounds();
+ gfx::Point icon_center = icon_bounds.CenterPoint();
+ ConvertPointToView(location_icon_view, this, &icon_center);
+ *x = icon_center.x();
+ return true;
+}
+
bool BrowserView::SplitHandleMoved(views::SingleSplitView* view) {
for (int i = 0; i < view->child_count(); ++i)
view->GetChildViewAt(i)->InvalidateLayout();
@@ -1820,15 +1830,6 @@ void BrowserView::InitSystemMenu() {
}
#endif
-int BrowserView::GetInfoBarArrowCenterX() const {
- const LocationIconView* location_icon_view =
- toolbar_->location_bar()->location_icon_view();
- gfx::Rect icon_bounds = location_icon_view->GetLocalBounds();
- gfx::Point icon_center = icon_bounds.CenterPoint();
- ConvertPointToView(location_icon_view, this, &icon_center);
- return icon_center.x();
-}
-
BrowserViewLayout* BrowserView::GetBrowserViewLayout() const {
return static_cast<BrowserViewLayout*>(GetLayoutManager());
}
diff --git a/chrome/browser/ui/views/frame/browser_view.h b/chrome/browser/ui/views/frame/browser_view.h
index 81171e0..c12c69e 100644
--- a/chrome/browser/ui/views/frame/browser_view.h
+++ b/chrome/browser/ui/views/frame/browser_view.h
@@ -375,6 +375,7 @@ class BrowserView : public BrowserBubbleHost,
// InfoBarContainer::Delegate overrides
virtual void InfoBarContainerHeightChanged(bool is_animating) OVERRIDE;
+ virtual bool DrawInfoBarArrows(int* x) const OVERRIDE;
// views::SingleSplitView::Observer overrides:
virtual bool SplitHandleMoved(views::SingleSplitView* view) OVERRIDE;
@@ -434,11 +435,6 @@ class BrowserView : public BrowserBubbleHost,
void InitSystemMenu();
#endif
- // Get the X value, in this BrowserView's coordinate system, where
- // the points of the infobar arrows should be anchored. This is the
- // center of the omnibox location icon.
- int GetInfoBarArrowCenterX() const;
-
// Returns the BrowserViewLayout.
BrowserViewLayout* GetBrowserViewLayout() const;
diff --git a/chrome/browser/ui/views/infobars/infobar.cc b/chrome/browser/ui/views/infobars/infobar.cc
index f433356..1cc03ba 100644
--- a/chrome/browser/ui/views/infobars/infobar.cc
+++ b/chrome/browser/ui/views/infobars/infobar.cc
@@ -4,6 +4,8 @@
#include "chrome/browser/ui/views/infobars/infobar.h"
+#include <cmath>
+
#include "ui/base/animation/slide_animation.h"
#include "chrome/browser/tab_contents/infobar_delegate.h"
#include "chrome/browser/ui/views/infobars/infobar_container.h"
@@ -13,7 +15,7 @@ InfoBar::InfoBar(InfoBarDelegate* delegate)
container_(NULL),
ALLOW_THIS_IN_INITIALIZER_LIST(animation_(new ui::SlideAnimation(this))),
bar_target_height_(kDefaultBarTargetHeight),
- tab_height_(0),
+ arrow_height_(0),
bar_height_(0) {
DCHECK(delegate != NULL);
animation_->SetTweenType(ui::Tween::LINEAR);
@@ -58,27 +60,40 @@ void InfoBar::SetBarTargetHeight(int height) {
}
int InfoBar::OffsetY(const gfx::Size& prefsize) const {
- return tab_height_ +
+ return arrow_height_ +
std::max((bar_target_height_ - prefsize.height()) / 2, 0) -
(bar_target_height_ - bar_height_);
}
+bool InfoBar::DrawInfoBarArrows(int* x) const {
+ return container_ && container_->DrawInfoBarArrows(x);
+}
+
void InfoBar::AnimationEnded(const ui::Animation* animation) {
RecalculateHeight();
MaybeDelete();
}
void InfoBar::RecalculateHeight() {
- int old_tab_height = tab_height_;
+ int old_arrow_height = arrow_height_;
int old_bar_height = bar_height_;
- tab_height_ =
- static_cast<int>(kTabTargetHeight * animation()->GetCurrentValue());
+ // The arrow area is |arrow_size| ^ 2. By taking the square root of the
+ // animation value, we cause a linear animation of the area, which matches the
+ // perception of the animation of the InfoBar.
+ arrow_height_ = static_cast<int>(kArrowTargetHeight *
+ sqrt(animation()->GetCurrentValue()));
+ // Add one more pixel for the stroke, if the arrow is to be visible at all.
+ // Without this, changing the arrow height from 0 to 1 would produce no
+ // visible effect, because the single pixel of stroke would paint atop the
+ // divider line above the infobar.
+ if (arrow_height_)
+ ++arrow_height_;
bar_height_ =
static_cast<int>(bar_target_height_ * animation()->GetCurrentValue());
// Don't re-layout if nothing has changed, e.g. because the animation step was
// not large enough to actually change the heights by at least a pixel.
- if ((old_tab_height != tab_height_) || (old_bar_height != bar_height_)) {
+ if ((old_arrow_height != arrow_height_) || (old_bar_height != bar_height_)) {
PlatformSpecificOnHeightRecalculated();
if (container_)
container_->OnInfoBarHeightChanged(animation_->is_animating());
diff --git a/chrome/browser/ui/views/infobars/infobar.h b/chrome/browser/ui/views/infobars/infobar.h
index fc67b53..6f1769a 100644
--- a/chrome/browser/ui/views/infobars/infobar.h
+++ b/chrome/browser/ui/views/infobars/infobar.h
@@ -35,13 +35,14 @@ class InfoBar : public ui::AnimationDelegate {
// container (triggering its deletion), and its delegate is closed.
void Hide(bool animate);
- int tab_height() const { return tab_height_; }
- int total_height() const { return tab_height_ + bar_height_; }
+ int arrow_height() const { return arrow_height_; }
+ int total_height() const { return arrow_height_ + bar_height_; }
protected:
- // The target heights of the InfoBar tab and bar portions, regardless of what
- // their current heights are (due to animation). Platforms must define these!
- static const int kTabTargetHeight;
+ // The target heights of the InfoBar arrow and bar portions, regardless of
+ // what their current heights are (due to animation). Platforms must define
+ // these!
+ static const int kArrowTargetHeight;
static const int kDefaultBarTargetHeight;
// ui::AnimationDelegate:
@@ -59,9 +60,11 @@ class InfoBar : public ui::AnimationDelegate {
// out) as we animate open and closed.
int OffsetY(const gfx::Size& prefsize) const;
+ // Passthrough to the container function of the same name.
+ bool DrawInfoBarArrows(int* x) const;
+
ui::SlideAnimation* animation() { return animation_.get(); }
const ui::SlideAnimation* animation() const { return animation_.get(); }
- int bar_target_height() const { return bar_target_height_; }
int bar_height() const { return bar_height_; }
// Platforms may optionally override these if they need to do work during
@@ -73,7 +76,7 @@ class InfoBar : public ui::AnimationDelegate {
// ui::AnimationDelegate:
virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE;
- // Finds the new desired tab and bar heights, and if they differ from the
+ // Finds the new desired arrow and bar heights, and if they differ from the
// current ones, calls PlatformSpecificOnHeightRecalculated() and informs our
// container our height has changed.
void RecalculateHeight();
@@ -90,8 +93,8 @@ class InfoBar : public ui::AnimationDelegate {
// The target height for the bar portion of the InfoBarView.
int bar_target_height_;
- // The current heights of the tab and bar portions.
- int tab_height_;
+ // The current heights of the arrow and bar portions.
+ int arrow_height_;
int bar_height_;
DISALLOW_COPY_AND_ASSIGN(InfoBar);
diff --git a/chrome/browser/ui/views/infobars/infobar_container.cc b/chrome/browser/ui/views/infobars/infobar_container.cc
index 8be8309..c4408bc 100644
--- a/chrome/browser/ui/views/infobars/infobar_container.cc
+++ b/chrome/browser/ui/views/infobars/infobar_container.cc
@@ -67,7 +67,7 @@ int InfoBarContainer::GetVerticalOverlap(int* total_height) {
for (InfoBars::iterator i(infobars_.begin()); i != infobars_.end(); ++i) {
InfoBar* infobar = *i;
- next_infobar_y -= infobar->tab_height();
+ next_infobar_y -= infobar->arrow_height();
vertical_overlap = std::max(vertical_overlap, -next_infobar_y);
next_infobar_y += infobar->total_height();
}
@@ -82,6 +82,10 @@ void InfoBarContainer::OnInfoBarHeightChanged(bool is_animating) {
delegate_->InfoBarContainerHeightChanged(is_animating);
}
+bool InfoBarContainer::DrawInfoBarArrows(int* x) const {
+ return delegate_ && delegate_->DrawInfoBarArrows(x);
+}
+
void InfoBarContainer::RemoveDelegate(InfoBarDelegate* delegate) {
tab_contents_->RemoveInfoBar(delegate);
}
diff --git a/chrome/browser/ui/views/infobars/infobar_container.h b/chrome/browser/ui/views/infobars/infobar_container.h
index 526b90b..2ed3fcc 100644
--- a/chrome/browser/ui/views/infobars/infobar_container.h
+++ b/chrome/browser/ui/views/infobars/infobar_container.h
@@ -25,11 +25,15 @@ class TabContents;
// functions, which are pure virtual here.
class InfoBarContainer : public NotificationObserver {
public:
- // The delegate is notified each time the infobar container changes height.
class Delegate {
public:
+ // The delegate is notified each time the infobar container changes height.
virtual void InfoBarContainerHeightChanged(bool is_animating) = 0;
+ // The delegate needs to tell us whether "unspoofable" arrows should be
+ // drawn, and if so, at what |x| coordinate. |x| may not be NULL.
+ virtual bool DrawInfoBarArrows(int* x) const = 0;
+
protected:
virtual ~Delegate();
};
@@ -52,6 +56,9 @@ class InfoBarContainer : public NotificationObserver {
// e.g. re-layout.
void OnInfoBarHeightChanged(bool is_animating);
+ // Passthrough to the delegate function of the same name.
+ bool DrawInfoBarArrows(int* x) const;
+
// Remove the specified InfoBarDelegate from the selected TabContents. This
// will notify us back and cause us to close the InfoBar. This is called from
// the InfoBar's close button handler.
diff --git a/chrome/browser/ui/views/infobars/infobar_container_view.cc b/chrome/browser/ui/views/infobars/infobar_container_view.cc
index eb1de351..0ab5fbf 100644
--- a/chrome/browser/ui/views/infobars/infobar_container_view.cc
+++ b/chrome/browser/ui/views/infobars/infobar_container_view.cc
@@ -32,7 +32,7 @@ void InfoBarContainerView::Layout() {
for (int i = 0; i < child_count(); ++i) {
InfoBarView* child = static_cast<InfoBarView*>(GetChildViewAt(i));
- top -= child->tab_height();
+ top -= child->arrow_height();
int child_height = child->total_height();
child->SetBounds(0, top, width(), child_height);
top += child_height;
diff --git a/chrome/browser/ui/views/infobars/infobar_view.cc b/chrome/browser/ui/views/infobars/infobar_view.cc
index 004fc94..f43fc60 100644
--- a/chrome/browser/ui/views/infobars/infobar_view.cc
+++ b/chrome/browser/ui/views/infobars/infobar_view.cc
@@ -9,7 +9,6 @@
#include "chrome/browser/tab_contents/infobar_delegate.h"
#include "chrome/browser/ui/views/infobars/infobar_background.h"
#include "chrome/browser/ui/views/infobars/infobar_button_border.h"
-#include "chrome/browser/ui/views/infobars/infobar_container.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "third_party/skia/include/effects/SkGradientShader.h"
@@ -37,20 +36,13 @@
#endif
// static
-const int InfoBar::kTabTargetHeight = 9;
+const int InfoBar::kArrowTargetHeight = 9;
const int InfoBar::kDefaultBarTargetHeight = 36;
const int InfoBarView::kButtonButtonSpacing = 10;
const int InfoBarView::kEndOfLabelSpacing = 16;
const int InfoBarView::kHorizontalPadding = 6;
-const int InfoBarView::kCurveWidth = 13;
-const int InfoBarView::kMaxIconWidth = 30;
-const int InfoBarView::kTabIconPadding = 2;
-
-const int InfoBarView::kTabWidth = (kCurveWidth + kTabIconPadding) * 2 +
- kMaxIconWidth;
-
InfoBarView::InfoBarView(InfoBarDelegate* delegate)
: InfoBar(delegate),
icon_(NULL),
@@ -154,32 +146,20 @@ void InfoBarView::Layout() {
// width is changed, which affects both paths.
stroke_path_->rewind();
fill_path_->rewind();
- 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),
- SkIntToScalar(-divider_y),
- SkIntToScalar(kCurveWidth),
- SkIntToScalar(-divider_y));
- stroke_path_->rLineTo(SkScalarMulAdd(kTabIconPadding, 2, kMaxIconWidth),
- 0.0);
- stroke_path_->rCubicTo(
- SkScalarDiv(kCurveWidth, 2), 0.0,
- SkScalarDiv(kCurveWidth, 2),
- SkIntToScalar(divider_y),
- SkIntToScalar(kCurveWidth),
- SkIntToScalar(divider_y));
-
- // Create the fill portion of the tab. Because the fill is inside the
- // bounds and will not cover the separator, we need to extend downward by a
- // pixel before closing.
+ int arrow_bottom = std::max(arrow_height() - 1, 0);
+ SkScalar arrow_bottom_scalar = SkIntToScalar(arrow_bottom);
+ int arrow_x;
+ if (DrawInfoBarArrows(&arrow_x) && arrow_bottom) {
+ stroke_path_->moveTo(SkIntToScalar(arrow_x - arrow_bottom),
+ arrow_bottom_scalar);
+ stroke_path_->rLineTo(arrow_bottom_scalar, -arrow_bottom_scalar);
+ stroke_path_->rLineTo(arrow_bottom_scalar, arrow_bottom_scalar);
+
+ // Without extending the fill downward by a pixel, Skia doesn't seem to want
+ // to fill over the divider above the bar portion.
*fill_path_ = *stroke_path_;
fill_path_->rLineTo(0.0, 1.0);
- fill_path_->rLineTo(-SkIntToScalar(kTabWidth), 0.0);
+ fill_path_->rLineTo(-arrow_bottom_scalar * 2, 0.0);
fill_path_->close();
// Fill and stroke have different opinions about how to treat paths.
@@ -192,25 +172,15 @@ void InfoBarView::Layout() {
stroke_path_->offset(SK_ScalarHalf, SK_ScalarHalf);
}
if (bar_height()) {
- fill_path_->addRect(0.0, SkIntToScalar(tab_height()),
+ fill_path_->addRect(0.0, SkIntToScalar(arrow_height()),
SkIntToScalar(width()), SkIntToScalar(height()));
}
int start_x = kHorizontalPadding;
if (icon_ != NULL) {
- // Center the icon horizontally within the tab, and vertically between the
- // entire height (tab + bar).
gfx::Size icon_size = icon_->GetPreferredSize();
- int center_x = std::max((kTabWidth - icon_size.width()) / 2, 0);
- int full_height = bar_target_height() + kTabTargetHeight;
-
- // This duplicates OffsetY except centered within the entire height (tab +
- // bar) instead of just within the bar.
- int offset_y =
- std::max((full_height - icon_size.height()) / 2, 0) -
- (full_height - height());
- icon_->SetBounds(center_x, offset_y, icon_size.width(), icon_size.height());
- start_x += icon_->bounds().right();
+ icon_->SetBounds(start_x, OffsetY(icon_size), icon_size.width(),
+ icon_size.height());
}
gfx::Size button_size = close_button_->GetPreferredSize();
@@ -294,7 +264,7 @@ void InfoBarView::PaintChildren(gfx::Canvas* canvas) {
// canvas_skia->clipPath(*fill_path_);
DCHECK_EQ(total_height(), height())
<< "Infobar piecewise heights do not match overall height";
- canvas->ClipRectInt(0, tab_height(), width(), bar_height());
+ canvas->ClipRectInt(0, arrow_height(), width(), bar_height());
views::View::PaintChildren(canvas);
canvas->Restore();
}
diff --git a/chrome/browser/ui/views/infobars/infobar_view.h b/chrome/browser/ui/views/infobars/infobar_view.h
index 654ebc3..3b4c948 100644
--- a/chrome/browser/ui/views/infobars/infobar_view.h
+++ b/chrome/browser/ui/views/infobars/infobar_view.h
@@ -81,11 +81,7 @@ class InfoBarView : public InfoBar,
int EndX() const;
private:
- static const int kCurveWidth;
static const int kHorizontalPadding;
- static const int kMaxIconWidth;
- static const int kTabIconPadding;
- static const int kTabWidth;
// InfoBar:
virtual void PlatformSpecificHide(bool animate) OVERRIDE;