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"
|
2018-04-20 07:49:29 +03:00
|
|
|
#include "mozilla/dom/Event.h"
|
2018-03-20 07:16:05 +03:00
|
|
|
#include "mozilla/dom/MouseEvent.h"
|
2018-04-05 20:42:40 +03:00
|
|
|
#include "mozilla/dom/EventTarget.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#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"
|
2017-10-03 01:05:19 +03:00
|
|
|
#include "nsAtom.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsID.h"
|
2003-02-24 13:18:18 +03:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#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 "nscore.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2012-07-13 10:33:42 +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
|
|
|
|
2017-06-22 09:02:59 +03:00
|
|
|
DocumentResizeEventListener::DocumentResizeEventListener(
|
|
|
|
HTMLEditor& aHTMLEditor)
|
|
|
|
: mHTMLEditorWeak(&aHTMLEditor)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-04-20 07:49:29 +03:00
|
|
|
DocumentResizeEventListener::HandleEvent(Event* aMouseEvent)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
2017-06-22 09:02:59 +03:00
|
|
|
RefPtr<HTMLEditor> htmlEditor = mHTMLEditorWeak.get();
|
|
|
|
if (htmlEditor) {
|
|
|
|
return htmlEditor->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::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
|
|
|
|
2017-06-22 09:02:59 +03:00
|
|
|
ResizerMouseMotionListener::ResizerMouseMotionListener(HTMLEditor& aHTMLEditor)
|
|
|
|
: mHTMLEditorWeak(&aHTMLEditor)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-04-20 07:49:29 +03:00
|
|
|
ResizerMouseMotionListener::HandleEvent(Event* aMouseEvent)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
2018-04-20 07:49:30 +03:00
|
|
|
MouseEvent* mouseEvent = aMouseEvent->AsMouseEvent();
|
2003-02-24 13:18:18 +03:00
|
|
|
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
|
2017-06-22 09:02:59 +03:00
|
|
|
RefPtr<HTMLEditor> htmlEditor = mHTMLEditorWeak.get();
|
|
|
|
if (htmlEditor) {
|
2003-02-24 13:18:18 +03:00
|
|
|
// check if we have to redisplay a resizing shadow
|
2018-01-10 06:47:16 +03:00
|
|
|
htmlEditor->OnMouseMove(mouseEvent);
|
2003-02-24 13:18:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-07-09 05:42:33 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::HTMLEditor
|
|
|
|
******************************************************************************/
|
2003-02-24 13:18:18 +03:00
|
|
|
|
2017-08-02 22:37:44 +03:00
|
|
|
ManualNACPtr
|
2016-07-09 05:42:33 +03:00
|
|
|
HTMLEditor::CreateResizer(int16_t aLocation,
|
2017-08-07 08:09:51 +03:00
|
|
|
nsIContent& aParentContent)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
2017-08-02 22:37:44 +03:00
|
|
|
ManualNACPtr ret =
|
2016-11-24 12:07:47 +03:00
|
|
|
CreateAnonymousElement(nsGkAtoms::span,
|
2017-08-07 08:09:51 +03:00
|
|
|
aParentContent,
|
2016-11-24 12:07:47 +03:00
|
|
|
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
|
2018-04-05 20:42:42 +03:00
|
|
|
ret->AddEventListener(NS_LITERAL_STRING("mousedown"), mEventListener,
|
|
|
|
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);
|
2018-06-03 19:25:41 +03:00
|
|
|
return std::move(ret);
|
2003-02-24 13:18:18 +03:00
|
|
|
}
|
|
|
|
|
2017-08-02 22:37:44 +03:00
|
|
|
ManualNACPtr
|
2017-08-07 08:09:51 +03:00
|
|
|
HTMLEditor::CreateShadow(nsIContent& aParentContent,
|
|
|
|
Element& aOriginalObject)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
|
|
|
// let's create an image through the element factory
|
2017-10-03 01:05:19 +03:00
|
|
|
RefPtr<nsAtom> name;
|
2017-08-07 08:09:51 +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
|
|
|
}
|
2017-08-02 22:37:44 +03:00
|
|
|
|
2017-08-07 08:09:51 +03:00
|
|
|
return CreateAnonymousElement(name, aParentContent,
|
2017-08-02 22:37:44 +03:00
|
|
|
NS_LITERAL_STRING("mozResizingShadow"), true);
|
2003-02-24 13:18:18 +03:00
|
|
|
}
|
|
|
|
|
2017-08-02 22:37:44 +03:00
|
|
|
ManualNACPtr
|
2017-08-07 08:09:51 +03:00
|
|
|
HTMLEditor::CreateResizingInfo(nsIContent& aParentContent)
|
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
|
2017-08-07 08:09:51 +03:00
|
|
|
return CreateAnonymousElement(nsGkAtoms::span, aParentContent,
|
2017-08-02 22:37:44 +03:00
|
|
|
NS_LITERAL_STRING("mozResizingInfo"), true);
|
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;
|
2017-10-03 01:05:19 +03:00
|
|
|
RefPtr<nsAtom> dummyUnit;
|
2018-02-02 12:42:25 +03:00
|
|
|
CSSEditUtils::GetComputedProperty(*mTopLeftHandle, *nsGkAtoms::width,
|
|
|
|
value);
|
|
|
|
CSSEditUtils::ParseLength(value, &resizerWidth, getter_AddRefs(dummyUnit));
|
|
|
|
CSSEditUtils::GetComputedProperty(*mTopLeftHandle, *nsGkAtoms::height,
|
|
|
|
value);
|
|
|
|
CSSEditUtils::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(
|
2017-08-07 08:09:51 +03:00
|
|
|
*mResizedObject,
|
2016-10-19 12:09:33 +03:00
|
|
|
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
|
2018-04-27 06:35:18 +03:00
|
|
|
HTMLEditor::ShowResizers(Element* aResizedElement)
|
2009-04-14 07:05:34 +04:00
|
|
|
{
|
2017-08-07 08:09:51 +03:00
|
|
|
if (NS_WARN_IF(!aResizedElement)) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2018-04-27 06:35:18 +03:00
|
|
|
return ShowResizers(*aResizedElement);
|
2018-01-30 07:42:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
HTMLEditor::ShowResizers(Element& aResizedElement)
|
|
|
|
{
|
|
|
|
nsresult rv = ShowResizersInner(aResizedElement);
|
2016-10-19 12:09:33 +03:00
|
|
|
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
|
2017-08-07 08:09:51 +03:00
|
|
|
HTMLEditor::ShowResizersInner(Element& aResizedElement)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
2008-04-14 00:22:31 +04:00
|
|
|
if (mResizedObject) {
|
|
|
|
NS_ERROR("call HideResizers first");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2017-08-07 08:09:51 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> parentContent = aResizedElement.GetParent();
|
|
|
|
if (NS_WARN_IF(!parentContent)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2017-09-09 17:49:02 +03:00
|
|
|
if (NS_WARN_IF(!IsDescendantOfEditorRoot(&aResizedElement))) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2017-08-07 08:09:51 +03:00
|
|
|
mResizedObject = &aResizedElement;
|
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.
|
2017-08-07 08:09:51 +03:00
|
|
|
mTopLeftHandle =
|
|
|
|
CreateResizer(nsIHTMLObjectResizer::eTopLeft, *parentContent);
|
2015-04-19 15:28:50 +03:00
|
|
|
NS_ENSURE_TRUE(mTopLeftHandle, NS_ERROR_FAILURE);
|
2017-08-07 08:09:51 +03:00
|
|
|
mTopHandle = CreateResizer(nsIHTMLObjectResizer::eTop, *parentContent);
|
2015-04-19 15:28:50 +03:00
|
|
|
NS_ENSURE_TRUE(mTopHandle, NS_ERROR_FAILURE);
|
2017-08-07 08:09:51 +03:00
|
|
|
mTopRightHandle =
|
|
|
|
CreateResizer(nsIHTMLObjectResizer::eTopRight, *parentContent);
|
2015-04-19 15:28:50 +03:00
|
|
|
NS_ENSURE_TRUE(mTopRightHandle, NS_ERROR_FAILURE);
|
|
|
|
|
2017-08-07 08:09:51 +03:00
|
|
|
mLeftHandle = CreateResizer(nsIHTMLObjectResizer::eLeft, *parentContent);
|
2015-04-19 15:28:50 +03:00
|
|
|
NS_ENSURE_TRUE(mLeftHandle, NS_ERROR_FAILURE);
|
2017-08-07 08:09:51 +03:00
|
|
|
mRightHandle = CreateResizer(nsIHTMLObjectResizer::eRight, *parentContent);
|
2015-04-19 15:28:50 +03:00
|
|
|
NS_ENSURE_TRUE(mRightHandle, NS_ERROR_FAILURE);
|
|
|
|
|
2017-08-07 08:09:51 +03:00
|
|
|
mBottomLeftHandle =
|
|
|
|
CreateResizer(nsIHTMLObjectResizer::eBottomLeft, *parentContent);
|
2015-04-19 15:28:50 +03:00
|
|
|
NS_ENSURE_TRUE(mBottomLeftHandle, NS_ERROR_FAILURE);
|
2017-08-07 08:09:51 +03:00
|
|
|
mBottomHandle = CreateResizer(nsIHTMLObjectResizer::eBottom, *parentContent);
|
2015-04-19 15:28:50 +03:00
|
|
|
NS_ENSURE_TRUE(mBottomHandle, NS_ERROR_FAILURE);
|
2017-08-07 08:09:51 +03:00
|
|
|
mBottomRightHandle =
|
|
|
|
CreateResizer(nsIHTMLObjectResizer::eBottomRight, *parentContent);
|
2015-04-19 15:28:50 +03:00
|
|
|
NS_ENSURE_TRUE(mBottomRightHandle, NS_ERROR_FAILURE);
|
2003-06-25 12:50:48 +04:00
|
|
|
|
2017-08-07 08:09:51 +03:00
|
|
|
nsresult rv =
|
|
|
|
GetPositionAndDimensions(aResizedElement,
|
|
|
|
mResizedObjectX,
|
|
|
|
mResizedObjectY,
|
|
|
|
mResizedObjectWidth,
|
|
|
|
mResizedObjectHeight,
|
|
|
|
mResizedObjectBorderLeft,
|
|
|
|
mResizedObjectBorderTop,
|
|
|
|
mResizedObjectMarginLeft,
|
|
|
|
mResizedObjectMarginTop);
|
2016-10-19 12:09:33 +03:00
|
|
|
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
|
2017-08-07 08:09:51 +03:00
|
|
|
mResizingShadow = CreateShadow(*parentContent, aResizedElement);
|
2015-04-19 15:28:50 +03:00
|
|
|
NS_ENSURE_TRUE(mResizingShadow, NS_ERROR_FAILURE);
|
2003-02-24 13:18:18 +03:00
|
|
|
// and set its position
|
2017-08-07 08:09:51 +03:00
|
|
|
rv = SetShadowPosition(mResizingShadow, &aResizedElement,
|
2016-10-19 12:09:33 +03:00
|
|
|
mResizedObjectX, mResizedObjectY);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-02-24 13:18:18 +03:00
|
|
|
|
|
|
|
// and then the resizing info tooltip
|
2017-08-07 08:09:51 +03:00
|
|
|
mResizingInfo = CreateResizingInfo(*parentContent);
|
2015-04-19 15:28:50 +03:00
|
|
|
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
|
|
|
|
2018-04-05 20:42:42 +03:00
|
|
|
nsCOMPtr<EventTarget> 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
|
|
|
|
2017-06-22 09:02:59 +03:00
|
|
|
mResizeEventListenerP = new DocumentResizeEventListener(*this);
|
2016-10-19 12:09:33 +03:00
|
|
|
rv = target->AddEventListener(NS_LITERAL_STRING("resize"),
|
|
|
|
mResizeEventListenerP, false);
|
2017-08-07 08:09:51 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2016-10-19 12:09:33 +03:00
|
|
|
// XXX Even when it failed to add event listener, should we need to set
|
|
|
|
// _moz_resizing attribute?
|
2017-08-07 08:09:51 +03:00
|
|
|
aResizedElement.SetAttr(kNameSpaceID_None, nsGkAtoms::_moz_resizing,
|
|
|
|
NS_LITERAL_STRING("true"), true);
|
|
|
|
|
|
|
|
MOZ_ASSERT(mResizedObject == &aResizedElement);
|
|
|
|
|
Bug 1452538 - Add telemetry probes HTMLEditors which have shown Gecko build-in editing UIs and count of user interaction with them r=Ehsan
Gecko has some built-in UIs:
* to edit size of objects like <img>, <table> and absolute positioned elements.
* to edit position of absolute positioned elements.
* to add/remove table columns and rows.
Currently, those UIs are available in both designMode editor and contenteditable
editor only on Gecko. I.e., the other browsers' users cannot modify as such
without web apps implement such function. So, for compatibility with the
other browsers, we should hide those UIs by default. On the other hand, if
this is too risky for backward compatibility, we should not do that.
So, before doing that, we should collect actual usage data of object resizers,
inline table editing UI, positioning UI of absolute positioned elements with
telemetry probes.
This patch adds 3 sets of probes for each UI. One is percentage of showing
each UI in all instantiated HTMLEditor. The other is number of user interaction
of each UI in HTMLEditors which has shown the UI.
This patch makes all new probes as "opt-out" because they are really important
data since used for deciding whether those UIs are necessary or unnecessary.
MozReview-Commit-ID: B9Y6GTiCPw6
--HG--
extra : rebase_source : 00e49f31712e24cb269ad3aa65c7d13b7cccb3a5
2018-04-09 11:31:23 +03:00
|
|
|
mHasShownResizers = true;
|
|
|
|
|
2017-08-07 08:09:51 +03:00
|
|
|
return NS_OK;
|
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
|
|
|
|
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,
|
2018-05-30 22:15:35 +03:00
|
|
|
std::move(mTopLeftHandle), ps);
|
2006-06-15 11:31:01 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
RemoveListenerAndDeleteRef(mousedown, mEventListener, true,
|
2018-05-30 22:15:35 +03:00
|
|
|
std::move(mTopHandle), ps);
|
2006-06-15 11:31:01 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
RemoveListenerAndDeleteRef(mousedown, mEventListener, true,
|
2018-05-30 22:15:35 +03:00
|
|
|
std::move(mTopRightHandle), ps);
|
2006-06-15 11:31:01 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
RemoveListenerAndDeleteRef(mousedown, mEventListener, true,
|
2018-05-30 22:15:35 +03:00
|
|
|
std::move(mLeftHandle), ps);
|
2006-06-15 11:31:01 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
RemoveListenerAndDeleteRef(mousedown, mEventListener, true,
|
2018-05-30 22:15:35 +03:00
|
|
|
std::move(mRightHandle), ps);
|
2006-06-15 11:31:01 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
RemoveListenerAndDeleteRef(mousedown, mEventListener, true,
|
2018-05-30 22:15:35 +03:00
|
|
|
std::move(mBottomLeftHandle), ps);
|
2006-06-15 11:31:01 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
RemoveListenerAndDeleteRef(mousedown, mEventListener, true,
|
2018-05-30 22:15:35 +03:00
|
|
|
std::move(mBottomHandle), ps);
|
2006-06-15 11:31:01 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
RemoveListenerAndDeleteRef(mousedown, mEventListener, true,
|
2018-05-30 22:15:35 +03:00
|
|
|
std::move(mBottomRightHandle), ps);
|
2006-06-15 11:31:01 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
RemoveListenerAndDeleteRef(mousedown, mEventListener, true,
|
2018-05-30 22:15:35 +03:00
|
|
|
std::move(mResizingShadow), ps);
|
2006-06-15 11:31:01 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
RemoveListenerAndDeleteRef(mousedown, mEventListener, true,
|
2018-05-30 22:15:35 +03:00
|
|
|
std::move(mResizingInfo), ps);
|
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 !
|
|
|
|
|
2018-04-05 20:42:40 +03:00
|
|
|
// nsCOMPtr so we can do_QueryInterface into it.
|
|
|
|
nsCOMPtr<EventTarget> target = GetDOMEventTarget();
|
2003-03-25 18:24:08 +03:00
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
if (target && mMouseMotionListenerP) {
|
2018-04-05 20:42:40 +03:00
|
|
|
target->RemoveEventListener(NS_LITERAL_STRING("mousemove"),
|
|
|
|
mMouseMotionListenerP, true);
|
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) {
|
2018-04-05 20:42:40 +03:00
|
|
|
target->RemoveEventListener(NS_LITERAL_STRING("resize"),
|
|
|
|
mResizeEventListenerP, false);
|
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
|
2018-04-27 06:35:18 +03:00
|
|
|
HTMLEditor::StartResizing(Element* aHandle)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsResizing = true;
|
2018-04-27 06:35:18 +03:00
|
|
|
mActivatedHandle = aHandle;
|
2015-04-19 15:28:50 +03:00
|
|
|
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;
|
2018-01-30 07:28:00 +03:00
|
|
|
mActivatedHandle->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) {
|
2017-06-22 09:02:59 +03: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
|
|
|
|
2018-04-05 20:42:42 +03:00
|
|
|
EventTarget* 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;
|
|
|
|
}
|
|
|
|
|
2018-01-10 06:47:16 +03:00
|
|
|
nsresult
|
|
|
|
HTMLEditor::OnMouseDown(int32_t aClientX,
|
|
|
|
int32_t aClientY,
|
2018-04-27 06:35:18 +03:00
|
|
|
Element* aTarget,
|
2018-04-20 19:53:17 +03:00
|
|
|
Event* aEvent)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
2018-04-27 06:35:18 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aTarget);
|
2018-01-30 07:27:59 +03:00
|
|
|
|
|
|
|
nsAutoString anonclass;
|
2018-04-27 06:35:18 +03:00
|
|
|
aTarget->GetAttribute(NS_LITERAL_STRING("_moz_anonclass"), anonclass);
|
2018-01-30 07:27:59 +03:00
|
|
|
|
|
|
|
if (anonclass.EqualsLiteral("mozResizer")) {
|
|
|
|
// If we have an anonymous element and that element is a resizer,
|
|
|
|
// let's start resizing!
|
|
|
|
aEvent->PreventDefault();
|
Bug 1452538 - Add telemetry probes HTMLEditors which have shown Gecko build-in editing UIs and count of user interaction with them r=Ehsan
Gecko has some built-in UIs:
* to edit size of objects like <img>, <table> and absolute positioned elements.
* to edit position of absolute positioned elements.
* to add/remove table columns and rows.
Currently, those UIs are available in both designMode editor and contenteditable
editor only on Gecko. I.e., the other browsers' users cannot modify as such
without web apps implement such function. So, for compatibility with the
other browsers, we should hide those UIs by default. On the other hand, if
this is too risky for backward compatibility, we should not do that.
So, before doing that, we should collect actual usage data of object resizers,
inline table editing UI, positioning UI of absolute positioned elements with
telemetry probes.
This patch adds 3 sets of probes for each UI. One is percentage of showing
each UI in all instantiated HTMLEditor. The other is number of user interaction
of each UI in HTMLEditors which has shown the UI.
This patch makes all new probes as "opt-out" because they are really important
data since used for deciding whether those UIs are necessary or unnecessary.
MozReview-Commit-ID: B9Y6GTiCPw6
--HG--
extra : rebase_source : 00e49f31712e24cb269ad3aa65c7d13b7cccb3a5
2018-04-09 11:31:23 +03:00
|
|
|
mResizerUsedCount++;
|
2018-01-30 07:27:59 +03:00
|
|
|
mOriginalX = aClientX;
|
|
|
|
mOriginalY = aClientY;
|
|
|
|
return StartResizing(aTarget);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (anonclass.EqualsLiteral("mozGrabber")) {
|
|
|
|
// If we have an anonymous element and that element is a grabber,
|
|
|
|
// let's start moving the element!
|
Bug 1452538 - Add telemetry probes HTMLEditors which have shown Gecko build-in editing UIs and count of user interaction with them r=Ehsan
Gecko has some built-in UIs:
* to edit size of objects like <img>, <table> and absolute positioned elements.
* to edit position of absolute positioned elements.
* to add/remove table columns and rows.
Currently, those UIs are available in both designMode editor and contenteditable
editor only on Gecko. I.e., the other browsers' users cannot modify as such
without web apps implement such function. So, for compatibility with the
other browsers, we should hide those UIs by default. On the other hand, if
this is too risky for backward compatibility, we should not do that.
So, before doing that, we should collect actual usage data of object resizers,
inline table editing UI, positioning UI of absolute positioned elements with
telemetry probes.
This patch adds 3 sets of probes for each UI. One is percentage of showing
each UI in all instantiated HTMLEditor. The other is number of user interaction
of each UI in HTMLEditors which has shown the UI.
This patch makes all new probes as "opt-out" because they are really important
data since used for deciding whether those UIs are necessary or unnecessary.
MozReview-Commit-ID: B9Y6GTiCPw6
--HG--
extra : rebase_source : 00e49f31712e24cb269ad3aa65c7d13b7cccb3a5
2018-04-09 11:31:23 +03:00
|
|
|
mGrabberUsedCount++;
|
2018-01-30 07:27:59 +03:00
|
|
|
mOriginalX = aClientX;
|
|
|
|
mOriginalY = aClientY;
|
|
|
|
return GrabberClicked();
|
|
|
|
}
|
|
|
|
|
2003-02-24 13:18:18 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-01-10 06:47:16 +03:00
|
|
|
nsresult
|
|
|
|
HTMLEditor::OnMouseUp(int32_t aClientX,
|
|
|
|
int32_t aClientY,
|
2018-04-27 06:35:18 +03:00
|
|
|
Element* 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,
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-public methods. I.e.,
they should be able to be called by anybody. E.g., command handlers, event
listeners, or JS via nsIEditor interface. The other is semi-public methods.
They are not called by the above examples but called by other classes which
are helper classes to handle edit actions. E.g., TextEditRules, HTMLEditRules,
HTMLEditUtils, CSSEditUtils and Transaction classes.
When we will implement InputEvent.inputType, we need to create new stack
class and create its instance at every true-public methods to manage current
inputType (like TextEditRules::AutoSafeEditorData). Therefore, it should not
happen that new code starts to call semi-public methods without the new
stack class instance.
For preventing this issue, we should make HTMLEditor have only the true-public
methods as public. The other public methods should be protected and their
users should be friend classes. Then, we can protect such method from external
classes.
Note that this patch just moves the methods without any changes in HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
ResizeAt aResizeAt)
|
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) {
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-public methods. I.e.,
they should be able to be called by anybody. E.g., command handlers, event
listeners, or JS via nsIEditor interface. The other is semi-public methods.
They are not called by the above examples but called by other classes which
are helper classes to handle edit actions. E.g., TextEditRules, HTMLEditRules,
HTMLEditUtils, CSSEditUtils and Transaction classes.
When we will implement InputEvent.inputType, we need to create new stack
class and create its instance at every true-public methods to manage current
inputType (like TextEditRules::AutoSafeEditorData). Therefore, it should not
happen that new code starts to call semi-public methods without the new
stack class instance.
For preventing this issue, we should make HTMLEditor have only the true-public
methods as public. The other public methods should be protected and their
users should be friend classes. Then, we can protect such method from external
classes.
Note that this patch just moves the methods without any changes in HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
switch (aResizeAt) {
|
|
|
|
case ResizeAt::eX:
|
|
|
|
case ResizeAt::eWidth:
|
2003-02-24 13:18:18 +03:00
|
|
|
result = aX - mOriginalX;
|
|
|
|
break;
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-public methods. I.e.,
they should be able to be called by anybody. E.g., command handlers, event
listeners, or JS via nsIEditor interface. The other is semi-public methods.
They are not called by the above examples but called by other classes which
are helper classes to handle edit actions. E.g., TextEditRules, HTMLEditRules,
HTMLEditUtils, CSSEditUtils and Transaction classes.
When we will implement InputEvent.inputType, we need to create new stack
class and create its instance at every true-public methods to manage current
inputType (like TextEditRules::AutoSafeEditorData). Therefore, it should not
happen that new code starts to call semi-public methods without the new
stack class instance.
For preventing this issue, we should make HTMLEditor have only the true-public
methods as public. The other public methods should be protected and their
users should be friend classes. Then, we can protect such method from external
classes.
Note that this patch just moves the methods without any changes in HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
case ResizeAt::eY:
|
|
|
|
case ResizeAt::eHeight:
|
2003-02-24 13:18:18 +03:00
|
|
|
result = aY - mOriginalY;
|
|
|
|
break;
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-public methods. I.e.,
they should be able to be called by anybody. E.g., command handlers, event
listeners, or JS via nsIEditor interface. The other is semi-public methods.
They are not called by the above examples but called by other classes which
are helper classes to handle edit actions. E.g., TextEditRules, HTMLEditRules,
HTMLEditUtils, CSSEditUtils and Transaction classes.
When we will implement InputEvent.inputType, we need to create new stack
class and create its instance at every true-public methods to manage current
inputType (like TextEditRules::AutoSafeEditorData). Therefore, it should not
happen that new code starts to call semi-public methods without the new
stack class instance.
For preventing this issue, we should make HTMLEditor have only the true-public
methods as public. The other public methods should be protected and their
users should be friend classes. Then, we can protect such method from external
classes.
Note that this patch just moves the methods without any changes in HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
default:
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Invalid resizing request");
|
2003-02-24 13:18:18 +03:00
|
|
|
}
|
|
|
|
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;
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-public methods. I.e.,
they should be able to be called by anybody. E.g., command handlers, event
listeners, or JS via nsIEditor interface. The other is semi-public methods.
They are not called by the above examples but called by other classes which
are helper classes to handle edit actions. E.g., TextEditRules, HTMLEditRules,
HTMLEditUtils, CSSEditUtils and Transaction classes.
When we will implement InputEvent.inputType, we need to create new stack
class and create its instance at every true-public methods to manage current
inputType (like TextEditRules::AutoSafeEditorData). Therefore, it should not
happen that new code starts to call semi-public methods without the new
stack class instance.
For preventing this issue, we should make HTMLEditor have only the true-public
methods as public. The other public methods should be protected and their
users should be friend classes. Then, we can protect such method from external
classes.
Note that this patch just moves the methods without any changes in HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
switch (aResizeAt) {
|
|
|
|
case ResizeAt::eX:
|
|
|
|
case ResizeAt::eWidth:
|
2003-02-24 13:18:18 +03:00
|
|
|
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;
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-public methods. I.e.,
they should be able to be called by anybody. E.g., command handlers, event
listeners, or JS via nsIEditor interface. The other is semi-public methods.
They are not called by the above examples but called by other classes which
are helper classes to handle edit actions. E.g., TextEditRules, HTMLEditRules,
HTMLEditUtils, CSSEditUtils and Transaction classes.
When we will implement InputEvent.inputType, we need to create new stack
class and create its instance at every true-public methods to manage current
inputType (like TextEditRules::AutoSafeEditorData). Therefore, it should not
happen that new code starts to call semi-public methods without the new
stack class instance.
For preventing this issue, we should make HTMLEditor have only the true-public
methods as public. The other public methods should be protected and their
users should be friend classes. Then, we can protect such method from external
classes.
Note that this patch just moves the methods without any changes in HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
case ResizeAt::eY:
|
|
|
|
case ResizeAt::eHeight:
|
2003-02-24 13:18:18 +03:00
|
|
|
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
|
|
|
{
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-public methods. I.e.,
they should be able to be called by anybody. E.g., command handlers, event
listeners, or JS via nsIEditor interface. The other is semi-public methods.
They are not called by the above examples but called by other classes which
are helper classes to handle edit actions. E.g., TextEditRules, HTMLEditRules,
HTMLEditUtils, CSSEditUtils and Transaction classes.
When we will implement InputEvent.inputType, we need to create new stack
class and create its instance at every true-public methods to manage current
inputType (like TextEditRules::AutoSafeEditorData). Therefore, it should not
happen that new code starts to call semi-public methods without the new
stack class instance.
For preventing this issue, we should make HTMLEditor have only the true-public
methods as public. The other public methods should be protected and their
users should be friend classes. Then, we can protect such method from external
classes.
Note that this patch just moves the methods without any changes in HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
int32_t resized =
|
|
|
|
mResizedObjectX +
|
|
|
|
GetNewResizingIncrement(aX, aY, ResizeAt::eX) * mXIncrementFactor;
|
|
|
|
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
|
|
|
{
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-public methods. I.e.,
they should be able to be called by anybody. E.g., command handlers, event
listeners, or JS via nsIEditor interface. The other is semi-public methods.
They are not called by the above examples but called by other classes which
are helper classes to handle edit actions. E.g., TextEditRules, HTMLEditRules,
HTMLEditUtils, CSSEditUtils and Transaction classes.
When we will implement InputEvent.inputType, we need to create new stack
class and create its instance at every true-public methods to manage current
inputType (like TextEditRules::AutoSafeEditorData). Therefore, it should not
happen that new code starts to call semi-public methods without the new
stack class instance.
For preventing this issue, we should make HTMLEditor have only the true-public
methods as public. The other public methods should be protected and their
users should be friend classes. Then, we can protect such method from external
classes.
Note that this patch just moves the methods without any changes in HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
int32_t resized =
|
|
|
|
mResizedObjectY +
|
|
|
|
GetNewResizingIncrement(aX, aY, ResizeAt::eY) * 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
|
|
|
{
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-public methods. I.e.,
they should be able to be called by anybody. E.g., command handlers, event
listeners, or JS via nsIEditor interface. The other is semi-public methods.
They are not called by the above examples but called by other classes which
are helper classes to handle edit actions. E.g., TextEditRules, HTMLEditRules,
HTMLEditUtils, CSSEditUtils and Transaction classes.
When we will implement InputEvent.inputType, we need to create new stack
class and create its instance at every true-public methods to manage current
inputType (like TextEditRules::AutoSafeEditorData). Therefore, it should not
happen that new code starts to call semi-public methods without the new
stack class instance.
For preventing this issue, we should make HTMLEditor have only the true-public
methods as public. The other public methods should be protected and their
users should be friend classes. Then, we can protect such method from external
classes.
Note that this patch just moves the methods without any changes in HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
int32_t resized =
|
|
|
|
mResizedObjectWidth +
|
|
|
|
GetNewResizingIncrement(aX, aY,
|
|
|
|
ResizeAt::eWidth) * 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
|
|
|
{
|
Bug 1463327 - part 3: Change scope of some methods of HTMLEditor which won't be called by non-helper classes of editing to protected r=m_kato
HTMLEditor has 2 type of public methods. One is rue-public methods. I.e.,
they should be able to be called by anybody. E.g., command handlers, event
listeners, or JS via nsIEditor interface. The other is semi-public methods.
They are not called by the above examples but called by other classes which
are helper classes to handle edit actions. E.g., TextEditRules, HTMLEditRules,
HTMLEditUtils, CSSEditUtils and Transaction classes.
When we will implement InputEvent.inputType, we need to create new stack
class and create its instance at every true-public methods to manage current
inputType (like TextEditRules::AutoSafeEditorData). Therefore, it should not
happen that new code starts to call semi-public methods without the new
stack class instance.
For preventing this issue, we should make HTMLEditor have only the true-public
methods as public. The other public methods should be protected and their
users should be friend classes. Then, we can protect such method from external
classes.
Note that this patch just moves the methods without any changes in HTMLEditor.h
(except removes BlockTransformationType since it's unused and replaces
ResizingRequestID with new enum class ResizeAt since normal enum isn't hit by
searchfox.org).
MozReview-Commit-ID: 7PC8E8vD7w2
--HG--
extra : rebase_source : 13f51565f2b89ab816ba529af18ee88193a9c932
2018-05-22 12:28:50 +03:00
|
|
|
int32_t resized =
|
|
|
|
mResizedObjectHeight +
|
|
|
|
GetNewResizingIncrement(aX, aY,
|
|
|
|
ResizeAt::eHeight) * mHeightIncrementFactor;
|
2013-01-15 16:22:03 +04:00
|
|
|
return std::max(resized, 1);
|
2003-02-24 13:18:18 +03:00
|
|
|
}
|
|
|
|
|
2017-06-22 09:02:59 +03:00
|
|
|
nsresult
|
2018-03-20 07:16:05 +03:00
|
|
|
HTMLEditor::OnMouseMove(MouseEvent* aMouseEvent)
|
2017-06-22 09:02:59 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aMouseEvent);
|
|
|
|
|
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
|
2018-03-20 07:16:05 +03:00
|
|
|
int32_t clientX = aMouseEvent->ClientX();
|
|
|
|
int32_t clientY = aMouseEvent->ClientY();
|
2003-02-24 13:18:18 +03:00
|
|
|
|
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) {
|
2018-03-20 07:16:05 +03:00
|
|
|
int32_t clientX = aMouseEvent->ClientX();
|
|
|
|
int32_t clientY = aMouseEvent->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;
|
2018-03-19 08:14:45 +03:00
|
|
|
StartMoving();
|
2003-06-25 12:50:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mIsMoving) {
|
2018-03-20 07:16:05 +03:00
|
|
|
int32_t clientX = aMouseEvent->ClientX();
|
|
|
|
int32_t clientY = aMouseEvent->ClientY();
|
2003-06-25 12:50:48 +04:00
|
|
|
|
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
|
2017-08-14 08:56:39 +03:00
|
|
|
AutoPlaceholderBatch 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)) {
|
2018-04-12 10:58:33 +03:00
|
|
|
RemoveAttributeWithTransaction(*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)) {
|
2018-04-12 10:58:33 +03:00
|
|
|
RemoveAttributeWithTransaction(*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);
|
2018-04-12 10:58:33 +03:00
|
|
|
SetAttributeWithTransaction(*mResizedObject, *nsGkAtoms::width, w);
|
2003-09-03 17:58:00 +04:00
|
|
|
}
|
|
|
|
if (setHeight) {
|
|
|
|
nsAutoString h;
|
|
|
|
h.AppendInt(height);
|
2018-04-12 10:58:33 +03:00
|
|
|
SetAttributeWithTransaction(*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
|
2018-04-27 06:35:18 +03:00
|
|
|
HTMLEditor::GetResizedObject(Element** aResizedObject)
|
2003-06-25 12:50:48 +04:00
|
|
|
{
|
2018-04-27 06:35:18 +03:00
|
|
|
RefPtr<Element> ret = mResizedObject;
|
2015-04-19 15:28:50 +03:00
|
|
|
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
|