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
|
|
|
|
2018-11-06 07:58:29 +03:00
|
|
|
#include "HTMLEditorEventListener.h"
|
2016-07-07 08:01:12 +03:00
|
|
|
#include "HTMLEditUtils.h"
|
2015-04-19 15:28:50 +03:00
|
|
|
#include "mozilla/DebugOnly.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
|
|
|
/******************************************************************************
|
|
|
|
* 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-01 18:59:07 +03:00
|
|
|
return 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
|
|
|
{
|
2018-09-11 11:15:52 +03:00
|
|
|
if (NS_WARN_IF(!mTopLeftHandle)) {
|
|
|
|
return NS_ERROR_FAILURE; // There are no resizers.
|
|
|
|
}
|
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
|
|
|
|
2003-06-25 12:50:48 +04:00
|
|
|
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
|
|
|
|
2018-09-11 11:15:52 +03:00
|
|
|
int32_t rw = static_cast<int32_t>((resizerWidth + 1) / 2);
|
|
|
|
int32_t rh = static_cast<int32_t>((resizerHeight+ 1) / 2);
|
|
|
|
|
|
|
|
// While moving each resizer, mutation event listener may hide the resizers.
|
|
|
|
// And in worst case, new resizers may be recreated. So, we need to store
|
|
|
|
// all resizers here, and then, if we detect a resizer is removed or replaced,
|
|
|
|
// we should do nothing anymore.
|
|
|
|
// FYI: Note that only checking if mTopLeftHandle is replaced is enough.
|
|
|
|
// We're may be in hot path if user resizes an element a lot. So,
|
|
|
|
// we should just add-ref mTopLeftHandle.
|
|
|
|
RefPtr<Element> topLeftHandle = mTopLeftHandle.get();
|
|
|
|
SetAnonymousElementPosition(x - rw, y - rh, mTopLeftHandle);
|
|
|
|
if (NS_WARN_IF(topLeftHandle != mTopLeftHandle)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
SetAnonymousElementPosition(x + w/2-rw, y - rh, mTopHandle);
|
|
|
|
if (NS_WARN_IF(topLeftHandle != mTopLeftHandle)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
SetAnonymousElementPosition(x + w-rw-1, y - rh, mTopRightHandle);
|
|
|
|
if (NS_WARN_IF(topLeftHandle != mTopLeftHandle)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2003-06-25 12:50:48 +04:00
|
|
|
|
2018-09-11 11:15:52 +03:00
|
|
|
SetAnonymousElementPosition(x - rw, y + h / 2 - rh, mLeftHandle);
|
|
|
|
if (NS_WARN_IF(topLeftHandle != mTopLeftHandle)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
SetAnonymousElementPosition(x + w-rw-1, y + h / 2 - rh, mRightHandle);
|
|
|
|
if (NS_WARN_IF(topLeftHandle != mTopLeftHandle)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2003-06-25 12:50:48 +04:00
|
|
|
|
2018-09-11 11:15:52 +03:00
|
|
|
SetAnonymousElementPosition(x - rw, y + h - rh - 1,
|
|
|
|
mBottomLeftHandle);
|
|
|
|
if (NS_WARN_IF(topLeftHandle != mTopLeftHandle)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
SetAnonymousElementPosition(x + w / 2 - rw, y + h - rh - 1,
|
|
|
|
mBottomHandle);
|
|
|
|
if (NS_WARN_IF(topLeftHandle != mTopLeftHandle)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
SetAnonymousElementPosition(x + w - rw - 1, y + h - rh - 1,
|
|
|
|
mBottomRightHandle);
|
|
|
|
if (NS_WARN_IF(topLeftHandle != mTopLeftHandle)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
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
|
|
|
{
|
2018-10-30 13:00:17 +03:00
|
|
|
AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing);
|
|
|
|
if (NS_WARN_IF(!editActionData.CanHandle())) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
|
2018-09-11 11:15:52 +03:00
|
|
|
nsresult rv = RefreshResizersInternal();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
HTMLEditor::RefreshResizersInternal()
|
|
|
|
{
|
2018-09-11 08:02:30 +03:00
|
|
|
// Don't warn even if resizers are not visible since script cannot check
|
|
|
|
// if they are visible and this is non-virtual method. So, the cost of
|
|
|
|
// calling this can be ignored.
|
2018-09-11 11:15:52 +03:00
|
|
|
if (!mResizedObject) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = GetPositionAndDimensions(*mResizedObject,
|
|
|
|
mResizedObjectX,
|
|
|
|
mResizedObjectY,
|
|
|
|
mResizedObjectWidth,
|
|
|
|
mResizedObjectHeight,
|
|
|
|
mResizedObjectBorderLeft,
|
|
|
|
mResizedObjectBorderTop,
|
|
|
|
mResizedObjectMarginLeft,
|
|
|
|
mResizedObjectMarginTop);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2003-06-25 12:50:48 +04:00
|
|
|
|
2016-10-19 12:09:33 +03:00
|
|
|
rv = SetAllResizersPosition();
|
2018-09-11 11:15:52 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(mResizingShadow,
|
|
|
|
"SetAllResizersPosition() should return error if resizers are hidden");
|
|
|
|
rv = SetShadowPosition(*mResizingShadow, *mResizedObject,
|
|
|
|
mResizedObjectX, mResizedObjectY);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2003-02-24 13:18:18 +03:00
|
|
|
}
|
|
|
|
|
2015-05-28 18:58:42 +03:00
|
|
|
nsresult
|
Bug 1485923 - Remove nsIHTMLObjectResizer.showResizers(), rename HTMLEditor::ShowResizers() to HTMLEditor::ShowResizersInternal() and merge it with HTMLEditor::ShowResizersInner() r=m_kato
First, nobody uses nsIHTMLObjectResizer.showResizers(). So, we can remove it.
Then, we have two private methods, one is non-virtual
HTMLEditor::ShowResizers(), and the other is HTMLEditor::ShowResizersInner().
HTMLEditor::ShowResizers() calls HTMLEditor::ShowResizersInner() and if
it fails, calls HideResizers(). However, in some cases, e.g., when it already
has visible resizers, hiding resizers does not make sense.
So, this patch removes non-virtual HTMLEditor::ShowResizers() method too,
then, renames HTMLEditor::ShowResizersInner() to HTMLEditor::ShowResizers(),
finally, it hides resizers only when it fails to setup resizers for keeping
resizers hidden.
Differential Revision: https://phabricator.services.mozilla.com/D4921
--HG--
extra : moz-landing-system : lando
2018-09-06 07:38:00 +03:00
|
|
|
HTMLEditor::ShowResizersInternal(Element& aResizedElement)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
Bug 1485923 - Remove nsIHTMLObjectResizer.showResizers(), rename HTMLEditor::ShowResizers() to HTMLEditor::ShowResizersInternal() and merge it with HTMLEditor::ShowResizersInner() r=m_kato
First, nobody uses nsIHTMLObjectResizer.showResizers(). So, we can remove it.
Then, we have two private methods, one is non-virtual
HTMLEditor::ShowResizers(), and the other is HTMLEditor::ShowResizersInner().
HTMLEditor::ShowResizers() calls HTMLEditor::ShowResizersInner() and if
it fails, calls HideResizers(). However, in some cases, e.g., when it already
has visible resizers, hiding resizers does not make sense.
So, this patch removes non-virtual HTMLEditor::ShowResizers() method too,
then, renames HTMLEditor::ShowResizersInner() to HTMLEditor::ShowResizers(),
finally, it hides resizers only when it fails to setup resizers for keeping
resizers hidden.
Differential Revision: https://phabricator.services.mozilla.com/D4921
--HG--
extra : moz-landing-system : lando
2018-09-06 07:38:00 +03:00
|
|
|
// When we have visible resizers, we cannot show new resizers.
|
2018-09-11 08:02:30 +03:00
|
|
|
// So, the caller should call HideResizersInternal() first if this
|
|
|
|
// returns error.
|
Bug 1485923 - Remove nsIHTMLObjectResizer.showResizers(), rename HTMLEditor::ShowResizers() to HTMLEditor::ShowResizersInternal() and merge it with HTMLEditor::ShowResizersInner() r=m_kato
First, nobody uses nsIHTMLObjectResizer.showResizers(). So, we can remove it.
Then, we have two private methods, one is non-virtual
HTMLEditor::ShowResizers(), and the other is HTMLEditor::ShowResizersInner().
HTMLEditor::ShowResizers() calls HTMLEditor::ShowResizersInner() and if
it fails, calls HideResizers(). However, in some cases, e.g., when it already
has visible resizers, hiding resizers does not make sense.
So, this patch removes non-virtual HTMLEditor::ShowResizers() method too,
then, renames HTMLEditor::ShowResizersInner() to HTMLEditor::ShowResizers(),
finally, it hides resizers only when it fails to setup resizers for keeping
resizers hidden.
Differential Revision: https://phabricator.services.mozilla.com/D4921
--HG--
extra : moz-landing-system : lando
2018-09-06 07:38:00 +03:00
|
|
|
if (NS_WARN_IF(mResizedObject)) {
|
2008-04-14 00:22:31 +04:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2017-08-07 08:09:51 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> parentContent = aResizedElement.GetParent();
|
|
|
|
if (NS_WARN_IF(!parentContent)) {
|
Bug 1485923 - Remove nsIHTMLObjectResizer.showResizers(), rename HTMLEditor::ShowResizers() to HTMLEditor::ShowResizersInternal() and merge it with HTMLEditor::ShowResizersInner() r=m_kato
First, nobody uses nsIHTMLObjectResizer.showResizers(). So, we can remove it.
Then, we have two private methods, one is non-virtual
HTMLEditor::ShowResizers(), and the other is HTMLEditor::ShowResizersInner().
HTMLEditor::ShowResizers() calls HTMLEditor::ShowResizersInner() and if
it fails, calls HideResizers(). However, in some cases, e.g., when it already
has visible resizers, hiding resizers does not make sense.
So, this patch removes non-virtual HTMLEditor::ShowResizers() method too,
then, renames HTMLEditor::ShowResizersInner() to HTMLEditor::ShowResizers(),
finally, it hides resizers only when it fails to setup resizers for keeping
resizers hidden.
Differential Revision: https://phabricator.services.mozilla.com/D4921
--HG--
extra : moz-landing-system : lando
2018-09-06 07:38:00 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2017-08-07 08:09:51 +03:00
|
|
|
}
|
|
|
|
|
2017-09-09 17:49:02 +03:00
|
|
|
if (NS_WARN_IF(!IsDescendantOfEditorRoot(&aResizedElement))) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
Bug 1485923 - Remove nsIHTMLObjectResizer.showResizers(), rename HTMLEditor::ShowResizers() to HTMLEditor::ShowResizersInternal() and merge it with HTMLEditor::ShowResizersInner() r=m_kato
First, nobody uses nsIHTMLObjectResizer.showResizers(). So, we can remove it.
Then, we have two private methods, one is non-virtual
HTMLEditor::ShowResizers(), and the other is HTMLEditor::ShowResizersInner().
HTMLEditor::ShowResizers() calls HTMLEditor::ShowResizersInner() and if
it fails, calls HideResizers(). However, in some cases, e.g., when it already
has visible resizers, hiding resizers does not make sense.
So, this patch removes non-virtual HTMLEditor::ShowResizers() method too,
then, renames HTMLEditor::ShowResizersInner() to HTMLEditor::ShowResizers(),
finally, it hides resizers only when it fails to setup resizers for keeping
resizers hidden.
Differential Revision: https://phabricator.services.mozilla.com/D4921
--HG--
extra : moz-landing-system : lando
2018-09-06 07:38:00 +03:00
|
|
|
// Let's create and setup resizers. If we failed something, we should
|
|
|
|
// cancel everything which we do in this method.
|
|
|
|
do {
|
|
|
|
mResizedObject = &aResizedElement;
|
2003-02-24 13:18:18 +03:00
|
|
|
|
Bug 1485923 - Remove nsIHTMLObjectResizer.showResizers(), rename HTMLEditor::ShowResizers() to HTMLEditor::ShowResizersInternal() and merge it with HTMLEditor::ShowResizersInner() r=m_kato
First, nobody uses nsIHTMLObjectResizer.showResizers(). So, we can remove it.
Then, we have two private methods, one is non-virtual
HTMLEditor::ShowResizers(), and the other is HTMLEditor::ShowResizersInner().
HTMLEditor::ShowResizers() calls HTMLEditor::ShowResizersInner() and if
it fails, calls HideResizers(). However, in some cases, e.g., when it already
has visible resizers, hiding resizers does not make sense.
So, this patch removes non-virtual HTMLEditor::ShowResizers() method too,
then, renames HTMLEditor::ShowResizersInner() to HTMLEditor::ShowResizers(),
finally, it hides resizers only when it fails to setup resizers for keeping
resizers hidden.
Differential Revision: https://phabricator.services.mozilla.com/D4921
--HG--
extra : moz-landing-system : lando
2018-09-06 07:38:00 +03:00
|
|
|
// The resizers and the shadow will be anonymous siblings of the element.
|
2018-09-11 11:15:52 +03:00
|
|
|
// Note that creating a resizer or shadow may causes calling
|
|
|
|
// HideRisizersInternal() via a mutation event listener. So, we should
|
|
|
|
// store new resizer to a local variable, then, check:
|
|
|
|
// - whether creating resizer is already set to the member or not
|
|
|
|
// - whether resizing element is changed to another element
|
|
|
|
// If showing resizers are canceled, we hit the latter check.
|
|
|
|
// If resizers for another element is shown during this, we hit the latter
|
|
|
|
// check too.
|
|
|
|
// If resizers are just shown again for same element, we hit the former
|
|
|
|
// check.
|
|
|
|
ManualNACPtr newResizer =
|
Bug 1485923 - Remove nsIHTMLObjectResizer.showResizers(), rename HTMLEditor::ShowResizers() to HTMLEditor::ShowResizersInternal() and merge it with HTMLEditor::ShowResizersInner() r=m_kato
First, nobody uses nsIHTMLObjectResizer.showResizers(). So, we can remove it.
Then, we have two private methods, one is non-virtual
HTMLEditor::ShowResizers(), and the other is HTMLEditor::ShowResizersInner().
HTMLEditor::ShowResizers() calls HTMLEditor::ShowResizersInner() and if
it fails, calls HideResizers(). However, in some cases, e.g., when it already
has visible resizers, hiding resizers does not make sense.
So, this patch removes non-virtual HTMLEditor::ShowResizers() method too,
then, renames HTMLEditor::ShowResizersInner() to HTMLEditor::ShowResizers(),
finally, it hides resizers only when it fails to setup resizers for keeping
resizers hidden.
Differential Revision: https://phabricator.services.mozilla.com/D4921
--HG--
extra : moz-landing-system : lando
2018-09-06 07:38:00 +03:00
|
|
|
CreateResizer(nsIHTMLObjectResizer::eTopLeft, *parentContent);
|
2018-09-11 11:15:52 +03:00
|
|
|
if (NS_WARN_IF(!newResizer)) {
|
Bug 1485923 - Remove nsIHTMLObjectResizer.showResizers(), rename HTMLEditor::ShowResizers() to HTMLEditor::ShowResizersInternal() and merge it with HTMLEditor::ShowResizersInner() r=m_kato
First, nobody uses nsIHTMLObjectResizer.showResizers(). So, we can remove it.
Then, we have two private methods, one is non-virtual
HTMLEditor::ShowResizers(), and the other is HTMLEditor::ShowResizersInner().
HTMLEditor::ShowResizers() calls HTMLEditor::ShowResizersInner() and if
it fails, calls HideResizers(). However, in some cases, e.g., when it already
has visible resizers, hiding resizers does not make sense.
So, this patch removes non-virtual HTMLEditor::ShowResizers() method too,
then, renames HTMLEditor::ShowResizersInner() to HTMLEditor::ShowResizers(),
finally, it hides resizers only when it fails to setup resizers for keeping
resizers hidden.
Differential Revision: https://phabricator.services.mozilla.com/D4921
--HG--
extra : moz-landing-system : lando
2018-09-06 07:38:00 +03:00
|
|
|
break;
|
|
|
|
}
|
2018-09-11 11:15:52 +03:00
|
|
|
if (NS_WARN_IF(mTopLeftHandle) ||
|
|
|
|
NS_WARN_IF(mResizedObject != &aResizedElement)) {
|
|
|
|
// Don't hide current resizers in this case because they are not what
|
|
|
|
// we're creating.
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
mTopLeftHandle = std::move(newResizer);
|
|
|
|
newResizer = CreateResizer(nsIHTMLObjectResizer::eTop, *parentContent);
|
|
|
|
if (NS_WARN_IF(!newResizer)) {
|
Bug 1485923 - Remove nsIHTMLObjectResizer.showResizers(), rename HTMLEditor::ShowResizers() to HTMLEditor::ShowResizersInternal() and merge it with HTMLEditor::ShowResizersInner() r=m_kato
First, nobody uses nsIHTMLObjectResizer.showResizers(). So, we can remove it.
Then, we have two private methods, one is non-virtual
HTMLEditor::ShowResizers(), and the other is HTMLEditor::ShowResizersInner().
HTMLEditor::ShowResizers() calls HTMLEditor::ShowResizersInner() and if
it fails, calls HideResizers(). However, in some cases, e.g., when it already
has visible resizers, hiding resizers does not make sense.
So, this patch removes non-virtual HTMLEditor::ShowResizers() method too,
then, renames HTMLEditor::ShowResizersInner() to HTMLEditor::ShowResizers(),
finally, it hides resizers only when it fails to setup resizers for keeping
resizers hidden.
Differential Revision: https://phabricator.services.mozilla.com/D4921
--HG--
extra : moz-landing-system : lando
2018-09-06 07:38:00 +03:00
|
|
|
break;
|
|
|
|
}
|
2018-09-11 11:15:52 +03:00
|
|
|
if (NS_WARN_IF(mTopHandle) ||
|
|
|
|
NS_WARN_IF(mResizedObject != &aResizedElement)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
mTopHandle = std::move(newResizer);
|
|
|
|
newResizer = CreateResizer(nsIHTMLObjectResizer::eTopRight, *parentContent);
|
|
|
|
if (NS_WARN_IF(!newResizer)) {
|
Bug 1485923 - Remove nsIHTMLObjectResizer.showResizers(), rename HTMLEditor::ShowResizers() to HTMLEditor::ShowResizersInternal() and merge it with HTMLEditor::ShowResizersInner() r=m_kato
First, nobody uses nsIHTMLObjectResizer.showResizers(). So, we can remove it.
Then, we have two private methods, one is non-virtual
HTMLEditor::ShowResizers(), and the other is HTMLEditor::ShowResizersInner().
HTMLEditor::ShowResizers() calls HTMLEditor::ShowResizersInner() and if
it fails, calls HideResizers(). However, in some cases, e.g., when it already
has visible resizers, hiding resizers does not make sense.
So, this patch removes non-virtual HTMLEditor::ShowResizers() method too,
then, renames HTMLEditor::ShowResizersInner() to HTMLEditor::ShowResizers(),
finally, it hides resizers only when it fails to setup resizers for keeping
resizers hidden.
Differential Revision: https://phabricator.services.mozilla.com/D4921
--HG--
extra : moz-landing-system : lando
2018-09-06 07:38:00 +03:00
|
|
|
break;
|
|
|
|
}
|
2018-09-11 11:15:52 +03:00
|
|
|
if (NS_WARN_IF(mTopRightHandle) ||
|
|
|
|
NS_WARN_IF(mResizedObject != &aResizedElement)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
mTopRightHandle = std::move(newResizer);
|
2003-06-25 12:50:48 +04:00
|
|
|
|
2018-09-11 11:15:52 +03:00
|
|
|
newResizer = CreateResizer(nsIHTMLObjectResizer::eLeft, *parentContent);
|
|
|
|
if (NS_WARN_IF(!newResizer)) {
|
Bug 1485923 - Remove nsIHTMLObjectResizer.showResizers(), rename HTMLEditor::ShowResizers() to HTMLEditor::ShowResizersInternal() and merge it with HTMLEditor::ShowResizersInner() r=m_kato
First, nobody uses nsIHTMLObjectResizer.showResizers(). So, we can remove it.
Then, we have two private methods, one is non-virtual
HTMLEditor::ShowResizers(), and the other is HTMLEditor::ShowResizersInner().
HTMLEditor::ShowResizers() calls HTMLEditor::ShowResizersInner() and if
it fails, calls HideResizers(). However, in some cases, e.g., when it already
has visible resizers, hiding resizers does not make sense.
So, this patch removes non-virtual HTMLEditor::ShowResizers() method too,
then, renames HTMLEditor::ShowResizersInner() to HTMLEditor::ShowResizers(),
finally, it hides resizers only when it fails to setup resizers for keeping
resizers hidden.
Differential Revision: https://phabricator.services.mozilla.com/D4921
--HG--
extra : moz-landing-system : lando
2018-09-06 07:38:00 +03:00
|
|
|
break;
|
|
|
|
}
|
2018-09-11 11:15:52 +03:00
|
|
|
if (NS_WARN_IF(mLeftHandle) ||
|
|
|
|
NS_WARN_IF(mResizedObject != &aResizedElement)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
mLeftHandle = std::move(newResizer);
|
|
|
|
newResizer = CreateResizer(nsIHTMLObjectResizer::eRight, *parentContent);
|
|
|
|
if (NS_WARN_IF(!newResizer)) {
|
Bug 1485923 - Remove nsIHTMLObjectResizer.showResizers(), rename HTMLEditor::ShowResizers() to HTMLEditor::ShowResizersInternal() and merge it with HTMLEditor::ShowResizersInner() r=m_kato
First, nobody uses nsIHTMLObjectResizer.showResizers(). So, we can remove it.
Then, we have two private methods, one is non-virtual
HTMLEditor::ShowResizers(), and the other is HTMLEditor::ShowResizersInner().
HTMLEditor::ShowResizers() calls HTMLEditor::ShowResizersInner() and if
it fails, calls HideResizers(). However, in some cases, e.g., when it already
has visible resizers, hiding resizers does not make sense.
So, this patch removes non-virtual HTMLEditor::ShowResizers() method too,
then, renames HTMLEditor::ShowResizersInner() to HTMLEditor::ShowResizers(),
finally, it hides resizers only when it fails to setup resizers for keeping
resizers hidden.
Differential Revision: https://phabricator.services.mozilla.com/D4921
--HG--
extra : moz-landing-system : lando
2018-09-06 07:38:00 +03:00
|
|
|
break;
|
|
|
|
}
|
2018-09-11 11:15:52 +03:00
|
|
|
if (NS_WARN_IF(mRightHandle) ||
|
|
|
|
NS_WARN_IF(mResizedObject != &aResizedElement)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
mRightHandle = std::move(newResizer);
|
2003-02-24 13:18:18 +03:00
|
|
|
|
2018-09-11 11:15:52 +03:00
|
|
|
newResizer =
|
Bug 1485923 - Remove nsIHTMLObjectResizer.showResizers(), rename HTMLEditor::ShowResizers() to HTMLEditor::ShowResizersInternal() and merge it with HTMLEditor::ShowResizersInner() r=m_kato
First, nobody uses nsIHTMLObjectResizer.showResizers(). So, we can remove it.
Then, we have two private methods, one is non-virtual
HTMLEditor::ShowResizers(), and the other is HTMLEditor::ShowResizersInner().
HTMLEditor::ShowResizers() calls HTMLEditor::ShowResizersInner() and if
it fails, calls HideResizers(). However, in some cases, e.g., when it already
has visible resizers, hiding resizers does not make sense.
So, this patch removes non-virtual HTMLEditor::ShowResizers() method too,
then, renames HTMLEditor::ShowResizersInner() to HTMLEditor::ShowResizers(),
finally, it hides resizers only when it fails to setup resizers for keeping
resizers hidden.
Differential Revision: https://phabricator.services.mozilla.com/D4921
--HG--
extra : moz-landing-system : lando
2018-09-06 07:38:00 +03:00
|
|
|
CreateResizer(nsIHTMLObjectResizer::eBottomLeft, *parentContent);
|
2018-09-11 11:15:52 +03:00
|
|
|
if (NS_WARN_IF(!newResizer)) {
|
Bug 1485923 - Remove nsIHTMLObjectResizer.showResizers(), rename HTMLEditor::ShowResizers() to HTMLEditor::ShowResizersInternal() and merge it with HTMLEditor::ShowResizersInner() r=m_kato
First, nobody uses nsIHTMLObjectResizer.showResizers(). So, we can remove it.
Then, we have two private methods, one is non-virtual
HTMLEditor::ShowResizers(), and the other is HTMLEditor::ShowResizersInner().
HTMLEditor::ShowResizers() calls HTMLEditor::ShowResizersInner() and if
it fails, calls HideResizers(). However, in some cases, e.g., when it already
has visible resizers, hiding resizers does not make sense.
So, this patch removes non-virtual HTMLEditor::ShowResizers() method too,
then, renames HTMLEditor::ShowResizersInner() to HTMLEditor::ShowResizers(),
finally, it hides resizers only when it fails to setup resizers for keeping
resizers hidden.
Differential Revision: https://phabricator.services.mozilla.com/D4921
--HG--
extra : moz-landing-system : lando
2018-09-06 07:38:00 +03:00
|
|
|
break;
|
|
|
|
}
|
2018-09-11 11:15:52 +03:00
|
|
|
if (NS_WARN_IF(mBottomLeftHandle) ||
|
|
|
|
NS_WARN_IF(mResizedObject != &aResizedElement)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
mBottomLeftHandle = std::move(newResizer);
|
|
|
|
newResizer = CreateResizer(nsIHTMLObjectResizer::eBottom, *parentContent);
|
|
|
|
if (NS_WARN_IF(!newResizer)) {
|
Bug 1485923 - Remove nsIHTMLObjectResizer.showResizers(), rename HTMLEditor::ShowResizers() to HTMLEditor::ShowResizersInternal() and merge it with HTMLEditor::ShowResizersInner() r=m_kato
First, nobody uses nsIHTMLObjectResizer.showResizers(). So, we can remove it.
Then, we have two private methods, one is non-virtual
HTMLEditor::ShowResizers(), and the other is HTMLEditor::ShowResizersInner().
HTMLEditor::ShowResizers() calls HTMLEditor::ShowResizersInner() and if
it fails, calls HideResizers(). However, in some cases, e.g., when it already
has visible resizers, hiding resizers does not make sense.
So, this patch removes non-virtual HTMLEditor::ShowResizers() method too,
then, renames HTMLEditor::ShowResizersInner() to HTMLEditor::ShowResizers(),
finally, it hides resizers only when it fails to setup resizers for keeping
resizers hidden.
Differential Revision: https://phabricator.services.mozilla.com/D4921
--HG--
extra : moz-landing-system : lando
2018-09-06 07:38:00 +03:00
|
|
|
break;
|
|
|
|
}
|
2018-09-11 11:15:52 +03:00
|
|
|
if (NS_WARN_IF(mBottomHandle) ||
|
|
|
|
NS_WARN_IF(mResizedObject != &aResizedElement)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
mBottomHandle = std::move(newResizer);
|
|
|
|
newResizer =
|
Bug 1485923 - Remove nsIHTMLObjectResizer.showResizers(), rename HTMLEditor::ShowResizers() to HTMLEditor::ShowResizersInternal() and merge it with HTMLEditor::ShowResizersInner() r=m_kato
First, nobody uses nsIHTMLObjectResizer.showResizers(). So, we can remove it.
Then, we have two private methods, one is non-virtual
HTMLEditor::ShowResizers(), and the other is HTMLEditor::ShowResizersInner().
HTMLEditor::ShowResizers() calls HTMLEditor::ShowResizersInner() and if
it fails, calls HideResizers(). However, in some cases, e.g., when it already
has visible resizers, hiding resizers does not make sense.
So, this patch removes non-virtual HTMLEditor::ShowResizers() method too,
then, renames HTMLEditor::ShowResizersInner() to HTMLEditor::ShowResizers(),
finally, it hides resizers only when it fails to setup resizers for keeping
resizers hidden.
Differential Revision: https://phabricator.services.mozilla.com/D4921
--HG--
extra : moz-landing-system : lando
2018-09-06 07:38:00 +03:00
|
|
|
CreateResizer(nsIHTMLObjectResizer::eBottomRight, *parentContent);
|
2018-09-11 11:15:52 +03:00
|
|
|
if (NS_WARN_IF(!newResizer)) {
|
Bug 1485923 - Remove nsIHTMLObjectResizer.showResizers(), rename HTMLEditor::ShowResizers() to HTMLEditor::ShowResizersInternal() and merge it with HTMLEditor::ShowResizersInner() r=m_kato
First, nobody uses nsIHTMLObjectResizer.showResizers(). So, we can remove it.
Then, we have two private methods, one is non-virtual
HTMLEditor::ShowResizers(), and the other is HTMLEditor::ShowResizersInner().
HTMLEditor::ShowResizers() calls HTMLEditor::ShowResizersInner() and if
it fails, calls HideResizers(). However, in some cases, e.g., when it already
has visible resizers, hiding resizers does not make sense.
So, this patch removes non-virtual HTMLEditor::ShowResizers() method too,
then, renames HTMLEditor::ShowResizersInner() to HTMLEditor::ShowResizers(),
finally, it hides resizers only when it fails to setup resizers for keeping
resizers hidden.
Differential Revision: https://phabricator.services.mozilla.com/D4921
--HG--
extra : moz-landing-system : lando
2018-09-06 07:38:00 +03:00
|
|
|
break;
|
|
|
|
}
|
2018-09-11 11:15:52 +03:00
|
|
|
if (NS_WARN_IF(mBottomRightHandle) ||
|
|
|
|
NS_WARN_IF(mResizedObject != &aResizedElement)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
mBottomRightHandle = std::move(newResizer);
|
|
|
|
|
|
|
|
// Store the last resizer which we created. This is useful when we
|
|
|
|
// need to check whether our resizers are hiddedn and recreated another
|
|
|
|
// set of resizers or not.
|
|
|
|
RefPtr<Element> createdBottomRightNalde = mBottomRightHandle.get();
|
|
|
|
|
|
|
|
nsresult rv = GetPositionAndDimensions(aResizedElement,
|
|
|
|
mResizedObjectX,
|
|
|
|
mResizedObjectY,
|
|
|
|
mResizedObjectWidth,
|
|
|
|
mResizedObjectHeight,
|
|
|
|
mResizedObjectBorderLeft,
|
|
|
|
mResizedObjectBorderTop,
|
|
|
|
mResizedObjectMarginLeft,
|
|
|
|
mResizedObjectMarginTop);
|
Bug 1485923 - Remove nsIHTMLObjectResizer.showResizers(), rename HTMLEditor::ShowResizers() to HTMLEditor::ShowResizersInternal() and merge it with HTMLEditor::ShowResizersInner() r=m_kato
First, nobody uses nsIHTMLObjectResizer.showResizers(). So, we can remove it.
Then, we have two private methods, one is non-virtual
HTMLEditor::ShowResizers(), and the other is HTMLEditor::ShowResizersInner().
HTMLEditor::ShowResizers() calls HTMLEditor::ShowResizersInner() and if
it fails, calls HideResizers(). However, in some cases, e.g., when it already
has visible resizers, hiding resizers does not make sense.
So, this patch removes non-virtual HTMLEditor::ShowResizers() method too,
then, renames HTMLEditor::ShowResizersInner() to HTMLEditor::ShowResizers(),
finally, it hides resizers only when it fails to setup resizers for keeping
resizers hidden.
Differential Revision: https://phabricator.services.mozilla.com/D4921
--HG--
extra : moz-landing-system : lando
2018-09-06 07:38:00 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
break;
|
|
|
|
}
|
2003-02-24 13:18:18 +03:00
|
|
|
|
Bug 1485923 - Remove nsIHTMLObjectResizer.showResizers(), rename HTMLEditor::ShowResizers() to HTMLEditor::ShowResizersInternal() and merge it with HTMLEditor::ShowResizersInner() r=m_kato
First, nobody uses nsIHTMLObjectResizer.showResizers(). So, we can remove it.
Then, we have two private methods, one is non-virtual
HTMLEditor::ShowResizers(), and the other is HTMLEditor::ShowResizersInner().
HTMLEditor::ShowResizers() calls HTMLEditor::ShowResizersInner() and if
it fails, calls HideResizers(). However, in some cases, e.g., when it already
has visible resizers, hiding resizers does not make sense.
So, this patch removes non-virtual HTMLEditor::ShowResizers() method too,
then, renames HTMLEditor::ShowResizersInner() to HTMLEditor::ShowResizers(),
finally, it hides resizers only when it fails to setup resizers for keeping
resizers hidden.
Differential Revision: https://phabricator.services.mozilla.com/D4921
--HG--
extra : moz-landing-system : lando
2018-09-06 07:38:00 +03:00
|
|
|
// and let's set their absolute positions in the document
|
|
|
|
rv = SetAllResizersPosition();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2018-09-11 11:15:52 +03:00
|
|
|
if (NS_WARN_IF(mBottomRightHandle.get() != createdBottomRightNalde)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
Bug 1485923 - Remove nsIHTMLObjectResizer.showResizers(), rename HTMLEditor::ShowResizers() to HTMLEditor::ShowResizersInternal() and merge it with HTMLEditor::ShowResizersInner() r=m_kato
First, nobody uses nsIHTMLObjectResizer.showResizers(). So, we can remove it.
Then, we have two private methods, one is non-virtual
HTMLEditor::ShowResizers(), and the other is HTMLEditor::ShowResizersInner().
HTMLEditor::ShowResizers() calls HTMLEditor::ShowResizersInner() and if
it fails, calls HideResizers(). However, in some cases, e.g., when it already
has visible resizers, hiding resizers does not make sense.
So, this patch removes non-virtual HTMLEditor::ShowResizers() method too,
then, renames HTMLEditor::ShowResizersInner() to HTMLEditor::ShowResizers(),
finally, it hides resizers only when it fails to setup resizers for keeping
resizers hidden.
Differential Revision: https://phabricator.services.mozilla.com/D4921
--HG--
extra : moz-landing-system : lando
2018-09-06 07:38:00 +03:00
|
|
|
break;
|
|
|
|
}
|
2003-02-24 13:18:18 +03:00
|
|
|
|
Bug 1485923 - Remove nsIHTMLObjectResizer.showResizers(), rename HTMLEditor::ShowResizers() to HTMLEditor::ShowResizersInternal() and merge it with HTMLEditor::ShowResizersInner() r=m_kato
First, nobody uses nsIHTMLObjectResizer.showResizers(). So, we can remove it.
Then, we have two private methods, one is non-virtual
HTMLEditor::ShowResizers(), and the other is HTMLEditor::ShowResizersInner().
HTMLEditor::ShowResizers() calls HTMLEditor::ShowResizersInner() and if
it fails, calls HideResizers(). However, in some cases, e.g., when it already
has visible resizers, hiding resizers does not make sense.
So, this patch removes non-virtual HTMLEditor::ShowResizers() method too,
then, renames HTMLEditor::ShowResizersInner() to HTMLEditor::ShowResizers(),
finally, it hides resizers only when it fails to setup resizers for keeping
resizers hidden.
Differential Revision: https://phabricator.services.mozilla.com/D4921
--HG--
extra : moz-landing-system : lando
2018-09-06 07:38:00 +03:00
|
|
|
// now, let's create the resizing shadow
|
2018-09-11 11:15:52 +03:00
|
|
|
ManualNACPtr newShadow = CreateShadow(*parentContent, aResizedElement);
|
|
|
|
if (NS_WARN_IF(!newShadow)) {
|
Bug 1485923 - Remove nsIHTMLObjectResizer.showResizers(), rename HTMLEditor::ShowResizers() to HTMLEditor::ShowResizersInternal() and merge it with HTMLEditor::ShowResizersInner() r=m_kato
First, nobody uses nsIHTMLObjectResizer.showResizers(). So, we can remove it.
Then, we have two private methods, one is non-virtual
HTMLEditor::ShowResizers(), and the other is HTMLEditor::ShowResizersInner().
HTMLEditor::ShowResizers() calls HTMLEditor::ShowResizersInner() and if
it fails, calls HideResizers(). However, in some cases, e.g., when it already
has visible resizers, hiding resizers does not make sense.
So, this patch removes non-virtual HTMLEditor::ShowResizers() method too,
then, renames HTMLEditor::ShowResizersInner() to HTMLEditor::ShowResizers(),
finally, it hides resizers only when it fails to setup resizers for keeping
resizers hidden.
Differential Revision: https://phabricator.services.mozilla.com/D4921
--HG--
extra : moz-landing-system : lando
2018-09-06 07:38:00 +03:00
|
|
|
break;
|
|
|
|
}
|
2018-09-11 11:15:52 +03:00
|
|
|
if (NS_WARN_IF(mResizingShadow) ||
|
|
|
|
NS_WARN_IF(mResizedObject != &aResizedElement)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
mResizingShadow = std::move(newShadow);
|
|
|
|
|
Bug 1485923 - Remove nsIHTMLObjectResizer.showResizers(), rename HTMLEditor::ShowResizers() to HTMLEditor::ShowResizersInternal() and merge it with HTMLEditor::ShowResizersInner() r=m_kato
First, nobody uses nsIHTMLObjectResizer.showResizers(). So, we can remove it.
Then, we have two private methods, one is non-virtual
HTMLEditor::ShowResizers(), and the other is HTMLEditor::ShowResizersInner().
HTMLEditor::ShowResizers() calls HTMLEditor::ShowResizersInner() and if
it fails, calls HideResizers(). However, in some cases, e.g., when it already
has visible resizers, hiding resizers does not make sense.
So, this patch removes non-virtual HTMLEditor::ShowResizers() method too,
then, renames HTMLEditor::ShowResizersInner() to HTMLEditor::ShowResizers(),
finally, it hides resizers only when it fails to setup resizers for keeping
resizers hidden.
Differential Revision: https://phabricator.services.mozilla.com/D4921
--HG--
extra : moz-landing-system : lando
2018-09-06 07:38:00 +03:00
|
|
|
// and set its position
|
2018-09-11 11:15:52 +03:00
|
|
|
rv = SetShadowPosition(*mResizingShadow, aResizedElement,
|
Bug 1485923 - Remove nsIHTMLObjectResizer.showResizers(), rename HTMLEditor::ShowResizers() to HTMLEditor::ShowResizersInternal() and merge it with HTMLEditor::ShowResizersInner() r=m_kato
First, nobody uses nsIHTMLObjectResizer.showResizers(). So, we can remove it.
Then, we have two private methods, one is non-virtual
HTMLEditor::ShowResizers(), and the other is HTMLEditor::ShowResizersInner().
HTMLEditor::ShowResizers() calls HTMLEditor::ShowResizersInner() and if
it fails, calls HideResizers(). However, in some cases, e.g., when it already
has visible resizers, hiding resizers does not make sense.
So, this patch removes non-virtual HTMLEditor::ShowResizers() method too,
then, renames HTMLEditor::ShowResizersInner() to HTMLEditor::ShowResizers(),
finally, it hides resizers only when it fails to setup resizers for keeping
resizers hidden.
Differential Revision: https://phabricator.services.mozilla.com/D4921
--HG--
extra : moz-landing-system : lando
2018-09-06 07:38:00 +03:00
|
|
|
mResizedObjectX, mResizedObjectY);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2018-09-11 11:15:52 +03:00
|
|
|
if (NS_WARN_IF(mBottomRightHandle.get() != createdBottomRightNalde)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
Bug 1485923 - Remove nsIHTMLObjectResizer.showResizers(), rename HTMLEditor::ShowResizers() to HTMLEditor::ShowResizersInternal() and merge it with HTMLEditor::ShowResizersInner() r=m_kato
First, nobody uses nsIHTMLObjectResizer.showResizers(). So, we can remove it.
Then, we have two private methods, one is non-virtual
HTMLEditor::ShowResizers(), and the other is HTMLEditor::ShowResizersInner().
HTMLEditor::ShowResizers() calls HTMLEditor::ShowResizersInner() and if
it fails, calls HideResizers(). However, in some cases, e.g., when it already
has visible resizers, hiding resizers does not make sense.
So, this patch removes non-virtual HTMLEditor::ShowResizers() method too,
then, renames HTMLEditor::ShowResizersInner() to HTMLEditor::ShowResizers(),
finally, it hides resizers only when it fails to setup resizers for keeping
resizers hidden.
Differential Revision: https://phabricator.services.mozilla.com/D4921
--HG--
extra : moz-landing-system : lando
2018-09-06 07:38:00 +03:00
|
|
|
break;
|
|
|
|
}
|
2003-02-24 13:18:18 +03:00
|
|
|
|
Bug 1485923 - Remove nsIHTMLObjectResizer.showResizers(), rename HTMLEditor::ShowResizers() to HTMLEditor::ShowResizersInternal() and merge it with HTMLEditor::ShowResizersInner() r=m_kato
First, nobody uses nsIHTMLObjectResizer.showResizers(). So, we can remove it.
Then, we have two private methods, one is non-virtual
HTMLEditor::ShowResizers(), and the other is HTMLEditor::ShowResizersInner().
HTMLEditor::ShowResizers() calls HTMLEditor::ShowResizersInner() and if
it fails, calls HideResizers(). However, in some cases, e.g., when it already
has visible resizers, hiding resizers does not make sense.
So, this patch removes non-virtual HTMLEditor::ShowResizers() method too,
then, renames HTMLEditor::ShowResizersInner() to HTMLEditor::ShowResizers(),
finally, it hides resizers only when it fails to setup resizers for keeping
resizers hidden.
Differential Revision: https://phabricator.services.mozilla.com/D4921
--HG--
extra : moz-landing-system : lando
2018-09-06 07:38:00 +03:00
|
|
|
// and then the resizing info tooltip
|
2018-09-11 11:15:52 +03:00
|
|
|
ManualNACPtr newResizingInfo = CreateResizingInfo(*parentContent);
|
|
|
|
if (NS_WARN_IF(!newResizingInfo)) {
|
Bug 1485923 - Remove nsIHTMLObjectResizer.showResizers(), rename HTMLEditor::ShowResizers() to HTMLEditor::ShowResizersInternal() and merge it with HTMLEditor::ShowResizersInner() r=m_kato
First, nobody uses nsIHTMLObjectResizer.showResizers(). So, we can remove it.
Then, we have two private methods, one is non-virtual
HTMLEditor::ShowResizers(), and the other is HTMLEditor::ShowResizersInner().
HTMLEditor::ShowResizers() calls HTMLEditor::ShowResizersInner() and if
it fails, calls HideResizers(). However, in some cases, e.g., when it already
has visible resizers, hiding resizers does not make sense.
So, this patch removes non-virtual HTMLEditor::ShowResizers() method too,
then, renames HTMLEditor::ShowResizersInner() to HTMLEditor::ShowResizers(),
finally, it hides resizers only when it fails to setup resizers for keeping
resizers hidden.
Differential Revision: https://phabricator.services.mozilla.com/D4921
--HG--
extra : moz-landing-system : lando
2018-09-06 07:38:00 +03:00
|
|
|
break;
|
|
|
|
}
|
2018-09-11 11:15:52 +03:00
|
|
|
if (NS_WARN_IF(mResizingInfo) ||
|
|
|
|
NS_WARN_IF(mResizedObject != &aResizedElement)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
mResizingInfo = std::move(newResizingInfo);
|
2003-02-24 13:18:18 +03:00
|
|
|
|
Bug 1485923 - Remove nsIHTMLObjectResizer.showResizers(), rename HTMLEditor::ShowResizers() to HTMLEditor::ShowResizersInternal() and merge it with HTMLEditor::ShowResizersInner() r=m_kato
First, nobody uses nsIHTMLObjectResizer.showResizers(). So, we can remove it.
Then, we have two private methods, one is non-virtual
HTMLEditor::ShowResizers(), and the other is HTMLEditor::ShowResizersInner().
HTMLEditor::ShowResizers() calls HTMLEditor::ShowResizersInner() and if
it fails, calls HideResizers(). However, in some cases, e.g., when it already
has visible resizers, hiding resizers does not make sense.
So, this patch removes non-virtual HTMLEditor::ShowResizers() method too,
then, renames HTMLEditor::ShowResizersInner() to HTMLEditor::ShowResizers(),
finally, it hides resizers only when it fails to setup resizers for keeping
resizers hidden.
Differential Revision: https://phabricator.services.mozilla.com/D4921
--HG--
extra : moz-landing-system : lando
2018-09-06 07:38:00 +03:00
|
|
|
// and listen to the "resize" event on the window first, get the
|
|
|
|
// window from the document...
|
2018-11-06 07:58:29 +03:00
|
|
|
if (NS_WARN_IF(!mEventListener)) {
|
Bug 1485923 - Remove nsIHTMLObjectResizer.showResizers(), rename HTMLEditor::ShowResizers() to HTMLEditor::ShowResizersInternal() and merge it with HTMLEditor::ShowResizersInner() r=m_kato
First, nobody uses nsIHTMLObjectResizer.showResizers(). So, we can remove it.
Then, we have two private methods, one is non-virtual
HTMLEditor::ShowResizers(), and the other is HTMLEditor::ShowResizersInner().
HTMLEditor::ShowResizers() calls HTMLEditor::ShowResizersInner() and if
it fails, calls HideResizers(). However, in some cases, e.g., when it already
has visible resizers, hiding resizers does not make sense.
So, this patch removes non-virtual HTMLEditor::ShowResizers() method too,
then, renames HTMLEditor::ShowResizersInner() to HTMLEditor::ShowResizers(),
finally, it hides resizers only when it fails to setup resizers for keeping
resizers hidden.
Differential Revision: https://phabricator.services.mozilla.com/D4921
--HG--
extra : moz-landing-system : lando
2018-09-06 07:38:00 +03:00
|
|
|
break;
|
|
|
|
}
|
2017-08-07 08:09:51 +03:00
|
|
|
|
2018-11-06 07:58:29 +03:00
|
|
|
rv = static_cast<HTMLEditorEventListener*>(mEventListener.get())->
|
|
|
|
ListenToWindowResizeEvent(true);
|
Bug 1485923 - Remove nsIHTMLObjectResizer.showResizers(), rename HTMLEditor::ShowResizers() to HTMLEditor::ShowResizersInternal() and merge it with HTMLEditor::ShowResizersInner() r=m_kato
First, nobody uses nsIHTMLObjectResizer.showResizers(). So, we can remove it.
Then, we have two private methods, one is non-virtual
HTMLEditor::ShowResizers(), and the other is HTMLEditor::ShowResizersInner().
HTMLEditor::ShowResizers() calls HTMLEditor::ShowResizersInner() and if
it fails, calls HideResizers(). However, in some cases, e.g., when it already
has visible resizers, hiding resizers does not make sense.
So, this patch removes non-virtual HTMLEditor::ShowResizers() method too,
then, renames HTMLEditor::ShowResizersInner() to HTMLEditor::ShowResizers(),
finally, it hides resizers only when it fails to setup resizers for keeping
resizers hidden.
Differential Revision: https://phabricator.services.mozilla.com/D4921
--HG--
extra : moz-landing-system : lando
2018-09-06 07:38:00 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
break;
|
|
|
|
}
|
2017-08-07 08:09:51 +03:00
|
|
|
|
Bug 1485923 - Remove nsIHTMLObjectResizer.showResizers(), rename HTMLEditor::ShowResizers() to HTMLEditor::ShowResizersInternal() and merge it with HTMLEditor::ShowResizersInner() r=m_kato
First, nobody uses nsIHTMLObjectResizer.showResizers(). So, we can remove it.
Then, we have two private methods, one is non-virtual
HTMLEditor::ShowResizers(), and the other is HTMLEditor::ShowResizersInner().
HTMLEditor::ShowResizers() calls HTMLEditor::ShowResizersInner() and if
it fails, calls HideResizers(). However, in some cases, e.g., when it already
has visible resizers, hiding resizers does not make sense.
So, this patch removes non-virtual HTMLEditor::ShowResizers() method too,
then, renames HTMLEditor::ShowResizersInner() to HTMLEditor::ShowResizers(),
finally, it hides resizers only when it fails to setup resizers for keeping
resizers hidden.
Differential Revision: https://phabricator.services.mozilla.com/D4921
--HG--
extra : moz-landing-system : lando
2018-09-06 07:38:00 +03:00
|
|
|
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
|
|
|
|
Bug 1485923 - Remove nsIHTMLObjectResizer.showResizers(), rename HTMLEditor::ShowResizers() to HTMLEditor::ShowResizersInternal() and merge it with HTMLEditor::ShowResizersInner() r=m_kato
First, nobody uses nsIHTMLObjectResizer.showResizers(). So, we can remove it.
Then, we have two private methods, one is non-virtual
HTMLEditor::ShowResizers(), and the other is HTMLEditor::ShowResizersInner().
HTMLEditor::ShowResizers() calls HTMLEditor::ShowResizersInner() and if
it fails, calls HideResizers(). However, in some cases, e.g., when it already
has visible resizers, hiding resizers does not make sense.
So, this patch removes non-virtual HTMLEditor::ShowResizers() method too,
then, renames HTMLEditor::ShowResizersInner() to HTMLEditor::ShowResizers(),
finally, it hides resizers only when it fails to setup resizers for keeping
resizers hidden.
Differential Revision: https://phabricator.services.mozilla.com/D4921
--HG--
extra : moz-landing-system : lando
2018-09-06 07:38:00 +03:00
|
|
|
mHasShownResizers = true;
|
|
|
|
|
|
|
|
// XXX Even when it failed to add event listener, should we need to set
|
|
|
|
// _moz_resizing attribute?
|
|
|
|
aResizedElement.SetAttr(kNameSpaceID_None, nsGkAtoms::_moz_resizing,
|
|
|
|
NS_LITERAL_STRING("true"), true);
|
|
|
|
return NS_OK;
|
|
|
|
} while (true);
|
|
|
|
|
2018-09-06 08:02:46 +03:00
|
|
|
DebugOnly<nsresult> rv = HideResizersInternal();
|
Bug 1485923 - Remove nsIHTMLObjectResizer.showResizers(), rename HTMLEditor::ShowResizers() to HTMLEditor::ShowResizersInternal() and merge it with HTMLEditor::ShowResizersInner() r=m_kato
First, nobody uses nsIHTMLObjectResizer.showResizers(). So, we can remove it.
Then, we have two private methods, one is non-virtual
HTMLEditor::ShowResizers(), and the other is HTMLEditor::ShowResizersInner().
HTMLEditor::ShowResizers() calls HTMLEditor::ShowResizersInner() and if
it fails, calls HideResizers(). However, in some cases, e.g., when it already
has visible resizers, hiding resizers does not make sense.
So, this patch removes non-virtual HTMLEditor::ShowResizers() method too,
then, renames HTMLEditor::ShowResizersInner() to HTMLEditor::ShowResizers(),
finally, it hides resizers only when it fails to setup resizers for keeping
resizers hidden.
Differential Revision: https://phabricator.services.mozilla.com/D4921
--HG--
extra : moz-landing-system : lando
2018-09-06 07:38:00 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"Failed to clean up unnecessary resizers");
|
|
|
|
return NS_ERROR_FAILURE;
|
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()
|
2018-09-06 08:02:46 +03:00
|
|
|
{
|
2018-10-30 13:00:17 +03:00
|
|
|
AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing);
|
|
|
|
if (NS_WARN_IF(!editActionData.CanHandle())) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
|
2018-09-06 08:02:46 +03:00
|
|
|
nsresult rv = HideResizersInternal();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
HTMLEditor::HideResizersInternal()
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
2018-09-11 08:02:30 +03:00
|
|
|
// Don't warn even if resizers are visible since script cannot check
|
|
|
|
// if they are visible and this is non-virtual method. So, the cost of
|
|
|
|
// calling this can be ignored.
|
|
|
|
if (!mResizedObject) {
|
2018-08-24 06:46:18 +03:00
|
|
|
return 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.
|
2018-08-24 06:46:18 +03:00
|
|
|
nsCOMPtr<nsIPresShell> presShell = GetPresShell();
|
|
|
|
NS_WARNING_ASSERTION(presShell, "There is no presShell");
|
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
|
|
|
|
2018-08-24 09:27:48 +03:00
|
|
|
// HTMLEditor should forget all members related to resizers first since
|
|
|
|
// removing a part of UI may cause showing the resizers again. In such
|
|
|
|
// case, the members may be overwritten by ShowResizers() and this will
|
|
|
|
// lose the chance to release the old resizers.
|
|
|
|
ManualNACPtr topLeftHandle(std::move(mTopLeftHandle));
|
|
|
|
ManualNACPtr topHandle(std::move(mTopHandle));
|
|
|
|
ManualNACPtr topRightHandle(std::move(mTopRightHandle));
|
|
|
|
ManualNACPtr leftHandle(std::move(mLeftHandle));
|
|
|
|
ManualNACPtr rightHandle(std::move(mRightHandle));
|
|
|
|
ManualNACPtr bottomLeftHandle(std::move(mBottomLeftHandle));
|
|
|
|
ManualNACPtr bottomHandle(std::move(mBottomHandle));
|
|
|
|
ManualNACPtr bottomRightHandle(std::move(mBottomRightHandle));
|
|
|
|
ManualNACPtr resizingShadow(std::move(mResizingShadow));
|
|
|
|
ManualNACPtr resizingInfo(std::move(mResizingInfo));
|
|
|
|
RefPtr<Element> activatedHandle(std::move(mActivatedHandle));
|
|
|
|
RefPtr<Element> resizedObject(std::move(mResizedObject));
|
|
|
|
|
|
|
|
// Remvoe all handles.
|
2011-10-17 18:59:28 +04:00
|
|
|
RemoveListenerAndDeleteRef(mousedown, mEventListener, true,
|
2018-08-24 09:27:48 +03:00
|
|
|
std::move(topLeftHandle), presShell);
|
2006-06-15 11:31:01 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
RemoveListenerAndDeleteRef(mousedown, mEventListener, true,
|
2018-08-24 09:27:48 +03:00
|
|
|
std::move(topHandle), presShell);
|
2006-06-15 11:31:01 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
RemoveListenerAndDeleteRef(mousedown, mEventListener, true,
|
2018-08-24 09:27:48 +03:00
|
|
|
std::move(topRightHandle), presShell);
|
2006-06-15 11:31:01 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
RemoveListenerAndDeleteRef(mousedown, mEventListener, true,
|
2018-08-24 09:27:48 +03:00
|
|
|
std::move(leftHandle), presShell);
|
2006-06-15 11:31:01 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
RemoveListenerAndDeleteRef(mousedown, mEventListener, true,
|
2018-08-24 09:27:48 +03:00
|
|
|
std::move(rightHandle), presShell);
|
2006-06-15 11:31:01 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
RemoveListenerAndDeleteRef(mousedown, mEventListener, true,
|
2018-08-24 09:27:48 +03:00
|
|
|
std::move(bottomLeftHandle), presShell);
|
2006-06-15 11:31:01 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
RemoveListenerAndDeleteRef(mousedown, mEventListener, true,
|
2018-08-24 09:27:48 +03:00
|
|
|
std::move(bottomHandle), presShell);
|
2006-06-15 11:31:01 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
RemoveListenerAndDeleteRef(mousedown, mEventListener, true,
|
2018-08-24 09:27:48 +03:00
|
|
|
std::move(bottomRightHandle), presShell);
|
2006-06-15 11:31:01 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
RemoveListenerAndDeleteRef(mousedown, mEventListener, true,
|
2018-08-24 09:27:48 +03:00
|
|
|
std::move(resizingShadow), presShell);
|
2006-06-15 11:31:01 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
RemoveListenerAndDeleteRef(mousedown, mEventListener, true,
|
2018-08-24 09:27:48 +03:00
|
|
|
std::move(resizingInfo), presShell);
|
2003-02-24 13:18:18 +03:00
|
|
|
|
2018-08-24 09:27:48 +03:00
|
|
|
// Remove active state of a resizer.
|
|
|
|
if (activatedHandle) {
|
|
|
|
activatedHandle->UnsetAttr(kNameSpaceID_None, nsGkAtoms::_moz_activated,
|
|
|
|
true);
|
2008-04-14 00:22:31 +04:00
|
|
|
}
|
|
|
|
|
2018-08-24 09:27:48 +03:00
|
|
|
// Remove resizing state of the target element.
|
|
|
|
resizedObject->UnsetAttr(kNameSpaceID_None, nsGkAtoms::_moz_resizing, true);
|
2003-02-24 13:18:18 +03:00
|
|
|
|
2018-11-06 09:09:18 +03:00
|
|
|
if (!mEventListener) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2003-03-25 18:24:08 +03:00
|
|
|
|
2018-11-06 09:09:18 +03:00
|
|
|
nsresult rv =
|
|
|
|
static_cast<HTMLEditorEventListener*>(mEventListener.get())->
|
|
|
|
ListenToMouseMoveEventForResizers(false);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
2018-08-24 09:27:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remove resize event listener from the window.
|
2018-11-06 07:58:29 +03:00
|
|
|
if (!mEventListener) {
|
2018-08-24 09:27:48 +03:00
|
|
|
return NS_OK;
|
2003-03-25 18:24:08 +03:00
|
|
|
}
|
2003-02-24 13:18:18 +03:00
|
|
|
|
2018-11-06 09:09:18 +03:00
|
|
|
rv = static_cast<HTMLEditorEventListener*>(mEventListener.get())->
|
|
|
|
ListenToWindowResizeEvent(false);
|
2018-11-06 07:58:29 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
2018-08-24 09:27:48 +03:00
|
|
|
}
|
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
|
2018-11-06 09:09:18 +03:00
|
|
|
if (NS_WARN_IF(!mEventListener)) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2003-02-24 13:18:18 +03:00
|
|
|
}
|
2018-11-06 09:09:18 +03:00
|
|
|
nsresult rv =
|
|
|
|
static_cast<HTMLEditorEventListener*>(mEventListener.get())->
|
|
|
|
ListenToMouseMoveEventForResizers(true);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2003-02-24 13:18:18 +03:00
|
|
|
}
|
|
|
|
|
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")) {
|
2018-10-30 13:00:17 +03:00
|
|
|
AutoEditActionDataSetter editActionData(*this, EditAction::eResizeElement);
|
|
|
|
if (NS_WARN_IF(!editActionData.CanHandle())) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
|
2018-01-30 07:27:59 +03:00
|
|
|
// 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")) {
|
2018-10-30 13:00:17 +03:00
|
|
|
AutoEditActionDataSetter editActionData(*this, EditAction::eMoveElement);
|
|
|
|
if (NS_WARN_IF(!editActionData.CanHandle())) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
|
2018-01-30 07:27:59 +03:00
|
|
|
// 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) {
|
2018-10-30 13:00:17 +03:00
|
|
|
AutoEditActionDataSetter editActionData(*this, EditAction::eResizeElement);
|
|
|
|
if (NS_WARN_IF(!editActionData.CanHandle())) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
|
2003-02-24 13:18:18 +03:00
|
|
|
// 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) {
|
2018-10-30 13:00:17 +03:00
|
|
|
AutoEditActionDataSetter editActionData(*this, EditAction::eMoveElement);
|
|
|
|
if (NS_WARN_IF(!editActionData.CanHandle())) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
|
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
|
2018-09-11 11:15:52 +03:00
|
|
|
HTMLEditor::SetShadowPosition(Element& aShadowElement,
|
|
|
|
Element& aElement,
|
|
|
|
int32_t aElementX,
|
|
|
|
int32_t aElementY)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
2018-09-11 11:15:52 +03:00
|
|
|
MOZ_ASSERT(&aShadowElement == mResizingShadow ||
|
|
|
|
&aShadowElement == mPositioningShadow);
|
|
|
|
RefPtr<Element> handlingShadowElement =
|
|
|
|
&aShadowElement == mResizingShadow ?
|
|
|
|
mResizingShadow.get() : mPositioningShadow.get();
|
|
|
|
|
|
|
|
SetAnonymousElementPosition(aElementX, aElementY, &aShadowElement);
|
|
|
|
if (NS_WARN_IF(&aShadowElement != handlingShadowElement)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2003-02-24 13:18:18 +03:00
|
|
|
|
2018-09-11 11:15:52 +03:00
|
|
|
if (!HTMLEditUtils::IsImage(&aElement)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString imageSource;
|
|
|
|
aElement.GetAttr(kNameSpaceID_None, nsGkAtoms::src, imageSource);
|
|
|
|
nsresult rv = aShadowElement.SetAttr(kNameSpaceID_None, nsGkAtoms::src,
|
|
|
|
imageSource, true);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv)) ||
|
|
|
|
NS_WARN_IF(&aShadowElement != handlingShadowElement)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
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) {
|
2018-10-30 13:00:17 +03:00
|
|
|
AutoEditActionDataSetter editActionData(*this, EditAction::eResizeElement);
|
|
|
|
if (NS_WARN_IF(!editActionData.CanHandle())) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
|
2003-02-24 13:18:18 +03:00
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2018-10-30 13:00:17 +03:00
|
|
|
AutoEditActionDataSetter editActionData(*this, EditAction::eMoveElement);
|
|
|
|
if (NS_WARN_IF(!editActionData.CanHandle())) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
|
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
|
2018-10-24 12:42:06 +03:00
|
|
|
AutoPlaceholderBatch treatAsOneTransaction(*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
|
|
|
|
2018-09-11 11:15:52 +03:00
|
|
|
DebugOnly<nsresult> rv = RefreshResizersInternal();
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed ot refresh resizers");
|
2003-06-25 12:50:48 +04:00
|
|
|
}
|
2003-02-24 13:18:18 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-07-09 05:42:33 +03:00
|
|
|
HTMLEditor::GetObjectResizingEnabled(bool* aIsObjectResizingEnabled)
|
2003-02-24 13:18:18 +03:00
|
|
|
{
|
Bug 1449564 - part 1: Disable object resizer and inline table editor in default r=m_kato
Gecko supports resizers of <img> elements and <table>, <td>, <th> elements and
has UI to remove existing table row or column in default. However, the other
browsers don't have such UI and web apps need to disable this feature with
calling both:
document.execCommand("enableObjectResizing", false, false);
document.execCommand("enableInlineTableEditing", false, false);
for avoiding conflicting with their own features to edit such elements.
Therefore, it doesn't make sense to keep enabling them in default only on
Gecko. If web apps want to keep using these features, they should call:
document.execCommand("enableObjectResizing", false, true);
document.execCommand("enableInlineTableEditing", false, true);
at initializing the editor.
And also this patch fixes bugs of
document.queryCommandState("enableObjectResizing") and
document.queryCommandState("enableInlineTableEditing"). They always return
false even after calling document.execCommand(..., false, true) since
nsSetDocumentStateCommand::GetCommandStateParams() sets bool value as
STATE_ATTRIBUTE. However, nsHTMLDocument::QueryCommandValue() which is the
caller referring STATE_ATTRIBUTE doesn't treat it as bool value. And also
those commands are related to state of document. Therefore, they should be
return as bool value of STATE_ALL instead. Then,
nsHTMLDocument::QueryCommandState() returns the state as expected. Note that
those commands are supported only by Gecko. So, we don't need to worry about
the compatibility.
Finally, this patch rewrites 2 existing tests to check basic behavior of
resizers and appearance of resizers.
Note that this patch does not add new tests to test inline table editor
since it's difficult to test the behavior with current API. Perhaps, we
should add an API to nsIHTMLEditor to retrieve each anonymous elements in
another bug since it requires to add wrapping API of SpecialPowers.
MozReview-Commit-ID: 1FhYo5vcV60
--HG--
rename : editor/libeditor/tests/test_objectResizing.html => editor/libeditor/tests/test_resizers_appearance.html
rename : editor/libeditor/tests/test_bug640321.html => editor/libeditor/tests/test_resizers_resizing_elements.html
extra : rebase_source : a707de5a64ef1f8ce974cdf1be093d1b4f61c7bc
2018-04-02 11:26:46 +03:00
|
|
|
*aIsObjectResizingEnabled = IsObjectResizerEnabled();
|
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
|
|
|
{
|
Bug 1449564 - part 1: Disable object resizer and inline table editor in default r=m_kato
Gecko supports resizers of <img> elements and <table>, <td>, <th> elements and
has UI to remove existing table row or column in default. However, the other
browsers don't have such UI and web apps need to disable this feature with
calling both:
document.execCommand("enableObjectResizing", false, false);
document.execCommand("enableInlineTableEditing", false, false);
for avoiding conflicting with their own features to edit such elements.
Therefore, it doesn't make sense to keep enabling them in default only on
Gecko. If web apps want to keep using these features, they should call:
document.execCommand("enableObjectResizing", false, true);
document.execCommand("enableInlineTableEditing", false, true);
at initializing the editor.
And also this patch fixes bugs of
document.queryCommandState("enableObjectResizing") and
document.queryCommandState("enableInlineTableEditing"). They always return
false even after calling document.execCommand(..., false, true) since
nsSetDocumentStateCommand::GetCommandStateParams() sets bool value as
STATE_ATTRIBUTE. However, nsHTMLDocument::QueryCommandValue() which is the
caller referring STATE_ATTRIBUTE doesn't treat it as bool value. And also
those commands are related to state of document. Therefore, they should be
return as bool value of STATE_ALL instead. Then,
nsHTMLDocument::QueryCommandState() returns the state as expected. Note that
those commands are supported only by Gecko. So, we don't need to worry about
the compatibility.
Finally, this patch rewrites 2 existing tests to check basic behavior of
resizers and appearance of resizers.
Note that this patch does not add new tests to test inline table editor
since it's difficult to test the behavior with current API. Perhaps, we
should add an API to nsIHTMLEditor to retrieve each anonymous elements in
another bug since it requires to add wrapping API of SpecialPowers.
MozReview-Commit-ID: 1FhYo5vcV60
--HG--
rename : editor/libeditor/tests/test_objectResizing.html => editor/libeditor/tests/test_resizers_appearance.html
rename : editor/libeditor/tests/test_bug640321.html => editor/libeditor/tests/test_resizers_resizing_elements.html
extra : rebase_source : a707de5a64ef1f8ce974cdf1be093d1b4f61c7bc
2018-04-02 11:26:46 +03:00
|
|
|
EnableObjectResizer(aObjectResizingEnabled);
|
2003-02-24 13:18:18 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-07-09 05:42:33 +03:00
|
|
|
} // namespace mozilla
|