2 * Copyright 2006 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 #include "wine/debug.h"
33 #include "wine/unicode.h"
35 #include "mshtml_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
39 static const WCHAR wszFont
[] = {'f','o','n','t',0};
40 static const WCHAR wszSize
[] = {'s','i','z','e',0};
42 static nsISelection
*get_ns_selection(HTMLDocument
*This
)
44 nsIDOMWindow
*dom_window
;
45 nsISelection
*nsselection
= NULL
;
48 if(!This
->nscontainer
)
51 nsres
= nsIWebBrowser_GetContentDOMWindow(This
->nscontainer
->webbrowser
, &dom_window
);
55 nsIDOMWindow_GetSelection(dom_window
, &nsselection
);
56 nsIDOMWindow_Release(dom_window
);
62 static void remove_child_attr(nsIDOMElement
*elem
, LPCWSTR tag
, nsAString
*attr_str
)
65 PRUint32 child_cnt
, i
;
66 nsIDOMNode
*child_node
;
67 nsIDOMNodeList
*node_list
;
70 nsIDOMElement_HasChildNodes(elem
, &has_children
);
74 nsIDOMElement_GetChildNodes(elem
, &node_list
);
75 nsIDOMNodeList_GetLength(node_list
, &child_cnt
);
77 for(i
=0; i
<child_cnt
; i
++) {
78 nsIDOMNodeList_Item(node_list
, i
, &child_node
);
80 nsIDOMNode_GetNodeType(child_node
, &node_type
);
81 if(node_type
== ELEMENT_NODE
) {
82 nsIDOMElement
*child_elem
;
84 const PRUnichar
*ctag
;
86 nsIDOMNode_QueryInterface(child_node
, &IID_nsIDOMElement
, (void**)&child_elem
);
88 nsAString_Init(&tag_str
, NULL
);
89 nsIDOMElement_GetTagName(child_elem
, &tag_str
);
90 nsAString_GetData(&tag_str
, &ctag
, NULL
);
92 if(!strcmpiW(ctag
, tag
))
93 /* FIXME: remove node if there are no more attributes */
94 nsIDOMElement_RemoveAttribute(child_elem
, attr_str
);
96 nsAString_Finish(&tag_str
);
98 remove_child_attr(child_elem
, tag
, attr_str
);
100 nsIDOMNode_Release(child_elem
);
103 nsIDOMNode_Release(child_node
);
106 nsIDOMNodeList_Release(node_list
);
109 void get_font_size(HTMLDocument
*This
, WCHAR
*ret
)
111 nsISelection
*nsselection
= get_ns_selection(This
);
112 nsIDOMElement
*elem
= NULL
;
113 nsIDOMNode
*node
= NULL
, *tmp_node
;
124 nsISelection_GetFocusNode(nsselection
, &node
);
125 nsISelection_Release(nsselection
);
128 nsres
= nsIDOMNode_GetNodeType(node
, &node_type
);
129 if(NS_FAILED(nsres
) || node_type
== DOCUMENT_NODE
)
132 if(node_type
== ELEMENT_NODE
) {
133 nsIDOMNode_QueryInterface(node
, &IID_nsIDOMElement
, (void**)&elem
);
135 nsAString_Init(&tag_str
, NULL
);
136 nsIDOMElement_GetTagName(elem
, &tag_str
);
137 nsAString_GetData(&tag_str
, &tag
, NULL
);
139 if(!strcmpiW(tag
, wszFont
)) {
140 nsAString size_str
, val_str
;
143 TRACE("found font tag %p", elem
);
145 nsAString_Init(&size_str
, wszSize
);
146 nsAString_Init(&val_str
, NULL
);
148 nsIDOMElement_GetAttribute(elem
, &size_str
, &val_str
);
149 nsAString_GetData(&val_str
, &val
, NULL
);
152 TRACE("found size %s\n", debugstr_w(val
));
156 nsAString_Finish(&size_str
);
157 nsAString_Finish(&val_str
);
160 nsAString_Finish(&tag_str
);
162 nsIDOMElement_Release(elem
);
169 nsIDOMNode_GetParentNode(node
, &node
);
170 nsIDOMNode_Release(tmp_node
);
174 nsIDOMNode_Release(node
);
177 void set_font_size(HTMLDocument
*This
, LPCWSTR size
)
179 nsISelection
*nsselection
;
181 nsIDOMDocument
*nsdoc
;
184 PRInt32 range_cnt
= 0;
190 nsselection
= get_ns_selection(This
);
195 nsres
= nsIWebNavigation_GetDocument(This
->nscontainer
->navigation
, &nsdoc
);
199 nsAString_Init(&font_str
, wszFont
);
200 nsAString_Init(&size_str
, wszSize
);
201 nsAString_Init(&val_str
, size
);
203 nsISelection_GetRangeCount(nsselection
, &range_cnt
);
205 FIXME("range_cnt %d not supprted\n", range_cnt
);
207 nsIDOMDocument_CreateElement(nsdoc
, &font_str
, &elem
);
208 nsIDOMElement_SetAttribute(elem
, &size_str
, &val_str
);
210 nsISelection_GetRangeAt(nsselection
, 0, &range
);
211 nsISelection_GetIsCollapsed(nsselection
, &collapsed
);
212 nsISelection_RemoveAllRanges(nsselection
);
214 nsIDOMRange_SurroundContents(range
, (nsIDOMNode
*)elem
);
217 nsISelection_Collapse(nsselection
, (nsIDOMNode
*)elem
, 0);
219 /* Remove all size attrbutes from the range */
220 remove_child_attr(elem
, wszFont
, &size_str
);
221 nsISelection_SelectAllChildren(nsselection
, (nsIDOMNode
*)elem
);
224 nsIDOMRange_Release(range
);
225 nsIDOMElement_Release(elem
);
227 nsAString_Finish(&font_str
);
228 nsAString_Finish(&size_str
);
229 nsAString_Finish(&val_str
);
231 nsISelection_Release(nsselection
);
232 nsIDOMDocument_Release(nsdoc
);