Last Comment Bug 745131 - (semantics2) Improve how <semantics> determine the visible child
(semantics2)
: Improve how <semantics> determine the visible child
Status: RESOLVED FIXED
: dev-doc-complete
Product: Core
Classification: Components
Component: MathML (show other bugs)
: Trunk
: All All
: -- normal (vote)
: mozilla23
Assigned To: Frédéric Wang (:fredw)
:
:
Mentors:
http://www.w3.org/TR/MathML3/chapter5...
Depends on: 876701
Blocks: mathml-2 557086
  Show dependency treegraph
 
Reported: 2012-04-13 03:14 PDT by Frédéric Wang (:fredw)
Modified: 2013-08-21 12:45 PDT (History)
7 users (show)
ryanvm: in‑testsuite+
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
testcase (2.10 KB, application/xhtml+xml)
2012-10-30 11:56 PDT, Frédéric Wang (:fredw)
no flags Details
Patch V1 (36.94 KB, patch)
2012-10-30 11:57 PDT, Frédéric Wang (:fredw)
no flags Details | Diff | Splinter Review
C++ source code of the GetSelectedFrame function (3.55 KB, text/x-c++src)
2012-11-01 06:31 PDT, Frédéric Wang (:fredw)
no flags Details
Patch V2 (41.07 KB, patch)
2012-11-01 12:18 PDT, Frédéric Wang (:fredw)
karlt: review-
Details | Diff | Splinter Review
Reftests V1 (9.22 KB, patch)
2012-11-01 12:19 PDT, Frédéric Wang (:fredw)
karlt: review+
Details | Diff | Splinter Review
Patch V3 - part 1 (4.52 KB, patch)
2013-04-12 06:30 PDT, Frédéric Wang (:fredw)
karlt: review-
karlt: feedback+
Details | Diff | Splinter Review
Patch V3 - part 2 (36.80 KB, patch)
2013-04-12 06:31 PDT, Frédéric Wang (:fredw)
karlt: review+
Details | Diff | Splinter Review
Patch V4 (41.00 KB, patch)
2013-05-09 11:39 PDT, Frédéric Wang (:fredw)
karlt: review+
Details | Diff | Splinter Review
Patch V4 (40.90 KB, patch)
2013-05-10 02:39 PDT, Frédéric Wang (:fredw)
no flags Details | Diff | Splinter Review

Description Frédéric Wang (:fredw) 2012-04-13 03:14:24 PDT
Follow-up of bug 154931 and bug 556767. Our current implementation is described in mathml.css:

-----
/* Hide embedded semantic MathML content (as opposed to presentational
   content, which we render). Ideally, here is the behavior that we want:

   if there is an annotation-xml[encoding="MathML-Presentation"]
     render that annotation, and ignore the first child of the
     <semantics> element and all other annotations, 
   else
     render the first child of <semantics> and ignore all annotations

   But this cannot be expressed with CSS. As a stop-gap, just render
   the first child to cater for most of the common cases - bug 154931.
*/
semantics > :not(:first-child) {
  display: none;
}
-----

The purpose of this bug is to implement the intended behavior. I think this will be similar to the maction case and so we can share the implementation. We can probably create a class nsMathMLselectedFrame that inherits from nsMathMLContainerFrame, overrides

nsMathMLContainerFrame::ChildListChanged
nsMathMLContainerFrame::BuildDisplayList
nsMathMLContainerFrame::Place

and implements a default

nsMathMLselectedFrame::GetSelectedFrame function (say, which returns the first child if any).

Then nsMathMLmactionFrame and nsMathMLsemanticsFrame will override nsMathMLselectedFrame::GetSelectedFrame. In nsMathMLsemanticsFrame that will be browsing the child list to find an annotation-xml element with encoding attribute "application/mathml-presentation+xml" (or "MathML-Presentation" for backward compatibility) and default to the first child otherwise.
Comment 1 Frédéric Wang (:fredw) 2012-10-29 10:05:23 PDT
Gecko may also try to display the first <annotation-xml> with a known encoding (presentation MathML, SVG, HTML) or text <annotation>. This will avoid to break Jacques Distler testcase in

