Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Side by Side Diff: Source/core/editing/FrameSelection.cpp

Issue 201293002: Add Traversal<*Element>::firstAncestor() API (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add firstAncestorOrSelf() Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/ElementTraversal.h ('k') | Source/core/html/HTMLElement.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 1702 matching lines...) Expand 10 before | Expand all | Expand 10 after
1713 FrameView* view = m_frame->view(); 1713 FrameView* view = m_frame->view();
1714 RenderView* renderView = m_frame->contentRenderer(); 1714 RenderView* renderView = m_frame->contentRenderer();
1715 1715
1716 if (!view || !renderView) 1716 if (!view || !renderView)
1717 return FloatRect(); 1717 return FloatRect();
1718 1718
1719 LayoutRect selectionRect = renderView->selectionBounds(clipToVisibleContent) ; 1719 LayoutRect selectionRect = renderView->selectionBounds(clipToVisibleContent) ;
1720 return clipToVisibleContent ? intersection(selectionRect, view->visibleConte ntRect()) : selectionRect; 1720 return clipToVisibleContent ? intersection(selectionRect, view->visibleConte ntRect()) : selectionRect;
1721 } 1721 }
1722 1722
1723 static inline HTMLFormElement* associatedFormElement(HTMLElement& element)
1724 {
1725 if (isHTMLFormElement(element))
1726 return &toHTMLFormElement(element);
1727 return element.formOwner();
1728 }
1729
1723 // Scans logically forward from "start", including any child frames. 1730 // Scans logically forward from "start", including any child frames.
1724 static HTMLFormElement* scanForForm(Node* start) 1731 static HTMLFormElement* scanForForm(Node* start)
1725 { 1732 {
1726 if (!start) 1733 if (!start)
1727 return 0; 1734 return 0;
1735
1728 HTMLElement* element = start->isHTMLElement() ? toHTMLElement(start) : Trave rsal<HTMLElement>::next(*start); 1736 HTMLElement* element = start->isHTMLElement() ? toHTMLElement(start) : Trave rsal<HTMLElement>::next(*start);
1729 for (; element; element = Traversal<HTMLElement>::next(*element)) { 1737 for (; element; element = Traversal<HTMLElement>::next(*element)) {
1730 if (isHTMLFormElement(*element)) 1738 if (HTMLFormElement* form = associatedFormElement(*element))
1731 return toHTMLFormElement(element); 1739 return form;
1732
1733 if (HTMLFormElement* owner = element->formOwner())
1734 return owner;
1735 1740
1736 if (isHTMLFrameElementBase(*element)) { 1741 if (isHTMLFrameElementBase(*element)) {
1737 Node* childDocument = toHTMLFrameElementBase(*element).contentDocume nt(); 1742 Node* childDocument = toHTMLFrameElementBase(*element).contentDocume nt();
1738 if (HTMLFormElement* frameResult = scanForForm(childDocument)) 1743 if (HTMLFormElement* frameResult = scanForForm(childDocument))
1739 return frameResult; 1744 return frameResult;
1740 } 1745 }
1741 } 1746 }
1742 return 0; 1747 return 0;
1743 } 1748 }
1744 1749
1745 // We look for either the form containing the current focus, or for one immediat ely after it 1750 // We look for either the form containing the current focus, or for one immediat ely after it
1746 HTMLFormElement* FrameSelection::currentForm() const 1751 HTMLFormElement* FrameSelection::currentForm() const
1747 { 1752 {
1748 // Start looking either at the active (first responder) node, or where the s election is. 1753 // Start looking either at the active (first responder) node, or where the s election is.
1749 Node* start = m_frame->document()->focusedElement(); 1754 Node* start = m_frame->document()->focusedElement();
1750 if (!start) 1755 if (!start)
1751 start = this->start().deprecatedNode(); 1756 start = this->start().deprecatedNode();
1757 if (!start)
1758 return 0;
1752 1759
1753 // Try walking up the node tree to find a form element. 1760 // Try walking up the node tree to find a form element.
1754 Node* node; 1761 for (HTMLElement* element = Traversal<HTMLElement>::firstAncestorOrSelf(*sta rt); element; element = Traversal<HTMLElement>::firstAncestor(*element)) {
1755 for (node = start; node; node = node->parentNode()) { 1762 if (HTMLFormElement* form = associatedFormElement(*element))
1756 if (isHTMLFormElement(*node)) 1763 return form;
1757 return toHTMLFormElement(node);
1758 if (node->isHTMLElement()) {
1759 HTMLFormElement* owner = toHTMLElement(node)->formOwner();
1760 if (owner)
1761 return owner;
1762 }
1763 } 1764 }
1764 1765
1765 // Try walking forward in the node tree to find a form element. 1766 // Try walking forward in the node tree to find a form element.
1766 return scanForForm(start); 1767 return scanForForm(start);
1767 } 1768 }
1768 1769
1769 void FrameSelection::revealSelection(const ScrollAlignment& alignment, RevealExt entOption revealExtentOption) 1770 void FrameSelection::revealSelection(const ScrollAlignment& alignment, RevealExt entOption revealExtentOption)
1770 { 1771 {
1771 LayoutRect rect; 1772 LayoutRect rect;
1772 1773
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1875 sel.showTreeForThis(); 1876 sel.showTreeForThis();
1876 } 1877 }
1877 1878
1878 void showTree(const WebCore::FrameSelection* sel) 1879 void showTree(const WebCore::FrameSelection* sel)
1879 { 1880 {
1880 if (sel) 1881 if (sel)
1881 sel->showTreeForThis(); 1882 sel->showTreeForThis();
1882 } 1883 }
1883 1884
1884 #endif 1885 #endif
OLDNEW
« no previous file with comments | « Source/core/dom/ElementTraversal.h ('k') | Source/core/html/HTMLElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698