00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00049 #include <stdio.h>
00050 #include <glib.h>
00051 #include <glib/gstdio.h>
00052 #include "browserTypes.h"
00053 #include "selection.h"
00054 #include "selectionFileHandler.h"
00055
00056
00057 #include "nsCOMPtr.h"
00058 #include "nsMemory.h"
00059 #include "gtkmozembed_internal.h"
00060 #include "nsString.h"
00061 #include "nsIWebBrowser.h"
00062 #include "nsIDOMNode.h"
00063 #include "nsIDOMNodeList.h"
00064 #include "nsIDOMNode.h"
00065 #include "nsISelection.h"
00066 #include "nsIDOMRange.h"
00067 #include "nsIDOMDocumentRange.h"
00068 #include "nsIDOMNSRange.h"
00069 #include "nsIDOMCharacterData.h"
00070 #include "nsIDOMWindow.h"
00071 #include "nsIDOMDocument.h"
00072 #include "nsIWebNavigation.h"
00073 #include "nsIDOMHTMLElement.h"
00074 #include "browserLog.h"
00075
00076 #ifdef SELECTION_ENABLED
00077
00078
00079 static void selection_free_list(GSList * theSelectionList);
00080 static GSList *mozilla_retrieve_selections(GtkMozEmbed * b);
00081 static nsISelection *mozilla_get_selection_object(nsIWebBrowser * wb);
00082 static bool mozilla_selection_get_node_index(nsCOMPtr < nsIDOMNode >
00083 theParentNode, nsCOMPtr < nsIDOMNode > theChildNode, int *parentNodeIndex,
00084 int *childNodeIndex);
00085 static bool mozilla_selection_node_is_valid(nsCOMPtr < nsIDOMNode > theNode);
00086 static void mozilla_display_node_info(nsCOMPtr < nsIDOMNode > theNode);
00087 static void mozilla_disect_range(nsCOMPtr < nsIDOMRange > theRange, nsCOMPtr < nsIDOMNode > theContainerNode, GSList ** theSelectionList);
00088 static bool mozilla_text_node_is_real(nsCOMPtr < nsIDOMNode > theNode);
00089 static bool mozilla_set_selection(GtkMozEmbed * b, SelectionID * theSelection);
00090
00091
00092
00093
00094
00095
00096
00097
00098 bool selection_clear_current_page_selections(GtkMozEmbed * mozEmbed)
00099 {
00100 if (selection_file_destroy(mozEmbed) == TRUE)
00101 {
00102
00103 gtk_moz_embed_reload(GTK_MOZ_EMBED(mozEmbed), GTK_MOZ_EMBED_FLAG_RELOADCHARSETCHANGE);
00104 return TRUE;
00105 }
00106 return FALSE;
00107 }
00108
00109
00110
00111
00112
00113
00114
00115
00116 bool selection_set_current_page_selections(GtkMozEmbed * embed)
00117 {
00118 FILE *selectionFile;
00119 GSList *selectionList;
00120 unsigned int length;
00121 SelectionID *theSelection;
00122
00123
00124
00125 if (selection_file_available(embed) == TRUE)
00126 {
00127 BR_LOGPRINTF("selection file available");
00128 selectionFile = selection_file_init(embed);
00129
00130 if (selectionFile)
00131 {
00132
00133 selectionList = selection_file_get_list(selectionFile);
00134 selection_file_close(selectionFile);
00135
00136
00137 if (selectionList)
00138 {
00139 length = g_slist_length(selectionList);
00140 BR_LOGPRINTF("selection file contains %d selections", length);
00141
00142 for (unsigned int index = 0; index < length; index++)
00143 {
00144 theSelection = (SelectionID *) g_slist_nth_data(selectionList, index);
00145 mozilla_set_selection(embed, theSelection);
00146
00147 g_free(theSelection);
00148 theSelection = NULL;
00149 }
00150
00151
00152 g_slist_free(selectionList);
00153 }
00154 }
00155 }
00156 else
00157 {
00158 BR_LOGPRINTF("selection file NOT available");
00159 }
00160
00161 return TRUE;
00162 }
00163
00164
00165
00166
00167
00168
00169
00170 bool selection_identify_and_store_selection(GtkMozEmbed * mozEmbed)
00171 {
00172 SelectionID *theSelection;
00173 FILE *selectionFile;
00174 GSList *theSelectionList;
00175 unsigned int length;
00176
00177 theSelectionList = mozilla_retrieve_selections(GTK_MOZ_EMBED(mozEmbed));
00178
00179 if (theSelectionList)
00180 {
00181 BR_LOGPRINTF("init selection file");
00182 selectionFile = selection_file_init(GTK_MOZ_EMBED(mozEmbed));
00183
00184 if (selectionFile)
00185 {
00186 length = g_slist_length(theSelectionList);
00187 BR_LOGPRINTF("theSelectionList contains %d selections", length);
00188
00189 for (unsigned int index = 0; index < length; index++)
00190 {
00191 theSelection = (SelectionID *) g_slist_nth_data(theSelectionList, index);
00192 BR_LOGPRINTF("store selection information [%d]", index);
00193 selection_file_store(selectionFile, theSelection);
00194 }
00195 BR_LOGPRINTF("close selection file");
00196 selection_file_close(selectionFile);
00197
00198
00199
00200 gtk_moz_embed_reload(GTK_MOZ_EMBED(mozEmbed), GTK_MOZ_EMBED_FLAG_RELOADCHARSETCHANGE);
00201
00202 }
00203 else
00204 {
00205 BR_ERRORPRINTF("Can NOT init selection file");
00206 return FALSE;
00207 }
00208
00209 selection_free_list(theSelectionList);
00210 }
00211 return TRUE;
00212 }
00213
00214
00215
00216
00217
00218
00219
00220 static void selection_free_list(GSList * theSelectionList)
00221 {
00222 SelectionID *theSelection;
00223 unsigned int length;
00224
00225 if (theSelectionList)
00226 {
00227 length = g_slist_length(theSelectionList);
00228
00229 for (unsigned int index = 0; index < length; index++)
00230 {
00231 theSelection = (SelectionID *) g_slist_nth_data(theSelectionList, index);
00232 g_free(theSelection);
00233 theSelection = NULL;
00234 }
00235
00236
00237 g_slist_free(theSelectionList);
00238 }
00239 return;
00240 }
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250 static bool mozilla_set_selection(GtkMozEmbed * b, SelectionID * theSelection)
00251 {
00252 nsAutoString parentTagName;
00253
00254 nsCOMPtr < nsIWebBrowser > wb;
00255 nsCOMPtr < nsIDOMDocument > domDoc;
00256 nsCOMPtr < nsIDOMNodeList > nodeList;
00257 nsCOMPtr < nsIDOMNodeList > childNodeList;
00258 nsCOMPtr < nsIDOMNode > parentNode;
00259 nsCOMPtr < nsIDOMNode > childNode;
00260 nsCOMPtr < nsIWebNavigation > nav;
00261 nsCOMPtr < nsIDOMDocumentRange > domDocRange;
00262 nsCOMPtr < nsIDOMRange > theRange;
00263
00264 BR_LOGPRINTF("entry");
00265
00266 if (theSelection)
00267 {
00268 g_return_val_if_fail(b != NULL, FALSE);
00269 gtk_moz_embed_get_nsIWebBrowser(b, getter_AddRefs(wb));
00270 if (!wb)
00271 return (FALSE);
00272
00273 nav = do_QueryInterface(wb);
00274 nav->GetDocument(getter_AddRefs(domDoc));
00275 if (!domDoc)
00276 return (FALSE);
00277
00278
00279 parentTagName.AssignWithConversion(theSelection->parentNodeTagName);
00280 domDoc->GetElementsByTagName(parentTagName, getter_AddRefs(nodeList));
00281 nodeList->Item(theSelection->parentNodeIndex, getter_AddRefs(parentNode));
00282 BR_LOGPRINTF("retrieved parent node");
00283 mozilla_display_node_info(parentNode);
00284
00285
00286 parentNode->GetChildNodes(getter_AddRefs(childNodeList));
00287 childNodeList->Item(theSelection->nodeIndex, getter_AddRefs(childNode));
00288
00289 BR_LOGPRINTF("retrieved child node");
00290 mozilla_display_node_info(childNode);
00291
00292
00293 domDocRange = do_QueryInterface(domDoc);
00294 domDocRange->CreateRange(getter_AddRefs(theRange));
00295
00296 theRange->SetStart(childNode, theSelection->selectionStart);
00297 theRange->SetEnd(childNode, theSelection->selectionStart + theSelection->selectionLength);
00298
00299 BR_LOGPRINTF("created range");
00300
00301 nsIDOMElement *newNode;
00302 nsAutoString tag;
00303
00304 tag.AssignWithConversion("HIGHLIGHT");
00305 domDoc->CreateElement(tag, &newNode);
00306 theRange->SurroundContents(newNode);
00307
00308 BR_LOGPRINTF("highlight range");
00309 }
00310 return FALSE;
00311 }
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322 static GSList *mozilla_retrieve_selections(GtkMozEmbed * b)
00323 {
00324 nsCOMPtr < nsIWebBrowser > wb;
00325 nsCOMPtr < nsISelection > selection;
00326 nsCOMPtr < nsIDOMRange > theRange;
00327 nsCOMPtr < nsIDOMNode > commonAncestorContainer;
00328 PRInt32 rangecount = 0;
00329 nsresult rv;
00330 GSList *theSelectionList;
00331
00332
00333 if (b == NULL)
00334 {
00335 BR_ERRORPRINTF("invalid input parameter");
00336 return NULL;
00337 }
00338
00339
00340 theSelectionList = NULL;
00341
00342
00343 gtk_moz_embed_get_nsIWebBrowser(b, getter_AddRefs(wb));
00344
00345 if (wb)
00346 {
00347 selection = mozilla_get_selection_object(wb);
00348
00349 if (selection)
00350 {
00351
00352 rv = selection->GetRangeCount(&rangecount);
00353 BR_LOGPRINTF("nsISelection::GetRangeCount() returned %d count = %d", rv, rangecount);
00354
00355 if (rangecount > 1)
00356 {
00357 BR_ERRORPRINTF("invalid RangeCount");
00358 }
00359 else
00360 {
00361
00362 rv = selection->GetRangeAt(0, getter_AddRefs(theRange));
00363 BR_LOGPRINTF("nsISelection::GetRangeAt() for index 0 returned %d", rv);
00364
00365 if (!theRange)
00366 {
00367 BR_ERRORPRINTF("Not able to get nsIDOMRange object");
00368 }
00369 else
00370 {
00371 theRange->GetCommonAncestorContainer(getter_AddRefs(commonAncestorContainer));
00372
00373 if (commonAncestorContainer)
00374 {
00375
00376 mozilla_disect_range(theRange, commonAncestorContainer, &theSelectionList);
00377
00378
00379 selection->RemoveAllRanges();
00380
00381 theRange->Detach();
00382 }
00383 else
00384 {
00385 BR_ERRORPRINTF("Not able to get commonAncestorContainer object");
00386 }
00387
00388 }
00389
00390 }
00391
00392 }
00393
00394 }
00395
00396 return theSelectionList;
00397 }
00398
00399
00400
00401
00402
00403
00404
00405 static nsISelection *mozilla_get_selection_object(nsIWebBrowser * wb)
00406 {
00407 nsresult rv;
00408
00409 nsCOMPtr < nsISelection > oNsSelection;
00410 nsCOMPtr < nsIDOMWindow > oDomWindow;
00411
00412
00413 rv = wb->GetContentDOMWindow(getter_AddRefs(oDomWindow));
00414
00415 BR_LOGPRINTF("GetSelectionObject -- nsIWebBrowser::GetContentDOMWindow() rv %d", rv);
00416
00417 if (!oDomWindow)
00418 {
00419 BR_ERRORPRINTF("GetSelectionObject -- Cannot get the nsIDOMNode Object");
00420 return NULL;
00421 }
00422
00423
00424 rv = oDomWindow->GetSelection(getter_AddRefs(oNsSelection));
00425
00426 BR_LOGPRINTF("GetSelectionObject -- nsIDOMWindow::GetContentDOMWindow()' rv %d", rv);
00427
00428 if (!oNsSelection)
00429 {
00430 BR_LOGPRINTF("GetSelectionObject -- Cannot get the nsISelection Object");
00431 return NULL;
00432 }
00433 return oNsSelection;
00434 }
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446 void mozilla_disect_range(nsCOMPtr < nsIDOMRange > theRange, nsCOMPtr < nsIDOMNode > theNode, GSList ** theSelectionList)
00447 {
00448 nsCOMPtr < nsIDOMNSRange > theNSRange;
00449 PRBool HasChildren;
00450
00451 nsCOMPtr < nsIDOMNode > theChild;
00452 nsCOMPtr < nsIDOMNode > childNode;
00453 PRBool inRange = FALSE;
00454 PRUint16 retval;
00455
00456 nsCOMPtr < nsIDOMNodeList > childNodeList;
00457 unsigned int childNodeListLength = 0;
00458 SelectionID *theSelection;
00459
00460 nsCOMPtr < nsIDOMNode > theParentNode;
00461 int parentNodeIndex;
00462 int childNodeIndex;
00463 unsigned int selectionLength;
00464
00465 nsCOMPtr < nsIDOMCharacterData > charData;
00466 nsString theParentNodeName;
00467
00468 nsCOMPtr < nsIDOMNode > startContainer;
00469 nsCOMPtr < nsIDOMNode > endContainer;
00470 int startOffset;
00471 int endOffset;
00472
00473
00474 theRange->GetStartContainer(getter_AddRefs(startContainer));
00475 theRange->GetEndContainer(getter_AddRefs(endContainer));
00476 theRange->GetStartOffset(&startOffset);
00477 theRange->GetEndOffset(&endOffset);
00478
00479 theNSRange = do_QueryInterface(theRange);
00480
00481 if (theNSRange)
00482 {
00483 BR_LOGPRINTF("---> got one nsIDOMNSRange object");
00484
00485
00486
00487
00488 if (mozilla_selection_node_is_valid(theNode))
00489 {
00490 theNSRange->IntersectsNode(theNode, &inRange);
00491
00492 if (inRange)
00493 {
00494
00495
00496 theNode->GetParentNode(getter_AddRefs(theParentNode));
00497 theParentNode->GetNodeName(theParentNodeName);
00498 mozilla_selection_get_node_index(theParentNode, theNode, &parentNodeIndex, &childNodeIndex);
00499
00500 charData = (do_QueryInterface(theNode));
00501 charData->GetLength(&selectionLength);
00502
00503
00504 theSelection = g_new0(SelectionID, 1);
00505 theSelection->nodeIndex = childNodeIndex;
00506 theSelection->parentNodeIndex = parentNodeIndex;
00507
00508 char *tagname = ToNewCString(theParentNodeName);
00509
00510 strcpy(theSelection->parentNodeTagName, tagname);
00511 nsMemory::Free(tagname);
00512
00513 mozilla_display_node_info(theNode);
00514
00515
00516
00517 theNSRange->CompareNode(theNode, &retval);
00518
00519 switch (retval)
00520 {
00521 case nsIDOMNSRange::NODE_INSIDE:
00522 {
00523 BR_LOGPRINTF("######## child -- NODE_INSIDE #######");
00524 theSelection->selectionLength = selectionLength;
00525 theSelection->selectionStart = 0;
00526
00527 }
00528 break;
00529 case nsIDOMNSRange::NODE_BEFORE:
00530 {
00531 BR_LOGPRINTF("######## child -- NODE_BEFORE ########");
00532
00533 if (theNode == startContainer)
00534 {
00535 theSelection->selectionStart = startOffset;
00536 }
00537 else
00538 {
00539 theSelection->selectionStart = 0;
00540 }
00541 theSelection->selectionLength = selectionLength - theSelection->selectionStart;
00542
00543 }
00544 break;
00545 case nsIDOMNSRange::NODE_AFTER:
00546 {
00547 if (theNode == endContainer)
00548 {
00549 theSelection->selectionLength = endOffset;
00550 }
00551 else
00552 {
00553 theSelection->selectionLength = selectionLength;
00554 }
00555 theSelection->selectionStart = 0;
00556
00557 }
00558 break;
00559 case nsIDOMNSRange::NODE_BEFORE_AND_AFTER:
00560 {
00561 BR_LOGPRINTF("######## NODE_BEFORE_AND_AFTER -- ########");
00562
00563 theSelection->selectionLength = endOffset - startOffset;
00564 theSelection->selectionStart = startOffset;
00565 }
00566 break;
00567 }
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578 BR_LOGPRINTF("add this selection to the list");
00579 *theSelectionList = g_slist_prepend(*theSelectionList, theSelection);
00580
00581 }
00582 }
00583 else
00584 {
00585 theNode->HasChildNodes(&HasChildren);
00586
00587 if (HasChildren)
00588 {
00589 theNode->GetChildNodes(getter_AddRefs(childNodeList));
00590
00591 if (childNodeList)
00592 {
00593 childNodeList->GetLength(&childNodeListLength);
00594
00595 for (unsigned int index = 0; index < childNodeListLength; index++)
00596 {
00597 childNodeList->Item(index, getter_AddRefs(childNode));
00598 mozilla_disect_range(theRange, childNode, theSelectionList);
00599 }
00600
00601 }
00602
00603 }
00604
00605 }
00606
00607 }
00608 else
00609 {
00610 BR_ERRORPRINTF("no nsIDOMNSRange object");
00611 }
00612 return;
00613 }
00614
00615 void mozilla_display_node_info(nsCOMPtr < nsIDOMNode > theNode)
00616 {
00617 nsString theParentNodeName;
00618 nsString theChildNodeName;
00619 nsString theParentNodeValue;
00620 nsString theChildNodeValue;
00621 nsString theChildClassName;
00622
00623 nsCOMPtr < nsIDOMNode > theParentNode;
00624 nsCOMPtr < nsIDOMNodeList > childNodeList;
00625 nsCOMPtr < nsIDOMNodeList > parentNodeList;
00626 unsigned int childNodeListLength = 0;
00627 unsigned parentNodeListLength = 0;
00628 int parentNodeIndex;
00629 int childNodeIndex;
00630 unsigned short childtype;
00631 unsigned short parenttype;
00632 PRBool HasChildren;
00633
00634 nsCOMPtr < nsIDOMHTMLElement > element;
00635
00636
00637
00638 theNode->GetNodeName(theChildNodeName);
00639 theNode->GetNodeValue(theChildNodeValue);
00640 theNode->GetNodeType(&childtype);
00641 theNode->GetParentNode(getter_AddRefs(theParentNode));
00642
00643 theNode->HasChildNodes(&HasChildren);
00644
00645 if (HasChildren)
00646 {
00647 theNode->GetChildNodes(getter_AddRefs(childNodeList));
00648
00649 if (childNodeList)
00650 {
00651 childNodeList->GetLength(&childNodeListLength);
00652 }
00653 }
00654
00655 char *childname = ToNewCString(theChildNodeName);
00656 char *childvalue = ToNewCString(theChildNodeValue);
00657
00658 mozilla_selection_get_node_index(theParentNode, theNode, &parentNodeIndex, &childNodeIndex);
00659
00660 BR_LOGPRINTF("--------- mozilla_display_node_info ----------------");
00661 BR_LOGPRINTF("--> node[%d] = %s \n--> (value = %s) \n--> (children = %d) \n--> (type = %d)\n", childNodeIndex, childname, childvalue,
00662 childNodeListLength, childtype);
00663
00664 nsMemory::Free(childvalue);
00665 nsMemory::Free(childname);
00666
00667 theParentNode->GetNodeName(theParentNodeName);
00668 theParentNode->GetNodeValue(theParentNodeValue);
00669 theParentNode->GetNodeType(&parenttype);
00670
00671 char *parentname = ToNewCString(theParentNodeName);
00672 char *parentvalue = ToNewCString(theParentNodeValue);
00673
00674 theParentNode->HasChildNodes(&HasChildren);
00675
00676 if (HasChildren)
00677 {
00678 theParentNode->GetChildNodes(getter_AddRefs(parentNodeList));
00679
00680 if (parentNodeList)
00681 {
00682 parentNodeList->GetLength(&parentNodeListLength);
00683 }
00684 }
00685
00686 BR_LOGPRINTF("--> parentNode[%d] = %s \n--> (value = %s) \n--> (children = %d) \n--> (type = %d)\n", parentNodeIndex, parentname,
00687 parentvalue, parentNodeListLength, parenttype);
00688 BR_LOGPRINTF("--------- mozilla_display_node_info ----------------");
00689
00690
00691 nsMemory::Free(parentvalue);
00692 nsMemory::Free(parentname);
00693
00694 }
00695
00696
00697
00698
00699
00700
00701
00702
00703 bool mozilla_selection_node_is_valid(nsCOMPtr < nsIDOMNode > theNode)
00704 {
00705 unsigned short childNodeType = 0;
00706 unsigned short theParentNodeType = 0;
00707
00708 nsCOMPtr < nsIDOMNode > theParentNode;
00709 nsString theNodeValue;
00710 nsAutoString HighLightTag;
00711 nsString theParentNodeName;
00712
00713 theNode->GetNodeType(&childNodeType);
00714
00715 if (childNodeType == nsIDOMNode::TEXT_NODE)
00716 {
00717 BR_LOGPRINTF("theNode = TEXT_NODE");
00718
00719
00720
00721 if (mozilla_text_node_is_real(theNode) == TRUE)
00722 {
00723 theNode->GetParentNode(getter_AddRefs(theParentNode));
00724
00725
00726 theParentNode->GetNodeName(theParentNodeName);
00727 HighLightTag.AssignWithConversion("HIGHLIGHT");
00728
00729 if (theParentNodeName.Equals(HighLightTag) == FALSE)
00730 {
00731 theParentNode->GetNodeType(&theParentNodeType);
00732
00733 if (theParentNodeType == nsIDOMNode::ELEMENT_NODE)
00734 {
00735 BR_LOGPRINTF("theParentNode = ELEMENT_NODE");
00736 BR_LOGPRINTF("VALID SELECTION");
00737 return TRUE;
00738 }
00739 else
00740 {
00741 BR_LOGPRINTF("theParentNode = %d", childNodeType);
00742 }
00743 }
00744 else
00745 {
00746 BR_LOGPRINTF("interfears with other selection !!!");
00747 }
00748 }
00749 else
00750 {
00751 BR_LOGPRINTF("no real text NODE");
00752 }
00753 }
00754 else
00755 {
00756 BR_LOGPRINTF("theNode = %d", childNodeType);
00757 }
00758
00759 BR_LOGPRINTF("INVALID SELECTION");
00760 return FALSE;
00761 }
00762
00763
00764
00765
00766
00767
00768
00769
00770 static bool mozilla_text_node_is_real(nsCOMPtr < nsIDOMNode > theNode)
00771 {
00772 nsCOMPtr < nsIDOMCharacterData > charData;
00773 nsString theCharDataValue;
00774 nsString theNodeValue;
00775 char *charValue;
00776 unsigned int index;
00777 bool returnValue = FALSE;
00778 unsigned int selectionLength;
00779
00780
00781
00782 theNode->GetNodeValue(theNodeValue);
00783
00784 if (!theNodeValue.IsEmpty())
00785 {
00786 charData = (do_QueryInterface(theNode));
00787 charData->GetLength(&selectionLength);
00788
00789 if (selectionLength)
00790 {
00791 charData->GetData(theCharDataValue);
00792 charValue = ToNewUTF8String(theCharDataValue);
00793
00794 for (index = 0; index < selectionLength; index++)
00795 {
00796 if ((charValue[index] != '\n') && (charValue[index] != ' '))
00797 {
00798 returnValue = TRUE;
00799 break;
00800 }
00801 }
00802
00803
00804 nsMemory::Free(charValue);
00805 }
00806 else
00807 {
00808 BR_LOGPRINTF("TEXT_NODE has length zero");
00809 }
00810
00811 }
00812 else
00813 {
00814 BR_LOGPRINTF("TEXT_NODE theNode has no value");
00815 }
00816
00817 return returnValue;
00818 }
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828 bool
00829 mozilla_selection_get_node_index(nsCOMPtr < nsIDOMNode > theParentNode,
00830 nsCOMPtr < nsIDOMNode > theChildNode, int *parentNodeIndex, int *childNodeIndex)
00831 {
00832 nsCOMPtr < nsIDOMDocument > domDoc;
00833 nsString theParentNodeName;
00834
00835 nsCOMPtr < nsIDOMNodeList > documentNodeList;
00836 nsCOMPtr < nsIDOMNodeList > childNodeList;
00837 unsigned int documentNodeListLength = 0;
00838 unsigned int childNodeListLength = 0;
00839
00840 nsCOMPtr < nsIDOMNode > node;
00841 nsCOMPtr < nsIDOMNode > childNode;
00842
00843 BR_LOGPRINTF("ENTRY");
00844
00845 if (theParentNode && theChildNode && parentNodeIndex && childNodeIndex)
00846 {
00847
00848 *childNodeIndex = -1;
00849 *parentNodeIndex = -1;
00850
00851 theParentNode->GetOwnerDocument(getter_AddRefs(domDoc));
00852
00853 if (domDoc)
00854 {
00855 theParentNode->GetNodeName(theParentNodeName);
00856 domDoc->GetElementsByTagName(theParentNodeName, getter_AddRefs(documentNodeList));
00857 documentNodeList->GetLength(&documentNodeListLength);
00858
00859 BR_LOGPRINTF("DOM document parent tag name nodeListLength %d", documentNodeListLength);
00860
00861 for (unsigned int index = 0; index < documentNodeListLength; index++)
00862 {
00863 documentNodeList->Item(index, getter_AddRefs(node));
00864
00865 if (node == theParentNode)
00866 {
00867 *parentNodeIndex = index;
00868 BR_LOGPRINTF("selection ParentNodeIndex %d", *parentNodeIndex);
00869
00870 break;
00871 }
00872 }
00873
00874 theParentNode->GetChildNodes(getter_AddRefs(childNodeList));
00875 childNodeList->GetLength(&childNodeListLength);
00876
00877 for (unsigned int index = 0; index < childNodeListLength; index++)
00878 {
00879 childNodeList->Item(index, getter_AddRefs(childNode));
00880 if (childNode == theChildNode)
00881 {
00882 *childNodeIndex = index;
00883 BR_LOGPRINTF("selection childNodeIndex %d", *childNodeIndex);
00884
00885 break;
00886 }
00887 }
00888
00889 BR_LOGPRINTF("EXIT");
00890 return TRUE;
00891 }
00892 else
00893 {
00894 BR_ERRORPRINTF("domDoc == NULL");
00895 }
00896 }
00897 else
00898 {
00899 BR_ERRORPRINTF("invalid input parameters");
00900 }
00901
00902 BR_LOGPRINTF("EXIT");
00903 return FALSE;
00904 }
00905
00906 #endif //SELECTION_ENABLED