summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralicet@chromium.org <alicet@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-22 02:45:06 +0000
committeralicet@chromium.org <alicet@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-22 02:45:06 +0000
commit017e49b850c956593bdce2d54c4ba4f88341f575 (patch)
tree439a8e79bde0ca6d6c2e9b32b9edd238aa75a84d
parent1eef48cd8c88c68d616de1deffd17178f4cfe596 (diff)
downloadchromium_src-017e49b850c956593bdce2d54c4ba4f88341f575.zip
chromium_src-017e49b850c956593bdce2d54c4ba4f88341f575.tar.gz
chromium_src-017e49b850c956593bdce2d54c4ba4f88341f575.tar.bz2
content settings bubble using new ui/views/bubble api.
BUG=98323 TEST=None Review URL: http://codereview.chromium.org/8603010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111085 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/ui/views/content_setting_bubble_contents.cc112
-rw-r--r--chrome/browser/ui/views/content_setting_bubble_contents.h34
-rw-r--r--chrome/browser/ui/views/location_bar/content_setting_image_view.cc49
-rw-r--r--chrome/browser/ui/views/location_bar/content_setting_image_view.h15
4 files changed, 85 insertions, 125 deletions
diff --git a/chrome/browser/ui/views/content_setting_bubble_contents.cc b/chrome/browser/ui/views/content_setting_bubble_contents.cc
index 56b4687..d4dc5cb 100644
--- a/chrome/browser/ui/views/content_setting_bubble_contents.cc
+++ b/chrome/browser/ui/views/content_setting_bubble_contents.cc
@@ -18,7 +18,6 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
#include "chrome/browser/ui/views/browser_dialogs.h"
-#include "chrome/browser/ui/views/bubble/bubble.h"
#include "content/browser/plugin_service.h"
#include "content/browser/tab_contents/tab_contents.h"
#include "content/public/browser/notification_source.h"
@@ -107,11 +106,13 @@ gfx::NativeCursor ContentSettingBubbleContents::Favicon::GetCursor(
ContentSettingBubbleContents::ContentSettingBubbleContents(
ContentSettingBubbleModel* content_setting_bubble_model,
Profile* profile,
- TabContents* tab_contents)
- : content_setting_bubble_model_(content_setting_bubble_model),
+ TabContents* tab_contents,
+ views::View* anchor_view,
+ views::BubbleBorder::ArrowLocation arrow_location)
+ : BubbleDelegateView(anchor_view, arrow_location, SK_ColorWHITE),
+ content_setting_bubble_model_(content_setting_bubble_model),
profile_(profile),
tab_contents_(tab_contents),
- bubble_(NULL),
custom_link_(NULL),
manage_link_(NULL),
close_button_(NULL) {
@@ -132,62 +133,11 @@ gfx::Size ContentSettingBubbleContents::GetPreferredSize() {
return preferred_size;
}
-void ContentSettingBubbleContents::ViewHierarchyChanged(bool is_add,
- View* parent,
- View* child) {
- if (is_add && (child == this))
- InitControlLayout();
+gfx::Point ContentSettingBubbleContents::GetAnchorPoint() {
+ return BubbleDelegateView::GetAnchorPoint().Subtract(gfx::Point(0, 5));
}
-void ContentSettingBubbleContents::ButtonPressed(views::Button* sender,
- const views::Event& event) {
- if (sender == close_button_) {
- bubble_->set_fade_away_on_close(true);
- bubble_->Close(); // CAREFUL: This deletes us.
- return;
- }
-
- for (RadioGroup::const_iterator i = radio_group_.begin();
- i != radio_group_.end(); ++i) {
- if (sender == *i) {
- content_setting_bubble_model_->OnRadioClicked(i - radio_group_.begin());
- return;
- }
- }
- NOTREACHED() << "unknown radio";
-}
-
-void ContentSettingBubbleContents::LinkClicked(views::Link* source,
- int event_flags) {
- if (source == custom_link_) {
- content_setting_bubble_model_->OnCustomLinkClicked();
- bubble_->set_fade_away_on_close(true);
- bubble_->Close(); // CAREFUL: This deletes us.
- return;
- }
- if (source == manage_link_) {
- bubble_->set_fade_away_on_close(true);
- content_setting_bubble_model_->OnManageLinkClicked();
- // CAREFUL: Showing the settings window activates it, which deactivates the
- // info bubble, which causes it to close, which deletes us.
- return;
- }
-
- PopupLinks::const_iterator i(popup_links_.find(source));
- DCHECK(i != popup_links_.end());
- content_setting_bubble_model_->OnPopupClicked(i->second);
-}
-
-void ContentSettingBubbleContents::Observe(
- int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- DCHECK(type == content::NOTIFICATION_TAB_CONTENTS_DESTROYED);
- DCHECK(source == content::Source<TabContents>(tab_contents_));
- tab_contents_ = NULL;
-}
-
-void ContentSettingBubbleContents::InitControlLayout() {
+void ContentSettingBubbleContents::Init() {
using views::GridLayout;
GridLayout* layout = new views::GridLayout(this);
@@ -340,3 +290,49 @@ void ContentSettingBubbleContents::InitControlLayout() {
this, l10n_util::GetStringUTF16(IDS_DONE));
layout->AddView(close_button_);
}
+
+void ContentSettingBubbleContents::ButtonPressed(views::Button* sender,
+ const views::Event& event) {
+ if (sender == close_button_) {
+ StartFade(false);
+ return;
+ }
+
+ for (RadioGroup::const_iterator i = radio_group_.begin();
+ i != radio_group_.end(); ++i) {
+ if (sender == *i) {
+ content_setting_bubble_model_->OnRadioClicked(i - radio_group_.begin());
+ return;
+ }
+ }
+ NOTREACHED() << "unknown radio";
+}
+
+void ContentSettingBubbleContents::LinkClicked(views::Link* source,
+ int event_flags) {
+ if (source == custom_link_) {
+ content_setting_bubble_model_->OnCustomLinkClicked();
+ StartFade(false);
+ return;
+ }
+ if (source == manage_link_) {
+ StartFade(false);
+ content_setting_bubble_model_->OnManageLinkClicked();
+ // CAREFUL: Showing the settings window activates it, which deactivates the
+ // info bubble, which causes it to close, which deletes us.
+ return;
+ }
+
+ PopupLinks::const_iterator i(popup_links_.find(source));
+ DCHECK(i != popup_links_.end());
+ content_setting_bubble_model_->OnPopupClicked(i->second);
+}
+
+void ContentSettingBubbleContents::Observe(
+ int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ DCHECK(type == content::NOTIFICATION_TAB_CONTENTS_DESTROYED);
+ DCHECK(source == content::Source<TabContents>(tab_contents_));
+ tab_contents_ = NULL;
+}
diff --git a/chrome/browser/ui/views/content_setting_bubble_contents.h b/chrome/browser/ui/views/content_setting_bubble_contents.h
index 4ea5ced..23e7902 100644
--- a/chrome/browser/ui/views/content_setting_bubble_contents.h
+++ b/chrome/browser/ui/views/content_setting_bubble_contents.h
@@ -13,6 +13,7 @@
#include "chrome/common/content_settings_types.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
+#include "ui/views/bubble/bubble_delegate.h"
#include "views/controls/button/button.h"
#include "views/controls/link_listener.h"
@@ -26,7 +27,6 @@
// get to a more comprehensive settings management dialog. A few types have
// more or fewer controls than this.
-class Bubble;
class ContentSettingBubbleModel;
class Profile;
class TabContents;
@@ -36,32 +36,36 @@ class TextButton;
class RadioButton;
}
-class ContentSettingBubbleContents : public views::View,
+class ContentSettingBubbleContents : public views::BubbleDelegateView,
public views::ButtonListener,
public views::LinkListener,
public content::NotificationObserver {
public:
ContentSettingBubbleContents(
ContentSettingBubbleModel* content_setting_bubble_model,
- Profile* profile, TabContents* tab_contents);
+ Profile* profile,
+ TabContents* tab_contents,
+ views::View* anchor_view,
+ views::BubbleBorder::ArrowLocation arrow_location);
virtual ~ContentSettingBubbleContents();
- // Sets |bubble_|, so we can close the bubble if needed. The caller owns
- // the bubble and must keep it alive.
- void set_bubble(Bubble* bubble) { bubble_ = bubble; }
-
virtual gfx::Size GetPreferredSize();
+ // views::BubbleDelegateView:
+ virtual gfx::Point GetAnchorPoint() OVERRIDE;
+
+ protected:
+ // views::BubbleDelegateView:
+ virtual void Init() OVERRIDE;
+
private:
class Favicon;
typedef std::map<views::Link*, int> PopupLinks;
- // Overridden from views::View:
- virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child);
-
// views::ButtonListener:
- virtual void ButtonPressed(views::Button* sender, const views::Event& event);
+ virtual void ButtonPressed(views::Button* sender,
+ const views::Event& event) OVERRIDE;
// views::LinkListener:
virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
@@ -69,10 +73,7 @@ class ContentSettingBubbleContents : public views::View,
// content::NotificationObserver:
virtual void Observe(int type,
const content::NotificationSource& source,
- const content::NotificationDetails& details);
-
- // Creates the child views.
- void InitControlLayout();
+ const content::NotificationDetails& details) OVERRIDE;
// Provides data for this bubble.
scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model_;
@@ -86,9 +87,6 @@ class ContentSettingBubbleContents : public views::View,
// A registrar for listening for TAB_CONTENTS_DESTROYED notifications.
content::NotificationRegistrar registrar_;
- // The Bubble holding us.
- Bubble* bubble_;
-
// Some of our controls, so we can tell what's been clicked when we get a
// message.
PopupLinks popup_links_;
diff --git a/chrome/browser/ui/views/location_bar/content_setting_image_view.cc b/chrome/browser/ui/views/location_bar/content_setting_image_view.cc
index d6cebb2..9c790cf 100644
--- a/chrome/browser/ui/views/location_bar/content_setting_image_view.cc
+++ b/chrome/browser/ui/views/location_bar/content_setting_image_view.cc
@@ -52,7 +52,6 @@ ContentSettingImageView::ContentSettingImageView(
ContentSettingImageModel::CreateContentSettingImageModel(
content_type)),
parent_(parent),
- bubble_(NULL),
animation_in_progress_(false),
text_size_(0),
visible_text_size_(0) {
@@ -60,8 +59,6 @@ ContentSettingImageView::ContentSettingImageView(
}
ContentSettingImageView::~ContentSettingImageView() {
- if (bubble_)
- bubble_->Close();
}
void ContentSettingImageView::UpdateFromTabContents(TabContents* tab_contents) {
@@ -131,28 +128,19 @@ void ContentSettingImageView::OnMouseReleased(const views::MouseEvent& event) {
if (!tab_contents)
return;
- gfx::Rect screen_bounds(GetImageBounds());
- gfx::Point origin(screen_bounds.origin());
- views::View::ConvertPointToScreen(this, &origin);
- screen_bounds.set_origin(origin);
Profile* profile = parent_->browser()->profile();
- ContentSettingBubbleContents* bubble_contents =
- new ContentSettingBubbleContents(
- ContentSettingBubbleModel::CreateContentSettingBubbleModel(
- parent_->browser(), tab_contents, profile,
- content_setting_image_model_->get_content_settings_type()),
- profile, tab_contents->tab_contents());
- bubble_ = Bubble::Show(GetWidget(), screen_bounds,
- views::BubbleBorder::TOP_RIGHT,
- views::BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR,
- bubble_contents, this);
- bubble_contents->set_bubble(bubble_);
-}
-
-void ContentSettingImageView::VisibilityChanged(View* starting_from,
- bool is_visible) {
- if (!is_visible && bubble_)
- bubble_->Close();
+ ContentSettingBubbleContents* bubble = new ContentSettingBubbleContents(
+ ContentSettingBubbleModel::CreateContentSettingBubbleModel(
+ parent_->browser(),
+ tab_contents,
+ profile,
+ content_setting_image_model_->get_content_settings_type()),
+ profile,
+ tab_contents->tab_contents(),
+ this,
+ views::BubbleBorder::TOP_RIGHT);
+ views::BubbleDelegateView::CreateBubble(bubble);
+ bubble->Show();
}
void ContentSettingImageView::OnPaint(gfx::Canvas* canvas) {
@@ -214,19 +202,6 @@ void ContentSettingImageView::OnPaintBackground(gfx::Canvas* canvas) {
kBoxCornerRadius, outer_paint);
}
-void ContentSettingImageView::BubbleClosing(Bubble* bubble,
- bool closed_by_escape) {
- bubble_ = NULL;
-}
-
-bool ContentSettingImageView::CloseOnEscape() {
- return true;
-}
-
-bool ContentSettingImageView::FadeInOnShow() {
- return false;
-}
-
void ContentSettingImageView::AnimateToState(double state) {
if (state >= 1.0) {
// Animaton is over, clear the variables.
diff --git a/chrome/browser/ui/views/location_bar/content_setting_image_view.h b/chrome/browser/ui/views/location_bar/content_setting_image_view.h
index 3a948dd..5f6a339 100644
--- a/chrome/browser/ui/views/location_bar/content_setting_image_view.h
+++ b/chrome/browser/ui/views/location_bar/content_setting_image_view.h
@@ -8,13 +8,12 @@
#include "base/memory/scoped_ptr.h"
#include "base/string16.h"
-#include "chrome/browser/ui/views/bubble/bubble.h"
#include "chrome/common/content_settings_types.h"
#include "ui/base/animation/linear_animation.h"
#include "views/controls/image_view.h"
class ContentSettingImageModel;
-class Bubble;
+class ContentSettingBubbleContents;
class LocationBarView;
class TabContents;
@@ -22,8 +21,9 @@ namespace views {
class MouseEvent;
}
+class ContentSettingsDelegateView;
+
class ContentSettingImageView : public views::ImageView,
- public BubbleDelegate,
public ui::LinearAnimation {
public:
ContentSettingImageView(ContentSettingsType content_type,
@@ -41,15 +41,9 @@ class ContentSettingImageView : public views::ImageView,
// views::ImageView overrides:
virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE;
virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE;
- virtual void VisibilityChanged(View* starting_from, bool is_visible) OVERRIDE;
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE;
- // BubbleDelegate overrides:
- virtual void BubbleClosing(Bubble* bubble, bool closed_by_escape) OVERRIDE;
- virtual bool CloseOnEscape() OVERRIDE;
- virtual bool FadeInOnShow() OVERRIDE;
-
// ui::LinearAnimation override:
virtual void AnimateToState(double state) OVERRIDE;
@@ -58,9 +52,6 @@ class ContentSettingImageView : public views::ImageView,
// The owning LocationBarView.
LocationBarView* parent_;
- // The currently shown info bubble if any.
- Bubble* bubble_;
-
string16 animated_text_;
bool animation_in_progress_;
int text_size_;