nsResizerFrame.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef nsResizerFrame_h___
  6. #define nsResizerFrame_h___
  7. #include "mozilla/Attributes.h"
  8. #include "mozilla/EventForwards.h"
  9. #include "nsTitleBarFrame.h"
  10. #include "Units.h"
  11. class nsIBaseWindow;
  12. using namespace mozilla;
  13. class nsResizerFrame : public nsTitleBarFrame
  14. {
  15. protected:
  16. struct Direction {
  17. int8_t mHorizontal;
  18. int8_t mVertical;
  19. };
  20. public:
  21. NS_DECL_FRAMEARENA_HELPERS
  22. friend nsIFrame* NS_NewResizerFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
  23. explicit nsResizerFrame(nsStyleContext* aContext);
  24. virtual nsresult HandleEvent(nsPresContext* aPresContext,
  25. mozilla::WidgetGUIEvent* aEvent,
  26. nsEventStatus* aEventStatus) override;
  27. virtual void MouseClicked(mozilla::WidgetMouseEvent* aEvent) override;
  28. protected:
  29. nsIContent* GetContentToResize(nsIPresShell* aPresShell, nsIBaseWindow** aWindow);
  30. Direction GetDirection();
  31. /**
  32. * Adjust the window position and size in a direction according to the mouse
  33. * movement and the resizer direction. The minimum and maximum size is used
  34. * to constrain the size.
  35. *
  36. * @param aPos left or top position
  37. * @param aSize width or height
  38. * @param aMinSize minimum width or height
  39. * @param aMacSize maximum width or height
  40. * @param aMovement the amount the mouse was moved
  41. * @param aResizerDirection resizer direction returned by GetDirection
  42. */
  43. static void AdjustDimensions(int32_t* aPos, int32_t* aSize,
  44. int32_t aMinSize, int32_t aMaxSize,
  45. int32_t aMovement, int8_t aResizerDirection);
  46. struct SizeInfo {
  47. nsString width, height;
  48. };
  49. static void SizeInfoDtorFunc(void *aObject, nsIAtom *aPropertyName,
  50. void *aPropertyValue, void *aData);
  51. static void ResizeContent(nsIContent* aContent, const Direction& aDirection,
  52. const SizeInfo& aSizeInfo, SizeInfo* aOriginalSizeInfo);
  53. static void MaybePersistOriginalSize(nsIContent* aContent, const SizeInfo& aSizeInfo);
  54. static void RestoreOriginalSize(nsIContent* aContent);
  55. protected:
  56. LayoutDeviceIntRect mMouseDownRect;
  57. LayoutDeviceIntPoint mMouseDownPoint;
  58. }; // class nsResizerFrame
  59. #endif /* nsResizerFrame_h___ */