diff options
20 files changed, 864 insertions, 761 deletions
diff --git a/chrome/browser/autofill/autofill_cc_infobar_win.cc b/chrome/browser/autofill/autofill_cc_infobar_win.cc index db44274..d24e4f0 100644 --- a/chrome/browser/autofill/autofill_cc_infobar_win.cc +++ b/chrome/browser/autofill/autofill_cc_infobar_win.cc @@ -4,8 +4,9 @@ #include "chrome/browser/autofill/autofill_cc_infobar.h" +#include "chrome/browser/tab_contents/infobar_delegate.h" #include "chrome/browser/ui/views/event_utils.h" -#include "chrome/browser/ui/views/infobars/infobars.h" +#include "chrome/browser/ui/views/infobars/confirm_infobar.h" #include "chrome/browser/ui/views/infobars/infobar_text_button.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" @@ -84,7 +85,7 @@ SaveCCInfoConfirmInfoBar::~SaveCCInfoConfirmInfoBar() { void SaveCCInfoConfirmInfoBar::Layout() { // Layout the close button. - InfoBar::Layout(); + InfoBarView::Layout(); int available_width = AlertInfoBar::GetAvailableWidth(); @@ -129,7 +130,7 @@ void SaveCCInfoConfirmInfoBar::LinkActivated(views::Link* source, void SaveCCInfoConfirmInfoBar::ViewHierarchyChanged(bool is_add, views::View* parent, views::View* child) { - InfoBar::ViewHierarchyChanged(is_add, parent, child); + InfoBarView::ViewHierarchyChanged(is_add, parent, child); if (is_add && child == this && !initialized_) { Init(); initialized_ = true; @@ -138,7 +139,7 @@ void SaveCCInfoConfirmInfoBar::ViewHierarchyChanged(bool is_add, void SaveCCInfoConfirmInfoBar::ButtonPressed(views::Button* sender, const views::Event& event) { - InfoBar::ButtonPressed(sender, event); + InfoBarView::ButtonPressed(sender, event); if (sender == save_button_) { if (GetDelegate()->Accept()) RemoveInfoBar(); diff --git a/chrome/browser/ui/views/infobars/after_translate_infobar.cc b/chrome/browser/ui/views/infobars/after_translate_infobar.cc index c7f111c..b7eea3d 100644 --- a/chrome/browser/ui/views/infobars/after_translate_infobar.cc +++ b/chrome/browser/ui/views/infobars/after_translate_infobar.cc @@ -67,7 +67,7 @@ void AfterTranslateInfoBar::Layout() { TranslateInfoBarBase::Layout(); // Layout the options menu button on right of bar. - int available_width = InfoBar::GetAvailableWidth(); + int available_width = InfoBarView::GetAvailableWidth(); gfx::Size pref_size = options_menu_button_->GetPreferredSize(); options_menu_button_->SetBounds(available_width - pref_size.width(), OffsetY(this, pref_size), pref_size.width(), pref_size.height()); @@ -78,32 +78,33 @@ void AfterTranslateInfoBar::Layout() { original_language_menu_button_ : target_language_menu_button_; pref_size = label_1_->GetPreferredSize(); - label_1_->SetBounds(icon_->bounds().right() + InfoBar::kIconLabelSpacing, - InfoBar::OffsetY(this, pref_size), pref_size.width(), pref_size.height()); + label_1_->SetBounds(icon_->bounds().right() + InfoBarView::kIconLabelSpacing, + InfoBarView::OffsetY(this, pref_size), pref_size.width(), + pref_size.height()); pref_size = left_button->GetPreferredSize(); left_button->SetBounds(label_1_->bounds().right() + - InfoBar::kButtonInLabelSpacing, OffsetY(this, pref_size), + InfoBarView::kButtonInLabelSpacing, OffsetY(this, pref_size), pref_size.width(), pref_size.height()); pref_size = label_2_->GetPreferredSize(); label_2_->SetBounds(left_button->bounds().right() + - InfoBar::kButtonInLabelSpacing, InfoBar::OffsetY(this, pref_size), + InfoBarView::kButtonInLabelSpacing, InfoBarView::OffsetY(this, pref_size), pref_size.width(), pref_size.height()); pref_size = right_button->GetPreferredSize(); right_button->SetBounds(label_2_->bounds().right() + - InfoBar::kButtonInLabelSpacing, OffsetY(this, pref_size), + InfoBarView::kButtonInLabelSpacing, OffsetY(this, pref_size), pref_size.width(), pref_size.height()); pref_size = label_3_->GetPreferredSize(); label_3_->SetBounds(right_button->bounds().right() + - InfoBar::kButtonInLabelSpacing, InfoBar::OffsetY(this, pref_size), + InfoBarView::kButtonInLabelSpacing, InfoBarView::OffsetY(this, pref_size), pref_size.width(), pref_size.height()); pref_size = revert_button_->GetPreferredSize(); revert_button_->SetBounds(label_3_->bounds().right() + - InfoBar::kButtonInLabelSpacing, InfoBar::OffsetY(this, pref_size), + InfoBarView::kButtonInLabelSpacing, InfoBarView::OffsetY(this, pref_size), pref_size.width(), pref_size.height()); } diff --git a/chrome/browser/ui/views/infobars/before_translate_infobar.cc b/chrome/browser/ui/views/infobars/before_translate_infobar.cc index 0feea6f..cb35426 100644 --- a/chrome/browser/ui/views/infobars/before_translate_infobar.cc +++ b/chrome/browser/ui/views/infobars/before_translate_infobar.cc @@ -78,46 +78,47 @@ void BeforeTranslateInfoBar::Layout() { TranslateInfoBarBase::Layout(); // Layout the options menu button on right of bar. - int available_width = InfoBar::GetAvailableWidth(); + int available_width = InfoBarView::GetAvailableWidth(); gfx::Size pref_size = options_menu_button_->GetPreferredSize(); options_menu_button_->SetBounds(available_width - pref_size.width(), OffsetY(this, pref_size), pref_size.width(), pref_size.height()); pref_size = label_1_->GetPreferredSize(); - label_1_->SetBounds(icon_->bounds().right() + InfoBar::kIconLabelSpacing, - InfoBar::OffsetY(this, pref_size), pref_size.width(), pref_size.height()); + label_1_->SetBounds(icon_->bounds().right() + InfoBarView::kIconLabelSpacing, + InfoBarView::OffsetY(this, pref_size), pref_size.width(), + pref_size.height()); pref_size = language_menu_button_->GetPreferredSize(); language_menu_button_->SetBounds(label_1_->bounds().right() + - InfoBar::kButtonInLabelSpacing, OffsetY(this, pref_size), + InfoBarView::kButtonInLabelSpacing, OffsetY(this, pref_size), pref_size.width(), pref_size.height()); pref_size = label_2_->GetPreferredSize(); label_2_->SetBounds(language_menu_button_->bounds().right() + - InfoBar::kButtonInLabelSpacing , InfoBar::OffsetY(this, pref_size), + InfoBarView::kButtonInLabelSpacing, InfoBarView::OffsetY(this, pref_size), pref_size.width(), pref_size.height()); pref_size = accept_button_->GetPreferredSize(); accept_button_->SetBounds( - label_2_->bounds().right() + InfoBar::kEndOfLabelSpacing, + label_2_->bounds().right() + InfoBarView::kEndOfLabelSpacing, OffsetY(this, pref_size), pref_size.width(), pref_size.height()); pref_size = deny_button_->GetPreferredSize(); deny_button_->SetBounds( - accept_button_->bounds().right() + InfoBar::kButtonButtonSpacing, + accept_button_->bounds().right() + InfoBarView::kButtonButtonSpacing, OffsetY(this, pref_size), pref_size.width(), pref_size.height()); if (never_translate_button_) { pref_size = never_translate_button_->GetPreferredSize(); never_translate_button_->SetBounds( - deny_button_->bounds().right() + InfoBar::kButtonButtonSpacing, + deny_button_->bounds().right() + InfoBarView::kButtonButtonSpacing, OffsetY(this, pref_size), pref_size.width(), pref_size.height()); } if (always_translate_button_) { DCHECK(!never_translate_button_); pref_size = always_translate_button_->GetPreferredSize(); always_translate_button_->SetBounds( - deny_button_->bounds().right() + InfoBar::kButtonButtonSpacing, + deny_button_->bounds().right() + InfoBarView::kButtonButtonSpacing, OffsetY(this, pref_size), pref_size.width(), pref_size.height()); } } diff --git a/chrome/browser/ui/views/infobars/before_translate_infobar.h b/chrome/browser/ui/views/infobars/before_translate_infobar.h index 8e4e9dde..2f2c538 100644 --- a/chrome/browser/ui/views/infobars/before_translate_infobar.h +++ b/chrome/browser/ui/views/infobars/before_translate_infobar.h @@ -9,7 +9,6 @@ #include "chrome/browser/translate/languages_menu_model.h" #include "chrome/browser/translate/options_menu_model.h" #include "chrome/browser/translate/translate_infobar_view.h" -#include "chrome/browser/ui/views/infobars/infobars.h" #include "chrome/browser/ui/views/infobars/translate_infobar_base.h" #include "views/controls/button/button.h" #include "views/controls/link.h" @@ -23,9 +22,8 @@ class Menu2; class MenuButton; } -class BeforeTranslateInfoBar - : public TranslateInfoBarBase, - public views::ViewMenuDelegate { +class BeforeTranslateInfoBar : public TranslateInfoBarBase, + public views::ViewMenuDelegate { public: explicit BeforeTranslateInfoBar(TranslateInfoBarDelegate* delegate); virtual ~BeforeTranslateInfoBar(); diff --git a/chrome/browser/ui/views/infobars/confirm_infobar.cc b/chrome/browser/ui/views/infobars/confirm_infobar.cc new file mode 100644 index 0000000..427beda --- /dev/null +++ b/chrome/browser/ui/views/infobars/confirm_infobar.cc @@ -0,0 +1,194 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/ui/views/infobars/confirm_infobar.h" + +#include "base/utf_string_conversions.h" +#include "chrome/browser/tab_contents/infobar_delegate.h" +#include "chrome/browser/ui/views/event_utils.h" +#include "chrome/browser/ui/views/infobars/infobar_text_button.h" +#include "ui/base/resource/resource_bundle.h" +#include "views/controls/image_view.h" +#include "views/controls/label.h" + +// AlertInfoBar, public: ------------------------------------------------------- + +AlertInfoBar::AlertInfoBar(ConfirmInfoBarDelegate* delegate) + : InfoBarView(delegate) { + label_ = new views::Label( + UTF16ToWideHack(delegate->GetMessageText()), + ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont)); + label_->SetColor(SK_ColorBLACK); + label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); + AddChildView(label_); + + icon_ = new views::ImageView; + if (delegate->GetIcon()) + icon_->SetImage(delegate->GetIcon()); + AddChildView(icon_); +} + +AlertInfoBar::~AlertInfoBar() { +} + +// AlertInfoBar, views::View overrides: ---------------------------------------- + +void AlertInfoBar::Layout() { + // Layout the close button. + InfoBarView::Layout(); + + // Layout the icon and text. + gfx::Size icon_ps = icon_->GetPreferredSize(); + icon_->SetBounds(kHorizontalPadding, OffsetY(this, icon_ps), icon_ps.width(), + icon_ps.height()); + + gfx::Size text_ps = label_->GetPreferredSize(); + int text_width = std::min( + text_ps.width(), + GetAvailableWidth() - icon_->bounds().right() - kIconLabelSpacing); + label_->SetBounds(icon_->bounds().right() + kIconLabelSpacing, + OffsetY(this, text_ps), text_width, text_ps.height()); +} + +// ConfirmInfoBarDelegate, InfoBarDelegate overrides: -------------------------- + +InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() { + return new ConfirmInfoBar(this); +} + +// ConfirmInfoBar, public: ----------------------------------------------------- + +ConfirmInfoBar::ConfirmInfoBar(ConfirmInfoBarDelegate* delegate) + : AlertInfoBar(delegate), + ok_button_(NULL), + cancel_button_(NULL), + link_(NULL), + initialized_(false) { + ok_button_ = InfoBarTextButton::Create(this, + (delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_OK) ? + delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK) : + string16()); + ok_button_->SetAccessibleName(WideToUTF16Hack(ok_button_->text())); + cancel_button_ = InfoBarTextButton::Create(this, + (delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_CANCEL) ? + delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL) : + string16()); + cancel_button_->SetAccessibleName(WideToUTF16Hack(cancel_button_->text())); + + // Set up the link. + link_ = new views::Link; + link_->SetText(UTF16ToWideHack(delegate->GetLinkText())); + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + link_->SetFont(rb.GetFont(ResourceBundle::MediumFont)); + link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); + link_->SetController(this); + link_->MakeReadableOverBackgroundColor(background()->get_color()); +} + +ConfirmInfoBar::~ConfirmInfoBar() { + if (!initialized_) { + delete ok_button_; + delete cancel_button_; + delete link_; + } +} + +// ConfirmInfoBar, views::LinkController implementation: ----------------------- + +void ConfirmInfoBar::LinkActivated(views::Link* source, int event_flags) { + DCHECK(source == link_); + DCHECK(link_->IsVisible()); + DCHECK(!link_->GetText().empty()); + if (GetDelegate()->LinkClicked( + event_utils::DispositionFromEventFlags(event_flags))) { + RemoveInfoBar(); + } +} + +// ConfirmInfoBar, views::View overrides: -------------------------------------- + +void ConfirmInfoBar::Layout() { + // First layout right aligned items (from right to left) in order to determine + // the space avalable, then layout the left aligned items. + + // Layout the close button. + InfoBarView::Layout(); + + // Layout the cancel and OK buttons. + int available_width = AlertInfoBar::GetAvailableWidth(); + int ok_button_width = 0; + int cancel_button_width = 0; + gfx::Size ok_ps = ok_button_->GetPreferredSize(); + gfx::Size cancel_ps = cancel_button_->GetPreferredSize(); + + if (GetDelegate()->GetButtons() & ConfirmInfoBarDelegate::BUTTON_OK) { + ok_button_width = ok_ps.width(); + } else { + ok_button_->SetVisible(false); + } + if (GetDelegate()->GetButtons() & ConfirmInfoBarDelegate::BUTTON_CANCEL) { + cancel_button_width = cancel_ps.width(); + } else { + cancel_button_->SetVisible(false); + } + + cancel_button_->SetBounds(available_width - cancel_button_width, + OffsetY(this, cancel_ps), cancel_ps.width(), + cancel_ps.height()); + int spacing = cancel_button_width > 0 ? kButtonButtonSpacing : 0; + ok_button_->SetBounds(cancel_button_->x() - spacing - ok_button_width, + OffsetY(this, ok_ps), ok_ps.width(), ok_ps.height()); + + // Layout the icon and label. + AlertInfoBar::Layout(); + + // Now append the link to the label's right edge. + link_->SetVisible(!link_->GetText().empty()); + gfx::Size link_ps = link_->GetPreferredSize(); + int link_x = label()->bounds().right() + kEndOfLabelSpacing; + int link_w = std::min(GetAvailableWidth() - link_x, link_ps.width()); + link_->SetBounds(link_x, OffsetY(this, link_ps), link_w, link_ps.height()); +} + +void ConfirmInfoBar::ViewHierarchyChanged(bool is_add, + views::View* parent, + views::View* child) { + if (is_add && child == this && !initialized_) { + Init(); + initialized_ = true; + } + InfoBarView::ViewHierarchyChanged(is_add, parent, child); +} + +// ConfirmInfoBar, views::ButtonListener implementation: --------------- + +void ConfirmInfoBar::ButtonPressed( + views::Button* sender, const views::Event& event) { + InfoBarView::ButtonPressed(sender, event); + if (sender == ok_button_) { + if (GetDelegate()->Accept()) + RemoveInfoBar(); + } else if (sender == cancel_button_) { + if (GetDelegate()->Cancel()) + RemoveInfoBar(); + } +} + +// ConfirmInfoBar, InfoBar overrides: ------------------------------------------ + +int ConfirmInfoBar::GetAvailableWidth() const { + return ok_button_->x() - kEndOfLabelSpacing; +} + +// ConfirmInfoBar, private: ---------------------------------------------------- + +ConfirmInfoBarDelegate* ConfirmInfoBar::GetDelegate() { + return delegate()->AsConfirmInfoBarDelegate(); +} + +void ConfirmInfoBar::Init() { + AddChildView(ok_button_); + AddChildView(cancel_button_); + AddChildView(link_); +} diff --git a/chrome/browser/ui/views/infobars/confirm_infobar.h b/chrome/browser/ui/views/infobars/confirm_infobar.h new file mode 100644 index 0000000..de9afb2 --- /dev/null +++ b/chrome/browser/ui/views/infobars/confirm_infobar.h @@ -0,0 +1,82 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_UI_VIEWS_INFOBARS_CONFIRM_INFOBAR_H_ +#define CHROME_BROWSER_UI_VIEWS_INFOBARS_CONFIRM_INFOBAR_H_ +#pragma once + +#include "chrome/browser/ui/views/infobars/infobar_view.h" +#include "views/controls/link.h" + +class ConfirmInfoBarDelegate; +class InfoBarTextButton; + +namespace views { +class Label; +} + +// TODO(pkasting): This class will die soon. +class AlertInfoBar : public InfoBarView { + public: + explicit AlertInfoBar(ConfirmInfoBarDelegate* delegate); + virtual ~AlertInfoBar(); + + // Overridden from views::View: + virtual void Layout(); + + protected: + views::Label* label() const { return label_; } + views::ImageView* icon() const { return icon_; } + + private: + views::Label* label_; + views::ImageView* icon_; + + DISALLOW_COPY_AND_ASSIGN(AlertInfoBar); +}; + +// An infobar that shows a message, up to two optional buttons, and an optional, +// right-aligned link. This is commonly used to do things like: +// "Would you like to do X? [Yes] [No] _Learn More_ [x]" +// TODO(pkasting): The above layout is the desired, but not current, layout; fix +// coming in a future patch. +class ConfirmInfoBar : public AlertInfoBar, + public views::LinkController { + public: + explicit ConfirmInfoBar(ConfirmInfoBarDelegate* delegate); + virtual ~ConfirmInfoBar(); + + // Overridden from views::LinkController: + virtual void LinkActivated(views::Link* source, int event_flags); + + // Overridden from views::View: + virtual void Layout(); + + protected: + // Overridden from views::View: + virtual void ViewHierarchyChanged(bool is_add, + views::View* parent, + views::View* child); + + // Overridden from views::ButtonListener: + virtual void ButtonPressed(views::Button* sender, const views::Event& event); + + // Overridden from InfoBar: + virtual int GetAvailableWidth() const; + + private: + void Init(); + + ConfirmInfoBarDelegate* GetDelegate(); + + InfoBarTextButton* ok_button_; + InfoBarTextButton* cancel_button_; + views::Link* link_; + + bool initialized_; + + DISALLOW_COPY_AND_ASSIGN(ConfirmInfoBar); +}; + +#endif // CHROME_BROWSER_UI_VIEWS_INFOBARS_CONFIRM_INFOBAR_H_ diff --git a/chrome/browser/ui/views/infobars/extension_infobar.cc b/chrome/browser/ui/views/infobars/extension_infobar.cc index b314603..5b95e4b 100644 --- a/chrome/browser/ui/views/infobars/extension_infobar.cc +++ b/chrome/browser/ui/views/infobars/extension_infobar.cc @@ -31,7 +31,7 @@ static const int kFarRightMargin = 30; static const int kDropArrowLeftMargin = 3; ExtensionInfoBar::ExtensionInfoBar(ExtensionInfoBarDelegate* delegate) - : InfoBar(delegate), + : InfoBarView(delegate), delegate_(delegate), ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) { delegate_->set_observer(this); @@ -80,7 +80,7 @@ void ExtensionInfoBar::OnExtensionPreferredSizeChanged(ExtensionView* view) { gfx::Size sz = view->GetPreferredSize(); // Clamp height to a min and a max size of between 1 and 2 InfoBars. - int default_height = static_cast<int>(InfoBar::kDefaultTargetHeight); + int default_height = static_cast<int>(InfoBarView::kDefaultTargetHeight); sz.set_height(std::max(default_height, sz.height())); sz.set_height(std::min(2 * default_height, sz.height())); @@ -92,7 +92,7 @@ void ExtensionInfoBar::OnExtensionPreferredSizeChanged(ExtensionView* view) { void ExtensionInfoBar::Layout() { // Layout the close button and the background. - InfoBar::Layout(); + InfoBarView::Layout(); // Layout the extension icon + drop down menu. int x = 0; diff --git a/chrome/browser/ui/views/infobars/extension_infobar.h b/chrome/browser/ui/views/infobars/extension_infobar.h index 9a0b7b9..aaa2729 100644 --- a/chrome/browser/ui/views/infobars/extension_infobar.h +++ b/chrome/browser/ui/views/infobars/extension_infobar.h @@ -6,7 +6,7 @@ #define CHROME_BROWSER_UI_VIEWS_INFOBARS_EXTENSION_INFOBAR_H_ #pragma once -#include "chrome/browser/ui/views/infobars/infobars.h" +#include "chrome/browser/ui/views/infobars/infobar_view.h" #include "chrome/browser/extensions/extension_infobar_delegate.h" #include "chrome/browser/extensions/image_loading_tracker.h" @@ -22,7 +22,7 @@ namespace views { } // This class implements InfoBars for Extensions. -class ExtensionInfoBar : public InfoBar, +class ExtensionInfoBar : public InfoBarView, public ExtensionView::Container, public ImageLoadingTracker::Observer, public ExtensionInfoBarDelegate::DelegateObserver, diff --git a/chrome/browser/ui/views/infobars/infobar_background.cc b/chrome/browser/ui/views/infobars/infobar_background.cc new file mode 100644 index 0000000..63360dd --- /dev/null +++ b/chrome/browser/ui/views/infobars/infobar_background.cc @@ -0,0 +1,55 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/ui/views/infobars/infobar_background.h" + +#include "gfx/canvas.h" +#include "ui/base/resource/resource_bundle.h" +#include "views/view.h" + +static const SkColor kWarningBackgroundColorTop = SkColorSetRGB(255, 242, 183); +static const SkColor kWarningBackgroundColorBottom = + SkColorSetRGB(250, 230, 145); + +static const SkColor kPageActionBackgroundColorTop = + SkColorSetRGB(218, 231, 249); +static const SkColor kPageActionBackgroundColorBottom = + SkColorSetRGB(179, 202, 231); + +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)); +} + +// InfoBarBackground, views::Background overrides: ----------------------------- + +void InfoBarBackground::Paint(gfx::Canvas* canvas, views::View* view) const { + // First paint the gradient background. + gradient_background_->Paint(canvas, view); + + // Now paint the separator line. + canvas->FillRectInt(ResourceBundle::toolbar_separator_color, 0, + view->height() - kSeparatorLineHeight, view->width(), + kSeparatorLineHeight); +} diff --git a/chrome/browser/ui/views/infobars/infobar_background.h b/chrome/browser/ui/views/infobars/infobar_background.h new file mode 100644 index 0000000..234ca1f --- /dev/null +++ b/chrome/browser/ui/views/infobars/infobar_background.h @@ -0,0 +1,26 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_BACKGROUND_H_ +#define CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_BACKGROUND_H_ +#pragma once + +#include "base/scoped_ptr.h" +#include "chrome/browser/tab_contents/infobar_delegate.h" +#include "views/background.h" + +class InfoBarBackground : public views::Background { + public: + explicit InfoBarBackground(InfoBarDelegate::Type infobar_type); + + // Overridden from views::Background: + virtual void Paint(gfx::Canvas* canvas, views::View* view) const; + + private: + scoped_ptr<views::Background> gradient_background_; + + DISALLOW_COPY_AND_ASSIGN(InfoBarBackground); +}; + +#endif // CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_BACKGROUND_H_ diff --git a/chrome/browser/ui/views/infobars/infobar_container.cc b/chrome/browser/ui/views/infobars/infobar_container.cc index e4f1445..e5fa743 100644 --- a/chrome/browser/ui/views/infobars/infobar_container.cc +++ b/chrome/browser/ui/views/infobars/infobar_container.cc @@ -8,7 +8,7 @@ #include "chrome/browser/tab_contents/infobar_delegate.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/ui/view_ids.h" -#include "chrome/browser/ui/views/infobars/infobars.h" +#include "chrome/browser/ui/views/infobars/infobar_view.h" #include "chrome/common/notification_details.h" #include "chrome/common/notification_source.h" #include "grit/generated_resources.h" @@ -35,7 +35,7 @@ InfoBarContainer::~InfoBarContainer() { void InfoBarContainer::ChangeTabContents(TabContents* contents) { registrar_.RemoveAll(); // No need to delete the child views here, their removal from the view - // hierarchy does this automatically (see InfoBar::InfoBarRemoved). + // hierarchy does this automatically (see InfoBarView::InfoBarRemoved). RemoveAllChildViews(false); tab_contents_ = contents; if (tab_contents_) { @@ -120,7 +120,7 @@ void InfoBarContainer::Observe(NotificationType type, void InfoBarContainer::UpdateInfoBars() { for (int i = 0; i < tab_contents_->infobar_delegate_count(); ++i) { InfoBarDelegate* delegate = tab_contents_->GetInfoBarDelegateAt(i); - InfoBar* infobar = delegate->CreateInfoBar(); + InfoBarView* infobar = static_cast<InfoBarView*>(delegate->CreateInfoBar()); infobar->set_container(this); AddChildView(infobar); infobar->Open(); @@ -129,7 +129,7 @@ void InfoBarContainer::UpdateInfoBars() { void InfoBarContainer::AddInfoBar(InfoBarDelegate* delegate, bool use_animation) { - InfoBar* infobar = delegate->CreateInfoBar(); + InfoBarView* infobar = static_cast<InfoBarView*>(delegate->CreateInfoBar()); infobar->set_container(this); AddChildView(infobar); @@ -147,7 +147,7 @@ void InfoBarContainer::RemoveInfoBar(InfoBarDelegate* delegate, // different number of infobars in container and infobar delegates in tab // contents. for (int i = 0; i < GetChildViewCount(); ++i) { - InfoBar* infobar = static_cast<InfoBar*>(GetChildViewAt(i)); + InfoBarView* infobar = static_cast<InfoBarView*>(GetChildViewAt(i)); if (infobar->delegate() == delegate) { if (use_animation) { // The View will be removed once the Close animation completes. diff --git a/chrome/browser/ui/views/infobars/infobar_view.cc b/chrome/browser/ui/views/infobars/infobar_view.cc new file mode 100644 index 0000000..a45021f --- /dev/null +++ b/chrome/browser/ui/views/infobars/infobar_view.cc @@ -0,0 +1,269 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/ui/views/infobars/infobar_view.h" + +#include "base/message_loop.h" +#include "base/utf_string_conversions.h" +#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 "grit/generated_resources.h" +#include "grit/theme_resources.h" +#include "ui/base/animation/slide_animation.h" +#include "ui/base/l10n/l10n_util.h" +#include "ui/base/resource/resource_bundle.h" +#include "views/controls/button/image_button.h" +#include "views/controls/image_view.h" +#include "views/controls/label.h" +#include "views/focus/external_focus_tracker.h" +#include "views/widget/widget.h" + +#if defined(OS_WIN) +#include "ui/base/win/hwnd_util.h" +#endif + +// static +const double InfoBarView::kDefaultTargetHeight = 36.0; +const int InfoBarView::kHorizontalPadding = 6; +const int InfoBarView::kIconLabelSpacing = 6; +const int InfoBarView::kButtonButtonSpacing = 10; +const int InfoBarView::kEndOfLabelSpacing = 16; +const int InfoBarView::kCloseButtonSpacing = 12; +const int InfoBarView::kButtonInLabelSpacing = 5; + +// InfoBarView, public: ------------------------------------------------------- + +InfoBarView::InfoBarView(InfoBarDelegate* delegate) + : InfoBar(delegate), + delegate_(delegate), + ALLOW_THIS_IN_INITIALIZER_LIST( + close_button_(new views::ImageButton(this))), + ALLOW_THIS_IN_INITIALIZER_LIST(delete_factory_(this)), + target_height_(kDefaultTargetHeight) { + // We delete ourselves when we're removed from the view hierarchy. + set_parent_owned(false); + + set_background(new InfoBarBackground(delegate->GetInfoBarType())); + + switch (delegate->GetInfoBarType()) { + case InfoBarDelegate::WARNING_TYPE: + SetAccessibleName( + l10n_util::GetStringUTF16(IDS_ACCNAME_INFOBAR_WARNING)); + break; + case InfoBarDelegate::PAGE_ACTION_TYPE: + SetAccessibleName( + l10n_util::GetStringUTF16(IDS_ACCNAME_INFOBAR_PAGE_ACTION)); + break; + default: + NOTREACHED(); + break; + } + + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + close_button_->SetImage(views::CustomButton::BS_NORMAL, + rb.GetBitmapNamed(IDR_CLOSE_BAR)); + close_button_->SetImage(views::CustomButton::BS_HOT, + rb.GetBitmapNamed(IDR_CLOSE_BAR_H)); + close_button_->SetImage(views::CustomButton::BS_PUSHED, + rb.GetBitmapNamed(IDR_CLOSE_BAR_P)); + close_button_->SetAccessibleName( + l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); + AddChildView(close_button_); + + animation_.reset(new ui::SlideAnimation(this)); + animation_->SetTweenType(ui::Tween::LINEAR); +} + +InfoBarView::~InfoBarView() { +} + +// InfoBarView, views::View overrides: ---------------------------------------- + +AccessibilityTypes::Role InfoBarView::GetAccessibleRole() { + return AccessibilityTypes::ROLE_ALERT; +} + +gfx::Size InfoBarView::GetPreferredSize() { + int height = static_cast<int>(target_height_ * animation_->GetCurrentValue()); + return gfx::Size(0, height); +} + +void InfoBarView::Layout() { + gfx::Size button_ps = close_button_->GetPreferredSize(); + close_button_->SetBounds(width() - kHorizontalPadding - button_ps.width(), + OffsetY(this, button_ps), button_ps.width(), + button_ps.height()); +} + +void InfoBarView::ViewHierarchyChanged(bool is_add, + views::View* parent, + views::View* child) { + if (child == this) { + if (is_add) { + InfoBarAdded(); + } else { + InfoBarRemoved(); + } + } + + if (GetWidget() && GetWidget()->IsAccessibleWidget()) { + // For accessibility, make the close button the last child view. + if (parent == this && child != close_button_ && + HasChildView(close_button_) && + GetChildViewAt(GetChildViewCount() - 1) != close_button_) { + RemoveChildView(close_button_); + AddChildView(close_button_); + } + + // Allow screen reader users to focus the close button. + close_button_->SetFocusable(true); + } +} + +// InfoBarView, protected: ---------------------------------------------------- + +int InfoBarView::GetAvailableWidth() const { + return close_button_->x() - kCloseButtonSpacing; +} + +void InfoBarView::RemoveInfoBar() const { + if (container_) + container_->RemoveDelegate(delegate()); +} + +int InfoBarView::CenterY(const gfx::Size prefsize) { + return std::max((static_cast<int>(target_height_) - + prefsize.height()) / 2, 0); +} + +int InfoBarView::OffsetY(views::View* parent, const gfx::Size prefsize) { + return CenterY(prefsize) - + (static_cast<int>(target_height_) - parent->height()); +} + +// InfoBarView, views::ButtonListener implementation: ------------------------- + +void InfoBarView::ButtonPressed(views::Button* sender, + const views::Event& event) { + if (sender == close_button_) { + if (delegate_) + delegate_->InfoBarDismissed(); + RemoveInfoBar(); + } +} + +// InfoBarView, views::FocusChangeListener implementation: -------------------- + +void InfoBarView::FocusWillChange(View* focused_before, View* focused_now) { + // This will trigger some screen readers to read the entire contents of this + // infobar. + if (focused_before && focused_now && + !this->IsParentOf(focused_before) && this->IsParentOf(focused_now)) { + NotifyAccessibilityEvent(AccessibilityTypes::EVENT_ALERT); + } +} + +// InfoBarView, ui::AnimationDelegate implementation: ------------------------- + +void InfoBarView::AnimationProgressed(const ui::Animation* animation) { + if (container_) + container_->InfoBarAnimated(true); +} + +void InfoBarView::AnimationEnded(const ui::Animation* animation) { + if (container_) { + container_->InfoBarAnimated(false); + + if (!animation_->IsShowing()) + Close(); + } +} + +// InfoBarView, private: ------------------------------------------------------ + +void InfoBarView::AnimateOpen() { + animation_->Show(); +} + +void InfoBarView::Open() { + // Set the animation value to 1.0 so that GetPreferredSize() returns the right + // size. + animation_->Reset(1.0); + if (container_) + container_->InfoBarAnimated(false); +} + +void InfoBarView::AnimateClose() { + bool restore_focus = true; +#if defined(OS_WIN) + // Do not restore focus (and active state with it) on Windows if some other + // top-level window became active. + if (GetWidget() && + !ui::DoesWindowBelongToActiveWindow(GetWidget()->GetNativeView())) { + restore_focus = false; + } +#endif // defined(OS_WIN) + DestroyFocusTracker(restore_focus); + animation_->Hide(); +} + +void InfoBarView::Close() { + GetParent()->RemoveChildView(this); + // Note that we only tell the delegate we're closed here, and not when we're + // simply destroyed (by virtue of a tab switch or being moved from window to + // window), since this action can cause the delegate to destroy itself. + if (delegate_) { + delegate_->InfoBarClosed(); + delegate_ = NULL; + } +} + +void InfoBarView::InfoBarAdded() { + // The container_ pointer must be set before adding to the view hierarchy. + DCHECK(container_); +#if defined(OS_WIN) + // When we're added to a view hierarchy within a widget, we create an + // external focus tracker to track what was focused in case we obtain + // focus so that we can restore focus when we're removed. + views::Widget* widget = GetWidget(); + if (widget) { + focus_tracker_.reset(new views::ExternalFocusTracker(this, + GetFocusManager())); + } +#endif + + if (GetFocusManager()) + GetFocusManager()->AddFocusChangeListener(this); + + NotifyAccessibilityEvent(AccessibilityTypes::EVENT_ALERT); +} + +void InfoBarView::InfoBarRemoved() { + DestroyFocusTracker(false); + // NULL our container_ pointer so that if Animation::Stop results in + // AnimationEnded being called, we do not try and delete ourselves twice. + container_ = NULL; + animation_->Stop(); + // Finally, clean ourselves up when we're removed from the view hierarchy + // since no-one refers to us now. + MessageLoop::current()->PostTask(FROM_HERE, + delete_factory_.NewRunnableMethod(&InfoBarView::DeleteSelf)); + + if (GetFocusManager()) + GetFocusManager()->RemoveFocusChangeListener(this); +} + +void InfoBarView::DestroyFocusTracker(bool restore_focus) { + if (focus_tracker_.get()) { + if (restore_focus) + focus_tracker_->FocusLastFocusedExternalView(); + focus_tracker_->SetFocusManager(NULL); + focus_tracker_.reset(NULL); + } +} + +void InfoBarView::DeleteSelf() { + delete this; +} diff --git a/chrome/browser/ui/views/infobars/infobars.h b/chrome/browser/ui/views/infobars/infobar_view.h index ba5967b..0710ad03 100644 --- a/chrome/browser/ui/views/infobars/infobars.h +++ b/chrome/browser/ui/views/infobars/infobar_view.h @@ -2,19 +2,17 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBARS_H_ -#define CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBARS_H_ +#ifndef CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_VIEW_H_ +#define CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_VIEW_H_ #pragma once #include "base/task.h" -#include "chrome/browser/tab_contents/infobar_delegate.h" #include "ui/base/animation/animation_delegate.h" #include "views/controls/button/button.h" -#include "views/controls/link.h" #include "views/focus/focus_manager.h" class InfoBarContainer; -class InfoBarTextButton; +class InfoBarDelegate; namespace ui { class SlideAnimation; @@ -27,30 +25,28 @@ class ImageView; class Label; } -// This file contains implementations for some general purpose InfoBars. See -// chrome/browser/tab_contents/infobar_delegate.h for the delegate interface(s) -// that you must implement to use these. - -class InfoBarBackground : public views::Background { +// TODO(pkasting): infobar_delegate.h forward declares "class InfoBar" but the +// definitions are (right now) completely port-specific. This stub class will +// be turned into the cross-platform base class for InfoBar views (in the MVC +// sense). Right now it's just here so the various InfoBarDelegates can +// continue to return an InfoBar*, it doesn't do anything. +class InfoBar { public: - explicit InfoBarBackground(InfoBarDelegate::Type infobar_type); - - // Overridden from views::Background: - virtual void Paint(gfx::Canvas* canvas, views::View* view) const; + explicit InfoBar(InfoBarDelegate* delegate) {} + virtual ~InfoBar() {} private: - scoped_ptr<views::Background> gradient_background_; - - DISALLOW_COPY_AND_ASSIGN(InfoBarBackground); + DISALLOW_COPY_AND_ASSIGN(InfoBar); }; -class InfoBar : public views::View, - public views::ButtonListener, - public views::FocusChangeListener, - public ui::AnimationDelegate { +class InfoBarView : public InfoBar, + public views::View, + public views::ButtonListener, + public views::FocusChangeListener, + public ui::AnimationDelegate { public: - explicit InfoBar(InfoBarDelegate* delegate); - virtual ~InfoBar(); + explicit InfoBarView(InfoBarDelegate* delegate); + virtual ~InfoBarView(); InfoBarDelegate* delegate() const { return delegate_; } @@ -161,93 +157,12 @@ class InfoBar : public views::View, scoped_ptr<views::ExternalFocusTracker> focus_tracker_; // Used to delete this object after a return to the message loop. - ScopedRunnableMethodFactory<InfoBar> delete_factory_; + ScopedRunnableMethodFactory<InfoBarView> delete_factory_; // The target height for the InfoBar. double target_height_; - DISALLOW_COPY_AND_ASSIGN(InfoBar); -}; - -class AlertInfoBar : public InfoBar { - public: - explicit AlertInfoBar(ConfirmInfoBarDelegate* delegate); - virtual ~AlertInfoBar(); - - // Overridden from views::View: - virtual void Layout(); - - protected: - views::Label* label() const { return label_; } - views::ImageView* icon() const { return icon_; } - - private: - views::Label* label_; - views::ImageView* icon_; - - 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::LinkController { - public: - explicit ConfirmInfoBar(ConfirmInfoBarDelegate* delegate); - virtual ~ConfirmInfoBar(); - - // Overridden from views::LinkController: - virtual void LinkActivated(views::Link* source, int event_flags); - - // Overridden from views::View: - virtual void Layout(); - - protected: - // Overridden from views::View: - virtual void ViewHierarchyChanged(bool is_add, - views::View* parent, - views::View* child); - - // Overridden from views::ButtonListener: - virtual void ButtonPressed(views::Button* sender, const views::Event& event); - - // Overridden from InfoBar: - virtual int GetAvailableWidth() const; - - private: - void Init(); - - ConfirmInfoBarDelegate* GetDelegate(); - - InfoBarTextButton* ok_button_; - InfoBarTextButton* cancel_button_; - views::Link* link_; - - bool initialized_; - - DISALLOW_COPY_AND_ASSIGN(ConfirmInfoBar); + DISALLOW_COPY_AND_ASSIGN(InfoBarView); }; - -#endif // CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBARS_H_ +#endif // CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_VIEW_H_ diff --git a/chrome/browser/ui/views/infobars/infobars.cc b/chrome/browser/ui/views/infobars/infobars.cc deleted file mode 100644 index 8129c273..0000000 --- a/chrome/browser/ui/views/infobars/infobars.cc +++ /dev/null @@ -1,605 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/views/infobars/infobars.h" - -#include "base/message_loop.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/ui/views/event_utils.h" -#include "chrome/browser/ui/views/infobars/infobar_container.h" -#include "chrome/browser/ui/views/infobars/infobar_text_button.h" -#include "gfx/canvas.h" -#include "grit/generated_resources.h" -#include "grit/theme_resources.h" -#include "ui/base/animation/slide_animation.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" -#include "views/background.h" -#include "views/controls/button/image_button.h" -#include "views/controls/button/native_button.h" -#include "views/controls/image_view.h" -#include "views/controls/label.h" -#include "views/focus/external_focus_tracker.h" -#include "views/widget/widget.h" - -#if defined(OS_WIN) -#include "ui/base/win/hwnd_util.h" -#endif - -// static -const double InfoBar::kDefaultTargetHeight = 36.0; -const int InfoBar::kHorizontalPadding = 6; -const int InfoBar::kIconLabelSpacing = 6; -const int InfoBar::kButtonButtonSpacing = 10; -const int InfoBar::kEndOfLabelSpacing = 16; -const int InfoBar::kCloseButtonSpacing = 12; -const int InfoBar::kButtonInLabelSpacing = 5; - -static const SkColor kWarningBackgroundColorTop = SkColorSetRGB(255, 242, 183); -static const SkColor kWarningBackgroundColorBottom = - SkColorSetRGB(250, 230, 145); - -static const SkColor kPageActionBackgroundColorTop = - SkColorSetRGB(218, 231, 249); -static const SkColor kPageActionBackgroundColorBottom = - SkColorSetRGB(179, 202, 231); - -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)); -} - -// InfoBarBackground, views::Background overrides: ----------------------------- - -void InfoBarBackground::Paint(gfx::Canvas* canvas, views::View* view) const { - // First paint the gradient background. - gradient_background_->Paint(canvas, view); - - // Now paint the separator line. - canvas->FillRectInt(ResourceBundle::toolbar_separator_color, 0, - view->height() - kSeparatorLineHeight, view->width(), - kSeparatorLineHeight); -} - -// InfoBar, public: ------------------------------------------------------------ - -InfoBar::InfoBar(InfoBarDelegate* delegate) - : delegate_(delegate), - ALLOW_THIS_IN_INITIALIZER_LIST( - close_button_(new views::ImageButton(this))), - ALLOW_THIS_IN_INITIALIZER_LIST(delete_factory_(this)), - target_height_(kDefaultTargetHeight) { - // We delete ourselves when we're removed from the view hierarchy. - set_parent_owned(false); - - set_background(new InfoBarBackground(delegate->GetInfoBarType())); - - switch (delegate->GetInfoBarType()) { - case InfoBarDelegate::WARNING_TYPE: - SetAccessibleName( - l10n_util::GetStringUTF16(IDS_ACCNAME_INFOBAR_WARNING)); - break; - case InfoBarDelegate::PAGE_ACTION_TYPE: - SetAccessibleName( - l10n_util::GetStringUTF16(IDS_ACCNAME_INFOBAR_PAGE_ACTION)); - break; - default: - NOTREACHED(); - break; - } - - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - close_button_->SetImage(views::CustomButton::BS_NORMAL, - rb.GetBitmapNamed(IDR_CLOSE_BAR)); - close_button_->SetImage(views::CustomButton::BS_HOT, - rb.GetBitmapNamed(IDR_CLOSE_BAR_H)); - close_button_->SetImage(views::CustomButton::BS_PUSHED, - rb.GetBitmapNamed(IDR_CLOSE_BAR_P)); - close_button_->SetAccessibleName( - l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); - AddChildView(close_button_); - - animation_.reset(new ui::SlideAnimation(this)); - animation_->SetTweenType(ui::Tween::LINEAR); -} - -InfoBar::~InfoBar() { -} - -// InfoBar, views::View overrides: --------------------------------------------- - -AccessibilityTypes::Role InfoBar::GetAccessibleRole() { - return AccessibilityTypes::ROLE_ALERT; -} - -gfx::Size InfoBar::GetPreferredSize() { - int height = static_cast<int>(target_height_ * 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(), - OffsetY(this, button_ps), button_ps.width(), - button_ps.height()); -} - -void InfoBar::ViewHierarchyChanged(bool is_add, views::View* parent, - views::View* child) { - if (child == this) { - if (is_add) { - InfoBarAdded(); - } else { - InfoBarRemoved(); - } - } - - if (GetWidget() && GetWidget()->IsAccessibleWidget()) { - // For accessibility, make the close button the last child view. - if (parent == this && child != close_button_ && - HasChildView(close_button_) && - GetChildViewAt(GetChildViewCount() - 1) != close_button_) { - RemoveChildView(close_button_); - AddChildView(close_button_); - } - - // Allow screen reader users to focus the close button. - close_button_->SetFocusable(true); - } -} - -// InfoBar, protected: --------------------------------------------------------- - -int InfoBar::GetAvailableWidth() const { - return close_button_->x() - kCloseButtonSpacing; -} - -void InfoBar::RemoveInfoBar() const { - if (container_) - container_->RemoveDelegate(delegate()); -} - -int InfoBar::CenterY(const gfx::Size prefsize) { - return std::max((static_cast<int>(target_height_) - - prefsize.height()) / 2, 0); -} - -int InfoBar::OffsetY(views::View* parent, const gfx::Size prefsize) { - return CenterY(prefsize) - - (static_cast<int>(target_height_) - parent->height()); -} - -// InfoBar, views::ButtonListener implementation: ------------------ - -void InfoBar::ButtonPressed(views::Button* sender, const views::Event& event) { - if (sender == close_button_) { - if (delegate_) - delegate_->InfoBarDismissed(); - RemoveInfoBar(); - } -} - -// InfoBar, views::FocusChangeListener implementation: ------------------ - -void InfoBar::FocusWillChange(View* focused_before, View* focused_now) { - // This will trigger some screen readers to read the entire contents of this - // infobar. - if (focused_before && focused_now && - !this->IsParentOf(focused_before) && this->IsParentOf(focused_now)) { - NotifyAccessibilityEvent(AccessibilityTypes::EVENT_ALERT); - } -} - -// InfoBar, ui::AnimationDelegate implementation: ------------------------------ - -void InfoBar::AnimationProgressed(const ui::Animation* animation) { - if (container_) - container_->InfoBarAnimated(true); -} - -void InfoBar::AnimationEnded(const ui::Animation* animation) { - if (container_) { - container_->InfoBarAnimated(false); - - if (!animation_->IsShowing()) - Close(); - } -} - -// InfoBar, private: ----------------------------------------------------------- - -void InfoBar::AnimateOpen() { - animation_->Show(); -} - -void InfoBar::Open() { - // Set the animation value to 1.0 so that GetPreferredSize() returns the right - // size. - animation_->Reset(1.0); - if (container_) - container_->InfoBarAnimated(false); -} - -void InfoBar::AnimateClose() { - bool restore_focus = true; -#if defined(OS_WIN) - // Do not restore focus (and active state with it) on Windows if some other - // top-level window became active. - if (GetWidget() && - !ui::DoesWindowBelongToActiveWindow(GetWidget()->GetNativeView())) { - restore_focus = false; - } -#endif // defined(OS_WIN) - DestroyFocusTracker(restore_focus); - animation_->Hide(); -} - -void InfoBar::Close() { - GetParent()->RemoveChildView(this); - // Note that we only tell the delegate we're closed here, and not when we're - // simply destroyed (by virtue of a tab switch or being moved from window to - // window), since this action can cause the delegate to destroy itself. - if (delegate_) { - delegate_->InfoBarClosed(); - delegate_ = NULL; - } -} - -void InfoBar::InfoBarAdded() { - // The container_ pointer must be set before adding to the view hierarchy. - DCHECK(container_); -#if defined(OS_WIN) - // When we're added to a view hierarchy within a widget, we create an - // external focus tracker to track what was focused in case we obtain - // focus so that we can restore focus when we're removed. - views::Widget* widget = GetWidget(); - if (widget) { - focus_tracker_.reset(new views::ExternalFocusTracker(this, - GetFocusManager())); - } -#endif - - if (GetFocusManager()) - GetFocusManager()->AddFocusChangeListener(this); - - NotifyAccessibilityEvent(AccessibilityTypes::EVENT_ALERT); -} - -void InfoBar::InfoBarRemoved() { - DestroyFocusTracker(false); - // NULL our container_ pointer so that if Animation::Stop results in - // AnimationEnded being called, we do not try and delete ourselves twice. - container_ = NULL; - animation_->Stop(); - // Finally, clean ourselves up when we're removed from the view hierarchy - // since no-one refers to us now. - MessageLoop::current()->PostTask(FROM_HERE, - delete_factory_.NewRunnableMethod(&InfoBar::DeleteSelf)); - - if (GetFocusManager()) - GetFocusManager()->RemoveFocusChangeListener(this); -} - -void InfoBar::DestroyFocusTracker(bool restore_focus) { - if (focus_tracker_.get()) { - if (restore_focus) - focus_tracker_->FocusLastFocusedExternalView(); - focus_tracker_->SetFocusManager(NULL); - focus_tracker_.reset(NULL); - } -} - -void InfoBar::DeleteSelf() { - delete this; -} - -// AlertInfoBar, public: ------------------------------------------------------- - -AlertInfoBar::AlertInfoBar(ConfirmInfoBarDelegate* delegate) - : InfoBar(delegate) { - label_ = new views::Label( - UTF16ToWideHack(delegate->GetMessageText()), - ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont)); - label_->SetColor(SK_ColorBLACK); - label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - AddChildView(label_); - - icon_ = new views::ImageView; - if (delegate->GetIcon()) - icon_->SetImage(delegate->GetIcon()); - AddChildView(icon_); -} - -AlertInfoBar::~AlertInfoBar() { -} - -// AlertInfoBar, views::View overrides: ---------------------------------------- - -void AlertInfoBar::Layout() { - // Layout the close button. - InfoBar::Layout(); - - // Layout the icon and text. - gfx::Size icon_ps = icon_->GetPreferredSize(); - icon_->SetBounds(kHorizontalPadding, OffsetY(this, icon_ps), icon_ps.width(), - icon_ps.height()); - - gfx::Size text_ps = label_->GetPreferredSize(); - int text_width = std::min( - text_ps.width(), - GetAvailableWidth() - icon_->bounds().right() - kIconLabelSpacing); - label_->SetBounds(icon_->bounds().right() + kIconLabelSpacing, - OffsetY(this, text_ps), text_width, text_ps.height()); -} - -// LinkInfoBar, public: -------------------------------------------------------- - -LinkInfoBar::LinkInfoBar(LinkInfoBarDelegate* delegate) - : InfoBar(delegate), - icon_(new views::ImageView), - label_1_(new views::Label), - label_2_(new views::Label), - link_(new views::Link) { - // Set up the icon. - if (delegate->GetIcon()) - icon_->SetImage(delegate->GetIcon()); - AddChildView(icon_); - - // Set up the labels. - size_t offset; - string16 message_text = delegate->GetMessageTextWithOffset(&offset); - if (offset != string16::npos) { - label_1_->SetText(UTF16ToWideHack(message_text.substr(0, offset))); - label_2_->SetText(UTF16ToWideHack(message_text.substr(offset))); - } else { - label_1_->SetText(UTF16ToWideHack(message_text)); - } - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - label_1_->SetFont(rb.GetFont(ResourceBundle::MediumFont)); - label_2_->SetFont(rb.GetFont(ResourceBundle::MediumFont)); - label_1_->SetColor(SK_ColorBLACK); - label_2_->SetColor(SK_ColorBLACK); - 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(UTF16ToWideHack(delegate->GetLinkText())); - link_->SetFont(rb.GetFont(ResourceBundle::MediumFont)); - link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - link_->SetController(this); - link_->MakeReadableOverBackgroundColor(background()->get_color()); - 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(), - 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(), - 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) - : AlertInfoBar(delegate), - ok_button_(NULL), - cancel_button_(NULL), - link_(NULL), - initialized_(false) { - ok_button_ = InfoBarTextButton::Create(this, - (delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_OK) ? - delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK) : - string16()); - ok_button_->SetAccessibleName(WideToUTF16Hack(ok_button_->text())); - cancel_button_ = InfoBarTextButton::Create(this, - (delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_CANCEL) ? - delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL) : - string16()); - cancel_button_->SetAccessibleName(WideToUTF16Hack(cancel_button_->text())); - - // Set up the link. - link_ = new views::Link; - link_->SetText(UTF16ToWideHack(delegate->GetLinkText())); - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - link_->SetFont(rb.GetFont(ResourceBundle::MediumFont)); - link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - link_->SetController(this); - link_->MakeReadableOverBackgroundColor(background()->get_color()); -} - -ConfirmInfoBar::~ConfirmInfoBar() { - if (!initialized_) { - delete ok_button_; - delete cancel_button_; - delete link_; - } -} - -// ConfirmInfoBar, views::LinkController implementation: ----------------------- - -void ConfirmInfoBar::LinkActivated(views::Link* source, int event_flags) { - DCHECK(source == link_); - DCHECK(link_->IsVisible()); - DCHECK(!link_->GetText().empty()); - if (GetDelegate()->LinkClicked( - event_utils::DispositionFromEventFlags(event_flags))) { - RemoveInfoBar(); - } -} - -// ConfirmInfoBar, views::View overrides: -------------------------------------- - -void ConfirmInfoBar::Layout() { - // First layout right aligned items (from right to left) in order to determine - // the space avalable, then layout the left aligned items. - - // Layout the close button. - InfoBar::Layout(); - - // Layout the cancel and OK buttons. - int available_width = AlertInfoBar::GetAvailableWidth(); - int ok_button_width = 0; - int cancel_button_width = 0; - gfx::Size ok_ps = ok_button_->GetPreferredSize(); - gfx::Size cancel_ps = cancel_button_->GetPreferredSize(); - - if (GetDelegate()->GetButtons() & ConfirmInfoBarDelegate::BUTTON_OK) { - ok_button_width = ok_ps.width(); - } else { - ok_button_->SetVisible(false); - } - if (GetDelegate()->GetButtons() & ConfirmInfoBarDelegate::BUTTON_CANCEL) { - cancel_button_width = cancel_ps.width(); - } else { - cancel_button_->SetVisible(false); - } - - cancel_button_->SetBounds(available_width - cancel_button_width, - OffsetY(this, cancel_ps), cancel_ps.width(), - cancel_ps.height()); - int spacing = cancel_button_width > 0 ? kButtonButtonSpacing : 0; - ok_button_->SetBounds(cancel_button_->x() - spacing - ok_button_width, - OffsetY(this, ok_ps), ok_ps.width(), ok_ps.height()); - - // Layout the icon and label. - AlertInfoBar::Layout(); - - // Now append the link to the label's right edge. - link_->SetVisible(!link_->GetText().empty()); - gfx::Size link_ps = link_->GetPreferredSize(); - int link_x = label()->bounds().right() + kEndOfLabelSpacing; - int link_w = std::min(GetAvailableWidth() - link_x, link_ps.width()); - link_->SetBounds(link_x, OffsetY(this, link_ps), link_w, link_ps.height()); -} - -void ConfirmInfoBar::ViewHierarchyChanged(bool is_add, - views::View* parent, - views::View* child) { - if (is_add && child == this && !initialized_) { - Init(); - initialized_ = true; - } - InfoBar::ViewHierarchyChanged(is_add, parent, child); -} - -// ConfirmInfoBar, views::ButtonListener implementation: --------------- - -void ConfirmInfoBar::ButtonPressed( - views::Button* sender, const views::Event& event) { - InfoBar::ButtonPressed(sender, event); - if (sender == ok_button_) { - if (GetDelegate()->Accept()) - RemoveInfoBar(); - } else if (sender == cancel_button_) { - if (GetDelegate()->Cancel()) - RemoveInfoBar(); - } -} - -// ConfirmInfoBar, InfoBar overrides: ------------------------------------------ - -int ConfirmInfoBar::GetAvailableWidth() const { - return ok_button_->x() - kEndOfLabelSpacing; -} - -// ConfirmInfoBar, private: ---------------------------------------------------- - -ConfirmInfoBarDelegate* ConfirmInfoBar::GetDelegate() { - return delegate()->AsConfirmInfoBarDelegate(); -} - -void ConfirmInfoBar::Init() { - AddChildView(ok_button_); - AddChildView(cancel_button_); - AddChildView(link_); -} - -// LinkInfoBarDelegate, InfoBarDelegate overrides: ----------------------------- - -InfoBar* LinkInfoBarDelegate::CreateInfoBar() { - return new LinkInfoBar(this); -} - -// ConfirmInfoBarDelegate, InfoBarDelegate overrides: -------------------------- - -InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() { - return new ConfirmInfoBar(this); -} diff --git a/chrome/browser/ui/views/infobars/link_infobar.cc b/chrome/browser/ui/views/infobars/link_infobar.cc new file mode 100644 index 0000000..973b977 --- /dev/null +++ b/chrome/browser/ui/views/infobars/link_infobar.cc @@ -0,0 +1,120 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/ui/views/infobars/link_infobar.h" + +#include "base/utf_string_conversions.h" +#include "chrome/browser/tab_contents/infobar_delegate.h" +#include "chrome/browser/ui/views/event_utils.h" +#include "ui/base/resource/resource_bundle.h" +#include "views/controls/image_view.h" + +// LinkInfoBarDelegate, InfoBarDelegate overrides: ----------------------------- + +InfoBar* LinkInfoBarDelegate::CreateInfoBar() { + return new LinkInfoBar(this); +} + +// LinkInfoBar, public: -------------------------------------------------------- + +LinkInfoBar::LinkInfoBar(LinkInfoBarDelegate* delegate) + : InfoBarView(delegate), + icon_(new views::ImageView), + label_1_(new views::Label), + label_2_(new views::Label), + link_(new views::Link) { + // Set up the icon. + if (delegate->GetIcon()) + icon_->SetImage(delegate->GetIcon()); + AddChildView(icon_); + + // Set up the labels. + size_t offset; + string16 message_text = delegate->GetMessageTextWithOffset(&offset); + if (offset != string16::npos) { + label_1_->SetText(UTF16ToWideHack(message_text.substr(0, offset))); + label_2_->SetText(UTF16ToWideHack(message_text.substr(offset))); + } else { + label_1_->SetText(UTF16ToWideHack(message_text)); + } + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + label_1_->SetFont(rb.GetFont(ResourceBundle::MediumFont)); + label_2_->SetFont(rb.GetFont(ResourceBundle::MediumFont)); + label_1_->SetColor(SK_ColorBLACK); + label_2_->SetColor(SK_ColorBLACK); + 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(UTF16ToWideHack(delegate->GetLinkText())); + link_->SetFont(rb.GetFont(ResourceBundle::MediumFont)); + link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); + link_->SetController(this); + link_->MakeReadableOverBackgroundColor(background()->get_color()); + 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. + InfoBarView::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(), + 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(), + OffsetY(this, label_2_ps), label_2_ps.width(), + label_2_ps.height()); +} + +// LinkInfoBar, private: ------------------------------------------------------- + +LinkInfoBarDelegate* LinkInfoBar::GetDelegate() { + return delegate()->AsLinkInfoBarDelegate(); +} diff --git a/chrome/browser/ui/views/infobars/link_infobar.h b/chrome/browser/ui/views/infobars/link_infobar.h new file mode 100644 index 0000000..1ca6bb7 --- /dev/null +++ b/chrome/browser/ui/views/infobars/link_infobar.h @@ -0,0 +1,38 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_UI_VIEWS_INFOBARS_LINK_INFOBAR_H_ +#define CHROME_BROWSER_UI_VIEWS_INFOBARS_LINK_INFOBAR_H_ +#pragma once + +#include "chrome/browser/ui/views/infobars/infobar_view.h" +#include "views/controls/link.h" + +class LinkInfoBarDelegate; + +// An infobar that shows a string with an embedded link. +class LinkInfoBar : public InfoBarView, + 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); +}; + +#endif // CHROME_BROWSER_UI_VIEWS_INFOBARS_LINK_INFOBAR_H_ diff --git a/chrome/browser/ui/views/infobars/translate_infobar_base.cc b/chrome/browser/ui/views/infobars/translate_infobar_base.cc index 897699f..696e623 100644 --- a/chrome/browser/ui/views/infobars/translate_infobar_base.cc +++ b/chrome/browser/ui/views/infobars/translate_infobar_base.cc @@ -19,7 +19,7 @@ TranslateInfoBarBase::TranslateInfoBarBase( TranslateInfoBarDelegate* delegate) - : InfoBar(delegate), + : InfoBarView(delegate), normal_background_(InfoBarDelegate::PAGE_ACTION_TYPE), error_background_(InfoBarDelegate::WARNING_TYPE) { icon_ = new views::ImageView; @@ -51,12 +51,12 @@ TranslateInfoBarBase::~TranslateInfoBarBase() { // Overridden from views::View: void TranslateInfoBarBase::Layout() { // Layout the close button. - InfoBar::Layout(); + InfoBarView::Layout(); // Layout the icon on left of bar. gfx::Size icon_ps = icon_->GetPreferredSize(); - icon_->SetBounds(InfoBar::kHorizontalPadding, InfoBar::OffsetY(this, icon_ps), - icon_ps.width(), icon_ps.height()); + icon_->SetBounds(InfoBarView::kHorizontalPadding, + InfoBarView::OffsetY(this, icon_ps), icon_ps.width(), icon_ps.height()); } views::Label* TranslateInfoBarBase::CreateLabel(const string16& text) { @@ -85,7 +85,7 @@ void TranslateInfoBarBase::AnimationProgressed(const ui::Animation* animation) { if (background_color_animation_.get() == animation) SchedulePaint(); // That'll trigger a PaintBackgroud. else - InfoBar::AnimationProgressed(animation); + InfoBarView::AnimationProgressed(animation); } views::MenuButton* TranslateInfoBarBase::CreateMenuButton( diff --git a/chrome/browser/ui/views/infobars/translate_infobar_base.h b/chrome/browser/ui/views/infobars/translate_infobar_base.h index 5bde594..16daf32 100644 --- a/chrome/browser/ui/views/infobars/translate_infobar_base.h +++ b/chrome/browser/ui/views/infobars/translate_infobar_base.h @@ -7,7 +7,8 @@ #pragma once #include "chrome/browser/translate/translate_infobar_view.h" -#include "chrome/browser/ui/views/infobars/infobars.h" +#include "chrome/browser/ui/views/infobars/infobar_background.h" +#include "chrome/browser/ui/views/infobars/infobar_view.h" class TranslateInfoBarDelegate; @@ -19,7 +20,7 @@ class ViewMenuDelegate; // This class contains some of the base functionality that translate infobars // use. class TranslateInfoBarBase : public TranslateInfoBarView, - public InfoBar { + public InfoBarView { public: explicit TranslateInfoBarBase(TranslateInfoBarDelegate* delegate); virtual ~TranslateInfoBarBase(); diff --git a/chrome/browser/ui/views/infobars/translate_message_infobar.cc b/chrome/browser/ui/views/infobars/translate_message_infobar.cc index f398289..7abff8f 100644 --- a/chrome/browser/ui/views/infobars/translate_message_infobar.cc +++ b/chrome/browser/ui/views/infobars/translate_message_infobar.cc @@ -7,6 +7,7 @@ #include "chrome/browser/translate/translate_infobar_delegate.h" #include "chrome/browser/ui/views/infobars/infobar_text_button.h" #include "views/controls/image_view.h" +#include "views/controls/label.h" TranslateMessageInfoBar::TranslateMessageInfoBar( TranslateInfoBarDelegate* delegate) @@ -26,23 +27,23 @@ TranslateMessageInfoBar::TranslateMessageInfoBar( void TranslateMessageInfoBar::Layout() { TranslateInfoBarBase::Layout(); - int x = icon_->bounds().right() + InfoBar::kIconLabelSpacing; + int x = icon_->bounds().right() + InfoBarView::kIconLabelSpacing; gfx::Size label_pref_size = label_->GetPreferredSize(); int available_width = GetAvailableWidth() - x; gfx::Size button_pref_size; if (button_) { button_pref_size = button_->GetPreferredSize(); available_width -= - (button_pref_size.width() + InfoBar::kButtonInLabelSpacing); + (button_pref_size.width() + InfoBarView::kButtonInLabelSpacing); } - label_->SetBounds(x, InfoBar::OffsetY(this, label_pref_size), + label_->SetBounds(x, InfoBarView::OffsetY(this, label_pref_size), std::min(label_pref_size.width(), available_width), label_pref_size.height()); if (button_) { button_->SetBounds(label_->bounds().right() + - InfoBar::kButtonInLabelSpacing, - InfoBar::OffsetY(this, button_pref_size), + InfoBarView::kButtonInLabelSpacing, + InfoBarView::OffsetY(this, button_pref_size), button_pref_size.width(), button_pref_size.height()); } } diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index b92cc14..f9a5ac5 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -3326,16 +3326,22 @@ 'browser/ui/views/infobars/after_translate_infobar.h', 'browser/ui/views/infobars/before_translate_infobar.cc', 'browser/ui/views/infobars/before_translate_infobar.h', + 'browser/ui/views/infobars/confirm_infobar.cc', + 'browser/ui/views/infobars/confirm_infobar.h', 'browser/ui/views/infobars/extension_infobar.cc', 'browser/ui/views/infobars/extension_infobar.h', + 'browser/ui/views/infobars/infobar_background.cc', + 'browser/ui/views/infobars/infobar_background.h', 'browser/ui/views/infobars/infobar_button_border.cc', 'browser/ui/views/infobars/infobar_button_border.h', 'browser/ui/views/infobars/infobar_container.cc', 'browser/ui/views/infobars/infobar_container.h', 'browser/ui/views/infobars/infobar_text_button.cc', 'browser/ui/views/infobars/infobar_text_button.h', - 'browser/ui/views/infobars/infobars.cc', - 'browser/ui/views/infobars/infobars.h', + 'browser/ui/views/infobars/infobar_view.cc', + 'browser/ui/views/infobars/infobar_view.h', + 'browser/ui/views/infobars/link_infobar.cc', + 'browser/ui/views/infobars/link_infobar.h', 'browser/ui/views/infobars/translate_infobar_base.cc', 'browser/ui/views/infobars/translate_infobar_base.h', 'browser/ui/views/infobars/translate_message_infobar.cc', |