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

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

Issue 2029883002: Moves mash/wm into ash/mus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_static_assert
Patch Set: move comment Created 4 years, 6 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/non_client_frame_controller.h ('k') | mash/wm/property_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
(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/non_client_frame_controller.h"
6
7 #include <stdint.h>
8
9 #include <memory>
10 #include <string>
11 #include <vector>
12
13 #include "base/macros.h"
14 #include "base/strings/utf_string_conversions.h"
15 #include "components/mus/public/cpp/property_type_converters.h"
16 #include "components/mus/public/cpp/window.h"
17 #include "components/mus/public/cpp/window_manager_delegate.h"
18 #include "components/mus/public/cpp/window_property.h"
19 #include "components/mus/public/interfaces/window_manager.mojom.h"
20 #include "components/mus/public/interfaces/window_tree_host.mojom.h"
21 #include "mash/wm/bridge/wm_window_mus.h"
22 #include "mash/wm/frame/frame_border_hit_test_controller.h"
23 #include "mash/wm/frame/move_event_handler.h"
24 #include "mash/wm/frame/non_client_frame_view_mash.h"
25 #include "mash/wm/property_util.h"
26 #include "mash/wm/shadow.h"
27 #include "ui/aura/layout_manager.h"
28 #include "ui/aura/window.h"
29 #include "ui/aura/window_tree_host.h"
30 #include "ui/compositor/layer.h"
31 #include "ui/gfx/geometry/vector2d.h"
32 #include "ui/views/mus/native_widget_mus.h"
33 #include "ui/views/widget/widget.h"
34
35 namespace mash {
36 namespace wm {
37 namespace {
38
39 // LayoutManager associated with the window created by WindowTreeHost. Resizes
40 // all children of the parent to match the bounds of the parent. Additionally
41 // handles sizing of a Shadow.
42 class ContentWindowLayoutManager : public aura::LayoutManager {
43 public:
44 ContentWindowLayoutManager(aura::Window* window, Shadow* shadow)
45 : window_(window), shadow_(shadow) {
46 OnWindowResized();
47 }
48 ~ContentWindowLayoutManager() override {}
49
50 private:
51 // Bounds for child windows.
52 gfx::Rect child_bounds() const {
53 return gfx::Rect(0, 0, window_->bounds().size().width(),
54 window_->bounds().size().height());
55 }
56
57 void UpdateChildBounds(aura::Window* child) {
58 child->SetBounds(child_bounds());
59 }
60
61 // aura::LayoutManager:
62 void OnWindowResized() override {
63 for (aura::Window* child : window_->children())
64 UpdateChildBounds(child);
65 // Shadow takes care of resizing the layer appropriately.
66 if (shadow_)
67 shadow_->SetContentBounds(child_bounds());
68 }
69 void OnWindowAddedToLayout(aura::Window* child) override {
70 UpdateChildBounds(child);
71 }
72 void OnWillRemoveWindowFromLayout(aura::Window* child) override {}
73 void OnWindowRemovedFromLayout(aura::Window* child) override {}
74 void OnChildWindowVisibilityChanged(aura::Window* child,
75 bool visible) override {}
76 void SetChildBounds(aura::Window* child,
77 const gfx::Rect& requested_bounds) override {
78 SetChildBoundsDirect(child, requested_bounds);
79 }
80
81 aura::Window* window_;
82 Shadow* shadow_;
83
84 DISALLOW_COPY_AND_ASSIGN(ContentWindowLayoutManager);
85 };
86
87 class WmNativeWidgetMus : public views::NativeWidgetMus {
88 public:
89 WmNativeWidgetMus(views::internal::NativeWidgetDelegate* delegate,
90 shell::Connector* connector,
91 mus::Window* window,
92 mus::WindowManagerClient* window_manager_client)
93 : NativeWidgetMus(delegate,
94 connector,
95 window,
96 mus::mojom::SurfaceType::UNDERLAY),
97 window_manager_client_(window_manager_client) {}
98 ~WmNativeWidgetMus() override {
99 }
100
101 // NativeWidgetMus:
102 views::NonClientFrameView* CreateNonClientFrameView() override {
103 views::Widget* widget =
104 static_cast<views::internal::NativeWidgetPrivate*>(this)->GetWidget();
105 NonClientFrameViewMash* frame_view =
106 new NonClientFrameViewMash(widget, window());
107 move_event_handler_.reset(new MoveEventHandler(
108 window(), window_manager_client_, GetNativeView()));
109 return frame_view;
110 }
111 void InitNativeWidget(const views::Widget::InitParams& params) override {
112 views::NativeWidgetMus::InitNativeWidget(params);
113 aura::WindowTreeHost* window_tree_host = GetNativeView()->GetHost();
114 // TODO(sky): shadow should be determined by window type and shadow type.
115 shadow_.reset(new Shadow);
116 shadow_->Init(Shadow::STYLE_INACTIVE);
117 shadow_->Install(window());
118 ContentWindowLayoutManager* layout_manager = new ContentWindowLayoutManager(
119 window_tree_host->window(), shadow_.get());
120 window_tree_host->window()->SetLayoutManager(layout_manager);
121 const int inset = Shadow::GetInteriorInsetForStyle(Shadow::STYLE_ACTIVE);
122 window_tree_host->SetOutputSurfacePadding(
123 gfx::Insets(inset, inset, inset, inset));
124 window_tree_host->window()->layer()->Add(shadow_->layer());
125 shadow_->layer()->parent()->StackAtBottom(shadow_->layer());
126 }
127 void CenterWindow(const gfx::Size& size) override {
128 // Do nothing. The client controls the size, not us.
129 }
130 bool SetWindowTitle(const base::string16& title) override {
131 // Do nothing. The client controls the window title, not us.
132 return false;
133 }
134 void SetWindowIcons(const gfx::ImageSkia& window_icon,
135 const gfx::ImageSkia& app_icon) override {
136 // Do nothing. The client controls window icons, not us.
137 }
138 void UpdateClientArea() override {
139 // This pushes the client area to the WS. We don't want to do that as
140 // the client area should come from the client, not us.
141 }
142
143 private:
144 // The shadow, may be null.
145 std::unique_ptr<Shadow> shadow_;
146
147 std::unique_ptr<MoveEventHandler> move_event_handler_;
148
149 mus::WindowManagerClient* window_manager_client_;
150
151 DISALLOW_COPY_AND_ASSIGN(WmNativeWidgetMus);
152 };
153
154 class ClientViewMus : public views::ClientView {
155 public:
156 ClientViewMus(views::Widget* widget,
157 views::View* contents_view,
158 NonClientFrameController* frame_controller)
159 : views::ClientView(widget, contents_view),
160 frame_controller_(frame_controller) {}
161 ~ClientViewMus() override {}
162
163 // views::ClientView:
164 bool CanClose() override {
165 if (!frame_controller_->window())
166 return true;
167
168 frame_controller_->window()->RequestClose();
169 return false;
170 }
171
172 private:
173 NonClientFrameController* frame_controller_;
174
175 DISALLOW_COPY_AND_ASSIGN(ClientViewMus);
176 };
177
178 } // namespace
179
180 // static
181 void NonClientFrameController::Create(
182 shell::Connector* connector,
183 mus::Window* parent,
184 mus::Window* window,
185 mus::WindowManagerClient* window_manager_client) {
186 new NonClientFrameController(connector, parent, window,
187 window_manager_client);
188 }
189
190 // static
191 gfx::Insets NonClientFrameController::GetPreferredClientAreaInsets() {
192 return NonClientFrameViewMash::GetPreferredClientAreaInsets();
193 }
194
195 // static
196 int NonClientFrameController::GetMaxTitleBarButtonWidth() {
197 return NonClientFrameViewMash::GetMaxTitleBarButtonWidth();
198 }
199
200 NonClientFrameController::NonClientFrameController(
201 shell::Connector* connector,
202 mus::Window* parent,
203 mus::Window* window,
204 mus::WindowManagerClient* window_manager_client)
205 : widget_(new views::Widget), window_(window) {
206 WmWindowMus* wm_window = WmWindowMus::Get(window);
207 wm_window->set_widget(widget_, WmWindowMus::WidgetCreationType::FOR_CLIENT);
208 window_->AddObserver(this);
209
210 // To simplify things this code creates a Widget. While a Widget is created
211 // we need to ensure we don't inadvertently change random properties of the
212 // underlying mus::Window. For example, showing the Widget shouldn't change
213 // the bounds of the mus::Window in anyway.
214 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
215 // We initiate focus at the mus level, not at the views level.
216 params.activatable = views::Widget::InitParams::ACTIVATABLE_NO;
217 params.delegate = this;
218 params.native_widget =
219 new WmNativeWidgetMus(widget_, connector, window, window_manager_client);
220 widget_->Init(params);
221
222 parent->AddChild(window);
223
224 widget_->ShowInactive();
225
226 const int shadow_inset =
227 Shadow::GetInteriorInsetForStyle(Shadow::STYLE_ACTIVE);
228 const gfx::Insets extended_hit_region =
229 wm_window->ShouldUseExtendedHitRegion()
230 ? FrameBorderHitTestController::GetResizeOutsideBoundsSize()
231 : gfx::Insets();
232 window_manager_client->SetUnderlaySurfaceOffsetAndExtendedHitArea(
233 window, gfx::Vector2d(shadow_inset, shadow_inset), extended_hit_region);
234 }
235
236 NonClientFrameController::~NonClientFrameController() {
237 if (window_)
238 window_->RemoveObserver(this);
239 }
240
241 base::string16 NonClientFrameController::GetWindowTitle() const {
242 if (!window_->HasSharedProperty(
243 mus::mojom::WindowManager::kWindowTitle_Property)) {
244 return base::string16();
245 }
246
247 base::string16 title = window_->GetSharedProperty<base::string16>(
248 mus::mojom::WindowManager::kWindowTitle_Property);
249
250 if (IsWindowJanky(window_))
251 title += base::ASCIIToUTF16(" !! Not responding !!");
252
253 return title;
254 }
255
256 views::View* NonClientFrameController::GetContentsView() {
257 return this;
258 }
259
260 bool NonClientFrameController::CanResize() const {
261 return window_ &&
262 (GetResizeBehavior(window_) & mus::mojom::kResizeBehaviorCanResize) !=
263 0;
264 }
265
266 bool NonClientFrameController::CanMaximize() const {
267 return window_ &&
268 (GetResizeBehavior(window_) &
269 mus::mojom::kResizeBehaviorCanMaximize) != 0;
270 }
271
272 bool NonClientFrameController::CanMinimize() const {
273 return window_ &&
274 (GetResizeBehavior(window_) &
275 mus::mojom::kResizeBehaviorCanMinimize) != 0;
276 }
277
278 bool NonClientFrameController::ShouldShowWindowTitle() const {
279 // Only draw the title if the client hasn't declared any additional client
280 // areas which might conflict with it.
281 return window_ && window_->additional_client_areas().empty();
282 }
283
284 views::ClientView* NonClientFrameController::CreateClientView(
285 views::Widget* widget) {
286 return new ClientViewMus(widget, GetContentsView(), this);
287 }
288
289 void NonClientFrameController::OnWindowSharedPropertyChanged(
290 mus::Window* window,
291 const std::string& name,
292 const std::vector<uint8_t>* old_data,
293 const std::vector<uint8_t>* new_data) {
294 if (name == mus::mojom::WindowManager::kResizeBehavior_Property)
295 widget_->OnSizeConstraintsChanged();
296 else if (name == mus::mojom::WindowManager::kWindowTitle_Property)
297 widget_->UpdateWindowTitle();
298 }
299
300 void NonClientFrameController::OnWindowLocalPropertyChanged(
301 mus::Window* window,
302 const void* key,
303 intptr_t old) {
304 if (IsWindowJankyProperty(key)) {
305 widget_->UpdateWindowTitle();
306 widget_->non_client_view()->frame_view()->SchedulePaint();
307 }
308 }
309
310 void NonClientFrameController::OnWindowDestroyed(mus::Window* window) {
311 window_->RemoveObserver(this);
312 window_ = nullptr;
313 }
314
315 } // namespace wm
316 } // namespace mash
OLDNEW
« no previous file with comments | « mash/wm/non_client_frame_controller.h ('k') | mash/wm/property_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698