Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ash / wm / system_modal_container_layout_manager.h
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef ASH_WM_SYSTEM_MODAL_CONTAINER_LAYOUT_MANAGER_H_
6 #define ASH_WM_SYSTEM_MODAL_CONTAINER_LAYOUT_MANAGER_H_
7
8 #include <vector>
9
10 #include "ash/ash_export.h"
11 #include "ash/snap_to_pixel_layout_manager.h"
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "ui/aura/window_observer.h"
16 #include "ui/keyboard/keyboard_controller_observer.h"
17
18 namespace aura {
19 class Window;
20 class EventFilter;
21 }
22 namespace gfx {
23 class Rect;
24 }
25 namespace views {
26 class Widget;
27 }
28
29 namespace ash {
30
31 // LayoutManager for the modal window container.
32 // System modal windows which are centered on the screen will be kept centered
33 // when the container size changes.
34 class ASH_EXPORT SystemModalContainerLayoutManager
35     : public SnapToPixelLayoutManager,
36       public aura::WindowObserver,
37       public keyboard::KeyboardControllerObserver {
38  public:
39   explicit SystemModalContainerLayoutManager(aura::Window* container);
40   ~SystemModalContainerLayoutManager() override;
41
42   bool has_modal_background() const { return modal_background_ != NULL; }
43
44   // Overridden from SnapToPixelLayoutManager:
45   void OnWindowResized() override;
46   void OnWindowAddedToLayout(aura::Window* child) override;
47   void OnWillRemoveWindowFromLayout(aura::Window* child) override;
48   void SetChildBounds(aura::Window* child,
49                       const gfx::Rect& requested_bounds) override;
50
51   // Overridden from aura::WindowObserver:
52   void OnWindowPropertyChanged(aura::Window* window,
53                                const void* key,
54                                intptr_t old) override;
55   void OnWindowDestroying(aura::Window* window) override;
56
57   // Overridden from keyboard::KeyboardControllerObserver:
58   void OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) override;
59
60   // Can a given |window| receive and handle input events?
61   bool CanWindowReceiveEvents(aura::Window* window);
62
63   // Activates next modal window if any. Returns false if there
64   // are no more modal windows in this layout manager.
65   bool ActivateNextModalWindow();
66
67   // Creates modal background window, which is a partially-opaque
68   // fullscreen window. If there is already a modal background window,
69   // it will bring it the top.
70   void CreateModalBackground();
71
72   void DestroyModalBackground();
73
74   // Is the |window| modal background?
75   static bool IsModalBackground(aura::Window* window);
76
77  private:
78   void AddModalWindow(aura::Window* window);
79   void RemoveModalWindow(aura::Window* window);
80
81   // Reposition the dialogs to become visible after the work area changes.
82   void PositionDialogsAfterWorkAreaResize();
83
84   // Get the usable bounds rectangle for enclosed dialogs.
85   gfx::Rect GetUsableDialogArea();
86
87   // Gets the new bounds for a |window| to use which are either centered (if the
88   // window was previously centered) or fitted to the screen.
89   gfx::Rect GetCenteredAndOrFittedBounds(const aura::Window* window);
90
91   // Returns true if |window_bounds| is centered.
92   bool DialogIsCentered(const gfx::Rect& window_bounds);
93
94   aura::Window* modal_window() {
95     return !modal_windows_.empty() ? modal_windows_.back() : NULL;
96   }
97
98   // The container that owns the layout manager.
99   aura::Window* container_;
100
101   // A widget that dims the windows behind the modal window(s) being
102   // shown in |container_|.
103   views::Widget* modal_background_;
104
105   // A stack of modal windows. Only the topmost can receive events.
106   std::vector<aura::Window*> modal_windows_;
107
108   DISALLOW_COPY_AND_ASSIGN(SystemModalContainerLayoutManager);
109 };
110
111 }  // namespace ash
112
113 #endif  // ASH_WM_SYSTEM_MODAL_CONTAINER_LAYOUT_MANAGER_H_