Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights | 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights |
| 3 * reserved. | 3 * reserved. |
| 4 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 4 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
| 5 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies) | 5 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies) |
| 6 * Copyright (C) 2015 Google Inc. All rights reserved. | 6 * Copyright (C) 2015 Google Inc. All rights reserved. |
| 7 * | 7 * |
| 8 * Redistribution and use in source and binary forms, with or without | 8 * Redistribution and use in source and binary forms, with or without |
| 9 * modification, are permitted provided that the following conditions | 9 * modification, are permitted provided that the following conditions |
| 10 * are met: | 10 * are met: |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 #include "core/editing/EditingUtilities.h" | 34 #include "core/editing/EditingUtilities.h" |
| 35 #include "core/editing/Editor.h" | 35 #include "core/editing/Editor.h" |
| 36 #include "core/editing/FrameSelection.h" | 36 #include "core/editing/FrameSelection.h" |
| 37 #include "core/editing/RenderedPosition.h" | 37 #include "core/editing/RenderedPosition.h" |
| 38 #include "core/editing/iterators/TextIterator.h" | 38 #include "core/editing/iterators/TextIterator.h" |
| 39 #include "core/editing/markers/DocumentMarkerController.h" | 39 #include "core/editing/markers/DocumentMarkerController.h" |
| 40 #include "core/events/Event.h" | 40 #include "core/events/Event.h" |
| 41 #include "core/frame/FrameView.h" | 41 #include "core/frame/FrameView.h" |
| 42 #include "core/frame/LocalFrame.h" | 42 #include "core/frame/LocalFrame.h" |
| 43 #include "core/frame/Settings.h" | 43 #include "core/frame/Settings.h" |
| 44 #include "core/input/EventHandler.h" | |
| 44 #include "core/layout/LayoutView.h" | 45 #include "core/layout/LayoutView.h" |
| 45 #include "core/layout/api/LayoutViewItem.h" | 46 #include "core/layout/api/LayoutViewItem.h" |
| 46 #include "core/page/FocusController.h" | 47 #include "core/page/FocusController.h" |
| 47 #include "core/page/Page.h" | 48 #include "core/page/Page.h" |
| 48 #include "platform/RuntimeEnabledFeatures.h" | 49 #include "platform/RuntimeEnabledFeatures.h" |
| 49 #include "platform/wtf/AutoReset.h" | 50 #include "platform/wtf/AutoReset.h" |
| 51 #include "public/web/WebMenuSourceType.h" | |
| 50 | 52 |
| 51 namespace blink { | 53 namespace blink { |
| 52 SelectionController* SelectionController::Create(LocalFrame& frame) { | 54 SelectionController* SelectionController::Create(LocalFrame& frame) { |
| 53 return new SelectionController(frame); | 55 return new SelectionController(frame); |
| 54 } | 56 } |
| 55 | 57 |
| 56 SelectionController::SelectionController(LocalFrame& frame) | 58 SelectionController::SelectionController(LocalFrame& frame) |
| 57 : frame_(&frame), | 59 : frame_(&frame), |
| 58 mouse_down_may_start_select_(false), | 60 mouse_down_may_start_select_(false), |
| 59 mouse_down_was_single_click_in_selection_(false), | 61 mouse_down_was_single_click_in_selection_(false), |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 FlooredIntPoint(event.Event().PositionInRootFrame())); | 189 FlooredIntPoint(event.Event().PositionInRootFrame())); |
| 188 if (!extend_selection && this->Selection().Contains(v_point)) { | 190 if (!extend_selection && this->Selection().Contains(v_point)) { |
| 189 mouse_down_was_single_click_in_selection_ = true; | 191 mouse_down_was_single_click_in_selection_ = true; |
| 190 if (!event.Event().FromTouch()) | 192 if (!event.Event().FromTouch()) |
| 191 return false; | 193 return false; |
| 192 | 194 |
| 193 if (!this->Selection().IsHandleVisible()) { | 195 if (!this->Selection().IsHandleVisible()) { |
| 194 UpdateSelectionForMouseDownDispatchingSelectStart( | 196 UpdateSelectionForMouseDownDispatchingSelectStart( |
| 195 inner_node, selection, kCharacterGranularity, | 197 inner_node, selection, kCharacterGranularity, |
| 196 HandleVisibility::kVisible); | 198 HandleVisibility::kVisible); |
| 199 frame_->GetEventHandler().ShowNonLocatedContextMenu(nullptr, | |
|
yosin_UTC9
2017/05/25 04:47:20
Since "selectionstart" event is cancelalbe, we sho
amaralp1
2017/05/25 07:11:56
Changed to only show context menu if |UpdateSelect
| |
| 200 kMenuSourceTouch); | |
|
yosin_UTC9
2017/05/25 04:47:21
Could you tell me why we use |kMenuSourceTouch| ev
amaralp1
2017/05/25 07:11:56
|event.FromTouch()| has to be true or else we woul
| |
| 197 return false; | 201 return false; |
| 198 } | 202 } |
| 199 } | 203 } |
| 200 } | 204 } |
| 201 | 205 |
| 202 if (extend_selection && !selection.IsNone()) { | 206 if (extend_selection && !selection.IsNone()) { |
| 203 // Note: "fast/events/shift-click-user-select-none.html" makes | 207 // Note: "fast/events/shift-click-user-select-none.html" makes |
| 204 // |pos.isNull()| true. | 208 // |pos.isNull()| true. |
| 205 const PositionInFlatTree& pos = AdjustPositionRespectUserSelectAll( | 209 const PositionInFlatTree& pos = AdjustPositionRespectUserSelectAll( |
| 206 inner_node, selection.Start(), selection.end(), | 210 inner_node, selection.Start(), selection.end(), |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 536 | 540 |
| 537 if (append_trailing_whitespace == AppendTrailingWhitespace::kShouldAppend) | 541 if (append_trailing_whitespace == AppendTrailingWhitespace::kShouldAppend) |
| 538 new_selection.AppendTrailingWhitespace(); | 542 new_selection.AppendTrailingWhitespace(); |
| 539 | 543 |
| 540 UpdateSelectionForMouseDownDispatchingSelectStart( | 544 UpdateSelectionForMouseDownDispatchingSelectStart( |
| 541 inner_node, | 545 inner_node, |
| 542 ExpandSelectionToRespectUserSelectAll(inner_node, new_selection), | 546 ExpandSelectionToRespectUserSelectAll(inner_node, new_selection), |
| 543 kWordGranularity, HandleVisibility::kNotVisible); | 547 kWordGranularity, HandleVisibility::kNotVisible); |
| 544 } | 548 } |
| 545 | 549 |
| 546 void SelectionController::SelectClosestWordFromMouseEvent( | 550 bool SelectionController::SelectClosestWordFromMouseEvent( |
| 547 const MouseEventWithHitTestResults& result) { | 551 const MouseEventWithHitTestResults& result) { |
| 548 if (!mouse_down_may_start_select_) | 552 if (!mouse_down_may_start_select_) |
| 549 return; | 553 return false; |
| 550 | 554 |
| 551 AppendTrailingWhitespace append_trailing_whitespace = | 555 AppendTrailingWhitespace append_trailing_whitespace = |
| 552 (result.Event().click_count == 2 && | 556 (result.Event().click_count == 2 && |
| 553 frame_->GetEditor().IsSelectTrailingWhitespaceEnabled()) | 557 frame_->GetEditor().IsSelectTrailingWhitespaceEnabled()) |
| 554 ? AppendTrailingWhitespace::kShouldAppend | 558 ? AppendTrailingWhitespace::kShouldAppend |
| 555 : AppendTrailingWhitespace::kDontAppend; | 559 : AppendTrailingWhitespace::kDontAppend; |
| 556 | 560 |
| 557 DCHECK(!frame_->GetDocument()->NeedsLayoutTreeUpdate()); | 561 DCHECK(!frame_->GetDocument()->NeedsLayoutTreeUpdate()); |
| 558 | 562 |
| 559 SelectClosestWordFromHitTestResult( | 563 return SelectClosestWordFromHitTestResult( |
| 560 result.GetHitTestResult(), append_trailing_whitespace, | 564 result.GetHitTestResult(), append_trailing_whitespace, |
| 561 result.Event().FromTouch() ? SelectInputEventType::kTouch | 565 result.Event().FromTouch() ? SelectInputEventType::kTouch |
| 562 : SelectInputEventType::kMouse); | 566 : SelectInputEventType::kMouse); |
| 563 } | 567 } |
| 564 | 568 |
| 565 void SelectionController::SelectClosestMisspellingFromMouseEvent( | 569 void SelectionController::SelectClosestMisspellingFromMouseEvent( |
| 566 const MouseEventWithHitTestResults& result) { | 570 const MouseEventWithHitTestResults& result) { |
| 567 if (!mouse_down_may_start_select_) | 571 if (!mouse_down_may_start_select_) |
| 568 return; | 572 return; |
| 569 | 573 |
| 570 SelectClosestMisspellingFromHitTestResult( | 574 SelectClosestMisspellingFromHitTestResult( |
| 571 result.GetHitTestResult(), | 575 result.GetHitTestResult(), |
| 572 (result.Event().click_count == 2 && | 576 (result.Event().click_count == 2 && |
| 573 frame_->GetEditor().IsSelectTrailingWhitespaceEnabled()) | 577 frame_->GetEditor().IsSelectTrailingWhitespaceEnabled()) |
| 574 ? AppendTrailingWhitespace::kShouldAppend | 578 ? AppendTrailingWhitespace::kShouldAppend |
| 575 : AppendTrailingWhitespace::kDontAppend); | 579 : AppendTrailingWhitespace::kDontAppend); |
| 576 } | 580 } |
| 577 | 581 |
| 578 void SelectionController::SelectClosestWordOrLinkFromMouseEvent( | 582 void SelectionController::SelectClosestWordOrLinkFromMouseEvent( |
| 579 const MouseEventWithHitTestResults& result) { | 583 const MouseEventWithHitTestResults& result) { |
| 580 if (!result.GetHitTestResult().IsLiveLink()) | 584 if (!result.GetHitTestResult().IsLiveLink()) { |
| 581 return SelectClosestWordFromMouseEvent(result); | 585 SelectClosestWordFromMouseEvent(result); |
| 586 return; | |
| 587 } | |
| 582 | 588 |
| 583 Node* inner_node = result.InnerNode(); | 589 Node* inner_node = result.InnerNode(); |
| 584 | 590 |
| 585 if (!inner_node || !inner_node->GetLayoutObject() || | 591 if (!inner_node || !inner_node->GetLayoutObject() || |
| 586 !mouse_down_may_start_select_) | 592 !mouse_down_may_start_select_) |
| 587 return; | 593 return; |
| 588 | 594 |
| 589 VisibleSelectionInFlatTree new_selection; | 595 VisibleSelectionInFlatTree new_selection; |
| 590 Element* url_element = result.GetHitTestResult().URLElement(); | 596 Element* url_element = result.GetHitTestResult().URLElement(); |
| 591 const VisiblePositionInFlatTree pos = | 597 const VisiblePositionInFlatTree pos = |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 756 return false; | 762 return false; |
| 757 | 763 |
| 758 if (Selection().ComputeVisibleSelectionInDOMTreeDeprecated().IsRange()) { | 764 if (Selection().ComputeVisibleSelectionInDOMTreeDeprecated().IsRange()) { |
| 759 // A double-click when range is already selected | 765 // A double-click when range is already selected |
| 760 // should not change the selection. So, do not call | 766 // should not change the selection. So, do not call |
| 761 // selectClosestWordFromMouseEvent, but do set | 767 // selectClosestWordFromMouseEvent, but do set |
| 762 // m_beganSelectingText to prevent handleMouseReleaseEvent | 768 // m_beganSelectingText to prevent handleMouseReleaseEvent |
| 763 // from setting caret selection. | 769 // from setting caret selection. |
| 764 selection_state_ = SelectionState::kExtendedSelection; | 770 selection_state_ = SelectionState::kExtendedSelection; |
| 765 } else { | 771 } else { |
| 766 SelectClosestWordFromMouseEvent(event); | 772 const bool did_select = SelectClosestWordFromMouseEvent(event); |
| 773 if (did_select && Selection().IsHandleVisible()) { | |
| 774 frame_->GetEventHandler().ShowNonLocatedContextMenu(nullptr, | |
| 775 kMenuSourceTouch); | |
| 776 } | |
| 767 } | 777 } |
| 768 return true; | 778 return true; |
| 769 } | 779 } |
| 770 | 780 |
| 771 bool SelectionController::HandleTripleClick( | 781 bool SelectionController::HandleTripleClick( |
| 772 const MouseEventWithHitTestResults& event) { | 782 const MouseEventWithHitTestResults& event) { |
| 773 TRACE_EVENT0("blink", | 783 TRACE_EVENT0("blink", |
| 774 "SelectionController::handleMousePressEventTripleClick"); | 784 "SelectionController::handleMousePressEventTripleClick"); |
| 775 | 785 |
| 776 if (!Selection().IsAvailable()) { | 786 if (!Selection().IsAvailable()) { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 796 new_selection = | 806 new_selection = |
| 797 CreateVisibleSelection(SelectionInFlatTree::Builder() | 807 CreateVisibleSelection(SelectionInFlatTree::Builder() |
| 798 .Collapse(pos.ToPositionWithAffinity()) | 808 .Collapse(pos.ToPositionWithAffinity()) |
| 799 .SetGranularity(kParagraphGranularity) | 809 .SetGranularity(kParagraphGranularity) |
| 800 .Build()); | 810 .Build()); |
| 801 } | 811 } |
| 802 | 812 |
| 803 const bool is_handle_visible = | 813 const bool is_handle_visible = |
| 804 event.Event().FromTouch() && new_selection.IsRange(); | 814 event.Event().FromTouch() && new_selection.IsRange(); |
| 805 | 815 |
| 806 return UpdateSelectionForMouseDownDispatchingSelectStart( | 816 const bool did_select = UpdateSelectionForMouseDownDispatchingSelectStart( |
| 807 inner_node, | 817 inner_node, |
| 808 ExpandSelectionToRespectUserSelectAll(inner_node, new_selection), | 818 ExpandSelectionToRespectUserSelectAll(inner_node, new_selection), |
| 809 kParagraphGranularity, | 819 kParagraphGranularity, |
| 810 is_handle_visible ? HandleVisibility::kVisible | 820 is_handle_visible ? HandleVisibility::kVisible |
| 811 : HandleVisibility::kNotVisible); | 821 : HandleVisibility::kNotVisible); |
| 822 if (did_select && Selection().IsHandleVisible()) { | |
|
yosin_UTC9
2017/05/25 04:47:20
early-return style is better.
if (!did_selection)
amaralp1
2017/05/25 07:11:56
Done.
| |
| 823 frame_->GetEventHandler().ShowNonLocatedContextMenu(nullptr, | |
| 824 kMenuSourceTouch); | |
| 825 } | |
| 826 return did_select; | |
| 812 } | 827 } |
| 813 | 828 |
| 814 bool SelectionController::HandleMousePressEvent( | 829 bool SelectionController::HandleMousePressEvent( |
| 815 const MouseEventWithHitTestResults& event) { | 830 const MouseEventWithHitTestResults& event) { |
| 816 TRACE_EVENT0("blink", "SelectionController::handleMousePressEvent"); | 831 TRACE_EVENT0("blink", "SelectionController::handleMousePressEvent"); |
| 817 | 832 |
| 818 // If we got the event back, that must mean it wasn't prevented, | 833 // If we got the event back, that must mean it wasn't prevented, |
| 819 // so it's allowed to start a drag or selection if it wasn't in a scrollbar. | 834 // so it's allowed to start a drag or selection if it wasn't in a scrollbar. |
| 820 mouse_down_may_start_select_ = | 835 mouse_down_may_start_select_ = |
| 821 (CanMouseDownStartSelect(event.InnerNode()) || IsLinkSelection(event)) && | 836 (CanMouseDownStartSelect(event.InnerNode()) || IsLinkSelection(event)) && |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1134 | 1149 |
| 1135 bool IsExtendingSelection(const MouseEventWithHitTestResults& event) { | 1150 bool IsExtendingSelection(const MouseEventWithHitTestResults& event) { |
| 1136 bool is_mouse_down_on_link_or_image = | 1151 bool is_mouse_down_on_link_or_image = |
| 1137 event.IsOverLink() || event.GetHitTestResult().GetImage(); | 1152 event.IsOverLink() || event.GetHitTestResult().GetImage(); |
| 1138 return (event.Event().GetModifiers() & WebInputEvent::Modifiers::kShiftKey) != | 1153 return (event.Event().GetModifiers() & WebInputEvent::Modifiers::kShiftKey) != |
| 1139 0 && | 1154 0 && |
| 1140 !is_mouse_down_on_link_or_image; | 1155 !is_mouse_down_on_link_or_image; |
| 1141 } | 1156 } |
| 1142 | 1157 |
| 1143 } // namespace blink | 1158 } // namespace blink |
| OLD | NEW |