Bug 700854 - {Media,Image,Video}Document should reference an external stylesheet for use in styling their content. r=roc

This commit is contained in:
Jared Wein 2011-11-10 15:08:07 -08:00
parent 80d13db5c2
commit 9bda12367b
8 changed files with 128 additions and 36 deletions

View File

@ -444,6 +444,8 @@
@BINPATH@/res/EditorOverride.css
@BINPATH@/res/contenteditable.css
@BINPATH@/res/designmode.css
@BINPATH@/res/TopLevelImageDocument.css
@BINPATH@/res/TopLevelVideoDocument.css
@BINPATH@/res/table-add-column-after-active.gif
@BINPATH@/res/table-add-column-after-hover.gif
@BINPATH@/res/table-add-column-after.gif

View File

@ -652,23 +652,22 @@ ImageDocument::CreateSyntheticDocument()
// the size of the paper and cannot break into continuations along
// multiple pages.
Element* head = GetHeadElement();
if (!head) {
NS_WARNING("no head on image document!");
return NS_ERROR_FAILURE;
}
NS_ENSURE_TRUE(head, NS_ERROR_FAILURE);
nsCOMPtr<nsINodeInfo> nodeInfo;
nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::style, nsnull,
kNameSpaceID_XHTML,
nsIDOMNode::ELEMENT_NODE);
NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
nsRefPtr<nsGenericHTMLElement> styleContent = NS_NewHTMLStyleElement(nodeInfo.forget());
if (!styleContent) {
return NS_ERROR_OUT_OF_MEMORY;
}
if (nsContentUtils::IsChildOfSameType(this)) {
nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::style, nsnull,
kNameSpaceID_XHTML,
nsIDOMNode::ELEMENT_NODE);
NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
nsRefPtr<nsGenericHTMLElement> styleContent = NS_NewHTMLStyleElement(nodeInfo.forget());
NS_ENSURE_TRUE(styleContent, NS_ERROR_OUT_OF_MEMORY);
styleContent->SetTextContent(NS_LITERAL_STRING("img { display: block; }"));
head->AppendChildTo(styleContent, false);
styleContent->SetTextContent(NS_LITERAL_STRING("img { display: block; }"));
head->AppendChildTo(styleContent, false);
} else {
LinkStylesheet(NS_LITERAL_STRING("resource://gre/res/TopLevelImageDocument.css"));
}
// Add the image element
Element* body = GetBodyElement();

View File

@ -243,9 +243,7 @@ MediaDocument::CreateSyntheticDocument()
NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
nsRefPtr<nsGenericHTMLElement> root = NS_NewHTMLHtmlElement(nodeInfo.forget());
if (!root) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ENSURE_TRUE(root, NS_ERROR_OUT_OF_MEMORY);
NS_ASSERTION(GetChildCount() == 0, "Shouldn't have any kids");
rv = AppendChildTo(root, false);
@ -258,20 +256,15 @@ MediaDocument::CreateSyntheticDocument()
// Create a <head> so our title has somewhere to live
nsRefPtr<nsGenericHTMLElement> head = NS_NewHTMLHeadElement(nodeInfo.forget());
if (!head) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ENSURE_TRUE(head, NS_ERROR_OUT_OF_MEMORY);
nsCOMPtr<nsINodeInfo> nodeInfoMeta;
nodeInfoMeta = mNodeInfoManager->GetNodeInfo(nsGkAtoms::meta, nsnull,
kNameSpaceID_XHTML,
nsIDOMNode::ELEMENT_NODE);
NS_ENSURE_TRUE(nodeInfoMeta, NS_ERROR_OUT_OF_MEMORY);
nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::meta, nsnull,
kNameSpaceID_XHTML,
nsIDOMNode::ELEMENT_NODE);
NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
nsRefPtr<nsGenericHTMLElement> metaContent = NS_NewHTMLMetaElement(nodeInfoMeta.forget());
if (!metaContent) {
return NS_ERROR_OUT_OF_MEMORY;
}
nsRefPtr<nsGenericHTMLElement> metaContent = NS_NewHTMLMetaElement(nodeInfo.forget());
NS_ENSURE_TRUE(metaContent, NS_ERROR_OUT_OF_MEMORY);
metaContent->SetAttr(kNameSpaceID_None, nsGkAtoms::name,
NS_LITERAL_STRING("viewport"),
true);
@ -289,9 +282,7 @@ MediaDocument::CreateSyntheticDocument()
NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
nsRefPtr<nsGenericHTMLElement> body = NS_NewHTMLBodyElement(nodeInfo.forget());
if (!body) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ENSURE_TRUE(body, NS_ERROR_OUT_OF_MEMORY);
root->AppendChildTo(body, false);
@ -354,6 +345,27 @@ MediaDocument::GetFileName(nsAString& aResult)
}
}
nsresult
MediaDocument::LinkStylesheet(const nsAString& aStylesheet)
{
nsCOMPtr<nsINodeInfo> nodeInfo;
nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::link, nsnull,
kNameSpaceID_XHTML,
nsIDOMNode::ELEMENT_NODE);
NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
nsRefPtr<nsGenericHTMLElement> link = NS_NewHTMLLinkElement(nodeInfo.forget());
NS_ENSURE_TRUE(link, NS_ERROR_OUT_OF_MEMORY);
link->SetAttr(kNameSpaceID_None, nsGkAtoms::rel,
NS_LITERAL_STRING("stylesheet"), true);
link->SetAttr(kNameSpaceID_None, nsGkAtoms::href, aStylesheet, true);
Element* head = GetHeadElement();
return head->AppendChildTo(link, false);
}
void
MediaDocument::UpdateTitleAndCharset(const nsACString& aTypeStr,
const char* const* aFormatNames,

View File

@ -72,6 +72,8 @@ protected:
void GetFileName(nsAString& aResult);
nsresult LinkStylesheet(const nsAString& aStylesheet);
// |aFormatNames[]| needs to have four elements in the following order:
// a format name with neither dimension nor file, a format name with
// filename but w/o dimension, a format name with dimension but w/o filename,

View File

@ -135,10 +135,9 @@ VideoDocument::CreateSyntheticVideoDocument(nsIChannel* aChannel,
true);
} else {
Element* head = GetHeadElement();
if (!head) {
NS_WARNING("no head on video document!");
return NS_ERROR_FAILURE;
}
NS_ENSURE_TRUE(head, NS_ERROR_FAILURE);
LinkStylesheet(NS_LITERAL_STRING("resource://gre/res/TopLevelVideoDocument.css"));
nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::style, nsnull,
kNameSpaceID_XHTML,

View File

@ -167,6 +167,8 @@ LOCAL_INCLUDES = \
_FILES = \
contenteditable.css \
designmode.css \
TopLevelImageDocument.css \
TopLevelVideoDocument.css \
$(NULL)
GARBAGE += $(addprefix $(DIST)/bin/res/,$(_FILES))

View File

@ -0,0 +1,38 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla.org code.
*
* Contributor(s):
* Carlo Alberto Ferraris <cafxx@strayorange.com>
* Jared Wein <jwein@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
This CSS stylesheet defines the rules to be applied to ImageDocuments that
are top level (e.g. not iframes).
*/

View File

@ -0,0 +1,38 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla.org code.
*
* Contributor(s):
* Carlo Alberto Ferraris <cafxx@strayorange.com>
* Jared Wein <jwein@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
This CSS stylesheet defines the rules to be applied to VideoDocuments that
are top level (e.g. not iframes).
*/