mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1130891 part 2 - Add option in document encoder for including ruby annotation in plain text. r=roc
This commit is contained in:
parent
2c36da3202
commit
b1b2bf17d4
@ -124,6 +124,11 @@ protected:
|
||||
// We have already checked that our parent is visible.
|
||||
return true;
|
||||
}
|
||||
if (aNode->IsHTMLElement(nsGkAtoms::rp)) {
|
||||
// Ruby parentheses are part of ruby structure, hence
|
||||
// shouldn't be stripped out even if it is not displayed.
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool isVisible = frame->StyleVisibility()->IsVisible();
|
||||
|
@ -35,7 +35,7 @@ interface nsIDocumentEncoderNodeFixup : nsISupports
|
||||
nsIDOMNode fixupNode(in nsIDOMNode aNode, out boolean aSerializeCloneKids);
|
||||
};
|
||||
|
||||
[scriptable, uuid(1158bd7e-a08b-4ff6-9417-6f99144cfccc)]
|
||||
[scriptable, uuid(e5ec69d7-eaa7-4de7-986b-455e17c7f71a)]
|
||||
interface nsIDocumentEncoder : nsISupports
|
||||
{
|
||||
// Output methods flag bits. There are a frightening number of these,
|
||||
@ -234,6 +234,12 @@ interface nsIDocumentEncoder : nsISupports
|
||||
*/
|
||||
const unsigned long OutputForPlainTextClipboardCopy = (1 << 25);
|
||||
|
||||
/**
|
||||
* Include ruby annotations and ruby parentheses in the output.
|
||||
* PlainText output only.
|
||||
*/
|
||||
const unsigned long OutputRubyAnnotation = (1 << 26);
|
||||
|
||||
/**
|
||||
* Initialize with a pointer to the document and the mime type.
|
||||
* @param aDocument Document to encode.
|
||||
|
@ -29,6 +29,7 @@ using namespace mozilla::dom;
|
||||
|
||||
#define PREF_STRUCTS "converter.html2txt.structs"
|
||||
#define PREF_HEADER_STRATEGY "converter.html2txt.header_strategy"
|
||||
#define PREF_ALWAYS_INCLUDE_RUBY "converter.html2txt.always_include_ruby"
|
||||
|
||||
static const int32_t kTabSize=4;
|
||||
static const int32_t kIndentSizeHeaders = 2; /* Indention of h1, if
|
||||
@ -92,6 +93,7 @@ nsPlainTextSerializer::nsPlainTextSerializer()
|
||||
mStartedOutput = false;
|
||||
|
||||
mPreformattedBlockBoundary = false;
|
||||
mWithRubyAnnotation = false; // will be read from pref and flag later
|
||||
|
||||
// initialize the tag stack to zero:
|
||||
// The stack only ever contains pointers to static atoms, so they don't
|
||||
@ -188,6 +190,13 @@ nsPlainTextSerializer::Init(uint32_t aFlags, uint32_t aWrapColumn,
|
||||
}
|
||||
}
|
||||
|
||||
// The pref is default inited to false in libpref, but we use true
|
||||
// as fallback value because we don't want to affect behavior in
|
||||
// other places which use this serializer currently.
|
||||
mWithRubyAnnotation =
|
||||
Preferences::GetBool(PREF_ALWAYS_INCLUDE_RUBY, true) ||
|
||||
(mFlags & nsIDocumentEncoder::OutputRubyAnnotation);
|
||||
|
||||
// XXX We should let the caller decide whether to do this or not
|
||||
mFlags &= ~nsIDocumentEncoder::OutputNoFramesContent;
|
||||
|
||||
@ -255,6 +264,19 @@ nsPlainTextSerializer::ShouldReplaceContainerWithPlaceholder(nsIAtom* aTag)
|
||||
(aTag == nsGkAtoms::video);
|
||||
}
|
||||
|
||||
bool
|
||||
nsPlainTextSerializer::IsIgnorableRubyAnnotation(nsIAtom* aTag)
|
||||
{
|
||||
if (mWithRubyAnnotation) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return
|
||||
aTag == nsGkAtoms::rp ||
|
||||
aTag == nsGkAtoms::rt ||
|
||||
aTag == nsGkAtoms::rtc;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPlainTextSerializer::AppendText(nsIContent* aText,
|
||||
int32_t aStartOffset,
|
||||
@ -440,6 +462,12 @@ nsPlainTextSerializer::DoOpenContainer(nsIAtom* aTag)
|
||||
mIgnoredChildNodeLevel++;
|
||||
return NS_OK;
|
||||
}
|
||||
if (IsIgnorableRubyAnnotation(aTag)) {
|
||||
// Ignorable ruby annotation shouldn't be replaced by a placeholder
|
||||
// character, neither any of its descendants.
|
||||
mIgnoredChildNodeLevel++;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (mFlags & nsIDocumentEncoder::OutputForPlainTextClipboardCopy) {
|
||||
if (mPreformattedBlockBoundary && DoOutput()) {
|
||||
@ -780,6 +808,10 @@ nsPlainTextSerializer::DoCloseContainer(nsIAtom* aTag)
|
||||
mIgnoredChildNodeLevel--;
|
||||
return NS_OK;
|
||||
}
|
||||
if (IsIgnorableRubyAnnotation(aTag)) {
|
||||
mIgnoredChildNodeLevel--;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (mFlags & nsIDocumentEncoder::OutputForPlainTextClipboardCopy) {
|
||||
if (DoOutput() && IsInPre() && IsElementBlock(mElement)) {
|
||||
|
@ -113,6 +113,7 @@ private:
|
||||
bool PopBool(nsTArray<bool>& aStack);
|
||||
|
||||
bool ShouldReplaceContainerWithPlaceholder(nsIAtom* aTag);
|
||||
bool IsIgnorableRubyAnnotation(nsIAtom* aTag);
|
||||
|
||||
bool IsElementPreformatted(mozilla::dom::Element* aElement);
|
||||
bool IsElementBlock(mozilla::dom::Element* aElement);
|
||||
@ -175,6 +176,9 @@ private:
|
||||
|
||||
bool mPreformattedBlockBoundary;
|
||||
|
||||
// Whether the output should include ruby annotations.
|
||||
bool mWithRubyAnnotation;
|
||||
|
||||
nsString mURL;
|
||||
int32_t mHeaderStrategy; /* Header strategy (pref)
|
||||
0 = no indention
|
||||
|
@ -1717,6 +1717,11 @@ pref("network.stricttransportsecurity.preloadlist", true);
|
||||
|
||||
pref("converter.html2txt.structs", true); // Output structured phrases (strong, em, code, sub, sup, b, i, u)
|
||||
pref("converter.html2txt.header_strategy", 1); // 0 = no indention; 1 = indention, increased with header level; 2 = numbering and slight indention
|
||||
// Whether we include ruby annotation in the text despite whether it
|
||||
// is requested. This was true because we didn't explicitly strip out
|
||||
// annotations. Set false by default to provide a better behavior, but
|
||||
// we want to be able to pref-off it if user doesn't like it.
|
||||
pref("converter.html2txt.always_include_ruby", false);
|
||||
|
||||
pref("intl.accept_languages", "chrome://global/locale/intl.properties");
|
||||
pref("intl.menuitems.alwaysappendaccesskeys","chrome://global/locale/intl.properties");
|
||||
|
Loading…
Reference in New Issue
Block a user