diff options
author | erikkay@chromium.org <erikkay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-06 23:50:06 +0000 |
---|---|---|
committer | erikkay@chromium.org <erikkay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-06 23:50:06 +0000 |
commit | ab4707af48416b411021b27e67b67270f3caec10 (patch) | |
tree | d4866a942d81d3a77d606be5c9132bfc14f6d3b8 /chrome/browser/views/extensions | |
parent | 7e5eb1cf0839ad0c6db1a3e1a682bdfd738783b9 (diff) | |
download | chromium_src-ab4707af48416b411021b27e67b67270f3caec10.zip chromium_src-ab4707af48416b411021b27e67b67270f3caec10.tar.gz chromium_src-ab4707af48416b411021b27e67b67270f3caec10.tar.bz2 |
Add an BubbleBorder to BrowserAction popups and fix positioning of the
popup.
BUG=23833,23835
TEST=none
Review URL: http://codereview.chromium.org/259065
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28187 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views/extensions')
-rw-r--r-- | chrome/browser/views/extensions/extension_popup.cc | 50 | ||||
-rw-r--r-- | chrome/browser/views/extensions/extension_popup.h | 16 |
2 files changed, 57 insertions, 9 deletions
diff --git a/chrome/browser/views/extensions/extension_popup.cc b/chrome/browser/views/extensions/extension_popup.cc index b938b27..c1174fb 100644 --- a/chrome/browser/views/extensions/extension_popup.cc +++ b/chrome/browser/views/extensions/extension_popup.cc @@ -14,27 +14,65 @@ #include "chrome/common/notification_source.h" #include "chrome/common/notification_type.h" +#include "views/widget/root_view.h" + ExtensionPopup::ExtensionPopup(ExtensionHost* host, views::Widget* frame, const gfx::Rect& relative_to) - : BrowserBubble(host->view(), - frame, - gfx::Point()), + : BrowserBubble(host->view(), frame, gfx::Point()), relative_to_(relative_to), extension_host_(host) { registrar_.Add(this, NotificationType::EXTENSION_HOST_DID_STOP_LOADING, Source<Profile>(host->profile())); + + // TODO(erikkay) Some of this border code is derived from InfoBubble. + // We should see if we can unify these classes. + gfx::NativeView native_window = frame->GetNativeView(); + border_widget_.reset(views::Widget::CreateTransparentPopupWidget(true)); + border_widget_->Init(native_window, bounds()); + border_ = new BubbleBorder; + border_->set_arrow_location(BubbleBorder::TOP_RIGHT); + border_view_ = new views::View; + border_view_->set_background(new BubbleBackground(border_)); + border_view_->set_border(border_); + border_widget_->SetContentsView(border_view_); } ExtensionPopup::~ExtensionPopup() { + border_widget_->Close(); +} + +void ExtensionPopup::Hide() { + BrowserBubble::Hide(); + border_widget_->Hide(); } void ExtensionPopup::Show() { ResizeToView(); - // Anchor on the lower right corner and extend to the left. - SetBounds(relative_to_.right() - width(), relative_to_.bottom(), - width(), height()); + // The rounded corners cut off more of the view than the border insets claim. + // Since we can't clip the ExtensionView's corners, we need to increase the + // inset by half the corner radius as well as lying about the size of the + // contents size to compensate. + int corner_inset = BubbleBorder::GetCornerRadius() / 2; + gfx::Size adjusted_size = bounds().size(); + adjusted_size.Enlarge(2 * corner_inset, 2 * corner_inset); + gfx::Rect rect = border_->GetBounds(relative_to_, adjusted_size); + border_widget_->SetBounds(rect); + + // Now calculate the inner bounds. This is a bit more convoluted than + // it should be because BrowserBubble coordinates are in Browser coordinates + // while |rect| is in screen coordinates. + gfx::Insets border_insets; + border_->GetInsets(&border_insets); + gfx::Point origin = rect.origin(); + views::View::ConvertPointToView(NULL, frame_->GetRootView(), &origin); + origin.set_x(origin.x() + border_insets.left() + corner_inset); + origin.set_y(origin.y() + border_insets.top() + corner_inset); + MoveTo(origin.x(), origin.y()); + + // Show the border first, then the popup overlaid on top. + border_widget_->Show(); BrowserBubble::Show(true); } diff --git a/chrome/browser/views/extensions/extension_popup.h b/chrome/browser/views/extensions/extension_popup.h index cdefc8e..ec0ba93 100644 --- a/chrome/browser/views/extensions/extension_popup.h +++ b/chrome/browser/views/extensions/extension_popup.h @@ -8,6 +8,7 @@ #include "googleurl/src/gurl.h" #include "chrome/browser/extensions/extension_host.h" #include "chrome/browser/views/browser_bubble.h" +#include "chrome/browser/views/bubble_border.h" #include "chrome/common/notification_observer.h" #include "chrome/common/notification_registrar.h" @@ -20,8 +21,8 @@ class ExtensionPopup : public BrowserBubble, virtual ~ExtensionPopup(); // Create and show a popup with |url| positioned below |relative_to| in - // |browser| coordinates. This is anchored to the lower right corner of the - // rect, extending to the left, just like the wrench and page menus. + // screen coordinates. This is anchored to the lower middle of the rect, + // extending to the left, just like the wrench and page menus. // // The actual display of the popup is delayed until the page contents // finish loading in order to minimize UI flashing and resizing. @@ -33,6 +34,7 @@ class ExtensionPopup : public BrowserBubble, // BrowserBubble overrides. virtual void Show(); + virtual void Hide(); // NotificationObserver overrides. virtual void Observe(NotificationType type, @@ -45,13 +47,21 @@ class ExtensionPopup : public BrowserBubble, const gfx::Rect& relative_to); // The area on the screen that the popup should be positioned relative to. - const gfx::Rect relative_to_; + gfx::Rect relative_to_; // The contained host for the view. scoped_ptr<ExtensionHost> extension_host_; NotificationRegistrar registrar_; + // A separate widget and associated pieces to draw a border behind the + // popup. This has to be a separate window in order to support transparency. + // Layered windows can't contain native child windows, so we wouldn't be + // able to have the ExtensionView child. + scoped_ptr<views::Widget> border_widget_; + BubbleBorder* border_; + views::View* border_view_; + DISALLOW_COPY_AND_ASSIGN(ExtensionPopup); }; |