| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef ASH_COMMON_WM_WINDOW_POSITIONER_H_ | 5 #ifndef ASH_COMMON_WM_WINDOW_POSITIONER_H_ |
| 6 #define ASH_COMMON_WM_WINDOW_POSITIONER_H_ | 6 #define ASH_COMMON_WM_WINDOW_POSITIONER_H_ |
| 7 | 7 |
| 8 #include "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "ui/base/ui_base_types.h" | 10 #include "ui/base/ui_base_types.h" |
| 11 | 11 |
| 12 namespace display { | 12 namespace display { |
| 13 class Display; | 13 class Display; |
| 14 } | 14 } |
| 15 | 15 |
| 16 namespace gfx { | 16 namespace gfx { |
| 17 class Rect; | 17 class Rect; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace ash { | 20 namespace ash { |
| 21 namespace wm { | 21 |
| 22 class WmGlobals; | 22 class WmShell; |
| 23 class WmWindow; | 23 class WmWindow; |
| 24 } | |
| 25 | 24 |
| 26 namespace test { | 25 namespace test { |
| 27 class WindowPositionerTest; | 26 class WindowPositionerTest; |
| 28 } | 27 } |
| 29 | 28 |
| 30 // WindowPositioner is used by the browser to move new popups automatically to | 29 // WindowPositioner is used by the browser to move new popups automatically to |
| 31 // a usable position on the closest work area (of the active window). | 30 // a usable position on the closest work area (of the active window). |
| 32 class ASH_EXPORT WindowPositioner { | 31 class ASH_EXPORT WindowPositioner { |
| 33 public: | 32 public: |
| 34 // When the screen resolution width is smaller then this size, The algorithm | 33 // When the screen resolution width is smaller then this size, The algorithm |
| 35 // will default to maximized. | 34 // will default to maximized. |
| 36 static int GetForceMaximizedWidthLimit(); | 35 static int GetForceMaximizedWidthLimit(); |
| 37 | 36 |
| 38 // The number of pixels which are kept free top, left and right when a window | 37 // The number of pixels which are kept free top, left and right when a window |
| 39 // gets positioned to its default location. | 38 // gets positioned to its default location. |
| 40 static const int kDesktopBorderSize; | 39 static const int kDesktopBorderSize; |
| 41 | 40 |
| 42 // Maximum width of a window even if there is more room on the desktop. | 41 // Maximum width of a window even if there is more room on the desktop. |
| 43 static const int kMaximumWindowWidth; | 42 static const int kMaximumWindowWidth; |
| 44 | 43 |
| 45 // Computes and returns the bounds and show state for new window | 44 // Computes and returns the bounds and show state for new window |
| 46 // based on the parameter passed AND existing windows. |window| is | 45 // based on the parameter passed AND existing windows. |window| is |
| 47 // the one this function will generate a bounds for and used to | 46 // the one this function will generate a bounds for and used to |
| 48 // exclude the self window in making decision how to position the | 47 // exclude the self window in making decision how to position the |
| 49 // window. |window| can be (and in most case) NULL. | 48 // window. |window| can be (and in most case) NULL. |
| 50 // |is_saved_bounds| indicates the |bounds_in_out| is the saved | 49 // |is_saved_bounds| indicates the |bounds_in_out| is the saved |
| 51 // bounds. | 50 // bounds. |
| 52 static void GetBoundsAndShowStateForNewWindow( | 51 static void GetBoundsAndShowStateForNewWindow( |
| 53 const wm::WmWindow* new_window, | 52 const WmWindow* new_window, |
| 54 bool is_saved_bounds, | 53 bool is_saved_bounds, |
| 55 ui::WindowShowState show_state_in, | 54 ui::WindowShowState show_state_in, |
| 56 gfx::Rect* bounds_in_out, | 55 gfx::Rect* bounds_in_out, |
| 57 ui::WindowShowState* show_state_out); | 56 ui::WindowShowState* show_state_out); |
| 58 | 57 |
| 59 // Returns the default bounds for a window to be created in the |display|. | 58 // Returns the default bounds for a window to be created in the |display|. |
| 60 static gfx::Rect GetDefaultWindowBounds(const display::Display& display); | 59 static gfx::Rect GetDefaultWindowBounds(const display::Display& display); |
| 61 | 60 |
| 62 // Check if after removal or hide of the given |removed_window| an | 61 // Check if after removal or hide of the given |removed_window| an |
| 63 // automated desktop location management can be performed and | 62 // automated desktop location management can be performed and |
| 64 // rearrange accordingly. | 63 // rearrange accordingly. |
| 65 static void RearrangeVisibleWindowOnHideOrRemove( | 64 static void RearrangeVisibleWindowOnHideOrRemove( |
| 66 const wm::WmWindow* removed_window); | 65 const WmWindow* removed_window); |
| 67 | 66 |
| 68 // Turn the automatic positioning logic temporarily off. Returns the previous | 67 // Turn the automatic positioning logic temporarily off. Returns the previous |
| 69 // state. | 68 // state. |
| 70 static bool DisableAutoPositioning(bool ignore); | 69 static bool DisableAutoPositioning(bool ignore); |
| 71 | 70 |
| 72 // Check if after insertion or showing of the given |added_window| | 71 // Check if after insertion or showing of the given |added_window| |
| 73 // an automated desktop location management can be performed and | 72 // an automated desktop location management can be performed and |
| 74 // rearrange accordingly. | 73 // rearrange accordingly. |
| 75 static void RearrangeVisibleWindowOnShow(wm::WmWindow* added_window); | 74 static void RearrangeVisibleWindowOnShow(WmWindow* added_window); |
| 76 | 75 |
| 77 explicit WindowPositioner(wm::WmGlobals* globals); | 76 explicit WindowPositioner(WmShell* shell); |
| 78 ~WindowPositioner(); | 77 ~WindowPositioner(); |
| 79 | 78 |
| 80 // Find a suitable screen position for a popup window and return it. The | 79 // Find a suitable screen position for a popup window and return it. The |
| 81 // passed input position is only used to retrieve the width and height. | 80 // passed input position is only used to retrieve the width and height. |
| 82 // The position is determined on the left / right / top / bottom first. If | 81 // The position is determined on the left / right / top / bottom first. If |
| 83 // no smart space is found, the position will follow the standard what other | 82 // no smart space is found, the position will follow the standard what other |
| 84 // operating systems do (default cascading style). | 83 // operating systems do (default cascading style). |
| 85 gfx::Rect GetPopupPosition(const gfx::Rect& old_pos); | 84 gfx::Rect GetPopupPosition(const gfx::Rect& old_pos); |
| 86 | 85 |
| 87 // Accessor to set a flag indicating whether the first window in ASH should | 86 // Accessor to set a flag indicating whether the first window in ASH should |
| (...skipping 14 matching lines...) Expand all Loading... |
| 102 const gfx::Rect& work_area); | 101 const gfx::Rect& work_area); |
| 103 | 102 |
| 104 // Align the location to the grid / snap to the right / bottom corner. | 103 // Align the location to the grid / snap to the right / bottom corner. |
| 105 gfx::Rect AlignPopupPosition(const gfx::Rect& pos, | 104 gfx::Rect AlignPopupPosition(const gfx::Rect& pos, |
| 106 const gfx::Rect& work_area, | 105 const gfx::Rect& work_area, |
| 107 int grid); | 106 int grid); |
| 108 | 107 |
| 109 // Constant exposed for unittest. | 108 // Constant exposed for unittest. |
| 110 static const int kMinimumWindowOffset; | 109 static const int kMinimumWindowOffset; |
| 111 | 110 |
| 112 wm::WmGlobals* globals_; | 111 WmShell* shell_; |
| 113 | 112 |
| 114 // The offset in X and Y for the next popup which opens. | 113 // The offset in X and Y for the next popup which opens. |
| 115 int pop_position_offset_increment_x; | 114 int pop_position_offset_increment_x; |
| 116 int pop_position_offset_increment_y; | 115 int pop_position_offset_increment_y; |
| 117 | 116 |
| 118 // The position on the screen for the first popup which gets shown if no | 117 // The position on the screen for the first popup which gets shown if no |
| 119 // empty space can be found. | 118 // empty space can be found. |
| 120 int popup_position_offset_from_screen_corner_x; | 119 int popup_position_offset_from_screen_corner_x; |
| 121 int popup_position_offset_from_screen_corner_y; | 120 int popup_position_offset_from_screen_corner_y; |
| 122 | 121 |
| 123 // The last used position. | 122 // The last used position. |
| 124 int last_popup_position_x_; | 123 int last_popup_position_x_; |
| 125 int last_popup_position_y_; | 124 int last_popup_position_y_; |
| 126 | 125 |
| 127 DISALLOW_COPY_AND_ASSIGN(WindowPositioner); | 126 DISALLOW_COPY_AND_ASSIGN(WindowPositioner); |
| 128 }; | 127 }; |
| 129 | 128 |
| 130 } // namespace ash | 129 } // namespace ash |
| 131 | 130 |
| 132 #endif // ASH_COMMON_WM_WINDOW_POSITIONER_H_ | 131 #endif // ASH_COMMON_WM_WINDOW_POSITIONER_H_ |
| OLD | NEW |