summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-20 08:45:01 +0000
committermsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-20 08:45:01 +0000
commitc85902c8c6f008debe5d9c87412bd2f1e8d0498e (patch)
treec2a389e584d652678088f7d73df96ccd2442c8fa
parenta03cdee9564290501a3ccf8e4a64b76f4e40fb89 (diff)
downloadchromium_src-c85902c8c6f008debe5d9c87412bd2f1e8d0498e.zip
chromium_src-c85902c8c6f008debe5d9c87412bd2f1e8d0498e.tar.gz
chromium_src-c85902c8c6f008debe5d9c87412bd2f1e8d0498e.tar.bz2
Rebase ExtensionInstalledBubble on the new views bubble.
Move some arrow anchor/location logic; etc. Expose non-const |chevron|, and |location_entry_view|. Add a setter for BubbleDelegateView's |anchor_view|. BUG=98323 TEST=ExtensionInstalledBubbles function as before. Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=110824 Review URL: http://codereview.chromium.org/8590047 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110858 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/ui/views/browser_actions_container.h1
-rw-r--r--chrome/browser/ui/views/extensions/extension_installed_bubble.cc83
-rw-r--r--chrome/browser/ui/views/extensions/extension_installed_bubble.h30
-rw-r--r--chrome/browser/ui/views/location_bar/location_bar_view.h2
-rw-r--r--ui/views/bubble/bubble_delegate.h1
5 files changed, 50 insertions, 67 deletions
diff --git a/chrome/browser/ui/views/browser_actions_container.h b/chrome/browser/ui/views/browser_actions_container.h
index 95a3a71..262b271 100644
--- a/chrome/browser/ui/views/browser_actions_container.h
+++ b/chrome/browser/ui/views/browser_actions_container.h
@@ -279,6 +279,7 @@ class BrowserActionsContainer
bool animating() const { return animation_target_size_ > 0; }
// Returns the chevron, if any.
+ views::View* chevron() { return chevron_; }
const views::View* chevron() const { return chevron_; }
// Returns the profile this container is associated with.
diff --git a/chrome/browser/ui/views/extensions/extension_installed_bubble.cc b/chrome/browser/ui/views/extensions/extension_installed_bubble.cc
index 62288d7..a4e977b 100644
--- a/chrome/browser/ui/views/extensions/extension_installed_bubble.cc
+++ b/chrome/browser/ui/views/extensions/extension_installed_bubble.cc
@@ -29,6 +29,7 @@
#include "grit/theme_resources_standard.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
+#include "ui/views/layout/fill_layout.h"
#include "ui/views/layout/layout_constants.h"
#include "views/controls/button/image_button.h"
#include "views/controls/image_view.h"
@@ -90,10 +91,11 @@ class InstalledBubbleContent : public views::View,
InstalledBubbleContent(Browser* browser,
const Extension* extension,
ExtensionInstalledBubble::BubbleType type,
- SkBitmap* icon)
+ SkBitmap* icon,
+ ExtensionInstalledBubble* bubble)
: browser_(browser),
extension_id_(extension->id()),
- bubble_(NULL),
+ bubble_(bubble),
type_(type),
info_(NULL) {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
@@ -172,17 +174,11 @@ class InstalledBubbleContent : public views::View,
AddChildView(close_button_);
}
- void set_bubble(Bubble* bubble) { bubble_ = bubble; }
-
- virtual void ButtonPressed(
- views::Button* sender,
- const views::Event& event) {
- if (sender == close_button_) {
- bubble_->set_fade_away_on_close(true);
- GetWidget()->Close();
- } else {
+ virtual void ButtonPressed(views::Button* sender, const views::Event& event) {
+ if (sender == close_button_)
+ bubble_->StartFade(false);
+ else
NOTREACHED() << "Unknown view";
- }
}
// Implements the views::LinkListener interface.
@@ -258,8 +254,8 @@ class InstalledBubbleContent : public views::View,
// The id of the extension just installed.
const std::string extension_id_;
- // The Bubble showing us.
- Bubble* bubble_;
+ // The ExtensionInstalledBubble showing us.
+ ExtensionInstalledBubble* bubble_;
ExtensionInstalledBubble::BubbleType type_;
views::ImageView* icon_;
@@ -284,8 +280,6 @@ ExtensionInstalledBubble::ExtensionInstalledBubble(const Extension* extension,
browser_(browser),
icon_(icon),
animation_wait_retries_(0) {
- AddRef(); // Balanced in BubbleClosing.
-
if (extension->is_app()) {
type_ = APP;
} else if (!extension_->omnibox_keyword().empty()) {
@@ -324,7 +318,8 @@ void ExtensionInstalledBubble::Observe(
// PostTask to ourself to allow all EXTENSION_LOADED Observers to run.
MessageLoopForUI::current()->PostTask(
FROM_HERE,
- base::Bind(&ExtensionInstalledBubble::ShowInternal, this));
+ base::Bind(&ExtensionInstalledBubble::ShowInternal,
+ base::Unretained(this)));
}
} else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) {
const Extension* extension =
@@ -339,7 +334,7 @@ void ExtensionInstalledBubble::Observe(
void ExtensionInstalledBubble::ShowInternal() {
BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_);
- const views::View* reference_view = NULL;
+ views::View* reference_view = NULL;
if (type_ == APP) {
if (browser_view->IsTabStripVisible()) {
AbstractTabStripView* tabstrip = browser_view->tabstrip();
@@ -360,7 +355,8 @@ void ExtensionInstalledBubble::ShowInternal() {
// animating, so check back in a little while.
MessageLoopForUI::current()->PostDelayedTask(
FROM_HERE,
- base::Bind(&ExtensionInstalledBubble::ShowInternal, this),
+ base::Bind(&ExtensionInstalledBubble::ShowInternal,
+ base::Unretained(this)),
kAnimationWaitTime);
return;
}
@@ -390,49 +386,38 @@ void ExtensionInstalledBubble::ShowInternal() {
// Default case.
if (reference_view == NULL)
reference_view = browser_view->GetToolbarView()->app_menu();
+ set_anchor_view(reference_view);
- gfx::Point origin;
- views::View::ConvertPointToScreen(reference_view, &origin);
- gfx::Rect bounds = reference_view->bounds();
- bounds.set_origin(origin);
- views::BubbleBorder::ArrowLocation arrow_location =
- views::BubbleBorder::TOP_RIGHT;
+ SetLayoutManager(new views::FillLayout());
+ AddChildView(
+ new InstalledBubbleContent(browser_, extension_, type_, &icon_, this));
+ views::BubbleDelegateView::CreateBubble(this);
+ StartFade(true);
+}
+gfx::Point ExtensionInstalledBubble::GetAnchorPoint() {
// For omnibox keyword bubbles, move the arrow to point to the left edge
// of the omnibox, just to the right of the icon.
if (type_ == OMNIBOX_KEYWORD) {
- bounds.set_origin(
- browser_view->GetLocationBarView()->GetLocationEntryOrigin());
- bounds.set_width(0);
- arrow_location = views::BubbleBorder::TOP_LEFT;
+ LocationBarView* location_bar_view =
+ BrowserView::GetBrowserViewForBrowser(browser_)->GetLocationBarView();
+ return location_bar_view->GetLocationEntryOrigin().Add(
+ gfx::Point(0, location_bar_view->location_entry_view()->height()));
}
+ return views::BubbleDelegateView::GetAnchorPoint();
+}
- bubble_content_ = new InstalledBubbleContent(
- browser_, extension_, type_, &icon_);
- Bubble* bubble = Bubble::Show(browser_view->GetWidget(), bounds,
- arrow_location,
- views::BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR,
- bubble_content_, this);
- bubble_content_->set_bubble(bubble);
+views::BubbleBorder::ArrowLocation
+ ExtensionInstalledBubble::GetArrowLocation() const {
+ return type_ == OMNIBOX_KEYWORD ? views::BubbleBorder::TOP_LEFT :
+ views::BubbleBorder::TOP_RIGHT;
}
-// BubbleDelegate
-void ExtensionInstalledBubble::BubbleClosing(Bubble* bubble,
- bool closed_by_escape) {
+void ExtensionInstalledBubble::WindowClosing() {
if (extension_ && type_ == PAGE_ACTION) {
BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_);
browser_view->GetLocationBarView()->SetPreviewEnabledPageAction(
extension_->page_action(),
false); // preview_enabled
}
-
- Release(); // Balanced in ctor.
-}
-
-bool ExtensionInstalledBubble::CloseOnEscape() {
- return true;
-}
-
-bool ExtensionInstalledBubble::FadeInOnShow() {
- return true;
}
diff --git a/chrome/browser/ui/views/extensions/extension_installed_bubble.h b/chrome/browser/ui/views/extensions/extension_installed_bubble.h
index f269ed1..0688659 100644
--- a/chrome/browser/ui/views/extensions/extension_installed_bubble.h
+++ b/chrome/browser/ui/views/extensions/extension_installed_bubble.h
@@ -6,16 +6,13 @@
#define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_INSTALLED_BUBBLE_H_
#pragma once
-#include "base/memory/ref_counted.h"
-#include "chrome/browser/ui/views/bubble/bubble.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "third_party/skia/include/core/SkBitmap.h"
+#include "ui/views/bubble/bubble_delegate.h"
class Browser;
class Extension;
-class InstalledBubbleContent;
-class SkBitmap;
// Provides feedback to the user upon successful installation of an
// extension. Depending on the type of extension, the Bubble will
@@ -27,12 +24,9 @@ class SkBitmap;
// APP -> The plus button in the tabstrip (for the New Tab Page).
// GENERIC -> The wrench menu. This case includes pageActions that
// don't specify a default icon.
-//
-// ExtensionInstallBubble manages its own lifetime.
class ExtensionInstalledBubble
- : public BubbleDelegate,
- public content::NotificationObserver,
- public base::RefCountedThreadSafe<ExtensionInstalledBubble> {
+ : public views::BubbleDelegateView,
+ public content::NotificationObserver {
public:
// The behavior and content of this Bubble comes in these varieties:
enum BubbleType {
@@ -51,11 +45,10 @@ class ExtensionInstalledBubble
const Extension* extension, Browser *browser, const SkBitmap& icon);
private:
- friend class base::RefCountedThreadSafe<ExtensionInstalledBubble>;
-
// Private ctor. Registers a listener for EXTENSION_LOADED.
- ExtensionInstalledBubble(
- const Extension* extension, Browser *browser, const SkBitmap& icon);
+ ExtensionInstalledBubble(const Extension* extension,
+ Browser *browser,
+ const SkBitmap& icon);
virtual ~ExtensionInstalledBubble();
@@ -67,16 +60,17 @@ class ExtensionInstalledBubble
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
- // BubbleDelegate
- virtual void BubbleClosing(Bubble* bubble, bool closed_by_escape) OVERRIDE;
- virtual bool CloseOnEscape() OVERRIDE;
- virtual bool FadeInOnShow() OVERRIDE;
+ // views::WidgetDelegate
+ virtual void WindowClosing() OVERRIDE;
+
+ // views::BubbleDelegate
+ virtual gfx::Point GetAnchorPoint() OVERRIDE;
+ virtual views::BubbleBorder::ArrowLocation GetArrowLocation() const OVERRIDE;
const Extension* extension_;
Browser* browser_;
SkBitmap icon_;
content::NotificationRegistrar registrar_;
- InstalledBubbleContent* bubble_content_;
BubbleType type_;
// How many times we've deferred due to animations being in progress.
diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.h b/chrome/browser/ui/views/location_bar/location_bar_view.h
index 1f6a8e6..6bf9899 100644
--- a/chrome/browser/ui/views/location_bar/location_bar_view.h
+++ b/chrome/browser/ui/views/location_bar/location_bar_view.h
@@ -202,6 +202,8 @@ class LocationBarView : public LocationBar,
return location_icon_view_;
}
+ views::View* location_entry_view() const { return location_entry_view_; }
+
// AutocompleteEditController
virtual void OnAutocompleteAccept(const GURL& url,
WindowOpenDisposition disposition,
diff --git a/ui/views/bubble/bubble_delegate.h b/ui/views/bubble/bubble_delegate.h
index a2654e1..b31c77d 100644
--- a/ui/views/bubble/bubble_delegate.h
+++ b/ui/views/bubble/bubble_delegate.h
@@ -60,6 +60,7 @@ class VIEWS_EXPORT BubbleDelegateView : public WidgetDelegateView,
}
View* anchor_view() const { return anchor_view_; }
+ void set_anchor_view(View* anchor_view) { anchor_view_ = anchor_view; }
bool use_focusless() const { return use_focusless_; }
void set_use_focusless(bool use_focusless) {