xdg_shell_surface.cc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright 2017 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. #include "components/exo/xdg_shell_surface.h"
  5. #include "ash/frame/non_client_frame_view_ash.h"
  6. #include "chromeos/ui/base/window_properties.h"
  7. #include "ui/aura/client/aura_constants.h"
  8. #include "ui/display/display.h"
  9. #include "ui/display/screen.h"
  10. #include "ui/gfx/geometry/rect.h"
  11. #include "ui/gfx/geometry/size.h"
  12. #include "ui/views/window/caption_button_layout_constants.h"
  13. namespace exo {
  14. ////////////////////////////////////////////////////////////////////////////////
  15. // XdgShellSurface, public:
  16. XdgShellSurface::XdgShellSurface(Surface* surface,
  17. const gfx::Point& origin,
  18. bool can_minimize,
  19. int container)
  20. : ShellSurface(surface, origin, can_minimize, container) {}
  21. XdgShellSurface::~XdgShellSurface() {}
  22. void XdgShellSurface::OverrideInitParams(views::Widget::InitParams* params) {
  23. DCHECK(params);
  24. // Auto-maximize can override the initial show_state, if it's enabled via
  25. // window property.
  26. bool auto_maximize_enabled = params->init_properties_container.GetProperty(
  27. chromeos::kAutoMaximizeXdgShellEnabled);
  28. if (auto_maximize_enabled && ShouldAutoMaximize())
  29. params->show_state = ui::SHOW_STATE_MAXIMIZED;
  30. // Show state should be overridden when set via window property.
  31. if (params->init_properties_container.GetProperty(
  32. aura::client::kShowStateKey)) {
  33. params->show_state = params->init_properties_container.GetProperty(
  34. aura::client::kShowStateKey);
  35. }
  36. }
  37. bool XdgShellSurface::ShouldAutoMaximize() {
  38. if (initial_show_state() != ui::SHOW_STATE_DEFAULT || is_popup_ ||
  39. !CanMaximize())
  40. return false;
  41. DCHECK(!widget_);
  42. gfx::Size work_area_size = display::Screen::GetScreen()
  43. ->GetDisplayNearestWindow(host_window())
  44. .work_area_size();
  45. DCHECK(!work_area_size.IsEmpty());
  46. gfx::Rect window_bounds = GetVisibleBounds();
  47. // This way to predict the size of the widget if it were maximized is brittle.
  48. // We rely on unit tests to guard against changes in the size of the window
  49. // decorations.
  50. if (frame_enabled()) {
  51. window_bounds.Inset(gfx::Insets().set_bottom(
  52. -views::GetCaptionButtonLayoutSize(
  53. views::CaptionButtonLayoutSize::kNonBrowserCaption)
  54. .height()));
  55. }
  56. return window_bounds.width() >= work_area_size.width() &&
  57. window_bounds.height() >= work_area_size.height();
  58. }
  59. } // namespace exo