LCOV - code coverage report
Current view: top level - layout/xul - nsResizerFrame.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 260 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 11 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : 
       6             : #include "nsAutoPtr.h"
       7             : #include "nsCOMPtr.h"
       8             : #include "nsIServiceManager.h"
       9             : #include "nsResizerFrame.h"
      10             : #include "nsIContent.h"
      11             : #include "nsIDocument.h"
      12             : #include "nsIDOMNodeList.h"
      13             : #include "nsGkAtoms.h"
      14             : #include "nsNameSpaceManager.h"
      15             : #include "nsIDOMCSSStyleDeclaration.h"
      16             : 
      17             : #include "nsPresContext.h"
      18             : #include "nsFrameManager.h"
      19             : #include "nsIDocShell.h"
      20             : #include "nsIDocShellTreeOwner.h"
      21             : #include "nsIBaseWindow.h"
      22             : #include "nsPIDOMWindow.h"
      23             : #include "mozilla/MouseEvents.h"
      24             : #include "nsContentUtils.h"
      25             : #include "nsMenuPopupFrame.h"
      26             : #include "nsIScreenManager.h"
      27             : #include "mozilla/dom/Element.h"
      28             : #include "nsError.h"
      29             : #include "nsICSSDeclaration.h"
      30             : #include "nsStyledElement.h"
      31             : #include <algorithm>
      32             : 
      33             : using namespace mozilla;
      34             : 
      35             : //
      36             : // NS_NewResizerFrame
      37             : //
      38             : // Creates a new Resizer frame and returns it
      39             : //
      40             : nsIFrame*
      41           0 : NS_NewResizerFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
      42             : {
      43           0 :   return new (aPresShell) nsResizerFrame(aContext);
      44             : }
      45             : 
      46           0 : NS_IMPL_FRAMEARENA_HELPERS(nsResizerFrame)
      47             : 
      48           0 : nsResizerFrame::nsResizerFrame(nsStyleContext* aContext)
      49           0 :   : nsTitleBarFrame(aContext, kClassID)
      50             : {
      51           0 : }
      52             : 
      53             : nsresult
      54           0 : nsResizerFrame::HandleEvent(nsPresContext* aPresContext,
      55             :                             WidgetGUIEvent* aEvent,
      56             :                             nsEventStatus* aEventStatus)
      57             : {
      58           0 :   NS_ENSURE_ARG_POINTER(aEventStatus);
      59           0 :   if (nsEventStatus_eConsumeNoDefault == *aEventStatus) {
      60           0 :     return NS_OK;
      61             :   }
      62             : 
      63           0 :   AutoWeakFrame weakFrame(this);
      64           0 :   bool doDefault = true;
      65             : 
      66           0 :   switch (aEvent->mMessage) {
      67             :     case eTouchStart:
      68             :     case eMouseDown: {
      69           0 :       if (aEvent->mClass == eTouchEventClass ||
      70           0 :           (aEvent->mClass == eMouseEventClass &&
      71           0 :            aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton)) {
      72           0 :         nsCOMPtr<nsIBaseWindow> window;
      73           0 :         nsIPresShell* presShell = aPresContext->GetPresShell();
      74             :         nsIContent* contentToResize =
      75           0 :           GetContentToResize(presShell, getter_AddRefs(window));
      76           0 :         if (contentToResize) {
      77           0 :           nsIFrame* frameToResize = contentToResize->GetPrimaryFrame();
      78           0 :           if (!frameToResize)
      79           0 :             break;
      80             : 
      81             :           // cache the content rectangle for the frame to resize
      82             :           // GetScreenRectInAppUnits returns the border box rectangle, so
      83             :           // adjust to get the desired content rectangle.
      84           0 :           nsRect rect = frameToResize->GetScreenRectInAppUnits();
      85           0 :           if (frameToResize->StylePosition()->mBoxSizing == StyleBoxSizing::Content) {
      86           0 :             rect.Deflate(frameToResize->GetUsedBorderAndPadding());
      87             :           }
      88             : 
      89             :           mMouseDownRect =
      90           0 :             LayoutDeviceIntRect::FromAppUnitsToNearest(rect, aPresContext->AppUnitsPerDevPixel());
      91           0 :           doDefault = false;
      92             :         }
      93             :         else {
      94             :           // If there is no window, then resizing isn't allowed.
      95           0 :           if (!window)
      96           0 :             break;
      97             : 
      98           0 :           doDefault = false;
      99             : 
     100             :           // ask the widget implementation to begin a resize drag if it can
     101           0 :           Direction direction = GetDirection();
     102           0 :           nsresult rv = aEvent->mWidget->BeginResizeDrag(aEvent,
     103           0 :                         direction.mHorizontal, direction.mVertical);
     104             :           // for native drags, don't set the fields below
     105           0 :           if (rv != NS_ERROR_NOT_IMPLEMENTED)
     106           0 :              break;
     107             : 
     108             :           // if there's no native resize support, we need to do window
     109             :           // resizing ourselves
     110           0 :           window->GetPositionAndSize(&mMouseDownRect.x, &mMouseDownRect.y,
     111           0 :                                      &mMouseDownRect.width, &mMouseDownRect.height);
     112             :         }
     113             : 
     114             :         // remember current mouse coordinates
     115           0 :         LayoutDeviceIntPoint refPoint;
     116           0 :         if (!GetEventPoint(aEvent, refPoint))
     117           0 :           return NS_OK;
     118           0 :         mMouseDownPoint = refPoint + aEvent->mWidget->WidgetToScreenOffset();
     119             : 
     120             :         // we're tracking
     121           0 :         mTrackingMouseMove = true;
     122             : 
     123           0 :         nsIPresShell::SetCapturingContent(GetContent(), CAPTURE_IGNOREALLOWED);
     124             :       }
     125             :     }
     126           0 :     break;
     127             : 
     128             :   case eTouchEnd:
     129             :   case eMouseUp: {
     130           0 :     if (aEvent->mClass == eTouchEventClass ||
     131           0 :         (aEvent->mClass == eMouseEventClass &&
     132           0 :          aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton)) {
     133             :       // we're done tracking.
     134           0 :       mTrackingMouseMove = false;
     135             : 
     136           0 :       nsIPresShell::SetCapturingContent(nullptr, 0);
     137             : 
     138           0 :       doDefault = false;
     139             :     }
     140             :   }
     141           0 :   break;
     142             : 
     143             :   case eTouchMove:
     144             :   case eMouseMove: {
     145           0 :     if (mTrackingMouseMove)
     146             :     {
     147           0 :       nsCOMPtr<nsIBaseWindow> window;
     148           0 :       nsIPresShell* presShell = aPresContext->GetPresShell();
     149             :       nsCOMPtr<nsIContent> contentToResize =
     150           0 :         GetContentToResize(presShell, getter_AddRefs(window));
     151             : 
     152             :       // check if the returned content really is a menupopup
     153           0 :       nsMenuPopupFrame* menuPopupFrame = nullptr;
     154           0 :       if (contentToResize) {
     155           0 :         menuPopupFrame = do_QueryFrame(contentToResize->GetPrimaryFrame());
     156             :       }
     157             : 
     158             :       // both MouseMove and direction are negative when pointing to the
     159             :       // top and left, and positive when pointing to the bottom and right
     160             : 
     161             :       // retrieve the offset of the mousemove event relative to the mousedown.
     162             :       // The difference is how much the resize needs to be
     163           0 :       LayoutDeviceIntPoint refPoint;
     164           0 :       if (!GetEventPoint(aEvent, refPoint))
     165           0 :         return NS_OK;
     166             :       LayoutDeviceIntPoint screenPoint =
     167           0 :         refPoint + aEvent->mWidget->WidgetToScreenOffset();
     168           0 :       LayoutDeviceIntPoint mouseMove(screenPoint - mMouseDownPoint);
     169             : 
     170             :       // Determine which direction to resize by checking the dir attribute.
     171             :       // For windows and menus, ensure that it can be resized in that direction.
     172           0 :       Direction direction = GetDirection();
     173           0 :       if (window || menuPopupFrame) {
     174           0 :         if (menuPopupFrame) {
     175           0 :           menuPopupFrame->CanAdjustEdges(
     176           0 :             (direction.mHorizontal == -1) ? eSideLeft : eSideRight,
     177           0 :             (direction.mVertical == -1) ? eSideTop : eSideBottom, mouseMove);
     178             :         }
     179             :       }
     180           0 :       else if (!contentToResize) {
     181           0 :         break; // don't do anything if there's nothing to resize
     182             :       }
     183             : 
     184           0 :       LayoutDeviceIntRect rect = mMouseDownRect;
     185             : 
     186             :       // Check if there are any size constraints on this window.
     187           0 :       widget::SizeConstraints sizeConstraints;
     188           0 :       if (window) {
     189           0 :         nsCOMPtr<nsIWidget> widget;
     190           0 :         window->GetMainWidget(getter_AddRefs(widget));
     191           0 :         sizeConstraints = widget->GetSizeConstraints();
     192             :       }
     193             : 
     194           0 :       AdjustDimensions(&rect.x, &rect.width, sizeConstraints.mMinSize.width,
     195           0 :                        sizeConstraints.mMaxSize.width, mouseMove.x, direction.mHorizontal);
     196           0 :       AdjustDimensions(&rect.y, &rect.height, sizeConstraints.mMinSize.height,
     197           0 :                        sizeConstraints.mMaxSize.height, mouseMove.y, direction.mVertical);
     198             : 
     199             :       // Don't allow resizing a window or a popup past the edge of the screen,
     200             :       // so adjust the rectangle to fit within the available screen area.
     201           0 :       if (window) {
     202           0 :         nsCOMPtr<nsIScreen> screen;
     203           0 :         nsCOMPtr<nsIScreenManager> sm(do_GetService("@mozilla.org/gfx/screenmanager;1"));
     204           0 :         if (sm) {
     205           0 :           CSSIntRect frameRect = GetScreenRect();
     206             :           // ScreenForRect requires display pixels, so scale from device pix
     207             :           double scale;
     208           0 :           window->GetUnscaledDevicePixelsPerCSSPixel(&scale);
     209           0 :           sm->ScreenForRect(NSToIntRound(frameRect.x / scale),
     210           0 :                             NSToIntRound(frameRect.y / scale), 1, 1,
     211           0 :                             getter_AddRefs(screen));
     212           0 :           if (screen) {
     213           0 :             LayoutDeviceIntRect screenRect;
     214           0 :             screen->GetRect(&screenRect.x, &screenRect.y,
     215           0 :                             &screenRect.width, &screenRect.height);
     216           0 :             rect.IntersectRect(rect, screenRect);
     217             :           }
     218             :         }
     219             :       }
     220           0 :       else if (menuPopupFrame) {
     221           0 :         nsRect frameRect = menuPopupFrame->GetScreenRectInAppUnits();
     222           0 :         nsIFrame* rootFrame = aPresContext->PresShell()->FrameManager()->GetRootFrame();
     223           0 :         nsRect rootScreenRect = rootFrame->GetScreenRectInAppUnits();
     224             : 
     225           0 :         nsPopupLevel popupLevel = menuPopupFrame->PopupLevel();
     226           0 :         int32_t appPerDev = aPresContext->AppUnitsPerDevPixel();
     227             :         LayoutDeviceIntRect screenRect = menuPopupFrame->GetConstraintRect
     228           0 :           (LayoutDeviceIntRect::FromAppUnitsToNearest(frameRect, appPerDev),
     229             :            // round using ...ToInside as it's better to be a pixel too small
     230             :            // than be too large. If the popup is too large it could get flipped
     231             :            // to the opposite side of the anchor point while resizing.
     232           0 :            LayoutDeviceIntRect::FromAppUnitsToInside(rootScreenRect, appPerDev),
     233           0 :            popupLevel);
     234           0 :         rect.IntersectRect(rect, screenRect);
     235             :       }
     236             : 
     237           0 :       if (contentToResize) {
     238             :         // convert the rectangle into css pixels. When changing the size in a
     239             :         // direction, don't allow the new size to be less that the resizer's
     240             :         // size. This ensures that content isn't resized too small as to make
     241             :         // the resizer invisible.
     242           0 :         nsRect appUnitsRect = ToAppUnits(rect.ToUnknownRect(), aPresContext->AppUnitsPerDevPixel());
     243           0 :         if (appUnitsRect.width < mRect.width && mouseMove.x)
     244           0 :           appUnitsRect.width = mRect.width;
     245           0 :         if (appUnitsRect.height < mRect.height && mouseMove.y)
     246           0 :           appUnitsRect.height = mRect.height;
     247           0 :         nsIntRect cssRect = appUnitsRect.ToInsidePixels(nsPresContext::AppUnitsPerCSSPixel());
     248             : 
     249           0 :         LayoutDeviceIntRect oldRect;
     250           0 :         AutoWeakFrame weakFrame(menuPopupFrame);
     251           0 :         if (menuPopupFrame) {
     252           0 :           nsCOMPtr<nsIWidget> widget = menuPopupFrame->GetWidget();
     253           0 :           if (widget)
     254           0 :             oldRect = widget->GetScreenBounds();
     255             : 
     256             :           // convert the new rectangle into outer window coordinates
     257           0 :           LayoutDeviceIntPoint clientOffset = widget->GetClientOffset();
     258           0 :           rect.x -= clientOffset.x;
     259           0 :           rect.y -= clientOffset.y;
     260             :         }
     261             : 
     262           0 :         SizeInfo sizeInfo, originalSizeInfo;
     263           0 :         sizeInfo.width.AppendInt(cssRect.width);
     264           0 :         sizeInfo.height.AppendInt(cssRect.height);
     265           0 :         ResizeContent(contentToResize, direction, sizeInfo, &originalSizeInfo);
     266           0 :         MaybePersistOriginalSize(contentToResize, originalSizeInfo);
     267             : 
     268             :         // Move the popup to the new location unless it is anchored, since
     269             :         // the position shouldn't change. nsMenuPopupFrame::SetPopupPosition
     270             :         // will instead ensure that the popup's position is anchored at the
     271             :         // right place.
     272           0 :         if (weakFrame.IsAlive() &&
     273           0 :             (oldRect.x != rect.x || oldRect.y != rect.y) &&
     274           0 :             (!menuPopupFrame->IsAnchored() ||
     275           0 :              menuPopupFrame->PopupLevel() != ePopupLevelParent)) {
     276             : 
     277           0 :           CSSPoint cssPos = rect.TopLeft() / aPresContext->CSSToDevPixelScale();
     278           0 :           menuPopupFrame->MoveTo(RoundedToInt(cssPos), true);
     279             :         }
     280             :       }
     281             :       else {
     282           0 :         window->SetPositionAndSize(rect.x, rect.y, rect.width, rect.height,
     283           0 :                                    nsIBaseWindow::eRepaint); // do the repaint.
     284             :       }
     285             : 
     286           0 :       doDefault = false;
     287             :     }
     288             :   }
     289           0 :   break;
     290             : 
     291             :   case eMouseClick: {
     292           0 :     WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent();
     293           0 :     if (mouseEvent->IsLeftClickEvent()) {
     294           0 :       MouseClicked(mouseEvent);
     295             :     }
     296           0 :     break;
     297             :   }
     298             :   case eMouseDoubleClick:
     299           0 :     if (aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton) {
     300           0 :       nsCOMPtr<nsIBaseWindow> window;
     301           0 :       nsIPresShell* presShell = aPresContext->GetPresShell();
     302             :       nsIContent* contentToResize =
     303           0 :         GetContentToResize(presShell, getter_AddRefs(window));
     304           0 :       if (contentToResize) {
     305           0 :         nsMenuPopupFrame* menuPopupFrame = do_QueryFrame(contentToResize->GetPrimaryFrame());
     306           0 :         if (menuPopupFrame)
     307           0 :           break; // Don't restore original sizing for menupopup frames until
     308             :                  // we handle screen constraints here. (Bug 357725)
     309             : 
     310           0 :         RestoreOriginalSize(contentToResize);
     311             :       }
     312             :     }
     313           0 :     break;
     314             : 
     315             :   default:
     316           0 :     break;
     317             :   }
     318             : 
     319           0 :   if (!doDefault)
     320           0 :     *aEventStatus = nsEventStatus_eConsumeNoDefault;
     321             : 
     322           0 :   if (doDefault && weakFrame.IsAlive())
     323           0 :     return nsTitleBarFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
     324             : 
     325           0 :   return NS_OK;
     326             : }
     327             : 
     328             : nsIContent*
     329           0 : nsResizerFrame::GetContentToResize(nsIPresShell* aPresShell, nsIBaseWindow** aWindow)
     330             : {
     331           0 :   *aWindow = nullptr;
     332             : 
     333           0 :   nsAutoString elementid;
     334           0 :   mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::element, elementid);
     335           0 :   if (elementid.IsEmpty()) {
     336             :     // If the resizer is in a popup, resize the popup's widget, otherwise
     337             :     // resize the widget associated with the window.
     338           0 :     nsIFrame* popup = GetParent();
     339           0 :     while (popup) {
     340           0 :       nsMenuPopupFrame* popupFrame = do_QueryFrame(popup);
     341           0 :       if (popupFrame) {
     342           0 :         return popupFrame->GetContent();
     343             :       }
     344           0 :       popup = popup->GetParent();
     345             :     }
     346             : 
     347             :     // don't allow resizing windows in content shells
     348           0 :     nsCOMPtr<nsIDocShellTreeItem> dsti = aPresShell->GetPresContext()->GetDocShell();
     349           0 :     if (!dsti || dsti->ItemType() != nsIDocShellTreeItem::typeChrome) {
     350             :       // don't allow resizers in content shells, except for the viewport
     351             :       // scrollbar which doesn't have a parent
     352           0 :       nsIContent* nonNativeAnon = mContent->FindFirstNonChromeOnlyAccessContent();
     353           0 :       if (!nonNativeAnon || nonNativeAnon->GetParent()) {
     354           0 :         return nullptr;
     355             :       }
     356             :     }
     357             : 
     358             :     // get the document and the window - should this be cached?
     359           0 :     if (nsPIDOMWindowOuter* domWindow = aPresShell->GetDocument()->GetWindow()) {
     360           0 :       nsCOMPtr<nsIDocShell> docShell = domWindow->GetDocShell();
     361           0 :       if (docShell) {
     362           0 :         nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
     363           0 :         docShell->GetTreeOwner(getter_AddRefs(treeOwner));
     364           0 :         if (treeOwner) {
     365           0 :           CallQueryInterface(treeOwner, aWindow);
     366             :         }
     367             :       }
     368             :     }
     369             : 
     370           0 :     return nullptr;
     371             :   }
     372             : 
     373           0 :   if (elementid.EqualsLiteral("_parent")) {
     374             :     // return the parent, but skip over native anonymous content
     375           0 :     nsIContent* parent = mContent->GetParent();
     376           0 :     return parent ? parent->FindFirstNonChromeOnlyAccessContent() : nullptr;
     377             :   }
     378             : 
     379           0 :   return aPresShell->GetDocument()->GetElementById(elementid);
     380             : }
     381             : 
     382             : void
     383           0 : nsResizerFrame::AdjustDimensions(int32_t* aPos, int32_t* aSize,
     384             :                                  int32_t aMinSize, int32_t aMaxSize,
     385             :                                  int32_t aMovement, int8_t aResizerDirection)
     386             : {
     387           0 :   int32_t oldSize = *aSize;
     388             : 
     389           0 :   *aSize += aResizerDirection * aMovement;
     390             :   // use one as a minimum size or the element could disappear
     391           0 :   if (*aSize < 1)
     392           0 :     *aSize = 1;
     393             : 
     394             :   // Constrain the size within the minimum and maximum size.
     395           0 :   *aSize = std::max(aMinSize, std::min(aMaxSize, *aSize));
     396             : 
     397             :   // For left and top resizers, the window must be moved left by the same
     398             :   // amount that the window was resized.
     399           0 :   if (aResizerDirection == -1)
     400           0 :     *aPos += oldSize - *aSize;
     401           0 : }
     402             : 
     403             : /* static */ void
     404           0 : nsResizerFrame::ResizeContent(nsIContent* aContent, const Direction& aDirection,
     405             :                               const SizeInfo& aSizeInfo, SizeInfo* aOriginalSizeInfo)
     406             : {
     407             :   // for XUL elements, just set the width and height attributes. For
     408             :   // other elements, set style.width and style.height
     409           0 :   if (aContent->IsXULElement()) {
     410           0 :     if (aOriginalSizeInfo) {
     411           0 :       aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::width,
     412           0 :                         aOriginalSizeInfo->width);
     413           0 :       aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::height,
     414           0 :                         aOriginalSizeInfo->height);
     415             :     }
     416             :     // only set the property if the element could have changed in that direction
     417           0 :     if (aDirection.mHorizontal) {
     418           0 :       aContent->SetAttr(kNameSpaceID_None, nsGkAtoms::width, aSizeInfo.width, true);
     419             :     }
     420           0 :     if (aDirection.mVertical) {
     421           0 :       aContent->SetAttr(kNameSpaceID_None, nsGkAtoms::height, aSizeInfo.height, true);
     422             :     }
     423             :   }
     424             :   else {
     425             :     nsCOMPtr<nsStyledElement> inlineStyleContent =
     426           0 :       do_QueryInterface(aContent);
     427           0 :     if (inlineStyleContent) {
     428           0 :       nsICSSDeclaration* decl = inlineStyleContent->Style();
     429             : 
     430           0 :       if (aOriginalSizeInfo) {
     431           0 :         decl->GetPropertyValue(NS_LITERAL_STRING("width"),
     432           0 :                                aOriginalSizeInfo->width);
     433           0 :         decl->GetPropertyValue(NS_LITERAL_STRING("height"),
     434           0 :                                aOriginalSizeInfo->height);
     435             :       }
     436             : 
     437             :       // only set the property if the element could have changed in that direction
     438           0 :       if (aDirection.mHorizontal) {
     439           0 :         nsAutoString widthstr(aSizeInfo.width);
     440           0 :         if (!widthstr.IsEmpty() &&
     441           0 :             !Substring(widthstr, widthstr.Length() - 2, 2).EqualsLiteral("px"))
     442           0 :           widthstr.AppendLiteral("px");
     443           0 :         decl->SetProperty(NS_LITERAL_STRING("width"), widthstr, EmptyString());
     444             :       }
     445           0 :       if (aDirection.mVertical) {
     446           0 :         nsAutoString heightstr(aSizeInfo.height);
     447           0 :         if (!heightstr.IsEmpty() &&
     448           0 :             !Substring(heightstr, heightstr.Length() - 2, 2).EqualsLiteral("px"))
     449           0 :           heightstr.AppendLiteral("px");
     450           0 :         decl->SetProperty(NS_LITERAL_STRING("height"), heightstr, EmptyString());
     451             :       }
     452             :     }
     453             :   }
     454           0 : }
     455             : 
     456             : /* static */ void
     457           0 : nsResizerFrame::MaybePersistOriginalSize(nsIContent* aContent,
     458             :                                          const SizeInfo& aSizeInfo)
     459             : {
     460             :   nsresult rv;
     461             : 
     462           0 :   aContent->GetProperty(nsGkAtoms::_moz_original_size, &rv);
     463           0 :   if (rv != NS_PROPTABLE_PROP_NOT_THERE)
     464           0 :     return;
     465             : 
     466           0 :   nsAutoPtr<SizeInfo> sizeInfo(new SizeInfo(aSizeInfo));
     467           0 :   rv = aContent->SetProperty(nsGkAtoms::_moz_original_size, sizeInfo.get(),
     468             :                              nsINode::DeleteProperty<nsResizerFrame::SizeInfo>);
     469           0 :   if (NS_SUCCEEDED(rv))
     470           0 :     sizeInfo.forget();
     471             : }
     472             : 
     473             : /* static */ void
     474           0 : nsResizerFrame::RestoreOriginalSize(nsIContent* aContent)
     475             : {
     476             :   nsresult rv;
     477             :   SizeInfo* sizeInfo =
     478           0 :     static_cast<SizeInfo*>(aContent->GetProperty(nsGkAtoms::_moz_original_size,
     479           0 :                            &rv));
     480           0 :   if (NS_FAILED(rv))
     481           0 :     return;
     482             : 
     483           0 :   NS_ASSERTION(sizeInfo, "We set a null sizeInfo!?");
     484           0 :   Direction direction = {1, 1};
     485           0 :   ResizeContent(aContent, direction, *sizeInfo, nullptr);
     486           0 :   aContent->DeleteProperty(nsGkAtoms::_moz_original_size);
     487             : }
     488             : 
     489             : /* returns a Direction struct containing the horizontal and vertical direction
     490             :  */
     491             : nsResizerFrame::Direction
     492           0 : nsResizerFrame::GetDirection()
     493             : {
     494             :   static const nsIContent::AttrValuesArray strings[] =
     495             :     {&nsGkAtoms::topleft,    &nsGkAtoms::top,    &nsGkAtoms::topright,
     496             :      &nsGkAtoms::left,                           &nsGkAtoms::right,
     497             :      &nsGkAtoms::bottomleft, &nsGkAtoms::bottom, &nsGkAtoms::bottomright,
     498             :      &nsGkAtoms::bottomstart,                    &nsGkAtoms::bottomend,
     499             :      nullptr};
     500             : 
     501             :   static const Direction directions[] =
     502             :     {{-1, -1}, {0, -1}, {1, -1},
     503             :      {-1,  0},          {1,  0},
     504             :      {-1,  1}, {0,  1}, {1,  1},
     505             :      {-1,  1},          {1,  1}
     506             :     };
     507             : 
     508           0 :   if (!GetContent()) {
     509           0 :     return directions[0]; // default: topleft
     510             :   }
     511             : 
     512           0 :   int32_t index = GetContent()->FindAttrValueIn(kNameSpaceID_None,
     513             :                                                 nsGkAtoms::dir,
     514           0 :                                                 strings, eCaseMatters);
     515           0 :   if (index < 0) {
     516           0 :     return directions[0]; // default: topleft
     517             :   }
     518             : 
     519           0 :   if (index >= 8) {
     520             :     // Directions 8 and higher are RTL-aware directions and should reverse the
     521             :     // horizontal component if RTL.
     522           0 :     WritingMode wm = GetWritingMode();
     523           0 :     if (!(wm.IsVertical() ? wm.IsVerticalLR() : wm.IsBidiLTR())) {
     524           0 :       Direction direction = directions[index];
     525           0 :       direction.mHorizontal *= -1;
     526           0 :       return direction;
     527             :     }
     528             :   }
     529             : 
     530           0 :   return directions[index];
     531             : }
     532             : 
     533             : void
     534           0 : nsResizerFrame::MouseClicked(WidgetMouseEvent* aEvent)
     535             : {
     536             :   // Execute the oncommand event handler.
     537           0 :   nsContentUtils::DispatchXULCommand(mContent, aEvent && aEvent->IsTrusted());
     538           0 : }

Generated by: LCOV version 1.13