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

Side by Side Diff: mash/wm/window_layout.cc

Issue 1994763002: Wires up WorkspaceLayoutManager in mash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: data deps Created 4 years, 7 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 | « mash/wm/window_layout.h ('k') | mash/wm/window_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 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 "mash/wm/window_layout.h"
6
7 #include <stdint.h>
8
9 #include "components/mus/public/cpp/property_type_converters.h"
10 #include "components/mus/public/cpp/window.h"
11 #include "components/mus/public/cpp/window_property.h"
12 #include "mash/wm/property_util.h"
13
14 namespace mash {
15 namespace wm {
16
17 WindowLayout::WindowLayout(mus::Window* owner) : LayoutManager(owner) {
18 AddLayoutProperty(mus::mojom::WindowManager::kPreferredSize_Property);
19 AddLayoutProperty(mus::mojom::WindowManager::kShowState_Property);
20 }
21 WindowLayout::~WindowLayout() {}
22
23 void WindowLayout::LayoutWindow(mus::Window* window) {
24 mus::mojom::ShowState show_state = GetWindowShowState(window);
25 gfx::Rect user_set_bounds = GetWindowUserSetBounds(window);
26 gfx::Size preferred_size = GetWindowPreferredSize(window);
27
28 // Maximized/fullscreen windows should be sized to the bounds of the
29 // container.
30 // If a window has bounds set by the user, those should be respected as long
31 // as they meet certain constraints (e.g. visible).
32 // TODO(beng): transient windows:
33 // Top level non-transient windows with no bounds but a preferred size should
34 // opened centered within the work area.
35 // Transient windows should be opened centered within their parent.
36
37 switch (show_state) {
38 case mus::mojom::ShowState::FULLSCREEN:
39 case mus::mojom::ShowState::MAXIMIZED:
40 FitToContainer(window);
41 break;
42
43 case mus::mojom::ShowState::DEFAULT:
44 case mus::mojom::ShowState::DOCKED:
45 case mus::mojom::ShowState::INACTIVE:
46 case mus::mojom::ShowState::NORMAL: {
47 if (!user_set_bounds.IsEmpty()) {
48 // If the bounds are unchanged, this will do nothing.
49 window->SetBounds(user_set_bounds);
50 } else if (!preferred_size.IsEmpty()) {
51 CenterWindow(window, preferred_size);
52 }
53 }
54 case mus::mojom::ShowState::MINIMIZED:
55 break;
56 default:
57 NOTREACHED();
58 break;
59 }
60 }
61
62 void WindowLayout::OnWindowSharedPropertyChanged(
63 mus::Window* window,
64 const std::string& name,
65 const std::vector<uint8_t>* old_data,
66 const std::vector<uint8_t>* new_data) {
67 // TODO(sky): this feels like the wrong place for this logic. Find a better
68 // place.
69 if (name == mus::mojom::WindowManager::kShowState_Property &&
70 GetWindowShowState(window) == mus::mojom::ShowState::MAXIMIZED) {
71 SetRestoreBounds(window, window->bounds());
72 }
73 LayoutManager::OnWindowSharedPropertyChanged(window, name, old_data,
74 new_data);
75 }
76
77 void WindowLayout::FitToContainer(mus::Window* window) {
78 window->SetBounds(gfx::Rect(owner()->bounds().size()));
79 }
80
81 void WindowLayout::CenterWindow(mus::Window* window,
82 const gfx::Size& preferred_size) {
83 const gfx::Rect bounds(
84 (owner()->bounds().width() - preferred_size.width()) / 2,
85 (owner()->bounds().height() - preferred_size.height()) / 2,
86 preferred_size.width(), preferred_size.height());
87 window->SetBounds(bounds);
88 }
89
90 } // namespace wm
91 } // namespace mash
OLDNEW
« no previous file with comments | « mash/wm/window_layout.h ('k') | mash/wm/window_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698