Bug 1442499 - EditorBase::IsPreformatted should return bool. r=masayuki

It is unnecessary to get PresShell for nsStyleText, so we can return bool
instead of nsresult and can change it to static method.

MozReview-Commit-ID: LGrdcaJuLO

--HG--
extra : rebase_source : bb6b6d990741c7b478e9699ae84cc6b89a765bf7
This commit is contained in:
Makoto Kato 2018-04-17 13:08:51 +09:00
Родитель 23d6c207ac
Коммит 5d349b958c
4 изменённых файлов: 29 добавлений и 40 удалений

Просмотреть файл

@ -4019,40 +4019,36 @@ EditorBase::GetEndChildNode(Selection* aSelection,
* IsPreformatted() checks the style info for the node for the preformatted
* text style.
*/
nsresult
EditorBase::IsPreformatted(nsIDOMNode* aNode,
bool* aResult)
// static
bool
EditorBase::IsPreformatted(nsINode* aNode)
{
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
NS_ENSURE_TRUE(aResult && content, NS_ERROR_NULL_POINTER);
nsCOMPtr<nsIPresShell> ps = GetPresShell();
NS_ENSURE_TRUE(ps, NS_ERROR_NOT_INITIALIZED);
if (NS_WARN_IF(!aNode)) {
return false;
}
// Look at the node (and its parent if it's not an element), and grab its
// ComputedStyle.
RefPtr<ComputedStyle> elementStyle;
if (!content->IsElement()) {
content = content->GetParent();
}
if (content && content->IsElement()) {
elementStyle =
nsComputedDOMStyle::GetComputedStyleNoFlush(content->AsElement(), nullptr);
Element* element = aNode->IsElement() ? aNode->AsElement() : nullptr;
if (!element) {
element = aNode->GetParentElement();
if (!element) {
return false;
}
}
elementStyle =
nsComputedDOMStyle::GetComputedStyleNoFlush(element, nullptr);
if (!elementStyle) {
// Consider nodes without a ComputedStyle to be NOT preformatted:
// For instance, this is true of JS tags inside the body (which show
// up as #text nodes but have no ComputedStyle).
*aResult = false;
return NS_OK;
return false;
}
const nsStyleText* styleText = elementStyle->StyleText();
*aResult = styleText->WhiteSpaceIsSignificant();
return NS_OK;
return styleText->WhiteSpaceIsSignificant();
}
template<typename PT, typename CT>

Просмотреть файл

@ -1248,7 +1248,7 @@ public:
*/
nsresult ClearSelection();
nsresult IsPreformatted(nsIDOMNode* aNode, bool* aResult);
static bool IsPreformatted(nsINode* aNode);
/**
* SplitNodeDeep() splits aMostAncestorToSplit deeply.

Просмотреть файл

@ -1374,11 +1374,7 @@ HTMLEditRules::WillInsertText(EditAction aAction,
// is our text going to be PREformatted?
// We remember this so that we know how to handle tabs.
bool isPRE;
NS_ENSURE_STATE(mHTMLEditor);
rv = mHTMLEditor->IsPreformatted(GetAsDOMNode(pointToInsert.GetContainer()),
&isPRE);
NS_ENSURE_SUCCESS(rv, rv);
bool isPRE = EditorBase::IsPreformatted(pointToInsert.GetContainer());
// turn off the edit listener: we know how to
// build the "doc changed range" ourselves, and it's
@ -5996,20 +5992,17 @@ HTMLEditRules::GetPromotedPoint(RulesEndpoint aWhere,
}
// Check for newlines in pre-formatted text nodes.
bool isPRE;
htmlEditor->IsPreformatted(nextNode->AsDOMNode(), &isPRE);
if (isPRE) {
if (EditorBase::IsTextNode(nextNode)) {
nsAutoString tempString;
nextNode->GetAsText()->GetData(tempString);
int32_t newlinePos = tempString.FindChar(nsCRT::LF);
if (newlinePos >= 0) {
if (static_cast<uint32_t>(newlinePos) + 1 == tempString.Length()) {
// No need for special processing if the newline is at the end.
break;
}
return EditorDOMPoint(nextNode, newlinePos + 1);
if (EditorBase::IsPreformatted(nextNode) &&
EditorBase::IsTextNode(nextNode)) {
nsAutoString tempString;
nextNode->GetAsText()->GetData(tempString);
int32_t newlinePos = tempString.FindChar(nsCRT::LF);
if (newlinePos >= 0) {
if (static_cast<uint32_t>(newlinePos) + 1 == tempString.Length()) {
// No need for special processing if the newline is at the end.
break;
}
return EditorDOMPoint(nextNode, newlinePos + 1);
}
}
nextNode = htmlEditor->GetNextEditableHTMLNodeInBlock(point);

Просмотреть файл

@ -908,7 +908,7 @@ WSRunObject::GetRuns()
ClearRuns();
// handle some easy cases first
mHTMLEditor->IsPreformatted(GetAsDOMNode(mNode), &mPRE);
mPRE = EditorBase::IsPreformatted(mNode);
// if it's preformatedd, or if we are surrounded by text or special, it's all one
// big normal ws run
if (mPRE ||