| 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 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 | 387 |
| 388 void FrameSelection::respondToNodeModification(Node* node, bool baseRemoved, boo
l extentRemoved, bool startRemoved, bool endRemoved) | 388 void FrameSelection::respondToNodeModification(Node* node, bool baseRemoved, boo
l extentRemoved, bool startRemoved, bool endRemoved) |
| 389 { | 389 { |
| 390 bool clearRenderTreeSelection = false; | 390 bool clearRenderTreeSelection = false; |
| 391 bool clearDOMTreeSelection = false; | 391 bool clearDOMTreeSelection = false; |
| 392 | 392 |
| 393 if (startRemoved || endRemoved) { | 393 if (startRemoved || endRemoved) { |
| 394 Position start = m_selection.start(); | 394 Position start = m_selection.start(); |
| 395 Position end = m_selection.end(); | 395 Position end = m_selection.end(); |
| 396 if (startRemoved) | 396 if (startRemoved) |
| 397 updatePositionForNodeRemoval(start, node); | 397 updatePositionForNodeRemoval(start, adoptRawResult(node)); |
| 398 if (endRemoved) | 398 if (endRemoved) |
| 399 updatePositionForNodeRemoval(end, node); | 399 updatePositionForNodeRemoval(end, adoptRawResult(node)); |
| 400 | 400 |
| 401 if (start.isNotNull() && end.isNotNull()) { | 401 if (start.isNotNull() && end.isNotNull()) { |
| 402 if (m_selection.isBaseFirst()) | 402 if (m_selection.isBaseFirst()) |
| 403 m_selection.setWithoutValidation(start, end); | 403 m_selection.setWithoutValidation(start, end); |
| 404 else | 404 else |
| 405 m_selection.setWithoutValidation(end, start); | 405 m_selection.setWithoutValidation(end, start); |
| 406 } else | 406 } else |
| 407 clearDOMTreeSelection = true; | 407 clearDOMTreeSelection = true; |
| 408 | 408 |
| 409 clearRenderTreeSelection = true; | 409 clearRenderTreeSelection = true; |
| (...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1219 { | 1219 { |
| 1220 const bool selectionHasDirection = true; | 1220 const bool selectionHasDirection = true; |
| 1221 setSelection(VisibleSelection(m_selection.base(), pos, affinity, selectionHa
sDirection), CloseTyping | ClearTypingStyle | userTriggered); | 1221 setSelection(VisibleSelection(m_selection.base(), pos, affinity, selectionHa
sDirection), CloseTyping | ClearTypingStyle | userTriggered); |
| 1222 } | 1222 } |
| 1223 | 1223 |
| 1224 void CaretBase::clearCaretRect() | 1224 void CaretBase::clearCaretRect() |
| 1225 { | 1225 { |
| 1226 m_caretLocalRect = LayoutRect(); | 1226 m_caretLocalRect = LayoutRect(); |
| 1227 } | 1227 } |
| 1228 | 1228 |
| 1229 static inline bool caretRendersInsideNode(Node* node) | 1229 static inline bool caretRendersInsideNode(const Handle<Node>& node) |
| 1230 { | 1230 { |
| 1231 return node && !isTableElement(node) && !editingIgnoresContent(node); | 1231 return node && !isTableElement(node) && !editingIgnoresContent(node); |
| 1232 } | 1232 } |
| 1233 | 1233 |
| 1234 static RenderObject* caretRenderer(Node* node) | 1234 static RenderObject* caretRenderer(Node* node) |
| 1235 { | 1235 { |
| 1236 if (!node) | 1236 if (!node) |
| 1237 return 0; | 1237 return 0; |
| 1238 | 1238 |
| 1239 RenderObject* renderer = node->renderer(); | 1239 RenderObject* renderer = node->renderer(); |
| 1240 if (!renderer) | 1240 if (!renderer) |
| 1241 return 0; | 1241 return 0; |
| 1242 | 1242 |
| 1243 // if caretNode is a block and caret is inside it then caret should be paint
ed by that block | 1243 // if caretNode is a block and caret is inside it then caret should be paint
ed by that block |
| 1244 bool paintedByBlock = renderer->isBlockFlow() && caretRendersInsideNode(node
); | 1244 bool paintedByBlock = renderer->isBlockFlow() && caretRendersInsideNode(adop
tRawResult(node)); |
| 1245 return paintedByBlock ? renderer : renderer->containingBlock(); | 1245 return paintedByBlock ? renderer : renderer->containingBlock(); |
| 1246 } | 1246 } |
| 1247 | 1247 |
| 1248 bool CaretBase::updateCaretRect(const Handle<Document>& document, const VisibleP
osition& caretPosition) | 1248 bool CaretBase::updateCaretRect(const Handle<Document>& document, const VisibleP
osition& caretPosition) |
| 1249 { | 1249 { |
| 1250 document->updateStyleIfNeeded(); | 1250 document->updateStyleIfNeeded(); |
| 1251 m_caretLocalRect = LayoutRect(); | 1251 m_caretLocalRect = LayoutRect(); |
| 1252 | 1252 |
| 1253 m_caretRectNeedsUpdate = false; | 1253 m_caretRectNeedsUpdate = false; |
| 1254 | 1254 |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1601 Handle<HTMLSelectElement> selectElement = toHTMLSelectElement(document->
focusedNode()); | 1601 Handle<HTMLSelectElement> selectElement = toHTMLSelectElement(document->
focusedNode()); |
| 1602 if (selectElement->canSelectAll()) { | 1602 if (selectElement->canSelectAll()) { |
| 1603 selectElement->selectAll(); | 1603 selectElement->selectAll(); |
| 1604 return; | 1604 return; |
| 1605 } | 1605 } |
| 1606 } | 1606 } |
| 1607 | 1607 |
| 1608 Handle<Node> root; | 1608 Handle<Node> root; |
| 1609 Handle<Node> selectStartTarget; | 1609 Handle<Node> selectStartTarget; |
| 1610 if (isContentEditable()) { | 1610 if (isContentEditable()) { |
| 1611 root = adoptRawResult(highestEditableRoot(m_selection.start())); | 1611 root = highestEditableRoot(m_selection.start()); |
| 1612 if (Node* shadowRoot = m_selection.nonBoundaryShadowTreeRootNode()) | 1612 if (Node* shadowRoot = m_selection.nonBoundaryShadowTreeRootNode()) |
| 1613 selectStartTarget = shadowRoot->shadowHost(); | 1613 selectStartTarget = shadowRoot->shadowHost(); |
| 1614 else | 1614 else |
| 1615 selectStartTarget = root; | 1615 selectStartTarget = root; |
| 1616 } else { | 1616 } else { |
| 1617 root = adoptRawResult(m_selection.nonBoundaryShadowTreeRootNode()); | 1617 root = adoptRawResult(m_selection.nonBoundaryShadowTreeRootNode()); |
| 1618 if (root) | 1618 if (root) |
| 1619 selectStartTarget = root->shadowHost(); | 1619 selectStartTarget = root->shadowHost(); |
| 1620 else { | 1620 else { |
| 1621 root = document->documentElement(); | 1621 root = document->documentElement(); |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1842 return widget && widget->isFrameView(); | 1842 return widget && widget->isFrameView(); |
| 1843 } | 1843 } |
| 1844 | 1844 |
| 1845 void FrameSelection::setFocusedNodeIfNeeded() | 1845 void FrameSelection::setFocusedNodeIfNeeded() |
| 1846 { | 1846 { |
| 1847 if (isNone() || !isFocused()) | 1847 if (isNone() || !isFocused()) |
| 1848 return; | 1848 return; |
| 1849 | 1849 |
| 1850 bool caretBrowsing = m_frame->settings() && m_frame->settings()->caretBrowsi
ngEnabled(); | 1850 bool caretBrowsing = m_frame->settings() && m_frame->settings()->caretBrowsi
ngEnabled(); |
| 1851 if (caretBrowsing) { | 1851 if (caretBrowsing) { |
| 1852 if (Node* anchor = enclosingAnchorElement(base())) { | 1852 if (Handle<Node> anchor = enclosingAnchorElement(base())) { |
| 1853 m_frame->page()->focusController()->setFocusedNode(adoptRawResult(an
chor), m_frame); | 1853 m_frame->page()->focusController()->setFocusedNode(anchor, m_frame); |
| 1854 return; | 1854 return; |
| 1855 } | 1855 } |
| 1856 } | 1856 } |
| 1857 | 1857 |
| 1858 if (Handle<Node> target = rootEditableElement()) { | 1858 if (Handle<Node> target = rootEditableElement()) { |
| 1859 // Walk up the DOM tree to search for a node to focus. | 1859 // Walk up the DOM tree to search for a node to focus. |
| 1860 while (target) { | 1860 while (target) { |
| 1861 // We don't want to set focus on a subframe when selecting in a pare
nt frame, | 1861 // We don't want to set focus on a subframe when selecting in a pare
nt frame, |
| 1862 // so add the !isFrameElement check here. There's probably a better
way to make this | 1862 // so add the !isFrameElement check here. There's probably a better
way to make this |
| 1863 // work in the long term, but this is the safest fix at this time. | 1863 // work in the long term, but this is the safest fix at this time. |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2000 bool caretBrowsing = m_frame->settings() && m_frame->settings()->caretBrowsi
ngEnabled(); | 2000 bool caretBrowsing = m_frame->settings() && m_frame->settings()->caretBrowsi
ngEnabled(); |
| 2001 if (!isNone() || !(document->rendererIsEditable() || caretBrowsing)) | 2001 if (!isNone() || !(document->rendererIsEditable() || caretBrowsing)) |
| 2002 return; | 2002 return; |
| 2003 | 2003 |
| 2004 Handle<Node> node = document->documentElement(); | 2004 Handle<Node> node = document->documentElement(); |
| 2005 while (node && !node->hasTagName(bodyTag)) { | 2005 while (node && !node->hasTagName(bodyTag)) { |
| 2006 HandleScope scope; | 2006 HandleScope scope; |
| 2007 node = NodeTraversal::next(node); | 2007 node = NodeTraversal::next(node); |
| 2008 } | 2008 } |
| 2009 if (node) | 2009 if (node) |
| 2010 setSelection(VisibleSelection(firstPositionInOrBeforeNode(node.raw()), D
OWNSTREAM)); | 2010 setSelection(VisibleSelection(firstPositionInOrBeforeNode(node), DOWNSTR
EAM)); |
| 2011 } | 2011 } |
| 2012 | 2012 |
| 2013 bool FrameSelection::shouldChangeSelection(const VisibleSelection& newSelection)
const | 2013 bool FrameSelection::shouldChangeSelection(const VisibleSelection& newSelection)
const |
| 2014 { | 2014 { |
| 2015 return m_frame->editor()->shouldChangeSelection(selection(), newSelection, n
ewSelection.affinity(), false); | 2015 return m_frame->editor()->shouldChangeSelection(selection(), newSelection, n
ewSelection.affinity(), false); |
| 2016 } | 2016 } |
| 2017 | 2017 |
| 2018 bool FrameSelection::dispatchSelectStart() | 2018 bool FrameSelection::dispatchSelectStart() |
| 2019 { | 2019 { |
| 2020 Handle<Node> selectStartTarget = m_selection.extent().containerNode(); | 2020 Handle<Node> selectStartTarget = m_selection.extent().containerNode(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2053 sel.showTreeForThis(); | 2053 sel.showTreeForThis(); |
| 2054 } | 2054 } |
| 2055 | 2055 |
| 2056 void showTree(const WebCore::FrameSelection* sel) | 2056 void showTree(const WebCore::FrameSelection* sel) |
| 2057 { | 2057 { |
| 2058 if (sel) | 2058 if (sel) |
| 2059 sel->showTreeForThis(); | 2059 sel->showTreeForThis(); |
| 2060 } | 2060 } |
| 2061 | 2061 |
| 2062 #endif | 2062 #endif |
| OLD | NEW |