diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-03 01:36:00 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-03 01:36:00 +0000 |
commit | 5855df7de77eee7ad51cdac73f7d294525d75faf (patch) | |
tree | 9231cdfe54737935a63620b894e895cba69bbb33 /chrome/browser/views | |
parent | f82a64d15a03c6db10ea33449c34d496a145b08e (diff) | |
download | chromium_src-5855df7de77eee7ad51cdac73f7d294525d75faf.zip chromium_src-5855df7de77eee7ad51cdac73f7d294525d75faf.tar.gz chromium_src-5855df7de77eee7ad51cdac73f7d294525d75faf.tar.bz2 |
Convert Alternate NavURL Fetcher to use the new infobar framework.
http://crbug.com/4620
Review URL: http://codereview.chromium.org/13070
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6268 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r-- | chrome/browser/views/infobars/infobars.cc | 108 | ||||
-rw-r--r-- | chrome/browser/views/infobars/infobars.h | 24 |
2 files changed, 132 insertions, 0 deletions
diff --git a/chrome/browser/views/infobars/infobars.cc b/chrome/browser/views/infobars/infobars.cc index 52fcf55..475b7ea 100644 --- a/chrome/browser/views/infobars/infobars.cc +++ b/chrome/browser/views/infobars/infobars.cc @@ -5,6 +5,7 @@ #include "chrome/browser/views/infobars/infobars.h" #include "chrome/app/theme/theme_resources.h" +#include "chrome/browser/views/event_utils.h" #include "chrome/browser/views/infobars/infobar_container.h" #include "chrome/common/l10n_util.h" #include "chrome/common/resource_bundle.h" @@ -24,6 +25,7 @@ static const int kVerticalPadding = 3; static const int kHorizontalPadding = 3; static const int kIconLabelSpacing = 5; static const int kButtonSpacing = 5; +static const int kWordSpacing = 2; static const SkColor kBackgroundColorTop = SkColorSetRGB(255, 242, 183); static const SkColor kBackgroundColorBottom = SkColorSetRGB(250, 230, 145); @@ -262,6 +264,106 @@ AlertInfoBarDelegate* AlertInfoBar::GetDelegate() { return delegate()->AsAlertInfoBarDelegate(); } +// LinkInfoBar, public: -------------------------------------------------------- + +LinkInfoBar::LinkInfoBar(LinkInfoBarDelegate* delegate) + : icon_(new views::ImageView), + label_1_(new views::Label), + label_2_(new views::Label), + link_(new views::Link), + InfoBar(delegate) { + // Set up the icon. + if (delegate->GetIcon()) + icon_->SetImage(delegate->GetIcon()); + AddChildView(icon_); + + // Set up the labels. + size_t offset; + std::wstring message_text = delegate->GetMessageTextWithOffset(&offset); + if (offset != std::wstring::npos) { + label_1_->SetText(message_text.substr(0, offset)); + label_2_->SetText(message_text.substr(offset)); + } else { + label_1_->SetText(message_text); + } + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + label_1_->SetFont(rb.GetFont(ResourceBundle::MediumFont)); + label_2_->SetFont(rb.GetFont(ResourceBundle::MediumFont)); + label_1_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); + label_2_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); + AddChildView(label_1_); + AddChildView(label_2_); + + // Set up the link. + link_->SetText(delegate->GetLinkText()); + link_->SetFont(rb.GetFont(ResourceBundle::MediumFont)); + link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); + link_->SetController(this); + AddChildView(link_); +} + +LinkInfoBar::~LinkInfoBar() { +} + +// LinkInfoBar, views::LinkController implementation: -------------------------- + +void LinkInfoBar::LinkActivated(views::Link* source, int event_flags) { + DCHECK(source == link_); + if (GetDelegate()->LinkClicked( + event_utils::DispositionFromEventFlags(event_flags))) { + RemoveInfoBar(); + } +} + +// LinkInfoBar, views::View overrides: ----------------------------------------- + +void LinkInfoBar::Layout() { + // Layout the close button. + InfoBar::Layout(); + + // Layout the icon. + gfx::Size icon_ps = icon_->GetPreferredSize(); + icon_->SetBounds(kHorizontalPadding, OffsetY(this, icon_ps), icon_ps.width(), + icon_ps.height()); + + int label_1_x = icon_->bounds().right() + kIconLabelSpacing; + + // Figure out the amount of space available to the rest of the content now + // that the close button and the icon have been positioned. + int available_width = GetAvailableWidth() - label_1_x; + + // Layout the left label. + gfx::Size label_1_ps = label_1_->GetPreferredSize(); + label_1_->SetBounds(label_1_x, OffsetY(this, label_1_ps), label_1_ps.width(), + label_1_ps.height()); + + // Layout the link. + gfx::Size link_ps = link_->GetPreferredSize(); + bool has_second_label = !label_2_->GetText().empty(); + if (has_second_label) { + // Embed the link in the text string between the two labels. + link_->SetBounds(label_1_->bounds().right() + kWordSpacing, + OffsetY(this, link_ps), link_ps.width(), link_ps.height()); + } else { + // Right-align the link toward the edge of the InfoBar. + link_->SetBounds(label_1_x + available_width - link_ps.width(), + OffsetY(this, link_ps), link_ps.width(), link_ps.height()); + } + + // Layout the right label (we do this regardless of whether or not it has + // text). + gfx::Size label_2_ps = label_2_->GetPreferredSize(); + label_2_->SetBounds(link_->bounds().right() + kWordSpacing, + OffsetY(this, label_2_ps), label_2_ps.width(), + label_2_ps.height()); +} + +// LinkInfoBar, private: ------------------------------------------------------- + +LinkInfoBarDelegate* LinkInfoBar::GetDelegate() { + return delegate()->AsLinkInfoBarDelegate(); +} + // ConfirmInfoBar, public: ----------------------------------------------------- ConfirmInfoBar::ConfirmInfoBar(ConfirmInfoBarDelegate* delegate) @@ -361,6 +463,12 @@ InfoBar* AlertInfoBarDelegate::CreateInfoBar() { return new AlertInfoBar(this); } +// LinkInfoBarDelegate, InfoBarDelegate overrides: ----------------------------- + +InfoBar* LinkInfoBarDelegate::CreateInfoBar() { + return new LinkInfoBar(this); +} + // ConfirmInfoBarDelegate, InfoBarDelegate overrides: -------------------------- InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() { diff --git a/chrome/browser/views/infobars/infobars.h b/chrome/browser/views/infobars/infobars.h index 028632b..e0ae487 100644 --- a/chrome/browser/views/infobars/infobars.h +++ b/chrome/browser/views/infobars/infobars.h @@ -7,6 +7,7 @@ #include "chrome/browser/infobar_delegate.h" #include "chrome/views/base_button.h" +#include "chrome/views/link.h" #include "chrome/views/native_button.h" class InfoBarContainer; @@ -133,6 +134,29 @@ class AlertInfoBar : public InfoBar { DISALLOW_COPY_AND_ASSIGN(AlertInfoBar); }; +class LinkInfoBar : public InfoBar, + public views::LinkController { + public: + explicit LinkInfoBar(LinkInfoBarDelegate* delegate); + virtual ~LinkInfoBar(); + + // Overridden from views::LinkController: + virtual void LinkActivated(views::Link* source, int event_flags); + + // Overridden from views::View: + virtual void Layout(); + + private: + LinkInfoBarDelegate* GetDelegate(); + + views::ImageView* icon_; + views::Label* label_1_; + views::Label* label_2_; + views::Link* link_; + + DISALLOW_COPY_AND_ASSIGN(LinkInfoBar); +}; + class ConfirmInfoBar : public AlertInfoBar, public views::NativeButton::Listener { public: |