Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv ed. | 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv ed. |
| 3 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 3 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
| 4 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies) | 4 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies) |
| 5 * Copyright (C) 2015 Google Inc. All rights reserved. | 5 * Copyright (C) 2015 Google Inc. All rights reserved. |
| 6 * | 6 * |
| 7 * Redistribution and use in source and binary forms, with or without | 7 * Redistribution and use in source and binary forms, with or without |
| 8 * modification, are permitted provided that the following conditions | 8 * modification, are permitted provided that the following conditions |
| 9 * are met: | 9 * are met: |
| 10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 if (!rootUserSelectAll) | 84 if (!rootUserSelectAll) |
| 85 return selection; | 85 return selection; |
| 86 | 86 |
| 87 VisibleSelection newSelection(selection); | 87 VisibleSelection newSelection(selection); |
| 88 newSelection.setBase(positionBeforeNode(rootUserSelectAll).upstream(CanCross EditingBoundary)); | 88 newSelection.setBase(positionBeforeNode(rootUserSelectAll).upstream(CanCross EditingBoundary)); |
| 89 newSelection.setExtent(positionAfterNode(rootUserSelectAll).downstream(CanCr ossEditingBoundary)); | 89 newSelection.setExtent(positionAfterNode(rootUserSelectAll).downstream(CanCr ossEditingBoundary)); |
| 90 | 90 |
| 91 return newSelection; | 91 return newSelection; |
| 92 } | 92 } |
| 93 | 93 |
| 94 bool expandSelectionUsingGranularity(VisibleSelection& selection, TextGranularit y granularity) | |
|
tkent
2015/06/19 02:17:09
should this be |static|?
yosin_UTC9
2015/06/19 03:41:44
Done.
| |
| 95 { | |
| 96 return selection.expandUsingGranularity(granularity); | |
| 97 } | |
| 98 | |
| 94 bool SelectionController::updateSelectionForMouseDownDispatchingSelectStart(Node * targetNode, const VisibleSelection& selection, TextGranularity granularity) | 99 bool SelectionController::updateSelectionForMouseDownDispatchingSelectStart(Node * targetNode, const VisibleSelection& selection, TextGranularity granularity) |
| 95 { | 100 { |
| 96 if (Position::nodeIsUserSelectNone(targetNode)) | 101 if (Position::nodeIsUserSelectNone(targetNode)) |
| 97 return false; | 102 return false; |
| 98 | 103 |
| 99 if (!dispatchSelectStart(targetNode)) | 104 if (!dispatchSelectStart(targetNode)) |
| 100 return false; | 105 return false; |
| 101 | 106 |
| 102 if (selection.isRange()) { | 107 if (selection.isRange()) { |
| 103 m_selectionInitiationState = ExtendedSelection; | 108 m_selectionInitiationState = ExtendedSelection; |
| 104 } else { | 109 } else { |
| 105 granularity = CharacterGranularity; | 110 granularity = CharacterGranularity; |
| 106 m_selectionInitiationState = PlacedCaret; | 111 m_selectionInitiationState = PlacedCaret; |
| 107 } | 112 } |
| 108 | 113 |
| 109 m_frame->selection().setNonDirectionalSelectionIfNeeded(selection, granulari ty); | 114 m_frame->selection().setNonDirectionalSelectionIfNeeded(selection, granulari ty); |
| 110 | 115 |
| 111 return true; | 116 return true; |
| 112 } | 117 } |
| 113 | 118 |
| 114 void SelectionController::selectClosestWordFromHitTestResult(const HitTestResult & result, AppendTrailingWhitespace appendTrailingWhitespace) | 119 void SelectionController::selectClosestWordFromHitTestResult(const HitTestResult & result, AppendTrailingWhitespace appendTrailingWhitespace) |
| 115 { | 120 { |
| 116 Node* innerNode = result.innerNode(); | 121 Node* innerNode = result.innerNode(); |
| 117 VisibleSelection newSelection; | 122 VisibleSelection newSelection; |
| 118 | 123 |
| 119 if (innerNode && innerNode->layoutObject()) { | 124 if (innerNode && innerNode->layoutObject()) { |
| 120 VisiblePosition pos(innerNode->layoutObject()->positionForPoint(result.l ocalPoint())); | 125 VisiblePosition pos(innerNode->layoutObject()->positionForPoint(result.l ocalPoint())); |
| 121 if (pos.isNotNull()) { | 126 if (pos.isNotNull()) { |
| 122 newSelection = VisibleSelection(pos); | 127 newSelection = VisibleSelection(pos); |
| 123 newSelection.expandUsingGranularity(WordGranularity); | 128 expandSelectionUsingGranularity(newSelection, WordGranularity); |
| 124 } | 129 } |
| 125 | 130 |
| 126 if (appendTrailingWhitespace == ShouldAppendTrailingWhitespace && newSel ection.isRange()) | 131 if (appendTrailingWhitespace == ShouldAppendTrailingWhitespace && newSel ection.isRange()) |
| 127 newSelection.appendTrailingWhitespace(); | 132 newSelection.appendTrailingWhitespace(); |
| 128 | 133 |
| 129 updateSelectionForMouseDownDispatchingSelectStart(innerNode, expandSelec tionToRespectUserSelectAll(innerNode, newSelection), WordGranularity); | 134 updateSelectionForMouseDownDispatchingSelectStart(innerNode, expandSelec tionToRespectUserSelectAll(innerNode, newSelection), WordGranularity); |
| 130 } | 135 } |
| 131 } | 136 } |
| 132 | 137 |
| 133 void SelectionController::selectClosestMisspellingFromHitTestResult(const HitTes tResult& result, AppendTrailingWhitespace appendTrailingWhitespace) | 138 void SelectionController::selectClosestMisspellingFromHitTestResult(const HitTes tResult& result, AppendTrailingWhitespace appendTrailingWhitespace) |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 return false; | 222 return false; |
| 218 | 223 |
| 219 Node* innerNode = event.innerNode(); | 224 Node* innerNode = event.innerNode(); |
| 220 if (!(innerNode && innerNode->layoutObject() && m_mouseDownMayStartSelect)) | 225 if (!(innerNode && innerNode->layoutObject() && m_mouseDownMayStartSelect)) |
| 221 return false; | 226 return false; |
| 222 | 227 |
| 223 VisibleSelection newSelection; | 228 VisibleSelection newSelection; |
| 224 VisiblePosition pos(innerNode->layoutObject()->positionForPoint(event.localP oint())); | 229 VisiblePosition pos(innerNode->layoutObject()->positionForPoint(event.localP oint())); |
| 225 if (pos.isNotNull()) { | 230 if (pos.isNotNull()) { |
| 226 newSelection = VisibleSelection(pos); | 231 newSelection = VisibleSelection(pos); |
| 227 newSelection.expandUsingGranularity(ParagraphGranularity); | 232 expandSelectionUsingGranularity(newSelection, ParagraphGranularity); |
| 228 } | 233 } |
| 229 | 234 |
| 230 return updateSelectionForMouseDownDispatchingSelectStart(innerNode, expandSe lectionToRespectUserSelectAll(innerNode, newSelection), ParagraphGranularity); | 235 return updateSelectionForMouseDownDispatchingSelectStart(innerNode, expandSe lectionToRespectUserSelectAll(innerNode, newSelection), ParagraphGranularity); |
| 231 } | 236 } |
| 232 | 237 |
| 233 static int textDistance(const Position& start, const Position& end) | 238 static int textDistance(const Position& start, const Position& end) |
| 234 { | 239 { |
| 235 RefPtrWillBeRawPtr<Range> range = Range::create(*start.document(), start, en d); | 240 RefPtrWillBeRawPtr<Range> range = Range::create(*start.document(), start, en d); |
| 236 return TextIterator::rangeLength(range->startPosition(), range->endPosition( ), true); | 241 return TextIterator::rangeLength(range->startPosition(), range->endPosition( ), true); |
| 237 } | 242 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 287 newSelection = VisibleSelection(end, pos); | 292 newSelection = VisibleSelection(end, pos); |
| 288 else | 293 else |
| 289 newSelection = VisibleSelection(start, pos); | 294 newSelection = VisibleSelection(start, pos); |
| 290 } | 295 } |
| 291 } else { | 296 } else { |
| 292 newSelection.setExtent(pos); | 297 newSelection.setExtent(pos); |
| 293 } | 298 } |
| 294 | 299 |
| 295 if (m_frame->selection().granularity() != CharacterGranularity) { | 300 if (m_frame->selection().granularity() != CharacterGranularity) { |
| 296 granularity = m_frame->selection().granularity(); | 301 granularity = m_frame->selection().granularity(); |
| 297 newSelection.expandUsingGranularity(m_frame->selection().granularity ()); | 302 expandSelectionUsingGranularity(newSelection, m_frame->selection().g ranularity()); |
| 298 } | 303 } |
| 299 } else { | 304 } else { |
| 300 newSelection = expandSelectionToRespectUserSelectAll(innerNode, VisibleS election(visiblePos)); | 305 newSelection = expandSelectionToRespectUserSelectAll(innerNode, VisibleS election(visiblePos)); |
| 301 } | 306 } |
| 302 | 307 |
| 303 // Updating the selection is considered side-effect of the event and so it d oesn't impact the handled state. | 308 // Updating the selection is considered side-effect of the event and so it d oesn't impact the handled state. |
| 304 updateSelectionForMouseDownDispatchingSelectStart(innerNode, newSelection, g ranularity); | 309 updateSelectionForMouseDownDispatchingSelectStart(innerNode, newSelection, g ranularity); |
| 305 return false; | 310 return false; |
| 306 } | 311 } |
| 307 | 312 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 405 else if (rootUserSelectAllForTarget && mousePressNode->layoutObject( )) | 410 else if (rootUserSelectAllForTarget && mousePressNode->layoutObject( )) |
| 406 newSelection.setExtent(positionAfterNode(rootUserSelectAllForTar get).downstream(CanCrossEditingBoundary)); | 411 newSelection.setExtent(positionAfterNode(rootUserSelectAllForTar get).downstream(CanCrossEditingBoundary)); |
| 407 else | 412 else |
| 408 newSelection.setExtent(targetPosition); | 413 newSelection.setExtent(targetPosition); |
| 409 } | 414 } |
| 410 } else { | 415 } else { |
| 411 newSelection.setExtent(targetPosition); | 416 newSelection.setExtent(targetPosition); |
| 412 } | 417 } |
| 413 | 418 |
| 414 if (m_frame->selection().granularity() != CharacterGranularity) | 419 if (m_frame->selection().granularity() != CharacterGranularity) |
| 415 newSelection.expandUsingGranularity(m_frame->selection().granularity()); | 420 expandSelectionUsingGranularity(newSelection, m_frame->selection().granu larity()); |
| 416 | 421 |
| 417 m_frame->selection().setNonDirectionalSelectionIfNeeded(newSelection, m_fram e->selection().granularity(), | 422 m_frame->selection().setNonDirectionalSelectionIfNeeded(newSelection, m_fram e->selection().granularity(), |
| 418 FrameSelection::AdjustEndpointsAtBidiBoundary); | 423 FrameSelection::AdjustEndpointsAtBidiBoundary); |
| 419 } | 424 } |
| 420 | 425 |
| 421 bool SelectionController::handleMouseReleaseEvent(const MouseEventWithHitTestRes ults& event, const LayoutPoint& dragStartPos) | 426 bool SelectionController::handleMouseReleaseEvent(const MouseEventWithHitTestRes ults& event, const LayoutPoint& dragStartPos) |
| 422 { | 427 { |
| 423 bool handled = false; | 428 bool handled = false; |
| 424 m_mouseDownMayStartSelect = false; | 429 m_mouseDownMayStartSelect = false; |
| 425 // Clear the selection if the mouse didn't move after the last mouse | 430 // Clear the selection if the mouse didn't move after the last mouse |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 557 { | 562 { |
| 558 return m_mouseDownMayStartSelect; | 563 return m_mouseDownMayStartSelect; |
| 559 } | 564 } |
| 560 | 565 |
| 561 bool SelectionController::mouseDownWasSingleClickInSelection() const | 566 bool SelectionController::mouseDownWasSingleClickInSelection() const |
| 562 { | 567 { |
| 563 return m_mouseDownWasSingleClickInSelection; | 568 return m_mouseDownWasSingleClickInSelection; |
| 564 } | 569 } |
| 565 | 570 |
| 566 } // namespace blink | 571 } // namespace blink |
| OLD | NEW |