diff options
author | Marco Pesenti Gritti <marco@it.gnome.org> | 2003-08-05 23:53:46 +0800 |
---|---|---|
committer | Marco Pesenti Gritti <mpeseng@src.gnome.org> | 2003-08-05 23:53:46 +0800 |
commit | 1d3c560d4e3eb2fea630f2d01d2af05e07c2131d (patch) | |
tree | c45551d88480b9e35899665b149d0bdf975d4677 | |
parent | 0cdb5df549513b32c291378257652adbe286faeb (diff) | |
download | gsoc2013-epiphany-1d3c560d4e3eb2fea630f2d01d2af05e07c2131d.tar gsoc2013-epiphany-1d3c560d4e3eb2fea630f2d01d2af05e07c2131d.tar.gz gsoc2013-epiphany-1d3c560d4e3eb2fea630f2d01d2af05e07c2131d.tar.bz2 gsoc2013-epiphany-1d3c560d4e3eb2fea630f2d01d2af05e07c2131d.tar.lz gsoc2013-epiphany-1d3c560d4e3eb2fea630f2d01d2af05e07c2131d.tar.xz gsoc2013-epiphany-1d3c560d4e3eb2fea630f2d01d2af05e07c2131d.tar.zst gsoc2013-epiphany-1d3c560d4e3eb2fea630f2d01d2af05e07c2131d.zip |
Use link text as bookmark title when no title is specified.
2003-08-05 Marco Pesenti Gritti <marco@it.gnome.org>
* embed/mozilla/EventContext.cpp:
* embed/mozilla/EventContext.h:
* src/popup-commands.c: (popup_cmd_bookmark_link):
Use link text as bookmark title when no title
is specified.
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | embed/mozilla/EventContext.cpp | 85 | ||||
-rw-r--r-- | embed/mozilla/EventContext.h | 1 | ||||
-rw-r--r-- | src/popup-commands.c | 16 |
4 files changed, 106 insertions, 5 deletions
@@ -1,3 +1,12 @@ +2003-08-05 Marco Pesenti Gritti <marco@it.gnome.org> + + * embed/mozilla/EventContext.cpp: + * embed/mozilla/EventContext.h: + * src/popup-commands.c: (popup_cmd_bookmark_link): + + Use link text as bookmark title when no title + is specified. + 2003-08-04 Metin AMiroff <metin@karegen.com> * configure.in: Added az to all linguas. diff --git a/embed/mozilla/EventContext.cpp b/embed/mozilla/EventContext.cpp index 4f518875f..7c30839d0 100644 --- a/embed/mozilla/EventContext.cpp +++ b/embed/mozilla/EventContext.cpp @@ -58,6 +58,84 @@ nsresult EventContext::Init (EphyWrapper *wrapper) return NS_OK; } +nsresult EventContext::GatherTextUnder (nsIDOMNode* aNode, nsString& aResult) +{ + nsAutoString text; + nsCOMPtr<nsIDOMNode> node; + aNode->GetFirstChild(getter_AddRefs(node)); + PRUint32 depth = 1; + + while (node && depth) + { + nsCOMPtr<nsIDOMCharacterData> charData(do_QueryInterface(node)); + PRUint16 nodeType; + + node->GetNodeType(&nodeType); + if (charData && nodeType == nsIDOMNode::TEXT_NODE) + { + /* Add this text to our collection. */ + text += NS_LITERAL_STRING(" "); + nsAutoString data; + charData->GetData(data); + text += data; + } + else + { + nsCOMPtr<nsIDOMHTMLImageElement> img(do_QueryInterface(node)); + if (img) + { + nsAutoString altText; + img->GetAlt(altText); + if (!altText.IsEmpty()) + { + text = altText; + break; + } + } + } + + /* Find the next node to test. */ + PRBool hasChildNodes; + node->HasChildNodes(&hasChildNodes); + if (hasChildNodes) + { + nsCOMPtr<nsIDOMNode> temp = node; + temp->GetFirstChild(getter_AddRefs(node)); + depth++; + } + else + { + nsCOMPtr<nsIDOMNode> nextSibling; + node->GetNextSibling(getter_AddRefs(nextSibling)); + if (nextSibling) + { + node = nextSibling; + } + else + { + nsCOMPtr<nsIDOMNode> parentNode; + node->GetParentNode(getter_AddRefs(parentNode)); + if (!parentNode) + { + node = nsnull; + } + else + { + nsCOMPtr<nsIDOMNode> nextSibling; + parentNode->GetNextSibling(getter_AddRefs(nextSibling)); + node = nextSibling; + depth--; + } + } + } + } + + text.CompressWhitespace(); + aResult = text; + + return NS_OK; +} + nsresult EventContext::ResolveBaseURL (nsIDocument *doc, const nsAString &relurl, nsACString &url) { nsresult rv; @@ -303,9 +381,14 @@ nsresult EventContext::GetEventContext (nsIDOMEventTarget *EventTarget, if (tag.Equals(NS_LITERAL_STRING("a"), nsCaseInsensitiveStringComparator())) { + nsAutoString tmp; + + rv = GatherTextUnder (node, tmp); + if (NS_SUCCEEDED(rv)) + SetStringProperty ("linktext", tmp); + nsCOMPtr <nsIDOMHTMLAnchorElement> anchor = do_QueryInterface(node); - nsAutoString tmp; rv = anchor->GetHref (tmp); if (NS_FAILED(rv)) return NS_ERROR_FAILURE; diff --git a/embed/mozilla/EventContext.h b/embed/mozilla/EventContext.h index 54c51b035..ca59d16dd 100644 --- a/embed/mozilla/EventContext.h +++ b/embed/mozilla/EventContext.h @@ -52,6 +52,7 @@ private: EphyWrapper *mWrapper; nsCOMPtr<nsIDOMDocument> mDOMDocument; + nsresult GatherTextUnder (nsIDOMNode* aNode, nsString& aResult); nsresult ResolveBaseURL (nsIDocument *doc, const nsAString &relurl, nsACString &url); nsresult ResolveDocumentURL (nsIDocument *doc, const nsAString &relurl, nsACString &url); nsresult GetEventContext (nsIDOMEventTarget *EventTarget, diff --git a/src/popup-commands.c b/src/popup-commands.c index 18dd5585c..0b5d112bd 100644 --- a/src/popup-commands.c +++ b/src/popup-commands.c @@ -122,7 +122,7 @@ popup_cmd_image_in_new_window (EggAction *action, void popup_cmd_bookmark_link (EggAction *action, - EphyWindow *window) + EphyWindow *window) { GtkWidget *new_bookmark; EphyBookmarks *bookmarks; @@ -132,6 +132,7 @@ popup_cmd_bookmark_link (EggAction *action, const GValue *link_rel; const GValue *link; const GValue *link_is_smart; + const GValue *linktext; const char *title; const char *location; const char *rel; @@ -144,15 +145,22 @@ popup_cmd_bookmark_link (EggAction *action, ephy_embed_event_get_property (info, "link", &link); ephy_embed_event_get_property (info, "link_title", &link_title); ephy_embed_event_get_property (info, "link_rel", &link_rel); + ephy_embed_event_get_property (info, "linktext", &linktext); - title = g_value_get_string (link_title); location = g_value_get_string (link); + g_return_if_fail (location); + rel = g_value_get_string (link_rel); is_smart = g_value_get_int (link_is_smart); - g_return_if_fail (location); + title = g_value_get_string (link_title); + + if (title == NULL || title[0] == '\0') + { + title = g_value_get_string (linktext); + } - if (!title || !title[0]) + if (title == NULL || title[0] == '\0') { title = location; } |