diff options
author | jianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-14 07:09:35 +0000 |
---|---|---|
committer | jianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-14 07:09:35 +0000 |
commit | 205d2e714f4bfa744769c76f7fe19e2907808618 (patch) | |
tree | 483690c35fa2e5f03072225c5953b3cd599d2639 /chrome/browser/ui | |
parent | 712f4b64f7ebead19b445209c69a54e3c38e1579 (diff) | |
download | chromium_src-205d2e714f4bfa744769c76f7fe19e2907808618.zip chromium_src-205d2e714f4bfa744769c76f7fe19e2907808618.tar.gz chromium_src-205d2e714f4bfa744769c76f7fe19e2907808618.tar.bz2 |
New panel should not stack with other panel or stack that is minimized by the system
BUG=188438
TEST=new tests
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=187796
Review URL: https://chromiumcodereview.appspot.com/12438006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188008 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui')
-rw-r--r-- | chrome/browser/ui/cocoa/panels/panel_cocoa.h | 1 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/panels/panel_cocoa.mm | 5 | ||||
-rw-r--r-- | chrome/browser/ui/gtk/panels/panel_gtk.cc | 5 | ||||
-rw-r--r-- | chrome/browser/ui/gtk/panels/panel_gtk.h | 1 | ||||
-rw-r--r-- | chrome/browser/ui/panels/native_panel.h | 5 | ||||
-rw-r--r-- | chrome/browser/ui/panels/native_panel_stack.h | 2 | ||||
-rw-r--r-- | chrome/browser/ui/panels/panel.cc | 4 | ||||
-rw-r--r-- | chrome/browser/ui/panels/panel.h | 4 | ||||
-rw-r--r-- | chrome/browser/ui/panels/panel_manager.cc | 9 | ||||
-rw-r--r-- | chrome/browser/ui/panels/stacked_panel_browsertest.cc | 62 | ||||
-rw-r--r-- | chrome/browser/ui/views/panels/panel_stack_view.cc | 59 | ||||
-rw-r--r-- | chrome/browser/ui/views/panels/panel_stack_view.h | 5 | ||||
-rw-r--r-- | chrome/browser/ui/views/panels/panel_view.cc | 4 | ||||
-rw-r--r-- | chrome/browser/ui/views/panels/panel_view.h | 1 |
14 files changed, 141 insertions, 26 deletions
diff --git a/chrome/browser/ui/cocoa/panels/panel_cocoa.h b/chrome/browser/ui/cocoa/panels/panel_cocoa.h index 1cb7845..65073aa 100644 --- a/chrome/browser/ui/cocoa/panels/panel_cocoa.h +++ b/chrome/browser/ui/cocoa/panels/panel_cocoa.h @@ -63,6 +63,7 @@ class PanelCocoa : public NativePanel { virtual int TitleOnlyHeight() const OVERRIDE; virtual void MinimizePanelBySystem() OVERRIDE; + virtual bool IsPanelMinimizedBySystem() const OVERRIDE; virtual NativePanelTesting* CreateNativePanelTesting() OVERRIDE; Panel* panel() const; diff --git a/chrome/browser/ui/cocoa/panels/panel_cocoa.mm b/chrome/browser/ui/cocoa/panels/panel_cocoa.mm index 722d88e..60c3c8f 100644 --- a/chrome/browser/ui/cocoa/panels/panel_cocoa.mm +++ b/chrome/browser/ui/cocoa/panels/panel_cocoa.mm @@ -244,6 +244,11 @@ void PanelCocoa::MinimizePanelBySystem() { NOTIMPLEMENTED(); } +bool PanelCocoa::IsPanelMinimizedBySystem() const { + NOTIMPLEMENTED(); + return false; +} + void PanelCocoa::PanelExpansionStateChanging( Panel::ExpansionState old_state, Panel::ExpansionState new_state) { [controller_ updateWindowLevel:(new_state != Panel::EXPANDED)]; diff --git a/chrome/browser/ui/gtk/panels/panel_gtk.cc b/chrome/browser/ui/gtk/panels/panel_gtk.cc index 0443833..a665528 100644 --- a/chrome/browser/ui/gtk/panels/panel_gtk.cc +++ b/chrome/browser/ui/gtk/panels/panel_gtk.cc @@ -321,6 +321,11 @@ void PanelGtk::MinimizePanelBySystem() { NOTIMPLEMENTED(); } +bool PanelGtk::IsPanelMinimizedBySystem() const { + NOTIMPLEMENTED(); + return false; +} + void PanelGtk::UpdateWindowShape() { int width = configure_size_.width(); int height = configure_size_.height(); diff --git a/chrome/browser/ui/gtk/panels/panel_gtk.h b/chrome/browser/ui/gtk/panels/panel_gtk.h index 1556af2..622373d 100644 --- a/chrome/browser/ui/gtk/panels/panel_gtk.h +++ b/chrome/browser/ui/gtk/panels/panel_gtk.h @@ -82,6 +82,7 @@ class PanelGtk : public NativePanel, virtual void UpdatePanelMinimizeRestoreButtonVisibility() OVERRIDE; virtual void SetWindowCornerStyle(panel::CornerStyle corner_style) OVERRIDE; virtual void MinimizePanelBySystem() OVERRIDE; + virtual bool IsPanelMinimizedBySystem() const OVERRIDE; virtual NativePanelTesting* CreateNativePanelTesting() OVERRIDE; diff --git a/chrome/browser/ui/panels/native_panel.h b/chrome/browser/ui/panels/native_panel.h index 757cb84..c849400 100644 --- a/chrome/browser/ui/panels/native_panel.h +++ b/chrome/browser/ui/panels/native_panel.h @@ -81,8 +81,13 @@ class NativePanel { // Sets how the panel window displays its 4 corners, rounded or not. virtual void SetWindowCornerStyle(panel::CornerStyle corner_style) = 0; + // Performs the system minimize for the panel, i.e. becoming iconic. virtual void MinimizePanelBySystem() = 0; + // Returns true if the panel has been minimized by the system, i.e. becoming + // iconic. + virtual bool IsPanelMinimizedBySystem() const = 0; + // Create testing interface for native panel. (Keep this last to separate // it from regular API.) virtual NativePanelTesting* CreateNativePanelTesting() = 0; diff --git a/chrome/browser/ui/panels/native_panel_stack.h b/chrome/browser/ui/panels/native_panel_stack.h index ad17d08..082a687 100644 --- a/chrome/browser/ui/panels/native_panel_stack.h +++ b/chrome/browser/ui/panels/native_panel_stack.h @@ -26,6 +26,8 @@ class NativePanelStack { virtual ~NativePanelStack() {} + virtual bool IsMinimized() const = 0; + protected: friend class StackedPanelCollection; diff --git a/chrome/browser/ui/panels/panel.cc b/chrome/browser/ui/panels/panel.cc index 1372b93..8482650 100644 --- a/chrome/browser/ui/panels/panel.cc +++ b/chrome/browser/ui/panels/panel.cc @@ -302,6 +302,10 @@ void Panel::Minimize() { collection_->MinimizePanel(this); } +bool Panel::IsMinimizedBySystem() const { + return native_panel_->IsPanelMinimizedBySystem(); +} + void Panel::Restore() { if (collection_) collection_->RestorePanel(this); diff --git a/chrome/browser/ui/panels/panel.h b/chrome/browser/ui/panels/panel.h index 8c2228b..3f79067 100644 --- a/chrome/browser/ui/panels/panel.h +++ b/chrome/browser/ui/panels/panel.h @@ -304,9 +304,11 @@ class Panel : public BaseWindow, // Applies |corner_style| to the panel window. void SetWindowCornerStyle(panel::CornerStyle corner_style); - // Performs the system minimize for the panel, i.e. hide the panel. + // Performs the system minimize for the panel, i.e. becoming iconic. void MinimizeBySystem(); + bool IsMinimizedBySystem() const; + protected: // Panel can only be created using PanelManager::CreatePanel() or subclass. // |app_name| is the default title for Panels when the page content does not diff --git a/chrome/browser/ui/panels/panel_manager.cc b/chrome/browser/ui/panels/panel_manager.cc index 0f9becd..d623a0a 100644 --- a/chrome/browser/ui/panels/panel_manager.cc +++ b/chrome/browser/ui/panels/panel_manager.cc @@ -11,6 +11,7 @@ #include "base/message_loop.h" #include "chrome/browser/ui/panels/detached_panel_collection.h" #include "chrome/browser/ui/panels/docked_panel_collection.h" +#include "chrome/browser/ui/panels/native_panel_stack.h" #include "chrome/browser/ui/panels/panel_drag_controller.h" #include "chrome/browser/ui/panels/panel_mouse_watcher.h" #include "chrome/browser/ui/panels/panel_resize_controller.h" @@ -318,6 +319,10 @@ PanelCollection* PanelManager::GetCollectionForNewPanel( panel->extension_id() != new_panel->extension_id()) continue; + // Do not add to the stack that is minimized by the system. + if (stack->native_stack()->IsMinimized()) + continue; + if (bounds.height() <= stack->GetMaximiumAvailableBottomSpace()) { *positioning_mask = static_cast<PanelCollection::PositioningMask>( *positioning_mask | PanelCollection::COLLAPSE_TO_FIT); @@ -349,6 +354,10 @@ PanelCollection* PanelManager::GetCollectionForNewPanel( panel->extension_id() != new_panel->extension_id()) continue; + // Do not stack with the panel that is minimized by the system. + if (panel->IsMinimizedBySystem()) + continue; + gfx::Rect work_area = display_settings_provider_->GetWorkAreaMatching(panel->GetBounds()); int max_available_space = diff --git a/chrome/browser/ui/panels/stacked_panel_browsertest.cc b/chrome/browser/ui/panels/stacked_panel_browsertest.cc index 1d06092..a5bdbd57 100644 --- a/chrome/browser/ui/panels/stacked_panel_browsertest.cc +++ b/chrome/browser/ui/panels/stacked_panel_browsertest.cc @@ -1099,6 +1099,68 @@ IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest, panel_manager->CloseAll(); } +IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest, + AddNewPanelNotWithSystemMinimizedDetachedPanel) { + PanelManager* panel_manager = PanelManager::GetInstance(); + + // Create 1 detached panel. + Panel* panel1 = CreateDetachedPanel("1", gfx::Rect(200, 50, 250, 150)); + EXPECT_EQ(1, panel_manager->num_panels()); + EXPECT_EQ(0, panel_manager->num_stacks()); + EXPECT_EQ(1, panel_manager->detached_collection()->num_panels()); + EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type()); + + // Minimize the detached panel by system. + panel1->OnMinimizeButtonClicked(panel::NO_MODIFIER); + + // Create new panel. Expect that new panel will open as a separate detached + // panel, instead of being grouped with the system-minimized detached panel. + CreatePanelParams params("N", gfx::Rect(50, 50, 150, 100), SHOW_AS_INACTIVE); + params.create_mode = PanelManager::CREATE_AS_DETACHED; + Panel* new_panel = CreatePanelWithParams(params); + EXPECT_EQ(2, panel_manager->num_panels()); + EXPECT_EQ(2, panel_manager->detached_collection()->num_panels()); + EXPECT_EQ(0, panel_manager->num_stacks()); + EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type()); + EXPECT_EQ(PanelCollection::DETACHED, new_panel->collection()->type()); + + panel_manager->CloseAll(); +} + +IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest, + AddNewPanelNotWithSystemMinimizedStack) { + PanelManager* panel_manager = PanelManager::GetInstance(); + + // Create one stack with 2 panels. + StackedPanelCollection* stack = panel_manager->CreateStack(); + Panel* panel1 = CreateStackedPanel("1", gfx::Rect(100, 90, 200, 150), stack); + Panel* panel2 = CreateStackedPanel("2", gfx::Rect(0, 0, 150, 100), stack); + EXPECT_EQ(2, panel_manager->num_panels()); + EXPECT_EQ(0, panel_manager->detached_collection()->num_panels()); + EXPECT_EQ(1, panel_manager->num_stacks()); + EXPECT_EQ(2, stack->num_panels()); + EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type()); + EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type()); + + // Minimize the stack by system. + stack->OnMinimizeButtonClicked(panel1, panel::NO_MODIFIER); + + // Create new panel. Expect that new panel will open as a separate detached + // panel, instead of appending to the system-minimized stack. + CreatePanelParams params("N", gfx::Rect(50, 50, 150, 100), SHOW_AS_INACTIVE); + params.create_mode = PanelManager::CREATE_AS_DETACHED; + Panel* new_panel = CreatePanelWithParams(params); + EXPECT_EQ(3, panel_manager->num_panels()); + EXPECT_EQ(1, panel_manager->detached_collection()->num_panels()); + EXPECT_EQ(1, panel_manager->num_stacks()); + EXPECT_EQ(2, stack->num_panels()); + EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type()); + EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type()); + EXPECT_EQ(PanelCollection::DETACHED, new_panel->collection()->type()); + + panel_manager->CloseAll(); +} + IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest, ClosePanels) { PanelManager* panel_manager = PanelManager::GetInstance(); diff --git a/chrome/browser/ui/views/panels/panel_stack_view.cc b/chrome/browser/ui/views/panels/panel_stack_view.cc index d12998b..9591153 100644 --- a/chrome/browser/ui/views/panels/panel_stack_view.cc +++ b/chrome/browser/ui/views/panels/panel_stack_view.cc @@ -99,35 +99,17 @@ void PanelStackView::SetBounds(const gfx::Rect& bounds) { void PanelStackView::Minimize() { // When the owner stack window is minimized by the system, its live preview - // is lost. We need to set it explicitly. -#if defined(OS_WIN) - // Live preview is only available since Windows 7. - if (base::win::GetVersion() < base::win::VERSION_WIN7) - return; - - HWND native_window = views::HWNDForWidget(window_); - - if (!thumbnailer_.get()) { - DCHECK(native_window); - thumbnailer_.reset(new TaskbarWindowThumbnailerWin(native_window)); - ui::HWNDSubclass::AddFilterToTarget(native_window, thumbnailer_.get()); - } - - std::vector<HWND> native_panel_windows; - for (StackedPanelCollection::Panels::const_iterator iter = - stacked_collection_->panels().begin(); - iter != stacked_collection_->panels().end(); ++iter) { - Panel* panel = *iter; - native_panel_windows.push_back( - views::HWNDForWidget( - static_cast<PanelView*>(panel->native_panel())->window())); - } - thumbnailer_->Start(native_panel_windows); -#endif + // is lost. We need to set it explicitly. This has to be done before the + // minimization. + CaptureThumbnailForLivePreview(); window_->Minimize(); } +bool PanelStackView::IsMinimized() const { + return window_->IsMinimized(); +} + void PanelStackView::DrawSystemAttention(bool draw_attention) { // The underlying call of FlashFrame, FlashWindowEx, seems not to work // correctly if it is called more than once consecutively. @@ -232,3 +214,30 @@ void PanelStackView::UpdateWindowOwnerForTaskbarIconAppearance(Panel* panel) { NOTIMPLEMENTED(); #endif } + +void PanelStackView::CaptureThumbnailForLivePreview() { +#if defined(OS_WIN) + // Live preview is only available since Windows 7. + if (base::win::GetVersion() < base::win::VERSION_WIN7) + return; + + HWND native_window = views::HWNDForWidget(window_); + + if (!thumbnailer_.get()) { + DCHECK(native_window); + thumbnailer_.reset(new TaskbarWindowThumbnailerWin(native_window)); + ui::HWNDSubclass::AddFilterToTarget(native_window, thumbnailer_.get()); + } + + std::vector<HWND> native_panel_windows; + for (StackedPanelCollection::Panels::const_iterator iter = + stacked_collection_->panels().begin(); + iter != stacked_collection_->panels().end(); ++iter) { + Panel* panel = *iter; + native_panel_windows.push_back( + views::HWNDForWidget( + static_cast<PanelView*>(panel->native_panel())->window())); + } + thumbnailer_->Start(native_panel_windows); +#endif +} diff --git a/chrome/browser/ui/views/panels/panel_stack_view.h b/chrome/browser/ui/views/panels/panel_stack_view.h index 19c2f02..34b6b6a 100644 --- a/chrome/browser/ui/views/panels/panel_stack_view.h +++ b/chrome/browser/ui/views/panels/panel_stack_view.h @@ -32,6 +32,7 @@ class PanelStackView : public NativePanelStack, virtual void OnPanelAddedOrRemoved(Panel* panel) OVERRIDE; virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE; virtual void Minimize() OVERRIDE; + virtual bool IsMinimized() const OVERRIDE; virtual void DrawSystemAttention(bool draw_attention) OVERRIDE; private: @@ -59,6 +60,10 @@ class PanelStackView : public NativePanelStack, // launcher. void UpdateWindowOwnerForTaskbarIconAppearance(Panel* panel); + // Capture the thumbnail of the whole stack and provide it to live preview + // (available since Windows 7). + void CaptureThumbnailForLivePreview(); + scoped_ptr<StackedPanelCollection> stacked_collection_; bool delay_initialized_; diff --git a/chrome/browser/ui/views/panels/panel_view.cc b/chrome/browser/ui/views/panels/panel_view.cc index 3e81297..4fbf520 100644 --- a/chrome/browser/ui/views/panels/panel_view.cc +++ b/chrome/browser/ui/views/panels/panel_view.cc @@ -642,6 +642,10 @@ void PanelView::MinimizePanelBySystem() { window_->Minimize(); } +bool PanelView::IsPanelMinimizedBySystem() const { + return window_->IsMinimized(); +} + void PanelView::AttachWebContents(content::WebContents* contents) { web_view_->SetWebContents(contents); } diff --git a/chrome/browser/ui/views/panels/panel_view.h b/chrome/browser/ui/views/panels/panel_view.h index 0147663..024a5cf 100644 --- a/chrome/browser/ui/views/panels/panel_view.h +++ b/chrome/browser/ui/views/panels/panel_view.h @@ -77,6 +77,7 @@ class PanelView : public NativePanel, const gfx::Size& window_size) const OVERRIDE; virtual int TitleOnlyHeight() const OVERRIDE; virtual void MinimizePanelBySystem() OVERRIDE; + virtual bool IsPanelMinimizedBySystem() const OVERRIDE; virtual NativePanelTesting* CreateNativePanelTesting() OVERRIDE; // Overridden from views::View: |