diff options
Diffstat (limited to 'chrome/browser/views')
-rw-r--r-- | chrome/browser/views/browser_bubble.cc | 38 | ||||
-rw-r--r-- | chrome/browser/views/browser_bubble.h | 7 | ||||
-rw-r--r-- | chrome/browser/views/frame/browser_bubble_host.cc | 43 | ||||
-rw-r--r-- | chrome/browser/views/frame/browser_bubble_host.h | 42 | ||||
-rw-r--r-- | chrome/browser/views/frame/browser_view.cc | 26 | ||||
-rw-r--r-- | chrome/browser/views/frame/browser_view.h | 11 |
6 files changed, 122 insertions, 45 deletions
diff --git a/chrome/browser/views/browser_bubble.cc b/chrome/browser/views/browser_bubble.cc index 1b690db..b199680 100644 --- a/chrome/browser/views/browser_bubble.cc +++ b/chrome/browser/views/browser_bubble.cc @@ -6,20 +6,35 @@ #include "app/l10n_util.h" #include "chrome/browser/views/frame/browser_view.h" +#if defined(OS_WIN) +#include "chrome/browser/external_tab_container.h" +#endif #include "views/widget/root_view.h" #include "views/window/window.h" namespace { -BrowserView* GetBrowserViewFromFrame(views::Widget* frame) { - BrowserView* browser_view = NULL; +BrowserBubbleHost* GetBubbleHostFromFrame(views::Widget* frame) { + if (!frame) + return NULL; + + BrowserBubbleHost* bubble_host = NULL; views::Window* window = frame->GetWindow(); if (window) { - browser_view = BrowserView::GetBrowserViewForNativeWindow( + bubble_host = BrowserView::GetBrowserViewForNativeWindow( window->GetNativeWindow()); - DCHECK(browser_view); + DCHECK(bubble_host); + } +#if defined(OS_WIN) + // The frame may also be an ExternalTabContainer, which is also capable of + // hosting BrowserBubbles. + gfx::NativeView native_view = frame->GetNativeView(); + if (!bubble_host) { + bubble_host = + ExternalTabContainer::GetExternalContainerFromNativeWindow(native_view); } - return browser_view; +#endif + return bubble_host; } } // namespace @@ -31,7 +46,8 @@ BrowserBubble::BrowserBubble(views::View* view, views::Widget* frame, visible_(false), delegate_(NULL), attached_(false), - drop_shadow_enabled_(drop_shadow) { + drop_shadow_enabled_(drop_shadow), + bubble_host_(GetBubbleHostFromFrame(frame)) { gfx::Size size = view->GetPreferredSize(); bounds_.SetRect(origin.x(), origin.y(), size.width(), size.height()); InitPopup(); @@ -55,9 +71,8 @@ void BrowserBubble::DetachFromBrowser() { return; attached_ = false; - BrowserView* browser_view = GetBrowserViewFromFrame(frame_); - if (browser_view) - browser_view->DetachBrowserBubble(this); + if (bubble_host_) + bubble_host_->DetachBrowserBubble(this); } void BrowserBubble::AttachToBrowser() { @@ -65,9 +80,8 @@ void BrowserBubble::AttachToBrowser() { if (attached_) return; - BrowserView* browser_view = GetBrowserViewFromFrame(frame_); - if (browser_view) - browser_view->AttachBrowserBubble(this); + if (bubble_host_) + bubble_host_->AttachBrowserBubble(this); attached_ = true; } diff --git a/chrome/browser/views/browser_bubble.h b/chrome/browser/views/browser_bubble.h index 012c552..feb55f8 100644 --- a/chrome/browser/views/browser_bubble.h +++ b/chrome/browser/views/browser_bubble.h @@ -8,6 +8,8 @@ #include "views/view.h" #include "views/widget/widget.h" +class BrowserBubbleHost; + // A class for creating a floating window that is "attached" to a particular // Browser. If you don't install a delegate, the bubble will hide // automatically when the browser moves. The bubble is only shown manually. @@ -58,7 +60,7 @@ class BrowserBubble { Delegate* delegate() const { return delegate_; } void set_delegate(Delegate* del) { delegate_ = del; } - // Notifications from BrowserView. + // Notifications from BrowserBubbleHost. // With no delegate, both of these default to Hiding the bubble. virtual void BrowserWindowMoved(); virtual void BrowserWindowClosing(); @@ -120,6 +122,9 @@ class BrowserBubble { // Does the bubble have a drop-shadow. bool drop_shadow_enabled_; + // Non-owning pointer to the host of this bubble. + BrowserBubbleHost* bubble_host_; + DISALLOW_COPY_AND_ASSIGN(BrowserBubble); }; diff --git a/chrome/browser/views/frame/browser_bubble_host.cc b/chrome/browser/views/frame/browser_bubble_host.cc new file mode 100644 index 0000000..60809bf --- /dev/null +++ b/chrome/browser/views/frame/browser_bubble_host.cc @@ -0,0 +1,43 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/views/frame/browser_bubble_host.h" + +#include "base/logging.h" +#include "chrome/browser/views/browser_bubble.h" + +void BrowserBubbleHost::WindowMoved() { + // Do safe iteration in case the bubble winds up closing as a result of this + // message. + for (BubbleSet::iterator i = browser_bubbles_.begin(); + i != browser_bubbles_.end();) { + BubbleSet::iterator bubble = i++; + (*bubble)->BrowserWindowMoved(); + } +} + +void BrowserBubbleHost::AttachBrowserBubble(BrowserBubble* bubble) { + DCHECK(browser_bubbles_.find(bubble) == browser_bubbles_.end()) << + "Attempt to register the same BrowserBubble multiple times."; + browser_bubbles_.insert(bubble); +} + +void BrowserBubbleHost::DetachBrowserBubble(BrowserBubble* bubble) { + BubbleSet::iterator it = browser_bubbles_.find(bubble); + DCHECK(it != browser_bubbles_.end()) << + "Attempt to detach an unrecognized BrowserBubble."; + if (it != browser_bubbles_.end()) + browser_bubbles_.erase(it); +} + +void BrowserBubbleHost::Close() { + // BrowserWindowClosing will usually cause the bubble to remove itself from + // the set, so we need to iterate in a way that's safe against deletion. + for (BubbleSet::iterator i = browser_bubbles_.begin(); + i != browser_bubbles_.end();) { + BubbleSet::iterator bubble = i++; + (*bubble)->BrowserWindowClosing(); + } +} + diff --git a/chrome/browser/views/frame/browser_bubble_host.h b/chrome/browser/views/frame/browser_bubble_host.h new file mode 100644 index 0000000..4763a50 --- /dev/null +++ b/chrome/browser/views/frame/browser_bubble_host.h @@ -0,0 +1,42 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_VIEWS_FRAME_BROWSER_BUBBLE_HOST_H_ +#define CHROME_BROWSER_VIEWS_FRAME_BROWSER_BUBBLE_HOST_H_ + +#include <set> + +#include "base/basictypes.h" + +class BrowserBubble; + +// A class providing a hosting environment for BrowserBubble instances. +// Allows for notification to attached BrowserBubbles of browser move, and +// close events. +class BrowserBubbleHost { + public: + BrowserBubbleHost() {} + + // Invoked when the window containing the attached browser-bubbles is moved. + // Calls BrowserBubble::BrowserWindowMoved on all attached bubbles. + void WindowMoved(); + + // To be called when the frame containing the BrowserBubbleHost is closing. + // Calls BrowserBubble::BrowserWindowClosing on all attached bubbles. + void Close(); + + // Registers/Unregisters |bubble| to receive notifications when the host moves + // or is closed. + void AttachBrowserBubble(BrowserBubble* bubble); + void DetachBrowserBubble(BrowserBubble* bubble); + + private: + // The set of bubbles associated with this host. + typedef std::set<BrowserBubble*> BubbleSet; + BubbleSet browser_bubbles_; + + DISALLOW_COPY_AND_ASSIGN(BrowserBubbleHost); +}; + +#endif // CHROME_BROWSER_VIEWS_FRAME_BROWSER_BUBBLE_HOST_H_ diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc index b6a3e17..f3ccddf 100644 --- a/chrome/browser/views/frame/browser_view.cc +++ b/chrome/browser/views/frame/browser_view.cc @@ -486,13 +486,7 @@ void BrowserView::WindowMoved() { status_bubble_->Reposition(); - // Do safe iteration in case the bubble winds up closing as a result of this - // message. - for (BubbleSet::iterator i = browser_bubbles_.begin(); - i != browser_bubbles_.end();) { - BubbleSet::iterator bubble = i++; - (*bubble)->BrowserWindowMoved(); - } + BrowserBubbleHost::WindowMoved(); browser::HideBookmarkBubbleView(); @@ -653,16 +647,6 @@ void BrowserView::RegisterBrowserViewPrefs(PrefService* prefs) { kDefaultHungPluginDetectFrequency); } -void BrowserView::AttachBrowserBubble(BrowserBubble* bubble) { - browser_bubbles_.insert(bubble); -} - -void BrowserView::DetachBrowserBubble(BrowserBubble* bubble) { - BubbleSet::iterator it = browser_bubbles_.find(bubble); - if (it != browser_bubbles_.end()) - browser_bubbles_.erase(it); -} - bool BrowserView::IsPositionInWindowCaption(const gfx::Point& point) { return GetBrowserViewLayout()->IsPositionInWindowCaption(point); } @@ -712,13 +696,7 @@ void BrowserView::SetBounds(const gfx::Rect& bounds) { } void BrowserView::Close() { - // BrowserWindowClosing will usually cause the bubble to remove itself from - // the set, so we need to iterate in a way that's safe against deletion. - for (BubbleSet::iterator i = browser_bubbles_.begin(); - i != browser_bubbles_.end();) { - BubbleSet::iterator bubble = i++; - (*bubble)->BrowserWindowClosing(); - } + BrowserBubbleHost::Close(); frame_->GetWindow()->Close(); } diff --git a/chrome/browser/views/frame/browser_view.h b/chrome/browser/views/frame/browser_view.h index 02fa1e0..7732621 100644 --- a/chrome/browser/views/frame/browser_view.h +++ b/chrome/browser/views/frame/browser_view.h @@ -17,6 +17,7 @@ #include "chrome/browser/browser.h" #include "chrome/browser/browser_window.h" #include "chrome/browser/tabs/tab_strip_model.h" +#include "chrome/browser/views/frame/browser_bubble_host.h" #include "chrome/browser/views/frame/browser_frame.h" #include "chrome/browser/views/infobars/infobar_container.h" #include "chrome/browser/views/tabs/tab_strip.h" @@ -67,7 +68,8 @@ class SingleSplitView; // A ClientView subclass that provides the contents of a browser window, // including the TabStrip, toolbars, download shelves, the content area etc. // -class BrowserView : public BrowserWindow, +class BrowserView : public BrowserBubbleHost, + public BrowserWindow, public BrowserWindowTesting, public NotificationObserver, public TabStripModelObserver, @@ -216,10 +218,6 @@ class BrowserView : public BrowserWindow, // Register preferences specific to this view. static void RegisterBrowserViewPrefs(PrefService* prefs); - // Attach/Detach a BrowserBubble to the browser. - void AttachBrowserBubble(BrowserBubble *bubble); - void DetachBrowserBubble(BrowserBubble *bubble); - // Returns true if the specified point(BrowserView coordinates) is in // in the window caption area of the browser window. bool IsPositionInWindowCaption(const gfx::Point& point); @@ -561,9 +559,6 @@ class BrowserView : public BrowserWindow, // A bottom bar for showing extensions. ExtensionShelf* extension_shelf_; - typedef std::set<BrowserBubble*> BubbleSet; - BubbleSet browser_bubbles_; - // The accessible name of this view. std::wstring accessible_name_; |