michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: #ifndef nsResizerFrame_h___ michael@0: #define nsResizerFrame_h___ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "mozilla/EventForwards.h" michael@0: #include "nsTitleBarFrame.h" michael@0: michael@0: class nsIBaseWindow; michael@0: class nsMenuPopupFrame; michael@0: michael@0: class nsResizerFrame : public nsTitleBarFrame michael@0: { michael@0: protected: michael@0: struct Direction { michael@0: int8_t mHorizontal; michael@0: int8_t mVertical; michael@0: }; michael@0: michael@0: public: michael@0: NS_DECL_FRAMEARENA_HELPERS michael@0: michael@0: friend nsIFrame* NS_NewResizerFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); michael@0: michael@0: nsResizerFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); michael@0: michael@0: virtual nsresult HandleEvent(nsPresContext* aPresContext, michael@0: mozilla::WidgetGUIEvent* aEvent, michael@0: nsEventStatus* aEventStatus) MOZ_OVERRIDE; michael@0: michael@0: virtual void MouseClicked(nsPresContext* aPresContext, michael@0: mozilla::WidgetMouseEvent* aEvent) MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: nsIContent* GetContentToResize(nsIPresShell* aPresShell, nsIBaseWindow** aWindow); michael@0: michael@0: Direction GetDirection(); michael@0: michael@0: /** michael@0: * Adjust the window position and size in a direction according to the mouse michael@0: * movement and the resizer direction. The minimum and maximum size is used michael@0: * to constrain the size. michael@0: * michael@0: * @param aPos left or top position michael@0: * @param aSize width or height michael@0: * @param aMinSize minimum width or height michael@0: * @param aMacSize maximum width or height michael@0: * @param aMovement the amount the mouse was moved michael@0: * @param aResizerDirection resizer direction returned by GetDirection michael@0: */ michael@0: static void AdjustDimensions(int32_t* aPos, int32_t* aSize, michael@0: int32_t aMinSize, int32_t aMaxSize, michael@0: int32_t aMovement, int8_t aResizerDirection); michael@0: michael@0: struct SizeInfo { michael@0: nsString width, height; michael@0: }; michael@0: static void SizeInfoDtorFunc(void *aObject, nsIAtom *aPropertyName, michael@0: void *aPropertyValue, void *aData); michael@0: static void ResizeContent(nsIContent* aContent, const Direction& aDirection, michael@0: const SizeInfo& aSizeInfo, SizeInfo* aOriginalSizeInfo); michael@0: static void MaybePersistOriginalSize(nsIContent* aContent, const SizeInfo& aSizeInfo); michael@0: static void RestoreOriginalSize(nsIContent* aContent); michael@0: michael@0: protected: michael@0: nsIntRect mMouseDownRect; michael@0: nsIntPoint mMouseDownPoint; michael@0: }; // class nsResizerFrame michael@0: michael@0: #endif /* nsResizerFrame_h___ */