Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Unified Diff: chrome/browser/notifications/balloon_collection_impl.cc

Issue 8503037: Fix the problem that notifications and panels overlap. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/notifications/balloon_collection_impl.cc
diff --git a/chrome/browser/notifications/balloon_collection_impl.cc b/chrome/browser/notifications/balloon_collection_impl.cc
index 9d234c222aa41ebe7753061c00b7ec4f1c3bccbc..b969811b88bc0403e2435736d67f6ee8c51e0663 100644
--- a/chrome/browser/notifications/balloon_collection_impl.cc
+++ b/chrome/browser/notifications/balloon_collection_impl.cc
@@ -10,7 +10,13 @@
#include "chrome/browser/notifications/balloon.h"
#include "chrome/browser/notifications/balloon_host.h"
#include "chrome/browser/notifications/notification.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/panels/panel_manager.h"
+#include "chrome/browser/ui/panels/panel.h"
#include "chrome/browser/ui/window_sizer.h"
+#include "chrome/common/chrome_notification_types.h"
+#include "content/public/browser/notification_registrar.h"
+#include "content/public/browser/notification_service.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"
@@ -35,6 +41,12 @@ BalloonCollectionImpl::BalloonCollectionImpl()
added_as_message_loop_observer_(false)
#endif
{
+ registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY,
+ content::NotificationService::AllSources());
+ registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSED,
+ content::NotificationService::AllSources());
+ registrar_.Add(this, chrome::NOTIFICATION_PANEL_CHANGED_BOUNDS,
+ content::NotificationService::AllSources());
SetPositionPreference(BalloonCollection::DEFAULT_POSITION);
}
@@ -153,6 +165,27 @@ const BalloonCollection::Balloons& BalloonCollectionImpl::GetActiveBalloons() {
return base_.balloons();
}
+void BalloonCollectionImpl::Observe(
+ int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ switch (type) {
+ case chrome::NOTIFICATION_BROWSER_WINDOW_READY:
+ case chrome::NOTIFICATION_BROWSER_CLOSED: {
+ Browser* browser = content::Source<Browser>(source).ptr();
+ if (browser->is_type_panel())
+ PositionBalloons(true);
+ break;
+ }
+ case chrome::NOTIFICATION_PANEL_CHANGED_BOUNDS:
+ PositionBalloons(true);
+ break;
+ default:
+ NOTREACHED();
+ break;
+ }
+}
+
void BalloonCollectionImpl::PositionBalloonsInternal(bool reposition) {
const Balloons& balloons = base_.balloons();
@@ -231,7 +264,9 @@ void BalloonCollectionImpl::HandleMouseMoveEvent() {
}
#endif
-BalloonCollectionImpl::Layout::Layout() : placement_(INVALID) {
+BalloonCollectionImpl::Layout::Layout()
+ : placement_(INVALID),
+ panel_height_base_(0) {
RefreshSystemMetrics();
}
@@ -260,10 +295,13 @@ gfx::Point BalloonCollectionImpl::Layout::GetLayoutOrigin() const {
x = work_area_.x() + HorizontalEdgeMargin();
y = work_area_.bottom() - VerticalEdgeMargin();
break;
- case VERTICALLY_FROM_BOTTOM_RIGHT:
+ case VERTICALLY_FROM_BOTTOM_RIGHT: {
x = work_area_.right() - HorizontalEdgeMargin();
- y = work_area_.bottom() - VerticalEdgeMargin();
+ // For this placement, balloon needs to stay on top of right-most panels
+ // to avoid overlapping.
+ y = work_area_.bottom() - VerticalEdgeMargin() - panel_height_base_;
break;
+ }
default:
NOTREACHED();
break;
@@ -363,6 +401,23 @@ gfx::Size BalloonCollectionImpl::Layout::ConstrainToSizeLimits(
std::min(max_balloon_height(), size.height())));
}
+int BalloonCollectionImpl::Layout::GetPanelHeightBase() const {
Dmitry Titov 2011/11/09 03:09:57 If we add a method on PanelManager to pull this he
jianli 2011/11/09 19:04:40 Indeed we don't need to expose 'horizontal_spacing
+ // The height base is computed based on the maximum height of the right-most
+ // panels that could overlap with the balloon.
+ int height_base = 0;
+ const PanelManager::Panels& panels = PanelManager::GetInstance()->panels();
+ for (PanelManager::Panels::const_iterator iter = panels.begin();
+ iter != panels.end(); ++iter) {
+ if ((*iter)->GetBounds().right() + PanelManager::horizontal_spacing() <=
+ work_area_.right() - max_balloon_width())
+ break;
+ int current_height = (*iter)->GetBounds().height();
+ if (current_height > height_base)
+ height_base = current_height;
+ }
+ return height_base;
+}
+
bool BalloonCollectionImpl::Layout::RefreshSystemMetrics() {
bool changed = false;
@@ -379,5 +434,7 @@ bool BalloonCollectionImpl::Layout::RefreshSystemMetrics() {
changed = true;
}
+ panel_height_base_ = GetPanelHeightBase();
+
return changed;
}

Powered by Google App Engine
This is Rietveld 408576698