Skip to content

Commit

Permalink
Fixed panel callout widgets showing up in the overview.
Browse files Browse the repository at this point in the history
Add hide/show functions for the callout widgets on the panel manager, and use
them from WindowSelectorPanels to control them.

BUG=377775
TEST=WindowSelectorTest.WindowOverviewHidesCalloutWidgets

Review URL: https://codereview.chromium.org/327873005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@276813 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
nsatragno@chromium.org committed Jun 12, 2014
1 parent ec83cd2 commit 5ca367f
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 42 deletions.
2 changes: 1 addition & 1 deletion ash/wm/overview/window_grid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ WindowGrid::WindowGrid(aura::Window* root_window,
// Attached panel windows are grouped into a single overview item per
// grid.
if (!panels_item) {
panels_item = new WindowSelectorPanels();
panels_item = new WindowSelectorPanels(root_window_);
window_list_.push_back(panels_item);
}
panels_item->AddWindow(*iter);
Expand Down
49 changes: 10 additions & 39 deletions ash/wm/overview/window_selector_panels.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ namespace ash {

namespace {

const int kPanelCalloutFadeInDurationMilliseconds = 50;

// This class extends ScopedTransformOverviewMode to hide and show the callout
// widget for a panel window when entering / leaving overview mode, as well as
// to add a transparent button for each panel window.
class ScopedTransformPanelWindow : public ScopedTransformOverviewWindow {
public:
ScopedTransformPanelWindow(aura::Window* window);
explicit ScopedTransformPanelWindow(aura::Window* window);
virtual ~ScopedTransformPanelWindow();

// ScopedTransformOverviewWindow overrides:
Expand All @@ -40,20 +38,9 @@ class ScopedTransformPanelWindow : public ScopedTransformOverviewWindow {
bool animate) OVERRIDE;

private:
// Returns the callout widget for the transformed panel.
views::Widget* GetCalloutWidget();

// Restores the callout visibility.
void RestoreCallout();

// Trigger relayout
void Relayout();

// Returns the panel window bounds after the transformation.
gfx::Rect GetTransformedBounds();

bool callout_visible_;

scoped_ptr<TransparentActivateWindowButton> window_button_;

DISALLOW_COPY_AND_ASSIGN(ScopedTransformPanelWindow);
Expand All @@ -64,14 +51,10 @@ ScopedTransformPanelWindow::ScopedTransformPanelWindow(aura::Window* window)
}

ScopedTransformPanelWindow::~ScopedTransformPanelWindow() {
// window() will be NULL if the window was destroyed.
if (window())
RestoreCallout();
}

void ScopedTransformPanelWindow::PrepareForOverview() {
ScopedTransformOverviewWindow::PrepareForOverview();
GetCalloutWidget()->GetLayer()->SetOpacity(0.0f);
window_button_.reset(new TransparentActivateWindowButton(window()));
}

Expand All @@ -83,26 +66,6 @@ void ScopedTransformPanelWindow::SetTransform(
window_button_->SetBounds(GetTransformedBounds());
}

views::Widget* ScopedTransformPanelWindow::GetCalloutWidget() {
DCHECK(window()->parent()->id() == kShellWindowId_PanelContainer);
PanelLayoutManager* panel_layout_manager =
static_cast<PanelLayoutManager*>(window()->parent()->layout_manager());
return panel_layout_manager->GetCalloutWidgetForPanel(window());
}

void ScopedTransformPanelWindow::RestoreCallout() {
scoped_ptr<ui::LayerAnimationSequence> sequence(
new ui::LayerAnimationSequence);
sequence->AddElement(ui::LayerAnimationElement::CreatePauseElement(
ui::LayerAnimationElement::OPACITY, base::TimeDelta::FromMilliseconds(
ScopedTransformOverviewWindow::kTransitionMilliseconds)));
sequence->AddElement(ui::LayerAnimationElement::CreateOpacityElement(1,
base::TimeDelta::FromMilliseconds(
kPanelCalloutFadeInDurationMilliseconds)));
GetCalloutWidget()->GetLayer()->GetAnimator()->StartAnimation(
sequence.release());
}

gfx::Rect ScopedTransformPanelWindow::GetTransformedBounds() {
gfx::RectF bounds(ScreenUtil::ConvertRectToScreen(
window()->GetRootWindow(), window()->layer()->bounds()));
Expand All @@ -118,13 +81,21 @@ gfx::Rect ScopedTransformPanelWindow::GetTransformedBounds() {

} // namespace

WindowSelectorPanels::WindowSelectorPanels() {
WindowSelectorPanels::WindowSelectorPanels(aura::Window* panels_root_window)
: panels_root_window_(panels_root_window) {
static_cast<PanelLayoutManager*>(
Shell::GetContainer(panels_root_window_, kShellWindowId_PanelContainer)->
layout_manager())->SetShowCalloutWidgets(false);
}

WindowSelectorPanels::~WindowSelectorPanels() {
static_cast<PanelLayoutManager*>(
Shell::GetContainer(panels_root_window_, kShellWindowId_PanelContainer)->
layout_manager())->SetShowCalloutWidgets(true);
}

void WindowSelectorPanels::AddWindow(aura::Window* window) {
DCHECK(window->GetRootWindow() == panels_root_window_);
transform_windows_.push_back(new ScopedTransformPanelWindow(window));
}

Expand Down
5 changes: 4 additions & 1 deletion ash/wm/overview/window_selector_panels.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ScopedTransformOverviewWindow;
// overview mode and the callout arrows are hidden at this point.
class WindowSelectorPanels : public WindowSelectorItem {
public:
WindowSelectorPanels();
explicit WindowSelectorPanels(aura::Window* panels_root_window);
virtual ~WindowSelectorPanels();

// Adds |window| to the selector item. This window should be an attached
Expand All @@ -44,6 +44,9 @@ class WindowSelectorPanels : public WindowSelectorItem {
typedef ScopedVector<ScopedTransformOverviewWindow> WindowList;
WindowList transform_windows_;

// The root window of the panels this item contains.
aura::Window* panels_root_window_;

DISALLOW_COPY_AND_ASSIGN(WindowSelectorPanels);
};

Expand Down
29 changes: 29 additions & 0 deletions ash/wm/overview/window_selector_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "ash/wm/overview/window_selector.h"
#include "ash/wm/overview/window_selector_controller.h"
#include "ash/wm/overview/window_selector_item.h"
#include "ash/wm/panels/panel_layout_manager.h"
#include "ash/wm/window_state.h"
#include "ash/wm/window_util.h"
#include "ash/wm/wm_event.h"
Expand Down Expand Up @@ -887,4 +888,32 @@ TEST_F(WindowSelectorTest, SelectWindowWithReturnKey) {
EXPECT_TRUE(wm::IsActiveWindow(window2.get()));
}

// Tests that overview mode hides the callout widget.
TEST_F(WindowSelectorTest, WindowOverviewHidesCalloutWidgets) {
scoped_ptr<aura::Window> panel1(CreatePanelWindow(gfx::Rect(0, 0, 100, 100)));
scoped_ptr<aura::Window> panel2(CreatePanelWindow(gfx::Rect(0, 0, 100, 100)));
PanelLayoutManager* panel_manager =
static_cast<PanelLayoutManager*>(panel1->parent()->layout_manager());

// By default, panel callout widgets are visible.
EXPECT_TRUE(
panel_manager->GetCalloutWidgetForPanel(panel1.get())->IsVisible());
EXPECT_TRUE(
panel_manager->GetCalloutWidgetForPanel(panel2.get())->IsVisible());

// Toggling the overview should hide the callout widgets.
ToggleOverview();
EXPECT_FALSE(
panel_manager->GetCalloutWidgetForPanel(panel1.get())->IsVisible());
EXPECT_FALSE(
panel_manager->GetCalloutWidgetForPanel(panel2.get())->IsVisible());

// Ending the overview should show them again.
ToggleOverview();
EXPECT_TRUE(
panel_manager->GetCalloutWidgetForPanel(panel1.get())->IsVisible());
EXPECT_TRUE(
panel_manager->GetCalloutWidgetForPanel(panel2.get())->IsVisible());
}

} // namespace ash
10 changes: 9 additions & 1 deletion ash/wm/panels/panel_layout_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ PanelLayoutManager::PanelLayoutManager(aura::Window* panel_container)
: panel_container_(panel_container),
in_add_window_(false),
in_layout_(false),
show_callout_widgets_(true),
dragged_panel_(NULL),
shelf_(NULL),
shelf_layout_manager_(NULL),
Expand Down Expand Up @@ -325,6 +326,13 @@ void PanelLayoutManager::ToggleMinimize(aura::Window* panel) {
window_state->Minimize();
}

void PanelLayoutManager::SetShowCalloutWidgets(bool show) {
if (show_callout_widgets_ == show)
return;
show_callout_widgets_ = show;
UpdateCallouts();
}

views::Widget* PanelLayoutManager::GetCalloutWidgetForPanel(
aura::Window* panel) {
DCHECK(panel->parent() == panel_container_);
Expand Down Expand Up @@ -814,7 +822,7 @@ void PanelLayoutManager::UpdateCallouts() {
panel->GetTargetBounds());
gfx::Rect icon_bounds = shelf_->GetScreenBoundsOfItemIconForWindow(panel);
if (icon_bounds.IsEmpty() || !panel->layer()->GetTargetVisibility() ||
panel == dragged_panel_) {
panel == dragged_panel_ || !show_callout_widgets_) {
callout_widget->Hide();
callout_widget->GetNativeWindow()->layer()->SetOpacity(0);
continue;
Expand Down
5 changes: 5 additions & 0 deletions ash/wm/panels/panel_layout_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class ASH_EXPORT PanelLayoutManager

void ToggleMinimize(aura::Window* panel);

// Hide / Show the panel callout widgets.
void SetShowCalloutWidgets(bool show);

// Returns the callout widget (arrow) for |panel|.
views::Widget* GetCalloutWidgetForPanel(aura::Window* panel);

Expand Down Expand Up @@ -169,6 +172,8 @@ class ASH_EXPORT PanelLayoutManager
bool in_add_window_;
// Protect against recursive calls to Relayout().
bool in_layout_;
// Indicates if the panel callout widget should be created.
bool show_callout_widgets_;
// Ordered list of unowned pointers to panel windows.
PanelList panel_windows_;
// The panel being dragged.
Expand Down

0 comments on commit 5ca367f

Please sign in to comment.