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