DOMCoreClasses.cpp 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528
  1. /*
  2. * Copyright (C) 2006, 2007, 2009 Apple Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
  14. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
  17. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  21. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include "config.h"
  26. #include "WebKitDLL.h"
  27. #include "DOMCoreClasses.h"
  28. #include "DOMCSSClasses.h"
  29. #include "DOMEventsClasses.h"
  30. #include "DOMHTMLClasses.h"
  31. #include "WebKitGraphics.h"
  32. #include <WebCore/BString.h>
  33. #include <WebCore/COMPtr.h>
  34. #include <WebCore/DOMWindow.h>
  35. #include <WebCore/Document.h>
  36. #include <WebCore/Element.h>
  37. #include <WebCore/Font.h>
  38. #include <WebCore/Frame.h>
  39. #include <WebCore/SimpleFontData.h>
  40. #include <WebCore/HTMLFormElement.h>
  41. #include <WebCore/HTMLInputElement.h>
  42. #include <WebCore/HTMLNames.h>
  43. #include <WebCore/HTMLOptionElement.h>
  44. #include <WebCore/HTMLSelectElement.h>
  45. #include <WebCore/HTMLTextAreaElement.h>
  46. #include <WebCore/NodeList.h>
  47. #include <WebCore/RenderObject.h>
  48. #include <WebCore/RenderTreeAsText.h>
  49. #include <initguid.h>
  50. // {3B0C0EFF-478B-4b0b-8290-D2321E08E23E}
  51. DEFINE_GUID(IID_DOMElement, 0x3b0c0eff, 0x478b, 0x4b0b, 0x82, 0x90, 0xd2, 0x32, 0x1e, 0x8, 0xe2, 0x3e);
  52. // Our normal style is just to say "using namespace WebCore" rather than having
  53. // individual using directives for each type from that namespace. But
  54. // "DOMObject" exists both in the WebCore namespace and unnamespaced in this
  55. // file, which leads to ambiguities if we say "using namespace WebCore".
  56. using namespace WebCore::HTMLNames;
  57. using WTF::AtomicString;
  58. using WebCore::BString;
  59. using WebCore::Element;
  60. using WebCore::ExceptionCode;
  61. using WebCore::FontDescription;
  62. using WebCore::Frame;
  63. using WebCore::IntRect;
  64. using WTF::String;
  65. // DOMObject - IUnknown -------------------------------------------------------
  66. HRESULT STDMETHODCALLTYPE DOMObject::QueryInterface(REFIID riid, void** ppvObject)
  67. {
  68. *ppvObject = 0;
  69. if (IsEqualGUID(riid, IID_IDOMObject))
  70. *ppvObject = static_cast<IDOMObject*>(this);
  71. else
  72. return WebScriptObject::QueryInterface(riid, ppvObject);
  73. AddRef();
  74. return S_OK;
  75. }
  76. // DOMNode - IUnknown ---------------------------------------------------------
  77. HRESULT STDMETHODCALLTYPE DOMNode::QueryInterface(REFIID riid, void** ppvObject)
  78. {
  79. *ppvObject = 0;
  80. if (IsEqualGUID(riid, IID_IDOMNode))
  81. *ppvObject = static_cast<IDOMNode*>(this);
  82. else if (IsEqualGUID(riid, __uuidof(DOMNode)))
  83. *ppvObject = static_cast<DOMNode*>(this);
  84. else if (IsEqualGUID(riid, __uuidof(IDOMEventTarget)))
  85. *ppvObject = static_cast<IDOMEventTarget*>(this);
  86. else
  87. return DOMObject::QueryInterface(riid, ppvObject);
  88. AddRef();
  89. return S_OK;
  90. }
  91. // DOMNode --------------------------------------------------------------------
  92. HRESULT STDMETHODCALLTYPE DOMNode::nodeName(
  93. /* [retval][out] */ BSTR* result)
  94. {
  95. if (!result)
  96. return E_POINTER;
  97. if (!m_node)
  98. return E_FAIL;
  99. *result = BString(m_node->nodeName()).release();
  100. return S_OK;
  101. }
  102. HRESULT STDMETHODCALLTYPE DOMNode::nodeValue(
  103. /* [retval][out] */ BSTR* result)
  104. {
  105. if (!m_node)
  106. return E_FAIL;
  107. WTF::String nodeValueStr = m_node->nodeValue();
  108. *result = SysAllocStringLen(nodeValueStr.characters(), nodeValueStr.length());
  109. if (nodeValueStr.length() && !*result)
  110. return E_OUTOFMEMORY;
  111. return S_OK;
  112. }
  113. HRESULT STDMETHODCALLTYPE DOMNode::setNodeValue(
  114. /* [in] */ BSTR /*value*/)
  115. {
  116. ASSERT_NOT_REACHED();
  117. return E_NOTIMPL;
  118. }
  119. HRESULT STDMETHODCALLTYPE DOMNode::nodeType(
  120. /* [retval][out] */ unsigned short* /*result*/)
  121. {
  122. ASSERT_NOT_REACHED();
  123. return E_NOTIMPL;
  124. }
  125. HRESULT STDMETHODCALLTYPE DOMNode::parentNode(
  126. /* [retval][out] */ IDOMNode** result)
  127. {
  128. *result = 0;
  129. if (!m_node || !m_node->parentNode())
  130. return E_FAIL;
  131. *result = DOMNode::createInstance(m_node->parentNode());
  132. return *result ? S_OK : E_FAIL;
  133. }
  134. HRESULT STDMETHODCALLTYPE DOMNode::childNodes(
  135. /* [retval][out] */ IDOMNodeList** result)
  136. {
  137. if (!m_node)
  138. return E_FAIL;
  139. if (!result)
  140. return E_POINTER;
  141. *result = DOMNodeList::createInstance(m_node->childNodes().get());
  142. return *result ? S_OK : E_FAIL;
  143. }
  144. HRESULT STDMETHODCALLTYPE DOMNode::firstChild(
  145. /* [retval][out] */ IDOMNode** /*result*/)
  146. {
  147. ASSERT_NOT_REACHED();
  148. return E_NOTIMPL;
  149. }
  150. HRESULT STDMETHODCALLTYPE DOMNode::lastChild(
  151. /* [retval][out] */ IDOMNode** /*result*/)
  152. {
  153. ASSERT_NOT_REACHED();
  154. return E_NOTIMPL;
  155. }
  156. HRESULT STDMETHODCALLTYPE DOMNode::previousSibling(
  157. /* [retval][out] */ IDOMNode** /*result*/)
  158. {
  159. ASSERT_NOT_REACHED();
  160. return E_NOTIMPL;
  161. }
  162. HRESULT STDMETHODCALLTYPE DOMNode::nextSibling(
  163. /* [retval][out] */ IDOMNode** result)
  164. {
  165. if (!result)
  166. return E_POINTER;
  167. *result = 0;
  168. if (!m_node)
  169. return E_FAIL;
  170. *result = DOMNode::createInstance(m_node->nextSibling());
  171. return *result ? S_OK : E_FAIL;
  172. }
  173. HRESULT STDMETHODCALLTYPE DOMNode::attributes(
  174. /* [retval][out] */ IDOMNamedNodeMap** /*result*/)
  175. {
  176. ASSERT_NOT_REACHED();
  177. return E_NOTIMPL;
  178. }
  179. HRESULT STDMETHODCALLTYPE DOMNode::ownerDocument(
  180. /* [retval][out] */ IDOMDocument** result)
  181. {
  182. if (!result)
  183. return E_POINTER;
  184. *result = 0;
  185. if (!m_node)
  186. return E_FAIL;
  187. *result = DOMDocument::createInstance(m_node->ownerDocument());
  188. return *result ? S_OK : E_FAIL;
  189. }
  190. HRESULT STDMETHODCALLTYPE DOMNode::insertBefore(
  191. /* [in] */ IDOMNode* newChild,
  192. /* [in] */ IDOMNode* refChild,
  193. /* [retval][out] */ IDOMNode** result)
  194. {
  195. if (!result)
  196. return E_POINTER;
  197. *result = 0;
  198. if (!m_node)
  199. return E_FAIL;
  200. COMPtr<DOMNode> newChildNode(Query, newChild);
  201. if (!newChildNode)
  202. return E_FAIL;
  203. COMPtr<DOMNode> refChildNode(Query, refChild);
  204. ExceptionCode ec;
  205. if (!m_node->insertBefore(newChildNode->node(), refChildNode ? refChildNode->node() : 0, ec))
  206. return E_FAIL;
  207. *result = newChild;
  208. (*result)->AddRef();
  209. return S_OK;
  210. }
  211. HRESULT STDMETHODCALLTYPE DOMNode::replaceChild(
  212. /* [in] */ IDOMNode* /*newChild*/,
  213. /* [in] */ IDOMNode* /*oldChild*/,
  214. /* [retval][out] */ IDOMNode** /*result*/)
  215. {
  216. ASSERT_NOT_REACHED();
  217. return E_NOTIMPL;
  218. }
  219. HRESULT STDMETHODCALLTYPE DOMNode::removeChild(
  220. /* [in] */ IDOMNode* oldChild,
  221. /* [retval][out] */ IDOMNode** result)
  222. {
  223. if (!result)
  224. return E_POINTER;
  225. *result = 0;
  226. if (!m_node)
  227. return E_FAIL;
  228. COMPtr<DOMNode> oldChildNode(Query, oldChild);
  229. if (!oldChildNode)
  230. return E_FAIL;
  231. ExceptionCode ec;
  232. if (!m_node->removeChild(oldChildNode->node(), ec))
  233. return E_FAIL;
  234. *result = oldChild;
  235. (*result)->AddRef();
  236. return S_OK;
  237. }
  238. HRESULT STDMETHODCALLTYPE DOMNode::appendChild(
  239. /* [in] */ IDOMNode* /*oldChild*/,
  240. /* [retval][out] */ IDOMNode** /*result*/)
  241. {
  242. ASSERT_NOT_REACHED();
  243. return E_NOTIMPL;
  244. }
  245. HRESULT STDMETHODCALLTYPE DOMNode::hasChildNodes(
  246. /* [retval][out] */ BOOL* /*result*/)
  247. {
  248. ASSERT_NOT_REACHED();
  249. return E_NOTIMPL;
  250. }
  251. HRESULT STDMETHODCALLTYPE DOMNode::cloneNode(
  252. /* [in] */ BOOL /*deep*/,
  253. /* [retval][out] */ IDOMNode** /*result*/)
  254. {
  255. ASSERT_NOT_REACHED();
  256. return E_NOTIMPL;
  257. }
  258. HRESULT STDMETHODCALLTYPE DOMNode::normalize( void)
  259. {
  260. ASSERT_NOT_REACHED();
  261. return E_NOTIMPL;
  262. }
  263. HRESULT STDMETHODCALLTYPE DOMNode::isSupported(
  264. /* [in] */ BSTR /*feature*/,
  265. /* [in] */ BSTR /*version*/,
  266. /* [retval][out] */ BOOL* /*result*/)
  267. {
  268. ASSERT_NOT_REACHED();
  269. return E_NOTIMPL;
  270. }
  271. HRESULT STDMETHODCALLTYPE DOMNode::namespaceURI(
  272. /* [retval][out] */ BSTR* /*result*/)
  273. {
  274. ASSERT_NOT_REACHED();
  275. return E_NOTIMPL;
  276. }
  277. HRESULT STDMETHODCALLTYPE DOMNode::prefix(
  278. /* [retval][out] */ BSTR* /*result*/)
  279. {
  280. ASSERT_NOT_REACHED();
  281. return E_NOTIMPL;
  282. }
  283. HRESULT STDMETHODCALLTYPE DOMNode::setPrefix(
  284. /* [in] */ BSTR /*prefix*/)
  285. {
  286. ASSERT_NOT_REACHED();
  287. return E_NOTIMPL;
  288. }
  289. HRESULT STDMETHODCALLTYPE DOMNode::localName(
  290. /* [retval][out] */ BSTR* /*result*/)
  291. {
  292. ASSERT_NOT_REACHED();
  293. return E_NOTIMPL;
  294. }
  295. HRESULT STDMETHODCALLTYPE DOMNode::hasAttributes(
  296. /* [retval][out] */ BOOL* /*result*/)
  297. {
  298. ASSERT_NOT_REACHED();
  299. return E_NOTIMPL;
  300. }
  301. HRESULT STDMETHODCALLTYPE DOMNode::isSameNode(
  302. /* [in] */ IDOMNode* other,
  303. /* [retval][out] */ BOOL* result)
  304. {
  305. if (!result) {
  306. ASSERT_NOT_REACHED();
  307. return E_POINTER;
  308. }
  309. *result = FALSE;
  310. if (!other)
  311. return E_POINTER;
  312. COMPtr<DOMNode> domOther;
  313. HRESULT hr = other->QueryInterface(__uuidof(DOMNode), (void**)&domOther);
  314. if (FAILED(hr))
  315. return hr;
  316. *result = m_node->isSameNode(domOther->node()) ? TRUE : FALSE;
  317. return S_OK;
  318. }
  319. HRESULT STDMETHODCALLTYPE DOMNode::isEqualNode(
  320. /* [in] */ IDOMNode* /*other*/,
  321. /* [retval][out] */ BOOL* /*result*/)
  322. {
  323. ASSERT_NOT_REACHED();
  324. return E_NOTIMPL;
  325. }
  326. HRESULT STDMETHODCALLTYPE DOMNode::textContent(
  327. /* [retval][out] */ BSTR* result)
  328. {
  329. if (!result)
  330. return E_POINTER;
  331. *result = BString(m_node->textContent()).release();
  332. return S_OK;
  333. }
  334. HRESULT STDMETHODCALLTYPE DOMNode::setTextContent(
  335. /* [in] */ BSTR /*text*/)
  336. {
  337. ASSERT_NOT_REACHED();
  338. return E_NOTIMPL;
  339. }
  340. // DOMNode - IDOMEventTarget --------------------------------------------------
  341. HRESULT DOMNode::addEventListener(
  342. /* [in] */ BSTR type,
  343. /* [in] */ IDOMEventListener* listener,
  344. /* [in] */ BOOL useCapture)
  345. {
  346. RefPtr<WebEventListener> webListener = WebEventListener::create(listener);
  347. m_node->addEventListener(type, webListener, useCapture);
  348. return S_OK;
  349. }
  350. HRESULT DOMNode::removeEventListener(
  351. /* [in] */ BSTR type,
  352. /* [in] */ IDOMEventListener* listener,
  353. /* [in] */ BOOL useCapture)
  354. {
  355. if (!listener || !type)
  356. return E_POINTER;
  357. if (!m_node)
  358. return E_FAIL;
  359. RefPtr<WebEventListener> webListener = WebEventListener::create(listener);
  360. m_node->removeEventListener(type, webListener.get(), useCapture);
  361. return S_OK;
  362. }
  363. HRESULT DOMNode::dispatchEvent(
  364. /* [in] */ IDOMEvent* evt,
  365. /* [retval][out] */ BOOL* result)
  366. {
  367. if (!evt || !result)
  368. return E_POINTER;
  369. if (!m_node)
  370. return E_FAIL;
  371. COMPtr<DOMEvent> domEvent;
  372. HRESULT hr = evt->QueryInterface(IID_DOMEvent, (void**) &domEvent);
  373. if (FAILED(hr))
  374. return hr;
  375. WebCore::ExceptionCode ec = 0;
  376. *result = m_node->dispatchEvent(domEvent->coreEvent(), ec) ? TRUE : FALSE;
  377. return ec ? E_FAIL : S_OK;
  378. }
  379. // DOMNode - DOMNode ----------------------------------------------------------
  380. DOMNode::DOMNode(WebCore::Node* n)
  381. : m_node(0)
  382. {
  383. if (n)
  384. n->ref();
  385. m_node = n;
  386. }
  387. DOMNode::~DOMNode()
  388. {
  389. if (m_node)
  390. m_node->deref();
  391. }
  392. IDOMNode* DOMNode::createInstance(WebCore::Node* n)
  393. {
  394. if (!n)
  395. return 0;
  396. HRESULT hr = S_OK;
  397. IDOMNode* domNode = 0;
  398. WebCore::Node::NodeType nodeType = n->nodeType();
  399. switch (nodeType) {
  400. case WebCore::Node::ELEMENT_NODE:
  401. {
  402. IDOMElement* newElement = DOMElement::createInstance(static_cast<WebCore::Element*>(n));
  403. if (newElement) {
  404. hr = newElement->QueryInterface(IID_IDOMNode, (void**)&domNode);
  405. newElement->Release();
  406. }
  407. }
  408. break;
  409. case WebCore::Node::DOCUMENT_NODE:
  410. {
  411. IDOMDocument* newDocument = DOMDocument::createInstance(n->document());
  412. if (newDocument) {
  413. hr = newDocument->QueryInterface(IID_IDOMNode, (void**)&domNode);
  414. newDocument->Release();
  415. }
  416. }
  417. break;
  418. default:
  419. {
  420. DOMNode* newNode = new DOMNode(n);
  421. hr = newNode->QueryInterface(IID_IDOMNode, (void**)&domNode);
  422. }
  423. break;
  424. }
  425. if (FAILED(hr))
  426. return 0;
  427. return domNode;
  428. }
  429. // DOMNodeList - IUnknown -----------------------------------------------------
  430. HRESULT STDMETHODCALLTYPE DOMNodeList::QueryInterface(REFIID riid, void** ppvObject)
  431. {
  432. *ppvObject = 0;
  433. if (IsEqualGUID(riid, IID_IDOMNodeList))
  434. *ppvObject = static_cast<IDOMNodeList*>(this);
  435. else
  436. return DOMObject::QueryInterface(riid, ppvObject);
  437. AddRef();
  438. return S_OK;
  439. }
  440. // IDOMNodeList ---------------------------------------------------------------
  441. HRESULT STDMETHODCALLTYPE DOMNodeList::item(
  442. /* [in] */ UINT index,
  443. /* [retval][out] */ IDOMNode **result)
  444. {
  445. *result = 0;
  446. if (!m_nodeList)
  447. return E_FAIL;
  448. WebCore::Node* itemNode = m_nodeList->item(index);
  449. if (!itemNode)
  450. return E_FAIL;
  451. *result = DOMNode::createInstance(itemNode);
  452. return *result ? S_OK : E_FAIL;
  453. }
  454. HRESULT STDMETHODCALLTYPE DOMNodeList::length(
  455. /* [retval][out] */ UINT *result)
  456. {
  457. *result = 0;
  458. if (!m_nodeList)
  459. return E_FAIL;
  460. *result = m_nodeList->length();
  461. return S_OK;
  462. }
  463. // DOMNodeList - DOMNodeList --------------------------------------------------
  464. DOMNodeList::DOMNodeList(WebCore::NodeList* l)
  465. : m_nodeList(0)
  466. {
  467. if (l)
  468. l->ref();
  469. m_nodeList = l;
  470. }
  471. DOMNodeList::~DOMNodeList()
  472. {
  473. if (m_nodeList)
  474. m_nodeList->deref();
  475. }
  476. IDOMNodeList* DOMNodeList::createInstance(WebCore::NodeList* l)
  477. {
  478. if (!l)
  479. return 0;
  480. IDOMNodeList* domNodeList = 0;
  481. DOMNodeList* newNodeList = new DOMNodeList(l);
  482. if (FAILED(newNodeList->QueryInterface(IID_IDOMNodeList, (void**)&domNodeList)))
  483. return 0;
  484. return domNodeList;
  485. }
  486. // DOMDocument - IUnknown -----------------------------------------------------
  487. HRESULT STDMETHODCALLTYPE DOMDocument::QueryInterface(REFIID riid, void** ppvObject)
  488. {
  489. *ppvObject = 0;
  490. if (IsEqualGUID(riid, IID_IDOMDocument))
  491. *ppvObject = static_cast<IDOMDocument*>(this);
  492. else if (IsEqualGUID(riid, IID_IDOMViewCSS))
  493. *ppvObject = static_cast<IDOMViewCSS*>(this);
  494. else if (IsEqualGUID(riid, IID_IDOMDocumentEvent))
  495. *ppvObject = static_cast<IDOMDocumentEvent*>(this);
  496. else
  497. return DOMNode::QueryInterface(riid, ppvObject);
  498. AddRef();
  499. return S_OK;
  500. }
  501. // DOMDocument ----------------------------------------------------------------
  502. HRESULT STDMETHODCALLTYPE DOMDocument::doctype(
  503. /* [retval][out] */ IDOMDocumentType** /*result*/)
  504. {
  505. ASSERT_NOT_REACHED();
  506. return E_NOTIMPL;
  507. }
  508. HRESULT STDMETHODCALLTYPE DOMDocument::implementation(
  509. /* [retval][out] */ IDOMImplementation** /*result*/)
  510. {
  511. ASSERT_NOT_REACHED();
  512. return E_NOTIMPL;
  513. }
  514. HRESULT STDMETHODCALLTYPE DOMDocument::documentElement(
  515. /* [retval][out] */ IDOMElement** result)
  516. {
  517. *result = DOMElement::createInstance(m_document->documentElement());
  518. return *result ? S_OK : E_FAIL;
  519. }
  520. HRESULT STDMETHODCALLTYPE DOMDocument::createElement(
  521. /* [in] */ BSTR tagName,
  522. /* [retval][out] */ IDOMElement** result)
  523. {
  524. if (!m_document)
  525. return E_FAIL;
  526. String tagNameString(tagName);
  527. ExceptionCode ec;
  528. *result = DOMElement::createInstance(m_document->createElement(tagNameString, ec).get());
  529. return *result ? S_OK : E_FAIL;
  530. }
  531. HRESULT STDMETHODCALLTYPE DOMDocument::createDocumentFragment(
  532. /* [retval][out] */ IDOMDocumentFragment** /*result*/)
  533. {
  534. ASSERT_NOT_REACHED();
  535. return E_NOTIMPL;
  536. }
  537. HRESULT STDMETHODCALLTYPE DOMDocument::createTextNode(
  538. /* [in] */ BSTR /*data*/,
  539. /* [retval][out] */ IDOMText** /*result*/)
  540. {
  541. ASSERT_NOT_REACHED();
  542. return E_NOTIMPL;
  543. }
  544. HRESULT STDMETHODCALLTYPE DOMDocument::createComment(
  545. /* [in] */ BSTR /*data*/,
  546. /* [retval][out] */ IDOMComment** /*result*/)
  547. {
  548. ASSERT_NOT_REACHED();
  549. return E_NOTIMPL;
  550. }
  551. HRESULT STDMETHODCALLTYPE DOMDocument::createCDATASection(
  552. /* [in] */ BSTR /*data*/,
  553. /* [retval][out] */ IDOMCDATASection** /*result*/)
  554. {
  555. ASSERT_NOT_REACHED();
  556. return E_NOTIMPL;
  557. }
  558. HRESULT STDMETHODCALLTYPE DOMDocument::createProcessingInstruction(
  559. /* [in] */ BSTR /*target*/,
  560. /* [in] */ BSTR /*data*/,
  561. /* [retval][out] */ IDOMProcessingInstruction** /*result*/)
  562. {
  563. ASSERT_NOT_REACHED();
  564. return E_NOTIMPL;
  565. }
  566. HRESULT STDMETHODCALLTYPE DOMDocument::createAttribute(
  567. /* [in] */ BSTR /*name*/,
  568. /* [retval][out] */ IDOMAttr** /*result*/)
  569. {
  570. ASSERT_NOT_REACHED();
  571. return E_NOTIMPL;
  572. }
  573. HRESULT STDMETHODCALLTYPE DOMDocument::createEntityReference(
  574. /* [in] */ BSTR /*name*/,
  575. /* [retval][out] */ IDOMEntityReference** /*result*/)
  576. {
  577. ASSERT_NOT_REACHED();
  578. return E_NOTIMPL;
  579. }
  580. HRESULT STDMETHODCALLTYPE DOMDocument::getElementsByTagName(
  581. /* [in] */ BSTR tagName,
  582. /* [retval][out] */ IDOMNodeList** result)
  583. {
  584. if (!m_document)
  585. return E_FAIL;
  586. String tagNameString(tagName);
  587. *result = DOMNodeList::createInstance(m_document->getElementsByTagName(tagNameString).get());
  588. return *result ? S_OK : E_FAIL;
  589. }
  590. HRESULT STDMETHODCALLTYPE DOMDocument::importNode(
  591. /* [in] */ IDOMNode* /*importedNode*/,
  592. /* [in] */ BOOL /*deep*/,
  593. /* [retval][out] */ IDOMNode** /*result*/)
  594. {
  595. ASSERT_NOT_REACHED();
  596. return E_NOTIMPL;
  597. }
  598. HRESULT STDMETHODCALLTYPE DOMDocument::createElementNS(
  599. /* [in] */ BSTR /*namespaceURI*/,
  600. /* [in] */ BSTR /*qualifiedName*/,
  601. /* [retval][out] */ IDOMElement** /*result*/)
  602. {
  603. ASSERT_NOT_REACHED();
  604. return E_NOTIMPL;
  605. }
  606. HRESULT STDMETHODCALLTYPE DOMDocument::createAttributeNS(
  607. /* [in] */ BSTR /*namespaceURI*/,
  608. /* [in] */ BSTR /*qualifiedName*/,
  609. /* [retval][out] */ IDOMAttr** /*result*/)
  610. {
  611. ASSERT_NOT_REACHED();
  612. return E_NOTIMPL;
  613. }
  614. HRESULT STDMETHODCALLTYPE DOMDocument::getElementsByTagNameNS(
  615. /* [in] */ BSTR namespaceURI,
  616. /* [in] */ BSTR localName,
  617. /* [retval][out] */ IDOMNodeList** result)
  618. {
  619. if (!m_document)
  620. return E_FAIL;
  621. String namespaceURIString(namespaceURI);
  622. String localNameString(localName);
  623. *result = DOMNodeList::createInstance(m_document->getElementsByTagNameNS(namespaceURIString, localNameString).get());
  624. return *result ? S_OK : E_FAIL;
  625. }
  626. HRESULT STDMETHODCALLTYPE DOMDocument::getElementById(
  627. /* [in] */ BSTR elementId,
  628. /* [retval][out] */ IDOMElement** result)
  629. {
  630. if (!m_document)
  631. return E_FAIL;
  632. String idString(elementId);
  633. *result = DOMElement::createInstance(m_document->getElementById(idString));
  634. return *result ? S_OK : E_FAIL;
  635. }
  636. // DOMDocument - IDOMViewCSS --------------------------------------------------
  637. HRESULT STDMETHODCALLTYPE DOMDocument::getComputedStyle(
  638. /* [in] */ IDOMElement* elt,
  639. /* [in] */ BSTR pseudoElt,
  640. /* [retval][out] */ IDOMCSSStyleDeclaration** result)
  641. {
  642. if (!elt || !result)
  643. return E_POINTER;
  644. COMPtr<DOMElement> domEle;
  645. HRESULT hr = elt->QueryInterface(IID_DOMElement, (void**)&domEle);
  646. if (FAILED(hr))
  647. return hr;
  648. Element* element = domEle->element();
  649. WebCore::DOMWindow* dv = m_document->defaultView();
  650. String pseudoEltString(pseudoElt);
  651. if (!dv)
  652. return E_FAIL;
  653. *result = DOMCSSStyleDeclaration::createInstance(dv->getComputedStyle(element, pseudoEltString.impl()).get());
  654. return *result ? S_OK : E_FAIL;
  655. }
  656. // DOMDocument - IDOMDocumentEvent --------------------------------------------
  657. HRESULT STDMETHODCALLTYPE DOMDocument::createEvent(
  658. /* [in] */ BSTR eventType,
  659. /* [retval][out] */ IDOMEvent **result)
  660. {
  661. String eventTypeString(eventType, SysStringLen(eventType));
  662. WebCore::ExceptionCode ec = 0;
  663. *result = DOMEvent::createInstance(m_document->createEvent(eventTypeString, ec));
  664. return *result ? S_OK : E_FAIL;
  665. }
  666. // DOMDocument - DOMDocument --------------------------------------------------
  667. DOMDocument::DOMDocument(WebCore::Document* d)
  668. : DOMNode(d)
  669. , m_document(d)
  670. {
  671. }
  672. DOMDocument::~DOMDocument()
  673. {
  674. }
  675. IDOMDocument* DOMDocument::createInstance(WebCore::Document* d)
  676. {
  677. if (!d)
  678. return 0;
  679. HRESULT hr;
  680. IDOMDocument* domDocument = 0;
  681. if (d->isHTMLDocument()) {
  682. DOMHTMLDocument* newDocument = new DOMHTMLDocument(d);
  683. hr = newDocument->QueryInterface(IID_IDOMDocument, (void**)&domDocument);
  684. } else {
  685. DOMDocument* newDocument = new DOMDocument(d);
  686. hr = newDocument->QueryInterface(IID_IDOMDocument, (void**)&domDocument);
  687. }
  688. if (FAILED(hr))
  689. return 0;
  690. return domDocument;
  691. }
  692. // DOMWindow - IUnknown ------------------------------------------------------
  693. HRESULT DOMWindow::QueryInterface(REFIID riid, void** ppvObject)
  694. {
  695. *ppvObject = 0;
  696. if (IsEqualGUID(riid, IID_IDOMWindow))
  697. *ppvObject = static_cast<IDOMWindow*>(this);
  698. else if (IsEqualGUID(riid, IID_IDOMEventTarget))
  699. *ppvObject = static_cast<IDOMEventTarget*>(this);
  700. else
  701. return DOMObject::QueryInterface(riid, ppvObject);
  702. AddRef();
  703. return S_OK;
  704. }
  705. // DOMWindow - IDOMWindow ------------------------------------------------------
  706. HRESULT DOMWindow::document(
  707. /* [out, retval] */ IDOMDocument** result)
  708. {
  709. if (!result) {
  710. ASSERT_NOT_REACHED();
  711. return E_POINTER;
  712. }
  713. *result = DOMDocument::createInstance(m_window->document());
  714. return *result ? S_OK : E_FAIL;
  715. }
  716. HRESULT DOMWindow::getComputedStyle(
  717. /* [in] */ IDOMElement* element,
  718. /* [in] */ BSTR pseudoElement)
  719. {
  720. ASSERT_NOT_REACHED();
  721. return E_NOTIMPL;
  722. }
  723. HRESULT DOMWindow::getMatchedCSSRules(
  724. /* [in] */ IDOMElement* element,
  725. /* [in] */ BSTR pseudoElement,
  726. /* [in] */ BOOL authorOnly,
  727. /* [out, retval] */ IDOMCSSRuleList** result)
  728. {
  729. ASSERT_NOT_REACHED();
  730. return E_NOTIMPL;
  731. }
  732. HRESULT DOMWindow::devicePixelRatio(
  733. /* [out, retval] */ double* result)
  734. {
  735. ASSERT_NOT_REACHED();
  736. return E_NOTIMPL;
  737. }
  738. // DOMWindow - IDOMEventTarget ------------------------------------------------------
  739. HRESULT DOMWindow::addEventListener(
  740. /* [in] */ BSTR type,
  741. /* [in] */ IDOMEventListener* listener,
  742. /* [in] */ BOOL useCapture)
  743. {
  744. if (!type || !listener)
  745. return E_POINTER;
  746. if (!m_window)
  747. return E_FAIL;
  748. RefPtr<WebEventListener> webListener = WebEventListener::create(listener);
  749. m_window->addEventListener(type, webListener, useCapture);
  750. return S_OK;
  751. }
  752. HRESULT DOMWindow::removeEventListener(
  753. /* [in] */ BSTR type,
  754. /* [in] */ IDOMEventListener* listener,
  755. /* [in] */ BOOL useCapture)
  756. {
  757. if (!type || !listener)
  758. return E_POINTER;
  759. if (!m_window)
  760. return E_FAIL;
  761. RefPtr<WebEventListener> webListener = WebEventListener::create(listener);
  762. m_window->removeEventListener(type, webListener.get(), useCapture);
  763. return S_OK;
  764. }
  765. HRESULT DOMWindow::dispatchEvent(
  766. /* [in] */ IDOMEvent* evt,
  767. /* [retval][out] */ BOOL* result)
  768. {
  769. if (!result || !evt)
  770. return E_POINTER;
  771. if (!m_window)
  772. return E_FAIL;
  773. COMPtr<DOMEvent> domEvent;
  774. HRESULT hr = evt->QueryInterface(IID_DOMEvent, (void**) &domEvent);
  775. if (FAILED(hr))
  776. return hr;
  777. WebCore::ExceptionCode ec = 0;
  778. *result = m_window->dispatchEvent(domEvent->coreEvent(), ec) ? TRUE : FALSE;
  779. return ec ? E_FAIL : S_OK;
  780. }
  781. // DOMWindow - DOMWindow --------------------------------------------------
  782. DOMWindow::DOMWindow(WebCore::DOMWindow* w)
  783. : m_window(w)
  784. {
  785. }
  786. DOMWindow::~DOMWindow()
  787. {
  788. }
  789. IDOMWindow* DOMWindow::createInstance(WebCore::DOMWindow* w)
  790. {
  791. if (!w)
  792. return 0;
  793. DOMWindow* newWindow = new DOMWindow(w);
  794. IDOMWindow* domWindow = 0;
  795. HRESULT hr = newWindow->QueryInterface(IID_IDOMWindow, reinterpret_cast<void**>(&domWindow));
  796. if (FAILED(hr))
  797. return 0;
  798. return domWindow;
  799. }
  800. // DOMElement - IUnknown ------------------------------------------------------
  801. HRESULT STDMETHODCALLTYPE DOMElement::QueryInterface(REFIID riid, void** ppvObject)
  802. {
  803. *ppvObject = 0;
  804. if (IsEqualGUID(riid, IID_IDOMElement))
  805. *ppvObject = static_cast<IDOMElement*>(this);
  806. else if (IsEqualGUID(riid, IID_DOMElement))
  807. *ppvObject = static_cast<DOMElement*>(this);
  808. else if (IsEqualGUID(riid, IID_IDOMElementPrivate))
  809. *ppvObject = static_cast<IDOMElementPrivate*>(this);
  810. else if (IsEqualGUID(riid, IID_IDOMNodeExtensions))
  811. *ppvObject = static_cast<IDOMNodeExtensions*>(this);
  812. else if (IsEqualGUID(riid, IID_IDOMElementCSSInlineStyle))
  813. *ppvObject = static_cast<IDOMElementCSSInlineStyle*>(this);
  814. else if (IsEqualGUID(riid, IID_IDOMElementExtensions))
  815. *ppvObject = static_cast<IDOMElementExtensions*>(this);
  816. else
  817. return DOMNode::QueryInterface(riid, ppvObject);
  818. AddRef();
  819. return S_OK;
  820. }
  821. // DOMElement - IDOMNodeExtensions---------------------------------------------
  822. HRESULT STDMETHODCALLTYPE DOMElement::boundingBox(
  823. /* [retval][out] */ LPRECT rect)
  824. {
  825. ::SetRectEmpty(rect);
  826. if (!m_element)
  827. return E_FAIL;
  828. WebCore::RenderObject *renderer = m_element->renderer();
  829. if (renderer) {
  830. IntRect boundsIntRect = renderer->absoluteBoundingBoxRect();
  831. rect->left = boundsIntRect.x();
  832. rect->top = boundsIntRect.y();
  833. rect->right = boundsIntRect.x() + boundsIntRect.width();
  834. rect->bottom = boundsIntRect.y() + boundsIntRect.height();
  835. }
  836. return S_OK;
  837. }
  838. HRESULT STDMETHODCALLTYPE DOMElement::lineBoxRects(
  839. /* [size_is][in] */ RECT* /*rects*/,
  840. /* [in] */ int /*cRects*/)
  841. {
  842. return E_NOTIMPL;
  843. }
  844. // IDOMElement ----------------------------------------------------------------
  845. HRESULT STDMETHODCALLTYPE DOMElement::tagName(
  846. /* [retval][out] */ BSTR* result)
  847. {
  848. if (!m_element)
  849. return E_FAIL;
  850. if (!result)
  851. return E_POINTER;
  852. *result = BString(m_element->tagName()).release();
  853. return S_OK;
  854. }
  855. HRESULT STDMETHODCALLTYPE DOMElement::getAttribute(
  856. /* [in] */ BSTR name,
  857. /* [retval][out] */ BSTR* result)
  858. {
  859. if (!m_element)
  860. return E_FAIL;
  861. WTF::String nameString(name, SysStringLen(name));
  862. WTF::String& attrValueString = (WTF::String&) m_element->getAttribute(nameString);
  863. *result = SysAllocStringLen(attrValueString.characters(), attrValueString.length());
  864. if (attrValueString.length() && !*result)
  865. return E_OUTOFMEMORY;
  866. return S_OK;
  867. }
  868. HRESULT STDMETHODCALLTYPE DOMElement::setAttribute(
  869. /* [in] */ BSTR name,
  870. /* [in] */ BSTR value)
  871. {
  872. if (!m_element)
  873. return E_FAIL;
  874. WTF::String nameString(name, SysStringLen(name));
  875. WTF::String valueString(value, SysStringLen(value));
  876. WebCore::ExceptionCode ec = 0;
  877. m_element->setAttribute(nameString, valueString, ec);
  878. return ec ? E_FAIL : S_OK;
  879. }
  880. HRESULT STDMETHODCALLTYPE DOMElement::removeAttribute(
  881. /* [in] */ BSTR /*name*/)
  882. {
  883. ASSERT_NOT_REACHED();
  884. return E_NOTIMPL;
  885. }
  886. HRESULT STDMETHODCALLTYPE DOMElement::getAttributeNode(
  887. /* [in] */ BSTR /*name*/,
  888. /* [retval][out] */ IDOMAttr** /*result*/)
  889. {
  890. ASSERT_NOT_REACHED();
  891. return E_NOTIMPL;
  892. }
  893. HRESULT STDMETHODCALLTYPE DOMElement::setAttributeNode(
  894. /* [in] */ IDOMAttr* /*newAttr*/,
  895. /* [retval][out] */ IDOMAttr** /*result*/)
  896. {
  897. ASSERT_NOT_REACHED();
  898. return E_NOTIMPL;
  899. }
  900. HRESULT STDMETHODCALLTYPE DOMElement::removeAttributeNode(
  901. /* [in] */ IDOMAttr* /*oldAttr*/,
  902. /* [retval][out] */ IDOMAttr** /*result*/)
  903. {
  904. ASSERT_NOT_REACHED();
  905. return E_NOTIMPL;
  906. }
  907. HRESULT STDMETHODCALLTYPE DOMElement::getElementsByTagName(
  908. /* [in] */ BSTR /*name*/,
  909. /* [retval][out] */ IDOMNodeList** /*result*/)
  910. {
  911. ASSERT_NOT_REACHED();
  912. return E_NOTIMPL;
  913. }
  914. HRESULT STDMETHODCALLTYPE DOMElement::getAttributeNS(
  915. /* [in] */ BSTR /*namespaceURI*/,
  916. /* [in] */ BSTR /*localName*/,
  917. /* [retval][out] */ BSTR* /*result*/)
  918. {
  919. ASSERT_NOT_REACHED();
  920. return E_NOTIMPL;
  921. }
  922. HRESULT STDMETHODCALLTYPE DOMElement::setAttributeNS(
  923. /* [in] */ BSTR /*namespaceURI*/,
  924. /* [in] */ BSTR /*qualifiedName*/,
  925. /* [in] */ BSTR /*value*/)
  926. {
  927. ASSERT_NOT_REACHED();
  928. return E_NOTIMPL;
  929. }
  930. HRESULT STDMETHODCALLTYPE DOMElement::removeAttributeNS(
  931. /* [in] */ BSTR /*namespaceURI*/,
  932. /* [in] */ BSTR /*localName*/)
  933. {
  934. ASSERT_NOT_REACHED();
  935. return E_NOTIMPL;
  936. }
  937. HRESULT STDMETHODCALLTYPE DOMElement::getAttributeNodeNS(
  938. /* [in] */ BSTR /*namespaceURI*/,
  939. /* [in] */ BSTR /*localName*/,
  940. /* [retval][out] */ IDOMAttr** /*result*/)
  941. {
  942. ASSERT_NOT_REACHED();
  943. return E_NOTIMPL;
  944. }
  945. HRESULT STDMETHODCALLTYPE DOMElement::setAttributeNodeNS(
  946. /* [in] */ IDOMAttr* /*newAttr*/,
  947. /* [retval][out] */ IDOMAttr** /*result*/)
  948. {
  949. ASSERT_NOT_REACHED();
  950. return E_NOTIMPL;
  951. }
  952. HRESULT STDMETHODCALLTYPE DOMElement::getElementsByTagNameNS(
  953. /* [in] */ BSTR /*namespaceURI*/,
  954. /* [in] */ BSTR /*localName*/,
  955. /* [retval][out] */ IDOMNodeList** /*result*/)
  956. {
  957. ASSERT_NOT_REACHED();
  958. return E_NOTIMPL;
  959. }
  960. HRESULT STDMETHODCALLTYPE DOMElement::hasAttribute(
  961. /* [in] */ BSTR /*name*/,
  962. /* [retval][out] */ BOOL* /*result*/)
  963. {
  964. ASSERT_NOT_REACHED();
  965. return E_NOTIMPL;
  966. }
  967. HRESULT STDMETHODCALLTYPE DOMElement::hasAttributeNS(
  968. /* [in] */ BSTR /*namespaceURI*/,
  969. /* [in] */ BSTR /*localName*/,
  970. /* [retval][out] */ BOOL* /*result*/)
  971. {
  972. ASSERT_NOT_REACHED();
  973. return E_NOTIMPL;
  974. }
  975. HRESULT STDMETHODCALLTYPE DOMElement::focus( void)
  976. {
  977. if (!m_element)
  978. return E_FAIL;
  979. m_element->focus();
  980. return S_OK;
  981. }
  982. HRESULT STDMETHODCALLTYPE DOMElement::blur( void)
  983. {
  984. if (!m_element)
  985. return E_FAIL;
  986. m_element->blur();
  987. return S_OK;
  988. }
  989. // IDOMElementPrivate ---------------------------------------------------------
  990. HRESULT DOMElement::coreElement(void **element)
  991. {
  992. if (!m_element)
  993. return E_FAIL;
  994. *element = (void*) m_element;
  995. return S_OK;
  996. }
  997. HRESULT STDMETHODCALLTYPE DOMElement::isEqual(
  998. /* [in] */ IDOMElement *other,
  999. /* [retval][out] */ BOOL *result)
  1000. {
  1001. *result = FALSE;
  1002. if (!other || !result)
  1003. return E_POINTER;
  1004. IDOMElementPrivate* otherPriv;
  1005. HRESULT hr = other->QueryInterface(IID_IDOMElementPrivate, (void**) &otherPriv);
  1006. if (FAILED(hr))
  1007. return hr;
  1008. void* otherCoreEle;
  1009. hr = otherPriv->coreElement(&otherCoreEle);
  1010. otherPriv->Release();
  1011. if (FAILED(hr))
  1012. return hr;
  1013. *result = (otherCoreEle == (void*)m_element) ? TRUE : FALSE;
  1014. return S_OK;
  1015. }
  1016. HRESULT STDMETHODCALLTYPE DOMElement::isFocused(
  1017. /* [retval][out] */ BOOL *result)
  1018. {
  1019. if (!m_element)
  1020. return E_FAIL;
  1021. if (m_element->document()->focusedElement() == m_element)
  1022. *result = TRUE;
  1023. else
  1024. *result = FALSE;
  1025. return S_OK;
  1026. }
  1027. HRESULT STDMETHODCALLTYPE DOMElement::innerText(
  1028. /* [retval][out] */ BSTR* result)
  1029. {
  1030. if (!result) {
  1031. ASSERT_NOT_REACHED();
  1032. return E_POINTER;
  1033. }
  1034. if (!m_element) {
  1035. ASSERT_NOT_REACHED();
  1036. return E_FAIL;
  1037. }
  1038. *result = BString(m_element->innerText()).release();
  1039. return S_OK;
  1040. }
  1041. HRESULT STDMETHODCALLTYPE DOMElement::font(WebFontDescription* webFontDescription)
  1042. {
  1043. if (!webFontDescription) {
  1044. ASSERT_NOT_REACHED();
  1045. return E_POINTER;
  1046. }
  1047. ASSERT(m_element);
  1048. WebCore::RenderObject* renderer = m_element->renderer();
  1049. if (!renderer)
  1050. return E_FAIL;
  1051. FontDescription fontDescription = renderer->style()->font().fontDescription();
  1052. AtomicString family = fontDescription.firstFamily();
  1053. webFontDescription->family = family.characters();
  1054. webFontDescription->familyLength = family.length();
  1055. webFontDescription->size = fontDescription.computedSize();
  1056. webFontDescription->bold = fontDescription.weight() >= WebCore::FontWeight600;
  1057. webFontDescription->italic = fontDescription.italic();
  1058. return S_OK;
  1059. }
  1060. HRESULT STDMETHODCALLTYPE DOMElement::renderedImage(HBITMAP* image)
  1061. {
  1062. if (!image) {
  1063. ASSERT_NOT_REACHED();
  1064. return E_POINTER;
  1065. }
  1066. *image = 0;
  1067. ASSERT(m_element);
  1068. Frame* frame = m_element->document()->frame();
  1069. if (!frame)
  1070. return E_FAIL;
  1071. *image = frame->nodeImage(m_element);
  1072. if (!*image)
  1073. return E_FAIL;
  1074. return S_OK;
  1075. }
  1076. HRESULT STDMETHODCALLTYPE DOMElement::markerTextForListItem(
  1077. /* [retval][out] */ BSTR* markerText)
  1078. {
  1079. if (!markerText)
  1080. return E_POINTER;
  1081. ASSERT(m_element);
  1082. *markerText = BString(WebCore::markerTextForListItem(m_element)).release();
  1083. return S_OK;
  1084. }
  1085. HRESULT STDMETHODCALLTYPE DOMElement::shadowPseudoId(
  1086. /* [retval][out] */ BSTR* result)
  1087. {
  1088. if (!result)
  1089. return E_POINTER;
  1090. ASSERT(m_element);
  1091. *result = BString(m_element->shadowPseudoId().string()).release();
  1092. return S_OK;
  1093. }
  1094. // IDOMElementCSSInlineStyle --------------------------------------------------
  1095. HRESULT STDMETHODCALLTYPE DOMElement::style(
  1096. /* [retval][out] */ IDOMCSSStyleDeclaration** result)
  1097. {
  1098. if (!result)
  1099. return E_POINTER;
  1100. if (!m_element)
  1101. return E_FAIL;
  1102. WebCore::CSSStyleDeclaration* style = m_element->style();
  1103. if (!style)
  1104. return E_FAIL;
  1105. *result = DOMCSSStyleDeclaration::createInstance(style);
  1106. return *result ? S_OK : E_FAIL;
  1107. }
  1108. // IDOMElementExtensions ------------------------------------------------------
  1109. HRESULT STDMETHODCALLTYPE DOMElement::offsetLeft(
  1110. /* [retval][out] */ int* result)
  1111. {
  1112. if (!m_element)
  1113. return E_FAIL;
  1114. *result = m_element->offsetLeft();
  1115. return S_OK;
  1116. }
  1117. HRESULT STDMETHODCALLTYPE DOMElement::offsetTop(
  1118. /* [retval][out] */ int* result)
  1119. {
  1120. if (!m_element)
  1121. return E_FAIL;
  1122. *result = m_element->offsetTop();
  1123. return S_OK;
  1124. }
  1125. HRESULT STDMETHODCALLTYPE DOMElement::offsetWidth(
  1126. /* [retval][out] */ int* result)
  1127. {
  1128. if (!m_element)
  1129. return E_FAIL;
  1130. *result = m_element->offsetWidth();
  1131. return S_OK;
  1132. }
  1133. HRESULT STDMETHODCALLTYPE DOMElement::offsetHeight(
  1134. /* [retval][out] */ int* result)
  1135. {
  1136. if (!m_element)
  1137. return E_FAIL;
  1138. *result = m_element->offsetHeight();
  1139. return S_OK;
  1140. }
  1141. HRESULT STDMETHODCALLTYPE DOMElement::offsetParent(
  1142. /* [retval][out] */ IDOMElement** /*result*/)
  1143. {
  1144. // FIXME
  1145. ASSERT_NOT_REACHED();
  1146. return E_NOTIMPL;
  1147. }
  1148. HRESULT STDMETHODCALLTYPE DOMElement::clientWidth(
  1149. /* [retval][out] */ int* result)
  1150. {
  1151. if (!m_element)
  1152. return E_FAIL;
  1153. *result = m_element->clientWidth();
  1154. return S_OK;
  1155. }
  1156. HRESULT STDMETHODCALLTYPE DOMElement::clientHeight(
  1157. /* [retval][out] */ int* result)
  1158. {
  1159. if (!m_element)
  1160. return E_FAIL;
  1161. *result = m_element->clientHeight();
  1162. return S_OK;
  1163. }
  1164. HRESULT STDMETHODCALLTYPE DOMElement::scrollLeft(
  1165. /* [retval][out] */ int* result)
  1166. {
  1167. if (!m_element)
  1168. return E_FAIL;
  1169. *result = m_element->scrollLeft();
  1170. return S_OK;
  1171. }
  1172. HRESULT STDMETHODCALLTYPE DOMElement::setScrollLeft(
  1173. /* [in] */ int /*newScrollLeft*/)
  1174. {
  1175. // FIXME
  1176. ASSERT_NOT_REACHED();
  1177. return E_NOTIMPL;
  1178. }
  1179. HRESULT STDMETHODCALLTYPE DOMElement::scrollTop(
  1180. /* [retval][out] */ int* result)
  1181. {
  1182. if (!m_element)
  1183. return E_FAIL;
  1184. *result = m_element->scrollTop();
  1185. return S_OK;
  1186. }
  1187. HRESULT STDMETHODCALLTYPE DOMElement::setScrollTop(
  1188. /* [in] */ int /*newScrollTop*/)
  1189. {
  1190. // FIXME
  1191. ASSERT_NOT_REACHED();
  1192. return E_NOTIMPL;
  1193. }
  1194. HRESULT STDMETHODCALLTYPE DOMElement::scrollWidth(
  1195. /* [retval][out] */ int* result)
  1196. {
  1197. if (!m_element)
  1198. return E_FAIL;
  1199. *result = m_element->scrollWidth();
  1200. return S_OK;
  1201. }
  1202. HRESULT STDMETHODCALLTYPE DOMElement::scrollHeight(
  1203. /* [retval][out] */ int* result)
  1204. {
  1205. if (!m_element)
  1206. return E_FAIL;
  1207. *result = m_element->scrollHeight();
  1208. return S_OK;
  1209. }
  1210. HRESULT STDMETHODCALLTYPE DOMElement::scrollIntoView(
  1211. /* [in] */ BOOL alignWithTop)
  1212. {
  1213. if (!m_element)
  1214. return E_FAIL;
  1215. m_element->scrollIntoView(!!alignWithTop);
  1216. return S_OK;
  1217. }
  1218. HRESULT STDMETHODCALLTYPE DOMElement::scrollIntoViewIfNeeded(
  1219. /* [in] */ BOOL centerIfNeeded)
  1220. {
  1221. if (!m_element)
  1222. return E_FAIL;
  1223. m_element->scrollIntoViewIfNeeded(!!centerIfNeeded);
  1224. return S_OK;
  1225. }
  1226. // DOMElement -----------------------------------------------------------------
  1227. DOMElement::DOMElement(WebCore::Element* e)
  1228. : DOMNode(e)
  1229. , m_element(e)
  1230. {
  1231. }
  1232. DOMElement::~DOMElement()
  1233. {
  1234. }
  1235. IDOMElement* DOMElement::createInstance(WebCore::Element* e)
  1236. {
  1237. if (!e)
  1238. return 0;
  1239. HRESULT hr;
  1240. IDOMElement* domElement = 0;
  1241. if (e->hasTagName(formTag)) {
  1242. DOMHTMLFormElement* newElement = new DOMHTMLFormElement(e);
  1243. hr = newElement->QueryInterface(IID_IDOMElement, (void**)&domElement);
  1244. } else if (e->hasTagName(iframeTag)) {
  1245. DOMHTMLIFrameElement* newElement = new DOMHTMLIFrameElement(e);
  1246. hr = newElement->QueryInterface(IID_IDOMElement, (void**)&domElement);
  1247. } else if (e->hasTagName(inputTag)) {
  1248. DOMHTMLInputElement* newElement = new DOMHTMLInputElement(e);
  1249. hr = newElement->QueryInterface(IID_IDOMElement, (void**)&domElement);
  1250. } else if (e->hasTagName(optionTag)) {
  1251. DOMHTMLOptionElement* newElement = new DOMHTMLOptionElement(e);
  1252. hr = newElement->QueryInterface(IID_IDOMElement, (void**)&domElement);
  1253. } else if (e->hasTagName(selectTag)) {
  1254. DOMHTMLSelectElement* newElement = new DOMHTMLSelectElement(e);
  1255. hr = newElement->QueryInterface(IID_IDOMElement, (void**)&domElement);
  1256. } else if (e->hasTagName(textareaTag)) {
  1257. DOMHTMLTextAreaElement* newElement = new DOMHTMLTextAreaElement(e);
  1258. hr = newElement->QueryInterface(IID_IDOMElement, (void**)&domElement);
  1259. } else if (e->isHTMLElement()) {
  1260. DOMHTMLElement* newElement = new DOMHTMLElement(e);
  1261. hr = newElement->QueryInterface(IID_IDOMElement, (void**)&domElement);
  1262. } else {
  1263. DOMElement* newElement = new DOMElement(e);
  1264. hr = newElement->QueryInterface(IID_IDOMElement, (void**)&domElement);
  1265. }
  1266. if (FAILED(hr))
  1267. return 0;
  1268. return domElement;
  1269. }