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

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

Issue 497733002: Declaring the weak_ptr_factory in proper order. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Maintaining function in proper order Created 6 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
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 <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 } 103 }
104 return make_scoped_ptr<WindowResizer>(window_resizer); 104 return make_scoped_ptr<WindowResizer>(window_resizer);
105 } 105 }
106 106
107 namespace { 107 namespace {
108 108
109 // Snapping distance used instead of WorkspaceWindowResizer::kScreenEdgeInset 109 // Snapping distance used instead of WorkspaceWindowResizer::kScreenEdgeInset
110 // when resizing a window using touchscreen. 110 // when resizing a window using touchscreen.
111 const int kScreenEdgeInsetForTouchDrag = 32; 111 const int kScreenEdgeInsetForTouchDrag = 32;
112 112
113 // Current instance for use by the WorkspaceWindowResizerTest.
114 WorkspaceWindowResizer* instance = NULL;
115
113 // Returns true if the window should stick to the edge. 116 // Returns true if the window should stick to the edge.
114 bool ShouldStickToEdge(int distance_from_edge, int sticky_size) { 117 bool ShouldStickToEdge(int distance_from_edge, int sticky_size) {
115 return distance_from_edge < sticky_size && 118 return distance_from_edge < sticky_size &&
116 distance_from_edge > -sticky_size * 2; 119 distance_from_edge > -sticky_size * 2;
117 } 120 }
118 121
119 // Returns the coordinate along the secondary axis to snap to. 122 // Returns the coordinate along the secondary axis to snap to.
120 int CoordinateAlongSecondaryAxis(SecondaryMagnetismEdge edge, 123 int CoordinateAlongSecondaryAxis(SecondaryMagnetismEdge edge,
121 int leading, 124 int leading,
122 int trailing, 125 int trailing,
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 252
250 // static 253 // static
251 const int WorkspaceWindowResizer::kMinOnscreenSize = 20; 254 const int WorkspaceWindowResizer::kMinOnscreenSize = 20;
252 255
253 // static 256 // static
254 const int WorkspaceWindowResizer::kMinOnscreenHeight = 32; 257 const int WorkspaceWindowResizer::kMinOnscreenHeight = 32;
255 258
256 // static 259 // static
257 const int WorkspaceWindowResizer::kScreenEdgeInset = 8; 260 const int WorkspaceWindowResizer::kScreenEdgeInset = 8;
258 261
259 // static 262 WorkspaceWindowResizer* WorkspaceWindowResizer::GetInstanceForTest() {
260 WorkspaceWindowResizer* WorkspaceWindowResizer::instance_ = NULL; 263 return instance;
264 }
261 265
262 // Represents the width or height of a window with constraints on its minimum 266 // Represents the width or height of a window with constraints on its minimum
263 // and maximum size. 0 represents a lack of a constraint. 267 // and maximum size. 0 represents a lack of a constraint.
264 class WindowSize { 268 class WindowSize {
265 public: 269 public:
266 WindowSize(int size, int min, int max) 270 WindowSize(int size, int min, int max)
267 : size_(size), 271 : size_(size),
268 min_(min), 272 min_(min),
269 max_(max) { 273 max_(max) {
270 // Grow the min/max bounds to include the starting size. 274 // Grow the min/max bounds to include the starting size.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 int size_; 330 int size_;
327 int min_; 331 int min_;
328 int max_; 332 int max_;
329 }; 333 };
330 334
331 WorkspaceWindowResizer::~WorkspaceWindowResizer() { 335 WorkspaceWindowResizer::~WorkspaceWindowResizer() {
332 if (did_lock_cursor_) { 336 if (did_lock_cursor_) {
333 Shell* shell = Shell::GetInstance(); 337 Shell* shell = Shell::GetInstance();
334 shell->cursor_manager()->UnlockCursor(); 338 shell->cursor_manager()->UnlockCursor();
335 } 339 }
336 if (instance_ == this) 340 if (instance == this)
337 instance_ = NULL; 341 instance = NULL;
338 } 342 }
339 343
340 // static 344 // static
341 WorkspaceWindowResizer* WorkspaceWindowResizer::Create( 345 WorkspaceWindowResizer* WorkspaceWindowResizer::Create(
342 wm::WindowState* window_state, 346 wm::WindowState* window_state,
343 const std::vector<aura::Window*>& attached_windows) { 347 const std::vector<aura::Window*>& attached_windows) {
344 return new WorkspaceWindowResizer(window_state, attached_windows); 348 return new WorkspaceWindowResizer(window_state, attached_windows);
345 } 349 }
346 350
347 void WorkspaceWindowResizer::Drag(const gfx::Point& location_in_parent, 351 void WorkspaceWindowResizer::Drag(const gfx::Point& location_in_parent,
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 int initial_size = PrimaryAxisSize(attached_windows_[i]->bounds().size()); 544 int initial_size = PrimaryAxisSize(attached_windows_[i]->bounds().size());
541 initial_size_.push_back(initial_size); 545 initial_size_.push_back(initial_size);
542 // If current size is smaller than the min, use the current size as the min. 546 // If current size is smaller than the min, use the current size as the min.
543 // This way we don't snap on resize. 547 // This way we don't snap on resize.
544 int min_size = std::min(initial_size, 548 int min_size = std::min(initial_size,
545 std::max(PrimaryAxisSize(min), kMinOnscreenSize)); 549 std::max(PrimaryAxisSize(min), kMinOnscreenSize));
546 total_min_ += min_size; 550 total_min_ += min_size;
547 total_initial_size_ += initial_size; 551 total_initial_size_ += initial_size;
548 total_available += std::max(min_size, initial_size) - min_size; 552 total_available += std::max(min_size, initial_size) - min_size;
549 } 553 }
550 instance_ = this; 554 instance = this;
551 } 555 }
552 556
553 void WorkspaceWindowResizer::LayoutAttachedWindows( 557 void WorkspaceWindowResizer::LayoutAttachedWindows(
554 gfx::Rect* bounds) { 558 gfx::Rect* bounds) {
555 gfx::Rect work_area(ScreenUtil::GetDisplayWorkAreaBoundsInParent( 559 gfx::Rect work_area(ScreenUtil::GetDisplayWorkAreaBoundsInParent(
556 GetTarget())); 560 GetTarget()));
557 int initial_size = PrimaryAxisSize(details().initial_bounds_in_parent.size()); 561 int initial_size = PrimaryAxisSize(details().initial_bounds_in_parent.size());
558 int current_size = PrimaryAxisSize(bounds->size()); 562 int current_size = PrimaryAxisSize(bounds->size());
559 int start = PrimaryAxisCoordinate(bounds->right(), bounds->bottom()); 563 int start = PrimaryAxisCoordinate(bounds->right(), bounds->bottom());
560 int end = PrimaryAxisCoordinate(work_area.right(), work_area.bottom()); 564 int end = PrimaryAxisCoordinate(work_area.right(), work_area.bottom());
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 snapped_type == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED); 1042 snapped_type == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED);
1039 gfx::Rect snapped_bounds = ScreenUtil::GetDisplayWorkAreaBoundsInParent( 1043 gfx::Rect snapped_bounds = ScreenUtil::GetDisplayWorkAreaBoundsInParent(
1040 GetTarget()); 1044 GetTarget());
1041 if (snapped_type == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED) 1045 if (snapped_type == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED)
1042 snapped_bounds.set_x(snapped_bounds.right() - bounds_in_parent.width()); 1046 snapped_bounds.set_x(snapped_bounds.right() - bounds_in_parent.width());
1043 snapped_bounds.set_width(bounds_in_parent.width()); 1047 snapped_bounds.set_width(bounds_in_parent.width());
1044 return bounds_in_parent == snapped_bounds; 1048 return bounds_in_parent == snapped_bounds;
1045 } 1049 }
1046 1050
1047 } // namespace ash 1051 } // 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