| OLD | NEW |
| 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> |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 std::unique_ptr<DetachedTitleAreaRendererForInternal> title_area_renderer_; | 165 std::unique_ptr<DetachedTitleAreaRendererForInternal> title_area_renderer_; |
| 166 | 166 |
| 167 DISALLOW_COPY_AND_ASSIGN(ImmersiveFullscreenControllerDelegateMus); | 167 DISALLOW_COPY_AND_ASSIGN(ImmersiveFullscreenControllerDelegateMus); |
| 168 }; | 168 }; |
| 169 | 169 |
| 170 class WmNativeWidgetAura : public views::NativeWidgetAura { | 170 class WmNativeWidgetAura : public views::NativeWidgetAura { |
| 171 public: | 171 public: |
| 172 WmNativeWidgetAura(views::internal::NativeWidgetDelegate* delegate, | 172 WmNativeWidgetAura(views::internal::NativeWidgetDelegate* delegate, |
| 173 aura::WindowManagerClient* window_manager_client, | 173 aura::WindowManagerClient* window_manager_client, |
| 174 bool remove_standard_frame, | 174 bool remove_standard_frame, |
| 175 bool enable_immersive) | 175 bool enable_immersive, |
| 176 mojom::WindowStyle window_style) |
| 176 // The NativeWidget is mirroring the real Widget created in client code. | 177 // The NativeWidget is mirroring the real Widget created in client code. |
| 177 // |is_parallel_widget_in_window_manager| is used to indicate this | 178 // |is_parallel_widget_in_window_manager| is used to indicate this |
| 178 : views::NativeWidgetAura( | 179 : views::NativeWidgetAura( |
| 179 delegate, | 180 delegate, |
| 180 true /* is_parallel_widget_in_window_manager */), | 181 true /* is_parallel_widget_in_window_manager */), |
| 181 remove_standard_frame_(remove_standard_frame), | 182 remove_standard_frame_(remove_standard_frame), |
| 182 enable_immersive_(enable_immersive), | 183 enable_immersive_(enable_immersive), |
| 184 window_style_(window_style), |
| 183 window_manager_client_(window_manager_client) {} | 185 window_manager_client_(window_manager_client) {} |
| 184 ~WmNativeWidgetAura() override {} | 186 ~WmNativeWidgetAura() override {} |
| 185 | 187 |
| 188 void SetHeaderHeight(int height) { |
| 189 if (custom_frame_view_) |
| 190 custom_frame_view_->SetHeaderHeight({height}); |
| 191 } |
| 192 |
| 186 // views::NativeWidgetAura: | 193 // views::NativeWidgetAura: |
| 187 views::NonClientFrameView* CreateNonClientFrameView() override { | 194 views::NonClientFrameView* CreateNonClientFrameView() override { |
| 188 move_event_handler_ = base::MakeUnique<MoveEventHandler>( | 195 move_event_handler_ = base::MakeUnique<MoveEventHandler>( |
| 189 window_manager_client_, GetNativeView()); | 196 window_manager_client_, GetNativeView()); |
| 190 // TODO(sky): investigate why we have this. Seems this should be the same | 197 // TODO(sky): investigate why we have this. Seems this should be the same |
| 191 // as not specifying client area insets. | 198 // as not specifying client area insets. |
| 192 if (remove_standard_frame_) | 199 if (remove_standard_frame_) |
| 193 return new EmptyDraggableNonClientFrameView(); | 200 return new EmptyDraggableNonClientFrameView(); |
| 194 aura::Window* window = GetNativeView(); | 201 aura::Window* window = GetNativeView(); |
| 195 if (window->GetProperty(aura::client::kWindowTypeKey) == | 202 if (window->GetProperty(aura::client::kWindowTypeKey) == |
| 196 ui::mojom::WindowType::PANEL) | 203 ui::mojom::WindowType::PANEL) |
| 197 return new PanelFrameView(GetWidget(), PanelFrameView::FRAME_ASH); | 204 return new PanelFrameView(GetWidget(), PanelFrameView::FRAME_ASH); |
| 198 immersive_delegate_ = | 205 immersive_delegate_ = |
| 199 base::MakeUnique<ImmersiveFullscreenControllerDelegateMus>(GetWidget(), | 206 base::MakeUnique<ImmersiveFullscreenControllerDelegateMus>(GetWidget(), |
| 200 window); | 207 window); |
| 201 return new CustomFrameViewMus(GetWidget(), immersive_delegate_.get(), | 208 |
| 202 enable_immersive_); | 209 // See description for details on ownership. |
| 210 custom_frame_view_ = |
| 211 new CustomFrameViewMus(GetWidget(), immersive_delegate_.get(), |
| 212 enable_immersive_, window_style_); |
| 213 return custom_frame_view_; |
| 203 } | 214 } |
| 204 | 215 |
| 205 private: | 216 private: |
| 206 const bool remove_standard_frame_; | 217 const bool remove_standard_frame_; |
| 207 const bool enable_immersive_; | 218 const bool enable_immersive_; |
| 219 const mojom::WindowStyle window_style_; |
| 208 | 220 |
| 209 std::unique_ptr<MoveEventHandler> move_event_handler_; | 221 std::unique_ptr<MoveEventHandler> move_event_handler_; |
| 210 | 222 |
| 211 aura::WindowManagerClient* window_manager_client_; | 223 aura::WindowManagerClient* window_manager_client_; |
| 212 | 224 |
| 213 std::unique_ptr<ImmersiveFullscreenControllerDelegateMus> immersive_delegate_; | 225 std::unique_ptr<ImmersiveFullscreenControllerDelegateMus> immersive_delegate_; |
| 214 | 226 |
| 227 // Not used for panels or if |remove_standard_frame_| is true. This is owned |
| 228 // by the Widget's view hierarchy (e.g. it's a child of Widget's root View). |
| 229 CustomFrameViewMus* custom_frame_view_ = nullptr; |
| 230 |
| 215 DISALLOW_COPY_AND_ASSIGN(WmNativeWidgetAura); | 231 DISALLOW_COPY_AND_ASSIGN(WmNativeWidgetAura); |
| 216 }; | 232 }; |
| 217 | 233 |
| 218 class ClientViewMus : public views::ClientView { | 234 class ClientViewMus : public views::ClientView { |
| 219 public: | 235 public: |
| 220 ClientViewMus(views::Widget* widget, | 236 ClientViewMus(views::Widget* widget, |
| 221 views::View* contents_view, | 237 views::View* contents_view, |
| 222 NonClientFrameController* frame_controller) | 238 NonClientFrameController* frame_controller) |
| 223 : views::ClientView(widget, contents_view), | 239 : views::ClientView(widget, contents_view), |
| 224 frame_controller_(frame_controller) {} | 240 frame_controller_(frame_controller) {} |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 // MusClient. | 284 // MusClient. |
| 269 views::Widget::InitParams params( | 285 views::Widget::InitParams params( |
| 270 static_cast<views::Widget::InitParams::Type>(window_type)); | 286 static_cast<views::Widget::InitParams::Type>(window_type)); |
| 271 DCHECK((parent && !context) || (!parent && context)); | 287 DCHECK((parent && !context) || (!parent && context)); |
| 272 params.parent = parent; | 288 params.parent = parent; |
| 273 params.context = context; | 289 params.context = context; |
| 274 // TODO: properly set |params.activatable|. Should key off whether underlying | 290 // TODO: properly set |params.activatable|. Should key off whether underlying |
| 275 // (mus) window can have focus. | 291 // (mus) window can have focus. |
| 276 params.delegate = this; | 292 params.delegate = this; |
| 277 params.bounds = bounds; | 293 params.bounds = bounds; |
| 294 // The title area leaves notches in the corners, requring translucent windows. |
| 295 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 278 WmNativeWidgetAura* native_widget = new WmNativeWidgetAura( | 296 WmNativeWidgetAura* native_widget = new WmNativeWidgetAura( |
| 279 widget_, window_manager_client_, ShouldRemoveStandardFrame(*properties), | 297 widget_, window_manager_client_, ShouldRemoveStandardFrame(*properties), |
| 280 ShouldEnableImmersive(*properties)); | 298 ShouldEnableImmersive(*properties), GetWindowStyle(*properties)); |
| 281 window_ = native_widget->GetNativeView(); | 299 window_ = native_widget->GetNativeView(); |
| 282 window_->SetProperty(aura::client::kTopLevelWindowInWM, true); | 300 window_->SetProperty(aura::client::kTopLevelWindowInWM, true); |
| 283 window_->SetProperty(kNonClientFrameControllerKey, this); | 301 window_->SetProperty(kNonClientFrameControllerKey, this); |
| 284 window_->SetProperty(kWidgetCreationTypeKey, WidgetCreationType::FOR_CLIENT); | 302 window_->SetProperty(kWidgetCreationTypeKey, WidgetCreationType::FOR_CLIENT); |
| 285 window_->AddObserver(this); | 303 window_->AddObserver(this); |
| 286 params.native_widget = native_widget; | 304 params.native_widget = native_widget; |
| 287 aura::SetWindowType(window_, window_type); | 305 aura::SetWindowType(window_, window_type); |
| 288 aura::PropertyConverter* property_converter = | 306 aura::PropertyConverter* property_converter = |
| 289 window_manager->property_converter(); | 307 window_manager->property_converter(); |
| 290 for (auto& property_pair : *properties) { | 308 for (auto& property_pair : *properties) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 307 aura::client::GetTransientWindowClient()->AddObserver(this); | 325 aura::client::GetTransientWindowClient()->AddObserver(this); |
| 308 } | 326 } |
| 309 | 327 |
| 310 // static | 328 // static |
| 311 NonClientFrameController* NonClientFrameController::Get(aura::Window* window) { | 329 NonClientFrameController* NonClientFrameController::Get(aura::Window* window) { |
| 312 return window->GetProperty(kNonClientFrameControllerKey); | 330 return window->GetProperty(kNonClientFrameControllerKey); |
| 313 } | 331 } |
| 314 | 332 |
| 315 // static | 333 // static |
| 316 gfx::Insets NonClientFrameController::GetPreferredClientAreaInsets() { | 334 gfx::Insets NonClientFrameController::GetPreferredClientAreaInsets() { |
| 317 // TODO(sky): figure out a better way to get this rather than hard coding. | |
| 318 // This value comes from the header (see DefaultHeaderPainter::LayoutHeader, | |
| 319 // which uses the preferred height of the CaptionButtonContainer, which uses | |
| 320 // the height of the close button). | |
| 321 return gfx::Insets( | 335 return gfx::Insets( |
| 322 GetAshLayoutSize(AshLayoutSize::NON_BROWSER_CAPTION_BUTTON).height(), 0, | 336 GetAshLayoutSize(AshLayoutSize::NON_BROWSER_CAPTION_BUTTON).height(), 0, |
| 323 0, 0); | 337 0, 0); |
| 324 } | 338 } |
| 325 | 339 |
| 326 // static | 340 // static |
| 327 int NonClientFrameController::GetMaxTitleBarButtonWidth() { | 341 int NonClientFrameController::GetMaxTitleBarButtonWidth() { |
| 328 // TODO(sky): same comment as for GetPreferredClientAreaInsets(). | |
| 329 return GetAshLayoutSize(AshLayoutSize::NON_BROWSER_CAPTION_BUTTON).width() * | 342 return GetAshLayoutSize(AshLayoutSize::NON_BROWSER_CAPTION_BUTTON).width() * |
| 330 3; | 343 3; |
| 331 } | 344 } |
| 332 | 345 |
| 333 void NonClientFrameController::SetClientArea( | 346 void NonClientFrameController::SetClientArea( |
| 334 const gfx::Insets& insets, | 347 const gfx::Insets& insets, |
| 335 const std::vector<gfx::Rect>& additional_client_areas) { | 348 const std::vector<gfx::Rect>& additional_client_areas) { |
| 336 client_area_insets_ = insets; | 349 client_area_insets_ = insets; |
| 337 additional_client_areas_ = additional_client_areas; | 350 additional_client_areas_ = additional_client_areas; |
| 351 static_cast<WmNativeWidgetAura*>(widget_->native_widget()) |
| 352 ->SetHeaderHeight(insets.top()); |
| 338 } | 353 } |
| 339 | 354 |
| 340 NonClientFrameController::~NonClientFrameController() { | 355 NonClientFrameController::~NonClientFrameController() { |
| 341 aura::client::GetTransientWindowClient()->RemoveObserver(this); | 356 aura::client::GetTransientWindowClient()->RemoveObserver(this); |
| 342 if (window_) | 357 if (window_) |
| 343 window_->RemoveObserver(this); | 358 window_->RemoveObserver(this); |
| 344 } | 359 } |
| 345 | 360 |
| 346 base::string16 NonClientFrameController::GetWindowTitle() const { | 361 base::string16 NonClientFrameController::GetWindowTitle() const { |
| 347 if (!window_ || !window_->GetProperty(aura::client::kTitleKey)) | 362 if (!window_ || !window_->GetProperty(aura::client::kTitleKey)) |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 void NonClientFrameController::OnWillRestackTransientChildAbove( | 448 void NonClientFrameController::OnWillRestackTransientChildAbove( |
| 434 aura::Window* parent, | 449 aura::Window* parent, |
| 435 aura::Window* transient_child) {} | 450 aura::Window* transient_child) {} |
| 436 | 451 |
| 437 void NonClientFrameController::OnDidRestackTransientChildAbove( | 452 void NonClientFrameController::OnDidRestackTransientChildAbove( |
| 438 aura::Window* parent, | 453 aura::Window* parent, |
| 439 aura::Window* transient_child) {} | 454 aura::Window* transient_child) {} |
| 440 | 455 |
| 441 } // namespace mus | 456 } // namespace mus |
| 442 } // namespace ash | 457 } // namespace ash |
| OLD | NEW |