Commit 44bf2fd5 authored by oshima's avatar oshima Committed by Commit bot

Support modal windows

* New ContainerParams
 -  default_parent to specify the default parent when no
    transient parent is specified.
 - modal_container_priority now controls the modal container
   used for a modal window created for the given container.
 - if not specified, it will fallback downwards to find one.
 - if window is specified as always_on_top, it will use top
   most modal container.

* Changed network selector/shutdown dialog to use the new API.

* Other change:
 Separated test windows to athena/test/base/test_windows.h

BUG=410499
TBR=sky@chromium.org,reed@chromium.org
TEST=coverd by unit tests

Committed: https://crrev.com/4903fd36b2b36f00efeb1b7bba81b7de6e9457a3
Cr-Commit-Position: refs/heads/master@{#300192}

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

Cr-Commit-Position: refs/heads/master@{#300288}
parent 3f5d1eae
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "athena/activity/public/activity.h" #include "athena/activity/public/activity.h"
#include "athena/activity/public/activity_factory.h" #include "athena/activity/public/activity_factory.h"
#include "athena/test/base/athena_test_base.h" #include "athena/test/base/athena_test_base.h"
#include "athena/test/base/test_windows.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
namespace athena { namespace athena {
...@@ -53,7 +54,7 @@ TEST_F(ActivityManagerTest, GetActivityForWindow) { ...@@ -53,7 +54,7 @@ TEST_F(ActivityManagerTest, GetActivityForWindow) {
EXPECT_EQ(NULL, manager->GetActivityForWindow(NULL)); EXPECT_EQ(NULL, manager->GetActivityForWindow(NULL));
scoped_ptr<aura::Window> window = CreateTestWindow(NULL, gfx::Rect()); scoped_ptr<aura::Window> window = test::CreateNormalWindow(NULL, NULL);
EXPECT_EQ(NULL, manager->GetActivityForWindow(window.get())); EXPECT_EQ(NULL, manager->GetActivityForWindow(window.get()));
} }
......
...@@ -84,6 +84,8 @@ ...@@ -84,6 +84,8 @@
'screen/screen_accelerator_handler.cc', 'screen/screen_accelerator_handler.cc',
'screen/screen_accelerator_handler.h', 'screen/screen_accelerator_handler.h',
'screen/screen_manager_impl.cc', 'screen/screen_manager_impl.cc',
'screen/modal_window_controller.cc',
'screen/modal_window_controller.h',
'system/background_controller.cc', 'system/background_controller.cc',
'system/background_controller.h', 'system/background_controller.h',
'system/network_selector.cc', 'system/network_selector.cc',
...@@ -274,6 +276,8 @@ ...@@ -274,6 +276,8 @@
'test/base/test_app_model_builder.cc', 'test/base/test_app_model_builder.cc',
'test/base/test_app_model_builder.h', 'test/base/test_app_model_builder.h',
'test/base/test_resource_manager_delegate.cc', 'test/base/test_resource_manager_delegate.cc',
'test/base/test_windows.cc',
'test/base/test_windows.h',
'wm/test/window_manager_impl_test_api.cc', 'wm/test/window_manager_impl_test_api.cc',
'wm/test/window_manager_impl_test_api.h', 'wm/test/window_manager_impl_test_api.h',
], ],
...@@ -301,6 +305,7 @@ ...@@ -301,6 +305,7 @@
'input/input_manager_unittest.cc', 'input/input_manager_unittest.cc',
'resource_manager/memory_pressure_notifier_unittest.cc', 'resource_manager/memory_pressure_notifier_unittest.cc',
'resource_manager/resource_manager_unittest.cc', 'resource_manager/resource_manager_unittest.cc',
'screen/modal_window_controller_unittest.cc',
'screen/screen_manager_unittest.cc', 'screen/screen_manager_unittest.cc',
'test/base/athena_unittests.cc', 'test/base/athena_unittests.cc',
'util/drag_handle_unittest.cc', 'util/drag_handle_unittest.cc',
......
...@@ -115,8 +115,8 @@ void StartAthenaEnv(scoped_refptr<base::TaskRunner> blocking_task_runner) { ...@@ -115,8 +115,8 @@ void StartAthenaEnv(scoped_refptr<base::TaskRunner> blocking_task_runner) {
athena::InputManager::Create()->OnRootWindowCreated(root_window); athena::InputManager::Create()->OnRootWindowCreated(root_window);
athena::ScreenManager::Create(root_window); athena::ScreenManager::Create(root_window);
athena::SystemUI::Create(blocking_task_runner);
athena::WindowManager::Create(); athena::WindowManager::Create();
athena::SystemUI::Create(blocking_task_runner);
athena::AppRegistry::Create(); athena::AppRegistry::Create();
SetupBackgroundImage(); SetupBackgroundImage();
...@@ -166,8 +166,8 @@ void ShutdownAthena() { ...@@ -166,8 +166,8 @@ void ShutdownAthena() {
session_started = false; session_started = false;
} }
athena::AppRegistry::ShutDown(); athena::AppRegistry::ShutDown();
athena::WindowManager::Shutdown();
athena::SystemUI::Shutdown(); athena::SystemUI::Shutdown();
athena::WindowManager::Shutdown();
athena::ScreenManager::Shutdown(); athena::ScreenManager::Shutdown();
athena::InputManager::Shutdown(); athena::InputManager::Shutdown();
athena::AthenaEnv::Shutdown(); athena::AthenaEnv::Shutdown();
......
...@@ -5,4 +5,7 @@ include_rules = [ ...@@ -5,4 +5,7 @@ include_rules = [
"+ui/events", "+ui/events",
"+ui/gfx", "+ui/gfx",
"+ui/wm", "+ui/wm",
"+third_party/skia/include",
# for tests.
"+athena/athena_export.h",
] ]
// 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/modal_window_controller.h"
#include "athena/screen/public/screen_manager.h"
#include "base/message_loop/message_loop.h"
#include "ui/aura/window.h"
#include "ui/aura/window_property.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_animation_observer.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/wm/core/window_animations.h"
namespace athena {
namespace {
DEFINE_OWNED_WINDOW_PROPERTY_KEY(ModalWindowController,
kModalWindowControllerKey,
NULL);
} // namespace
// static
ModalWindowController* ModalWindowController::Get(aura::Window* container) {
ModalWindowController* controller =
container->GetProperty(kModalWindowControllerKey);
CHECK(controller);
return controller;
}
ModalWindowController::ModalWindowController(int priority)
: modal_container_(NULL),
dimmer_window_(new aura::Window(NULL)),
dimmed_(false) {
ScreenManager::ContainerParams params("ModalContainer", priority);
params.can_activate_children = true;
params.block_events = true;
modal_container_ = ScreenManager::Get()->CreateContainer(params);
modal_container_->SetProperty(kModalWindowControllerKey, this);
dimmer_window_->SetType(ui::wm::WINDOW_TYPE_NORMAL);
dimmer_window_->Init(aura::WINDOW_LAYER_SOLID_COLOR);
dimmer_window_->layer()->SetColor(SK_ColorBLACK);
dimmer_window_->layer()->SetOpacity(0.0f);
dimmer_window_->Show();
modal_container_->AddChild(dimmer_window_);
modal_container_->AddObserver(this);
UpdateDimmerWindowBounds();
}
ModalWindowController::~ModalWindowController() {
if (modal_container_)
modal_container_->RemoveObserver(this);
}
void ModalWindowController::OnWindowAdded(aura::Window* child) {
DCHECK_NE(child, dimmer_window_);
if (IsChildWindow(child)) {
child->AddObserver(this);
UpdateDimming(NULL);
}
}
void ModalWindowController::OnWindowVisibilityChanged(aura::Window* window,
bool visible) {
if (IsChildWindow(window))
UpdateDimming(NULL);
}
void ModalWindowController::OnWindowBoundsChanged(aura::Window* window,
const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) {
if (window == modal_container_)
UpdateDimmerWindowBounds();
}
void ModalWindowController::OnWindowDestroyed(aura::Window* window) {
UpdateDimming(window);
}
bool ModalWindowController::IsChildWindow(aura::Window* child) const {
return child->parent() == modal_container_ && child != dimmer_window_;
}
void ModalWindowController::UpdateDimmerWindowBounds() {
gfx::Rect bounds(modal_container_->bounds().size());
dimmer_window_->SetBounds(bounds);
}
void ModalWindowController::UpdateDimming(aura::Window* ignore) {
if (!modal_container_ || !dimmer_window_)
return;
bool should_delete = true;
for (aura::Window* window : modal_container_->children()) {
if (window == dimmer_window_ || window == ignore)
continue;
should_delete = false;
if (window->TargetVisibility()) {
SetDimmed(true);
return;
}
}
SetDimmed(false);
if (should_delete) {
// Remove the container from root so that the container becomes
// invisible, but don't delete it until next event execution
// because the call stack may still have and use the pointer.
modal_container_->RemoveObserver(this);
modal_container_->parent()->RemoveChild(modal_container_);
base::MessageLoopForUI::current()->DeleteSoon(FROM_HERE, modal_container_);
modal_container_ = NULL;
dimmer_window_ = NULL;
}
}
void ModalWindowController::SetDimmed(bool dimmed) {
const float kDimmedOpacity = 0.4f;
if (!dimmer_window_ || dimmed_ == dimmed)
return;
dimmed_ = dimmed;
const int kDimmAnimationDurationMs = 500;
if (dimmed) {
ui::ScopedLayerAnimationSettings settings(
dimmer_window_->layer()->GetAnimator());
settings.SetTransitionDuration(
base::TimeDelta::FromMilliseconds(kDimmAnimationDurationMs));
dimmer_window_->layer()->SetOpacity(kDimmedOpacity);
} else {
// ScopedHidingAnimationSettings will detach the animating and
// recreate layers for the container so that animation can continue
// even if the container is removed immediately.
wm::ScopedHidingAnimationSettings settings(modal_container_);
settings.layer_animation_settings()->SetTransitionDuration(
base::TimeDelta::FromMilliseconds(kDimmAnimationDurationMs));
modal_container_->layer()->SetOpacity(0.0f);
}
}
} // namespace athena
// 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_SCREEN_MODAL_WINDOW_CONTROLLER_H_
#define ATHENA_SCREEN_MODAL_WINDOW_CONTROLLER_H_
#include "athena/athena_export.h"
#include "ui/aura/window_observer.h"
namespace athena {
// ModalWindow controller manages the modal window and
// its container. This gets created when a modal window is opened
// and deleted when all modal windows are deleted.
class ATHENA_EXPORT ModalWindowController : public aura::WindowObserver {
public:
// Returns the ModalWindowController associated with the container.
static ModalWindowController* Get(aura::Window* container);
explicit ModalWindowController(int container_priority);
virtual ~ModalWindowController();
aura::Window* modal_container() { return modal_container_; }
bool dimmed() const { return dimmed_; }
private:
// aura::WindowObserver:
virtual void OnWindowAdded(aura::Window* child) override;
virtual void OnWindowVisibilityChanged(aura::Window* window,
bool visible) override;
virtual void OnWindowBoundsChanged(aura::Window* window,
const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) override;
virtual void OnWindowDestroyed(aura::Window* window) override;
// Tells if the child is not a dimmer window and a child of the modal
// container.
bool IsChildWindow(aura::Window* child) const;
void UpdateDimmerWindowBounds();
// Change dimming state based on the visible window in the container.
void UpdateDimming(aura::Window* ignore);
// Note: changing true -> false will delete the modal_container_.
void SetDimmed(bool dimmed);
aura::Window* modal_container_; // not owned.
aura::Window* dimmer_window_; // not owned.
bool dimmed_;
DISALLOW_COPY_AND_ASSIGN(ModalWindowController);
};
} // namespace athena
#endif // ATHENA_SCREEN_MODAL_WINDOW_CONTROLLER_H_
// 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/modal_window_controller.h"
#include "athena/screen/screen_manager_impl.h"
#include "athena/test/base/athena_test_base.h"
#include "athena/test/base/test_windows.h"
#include "athena/util/container_priorities.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/window.h"
namespace athena {
typedef test::AthenaTestBase ModalWindowControllerTest;
aura::Window* FindContainerByPriority(int priority) {
ScreenManagerImpl* screen_manager =
static_cast<ScreenManagerImpl*>(ScreenManager::Get());
return screen_manager->FindContainerByPriority(priority);
}
TEST_F(ModalWindowControllerTest, ModalContainer) {
aura::test::EventCountDelegate delegate;
scoped_ptr<aura::Window> modal(test::CreateTransientWindow(
&delegate, NULL, ui::MODAL_TYPE_SYSTEM, false));
aura::Window* modal_container = FindContainerByPriority(CP_SYSTEM_MODAL);
EXPECT_TRUE(modal_container);
ModalWindowController* modal_controller =
ModalWindowController::Get(modal_container);
ASSERT_TRUE(modal_controller);
EXPECT_EQ(modal_container, modal->parent());
EXPECT_FALSE(modal_controller->dimmed());
modal->Show();
EXPECT_TRUE(modal_controller->dimmed());
modal->Hide();
EXPECT_TRUE(FindContainerByPriority(CP_SYSTEM_MODAL));
EXPECT_FALSE(modal_controller->dimmed());
modal->Show();
EXPECT_TRUE(FindContainerByPriority(CP_SYSTEM_MODAL));
EXPECT_TRUE(modal_controller->dimmed());
modal.reset();
EXPECT_FALSE(FindContainerByPriority(CP_SYSTEM_MODAL));
// Create two.
modal = test::CreateTransientWindow(
&delegate, NULL, ui::MODAL_TYPE_SYSTEM, false).Pass();
scoped_ptr<aura::Window> modal2(test::CreateTransientWindow(
&delegate, NULL, ui::MODAL_TYPE_SYSTEM, false));
modal_container = FindContainerByPriority(CP_SYSTEM_MODAL);
EXPECT_TRUE(modal_container);
modal_controller = ModalWindowController::Get(modal_container);
ASSERT_TRUE(modal_controller);
EXPECT_EQ(modal_container, modal->parent());
EXPECT_EQ(modal_container, modal2->parent());
EXPECT_FALSE(modal_controller->dimmed());
modal->Show();
EXPECT_TRUE(modal_controller->dimmed());
modal2->Show();
EXPECT_TRUE(modal_controller->dimmed());
modal->Hide();
EXPECT_TRUE(modal_controller->dimmed());
modal2->Hide();
EXPECT_FALSE(modal_controller->dimmed());
EXPECT_TRUE(FindContainerByPriority(CP_SYSTEM_MODAL));
modal2.reset();
EXPECT_TRUE(FindContainerByPriority(CP_SYSTEM_MODAL));
EXPECT_FALSE(modal_controller->dimmed());
modal.reset();
EXPECT_FALSE(FindContainerByPriority(CP_SYSTEM_MODAL));
}
TEST_F(ModalWindowControllerTest, NestedModalWindows) {
ScreenManager::ContainerParams params("top", CP_END);
params.can_activate_children = true;
params.modal_container_priority = CP_END + 1;
aura::Window* top_container = ScreenManager::Get()->CreateContainer(params);
aura::test::TestWindowDelegate delegate;
scoped_ptr<aura::Window> top_w1(
test::CreateNormalWindow(&delegate, top_container));
EXPECT_EQ(top_container, top_w1->parent());
aura::Window* default_container = FindContainerByPriority(CP_DEFAULT);
EXPECT_TRUE(default_container);
scoped_ptr<aura::Window> normal_w1(test::CreateNormalWindow(&delegate, NULL));
EXPECT_EQ(default_container, normal_w1->parent());
scoped_ptr<aura::Window> normal_m1(test::CreateTransientWindow(
&delegate, normal_w1.get(), ui::MODAL_TYPE_SYSTEM, false));
aura::Window* default_modal_container =
FindContainerByPriority(CP_SYSTEM_MODAL);
EXPECT_EQ(default_modal_container, normal_m1->parent());
// A modal window with the transient parent which doesn't specify
// the modal container should fallback the default container's modal
// container.
aura::Window* home_container = FindContainerByPriority(CP_DEFAULT);
EXPECT_TRUE(home_container);
scoped_ptr<aura::Window> normal_m2(test::CreateTransientWindow(
&delegate, home_container, ui::MODAL_TYPE_SYSTEM, false));
EXPECT_EQ(default_modal_container, normal_m2->parent());
// No modal container for top container yet.
EXPECT_FALSE(FindContainerByPriority(CP_END + 1));
// Creating a modal with always on top creates the modal dialog on top
// most dialog container.
scoped_ptr<aura::Window> top_m0(test::CreateTransientWindow(
&delegate, NULL, ui::MODAL_TYPE_SYSTEM, true));
aura::Window* top_modal_container = FindContainerByPriority(CP_END + 1);
EXPECT_EQ(top_modal_container, top_m0->parent());
// Creating a modal dialog with transient parent on the top container
// creates the winodw on the top container's modal container.
scoped_ptr<aura::Window> top_m1(test::CreateTransientWindow(
&delegate, top_w1.get(), ui::MODAL_TYPE_SYSTEM, true));
EXPECT_EQ(top_modal_container, top_m1->parent());
normal_m1.reset();
EXPECT_TRUE(FindContainerByPriority(CP_SYSTEM_MODAL));
normal_m2.reset();
EXPECT_FALSE(FindContainerByPriority(CP_SYSTEM_MODAL));
top_m0.reset();
EXPECT_TRUE(FindContainerByPriority(CP_END + 1));
top_m1.reset();
EXPECT_FALSE(FindContainerByPriority(CP_END + 1));
}
} // namespace athena
...@@ -29,11 +29,37 @@ class ATHENA_EXPORT ScreenManager { ...@@ -29,11 +29,37 @@ class ATHENA_EXPORT ScreenManager {
// True if the container can activate its child window. // True if the container can activate its child window.
bool can_activate_children; bool can_activate_children;
// True if the container will grab all of input events. // True if the container will block evnets from containers behind it.
bool grab_inputs; bool block_events;
// Defines the z_order priority of the container. // Defines the z_order priority of the container.
int z_order_priority; int z_order_priority;
// True if this container should be used as a default parent.
bool default_parent;
// The container priority used to open modal dialog window
// created with this container as a transient parent (Note: A modal window
// should
// use a trnasient parent, not a direct parent, or no transient parent.)
//
// Default is -1, and it will fallback to the container behind this
// container,
// that has the modal container proiroty.
//
// The modal container for modal window is selected as follows.
// 1) a window must be created with |aura::client::kModalKey| property
// without explicit parent set.
// 2.a) If aura::client::kAlwaysOnTopKey is NOT set, it uses the stand flow
// described above. (fallback to containers behind this).
// 2.b) If aura::client::kAlwaysOnTopKey is set, it searches the top most
// container which has |modal_container_priority| != -1.
// 3) Look for the container with |modal_container_priority|, and create
// one if it doesn't exist.
//
// Created modal container will self destruct if last modal window
// is deleted.
int modal_container_priority;
}; };
// Creates, returns and deletes the singleton object of the ScreenManager // Creates, returns and deletes the singleton object of the ScreenManager
...@@ -44,11 +70,6 @@ class ATHENA_EXPORT ScreenManager { ...@@ -44,11 +70,6 @@ class ATHENA_EXPORT ScreenManager {
virtual ~ScreenManager() {} virtual ~ScreenManager() {}
// Creates the container window that is used when creating a normal
// widget without specific parent.
virtual aura::Window* CreateDefaultContainer(
const ContainerParams& params) = 0;
// Creates the container window on the screen. // Creates the container window on the screen.
virtual aura::Window* CreateContainer(const ContainerParams& params) = 0; virtual aura::Window* CreateContainer(const ContainerParams& params) = 0;
......
// Copyright 2014 The Chromium Authors. All rights reserved. // Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef ATHENA_SCREEN_SCREEN_ACCELERATOR_HANDLER_H_
#define ATHENA_SCREEN_SCREEN_ACCELERATOR_HANDLER_H_
#include "athena/input/public/accelerator_manager.h" #include "athena/input/public/accelerator_manager.h"
...@@ -31,3 +33,5 @@ class ScreenAcceleratorHandler : public AcceleratorHandler { ...@@ -31,3 +33,5 @@ class ScreenAcceleratorHandler : public AcceleratorHandler {
}; };
} // namespace athena } // namespace athena
#endif // ATHENA_SCREEN_SCREEN_ACCELERATOR_HANDLER_H_
This diff is collapsed.
// 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_SCREEN_SCREEN_MANAGER_IMPL_H_
#define ATHENA_SCREEN_SCREEN_MANAGER_IMPL_H_
#include "athena/athena_export.h"
#include "athena/screen/public/screen_manager.h"
#include "base/memory/scoped_ptr.h"
#include "ui/aura/client/window_tree_client.h"
namespace aura {
namespace client {
class FocusClient;
class ScreenPositionClient;
}
}
namespace wm {
class ScopedCaptureClient;
}
namespace athena {
class AcceleratorHandler;
class ATHENA_EXPORT ScreenManagerImpl : public ScreenManager,
public aura::client::WindowTreeClient {
public:
explicit ScreenManagerImpl(aura::Window* root_window);
virtual ~ScreenManagerImpl();
void Init();
// Returns a container which has |priority|. Null if such container
// doesn't exist.
aura::Window* FindContainerByPriority(int priority);
private:
// ScreenManager:
virtual aura::Window* CreateContainer(const ContainerParams& params) override;
virtual aura::Window* GetContext() override;
virtual void SetRotation(gfx::Display::Rotation rotation) override;
virtual void SetRotationLocked(bool rotation_locked) override;
// aura::client::WindowTreeClient:
virtual aura::Window* GetDefaultParent(aura::Window* context,
aura::Window* window,
const gfx::Rect& bounds) override;
int GetModalContainerPriority(aura::Window* window, aura::Window* parent);
// Returns a container with |params.default_parent| == true.
aura::Window* GetDefaultContainer();
// Not owned.
aura::Window* root_window_;
scoped_ptr<aura::client::FocusClient> focus_client_;
scoped_ptr<AcceleratorHandler> accelerator_handler_;
scoped_ptr<::wm::ScopedCaptureClient> capture_client_;
scoped_ptr<aura::client::ScreenPositionClient> screen_position_client_;
gfx::Display::Rotation last_requested_rotation_;
bool rotation_locked_;
DISALLOW_COPY_AND_ASSIGN(ScreenManagerImpl);
};
} // namespace athena
#endif // ATHENA_SCREEN_SCREEN_MANAGER_IMPL_H_
This diff is collapsed.
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "athena/system/network_selector.h" #include "athena/system/network_selector.h"
#include "athena/screen/public/screen_manager.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chromeos/network/network_configuration_handler.h" #include "chromeos/network/network_configuration_handler.h"
...@@ -38,6 +39,7 @@ ...@@ -38,6 +39,7 @@
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
#include "ui/views/layout/fill_layout.h" #include "ui/views/layout/fill_layout.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
#include "ui/views/window/dialog_delegate.h"
using chromeos::NetworkConfigurationHandler; using chromeos::NetworkConfigurationHandler;
using chromeos::NetworkConnectionHandler; using chromeos::NetworkConnectionHandler;
...@@ -47,18 +49,14 @@ using chromeos::NetworkState; ...@@ -47,18 +49,14 @@ using chromeos::NetworkState;
namespace { namespace {
const int kBackgroundColor = SkColorSetARGB(0x7f, 0, 0, 0);
// The View for the user to enter the password for connceting to a network. This // The View for the user to enter the password for connceting to a network. This
// view also shows an error message if the network connection fails. // view also shows an error message if the network connection fails.
class PasswordView : public views::View, public views::ButtonListener { class PasswordView : public views::View, public views::ButtonListener {
public: public:
PasswordView(const ui::NetworkInfo& network, PasswordView(const ui::NetworkInfo& network,
const base::Callback<void(bool)>& callback, const base::Callback<void(bool)>& callback)
views::View* parent_container)
: network_(network), : network_(network),
callback_(callback), callback_(callback),
parent_container_(parent_container),
connect_(NULL), connect_(NULL),
cancel_(NULL), cancel_(NULL),
textfield_(NULL), textfield_(NULL),
...@@ -102,7 +100,7 @@ class PasswordView : public views::View, public views::ButtonListener { ...@@ -102,7 +100,7 @@ class PasswordView : public views::View, public views::ButtonListener {
virtual ~PasswordView() {} virtual ~PasswordView() {}
private: private:
void Close(bool successful) { callback_.Run(successful); } void CloseDialog(bool successful) { callback_.Run(successful); }
void OnKnownError(const std::string& error_name, void OnKnownError(const std::string& error_name,
scoped_ptr<base::DictionaryValue> error_data) { scoped_ptr<base::DictionaryValue> error_data) {
...@@ -122,7 +120,7 @@ class PasswordView : public views::View, public views::ButtonListener { ...@@ -122,7 +120,7 @@ class PasswordView : public views::View, public views::ButtonListener {
if (!error_msg_->parent()) { if (!error_msg_->parent()) {
AddChildView(error_msg_); AddChildView(error_msg_);
InvalidateLayout(); InvalidateLayout();
parent_container_->Layout(); GetWidget()->GetRootView()->Layout();
ScrollRectToVisible(error_msg_->bounds()); ScrollRectToVisible(error_msg_->bounds());
} }
connect_->SetEnabled(true); connect_->SetEnabled(true);
...@@ -149,7 +147,7 @@ class PasswordView : public views::View, public views::ButtonListener { ...@@ -149,7 +147,7 @@ class PasswordView : public views::View, public views::ButtonListener {
check_error_state); check_error_state);
} }
void OnConnectionSucceed() { Close(true); } void OnConnectionSucceed() { CloseDialog(true); }
// views::View: // views::View:
virtual void ViewHierarchyChanged( virtual void ViewHierarchyChanged(
...@@ -176,7 +174,7 @@ class PasswordView : public views::View, public views::ButtonListener { ...@@ -176,7 +174,7 @@ class PasswordView : public views::View, public views::ButtonListener {
textfield_->text()), textfield_->text()),
base::Bind(&PasswordView::OnKnownError, weak_ptr_.GetWeakPtr())); base::Bind(&PasswordView::OnKnownError, weak_ptr_.GetWeakPtr()));
} else if (sender == cancel_) { } else if (sender == cancel_) {
Close(false); CloseDialog(false);
} else { } else {
NOTREACHED(); NOTREACHED();
} }
...@@ -184,7 +182,6 @@ class PasswordView : public views::View, public views::ButtonListener { ...@@ -184,7 +182,6 @@ class PasswordView : public views::View, public views::ButtonListener {
ui::NetworkInfo network_; ui::NetworkInfo network_;
base::Callback<void(bool)> callback_; base::Callback<void(bool)> callback_;
views::View* parent_container_;
views::BlueButton* connect_; views::BlueButton* connect_;
views::LabelButton* cancel_; views::LabelButton* cancel_;
...@@ -199,8 +196,8 @@ class PasswordView : public views::View, public views::ButtonListener { ...@@ -199,8 +196,8 @@ class PasswordView : public views::View, public views::ButtonListener {
// contains the View for taking password for password-protected networks. // contains the View for taking password for password-protected networks.
class NetworkRow : public views::View { class NetworkRow : public views::View {
public: public:
NetworkRow(const ui::NetworkInfo& network, views::View* container) NetworkRow(const ui::NetworkInfo& network)
: network_(network), container_(container), weak_ptr_(this) { : network_(network), weak_ptr_(this) {
SetBorder(views::Border::CreateEmptyBorder(10, 5, 10, 5)); SetBorder(views::Border::CreateEmptyBorder(10, 5, 10, 5));
SetLayoutManager( SetLayoutManager(
new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 10)); new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 10));
...@@ -230,7 +227,7 @@ class NetworkRow : public views::View { ...@@ -230,7 +227,7 @@ class NetworkRow : public views::View {
void OnPasswordComplete(bool successful) { void OnPasswordComplete(bool successful) {
password_view_.reset(); password_view_.reset();
InvalidateLayout(); InvalidateLayout();
container_->Layout(); GetWidget()->GetRootView()->Layout();
ScrollRectToVisible(GetContentsBounds()); ScrollRectToVisible(GetContentsBounds());
} }
...@@ -249,12 +246,11 @@ class NetworkRow : public views::View { ...@@ -249,12 +246,11 @@ class NetworkRow : public views::View {
password_view_.reset(new PasswordView( password_view_.reset(new PasswordView(
network_, network_,
base::Bind(&NetworkRow::OnPasswordComplete, weak_ptr_.GetWeakPtr()), base::Bind(&NetworkRow::OnPasswordComplete, weak_ptr_.GetWeakPtr())));
container_));
password_view_->set_owned_by_client(); password_view_->set_owned_by_client();
AddChildView(password_view_.get()); AddChildView(password_view_.get());
PreferredSizeChanged(); PreferredSizeChanged();
container_->Layout(); GetWidget()->GetRootView()->Layout();
ScrollRectToVisible(password_view_->bounds()); ScrollRectToVisible(password_view_->bounds());
} }
...@@ -310,7 +306,6 @@ class NetworkRow : public views::View { ...@@ -310,7 +306,6 @@ class NetworkRow : public views::View {
} }
ui::NetworkInfo network_; ui::NetworkInfo network_;
views::View* container_;
scoped_ptr<views::View> password_view_; scoped_ptr<views::View> password_view_;
base::WeakPtrFactory<NetworkRow> weak_ptr_; base::WeakPtrFactory<NetworkRow> weak_ptr_;
...@@ -319,15 +314,12 @@ class NetworkRow : public views::View { ...@@ -319,15 +314,12 @@ class NetworkRow : public views::View {
class NetworkSelector : public ui::NetworkListDelegate, class NetworkSelector : public ui::NetworkListDelegate,
public chromeos::NetworkStateHandlerObserver, public chromeos::NetworkStateHandlerObserver,
public ui::EventHandler { public views::DialogDelegate {
public: public:
explicit NetworkSelector(aura::Window* container) NetworkSelector()
: background_view_(NULL), : scroll_content_(NULL), scroller_(NULL), network_list_(this) {
scroll_content_(NULL),
scroller_(NULL),
network_list_(this) {
CreateWidget(container);
CreateNetworkList(); CreateNetworkList();
CreateWidget();
NetworkHandler::Get()->network_state_handler()->RequestScan(); NetworkHandler::Get()->network_state_handler()->RequestScan();
NetworkHandler::Get()->network_state_handler()->AddObserver(this, NetworkHandler::Get()->network_state_handler()->AddObserver(this,
...@@ -340,36 +332,19 @@ class NetworkSelector : public ui::NetworkListDelegate, ...@@ -340,36 +332,19 @@ class NetworkSelector : public ui::NetworkListDelegate,
} }
private: private:
void CreateWidget(aura::Window* container) { void CreateWidget() {
views::Widget::InitParams params; // Same as CreateDialogWidgetWithBounds() with an empty |bounds|.
params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS; views::Widget* widget = views::DialogDelegate::CreateDialogWidget(
params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; this, athena::ScreenManager::Get()->GetContext(), NULL);
params.activatable = views::Widget::InitParams::ACTIVATABLE_DEFAULT; widget->Show();
params.accept_events = true; widget->CenterWindow(gfx::Size(400, 400));
params.bounds = gfx::Rect(container->bounds().size());
params.parent = container;
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
widget_.reset(new views::Widget());
widget_->Init(params);
widget_->Show();
background_view_ = new views::View;
background_view_->set_background(
views::Background::CreateSolidBackground(kBackgroundColor));
background_view_->SetBorder(
views::Border::CreateEmptyBorder(100, 300, 300, 300));
background_view_->SetLayoutManager(new views::FillLayout());
background_view_->set_target_handler(this);
widget_->SetContentsView(background_view_);
} }
void CreateNetworkList() { void CreateNetworkList() {
const int kListHeight = 500; const int kListHeight = 400;
scroller_ = new views::ScrollView(); scroller_ = new views::ScrollView();
scroller_->set_background( scroller_->set_background(
views::Background::CreateSolidBackground(SK_ColorWHITE)); views::Background::CreateSolidBackground(SK_ColorWHITE));
scroller_->SetBounds(0, 0, 400, kListHeight);
scroll_content_ = new views::View; scroll_content_ = new views::View;
scroll_content_->SetLayoutManager( scroll_content_->SetLayoutManager(
...@@ -378,21 +353,16 @@ class NetworkSelector : public ui::NetworkListDelegate, ...@@ -378,21 +353,16 @@ class NetworkSelector : public ui::NetworkListDelegate,
scroller_->ClipHeightTo(kListHeight, kListHeight); scroller_->ClipHeightTo(kListHeight, kListHeight);
scroller_->SetVerticalScrollBar(new views::OverlayScrollBar(false)); scroller_->SetVerticalScrollBar(new views::OverlayScrollBar(false));
background_view_->AddChildView(scroller_);
background_view_->Layout();
network_list_.set_content_view(scroll_content_); network_list_.set_content_view(scroll_content_);
} }
void UpdateNetworkList() { network_list_.UpdateNetworkList(); } void UpdateNetworkList() { network_list_.UpdateNetworkList(); }
void Close() { delete this; }
// ui::NetworkListDelegate: // ui::NetworkListDelegate:
virtual views::View* CreateViewForNetwork( virtual views::View* CreateViewForNetwork(
const ui::NetworkInfo& info) override { const ui::NetworkInfo& info) override {
return new NetworkRow(info, background_view_); return new NetworkRow(info);
} }
virtual bool IsViewHovered(views::View* view) override { virtual bool IsViewHovered(views::View* view) override {
...@@ -429,25 +399,19 @@ class NetworkSelector : public ui::NetworkListDelegate, ...@@ -429,25 +399,19 @@ class NetworkSelector : public ui::NetworkListDelegate,
virtual void NetworkPropertiesUpdated( virtual void NetworkPropertiesUpdated(
const chromeos::NetworkState* network) override {} const chromeos::NetworkState* network) override {}
// ui::EventHandler: // views::DialogDelegate:
virtual void OnMouseEvent(ui::MouseEvent* mouse) override { virtual ui::ModalType GetModalType() const override {
CHECK_EQ(background_view_, mouse->target()); return ui::MODAL_TYPE_SYSTEM;
if (mouse->type() == ui::ET_MOUSE_PRESSED && !mouse->handled()) {
Close();
mouse->SetHandled();
}
} }
virtual void DeleteDelegate() override { delete this; }
virtual void OnGestureEvent(ui::GestureEvent* gesture) override { virtual views::Widget* GetWidget() override { return scroller_->GetWidget(); }
CHECK_EQ(background_view_, gesture->target()); virtual const views::Widget* GetWidget() const override {
if (gesture->type() == ui::ET_GESTURE_TAP && !gesture->handled()) { return scroller_->GetWidget();
Close();
gesture->SetHandled();
}
} }
virtual views::View* GetContentsView() override { return scroller_; }
virtual int GetDialogButtons() const override { return ui::DIALOG_BUTTON_OK; }
virtual bool Close() override { return true; }
scoped_ptr<views::Widget> widget_;
views::View* background_view_;
views::View* scroll_content_; views::View* scroll_content_;
views::ScrollView* scroller_; views::ScrollView* scroller_;
...@@ -462,8 +426,8 @@ class NetworkSelector : public ui::NetworkListDelegate, ...@@ -462,8 +426,8 @@ class NetworkSelector : public ui::NetworkListDelegate,
namespace athena { namespace athena {
void CreateNetworkSelector(aura::Window* container) { void CreateNetworkSelector() {
new NetworkSelector(container); new NetworkSelector();
} }
} // namespace athena } // namespace athena
...@@ -5,13 +5,9 @@ ...@@ -5,13 +5,9 @@
#ifndef ATHENA_SYSTEM_NETWORK_SELECTOR_H_ #ifndef ATHENA_SYSTEM_NETWORK_SELECTOR_H_
#define ATHENA_SYSTEM_NETWORK_SELECTOR_H_ #define ATHENA_SYSTEM_NETWORK_SELECTOR_H_
namespace aura {
class Window;
}
namespace athena { namespace athena {
void CreateNetworkSelector(aura::Window* window); void CreateNetworkSelector();
} // namespace athena } // namespace athena
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
#include "ui/views/window/dialog_delegate.h"
namespace athena { namespace athena {
namespace { namespace {
...@@ -23,10 +24,33 @@ namespace { ...@@ -23,10 +24,33 @@ namespace {
// device after shutdown dialog is shown. // device after shutdown dialog is shown.
const int kShutdownTimeoutMs = 4000; const int kShutdownTimeoutMs = 4000;
class ModalWidgetDelegate : public views::WidgetDelegate {
public:
explicit ModalWidgetDelegate(views::View* contents_view)
: contents_view_(contents_view) {}
virtual ~ModalWidgetDelegate() {}
// Overridden from WidgetDelegate:
virtual views::Widget* GetWidget() override {
return contents_view_->GetWidget();
}
virtual const views::Widget* GetWidget() const override {
return contents_view_->GetWidget();
}
virtual views::View* GetContentsView() override { return contents_view_; }
virtual ui::ModalType GetModalType() const override {
return ui::MODAL_TYPE_SYSTEM;
}
private:
views::View* contents_view_;
DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate);
};
} // namespace } // namespace
ShutdownDialog::ShutdownDialog(aura::Window* dialog_container) ShutdownDialog::ShutdownDialog() : state_(STATE_OTHER) {
: warning_message_container_(dialog_container), state_(STATE_OTHER) {
InputManager::Get()->AddPowerButtonObserver(this); InputManager::Get()->AddPowerButtonObserver(this);
} }
...@@ -37,13 +61,6 @@ ShutdownDialog::~ShutdownDialog() { ...@@ -37,13 +61,6 @@ ShutdownDialog::~ShutdownDialog() {
void ShutdownDialog::ShowShutdownWarningDialog() { void ShutdownDialog::ShowShutdownWarningDialog() {
state_ = STATE_SHUTDOWN_WARNING_VISIBLE; state_ = STATE_SHUTDOWN_WARNING_VISIBLE;
shutdown_warning_message_.reset(new views::Widget);
views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.parent = warning_message_container_;
shutdown_warning_message_->Init(params);
views::Label* label = views::Label* label =
new views::Label(l10n_util::GetStringUTF16(IDS_ATHENA_SHUTDOWN_WARNING)); new views::Label(l10n_util::GetStringUTF16(IDS_ATHENA_SHUTDOWN_WARNING));
label->SetBackgroundColor(SK_ColorWHITE); label->SetBackgroundColor(SK_ColorWHITE);
...@@ -59,9 +76,18 @@ void ShutdownDialog::ShowShutdownWarningDialog() { ...@@ -59,9 +76,18 @@ void ShutdownDialog::ShowShutdownWarningDialog() {
views::Background::CreateSolidBackground(SK_ColorWHITE)); views::Background::CreateSolidBackground(SK_ColorWHITE));
container->SetBorder(views::Border::CreateSolidBorder(1, SK_ColorBLACK)); container->SetBorder(views::Border::CreateSolidBorder(1, SK_ColorBLACK));
shutdown_warning_message_->SetContentsView(container); views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
shutdown_warning_message_->CenterWindow(container->GetPreferredSize()); params.delegate = new ModalWidgetDelegate(container);
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.context = ScreenManager::Get()->GetContext();
// Use top most modal container.
params.keep_on_top = true;
shutdown_warning_message_.reset(new views::Widget);
shutdown_warning_message_->Init(params);
shutdown_warning_message_->Show(); shutdown_warning_message_->Show();
shutdown_warning_message_->CenterWindow(container->GetPreferredSize());
timer_.Start(FROM_HERE, timer_.Start(FROM_HERE,
base::TimeDelta::FromMilliseconds(kShutdownTimeoutMs), base::TimeDelta::FromMilliseconds(kShutdownTimeoutMs),
this, this,
......
...@@ -23,7 +23,7 @@ namespace athena { ...@@ -23,7 +23,7 @@ namespace athena {
// Shuts down in response to the power button being pressed. // Shuts down in response to the power button being pressed.
class ShutdownDialog : public PowerButtonObserver { class ShutdownDialog : public PowerButtonObserver {
public: public:
explicit ShutdownDialog(aura::Window* dialog_container); explicit ShutdownDialog();
virtual ~ShutdownDialog(); virtual ~ShutdownDialog();
private: private:
......
...@@ -208,9 +208,7 @@ class StatusIconContainerView::UpdateStatus ...@@ -208,9 +208,7 @@ class StatusIconContainerView::UpdateStatus
}; };
StatusIconContainerView::StatusIconContainerView( StatusIconContainerView::StatusIconContainerView(
SystemUI::ColorScheme color_scheme, SystemUI::ColorScheme color_scheme) {
aura::Window* system_modal_container)
: system_modal_container_(system_modal_container) {
const int kHorizontalSpacing = 10; const int kHorizontalSpacing = 10;
const int kVerticalSpacing = 3; const int kVerticalSpacing = 3;
const int kBetweenChildSpacing = 10; const int kBetweenChildSpacing = 10;
...@@ -241,13 +239,13 @@ StatusIconContainerView::~StatusIconContainerView() { ...@@ -241,13 +239,13 @@ StatusIconContainerView::~StatusIconContainerView() {
} }
bool StatusIconContainerView::OnMousePressed(const ui::MouseEvent& event) { bool StatusIconContainerView::OnMousePressed(const ui::MouseEvent& event) {
CreateNetworkSelector(system_modal_container_); CreateNetworkSelector();
return true; return true;
} }
void StatusIconContainerView::OnGestureEvent(ui::GestureEvent* event) { void StatusIconContainerView::OnGestureEvent(ui::GestureEvent* event) {
if (event->type() == ui::ET_GESTURE_TAP) { if (event->type() == ui::ET_GESTURE_TAP) {
CreateNetworkSelector(system_modal_container_); CreateNetworkSelector();
event->SetHandled(); event->SetHandled();
} }
} }
......
...@@ -9,17 +9,12 @@ ...@@ -9,17 +9,12 @@
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "ui/views/view.h" #include "ui/views/view.h"
namespace aura {
class Window;
}
namespace athena { namespace athena {
// View which displays the system tray icons. // View which displays the system tray icons.
class StatusIconContainerView : public views::View { class StatusIconContainerView : public views::View {
public: public:
StatusIconContainerView(SystemUI::ColorScheme color_scheme, StatusIconContainerView(SystemUI::ColorScheme color_scheme);
aura::Window* popup_container);
virtual ~StatusIconContainerView(); virtual ~StatusIconContainerView();
private: private:
...@@ -28,9 +23,6 @@ class StatusIconContainerView : public views::View { ...@@ -28,9 +23,6 @@ class StatusIconContainerView : public views::View {
virtual void OnGestureEvent(ui::GestureEvent* event) override; virtual void OnGestureEvent(ui::GestureEvent* event) override;
virtual void ChildPreferredSizeChanged(views::View* child) override; virtual void ChildPreferredSizeChanged(views::View* child) override;
// Parent container that the "select network" dialog should use.
aura::Window* system_modal_container_;
class PowerStatus; class PowerStatus;
scoped_ptr<PowerStatus> power_status_; scoped_ptr<PowerStatus> power_status_;
......
...@@ -27,11 +27,9 @@ SystemUI* instance = NULL; ...@@ -27,11 +27,9 @@ SystemUI* instance = NULL;
// right. // right.
class SystemInfoView : public views::View { class SystemInfoView : public views::View {
public: public:
SystemInfoView(SystemUI::ColorScheme color_scheme, SystemInfoView(SystemUI::ColorScheme color_scheme)
aura::Window* system_modal_container)
: time_view_(new TimeView(color_scheme)), : time_view_(new TimeView(color_scheme)),
status_icon_view_( status_icon_view_(new StatusIconContainerView(color_scheme)) {
new StatusIconContainerView(color_scheme, system_modal_container)) {
AddChildView(time_view_); AddChildView(time_view_);
AddChildView(status_icon_view_); AddChildView(status_icon_view_);
} }
...@@ -76,8 +74,7 @@ class SystemUIImpl : public SystemUI { ...@@ -76,8 +74,7 @@ class SystemUIImpl : public SystemUI {
public: public:
SystemUIImpl(scoped_refptr<base::TaskRunner> blocking_task_runner) SystemUIImpl(scoped_refptr<base::TaskRunner> blocking_task_runner)
: orientation_controller_(new OrientationController()), : orientation_controller_(new OrientationController()),
background_container_(NULL), background_container_(NULL) {
system_modal_container_(NULL) {
orientation_controller_->InitWith(blocking_task_runner); orientation_controller_->InitWith(blocking_task_runner);
} }
...@@ -93,34 +90,22 @@ class SystemUIImpl : public SystemUI { ...@@ -93,34 +90,22 @@ class SystemUIImpl : public SystemUI {
ScreenManager::ContainerParams("AthenaBackground", CP_BACKGROUND)); ScreenManager::ContainerParams("AthenaBackground", CP_BACKGROUND));
background_container_->SetLayoutManager( background_container_->SetLayoutManager(
new FillLayoutManager(background_container_)); new FillLayoutManager(background_container_));
ScreenManager::ContainerParams system_modal_params(
"AthenaSystemModalContainer", CP_SYSTEM_MODAL); shutdown_dialog_.reset(new ShutdownDialog());
system_modal_params.can_activate_children = true;
system_modal_container_ =
screen_manager->CreateContainer(system_modal_params);
login_screen_system_modal_container_ = screen_manager->CreateContainer(
ScreenManager::ContainerParams("AthenaLoginScreenSystemModalContainer",
CP_LOGIN_SCREEN_SYSTEM_MODAL));
// Use |login_screen_system_modal_container_| for the power button's dialog
// because it needs to show over the login screen.
// TODO(pkotwicz): Pick the most appropriate container based on whether the
// user has logged in.
shutdown_dialog_.reset(
new ShutdownDialog(login_screen_system_modal_container_));
background_controller_.reset( background_controller_.reset(
new BackgroundController(background_container_)); new BackgroundController(background_container_));
} }
private:
// SystemUI:
virtual void SetBackgroundImage(const gfx::ImageSkia& image) override { virtual void SetBackgroundImage(const gfx::ImageSkia& image) override {
background_controller_->SetImage(image); background_controller_->SetImage(image);
} }
virtual views::View* CreateSystemInfoView(ColorScheme color_scheme) override { virtual views::View* CreateSystemInfoView(ColorScheme color_scheme) override {
return new SystemInfoView(color_scheme, system_modal_container_); return new SystemInfoView(color_scheme);
} }
private:
scoped_ptr<OrientationController> orientation_controller_; scoped_ptr<OrientationController> orientation_controller_;
scoped_ptr<ShutdownDialog> shutdown_dialog_; scoped_ptr<ShutdownDialog> shutdown_dialog_;
scoped_ptr<BackgroundController> background_controller_; scoped_ptr<BackgroundController> background_controller_;
......
...@@ -16,6 +16,6 @@ include_rules = [ ...@@ -16,6 +16,6 @@ include_rules = [
"+ui/gfx", "+ui/gfx",
"+ui/gl", "+ui/gl",
"+ui/views", "+ui/views",
"+ui/wm/core", "+ui/wm",
] ]
...@@ -5,11 +5,8 @@ ...@@ -5,11 +5,8 @@
#include "athena/test/base/athena_test_base.h" #include "athena/test/base/athena_test_base.h"
#include "athena/env/public/athena_env.h" #include "athena/env/public/athena_env.h"
#include "athena/screen/public/screen_manager.h"
#include "athena/test/base/athena_test_helper.h" #include "athena/test/base/athena_test_helper.h"
#include "ui/aura/client/window_tree_client.h"
#include "ui/aura/test/event_generator_delegate_aura.h" #include "ui/aura/test/event_generator_delegate_aura.h"
#include "ui/aura/window.h"
#include "ui/compositor/test/context_factories_for_test.h" #include "ui/compositor/test/context_factories_for_test.h"
#if defined(USE_X11) #if defined(USE_X11)
...@@ -65,16 +62,5 @@ void AthenaTestBase::RunAllPendingInMessageLoop() { ...@@ -65,16 +62,5 @@ void AthenaTestBase::RunAllPendingInMessageLoop() {
helper_->RunAllPendingInMessageLoop(); helper_->RunAllPendingInMessageLoop();
} }
scoped_ptr<aura::Window> AthenaTestBase::CreateTestWindow(
aura::WindowDelegate* delegate,
const gfx::Rect& bounds) {
scoped_ptr<aura::Window> window(new aura::Window(delegate));
window->SetType(ui::wm::WINDOW_TYPE_NORMAL);
window->Init(aura::WINDOW_LAYER_SOLID_COLOR);
aura::client::ParentWindowWithContext(
window.get(), ScreenManager::Get()->GetContext(), bounds);
return window.Pass();
}
} // namespace test } // namespace test
} // namespace athena } // namespace athena
...@@ -31,9 +31,6 @@ class AthenaTestBase : public testing::Test { ...@@ -31,9 +31,6 @@ class AthenaTestBase : public testing::Test {
protected: protected:
void RunAllPendingInMessageLoop(); void RunAllPendingInMessageLoop();
scoped_ptr<aura::Window> CreateTestWindow(aura::WindowDelegate* delegate,
const gfx::Rect& bounds);
aura::Window* root_window() { return helper_->GetRootWindow(); } aura::Window* root_window() { return helper_->GetRootWindow(); }
aura::WindowTreeHost* host() { return helper_->GetHost(); } aura::WindowTreeHost* host() { return helper_->GetHost(); }
......
// 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/test/base/test_windows.h"
#include "athena/screen/public/screen_manager.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/window_tree_client.h"
#include "ui/aura/window.h"
#include "ui/wm/core/window_util.h"
namespace athena {
namespace test {
scoped_ptr<aura::Window> CreateNormalWindow(aura::WindowDelegate* delegate,
aura::Window* parent) {
return CreateWindowWithType(delegate, parent, ui::wm::WINDOW_TYPE_NORMAL);
}
scoped_ptr<aura::Window> CreateWindowWithType(aura::WindowDelegate* delegate,
aura::Window* parent,
ui::wm::WindowType window_type) {
scoped_ptr<aura::Window> window(new aura::Window(delegate));
window->SetType(window_type);
window->Init(aura::WINDOW_LAYER_SOLID_COLOR);
if (parent) {
parent->AddChild(window.get());
} else {
aura::client::ParentWindowWithContext(
window.get(), ScreenManager::Get()->GetContext(), gfx::Rect());
}
return window.Pass();
}
scoped_ptr<aura::Window> CreateTransientWindow(aura::WindowDelegate* delegate,
aura::Window* transient_parent,
ui::ModalType modal_type,
bool top_most) {
scoped_ptr<aura::Window> window(new aura::Window(delegate));
window->SetType(ui::wm::WINDOW_TYPE_NORMAL);
window->Init(aura::WINDOW_LAYER_SOLID_COLOR);
window->SetProperty(aura::client::kModalKey, modal_type);
window->SetProperty(aura::client::kAlwaysOnTopKey, top_most);
if (transient_parent)
wm::AddTransientChild(transient_parent, window.get());
aura::client::ParentWindowWithContext(
window.get(), ScreenManager::Get()->GetContext(), gfx::Rect());
return window.Pass();
}
} // namespace test
} // namespace athena
// 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_TEST_BASE_TEST_WINDOWS_H_
#define ATHENA_TEST_BASE_TEST_WINDOWS_H_
#include "base/memory/scoped_ptr.h"
#include "ui/base/ui_base_types.h"
#include "ui/wm/public/window_types.h"
namespace aura {
class Window;
class WindowDelegate;
}
namespace gfx {
class Rect;
}
namespace athena {
namespace test {
scoped_ptr<aura::Window> CreateNormalWindow(aura::WindowDelegate* delegate,
aura::Window* parent);
scoped_ptr<aura::Window> CreateWindowWithType(aura::WindowDelegate* delegate,
aura::Window* parent,
ui::wm::WindowType window_type);
scoped_ptr<aura::Window> CreateTransientWindow(aura::WindowDelegate* delegate,
aura::Window* transient_parent,
ui::ModalType modal_type,
bool top_most);
} // namespace test
} // namespace athena
#endif // ATHENA_TEST_BASE_TEST_WINDOWS_H_
...@@ -12,9 +12,11 @@ enum ContainerPriorities { ...@@ -12,9 +12,11 @@ enum ContainerPriorities {
CP_DEFAULT, CP_DEFAULT,
CP_HOME_CARD, CP_HOME_CARD,
CP_SYSTEM_MODAL, CP_SYSTEM_MODAL,
// TODO(oshima): rename LOGIN_xxx to something more generic.
CP_LOGIN_SCREEN, CP_LOGIN_SCREEN,
CP_LOGIN_SCREEN_SYSTEM_MODAL, CP_LOGIN_SCREEN_SYSTEM_MODAL,
CP_VIRTUAL_KEYBOARD, CP_VIRTUAL_KEYBOARD,
CP_END,
}; };
} // namespace athena } // namespace athena
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "athena/screen/public/screen_manager.h" #include "athena/screen/public/screen_manager.h"
#include "athena/test/base/athena_test_base.h" #include "athena/test/base/athena_test_base.h"
#include "athena/test/base/test_windows.h"
#include "athena/wm/public/window_list_provider.h" #include "athena/wm/public/window_list_provider.h"
#include "athena/wm/test/window_manager_impl_test_api.h" #include "athena/wm/test/window_manager_impl_test_api.h"
#include "base/memory/scoped_vector.h" #include "base/memory/scoped_vector.h"
...@@ -102,7 +103,7 @@ TEST_F(SplitViewControllerTest, SplitModeActivation) { ...@@ -102,7 +103,7 @@ TEST_F(SplitViewControllerTest, SplitModeActivation) {
ScopedVector<aura::Window> windows; ScopedVector<aura::Window> windows;
const int kNumWindows = 6; const int kNumWindows = 6;
for (size_t i = 0; i < kNumWindows; ++i) { for (size_t i = 0; i < kNumWindows; ++i) {
scoped_ptr<aura::Window> window = CreateTestWindow(NULL, gfx::Rect()); scoped_ptr<aura::Window> window = test::CreateNormalWindow(NULL, NULL);
windows.push_back(window.release()); windows.push_back(window.release());
windows[i]->Hide(); windows[i]->Hide();
} }
...@@ -194,7 +195,7 @@ TEST_F(SplitViewControllerTest, ScrollDragHandle) { ...@@ -194,7 +195,7 @@ TEST_F(SplitViewControllerTest, ScrollDragHandle) {
ScopedVector<aura::Window> windows; ScopedVector<aura::Window> windows;
const int kNumWindows = 2; const int kNumWindows = 2;
for (size_t i = 0; i < kNumWindows; ++i) { for (size_t i = 0; i < kNumWindows; ++i) {
scoped_ptr<aura::Window> window = CreateTestWindow(NULL, gfx::Rect()); scoped_ptr<aura::Window> window = test::CreateNormalWindow(NULL, NULL);
windows.push_back(window.release()); windows.push_back(window.release());
windows[i]->Hide(); windows[i]->Hide();
} }
...@@ -290,7 +291,7 @@ TEST_F(SplitViewControllerTest, LandscapeOnly) { ...@@ -290,7 +291,7 @@ TEST_F(SplitViewControllerTest, LandscapeOnly) {
ScopedVector<aura::Window> windows; ScopedVector<aura::Window> windows;
const int kNumWindows = 2; const int kNumWindows = 2;
for (size_t i = 0; i < kNumWindows; ++i) { for (size_t i = 0; i < kNumWindows; ++i) {
scoped_ptr<aura::Window> window = CreateTestWindow(NULL, gfx::Rect()); scoped_ptr<aura::Window> window = test::CreateNormalWindow(NULL, NULL);
window->Hide(); window->Hide();
windows.push_back(window.release()); windows.push_back(window.release());
} }
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "athena/screen/public/screen_manager.h" #include "athena/screen/public/screen_manager.h"
#include "athena/test/base/athena_test_base.h" #include "athena/test/base/athena_test_base.h"
#include "athena/test/base/test_windows.h"
#include "athena/wm/public/window_list_provider_observer.h" #include "athena/wm/public/window_list_provider_observer.h"
#include "athena/wm/public/window_manager.h" #include "athena/wm/public/window_manager.h"
#include "ui/aura/client/window_tree_client.h" #include "ui/aura/client/window_tree_client.h"
...@@ -36,18 +37,6 @@ scoped_ptr<aura::Window> CreateWindow(aura::Window* parent, ...@@ -36,18 +37,6 @@ scoped_ptr<aura::Window> CreateWindow(aura::Window* parent,
return window.Pass(); return window.Pass();
} }
scoped_ptr<aura::Window> CreateTransientWindow(aura::Window* transient_parent,
aura::WindowDelegate* delegate,
ui::wm::WindowType window_type) {
scoped_ptr<aura::Window> window(new aura::Window(delegate));
window->SetType(window_type);
window->Init(aura::WINDOW_LAYER_SOLID_COLOR);
wm::AddTransientChild(transient_parent, window.get());
aura::client::ParentWindowWithContext(
window.get(), ScreenManager::Get()->GetContext(), gfx::Rect());
return window.Pass();
}
// Return a string which defines the order of windows in |now| using the indices // Return a string which defines the order of windows in |now| using the indices
// of |original|. The string will then have the lowest/oldest window on the left // of |original|. The string will then have the lowest/oldest window on the left
// and the highest / newest on the right. // and the highest / newest on the right.
...@@ -116,8 +105,8 @@ TEST_F(WindowListProviderImplTest, StackingOrder) { ...@@ -116,8 +105,8 @@ TEST_F(WindowListProviderImplTest, StackingOrder) {
scoped_ptr<WindowListProvider> list_provider( scoped_ptr<WindowListProvider> list_provider(
new WindowListProviderImpl(container.get())); new WindowListProviderImpl(container.get()));
scoped_ptr<aura::Window> first = scoped_ptr<aura::Window> first = test::CreateWindowWithType(
CreateWindow(container.get(), &delegate, ui::wm::WINDOW_TYPE_NORMAL); &delegate, container.get(), ui::wm::WINDOW_TYPE_NORMAL);
scoped_ptr<aura::Window> second = scoped_ptr<aura::Window> second =
CreateWindow(container.get(), &delegate, ui::wm::WINDOW_TYPE_NORMAL); CreateWindow(container.get(), &delegate, ui::wm::WINDOW_TYPE_NORMAL);
scoped_ptr<aura::Window> third = scoped_ptr<aura::Window> third =
...@@ -307,12 +296,12 @@ TEST_F(WindowListProviderImplTest, TransientWindows) { ...@@ -307,12 +296,12 @@ TEST_F(WindowListProviderImplTest, TransientWindows) {
scoped_ptr<WindowListObserver> observer( scoped_ptr<WindowListObserver> observer(
new WindowListObserver(list_provider)); new WindowListObserver(list_provider));
scoped_ptr<aura::Window> w1 = CreateTestWindow(&delegate, gfx::Rect()); scoped_ptr<aura::Window> w1 = test::CreateNormalWindow(&delegate, NULL);
w1->Show(); w1->Show();
scoped_ptr<aura::Window> w2 = CreateTestWindow(&delegate, gfx::Rect()); scoped_ptr<aura::Window> w2 = test::CreateNormalWindow(&delegate, NULL);
w2->Show(); w2->Show();
scoped_ptr<aura::Window> t1 = scoped_ptr<aura::Window> t1 = test::CreateTransientWindow(
CreateTransientWindow(w1.get(), &delegate, ui::wm::WINDOW_TYPE_NORMAL); &delegate, w1.get(), ui::MODAL_TYPE_NONE, false);
t1->Show(); t1->Show();
EXPECT_EQ(2u, list_provider->GetWindowList().size()); EXPECT_EQ(2u, list_provider->GetWindowList().size());
......
...@@ -150,7 +150,9 @@ void AthenaContainerLayoutManager::SetChildBounds( ...@@ -150,7 +150,9 @@ void AthenaContainerLayoutManager::SetChildBounds(
WindowManagerImpl::WindowManagerImpl() { WindowManagerImpl::WindowManagerImpl() {
ScreenManager::ContainerParams params("DefaultContainer", CP_DEFAULT); ScreenManager::ContainerParams params("DefaultContainer", CP_DEFAULT);
params.can_activate_children = true; params.can_activate_children = true;
container_.reset(ScreenManager::Get()->CreateDefaultContainer(params)); params.default_parent = true;
params.modal_container_priority = CP_SYSTEM_MODAL;
container_.reset(ScreenManager::Get()->CreateContainer(params));
container_->SetLayoutManager(new AthenaContainerLayoutManager); container_->SetLayoutManager(new AthenaContainerLayoutManager);
container_->AddObserver(this); container_->AddObserver(this);
window_list_provider_.reset(new WindowListProviderImpl(container_.get())); window_list_provider_.reset(new WindowListProviderImpl(container_.get()));
...@@ -164,6 +166,8 @@ WindowManagerImpl::WindowManagerImpl() { ...@@ -164,6 +166,8 @@ WindowManagerImpl::WindowManagerImpl() {
wm_state_.reset(new wm::WMState()); wm_state_.reset(new wm::WMState());
aura::client::ActivationClient* activation_client = aura::client::ActivationClient* activation_client =
aura::client::GetActivationClient(container_->GetRootWindow()); aura::client::GetActivationClient(container_->GetRootWindow());
DCHECK(container_->GetRootWindow());
DCHECK(activation_client);
shadow_controller_.reset(new wm::ShadowController(activation_client)); shadow_controller_.reset(new wm::ShadowController(activation_client));
instance = this; instance = this;
InstallAccelerators(); InstallAccelerators();
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "athena/screen/public/screen_manager.h" #include "athena/screen/public/screen_manager.h"
#include "athena/test/base/athena_test_base.h" #include "athena/test/base/athena_test_base.h"
#include "athena/test/base/test_windows.h"
#include "athena/wm/public/window_list_provider.h" #include "athena/wm/public/window_list_provider.h"
#include "athena/wm/split_view_controller.h" #include "athena/wm/split_view_controller.h"
#include "athena/wm/test/window_manager_impl_test_api.h" #include "athena/wm/test/window_manager_impl_test_api.h"
...@@ -28,7 +29,7 @@ class WindowManagerTest : public test::AthenaTestBase { ...@@ -28,7 +29,7 @@ class WindowManagerTest : public test::AthenaTestBase {
scoped_ptr<aura::Window> CreateAndActivateWindow( scoped_ptr<aura::Window> CreateAndActivateWindow(
aura::WindowDelegate* delegate) { aura::WindowDelegate* delegate) {
scoped_ptr<aura::Window> window(CreateTestWindow(delegate, gfx::Rect())); scoped_ptr<aura::Window> window(test::CreateNormalWindow(delegate, NULL));
window->Show(); window->Show();
wm::ActivateWindow(window.get()); wm::ActivateWindow(window.get());
return window.Pass(); return window.Pass();
......
...@@ -70,7 +70,9 @@ void LockWindowAura::Init() { ...@@ -70,7 +70,9 @@ void LockWindowAura::Init() {
athena::ScreenManager::ContainerParams container_params( athena::ScreenManager::ContainerParams container_params(
"LoginScreen", athena::CP_LOGIN_SCREEN); "LoginScreen", athena::CP_LOGIN_SCREEN);
container_params.can_activate_children = true; container_params.can_activate_children = true;
container_params.grab_inputs = true; container_params.block_events = true;
container_params.modal_container_priority =
athena::CP_LOGIN_SCREEN_SYSTEM_MODAL;
lock_screen_container_.reset( lock_screen_container_.reset(
athena::ScreenManager::Get()->CreateContainer(container_params)); athena::ScreenManager::Get()->CreateContainer(container_params));
params.parent = lock_screen_container_.get(); params.parent = lock_screen_container_.get();
......
...@@ -1063,6 +1063,9 @@ void LoginDisplayHostImpl::InitLoginWindowAndView() { ...@@ -1063,6 +1063,9 @@ void LoginDisplayHostImpl::InitLoginWindowAndView() {
athena::ScreenManager::ContainerParams container_params( athena::ScreenManager::ContainerParams container_params(
"LoginScreen", athena::CP_LOGIN_SCREEN); "LoginScreen", athena::CP_LOGIN_SCREEN);
container_params.can_activate_children = true; container_params.can_activate_children = true;
container_params.block_events = true;
container_params.modal_container_priority =
athena::CP_LOGIN_SCREEN_SYSTEM_MODAL;
login_screen_container_.reset( login_screen_container_.reset(
athena::ScreenManager::Get()->CreateContainer(container_params)); athena::ScreenManager::Get()->CreateContainer(container_params));
params.parent = login_screen_container_.get(); params.parent = login_screen_container_.get();
......
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