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

Side by Side Diff: ash/wm/default_window_resizer.cc

Issue 10910164: Removes the grid from ash. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix ShelfBrowserTest Created 8 years, 3 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
« no previous file with comments | « ash/wm/custom_frame_view_ash_unittest.cc ('k') | ash/wm/gestures/system_pinch_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/default_window_resizer.h" 5 #include "ash/wm/default_window_resizer.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/wm/coordinate_conversion.h" 8 #include "ash/wm/coordinate_conversion.h"
9 #include "ash/wm/cursor_manager.h" 9 #include "ash/wm/cursor_manager.h"
10 #include "ui/aura/client/aura_constants.h" 10 #include "ui/aura/client/aura_constants.h"
11 #include "ui/aura/env.h" 11 #include "ui/aura/env.h"
12 #include "ui/aura/root_window.h" 12 #include "ui/aura/root_window.h"
13 #include "ui/aura/window.h" 13 #include "ui/aura/window.h"
14 #include "ui/aura/window_delegate.h" 14 #include "ui/aura/window_delegate.h"
15 #include "ui/base/hit_test.h" 15 #include "ui/base/hit_test.h"
16 #include "ui/base/ui_base_types.h" 16 #include "ui/base/ui_base_types.h"
17 #include "ui/compositor/layer.h"
18 #include "ui/compositor/scoped_layer_animation_settings.h"
19 #include "ui/gfx/screen.h" 17 #include "ui/gfx/screen.h"
20 18
21 namespace ash { 19 namespace ash {
22 20
23 DefaultWindowResizer::~DefaultWindowResizer() { 21 DefaultWindowResizer::~DefaultWindowResizer() {
24 ash::Shell::GetInstance()->cursor_manager()->UnlockCursor(); 22 ash::Shell::GetInstance()->cursor_manager()->UnlockCursor();
25 } 23 }
26 24
27 // static 25 // static
28 DefaultWindowResizer* 26 DefaultWindowResizer*
29 DefaultWindowResizer::Create(aura::Window* window, 27 DefaultWindowResizer::Create(aura::Window* window,
30 const gfx::Point& location, 28 const gfx::Point& location,
31 int window_component) { 29 int window_component) {
32 Details details(window, location, window_component); 30 Details details(window, location, window_component);
33 return details.is_resizable ? new DefaultWindowResizer(details) : NULL; 31 return details.is_resizable ? new DefaultWindowResizer(details) : NULL;
34 } 32 }
35 33
36 void DefaultWindowResizer::Drag(const gfx::Point& location, int event_flags) { 34 void DefaultWindowResizer::Drag(const gfx::Point& location, int event_flags) {
37 std::pair<aura::RootWindow*, gfx::Point> actual_location = 35 std::pair<aura::RootWindow*, gfx::Point> actual_location =
38 wm::GetRootWindowRelativeToWindow(details_.window->parent(), location); 36 wm::GetRootWindowRelativeToWindow(details_.window->parent(), location);
39 37
40 // TODO(mazda|yusukes): Implement dragging an item from one display to another 38 // TODO(mazda|yusukes): Implement dragging an item from one display to another
41 aura::RootWindow* current_root = actual_location.first; 39 aura::RootWindow* current_root = actual_location.first;
42 if (current_root != details_.window->GetRootWindow()) 40 if (current_root != details_.window->GetRootWindow())
43 return; 41 return;
44 42
45 int grid_size = event_flags & ui::EF_CONTROL_DOWN ? 43 gfx::Rect bounds(CalculateBoundsForDrag(details_, location));
46 0 : ash::Shell::GetInstance()->GetGridSize();
47 gfx::Rect bounds(CalculateBoundsForDrag(details_, location, grid_size));
48 if (bounds != details_.window->bounds()) { 44 if (bounds != details_.window->bounds()) {
49 did_move_or_resize_ = true; 45 did_move_or_resize_ = true;
50 details_.window->SetBounds(bounds); 46 details_.window->SetBounds(bounds);
51 } 47 }
52 } 48 }
53 49
54 void DefaultWindowResizer::CompleteDrag(int event_flags) { 50 void DefaultWindowResizer::CompleteDrag(int event_flags) {
55 int grid_size = event_flags & ui::EF_CONTROL_DOWN ?
56 0 : ash::Shell::GetInstance()->GetGridSize();
57 if (grid_size <= 1 || !did_move_or_resize_)
58 return;
59 gfx::Rect new_bounds(
60 AdjustBoundsToGrid(details_.window->bounds(), grid_size));
61 if (new_bounds == details_.window->bounds())
62 return;
63
64 if (new_bounds.size() != details_.window->bounds().size()) {
65 // Don't attempt to animate a size change.
66 details_.window->SetBounds(new_bounds);
67 return;
68 }
69
70 ui::ScopedLayerAnimationSettings scoped_setter(
71 details_.window->layer()->GetAnimator());
72 // Use a small duration since the grid is small.
73 scoped_setter.SetTransitionDuration(base::TimeDelta::FromMilliseconds(100));
74 details_.window->SetBounds(new_bounds);
75 } 51 }
76 52
77 void DefaultWindowResizer::RevertDrag() { 53 void DefaultWindowResizer::RevertDrag() {
78 if (!did_move_or_resize_) 54 if (!did_move_or_resize_)
79 return; 55 return;
80 56
81 details_.window->SetBounds(details_.initial_bounds); 57 details_.window->SetBounds(details_.initial_bounds);
82 } 58 }
83 59
84 aura::Window* DefaultWindowResizer::GetTarget() { 60 aura::Window* DefaultWindowResizer::GetTarget() {
85 return details_.window; 61 return details_.window;
86 } 62 }
87 63
88 DefaultWindowResizer::DefaultWindowResizer(const Details& details) 64 DefaultWindowResizer::DefaultWindowResizer(const Details& details)
89 : details_(details), 65 : details_(details),
90 did_move_or_resize_(false) { 66 did_move_or_resize_(false) {
91 DCHECK(details_.is_resizable); 67 DCHECK(details_.is_resizable);
92 ash::Shell::GetInstance()->cursor_manager()->LockCursor(); 68 ash::Shell::GetInstance()->cursor_manager()->LockCursor();
93 } 69 }
94 70
95 } // namespace aura 71 } // namespace aura
OLDNEW
« no previous file with comments | « ash/wm/custom_frame_view_ash_unittest.cc ('k') | ash/wm/gestures/system_pinch_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698