summaryrefslogtreecommitdiffstats
path: root/ash/wm/modal_container_layout_manager.h
blob: 471430bc2417eb064ccafbd064cd40d4db6f396b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// 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.

#ifndef ASH_WM_MODAL_CONTAINER_LAYOUT_MANAGER_H_
#define ASH_WM_MODAL_CONTAINER_LAYOUT_MANAGER_H_
#pragma once

#include <vector>

#include "ash/wm/modality_event_filter_delegate.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "ui/aura/layout_manager.h"
#include "ui/aura/window_observer.h"
#include "ui/aura_shell/aura_shell_export.h"
#include "ui/gfx/compositor/layer_animation_observer.h"

namespace aura {
class Window;
class EventFilter;
}
namespace gfx {
class Rect;
}
namespace views {
class Widget;
}

namespace aura_shell {
namespace internal {

// LayoutManager for the modal window container.
class AURA_SHELL_EXPORT ModalContainerLayoutManager
    : public aura::LayoutManager,
      public aura::WindowObserver,
      public ui::LayerAnimationObserver,
      public ModalityEventFilterDelegate {
 public:
  explicit ModalContainerLayoutManager(aura::Window* container);
  virtual ~ModalContainerLayoutManager();

  // Overridden from aura::LayoutManager:
  virtual void OnWindowResized() OVERRIDE;
  virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE;
  virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE;
  virtual void OnChildWindowVisibilityChanged(aura::Window* child,
                                              bool visibile) OVERRIDE;
  virtual void SetChildBounds(aura::Window* child,
                              const gfx::Rect& requested_bounds) OVERRIDE;

  // Overridden from aura::WindowObserver:
  virtual void OnWindowPropertyChanged(aura::Window* window,
                                       const char* key,
                                       void* old) OVERRIDE;

  // Overridden from ui::LayerAnimationObserver:
  virtual void OnLayerAnimationEnded(
      const ui::LayerAnimationSequence* sequence) OVERRIDE;
  virtual void OnLayerAnimationAborted(
      const ui::LayerAnimationSequence* sequence) OVERRIDE;
  virtual void OnLayerAnimationScheduled(
      const ui::LayerAnimationSequence* sequence) OVERRIDE;

  // Overridden from ModalityEventFilterDelegate:
  virtual bool CanWindowReceiveEvents(aura::Window* window) OVERRIDE;

 private:
  void AddModalWindow(aura::Window* window);
  void RemoveModalWindow(aura::Window* window);

  void CreateModalScreen();
  void DestroyModalScreen();
  void HideModalScreen();

  aura::Window* modal_window() {
    return !modal_windows_.empty() ? modal_windows_.back() : NULL;
  }

  // The container that owns the layout manager.
  aura::Window* container_;

  // A "screen" widget that dims the windows behind the modal window(s) being
  // shown in |container_|.
  views::Widget* modal_screen_;

  // A stack of modal windows. Only the topmost can receive events.
  std::vector<aura::Window*> modal_windows_;

  // An event filter that enforces the modality of the topmost window in
  // |modal_windows_|. The event filter is attached when a modal window is
  // added, and removed when the last is closed.
  scoped_ptr<aura::EventFilter> modality_filter_;

  DISALLOW_COPY_AND_ASSIGN(ModalContainerLayoutManager);
};

}  // namespace internal
}  // namespace aura_shell

#endif  // ASH_WM_MODAL_CONTAINER_LAYOUT_MANAGER_H_