Home | History | Annotate | Download | only in wm
      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 "base/basictypes.h"
     12 #include "base/compiler_specific.h"
     13 #include "base/memory/scoped_ptr.h"
     14 #include "ui/aura/layout_manager.h"
     15 #include "ui/aura/window_observer.h"
     16 
     17 namespace aura {
     18 class Window;
     19 class EventFilter;
     20 }
     21 namespace gfx {
     22 class Rect;
     23 }
     24 namespace views {
     25 class Widget;
     26 }
     27 
     28 namespace ash {
     29 namespace internal {
     30 
     31 // LayoutManager for the modal window container.
     32 class ASH_EXPORT SystemModalContainerLayoutManager
     33     : public aura::LayoutManager,
     34       public aura::WindowObserver {
     35  public:
     36   explicit SystemModalContainerLayoutManager(aura::Window* container);
     37   virtual ~SystemModalContainerLayoutManager();
     38 
     39   bool has_modal_background() const { return modal_background_ != NULL; }
     40 
     41   // Overridden from aura::LayoutManager:
     42   virtual void OnWindowResized() OVERRIDE;
     43   virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE;
     44   virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE;
     45   virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE;
     46   virtual void OnChildWindowVisibilityChanged(aura::Window* child,
     47                                               bool visibile) OVERRIDE;
     48   virtual void SetChildBounds(aura::Window* child,
     49                               const gfx::Rect& requested_bounds) OVERRIDE;
     50 
     51   // Overridden from aura::WindowObserver:
     52   virtual void OnWindowPropertyChanged(aura::Window* window,
     53                                        const void* key,
     54                                        intptr_t old) OVERRIDE;
     55   virtual void OnWindowDestroying(aura::Window* window) OVERRIDE;
     56 
     57   // Can a given |window| receive and handle input events?
     58   bool CanWindowReceiveEvents(aura::Window* window);
     59 
     60   // Activates next modal window if any. Returns false if there
     61   // are no more modal windows in this layout manager.
     62   bool ActivateNextModalWindow();
     63 
     64   // Creates modal background window, which is a partially-opaque
     65   // fullscreen window. If there is already a modal background window,
     66   // it will bring it the top.
     67   void CreateModalBackground();
     68 
     69   void DestroyModalBackground();
     70 
     71   // Is the |window| modal background?
     72   static bool IsModalBackground(aura::Window* window);
     73 
     74  private:
     75   void AddModalWindow(aura::Window* window);
     76   void RemoveModalWindow(aura::Window* window);
     77 
     78   aura::Window* modal_window() {
     79     return !modal_windows_.empty() ? modal_windows_.back() : NULL;
     80   }
     81 
     82   // The container that owns the layout manager.
     83   aura::Window* container_;
     84 
     85   // A widget that dims the windows behind the modal window(s) being
     86   // shown in |container_|.
     87   views::Widget* modal_background_;
     88 
     89   // A stack of modal windows. Only the topmost can receive events.
     90   std::vector<aura::Window*> modal_windows_;
     91 
     92   DISALLOW_COPY_AND_ASSIGN(SystemModalContainerLayoutManager);
     93 };
     94 
     95 }  // namespace internal
     96 }  // namespace ash
     97 
     98 #endif  // ASH_WM_SYSTEM_MODAL_CONTAINER_LAYOUT_MANAGER_H_
     99