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

Side by Side Diff: ash/mus/non_client_frame_controller.cc

Issue 2277563002: Wires up immersive mode for chrome and mash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: feedback Created 4 years, 4 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 2015 The Chromium Authors. All rights reserved. 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 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/mus/non_client_frame_controller.h" 5 #include "ash/mus/non_client_frame_controller.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "ash/common/ash_constants.h" 13 #include "ash/common/ash_constants.h"
14 #include "ash/common/ash_layout_constants.h" 14 #include "ash/common/ash_layout_constants.h"
15 #include "ash/common/frame/custom_frame_view_ash.h" 15 #include "ash/common/frame/custom_frame_view_ash.h"
16 #include "ash/mus/bridge/wm_window_mus.h" 16 #include "ash/mus/bridge/wm_window_mus.h"
17 #include "ash/mus/frame/custom_frame_view_mus.h"
18 #include "ash/mus/frame/detached_title_area_renderer.h"
17 #include "ash/mus/move_event_handler.h" 19 #include "ash/mus/move_event_handler.h"
18 #include "ash/mus/property_util.h" 20 #include "ash/mus/property_util.h"
19 #include "ash/mus/shadow.h" 21 #include "ash/mus/shadow.h"
22 #include "ash/shared/immersive_fullscreen_controller_delegate.h"
20 #include "base/macros.h" 23 #include "base/macros.h"
21 #include "base/strings/utf_string_conversions.h" 24 #include "base/strings/utf_string_conversions.h"
22 #include "services/ui/public/cpp/property_type_converters.h" 25 #include "services/ui/public/cpp/property_type_converters.h"
23 #include "services/ui/public/cpp/window.h" 26 #include "services/ui/public/cpp/window.h"
24 #include "services/ui/public/cpp/window_manager_delegate.h" 27 #include "services/ui/public/cpp/window_manager_delegate.h"
25 #include "services/ui/public/cpp/window_property.h" 28 #include "services/ui/public/cpp/window_property.h"
29 #include "services/ui/public/cpp/window_tree_client.h"
26 #include "services/ui/public/interfaces/window_manager.mojom.h" 30 #include "services/ui/public/interfaces/window_manager.mojom.h"
27 #include "services/ui/public/interfaces/window_tree_host.mojom.h" 31 #include "services/ui/public/interfaces/window_tree_host.mojom.h"
28 #include "ui/aura/layout_manager.h" 32 #include "ui/aura/layout_manager.h"
29 #include "ui/aura/window.h" 33 #include "ui/aura/window.h"
30 #include "ui/aura/window_tree_host.h" 34 #include "ui/aura/window_tree_host.h"
31 #include "ui/base/hit_test.h" 35 #include "ui/base/hit_test.h"
32 #include "ui/compositor/layer.h" 36 #include "ui/compositor/layer.h"
33 #include "ui/gfx/geometry/vector2d.h" 37 #include "ui/gfx/geometry/vector2d.h"
34 #include "ui/views/mus/native_widget_mus.h" 38 #include "ui/views/mus/native_widget_mus.h"
35 #include "ui/views/widget/widget.h" 39 #include "ui/views/widget/widget.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask) override {} 107 void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask) override {}
104 void ResetWindowControls() override {} 108 void ResetWindowControls() override {}
105 void UpdateWindowIcon() override {} 109 void UpdateWindowIcon() override {}
106 void UpdateWindowTitle() override {} 110 void UpdateWindowTitle() override {}
107 void SizeConstraintsChanged() override {} 111 void SizeConstraintsChanged() override {}
108 112
109 private: 113 private:
110 DISALLOW_COPY_AND_ASSIGN(EmptyDraggableNonClientFrameView); 114 DISALLOW_COPY_AND_ASSIGN(EmptyDraggableNonClientFrameView);
111 }; 115 };
112 116
117 // Creates a ui::Window to host the top container when in immersive mode. The
118 // top container contains a DetachedTitleAreaRenderer, which handles drawing and
119 // events.
120 class ImmersiveFullscreenControllerDelegateMus
121 : public ImmersiveFullscreenControllerDelegate,
122 public DetachedTitleAreaRendererHost {
123 public:
124 ImmersiveFullscreenControllerDelegateMus(views::Widget* frame,
125 ui::Window* frame_window)
126 : frame_(frame), frame_window_(frame_window) {}
127 ~ImmersiveFullscreenControllerDelegateMus() override {
128 DestroyTitleAreaWindow();
129 }
130
131 // WmImmersiveFullscreenControllerDelegate:
132 void OnImmersiveRevealStarted() override {
133 CreateTitleAreaWindow();
134 SetVisibleFraction(0);
135 }
136 void OnImmersiveRevealEnded() override { DestroyTitleAreaWindow(); }
137 void OnImmersiveFullscreenExited() override { DestroyTitleAreaWindow(); }
138 void SetVisibleFraction(double visible_fraction) override {
139 if (!title_area_window_)
140 return;
141 gfx::Rect bounds = title_area_window_->bounds();
142 bounds.set_y(frame_window_->bounds().y() - bounds.height() +
143 visible_fraction * bounds.height());
144 title_area_window_->SetBounds(bounds);
145 }
146 std::vector<gfx::Rect> GetVisibleBoundsInScreen() const override {
147 std::vector<gfx::Rect> result;
148 if (!title_area_window_)
149 return result;
150
151 // Clip the bounds of the title area to that of the |frame_window_|.
152 gfx::Rect visible_bounds = title_area_window_->bounds();
153 visible_bounds.Intersect(frame_window_->bounds());
154 // The intersection is in the coordinates of |title_area_window_|'s parent,
155 // convert to be in |title_area_window_| and then to screen.
156 visible_bounds -= title_area_window_->bounds().origin().OffsetFromOrigin();
157 // TODO: this needs updating when parent of |title_area_window| is changed,
158 // DCHECK is to ensure when parent changes this code is updated.
159 // http://crbug.com/640392.
160 DCHECK_EQ(frame_window_->parent(), title_area_window_->parent());
161 result.push_back(WmWindowMus::Get(title_area_window_)
162 ->ConvertRectToScreen(visible_bounds));
163 return result;
164 }
165
166 // DetachedTitleAreaRendererHost:
167 void OnDetachedTitleAreaRendererDestroyed(
168 DetachedTitleAreaRenderer* renderer) override {
169 title_area_renderer_ = nullptr;
170 title_area_window_ = nullptr;
171 }
172
173 private:
174 void CreateTitleAreaWindow() {
175 if (title_area_window_)
176 return;
177
178 title_area_window_ = frame_window_->window_tree()->NewWindow();
179 // TODO(sky): bounds aren't right here. Need to convert to display.
180 gfx::Rect bounds = frame_window_->bounds();
181 // Use the preferred size as when fullscreen the client area is generally
182 // set to 0.
183 bounds.set_height(
184 NonClientFrameController::GetPreferredClientAreaInsets().top());
185 bounds.set_y(bounds.y() - bounds.height());
186 title_area_window_->SetBounds(bounds);
187 // TODO: making the reveal window a sibling is likely problematic.
188 // http://crbug.com/640392, see also comment in GetVisibleBoundsInScreen().
189 frame_window_->parent()->AddChild(title_area_window_);
190 title_area_window_->Reorder(frame_window_,
191 ui::mojom::OrderDirection::ABOVE);
192 title_area_renderer_ =
193 new DetachedTitleAreaRenderer(this, frame_, title_area_window_,
194 DetachedTitleAreaRenderer::Source::MASH);
195 }
196
197 void DestroyTitleAreaWindow() {
198 if (!title_area_window_)
199 return;
200 title_area_renderer_->Destroy();
201 title_area_renderer_ = nullptr;
202 // TitleAreaRevealer ends up owning window.
203 title_area_window_ = nullptr;
204 }
205
206 // The Widget immersive mode is operating on.
207 views::Widget* frame_;
208
209 // The ui::Window associated with |frame_|.
210 ui::Window* frame_window_;
211
212 // The window hosting the title area.
213 ui::Window* title_area_window_ = nullptr;
214
215 DetachedTitleAreaRenderer* title_area_renderer_ = nullptr;
216
217 DISALLOW_COPY_AND_ASSIGN(ImmersiveFullscreenControllerDelegateMus);
218 };
219
113 class WmNativeWidgetMus : public views::NativeWidgetMus { 220 class WmNativeWidgetMus : public views::NativeWidgetMus {
114 public: 221 public:
115 WmNativeWidgetMus(views::internal::NativeWidgetDelegate* delegate, 222 WmNativeWidgetMus(views::internal::NativeWidgetDelegate* delegate,
116 ui::Window* window, 223 ui::Window* window,
117 ui::WindowManagerClient* window_manager_client) 224 ui::WindowManagerClient* window_manager_client)
118 : NativeWidgetMus(delegate, window, ui::mojom::SurfaceType::UNDERLAY), 225 : NativeWidgetMus(delegate, window, ui::mojom::SurfaceType::UNDERLAY),
119 window_manager_client_(window_manager_client) {} 226 window_manager_client_(window_manager_client) {}
120 ~WmNativeWidgetMus() override {} 227 ~WmNativeWidgetMus() override {}
121 228
122 // NativeWidgetMus: 229 // NativeWidgetMus:
123 views::NonClientFrameView* CreateNonClientFrameView() override { 230 views::NonClientFrameView* CreateNonClientFrameView() override {
124 move_event_handler_.reset(new MoveEventHandler( 231 move_event_handler_.reset(new MoveEventHandler(
125 window(), window_manager_client_, GetNativeView())); 232 window(), window_manager_client_, GetNativeView()));
126 if (ShouldRemoveStandardFrame(window())) 233 if (ShouldRemoveStandardFrame(window()))
127 return new EmptyDraggableNonClientFrameView(); 234 return new EmptyDraggableNonClientFrameView();
128 return new CustomFrameViewAsh(GetWidget()); 235 immersive_delegate_.reset(
236 new ImmersiveFullscreenControllerDelegateMus(GetWidget(), window()));
237 const bool enable_immersive =
238 !window()->HasSharedProperty(
239 ui::mojom::WindowManager::kDisableImmersive_Property) ||
240 !window()->GetSharedProperty<bool>(
241 ui::mojom::WindowManager::kDisableImmersive_Property);
242 return new CustomFrameViewMus(GetWidget(), immersive_delegate_.get(),
243 enable_immersive);
129 } 244 }
130 void InitNativeWidget(const views::Widget::InitParams& params) override { 245 void InitNativeWidget(const views::Widget::InitParams& params) override {
131 views::NativeWidgetMus::InitNativeWidget(params); 246 views::NativeWidgetMus::InitNativeWidget(params);
132 aura::WindowTreeHost* window_tree_host = GetNativeView()->GetHost(); 247 aura::WindowTreeHost* window_tree_host = GetNativeView()->GetHost();
133 // TODO(sky): shadow should be determined by window type and shadow type. 248 // TODO(sky): shadow should be determined by window type and shadow type.
134 shadow_.reset(new Shadow); 249 shadow_.reset(new Shadow);
135 shadow_->Init(Shadow::STYLE_INACTIVE); 250 shadow_->Init(Shadow::STYLE_INACTIVE);
136 shadow_->Install(window()); 251 shadow_->Install(window());
137 ContentWindowLayoutManager* layout_manager = new ContentWindowLayoutManager( 252 ContentWindowLayoutManager* layout_manager = new ContentWindowLayoutManager(
138 window_tree_host->window(), shadow_.get()); 253 window_tree_host->window(), shadow_.get());
139 window_tree_host->window()->SetLayoutManager(layout_manager); 254 window_tree_host->window()->SetLayoutManager(layout_manager);
140 const int inset = Shadow::GetInteriorInsetForStyle(Shadow::STYLE_ACTIVE); 255 const int inset = Shadow::GetInteriorInsetForStyle(Shadow::STYLE_ACTIVE);
141 window_tree_host->SetOutputSurfacePadding( 256 window_tree_host->SetOutputSurfacePadding(
142 gfx::Insets(inset, inset, inset, inset)); 257 gfx::Insets(inset, inset, inset, inset));
143 window_tree_host->window()->layer()->Add(shadow_->layer()); 258 window_tree_host->window()->layer()->Add(shadow_->layer());
144 shadow_->layer()->parent()->StackAtBottom(shadow_->layer()); 259 shadow_->layer()->parent()->StackAtBottom(shadow_->layer());
145 } 260 }
146 261
147 private: 262 private:
148 // The shadow, may be null. 263 // The shadow, may be null.
149 std::unique_ptr<Shadow> shadow_; 264 std::unique_ptr<Shadow> shadow_;
150 265
151 std::unique_ptr<MoveEventHandler> move_event_handler_; 266 std::unique_ptr<MoveEventHandler> move_event_handler_;
152 267
153 ui::WindowManagerClient* window_manager_client_; 268 ui::WindowManagerClient* window_manager_client_;
154 269
270 std::unique_ptr<ImmersiveFullscreenControllerDelegateMus> immersive_delegate_;
271
155 DISALLOW_COPY_AND_ASSIGN(WmNativeWidgetMus); 272 DISALLOW_COPY_AND_ASSIGN(WmNativeWidgetMus);
156 }; 273 };
157 274
158 class ClientViewMus : public views::ClientView { 275 class ClientViewMus : public views::ClientView {
159 public: 276 public:
160 ClientViewMus(views::Widget* widget, 277 ClientViewMus(views::Widget* widget,
161 views::View* contents_view, 278 views::View* contents_view,
162 NonClientFrameController* frame_controller) 279 NonClientFrameController* frame_controller)
163 : views::ClientView(widget, contents_view), 280 : views::ClientView(widget, contents_view),
164 frame_controller_(frame_controller) {} 281 frame_controller_(frame_controller) {}
(...skipping 18 matching lines...) Expand all
183 // true. 300 // true.
184 gfx::Insets GetExtendedHitRegion() { 301 gfx::Insets GetExtendedHitRegion() {
185 return gfx::Insets(kResizeOutsideBoundsSize, kResizeOutsideBoundsSize, 302 return gfx::Insets(kResizeOutsideBoundsSize, kResizeOutsideBoundsSize,
186 kResizeOutsideBoundsSize, kResizeOutsideBoundsSize); 303 kResizeOutsideBoundsSize, kResizeOutsideBoundsSize);
187 } 304 }
188 305
189 } // namespace 306 } // namespace
190 307
191 // static 308 // static
192 void NonClientFrameController::Create( 309 void NonClientFrameController::Create(
193 shell::Connector* connector,
194 ui::Window* parent, 310 ui::Window* parent,
195 ui::Window* window, 311 ui::Window* window,
196 ui::WindowManagerClient* window_manager_client) { 312 ui::WindowManagerClient* window_manager_client) {
197 new NonClientFrameController(connector, parent, window, 313 new NonClientFrameController(parent, window, window_manager_client);
198 window_manager_client);
199 } 314 }
200 315
201 // static 316 // static
202 gfx::Insets NonClientFrameController::GetPreferredClientAreaInsets() { 317 gfx::Insets NonClientFrameController::GetPreferredClientAreaInsets() {
203 // TODO(sky): figure out a better way to get this rather than hard coding. 318 // TODO(sky): figure out a better way to get this rather than hard coding.
204 // This value comes from the header (see DefaultHeaderPainter::LayoutHeader, 319 // This value comes from the header (see DefaultHeaderPainter::LayoutHeader,
205 // which uses the preferred height of the CaptionButtonContainer, which uses 320 // which uses the preferred height of the CaptionButtonContainer, which uses
206 // the height of the close button). 321 // the height of the close button).
207 return gfx::Insets( 322 return gfx::Insets(
208 GetAshLayoutSize(AshLayoutSize::NON_BROWSER_CAPTION_BUTTON).height(), 0, 323 GetAshLayoutSize(AshLayoutSize::NON_BROWSER_CAPTION_BUTTON).height(), 0,
209 0, 0); 324 0, 0);
210 } 325 }
211 326
212 // static 327 // static
213 int NonClientFrameController::GetMaxTitleBarButtonWidth() { 328 int NonClientFrameController::GetMaxTitleBarButtonWidth() {
214 // TODO(sky): same comment as for GetPreferredClientAreaInsets(). 329 // TODO(sky): same comment as for GetPreferredClientAreaInsets().
215 return GetAshLayoutSize(AshLayoutSize::NON_BROWSER_CAPTION_BUTTON).width() * 330 return GetAshLayoutSize(AshLayoutSize::NON_BROWSER_CAPTION_BUTTON).width() *
216 3; 331 3;
217 } 332 }
218 333
219 NonClientFrameController::NonClientFrameController( 334 NonClientFrameController::NonClientFrameController(
220 shell::Connector* connector,
221 ui::Window* parent, 335 ui::Window* parent,
222 ui::Window* window, 336 ui::Window* window,
223 ui::WindowManagerClient* window_manager_client) 337 ui::WindowManagerClient* window_manager_client)
224 : widget_(new views::Widget), window_(window) { 338 : widget_(new views::Widget), window_(window) {
225 WmWindowMus* wm_window = WmWindowMus::Get(window); 339 WmWindowMus* wm_window = WmWindowMus::Get(window);
226 wm_window->set_widget(widget_, WmWindowMus::WidgetCreationType::FOR_CLIENT); 340 wm_window->set_widget(widget_, WmWindowMus::WidgetCreationType::FOR_CLIENT);
227 window_->AddObserver(this); 341 window_->AddObserver(this);
228 342
229 // To simplify things this code creates a Widget. While a Widget is created 343 // To simplify things this code creates a Widget. While a Widget is created
230 // we need to ensure we don't inadvertently change random properties of the 344 // we need to ensure we don't inadvertently change random properties of the
(...skipping 16 matching lines...) Expand all
247 const gfx::Insets extended_hit_region = 361 const gfx::Insets extended_hit_region =
248 wm_window->ShouldUseExtendedHitRegion() ? GetExtendedHitRegion() 362 wm_window->ShouldUseExtendedHitRegion() ? GetExtendedHitRegion()
249 : gfx::Insets(); 363 : gfx::Insets();
250 window_manager_client->SetUnderlaySurfaceOffsetAndExtendedHitArea( 364 window_manager_client->SetUnderlaySurfaceOffsetAndExtendedHitArea(
251 window, gfx::Vector2d(shadow_inset, shadow_inset), extended_hit_region); 365 window, gfx::Vector2d(shadow_inset, shadow_inset), extended_hit_region);
252 } 366 }
253 367
254 NonClientFrameController::~NonClientFrameController() { 368 NonClientFrameController::~NonClientFrameController() {
255 if (window_) 369 if (window_)
256 window_->RemoveObserver(this); 370 window_->RemoveObserver(this);
371 if (detached_title_area_renderer_)
372 detached_title_area_renderer_->Destroy();
373 }
374
375 void NonClientFrameController::OnDetachedTitleAreaRendererDestroyed(
376 DetachedTitleAreaRenderer* renderer) {
377 DCHECK_EQ(detached_title_area_renderer_, renderer);
378 detached_title_area_renderer_ = nullptr;
257 } 379 }
258 380
259 base::string16 NonClientFrameController::GetWindowTitle() const { 381 base::string16 NonClientFrameController::GetWindowTitle() const {
260 if (!window_->HasSharedProperty( 382 if (!window_->HasSharedProperty(
261 ui::mojom::WindowManager::kWindowTitle_Property)) { 383 ui::mojom::WindowManager::kWindowTitle_Property)) {
262 return base::string16(); 384 return base::string16();
263 } 385 }
264 386
265 base::string16 title = window_->GetSharedProperty<base::string16>( 387 base::string16 title = window_->GetSharedProperty<base::string16>(
266 ui::mojom::WindowManager::kWindowTitle_Property); 388 ui::mojom::WindowManager::kWindowTitle_Property);
(...skipping 30 matching lines...) Expand all
297 // Only draw the title if the client hasn't declared any additional client 419 // Only draw the title if the client hasn't declared any additional client
298 // areas which might conflict with it. 420 // areas which might conflict with it.
299 return window_ && window_->additional_client_areas().empty(); 421 return window_ && window_->additional_client_areas().empty();
300 } 422 }
301 423
302 views::ClientView* NonClientFrameController::CreateClientView( 424 views::ClientView* NonClientFrameController::CreateClientView(
303 views::Widget* widget) { 425 views::Widget* widget) {
304 return new ClientViewMus(widget, GetContentsView(), this); 426 return new ClientViewMus(widget, GetContentsView(), this);
305 } 427 }
306 428
429 void NonClientFrameController::OnTreeChanged(const TreeChangeParams& params) {
430 if (params.new_parent != window_ ||
431 !ShouldRenderParentTitleArea(params.target)) {
432 return;
433 }
434 if (detached_title_area_renderer_) {
435 detached_title_area_renderer_->Destroy();
436 detached_title_area_renderer_ = nullptr;
437 }
438 detached_title_area_renderer_ = new DetachedTitleAreaRenderer(
439 this, widget_, params.target, DetachedTitleAreaRenderer::Source::CLIENT);
440 }
441
307 void NonClientFrameController::OnWindowSharedPropertyChanged( 442 void NonClientFrameController::OnWindowSharedPropertyChanged(
308 ui::Window* window, 443 ui::Window* window,
309 const std::string& name, 444 const std::string& name,
310 const std::vector<uint8_t>* old_data, 445 const std::vector<uint8_t>* old_data,
311 const std::vector<uint8_t>* new_data) { 446 const std::vector<uint8_t>* new_data) {
312 if (name == ui::mojom::WindowManager::kResizeBehavior_Property) 447 if (name == ui::mojom::WindowManager::kResizeBehavior_Property)
313 widget_->OnSizeConstraintsChanged(); 448 widget_->OnSizeConstraintsChanged();
314 else if (name == ui::mojom::WindowManager::kWindowTitle_Property) 449 else if (name == ui::mojom::WindowManager::kWindowTitle_Property)
315 widget_->UpdateWindowTitle(); 450 widget_->UpdateWindowTitle();
316 } 451 }
317 452
318 void NonClientFrameController::OnWindowLocalPropertyChanged(ui::Window* window, 453 void NonClientFrameController::OnWindowLocalPropertyChanged(ui::Window* window,
319 const void* key, 454 const void* key,
320 intptr_t old) { 455 intptr_t old) {
321 if (IsWindowJankyProperty(key)) { 456 if (IsWindowJankyProperty(key)) {
322 widget_->UpdateWindowTitle(); 457 widget_->UpdateWindowTitle();
323 widget_->non_client_view()->frame_view()->SchedulePaint(); 458 widget_->non_client_view()->frame_view()->SchedulePaint();
324 } 459 }
325 } 460 }
326 461
327 void NonClientFrameController::OnWindowDestroyed(ui::Window* window) { 462 void NonClientFrameController::OnWindowDestroyed(ui::Window* window) {
328 window_->RemoveObserver(this); 463 window_->RemoveObserver(this);
329 window_ = nullptr; 464 window_ = nullptr;
330 } 465 }
331 466
332 } // namespace mus 467 } // namespace mus
333 } // namespace ash 468 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698