Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(588)

Side by Side Diff: ash/wm/workspace/workspace_window_resizer.cc

Issue 9455063: Makes windows scale slightly when dragging the caption. Also wired (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes tests Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 #include "ash/wm/workspace/workspace_window_resizer.h" 5 #include "ash/wm/workspace/workspace_window_resizer.h"
6 6
7 #include "ui/aura/window.h" 7 #include "ui/aura/window.h"
8 #include "ui/aura/window_delegate.h" 8 #include "ui/aura/window_delegate.h"
9 #include "ui/aura/window_property.h" 9 #include "ui/aura/window_property.h"
10 #include "ui/base/hit_test.h"
11 #include "ui/gfx/compositor/scoped_layer_animation_settings.h"
12 #include "ui/gfx/compositor/layer.h"
10 #include "ui/gfx/screen.h" 13 #include "ui/gfx/screen.h"
14 #include "ui/gfx/transform.h"
11 15
12 DECLARE_WINDOW_PROPERTY_TYPE(int) 16 DECLARE_WINDOW_PROPERTY_TYPE(int)
13 17
14 namespace ash { 18 namespace ash {
15 namespace internal { 19 namespace internal {
16 20
17 namespace { 21 namespace {
18 22
19 const aura::WindowProperty<int> kHeightBeforeObscuredProp = {0}; 23 const aura::WindowProperty<int> kHeightBeforeObscuredProp = {0};
20 const aura::WindowProperty<int>* const kHeightBeforeObscuredKey = 24 const aura::WindowProperty<int>* const kHeightBeforeObscuredKey =
21 &kHeightBeforeObscuredProp; 25 &kHeightBeforeObscuredProp;
22 26
23 } // namespace 27 } // namespace
24 28
29 // static
30 bool WorkspaceWindowResizer::scale_windows_ = true;
31
25 WorkspaceWindowResizer::WorkspaceWindowResizer(aura::Window* window, 32 WorkspaceWindowResizer::WorkspaceWindowResizer(aura::Window* window,
26 const gfx::Point& location, 33 const gfx::Point& location,
27 int window_component, 34 int window_component,
28 int grid_size) 35 int grid_size)
29 : WindowResizer(window, location, window_component, grid_size) { 36 : WindowResizer(window, location, window_component, grid_size),
37 scale_window_(scale_windows_ && is_resizable() &&
38 window_component == HTCAPTION) {
30 if (is_resizable() && GetHeightBeforeObscured(window) && 39 if (is_resizable() && GetHeightBeforeObscured(window) &&
31 (!WindowTouchesBottomOfScreen() || 40 (!WindowTouchesBottomOfScreen() ||
32 bounds_change() != kBoundsChange_Repositions)) { 41 bounds_change() != kBoundsChange_Repositions)) {
33 ClearHeightBeforeObscured(window); 42 ClearHeightBeforeObscured(window);
34 } 43 }
44 if (scale_window_) {
45 // When dragging the caption scale slightly from the center.
46 float scale = 1.01f;
47 float x_offset =
48 static_cast<float>(window->bounds().width()) * (scale - 1) / 2.0f;
49 float y_offset =
50 (static_cast<float>(window->bounds().width()) * (scale - 1) / 2.0f);
51 ui::Transform transform;
52 transform.SetTranslate(-x_offset, -y_offset);
53 transform.SetScaleX(scale);
54 transform.SetScaleY(scale);
55 window->layer()->SetTransform(transform);
56 }
35 } 57 }
36 58
37 WorkspaceWindowResizer::~WorkspaceWindowResizer() { 59 WorkspaceWindowResizer::~WorkspaceWindowResizer() {
38 } 60 }
39 61
62 // static
63 void WorkspaceWindowResizer::SetScaleWindowsForTest(bool value) {
64 scale_windows_ = value;
65 }
66
67 void WorkspaceWindowResizer::CompleteDrag() {
68 if (!did_move_or_resize() || grid_size() <= 1) {
69 if (scale_window_) {
70 ui::ScopedLayerAnimationSettings scoped_setter(
71 window()->layer()->GetAnimator());
72 window()->layer()->SetTransform(ui::Transform());
73 }
74 return;
75 }
76
77 gfx::Rect new_bounds(GetFinalBounds());
78 if (new_bounds.size() != window()->bounds().size()) {
79 // Don't attempt to animate a size change.
80 window()->SetBounds(new_bounds);
81 if (scale_window_)
82 window()->layer()->SetTransform(ui::Transform());
83 return;
84 }
85
86 ui::ScopedLayerAnimationSettings scoped_setter(
87 window()->layer()->GetAnimator());
88 // Use a small duration since the grid is small.
89 scoped_setter.SetTransitionDuration(base::TimeDelta::FromMilliseconds(100));
90 window()->SetBounds(new_bounds);
91 if (scale_window_)
92 window()->layer()->SetTransform(ui::Transform());
93 }
94
95 void WorkspaceWindowResizer::RevertDrag() {
96 if (scale_window_)
97 window()->layer()->SetTransform(ui::Transform());
98 WindowResizer::RevertDrag();
99 }
100
40 gfx::Rect WorkspaceWindowResizer::GetBoundsForDrag(const gfx::Point& location) { 101 gfx::Rect WorkspaceWindowResizer::GetBoundsForDrag(const gfx::Point& location) {
41 if (!is_resizable()) 102 if (!is_resizable())
42 return WindowResizer::GetBoundsForDrag(location); 103 return WindowResizer::GetBoundsForDrag(location);
43 104
44 gfx::Rect bounds(WindowResizer::GetBoundsForDrag(location)); 105 gfx::Rect bounds(WindowResizer::GetBoundsForDrag(location));
45 AdjustBounds(&bounds); 106 AdjustBounds(&bounds);
46 return bounds; 107 return bounds;
47 } 108 }
48 109
49 gfx::Rect WorkspaceWindowResizer::GetFinalBounds() { 110 gfx::Rect WorkspaceWindowResizer::GetFinalBounds() {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 } 165 }
105 } 166 }
106 167
107 bool WorkspaceWindowResizer::WindowTouchesBottomOfScreen() const { 168 bool WorkspaceWindowResizer::WindowTouchesBottomOfScreen() const {
108 gfx::Rect work_area(gfx::Screen::GetMonitorWorkAreaNearestWindow(window())); 169 gfx::Rect work_area(gfx::Screen::GetMonitorWorkAreaNearestWindow(window()));
109 return window()->bounds().bottom() == work_area.bottom(); 170 return window()->bounds().bottom() == work_area.bottom();
110 } 171 }
111 172
112 } // namespace internal 173 } // namespace internal
113 } // namespace ash 174 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/workspace/workspace_window_resizer.h ('k') | ash/wm/workspace/workspace_window_resizer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698