| Index: ui/aura_shell/transient_container_layout_manager.cc
|
| ===================================================================
|
| --- ui/aura_shell/transient_container_layout_manager.cc (revision 0)
|
| +++ ui/aura_shell/transient_container_layout_manager.cc (revision 0)
|
| @@ -0,0 +1,190 @@
|
| +// Copyright (c) 2011 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 "ui/aura_shell/transient_container_layout_manager.h"
|
| +
|
| +#include "base/bind.h"
|
| +#include "ui/aura/client/aura_constants.h"
|
| +#include "ui/aura/desktop.h"
|
| +#include "ui/aura/event.h"
|
| +#include "ui/aura/window.h"
|
| +#include "ui/aura_shell/shell.h"
|
| +#include "ui/aura_shell/stacking_controller.h"
|
| +#include "ui/gfx/canvas.h"
|
| +#include "ui/gfx/compositor/layer.h"
|
| +#include "ui/gfx/compositor/layer_animator.h"
|
| +#include "views/view.h"
|
| +#include "views/widget/widget.h"
|
| +
|
| +namespace aura_shell {
|
| +namespace internal {
|
| +
|
| +namespace {
|
| +
|
| +class ScreenView : public views::View {
|
| + public:
|
| + ScreenView() {}
|
| + virtual ~ScreenView() {}
|
| +
|
| + // Overridden from views::View:
|
| + virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
|
| + canvas->FillRect(SK_ColorBLACK, GetLocalBounds());
|
| + }
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(ScreenView);
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// TransientContainerLayoutManager, public:
|
| +
|
| +TransientContainerLayoutManager::TransientContainerLayoutManager(
|
| + aura::Window* container)
|
| + : container_(container),
|
| + modal_screen_(NULL),
|
| + ALLOW_THIS_IN_INITIALIZER_LIST(
|
| + modality_filter_(new ModalityEventFilter(container, this))) {
|
| +}
|
| +
|
| +TransientContainerLayoutManager::~TransientContainerLayoutManager() {
|
| +}
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// TransientContainerLayoutManager, aura::LayoutManager implementation:
|
| +
|
| +void TransientContainerLayoutManager::OnWindowResized() {
|
| + if (modal_screen_) {
|
| + modal_screen_->SetBounds(gfx::Rect(0, 0, container_->bounds().width(),
|
| + container_->bounds().height()));
|
| + }
|
| +}
|
| +
|
| +void TransientContainerLayoutManager::OnWindowAddedToLayout(
|
| + aura::Window* child) {
|
| + child->AddObserver(this);
|
| +}
|
| +
|
| +void TransientContainerLayoutManager::OnWillRemoveWindowFromLayout(
|
| + aura::Window* child) {
|
| + child->RemoveObserver(this);
|
| + if (child->GetBoolProperty(aura::kModalKey))
|
| + RemoveModalWindow(child);
|
| +}
|
| +
|
| +void TransientContainerLayoutManager::OnChildWindowVisibilityChanged(
|
| + aura::Window* child,
|
| + bool visible) {
|
| +}
|
| +
|
| +void TransientContainerLayoutManager::SetChildBounds(
|
| + aura::Window* child,
|
| + const gfx::Rect& requested_bounds) {
|
| + SetChildBoundsDirect(child, requested_bounds);
|
| +}
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// TransientContainerLayoutManager, aura::WindowObserver implementation:
|
| +
|
| +void TransientContainerLayoutManager::OnPropertyChanged(aura::Window* window,
|
| + const char* key,
|
| + void* old) {
|
| + if (key != aura::kModalKey)
|
| + return;
|
| +
|
| + if (window->GetBoolProperty(aura::kModalKey)) {
|
| + AddModalWindow(window);
|
| + } else if (reinterpret_cast<bool>(old)) {
|
| + RemoveModalWindow(window);
|
| + }
|
| +}
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// TransientContainerLayoutManager, ui::LayerAnimationObserver implementation:
|
| +
|
| +void TransientContainerLayoutManager::OnLayerAnimationEnded(
|
| + const ui::LayerAnimationSequence* sequence) {
|
| + if (modal_screen_ && !modal_screen_->GetNativeView()->layer()->ShouldDraw())
|
| + DestroyModalScreen();
|
| +}
|
| +
|
| +void TransientContainerLayoutManager::OnLayerAnimationAborted(
|
| + const ui::LayerAnimationSequence* sequence) {
|
| +}
|
| +
|
| +void TransientContainerLayoutManager::OnLayerAnimationScheduled(
|
| + const ui::LayerAnimationSequence* sequence) {
|
| +}
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// TransientContainerLayoutManager,
|
| +// ModalityEventFilter::Delegate implementation:
|
| +
|
| +bool TransientContainerLayoutManager::CanWindowReceiveEvents(
|
| + aura::Window* window) {
|
| + return StackingController::GetActivatableWindow(window) == modal_window();
|
| +}
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// TransientContainerLayoutManager, private:
|
| +
|
| +void TransientContainerLayoutManager::AddModalWindow(aura::Window* window) {
|
| + modal_windows_.push_back(window);
|
| + CreateModalScreen();
|
| + container_->MoveChildToFront(window);
|
| + window->Activate();
|
| +}
|
| +
|
| +void TransientContainerLayoutManager::RemoveModalWindow(aura::Window* window) {
|
| + aura::Window::Windows::iterator it =
|
| + std::find(modal_windows_.begin(), modal_windows_.end(), window);
|
| + if (it != modal_windows_.end())
|
| + modal_windows_.erase(it);
|
| +
|
| + if (modal_windows_.empty())
|
| + HideModalScreen();
|
| + else
|
| + modal_window()->Activate();
|
| +}
|
| +
|
| +void TransientContainerLayoutManager::CreateModalScreen() {
|
| + if (modal_screen_)
|
| + return;
|
| + modal_screen_ = new views::Widget;
|
| + views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL);
|
| + params.parent = container_;
|
| + params.bounds = gfx::Rect(0, 0, container_->bounds().width(),
|
| + container_->bounds().height());
|
| + modal_screen_->Init(params);
|
| + modal_screen_->GetNativeView()->set_name(
|
| + "TransientContainerLayoutManager.ModalScreen");
|
| + modal_screen_->SetContentsView(new ScreenView);
|
| + modal_screen_->GetNativeView()->layer()->SetOpacity(0.0f);
|
| + modal_screen_->GetNativeView()->layer()->GetAnimator()->AddObserver(this);
|
| +
|
| + Shell::GetInstance()->AddDesktopEventFilter(modality_filter_.get());
|
| +
|
| + ui::LayerAnimator::ScopedSettings settings(
|
| + modal_screen_->GetNativeView()->layer()->GetAnimator());
|
| + modal_screen_->Show();
|
| + modal_screen_->GetNativeView()->layer()->SetOpacity(0.5f);
|
| + container_->MoveChildToFront(modal_screen_->GetNativeView());
|
| +}
|
| +
|
| +void TransientContainerLayoutManager::DestroyModalScreen() {
|
| + modal_screen_->GetNativeView()->layer()->GetAnimator()->RemoveObserver(this);
|
| + modal_screen_->Close();
|
| + modal_screen_ = NULL;
|
| +}
|
| +
|
| +void TransientContainerLayoutManager::HideModalScreen() {
|
| + Shell::GetInstance()->RemoveDesktopEventFilter(modality_filter_.get());
|
| + ui::LayerAnimator::ScopedSettings settings(
|
| + modal_screen_->GetNativeView()->layer()->GetAnimator());
|
| + modal_screen_->GetNativeView()->layer()->SetOpacity(0.0f);
|
| +}
|
| +
|
| +} // namespace internal
|
| +} // namespace aura_shell
|
|
|
| Property changes on: ui\aura_shell\transient_container_layout_manager.cc
|
| ___________________________________________________________________
|
| Added: svn:eol-style
|
| + LF
|
|
|
|
|