Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(251)

Side by Side Diff: third_party/WebKit/Source/core/editing/FrameSelection.cpp

Issue 2201853002: Blink handle selection handle visibility (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: try running even rebaseline tests Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 } 151 }
152 152
153 const VisibleSelectionInFlatTree& FrameSelection::selectionInFlatTree() const { 153 const VisibleSelectionInFlatTree& FrameSelection::selectionInFlatTree() const {
154 return visibleSelection<EditingInFlatTreeStrategy>(); 154 return visibleSelection<EditingInFlatTreeStrategy>();
155 } 155 }
156 156
157 void FrameSelection::moveTo(const VisiblePosition& pos, 157 void FrameSelection::moveTo(const VisiblePosition& pos,
158 EUserTriggered userTriggered, 158 EUserTriggered userTriggered,
159 CursorAlignOnScroll align) { 159 CursorAlignOnScroll align) {
160 SetSelectionOptions options = CloseTyping | ClearTypingStyle | userTriggered; 160 SetSelectionOptions options = CloseTyping | ClearTypingStyle | userTriggered;
161 setSelection(createVisibleSelection(pos, pos, selection().isDirectional()), 161 bool isHandleVisible = userTriggered == UserTriggered;
162 setSelection(createVisibleSelection(pos, pos, selection().isDirectional(),
163 isHandleVisible),
162 options, align); 164 options, align);
163 } 165 }
164 166
165 void FrameSelection::moveTo(const Position& pos, TextAffinity affinity) { 167 void FrameSelection::moveTo(const Position& pos, TextAffinity affinity) {
166 SetSelectionOptions options = CloseTyping | ClearTypingStyle; 168 SetSelectionOptions options = CloseTyping | ClearTypingStyle;
167 setSelection( 169 setSelection(
168 createVisibleSelection(pos, affinity, selection().isDirectional()), 170 createVisibleSelection(pos, affinity, selection().isDirectional()),
169 options); 171 options);
170 } 172 }
171 173
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 810
809 void FrameSelection::dataWillChange(const CharacterData& node) { 811 void FrameSelection::dataWillChange(const CharacterData& node) {
810 m_frameCaret->dataWillChange(node); 812 m_frameCaret->dataWillChange(node);
811 } 813 }
812 814
813 void FrameSelection::paintCaret(GraphicsContext& context, 815 void FrameSelection::paintCaret(GraphicsContext& context,
814 const LayoutPoint& paintOffset) { 816 const LayoutPoint& paintOffset) {
815 m_frameCaret->paintCaret(context, paintOffset); 817 m_frameCaret->paintCaret(context, paintOffset);
816 } 818 }
817 819
818 bool FrameSelection::contains(const LayoutPoint& point) { 820 bool FrameSelection::contains(const HitTestResult& result) {
819 if (document().layoutViewItem().isNull())
820 return false;
821
822 // Treat a collapsed selection like no selection. 821 // Treat a collapsed selection like no selection.
823 const VisibleSelectionInFlatTree& visibleSelection = 822 const VisibleSelectionInFlatTree& visibleSelection =
824 this->visibleSelection<EditingInFlatTreeStrategy>(); 823 this->visibleSelection<EditingInFlatTreeStrategy>();
825 if (!visibleSelection.isRange()) 824 if (!visibleSelection.isRange())
826 return false; 825 return false;
827 826
828 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active);
829 HitTestResult result(request, point);
830 document().layoutViewItem().hitTest(result);
831 Node* innerNode = result.innerNode(); 827 Node* innerNode = result.innerNode();
832 if (!innerNode || !innerNode->layoutObject()) 828 if (!innerNode || !innerNode->layoutObject())
833 return false; 829 return false;
834 830
835 const VisiblePositionInFlatTree& visiblePos = 831 const VisiblePositionInFlatTree& visiblePos =
836 createVisiblePosition(fromPositionInDOMTree<EditingInFlatTreeStrategy>( 832 createVisiblePosition(fromPositionInDOMTree<EditingInFlatTreeStrategy>(
837 innerNode->layoutObject()->positionForPoint(result.localPoint()))); 833 innerNode->layoutObject()->positionForPoint(result.localPoint())));
838 if (visiblePos.isNull()) 834 if (visiblePos.isNull())
839 return false; 835 return false;
840 836
841 const VisiblePositionInFlatTree& visibleStart = 837 const VisiblePositionInFlatTree& visibleStart =
842 visibleSelection.visibleStart(); 838 visibleSelection.visibleStart();
843 const VisiblePositionInFlatTree& visibleEnd = visibleSelection.visibleEnd(); 839 const VisiblePositionInFlatTree& visibleEnd = visibleSelection.visibleEnd();
844 if (visibleStart.isNull() || visibleEnd.isNull()) 840 if (visibleStart.isNull() || visibleEnd.isNull())
845 return false; 841 return false;
846 842
847 const PositionInFlatTree& start = visibleStart.deepEquivalent(); 843 const PositionInFlatTree& start = visibleStart.deepEquivalent();
848 const PositionInFlatTree& end = visibleEnd.deepEquivalent(); 844 const PositionInFlatTree& end = visibleEnd.deepEquivalent();
849 const PositionInFlatTree& pos = visiblePos.deepEquivalent(); 845 const PositionInFlatTree& pos = visiblePos.deepEquivalent();
850 return start.compareTo(pos) <= 0 && pos.compareTo(end) <= 0; 846 return start.compareTo(pos) <= 0 && pos.compareTo(end) <= 0;
851 } 847 }
852 848
849 bool FrameSelection::contains(const LayoutPoint& point) {
850 if (document().layoutViewItem().isNull())
851 return false;
852
853 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active);
854 HitTestResult result(request, point);
855 document().layoutViewItem().hitTest(result);
856
857 return contains(result);
858 }
859
853 // Workaround for the fact that it's hard to delete a frame. 860 // Workaround for the fact that it's hard to delete a frame.
854 // Call this after doing user-triggered selections to make it easy to delete the 861 // Call this after doing user-triggered selections to make it easy to delete the
855 // frame you entirely selected. Can't do this implicitly as part of every 862 // frame you entirely selected. Can't do this implicitly as part of every
856 // setSelection call because in some contexts it might not be good for the focus 863 // setSelection call because in some contexts it might not be good for the focus
857 // to move to another frame. So instead we call it from places where we are 864 // to move to another frame. So instead we call it from places where we are
858 // selecting with the mouse or the keyboard after setting the selection. 865 // selecting with the mouse or the keyboard after setting the selection.
859 void FrameSelection::selectFrameElementInParentIfFullySelected() { 866 void FrameSelection::selectFrameElementInParentIfFullySelected() {
860 // Find the parent frame; if there is none, then we have nothing to do. 867 // Find the parent frame; if there is none, then we have nothing to do.
861 Frame* parent = m_frame->tree().parent(); 868 Frame* parent = m_frame->tree().parent();
862 if (!parent) 869 if (!parent)
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 SetSelectionOptions options) { 1001 SetSelectionOptions options) {
995 if (range.isNull()) 1002 if (range.isNull())
996 return false; 1003 return false;
997 m_selectionEditor->resetLogicalRange(); 1004 m_selectionEditor->resetLogicalRange();
998 // Since |FrameSeleciton::setSelection()| dispatches events and DOM tree 1005 // Since |FrameSeleciton::setSelection()| dispatches events and DOM tree
999 // can be modified by event handlers, we should create |Range| object before 1006 // can be modified by event handlers, we should create |Range| object before
1000 // calling it. 1007 // calling it.
1001 Range* logicalRange = createRange(range); 1008 Range* logicalRange = createRange(range);
1002 VisibleSelection newSelection = createVisibleSelection( 1009 VisibleSelection newSelection = createVisibleSelection(
1003 range.startPosition(), range.endPosition(), affinity, 1010 range.startPosition(), range.endPosition(), affinity,
1004 directional == SelectionDirectionalMode::Directional); 1011 directional == SelectionDirectionalMode::Directional,
1012 selection().isHandleVisible());
1005 setSelection(newSelection, options); 1013 setSelection(newSelection, options);
1006 m_selectionEditor->setLogicalRange(logicalRange); 1014 m_selectionEditor->setLogicalRange(logicalRange);
1007 return true; 1015 return true;
1008 } 1016 }
1009 1017
1010 Range* FrameSelection::firstRange() const { 1018 Range* FrameSelection::firstRange() const {
1011 return m_selectionEditor->firstRange(); 1019 return m_selectionEditor->firstRange();
1012 } 1020 }
1013 1021
1014 bool FrameSelection::isInPasswordField() const { 1022 bool FrameSelection::isInPasswordField() const {
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
1392 1400
1393 bool FrameSelection::selectWordAroundPosition(const VisiblePosition& position) { 1401 bool FrameSelection::selectWordAroundPosition(const VisiblePosition& position) {
1394 static const EWordSide wordSideList[2] = {RightWordIfOnBoundary, 1402 static const EWordSide wordSideList[2] = {RightWordIfOnBoundary,
1395 LeftWordIfOnBoundary}; 1403 LeftWordIfOnBoundary};
1396 for (EWordSide wordSide : wordSideList) { 1404 for (EWordSide wordSide : wordSideList) {
1397 VisiblePosition start = startOfWord(position, wordSide); 1405 VisiblePosition start = startOfWord(position, wordSide);
1398 VisiblePosition end = endOfWord(position, wordSide); 1406 VisiblePosition end = endOfWord(position, wordSide);
1399 String text = 1407 String text =
1400 plainText(EphemeralRange(start.deepEquivalent(), end.deepEquivalent())); 1408 plainText(EphemeralRange(start.deepEquivalent(), end.deepEquivalent()));
1401 if (!text.isEmpty() && !isSeparator(text.characterStartingAt(0))) { 1409 if (!text.isEmpty() && !isSeparator(text.characterStartingAt(0))) {
1402 setSelection(createVisibleSelection(start, end), WordGranularity); 1410 VisibleSelection newSelection = createVisibleSelection(start, end);
1411 newSelection.setIsHandleVisible(selection().isHandleVisible());
1412 setSelection(newSelection, WordGranularity);
1403 return true; 1413 return true;
1404 } 1414 }
1405 } 1415 }
1406 1416
1407 return false; 1417 return false;
1408 } 1418 }
1409 1419
1410 GranularityStrategy* FrameSelection::granularityStrategy() { 1420 GranularityStrategy* FrameSelection::granularityStrategy() {
1411 // We do lazy initalization for m_granularityStrategy, because if we 1421 // We do lazy initalization for m_granularityStrategy, because if we
1412 // initialize it right in the constructor - the correct settings may not be 1422 // initialize it right in the constructor - the correct settings may not be
(...skipping 12 matching lines...) Expand all
1425 m_granularityStrategy = wrapUnique(new CharacterGranularityStrategy()); 1435 m_granularityStrategy = wrapUnique(new CharacterGranularityStrategy());
1426 return m_granularityStrategy.get(); 1436 return m_granularityStrategy.get();
1427 } 1437 }
1428 1438
1429 void FrameSelection::moveRangeSelectionExtent(const IntPoint& contentsPoint) { 1439 void FrameSelection::moveRangeSelectionExtent(const IntPoint& contentsPoint) {
1430 if (isNone()) 1440 if (isNone())
1431 return; 1441 return;
1432 1442
1433 VisibleSelection newSelection = 1443 VisibleSelection newSelection =
1434 granularityStrategy()->updateExtent(contentsPoint, m_frame); 1444 granularityStrategy()->updateExtent(contentsPoint, m_frame);
1445 newSelection.setIsHandleVisible(
1446 m_selectionEditor->visibleSelection<EditingStrategy>().isHandleVisible());
1435 setSelection(newSelection, 1447 setSelection(newSelection,
1436 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | 1448 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle |
1437 FrameSelection::DoNotClearStrategy | UserTriggered, 1449 FrameSelection::DoNotClearStrategy | UserTriggered,
1438 CursorAlignOnScroll::IfNeeded, CharacterGranularity); 1450 CursorAlignOnScroll::IfNeeded, CharacterGranularity);
1439 } 1451 }
1440 1452
1441 void FrameSelection::moveRangeSelection(const VisiblePosition& basePosition, 1453 void FrameSelection::moveRangeSelection(const VisiblePosition& basePosition,
1442 const VisiblePosition& extentPosition, 1454 const VisiblePosition& extentPosition,
1443 TextGranularity granularity) { 1455 TextGranularity granularity) {
1444 VisibleSelection newSelection = 1456 VisibleSelection newSelection =
1445 createVisibleSelection(basePosition, extentPosition); 1457 createVisibleSelection(basePosition, extentPosition);
1458 newSelection.setIsHandleVisible(
1459 m_selectionEditor->visibleSelection<EditingStrategy>().isHandleVisible());
1446 newSelection.expandUsingGranularity(granularity); 1460 newSelection.expandUsingGranularity(granularity);
1447 1461
1448 if (newSelection.isNone()) 1462 if (newSelection.isNone())
1449 return; 1463 return;
1450 1464
1451 setSelection(newSelection, granularity); 1465 setSelection(newSelection, granularity);
1452 } 1466 }
1453 1467
1454 void FrameSelection::updateIfNeeded() { 1468 void FrameSelection::updateIfNeeded() {
1455 m_selectionEditor->updateIfNeeded(); 1469 m_selectionEditor->updateIfNeeded();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1493 } 1507 }
1494 1508
1495 void showTree(const blink::FrameSelection* sel) { 1509 void showTree(const blink::FrameSelection* sel) {
1496 if (sel) 1510 if (sel)
1497 sel->showTreeForThis(); 1511 sel->showTreeForThis();
1498 else 1512 else
1499 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; 1513 LOG(INFO) << "Cannot showTree for <null> FrameSelection.";
1500 } 1514 }
1501 1515
1502 #endif 1516 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698