Enable snappy for IndexedDB.
[chromium-blink-merge.git] / ash / wm / base_layout_manager.h
blob7a94bf389cbc5460df6120535ca05eb5fb4bb375
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.
5 #ifndef ASH_WM_BASE_LAYOUT_MANAGER_H_
6 #define ASH_WM_BASE_LAYOUT_MANAGER_H_
8 #include <set>
10 #include "ash/ash_export.h"
11 #include "ash/shell_observer.h"
12 #include "ash/wm/window_state_observer.h"
13 #include "base/basictypes.h"
14 #include "base/compiler_specific.h"
15 #include "ui/aura/client/activation_change_observer.h"
16 #include "ui/aura/layout_manager.h"
17 #include "ui/aura/window_observer.h"
18 #include "ui/base/ui_base_types.h"
19 #include "ui/events/event_handler.h"
21 namespace aura {
22 class RootWindow;
23 class Window;
26 namespace ash {
27 namespace wm {
28 class WindowState;
31 namespace internal {
33 // BaseLayoutManager is the simplest possible implementation for a window
34 // layout manager. It listens for changes to kShowStateKey and resizes the
35 // window appropriately. Subclasses should be sure to invoke the base class
36 // for adding and removing windows, otherwise show state will not be tracked
37 // properly.
38 class ASH_EXPORT BaseLayoutManager
39 : public aura::LayoutManager,
40 public aura::WindowObserver,
41 public aura::client::ActivationChangeObserver,
42 public ShellObserver,
43 public wm::WindowStateObserver {
44 public:
45 typedef std::set<aura::Window*> WindowSet;
47 explicit BaseLayoutManager(aura::RootWindow* root_window);
48 virtual ~BaseLayoutManager();
50 const WindowSet& windows() const { return windows_; }
52 // Given a |window| and tentative |restore_bounds|, returns new bounds that
53 // ensure that at least a few pixels of the screen background are visible
54 // outside the edges of the window.
55 static gfx::Rect BoundsWithScreenEdgeVisible(aura::Window* window,
56 const gfx::Rect& restore_bounds);
58 // aura::LayoutManager overrides:
59 virtual void OnWindowResized() OVERRIDE;
60 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE;
61 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE;
62 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE;
63 virtual void OnChildWindowVisibilityChanged(aura::Window* child,
64 bool visible) OVERRIDE;
65 virtual void SetChildBounds(aura::Window* child,
66 const gfx::Rect& requested_bounds) OVERRIDE;
68 // aura::WindowObserver overrides:
69 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE;
70 virtual void OnWindowBoundsChanged(aura::Window* window,
71 const gfx::Rect& old_bounds,
72 const gfx::Rect& new_bounds) OVERRIDE;
74 // aura::client::ActivationChangeObserver overrides:
75 virtual void OnWindowActivated(aura::Window* gained_active,
76 aura::Window* lost_active) OVERRIDE;
78 // ash::ShellObserver overrides:
79 virtual void OnDisplayWorkAreaInsetsChanged() OVERRIDE;
81 // wm::WindowStateObserver overrides:
82 virtual void OnWindowShowTypeChanged(wm::WindowState* window_state,
83 wm::WindowShowType type) OVERRIDE;
85 protected:
86 enum AdjustWindowReason {
87 ADJUST_WINDOW_DISPLAY_SIZE_CHANGED,
88 ADJUST_WINDOW_WORK_AREA_INSETS_CHANGED,
91 // Invoked from OnWindowPropertyChanged() if |kShowStateKey| changes.
92 virtual void ShowStateChanged(wm::WindowState* window_state,
93 ui::WindowShowState last_show_state);
95 // Adjusts the window's bounds when the display area changes for given
96 // window. This happens when the display size, work area insets or
97 // the display on which the window exists has changed.
98 // If this is called for a display size change (i.e. |reason|
99 // is ADJUST_WINDOW_DISPLAY_SIZE_CHANGED), the non-maximized/non-fullscreen
100 // windows are readjusted to make sure the window is completely within the
101 // display region. Otherwise, it makes sure at least some parts of the window
102 // is on display.
103 virtual void AdjustAllWindowsBoundsForWorkAreaChange(
104 AdjustWindowReason reason);
106 // Adjusts the sizes of the specific window in respond to a screen change or
107 // display-area size change.
108 virtual void AdjustWindowBoundsForWorkAreaChange(
109 wm::WindowState* window_state,
110 AdjustWindowReason reason);
112 aura::RootWindow* root_window() { return root_window_; }
114 private:
115 // Update window bounds based on a change in show state.
116 void UpdateBoundsFromShowState(wm::WindowState* controller);
118 // Set of windows we're listening to.
119 WindowSet windows_;
121 aura::RootWindow* root_window_;
123 DISALLOW_COPY_AND_ASSIGN(BaseLayoutManager);
126 } // namespace internal
127 } // namespace ash
129 #endif // ASH_WM_BASE_LAYOUT_MANAGER_H_