Commit c85902c8 authored by msw@chromium.org's avatar msw@chromium.org

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
parent a03cdee9
...@@ -279,6 +279,7 @@ class BrowserActionsContainer ...@@ -279,6 +279,7 @@ class BrowserActionsContainer
bool animating() const { return animation_target_size_ > 0; } bool animating() const { return animation_target_size_ > 0; }
// Returns the chevron, if any. // Returns the chevron, if any.
views::View* chevron() { return chevron_; }
const views::View* chevron() const { return chevron_; } const views::View* chevron() const { return chevron_; }
// Returns the profile this container is associated with. // Returns the profile this container is associated with.
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "grit/theme_resources_standard.h" #include "grit/theme_resources_standard.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/layout/layout_constants.h" #include "ui/views/layout/layout_constants.h"
#include "views/controls/button/image_button.h" #include "views/controls/button/image_button.h"
#include "views/controls/image_view.h" #include "views/controls/image_view.h"
...@@ -90,10 +91,11 @@ class InstalledBubbleContent : public views::View, ...@@ -90,10 +91,11 @@ class InstalledBubbleContent : public views::View,
InstalledBubbleContent(Browser* browser, InstalledBubbleContent(Browser* browser,
const Extension* extension, const Extension* extension,
ExtensionInstalledBubble::BubbleType type, ExtensionInstalledBubble::BubbleType type,
SkBitmap* icon) SkBitmap* icon,
ExtensionInstalledBubble* bubble)
: browser_(browser), : browser_(browser),
extension_id_(extension->id()), extension_id_(extension->id()),
bubble_(NULL), bubble_(bubble),
type_(type), type_(type),
info_(NULL) { info_(NULL) {
ResourceBundle& rb = ResourceBundle::GetSharedInstance(); ResourceBundle& rb = ResourceBundle::GetSharedInstance();
...@@ -172,17 +174,11 @@ class InstalledBubbleContent : public views::View, ...@@ -172,17 +174,11 @@ class InstalledBubbleContent : public views::View,
AddChildView(close_button_); AddChildView(close_button_);
} }
void set_bubble(Bubble* bubble) { bubble_ = bubble; } virtual void ButtonPressed(views::Button* sender, const views::Event& event) {
if (sender == close_button_)
virtual void ButtonPressed( bubble_->StartFade(false);
views::Button* sender, else
const views::Event& event) {
if (sender == close_button_) {
bubble_->set_fade_away_on_close(true);
GetWidget()->Close();
} else {
NOTREACHED() << "Unknown view"; NOTREACHED() << "Unknown view";
}
} }
// Implements the views::LinkListener interface. // Implements the views::LinkListener interface.
...@@ -258,8 +254,8 @@ class InstalledBubbleContent : public views::View, ...@@ -258,8 +254,8 @@ class InstalledBubbleContent : public views::View,
// The id of the extension just installed. // The id of the extension just installed.
const std::string extension_id_; const std::string extension_id_;
// The Bubble showing us. // The ExtensionInstalledBubble showing us.
Bubble* bubble_; ExtensionInstalledBubble* bubble_;
ExtensionInstalledBubble::BubbleType type_; ExtensionInstalledBubble::BubbleType type_;
views::ImageView* icon_; views::ImageView* icon_;
...@@ -284,8 +280,6 @@ ExtensionInstalledBubble::ExtensionInstalledBubble(const Extension* extension, ...@@ -284,8 +280,6 @@ ExtensionInstalledBubble::ExtensionInstalledBubble(const Extension* extension,
browser_(browser), browser_(browser),
icon_(icon), icon_(icon),
animation_wait_retries_(0) { animation_wait_retries_(0) {
AddRef(); // Balanced in BubbleClosing.
if (extension->is_app()) { if (extension->is_app()) {
type_ = APP; type_ = APP;
} else if (!extension_->omnibox_keyword().empty()) { } else if (!extension_->omnibox_keyword().empty()) {
...@@ -324,7 +318,8 @@ void ExtensionInstalledBubble::Observe( ...@@ -324,7 +318,8 @@ void ExtensionInstalledBubble::Observe(
// PostTask to ourself to allow all EXTENSION_LOADED Observers to run. // PostTask to ourself to allow all EXTENSION_LOADED Observers to run.
MessageLoopForUI::current()->PostTask( MessageLoopForUI::current()->PostTask(
FROM_HERE, FROM_HERE,
base::Bind(&ExtensionInstalledBubble::ShowInternal, this)); base::Bind(&ExtensionInstalledBubble::ShowInternal,
base::Unretained(this)));
} }
} else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) { } else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) {
const Extension* extension = const Extension* extension =
...@@ -339,7 +334,7 @@ void ExtensionInstalledBubble::Observe( ...@@ -339,7 +334,7 @@ void ExtensionInstalledBubble::Observe(
void ExtensionInstalledBubble::ShowInternal() { void ExtensionInstalledBubble::ShowInternal() {
BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_);
const views::View* reference_view = NULL; views::View* reference_view = NULL;
if (type_ == APP) { if (type_ == APP) {
if (browser_view->IsTabStripVisible()) { if (browser_view->IsTabStripVisible()) {
AbstractTabStripView* tabstrip = browser_view->tabstrip(); AbstractTabStripView* tabstrip = browser_view->tabstrip();
...@@ -360,7 +355,8 @@ void ExtensionInstalledBubble::ShowInternal() { ...@@ -360,7 +355,8 @@ void ExtensionInstalledBubble::ShowInternal() {
// animating, so check back in a little while. // animating, so check back in a little while.
MessageLoopForUI::current()->PostDelayedTask( MessageLoopForUI::current()->PostDelayedTask(
FROM_HERE, FROM_HERE,
base::Bind(&ExtensionInstalledBubble::ShowInternal, this), base::Bind(&ExtensionInstalledBubble::ShowInternal,
base::Unretained(this)),
kAnimationWaitTime); kAnimationWaitTime);
return; return;
} }
...@@ -390,49 +386,38 @@ void ExtensionInstalledBubble::ShowInternal() { ...@@ -390,49 +386,38 @@ void ExtensionInstalledBubble::ShowInternal() {
// Default case. // Default case.
if (reference_view == NULL) if (reference_view == NULL)
reference_view = browser_view->GetToolbarView()->app_menu(); reference_view = browser_view->GetToolbarView()->app_menu();
set_anchor_view(reference_view);
gfx::Point origin; SetLayoutManager(new views::FillLayout());
views::View::ConvertPointToScreen(reference_view, &origin); AddChildView(
gfx::Rect bounds = reference_view->bounds(); new InstalledBubbleContent(browser_, extension_, type_, &icon_, this));
bounds.set_origin(origin); views::BubbleDelegateView::CreateBubble(this);
views::BubbleBorder::ArrowLocation arrow_location = StartFade(true);
views::BubbleBorder::TOP_RIGHT; }
gfx::Point ExtensionInstalledBubble::GetAnchorPoint() {
// For omnibox keyword bubbles, move the arrow to point to the left edge // For omnibox keyword bubbles, move the arrow to point to the left edge
// of the omnibox, just to the right of the icon. // of the omnibox, just to the right of the icon.
if (type_ == OMNIBOX_KEYWORD) { if (type_ == OMNIBOX_KEYWORD) {
bounds.set_origin( LocationBarView* location_bar_view =
browser_view->GetLocationBarView()->GetLocationEntryOrigin()); BrowserView::GetBrowserViewForBrowser(browser_)->GetLocationBarView();
bounds.set_width(0); return location_bar_view->GetLocationEntryOrigin().Add(
arrow_location = views::BubbleBorder::TOP_LEFT; gfx::Point(0, location_bar_view->location_entry_view()->height()));
} }
return views::BubbleDelegateView::GetAnchorPoint();
}
bubble_content_ = new InstalledBubbleContent( views::BubbleBorder::ArrowLocation
browser_, extension_, type_, &icon_); ExtensionInstalledBubble::GetArrowLocation() const {
Bubble* bubble = Bubble::Show(browser_view->GetWidget(), bounds, return type_ == OMNIBOX_KEYWORD ? views::BubbleBorder::TOP_LEFT :
arrow_location, views::BubbleBorder::TOP_RIGHT;
views::BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR,
bubble_content_, this);
bubble_content_->set_bubble(bubble);
} }
// BubbleDelegate void ExtensionInstalledBubble::WindowClosing() {
void ExtensionInstalledBubble::BubbleClosing(Bubble* bubble,
bool closed_by_escape) {
if (extension_ && type_ == PAGE_ACTION) { if (extension_ && type_ == PAGE_ACTION) {
BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_);
browser_view->GetLocationBarView()->SetPreviewEnabledPageAction( browser_view->GetLocationBarView()->SetPreviewEnabledPageAction(
extension_->page_action(), extension_->page_action(),
false); // preview_enabled false); // preview_enabled
} }
Release(); // Balanced in ctor.
}
bool ExtensionInstalledBubble::CloseOnEscape() {
return true;
}
bool ExtensionInstalledBubble::FadeInOnShow() {
return true;
} }
...@@ -6,16 +6,13 @@ ...@@ -6,16 +6,13 @@
#define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_INSTALLED_BUBBLE_H_ #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_INSTALLED_BUBBLE_H_
#pragma once #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_observer.h"
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
#include "ui/views/bubble/bubble_delegate.h"
class Browser; class Browser;
class Extension; class Extension;
class InstalledBubbleContent;
class SkBitmap;
// Provides feedback to the user upon successful installation of an // Provides feedback to the user upon successful installation of an
// extension. Depending on the type of extension, the Bubble will // extension. Depending on the type of extension, the Bubble will
...@@ -27,12 +24,9 @@ class SkBitmap; ...@@ -27,12 +24,9 @@ class SkBitmap;
// APP -> The plus button in the tabstrip (for the New Tab Page). // APP -> The plus button in the tabstrip (for the New Tab Page).
// GENERIC -> The wrench menu. This case includes pageActions that // GENERIC -> The wrench menu. This case includes pageActions that
// don't specify a default icon. // don't specify a default icon.
//
// ExtensionInstallBubble manages its own lifetime.
class ExtensionInstalledBubble class ExtensionInstalledBubble
: public BubbleDelegate, : public views::BubbleDelegateView,
public content::NotificationObserver, public content::NotificationObserver {
public base::RefCountedThreadSafe<ExtensionInstalledBubble> {
public: public:
// The behavior and content of this Bubble comes in these varieties: // The behavior and content of this Bubble comes in these varieties:
enum BubbleType { enum BubbleType {
...@@ -51,11 +45,10 @@ class ExtensionInstalledBubble ...@@ -51,11 +45,10 @@ class ExtensionInstalledBubble
const Extension* extension, Browser *browser, const SkBitmap& icon); const Extension* extension, Browser *browser, const SkBitmap& icon);
private: private:
friend class base::RefCountedThreadSafe<ExtensionInstalledBubble>;
// Private ctor. Registers a listener for EXTENSION_LOADED. // Private ctor. Registers a listener for EXTENSION_LOADED.
ExtensionInstalledBubble( ExtensionInstalledBubble(const Extension* extension,
const Extension* extension, Browser *browser, const SkBitmap& icon); Browser *browser,
const SkBitmap& icon);
virtual ~ExtensionInstalledBubble(); virtual ~ExtensionInstalledBubble();
...@@ -67,16 +60,17 @@ class ExtensionInstalledBubble ...@@ -67,16 +60,17 @@ class ExtensionInstalledBubble
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE; const content::NotificationDetails& details) OVERRIDE;
// BubbleDelegate // views::WidgetDelegate
virtual void BubbleClosing(Bubble* bubble, bool closed_by_escape) OVERRIDE; virtual void WindowClosing() OVERRIDE;
virtual bool CloseOnEscape() OVERRIDE;
virtual bool FadeInOnShow() OVERRIDE; // views::BubbleDelegate
virtual gfx::Point GetAnchorPoint() OVERRIDE;
virtual views::BubbleBorder::ArrowLocation GetArrowLocation() const OVERRIDE;
const Extension* extension_; const Extension* extension_;
Browser* browser_; Browser* browser_;
SkBitmap icon_; SkBitmap icon_;
content::NotificationRegistrar registrar_; content::NotificationRegistrar registrar_;
InstalledBubbleContent* bubble_content_;
BubbleType type_; BubbleType type_;
// How many times we've deferred due to animations being in progress. // How many times we've deferred due to animations being in progress.
......
...@@ -202,6 +202,8 @@ class LocationBarView : public LocationBar, ...@@ -202,6 +202,8 @@ class LocationBarView : public LocationBar,
return location_icon_view_; return location_icon_view_;
} }
views::View* location_entry_view() const { return location_entry_view_; }
// AutocompleteEditController // AutocompleteEditController
virtual void OnAutocompleteAccept(const GURL& url, virtual void OnAutocompleteAccept(const GURL& url,
WindowOpenDisposition disposition, WindowOpenDisposition disposition,
......
...@@ -60,6 +60,7 @@ class VIEWS_EXPORT BubbleDelegateView : public WidgetDelegateView, ...@@ -60,6 +60,7 @@ class VIEWS_EXPORT BubbleDelegateView : public WidgetDelegateView,
} }
View* anchor_view() const { return anchor_view_; } 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_; } bool use_focusless() const { return use_focusless_; }
void set_use_focusless(bool use_focusless) { void set_use_focusless(bool use_focusless) {
......
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