2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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/. */
|
2001-02-02 17:27:38 +03:00
|
|
|
|
2013-08-31 01:37:12 +04:00
|
|
|
#include "nsMathMLmactionFrame.h"
|
2001-02-02 17:27:38 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2014-02-28 03:04:46 +04:00
|
|
|
#include "nsNameSpaceManager.h"
|
2013-11-20 23:18:25 +04:00
|
|
|
#include "nsIDocShell.h"
|
2001-02-02 17:27:38 +03:00
|
|
|
#include "nsIDocShellTreeOwner.h"
|
|
|
|
#include "nsIWebBrowserChrome.h"
|
2001-09-06 01:28:38 +04:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2012-07-02 03:45:59 +04:00
|
|
|
#include "nsTextFragment.h"
|
2013-10-08 03:15:59 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2018-04-20 07:49:29 +03:00
|
|
|
#include "mozilla/dom/Event.h"
|
|
|
|
|
2018-11-13 01:20:52 +03:00
|
|
|
using namespace mozilla;
|
2018-04-20 07:49:29 +03:00
|
|
|
using mozilla::dom::Event;
|
2001-02-02 17:27:38 +03:00
|
|
|
|
|
|
|
//
|
|
|
|
// <maction> -- bind actions to a subexpression - implementation
|
|
|
|
//
|
|
|
|
|
2012-06-13 04:05:58 +04:00
|
|
|
enum nsMactionActionTypes {
|
|
|
|
NS_MATHML_ACTION_TYPE_CLASS_ERROR = 0x10,
|
|
|
|
NS_MATHML_ACTION_TYPE_CLASS_USE_SELECTION = 0x20,
|
|
|
|
NS_MATHML_ACTION_TYPE_CLASS_IGNORE_SELECTION = 0x40,
|
|
|
|
NS_MATHML_ACTION_TYPE_CLASS_BITMASK = 0xF0,
|
|
|
|
|
|
|
|
NS_MATHML_ACTION_TYPE_NONE = NS_MATHML_ACTION_TYPE_CLASS_ERROR | 0x01,
|
|
|
|
|
|
|
|
NS_MATHML_ACTION_TYPE_TOGGLE =
|
|
|
|
NS_MATHML_ACTION_TYPE_CLASS_USE_SELECTION | 0x01,
|
|
|
|
NS_MATHML_ACTION_TYPE_UNKNOWN =
|
|
|
|
NS_MATHML_ACTION_TYPE_CLASS_USE_SELECTION | 0x02,
|
|
|
|
|
|
|
|
NS_MATHML_ACTION_TYPE_STATUSLINE =
|
|
|
|
NS_MATHML_ACTION_TYPE_CLASS_IGNORE_SELECTION | 0x01,
|
|
|
|
NS_MATHML_ACTION_TYPE_TOOLTIP =
|
|
|
|
NS_MATHML_ACTION_TYPE_CLASS_IGNORE_SELECTION | 0x02
|
|
|
|
};
|
2001-02-02 17:27:38 +03:00
|
|
|
|
2012-05-18 21:35:43 +04:00
|
|
|
// helper function to parse actiontype attribute
|
|
|
|
static int32_t GetActionType(nsIContent* aContent) {
|
|
|
|
nsAutoString value;
|
|
|
|
|
2012-06-13 04:05:58 +04:00
|
|
|
if (aContent) {
|
2017-12-07 21:13:50 +03:00
|
|
|
if (!aContent->IsElement() ||
|
|
|
|
!aContent->AsElement()->GetAttr(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::actiontype_, value))
|
2017-07-06 15:00:35 +03:00
|
|
|
return NS_MATHML_ACTION_TYPE_NONE;
|
2012-06-13 04:05:58 +04:00
|
|
|
}
|
2012-05-18 21:35:43 +04:00
|
|
|
|
|
|
|
if (value.EqualsLiteral("toggle")) return NS_MATHML_ACTION_TYPE_TOGGLE;
|
|
|
|
if (value.EqualsLiteral("statusline"))
|
|
|
|
return NS_MATHML_ACTION_TYPE_STATUSLINE;
|
|
|
|
if (value.EqualsLiteral("tooltip")) return NS_MATHML_ACTION_TYPE_TOOLTIP;
|
|
|
|
|
2012-06-13 04:05:58 +04:00
|
|
|
return NS_MATHML_ACTION_TYPE_UNKNOWN;
|
2012-05-18 21:35:43 +04:00
|
|
|
}
|
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
nsIFrame* NS_NewMathMLmactionFrame(nsIPresShell* aPresShell,
|
|
|
|
ComputedStyle* aStyle) {
|
2019-02-05 19:45:54 +03:00
|
|
|
return new (aPresShell)
|
|
|
|
nsMathMLmactionFrame(aStyle, aPresShell->GetPresContext());
|
2001-02-02 17:27:38 +03:00
|
|
|
}
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsMathMLmactionFrame)
|
|
|
|
|
2001-02-02 17:27:38 +03:00
|
|
|
nsMathMLmactionFrame::~nsMathMLmactionFrame() {
|
|
|
|
// unregister us as a mouse event listener ...
|
2007-05-14 13:11:38 +04:00
|
|
|
// printf("maction:%p unregistering as mouse event listener ...\n", this);
|
2011-06-28 21:59:14 +04:00
|
|
|
if (mListener) {
|
2011-12-01 11:40:51 +04:00
|
|
|
mContent->RemoveSystemEventListener(NS_LITERAL_STRING("click"), mListener,
|
|
|
|
false);
|
|
|
|
mContent->RemoveSystemEventListener(NS_LITERAL_STRING("mouseover"),
|
|
|
|
mListener, false);
|
|
|
|
mContent->RemoveSystemEventListener(NS_LITERAL_STRING("mouseout"),
|
|
|
|
mListener, false);
|
2011-06-28 21:59:14 +04:00
|
|
|
}
|
2001-02-02 17:27:38 +03:00
|
|
|
}
|
|
|
|
|
2014-05-25 02:20:40 +04:00
|
|
|
void nsMathMLmactionFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow) {
|
2001-02-02 17:27:38 +03:00
|
|
|
// Init our local attributes
|
|
|
|
|
|
|
|
mChildCount = -1; // these will be updated in GetSelectedFrame()
|
2012-05-18 21:35:43 +04:00
|
|
|
mActionType = GetActionType(aContent);
|
2001-02-02 17:27:38 +03:00
|
|
|
|
|
|
|
// Let the base class do the rest
|
2013-05-10 16:40:44 +04:00
|
|
|
return nsMathMLSelectedFrame::Init(aContent, aParent, aPrevInFlow);
|
2011-03-25 06:38:59 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult nsMathMLmactionFrame::ChildListChanged(int32_t aModType) {
|
2006-01-09 03:36:46 +03:00
|
|
|
// update cached values
|
|
|
|
mChildCount = -1;
|
2012-07-30 18:20:58 +04:00
|
|
|
mSelectedFrame = nullptr;
|
2006-01-09 03:36:46 +03:00
|
|
|
|
2013-05-10 16:40:44 +04:00
|
|
|
return nsMathMLSelectedFrame::ChildListChanged(aModType);
|
2006-01-09 03:36:46 +03:00
|
|
|
}
|
|
|
|
|
2001-02-02 17:27:38 +03:00
|
|
|
// return the frame whose number is given by the attribute selection="number"
|
|
|
|
nsIFrame* nsMathMLmactionFrame::GetSelectedFrame() {
|
|
|
|
nsAutoString value;
|
2017-07-06 15:00:35 +03:00
|
|
|
int32_t selection;
|
2001-02-02 17:27:38 +03:00
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
if ((mActionType & NS_MATHML_ACTION_TYPE_CLASS_BITMASK) ==
|
2012-06-13 04:05:58 +04:00
|
|
|
NS_MATHML_ACTION_TYPE_CLASS_ERROR) {
|
|
|
|
mSelection = -1;
|
2013-05-10 16:40:44 +04:00
|
|
|
mInvalidMarkup = true;
|
2012-07-30 18:20:58 +04:00
|
|
|
mSelectedFrame = nullptr;
|
2012-06-13 04:05:58 +04:00
|
|
|
return mSelectedFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Selection is not applied to tooltip and statusline.
|
|
|
|
// Thereby return the first child.
|
2017-07-06 15:00:35 +03:00
|
|
|
if ((mActionType & NS_MATHML_ACTION_TYPE_CLASS_BITMASK) ==
|
2012-06-13 04:05:58 +04:00
|
|
|
NS_MATHML_ACTION_TYPE_CLASS_IGNORE_SELECTION) {
|
2012-04-25 03:49:59 +04:00
|
|
|
// We don't touch mChildCount here. It's incorrect to assign it 1,
|
|
|
|
// and it's inefficient to count the children. It's fine to leave
|
|
|
|
// it be equal -1 because it's not used with other actiontypes.
|
|
|
|
mSelection = 1;
|
2013-05-10 16:40:44 +04:00
|
|
|
mInvalidMarkup = false;
|
2012-04-25 03:49:59 +04:00
|
|
|
mSelectedFrame = mFrames.FirstChild();
|
|
|
|
return mSelectedFrame;
|
|
|
|
}
|
|
|
|
|
2017-12-07 21:13:50 +03:00
|
|
|
mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::selection_,
|
|
|
|
value);
|
2005-10-28 15:25:24 +04:00
|
|
|
if (!value.IsEmpty()) {
|
2012-07-27 17:59:29 +04:00
|
|
|
nsresult errorCode;
|
2001-02-02 17:27:38 +03:00
|
|
|
selection = value.ToInteger(&errorCode);
|
2017-07-06 15:00:35 +03:00
|
|
|
if (NS_FAILED(errorCode)) selection = 1;
|
2001-02-02 17:27:38 +03:00
|
|
|
} else
|
|
|
|
selection = 1; // default is first frame
|
|
|
|
|
|
|
|
if (-1 != mChildCount) { // we have been in this function before...
|
|
|
|
// cater for invalid user-supplied selection
|
2012-06-13 04:05:58 +04:00
|
|
|
if (selection > mChildCount || selection < 1) selection = -1;
|
2001-02-02 17:27:38 +03:00
|
|
|
// quick return if it is identical with our cache
|
2017-07-06 15:00:35 +03:00
|
|
|
if (selection == mSelection) return mSelectedFrame;
|
2001-02-02 17:27:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// get the selected child and cache new values...
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t count = 0;
|
2001-02-02 17:27:38 +03:00
|
|
|
nsIFrame* childFrame = mFrames.FirstChild();
|
|
|
|
while (childFrame) {
|
2001-02-23 19:10:51 +03:00
|
|
|
if (!mSelectedFrame) mSelectedFrame = childFrame; // default is first child
|
|
|
|
if (++count == selection) mSelectedFrame = childFrame;
|
|
|
|
|
2003-07-08 15:00:00 +04:00
|
|
|
childFrame = childFrame->GetNextSibling();
|
2001-02-02 17:27:38 +03:00
|
|
|
}
|
|
|
|
// cater for invalid user-supplied selection
|
2012-06-13 04:05:58 +04:00
|
|
|
if (selection > count || selection < 1) selection = -1;
|
2001-02-02 17:27:38 +03:00
|
|
|
|
|
|
|
mChildCount = count;
|
|
|
|
mSelection = selection;
|
2013-05-10 16:40:44 +04:00
|
|
|
mInvalidMarkup = (mSelection == -1);
|
2012-04-28 19:02:22 +04:00
|
|
|
TransmitAutomaticData();
|
2001-02-02 17:27:38 +03:00
|
|
|
|
|
|
|
return mSelectedFrame;
|
|
|
|
}
|
|
|
|
|
2011-08-25 00:54:30 +04:00
|
|
|
void nsMathMLmactionFrame::SetInitialChildList(ChildListID aListID,
|
2009-07-28 16:53:20 +04:00
|
|
|
nsFrameList& aChildList) {
|
2014-05-28 23:36:58 +04:00
|
|
|
nsMathMLSelectedFrame::SetInitialChildList(aListID, aChildList);
|
2001-02-02 17:27:38 +03:00
|
|
|
|
2013-05-10 16:40:44 +04:00
|
|
|
if (!mSelectedFrame) {
|
2001-05-19 16:09:41 +04:00
|
|
|
mActionType = NS_MATHML_ACTION_TYPE_NONE;
|
|
|
|
} else {
|
2009-11-04 01:43:39 +03:00
|
|
|
// create mouse event listener and register it
|
|
|
|
mListener = new nsMathMLmactionFrame::MouseListener(this);
|
2001-05-19 16:09:41 +04:00
|
|
|
// printf("maction:%p registering as mouse event listener ...\n", this);
|
2011-12-01 11:40:51 +04:00
|
|
|
mContent->AddSystemEventListener(NS_LITERAL_STRING("click"), mListener,
|
|
|
|
false, false);
|
|
|
|
mContent->AddSystemEventListener(NS_LITERAL_STRING("mouseover"), mListener,
|
|
|
|
false, false);
|
|
|
|
mContent->AddSystemEventListener(NS_LITERAL_STRING("mouseout"), mListener,
|
|
|
|
false, false);
|
2001-05-19 16:09:41 +04:00
|
|
|
}
|
2001-02-02 17:27:38 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult nsMathMLmactionFrame::AttributeChanged(int32_t aNameSpaceID,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aAttribute,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aModType) {
|
2012-05-18 21:35:43 +04:00
|
|
|
bool needsReflow = false;
|
|
|
|
|
2017-09-29 00:51:49 +03:00
|
|
|
InvalidateFrame();
|
|
|
|
|
2012-05-18 21:35:43 +04:00
|
|
|
if (aAttribute == nsGkAtoms::actiontype_) {
|
|
|
|
// updating mActionType ...
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t oldActionType = mActionType;
|
2012-05-18 21:35:43 +04:00
|
|
|
mActionType = GetActionType(mContent);
|
|
|
|
|
2012-06-13 04:05:58 +04:00
|
|
|
// Initiate a reflow when actiontype classes are different.
|
|
|
|
if ((oldActionType & NS_MATHML_ACTION_TYPE_CLASS_BITMASK) !=
|
|
|
|
(mActionType & NS_MATHML_ACTION_TYPE_CLASS_BITMASK)) {
|
2012-05-18 21:35:43 +04:00
|
|
|
needsReflow = true;
|
|
|
|
}
|
|
|
|
} else if (aAttribute == nsGkAtoms::selection_) {
|
2017-07-06 15:00:35 +03:00
|
|
|
if ((mActionType & NS_MATHML_ACTION_TYPE_CLASS_BITMASK) ==
|
2012-06-13 04:05:58 +04:00
|
|
|
NS_MATHML_ACTION_TYPE_CLASS_USE_SELECTION) {
|
2012-05-18 21:35:43 +04:00
|
|
|
needsReflow = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// let the base class handle other attribute changes
|
2017-07-06 15:00:35 +03:00
|
|
|
return nsMathMLContainerFrame::AttributeChanged(aNameSpaceID, aAttribute,
|
2012-05-18 21:35:43 +04:00
|
|
|
aModType);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (needsReflow) {
|
|
|
|
PresShell()->FrameNeedsReflow(this, nsIPresShell::eTreeChange,
|
|
|
|
NS_FRAME_IS_DIRTY);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-02-02 17:27:38 +03:00
|
|
|
// ################################################################
|
2017-07-06 15:00:35 +03:00
|
|
|
// Event handlers
|
2001-02-02 17:27:38 +03:00
|
|
|
// ################################################################
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsMathMLmactionFrame::MouseListener, nsIDOMEventListener)
|
2009-11-04 01:43:39 +03:00
|
|
|
|
2001-02-02 17:27:38 +03:00
|
|
|
// helper to show a msg on the status bar
|
2014-09-24 08:34:00 +04:00
|
|
|
// curled from nsPluginFrame.cpp ...
|
2009-11-04 01:43:39 +03:00
|
|
|
static void ShowStatus(nsPresContext* aPresContext, nsString& aStatusMsg) {
|
2013-11-20 23:18:25 +04:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShellItem(aPresContext->GetDocShell());
|
|
|
|
if (docShellItem) {
|
|
|
|
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
|
|
|
|
docShellItem->GetTreeOwner(getter_AddRefs(treeOwner));
|
|
|
|
if (treeOwner) {
|
|
|
|
nsCOMPtr<nsIWebBrowserChrome> browserChrome(do_GetInterface(treeOwner));
|
|
|
|
if (browserChrome) {
|
|
|
|
browserChrome->SetStatus(nsIWebBrowserChrome::STATUS_LINK,
|
|
|
|
aStatusMsg.get());
|
2001-02-02 17:27:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-13 03:35:42 +04:00
|
|
|
NS_IMETHODIMP
|
2018-04-20 07:49:29 +03:00
|
|
|
nsMathMLmactionFrame::MouseListener::HandleEvent(Event* aEvent) {
|
2011-06-28 21:59:14 +04:00
|
|
|
nsAutoString eventType;
|
|
|
|
aEvent->GetType(eventType);
|
|
|
|
if (eventType.EqualsLiteral("mouseover")) {
|
|
|
|
mOwner->MouseOver();
|
2011-08-31 16:16:13 +04:00
|
|
|
} else if (eventType.EqualsLiteral("click")) {
|
2011-06-28 21:59:14 +04:00
|
|
|
mOwner->MouseClick();
|
|
|
|
} else if (eventType.EqualsLiteral("mouseout")) {
|
|
|
|
mOwner->MouseOut();
|
|
|
|
} else {
|
2017-10-25 09:52:56 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Unexpected eventType");
|
2011-06-28 21:59:14 +04:00
|
|
|
}
|
|
|
|
|
2009-11-04 01:43:39 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsMathMLmactionFrame::MouseOver() {
|
2001-02-02 17:27:38 +03:00
|
|
|
// see if we should display a status message
|
2001-04-30 02:20:35 +04:00
|
|
|
if (NS_MATHML_ACTION_TYPE_STATUSLINE == mActionType) {
|
2012-03-29 13:50:02 +04:00
|
|
|
// retrieve content from a second child if it exists
|
|
|
|
nsIFrame* childFrame = mFrames.FrameAt(1);
|
|
|
|
if (!childFrame) return;
|
|
|
|
|
|
|
|
nsIContent* content = childFrame->GetContent();
|
|
|
|
if (!content) return;
|
|
|
|
|
|
|
|
// check whether the content is mtext or not
|
2015-03-03 14:09:00 +03:00
|
|
|
if (content->IsMathMLElement(nsGkAtoms::mtext_)) {
|
2012-03-29 13:50:02 +04:00
|
|
|
// get the text to be displayed
|
|
|
|
content = content->GetFirstChild();
|
|
|
|
if (!content) return;
|
|
|
|
|
|
|
|
const nsTextFragment* textFrg = content->GetText();
|
|
|
|
if (!textFrg) return;
|
|
|
|
|
|
|
|
nsAutoString text;
|
|
|
|
textFrg->AppendTo(text);
|
|
|
|
// collapse whitespaces as listed in REC, section 3.2.6.1
|
|
|
|
text.CompressWhitespace();
|
|
|
|
ShowStatus(PresContext(), text);
|
2001-02-02 17:27:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-04 01:43:39 +03:00
|
|
|
void nsMathMLmactionFrame::MouseOut() {
|
2001-02-02 17:27:38 +03:00
|
|
|
// see if we should remove the status message
|
2001-04-30 02:20:35 +04:00
|
|
|
if (NS_MATHML_ACTION_TYPE_STATUSLINE == mActionType) {
|
2001-02-02 17:27:38 +03:00
|
|
|
nsAutoString value;
|
|
|
|
value.SetLength(0);
|
2007-03-31 01:11:41 +04:00
|
|
|
ShowStatus(PresContext(), value);
|
2001-02-02 17:27:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-04 01:43:39 +03:00
|
|
|
void nsMathMLmactionFrame::MouseClick() {
|
2001-04-30 02:20:35 +04:00
|
|
|
if (NS_MATHML_ACTION_TYPE_TOGGLE == mActionType) {
|
2001-02-02 17:27:38 +03:00
|
|
|
if (mChildCount > 1) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t selection = (mSelection == mChildCount) ? 1 : mSelection + 1;
|
2006-04-24 09:40:11 +04:00
|
|
|
nsAutoString value;
|
2015-12-01 23:50:47 +03:00
|
|
|
value.AppendInt(selection);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool notify = false; // don't yet notify the document
|
2017-12-05 20:05:51 +03:00
|
|
|
mContent->AsElement()->SetAttr(kNameSpaceID_None, nsGkAtoms::selection_,
|
|
|
|
value, notify);
|
2001-02-02 17:27:38 +03:00
|
|
|
|
|
|
|
// Now trigger a content-changed reflow...
|
2007-05-06 23:16:51 +04:00
|
|
|
PresShell()->FrameNeedsReflow(mSelectedFrame, nsIPresShell::eTreeChange,
|
|
|
|
NS_FRAME_IS_DIRTY);
|
2001-02-02 17:27:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|