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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 288 } | 288 } |
| 289 | 289 |
| 290 void SelectionController::selectClosestWordFromHitTestResult(const HitTestResult & result, AppendTrailingWhitespace appendTrailingWhitespace) | 290 void SelectionController::selectClosestWordFromHitTestResult(const HitTestResult & result, AppendTrailingWhitespace appendTrailingWhitespace) |
| 291 { | 291 { |
| 292 Node* innerNode = result.innerNode(); | 292 Node* innerNode = result.innerNode(); |
| 293 VisibleSelectionInFlatTree newSelection; | 293 VisibleSelectionInFlatTree newSelection; |
| 294 | 294 |
| 295 if (!innerNode || !innerNode->layoutObject()) | 295 if (!innerNode || !innerNode->layoutObject()) |
| 296 return; | 296 return; |
| 297 | 297 |
| 298 const VisiblePositionInFlatTree& pos = visiblePositionOfHitTestResult(result ); | 298 // Special-case image local offset to always be zero, to avoid triggering |
| 299 // LayoutReplaced::positionFromPoint's advancement of the position at the | |
| 300 // mid-point of the the image (which was intended for mouse-drag selection | |
| 301 // and isn't desirable for long-press). | |
| 302 HitTestResult adjustedHitTestResult = result; | |
| 303 if (result.image()) { | |
|
yosin_UTC9
2016/04/05 05:16:45
nit: we don't need to have "{}" here, since then-c
aelias_OOO_until_Jul13
2016/04/05 06:48:36
Done.
| |
| 304 adjustedHitTestResult.setNodeAndPosition(result.innerNode(), LayoutPoint (0, 0)); | |
| 305 } | |
| 306 | |
| 307 const VisiblePositionInFlatTree& pos = visiblePositionOfHitTestResult(adjust edHitTestResult); | |
| 299 if (pos.isNotNull()) { | 308 if (pos.isNotNull()) { |
| 300 newSelection = VisibleSelectionInFlatTree(pos); | 309 newSelection = VisibleSelectionInFlatTree(pos); |
| 301 newSelection.expandUsingGranularity(WordGranularity); | 310 newSelection.expandUsingGranularity(WordGranularity); |
| 302 } | 311 } |
| 303 | 312 |
| 304 #if OS(ANDROID) | 313 if (appendTrailingWhitespace == AppendTrailingWhitespace::DontAppend) { |
| 305 // If node doesn't have text except space, tab or line break, do not | 314 // If node doesn't have text except space, tab or line break, do not |
| 306 // select that 'empty' area. | 315 // select that 'empty' area. |
| 307 EphemeralRangeInFlatTree range = EphemeralRangeInFlatTree(newSelection.start (), newSelection.end()); | 316 EphemeralRangeInFlatTree range = EphemeralRangeInFlatTree(newSelection.s tart(), newSelection.end()); |
|
yosin_UTC9
2016/04/05 05:16:45
nit: |const EphmeralRangeInFlatTree&| to avoid unn
aelias_OOO_until_Jul13
2016/04/05 06:48:36
Switched to parens-on-local-variable-constructor s
| |
| 308 const String& str = plainText(range, TextIteratorDefaultBehavior); | 317 const String& str = plainText(range, TextIteratorEmitsObjectReplacementC haracter); |
| 309 if (str.isEmpty() || str.simplifyWhiteSpace().containsOnlyWhitespace()) | 318 if (str.simplifyWhiteSpace().isEmpty()) |
| 310 return; | 319 return; |
| 311 #endif | 320 } else { |
|
yosin_UTC9
2016/04/05 05:16:45
To avoid nesting, we can write:
} else if (newSel
aelias_OOO_until_Jul13
2016/04/05 06:48:36
Switched this back to the former syntax anyway.
| |
| 312 | 321 if (newSelection.isRange()) |
| 313 if (appendTrailingWhitespace == AppendTrailingWhitespace::ShouldAppend && ne wSelection.isRange()) | 322 newSelection.appendTrailingWhitespace(); |
| 314 newSelection.appendTrailingWhitespace(); | 323 } |
| 315 | 324 |
| 316 updateSelectionForMouseDownDispatchingSelectStart(innerNode, expandSelection ToRespectUserSelectAll(innerNode, newSelection), WordGranularity); | 325 updateSelectionForMouseDownDispatchingSelectStart(innerNode, expandSelection ToRespectUserSelectAll(innerNode, newSelection), WordGranularity); |
| 317 } | 326 } |
| 318 | 327 |
| 319 void SelectionController::selectClosestMisspellingFromHitTestResult(const HitTes tResult& result, AppendTrailingWhitespace appendTrailingWhitespace) | 328 void SelectionController::selectClosestMisspellingFromHitTestResult(const HitTes tResult& result, AppendTrailingWhitespace appendTrailingWhitespace) |
| 320 { | 329 { |
| 321 Node* innerNode = result.innerNode(); | 330 Node* innerNode = result.innerNode(); |
| 322 VisibleSelectionInFlatTree newSelection; | 331 VisibleSelectionInFlatTree newSelection; |
| 323 | 332 |
| 324 if (!innerNode || !innerNode->layoutObject()) | 333 if (!innerNode || !innerNode->layoutObject()) |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 533 | 542 |
| 534 return false; | 543 return false; |
| 535 } | 544 } |
| 536 | 545 |
| 537 bool SelectionController::handleGestureLongPress(const PlatformGestureEvent& ges tureEvent, const HitTestResult& hitTestResult) | 546 bool SelectionController::handleGestureLongPress(const PlatformGestureEvent& ges tureEvent, const HitTestResult& hitTestResult) |
| 538 { | 547 { |
| 539 if (hitTestResult.isLiveLink()) | 548 if (hitTestResult.isLiveLink()) |
| 540 return false; | 549 return false; |
| 541 | 550 |
| 542 Node* innerNode = hitTestResult.innerNode(); | 551 Node* innerNode = hitTestResult.innerNode(); |
| 543 #if OS(ANDROID) | |
| 544 bool innerNodeIsSelectable = innerNode && (innerNode->isContentEditable() || innerNode->isTextNode() || innerNode->canStartSelection()); | 552 bool innerNodeIsSelectable = innerNode && (innerNode->isContentEditable() || innerNode->isTextNode() || innerNode->canStartSelection()); |
| 545 #else | |
| 546 bool innerNodeIsSelectable = innerNode && (innerNode->isContentEditable() || innerNode->isTextNode()); | |
| 547 #endif | |
| 548 if (!innerNodeIsSelectable) | 553 if (!innerNodeIsSelectable) |
| 549 return false; | 554 return false; |
| 550 | 555 |
| 551 selectClosestWordFromHitTestResult(hitTestResult, AppendTrailingWhitespace:: DontAppend); | 556 selectClosestWordFromHitTestResult(hitTestResult, AppendTrailingWhitespace:: DontAppend); |
| 552 return selection().isRange(); | 557 return selection().isRange(); |
| 553 } | 558 } |
| 554 | 559 |
| 555 void SelectionController::sendContextMenuEvent(const MouseEventWithHitTestResult s& mev, const LayoutPoint& position) | 560 void SelectionController::sendContextMenuEvent(const MouseEventWithHitTestResult s& mev, const LayoutPoint& position) |
| 556 { | 561 { |
| 557 if (selection().contains(position) | 562 if (selection().contains(position) |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 617 else | 622 else |
| 618 m_selectionState = SelectionState::HaveNotStartedSelection; | 623 m_selectionState = SelectionState::HaveNotStartedSelection; |
| 619 } | 624 } |
| 620 | 625 |
| 621 FrameSelection& SelectionController::selection() const | 626 FrameSelection& SelectionController::selection() const |
| 622 { | 627 { |
| 623 return m_frame->selection(); | 628 return m_frame->selection(); |
| 624 } | 629 } |
| 625 | 630 |
| 626 } // namespace blink | 631 } // namespace blink |
| OLD | NEW |