OLD | NEW |
(Empty) | |
| 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 #include "ash/wm/workspace/workspace_window_resizer.h" |
| 6 |
| 7 #include "ui/aura/window.h" |
| 8 #include "ui/aura/window_delegate.h" |
| 9 #include "ui/aura/window_property.h" |
| 10 #include "ui/gfx/screen.h" |
| 11 |
| 12 DECLARE_WINDOW_PROPERTY_TYPE(int) |
| 13 |
| 14 namespace ash { |
| 15 namespace internal { |
| 16 |
| 17 namespace { |
| 18 |
| 19 const aura::WindowProperty<int> kHeightBeforeObscuredProp = {NULL}; |
| 20 const aura::WindowProperty<int>* const kHeightBeforeObscuredKey = |
| 21 &kHeightBeforeObscuredProp; |
| 22 |
| 23 } // namespace |
| 24 |
| 25 WorkspaceWindowResizer::WorkspaceWindowResizer(aura::Window* window, |
| 26 const gfx::Point& location, |
| 27 int window_component, |
| 28 int grid_size) |
| 29 : WindowResizer(window, location, window_component, grid_size) { |
| 30 if (is_resizable() && GetHeightBeforeObscured(window) && |
| 31 (!WindowTouchesBottomOfScreen() || |
| 32 bounds_change() != kBoundsChange_Repositions)) { |
| 33 ClearHeightBeforeObscured(window); |
| 34 } |
| 35 } |
| 36 |
| 37 WorkspaceWindowResizer::~WorkspaceWindowResizer() { |
| 38 } |
| 39 |
| 40 gfx::Rect WorkspaceWindowResizer::GetBoundsForDrag(const gfx::Point& location) { |
| 41 if (!is_resizable()) |
| 42 return WindowResizer::GetBoundsForDrag(location); |
| 43 |
| 44 gfx::Rect bounds(WindowResizer::GetBoundsForDrag(location)); |
| 45 AdjustBounds(&bounds); |
| 46 return bounds; |
| 47 } |
| 48 |
| 49 gfx::Rect WorkspaceWindowResizer::GetFinalBounds() { |
| 50 if (grid_size() <= 1 || !GetHeightBeforeObscured(window())) |
| 51 return WindowResizer::GetFinalBounds(); |
| 52 |
| 53 gfx::Rect initial_bounds(window()->bounds()); |
| 54 bool at_bottom = WindowTouchesBottomOfScreen(); |
| 55 gfx::Rect bounds(WindowResizer::GetFinalBounds()); |
| 56 if (at_bottom && bounds.y() != initial_bounds.y()) { |
| 57 if (bounds.y() < initial_bounds.y()) { |
| 58 bounds.set_height(bounds.height() + grid_size() - |
| 59 (initial_bounds.y() - bounds.y())); |
| 60 } |
| 61 AdjustBounds(&bounds); |
| 62 } |
| 63 return bounds; |
| 64 } |
| 65 |
| 66 // static |
| 67 void WorkspaceWindowResizer::SetHeightBeforeObscured(aura::Window* window, |
| 68 int height) { |
| 69 window->SetProperty(kHeightBeforeObscuredKey, height); |
| 70 } |
| 71 |
| 72 // static |
| 73 void WorkspaceWindowResizer::ClearHeightBeforeObscured(aura::Window* window) { |
| 74 window->SetProperty(kHeightBeforeObscuredKey, 0); |
| 75 } |
| 76 |
| 77 // static |
| 78 int WorkspaceWindowResizer::GetHeightBeforeObscured(aura::Window* window) { |
| 79 return window->GetProperty(kHeightBeforeObscuredKey); |
| 80 } |
| 81 |
| 82 void WorkspaceWindowResizer::AdjustBounds(gfx::Rect* bounds) const { |
| 83 gfx::Rect work_area(gfx::Screen::GetMonitorWorkAreaNearestWindow(window())); |
| 84 if (bounds->bottom() < work_area.bottom()) { |
| 85 int height = GetHeightBeforeObscured(window()); |
| 86 if (!height) |
| 87 return; |
| 88 height = std::max(bounds->height(), height); |
| 89 bounds->set_height(std::min(work_area.bottom() - bounds->y(), height)); |
| 90 return; |
| 91 } |
| 92 |
| 93 if (bounds->bottom() == work_area.bottom()) |
| 94 return; |
| 95 |
| 96 if (!GetHeightBeforeObscured(window())) |
| 97 SetHeightBeforeObscured(window(), window()->bounds().height()); |
| 98 |
| 99 gfx::Size min_size = window()->delegate()->GetMinimumSize(); |
| 100 bounds->set_height(std::max(0, work_area.bottom() - bounds->y())); |
| 101 if (bounds->height() < min_size.height()) { |
| 102 bounds->set_height(min_size.height()); |
| 103 bounds->set_y(work_area.bottom() - min_size.height()); |
| 104 } |
| 105 } |
| 106 |
| 107 bool WorkspaceWindowResizer::WindowTouchesBottomOfScreen() const { |
| 108 gfx::Rect work_area(gfx::Screen::GetMonitorWorkAreaNearestWindow(window())); |
| 109 return window()->bounds().bottom() == work_area.bottom(); |
| 110 } |
| 111 |
| 112 } // namespace internal |
| 113 } // namespace ash |
OLD | NEW |