Commit 017dbda0 authored by oshima@chromium.org's avatar oshima@chromium.org

Use ShadowController instead of creating its own.

Added SHADOW_TYPE_RECTANGULAR_ALWAYS_ACTIVE which lets the window always use the active shadow.

BUG=None

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

Cr-Commit-Position: refs/heads/master@{#289153}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289153 0039d316-1c4b-4281-b951-d872f2087c98
parent 9336f5ba
......@@ -26,7 +26,7 @@
#include "ui/views/layout/box_layout.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
#include "ui/wm/core/shadow.h"
#include "ui/wm/core/shadow_types.h"
#include "ui/wm/core/visibility_controller.h"
#include "ui/wm/core/window_animations.h"
#include "ui/wm/public/activation_change_observer.h"
......@@ -291,12 +291,10 @@ class HomeCardView : public views::WidgetDelegateView {
contents_view->SetActivePage(contents_view->GetPageIndexForNamedPage(
app_list::ContentsView::NAMED_PAGE_START));
}
if (state == HomeCard::VISIBLE_MINIMIZED)
shadow_.reset();
// Do not create the shadow yet. Instead, create it in OnWidgetMove(), to
// make sure that widget has been resized correctly (because the size of the
// shadow depends on the size of the widget).
wm::SetShadowType(GetWidget()->GetNativeView(),
state == HomeCard::VISIBLE_MINIMIZED ?
wm::SHADOW_TYPE_NONE :
wm::SHADOW_TYPE_RECTANGULAR);
}
void ClearGesture() {
......@@ -329,24 +327,6 @@ class HomeCardView : public views::WidgetDelegateView {
}
private:
// views::WidgetDelegate:
virtual void OnWidgetMove() OVERRIDE {
if (!minimized_view_->visible()) {
aura::Window* window = GetWidget()->GetNativeWindow();
if (!shadow_) {
shadow_.reset(new wm::Shadow());
shadow_->Init(wm::Shadow::STYLE_ACTIVE);
shadow_->SetContentBounds(gfx::Rect(window->bounds().size()));
shadow_->layer()->SetVisible(true);
ui::Layer* layer = window->layer();
layer->Add(shadow_->layer());
} else {
shadow_->SetContentBounds(gfx::Rect(window->bounds().size()));
}
}
}
virtual views::View* GetContentsView() OVERRIDE {
return this;
}
......@@ -354,7 +334,6 @@ class HomeCardView : public views::WidgetDelegateView {
app_list::AppListMainView* main_view_;
BottomHomeView* bottom_view_;
views::View* minimized_view_;
scoped_ptr<wm::Shadow> shadow_;
scoped_ptr<HomeCardGestureManager> gesture_manager_;
HomeCardGestureManager::Delegate* gesture_delegate_;
......
......@@ -19,8 +19,10 @@
#include "base/observer_list.h"
#include "ui/aura/layout_manager.h"
#include "ui/aura/window.h"
#include "ui/wm/core/shadow_controller.h"
#include "ui/wm/core/window_util.h"
#include "ui/wm/core/wm_state.h"
#include "ui/wm/public/activation_client.h"
#include "ui/wm/public/window_types.h"
namespace athena {
......@@ -44,7 +46,7 @@ class WindowManagerImpl : public WindowManager,
private:
enum Command {
COMMAND_TOGGLE_OVERVIEW,
CMD_TOGGLE_OVERVIEW,
};
// Sets whether overview mode is active.
......@@ -84,6 +86,7 @@ class WindowManagerImpl : public WindowManager,
scoped_ptr<SplitViewController> split_view_controller_;
scoped_ptr<wm::WMState> wm_state_;
scoped_ptr<TitleDragController> title_drag_controller_;
scoped_ptr<wm::ShadowController> shadow_controller_;
DISALLOW_COPY_AND_ASSIGN(WindowManagerImpl);
};
......@@ -123,6 +126,9 @@ WindowManagerImpl::WindowManagerImpl() {
container_->AddPreTargetHandler(bezel_controller_.get());
title_drag_controller_.reset(new TitleDragController(container_.get(), this));
wm_state_.reset(new wm::WMState());
aura::client::ActivationClient* activation_client =
aura::client::GetActivationClient(container_->GetRootWindow());
shadow_controller_.reset(new wm::ShadowController(activation_client));
instance = this;
InstallAccelerators();
}
......@@ -185,7 +191,7 @@ void WindowManagerImpl::SetInOverview(bool active) {
void WindowManagerImpl::InstallAccelerators() {
const AcceleratorData accelerator_data[] = {
{TRIGGER_ON_PRESS, ui::VKEY_F6, ui::EF_NONE, COMMAND_TOGGLE_OVERVIEW,
{TRIGGER_ON_PRESS, ui::VKEY_F6, ui::EF_NONE, CMD_TOGGLE_OVERVIEW,
AF_NONE},
};
AcceleratorManager::Get()->RegisterAccelerators(
......@@ -223,7 +229,7 @@ bool WindowManagerImpl::IsCommandEnabled(int command_id) const {
bool WindowManagerImpl::OnAcceleratorFired(int command_id,
const ui::Accelerator& accelerator) {
switch (command_id) {
case COMMAND_TOGGLE_OVERVIEW:
case CMD_TOGGLE_OVERVIEW:
ToggleOverview();
break;
}
......
......@@ -25,7 +25,7 @@
#include "ui/events/gestures/fling_curve.h"
#include "ui/gfx/frame_time.h"
#include "ui/gfx/transform.h"
#include "ui/wm/core/shadow.h"
#include "ui/wm/core/shadow_types.h"
namespace {
......@@ -39,8 +39,6 @@ struct WindowOverviewState {
// The current overview state of the window. 0.f means the window is at the
// topmost position. 1.f means the window is at the bottom-most position.
float progress;
scoped_ptr<wm::Shadow> shadow;
};
} // namespace
......@@ -76,6 +74,7 @@ void RestoreWindowState(aura::Window* window) {
ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(250));
window->SetTransform(gfx::Transform());
wm::SetShadowType(window, wm::SHADOW_TYPE_NONE);
}
// Always returns the same target.
......@@ -167,8 +166,8 @@ class WindowOverviewModeImpl : public WindowOverviewMode,
state->top = top_transform;
state->bottom = bottom_transform;
state->progress = 0.f;
state->shadow = CreateShadowForWindow(window);
window->SetProperty(kWindowOverviewState, state);
wm::SetShadowType(window, wm::SHADOW_TYPE_RECTANGULAR_ALWAYS_ACTIVE);
}
}
......@@ -206,15 +205,6 @@ class WindowOverviewModeImpl : public WindowOverviewMode,
}
}
scoped_ptr<wm::Shadow> CreateShadowForWindow(aura::Window* window) {
scoped_ptr<wm::Shadow> shadow(new wm::Shadow());
shadow->Init(wm::Shadow::STYLE_ACTIVE);
shadow->SetContentBounds(gfx::Rect(container_->bounds().size()));
shadow->layer()->SetVisible(true);
window->layer()->Add(shadow->layer());
return shadow.Pass();
}
aura::Window* SelectWindowAt(ui::LocatedEvent* event) {
CHECK_EQ(container_, event->target());
// Find the old targeter to find the target of the event.
......
......@@ -51,12 +51,25 @@ bool ShouldUseSmallShadowForWindow(aura::Window* window) {
return false;
}
bool IsShadowAlwaysActive(aura::Window* window) {
return GetShadowType(window) == SHADOW_TYPE_RECTANGULAR_ALWAYS_ACTIVE;
}
Shadow::Style GetShadowStyleForWindow(aura::Window* window) {
return ShouldUseSmallShadowForWindow(window) ? Shadow::STYLE_SMALL :
((IsActiveWindow(window) || IsShadowAlwaysActive(window)) ?
Shadow::STYLE_ACTIVE : Shadow::STYLE_INACTIVE);
}
// Returns the shadow style to be applied to |losing_active| when it is losing
// active to |gaining_active|. |gaining_active| may be of a type that hides when
// inactive, and as such we do not want to render |losing_active| as inactive.
Shadow::Style GetShadowStyleForWindowLosingActive(
aura::Window* losing_active,
aura::Window* gaining_active) {
if (IsShadowAlwaysActive(losing_active))
return Shadow::STYLE_ACTIVE;
if (gaining_active && aura::client::GetHideOnDeactivate(gaining_active)) {
aura::Window::Windows::const_iterator it =
std::find(GetTransientChildren(losing_active).begin(),
......@@ -200,6 +213,7 @@ bool ShadowController::Impl::ShouldShowShadowForWindow(
case SHADOW_TYPE_NONE:
return false;
case SHADOW_TYPE_RECTANGULAR:
case SHADOW_TYPE_RECTANGULAR_ALWAYS_ACTIVE:
return true;
default:
NOTREACHED() << "Unknown shadow type " << type;
......@@ -216,18 +230,18 @@ void ShadowController::Impl::HandlePossibleShadowVisibilityChange(
aura::Window* window) {
const bool should_show = ShouldShowShadowForWindow(window);
Shadow* shadow = GetShadowForWindow(window);
if (shadow)
if (shadow) {
shadow->SetStyle(GetShadowStyleForWindow(window));
shadow->layer()->SetVisible(should_show);
else if (should_show && !shadow)
} else if (should_show && !shadow) {
CreateShadowForWindow(window);
}
}
void ShadowController::Impl::CreateShadowForWindow(aura::Window* window) {
linked_ptr<Shadow> shadow(new Shadow());
window_shadows_.insert(make_pair(window, shadow));
shadow->Init(ShouldUseSmallShadowForWindow(window) ?
Shadow::STYLE_SMALL : Shadow::STYLE_ACTIVE);
shadow->Init(GetShadowStyleForWindow(window));
shadow->SetContentBounds(gfx::Rect(window->bounds().size()));
shadow->layer()->SetVisible(ShouldShowShadowForWindow(window));
window->layer()->Add(shadow->layer());
......
......@@ -216,4 +216,58 @@ TEST_F(ShadowControllerTest, TransientParentKeepsActiveShadow) {
EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow1->style());
}
TEST_F(ShadowControllerTest, AlwaysActive) {
ShadowController::TestApi api(shadow_controller());
scoped_ptr<aura::Window> window1(new aura::Window(NULL));
window1->SetType(ui::wm::WINDOW_TYPE_NORMAL);
window1->Init(aura::WINDOW_LAYER_TEXTURED);
ParentWindow(window1.get());
window1->SetBounds(gfx::Rect(10, 20, 300, 400));
SetShadowType(window1.get(), SHADOW_TYPE_RECTANGULAR_ALWAYS_ACTIVE);
window1->Show();
// Showing the window with SHADOW_TYPE_RECTANGULAR_ALWAYS_ACTIVE should
// have active shadow.
EXPECT_EQ(Shadow::STYLE_ACTIVE,
api.GetShadowForWindow(window1.get())->style());
scoped_ptr<aura::Window> window2(new aura::Window(NULL));
window2->SetType(ui::wm::WINDOW_TYPE_NORMAL);
window2->Init(aura::WINDOW_LAYER_TEXTURED);
ParentWindow(window2.get());
window2->SetBounds(gfx::Rect(11, 21, 301, 401));
window2->Show();
// Setting SHADOW_TYPE_RECTANGULAR_ALWAYS_ACTIVE to the visible window
// should set the active shadow.
EXPECT_EQ(Shadow::STYLE_INACTIVE,
api.GetShadowForWindow(window2.get())->style());
SetShadowType(window2.get(), SHADOW_TYPE_RECTANGULAR_ALWAYS_ACTIVE);
EXPECT_EQ(Shadow::STYLE_ACTIVE,
api.GetShadowForWindow(window2.get())->style());
// Activation should not change the shadow style.
ActivateWindow(window2.get());
EXPECT_EQ(Shadow::STYLE_ACTIVE,
api.GetShadowForWindow(window1.get())->style());
EXPECT_EQ(Shadow::STYLE_ACTIVE,
api.GetShadowForWindow(window2.get())->style());
ActivateWindow(window1.get());
EXPECT_EQ(Shadow::STYLE_ACTIVE,
api.GetShadowForWindow(window1.get())->style());
EXPECT_EQ(Shadow::STYLE_ACTIVE,
api.GetShadowForWindow(window2.get())->style());
// Restore the style to plain RECTANGULAR and make sure the inactive window
// gets the inactive shadow.
SetShadowType(window1.get(), SHADOW_TYPE_RECTANGULAR);
SetShadowType(window2.get(), SHADOW_TYPE_RECTANGULAR);
EXPECT_EQ(Shadow::STYLE_ACTIVE,
api.GetShadowForWindow(window1.get())->style());
EXPECT_EQ(Shadow::STYLE_INACTIVE,
api.GetShadowForWindow(window2.get())->style());
}
} // namespace wm
......@@ -20,6 +20,7 @@ enum ShadowType {
// Starts at 0 due to the cast in GetShadowType().
SHADOW_TYPE_NONE = 0,
SHADOW_TYPE_RECTANGULAR,
SHADOW_TYPE_RECTANGULAR_ALWAYS_ACTIVE,
};
WM_EXPORT void SetShadowType(aura::Window* window, ShadowType shadow_type);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment