2003-02-24 13:18:18 +03: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/. */
|
2003-02-24 13:18:18 +03:00
|
|
|
|
2016-07-09 05:42:33 +03:00
|
|
|
#include "mozilla/HTMLEditor.h"
|
2016-07-07 13:49:07 +03:00
|
|
|
#include "HTMLEditorObjectResizerUtils.h"
|
2014-12-02 08:07:42 +03:00
|
|
|
|
2016-07-07 08:01:12 +03:00
|
|
|
#include "HTMLEditUtils.h"
|
2015-04-19 15:28:50 +03:00
|
|
|
#include "mozilla/DebugOnly.h"
|
2016-07-08 08:03:31 +03:00
|
|
|
#include "mozilla/EditorUtils.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "mozilla/LookAndFeel.h"
|
2013-02-16 07:55:36 +04:00
|
|
|
#include "mozilla/MathAlgorithms.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
#include "mozilla/mozalloc.h"
|
|
|
|
#include "nsAString.h"
|
|
|
|
#include "nsAlgorithm.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsError.h"
|
2014-08-29 15:43:24 +04:00
|
|
|
#include "nsGkAtoms.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsID.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDOMEvent.h"
|
2011-06-24 06:18:00 +04:00
|
|
|
#include "nsIDOMEventTarget.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsIDOMMouseEvent.h"
|
|
|
|
#include "nsIDOMNode.h"
|
2003-02-24 13:18:18 +03:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIEditor.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsIHTMLObjectResizer.h"
|
2003-02-24 13:18:18 +03:00
|
|
|
#include "nsIPresShell.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsISupportsUtils.h"
|
2005-11-29 02:56:44 +03:00
|
|
|
#include "nsPIDOMWindow.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsStringFwd.h"
|
|
|
|
#include "nsSubstringTuple.h"
|
|
|
|
#include "nscore.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2012-07-13 10:33:42 +04:00
|
|
|
|
|
|
|
class nsISelection;
|
2003-06-25 12:50:48 +04:00
|
|
|
|
2016-07-07 13:49:07 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
using namespace dom;
|
|
|
|
|
2016-07-09 05:42:33 +03:00
|
|
|
/******************************************************************************
|
2016-07-07 13:49:07 +03:00
|
|
|
* mozilla::DocumentResizeEventListener
|
2016-07-09 05:42:33 +03:00
|
|
|
******************************************************************************/
|
2011-06-17 04:59:29 +04:00
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(DocumentResizeEventListener, nsIDOMEventListener)
|
2003-02-24 13:18:18 +03:00
|
|
|
|
2016-07-09 05:42:33 +03:00
|
|
|
DocumentResizeEventListener::DocumentResizeEventListener(nsIHTMLEditor* aEditor)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
2003-10-10 02:08:59 +04:00
|
|
|
mEditor = do_GetWeakReference(aEditor);
|
2003-02-24 13:18:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-06-25 12:50:48 +04:00
|
|
|
DocumentResizeEventListener::HandleEvent(nsIDOMEvent* aMouseEvent)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
2003-10-10 02:08:59 +04:00
|
|
|
nsCOMPtr<nsIHTMLObjectResizer> objectResizer = do_QueryReferent(mEditor);
|
2016-10-24 05:27:45 +03:00
|
|
|
if (objectResizer) {
|
2003-10-10 02:08:59 +04:00
|
|
|
return objectResizer->RefreshResizers();
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
2003-10-10 02:08:59 +04:00
|
|
|
return NS_OK;
|
2003-02-24 13:18:18 +03:00
|
|
|
}
|
|
|
|
|
2016-07-09 05:42:33 +03:00
|
|
|
/******************************************************************************
|
2016-07-07 13:49:07 +03:00
|
|
|
* mozilla::ResizerSelectionListener
|
2016-07-09 05:42:33 +03:00
|
|
|
******************************************************************************/
|
2003-02-24 13:18:18 +03:00
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(ResizerSelectionListener, nsISelectionListener)
|
2003-02-24 13:18:18 +03:00
|
|
|
|
2016-07-09 05:42:33 +03:00
|
|
|
ResizerSelectionListener::ResizerSelectionListener(nsIHTMLEditor* aEditor)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
2003-10-10 02:08:59 +04:00
|
|
|
mEditor = do_GetWeakReference(aEditor);
|
2003-02-24 13:18:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-07-09 05:42:33 +03:00
|
|
|
ResizerSelectionListener::NotifySelectionChanged(nsIDOMDocument* aDOMDocument,
|
|
|
|
nsISelection* aSelection,
|
|
|
|
int16_t aReason)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
|
|
|
if ((aReason & (nsISelectionListener::MOUSEDOWN_REASON |
|
|
|
|
nsISelectionListener::KEYPRESS_REASON |
|
2016-10-24 05:27:45 +03:00
|
|
|
nsISelectionListener::SELECTALL_REASON)) && aSelection) {
|
2003-02-24 13:18:18 +03:00
|
|
|
// the selection changed and we need to check if we have to
|
|
|
|
// hide and/or redisplay resizing handles
|
2003-10-10 02:08:59 +04:00
|
|
|
nsCOMPtr<nsIHTMLEditor> editor = do_QueryReferent(mEditor);
|
2016-10-24 05:27:45 +03:00
|
|
|
if (editor) {
|
2003-10-10 02:08:59 +04:00
|
|
|
editor->CheckSelectionStateForAnonymousButtons(aSelection);
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
2003-02-24 13:18:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-07-09 05:42:33 +03:00
|
|
|
/******************************************************************************
|
2016-07-07 13:49:07 +03:00
|
|
|
* mozilla::ResizerMouseMotionListener
|
2016-07-09 05:42:33 +03:00
|
|
|
******************************************************************************/
|
2003-02-24 13:18:18 +03:00
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(ResizerMouseMotionListener, nsIDOMEventListener)
|
2003-02-24 13:18:18 +03:00
|
|
|
|
2016-07-09 05:42:33 +03:00
|
|
|
ResizerMouseMotionListener::ResizerMouseMotionListener(nsIHTMLEditor* aEditor)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
2003-10-10 02:08:59 +04:00
|
|
|
mEditor = do_GetWeakReference(aEditor);
|
2003-02-24 13:18:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-06-28 03:34:54 +04:00
|
|
|
ResizerMouseMotionListener::HandleEvent(nsIDOMEvent* aMouseEvent)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMMouseEvent> mouseEvent ( do_QueryInterface(aMouseEvent) );
|
|
|
|
if (!mouseEvent) {
|
|
|
|
//non-ui event passed in. bad things.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-09-03 17:58:00 +04:00
|
|
|
// Don't do anything special if not an HTML object resizer editor
|
2003-10-10 02:08:59 +04:00
|
|
|
nsCOMPtr<nsIHTMLObjectResizer> objectResizer = do_QueryReferent(mEditor);
|
2016-10-24 05:27:45 +03:00
|
|
|
if (objectResizer) {
|
2003-02-24 13:18:18 +03:00
|
|
|
// check if we have to redisplay a resizing shadow
|
|
|
|
objectResizer->MouseMove(aMouseEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-07-09 05:42:33 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::HTMLEditor
|
|
|
|
******************************************************************************/
|
2003-02-24 13:18:18 +03:00
|
|
|
|
2015-04-19 15:28:50 +03:00
|
|
|
already_AddRefed<Element>
|
2016-07-09 05:42:33 +03:00
|
|
|
HTMLEditor::CreateResizer(int16_t aLocation,
|
|
|
|
nsIDOMNode* aParentNode)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
2016-11-24 12:07:47 +03:00
|
|
|
RefPtr<Element> ret =
|
|
|
|
CreateAnonymousElement(nsGkAtoms::span,
|
|
|
|
aParentNode,
|
|
|
|
NS_LITERAL_STRING("mozResizer"),
|
|
|
|
false);
|
|
|
|
if (NS_WARN_IF(!ret)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2003-02-24 13:18:18 +03:00
|
|
|
|
|
|
|
// add the mouse listener so we can detect a click on a resizer
|
2016-11-24 12:07:47 +03:00
|
|
|
nsCOMPtr<nsIDOMEventTarget> evtTarget = do_QueryInterface(ret);
|
2010-03-06 07:01:28 +03:00
|
|
|
evtTarget->AddEventListener(NS_LITERAL_STRING("mousedown"), mEventListener,
|
2011-10-17 18:59:28 +04:00
|
|
|
true);
|
2003-02-24 13:18:18 +03:00
|
|
|
|
|
|
|
nsAutoString locationStr;
|
|
|
|
switch (aLocation) {
|
|
|
|
case nsIHTMLObjectResizer::eTopLeft:
|
|
|
|
locationStr = kTopLeft;
|
|
|
|
break;
|
|
|
|
case nsIHTMLObjectResizer::eTop:
|
|
|
|
locationStr = kTop;
|
|
|
|
break;
|
|
|
|
case nsIHTMLObjectResizer::eTopRight:
|
|
|
|
locationStr = kTopRight;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIHTMLObjectResizer::eLeft:
|
|
|
|
locationStr = kLeft;
|
|
|
|
break;
|
|
|
|
case nsIHTMLObjectResizer::eRight:
|
|
|
|
locationStr = kRight;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIHTMLObjectResizer::eBottomLeft:
|
|
|
|
locationStr = kBottomLeft;
|
|
|
|
break;
|
|
|
|
case nsIHTMLObjectResizer::eBottom:
|
|
|
|
locationStr = kBottom;
|
|
|
|
break;
|
|
|
|
case nsIHTMLObjectResizer::eBottomRight:
|
|
|
|
locationStr = kBottomRight;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-11-24 12:07:47 +03:00
|
|
|
nsresult rv =
|
|
|
|
ret->SetAttr(kNameSpaceID_None, nsGkAtoms::anonlocation, locationStr, true);
|
2016-10-19 12:09:33 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
2015-04-19 15:28:50 +03:00
|
|
|
return ret.forget();
|
2003-02-24 13:18:18 +03:00
|
|
|
}
|
|
|
|
|
2015-04-19 15:28:50 +03:00
|
|
|
already_AddRefed<Element>
|
2016-07-09 05:42:33 +03:00
|
|
|
HTMLEditor::CreateShadow(nsIDOMNode* aParentNode,
|
|
|
|
nsIDOMElement* aOriginalObject)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
|
|
|
// let's create an image through the element factory
|
2016-11-24 12:07:47 +03:00
|
|
|
nsCOMPtr<nsIAtom> name;
|
2016-07-07 08:01:12 +03:00
|
|
|
if (HTMLEditUtils::IsImage(aOriginalObject)) {
|
2016-11-24 12:07:47 +03:00
|
|
|
name = nsGkAtoms::img;
|
2016-07-07 08:01:12 +03:00
|
|
|
} else {
|
2016-11-24 12:07:47 +03:00
|
|
|
name = nsGkAtoms::span;
|
2016-07-07 08:01:12 +03:00
|
|
|
}
|
2016-11-24 12:07:47 +03:00
|
|
|
RefPtr<Element> ret =
|
|
|
|
CreateAnonymousElement(name, aParentNode,
|
|
|
|
NS_LITERAL_STRING("mozResizingShadow"), true);
|
2015-04-19 15:28:50 +03:00
|
|
|
return ret.forget();
|
2003-02-24 13:18:18 +03:00
|
|
|
}
|
|
|
|
|
2015-04-19 15:28:50 +03:00
|
|
|
already_AddRefed<Element>
|
2016-07-09 05:42:33 +03:00
|
|
|
HTMLEditor::CreateResizingInfo(nsIDOMNode* aParentNode)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
2003-06-25 12:50:48 +04:00
|
|
|
// let's create an info box through the element factory
|
2016-11-24 12:07:47 +03:00
|
|
|
RefPtr<Element> ret =
|
|
|
|
CreateAnonymousElement(nsGkAtoms::span, aParentNode,
|
|
|
|
NS_LITERAL_STRING("mozResizingInfo"), true);
|
2015-04-19 15:28:50 +03:00
|
|
|
return ret.forget();
|
2003-02-24 13:18:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2016-07-09 05:42:33 +03:00
|
|
|
HTMLEditor::SetAllResizersPosition()
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
2010-06-18 00:40:48 +04:00
|
|
|
NS_ENSURE_TRUE(mTopLeftHandle, NS_ERROR_FAILURE);
|
2007-01-11 01:44:29 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t x = mResizedObjectX;
|
|
|
|
int32_t y = mResizedObjectY;
|
|
|
|
int32_t w = mResizedObjectWidth;
|
|
|
|
int32_t h = mResizedObjectHeight;
|
2003-02-24 13:18:18 +03:00
|
|
|
|
|
|
|
// now let's place all the resizers around the image
|
|
|
|
|
2003-06-25 12:50:48 +04:00
|
|
|
// get the size of resizers
|
|
|
|
nsAutoString value;
|
|
|
|
float resizerWidth, resizerHeight;
|
|
|
|
nsCOMPtr<nsIAtom> dummyUnit;
|
2016-07-07 12:35:13 +03:00
|
|
|
mCSSEditUtils->GetComputedProperty(*mTopLeftHandle, *nsGkAtoms::width,
|
2015-04-19 15:28:50 +03:00
|
|
|
value);
|
2016-07-07 12:35:13 +03:00
|
|
|
mCSSEditUtils->ParseLength(value, &resizerWidth, getter_AddRefs(dummyUnit));
|
|
|
|
mCSSEditUtils->GetComputedProperty(*mTopLeftHandle, *nsGkAtoms::height,
|
2015-04-19 15:28:50 +03:00
|
|
|
value);
|
2016-07-07 12:35:13 +03:00
|
|
|
mCSSEditUtils->ParseLength(value, &resizerHeight, getter_AddRefs(dummyUnit));
|
2003-02-24 13:18:18 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t rw = (int32_t)((resizerWidth + 1) / 2);
|
|
|
|
int32_t rh = (int32_t)((resizerHeight+ 1) / 2);
|
2003-06-25 12:50:48 +04:00
|
|
|
|
2016-11-24 09:58:01 +03:00
|
|
|
SetAnonymousElementPosition(x-rw, y-rh, mTopLeftHandle);
|
|
|
|
SetAnonymousElementPosition(x+w/2-rw, y-rh, mTopHandle);
|
|
|
|
SetAnonymousElementPosition(x+w-rw-1, y-rh, mTopRightHandle);
|
2003-06-25 12:50:48 +04:00
|
|
|
|
2016-11-24 09:58:01 +03:00
|
|
|
SetAnonymousElementPosition(x-rw, y+h/2-rh, mLeftHandle);
|
|
|
|
SetAnonymousElementPosition(x+w-rw-1, y+h/2-rh, mRightHandle);
|
2003-06-25 12:50:48 +04:00
|
|
|
|
2016-11-24 09:58:01 +03:00
|
|
|
SetAnonymousElementPosition(x-rw, y+h-rh-1, mBottomLeftHandle);
|
|
|
|
SetAnonymousElementPosition(x+w/2-rw, y+h-rh-1, mBottomHandle);
|
|
|
|
SetAnonymousElementPosition(x+w-rw-1, y+h-rh-1, mBottomRightHandle);
|
2003-02-24 13:18:18 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-07-09 05:42:33 +03:00
|
|
|
HTMLEditor::RefreshResizers()
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
2003-06-25 12:50:48 +04:00
|
|
|
// nothing to do if resizers are not displayed...
|
2010-06-18 00:40:48 +04:00
|
|
|
NS_ENSURE_TRUE(mResizedObject, NS_OK);
|
2003-06-25 12:50:48 +04:00
|
|
|
|
2016-10-19 12:09:33 +03:00
|
|
|
nsresult rv =
|
|
|
|
GetPositionAndDimensions(
|
|
|
|
static_cast<nsIDOMElement*>(GetAsDOMNode(mResizedObject)),
|
|
|
|
mResizedObjectX,
|
|
|
|
mResizedObjectY,
|
|
|
|
mResizedObjectWidth,
|
|
|
|
mResizedObjectHeight,
|
|
|
|
mResizedObjectBorderLeft,
|
|
|
|
mResizedObjectBorderTop,
|
|
|
|
mResizedObjectMarginLeft,
|
|
|
|
mResizedObjectMarginTop);
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = SetAllResizersPosition();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-06-25 12:50:48 +04:00
|
|
|
return SetShadowPosition(mResizingShadow, mResizedObject,
|
|
|
|
mResizedObjectX, mResizedObjectY);
|
2003-02-24 13:18:18 +03:00
|
|
|
}
|
|
|
|
|
2015-05-28 18:58:42 +03:00
|
|
|
NS_IMETHODIMP
|
2016-07-09 05:42:33 +03:00
|
|
|
HTMLEditor::ShowResizers(nsIDOMElement* aResizedElement)
|
2009-04-14 07:05:34 +04:00
|
|
|
{
|
2016-10-19 12:09:33 +03:00
|
|
|
nsresult rv = ShowResizersInner(aResizedElement);
|
|
|
|
if (NS_FAILED(rv)) {
|
2009-04-14 07:05:34 +04:00
|
|
|
HideResizers();
|
2016-10-19 12:09:33 +03:00
|
|
|
}
|
|
|
|
return rv;
|
2009-04-14 07:05:34 +04:00
|
|
|
}
|
|
|
|
|
2015-05-28 18:58:42 +03:00
|
|
|
nsresult
|
2016-07-09 05:42:33 +03:00
|
|
|
HTMLEditor::ShowResizersInner(nsIDOMElement* aResizedElement)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
2003-06-25 12:50:48 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aResizedElement);
|
2009-04-14 07:05:34 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> parentNode;
|
2016-10-19 12:09:33 +03:00
|
|
|
nsresult rv = aResizedElement->GetParentNode(getter_AddRefs(parentNode));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-04-14 00:22:31 +04:00
|
|
|
|
|
|
|
if (mResizedObject) {
|
|
|
|
NS_ERROR("call HideResizers first");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2015-04-19 15:28:50 +03:00
|
|
|
mResizedObject = do_QueryInterface(aResizedElement);
|
|
|
|
NS_ENSURE_STATE(mResizedObject);
|
2003-02-24 13:18:18 +03:00
|
|
|
|
2008-01-22 10:39:06 +03:00
|
|
|
// The resizers and the shadow will be anonymous siblings of the element.
|
2015-04-19 15:28:50 +03:00
|
|
|
mTopLeftHandle = CreateResizer(nsIHTMLObjectResizer::eTopLeft, parentNode);
|
|
|
|
NS_ENSURE_TRUE(mTopLeftHandle, NS_ERROR_FAILURE);
|
|
|
|
mTopHandle = CreateResizer(nsIHTMLObjectResizer::eTop, parentNode);
|
|
|
|
NS_ENSURE_TRUE(mTopHandle, NS_ERROR_FAILURE);
|
|
|
|
mTopRightHandle = CreateResizer(nsIHTMLObjectResizer::eTopRight, parentNode);
|
|
|
|
NS_ENSURE_TRUE(mTopRightHandle, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
mLeftHandle = CreateResizer(nsIHTMLObjectResizer::eLeft, parentNode);
|
|
|
|
NS_ENSURE_TRUE(mLeftHandle, NS_ERROR_FAILURE);
|
|
|
|
mRightHandle = CreateResizer(nsIHTMLObjectResizer::eRight, parentNode);
|
|
|
|
NS_ENSURE_TRUE(mRightHandle, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
mBottomLeftHandle = CreateResizer(nsIHTMLObjectResizer::eBottomLeft, parentNode);
|
|
|
|
NS_ENSURE_TRUE(mBottomLeftHandle, NS_ERROR_FAILURE);
|
|
|
|
mBottomHandle = CreateResizer(nsIHTMLObjectResizer::eBottom, parentNode);
|
|
|
|
NS_ENSURE_TRUE(mBottomHandle, NS_ERROR_FAILURE);
|
|
|
|
mBottomRightHandle = CreateResizer(nsIHTMLObjectResizer::eBottomRight, parentNode);
|
|
|
|
NS_ENSURE_TRUE(mBottomRightHandle, NS_ERROR_FAILURE);
|
2003-06-25 12:50:48 +04:00
|
|
|
|
2016-10-19 12:09:33 +03:00
|
|
|
rv = GetPositionAndDimensions(aResizedElement,
|
|
|
|
mResizedObjectX,
|
|
|
|
mResizedObjectY,
|
|
|
|
mResizedObjectWidth,
|
|
|
|
mResizedObjectHeight,
|
|
|
|
mResizedObjectBorderLeft,
|
|
|
|
mResizedObjectBorderTop,
|
|
|
|
mResizedObjectMarginLeft,
|
|
|
|
mResizedObjectMarginTop);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-02-24 13:18:18 +03:00
|
|
|
|
|
|
|
// and let's set their absolute positions in the document
|
2016-10-19 12:09:33 +03:00
|
|
|
rv = SetAllResizersPosition();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-02-24 13:18:18 +03:00
|
|
|
|
|
|
|
// now, let's create the resizing shadow
|
2015-04-19 15:28:50 +03:00
|
|
|
mResizingShadow = CreateShadow(parentNode, aResizedElement);
|
|
|
|
NS_ENSURE_TRUE(mResizingShadow, NS_ERROR_FAILURE);
|
2003-02-24 13:18:18 +03:00
|
|
|
// and set its position
|
2016-10-19 12:09:33 +03:00
|
|
|
rv = SetShadowPosition(mResizingShadow, mResizedObject,
|
|
|
|
mResizedObjectX, mResizedObjectY);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-02-24 13:18:18 +03:00
|
|
|
|
|
|
|
// and then the resizing info tooltip
|
2015-04-19 15:28:50 +03:00
|
|
|
mResizingInfo = CreateResizingInfo(parentNode);
|
|
|
|
NS_ENSURE_TRUE(mResizingInfo, NS_ERROR_FAILURE);
|
2003-02-24 13:18:18 +03:00
|
|
|
|
2005-11-29 02:56:44 +03:00
|
|
|
// and listen to the "resize" event on the window first, get the
|
|
|
|
// window from the document...
|
2012-03-24 12:19:14 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = GetDocument();
|
2010-06-17 23:41:16 +04:00
|
|
|
NS_ENSURE_TRUE(doc, NS_ERROR_NULL_POINTER);
|
2003-02-24 13:18:18 +03:00
|
|
|
|
2005-11-29 02:56:44 +03:00
|
|
|
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(doc->GetWindow());
|
2016-10-24 05:27:45 +03:00
|
|
|
if (!target) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2003-02-24 13:18:18 +03:00
|
|
|
|
2003-06-25 12:50:48 +04:00
|
|
|
mResizeEventListenerP = new DocumentResizeEventListener(this);
|
2016-10-24 05:27:45 +03:00
|
|
|
if (!mResizeEventListenerP) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2016-10-19 12:09:33 +03:00
|
|
|
rv = target->AddEventListener(NS_LITERAL_STRING("resize"),
|
|
|
|
mResizeEventListenerP, false);
|
|
|
|
// XXX Even when it failed to add event listener, should we need to set
|
|
|
|
// _moz_resizing attribute?
|
2003-06-25 12:50:48 +04:00
|
|
|
aResizedElement->SetAttribute(NS_LITERAL_STRING("_moz_resizing"), NS_LITERAL_STRING("true"));
|
2016-10-19 12:09:33 +03:00
|
|
|
return rv;
|
2003-02-24 13:18:18 +03:00
|
|
|
}
|
|
|
|
|
2015-05-28 18:58:42 +03:00
|
|
|
NS_IMETHODIMP
|
2016-07-09 05:42:33 +03:00
|
|
|
HTMLEditor::HideResizers()
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
2010-06-18 00:40:48 +04:00
|
|
|
NS_ENSURE_TRUE(mResizedObject, NS_OK);
|
2003-02-24 13:18:18 +03:00
|
|
|
|
2003-03-25 18:24:08 +03:00
|
|
|
// get the presshell's document observer interface.
|
2011-05-22 16:43:13 +04:00
|
|
|
nsCOMPtr<nsIPresShell> ps = GetPresShell();
|
2010-05-06 05:20:43 +04:00
|
|
|
// We allow the pres shell to be null; when it is, we presume there
|
|
|
|
// are no document observers to notify, but we still want to
|
|
|
|
// UnbindFromTree.
|
2003-03-25 18:24:08 +03:00
|
|
|
|
2009-04-14 07:05:34 +04:00
|
|
|
nsCOMPtr<nsIContent> parentContent;
|
|
|
|
|
|
|
|
if (mTopLeftHandle) {
|
2015-04-19 15:28:50 +03:00
|
|
|
parentContent = mTopLeftHandle->GetParent();
|
2009-04-14 07:05:34 +04:00
|
|
|
}
|
2003-03-25 18:24:08 +03:00
|
|
|
|
2006-06-15 11:31:01 +04:00
|
|
|
NS_NAMED_LITERAL_STRING(mousedown, "mousedown");
|
2008-01-22 10:39:06 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
RemoveListenerAndDeleteRef(mousedown, mEventListener, true,
|
2008-01-22 10:39:06 +03:00
|
|
|
mTopLeftHandle, parentContent, ps);
|
2012-07-30 18:20:58 +04:00
|
|
|
mTopLeftHandle = nullptr;
|
2006-06-15 11:31:01 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
RemoveListenerAndDeleteRef(mousedown, mEventListener, true,
|
2008-01-22 10:39:06 +03:00
|
|
|
mTopHandle, parentContent, ps);
|
2012-07-30 18:20:58 +04:00
|
|
|
mTopHandle = nullptr;
|
2006-06-15 11:31:01 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
RemoveListenerAndDeleteRef(mousedown, mEventListener, true,
|
2008-01-22 10:39:06 +03:00
|
|
|
mTopRightHandle, parentContent, ps);
|
2012-07-30 18:20:58 +04:00
|
|
|
mTopRightHandle = nullptr;
|
2006-06-15 11:31:01 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
RemoveListenerAndDeleteRef(mousedown, mEventListener, true,
|
2008-01-22 10:39:06 +03:00
|
|
|
mLeftHandle, parentContent, ps);
|
2012-07-30 18:20:58 +04:00
|
|
|
mLeftHandle = nullptr;
|
2006-06-15 11:31:01 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
RemoveListenerAndDeleteRef(mousedown, mEventListener, true,
|
2008-01-22 10:39:06 +03:00
|
|
|
mRightHandle, parentContent, ps);
|
2012-07-30 18:20:58 +04:00
|
|
|
mRightHandle = nullptr;
|
2006-06-15 11:31:01 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
RemoveListenerAndDeleteRef(mousedown, mEventListener, true,
|
2008-01-22 10:39:06 +03:00
|
|
|
mBottomLeftHandle, parentContent, ps);
|
2012-07-30 18:20:58 +04:00
|
|
|
mBottomLeftHandle = nullptr;
|
2006-06-15 11:31:01 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
RemoveListenerAndDeleteRef(mousedown, mEventListener, true,
|
2008-01-22 10:39:06 +03:00
|
|
|
mBottomHandle, parentContent, ps);
|
2012-07-30 18:20:58 +04:00
|
|
|
mBottomHandle = nullptr;
|
2006-06-15 11:31:01 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
RemoveListenerAndDeleteRef(mousedown, mEventListener, true,
|
2008-01-22 10:39:06 +03:00
|
|
|
mBottomRightHandle, parentContent, ps);
|
2012-07-30 18:20:58 +04:00
|
|
|
mBottomRightHandle = nullptr;
|
2006-06-15 11:31:01 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
RemoveListenerAndDeleteRef(mousedown, mEventListener, true,
|
2008-01-22 10:39:06 +03:00
|
|
|
mResizingShadow, parentContent, ps);
|
2012-07-30 18:20:58 +04:00
|
|
|
mResizingShadow = nullptr;
|
2006-06-15 11:31:01 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
RemoveListenerAndDeleteRef(mousedown, mEventListener, true,
|
2008-01-22 10:39:06 +03:00
|
|
|
mResizingInfo, parentContent, ps);
|
2012-07-30 18:20:58 +04:00
|
|
|
mResizingInfo = nullptr;
|
2003-02-24 13:18:18 +03:00
|
|
|
|
2008-04-14 00:22:31 +04:00
|
|
|
if (mActivatedHandle) {
|
2015-04-19 15:28:50 +03:00
|
|
|
mActivatedHandle->UnsetAttr(kNameSpaceID_None, nsGkAtoms::_moz_activated,
|
|
|
|
true);
|
2012-07-30 18:20:58 +04:00
|
|
|
mActivatedHandle = nullptr;
|
2008-04-14 00:22:31 +04:00
|
|
|
}
|
|
|
|
|
2003-02-24 13:18:18 +03:00
|
|
|
// don't forget to remove the listeners !
|
|
|
|
|
2011-06-24 06:18:01 +04:00
|
|
|
nsCOMPtr<nsIDOMEventTarget> target = GetDOMEventTarget();
|
2003-03-25 18:24:08 +03:00
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
if (target && mMouseMotionListenerP) {
|
2016-10-19 12:09:33 +03:00
|
|
|
DebugOnly<nsresult> rv =
|
|
|
|
target->RemoveEventListener(NS_LITERAL_STRING("mousemove"),
|
|
|
|
mMouseMotionListenerP, true);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to remove mouse motion listener");
|
2003-02-24 13:18:18 +03:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
mMouseMotionListenerP = nullptr;
|
2003-02-24 13:18:18 +03:00
|
|
|
|
2012-03-24 12:19:14 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = GetDocument();
|
2016-10-24 05:27:45 +03:00
|
|
|
if (!doc) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2007-05-14 13:11:38 +04:00
|
|
|
target = do_QueryInterface(doc->GetWindow());
|
2016-10-24 05:27:45 +03:00
|
|
|
if (!target) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2003-02-24 13:18:18 +03:00
|
|
|
|
2005-11-29 02:56:44 +03:00
|
|
|
if (mResizeEventListenerP) {
|
2016-10-19 12:09:33 +03:00
|
|
|
DebugOnly<nsresult> rv =
|
|
|
|
target->RemoveEventListener(NS_LITERAL_STRING("resize"),
|
|
|
|
mResizeEventListenerP, false);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to remove resize event listener");
|
2003-03-25 18:24:08 +03:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
mResizeEventListenerP = nullptr;
|
2003-02-24 13:18:18 +03:00
|
|
|
|
2015-04-19 15:28:50 +03:00
|
|
|
mResizedObject->UnsetAttr(kNameSpaceID_None, nsGkAtoms::_moz_resizing, true);
|
2012-07-30 18:20:58 +04:00
|
|
|
mResizedObject = nullptr;
|
2003-02-24 13:18:18 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-07-09 05:42:33 +03:00
|
|
|
HTMLEditor::HideShadowAndInfo()
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
2016-10-24 05:27:45 +03:00
|
|
|
if (mResizingShadow) {
|
2015-04-19 15:28:50 +03:00
|
|
|
mResizingShadow->SetAttr(kNameSpaceID_None, nsGkAtoms::_class,
|
|
|
|
NS_LITERAL_STRING("hidden"), true);
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
|
|
|
if (mResizingInfo) {
|
2015-04-19 15:28:50 +03:00
|
|
|
mResizingInfo->SetAttr(kNameSpaceID_None, nsGkAtoms::_class,
|
|
|
|
NS_LITERAL_STRING("hidden"), true);
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
2003-02-24 13:18:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2016-07-09 05:42:33 +03:00
|
|
|
HTMLEditor::StartResizing(nsIDOMElement* aHandle)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsResizing = true;
|
2015-04-19 15:28:50 +03:00
|
|
|
mActivatedHandle = do_QueryInterface(aHandle);
|
|
|
|
NS_ENSURE_STATE(mActivatedHandle || !aHandle);
|
|
|
|
mActivatedHandle->SetAttr(kNameSpaceID_None, nsGkAtoms::_moz_activated,
|
|
|
|
NS_LITERAL_STRING("true"), true);
|
2003-06-25 12:50:48 +04:00
|
|
|
|
|
|
|
// do we want to preserve ratio or not?
|
2016-07-07 08:01:12 +03:00
|
|
|
bool preserveRatio = HTMLEditUtils::IsImage(mResizedObject) &&
|
2011-09-29 10:19:26 +04:00
|
|
|
Preferences::GetBool("editor.resizing.preserve_ratio", true);
|
2003-02-24 13:18:18 +03:00
|
|
|
|
|
|
|
// the way we change the position/size of the shadow depends on
|
|
|
|
// the handle
|
|
|
|
nsAutoString locationStr;
|
|
|
|
aHandle->GetAttribute(NS_LITERAL_STRING("anonlocation"), locationStr);
|
2003-06-25 12:50:48 +04:00
|
|
|
if (locationStr.Equals(kTopLeft)) {
|
|
|
|
SetResizeIncrements(1, 1, -1, -1, preserveRatio);
|
2016-10-24 05:27:45 +03:00
|
|
|
} else if (locationStr.Equals(kTop)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
SetResizeIncrements(0, 1, 0, -1, false);
|
2016-10-24 05:27:45 +03:00
|
|
|
} else if (locationStr.Equals(kTopRight)) {
|
2003-06-25 12:50:48 +04:00
|
|
|
SetResizeIncrements(0, 1, 1, -1, preserveRatio);
|
2016-10-24 05:27:45 +03:00
|
|
|
} else if (locationStr.Equals(kLeft)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
SetResizeIncrements(1, 0, -1, 0, false);
|
2016-10-24 05:27:45 +03:00
|
|
|
} else if (locationStr.Equals(kRight)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
SetResizeIncrements(0, 0, 1, 0, false);
|
2016-10-24 05:27:45 +03:00
|
|
|
} else if (locationStr.Equals(kBottomLeft)) {
|
2003-06-25 12:50:48 +04:00
|
|
|
SetResizeIncrements(1, 0, -1, 1, preserveRatio);
|
2016-10-24 05:27:45 +03:00
|
|
|
} else if (locationStr.Equals(kBottom)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
SetResizeIncrements(0, 0, 0, 1, false);
|
2016-10-24 05:27:45 +03:00
|
|
|
} else if (locationStr.Equals(kBottomRight)) {
|
2003-06-25 12:50:48 +04:00
|
|
|
SetResizeIncrements(0, 0, 1, 1, preserveRatio);
|
|
|
|
}
|
2003-02-24 13:18:18 +03:00
|
|
|
|
|
|
|
// make the shadow appear
|
2015-04-19 15:28:50 +03:00
|
|
|
mResizingShadow->UnsetAttr(kNameSpaceID_None, nsGkAtoms::_class, true);
|
2003-02-24 13:18:18 +03:00
|
|
|
|
|
|
|
// position it
|
2016-07-07 12:35:13 +03:00
|
|
|
mCSSEditUtils->SetCSSPropertyPixels(*mResizingShadow, *nsGkAtoms::width,
|
2003-09-03 17:58:00 +04:00
|
|
|
mResizedObjectWidth);
|
2016-07-07 12:35:13 +03:00
|
|
|
mCSSEditUtils->SetCSSPropertyPixels(*mResizingShadow, *nsGkAtoms::height,
|
2003-09-03 17:58:00 +04:00
|
|
|
mResizedObjectHeight);
|
2003-02-24 13:18:18 +03:00
|
|
|
|
2003-06-25 12:50:48 +04:00
|
|
|
// add a mouse move listener to the editor
|
2011-06-17 04:59:29 +04:00
|
|
|
nsresult result = NS_OK;
|
2003-06-25 12:50:48 +04:00
|
|
|
if (!mMouseMotionListenerP) {
|
2003-04-10 01:10:58 +04:00
|
|
|
mMouseMotionListenerP = new ResizerMouseMotionListener(this);
|
2005-03-24 22:00:01 +03:00
|
|
|
if (!mMouseMotionListenerP) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2003-04-10 01:10:58 +04:00
|
|
|
}
|
2005-03-24 22:00:01 +03:00
|
|
|
|
2011-06-24 06:18:01 +04:00
|
|
|
nsCOMPtr<nsIDOMEventTarget> target = GetDOMEventTarget();
|
2007-05-14 13:11:38 +04:00
|
|
|
NS_ENSURE_TRUE(target, NS_ERROR_FAILURE);
|
2005-03-24 22:00:01 +03:00
|
|
|
|
2007-05-14 13:11:38 +04:00
|
|
|
result = target->AddEventListener(NS_LITERAL_STRING("mousemove"),
|
2011-10-17 18:59:28 +04:00
|
|
|
mMouseMotionListenerP, true);
|
2005-03-24 22:00:01 +03:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(result),
|
|
|
|
"failed to register mouse motion listener");
|
2003-02-24 13:18:18 +03:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-05-28 18:58:42 +03:00
|
|
|
NS_IMETHODIMP
|
2016-07-09 05:42:33 +03:00
|
|
|
HTMLEditor::MouseDown(int32_t aClientX,
|
|
|
|
int32_t aClientY,
|
|
|
|
nsIDOMElement* aTarget,
|
|
|
|
nsIDOMEvent* aEvent)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool anonElement = false;
|
2003-02-24 13:18:18 +03:00
|
|
|
if (aTarget && NS_SUCCEEDED(aTarget->HasAttribute(NS_LITERAL_STRING("_moz_anonclass"), &anonElement)))
|
|
|
|
// we caught a click on an anonymous element
|
|
|
|
if (anonElement) {
|
|
|
|
nsAutoString anonclass;
|
2016-10-19 12:09:33 +03:00
|
|
|
nsresult rv =
|
|
|
|
aTarget->GetAttribute(NS_LITERAL_STRING("_moz_anonclass"), anonclass);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2004-05-23 02:15:22 +04:00
|
|
|
if (anonclass.EqualsLiteral("mozResizer")) {
|
2003-02-24 13:18:18 +03:00
|
|
|
// and that element is a resizer, let's start resizing!
|
2008-04-23 15:53:29 +04:00
|
|
|
aEvent->PreventDefault();
|
|
|
|
|
2003-02-24 13:18:18 +03:00
|
|
|
mOriginalX = aClientX;
|
|
|
|
mOriginalY = aClientY;
|
2003-06-25 12:50:48 +04:00
|
|
|
return StartResizing(aTarget);
|
|
|
|
}
|
2004-05-23 02:15:22 +04:00
|
|
|
if (anonclass.EqualsLiteral("mozGrabber")) {
|
2003-06-25 12:50:48 +04:00
|
|
|
// and that element is a grabber, let's start moving the element!
|
|
|
|
mOriginalX = aClientX;
|
|
|
|
mOriginalY = aClientY;
|
|
|
|
return GrabberClicked();
|
2003-02-24 13:18:18 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-05-28 18:58:42 +03:00
|
|
|
NS_IMETHODIMP
|
2016-07-09 05:42:33 +03:00
|
|
|
HTMLEditor::MouseUp(int32_t aClientX,
|
|
|
|
int32_t aClientY,
|
|
|
|
nsIDOMElement* aTarget)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
|
|
|
if (mIsResizing) {
|
|
|
|
// we are resizing and release the mouse button, so let's
|
|
|
|
// end the resizing process
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsResizing = false;
|
2003-02-24 13:18:18 +03:00
|
|
|
HideShadowAndInfo();
|
|
|
|
SetFinalSize(aClientX, aClientY);
|
2016-10-24 05:27:45 +03:00
|
|
|
} else if (mIsMoving || mGrabberClicked) {
|
2003-06-25 12:50:48 +04:00
|
|
|
if (mIsMoving) {
|
2015-04-19 15:28:50 +03:00
|
|
|
mPositioningShadow->SetAttr(kNameSpaceID_None, nsGkAtoms::_class,
|
|
|
|
NS_LITERAL_STRING("hidden"), true);
|
2003-06-25 12:50:48 +04:00
|
|
|
SetFinalPosition(aClientX, aClientY);
|
|
|
|
}
|
|
|
|
if (mGrabberClicked) {
|
|
|
|
EndMoving();
|
|
|
|
}
|
|
|
|
}
|
2003-02-24 13:18:18 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-07-09 05:42:33 +03:00
|
|
|
HTMLEditor::SetResizeIncrements(int32_t aX,
|
|
|
|
int32_t aY,
|
|
|
|
int32_t aW,
|
|
|
|
int32_t aH,
|
|
|
|
bool aPreserveRatio)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
|
|
|
mXIncrementFactor = aX;
|
|
|
|
mYIncrementFactor = aY;
|
|
|
|
mWidthIncrementFactor = aW;
|
|
|
|
mHeightIncrementFactor = aH;
|
|
|
|
mPreserveRatio = aPreserveRatio;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2016-07-09 05:42:33 +03:00
|
|
|
HTMLEditor::SetResizingInfoPosition(int32_t aX,
|
|
|
|
int32_t aY,
|
|
|
|
int32_t aW,
|
|
|
|
int32_t aH)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
2008-01-22 10:39:06 +03:00
|
|
|
// Determine the position of the resizing info box based upon the new
|
|
|
|
// position and size of the element (aX, aY, aW, aH), and which
|
|
|
|
// resizer is the "activated handle". For example, place the resizing
|
|
|
|
// info box at the bottom-right corner of the new element, if the element
|
|
|
|
// is being resized by the bottom-right resizer.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t infoXPosition;
|
|
|
|
int32_t infoYPosition;
|
2008-01-22 10:39:06 +03:00
|
|
|
|
|
|
|
if (mActivatedHandle == mTopLeftHandle ||
|
|
|
|
mActivatedHandle == mLeftHandle ||
|
2016-10-24 05:27:45 +03:00
|
|
|
mActivatedHandle == mBottomLeftHandle) {
|
2008-01-22 10:39:06 +03:00
|
|
|
infoXPosition = aX;
|
2016-10-24 05:27:45 +03:00
|
|
|
} else if (mActivatedHandle == mTopHandle ||
|
|
|
|
mActivatedHandle == mBottomHandle) {
|
2008-01-22 10:39:06 +03:00
|
|
|
infoXPosition = aX + (aW / 2);
|
2016-10-24 05:27:45 +03:00
|
|
|
} else {
|
2008-01-22 10:39:06 +03:00
|
|
|
// should only occur when mActivatedHandle is one of the 3 right-side
|
|
|
|
// handles, but this is a reasonable default if it isn't any of them (?)
|
|
|
|
infoXPosition = aX + aW;
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
2008-01-22 10:39:06 +03:00
|
|
|
|
|
|
|
if (mActivatedHandle == mTopLeftHandle ||
|
|
|
|
mActivatedHandle == mTopHandle ||
|
2016-10-24 05:27:45 +03:00
|
|
|
mActivatedHandle == mTopRightHandle) {
|
2008-01-22 10:39:06 +03:00
|
|
|
infoYPosition = aY;
|
2016-10-24 05:27:45 +03:00
|
|
|
} else if (mActivatedHandle == mLeftHandle ||
|
|
|
|
mActivatedHandle == mRightHandle) {
|
2008-01-22 10:39:06 +03:00
|
|
|
infoYPosition = aY + (aH / 2);
|
2016-10-24 05:27:45 +03:00
|
|
|
} else {
|
2008-01-22 10:39:06 +03:00
|
|
|
// should only occur when mActivatedHandle is one of the 3 bottom-side
|
|
|
|
// handles, but this is a reasonable default if it isn't any of them (?)
|
|
|
|
infoYPosition = aY + aH;
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
2008-01-22 10:39:06 +03:00
|
|
|
|
|
|
|
// Offset info box by 20 so it's not directly under the mouse cursor.
|
|
|
|
const int mouseCursorOffset = 20;
|
2016-07-07 12:35:13 +03:00
|
|
|
mCSSEditUtils->SetCSSPropertyPixels(*mResizingInfo, *nsGkAtoms::left,
|
2008-01-22 10:39:06 +03:00
|
|
|
infoXPosition + mouseCursorOffset);
|
2016-07-07 12:35:13 +03:00
|
|
|
mCSSEditUtils->SetCSSPropertyPixels(*mResizingInfo, *nsGkAtoms::top,
|
2008-01-22 10:39:06 +03:00
|
|
|
infoYPosition + mouseCursorOffset);
|
2003-02-24 13:18:18 +03:00
|
|
|
|
2015-04-19 15:28:50 +03:00
|
|
|
nsCOMPtr<nsIContent> textInfo = mResizingInfo->GetFirstChild();
|
2016-10-19 12:09:33 +03:00
|
|
|
ErrorResult erv;
|
2003-02-24 13:18:18 +03:00
|
|
|
if (textInfo) {
|
2016-10-19 12:09:33 +03:00
|
|
|
mResizingInfo->RemoveChild(*textInfo, erv);
|
|
|
|
NS_ENSURE_TRUE(!erv.Failed(), erv.StealNSResult());
|
2012-07-30 18:20:58 +04:00
|
|
|
textInfo = nullptr;
|
2003-02-24 13:18:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString widthStr, heightStr, diffWidthStr, diffHeightStr;
|
|
|
|
widthStr.AppendInt(aW);
|
|
|
|
heightStr.AppendInt(aH);
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t diffWidth = aW - mResizedObjectWidth;
|
|
|
|
int32_t diffHeight = aH - mResizedObjectHeight;
|
2016-10-24 05:27:45 +03:00
|
|
|
if (diffWidth > 0) {
|
2014-05-26 22:55:08 +04:00
|
|
|
diffWidthStr.Assign('+');
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
|
|
|
if (diffHeight > 0) {
|
2014-05-26 22:55:08 +04:00
|
|
|
diffHeightStr.Assign('+');
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
2003-02-24 13:18:18 +03:00
|
|
|
diffWidthStr.AppendInt(diffWidth);
|
|
|
|
diffHeightStr.AppendInt(diffHeight);
|
|
|
|
|
|
|
|
nsAutoString info(widthStr + NS_LITERAL_STRING(" x ") + heightStr +
|
|
|
|
NS_LITERAL_STRING(" (") + diffWidthStr +
|
|
|
|
NS_LITERAL_STRING(", ") + diffHeightStr +
|
|
|
|
NS_LITERAL_STRING(")"));
|
|
|
|
|
2017-05-29 05:28:21 +03:00
|
|
|
nsCOMPtr<nsIDocument> doc = GetDocument();
|
|
|
|
textInfo = doc->CreateTextNode(info);
|
|
|
|
if (NS_WARN_IF(!textInfo)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2016-10-19 12:09:33 +03:00
|
|
|
mResizingInfo->AppendChild(*textInfo, erv);
|
2017-05-29 05:28:21 +03:00
|
|
|
if (NS_WARN_IF(erv.Failed())) {
|
|
|
|
return erv.StealNSResult();
|
|
|
|
}
|
2003-02-24 13:18:18 +03:00
|
|
|
|
2016-10-19 12:09:33 +03:00
|
|
|
return mResizingInfo->UnsetAttr(kNameSpaceID_None, nsGkAtoms::_class, true);
|
2003-02-24 13:18:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2016-07-09 05:42:33 +03:00
|
|
|
HTMLEditor::SetShadowPosition(Element* aShadow,
|
|
|
|
Element* aOriginalObject,
|
|
|
|
int32_t aOriginalObjectX,
|
|
|
|
int32_t aOriginalObjectY)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
2016-11-24 09:58:01 +03:00
|
|
|
SetAnonymousElementPosition(aOriginalObjectX, aOriginalObjectY, aShadow);
|
2003-02-24 13:18:18 +03:00
|
|
|
|
2016-07-07 08:01:12 +03:00
|
|
|
if (HTMLEditUtils::IsImage(aOriginalObject)) {
|
2003-02-24 13:18:18 +03:00
|
|
|
nsAutoString imageSource;
|
2015-04-19 15:28:50 +03:00
|
|
|
aOriginalObject->GetAttr(kNameSpaceID_None, nsGkAtoms::src, imageSource);
|
2016-10-19 12:09:33 +03:00
|
|
|
nsresult rv = aShadow->SetAttr(kNameSpaceID_None, nsGkAtoms::src,
|
|
|
|
imageSource, true);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-02-24 13:18:18 +03:00
|
|
|
}
|
2003-06-25 12:50:48 +04:00
|
|
|
return NS_OK;
|
2003-02-24 13:18:18 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
2016-07-09 05:42:33 +03:00
|
|
|
HTMLEditor::GetNewResizingIncrement(int32_t aX,
|
|
|
|
int32_t aY,
|
|
|
|
int32_t aID)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t result = 0;
|
2003-02-24 13:18:18 +03:00
|
|
|
if (!mPreserveRatio) {
|
|
|
|
switch (aID) {
|
|
|
|
case kX:
|
|
|
|
case kWidth:
|
|
|
|
result = aX - mOriginalX;
|
|
|
|
break;
|
|
|
|
case kY:
|
|
|
|
case kHeight:
|
|
|
|
result = aY - mOriginalY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t xi = (aX - mOriginalX) * mWidthIncrementFactor;
|
|
|
|
int32_t yi = (aY - mOriginalY) * mHeightIncrementFactor;
|
2015-05-28 18:58:42 +03:00
|
|
|
float objectSizeRatio =
|
2003-02-24 13:18:18 +03:00
|
|
|
((float)mResizedObjectWidth) / ((float)mResizedObjectHeight);
|
|
|
|
result = (xi > yi) ? xi : yi;
|
|
|
|
switch (aID) {
|
|
|
|
case kX:
|
|
|
|
case kWidth:
|
|
|
|
if (result == yi)
|
2012-08-22 19:56:38 +04:00
|
|
|
result = (int32_t) (((float) result) * objectSizeRatio);
|
|
|
|
result = (int32_t) (((float) result) * mWidthIncrementFactor);
|
2003-02-24 13:18:18 +03:00
|
|
|
break;
|
|
|
|
case kY:
|
|
|
|
case kHeight:
|
|
|
|
if (result == xi)
|
2012-08-22 19:56:38 +04:00
|
|
|
result = (int32_t) (((float) result) / objectSizeRatio);
|
|
|
|
result = (int32_t) (((float) result) * mHeightIncrementFactor);
|
2003-02-24 13:18:18 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
2016-07-09 05:42:33 +03:00
|
|
|
HTMLEditor::GetNewResizingX(int32_t aX,
|
|
|
|
int32_t aY)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t resized = mResizedObjectX +
|
2003-02-24 13:18:18 +03:00
|
|
|
GetNewResizingIncrement(aX, aY, kX) * mXIncrementFactor;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t max = mResizedObjectX + mResizedObjectWidth;
|
2013-01-15 16:22:03 +04:00
|
|
|
return std::min(resized, max);
|
2003-02-24 13:18:18 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
2016-07-09 05:42:33 +03:00
|
|
|
HTMLEditor::GetNewResizingY(int32_t aX,
|
|
|
|
int32_t aY)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t resized = mResizedObjectY +
|
2003-02-24 13:18:18 +03:00
|
|
|
GetNewResizingIncrement(aX, aY, kY) * mYIncrementFactor;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t max = mResizedObjectY + mResizedObjectHeight;
|
2013-01-15 16:22:03 +04:00
|
|
|
return std::min(resized, max);
|
2003-02-24 13:18:18 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
2016-07-09 05:42:33 +03:00
|
|
|
HTMLEditor::GetNewResizingWidth(int32_t aX,
|
|
|
|
int32_t aY)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t resized = mResizedObjectWidth +
|
2003-02-24 13:18:18 +03:00
|
|
|
GetNewResizingIncrement(aX, aY, kWidth) *
|
|
|
|
mWidthIncrementFactor;
|
2013-01-15 16:22:03 +04:00
|
|
|
return std::max(resized, 1);
|
2003-02-24 13:18:18 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
2016-07-09 05:42:33 +03:00
|
|
|
HTMLEditor::GetNewResizingHeight(int32_t aX,
|
|
|
|
int32_t aY)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t resized = mResizedObjectHeight +
|
2003-02-24 13:18:18 +03:00
|
|
|
GetNewResizingIncrement(aX, aY, kHeight) *
|
|
|
|
mHeightIncrementFactor;
|
2013-01-15 16:22:03 +04:00
|
|
|
return std::max(resized, 1);
|
2003-02-24 13:18:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-07-09 05:42:33 +03:00
|
|
|
HTMLEditor::MouseMove(nsIDOMEvent* aMouseEvent)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
2003-06-25 12:50:48 +04:00
|
|
|
NS_NAMED_LITERAL_STRING(leftStr, "left");
|
|
|
|
NS_NAMED_LITERAL_STRING(topStr, "top");
|
|
|
|
|
2003-02-24 13:18:18 +03:00
|
|
|
if (mIsResizing) {
|
|
|
|
// we are resizing and the mouse pointer's position has changed
|
|
|
|
// we have to resdisplay the shadow
|
|
|
|
nsCOMPtr<nsIDOMMouseEvent> mouseEvent ( do_QueryInterface(aMouseEvent) );
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t clientX, clientY;
|
2003-02-24 13:18:18 +03:00
|
|
|
mouseEvent->GetClientX(&clientX);
|
|
|
|
mouseEvent->GetClientY(&clientY);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t newX = GetNewResizingX(clientX, clientY);
|
|
|
|
int32_t newY = GetNewResizingY(clientX, clientY);
|
|
|
|
int32_t newWidth = GetNewResizingWidth(clientX, clientY);
|
|
|
|
int32_t newHeight = GetNewResizingHeight(clientX, clientY);
|
2003-09-03 17:58:00 +04:00
|
|
|
|
2016-07-07 12:35:13 +03:00
|
|
|
mCSSEditUtils->SetCSSPropertyPixels(*mResizingShadow, *nsGkAtoms::left,
|
2008-01-22 10:39:06 +03:00
|
|
|
newX);
|
2016-07-07 12:35:13 +03:00
|
|
|
mCSSEditUtils->SetCSSPropertyPixels(*mResizingShadow, *nsGkAtoms::top,
|
2008-01-22 10:39:06 +03:00
|
|
|
newY);
|
2016-07-07 12:35:13 +03:00
|
|
|
mCSSEditUtils->SetCSSPropertyPixels(*mResizingShadow, *nsGkAtoms::width,
|
2003-09-03 17:58:00 +04:00
|
|
|
newWidth);
|
2016-07-07 12:35:13 +03:00
|
|
|
mCSSEditUtils->SetCSSPropertyPixels(*mResizingShadow, *nsGkAtoms::height,
|
2003-09-03 17:58:00 +04:00
|
|
|
newHeight);
|
2003-06-25 12:50:48 +04:00
|
|
|
|
2008-01-22 10:39:06 +03:00
|
|
|
return SetResizingInfoPosition(newX, newY, newWidth, newHeight);
|
2003-06-25 12:50:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mGrabberClicked) {
|
|
|
|
nsCOMPtr<nsIDOMMouseEvent> mouseEvent ( do_QueryInterface(aMouseEvent) );
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t clientX, clientY;
|
2003-06-25 12:50:48 +04:00
|
|
|
mouseEvent->GetClientX(&clientX);
|
|
|
|
mouseEvent->GetClientY(&clientY);
|
2003-02-24 13:18:18 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t xThreshold =
|
2011-09-09 06:27:12 +04:00
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_DragThresholdX, 1);
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t yThreshold =
|
2011-09-09 06:27:12 +04:00
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_DragThresholdY, 1);
|
2003-06-25 12:50:48 +04:00
|
|
|
|
2013-03-06 03:43:30 +04:00
|
|
|
if (DeprecatedAbs(clientX - mOriginalX) * 2 >= xThreshold ||
|
|
|
|
DeprecatedAbs(clientY - mOriginalY) * 2 >= yThreshold) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mGrabberClicked = false;
|
2012-07-30 18:20:58 +04:00
|
|
|
StartMoving(nullptr);
|
2003-06-25 12:50:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mIsMoving) {
|
|
|
|
nsCOMPtr<nsIDOMMouseEvent> mouseEvent ( do_QueryInterface(aMouseEvent) );
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t clientX, clientY;
|
2003-06-25 12:50:48 +04:00
|
|
|
mouseEvent->GetClientX(&clientX);
|
|
|
|
mouseEvent->GetClientY(&clientY);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t newX = mPositionedObjectX + clientX - mOriginalX;
|
|
|
|
int32_t newY = mPositionedObjectY + clientY - mOriginalY;
|
2003-06-25 12:50:48 +04:00
|
|
|
|
|
|
|
SnapToGrid(newX, newY);
|
|
|
|
|
2016-07-07 12:35:13 +03:00
|
|
|
mCSSEditUtils->SetCSSPropertyPixels(*mPositioningShadow, *nsGkAtoms::left,
|
2015-04-19 15:28:50 +03:00
|
|
|
newX);
|
2016-07-07 12:35:13 +03:00
|
|
|
mCSSEditUtils->SetCSSPropertyPixels(*mPositioningShadow, *nsGkAtoms::top,
|
2015-04-19 15:28:50 +03:00
|
|
|
newY);
|
2003-02-24 13:18:18 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-07-09 05:42:33 +03:00
|
|
|
HTMLEditor::SetFinalSize(int32_t aX,
|
|
|
|
int32_t aY)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
2003-06-25 12:50:48 +04:00
|
|
|
if (!mResizedObject) {
|
|
|
|
// paranoia
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mActivatedHandle) {
|
2015-04-19 15:28:50 +03:00
|
|
|
mActivatedHandle->UnsetAttr(kNameSpaceID_None, nsGkAtoms::_moz_activated, true);
|
2012-07-30 18:20:58 +04:00
|
|
|
mActivatedHandle = nullptr;
|
2003-06-25 12:50:48 +04:00
|
|
|
}
|
2003-04-10 01:10:58 +04:00
|
|
|
|
2003-02-24 13:18:18 +03:00
|
|
|
// we have now to set the new width and height of the resized object
|
|
|
|
// we don't set the x and y position because we don't control that in
|
|
|
|
// a normal HTML layout
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t left = GetNewResizingX(aX, aY);
|
|
|
|
int32_t top = GetNewResizingY(aX, aY);
|
|
|
|
int32_t width = GetNewResizingWidth(aX, aY);
|
|
|
|
int32_t height = GetNewResizingHeight(aX, aY);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool setWidth = !mResizedObjectIsAbsolutelyPositioned || (width != mResizedObjectWidth);
|
|
|
|
bool setHeight = !mResizedObjectIsAbsolutelyPositioned || (height != mResizedObjectHeight);
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t x, y;
|
2003-09-03 17:58:00 +04:00
|
|
|
x = left - ((mResizedObjectIsAbsolutelyPositioned) ? mResizedObjectBorderLeft+mResizedObjectMarginLeft : 0);
|
|
|
|
y = top - ((mResizedObjectIsAbsolutelyPositioned) ? mResizedObjectBorderTop+mResizedObjectMarginTop : 0);
|
2003-02-24 13:18:18 +03:00
|
|
|
|
|
|
|
// we want one transaction only from a user's point of view
|
2016-06-23 12:46:58 +03:00
|
|
|
AutoEditBatch batchIt(this);
|
2003-02-24 13:18:18 +03:00
|
|
|
|
2003-06-25 12:50:48 +04:00
|
|
|
if (mResizedObjectIsAbsolutelyPositioned) {
|
2016-10-24 05:27:45 +03:00
|
|
|
if (setHeight) {
|
2016-12-20 14:53:00 +03:00
|
|
|
mCSSEditUtils->SetCSSPropertyPixels(*mResizedObject, *nsGkAtoms::top, y);
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
|
|
|
if (setWidth) {
|
2016-12-20 14:53:00 +03:00
|
|
|
mCSSEditUtils->SetCSSPropertyPixels(*mResizedObject, *nsGkAtoms::left, x);
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
2003-06-25 12:50:48 +04:00
|
|
|
}
|
2012-02-01 14:54:22 +04:00
|
|
|
if (IsCSSEnabled() || mResizedObjectIsAbsolutelyPositioned) {
|
2015-04-19 15:28:50 +03:00
|
|
|
if (setWidth && mResizedObject->HasAttr(kNameSpaceID_None, nsGkAtoms::width)) {
|
2016-12-20 14:53:00 +03:00
|
|
|
RemoveAttribute(mResizedObject, nsGkAtoms::width);
|
2015-04-19 15:28:50 +03:00
|
|
|
}
|
2003-02-24 13:18:18 +03:00
|
|
|
|
2015-04-19 15:28:50 +03:00
|
|
|
if (setHeight && mResizedObject->HasAttr(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::height)) {
|
2016-12-20 14:53:00 +03:00
|
|
|
RemoveAttribute(mResizedObject, nsGkAtoms::height);
|
2015-04-19 15:28:50 +03:00
|
|
|
}
|
2003-02-24 13:18:18 +03:00
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
if (setWidth) {
|
2016-12-20 14:53:00 +03:00
|
|
|
mCSSEditUtils->SetCSSPropertyPixels(*mResizedObject, *nsGkAtoms::width,
|
2014-08-29 15:43:24 +04:00
|
|
|
width);
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
|
|
|
if (setHeight) {
|
2016-12-20 14:53:00 +03:00
|
|
|
mCSSEditUtils->SetCSSPropertyPixels(*mResizedObject, *nsGkAtoms::height,
|
2014-08-29 15:43:24 +04:00
|
|
|
height);
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
|
|
|
} else {
|
2003-02-24 13:18:18 +03:00
|
|
|
// we use HTML size and remove all equivalent CSS properties
|
|
|
|
|
|
|
|
// we set the CSS width and height to remove it later,
|
|
|
|
// triggering an immediate reflow; otherwise, we have problems
|
|
|
|
// with asynchronous reflow
|
2016-10-24 05:27:45 +03:00
|
|
|
if (setWidth) {
|
2016-12-20 14:53:00 +03:00
|
|
|
mCSSEditUtils->SetCSSPropertyPixels(*mResizedObject, *nsGkAtoms::width,
|
2014-08-29 15:43:24 +04:00
|
|
|
width);
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
|
|
|
if (setHeight) {
|
2016-12-20 14:53:00 +03:00
|
|
|
mCSSEditUtils->SetCSSPropertyPixels(*mResizedObject, *nsGkAtoms::height,
|
2014-08-29 15:43:24 +04:00
|
|
|
height);
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
2003-09-03 17:58:00 +04:00
|
|
|
if (setWidth) {
|
|
|
|
nsAutoString w;
|
|
|
|
w.AppendInt(width);
|
2016-12-20 14:53:00 +03:00
|
|
|
SetAttribute(mResizedObject, nsGkAtoms::width, w);
|
2003-09-03 17:58:00 +04:00
|
|
|
}
|
|
|
|
if (setHeight) {
|
|
|
|
nsAutoString h;
|
|
|
|
h.AppendInt(height);
|
2016-12-20 14:53:00 +03:00
|
|
|
SetAttribute(mResizedObject, nsGkAtoms::height, h);
|
2003-09-03 17:58:00 +04:00
|
|
|
}
|
2003-06-25 12:50:48 +04:00
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
if (setWidth) {
|
2016-12-20 14:53:00 +03:00
|
|
|
mCSSEditUtils->RemoveCSSProperty(*mResizedObject, *nsGkAtoms::width,
|
2014-08-29 15:43:24 +04:00
|
|
|
EmptyString());
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
|
|
|
if (setHeight) {
|
2016-12-20 14:53:00 +03:00
|
|
|
mCSSEditUtils->RemoveCSSProperty(*mResizedObject, *nsGkAtoms::height,
|
2014-08-29 15:43:24 +04:00
|
|
|
EmptyString());
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
2003-02-24 13:18:18 +03:00
|
|
|
}
|
|
|
|
|
2003-06-25 12:50:48 +04:00
|
|
|
// keep track of that size
|
|
|
|
mResizedObjectWidth = width;
|
|
|
|
mResizedObjectHeight = height;
|
2003-02-24 13:18:18 +03:00
|
|
|
|
2003-06-25 12:50:48 +04:00
|
|
|
RefreshResizers();
|
|
|
|
}
|
2003-02-24 13:18:18 +03:00
|
|
|
|
2003-06-25 12:50:48 +04:00
|
|
|
NS_IMETHODIMP
|
2016-07-09 05:42:33 +03:00
|
|
|
HTMLEditor::GetResizedObject(nsIDOMElement** aResizedObject)
|
2003-06-25 12:50:48 +04:00
|
|
|
{
|
2015-04-19 15:28:50 +03:00
|
|
|
nsCOMPtr<nsIDOMElement> ret = static_cast<nsIDOMElement*>(GetAsDOMNode(mResizedObject));
|
|
|
|
ret.forget(aResizedObject);
|
2003-02-24 13:18:18 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-07-09 05:42:33 +03:00
|
|
|
HTMLEditor::GetObjectResizingEnabled(bool* aIsObjectResizingEnabled)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
2003-06-25 12:50:48 +04:00
|
|
|
*aIsObjectResizingEnabled = mIsObjectResizingEnabled;
|
2003-02-24 13:18:18 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-07-09 05:42:33 +03:00
|
|
|
HTMLEditor::SetObjectResizingEnabled(bool aObjectResizingEnabled)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
2003-06-25 12:50:48 +04:00
|
|
|
mIsObjectResizingEnabled = aObjectResizingEnabled;
|
2003-02-24 13:18:18 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-07-09 05:42:33 +03:00
|
|
|
} // namespace mozilla
|