frameless_view.cc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Copyright (c) 2014 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "atom/browser/ui/views/frameless_view.h"
  5. #include "atom/browser/native_window_views.h"
  6. #include "ui/aura/window.h"
  7. #include "ui/base/hit_test.h"
  8. #include "ui/views/widget/widget.h"
  9. #include "ui/views/widget/widget_delegate.h"
  10. namespace atom {
  11. namespace {
  12. const int kResizeInsideBoundsSize = 5;
  13. const int kResizeAreaCornerSize = 16;
  14. } // namespace
  15. // static
  16. const char FramelessView::kViewClassName[] = "FramelessView";
  17. FramelessView::FramelessView() {}
  18. FramelessView::~FramelessView() {}
  19. void FramelessView::Init(NativeWindowViews* window, views::Widget* frame) {
  20. window_ = window;
  21. frame_ = frame;
  22. }
  23. int FramelessView::ResizingBorderHitTest(const gfx::Point& point) {
  24. // Check the frame first, as we allow a small area overlapping the contents
  25. // to be used for resize handles.
  26. bool can_ever_resize = frame_->widget_delegate()
  27. ? frame_->widget_delegate()->CanResize()
  28. : false;
  29. // Don't allow overlapping resize handles when the window is maximized or
  30. // fullscreen, as it can't be resized in those states.
  31. int resize_border = frame_->IsMaximized() || frame_->IsFullscreen()
  32. ? 0
  33. : kResizeInsideBoundsSize;
  34. return GetHTComponentForFrame(point, resize_border, resize_border,
  35. kResizeAreaCornerSize, kResizeAreaCornerSize,
  36. can_ever_resize);
  37. }
  38. gfx::Rect FramelessView::GetBoundsForClientView() const {
  39. return bounds();
  40. }
  41. gfx::Rect FramelessView::GetWindowBoundsForClientBounds(
  42. const gfx::Rect& client_bounds) const {
  43. gfx::Rect window_bounds = client_bounds;
  44. // Enforce minimum size (1, 1) in case that client_bounds is passed with
  45. // empty size. This could occur when the frameless window is being
  46. // initialized.
  47. if (window_bounds.IsEmpty()) {
  48. window_bounds.set_width(1);
  49. window_bounds.set_height(1);
  50. }
  51. return window_bounds;
  52. }
  53. int FramelessView::NonClientHitTest(const gfx::Point& cursor) {
  54. if (frame_->IsFullscreen())
  55. return HTCLIENT;
  56. // Check for possible draggable region in the client area for the frameless
  57. // window.
  58. SkRegion* draggable_region = window_->draggable_region();
  59. if (draggable_region && draggable_region->contains(cursor.x(), cursor.y()))
  60. return HTCAPTION;
  61. // Support resizing frameless window by dragging the border.
  62. int frame_component = ResizingBorderHitTest(cursor);
  63. if (frame_component != HTNOWHERE)
  64. return frame_component;
  65. return HTCLIENT;
  66. }
  67. void FramelessView::GetWindowMask(const gfx::Size& size,
  68. gfx::Path* window_mask) {}
  69. void FramelessView::ResetWindowControls() {}
  70. void FramelessView::UpdateWindowIcon() {}
  71. void FramelessView::UpdateWindowTitle() {}
  72. void FramelessView::SizeConstraintsChanged() {}
  73. gfx::Size FramelessView::CalculatePreferredSize() const {
  74. return frame_->non_client_view()
  75. ->GetWindowBoundsForClientBounds(
  76. gfx::Rect(frame_->client_view()->GetPreferredSize()))
  77. .size();
  78. }
  79. gfx::Size FramelessView::GetMinimumSize() const {
  80. return window_->GetContentMinimumSize();
  81. }
  82. gfx::Size FramelessView::GetMaximumSize() const {
  83. return window_->GetContentMaximumSize();
  84. }
  85. const char* FramelessView::GetClassName() const {
  86. return kViewClassName;
  87. }
  88. } // namespace atom