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

Side by Side Diff: ash/wm/common/window_positioning_utils.cc

Issue 1901773002: Removes most of aura dependencies from DefaultState (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@wm_window_positioner
Patch Set: nit and merge Created 4 years, 8 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
« no previous file with comments | « ash/wm/common/window_positioning_utils.h ('k') | ash/wm/common/window_state_util.h » ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/common/window_positioning_utils.h" 5 #include "ash/wm/common/window_positioning_utils.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/wm/common/wm_screen_util.h"
10 #include "ash/wm/common/wm_window.h"
9 #include "ui/gfx/geometry/rect.h" 11 #include "ui/gfx/geometry/rect.h"
10 #include "ui/gfx/geometry/size.h" 12 #include "ui/gfx/geometry/size.h"
11 13
12 namespace ash { 14 namespace ash {
13 namespace wm { 15 namespace wm {
14 16
17 namespace {
18
19 // Returns the default width of a snapped window.
20 int GetDefaultSnappedWindowWidth(WmWindow* window) {
21 const float kSnappedWidthWorkspaceRatio = 0.5f;
22
23 int work_area_width = GetDisplayWorkAreaBoundsInParent(window).width();
24 int min_width = window->GetMinimumSize().width();
25 int ideal_width =
26 static_cast<int>(work_area_width * kSnappedWidthWorkspaceRatio);
27 return std::min(work_area_width, std::max(ideal_width, min_width));
28 }
29
30 } // namespace
31
15 void AdjustBoundsSmallerThan(const gfx::Size& max_size, gfx::Rect* bounds) { 32 void AdjustBoundsSmallerThan(const gfx::Size& max_size, gfx::Rect* bounds) {
16 bounds->set_width(std::min(bounds->width(), max_size.width())); 33 bounds->set_width(std::min(bounds->width(), max_size.width()));
17 bounds->set_height(std::min(bounds->height(), max_size.height())); 34 bounds->set_height(std::min(bounds->height(), max_size.height()));
18 } 35 }
19 36
20 void AdjustBoundsToEnsureWindowVisibility(const gfx::Rect& visible_area, 37 void AdjustBoundsToEnsureWindowVisibility(const gfx::Rect& visible_area,
21 int min_width, 38 int min_width,
22 int min_height, 39 int min_height,
23 gfx::Rect* bounds) { 40 gfx::Rect* bounds) {
24 AdjustBoundsSmallerThan(visible_area.size(), bounds); 41 AdjustBoundsSmallerThan(visible_area.size(), bounds);
(...skipping 14 matching lines...) Expand all
39 if (bounds->y() < visible_area.y()) 56 if (bounds->y() < visible_area.y())
40 bounds->set_y(visible_area.y()); 57 bounds->set_y(visible_area.y());
41 } 58 }
42 59
43 void AdjustBoundsToEnsureMinimumWindowVisibility(const gfx::Rect& visible_area, 60 void AdjustBoundsToEnsureMinimumWindowVisibility(const gfx::Rect& visible_area,
44 gfx::Rect* bounds) { 61 gfx::Rect* bounds) {
45 AdjustBoundsToEnsureWindowVisibility(visible_area, kMinimumOnScreenArea, 62 AdjustBoundsToEnsureWindowVisibility(visible_area, kMinimumOnScreenArea,
46 kMinimumOnScreenArea, bounds); 63 kMinimumOnScreenArea, bounds);
47 } 64 }
48 65
66 gfx::Rect GetDefaultLeftSnappedWindowBoundsInParent(wm::WmWindow* window) {
67 gfx::Rect work_area_in_parent(GetDisplayWorkAreaBoundsInParent(window));
68 return gfx::Rect(work_area_in_parent.x(), work_area_in_parent.y(),
69 GetDefaultSnappedWindowWidth(window),
70 work_area_in_parent.height());
71 }
72
73 gfx::Rect GetDefaultRightSnappedWindowBoundsInParent(wm::WmWindow* window) {
74 gfx::Rect work_area_in_parent(GetDisplayWorkAreaBoundsInParent(window));
75 int width = GetDefaultSnappedWindowWidth(window);
76 return gfx::Rect(work_area_in_parent.right() - width, work_area_in_parent.y(),
77 width, work_area_in_parent.height());
78 }
79
49 } // namespace wm 80 } // namespace wm
50 } // namespace ash 81 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/common/window_positioning_utils.h ('k') | ash/wm/common/window_state_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698