diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-09 07:35:32 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-09 07:35:32 +0000 |
commit | 213dac2f0bff9162502fe325b6ebb85a255efcb2 (patch) | |
tree | 3640cb1f19976e38677b8632537d2d41f8444d0f /chrome/browser/views/infobars | |
parent | 6de53d401aa8dc6c7e0a9874c71a95ce88ade50d (diff) | |
download | chromium_src-213dac2f0bff9162502fe325b6ebb85a255efcb2.zip chromium_src-213dac2f0bff9162502fe325b6ebb85a255efcb2.tar.gz chromium_src-213dac2f0bff9162502fe325b6ebb85a255efcb2.tar.bz2 |
Move browser/views to browser/ui/views
TBR=brettw
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/4694005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65508 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views/infobars')
18 files changed, 27 insertions, 2413 deletions
diff --git a/chrome/browser/views/infobars/after_translate_infobar.cc b/chrome/browser/views/infobars/after_translate_infobar.cc deleted file mode 100644 index 63b6c8a..0000000 --- a/chrome/browser/views/infobars/after_translate_infobar.cc +++ /dev/null @@ -1,169 +0,0 @@ -// Copyright (c) 2010 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/views/infobars/after_translate_infobar.h" - -#include "app/l10n_util.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/translate/options_menu_model.h" -#include "chrome/browser/translate/translate_infobar_delegate.h" -#include "chrome/browser/views/infobars/infobar_button_border.h" -#include "chrome/browser/views/infobars/infobar_text_button.h" -#include "grit/app_resources.h" -#include "grit/generated_resources.h" -#include "views/controls/button/menu_button.h" -#include "views/controls/button/text_button.h" -#include "views/controls/image_view.h" -#include "views/controls/label.h" -#include "views/controls/menu/menu_2.h" - -AfterTranslateInfoBar::AfterTranslateInfoBar( - TranslateInfoBarDelegate* delegate) - : TranslateInfoBarBase(delegate), - original_language_menu_model_(delegate, LanguagesMenuModel::ORIGINAL), - target_language_menu_model_(delegate, LanguagesMenuModel::TARGET), - options_menu_model_(delegate), - swapped_language_buttons_(false) { - std::vector<string16> strings; - TranslateInfoBarDelegate::GetAfterTranslateStrings( - &strings, &swapped_language_buttons_); - DCHECK(strings.size() == 3U); - - label_1_ = CreateLabel(strings[0]); - AddChildView(label_1_); - - label_2_ = CreateLabel(strings[1]); - AddChildView(label_2_); - - label_3_ = CreateLabel(strings[2]); - AddChildView(label_3_); - - original_language_menu_button_ = CreateMenuButton(string16(), true, this); - AddChildView(original_language_menu_button_); - - target_language_menu_button_ = CreateMenuButton(string16(), true, this); - AddChildView(target_language_menu_button_); - - options_menu_button_ = - CreateMenuButton(l10n_util::GetStringUTF16(IDS_TRANSLATE_INFOBAR_OPTIONS), - false, this); - AddChildView(options_menu_button_); - - revert_button_ = InfoBarTextButton::Create(this, - l10n_util::GetStringUTF16(IDS_TRANSLATE_INFOBAR_REVERT)); - AddChildView(revert_button_); - - UpdateLanguageButtonText(LanguagesMenuModel::ORIGINAL); - UpdateLanguageButtonText(LanguagesMenuModel::TARGET); -} - -AfterTranslateInfoBar::~AfterTranslateInfoBar() { -} - -// Overridden from views::View: -void AfterTranslateInfoBar::Layout() { - // Layout the icon and close button. - TranslateInfoBarBase::Layout(); - - // Layout the options menu button on right of bar. - int available_width = InfoBar::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()); - - views::MenuButton* left_button = swapped_language_buttons_ ? - target_language_menu_button_ : original_language_menu_button_; - views::MenuButton* right_button = swapped_language_buttons_ ? - 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()); - - pref_size = left_button->GetPreferredSize(); - left_button->SetBounds(label_1_->bounds().right() + - InfoBar::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), - pref_size.width(), pref_size.height()); - - pref_size = right_button->GetPreferredSize(); - right_button->SetBounds(label_2_->bounds().right() + - InfoBar::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), - 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), - pref_size.width(), pref_size.height()); -} - -void AfterTranslateInfoBar::OriginalLanguageChanged() { - UpdateLanguageButtonText(LanguagesMenuModel::ORIGINAL); -} - -void AfterTranslateInfoBar::TargetLanguageChanged() { - UpdateLanguageButtonText(LanguagesMenuModel::TARGET); -} - -void AfterTranslateInfoBar::ButtonPressed(views::Button* sender, - const views::Event& event) { - if (sender == revert_button_) { - GetDelegate()->RevertTranslation(); - return; - } - TranslateInfoBarBase::ButtonPressed(sender, event); -} - -void AfterTranslateInfoBar::RunMenu(views::View* source, - const gfx::Point& pt) { - if (source == original_language_menu_button_) { - if (!original_language_menu_.get()) { - original_language_menu_.reset( - new views::Menu2(&original_language_menu_model_)); - } - original_language_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); - } else if (source == target_language_menu_button_) { - if (!target_language_menu_.get()) { - target_language_menu_.reset( - new views::Menu2(&target_language_menu_model_)); - } - target_language_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); - } else if (source == options_menu_button_) { - if (!options_menu_.get()) - options_menu_.reset(new views::Menu2(&options_menu_model_)); - options_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); - } else { - NOTREACHED(); - } -} - -void AfterTranslateInfoBar::UpdateLanguageButtonText( - LanguagesMenuModel::LanguageType language_type) { - int language_index; - views::MenuButton* language_button; - if (language_type == LanguagesMenuModel::ORIGINAL) { - language_index = GetDelegate()->original_language_index(); - language_button = original_language_menu_button_; - } else { - language_index = GetDelegate()->target_language_index(); - language_button = target_language_menu_button_; - } - string16 language = - GetDelegate()->GetLanguageDisplayableNameAt(language_index); - language_button->SetText(UTF16ToWideHack(language)); - // The following line is necessary for the preferred size to be recomputed. - language_button->ClearMaxTextSize(); - // The button may have to grow to show the new text. - Layout(); - SchedulePaint(); -} diff --git a/chrome/browser/views/infobars/after_translate_infobar.h b/chrome/browser/views/infobars/after_translate_infobar.h index 1b94ec8..d0c8fcc 100644 --- a/chrome/browser/views/infobars/after_translate_infobar.h +++ b/chrome/browser/views/infobars/after_translate_infobar.h @@ -6,74 +6,8 @@ #define CHROME_BROWSER_VIEWS_INFOBARS_AFTER_TRANSLATE_INFOBAR_H_ #pragma once -#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/views/infobars/translate_infobar_base.h" -#include "views/controls/button/button.h" -#include "views/controls/link.h" -#include "views/controls/menu/view_menu_delegate.h" - -class InfoBarTextButton; -class TranslateInfoBarDelegate; - -namespace views { -class Menu2; -class MenuButton; -} - -class AfterTranslateInfoBar : public TranslateInfoBarBase, - public views::ViewMenuDelegate { - public: - explicit AfterTranslateInfoBar(TranslateInfoBarDelegate* delegate); - virtual ~AfterTranslateInfoBar(); - - // Overridden from views::View: - virtual void Layout(); - - // Overridden from TranslateInfoBarView: - virtual void OriginalLanguageChanged(); - virtual void TargetLanguageChanged(); - - // Overridden from views::ButtonListener: - virtual void ButtonPressed(views::Button* sender, const views::Event& event); - - protected: - // Overridden from views::ViewMenuDelegate: - virtual void RunMenu(View* source, const gfx::Point& pt); - - private: - // Sets the text of the original or target language menu buttons to reflect - // the current value from the delegate. - void UpdateLanguageButtonText(LanguagesMenuModel::LanguageType language); - - // The text displayed in the infobar is something like: - // "Translated from <lang1> to <lang2>" - // Where <lang1> and <lang2> are displayed in a combobox. - // So the text is split in 3 chunks, each one displayed in one of the label - // below. - views::Label* label_1_; - views::Label* label_2_; - views::Label* label_3_; - - views::MenuButton* original_language_menu_button_; - views::MenuButton* target_language_menu_button_; - views::MenuButton* options_menu_button_; - InfoBarTextButton* revert_button_; - - scoped_ptr<views::Menu2> original_language_menu_; - LanguagesMenuModel original_language_menu_model_; - - scoped_ptr<views::Menu2> target_language_menu_; - LanguagesMenuModel target_language_menu_model_; - - scoped_ptr<views::Menu2> options_menu_; - OptionsMenuModel options_menu_model_; - - // True if the target language comes before the original one. - bool swapped_language_buttons_; - - DISALLOW_COPY_AND_ASSIGN(AfterTranslateInfoBar); -}; +#include "chrome/browser/ui/views/infobars/after_translate_infobar.h" +// TODO(beng): remove this file once all includes have been updated. #endif // CHROME_BROWSER_VIEWS_INFOBARS_AFTER_TRANSLATE_INFOBAR_H_ + diff --git a/chrome/browser/views/infobars/before_translate_infobar.cc b/chrome/browser/views/infobars/before_translate_infobar.cc deleted file mode 100644 index f4d636a..0000000 --- a/chrome/browser/views/infobars/before_translate_infobar.cc +++ /dev/null @@ -1,173 +0,0 @@ -// Copyright (c) 2010 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/views/infobars/before_translate_infobar.h" - -#include "app/l10n_util.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/translate/options_menu_model.h" -#include "chrome/browser/translate/translate_infobar_delegate.h" -#include "chrome/browser/views/infobars/infobar_text_button.h" -#include "grit/generated_resources.h" -#include "views/controls/button/menu_button.h" -#include "views/controls/image_view.h" -#include "views/controls/menu/menu_2.h" - -BeforeTranslateInfoBar::BeforeTranslateInfoBar( - TranslateInfoBarDelegate* delegate) - : TranslateInfoBarBase(delegate), - never_translate_button_(NULL), - always_translate_button_(NULL), - languages_menu_model_(delegate, LanguagesMenuModel::ORIGINAL), - options_menu_model_(delegate) { - size_t offset = 0; - string16 text = - l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_BEFORE_MESSAGE, - string16(), &offset); - - label_1_ = CreateLabel(text.substr(0, offset)); - AddChildView(label_1_); - - label_2_ = CreateLabel(text.substr(offset)); - AddChildView(label_2_); - - accept_button_ = - InfoBarTextButton::CreateWithMessageID(this, - IDS_TRANSLATE_INFOBAR_ACCEPT); - AddChildView(accept_button_); - - deny_button_ = - InfoBarTextButton::CreateWithMessageID(this, - IDS_TRANSLATE_INFOBAR_DENY); - AddChildView(deny_button_); - - language_menu_button_ = CreateMenuButton(string16(), true, this); - AddChildView(language_menu_button_); - - options_menu_button_ = - CreateMenuButton(l10n_util::GetStringUTF16(IDS_TRANSLATE_INFOBAR_OPTIONS), - false, this); - AddChildView(options_menu_button_); - - if (delegate->ShouldShowNeverTranslateButton()) { - const string16& language = delegate->GetLanguageDisplayableNameAt( - delegate->original_language_index()); - never_translate_button_ = InfoBarTextButton::CreateWithMessageIDAndParam( - this, IDS_TRANSLATE_INFOBAR_NEVER_TRANSLATE, language); - AddChildView(never_translate_button_); - } - - if (delegate->ShouldShowAlwaysTranslateButton()) { - const string16& language = delegate->GetLanguageDisplayableNameAt( - delegate->original_language_index()); - always_translate_button_ = InfoBarTextButton::CreateWithMessageIDAndParam( - this, IDS_TRANSLATE_INFOBAR_ALWAYS_TRANSLATE, language); - AddChildView(always_translate_button_); - } - - UpdateOriginalButtonText(); -} - -BeforeTranslateInfoBar::~BeforeTranslateInfoBar() { -} - -// Overridden from views::View: -void BeforeTranslateInfoBar::Layout() { - // Layout the icon and close button. - TranslateInfoBarBase::Layout(); - - // Layout the options menu button on right of bar. - int available_width = InfoBar::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()); - - pref_size = language_menu_button_->GetPreferredSize(); - language_menu_button_->SetBounds(label_1_->bounds().right() + - InfoBar::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), - pref_size.width(), pref_size.height()); - - pref_size = accept_button_->GetPreferredSize(); - accept_button_->SetBounds( - label_2_->bounds().right() + InfoBar::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, - 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, - 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, - OffsetY(this, pref_size), pref_size.width(), pref_size.height()); - } -} - -void BeforeTranslateInfoBar::ButtonPressed(views::Button* sender, - const views::Event& event) { - if (sender == accept_button_) { - GetDelegate()->Translate(); - } else if (sender == deny_button_) { - RemoveInfoBar(); - GetDelegate()->TranslationDeclined(); - } else if (sender == never_translate_button_) { - GetDelegate()->NeverTranslatePageLanguage(); - } else if (sender == always_translate_button_) { - GetDelegate()->AlwaysTranslatePageLanguage(); - } else { - TranslateInfoBarBase::ButtonPressed(sender, event); - } -} - -void BeforeTranslateInfoBar::OriginalLanguageChanged() { - UpdateOriginalButtonText(); -} - -void BeforeTranslateInfoBar::TargetLanguageChanged() { - NOTREACHED(); -} - -void BeforeTranslateInfoBar::RunMenu(views::View* source, - const gfx::Point& pt) { - if (source == language_menu_button_) { - if (!languages_menu_.get()) - languages_menu_.reset(new views::Menu2(&languages_menu_model_)); - languages_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); - } else if (source == options_menu_button_) { - if (!options_menu_.get()) - options_menu_.reset(new views::Menu2(&options_menu_model_)); - options_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); - } else { - NOTREACHED(); - } -} - -void BeforeTranslateInfoBar::UpdateOriginalButtonText() { - string16 language = GetDelegate()->GetLanguageDisplayableNameAt( - GetDelegate()->original_language_index()); - language_menu_button_->SetText(UTF16ToWideHack(language)); - // The following line is necessary for the preferred size to be recomputed. - language_menu_button_->ClearMaxTextSize(); - // The button may have to grow to show the new text. - Layout(); - SchedulePaint(); -} diff --git a/chrome/browser/views/infobars/before_translate_infobar.h b/chrome/browser/views/infobars/before_translate_infobar.h index 7ac6208..1cf685c 100644 --- a/chrome/browser/views/infobars/before_translate_infobar.h +++ b/chrome/browser/views/infobars/before_translate_infobar.h @@ -6,71 +6,8 @@ #define CHROME_BROWSER_VIEWS_INFOBARS_BEFORE_TRANSLATE_INFOBAR_H_ #pragma once -#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/views/infobars/infobars.h" -#include "chrome/browser/views/infobars/translate_infobar_base.h" -#include "views/controls/button/button.h" -#include "views/controls/link.h" -#include "views/controls/menu/view_menu_delegate.h" - -class InfoBarTextButton; -class TranslateInfoBarDelegate; - -namespace views { -class Menu2; -class MenuButton; -} - -class BeforeTranslateInfoBar - : public TranslateInfoBarBase, - public views::ViewMenuDelegate { - public: - explicit BeforeTranslateInfoBar(TranslateInfoBarDelegate* delegate); - virtual ~BeforeTranslateInfoBar(); - - // Overridden from views::View: - virtual void Layout(); - - // Overridden from views::ButtonListener: - virtual void ButtonPressed(views::Button* sender, const views::Event& event); - - // Overridden from TranslateInfoBarView: - virtual void OriginalLanguageChanged(); - virtual void TargetLanguageChanged(); - - protected: - // Overridden from views::ViewMenuDelegate: - virtual void RunMenu(View* source, const gfx::Point& pt); - - private: - // Sets the text of the original language menu button to reflect the current - // value from the delegate. - void UpdateOriginalButtonText(); - - // The text displayed in the infobar is something like: - // "The page is in <lang>. Would you like to translate it?" - // Where <lang> is displayed in a combobox. - // So the text is split in 2 chunks, each one displayed in one of the label - // below. - views::Label* label_1_; - views::Label* label_2_; - - views::MenuButton* language_menu_button_; - views::MenuButton* options_menu_button_; - InfoBarTextButton* accept_button_; - InfoBarTextButton* deny_button_; - InfoBarTextButton* never_translate_button_; - InfoBarTextButton* always_translate_button_; - - scoped_ptr<views::Menu2> languages_menu_; - LanguagesMenuModel languages_menu_model_; - - scoped_ptr<views::Menu2> options_menu_; - OptionsMenuModel options_menu_model_; - - DISALLOW_COPY_AND_ASSIGN(BeforeTranslateInfoBar); -}; +#include "chrome/browser/ui/views/infobars/before_translate_infobar.h" +// TODO(beng): remove this file once all includes have been updated. #endif // CHROME_BROWSER_VIEWS_INFOBARS_BEFORE_TRANSLATE_INFOBAR_H_ + diff --git a/chrome/browser/views/infobars/extension_infobar.cc b/chrome/browser/views/infobars/extension_infobar.cc deleted file mode 100644 index e2fb43f..0000000 --- a/chrome/browser/views/infobars/extension_infobar.cc +++ /dev/null @@ -1,183 +0,0 @@ -// Copyright (c) 2010 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/views/infobars/extension_infobar.h" - -#include "app/resource_bundle.h" -#include "app/slide_animation.h" -#include "chrome/browser/extensions/extension_context_menu_model.h" -#include "chrome/browser/extensions/extension_infobar_delegate.h" -#include "chrome/browser/extensions/extension_host.h" -#include "chrome/browser/platform_util.h" -#include "chrome/browser/views/frame/browser_view.h" -#include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_icon_set.h" -#include "chrome/common/extensions/extension_resource.h" -#include "gfx/canvas_skia.h" -#include "grit/theme_resources.h" -#include "views/controls/button/menu_button.h" -#include "views/controls/menu/menu_2.h" -#include "views/widget/widget.h" - -// The horizontal margin between the menu and the Extension (HTML) view. -static const int kMenuHorizontalMargin = 1; - -// The amount of space to the right of the Extension (HTML) view (to avoid -// overlapping the close button for the InfoBar). -static const int kFarRightMargin = 30; - -// The margin between the extension icon and the drop-down arrow bitmap. -static const int kDropArrowLeftMargin = 3; - -ExtensionInfoBar::ExtensionInfoBar(ExtensionInfoBarDelegate* delegate) - : InfoBar(delegate), - delegate_(delegate), - ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) { - delegate_->set_observer(this); - - ExtensionHost* extension_host = delegate_->extension_host(); - - // We set the target height for the InfoBar to be the height of the - // ExtensionView it contains (plus 1 because the view should not overlap the - // separator line at the bottom). When the InfoBar is first created, however, - // this value is 0 but becomes positive after the InfoBar has been shown. See - // function: OnExtensionPreferredSizeChanged. - gfx::Size sz = extension_host->view()->GetPreferredSize(); - if (sz.height() > 0) - sz.set_height(sz.height() + 1); - set_target_height(sz.height()); - - // Setup the extension icon and its associated drop down menu. - SetupIconAndMenu(); - - // Get notified of resize events for the ExtensionView. - extension_host->view()->SetContainer(this); - // We show the ExtensionView, but we don't want it deleted when we get - // destroyed, which happens on tab switching (for example). - extension_host->view()->set_parent_owned(false); - AddChildView(extension_host->view()); -} - -ExtensionInfoBar::~ExtensionInfoBar() { - if (delegate_) { - delegate_->extension_host()->view()->SetContainer(NULL); - delegate_->set_observer(NULL); - } -} - -void ExtensionInfoBar::OnExtensionPreferredSizeChanged(ExtensionView* view) { - DCHECK(view == delegate_->extension_host()->view()); - - // When the infobar is closed, it animates to 0 vertical height. We'll - // continue to get size changed notifications from the ExtensionView, but we - // need to ignore them otherwise we'll try to re-animate open (and leak the - // infobar view). - if (delegate_->closing()) - return; - - delegate_->extension_host()->view()->SetVisible(true); - - 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); - sz.set_height(std::max(default_height, sz.height())); - sz.set_height(std::min(2 * default_height, sz.height())); - - if (height() == 0) - animation()->Reset(0.0); - set_target_height(sz.height()); - animation()->Show(); -} - -void ExtensionInfoBar::Layout() { - // Layout the close button and the background. - InfoBar::Layout(); - - // Layout the extension icon + drop down menu. - int x = 0; - gfx::Size sz = menu_->GetPreferredSize(); - menu_->SetBounds(x, - (height() - sz.height()) / 2, - sz.width(), sz.height()); - x += sz.width() + kMenuHorizontalMargin; - - // Layout the ExtensionView, showing the HTML InfoBar. - ExtensionView* view = delegate_->extension_host()->view(); - view->SetBounds(x, 0, width() - x - kFarRightMargin - 1, height() - 1); -} - -void ExtensionInfoBar::OnImageLoaded( - SkBitmap* image, ExtensionResource resource, int index) { - if (!delegate_) - return; // The delegate can go away while we asynchronously load images. - - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - - // We fall back on the default extension icon on failure. - SkBitmap* icon; - if (!image || image->empty()) - icon = rb.GetBitmapNamed(IDR_EXTENSIONS_SECTION); - else - icon = image; - - SkBitmap* drop_image = rb.GetBitmapNamed(IDR_APP_DROPARROW); - - int image_size = Extension::EXTENSION_ICON_BITTY; - scoped_ptr<gfx::CanvasSkia> canvas( - new gfx::CanvasSkia( - image_size + kDropArrowLeftMargin + drop_image->width(), - image_size, false)); - canvas->DrawBitmapInt(*icon, - 0, 0, icon->width(), icon->height(), - 0, 0, image_size, image_size, - false); - canvas->DrawBitmapInt(*drop_image, - image_size + kDropArrowLeftMargin, - image_size / 2); - menu_->SetIcon(canvas->ExtractBitmap()); - menu_->SetVisible(true); - - Layout(); -} - -void ExtensionInfoBar::OnDelegateDeleted() { - delegate_->extension_host()->view()->SetContainer(NULL); - delegate_ = NULL; -} - -void ExtensionInfoBar::RunMenu(View* source, const gfx::Point& pt) { - if (!options_menu_contents_.get()) { - Browser* browser = BrowserView::GetBrowserViewForNativeWindow( - platform_util::GetTopLevel(source->GetWidget()->GetNativeView()))-> - browser(); - options_menu_contents_ = new ExtensionContextMenuModel( - delegate_->extension_host()->extension(), browser, NULL); - } - - options_menu_menu_.reset(new views::Menu2(options_menu_contents_.get())); - options_menu_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPLEFT); -} - -void ExtensionInfoBar::SetupIconAndMenu() { - menu_ = new views::MenuButton(NULL, std::wstring(), this, false); - menu_->SetVisible(false); - AddChildView(menu_); - - const Extension* extension = delegate_->extension_host()->extension(); - ExtensionResource icon_resource = extension->GetIconResource( - Extension::EXTENSION_ICON_BITTY, ExtensionIconSet::MATCH_EXACTLY); - if (!icon_resource.relative_path().empty()) { - // Create a tracker to load the image. It will report back on OnImageLoaded. - tracker_.LoadImage(extension, icon_resource, - gfx::Size(Extension::EXTENSION_ICON_BITTY, - Extension::EXTENSION_ICON_BITTY), - ImageLoadingTracker::DONT_CACHE); - } else { - OnImageLoaded(NULL, icon_resource, 0); // |image|, |index|. - } -} - -InfoBar* ExtensionInfoBarDelegate::CreateInfoBar() { - return new ExtensionInfoBar(this); -} diff --git a/chrome/browser/views/infobars/extension_infobar.h b/chrome/browser/views/infobars/extension_infobar.h index b4bab7e..0b1ae4a 100644 --- a/chrome/browser/views/infobars/extension_infobar.h +++ b/chrome/browser/views/infobars/extension_infobar.h @@ -6,67 +6,8 @@ #define CHROME_BROWSER_VIEWS_INFOBARS_EXTENSION_INFOBAR_H_ #pragma once -#include "chrome/browser/views/infobars/infobars.h" - -#include "chrome/browser/extensions/extension_infobar_delegate.h" -#include "chrome/browser/extensions/image_loading_tracker.h" -#include "chrome/browser/views/extensions/extension_view.h" -#include "views/controls/menu/view_menu_delegate.h" - -class ExtensionContextMenuModel; -class ExtensionInfoBarDelegate; - -namespace views { - class MenuButton; - class Menu2; -} - -// This class implements InfoBars for Extensions. -class ExtensionInfoBar : public InfoBar, - public ExtensionView::Container, - public ImageLoadingTracker::Observer, - public ExtensionInfoBarDelegate::DelegateObserver, - public views::ViewMenuDelegate { - public: - explicit ExtensionInfoBar(ExtensionInfoBarDelegate* delegate); - virtual ~ExtensionInfoBar(); - - // Overridden from ExtensionView::Container: - virtual void OnExtensionMouseMove(ExtensionView* view) {} - virtual void OnExtensionMouseLeave(ExtensionView* view) {} - virtual void OnExtensionPreferredSizeChanged(ExtensionView* view); - - // Overridden from views::View: - virtual void Layout(); - - // Overridden from ImageLoadingTracker::Observer: - virtual void OnImageLoaded( - SkBitmap* image, ExtensionResource resource, int index); - - // Overridden from ExtensionInfoBarDelegate::DelegateObserver: - virtual void OnDelegateDeleted(); - - // Overridden from views::ViewMenuDelegate: - virtual void RunMenu(View* source, const gfx::Point& pt); - - private: - // Setup the menu button showing the small extension icon and its dropdown - // menu. - void SetupIconAndMenu(); - - NotificationRegistrar notification_registrar_; - - ExtensionInfoBarDelegate* delegate_; - - // The dropdown menu for accessing the contextual extension actions. - scoped_refptr<ExtensionContextMenuModel> options_menu_contents_; - scoped_ptr<views::Menu2> options_menu_menu_; - views::MenuButton* menu_; - - // Keeps track of images being loaded on the File thread. - ImageLoadingTracker tracker_; - - DISALLOW_COPY_AND_ASSIGN(ExtensionInfoBar); -}; +#include "chrome/browser/ui/views/infobars/extension_infobar.h" +// TODO(beng): remove this file once all includes have been updated. #endif // CHROME_BROWSER_VIEWS_INFOBARS_EXTENSION_INFOBAR_H_ + diff --git a/chrome/browser/views/infobars/infobar_button_border.cc b/chrome/browser/views/infobars/infobar_button_border.cc deleted file mode 100644 index ed65885..0000000 --- a/chrome/browser/views/infobars/infobar_button_border.cc +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright (c) 2010 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/views/infobars/infobar_button_border.h" - -#include "app/resource_bundle.h" -#include "gfx/canvas.h" -#include "grit/theme_resources.h" -#include "views/controls/button/text_button.h" - -// Preferred padding between text and edge -static const int kPreferredPaddingHorizontal = 6; -static const int kPreferredPaddingVertical = 5; - -// InfoBarButtonBorder, public: ---------------------------------------------- - -InfoBarButtonBorder::InfoBarButtonBorder() { - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - - normal_set_.top_left = rb.GetBitmapNamed(IDR_INFOBARBUTTON_TOP_LEFT_N); - normal_set_.top = rb.GetBitmapNamed(IDR_INFOBARBUTTON_TOP_N); - normal_set_.top_right = rb.GetBitmapNamed(IDR_INFOBARBUTTON_TOP_RIGHT_N); - normal_set_.left = rb.GetBitmapNamed(IDR_INFOBARBUTTON_LEFT_N); - normal_set_.center = rb.GetBitmapNamed(IDR_INFOBARBUTTON_CENTER_N); - normal_set_.right = rb.GetBitmapNamed(IDR_INFOBARBUTTON_RIGHT_N); - normal_set_.bottom_left = rb.GetBitmapNamed(IDR_INFOBARBUTTON_BOTTOM_LEFT_N); - normal_set_.bottom = rb.GetBitmapNamed(IDR_INFOBARBUTTON_BOTTOM_N); - normal_set_.bottom_right = - rb.GetBitmapNamed(IDR_INFOBARBUTTON_BOTTOM_RIGHT_N); - - hot_set_.top_left = rb.GetBitmapNamed(IDR_INFOBARBUTTON_TOP_LEFT_H); - hot_set_.top = rb.GetBitmapNamed(IDR_INFOBARBUTTON_TOP_H); - hot_set_.top_right = rb.GetBitmapNamed(IDR_INFOBARBUTTON_TOP_RIGHT_H); - hot_set_.left = rb.GetBitmapNamed(IDR_INFOBARBUTTON_LEFT_H); - hot_set_.center = rb.GetBitmapNamed(IDR_INFOBARBUTTON_CENTER_H); - hot_set_.right = rb.GetBitmapNamed(IDR_INFOBARBUTTON_RIGHT_H); - hot_set_.bottom_left = rb.GetBitmapNamed(IDR_INFOBARBUTTON_BOTTOM_LEFT_H); - hot_set_.bottom = rb.GetBitmapNamed(IDR_INFOBARBUTTON_BOTTOM_H); - hot_set_.bottom_right = rb.GetBitmapNamed(IDR_INFOBARBUTTON_BOTTOM_RIGHT_H); - - pushed_set_.top_left = rb.GetBitmapNamed(IDR_INFOBARBUTTON_TOP_LEFT_P); - pushed_set_.top = rb.GetBitmapNamed(IDR_INFOBARBUTTON_TOP_P); - pushed_set_.top_right = rb.GetBitmapNamed(IDR_INFOBARBUTTON_TOP_RIGHT_P); - pushed_set_.left = rb.GetBitmapNamed(IDR_INFOBARBUTTON_LEFT_P); - pushed_set_.center = rb.GetBitmapNamed(IDR_INFOBARBUTTON_CENTER_P); - pushed_set_.right = rb.GetBitmapNamed(IDR_INFOBARBUTTON_RIGHT_P); - pushed_set_.bottom_left = rb.GetBitmapNamed(IDR_INFOBARBUTTON_BOTTOM_LEFT_P); - pushed_set_.bottom = rb.GetBitmapNamed(IDR_INFOBARBUTTON_BOTTOM_P); - pushed_set_.bottom_right = - rb.GetBitmapNamed(IDR_INFOBARBUTTON_BOTTOM_RIGHT_P); -} - -InfoBarButtonBorder::~InfoBarButtonBorder() { -} - -// InfoBarButtonBorder, Border overrides: ------------------------------------ - -void InfoBarButtonBorder::GetInsets(gfx::Insets* insets) const { - insets->Set(kPreferredPaddingVertical, kPreferredPaddingHorizontal, - kPreferredPaddingVertical, kPreferredPaddingHorizontal); -} - -void InfoBarButtonBorder::Paint(const views::View& view, - gfx::Canvas* canvas) const { - const views::TextButton* mb = static_cast<const views::TextButton*>(&view); - int state = mb->state(); - - // TextButton takes care of deciding when to call Paint. - const MBBImageSet* set = &normal_set_; - if (state == views::TextButton::BS_HOT) - set = &hot_set_; - else if (state == views::TextButton::BS_PUSHED) - set = &pushed_set_; - - gfx::Rect bounds = view.bounds(); - - // Draw top left image. - canvas->DrawBitmapInt(*set->top_left, 0, 0); - - // Stretch top image. - canvas->DrawBitmapInt( - *set->top, - 0, 0, set->top->width(), set->top->height(), - set->top_left->width(), - 0, - bounds.width() - set->top_right->width() - set->top_left->width(), - set->top->height(), false); - - // Draw top right image. - canvas->DrawBitmapInt(*set->top_right, - bounds.width() - set->top_right->width(), 0); - - // Stretch left image. - canvas->DrawBitmapInt( - *set->left, - 0, 0, set->left->width(), set->left->height(), - 0, - set->top_left->height(), - set->top_left->width(), - bounds.height() - set->top->height() - set->bottom_left->height(), false); - - // Stretch center image. - canvas->DrawBitmapInt( - *set->center, - 0, 0, set->center->width(), set->center->height(), - set->left->width(), - set->top->height(), - bounds.width() - set->right->width() - set->left->width(), - bounds.height() - set->bottom->height() - set->top->height(), false); - - // Stretch right image. - canvas->DrawBitmapInt( - *set->right, - 0, 0, set->right->width(), set->right->height(), - bounds.width() - set->right->width(), - set->top_right->height(), - set->right->width(), - bounds.height() - set->bottom_right->height() - - set->top_right->height(), false); - - // Draw bottom left image. - canvas->DrawBitmapInt(*set->bottom_left, - 0, - bounds.height() - set->bottom_left->height()); - - // Stretch bottom image. - canvas->DrawBitmapInt( - *set->bottom, - 0, 0, set->bottom->width(), set->bottom->height(), - set->bottom_left->width(), - bounds.height() - set->bottom->height(), - bounds.width() - set->bottom_right->width() - - set->bottom_left->width(), - set->bottom->height(), false); - - // Draw bottom right image. - canvas->DrawBitmapInt(*set->bottom_right, - bounds.width() - set->bottom_right->width(), - bounds.height() - set->bottom_right->height()); -} diff --git a/chrome/browser/views/infobars/infobar_button_border.h b/chrome/browser/views/infobars/infobar_button_border.h index 865e4f8..daafb16 100644 --- a/chrome/browser/views/infobars/infobar_button_border.h +++ b/chrome/browser/views/infobars/infobar_button_border.h @@ -6,48 +6,8 @@ #define CHROME_BROWSER_VIEWS_INFOBARS_INFOBAR_BUTTON_BORDER_H_ #pragma once -#include "views/border.h" - -#include "third_party/skia/include/core/SkBitmap.h" - -namespace gfx { -class Canvas; -} -namespace views { -class View; -} - -// A TextButtonBorder that is dark and also paints the button frame in the -// normal state. - -class InfoBarButtonBorder : public views::Border { - public: - InfoBarButtonBorder(); - virtual ~InfoBarButtonBorder(); - - // Overriden from Border: - virtual void GetInsets(gfx::Insets* insets) const; - virtual void Paint(const views::View& view, gfx::Canvas* canvas) const; - - private: - // Images - struct MBBImageSet { - SkBitmap* top_left; - SkBitmap* top; - SkBitmap* top_right; - SkBitmap* left; - SkBitmap* center; - SkBitmap* right; - SkBitmap* bottom_left; - SkBitmap* bottom; - SkBitmap* bottom_right; - }; - - MBBImageSet normal_set_; - MBBImageSet hot_set_; - MBBImageSet pushed_set_; - - DISALLOW_COPY_AND_ASSIGN(InfoBarButtonBorder); -}; +#include "chrome/browser/ui/views/infobars/infobar_button_border.h" +// TODO(beng): remove this file once all includes have been updated. #endif // CHROME_BROWSER_VIEWS_INFOBARS_INFOBAR_BUTTON_BORDER_H_ + diff --git a/chrome/browser/views/infobars/infobar_container.cc b/chrome/browser/views/infobars/infobar_container.cc deleted file mode 100644 index 5779fde..0000000 --- a/chrome/browser/views/infobars/infobar_container.cc +++ /dev/null @@ -1,164 +0,0 @@ -// Copyright (c) 2010 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/views/infobars/infobar_container.h" - -#include "app/l10n_util.h" -#include "chrome/browser/tab_contents/infobar_delegate.h" -#include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/browser/view_ids.h" -#include "chrome/browser/views/infobars/infobars.h" -#include "chrome/common/notification_service.h" -#include "grit/generated_resources.h" - -// InfoBarContainer, public: --------------------------------------------------- - -InfoBarContainer::InfoBarContainer(Delegate* delegate) - : delegate_(delegate), - tab_contents_(NULL) { - SetID(VIEW_ID_INFO_BAR_CONTAINER); - SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_INFOBAR_CONTAINER)); -} - -InfoBarContainer::~InfoBarContainer() { - // We NULL this pointer before resetting the TabContents to prevent view - // hierarchy modifications from attempting to resize the delegate which - // could be in the process of shutting down. - delegate_ = NULL; - ChangeTabContents(NULL); -} - -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). - RemoveAllChildViews(false); - tab_contents_ = contents; - if (tab_contents_) { - UpdateInfoBars(); - Source<TabContents> tc_source(tab_contents_); - registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_ADDED, - tc_source); - registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, - tc_source); - registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REPLACED, - tc_source); - } -} - -void InfoBarContainer::InfoBarAnimated(bool completed) { - if (delegate_) - delegate_->InfoBarSizeChanged(!completed); -} - -void InfoBarContainer::RemoveDelegate(InfoBarDelegate* delegate) { - tab_contents_->RemoveInfoBar(delegate); -} - -// InfoBarContainer, views::View overrides: ------------------------------------ - -gfx::Size InfoBarContainer::GetPreferredSize() { - // We do not have a preferred width (we will expand to fit the available width - // of the delegate). Our preferred height is the sum of the preferred - // heights of the InfoBars contained within us. - int height = 0; - for (int i = 0; i < GetChildViewCount(); ++i) - height += GetChildViewAt(i)->GetPreferredSize().height(); - return gfx::Size(0, height); -} - -void InfoBarContainer::Layout() { - int top = 0; - for (int i = 0; i < GetChildViewCount(); ++i) { - views::View* child = GetChildViewAt(i); - gfx::Size ps = child->GetPreferredSize(); - child->SetBounds(0, top, width(), ps.height()); - top += ps.height(); - } -} - -AccessibilityTypes::Role InfoBarContainer::GetAccessibleRole() { - return AccessibilityTypes::ROLE_GROUPING; -} - -void InfoBarContainer::ViewHierarchyChanged(bool is_add, - views::View* parent, - views::View* child) { - if (parent == this && child->GetParent() == this) { - if (delegate_) { - // An InfoBar child was added or removed. Tell the delegate it needs to - // re-layout since our preferred size will have changed. - delegate_->InfoBarSizeChanged(false); - } - } -} - -// InfoBarContainer, NotificationObserver implementation: ---------------------- - -void InfoBarContainer::Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - if (type == NotificationType::TAB_CONTENTS_INFOBAR_ADDED) { - AddInfoBar(Details<InfoBarDelegate>(details).ptr(), true); // animated - } else if (type == NotificationType::TAB_CONTENTS_INFOBAR_REMOVED) { - RemoveInfoBar(Details<InfoBarDelegate>(details).ptr(), true); // animated - } else if (type == NotificationType::TAB_CONTENTS_INFOBAR_REPLACED) { - std::pair<InfoBarDelegate*, InfoBarDelegate*>* delegates = - Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details).ptr(); - ReplaceInfoBar(delegates->first, delegates->second); - } else { - NOTREACHED(); - } -} - -// InfoBarContainer, private: -------------------------------------------------- - -void InfoBarContainer::UpdateInfoBars() { - for (int i = 0; i < tab_contents_->infobar_delegate_count(); ++i) { - InfoBarDelegate* delegate = tab_contents_->GetInfoBarDelegateAt(i); - InfoBar* infobar = delegate->CreateInfoBar(); - infobar->set_container(this); - AddChildView(infobar); - infobar->Open(); - } -} - -void InfoBarContainer::AddInfoBar(InfoBarDelegate* delegate, - bool use_animation) { - InfoBar* infobar = delegate->CreateInfoBar(); - infobar->set_container(this); - AddChildView(infobar); - - if (use_animation) - infobar->AnimateOpen(); - else - infobar->Open(); -} - -void InfoBarContainer::RemoveInfoBar(InfoBarDelegate* delegate, - bool use_animation) { - // Search for infobar associated with |delegate| among child views. - // We cannot search for |delegate| in tab_contents, because an infobar remains - // a child view until its close animation completes, which can result in - // 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)); - if (infobar->delegate() == delegate) { - if (use_animation) { - // The View will be removed once the Close animation completes. - infobar->AnimateClose(); - } else { - infobar->Close(); - } - break; - } - } -} - -void InfoBarContainer::ReplaceInfoBar(InfoBarDelegate* old_delegate, - InfoBarDelegate* new_delegate) { - RemoveInfoBar(old_delegate, false); // no animation - AddInfoBar(new_delegate, false); // no animation -} diff --git a/chrome/browser/views/infobars/infobar_container.h b/chrome/browser/views/infobars/infobar_container.h index 89d5a91..13c3f56 100644 --- a/chrome/browser/views/infobars/infobar_container.h +++ b/chrome/browser/views/infobars/infobar_container.h @@ -6,89 +6,8 @@ #define CHROME_BROWSER_VIEWS_INFOBARS_INFOBAR_CONTAINER_H_ #pragma once -#include "chrome/browser/views/accessible_pane_view.h" -#include "chrome/common/notification_observer.h" -#include "chrome/common/notification_registrar.h" -#include "views/view.h" - -class BrowserView; -class InfoBarDelegate; -class TabContents; - -// A views::View subclass that contains a collection of InfoBars associated with -// a TabContents. -class InfoBarContainer : public AccessiblePaneView, - public NotificationObserver { - public: - // Implement this interface when you want to receive notifications from the - // InfoBarContainer - class Delegate { - public: - virtual ~Delegate() {} - virtual void InfoBarSizeChanged(bool is_animating) = 0; - }; - - explicit InfoBarContainer(Delegate* delegate); - virtual ~InfoBarContainer(); - - // Changes the TabContents for which this container is showing InfoBars. Can - // be NULL. - void ChangeTabContents(TabContents* contents); - - // Called by child InfoBars as they animate. If |completed| is true, the - // animation has finished running. - void InfoBarAnimated(bool completed); - - // Remove the specified InfoBarDelegate from the selected TabContents. This - // will notify us back and cause us to close the View. This is called from - // the InfoBar's close button handler. - void RemoveDelegate(InfoBarDelegate* delegate); - - // Overridden from views::View: - virtual gfx::Size GetPreferredSize(); - virtual void Layout(); - virtual AccessibilityTypes::Role GetAccessibleRole(); - - protected: - virtual void ViewHierarchyChanged(bool is_add, - views::View* parent, - views::View* child); - - private: - // Overridden from NotificationObserver: - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details); - - // Constructs the InfoBars needed to reflect the state of the current - // TabContents associated with this container. No animations are run during - // this process. - void UpdateInfoBars(); - - // Adds an InfoBar for the specified delegate, in response to a notification - // from the selected TabContents. The InfoBar's appearance will be animated - // if |use_animation| is true. - void AddInfoBar(InfoBarDelegate* delegate, bool use_animation); - - // Removes an InfoBar for the specified delegate, in response to a - // notification from the selected TabContents. The InfoBar's disappearance - // will be animated if |use_animation| is true. - void RemoveInfoBar(InfoBarDelegate* delegate, bool use_animation); - - // Replaces an InfoBar for the specified delegate with a new one. There is no - // animation. - void ReplaceInfoBar(InfoBarDelegate* old_delegate, - InfoBarDelegate* new_delegate); - - NotificationRegistrar registrar_; - - // The Delegate which receives notifications from the InfoBarContainer. - Delegate* delegate_; - - // The TabContents for which we are currently showing InfoBars. - TabContents* tab_contents_; - - DISALLOW_COPY_AND_ASSIGN(InfoBarContainer); -}; +#include "chrome/browser/ui/views/infobars/infobar_container.h" +// TODO(beng): remove this file once all includes have been updated. #endif // CHROME_BROWSER_VIEWS_INFOBARS_INFOBAR_CONTAINER_H_ + diff --git a/chrome/browser/views/infobars/infobar_text_button.cc b/chrome/browser/views/infobars/infobar_text_button.cc deleted file mode 100644 index ebf5d22..0000000 --- a/chrome/browser/views/infobars/infobar_text_button.cc +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) 2010 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/views/infobars/infobar_text_button.h" - -#include "app/l10n_util.h" -#include "app/resource_bundle.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/views/infobars/infobar_button_border.h" - -// static -InfoBarTextButton* InfoBarTextButton::Create(views::ButtonListener* listener, - const string16& text) { - return new InfoBarTextButton(listener, text); -} - -// static -InfoBarTextButton* InfoBarTextButton::CreateWithMessageID( - views::ButtonListener* listener, int message_id) { - return new InfoBarTextButton(listener, - l10n_util::GetStringUTF16(message_id)); -} - -// static -InfoBarTextButton* InfoBarTextButton::CreateWithMessageIDAndParam( - views::ButtonListener* listener, int message_id, const string16& param) { - return new InfoBarTextButton(listener, - l10n_util::GetStringFUTF16(message_id, param)); -} - -InfoBarTextButton::~InfoBarTextButton() { -} - -bool InfoBarTextButton::OnMousePressed(const views::MouseEvent& e) { - return views::CustomButton::OnMousePressed(e); -} - -InfoBarTextButton::InfoBarTextButton(views::ButtonListener* listener, - const string16& text) - // Don't use text to construct TextButton because we need to set font - // before setting text so that the button will resize to fit entire text. - : TextButton(listener, std::wstring()) { - set_border(new InfoBarButtonBorder); - SetNormalHasBorder(true); // Normal button state has border. - SetAnimationDuration(0); // Disable animation during state change. - // Set font colors for different states. - SetEnabledColor(SK_ColorBLACK); - SetHighlightColor(SK_ColorBLACK); - SetHoverColor(SK_ColorBLACK); - // Set font then text, then size button to fit text. - SetFont( - ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont)); - SetText(UTF16ToWideHack(text)); - ClearMaxTextSize(); - SizeToPreferredSize(); -} diff --git a/chrome/browser/views/infobars/infobar_text_button.h b/chrome/browser/views/infobars/infobar_text_button.h index 35f16a1..7255f0d 100644 --- a/chrome/browser/views/infobars/infobar_text_button.h +++ b/chrome/browser/views/infobars/infobar_text_button.h @@ -6,33 +6,8 @@ #define CHROME_BROWSER_VIEWS_INFOBARS_INFOBAR_TEXT_BUTTON_H_ #pragma once -#include "views/controls/button/text_button.h" - -// A TextButton subclass that overrides OnMousePressed to default to -// CustomButton so as to create pressed state effect. - -class InfoBarTextButton : public views::TextButton { - public: - // Creates a button with the specified |text|. - static InfoBarTextButton* Create(views::ButtonListener* listener, - const string16& text); - // Creates a button which text is the resource string identified by - // |message_id|. - static InfoBarTextButton* CreateWithMessageID(views::ButtonListener* listener, - int message_id); - static InfoBarTextButton* CreateWithMessageIDAndParam( - views::ButtonListener* listener, int message_id, const string16& param); - - virtual ~InfoBarTextButton(); - - protected: - InfoBarTextButton(views::ButtonListener* listener, const string16& text); - - // Overriden from TextButton: - virtual bool OnMousePressed(const views::MouseEvent& e); - - private: - DISALLOW_COPY_AND_ASSIGN(InfoBarTextButton); -}; +#include "chrome/browser/ui/views/infobars/infobar_text_button.h" +// TODO(beng): remove this file once all includes have been updated. #endif // CHROME_BROWSER_VIEWS_INFOBARS_INFOBAR_TEXT_BUTTON_H_ + diff --git a/chrome/browser/views/infobars/infobars.cc b/chrome/browser/views/infobars/infobars.cc deleted file mode 100644 index c96f72f..0000000 --- a/chrome/browser/views/infobars/infobars.cc +++ /dev/null @@ -1,614 +0,0 @@ -// Copyright (c) 2010 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/views/infobars/infobars.h" - -#include "app/l10n_util.h" -#include "app/resource_bundle.h" -#include "app/slide_animation.h" -#if defined(OS_WIN) -#include "app/win_util.h" -#endif // defined(OS_WIN) -#include "base/message_loop.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/views/event_utils.h" -#include "chrome/browser/views/infobars/infobar_container.h" -#include "gfx/canvas.h" -#include "grit/generated_resources.h" -#include "grit/theme_resources.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" - -// 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::GetString(IDS_ACCNAME_INFOBAR_WARNING)); - break; - case InfoBarDelegate::PAGE_ACTION_TYPE: - SetAccessibleName(l10n_util::GetString(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::GetString(IDS_ACCNAME_CLOSE)); - AddChildView(close_button_); - - animation_.reset(new SlideAnimation(this)); - animation_->SetTweenType(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, AnimationDelegate implementation: ---------------------------------- - -void InfoBar::AnimationProgressed(const Animation* animation) { - if (container_) - container_->InfoBarAnimated(true); -} - -void InfoBar::AnimationEnded(const 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() && - !win_util::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(AlertInfoBarDelegate* 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()); -} - -// AlertInfoBar, private: ------------------------------------------------------ - -AlertInfoBarDelegate* AlertInfoBar::GetDelegate() { - return delegate()->AsAlertInfoBarDelegate(); -} - -// 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_ = new views::NativeButton(this, - UTF16ToWideHack(delegate->GetButtonLabel( - ConfirmInfoBarDelegate::BUTTON_OK))); - ok_button_->SetAccessibleName(ok_button_->label()); - if (delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_OK_DEFAULT) - ok_button_->SetAppearsAsDefault(true); - if (delegate->NeedElevation(ConfirmInfoBarDelegate::BUTTON_OK)) - ok_button_->SetNeedElevation(true); - cancel_button_ = new views::NativeButton( - this, UTF16ToWideHack( - delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL))); - cancel_button_->SetAccessibleName(cancel_button_->label()); - - // 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_); -} - -// AlertInfoBarDelegate, InfoBarDelegate overrides: ---------------------------- - -InfoBar* AlertInfoBarDelegate::CreateInfoBar() { - return new AlertInfoBar(this); -} - -// 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/views/infobars/infobars.h b/chrome/browser/views/infobars/infobars.h index ec270d5..9345bdc 100644 --- a/chrome/browser/views/infobars/infobars.h +++ b/chrome/browser/views/infobars/infobars.h @@ -6,246 +6,8 @@ #define CHROME_BROWSER_VIEWS_INFOBARS_INFOBARS_H_ #pragma once -#include "app/animation.h" -#include "base/task.h" -#include "chrome/browser/tab_contents/infobar_delegate.h" -#include "views/controls/button/button.h" -#include "views/controls/link.h" -#include "views/focus/focus_manager.h" - -class InfoBarContainer; -class SlideAnimation; -namespace views { -class ExternalFocusTracker; -class ImageButton; -class ImageView; -class Label; -class NativeButton; -} - -// 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 { - 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); -}; - -class InfoBar : public views::View, - public views::ButtonListener, - public views::FocusChangeListener, - public AnimationDelegate { - public: - explicit InfoBar(InfoBarDelegate* delegate); - virtual ~InfoBar(); - - InfoBarDelegate* delegate() const { return delegate_; } - - // Set a link to the parent InfoBarContainer. This must be set before the - // InfoBar is added to the view hierarchy. - void set_container(InfoBarContainer* container) { container_ = container; } - - // The target height of the InfoBar, regardless of what its current height - // is (due to animation). - static const double kDefaultTargetHeight; - - static const int kHorizontalPadding; - static const int kIconLabelSpacing; - static const int kButtonButtonSpacing; - static const int kEndOfLabelSpacing; - static const int kCloseButtonSpacing; - static const int kButtonInLabelSpacing; - - // Overridden from views::View: - virtual AccessibilityTypes::Role GetAccessibleRole(); - virtual gfx::Size GetPreferredSize(); - virtual void Layout(); - - protected: - // Overridden from views::View: - virtual void ViewHierarchyChanged(bool is_add, - views::View* parent, - views::View* child); - - // Returns the available width of the View for use by child view layout, - // excluding the close button. - virtual int GetAvailableWidth() const; - - // Removes our associated InfoBarDelegate from the associated TabContents. - // (Will lead to this InfoBar being closed). - void RemoveInfoBar() const; - - void set_target_height(double height) { target_height_ = height; } - - SlideAnimation* animation() { return animation_.get(); } - - // Returns a centered y-position of a control of height specified in - // |prefsize| within the standard InfoBar height. Stable during an animation. - int CenterY(const gfx::Size prefsize); - - // Returns a centered y-position of a control of height specified in - // |prefsize| within the standard InfoBar height, adjusted according to the - // current amount of animation offset the |parent| InfoBar currently has. - // Changes during an animation. - int OffsetY(views::View* parent, const gfx::Size prefsize); - - // Overridden from views::ButtonListener: - virtual void ButtonPressed(views::Button* sender, const views::Event& event); - - // Overridden from views::FocusChangeListener: - virtual void FocusWillChange(View* focused_before, View* focused_now); - - // Overridden from AnimationDelegate: - virtual void AnimationProgressed(const Animation* animation); - virtual void AnimationEnded(const Animation* animation); - - private: - friend class InfoBarContainer; - - // Starts animating the InfoBar open. - void AnimateOpen(); - - // Opens the InfoBar immediately. - void Open(); - - // Starts animating the InfoBar closed. It will not be closed until the - // animation has completed, when |Close| will be called. - void AnimateClose(); - - // Closes the InfoBar immediately and removes it from its container. Notifies - // the delegate that it has closed. The InfoBar is deleted after this function - // is called. - void Close(); - - // Called when an InfoBar is added or removed from a view hierarchy to do - // setup and shutdown. - void InfoBarAdded(); - void InfoBarRemoved(); - - // Destroys the external focus tracker, if present. If |restore_focus| is - // true, restores focus to the view tracked by the focus tracker before doing - // so. - void DestroyFocusTracker(bool restore_focus); - - // Deletes this object (called after a return to the message loop to allow - // the stack in ViewHierarchyChanged to unwind). - void DeleteSelf(); - - // The InfoBar's container - InfoBarContainer* container_; - - // The InfoBar's delegate. - InfoBarDelegate* delegate_; - - // The Close Button at the right edge of the InfoBar. - views::ImageButton* close_button_; - - // The animation that runs when the InfoBar is opened or closed. - scoped_ptr<SlideAnimation> animation_; - - // Tracks and stores the last focused view which is not the InfoBar or any of - // its children. Used to restore focus once the InfoBar is closed. - scoped_ptr<views::ExternalFocusTracker> focus_tracker_; - - // Used to delete this object after a return to the message loop. - ScopedRunnableMethodFactory<InfoBar> delete_factory_; - - // The target height for the InfoBar. - double target_height_; - - DISALLOW_COPY_AND_ASSIGN(InfoBar); -}; - -class AlertInfoBar : public InfoBar { - public: - explicit AlertInfoBar(AlertInfoBarDelegate* delegate); - virtual ~AlertInfoBar(); - - // Overridden from views::View: - virtual void Layout(); - - protected: - views::Label* label() const { return label_; } - views::ImageView* icon() const { return icon_; } - - private: - AlertInfoBarDelegate* GetDelegate(); - - 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(); - - views::NativeButton* ok_button_; - views::NativeButton* cancel_button_; - views::Link* link_; - - bool initialized_; - - DISALLOW_COPY_AND_ASSIGN(ConfirmInfoBar); -}; - +#include "chrome/browser/ui/views/infobars/infobars.h" +// TODO(beng): remove this file once all includes have been updated. #endif // CHROME_BROWSER_VIEWS_INFOBARS_INFOBARS_H_ + diff --git a/chrome/browser/views/infobars/translate_infobar_base.cc b/chrome/browser/views/infobars/translate_infobar_base.cc deleted file mode 100644 index 4eb0bdd..0000000 --- a/chrome/browser/views/infobars/translate_infobar_base.cc +++ /dev/null @@ -1,178 +0,0 @@ -// Copyright (c) 2010 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/views/infobars/translate_infobar_base.h" - -#include "app/resource_bundle.h" -#include "app/slide_animation.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/translate/translate_infobar_delegate.h" -#include "chrome/browser/views/infobars/after_translate_infobar.h" -#include "chrome/browser/views/infobars/before_translate_infobar.h" -#include "chrome/browser/views/infobars/translate_message_infobar.h" -#include "chrome/browser/views/infobars/infobar_button_border.h" -#include "gfx/canvas_skia.h" -#include "grit/theme_resources.h" -#include "views/controls/button/menu_button.h" -#include "views/controls/image_view.h" - -TranslateInfoBarBase::TranslateInfoBarBase( - TranslateInfoBarDelegate* delegate) - : InfoBar(delegate), - normal_background_(InfoBarDelegate::PAGE_ACTION_TYPE), - error_background_(InfoBarDelegate::WARNING_TYPE) { - icon_ = new views::ImageView; - SkBitmap* image = delegate->GetIcon(); - if (image) - icon_->SetImage(image); - AddChildView(icon_); - - TranslateInfoBarDelegate::BackgroundAnimationType animation = - delegate->background_animation_type(); - if (animation != TranslateInfoBarDelegate::NONE) { - background_color_animation_.reset(new SlideAnimation(this)); - background_color_animation_->SetTweenType(Tween::LINEAR); - background_color_animation_->SetSlideDuration(500); - if (animation == TranslateInfoBarDelegate::NORMAL_TO_ERROR) { - background_color_animation_->Show(); - } else { - DCHECK_EQ(TranslateInfoBarDelegate::ERROR_TO_NORMAL, animation); - // Hide() runs the animation in reverse. - background_color_animation_->Reset(1.0); - background_color_animation_->Hide(); - } - } -} - -TranslateInfoBarBase::~TranslateInfoBarBase() { -} - -// Overridden from views::View: -void TranslateInfoBarBase::Layout() { - // Layout the close button. - InfoBar::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()); -} - -views::Label* TranslateInfoBarBase::CreateLabel(const string16& text) { - views::Label* label = new views::Label(UTF16ToWideHack(text), - ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont)); - label->SetColor(SK_ColorBLACK); - label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - return label; -} - -void TranslateInfoBarBase::PaintBackground(gfx::Canvas* canvas) { - // If we're not animating, simply paint the background for the current state. - if (background_color_animation_ == NULL || - !background_color_animation_->is_animating()) { - GetBackground().Paint(canvas, this); - return; - } - - FadeBackground(canvas, 1.0 - background_color_animation_->GetCurrentValue(), - normal_background_); - FadeBackground(canvas, background_color_animation_->GetCurrentValue(), - error_background_); -} - -void TranslateInfoBarBase::AnimationProgressed(const Animation* animation) { - if (background_color_animation_.get() == animation) - SchedulePaint(); // That'll trigger a PaintBackgroud. - else - InfoBar::AnimationProgressed(animation); -} - -views::MenuButton* TranslateInfoBarBase::CreateMenuButton( - const string16& text, - bool normal_has_border, - views::ViewMenuDelegate* menu_delegate) { - // Don't use text to instantiate MenuButton because we need to set font before - // setting text so that the button will resize to fit the entire text. - views::MenuButton* menu_button = - new views::MenuButton(NULL, std::wstring(), menu_delegate, true); - menu_button->set_border(new InfoBarButtonBorder); - menu_button->set_menu_marker(ResourceBundle::GetSharedInstance(). - GetBitmapNamed(IDR_INFOBARBUTTON_MENU_DROPARROW)); - if (normal_has_border) { - menu_button->SetNormalHasBorder(true); // Normal button state has border. - // Disable animation during state change. - menu_button->SetAnimationDuration(0); - } - // Set font colors for different states. - menu_button->SetEnabledColor(SK_ColorBLACK); - menu_button->SetHighlightColor(SK_ColorBLACK); - menu_button->SetHoverColor(SK_ColorBLACK); - - // Set font then text, then size button to fit text. - menu_button->SetFont(ResourceBundle::GetSharedInstance().GetFont( - ResourceBundle::MediumFont)); - menu_button->SetText(UTF16ToWideHack(text)); - menu_button->ClearMaxTextSize(); - menu_button->SizeToPreferredSize(); - return menu_button; -} - -gfx::Point TranslateInfoBarBase::DetermineMenuPosition( - views::MenuButton* menu_button) { - gfx::Rect lb = menu_button->GetLocalBounds(true); - gfx::Point menu_position(lb.origin()); - menu_position.Offset(2, lb.height() - 3); - if (base::i18n::IsRTL()) - menu_position.Offset(lb.width() - 4, 0); - - View::ConvertPointToScreen(menu_button, &menu_position); -#if defined(OS_WIN) - int left_bound = GetSystemMetrics(SM_XVIRTUALSCREEN); - if (menu_position.x() < left_bound) - menu_position.set_x(left_bound); -#endif - return menu_position; -} - -TranslateInfoBarDelegate* TranslateInfoBarBase::GetDelegate() const { - return static_cast<TranslateInfoBarDelegate*>(delegate()); -} - -const InfoBarBackground& TranslateInfoBarBase::GetBackground() const { - return GetDelegate()->IsError() ? error_background_ : normal_background_; -} - -void TranslateInfoBarBase::FadeBackground(gfx::Canvas* canvas, - double animation_value, - const InfoBarBackground& background) { - // Draw the background into an offscreen buffer with alpha value per animation - // value, then blend it back into the current canvas. - canvas->SaveLayerAlpha(static_cast<int>(animation_value * 255)); - canvas->AsCanvasSkia()->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); - background.Paint(canvas, this); - canvas->Restore(); -} - -// TranslateInfoBarDelegate views specific method: -InfoBar* TranslateInfoBarDelegate::CreateInfoBar() { - TranslateInfoBarBase* infobar = NULL; - switch (type_) { - case BEFORE_TRANSLATE: - infobar = new BeforeTranslateInfoBar(this); - break; - case AFTER_TRANSLATE: - infobar = new AfterTranslateInfoBar(this); - break; - case TRANSLATING: - case TRANSLATION_ERROR: - infobar = new TranslateMessageInfoBar(this); - break; - default: - NOTREACHED(); - } - // Set |infobar_view_| so that the model can notify the infobar when it - // changes. - infobar_view_ = infobar; - return infobar; -} diff --git a/chrome/browser/views/infobars/translate_infobar_base.h b/chrome/browser/views/infobars/translate_infobar_base.h index a16d1ca..84b68dc 100644 --- a/chrome/browser/views/infobars/translate_infobar_base.h +++ b/chrome/browser/views/infobars/translate_infobar_base.h @@ -6,70 +6,8 @@ #define CHROME_BROWSER_VIEWS_INFOBARS_TRANSLATE_INFOBAR_BASE_H_ #pragma once -#include "chrome/browser/translate/translate_infobar_view.h" -#include "chrome/browser/views/infobars/infobars.h" - -class TranslateInfoBarDelegate; - -namespace views { -class MenuButton; -class ViewMenuDelegate; -} - -// This class contains some of the base functionality that translate infobars -// use. -class TranslateInfoBarBase : public TranslateInfoBarView, - public InfoBar { - public: - explicit TranslateInfoBarBase(TranslateInfoBarDelegate* delegate); - virtual ~TranslateInfoBarBase(); - - // TranslateInfoBarView implementation: - virtual void OriginalLanguageChanged() {} - virtual void TargetLanguageChanged() {} - - // Overridden from views::View: - virtual void Layout(); - virtual void PaintBackground(gfx::Canvas* canvas); - - protected: - // Overridden from AnimationDelegate: - virtual void AnimationProgressed(const Animation* animation); - - // Creates a label with the appropriate font and color for the translate - // infobars. - views::Label* CreateLabel(const string16& text); - - // Creates a menu-button with a custom appearance for the translate infobars. - views::MenuButton* CreateMenuButton(const string16& text, - bool normal_has_border, - views::ViewMenuDelegate* menu_delegate); - - // Returns the location at which the menu triggered by |menu_button| should be - // positioned. - gfx::Point DetermineMenuPosition(views::MenuButton* menu_button); - - // Convenience to retrieve the TranslateInfoBarDelegate for this infobar. - TranslateInfoBarDelegate* GetDelegate() const; - - // The translate icon. - views::ImageView* icon_; - - InfoBarBackground normal_background_; - InfoBarBackground error_background_; - scoped_ptr<SlideAnimation> background_color_animation_; - - private: - // Returns the background that should be displayed when not animating. - const InfoBarBackground& GetBackground() const; - - // Paints |background| to |canvas| with the opacity level based on - // |animation_value|. - void FadeBackground(gfx::Canvas* canvas, - double animation_value, - const InfoBarBackground& background); - - DISALLOW_COPY_AND_ASSIGN(TranslateInfoBarBase); -}; +#include "chrome/browser/ui/views/infobars/translate_infobar_base.h" +// TODO(beng): remove this file once all includes have been updated. #endif // CHROME_BROWSER_VIEWS_INFOBARS_TRANSLATE_INFOBAR_BASE_H_ + diff --git a/chrome/browser/views/infobars/translate_message_infobar.cc b/chrome/browser/views/infobars/translate_message_infobar.cc deleted file mode 100644 index 8094d4e..0000000 --- a/chrome/browser/views/infobars/translate_message_infobar.cc +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) 2010 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/views/infobars/translate_message_infobar.h" - -#include "chrome/browser/translate/translate_infobar_delegate.h" -#include "chrome/browser/views/infobars/infobar_text_button.h" -#include "views/controls/image_view.h" - -TranslateMessageInfoBar::TranslateMessageInfoBar( - TranslateInfoBarDelegate* delegate) - : TranslateInfoBarBase(delegate) { - label_ = CreateLabel(delegate->GetMessageInfoBarText()); - AddChildView(label_); - - string16 button_text = delegate->GetMessageInfoBarButtonText(); - if (button_text.empty()) { - button_ = NULL; - } else { - button_ = InfoBarTextButton::Create(this, button_text); - AddChildView(button_); - } -} - -void TranslateMessageInfoBar::Layout() { - TranslateInfoBarBase::Layout(); - - int x = icon_->bounds().right() + InfoBar::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); - } - label_->SetBounds(x, InfoBar::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), - button_pref_size.width(), button_pref_size.height()); - } -} - -void TranslateMessageInfoBar::ButtonPressed(views::Button* sender, - const views::Event& event) { - if (sender == button_) { - GetDelegate()->MessageInfoBarButtonPressed(); - return; - } - TranslateInfoBarBase::ButtonPressed(sender, event); -} diff --git a/chrome/browser/views/infobars/translate_message_infobar.h b/chrome/browser/views/infobars/translate_message_infobar.h index e77bcf2..d893fe7 100644 --- a/chrome/browser/views/infobars/translate_message_infobar.h +++ b/chrome/browser/views/infobars/translate_message_infobar.h @@ -6,24 +6,8 @@ #define CHROME_BROWSER_VIEWS_INFOBARS_TRANSLATE_MESSAGE_INFOBAR_H_ #pragma once -#include "chrome/browser/views/infobars/translate_infobar_base.h" - -class InfoBarTextButton; - -class TranslateMessageInfoBar : public TranslateInfoBarBase { - public: - explicit TranslateMessageInfoBar(TranslateInfoBarDelegate* delegate); - - virtual void Layout(); - - // views::ButtonListener implementation: - virtual void ButtonPressed(views::Button* sender, const views::Event& event); - - private: - views::Label* label_; - InfoBarTextButton* button_; - - DISALLOW_COPY_AND_ASSIGN(TranslateMessageInfoBar); -}; +#include "chrome/browser/ui/views/infobars/translate_message_infobar.h" +// TODO(beng): remove this file once all includes have been updated. #endif // CHROME_BROWSER_VIEWS_INFOBARS_TRANSLATE_MESSAGE_INFOBAR_H_ + |