| 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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 SetSelectionOptions options = CloseTyping | ClearTypingStyle | userTriggered
; | 168 SetSelectionOptions options = CloseTyping | ClearTypingStyle | userTriggered
; |
| 169 setSelection(VisibleSelection(pos, pos, selection().isDirectional()), option
s, align); | 169 setSelection(VisibleSelection(pos, pos, selection().isDirectional()), option
s, align); |
| 170 } | 170 } |
| 171 | 171 |
| 172 void FrameSelection::moveTo(const Position &pos, TextAffinity affinity) | 172 void FrameSelection::moveTo(const Position &pos, TextAffinity affinity) |
| 173 { | 173 { |
| 174 SetSelectionOptions options = CloseTyping | ClearTypingStyle; | 174 SetSelectionOptions options = CloseTyping | ClearTypingStyle; |
| 175 setSelection(VisibleSelection(pos, affinity, selection().isDirectional()), o
ptions); | 175 setSelection(VisibleSelection(pos, affinity, selection().isDirectional()), o
ptions); |
| 176 } | 176 } |
| 177 | 177 |
| 178 // TODO(xiaochengh): We should not use reference to return value. |
| 178 template <typename Strategy> | 179 template <typename Strategy> |
| 179 static void adjustEndpointsAtBidiBoundary(VisiblePositionTemplate<Strategy>& vis
ibleBase, VisiblePositionTemplate<Strategy>& visibleExtent) | 180 static void adjustEndpointsAtBidiBoundary(VisiblePositionTemplate<Strategy>& vis
ibleBase, VisiblePositionTemplate<Strategy>& visibleExtent) |
| 180 { | 181 { |
| 182 // TODO(xiaochengh): Replace it with |DCHECK(visibleBase.isValid())| and |
| 183 // |DCHECK(visibleExtent.isValid())| once |VisiblePosition::isValid| is |
| 184 // implemented. |
| 185 DCHECK(visibleBase.isNull() || !visibleBase.deepEquivalent().document()->nee
dsLayoutTreeUpdate()); |
| 186 |
| 181 RenderedPosition base(visibleBase); | 187 RenderedPosition base(visibleBase); |
| 182 RenderedPosition extent(visibleExtent); | 188 RenderedPosition extent(visibleExtent); |
| 183 | 189 |
| 184 if (base.isNull() || extent.isNull() || base.isEquivalent(extent)) | 190 if (base.isNull() || extent.isNull() || base.isEquivalent(extent)) |
| 185 return; | 191 return; |
| 186 | 192 |
| 187 if (base.atLeftBoundaryOfBidiRun()) { | 193 if (base.atLeftBoundaryOfBidiRun()) { |
| 188 if (!extent.atRightBoundaryOfBidiRun(base.bidiLevelOnRight()) | 194 if (!extent.atRightBoundaryOfBidiRun(base.bidiLevelOnRight()) |
| 189 && base.isEquivalent(extent.leftBoundaryOfBidiRun(base.bidiLevelOnRi
ght()))) { | 195 && base.isEquivalent(extent.leftBoundaryOfBidiRun(base.bidiLevelOnRi
ght()))) { |
| 190 visibleBase = createVisiblePositionDeprecated(fromPositionInDOMTree<
Strategy>(base.positionAtLeftBoundaryOfBiDiRun())); | 196 visibleBase = createVisiblePosition(fromPositionInDOMTree<Strategy>(
base.positionAtLeftBoundaryOfBiDiRun())); |
| 191 return; | 197 return; |
| 192 } | 198 } |
| 193 return; | 199 return; |
| 194 } | 200 } |
| 195 | 201 |
| 196 if (base.atRightBoundaryOfBidiRun()) { | 202 if (base.atRightBoundaryOfBidiRun()) { |
| 197 if (!extent.atLeftBoundaryOfBidiRun(base.bidiLevelOnLeft()) | 203 if (!extent.atLeftBoundaryOfBidiRun(base.bidiLevelOnLeft()) |
| 198 && base.isEquivalent(extent.rightBoundaryOfBidiRun(base.bidiLevelOnL
eft()))) { | 204 && base.isEquivalent(extent.rightBoundaryOfBidiRun(base.bidiLevelOnL
eft()))) { |
| 199 visibleBase = createVisiblePositionDeprecated(fromPositionInDOMTree<
Strategy>(base.positionAtRightBoundaryOfBiDiRun())); | 205 visibleBase = createVisiblePosition(fromPositionInDOMTree<Strategy>(
base.positionAtRightBoundaryOfBiDiRun())); |
| 200 return; | 206 return; |
| 201 } | 207 } |
| 202 return; | 208 return; |
| 203 } | 209 } |
| 204 | 210 |
| 205 if (extent.atLeftBoundaryOfBidiRun() && extent.isEquivalent(base.leftBoundar
yOfBidiRun(extent.bidiLevelOnRight()))) { | 211 if (extent.atLeftBoundaryOfBidiRun() && extent.isEquivalent(base.leftBoundar
yOfBidiRun(extent.bidiLevelOnRight()))) { |
| 206 visibleExtent = createVisiblePositionDeprecated(fromPositionInDOMTree<St
rategy>(extent.positionAtLeftBoundaryOfBiDiRun())); | 212 visibleExtent = createVisiblePosition(fromPositionInDOMTree<Strategy>(ex
tent.positionAtLeftBoundaryOfBiDiRun())); |
| 207 return; | 213 return; |
| 208 } | 214 } |
| 209 | 215 |
| 210 if (extent.atRightBoundaryOfBidiRun() && extent.isEquivalent(base.rightBound
aryOfBidiRun(extent.bidiLevelOnLeft()))) { | 216 if (extent.atRightBoundaryOfBidiRun() && extent.isEquivalent(base.rightBound
aryOfBidiRun(extent.bidiLevelOnLeft()))) { |
| 211 visibleExtent = createVisiblePositionDeprecated(fromPositionInDOMTree<St
rategy>(extent.positionAtRightBoundaryOfBiDiRun())); | 217 visibleExtent = createVisiblePosition(fromPositionInDOMTree<Strategy>(ex
tent.positionAtRightBoundaryOfBiDiRun())); |
| 212 return; | 218 return; |
| 213 } | 219 } |
| 214 } | 220 } |
| 215 | 221 |
| 216 void FrameSelection::setNonDirectionalSelectionIfNeeded(const VisibleSelectionIn
FlatTree& passedNewSelection, TextGranularity granularity, EndPointsAdjustmentMo
de endpointsAdjustmentMode) | 222 void FrameSelection::setNonDirectionalSelectionIfNeeded(const VisibleSelectionIn
FlatTree& passedNewSelection, TextGranularity granularity, EndPointsAdjustmentMo
de endpointsAdjustmentMode) |
| 217 { | 223 { |
| 218 VisibleSelectionInFlatTree newSelection = passedNewSelection; | 224 VisibleSelectionInFlatTree newSelection = passedNewSelection; |
| 219 bool isDirectional = shouldAlwaysUseDirectionalSelection(m_frame) || newSele
ction.isDirectional(); | 225 bool isDirectional = shouldAlwaysUseDirectionalSelection(m_frame) || newSele
ction.isDirectional(); |
| 220 | 226 |
| 227 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
| 228 // needs to be audited. See http://crbug.com/590369 for more details. |
| 229 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 230 |
| 221 const PositionInFlatTree basePosition = m_originalBaseInFlatTree.deepEquival
ent(); | 231 const PositionInFlatTree basePosition = m_originalBaseInFlatTree.deepEquival
ent(); |
| 222 const VisiblePositionInFlatTree originalBase = basePosition.isConnected() ?
createVisiblePositionDeprecated(basePosition) : VisiblePositionInFlatTree(); | 232 const VisiblePositionInFlatTree originalBase = basePosition.isConnected() ?
createVisiblePosition(basePosition) : VisiblePositionInFlatTree(); |
| 223 const VisiblePositionInFlatTree base = originalBase.isNotNull() ? originalBa
se : createVisiblePositionDeprecated(newSelection.base()); | 233 const VisiblePositionInFlatTree base = originalBase.isNotNull() ? originalBa
se : createVisiblePosition(newSelection.base()); |
| 224 VisiblePositionInFlatTree newBase = base; | 234 VisiblePositionInFlatTree newBase = base; |
| 225 const VisiblePositionInFlatTree extent = createVisiblePositionDeprecated(new
Selection.extent()); | 235 const VisiblePositionInFlatTree extent = createVisiblePosition(newSelection.
extent()); |
| 226 VisiblePositionInFlatTree newExtent = extent; | 236 VisiblePositionInFlatTree newExtent = extent; |
| 227 if (endpointsAdjustmentMode == AdjustEndpointsAtBidiBoundary) | 237 if (endpointsAdjustmentMode == AdjustEndpointsAtBidiBoundary) |
| 228 adjustEndpointsAtBidiBoundary(newBase, newExtent); | 238 adjustEndpointsAtBidiBoundary(newBase, newExtent); |
| 229 | 239 |
| 230 if (newBase.deepEquivalent() != base.deepEquivalent() || newExtent.deepEquiv
alent() != extent.deepEquivalent()) { | 240 if (newBase.deepEquivalent() != base.deepEquivalent() || newExtent.deepEquiv
alent() != extent.deepEquivalent()) { |
| 231 m_originalBaseInFlatTree = base; | 241 m_originalBaseInFlatTree = base; |
| 232 newSelection.setBase(newBase); | 242 newSelection.setBase(newBase); |
| 233 newSelection.setExtent(newExtent); | 243 newSelection.setExtent(newExtent); |
| 234 } else if (originalBase.isNotNull()) { | 244 } else if (originalBase.isNotNull()) { |
| 235 if (visibleSelection<EditingInFlatTreeStrategy>().base() == newSelection
.base()) | 245 if (visibleSelection<EditingInFlatTreeStrategy>().base() == newSelection
.base()) |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 if (!visibleSelection.isRange()) | 748 if (!visibleSelection.isRange()) |
| 739 return false; | 749 return false; |
| 740 | 750 |
| 741 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active); | 751 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active); |
| 742 HitTestResult result(request, point); | 752 HitTestResult result(request, point); |
| 743 document().layoutViewItem().hitTest(result); | 753 document().layoutViewItem().hitTest(result); |
| 744 Node* innerNode = result.innerNode(); | 754 Node* innerNode = result.innerNode(); |
| 745 if (!innerNode || !innerNode->layoutObject()) | 755 if (!innerNode || !innerNode->layoutObject()) |
| 746 return false; | 756 return false; |
| 747 | 757 |
| 748 const VisiblePositionInFlatTree& visiblePos = createVisiblePositionDeprecate
d(fromPositionInDOMTree<EditingInFlatTreeStrategy>(innerNode->layoutObject()->po
sitionForPoint(result.localPoint()))); | 758 const VisiblePositionInFlatTree& visiblePos = createVisiblePosition(fromPosi
tionInDOMTree<EditingInFlatTreeStrategy>(innerNode->layoutObject()->positionForP
oint(result.localPoint()))); |
| 749 if (visiblePos.isNull()) | 759 if (visiblePos.isNull()) |
| 750 return false; | 760 return false; |
| 751 | 761 |
| 752 const VisiblePositionInFlatTree& visibleStart = visibleSelection.visibleStar
t(); | 762 const VisiblePositionInFlatTree& visibleStart = visibleSelection.visibleStar
t(); |
| 753 const VisiblePositionInFlatTree& visibleEnd = visibleSelection.visibleEnd(); | 763 const VisiblePositionInFlatTree& visibleEnd = visibleSelection.visibleEnd(); |
| 754 if (visibleStart.isNull() || visibleEnd.isNull()) | 764 if (visibleStart.isNull() || visibleEnd.isNull()) |
| 755 return false; | 765 return false; |
| 756 | 766 |
| 757 const PositionInFlatTree& start = visibleStart.deepEquivalent(); | 767 const PositionInFlatTree& start = visibleStart.deepEquivalent(); |
| 758 const PositionInFlatTree& end = visibleEnd.deepEquivalent(); | 768 const PositionInFlatTree& end = visibleEnd.deepEquivalent(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 789 | 799 |
| 790 // Get to the <iframe> or <frame> (or even <object>) element in the parent f
rame. | 800 // Get to the <iframe> or <frame> (or even <object>) element in the parent f
rame. |
| 791 // FIXME: Doesn't work for OOPI. | 801 // FIXME: Doesn't work for OOPI. |
| 792 HTMLFrameOwnerElement* ownerElement = m_frame->deprecatedLocalOwner(); | 802 HTMLFrameOwnerElement* ownerElement = m_frame->deprecatedLocalOwner(); |
| 793 if (!ownerElement) | 803 if (!ownerElement) |
| 794 return; | 804 return; |
| 795 ContainerNode* ownerElementParent = ownerElement->parentNode(); | 805 ContainerNode* ownerElementParent = ownerElement->parentNode(); |
| 796 if (!ownerElementParent) | 806 if (!ownerElementParent) |
| 797 return; | 807 return; |
| 798 | 808 |
| 809 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
| 810 // needs to be audited. See http://crbug.com/590369 for more details. |
| 811 ownerElementParent->document().updateStyleAndLayoutIgnorePendingStylesheets(
); |
| 812 |
| 799 // This method's purpose is it to make it easier to select iframes (in order
to delete them). Don't do anything if the iframe isn't deletable. | 813 // This method's purpose is it to make it easier to select iframes (in order
to delete them). Don't do anything if the iframe isn't deletable. |
| 800 if (!blink::hasEditableStyle(*ownerElementParent)) | 814 if (!blink::hasEditableStyle(*ownerElementParent)) |
| 801 return; | 815 return; |
| 802 | 816 |
| 803 // Create compute positions before and after the element. | 817 // Create compute positions before and after the element. |
| 804 unsigned ownerElementNodeIndex = ownerElement->nodeIndex(); | 818 unsigned ownerElementNodeIndex = ownerElement->nodeIndex(); |
| 805 VisiblePosition beforeOwnerElement = createVisiblePositionDeprecated(Positio
n(ownerElementParent, ownerElementNodeIndex)); | 819 VisiblePosition beforeOwnerElement = createVisiblePosition(Position(ownerEle
mentParent, ownerElementNodeIndex)); |
| 806 VisiblePosition afterOwnerElement = createVisiblePositionDeprecated(Position
(ownerElementParent, ownerElementNodeIndex + 1), VP_UPSTREAM_IF_POSSIBLE); | 820 VisiblePosition afterOwnerElement = createVisiblePosition(Position(ownerElem
entParent, ownerElementNodeIndex + 1), VP_UPSTREAM_IF_POSSIBLE); |
| 807 | 821 |
| 808 // Focus on the parent frame, and then select from before this element to af
ter. | 822 // Focus on the parent frame, and then select from before this element to af
ter. |
| 809 VisibleSelection newSelection(beforeOwnerElement, afterOwnerElement); | 823 VisibleSelection newSelection(beforeOwnerElement, afterOwnerElement); |
| 810 page->focusController().setFocusedFrame(parent); | 824 page->focusController().setFocusedFrame(parent); |
| 811 // setFocusedFrame can dispatch synchronous focus/blur events. The document | 825 // setFocusedFrame can dispatch synchronous focus/blur events. The document |
| 812 // tree might be modified. | 826 // tree might be modified. |
| 813 if (newSelection.isNonOrphanedCaretOrRange()) | 827 if (newSelection.isNonOrphanedCaretOrRange()) |
| 814 toLocalFrame(parent)->selection().setSelection(newSelection); | 828 toLocalFrame(parent)->selection().setSelection(newSelection); |
| 815 } | 829 } |
| 816 | 830 |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1160 | 1174 |
| 1161 LayoutRect rect; | 1175 LayoutRect rect; |
| 1162 | 1176 |
| 1163 switch (getSelectionType()) { | 1177 switch (getSelectionType()) { |
| 1164 case NoSelection: | 1178 case NoSelection: |
| 1165 return; | 1179 return; |
| 1166 case CaretSelection: | 1180 case CaretSelection: |
| 1167 rect = LayoutRect(absoluteCaretBounds()); | 1181 rect = LayoutRect(absoluteCaretBounds()); |
| 1168 break; | 1182 break; |
| 1169 case RangeSelection: | 1183 case RangeSelection: |
| 1170 rect = LayoutRect(revealExtentOption == RevealExtent ? absoluteCaretBoun
dsOf(createVisiblePositionDeprecated(extent())) : enclosingIntRect(unclippedBoun
ds())); | 1184 rect = LayoutRect(revealExtentOption == RevealExtent ? absoluteCaretBoun
dsOf(createVisiblePosition(extent())) : enclosingIntRect(unclippedBounds())); |
| 1171 break; | 1185 break; |
| 1172 } | 1186 } |
| 1173 | 1187 |
| 1174 Position start = this->start(); | 1188 Position start = this->start(); |
| 1175 DCHECK(start.anchorNode()); | 1189 DCHECK(start.anchorNode()); |
| 1176 if (start.anchorNode() && start.anchorNode()->layoutObject()) { | 1190 if (start.anchorNode() && start.anchorNode()->layoutObject()) { |
| 1177 // FIXME: This code only handles scrolling the startContainer's layer, b
ut | 1191 // FIXME: This code only handles scrolling the startContainer's layer, b
ut |
| 1178 // the selection rect could intersect more than just that. | 1192 // the selection rect could intersect more than just that. |
| 1179 if (DocumentLoader* documentLoader = m_frame->loader().documentLoader()) | 1193 if (DocumentLoader* documentLoader = m_frame->loader().documentLoader()) |
| 1180 documentLoader->initialScrollState().wasScrolledByUser = true; | 1194 documentLoader->initialScrollState().wasScrolledByUser = true; |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1380 | 1394 |
| 1381 void showTree(const blink::FrameSelection* sel) | 1395 void showTree(const blink::FrameSelection* sel) |
| 1382 { | 1396 { |
| 1383 if (sel) | 1397 if (sel) |
| 1384 sel->showTreeForThis(); | 1398 sel->showTreeForThis(); |
| 1385 else | 1399 else |
| 1386 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; | 1400 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; |
| 1387 } | 1401 } |
| 1388 | 1402 |
| 1389 #endif | 1403 #endif |
| OLD | NEW |