https://bugs.webkit.org/show_bug.cgi?id=100626
Comment 2 Frédéric Wang (:fredw) 2012-10-30 11:56:59 PDT
Created attachment 676694 [details]
testcase
Comment 3 Frédéric Wang (:fredw) 2012-10-30 11:57:59 PDT
Created attachment 676696 [details] [diff] [review]
Patch V1

So here is a first patch that tries to reproduce the behavior discussed elsewhere. Still a WIP.
Comment 4 Frédéric Wang (:fredw) 2012-10-30 12:02:16 PDT
Bill: could would please include this patch in your builds, so that people could give their advice on the patch behavior.
Comment 5 Bill Gianopoulos [:WG9s] 2012-10-31 06:40:17 PDT
(In reply to Frédéric Wang (:fredw) from comment #4)
> Bill: could would please include this patch in your builds, so that people
> could give their advice on the patch behavior.

I tried yet the nsMathMLmactionFrame.cpp and nsMathMLmactionFrame.h portions of the patch did not apply even with -F7.  Is there some other patch i need to apply first to get this to apply as posted?
Comment 6 Frédéric Wang (:fredw) 2012-11-01 06:26:07 PDT
I don't know if Bill solved his issue with "hg copy" but anyway I've sent my patches to the try server. Builds should be available here (for the moment the directory is not created, so you'll get a 404 error):

http://ftp.mozilla.org/pub/mozilla.org/firefox/try-builds/fred.wang@free.fr-beae9064e260
Comment 7 Frédéric Wang (:fredw) 2012-11-01 06:31:19 PDT
Created attachment 677379 [details]
C++ source code of the GetSelectedFrame function

Here is the important part of the <semantics> implementation: the selection of the visible frame. Please tell me if that sounds reasonable to you. I guess you all read C++ and I've commented the code, but tell me if you need precision.

I don't think Webkit implements space-like or embellished op but basically the rules for <semantics> will be the same as <maction> and <annotation-xml> will behave as an <mrow>.
Comment 8 Frédéric Wang (:fredw) 2012-11-01 12:18:45 PDT
Created attachment 677519 [details] [diff] [review]
Patch V2
Comment 9 Frédéric Wang (:fredw) 2012-11-01 12:19:19 PDT
Created attachment 677520 [details] [diff] [review]
Reftests V1
Comment 10 Frédéric Wang (:fredw) 2012-11-01 12:21:05 PDT
There were so assertions due to <annotation> trying to find the direction attribute, but this should be fixed now.

https://tbpl.mozilla.org/?tree=Try&rev=beae9064e260

The builds should now be available here:

http://ftp.mozilla.org/pub/mozilla.org/firefox/try-builds/fred.wang@free.fr-beae9064e260
Comment 12 Bill Gianopoulos [:WG9s] 2012-11-01 17:19:03 PDT
(In reply to Frédéric Wang (:fredw) from comment #6)
> I don't know if Bill solved his issue with "hg copy" but anyway I've sent my
> patches to the try server. Builds should be available here (for the moment
> the directory is not created, so you'll get a 404 error):

I finally remembered how my script to process copies worked.  Builds are in progress now.
Comment 13 Frédéric Wang (:fredw) 2012-12-01 13:57:57 PST
Karl: any update on the review?
Comment 14 Bill Gianopoulos [:WG9s] 2013-02-05 16:01:45 PST
(In reply to Frédéric Wang (:fredw) from comment #8)
> Created attachment 677519 [details] [diff] [review]
> Patch V2

This patch no longer applies cleanly.
Comment 15 Karl Tomlinson (:karlt) 2013-02-12 22:35:19 PST
Comment on attachment 677520 [details] [diff] [review]
Reftests V1

I wonder why "content MathML" in semantics-2 compares semantics with maction.
Be careful not to rely on tests passing because the implementation is shared.
Is content MathML valid within maction?

"annotation 2" may actually be a case for preferring known encodings over 
an annotation assumed to be plain text, but simple rules are easier for
developers to predict.
Comment 16 Karl Tomlinson (:karlt) 2013-02-12 22:36:47 PST
Comment on attachment 677519 [details] [diff] [review]
Patch V2

This approach looks sensible to me.  A few things with the interaction of base
and derived classes could be improved to make things clearer, I think.

A nsMathMLSelectedFrame is never instantiated except as a derived class.  I
assume that means that NS_IMPL_FRAMEARENA_HELPERS and FRAME_ID are not
required for this class.  Can you make the build succeed without these
declarations?

Similarly nsMathMLSelectedFrame::GetSelectedFrame() can be pure virtual.

Moving nsMathMLSelectedFrame::SetInitialChildList() to nsMathMLsemanticsFrame
would make it clearer that this method is only used there.
Or perhaps nsMathMLmactionFrame::SetInitialChildList() could first call the
base class method and check mSelectedFrame where it currently uses the
GetSelectedFrame() return value.
Actually, there is an inconsistency between SetInitialChildList setting
mActionType to none when there are no children but ChildListChanged doesn't.
I suspect SetInitialChildList doesn't need to set mActionType to none.
nsMathMLmactionFrame::SetInitialChildList() could always add the event
listeners, or I guess that could be done in Init() and nsMathMLmactionFrame
would just use the base class SetInitialChildList()

nsMathMLmactionFrame::ChildListChanged() and
nsMathMLSelectedFrame::ChildListChanged() both call GetSelectedFrame(), even
though one chains up to the other.

>-nsMathMLmactionFrame::ChildListChanged(int32_t aModType)
>+nsMathMLSelectedFrame::ChildListChanged(int32_t aModType)
> {
>   // update cached values
>-  mChildCount = -1;
>-  mSelection = 0;
>+  mInvalidMarkup = false;
>   mSelectedFrame = nullptr;
>   GetSelectedFrame();

nsMathMLsemanticsFrame doesn't use cached values, so I think it would
make more sense to leave "mSelectedFrame = nullptr" in nsMathMLmactionFrame
and remove the comment here.

nsMathMLmactionFrame::GetSelectedFrame() always sets mInvalidMarkup
appropriately (if it has changed), so I think it would make sense to do
similarly in nsMathMLsemanticsFrame::GetSelectedFrame() and then
mInvalidMarkup would not need to be reset here.

>-  // This very first call to GetSelectedFrame() will cause us to be marked as an
>-  // embellished operator if the selected child is an embellished operator

Should this comment be retained in nsMathMLSelectedFrame (because it also
applies to semantics)?

>+  //   - <semantics-xml> behaves the same as <mrow>

"annotation-xml", I assume.

>+  // Using <annotation> or <annotation-xml> as as a first child is invalid.

Remove one "as".

>+  bool firstChildIsAnnotation = false;
>+  if (childFrame) {

childFrame was checked above, so no need to check again here.

Removing that test mean that the next if block can be replaced with
initialization of firstChildIsAnnotation with the boolean expression.

>+  // If the first child is a presentation MathML element other than
>+  // <annotation> or <annotation-xml>, we are done.
>+  if (!firstChildIsAnnotation &&
>+      childFrame && childFrame->IsFrameOfType(nsIFrame::eMathML)) {

Similarly, here no need to check childFrame. 

>+        // If the <annotation> element has an src attribute, it is a reference
>+        // and we ignore it. Otherwise, we assume it is a plain text annotation

Leave out "plain" from this comment, I assume.  I expect application/x-tex
might be a common encoding here.

annotation-xml elements can also have a src attribute.  Should they also be
ignored for now, or are they actually fetched?

Consider using |continue| to move to the next element in this loop, requiring fewer levels of indent.
Comment 17 Frédéric Wang (:fredw) 2013-02-13 01:36:47 PST
Thanks Karl. I'm clearing the "assign to" field for now and setting this bug as mentored, so that someone might finish the work.

(In reply to Karl Tomlinson (:karlt) from comment #15)
> Comment on attachment 677520 [details] [diff] [review]
> Reftests V1
> 
> I wonder why "content MathML" in semantics-2 compares semantics with maction.
> Be careful not to rely on tests passing because the implementation is shared.
> Is content MathML valid within maction?

Yes, I think it should just be <csymbol>. Perhaps I did that to prevent some pixel diff but I don't remember.

> 
> "annotation 2" may actually be a case for preferring known encodings over 
> an annotation assumed to be plain text, but simple rules are easier for
> developers to predict.

I guess you mean that application/mathml-presentation+xml could be chosen here. In this implementation, I'm taken the simplest approach and display the first known encoding.


(In reply to Karl Tomlinson (:karlt) from comment #16)
> >-  // This very first call to GetSelectedFrame() will cause us to be marked as an
> >-  // embellished operator if the selected child is an embellished operator
> 
> Should this comment be retained in nsMathMLSelectedFrame (because it also
> applies to semantics)?

I think I reported this to the Math WG mailing list. More generally, Neil proposed to take the embellished op data from the first embellished op child. Again, I prefer the simpler approach to take the embellished op data from the selected child and this is consistent with maction.

> annotation-xml elements can also have a src attribute.  Should they also be
> ignored for now, or are they actually fetched?

I think they should be ignored too for now.
Comment 18 Frédéric Wang (:fredw) 2013-04-12 06:30:54 PDT
Created attachment 736783 [details] [diff] [review]
Patch V3 - part 1
Comment 19 Frédéric Wang (:fredw) 2013-04-12 06:31:20 PDT
Created attachment 736784 [details] [diff] [review]
Patch V3 - part 2
Comment 20 Karl Tomlinson (:karlt) 2013-05-08 23:19:39 PDT
Comment on attachment 736783 [details] [diff] [review]
Patch V3 - part 1

The changes are good.  The r- is just because this patch shouldn't be committed on its own as this revision won't build due to duplicate symbols.
Comment 21 Karl Tomlinson (:karlt) 2013-05-08 23:21:14 PDT
Comment on attachment 736784 [details] [diff] [review]
Patch V3 - part 2

Missed this from comment 16:

> nsMathMLmactionFrame::ChildListChanged() and
> nsMathMLSelectedFrame::ChildListChanged() both call GetSelectedFrame(), even
> though one chains up to the other.

So remove the GetSelectedFrame() call from mactionFrame.

r+ with that change and this patch folded together with attachment 677520 [details] [diff] [review] into a single patch.  (See hg help qfold for one way to do that.)

There is a small merge conflict to fix up as nsIDOMEventTarget.h is no longer
included.
Comment 22 Frédéric Wang (:fredw) 2013-05-09 11:39:58 PDT
Created attachment 747534 [details] [diff] [review]
Patch V4
Comment 23 Karl Tomlinson (:karlt) 2013-05-09 17:08:31 PDT
Comment on attachment 747534 [details] [diff] [review]
Patch V4

>Improve how <semantics> determine the visible child - part 1. b=745131, r=karlt.
>* * *
>Improve how <semantics> determine the visible child - part 2. b=745131, r=karlt.

Just use qref to rewrite the commit message as one line.
Comment 24 Frédéric Wang (:fredw) 2013-05-10 02:39:04 PDT
Created attachment 747872 [details] [diff] [review]
Patch V4
Comment 27 Frédéric Wang (:fredw) 2013-05-12 02:23:51 PDT
I updated the status and testsuite pages.

The selection of the visible semantics child is given by the following algorithm:

http://mxr.mozilla.org/mozilla-central/source/layout/mathml/nsMathMLsemanticsFrame.cpp#26
Comment 28 Florian Scholz [:fscholz] (MDN) 2013-08-21 12:45:07 PDT
Updated:
https://developer.mozilla.org/en-US/docs/Web/MathML/Element/semantics

Added a note to:
https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Releases/23#MathML

Editorial / technical review is always welcome :)

Note You need to log in before you can comment on or make changes to this bug.