summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/frame
diff options
context:
space:
mode:
authortwiz@chromium.org <twiz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-16 02:24:18 +0000
committertwiz@chromium.org <twiz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-16 02:24:18 +0000
commit2b19e2feeac2a01b2068595bd2913a194a6527e5 (patch)
treefff83de7ba198462e1d00b96911685418dd130bd /chrome/browser/views/frame
parent00a3768102287ae6f8ff5e28347a920759d3374d (diff)
downloadchromium_src-2b19e2feeac2a01b2068595bd2913a194a6527e5.zip
chromium_src-2b19e2feeac2a01b2068595bd2913a194a6527e5.tar.gz
chromium_src-2b19e2feeac2a01b2068595bd2913a194a6527e5.tar.bz2
Clone of issue 600130. (http://codereview.chromium.org/600130)
BUG=None TEST=None Review URL: http://codereview.chromium.org/593111 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39077 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views/frame')
-rw-r--r--chrome/browser/views/frame/browser_bubble_host.cc43
-rw-r--r--chrome/browser/views/frame/browser_bubble_host.h42
-rw-r--r--chrome/browser/views/frame/browser_view.cc26
-rw-r--r--chrome/browser/views/frame/browser_view.h11
4 files changed, 90 insertions, 32 deletions
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_;