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

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

Issue 196683003: Use new is*Element() helper functions more in editing code (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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
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 29 matching lines...) Expand all
40 #include "core/editing/Editor.h" 40 #include "core/editing/Editor.h"
41 #include "core/editing/InputMethodController.h" 41 #include "core/editing/InputMethodController.h"
42 #include "core/editing/RenderedPosition.h" 42 #include "core/editing/RenderedPosition.h"
43 #include "core/editing/SpellChecker.h" 43 #include "core/editing/SpellChecker.h"
44 #include "core/editing/TextIterator.h" 44 #include "core/editing/TextIterator.h"
45 #include "core/editing/TypingCommand.h" 45 #include "core/editing/TypingCommand.h"
46 #include "core/editing/VisibleUnits.h" 46 #include "core/editing/VisibleUnits.h"
47 #include "core/editing/htmlediting.h" 47 #include "core/editing/htmlediting.h"
48 #include "core/frame/DOMWindow.h" 48 #include "core/frame/DOMWindow.h"
49 #include "core/frame/LocalFrame.h" 49 #include "core/frame/LocalFrame.h"
50 #include "core/html/HTMLBodyElement.h"
50 #include "core/html/HTMLFormElement.h" 51 #include "core/html/HTMLFormElement.h"
51 #include "core/html/HTMLFrameElementBase.h" 52 #include "core/html/HTMLFrameElementBase.h"
52 #include "core/html/HTMLInputElement.h" 53 #include "core/html/HTMLInputElement.h"
53 #include "core/html/HTMLSelectElement.h" 54 #include "core/html/HTMLSelectElement.h"
54 #include "core/page/EditorClient.h" 55 #include "core/page/EditorClient.h"
55 #include "core/page/EventHandler.h" 56 #include "core/page/EventHandler.h"
56 #include "core/page/FocusController.h" 57 #include "core/page/FocusController.h"
57 #include "core/page/FrameTree.h" 58 #include "core/page/FrameTree.h"
58 #include "core/frame/FrameView.h" 59 #include "core/frame/FrameView.h"
59 #include "core/page/Page.h" 60 #include "core/page/Page.h"
(...skipping 1294 matching lines...) Expand 10 before | Expand all | Expand 10 after
1354 // Focus on the parent frame, and then select from before this element to af ter. 1355 // Focus on the parent frame, and then select from before this element to af ter.
1355 VisibleSelection newSelection(beforeOwnerElement, afterOwnerElement); 1356 VisibleSelection newSelection(beforeOwnerElement, afterOwnerElement);
1356 page->focusController().setFocusedFrame(parent); 1357 page->focusController().setFocusedFrame(parent);
1357 parent->selection().setSelection(newSelection); 1358 parent->selection().setSelection(newSelection);
1358 } 1359 }
1359 1360
1360 void FrameSelection::selectAll() 1361 void FrameSelection::selectAll()
1361 { 1362 {
1362 Document* document = m_frame->document(); 1363 Document* document = m_frame->document();
1363 1364
1364 if (document->focusedElement() && document->focusedElement()->hasTagName(sel ectTag)) { 1365 if (isHTMLSelectElement(document->focusedElement())) {
1365 HTMLSelectElement* selectElement = toHTMLSelectElement(document->focused Element()); 1366 HTMLSelectElement* selectElement = toHTMLSelectElement(document->focused Element());
1366 if (selectElement->canSelectAll()) { 1367 if (selectElement->canSelectAll()) {
1367 selectElement->selectAll(); 1368 selectElement->selectAll();
1368 return; 1369 return;
1369 } 1370 }
1370 } 1371 }
1371 1372
1372 RefPtr<Node> root = nullptr; 1373 RefPtr<Node> root = nullptr;
1373 Node* selectStartTarget = 0; 1374 Node* selectStartTarget = 0;
1374 if (isContentEditable()) { 1375 if (isContentEditable()) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1430 PassRefPtr<Range> FrameSelection::firstRange() const 1431 PassRefPtr<Range> FrameSelection::firstRange() const
1431 { 1432 {
1432 if (m_logicalRange) 1433 if (m_logicalRange)
1433 return m_logicalRange->cloneRange(ASSERT_NO_EXCEPTION); 1434 return m_logicalRange->cloneRange(ASSERT_NO_EXCEPTION);
1434 return m_selection.firstRange(); 1435 return m_selection.firstRange();
1435 } 1436 }
1436 1437
1437 bool FrameSelection::isInPasswordField() const 1438 bool FrameSelection::isInPasswordField() const
1438 { 1439 {
1439 HTMLTextFormControlElement* textControl = enclosingTextFormControl(start()); 1440 HTMLTextFormControlElement* textControl = enclosingTextFormControl(start());
1440 return textControl && textControl->hasTagName(inputTag) && toHTMLInputElemen t(textControl)->isPasswordField(); 1441 return isHTMLInputElement(textControl) && toHTMLInputElement(textControl)->i sPasswordField();
1441 } 1442 }
1442 1443
1443 void FrameSelection::notifyAccessibilityForSelectionChange() 1444 void FrameSelection::notifyAccessibilityForSelectionChange()
1444 { 1445 {
1445 if (m_selection.start().isNotNull() && m_selection.end().isNotNull()) { 1446 if (m_selection.start().isNotNull() && m_selection.end().isNotNull()) {
1446 if (AXObjectCache* cache = m_frame->document()->existingAXObjectCache()) 1447 if (AXObjectCache* cache = m_frame->document()->existingAXObjectCache())
1447 cache->selectionChanged(m_selection.start().containerNode()); 1448 cache->selectionChanged(m_selection.start().containerNode());
1448 } 1449 }
1449 } 1450 }
1450 1451
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1717 1718
1718 LayoutRect selectionRect = renderView->selectionBounds(clipToVisibleContent) ; 1719 LayoutRect selectionRect = renderView->selectionBounds(clipToVisibleContent) ;
1719 return clipToVisibleContent ? intersection(selectionRect, view->visibleConte ntRect()) : selectionRect; 1720 return clipToVisibleContent ? intersection(selectionRect, view->visibleConte ntRect()) : selectionRect;
1720 } 1721 }
1721 1722
1722 // Scans logically forward from "start", including any child frames. 1723 // Scans logically forward from "start", including any child frames.
1723 static HTMLFormElement* scanForForm(Node* start) 1724 static HTMLFormElement* scanForForm(Node* start)
1724 { 1725 {
1725 if (!start) 1726 if (!start)
1726 return 0; 1727 return 0;
1727 Element* element = start->isElementNode() ? toElement(start) : ElementTraver sal::next(*start); 1728 HTMLElement* element = start->isHTMLElement() ? toHTMLElement(start) : Trave rsal<HTMLElement>::next(*start);
1728 for (; element; element = ElementTraversal::next(*element)) { 1729 for (; element; element = Traversal<HTMLElement>::next(*element)) {
1729 if (element->hasTagName(formTag)) 1730 if (isHTMLFormElement(*element))
1730 return toHTMLFormElement(element); 1731 return toHTMLFormElement(element);
1731 if (element->isHTMLElement()) { 1732
1732 HTMLFormElement* owner = toHTMLElement(element)->formOwner(); 1733 if (HTMLFormElement* owner = element->formOwner())
1733 if (owner)
1734 return owner; 1734 return owner;
1735 } 1735
1736 if (element->hasTagName(frameTag) || element->hasTagName(iframeTag)) { 1736 if (isHTMLFrameElement(*element) || isHTMLIFrameElement(*element)) {
1737 Node* childDocument = toHTMLFrameElementBase(element)->contentDocume nt(); 1737 Node* childDocument = toHTMLFrameElementBase(*element).contentDocume nt();
1738 if (HTMLFormElement* frameResult = scanForForm(childDocument)) 1738 if (HTMLFormElement* frameResult = scanForForm(childDocument))
1739 return frameResult; 1739 return frameResult;
1740 } 1740 }
1741 } 1741 }
1742 return 0; 1742 return 0;
1743 } 1743 }
1744 1744
1745 // We look for either the form containing the current focus, or for one immediat ely after it 1745 // We look for either the form containing the current focus, or for one immediat ely after it
1746 HTMLFormElement* FrameSelection::currentForm() const 1746 HTMLFormElement* FrameSelection::currentForm() const
1747 { 1747 {
1748 // Start looking either at the active (first responder) node, or where the s election is. 1748 // Start looking either at the active (first responder) node, or where the s election is.
1749 Node* start = m_frame->document()->focusedElement(); 1749 Node* start = m_frame->document()->focusedElement();
1750 if (!start) 1750 if (!start)
1751 start = this->start().deprecatedNode(); 1751 start = this->start().deprecatedNode();
1752 1752
1753 // Try walking up the node tree to find a form element. 1753 // Try walking up the node tree to find a form element.
1754 Node* node; 1754 Node* node;
1755 for (node = start; node; node = node->parentNode()) { 1755 for (node = start; node; node = node->parentNode()) {
1756 if (node->hasTagName(formTag)) 1756 if (isHTMLFormElement(*node))
1757 return toHTMLFormElement(node); 1757 return toHTMLFormElement(node);
1758 if (node->isHTMLElement()) { 1758 if (node->isHTMLElement()) {
1759 HTMLFormElement* owner = toHTMLElement(node)->formOwner(); 1759 HTMLFormElement* owner = toHTMLElement(node)->formOwner();
1760 if (owner) 1760 if (owner)
1761 return owner; 1761 return owner;
1762 } 1762 }
1763 } 1763 }
1764 1764
1765 // Try walking forward in the node tree to find a form element. 1765 // Try walking forward in the node tree to find a form element.
1766 return scanForForm(start); 1766 return scanForForm(start);
(...skipping 29 matching lines...) Expand all
1796 { 1796 {
1797 // Put a caret inside the body if the entire frame is editable (either the 1797 // Put a caret inside the body if the entire frame is editable (either the
1798 // entire WebView is editable or designMode is on for this document). 1798 // entire WebView is editable or designMode is on for this document).
1799 1799
1800 Document* document = m_frame->document(); 1800 Document* document = m_frame->document();
1801 bool caretBrowsing = m_frame->settings() && m_frame->settings()->caretBrowsi ngEnabled(); 1801 bool caretBrowsing = m_frame->settings() && m_frame->settings()->caretBrowsi ngEnabled();
1802 if (!isNone() || !(document->rendererIsEditable() || caretBrowsing)) 1802 if (!isNone() || !(document->rendererIsEditable() || caretBrowsing))
1803 return; 1803 return;
1804 1804
1805 Node* node = document->documentElement(); 1805 Node* node = document->documentElement();
1806 while (node && !node->hasTagName(bodyTag)) 1806 if (!node)
1807 node = NodeTraversal::next(*node); 1807 return;
1808 if (node) 1808 Node* body = isHTMLBodyElement(*node) ? node : Traversal<HTMLBodyElement>::n ext(*node);
1809 setSelection(VisibleSelection(firstPositionInOrBeforeNode(node), DOWNSTR EAM)); 1809 if (body)
1810 setSelection(VisibleSelection(firstPositionInOrBeforeNode(body), DOWNSTR EAM));
1810 } 1811 }
1811 1812
1812 bool FrameSelection::dispatchSelectStart() 1813 bool FrameSelection::dispatchSelectStart()
1813 { 1814 {
1814 Node* selectStartTarget = m_selection.extent().containerNode(); 1815 Node* selectStartTarget = m_selection.extent().containerNode();
1815 if (!selectStartTarget) 1816 if (!selectStartTarget)
1816 return true; 1817 return true;
1817 1818
1818 return selectStartTarget->dispatchEvent(Event::createCancelableBubble(EventT ypeNames::selectstart)); 1819 return selectStartTarget->dispatchEvent(Event::createCancelableBubble(EventT ypeNames::selectstart));
1819 } 1820 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1874 sel.showTreeForThis(); 1875 sel.showTreeForThis();
1875 } 1876 }
1876 1877
1877 void showTree(const WebCore::FrameSelection* sel) 1878 void showTree(const WebCore::FrameSelection* sel)
1878 { 1879 {
1879 if (sel) 1880 if (sel)
1880 sel->showTreeForThis(); 1881 sel->showTreeForThis();
1881 } 1882 }
1882 1883
1883 #endif 1884 #endif
OLDNEW
« no previous file with comments | « Source/core/editing/FormatBlockCommand.cpp ('k') | Source/core/editing/IndentOutdentCommand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698