views_nswindow_delegate.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright 2014 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. #ifndef COMPONENTS_REMOTE_COCOA_APP_SHIM_VIEWS_NSWINDOW_DELEGATE_H_
  5. #define COMPONENTS_REMOTE_COCOA_APP_SHIM_VIEWS_NSWINDOW_DELEGATE_H_
  6. #include "base/memory/raw_ptr.h"
  7. #import <Cocoa/Cocoa.h>
  8. #import "base/mac/scoped_nsobject.h"
  9. #include "components/remote_cocoa/app_shim/remote_cocoa_app_shim_export.h"
  10. #include "third_party/abseil-cpp/absl/types/optional.h"
  11. namespace remote_cocoa {
  12. class NativeWidgetNSWindowBridge;
  13. } // namespace remote_cocoa
  14. // The delegate set on the NSWindow when a
  15. // remote_cocoa::NativeWidgetNSWindowBridge is initialized.
  16. REMOTE_COCOA_APP_SHIM_EXPORT
  17. @interface ViewsNSWindowDelegate : NSObject <NSWindowDelegate> {
  18. @private
  19. raw_ptr<remote_cocoa::NativeWidgetNSWindowBridge>
  20. _parent; // Weak. Owns this.
  21. base::scoped_nsobject<NSCursor> _cursor;
  22. absl::optional<float> _aspectRatio;
  23. // Only valid during a live resize.
  24. // Used to keep track of whether a resize is happening horizontally or
  25. // vertically, even if physically the user is resizing in both directions.
  26. // The value is significant when |_aspectRatio| is set, i.e., we are
  27. // responsible for maintaining the aspect ratio of the window. As the user is
  28. // dragging one of the corners to resize, we need the resize to be either
  29. // horizontal or vertical all the time, so we pick one of the directions and
  30. // stick to it. This is necessary to achieve stable results, because in order
  31. // to keep the aspect ratio fixed we override one window dimension with a
  32. // value computed from the other dimension.
  33. absl::optional<bool> _resizingHorizontally;
  34. }
  35. // If set, the cursor set in -[NSResponder updateCursor:] when the window is
  36. // reached along the responder chain.
  37. @property(retain, nonatomic) NSCursor* cursor;
  38. // Initialize with the given |parent|.
  39. - (instancetype)initWithBridgedNativeWidget:
  40. (remote_cocoa::NativeWidgetNSWindowBridge*)parent;
  41. // Notify that the window has been reordered in (or removed from) the window
  42. // server's screen list. This is a substitute for -[NSWindowDelegate
  43. // windowDidExpose:], which is only sent for nonretained windows (those without
  44. // a backing store). |notification| is optional and can be set when redirecting
  45. // a notification such as NSApplicationDidHideNotification.
  46. - (void)onWindowOrderChanged:(NSNotification*)notification;
  47. // Notify that the system control tint changed.
  48. - (void)onSystemControlTintChanged:(NSNotification*)notification;
  49. // Called on the delegate of a modal sheet when its modal session ends.
  50. - (void)sheetDidEnd:(NSWindow*)sheet
  51. returnCode:(NSInteger)returnCode
  52. contextInfo:(void*)contextInfo;
  53. // Set the aspect ratio of the window. Window resizes will be constrained in an
  54. // attempt to maintain the aspect ratio.
  55. // Cocoa provides this functionality via the [NSWindow aspectRatio] property,
  56. // but its implementation prioritizes the aspect ratio over the minimum size:
  57. // one of the dimensions can go below the minimum size if that's what it takes
  58. // to maintain the aspect ratio. This is inacceptable for us.
  59. - (void)setAspectRatio:(float)aspectRatio;
  60. @end
  61. #endif // COMPONENTS_REMOTE_COCOA_APP_SHIM_VIEWS_NSWINDOW_DELEGATE_H_