OLD | NEW |
---|---|
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 Loading... | |
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; | |
1759 | |
1760 // Check current Node to find a form element. | |
1761 if (start->isHTMLElement()) { | |
1762 if (HTMLFormElement* form = associatedFormElement(toHTMLElement(*start)) ) | |
1763 return form; | |
1764 } | |
1752 | 1765 |
1753 // Try walking up the node tree to find a form element. | 1766 // Try walking up the node tree to find a form element. |
1754 Node* node; | 1767 for (HTMLElement* element = Traversal<HTMLElement>::firstAncestor(*start); e lement; element = Traversal<HTMLElement>::firstAncestor(*element)) { |
esprehn
2014/03/27 13:28:16
Couldn't we just add ::firstAncestorOrSelf(Node*)
Inactive
2014/03/27 13:32:05
Excellent idea. I thought about it but couldn't co
| |
1755 for (node = start; node; node = node->parentNode()) { | 1768 if (HTMLFormElement* form = associatedFormElement(*element)) |
1756 if (isHTMLFormElement(*node)) | 1769 return form; |
1757 return toHTMLFormElement(node); | |
1758 if (node->isHTMLElement()) { | |
1759 HTMLFormElement* owner = toHTMLElement(node)->formOwner(); | |
1760 if (owner) | |
1761 return owner; | |
1762 } | |
1763 } | 1770 } |
1764 | 1771 |
1765 // Try walking forward in the node tree to find a form element. | 1772 // Try walking forward in the node tree to find a form element. |
1766 return scanForForm(start); | 1773 return scanForForm(start); |
1767 } | 1774 } |
1768 | 1775 |
1769 void FrameSelection::revealSelection(const ScrollAlignment& alignment, RevealExt entOption revealExtentOption) | 1776 void FrameSelection::revealSelection(const ScrollAlignment& alignment, RevealExt entOption revealExtentOption) |
1770 { | 1777 { |
1771 LayoutRect rect; | 1778 LayoutRect rect; |
1772 | 1779 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1875 sel.showTreeForThis(); | 1882 sel.showTreeForThis(); |
1876 } | 1883 } |
1877 | 1884 |
1878 void showTree(const WebCore::FrameSelection* sel) | 1885 void showTree(const WebCore::FrameSelection* sel) |
1879 { | 1886 { |
1880 if (sel) | 1887 if (sel) |
1881 sel->showTreeForThis(); | 1888 sel->showTreeForThis(); |
1882 } | 1889 } |
1883 | 1890 |
1884 #endif | 1891 #endif |
OLD | NEW |