Commit 017e49b8 authored by alicet@chromium.org's avatar alicet@chromium.org

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
parent 1eef48cd
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/content_settings/content_setting_bubble_model.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/browser_dialogs.h"
#include "chrome/browser/ui/views/bubble/bubble.h"
#include "content/browser/plugin_service.h" #include "content/browser/plugin_service.h"
#include "content/browser/tab_contents/tab_contents.h" #include "content/browser/tab_contents/tab_contents.h"
#include "content/public/browser/notification_source.h" #include "content/public/browser/notification_source.h"
...@@ -107,11 +106,13 @@ gfx::NativeCursor ContentSettingBubbleContents::Favicon::GetCursor( ...@@ -107,11 +106,13 @@ gfx::NativeCursor ContentSettingBubbleContents::Favicon::GetCursor(
ContentSettingBubbleContents::ContentSettingBubbleContents( ContentSettingBubbleContents::ContentSettingBubbleContents(
ContentSettingBubbleModel* content_setting_bubble_model, ContentSettingBubbleModel* content_setting_bubble_model,
Profile* profile, Profile* profile,
TabContents* tab_contents) TabContents* tab_contents,
: content_setting_bubble_model_(content_setting_bubble_model), 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), profile_(profile),
tab_contents_(tab_contents), tab_contents_(tab_contents),
bubble_(NULL),
custom_link_(NULL), custom_link_(NULL),
manage_link_(NULL), manage_link_(NULL),
close_button_(NULL) { close_button_(NULL) {
...@@ -132,62 +133,11 @@ gfx::Size ContentSettingBubbleContents::GetPreferredSize() { ...@@ -132,62 +133,11 @@ gfx::Size ContentSettingBubbleContents::GetPreferredSize() {
return preferred_size; return preferred_size;
} }
void ContentSettingBubbleContents::ViewHierarchyChanged(bool is_add, gfx::Point ContentSettingBubbleContents::GetAnchorPoint() {
View* parent, return BubbleDelegateView::GetAnchorPoint().Subtract(gfx::Point(0, 5));
View* child) {
if (is_add && (child == this))
InitControlLayout();
} }
void ContentSettingBubbleContents::ButtonPressed(views::Button* sender, void ContentSettingBubbleContents::Init() {
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() {
using views::GridLayout; using views::GridLayout;
GridLayout* layout = new views::GridLayout(this); GridLayout* layout = new views::GridLayout(this);
...@@ -340,3 +290,49 @@ void ContentSettingBubbleContents::InitControlLayout() { ...@@ -340,3 +290,49 @@ void ContentSettingBubbleContents::InitControlLayout() {
this, l10n_util::GetStringUTF16(IDS_DONE)); this, l10n_util::GetStringUTF16(IDS_DONE));
layout->AddView(close_button_); 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;
}
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "chrome/common/content_settings_types.h" #include "chrome/common/content_settings_types.h"
#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "ui/views/bubble/bubble_delegate.h"
#include "views/controls/button/button.h" #include "views/controls/button/button.h"
#include "views/controls/link_listener.h" #include "views/controls/link_listener.h"
...@@ -26,7 +27,6 @@ ...@@ -26,7 +27,6 @@
// get to a more comprehensive settings management dialog. A few types have // get to a more comprehensive settings management dialog. A few types have
// more or fewer controls than this. // more or fewer controls than this.
class Bubble;
class ContentSettingBubbleModel; class ContentSettingBubbleModel;
class Profile; class Profile;
class TabContents; class TabContents;
...@@ -36,32 +36,36 @@ class TextButton; ...@@ -36,32 +36,36 @@ class TextButton;
class RadioButton; class RadioButton;
} }
class ContentSettingBubbleContents : public views::View, class ContentSettingBubbleContents : public views::BubbleDelegateView,
public views::ButtonListener, public views::ButtonListener,
public views::LinkListener, public views::LinkListener,
public content::NotificationObserver { public content::NotificationObserver {
public: public:
ContentSettingBubbleContents( ContentSettingBubbleContents(
ContentSettingBubbleModel* content_setting_bubble_model, 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(); 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(); virtual gfx::Size GetPreferredSize();
// views::BubbleDelegateView:
virtual gfx::Point GetAnchorPoint() OVERRIDE;
protected:
// views::BubbleDelegateView:
virtual void Init() OVERRIDE;
private: private:
class Favicon; class Favicon;
typedef std::map<views::Link*, int> PopupLinks; typedef std::map<views::Link*, int> PopupLinks;
// Overridden from views::View:
virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child);
// views::ButtonListener: // 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: // views::LinkListener:
virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
...@@ -69,10 +73,7 @@ class ContentSettingBubbleContents : public views::View, ...@@ -69,10 +73,7 @@ class ContentSettingBubbleContents : public views::View,
// content::NotificationObserver: // content::NotificationObserver:
virtual void Observe(int type, virtual void Observe(int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details); const content::NotificationDetails& details) OVERRIDE;
// Creates the child views.
void InitControlLayout();
// Provides data for this bubble. // Provides data for this bubble.
scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model_; scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model_;
...@@ -86,9 +87,6 @@ class ContentSettingBubbleContents : public views::View, ...@@ -86,9 +87,6 @@ class ContentSettingBubbleContents : public views::View,
// A registrar for listening for TAB_CONTENTS_DESTROYED notifications. // A registrar for listening for TAB_CONTENTS_DESTROYED notifications.
content::NotificationRegistrar registrar_; 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 // Some of our controls, so we can tell what's been clicked when we get a
// message. // message.
PopupLinks popup_links_; PopupLinks popup_links_;
......
...@@ -52,7 +52,6 @@ ContentSettingImageView::ContentSettingImageView( ...@@ -52,7 +52,6 @@ ContentSettingImageView::ContentSettingImageView(
ContentSettingImageModel::CreateContentSettingImageModel( ContentSettingImageModel::CreateContentSettingImageModel(
content_type)), content_type)),
parent_(parent), parent_(parent),
bubble_(NULL),
animation_in_progress_(false), animation_in_progress_(false),
text_size_(0), text_size_(0),
visible_text_size_(0) { visible_text_size_(0) {
...@@ -60,8 +59,6 @@ ContentSettingImageView::ContentSettingImageView( ...@@ -60,8 +59,6 @@ ContentSettingImageView::ContentSettingImageView(
} }
ContentSettingImageView::~ContentSettingImageView() { ContentSettingImageView::~ContentSettingImageView() {
if (bubble_)
bubble_->Close();
} }
void ContentSettingImageView::UpdateFromTabContents(TabContents* tab_contents) { void ContentSettingImageView::UpdateFromTabContents(TabContents* tab_contents) {
...@@ -131,28 +128,19 @@ void ContentSettingImageView::OnMouseReleased(const views::MouseEvent& event) { ...@@ -131,28 +128,19 @@ void ContentSettingImageView::OnMouseReleased(const views::MouseEvent& event) {
if (!tab_contents) if (!tab_contents)
return; 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(); Profile* profile = parent_->browser()->profile();
ContentSettingBubbleContents* bubble_contents = ContentSettingBubbleContents* bubble = new ContentSettingBubbleContents(
new ContentSettingBubbleContents( ContentSettingBubbleModel::CreateContentSettingBubbleModel(
ContentSettingBubbleModel::CreateContentSettingBubbleModel( parent_->browser(),
parent_->browser(), tab_contents, profile, tab_contents,
content_setting_image_model_->get_content_settings_type()), profile,
profile, tab_contents->tab_contents()); content_setting_image_model_->get_content_settings_type()),
bubble_ = Bubble::Show(GetWidget(), screen_bounds, profile,
views::BubbleBorder::TOP_RIGHT, tab_contents->tab_contents(),
views::BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR, this,
bubble_contents, this); views::BubbleBorder::TOP_RIGHT);
bubble_contents->set_bubble(bubble_); views::BubbleDelegateView::CreateBubble(bubble);
} bubble->Show();
void ContentSettingImageView::VisibilityChanged(View* starting_from,
bool is_visible) {
if (!is_visible && bubble_)
bubble_->Close();
} }
void ContentSettingImageView::OnPaint(gfx::Canvas* canvas) { void ContentSettingImageView::OnPaint(gfx::Canvas* canvas) {
...@@ -214,19 +202,6 @@ void ContentSettingImageView::OnPaintBackground(gfx::Canvas* canvas) { ...@@ -214,19 +202,6 @@ void ContentSettingImageView::OnPaintBackground(gfx::Canvas* canvas) {
kBoxCornerRadius, outer_paint); 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) { void ContentSettingImageView::AnimateToState(double state) {
if (state >= 1.0) { if (state >= 1.0) {
// Animaton is over, clear the variables. // Animaton is over, clear the variables.
......
...@@ -8,13 +8,12 @@ ...@@ -8,13 +8,12 @@
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/string16.h" #include "base/string16.h"
#include "chrome/browser/ui/views/bubble/bubble.h"
#include "chrome/common/content_settings_types.h" #include "chrome/common/content_settings_types.h"
#include "ui/base/animation/linear_animation.h" #include "ui/base/animation/linear_animation.h"
#include "views/controls/image_view.h" #include "views/controls/image_view.h"
class ContentSettingImageModel; class ContentSettingImageModel;
class Bubble; class ContentSettingBubbleContents;
class LocationBarView; class LocationBarView;
class TabContents; class TabContents;
...@@ -22,8 +21,9 @@ namespace views { ...@@ -22,8 +21,9 @@ namespace views {
class MouseEvent; class MouseEvent;
} }
class ContentSettingsDelegateView;
class ContentSettingImageView : public views::ImageView, class ContentSettingImageView : public views::ImageView,
public BubbleDelegate,
public ui::LinearAnimation { public ui::LinearAnimation {
public: public:
ContentSettingImageView(ContentSettingsType content_type, ContentSettingImageView(ContentSettingsType content_type,
...@@ -41,15 +41,9 @@ class ContentSettingImageView : public views::ImageView, ...@@ -41,15 +41,9 @@ class ContentSettingImageView : public views::ImageView,
// views::ImageView overrides: // views::ImageView overrides:
virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE; virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE;
virtual void OnMouseReleased(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 OnPaint(gfx::Canvas* canvas) OVERRIDE;
virtual void OnPaintBackground(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: // ui::LinearAnimation override:
virtual void AnimateToState(double state) OVERRIDE; virtual void AnimateToState(double state) OVERRIDE;
...@@ -58,9 +52,6 @@ class ContentSettingImageView : public views::ImageView, ...@@ -58,9 +52,6 @@ class ContentSettingImageView : public views::ImageView,
// The owning LocationBarView. // The owning LocationBarView.
LocationBarView* parent_; LocationBarView* parent_;
// The currently shown info bubble if any.
Bubble* bubble_;
string16 animated_text_; string16 animated_text_;
bool animation_in_progress_; bool animation_in_progress_;
int text_size_; int text_size_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment