Skip to content

Commit

Permalink
Explicit container priority
Browse files Browse the repository at this point in the history
* This will allow a client to create & destroy a container with specific z order, without relying on the order it is created. (will be used for login/lock screen)

* Changed to single click to open home card, instead of double click because it's easier and consistent with ash. (ash uses single click to open/activate things)

* I tried to add check but I couldn't come  up with good solution using window oberver as the child is always added to the top first.

BUG=394121

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285185 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
oshima@chromium.org committed Jul 24, 2014
1 parent 3fdee23 commit 1b9697d
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 25 deletions.
3 changes: 2 additions & 1 deletion athena/athena.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
'activity/public/activity_manager.h',
'activity/public/activity_view_manager.h',
'activity/public/activity_view_model.h',
# move athena_export.h to common/
'athena_export.h',
'common/container_priorities.h',
'common/fill_layout_manager.cc',
'common/fill_layout_manager.h',
'common/switches.cc',
Expand Down Expand Up @@ -158,6 +158,7 @@
'activity/activity_manager_unittest.cc',
'home/home_card_unittest.cc',
'input/accelerator_manager_unittest.cc',
'screen/screen_manager_unittest.cc',
'wm/window_manager_unittest.cc',
],
}
Expand Down
20 changes: 20 additions & 0 deletions athena/common/container_priorities.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2014 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.

#ifndef ATHENA_COMMON_CONTAINER_PRIORITIES_H_
#define ATHENA_COMMON_CONTAINER_PRIORITIES_H_

namespace athena {

enum ContainerPriorities {
CP_BACKGROUND = 0,
CP_DEFAULT,
CP_HOME_CARD,
CP_VIRTUAL_KEYBOARD,
CP_DEBUG,
};

} // namespace athena

#endif // ATHENA_COMMON_CONTAINER_PRIORITIES_H_
3 changes: 2 additions & 1 deletion athena/home/home_card_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <limits>

#include "athena/common/container_priorities.h"
#include "athena/home/app_list_view_delegate.h"
#include "athena/home/bottom_home_view.h"
#include "athena/home/minimized_home.h"
Expand Down Expand Up @@ -329,7 +330,7 @@ void HomeCardImpl::UpdateVirtualKeyboardBounds(

void HomeCardImpl::Init() {
InstallAccelerators();
ScreenManager::ContainerParams params("HomeCardContainer");
ScreenManager::ContainerParams params("HomeCardContainer", CP_HOME_CARD);
params.can_activate_children = true;
aura::Window* container = ScreenManager::Get()->CreateContainer(params);
layout_manager_ = new HomeCardLayoutManager(this);
Expand Down
2 changes: 1 addition & 1 deletion athena/home/minimized_home.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class MinimizedHomeView : public views::View {
}

virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE {
if (event.IsLeftMouseButton() && event.GetClickCount() > 1) {
if (event.IsLeftMouseButton() && event.GetClickCount() == 1) {
delegate_->OnDragUpCompleted();
SetColor(kDragHandleColorNormal);
return true;
Expand Down
4 changes: 3 additions & 1 deletion athena/main/debug/debug_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "athena/main/debug/debug_window.h"

#include "athena/common/container_priorities.h"
#include "athena/resources/athena_resources.h"
#include "athena/screen/public/screen_manager.h"
#include "base/bind.h"
Expand Down Expand Up @@ -168,7 +169,8 @@ class DebugWidget {

private:
void CreateContainer() {
athena::ScreenManager::ContainerParams params("DebugContainer");
athena::ScreenManager::ContainerParams params("DebugContainer",
athena::CP_DEBUG);
container_ = athena::ScreenManager::Get()->CreateContainer(params);
}

Expand Down
5 changes: 4 additions & 1 deletion athena/screen/public/screen_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ namespace athena {
class ATHENA_EXPORT ScreenManager {
public:
struct ContainerParams {
ContainerParams(const std::string& name);
ContainerParams(const std::string& name, int z_order_priority);
std::string name;

// True if the container can activate its child window.
bool can_activate_children;

// Defines the z_order priority of the container.
int z_order_priority;
};

// Creates, returns and deletes the singleton object of the ScreenManager
Expand Down
80 changes: 62 additions & 18 deletions athena/screen/screen_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "athena/screen/public/screen_manager.h"

#include "athena/common/container_priorities.h"
#include "athena/common/fill_layout_manager.h"
#include "athena/input/public/accelerator_manager.h"
#include "athena/screen/background_controller.h"
Expand Down Expand Up @@ -127,10 +128,24 @@ class ScreenManagerImpl : public ScreenManager {
DISALLOW_COPY_AND_ASSIGN(ScreenManagerImpl);
};

ScreenManagerImpl::ScreenManagerImpl(aura::Window* root_window)
: root_window_(root_window) {
DCHECK(root_window_);
DCHECK(!instance);
instance = this;
}

ScreenManagerImpl::~ScreenManagerImpl() {
aura::client::SetScreenPositionClient(root_window_, NULL);
aura::client::SetWindowTreeClient(root_window_, NULL);
instance = NULL;
}

void ScreenManagerImpl::Init() {
// TODO(oshima): Move the background out from ScreenManager.
root_window_->SetLayoutManager(new FillLayoutManager(root_window_));
background_window_ = CreateContainer(ContainerParams("AthenaBackground"));
background_window_ =
CreateContainer(ContainerParams("AthenaBackground", CP_BACKGROUND));

background_window_->SetLayoutManager(
new FillLayoutManager(background_window_));
Expand All @@ -153,39 +168,68 @@ aura::Window* ScreenManagerImpl::CreateDefaultContainer(
return container;
}

// A functor to find a container that has the higher priority.
struct HigherPriorityFinder {
HigherPriorityFinder(int p) : priority(p) {}
bool operator()(aura::Window* window) {
return window->GetProperty(kContainerParamsKey)->z_order_priority >
priority;
}
int priority;
};

#if !defined(NDEBUG)
struct PriorityMatcher {
PriorityMatcher(int p) : priority(p) {}
bool operator()(aura::Window* window) {
return window->GetProperty(kContainerParamsKey)->z_order_priority ==
priority;
}
int priority;
};
#endif

aura::Window* ScreenManagerImpl::CreateContainer(
const ContainerParams& params) {
aura::Window* container = new aura::Window(NULL);
CHECK_GE(params.z_order_priority, 0);
container->Init(aura::WINDOW_LAYER_NOT_DRAWN);
container->SetName(params.name);

const aura::Window::Windows& children = root_window_->children();

#if !defined(NDEBUG)
DCHECK(std::find_if(children.begin(),
children.end(),
PriorityMatcher(params.z_order_priority))
== children.end())
<< "The container with the priority "
<< params.z_order_priority << " already exists.";
#endif

container->SetProperty(kContainerParamsKey, new ContainerParams(params));
root_window_->AddChild(container);

aura::Window::Windows::const_iterator iter =
std::find_if(children.begin(),
children.end(),
HigherPriorityFinder(params.z_order_priority));
if (iter != children.end())
root_window_->StackChildBelow(container, *iter);

container->Show();
container->SetProperty(kContainerParamsKey, new ContainerParams(params));
return container;
}

void ScreenManagerImpl::SetBackgroundImage(const gfx::ImageSkia& image) {
background_controller_->SetImage(image);
}

ScreenManagerImpl::ScreenManagerImpl(aura::Window* root_window)
: root_window_(root_window) {
DCHECK(root_window_);
DCHECK(!instance);
instance = this;
}

ScreenManagerImpl::~ScreenManagerImpl() {
aura::client::SetScreenPositionClient(root_window_, NULL);
aura::client::SetWindowTreeClient(root_window_, NULL);
instance = NULL;
}

} // namespace

ScreenManager::ContainerParams::ContainerParams(const std::string& n)
: name(n),
can_activate_children(false) {
ScreenManager::ContainerParams::ContainerParams(const std::string& n,
int priority)
: name(n), can_activate_children(false), z_order_priority(priority) {
}

// static
Expand Down
62 changes: 62 additions & 0 deletions athena/screen/screen_manager_unittest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright 2014 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 "athena/screen/public/screen_manager.h"

#include <string>

#include "athena/test/athena_test_base.h"
#include "ui/aura/window.h"

typedef athena::test::AthenaTestBase ScreenManagerTest;

namespace athena {
namespace {

aura::Window* Create(const std::string& name, int z_order_priority) {
ScreenManager::ContainerParams params(name, z_order_priority);
return ScreenManager::Get()->CreateContainer(params);
}

void CheckZOrder(aura::Window* w1, aura::Window* w2) {
aura::Window* parent = w1->parent();
const aura::Window::Windows& children = parent->children();
aura::Window::Windows::const_iterator begin_iter = children.begin();
aura::Window::Windows::const_iterator end_iter = children.end();

aura::Window::Windows::const_iterator w1_iter =
std::find(begin_iter, end_iter, w1);
aura::Window::Windows::const_iterator w2_iter =
std::find(begin_iter, end_iter, w2);
EXPECT_NE(end_iter, w1_iter);
EXPECT_NE(end_iter, w2_iter);
EXPECT_TRUE(w1_iter < w2_iter);
}

} // namespace

TEST_F(ScreenManagerTest, Zorder) {
aura::Window* window_10 = Create("test10", 10);
aura::Window* window_11 = Create("test11", 11);
aura::Window* window_12 = Create("test12", 12);

{
SCOPED_TRACE("Init");
CheckZOrder(window_10, window_11);
CheckZOrder(window_11, window_12);
}
{
SCOPED_TRACE("Delete");
delete window_11;
CheckZOrder(window_10, window_12);
}
{
SCOPED_TRACE("Insert");
window_11 = Create("test11", 11);
CheckZOrder(window_10, window_11);
CheckZOrder(window_11, window_12);
}
}

} // namespace athena
4 changes: 3 additions & 1 deletion athena/virtual_keyboard/virtual_keyboard_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "athena/virtual_keyboard/public/virtual_keyboard_manager.h"

#include "athena/common/container_priorities.h"
#include "athena/common/fill_layout_manager.h"
#include "athena/screen/public/screen_manager.h"
#include "athena/virtual_keyboard/vk_webui_controller.h"
Expand Down Expand Up @@ -76,7 +77,8 @@ class VirtualKeyboardManagerImpl : public VirtualKeyboardManager {

private:
void Init() {
athena::ScreenManager::ContainerParams params("VirtualKeyboardContainer");
athena::ScreenManager::ContainerParams params("VirtualKeyboardContainer",
CP_VIRTUAL_KEYBOARD);
container_ = athena::ScreenManager::Get()->CreateContainer(params);
container_->SetLayoutManager(new FillLayoutManager(container_));
keyboard::SetOverrideContentUrl(GURL(keyboard::kKeyboardURL));
Expand Down
3 changes: 2 additions & 1 deletion athena/wm/window_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "athena/wm/public/window_manager.h"

#include "athena/common/container_priorities.h"
#include "athena/input/public/accelerator_manager.h"
#include "athena/screen/public/screen_manager.h"
#include "athena/wm/bezel_controller.h"
Expand Down Expand Up @@ -86,7 +87,7 @@ class AthenaContainerLayoutManager : public aura::LayoutManager {
class WindowManagerImpl* instance = NULL;

WindowManagerImpl::WindowManagerImpl() {
ScreenManager::ContainerParams params("DefaultContainer");
ScreenManager::ContainerParams params("DefaultContainer", CP_DEFAULT);
params.can_activate_children = true;
container_.reset(ScreenManager::Get()->CreateDefaultContainer(params));
container_->SetLayoutManager(new AthenaContainerLayoutManager);
Expand Down

0 comments on commit 1b9697d

Please sign in to comment.