diff options
author | scr@chromium.org <scr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-04 22:20:02 +0000 |
---|---|---|
committer | scr@chromium.org <scr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-04 22:20:02 +0000 |
commit | c28834f61f07d7aebc54b82060bed29c5a1cf1d4 (patch) | |
tree | d35831135ffaca704821a947fb37d6dfb10c34f2 /chrome | |
parent | a8768512df3ef064a6983c1385f7f3f9b7588476 (diff) | |
download | chromium_src-c28834f61f07d7aebc54b82060bed29c5a1cf1d4.zip chromium_src-c28834f61f07d7aebc54b82060bed29c5a1cf1d4.tar.gz chromium_src-c28834f61f07d7aebc54b82060bed29c5a1cf1d4.tar.bz2 |
[views] spoof proof infobars.
Ported changes for http://codereview.chromium.org/3919004/ to views
for Windows and ChromeOS. Promoted infobar_arrow_model to ui, but
disabled from gyp for mac until it can be ported for that platform in
Bug 57106.
BUG=48996
TEST=manual, with animations slowed down 100x. Check with bookmarks
bar and without, check with multiple info bars by going to russia.ru
and killing flash. New tab and switching tabs hide and show the info
bars correctly.
Review URL: http://codereview.chromium.org/5978005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@73855 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
9 files changed, 122 insertions, 17 deletions
diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc index 06d8389..b4ff7aa 100644 --- a/chrome/browser/ui/views/frame/browser_view.cc +++ b/chrome/browser/ui/views/frame/browser_view.cc @@ -51,6 +51,7 @@ #include "chrome/browser/ui/views/frame/browser_view_layout.h" #include "chrome/browser/ui/views/frame/contents_container.h" #include "chrome/browser/ui/views/fullscreen_exit_bubble.h" +#include "chrome/browser/ui/views/location_bar/location_icon_view.h" #include "chrome/browser/ui/views/status_bubble_views.h" #include "chrome/browser/ui/views/tab_contents/tab_contents_container.h" #include "chrome/browser/ui/views/tabs/browser_tab_strip_controller.h" @@ -1804,6 +1805,14 @@ void BrowserView::Layout() { #endif } +void BrowserView::PaintChildren(gfx::Canvas* canvas) { + views::ClientView::PaintChildren(canvas); + + infobar_container_->PaintInfoBarArrows(canvas->AsCanvasSkia(), + this, + GetInfoBarArrowCenterX()); +} + void BrowserView::ViewHierarchyChanged(bool is_add, views::View* parent, views::View* child) { @@ -1976,6 +1985,16 @@ void BrowserView::InitSystemMenu() { } #endif +int BrowserView::GetInfoBarArrowCenterX() const { + LocationBarView* location_bar_view = toolbar_->location_bar(); + const LocationIconView* location_icon_view = + location_bar_view->location_icon_view(); + gfx::Rect icon_bounds = location_icon_view->bounds(); + gfx::Point icon_center = icon_bounds.CenterPoint(); + ConvertPointToView(location_bar_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 f9dd976..bb69a1e 100644 --- a/chrome/browser/ui/views/frame/browser_view.h +++ b/chrome/browser/ui/views/frame/browser_view.h @@ -415,6 +415,7 @@ class BrowserView : public BrowserBubbleHost, // Overridden from views::View: virtual std::string GetClassName() const; virtual void Layout(); + virtual void PaintChildren(gfx::Canvas* canvas); virtual void ViewHierarchyChanged(bool is_add, views::View* parent, views::View* child); @@ -442,6 +443,11 @@ 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_background.cc b/chrome/browser/ui/views/infobars/infobar_background.cc index 63360dd..e08de2a 100644 --- a/chrome/browser/ui/views/infobars/infobar_background.cc +++ b/chrome/browser/ui/views/infobars/infobar_background.cc @@ -22,24 +22,20 @@ static const int kSeparatorLineHeight = 1; // InfoBarBackground, public: -------------------------------------------------- InfoBarBackground::InfoBarBackground(InfoBarDelegate::Type infobar_type) { - SkColor top_color; - SkColor bottom_color; - switch (infobar_type) { - case InfoBarDelegate::WARNING_TYPE: - top_color = kWarningBackgroundColorTop; - bottom_color = kWarningBackgroundColorBottom; - break; - case InfoBarDelegate::PAGE_ACTION_TYPE: - top_color = kPageActionBackgroundColorTop; - bottom_color = kPageActionBackgroundColorBottom; - break; - default: - NOTREACHED(); - break; - } gradient_background_.reset( - views::Background::CreateVerticalGradientBackground(top_color, - bottom_color)); + views::Background::CreateVerticalGradientBackground( + GetTopColor(infobar_type), + GetBottomColor(infobar_type))); +} + +SkColor InfoBarBackground::GetTopColor(InfoBarDelegate::Type infobar_type) { + return (infobar_type == InfoBarDelegate::WARNING_TYPE) ? + kWarningBackgroundColorTop : kPageActionBackgroundColorTop; +} + +SkColor InfoBarBackground::GetBottomColor(InfoBarDelegate::Type infobar_type) { + return (infobar_type == InfoBarDelegate::WARNING_TYPE) ? + kWarningBackgroundColorBottom : kPageActionBackgroundColorBottom; } // InfoBarBackground, views::Background overrides: ----------------------------- diff --git a/chrome/browser/ui/views/infobars/infobar_background.h b/chrome/browser/ui/views/infobars/infobar_background.h index 234ca1f..9b967c0 100644 --- a/chrome/browser/ui/views/infobars/infobar_background.h +++ b/chrome/browser/ui/views/infobars/infobar_background.h @@ -17,6 +17,9 @@ class InfoBarBackground : public views::Background { // Overridden from views::Background: virtual void Paint(gfx::Canvas* canvas, views::View* view) const; + static SkColor GetTopColor(InfoBarDelegate::Type infobar_type); + static SkColor GetBottomColor(InfoBarDelegate::Type infobar_type); + private: scoped_ptr<views::Background> gradient_background_; diff --git a/chrome/browser/ui/views/infobars/infobar_container.cc b/chrome/browser/ui/views/infobars/infobar_container.cc index e5fa743..c829c14 100644 --- a/chrome/browser/ui/views/infobars/infobar_container.cc +++ b/chrome/browser/ui/views/infobars/infobar_container.cc @@ -59,6 +59,15 @@ void InfoBarContainer::RemoveDelegate(InfoBarDelegate* delegate) { tab_contents_->RemoveInfoBar(delegate); } +void InfoBarContainer::PaintInfoBarArrows(gfx::Canvas* canvas, + views::View* outer_view, + int arrow_center_x) { + for(int i = 0; i < GetChildViewCount(); ++i) { + InfoBarView* infobar = static_cast<InfoBarView*>(GetChildViewAt(i)); + infobar->PaintArrow(canvas, outer_view, arrow_center_x); + } +} + // InfoBarContainer, views::View overrides: ------------------------------------ gfx::Size InfoBarContainer::GetPreferredSize() { diff --git a/chrome/browser/ui/views/infobars/infobar_container.h b/chrome/browser/ui/views/infobars/infobar_container.h index 1461700..9a02bc8 100644 --- a/chrome/browser/ui/views/infobars/infobar_container.h +++ b/chrome/browser/ui/views/infobars/infobar_container.h @@ -44,6 +44,13 @@ class InfoBarContainer : public AccessiblePaneView, // the InfoBar's close button handler. void RemoveDelegate(InfoBarDelegate* delegate); + // Paint the InfoBar arrows on |canvas|. |arrow_center_x| indicates + // the desired location of the center of the arrow in the + // |outer_view| coordinate system. + void PaintInfoBarArrows(gfx::Canvas* canvas, + views::View* outer_view, + int arrow_center_x); + // Overridden from views::View: virtual gfx::Size GetPreferredSize(); virtual void Layout(); diff --git a/chrome/browser/ui/views/infobars/infobar_view.cc b/chrome/browser/ui/views/infobars/infobar_view.cc index a45021f..5e90a16 100644 --- a/chrome/browser/ui/views/infobars/infobar_view.cc +++ b/chrome/browser/ui/views/infobars/infobar_view.cc @@ -9,8 +9,10 @@ #include "chrome/browser/ui/views/infobars/infobar_background.h" #include "chrome/browser/ui/views/infobars/infobar_container.h" #include "chrome/browser/tab_contents/infobar_delegate.h" +#include "gfx/canvas_skia_paint.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" +#include "third_party/skia/include/effects/SkGradientShader.h" #include "ui/base/animation/slide_animation.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" @@ -79,6 +81,58 @@ InfoBarView::InfoBarView(InfoBarDelegate* delegate) InfoBarView::~InfoBarView() { } +void InfoBarView::PaintArrow(gfx::Canvas* canvas, + views::View* outer_view, + int arrow_center_x) { + gfx::Point infobar_top(0, y()); + ConvertPointToView(GetParent(), outer_view, &infobar_top); + int infobar_top_y = infobar_top.y(); + + // The size of the arrow (its height; also half its width). 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. + const int kArrowSize = 10; + int arrow_size = static_cast<int>(kArrowSize * + sqrt(animation_->GetCurrentValue())); + + SkPath fill_path; + fill_path.moveTo(SkPoint::Make(SkIntToScalar(arrow_center_x - arrow_size), + SkIntToScalar(infobar_top_y))); + fill_path.rLineTo(SkIntToScalar(arrow_size), SkIntToScalar(-arrow_size)); + fill_path.rLineTo(SkIntToScalar(arrow_size), SkIntToScalar(arrow_size)); + SkPath border_path(fill_path); + fill_path.close(); + + SkPaint paint; + paint.setStrokeWidth(1); + paint.setStyle(SkPaint::kFill_Style); + + SkPoint grad_points[2]; + grad_points[0].set(SkIntToScalar(0), SkIntToScalar(infobar_top_y)); + grad_points[1].set(SkIntToScalar(0), + SkIntToScalar(infobar_top_y + target_height_)); + + SkColor grad_colors[2]; + grad_colors[0] = InfoBarBackground::GetTopColor(delegate_->GetInfoBarType()); + grad_colors[1] = + InfoBarBackground::GetBottomColor(delegate_->GetInfoBarType()); + + SkShader* gradient_shader = SkGradientShader::CreateLinear( + grad_points, grad_colors, NULL, 2, SkShader::kMirror_TileMode); + paint.setShader(gradient_shader); + gradient_shader->unref(); + + gfx::CanvasSkia* canvas_skia = canvas->AsCanvasSkia(); + canvas_skia->drawPath(fill_path, paint); + + paint.setShader(NULL); + paint.setColor(SkColorSetA(ResourceBundle::toolbar_separator_color, + SkColorGetA(grad_colors[0]))); + paint.setStyle(SkPaint::kStroke_Style); + canvas_skia->drawPath(border_path, paint); +} + // InfoBarView, views::View overrides: ---------------------------------------- AccessibilityTypes::Role InfoBarView::GetAccessibleRole() { diff --git a/chrome/browser/ui/views/infobars/infobar_view.h b/chrome/browser/ui/views/infobars/infobar_view.h index 0710ad03..b52e64f 100644 --- a/chrome/browser/ui/views/infobars/infobar_view.h +++ b/chrome/browser/ui/views/infobars/infobar_view.h @@ -70,6 +70,13 @@ class InfoBarView : public InfoBar, virtual gfx::Size GetPreferredSize(); virtual void Layout(); + // Paint the arrow on |canvas|. |arrow_center_x| indicates the + // desired location of the center of the arrow in the |outer_view| + // coordinate system. + void PaintArrow(gfx::Canvas* canvas, + views::View* outer_view, + int arrow_center_x); + protected: // Overridden from views::View: virtual void ViewHierarchyChanged(bool is_add, diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.h b/chrome/browser/ui/views/location_bar/location_bar_view.h index d149aba..63d6997 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.h +++ b/chrome/browser/ui/views/location_bar/location_bar_view.h @@ -185,6 +185,10 @@ class LocationBarView : public LocationBar, virtual void OnMouseReleased(const views::MouseEvent& event, bool canceled); #endif + const LocationIconView* location_icon_view() const { + return location_icon_view_; + } + // AutocompleteEditController virtual void OnAutocompleteWillClosePopup(); virtual void OnAutocompleteLosingFocus(gfx::NativeView view_gaining_focus); |