Bug 1197765 - Compare text content inside frame instead of the content node for ruby autohiding. r=dbaron

This commit is contained in:
Xidorn Quan
2015-09-01 09:24:37 +10:00
parent 27b783e6bc
commit f78a9c1678
6 changed files with 64 additions and 5 deletions

View File

@@ -1312,6 +1312,8 @@ public:
* are not converted into newlines. Only textnodes and cdata nodes are
* added to the result.
*
* @see nsLayoutUtils::GetFrameTextContent
*
* @param aNode Node to get textual contents of.
* @param aDeep If true child elements of aNode are recursivly descended
* into to find text children.

View File

@@ -8577,3 +8577,26 @@ nsLayoutUtils::ShouldUseNoFramesSheet(nsIDocument* aDocument)
}
return !allowSubframes;
}
/* static */ void
nsLayoutUtils::GetFrameTextContent(nsIFrame* aFrame, nsAString& aResult)
{
aResult.Truncate();
AppendFrameTextContent(aFrame, aResult);
}
/* static */ void
nsLayoutUtils::AppendFrameTextContent(nsIFrame* aFrame, nsAString& aResult)
{
if (aFrame->GetType() == nsGkAtoms::textFrame) {
auto textFrame = static_cast<nsTextFrame*>(aFrame);
auto offset = textFrame->GetContentOffset();
auto length = textFrame->GetContentLength();
textFrame->GetContent()->
GetText()->AppendTo(aResult, offset, length);
} else {
for (nsIFrame* child : aFrame->PrincipalChildList()) {
AppendFrameTextContent(child, aResult);
}
}
}

View File

@@ -2719,6 +2719,26 @@ public:
static bool ShouldUseNoScriptSheet(nsIDocument* aDocument);
static bool ShouldUseNoFramesSheet(nsIDocument* aDocument);
/**
* Get the text content inside the frame. This methods traverse the
* frame tree and collect the content from text frames. Note that this
* method is similiar to nsContentUtils::GetNodeTextContent, but it at
* least differs from that method in the following things:
* 1. it skips text content inside nodes like style, script, textarea
* which don't generate an in-tree text frame for the text;
* 2. it skips elements with display property set to none;
* 3. it skips out-of-flow elements;
* 4. it includes content inside pseudo elements;
* 5. it may include part of text content of a node if a text frame
* inside is split to different continuations.
*/
static void GetFrameTextContent(nsIFrame* aFrame, nsAString& aResult);
/**
* Same as GetFrameTextContent but appends the result rather than sets it.
*/
static void AppendFrameTextContent(nsIFrame* aFrame, nsAString& aResult);
private:
static uint32_t sFontSizeInflationEmPerLine;
static uint32_t sFontSizeInflationMinTwips;

View File

@@ -13,7 +13,7 @@
#include "mozilla/DebugOnly.h"
#include "mozilla/Maybe.h"
#include "mozilla/WritingModes.h"
#include "nsContentUtils.h"
#include "nsLayoutUtils.h"
#include "nsLineLayout.h"
#include "nsPresContext.h"
#include "nsStyleContext.h"
@@ -609,8 +609,7 @@ nsRubyBaseContainerFrame::ReflowOneColumn(const ReflowState& aReflowState,
nsAutoString baseText;
if (aColumn.mBaseFrame) {
nsContentUtils::GetNodeTextContent(aColumn.mBaseFrame->GetContent(),
true, baseText);
nsLayoutUtils::GetFrameTextContent(aColumn.mBaseFrame, baseText);
}
// Reflow text frames
@@ -618,8 +617,7 @@ nsRubyBaseContainerFrame::ReflowOneColumn(const ReflowState& aReflowState,
nsRubyTextFrame* textFrame = aColumn.mTextFrames[i];
if (textFrame) {
nsAutoString annotationText;
nsContentUtils::GetNodeTextContent(textFrame->GetContent(),
true, annotationText);
nsLayoutUtils::GetFrameTextContent(textFrame, annotationText);
// Per CSS Ruby spec, the content comparison for auto-hiding
// takes place prior to white spaces collapsing (white-space)

View File

@@ -9,4 +9,5 @@
== ruby-autohide-001.html ruby-autohide-001-ref.html
== ruby-autohide-002.html ruby-autohide-002-ref.html
== ruby-autohide-003.html ruby-autohide-003-ref.html
== ruby-autohide-004.html ruby-autohide-001-ref.html

View File

@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>CSS Test: Autohide ruby annotations which are identical to their bases</title>
<link rel="author" title="Xidorn Quan" href="mailto:quanxunzhen@gmail.com">
<link rel="help" href="http://www.w3.org/TR/css-ruby-1/#autohide">
<link rel="match" href="ruby-autohide-001-ref.html">
</head>
<body>
<ruby>
<rt></rt><rt></rt><rt></rt><rt></rt>
</ruby>
</body>
</html>