summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-01 03:50:45 +0000
committerjianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-01 03:50:45 +0000
commit83bac47170b11cc5513ca91c62b702ae8fe0eb16 (patch)
tree4b5329a5b03274df56f424e5cd7e95248ac684db
parent371dab1e621ab4157e42f4518e16a50b6ae03b56 (diff)
downloadchromium_src-83bac47170b11cc5513ca91c62b702ae8fe0eb16.zip
chromium_src-83bac47170b11cc5513ca91c62b702ae8fe0eb16.tar.gz
chromium_src-83bac47170b11cc5513ca91c62b702ae8fe0eb16.tar.bz2
Fix bug 127498: Panels: The position of notifications aren't adjusted when panels are detached
I fixed a bunch of other issues that could cause balloons not to repositioned in addition to the issue described in the bug. We now observe a new NOTIFICATION_PANEL_STRIP_CHANGED notification that is triggered each time when strip needs to be updated. In addition, we also need to listen to NOTIFICATION_PANEL_CHANGED_EXPANSION_STATE because expansion state change does not update the strip. More tests are added to cover various kinds of panel operations that could affect positioning of desktop notification balloon. They now live in the new test file. BUG=127498,118168 TEST=New tests Review URL: https://chromiumcodereview.appspot.com/10454027 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@139965 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/notifications/balloon_collection_impl.cc34
-rw-r--r--chrome/browser/notifications/balloon_collection_impl.h2
-rw-r--r--chrome/browser/ui/cocoa/notifications/balloon_collection_cocoa.mm2
-rw-r--r--chrome/browser/ui/gtk/notifications/balloon_collection_gtk.cc2
-rw-r--r--chrome/browser/ui/panels/base_panel_browser_test.cc20
-rw-r--r--chrome/browser/ui/panels/base_panel_browser_test.h2
-rw-r--r--chrome/browser/ui/panels/docked_panel_strip.cc5
-rw-r--r--chrome/browser/ui/panels/panel.cc10
-rw-r--r--chrome/browser/ui/panels/panel_and_desktop_notification_browsertest.cc408
-rw-r--r--chrome/browser/ui/panels/panel_browser_view.cc10
-rw-r--r--chrome/browser/ui/panels/panel_browsertest.cc169
-rw-r--r--chrome/browser/ui/panels/panel_manager.cc5
-rw-r--r--chrome/browser/ui/views/notifications/balloon_collection_views.cc2
-rw-r--r--chrome/chrome_tests.gypi2
-rw-r--r--chrome/common/chrome_notification_types.h12
15 files changed, 436 insertions, 249 deletions
diff --git a/chrome/browser/notifications/balloon_collection_impl.cc b/chrome/browser/notifications/balloon_collection_impl.cc
index 565aba4..e684925 100644
--- a/chrome/browser/notifications/balloon_collection_impl.cc
+++ b/chrome/browser/notifications/balloon_collection_impl.cc
@@ -45,11 +45,9 @@ BalloonCollectionImpl::BalloonCollectionImpl()
added_as_message_loop_observer_(false)
#endif
{
- registrar_.Add(this, chrome::NOTIFICATION_PANEL_ADDED,
+ registrar_.Add(this, chrome::NOTIFICATION_PANEL_STRIP_UPDATED,
content::NotificationService::AllSources());
- registrar_.Add(this, chrome::NOTIFICATION_PANEL_CLOSED,
- content::NotificationService::AllSources());
- registrar_.Add(this, chrome::NOTIFICATION_PANEL_CHANGED_BOUNDS,
+ registrar_.Add(this, chrome::NOTIFICATION_PANEL_CHANGED_EXPANSION_STATE,
content::NotificationService::AllSources());
SetPositionPreference(BalloonCollection::DEFAULT_POSITION);
@@ -184,13 +182,10 @@ void BalloonCollectionImpl::Observe(
const content::NotificationDetails& details) {
gfx::Rect bounds;
switch (type) {
- case chrome::NOTIFICATION_PANEL_CHANGED_BOUNDS:
- bounds = content::Source<Panel>(source).ptr()->GetBounds();
- // Fall through.
- case chrome::NOTIFICATION_PANEL_ADDED:
- case chrome::NOTIFICATION_PANEL_CLOSED:
+ case chrome::NOTIFICATION_PANEL_STRIP_UPDATED:
+ case chrome::NOTIFICATION_PANEL_CHANGED_EXPANSION_STATE:
layout_.enable_computing_panel_offset();
- if (layout_.ComputeOffsetToMoveAbovePanels(bounds))
+ if (layout_.ComputeOffsetToMoveAbovePanels())
PositionBalloons(true);
break;
default:
@@ -409,8 +404,7 @@ gfx::Size BalloonCollectionImpl::Layout::ConstrainToSizeLimits(
std::min(max_balloon_height(), size.height())));
}
-bool BalloonCollectionImpl::Layout::ComputeOffsetToMoveAbovePanels(
- const gfx::Rect& panel_bounds) {
+bool BalloonCollectionImpl::Layout::ComputeOffsetToMoveAbovePanels() {
// If the offset is not enabled due to that we have not received a
// notification about panel, don't proceed because we don't want to call
// PanelManager::GetInstance() to create an instance when panel is not
@@ -425,14 +419,6 @@ bool BalloonCollectionImpl::Layout::ComputeOffsetToMoveAbovePanels(
// The offset is the maximum height of panels that could overlap with the
// balloons.
if (NeedToMoveAboveLeftSidePanels()) {
- // If the affecting panel does not lie in the balloon area, no need to
- // update the offset.
- if (!panel_bounds.IsEmpty() &&
- (panel_bounds.right() <= work_area_.x() ||
- panel_bounds.x() >= work_area_.x() + max_balloon_width())) {
- return false;
- }
-
for (DockedPanelStrip::Panels::const_reverse_iterator iter =
panels.rbegin();
iter != panels.rend(); ++iter) {
@@ -445,14 +431,6 @@ bool BalloonCollectionImpl::Layout::ComputeOffsetToMoveAbovePanels(
offset_to_move_above_panels = current_height;
}
} else if (NeedToMoveAboveRightSidePanels()) {
- // If the affecting panel does not lie in the balloon area, no need to
- // update the offset.
- if (!panel_bounds.IsEmpty() &&
- (panel_bounds.right() <= work_area_.right() - max_balloon_width() ||
- panel_bounds.x() >= work_area_.right())) {
- return false;
- }
-
for (DockedPanelStrip::Panels::const_iterator iter = panels.begin();
iter != panels.end(); ++iter) {
// No need to check panels beyond the area occupied by the balloons.
diff --git a/chrome/browser/notifications/balloon_collection_impl.h b/chrome/browser/notifications/balloon_collection_impl.h
index 17804b9..11b5570 100644
--- a/chrome/browser/notifications/balloon_collection_impl.h
+++ b/chrome/browser/notifications/balloon_collection_impl.h
@@ -146,7 +146,7 @@ class BalloonCollectionImpl : public BalloonCollection,
// Returns true if there is change to the offset that requires the balloons
// to be repositioned.
- bool ComputeOffsetToMoveAbovePanels(const gfx::Rect& panel_bounds);
+ bool ComputeOffsetToMoveAbovePanels();
void enable_computing_panel_offset() {
need_to_compute_panel_offset_ = true;
diff --git a/chrome/browser/ui/cocoa/notifications/balloon_collection_cocoa.mm b/chrome/browser/ui/cocoa/notifications/balloon_collection_cocoa.mm
index 65aeab0..9e76836 100644
--- a/chrome/browser/ui/cocoa/notifications/balloon_collection_cocoa.mm
+++ b/chrome/browser/ui/cocoa/notifications/balloon_collection_cocoa.mm
@@ -69,7 +69,7 @@ void BalloonCollectionImpl::SetPositionPreference(
else
NOTREACHED();
- layout_.ComputeOffsetToMoveAbovePanels(gfx::Rect());
+ layout_.ComputeOffsetToMoveAbovePanels();
PositionBalloons(true);
}
diff --git a/chrome/browser/ui/gtk/notifications/balloon_collection_gtk.cc b/chrome/browser/ui/gtk/notifications/balloon_collection_gtk.cc
index 1a6fdfe..c07bdbd 100644
--- a/chrome/browser/ui/gtk/notifications/balloon_collection_gtk.cc
+++ b/chrome/browser/ui/gtk/notifications/balloon_collection_gtk.cc
@@ -83,7 +83,7 @@ void BalloonCollectionImpl::SetPositionPreference(
else
NOTREACHED();
- layout_.ComputeOffsetToMoveAbovePanels(gfx::Rect());
+ layout_.ComputeOffsetToMoveAbovePanels();
PositionBalloons(true);
}
diff --git a/chrome/browser/ui/panels/base_panel_browser_test.cc b/chrome/browser/ui/panels/base_panel_browser_test.cc
index 39f803d..9db1e075 100644
--- a/chrome/browser/ui/panels/base_panel_browser_test.cc
+++ b/chrome/browser/ui/panels/base_panel_browser_test.cc
@@ -243,26 +243,6 @@ void BasePanelBrowserTest::SetUpOnMainThread() {
ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
}
-void BasePanelBrowserTest::WaitForPanelAdded(Panel* panel) {
- if (ExistsPanel(panel))
- return;
- ui_test_utils::WindowedNotificationObserver signal(
- chrome::NOTIFICATION_PANEL_ADDED,
- content::Source<Panel>(panel));
- signal.Wait();
- EXPECT_TRUE(ExistsPanel(panel));
-}
-
-void BasePanelBrowserTest::WaitForPanelRemoved(Panel* panel) {
- if (!ExistsPanel(panel))
- return;
- ui_test_utils::WindowedNotificationObserver signal(
- chrome::NOTIFICATION_PANEL_CLOSED,
- content::Source<Panel>(panel));
- signal.Wait();
- EXPECT_FALSE(ExistsPanel(panel));
-}
-
void BasePanelBrowserTest::WaitForPanelActiveState(
Panel* panel, ActiveState expected_state) {
DCHECK(expected_state == SHOW_AS_ACTIVE ||
diff --git a/chrome/browser/ui/panels/base_panel_browser_test.h b/chrome/browser/ui/panels/base_panel_browser_test.h
index f845151..03c4c9a 100644
--- a/chrome/browser/ui/panels/base_panel_browser_test.h
+++ b/chrome/browser/ui/panels/base_panel_browser_test.h
@@ -82,8 +82,6 @@ class BasePanelBrowserTest : public InProcessBrowserTest {
Panel* CreateDockedPanel(const std::string& name, const gfx::Rect& bounds);
Panel* CreateDetachedPanel(const std::string& name, const gfx::Rect& bounds);
- void WaitForPanelAdded(Panel* panel);
- void WaitForPanelRemoved(Panel* panel);
void WaitForPanelActiveState(Panel* panel, ActiveState state);
void WaitForWindowSizeAvailable(Panel* panel);
void WaitForBoundsAnimationFinished(Panel* panel);
diff --git a/chrome/browser/ui/panels/docked_panel_strip.cc b/chrome/browser/ui/panels/docked_panel_strip.cc
index 6e48d7b..0778d6cd 100644
--- a/chrome/browser/ui/panels/docked_panel_strip.cc
+++ b/chrome/browser/ui/panels/docked_panel_strip.cc
@@ -811,6 +811,11 @@ void DockedPanelStrip::RefreshLayout() {
}
}
}
+
+ content::NotificationService::current()->Notify(
+ chrome::NOTIFICATION_PANEL_STRIP_UPDATED,
+ content::Source<PanelStrip>(this),
+ content::NotificationService::NoDetails());
}
int DockedPanelStrip::WidthToDisplayPanelInStrip(bool is_for_active_panel,
diff --git a/chrome/browser/ui/panels/panel.cc b/chrome/browser/ui/panels/panel.cc
index 36b94db..3ecad38 100644
--- a/chrome/browser/ui/panels/panel.cc
+++ b/chrome/browser/ui/panels/panel.cc
@@ -90,20 +90,10 @@ panel::Resizability Panel::CanResizeByMouse() const {
void Panel::SetPanelBounds(const gfx::Rect& bounds) {
native_panel_->SetPanelBounds(bounds);
-
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_PANEL_CHANGED_BOUNDS,
- content::Source<Panel>(this),
- content::NotificationService::NoDetails());
}
void Panel::SetPanelBoundsInstantly(const gfx::Rect& bounds) {
native_panel_->SetPanelBoundsInstantly(bounds);
-
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_PANEL_CHANGED_BOUNDS,
- content::Source<Panel>(this),
- content::NotificationService::NoDetails());
}
void Panel::LimitSizeToDisplayArea(const gfx::Rect& display_area) {
diff --git a/chrome/browser/ui/panels/panel_and_desktop_notification_browsertest.cc b/chrome/browser/ui/panels/panel_and_desktop_notification_browsertest.cc
new file mode 100644
index 0000000..44128bf
--- /dev/null
+++ b/chrome/browser/ui/panels/panel_and_desktop_notification_browsertest.cc
@@ -0,0 +1,408 @@
+// Copyright (c) 2012 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 "base/utf_string_conversions.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/notifications/balloon.h"
+#include "chrome/browser/notifications/balloon_collection_impl.h"
+#include "chrome/browser/notifications/desktop_notification_service.h"
+#include "chrome/browser/notifications/notification.h"
+#include "chrome/browser/notifications/notification_ui_manager.h"
+#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/panels/base_panel_browser_test.h"
+#include "chrome/browser/ui/panels/panel.h"
+#include "chrome/browser/ui/panels/panel_manager.h"
+#include "chrome/browser/ui/panels/test_panel_mouse_watcher.h"
+#include "chrome/common/pref_names.h"
+#include "content/public/common/show_desktop_notification_params.h"
+#include "ui/gfx/screen.h"
+
+// Desktop notification code subscribes to various panel change notifications
+// so that it knows when to adjusts balloon positions. In order to give
+// desktop notification code a chance to process the change notifications,
+// we call MessageLoopForUI::current()->RunAllPending() after any panel change
+// has been made.
+class PanelAndDesktopNotificationTest : public BasePanelBrowserTest {
+ public:
+ PanelAndDesktopNotificationTest() : BasePanelBrowserTest() {
+ }
+
+ virtual ~PanelAndDesktopNotificationTest() {
+ }
+
+ virtual void SetUpOnMainThread() OVERRIDE {
+ // Do not use our own testing work area since desktop notification code
+ // does not have the hook up for testing work area.
+ disable_display_settings_mock();
+
+ BasePanelBrowserTest::SetUpOnMainThread();
+
+ g_browser_process->local_state()->SetInteger(
+ prefs::kDesktopNotificationPosition, BalloonCollection::LOWER_RIGHT);
+ balloons_ = new BalloonCollectionImpl();
+ ui_manager_.reset(NotificationUIManager::Create(
+ g_browser_process->local_state(), balloons_));
+ service_.reset(new DesktopNotificationService(browser()->profile(),
+ ui_manager_.get()));
+ }
+
+ virtual void CleanUpOnMainThread() OVERRIDE {
+ balloons_->RemoveAll();
+ MessageLoopForUI::current()->RunAllPending();
+
+ service_.reset();
+ ui_manager_.reset();
+
+ BasePanelBrowserTest::CleanUpOnMainThread();
+ }
+
+ content::ShowDesktopNotificationHostMsgParams StandardTestNotification() {
+ content::ShowDesktopNotificationHostMsgParams params;
+ params.notification_id = 0;
+ params.origin = GURL("http://www.google.com");
+ params.is_html = false;
+ params.icon_url = GURL("/icon.png");
+ params.title = ASCIIToUTF16("Title");
+ params.body = ASCIIToUTF16("Text");
+ params.direction = WebKit::WebTextDirectionDefault;
+ return params;
+ }
+
+ Balloon* CreateBalloon() {
+ content::ShowDesktopNotificationHostMsgParams params =
+ StandardTestNotification();
+ EXPECT_TRUE(service()->ShowDesktopNotification(
+ params, 0, 0, DesktopNotificationService::PageNotification));
+ MessageLoopForUI::current()->RunAllPending();
+ return balloons().front();
+ }
+
+ static int GetBalloonBottomPosition(Balloon* balloon) {
+#if defined(OS_MACOSX)
+ // The position returned by the notification balloon is based on Mac's
+ // vertically inverted orientation. We need to flip it so that it can
+ // be compared against the position returned by the panel.
+ gfx::Size screen_size = gfx::Screen::GetPrimaryMonitor().size();
+ return screen_size.height() - balloon->GetPosition().y();
+#else
+ return balloon->GetPosition().y() + balloon->GetViewSize().height();
+#endif
+ }
+
+ static void DragPanelToMouseLocation(Panel* panel,
+ const gfx::Point& new_mouse_location) {
+ PanelManager* panel_manager = PanelManager::GetInstance();
+ panel_manager->StartDragging(panel, panel->GetBounds().origin());
+ panel_manager->Drag(new_mouse_location);
+ panel_manager->EndDragging(false);
+ }
+
+ static void ResizePanelByMouseWithDelta(Panel* panel,
+ panel::ResizingSides side,
+ const gfx::Point& delta) {
+ PanelManager* panel_manager = PanelManager::GetInstance();
+ gfx::Point mouse_location = panel->GetBounds().origin();
+ panel_manager->StartResizingByMouse(panel, mouse_location, side);
+ panel_manager->ResizeByMouse(mouse_location.Add(delta));
+ panel_manager->EndResizingByMouse(false);
+ }
+
+ DesktopNotificationService* service() const { return service_.get(); }
+ const BalloonCollection::Balloons& balloons() const {
+ return balloons_->GetActiveBalloons();
+ }
+
+ private:
+ BalloonCollectionImpl* balloons_; // Owned by NotificationUIManager.
+ scoped_ptr<NotificationUIManager> ui_manager_;
+ scoped_ptr<DesktopNotificationService> service_;
+};
+
+IN_PROC_BROWSER_TEST_F(PanelAndDesktopNotificationTest, AddAndClosePanel) {
+ Balloon* balloon = CreateBalloon();
+ int original_balloon_bottom = GetBalloonBottomPosition(balloon);
+
+ // Create a docked panel. Expect that the notification balloon moves up to be
+ // above the panel.
+ Panel* panel = CreateDockedPanel("1", gfx::Rect(0, 0, 200, 200));
+ MessageLoopForUI::current()->RunAllPending();
+ int balloon_bottom = GetBalloonBottomPosition(balloon);
+ EXPECT_LT(balloon_bottom, panel->GetBounds().y());
+ EXPECT_LT(balloon_bottom, original_balloon_bottom);
+
+ // Close the panel. Expect the notification balloon moves back to its original
+ // position.
+ panel->Close();
+ MessageLoopForUI::current()->RunAllPending();
+ EXPECT_EQ(original_balloon_bottom, GetBalloonBottomPosition(balloon));
+}
+
+IN_PROC_BROWSER_TEST_F(PanelAndDesktopNotificationTest,
+ ExpandAndCollapsePanel) {
+ // Disable mouse watcher since we don't want mouse movements to affect panel
+ // testing for title-only state.
+ PanelManager* panel_manager = PanelManager::GetInstance();
+ PanelMouseWatcher* mouse_watcher = new TestPanelMouseWatcher();
+ panel_manager->SetMouseWatcherForTesting(mouse_watcher);
+
+ Balloon* balloon = CreateBalloon();
+
+ // Create a docked panel. Expect that the notification balloon moves up to be
+ // above the panel.
+ Panel* panel = CreateDockedPanel("1", gfx::Rect(0, 0, 200, 200));
+ MessageLoopForUI::current()->RunAllPending();
+ int balloon_bottom_on_expanded = GetBalloonBottomPosition(balloon);
+ EXPECT_LT(balloon_bottom_on_expanded, panel->GetBounds().y());
+
+ // Minimize the panel. Expect that the notification balloon moves down, but
+ // still above the minimized panel.
+ panel->Minimize();
+ MessageLoopForUI::current()->RunAllPending();
+ int balloon_bottom_on_minimized = GetBalloonBottomPosition(balloon);
+ EXPECT_LT(balloon_bottom_on_minimized, panel->GetBounds().y());
+ EXPECT_LT(balloon_bottom_on_expanded, balloon_bottom_on_minimized);
+
+ // Bring up the title-bar for the panel by drawing attention. Expect that the
+ // notification balloon moves up a little bit to be still above the title-only
+ // panel.
+ panel->FlashFrame(true);
+ MessageLoopForUI::current()->RunAllPending();
+ int balloon_bottom_on_title_only = GetBalloonBottomPosition(balloon);
+ EXPECT_LT(balloon_bottom_on_title_only, panel->GetBounds().y());
+ EXPECT_LT(balloon_bottom_on_title_only, balloon_bottom_on_minimized);
+ EXPECT_LT(balloon_bottom_on_expanded, balloon_bottom_on_title_only);
+
+ // Expand the panel. Expect that the notification balloon moves up to go back
+ // to the same position when the panel is expanded.
+ panel->Restore();
+ MessageLoopForUI::current()->RunAllPending();
+ EXPECT_EQ(balloon_bottom_on_expanded, GetBalloonBottomPosition(balloon));
+
+ PanelManager::GetInstance()->CloseAll();
+}
+
+IN_PROC_BROWSER_TEST_F(PanelAndDesktopNotificationTest, DragNarrowPanel) {
+ Balloon* balloon = CreateBalloon();
+
+ // Let the panel width be smaller than the balloon width.
+ int panel_width = balloon->GetViewSize().width() - 50;
+
+ // Create 2 docked panels. Expect that the notification balloon moves up to be
+ // above the tall panel.
+ Panel* tall_panel = CreateDockedPanel("1", gfx::Rect(0, 0, panel_width, 300));
+ Panel* short_panel = CreateDockedPanel(
+ "2", gfx::Rect(0, 0, panel_width, 200));
+ MessageLoopForUI::current()->RunAllPending();
+ int balloon_bottom = GetBalloonBottomPosition(balloon);
+ EXPECT_LT(balloon_bottom, tall_panel->GetBounds().y());
+
+ // Swap 2 docked panels by dragging. Expect that the notificaition balloon
+ // remains at the same position.
+ DragPanelToMouseLocation(tall_panel, short_panel->GetBounds().origin());
+ MessageLoopForUI::current()->RunAllPending();
+ EXPECT_EQ(balloon_bottom, GetBalloonBottomPosition(balloon));
+
+ PanelManager::GetInstance()->CloseAll();
+}
+
+IN_PROC_BROWSER_TEST_F(PanelAndDesktopNotificationTest, DragWidePanel) {
+ Balloon* balloon = CreateBalloon();
+
+ // Let the panel width be greater than the balloon width.
+ int panel_width = balloon->GetViewSize().width() + 50;
+
+ // Create 2 docked panels. Expect that the notification balloon moves up to be
+ // above the tall panel.
+ Panel* tall_panel = CreateDockedPanel("1", gfx::Rect(0, 0, panel_width, 300));
+ Panel* short_panel = CreateDockedPanel(
+ "2", gfx::Rect(0, 0, panel_width, 200));
+ MessageLoopForUI::current()->RunAllPending();
+ int balloon_bottom_before_drag = GetBalloonBottomPosition(balloon);
+ EXPECT_LT(balloon_bottom_before_drag, tall_panel->GetBounds().y());
+
+ // Swap 2 docked panels by dragging. Expect that the notificaiton balloon
+ // moves down to be just above the short panel.
+ DragPanelToMouseLocation(tall_panel, short_panel->GetBounds().origin());
+ MessageLoopForUI::current()->RunAllPending();
+ int balloon_bottom_after_drag = GetBalloonBottomPosition(balloon);
+ EXPECT_LT(balloon_bottom_after_drag, short_panel->GetBounds().y());
+ EXPECT_LT(balloon_bottom_before_drag, balloon_bottom_after_drag);
+
+ PanelManager::GetInstance()->CloseAll();
+}
+
+IN_PROC_BROWSER_TEST_F(PanelAndDesktopNotificationTest, DetachAndAttachPanel) {
+ PanelManager* panel_manager = PanelManager::GetInstance();
+ Balloon* balloon = CreateBalloon();
+ int original_balloon_bottom = GetBalloonBottomPosition(balloon);
+
+ // Create a docked panel. Expect that the notification balloon moves up to be
+ // above the panel.
+ Panel* panel = CreateDockedPanel("1", gfx::Rect(0, 0, 200, 200));
+ MessageLoopForUI::current()->RunAllPending();
+ int balloon_bottom_after_panel_created = GetBalloonBottomPosition(balloon);
+ EXPECT_LT(balloon_bottom_after_panel_created, panel->GetBounds().y());
+ EXPECT_LT(balloon_bottom_after_panel_created, original_balloon_bottom);
+
+ // Detach the panel. Expect that the notification balloon moves down to its
+ // original position.
+ panel_manager->MovePanelToStrip(
+ panel, PanelStrip::DETACHED, PanelStrip::DEFAULT_POSITION);
+ MessageLoopForUI::current()->RunAllPending();
+ EXPECT_EQ(PanelStrip::DETACHED, panel->panel_strip()->type());
+ EXPECT_EQ(original_balloon_bottom, GetBalloonBottomPosition(balloon));
+
+ // Reattach the panel. Expect that the notification balloon moves above the
+ // panel.
+ panel_manager->MovePanelToStrip(
+ panel, PanelStrip::DOCKED, PanelStrip::DEFAULT_POSITION);
+ MessageLoopForUI::current()->RunAllPending();
+ EXPECT_EQ(PanelStrip::DOCKED, panel->panel_strip()->type());
+ EXPECT_EQ(balloon_bottom_after_panel_created,
+ GetBalloonBottomPosition(balloon));
+
+ panel_manager->CloseAll();
+}
+
+IN_PROC_BROWSER_TEST_F(PanelAndDesktopNotificationTest, ResizePanel) {
+ PanelManager* panel_manager = PanelManager::GetInstance();
+ Balloon* balloon = CreateBalloon();
+
+ // Create a docked panel. Expect that the notification balloon moves up to be
+ // above the panel.
+ Panel* panel = CreateDockedPanel("1", gfx::Rect(0, 0, 200, 200));
+ MessageLoopForUI::current()->RunAllPending();
+ int balloon_bottom = GetBalloonBottomPosition(balloon);
+ gfx::Rect original_bounds = panel->GetBounds();
+ EXPECT_LT(balloon_bottom, original_bounds.y());
+
+ // Resize the panel to make it taller. Expect that the notification balloon
+ // moves further up by the amount of enlarge offset.
+ gfx::Point resize_delta(50, 100);
+ gfx::Rect new_bounds = original_bounds;
+ new_bounds.set_width(new_bounds.width() + resize_delta.x());
+ new_bounds.set_height(new_bounds.height() + resize_delta.y());
+ panel->SetBounds(new_bounds);
+ MessageLoopForUI::current()->RunAllPending();
+ int balloon_bottom2 = GetBalloonBottomPosition(balloon);
+ EXPECT_EQ(balloon_bottom - resize_delta.y(), balloon_bottom2);
+
+ // Resize the panel to make it shorter. Expect that the notification balloon
+ // moves down by the amount of shrink offset.
+ resize_delta = gfx::Point(0, -60);
+ new_bounds.set_width(new_bounds.width() + resize_delta.x());
+ new_bounds.set_height(new_bounds.height() + resize_delta.y());
+ panel->SetBounds(new_bounds);
+ MessageLoopForUI::current()->RunAllPending();
+ int balloon_bottom3 = GetBalloonBottomPosition(balloon);
+ EXPECT_EQ(balloon_bottom2 - resize_delta.y(), balloon_bottom3);
+
+ panel_manager->CloseAll();
+}
+
+IN_PROC_BROWSER_TEST_F(PanelAndDesktopNotificationTest, ResizePanelByMouse) {
+ Balloon* balloon = CreateBalloon();
+
+ // Create a docked panel. Expect that the notification balloon moves up to be
+ // above the panel.
+ Panel* panel = CreateDockedPanel("1", gfx::Rect(0, 0, 200, 200));
+ MessageLoopForUI::current()->RunAllPending();
+ int balloon_bottom = GetBalloonBottomPosition(balloon);
+ EXPECT_LT(balloon_bottom, panel->GetBounds().y());
+
+ // Resize the panel to make it taller. Expect that the notification balloon
+ // moves further up by the amount of enlarge offset.
+ gfx::Point drag_delta(-50, -100);
+ ResizePanelByMouseWithDelta(panel, panel::RESIZE_TOP_LEFT, drag_delta);
+ MessageLoopForUI::current()->RunAllPending();
+ int balloon_bottom2 = GetBalloonBottomPosition(balloon);
+ EXPECT_EQ(balloon_bottom + drag_delta.y(), balloon_bottom2);
+
+ // Resize the panel to make it shorter. Expect that the notification balloon
+ // moves down by the amount of shrink offset.
+ drag_delta = gfx::Point(0, 60);
+ ResizePanelByMouseWithDelta(panel, panel::RESIZE_TOP, drag_delta);
+ MessageLoopForUI::current()->RunAllPending();
+ int balloon_bottom3 = GetBalloonBottomPosition(balloon);
+ EXPECT_EQ(balloon_bottom2 + drag_delta.y(), balloon_bottom3);
+
+ PanelManager::GetInstance()->CloseAll();
+}
+
+IN_PROC_BROWSER_TEST_F(PanelAndDesktopNotificationTest, InteractWithTwoPanels) {
+ Balloon* balloon = CreateBalloon();
+ int original_balloon_bottom = GetBalloonBottomPosition(balloon);
+
+ // Let the panel width be smaller than the balloon width.
+ int panel_width = balloon->GetViewSize().width() - 50;
+
+ // Create a short panel. Expect that the notification balloon moves up to be
+ // above the short panel.
+ Panel* short_panel = CreateDockedPanel(
+ "1", gfx::Rect(0, 0, panel_width, 150));
+ MessageLoopForUI::current()->RunAllPending();
+ int balloon_bottom_after_short_panel_created =
+ GetBalloonBottomPosition(balloon);
+ EXPECT_LT(balloon_bottom_after_short_panel_created,
+ short_panel->GetBounds().y());
+ EXPECT_LT(balloon_bottom_after_short_panel_created, original_balloon_bottom);
+
+ // Create a tall panel. Expect that the notification balloon moves further up
+ // to be above the tall panel.
+ Panel* tall_panel = CreateDockedPanel("2", gfx::Rect(0, 0, panel_width, 200));
+ MessageLoopForUI::current()->RunAllPending();
+ int balloon_bottom_after_tall_panel_created =
+ GetBalloonBottomPosition(balloon);
+ EXPECT_LT(balloon_bottom_after_tall_panel_created,
+ tall_panel->GetBounds().y());
+ EXPECT_LT(balloon_bottom_after_tall_panel_created,
+ balloon_bottom_after_short_panel_created);
+
+ // Minimize tall panel. Expect that the notification balloon moves down to the
+ // same position when short panel is first created.
+ tall_panel->Minimize();
+ MessageLoopForUI::current()->RunAllPending();
+ int balloon_bottom_after_tall_panel_minimized =
+ GetBalloonBottomPosition(balloon);
+ EXPECT_EQ(balloon_bottom_after_short_panel_created,
+ balloon_bottom_after_tall_panel_minimized);
+
+ // Minimize short panel. Expect that the notification balloon moves further
+ // down.
+ short_panel->Minimize();
+ MessageLoopForUI::current()->RunAllPending();
+ int balloon_bottom_after_both_panels_minimized =
+ GetBalloonBottomPosition(balloon);
+ EXPECT_LT(balloon_bottom_after_both_panels_minimized,
+ short_panel->GetBounds().y());
+ EXPECT_LT(balloon_bottom_after_both_panels_minimized,
+ tall_panel->GetBounds().y());
+ EXPECT_LT(balloon_bottom_after_short_panel_created,
+ balloon_bottom_after_both_panels_minimized);
+ EXPECT_LT(balloon_bottom_after_both_panels_minimized,
+ original_balloon_bottom);
+
+ // Expand short panel. Expect that the notification balloon moves further up
+ // to the same position when short panel is first created.
+ short_panel->Restore();
+ MessageLoopForUI::current()->RunAllPending();
+ int balloon_bottom_after_short_panel_expanded =
+ GetBalloonBottomPosition(balloon);
+ EXPECT_EQ(balloon_bottom_after_short_panel_created,
+ balloon_bottom_after_short_panel_expanded);
+
+ // Close tall panel. Expect that the notification balloon moves down to the
+ // same position when short panel is first created.
+ tall_panel->Close();
+ MessageLoopForUI::current()->RunAllPending();
+ EXPECT_EQ(balloon_bottom_after_short_panel_created,
+ GetBalloonBottomPosition(balloon));
+
+ // Close short panel. Expect that the notification balloo moves back to its
+ // original position.
+ short_panel->Close();
+ MessageLoopForUI::current()->RunAllPending();
+ EXPECT_EQ(original_balloon_bottom, GetBalloonBottomPosition(balloon));
+}
diff --git a/chrome/browser/ui/panels/panel_browser_view.cc b/chrome/browser/ui/panels/panel_browser_view.cc
index 9e60cfc..34a893d 100644
--- a/chrome/browser/ui/panels/panel_browser_view.cc
+++ b/chrome/browser/ui/panels/panel_browser_view.cc
@@ -257,11 +257,17 @@ void PanelBrowserView::OnWindowBeginUserBoundsChange() {
}
void PanelBrowserView::OnWindowEndUserBoundsChange() {
- bounds_ = GetBounds();
+ panel_->OnPanelEndUserResizing();
+
+ // No need to proceed with post-resizing update when there is no size change.
+ gfx::Rect new_bounds = GetBounds();
+ if (bounds_ == new_bounds)
+ return;
+ bounds_ = new_bounds;
+
panel_->IncreaseMaxSize(bounds_.size());
panel_->set_full_size(bounds_.size());
- panel_->OnPanelEndUserResizing();
panel_->panel_strip()->RefreshLayout();
}
diff --git a/chrome/browser/ui/panels/panel_browsertest.cc b/chrome/browser/ui/panels/panel_browsertest.cc
index 0947bc2..2b943eb 100644
--- a/chrome/browser/ui/panels/panel_browsertest.cc
+++ b/chrome/browser/ui/panels/panel_browsertest.cc
@@ -4,15 +4,9 @@
#include "base/bind.h"
#include "base/utf_string_conversions.h"
-#include "chrome/browser/browser_process.h"
#include "chrome/browser/download/download_service.h"
#include "chrome/browser/download/download_service_factory.h"
#include "chrome/browser/net/url_request_mock_util.h"
-#include "chrome/browser/notifications/balloon.h"
-#include "chrome/browser/notifications/balloon_collection_impl.h"
-#include "chrome/browser/notifications/desktop_notification_service.h"
-#include "chrome/browser/notifications/notification.h"
-#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/browser/prefs/browser_prefs.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
@@ -39,7 +33,6 @@
#include "content/public/browser/download_manager.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/web_contents.h"
-#include "content/public/common/show_desktop_notification_params.h"
#include "content/public/common/url_constants.h"
#include "content/test/net/url_request_mock_http_job.h"
#include "net/base/net_util.h"
@@ -1745,165 +1738,3 @@ IN_PROC_BROWSER_TEST_F(PanelDownloadTest, MAYBE_DownloadNoTabbedBrowser) {
panel_browser->CloseWindow();
}
-
-class PanelAndNotificationTest : public PanelBrowserTest {
- public:
- PanelAndNotificationTest() : PanelBrowserTest() {
- }
-
- virtual ~PanelAndNotificationTest() {
- }
-
- virtual void SetUpOnMainThread() OVERRIDE {
- // Do not use our own testing work area since desktop notification code
- // does not have the hook up for testing work area.
- disable_display_settings_mock();
-
- PanelBrowserTest::SetUpOnMainThread();
-
- g_browser_process->local_state()->SetInteger(
- prefs::kDesktopNotificationPosition, BalloonCollection::LOWER_RIGHT);
- balloons_ = new BalloonCollectionImpl();
- ui_manager_.reset(NotificationUIManager::Create(
- g_browser_process->local_state(), balloons_));
- service_.reset(new DesktopNotificationService(browser()->profile(),
- ui_manager_.get()));
- }
-
- virtual void CleanUpOnMainThread() OVERRIDE {
- balloons_->RemoveAll();
- MessageLoopForUI::current()->RunAllPending();
-
- service_.reset();
- ui_manager_.reset();
-
- PanelBrowserTest::CleanUpOnMainThread();
- }
-
- content::ShowDesktopNotificationHostMsgParams StandardTestNotification() {
- content::ShowDesktopNotificationHostMsgParams params;
- params.notification_id = 0;
- params.origin = GURL("http://www.google.com");
- params.is_html = false;
- params.icon_url = GURL("/icon.png");
- params.title = ASCIIToUTF16("Title");
- params.body = ASCIIToUTF16("Text");
- params.direction = WebKit::WebTextDirectionDefault;
- return params;
- }
-
- int GetBalloonBottomPosition(Balloon* balloon) const {
-#if defined(OS_MACOSX)
- // The position returned by the notification balloon is based on Mac's
- // vertically inverted orientation. We need to flip it so that it can
- // be compared against the position returned by the panel.
- gfx::Size screen_size = gfx::Screen::GetPrimaryMonitor().size();
- return screen_size.height() - balloon->GetPosition().y();
-#else
- return balloon->GetPosition().y() + balloon->GetViewSize().height();
-#endif
- }
-
- DesktopNotificationService* service() const { return service_.get(); }
- const BalloonCollection::Balloons& balloons() const {
- return balloons_->GetActiveBalloons();
- }
-
- private:
- BalloonCollectionImpl* balloons_; // Owned by NotificationUIManager.
- scoped_ptr<NotificationUIManager> ui_manager_;
- scoped_ptr<DesktopNotificationService> service_;
-};
-
-// crbug.com/118168
-IN_PROC_BROWSER_TEST_F(PanelAndNotificationTest, FAILS_NoOverlapping) {
- const int kPanelWidth = 200;
- const int kShortPanelHeight = 150;
- const int kTallPanelHeight = 200;
-
- content::ShowDesktopNotificationHostMsgParams params =
- StandardTestNotification();
- EXPECT_TRUE(service()->ShowDesktopNotification(
- params, 0, 0, DesktopNotificationService::PageNotification));
- MessageLoopForUI::current()->RunAllPending();
- Balloon* balloon = balloons().front();
- int original_balloon_bottom = GetBalloonBottomPosition(balloon);
- // Ensure that balloon width is greater than the panel width.
- EXPECT_GT(balloon->GetViewSize().width(), kPanelWidth);
-
- // Creating a short panel should move the notification balloon up.
- Panel* panel1 = CreatePanelWithBounds(
- "Panel1", gfx::Rect(0, 0, kPanelWidth, kShortPanelHeight));
- WaitForPanelAdded(panel1);
- int balloon_bottom_after_short_panel_created =
- GetBalloonBottomPosition(balloon);
- EXPECT_LT(balloon_bottom_after_short_panel_created, panel1->GetBounds().y());
- EXPECT_LT(balloon_bottom_after_short_panel_created, original_balloon_bottom);
-
- // Creating another tall panel should move the notification balloon further
- // up.
- Panel* panel2 = CreatePanelWithBounds(
- "Panel2", gfx::Rect(0, 0, kPanelWidth, kTallPanelHeight));
- WaitForPanelAdded(panel2);
- int balloon_bottom_after_tall_panel_created =
- GetBalloonBottomPosition(balloon);
- EXPECT_LT(balloon_bottom_after_tall_panel_created, panel2->GetBounds().y());
- EXPECT_LT(balloon_bottom_after_tall_panel_created,
- balloon_bottom_after_short_panel_created);
-
- // Minimizing tall panel should move the notification balloon down to the same
- // position when short panel is first created.
- panel2->SetExpansionState(Panel::MINIMIZED);
- WaitForBoundsAnimationFinished(panel2);
- int balloon_bottom_after_tall_panel_minimized =
- GetBalloonBottomPosition(balloon);
- EXPECT_EQ(balloon_bottom_after_short_panel_created,
- balloon_bottom_after_tall_panel_minimized);
-
- // Minimizing short panel should move the notification balloon further down.
- panel1->SetExpansionState(Panel::MINIMIZED);
- WaitForBoundsAnimationFinished(panel1);
- int balloon_bottom_after_both_panels_minimized =
- GetBalloonBottomPosition(balloon);
- EXPECT_LT(balloon_bottom_after_both_panels_minimized,
- panel1->GetBounds().y());
- EXPECT_LT(balloon_bottom_after_both_panels_minimized,
- panel2->GetBounds().y());
- EXPECT_LT(balloon_bottom_after_short_panel_created,
- balloon_bottom_after_both_panels_minimized);
- EXPECT_LT(balloon_bottom_after_both_panels_minimized,
- original_balloon_bottom);
-
- // Bringing up the titlebar for tall panel should move the notification
- // balloon up a little bit.
- panel2->SetExpansionState(Panel::TITLE_ONLY);
- WaitForBoundsAnimationFinished(panel2);
- int balloon_bottom_after_tall_panel_titlebar_up =
- GetBalloonBottomPosition(balloon);
- EXPECT_LT(balloon_bottom_after_tall_panel_titlebar_up,
- panel2->GetBounds().y());
- EXPECT_LT(balloon_bottom_after_tall_panel_titlebar_up,
- balloon_bottom_after_both_panels_minimized);
- EXPECT_LT(balloon_bottom_after_short_panel_created,
- balloon_bottom_after_tall_panel_titlebar_up);
-
- // Expanding short panel should move the notification balloon further up to
- // the same position when short panel is first created.
- panel1->SetExpansionState(Panel::EXPANDED);
- WaitForBoundsAnimationFinished(panel1);
- int balloon_bottom_after_short_panel_expanded =
- GetBalloonBottomPosition(balloon);
- EXPECT_EQ(balloon_bottom_after_short_panel_created,
- balloon_bottom_after_short_panel_expanded);
-
- // Closing short panel should move the notification balloon down to the same
- // position when tall panel brings up its titlebar.
- CloseWindowAndWait(panel1);
- EXPECT_EQ(balloon_bottom_after_tall_panel_titlebar_up,
- GetBalloonBottomPosition(balloon));
-
- // Closing the remaining tall panel should move the notification balloon back
- // to its original position.
- CloseWindowAndWait(panel2);
- EXPECT_EQ(original_balloon_bottom, GetBalloonBottomPosition(balloon));
-}
diff --git a/chrome/browser/ui/panels/panel_manager.cc b/chrome/browser/ui/panels/panel_manager.cc
index 0a3a8e0..957faba 100644
--- a/chrome/browser/ui/panels/panel_manager.cc
+++ b/chrome/browser/ui/panels/panel_manager.cc
@@ -189,11 +189,6 @@ Panel* PanelManager::CreatePanel(Browser* browser) {
docked_strip_->AddPanel(panel, PanelStrip::DELAY_LAYOUT_REFRESH);
docked_strip_->UpdatePanelOnStripChange(panel);
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_PANEL_ADDED,
- content::Source<Panel>(panel),
- content::NotificationService::NoDetails());
-
return panel;
}
diff --git a/chrome/browser/ui/views/notifications/balloon_collection_views.cc b/chrome/browser/ui/views/notifications/balloon_collection_views.cc
index 34f5cf2..68d85b2 100644
--- a/chrome/browser/ui/views/notifications/balloon_collection_views.cc
+++ b/chrome/browser/ui/views/notifications/balloon_collection_views.cc
@@ -103,7 +103,7 @@ void BalloonCollectionImpl::SetPositionPreference(
else
NOTREACHED();
- layout_.ComputeOffsetToMoveAbovePanels(gfx::Rect());
+ layout_.ComputeOffsetToMoveAbovePanels();
PositionBalloons(true);
}
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index e8865dc..ae8c85f2 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -484,6 +484,7 @@
'browser/ui/omnibox/omnibox_view_browsertest.cc',
'browser/ui/panels/detached_panel_browsertest.cc',
'browser/ui/panels/docked_panel_browsertest.cc',
+ 'browser/ui/panels/panel_and_desktop_notification_browsertest.cc',
'browser/ui/panels/panel_browsertest.cc',
'browser/ui/panels/panel_drag_browsertest.cc',
'browser/ui/panels/panel_resize_browsertest.cc',
@@ -577,6 +578,7 @@
'sources!': [
'browser/ui/panels/detached_panel_browsertest.cc',
'browser/ui/panels/docked_panel_browsertest.cc',
+ 'browser/ui/panels/panel_and_desktop_notification_browsertest.cc',
'browser/ui/panels/panel_browsertest.cc',
'browser/ui/panels/panel_drag_browsertest.cc',
'browser/ui/panels/panel_resize_browsertest.cc',
diff --git a/chrome/common/chrome_notification_types.h b/chrome/common/chrome_notification_types.h
index bd2491b..cf151da 100644
--- a/chrome/common/chrome_notification_types.h
+++ b/chrome/common/chrome_notification_types.h
@@ -1069,19 +1069,13 @@ enum NotificationType {
// Used only in unit testing.
NOTIFICATION_PANEL_WINDOW_SIZE_KNOWN,
- // Sent when panel's bounds get changed.
- // The source is the Panel, no details.
+ // Sent when panel strip get updated.
+ // The source is the PanelStrip, no details.
// Used only in coordination with notification balloons.
- NOTIFICATION_PANEL_CHANGED_BOUNDS,
-
- // Sent when panel is added into the panel manager.
- // The source is the Panel, no details.
- // Used only in coordination with notification balloons.
- NOTIFICATION_PANEL_ADDED,
+ NOTIFICATION_PANEL_STRIP_UPDATED,
// Sent when panel is closed.
// The source is the Panel, no details.
- // Used only in coordination with notification balloons.
NOTIFICATION_PANEL_CLOSED,
// Sent when a global error has changed and the error UI should update it