2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2000-07-12 03:37:00 +04:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
2009-12-23 21:45:44 +03:00
|
|
|
#include "nsIServiceManager.h"
|
2000-07-12 03:37:00 +04:00
|
|
|
#include "nsResizerFrame.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMNodeList.h"
|
2006-12-26 20:47:52 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2014-02-28 03:04:46 +04:00
|
|
|
#include "nsNameSpaceManager.h"
|
2009-12-23 21:45:44 +03:00
|
|
|
#include "nsIDOMElementCSSInlineStyle.h"
|
|
|
|
#include "nsIDOMCSSStyleDeclaration.h"
|
2000-07-12 03:37:00 +04:00
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2009-12-23 21:45:44 +03:00
|
|
|
#include "nsFrameManager.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIDocShellTreeOwner.h"
|
|
|
|
#include "nsIBaseWindow.h"
|
2005-11-29 02:56:44 +03:00
|
|
|
#include "nsPIDOMWindow.h"
|
2013-09-25 15:21:18 +04:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2009-06-30 11:56:40 +04:00
|
|
|
#include "nsContentUtils.h"
|
2009-12-23 21:45:44 +03:00
|
|
|
#include "nsMenuPopupFrame.h"
|
|
|
|
#include "nsIScreenManager.h"
|
2011-07-20 23:18:54 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2011-07-20 23:18:54 +04:00
|
|
|
|
2012-07-31 04:43:29 +04:00
|
|
|
using namespace mozilla;
|
2000-07-12 03:37:00 +04:00
|
|
|
|
|
|
|
//
|
2005-10-27 01:46:39 +04:00
|
|
|
// NS_NewResizerFrame
|
2000-07-12 03:37:00 +04:00
|
|
|
//
|
2005-10-27 01:46:39 +04:00
|
|
|
// Creates a new Resizer frame and returns it
|
2000-07-12 03:37:00 +04:00
|
|
|
//
|
2005-10-27 01:46:39 +04:00
|
|
|
nsIFrame*
|
2006-03-27 01:30:36 +04:00
|
|
|
NS_NewResizerFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2000-07-12 03:37:00 +04:00
|
|
|
{
|
2015-01-06 12:27:56 +03:00
|
|
|
return new (aPresShell) nsResizerFrame(aContext);
|
2009-09-12 20:49:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsResizerFrame)
|
2000-07-12 03:37:00 +04:00
|
|
|
|
2015-01-06 12:27:56 +03:00
|
|
|
nsResizerFrame::nsResizerFrame(nsStyleContext* aContext)
|
|
|
|
:nsTitleBarFrame(aContext)
|
2000-07-12 03:37:00 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-18 11:47:48 +04:00
|
|
|
nsresult
|
2005-11-29 02:56:44 +03:00
|
|
|
nsResizerFrame::HandleEvent(nsPresContext* aPresContext,
|
2013-10-02 07:46:03 +04:00
|
|
|
WidgetGUIEvent* aEvent,
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
nsEventStatus* aEventStatus)
|
2000-07-12 03:37:00 +04:00
|
|
|
{
|
2009-02-27 13:48:25 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aEventStatus);
|
|
|
|
if (nsEventStatus_eConsumeNoDefault == *aEventStatus) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-10-02 11:28:36 +04:00
|
|
|
nsWeakFrame weakFrame(this);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool doDefault = true;
|
2000-07-12 03:37:00 +04:00
|
|
|
|
|
|
|
switch (aEvent->message) {
|
2012-07-28 02:01:12 +04:00
|
|
|
case NS_TOUCH_START:
|
2009-12-23 21:45:44 +03:00
|
|
|
case NS_MOUSE_BUTTON_DOWN: {
|
2014-08-04 09:28:53 +04:00
|
|
|
if (aEvent->mClass == eTouchEventClass ||
|
2014-08-04 09:28:50 +04:00
|
|
|
(aEvent->mClass == eMouseEventClass &&
|
2013-10-22 12:55:20 +04:00
|
|
|
aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton)) {
|
2009-12-23 21:45:44 +03:00
|
|
|
nsCOMPtr<nsIBaseWindow> window;
|
|
|
|
nsIPresShell* presShell = aPresContext->GetPresShell();
|
|
|
|
nsIContent* contentToResize =
|
|
|
|
GetContentToResize(presShell, getter_AddRefs(window));
|
|
|
|
if (contentToResize) {
|
2009-12-25 00:20:06 +03:00
|
|
|
nsIFrame* frameToResize = contentToResize->GetPrimaryFrame();
|
2009-12-23 21:45:44 +03:00
|
|
|
if (!frameToResize)
|
|
|
|
break;
|
|
|
|
|
2010-03-23 21:52:56 +03:00
|
|
|
// cache the content rectangle for the frame to resize
|
|
|
|
// GetScreenRectInAppUnits returns the border box rectangle, so
|
|
|
|
// adjust to get the desired content rectangle.
|
|
|
|
nsRect rect = frameToResize->GetScreenRectInAppUnits();
|
2013-02-17 01:51:02 +04:00
|
|
|
switch (frameToResize->StylePosition()->mBoxSizing) {
|
2010-03-23 21:52:56 +03:00
|
|
|
case NS_STYLE_BOX_SIZING_CONTENT:
|
2011-04-19 07:07:48 +04:00
|
|
|
rect.Deflate(frameToResize->GetUsedPadding());
|
2010-03-23 21:52:56 +03:00
|
|
|
case NS_STYLE_BOX_SIZING_PADDING:
|
2011-04-19 07:07:48 +04:00
|
|
|
rect.Deflate(frameToResize->GetUsedBorder());
|
2010-03-23 21:52:56 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-02-15 21:52:28 +03:00
|
|
|
mMouseDownRect =
|
|
|
|
LayoutDeviceIntRect::FromAppUnitsToNearest(rect, aPresContext->AppUnitsPerDevPixel());
|
2011-10-17 18:59:28 +04:00
|
|
|
doDefault = false;
|
2009-12-23 21:45:44 +03:00
|
|
|
}
|
|
|
|
else {
|
2011-09-30 00:05:10 +04:00
|
|
|
// If there is no window, then resizing isn't allowed.
|
|
|
|
if (!window)
|
|
|
|
break;
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
doDefault = false;
|
2011-09-30 00:05:10 +04:00
|
|
|
|
2009-12-23 21:45:44 +03:00
|
|
|
// ask the widget implementation to begin a resize drag if it can
|
|
|
|
Direction direction = GetDirection();
|
|
|
|
nsresult rv = aEvent->widget->BeginResizeDrag(aEvent,
|
|
|
|
direction.mHorizontal, direction.mVertical);
|
2011-09-30 00:05:10 +04:00
|
|
|
// for native drags, don't set the fields below
|
|
|
|
if (rv != NS_ERROR_NOT_IMPLEMENTED)
|
|
|
|
break;
|
|
|
|
|
|
|
|
// if there's no native resize support, we need to do window
|
|
|
|
// resizing ourselves
|
|
|
|
window->GetPositionAndSize(&mMouseDownRect.x, &mMouseDownRect.y,
|
|
|
|
&mMouseDownRect.width, &mMouseDownRect.height);
|
2009-12-23 21:45:44 +03:00
|
|
|
}
|
|
|
|
|
2012-07-28 02:01:12 +04:00
|
|
|
// remember current mouse coordinates
|
2015-02-02 01:27:41 +03:00
|
|
|
LayoutDeviceIntPoint refPoint;
|
2012-07-28 02:01:12 +04:00
|
|
|
if (!GetEventPoint(aEvent, refPoint))
|
|
|
|
return NS_OK;
|
2015-02-04 23:21:03 +03:00
|
|
|
mMouseDownPoint = refPoint + aEvent->widget->WidgetToScreenOffset();
|
2012-07-28 02:01:12 +04:00
|
|
|
|
2009-12-23 21:45:44 +03:00
|
|
|
// we're tracking
|
2011-10-17 18:59:28 +04:00
|
|
|
mTrackingMouseMove = true;
|
2009-12-23 21:45:44 +03:00
|
|
|
|
|
|
|
nsIPresShell::SetCapturingContent(GetContent(), CAPTURE_IGNOREALLOWED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2000-07-12 03:37:00 +04:00
|
|
|
|
2012-07-28 02:01:12 +04:00
|
|
|
case NS_TOUCH_END:
|
2009-12-23 21:45:44 +03:00
|
|
|
case NS_MOUSE_BUTTON_UP: {
|
2014-08-04 09:28:53 +04:00
|
|
|
if (aEvent->mClass == eTouchEventClass ||
|
2014-08-04 09:28:50 +04:00
|
|
|
(aEvent->mClass == eMouseEventClass &&
|
2013-10-22 12:55:20 +04:00
|
|
|
aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton)) {
|
2009-12-23 21:45:44 +03:00
|
|
|
// we're done tracking.
|
2011-10-17 18:59:28 +04:00
|
|
|
mTrackingMouseMove = false;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIPresShell::SetCapturingContent(nullptr, 0);
|
2000-07-12 03:37:00 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
doDefault = false;
|
2009-12-23 21:45:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-07-28 02:01:12 +04:00
|
|
|
case NS_TOUCH_MOVE:
|
2009-12-23 21:45:44 +03:00
|
|
|
case NS_MOUSE_MOVE: {
|
|
|
|
if (mTrackingMouseMove)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIBaseWindow> window;
|
|
|
|
nsIPresShell* presShell = aPresContext->GetPresShell();
|
|
|
|
nsCOMPtr<nsIContent> contentToResize =
|
|
|
|
GetContentToResize(presShell, getter_AddRefs(window));
|
|
|
|
|
|
|
|
// check if the returned content really is a menupopup
|
2012-07-30 18:20:58 +04:00
|
|
|
nsMenuPopupFrame* menuPopupFrame = nullptr;
|
2009-12-23 21:45:44 +03:00
|
|
|
if (contentToResize) {
|
2012-07-31 04:43:28 +04:00
|
|
|
menuPopupFrame = do_QueryFrame(contentToResize->GetPrimaryFrame());
|
2009-12-23 21:45:44 +03:00
|
|
|
}
|
2000-07-12 03:37:00 +04:00
|
|
|
|
2009-12-23 21:45:44 +03:00
|
|
|
// both MouseMove and direction are negative when pointing to the
|
|
|
|
// top and left, and positive when pointing to the bottom and right
|
|
|
|
|
|
|
|
// retrieve the offset of the mousemove event relative to the mousedown.
|
|
|
|
// The difference is how much the resize needs to be
|
2015-02-02 01:27:41 +03:00
|
|
|
LayoutDeviceIntPoint refPoint;
|
2012-07-28 02:01:12 +04:00
|
|
|
if (!GetEventPoint(aEvent, refPoint))
|
|
|
|
return NS_OK;
|
2015-02-04 23:21:03 +03:00
|
|
|
LayoutDeviceIntPoint screenPoint = refPoint + aEvent->widget->WidgetToScreenOffset();
|
2015-02-02 01:27:41 +03:00
|
|
|
LayoutDeviceIntPoint mouseMove(screenPoint - mMouseDownPoint);
|
2009-12-23 21:45:44 +03:00
|
|
|
|
2010-03-19 14:49:33 +03:00
|
|
|
// Determine which direction to resize by checking the dir attribute.
|
|
|
|
// For windows and menus, ensure that it can be resized in that direction.
|
|
|
|
Direction direction = GetDirection();
|
2009-12-23 21:45:44 +03:00
|
|
|
if (window || menuPopupFrame) {
|
|
|
|
if (menuPopupFrame) {
|
|
|
|
menuPopupFrame->CanAdjustEdges(
|
|
|
|
(direction.mHorizontal == -1) ? NS_SIDE_LEFT : NS_SIDE_RIGHT,
|
|
|
|
(direction.mVertical == -1) ? NS_SIDE_TOP : NS_SIDE_BOTTOM, mouseMove);
|
|
|
|
}
|
|
|
|
}
|
2010-03-19 14:49:33 +03:00
|
|
|
else if (!contentToResize) {
|
2009-12-23 21:45:44 +03:00
|
|
|
break; // don't do anything if there's nothing to resize
|
|
|
|
}
|
2005-11-29 02:56:44 +03:00
|
|
|
|
2015-02-15 21:52:28 +03:00
|
|
|
LayoutDeviceIntRect rect = mMouseDownRect;
|
2012-07-31 04:43:29 +04:00
|
|
|
|
|
|
|
// Check if there are any size constraints on this window.
|
|
|
|
widget::SizeConstraints sizeConstraints;
|
|
|
|
if (window) {
|
|
|
|
nsCOMPtr<nsIWidget> widget;
|
|
|
|
window->GetMainWidget(getter_AddRefs(widget));
|
|
|
|
sizeConstraints = widget->GetSizeConstraints();
|
|
|
|
}
|
|
|
|
|
|
|
|
AdjustDimensions(&rect.x, &rect.width, sizeConstraints.mMinSize.width,
|
|
|
|
sizeConstraints.mMaxSize.width, mouseMove.x, direction.mHorizontal);
|
|
|
|
AdjustDimensions(&rect.y, &rect.height, sizeConstraints.mMinSize.height,
|
|
|
|
sizeConstraints.mMaxSize.height, mouseMove.y, direction.mVertical);
|
2009-12-23 21:45:44 +03:00
|
|
|
|
|
|
|
// Don't allow resizing a window or a popup past the edge of the screen,
|
|
|
|
// so adjust the rectangle to fit within the available screen area.
|
|
|
|
if (window) {
|
|
|
|
nsCOMPtr<nsIScreen> screen;
|
|
|
|
nsCOMPtr<nsIScreenManager> sm(do_GetService("@mozilla.org/gfx/screenmanager;1"));
|
|
|
|
if (sm) {
|
|
|
|
nsIntRect frameRect = GetScreenRect();
|
2012-10-16 23:41:19 +04:00
|
|
|
// ScreenForRect requires display pixels, so scale from device pix
|
|
|
|
double scale;
|
|
|
|
window->GetUnscaledDevicePixelsPerCSSPixel(&scale);
|
|
|
|
sm->ScreenForRect(NSToIntRound(frameRect.x / scale),
|
|
|
|
NSToIntRound(frameRect.y / scale), 1, 1,
|
|
|
|
getter_AddRefs(screen));
|
2009-12-23 21:45:44 +03:00
|
|
|
if (screen) {
|
2015-02-15 21:52:28 +03:00
|
|
|
LayoutDeviceIntRect screenRect;
|
2009-12-23 21:45:44 +03:00
|
|
|
screen->GetRect(&screenRect.x, &screenRect.y,
|
|
|
|
&screenRect.width, &screenRect.height);
|
|
|
|
rect.IntersectRect(rect, screenRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (menuPopupFrame) {
|
2010-08-02 19:06:04 +04:00
|
|
|
nsRect frameRect = menuPopupFrame->GetScreenRectInAppUnits();
|
2009-12-23 21:45:44 +03:00
|
|
|
nsIFrame* rootFrame = aPresContext->PresShell()->FrameManager()->GetRootFrame();
|
|
|
|
nsRect rootScreenRect = rootFrame->GetScreenRectInAppUnits();
|
|
|
|
|
2014-02-07 21:35:09 +04:00
|
|
|
nsPopupLevel popupLevel = menuPopupFrame->PopupLevel();
|
|
|
|
nsRect screenRect = menuPopupFrame->GetConstraintRect(frameRect, rootScreenRect, popupLevel);
|
2009-12-23 21:45:44 +03:00
|
|
|
// round using ToInsidePixels as it's better to be a pixel too small
|
|
|
|
// than be too large. If the popup is too large it could get flipped
|
|
|
|
// to the opposite side of the anchor point while resizing.
|
|
|
|
nsIntRect screenRectPixels = screenRect.ToInsidePixels(aPresContext->AppUnitsPerDevPixel());
|
2015-02-15 21:52:28 +03:00
|
|
|
rect.IntersectRect(rect, LayoutDevicePixel::FromUntyped(screenRectPixels));
|
2009-12-23 21:45:44 +03:00
|
|
|
}
|
2005-11-29 02:56:44 +03:00
|
|
|
|
2009-12-23 21:45:44 +03:00
|
|
|
if (contentToResize) {
|
2010-03-19 14:49:33 +03:00
|
|
|
// convert the rectangle into css pixels. When changing the size in a
|
|
|
|
// direction, don't allow the new size to be less that the resizer's
|
|
|
|
// size. This ensures that content isn't resized too small as to make
|
|
|
|
// the resizer invisible.
|
2015-02-15 21:52:28 +03:00
|
|
|
nsRect appUnitsRect = LayoutDevicePixel::ToUntyped(rect).ToAppUnits(aPresContext->AppUnitsPerDevPixel());
|
2010-03-19 14:49:33 +03:00
|
|
|
if (appUnitsRect.width < mRect.width && mouseMove.x)
|
|
|
|
appUnitsRect.width = mRect.width;
|
|
|
|
if (appUnitsRect.height < mRect.height && mouseMove.y)
|
|
|
|
appUnitsRect.height = mRect.height;
|
|
|
|
nsIntRect cssRect = appUnitsRect.ToInsidePixels(nsPresContext::AppUnitsPerCSSPixel());
|
2009-12-23 21:45:44 +03:00
|
|
|
|
2011-08-18 18:25:36 +04:00
|
|
|
nsIntRect oldRect;
|
|
|
|
nsWeakFrame weakFrame(menuPopupFrame);
|
|
|
|
if (menuPopupFrame) {
|
2011-12-02 01:35:42 +04:00
|
|
|
nsCOMPtr<nsIWidget> widget = menuPopupFrame->GetWidget();
|
2011-08-18 18:25:36 +04:00
|
|
|
if (widget)
|
|
|
|
widget->GetScreenBounds(oldRect);
|
|
|
|
|
|
|
|
// convert the new rectangle into outer window coordinates
|
|
|
|
nsIntPoint clientOffset = widget->GetClientOffset();
|
2014-04-08 16:45:52 +04:00
|
|
|
rect.x -= clientOffset.x;
|
|
|
|
rect.y -= clientOffset.y;
|
2009-12-23 21:45:44 +03:00
|
|
|
}
|
2011-08-18 18:25:36 +04:00
|
|
|
|
|
|
|
SizeInfo sizeInfo, originalSizeInfo;
|
|
|
|
sizeInfo.width.AppendInt(cssRect.width);
|
|
|
|
sizeInfo.height.AppendInt(cssRect.height);
|
|
|
|
ResizeContent(contentToResize, direction, sizeInfo, &originalSizeInfo);
|
|
|
|
MaybePersistOriginalSize(contentToResize, originalSizeInfo);
|
|
|
|
|
2012-07-31 04:43:29 +04:00
|
|
|
// Move the popup to the new location unless it is anchored, since
|
|
|
|
// the position shouldn't change. nsMenuPopupFrame::SetPopupPosition
|
|
|
|
// will instead ensure that the popup's position is anchored at the
|
|
|
|
// right place.
|
2011-08-18 18:25:36 +04:00
|
|
|
if (weakFrame.IsAlive() &&
|
|
|
|
(oldRect.x != rect.x || oldRect.y != rect.y) &&
|
|
|
|
(!menuPopupFrame->IsAnchored() ||
|
|
|
|
menuPopupFrame->PopupLevel() != ePopupLevelParent)) {
|
2014-04-08 16:45:52 +04:00
|
|
|
|
|
|
|
rect.x = aPresContext->DevPixelsToIntCSSPixels(rect.x);
|
|
|
|
rect.y = aPresContext->DevPixelsToIntCSSPixels(rect.y);
|
2011-10-17 18:59:28 +04:00
|
|
|
menuPopupFrame->MoveTo(rect.x, rect.y, true);
|
2009-12-23 21:45:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2011-10-17 18:59:28 +04:00
|
|
|
window->SetPositionAndSize(rect.x, rect.y, rect.width, rect.height, true); // do the repaint.
|
2009-12-23 21:45:44 +03:00
|
|
|
}
|
2005-11-29 02:56:44 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
doDefault = false;
|
2009-12-23 21:45:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-10-28 13:03:19 +04:00
|
|
|
case NS_MOUSE_CLICK: {
|
|
|
|
WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent();
|
|
|
|
if (mouseEvent->IsLeftClickEvent()) {
|
|
|
|
MouseClicked(aPresContext, mouseEvent);
|
2009-12-23 21:45:44 +03:00
|
|
|
}
|
|
|
|
break;
|
2013-10-28 13:03:19 +04:00
|
|
|
}
|
2011-08-18 18:25:36 +04:00
|
|
|
case NS_MOUSE_DOUBLECLICK:
|
2013-10-22 12:55:20 +04:00
|
|
|
if (aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton) {
|
2011-08-18 18:25:36 +04:00
|
|
|
nsCOMPtr<nsIBaseWindow> window;
|
|
|
|
nsIPresShell* presShell = aPresContext->GetPresShell();
|
|
|
|
nsIContent* contentToResize =
|
|
|
|
GetContentToResize(presShell, getter_AddRefs(window));
|
|
|
|
if (contentToResize) {
|
2012-07-31 04:43:28 +04:00
|
|
|
nsMenuPopupFrame* menuPopupFrame = do_QueryFrame(contentToResize->GetPrimaryFrame());
|
|
|
|
if (menuPopupFrame)
|
2011-08-18 18:25:36 +04:00
|
|
|
break; // Don't restore original sizing for menupopup frames until
|
|
|
|
// we handle screen constraints here. (Bug 357725)
|
|
|
|
|
|
|
|
RestoreOriginalSize(contentToResize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2009-12-23 21:45:44 +03:00
|
|
|
}
|
2005-11-29 02:56:44 +03:00
|
|
|
|
2009-12-23 21:45:44 +03:00
|
|
|
if (!doDefault)
|
|
|
|
*aEventStatus = nsEventStatus_eConsumeNoDefault;
|
2005-11-29 02:56:44 +03:00
|
|
|
|
2009-12-23 21:45:44 +03:00
|
|
|
if (doDefault && weakFrame.IsAlive())
|
|
|
|
return nsTitleBarFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
2011-07-29 13:38:41 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
2009-12-23 21:45:44 +03:00
|
|
|
}
|
2000-07-12 03:37:00 +04:00
|
|
|
|
2009-12-23 21:45:44 +03:00
|
|
|
nsIContent*
|
|
|
|
nsResizerFrame::GetContentToResize(nsIPresShell* aPresShell, nsIBaseWindow** aWindow)
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aWindow = nullptr;
|
2009-12-23 21:45:44 +03:00
|
|
|
|
|
|
|
nsAutoString elementid;
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::element, elementid);
|
|
|
|
if (elementid.IsEmpty()) {
|
|
|
|
// If the resizer is in a popup, resize the popup's widget, otherwise
|
|
|
|
// resize the widget associated with the window.
|
|
|
|
nsIFrame* popup = GetParent();
|
|
|
|
while (popup) {
|
2012-07-31 04:43:28 +04:00
|
|
|
nsMenuPopupFrame* popupFrame = do_QueryFrame(popup);
|
|
|
|
if (popupFrame) {
|
|
|
|
return popupFrame->GetContent();
|
2009-12-23 21:45:44 +03:00
|
|
|
}
|
|
|
|
popup = popup->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
// don't allow resizing windows in content shells
|
2013-11-20 23:18:25 +04:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> dsti = aPresShell->GetPresContext()->GetDocShell();
|
2014-01-20 11:58:26 +04:00
|
|
|
if (!dsti || dsti->ItemType() != nsIDocShellTreeItem::typeChrome) {
|
2011-01-17 17:35:32 +03:00
|
|
|
// don't allow resizers in content shells, except for the viewport
|
|
|
|
// scrollbar which doesn't have a parent
|
2012-10-10 23:04:42 +04:00
|
|
|
nsIContent* nonNativeAnon = mContent->FindFirstNonChromeOnlyAccessContent();
|
2011-09-30 00:05:10 +04:00
|
|
|
if (!nonNativeAnon || nonNativeAnon->GetParent()) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-01-17 17:35:32 +03:00
|
|
|
}
|
|
|
|
}
|
2009-12-23 21:45:44 +03:00
|
|
|
|
|
|
|
// get the document and the window - should this be cached?
|
|
|
|
nsPIDOMWindow *domWindow = aPresShell->GetDocument()->GetWindow();
|
|
|
|
if (domWindow) {
|
2013-02-13 02:02:51 +04:00
|
|
|
nsCOMPtr<nsIDocShell> docShell = domWindow->GetDocShell();
|
|
|
|
if (docShell) {
|
2009-12-23 21:45:44 +03:00
|
|
|
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
|
2013-02-13 02:02:51 +04:00
|
|
|
docShell->GetTreeOwner(getter_AddRefs(treeOwner));
|
2009-12-23 21:45:44 +03:00
|
|
|
if (treeOwner) {
|
|
|
|
CallQueryInterface(treeOwner, aWindow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-07-12 03:37:00 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-12-23 21:45:44 +03:00
|
|
|
}
|
2000-07-12 03:37:00 +04:00
|
|
|
|
2009-12-23 21:45:44 +03:00
|
|
|
if (elementid.EqualsLiteral("_parent")) {
|
2010-03-19 14:49:33 +03:00
|
|
|
// return the parent, but skip over native anonymous content
|
|
|
|
nsIContent* parent = mContent->GetParent();
|
2012-10-10 23:04:42 +04:00
|
|
|
return parent ? parent->FindFirstNonChromeOnlyAccessContent() : nullptr;
|
2000-07-12 03:37:00 +04:00
|
|
|
}
|
2005-11-29 02:56:44 +03:00
|
|
|
|
2010-06-24 01:35:57 +04:00
|
|
|
return aPresShell->GetDocument()->GetElementById(elementid);
|
2000-07-12 03:37:00 +04:00
|
|
|
}
|
|
|
|
|
2008-06-16 05:36:28 +04:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsResizerFrame::AdjustDimensions(int32_t* aPos, int32_t* aSize,
|
|
|
|
int32_t aMinSize, int32_t aMaxSize,
|
|
|
|
int32_t aMovement, int8_t aResizerDirection)
|
2000-07-12 03:37:00 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t oldSize = *aSize;
|
2012-07-31 04:43:29 +04:00
|
|
|
|
|
|
|
*aSize += aResizerDirection * aMovement;
|
|
|
|
// use one as a minimum size or the element could disappear
|
|
|
|
if (*aSize < 1)
|
|
|
|
*aSize = 1;
|
|
|
|
|
|
|
|
// Constrain the size within the minimum and maximum size.
|
2013-01-15 16:22:03 +04:00
|
|
|
*aSize = std::max(aMinSize, std::min(aMaxSize, *aSize));
|
2012-07-31 04:43:29 +04:00
|
|
|
|
|
|
|
// For left and top resizers, the window must be moved left by the same
|
|
|
|
// amount that the window was resized.
|
|
|
|
if (aResizerDirection == -1)
|
|
|
|
*aPos += oldSize - *aSize;
|
2000-07-12 03:37:00 +04:00
|
|
|
}
|
|
|
|
|
2011-08-18 18:25:36 +04:00
|
|
|
/* static */ void
|
|
|
|
nsResizerFrame::ResizeContent(nsIContent* aContent, const Direction& aDirection,
|
|
|
|
const SizeInfo& aSizeInfo, SizeInfo* aOriginalSizeInfo)
|
|
|
|
{
|
|
|
|
// for XUL elements, just set the width and height attributes. For
|
|
|
|
// other elements, set style.width and style.height
|
2015-03-03 14:08:59 +03:00
|
|
|
if (aContent->IsXULElement()) {
|
2011-08-18 18:25:36 +04:00
|
|
|
if (aOriginalSizeInfo) {
|
|
|
|
aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::width,
|
|
|
|
aOriginalSizeInfo->width);
|
|
|
|
aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::height,
|
|
|
|
aOriginalSizeInfo->height);
|
|
|
|
}
|
|
|
|
// only set the property if the element could have changed in that direction
|
|
|
|
if (aDirection.mHorizontal) {
|
2011-10-17 18:59:28 +04:00
|
|
|
aContent->SetAttr(kNameSpaceID_None, nsGkAtoms::width, aSizeInfo.width, true);
|
2011-08-18 18:25:36 +04:00
|
|
|
}
|
|
|
|
if (aDirection.mVertical) {
|
2011-10-17 18:59:28 +04:00
|
|
|
aContent->SetAttr(kNameSpaceID_None, nsGkAtoms::height, aSizeInfo.height, true);
|
2011-08-18 18:25:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIDOMElementCSSInlineStyle> inlineStyleContent =
|
|
|
|
do_QueryInterface(aContent);
|
|
|
|
if (inlineStyleContent) {
|
|
|
|
nsCOMPtr<nsIDOMCSSStyleDeclaration> decl;
|
|
|
|
inlineStyleContent->GetStyle(getter_AddRefs(decl));
|
|
|
|
|
|
|
|
if (aOriginalSizeInfo) {
|
|
|
|
decl->GetPropertyValue(NS_LITERAL_STRING("width"),
|
|
|
|
aOriginalSizeInfo->width);
|
|
|
|
decl->GetPropertyValue(NS_LITERAL_STRING("height"),
|
|
|
|
aOriginalSizeInfo->height);
|
|
|
|
}
|
|
|
|
|
|
|
|
// only set the property if the element could have changed in that direction
|
|
|
|
if (aDirection.mHorizontal) {
|
|
|
|
nsAutoString widthstr(aSizeInfo.width);
|
|
|
|
if (!widthstr.IsEmpty() &&
|
|
|
|
!Substring(widthstr, widthstr.Length() - 2, 2).EqualsLiteral("px"))
|
|
|
|
widthstr.AppendLiteral("px");
|
|
|
|
decl->SetProperty(NS_LITERAL_STRING("width"), widthstr, EmptyString());
|
|
|
|
}
|
|
|
|
if (aDirection.mVertical) {
|
|
|
|
nsAutoString heightstr(aSizeInfo.height);
|
|
|
|
if (!heightstr.IsEmpty() &&
|
|
|
|
!Substring(heightstr, heightstr.Length() - 2, 2).EqualsLiteral("px"))
|
|
|
|
heightstr.AppendLiteral("px");
|
|
|
|
decl->SetProperty(NS_LITERAL_STRING("height"), heightstr, EmptyString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
nsResizerFrame::MaybePersistOriginalSize(nsIContent* aContent,
|
|
|
|
const SizeInfo& aSizeInfo)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
aContent->GetProperty(nsGkAtoms::_moz_original_size, &rv);
|
|
|
|
if (rv != NS_PROPTABLE_PROP_NOT_THERE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsAutoPtr<SizeInfo> sizeInfo(new SizeInfo(aSizeInfo));
|
|
|
|
rv = aContent->SetProperty(nsGkAtoms::_moz_original_size, sizeInfo.get(),
|
2014-03-25 17:25:47 +04:00
|
|
|
nsINode::DeleteProperty<nsResizerFrame::SizeInfo>);
|
2011-08-18 18:25:36 +04:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
sizeInfo.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
nsResizerFrame::RestoreOriginalSize(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
SizeInfo* sizeInfo =
|
|
|
|
static_cast<SizeInfo*>(aContent->GetProperty(nsGkAtoms::_moz_original_size,
|
|
|
|
&rv));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return;
|
|
|
|
|
|
|
|
NS_ASSERTION(sizeInfo, "We set a null sizeInfo!?");
|
|
|
|
Direction direction = {1, 1};
|
2012-07-30 18:20:58 +04:00
|
|
|
ResizeContent(aContent, direction, *sizeInfo, nullptr);
|
2011-08-18 18:25:36 +04:00
|
|
|
aContent->DeleteProperty(nsGkAtoms::_moz_original_size);
|
|
|
|
}
|
|
|
|
|
2008-06-16 05:36:28 +04:00
|
|
|
/* returns a Direction struct containing the horizontal and vertical direction
|
2000-07-12 03:37:00 +04:00
|
|
|
*/
|
2008-06-16 05:36:28 +04:00
|
|
|
nsResizerFrame::Direction
|
|
|
|
nsResizerFrame::GetDirection()
|
2000-07-12 03:37:00 +04:00
|
|
|
{
|
2008-06-16 05:36:28 +04:00
|
|
|
static const nsIContent::AttrValuesArray strings[] =
|
|
|
|
{&nsGkAtoms::topleft, &nsGkAtoms::top, &nsGkAtoms::topright,
|
|
|
|
&nsGkAtoms::left, &nsGkAtoms::right,
|
|
|
|
&nsGkAtoms::bottomleft, &nsGkAtoms::bottom, &nsGkAtoms::bottomright,
|
2011-07-29 13:38:41 +04:00
|
|
|
&nsGkAtoms::bottomstart, &nsGkAtoms::bottomend,
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr};
|
2008-06-16 05:36:28 +04:00
|
|
|
|
|
|
|
static const Direction directions[] =
|
|
|
|
{{-1, -1}, {0, -1}, {1, -1},
|
|
|
|
{-1, 0}, {1, 0},
|
2009-01-18 13:28:19 +03:00
|
|
|
{-1, 1}, {0, 1}, {1, 1},
|
2011-07-29 13:38:41 +04:00
|
|
|
{-1, 1}, {1, 1}
|
2008-06-16 05:36:28 +04:00
|
|
|
};
|
2000-07-12 03:37:00 +04:00
|
|
|
|
2014-11-13 16:24:00 +03:00
|
|
|
if (!GetContent()) {
|
2008-06-16 05:36:28 +04:00
|
|
|
return directions[0]; // default: topleft
|
2014-11-13 16:24:00 +03:00
|
|
|
}
|
2000-07-12 03:37:00 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t index = GetContent()->FindAttrValueIn(kNameSpaceID_None,
|
2008-06-16 05:36:28 +04:00
|
|
|
nsGkAtoms::dir,
|
|
|
|
strings, eCaseMatters);
|
2014-11-13 16:24:00 +03:00
|
|
|
if (index < 0) {
|
2008-06-16 05:36:28 +04:00
|
|
|
return directions[0]; // default: topleft
|
2014-11-13 16:24:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (index >= 8) {
|
2009-01-18 13:28:19 +03:00
|
|
|
// Directions 8 and higher are RTL-aware directions and should reverse the
|
|
|
|
// horizontal component if RTL.
|
2014-11-13 16:24:00 +03:00
|
|
|
WritingMode wm = GetWritingMode();
|
|
|
|
if (!(wm.IsVertical() ? wm.IsVerticalLR() : wm.IsBidiLTR())) {
|
|
|
|
Direction direction = directions[index];
|
|
|
|
direction.mHorizontal *= -1;
|
|
|
|
return direction;
|
|
|
|
}
|
2009-01-18 13:28:19 +03:00
|
|
|
}
|
2014-11-13 16:24:00 +03:00
|
|
|
|
2009-01-18 13:28:19 +03:00
|
|
|
return directions[index];
|
2000-07-12 03:37:00 +04:00
|
|
|
}
|
|
|
|
|
2005-11-29 02:56:44 +03:00
|
|
|
void
|
2013-10-02 07:46:03 +04:00
|
|
|
nsResizerFrame::MouseClicked(nsPresContext* aPresContext,
|
2013-10-28 13:03:19 +04:00
|
|
|
WidgetMouseEvent* aEvent)
|
2000-07-12 03:37:00 +04:00
|
|
|
{
|
|
|
|
// Execute the oncommand event handler.
|
2009-06-30 11:56:40 +04:00
|
|
|
nsContentUtils::DispatchXULCommand(mContent,
|
2012-12-16 05:26:03 +04:00
|
|
|
aEvent && aEvent->mFlags.mIsTrusted);
|
2000-07-12 03:37:00 +04:00
|
|
|
}
|