Changeset 126284 in webkit
- Timestamp:
- Aug 22, 2012 3:23:55 AM (12 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r126282 r126284 1 2012-08-22 Allan Sandfeld Jensen <allan.jensen@nokia.com> 2 3 [TouchAdjustment] Adjust to word or selection 4 https://bugs.webkit.org/show_bug.cgi?id=94449 5 6 Reviewed by Antonio Gomes. 7 8 Tests that touch-adjustment can adjust to the right subtargets within text-nodes. 9 10 * touchadjustment/context-menu-select-text.html: 11 * touchadjustment/context-menu-text-subtargets-expected.txt: Added. 12 * touchadjustment/context-menu-text-subtargets.html: Added. 13 * touchadjustment/resources/touchadjustment.js: 14 (pointToString): 15 (shouldBeWithin): 16 1 17 2012-08-22 Balazs Ankes <bank@inf.u-szeged.hu> 2 18 -
trunk/LayoutTests/touchadjustment/context-menu-select-text.html
r126069 r126284 2 2 <html> 3 3 <head> 4 <title>Touch Adjustment : Adjust context-menu to selectable words- bug 94101</title>4 <title>Touch Adjustment : Adjust context-menu to selectable text - bug 94101</title> 5 5 <script src="../fast/js/resources/js-test-pre.js"></script> 6 6 <script src="resources/touchadjustment.js"></script> -
trunk/LayoutTests/touchadjustment/resources/touchadjustment.js
r126069 r126284 25 25 } 26 26 27 function boundsToString(bounds) 28 { 29 return "("+bounds.left+","+bounds.top+")x("+bounds.width+","+bounds.height+")"; 30 } 31 32 function pointToString(point) 33 { 34 return "("+point.x+","+point.y+")"; 35 } 36 37 27 38 function shouldBeNode(adjustedNode, targetNode) { 28 39 if (typeof targetNode == "string") { … … 43 54 } 44 55 } 56 57 function shouldBeWithin(adjustedPoint, targetArea) { 58 if (adjustedPoint.x >= targetArea.left && adjustedPoint.y >= targetArea.top 59 && adjustedPoint.x <= (targetArea.left + targetArea.width) 60 && adjustedPoint.y <= (targetArea.top + targetArea.height)) { 61 testPassed("adjusted point was within " + boundsToString(targetArea)); 62 } else { 63 testFailed("adjusted node should be within " + boundsToString(targetArea) + ". Was " + pointToString(adjustedPoint)); 64 } 65 } 66 45 67 46 68 function testTouchPoint(touchpoint, targetNode, allowTextNodes) -
trunk/Source/WebCore/ChangeLog
r126283 r126284 1 2012-08-22 Allan Sandfeld Jensen <allan.jensen@nokia.com> 2 3 [TouchAdjustment] Adjust to word or selection 4 https://bugs.webkit.org/show_bug.cgi?id=94449 5 6 Reviewed by Antonio Gomes. 7 8 Makes each separate word a separate subtarget when context menu triggers 9 selections, and only the selected part of a partial selected node a 10 target when selections are not overridden. 11 12 Fix of reverted commit r126026, fix misplaced ASSERT. 13 14 Test: touchadjustment/context-menu-text-subtargets.html 15 16 * page/TouchAdjustment.cpp: 17 (TouchAdjustment): 18 (WebCore::TouchAdjustment::providesContextMenuItems): 19 (WebCore::TouchAdjustment::appendQuadsToSubtargetList): 20 (WebCore::TouchAdjustment::appendBasicSubtargetsForNode): 21 (WebCore::TouchAdjustment::appendContextSubtargetsForNode): 22 (WebCore::TouchAdjustment::compileSubtargetList): 23 (WebCore::findBestClickableCandidate): 24 (WebCore::findBestContextMenuCandidate): 25 1 26 2012-08-22 Andrey Adaikin <aandrey@chromium.org> 2 27 -
trunk/Source/WebCore/page/TouchAdjustment.cpp
r126069 r126284 36 36 #include "RenderObject.h" 37 37 #include "RenderStyle.h" 38 #include "RenderText.h" 38 39 #include "ShadowRoot.h" 40 #include "Text.h" 41 #include "TextBreakIterator.h" 39 42 40 43 namespace WebCore { … … 63 66 typedef Vector<SubtargetGeometry> SubtargetGeometryList; 64 67 typedef bool (*NodeFilter)(Node*); 68 typedef void (*AppendSubtargetsForNode)(Node*, SubtargetGeometryList&); 65 69 typedef float (*DistanceFunction)(const IntPoint&, const IntRect&, const SubtargetGeometry&); 66 70 … … 102 106 return true; 103 107 if (node->renderer()->canBeSelectionLeaf()) { 104 // If the context menu gesture will trigger a selection all selectable nodes are targets. 105 // FIXME: To improve the adjusted point, each individual word should be a separate subtarget, 106 // see for example FatFingers::checkForText() in WebKit/blackberry. 108 // If the context menu gesture will trigger a selection all selectable nodes are valid targets. 107 109 if (node->renderer()->frame()->editor()->behavior().shouldSelectOnContextualMenuClick()) 108 110 return true; 109 // FIXME: A selected text might only be partially selected, and we should only append110 // the selected subtargets of it in appendSubtargetsForNodeToList().111 // Only the selected part of the renderer is a valid target, but this will be corrected in 112 // appendContextSubtargetsForNode. 111 113 if (node->renderer()->selectionState() != RenderObject::SelectionNone) 112 114 return true; … … 115 117 } 116 118 117 static inline void appendSubtargetsForNodeToList(Node* node, SubtargetGeometryList& subtargets) 118 { 119 // Since the node is a result of a hit test, we are already ensured it has a renderer. 120 ASSERT(node->renderer()); 121 122 Vector<FloatQuad> quads; 123 node->renderer()->absoluteQuads(quads); 124 119 static inline void appendQuadsToSubtargetList(Vector<FloatQuad>& quads, Node* node, SubtargetGeometryList& subtargets) 120 { 125 121 Vector<FloatQuad>::const_iterator it = quads.begin(); 126 122 const Vector<FloatQuad>::const_iterator end = quads.end(); 127 123 for (; it != end; ++it) 128 124 subtargets.append(SubtargetGeometry(node, *it)); 125 } 126 127 static inline void appendBasicSubtargetsForNode(Node* node, SubtargetGeometryList& subtargets) 128 { 129 // Since the node is a result of a hit test, we are already ensured it has a renderer. 130 ASSERT(node->renderer()); 131 132 Vector<FloatQuad> quads; 133 node->renderer()->absoluteQuads(quads); 134 135 appendQuadsToSubtargetList(quads, node, subtargets); 136 } 137 138 static inline void appendContextSubtargetsForNode(Node* node, SubtargetGeometryList& subtargets) 139 { 140 // This is a variant of appendBasicSubtargetsForNode that adds special subtargets for 141 // selected or auto-selectable parts of text nodes. 142 ASSERT(node->renderer()); 143 144 if (!node->isTextNode()) 145 return appendBasicSubtargetsForNode(node, subtargets); 146 147 Text* textNode = static_cast<WebCore::Text*>(node); 148 RenderText* textRenderer = static_cast<RenderText*>(textNode->renderer()); 149 150 if (textRenderer->frame()->editor()->behavior().shouldSelectOnContextualMenuClick()) { 151 // Make subtargets out of every word. 152 String textValue = textNode->data(); 153 TextBreakIterator* wordIterator = wordBreakIterator(textValue.characters(), textValue.length()); 154 int lastOffset = textBreakFirst(wordIterator); 155 if (lastOffset == -1) 156 return; 157 int offset; 158 while ((offset = textBreakNext(wordIterator)) != -1) { 159 if (isWordTextBreak(wordIterator)) { 160 Vector<FloatQuad> quads; 161 textRenderer->absoluteQuadsForRange(quads, lastOffset, offset); 162 appendQuadsToSubtargetList(quads, textNode, subtargets); 163 } 164 lastOffset = offset; 165 } 166 } else { 167 if (textRenderer->selectionState() == RenderObject::SelectionNone) 168 return appendBasicSubtargetsForNode(node, subtargets); 169 // If selected, make subtargets out of only the selected part of the text. 170 int startPos, endPos; 171 switch (textRenderer->selectionState()) { 172 case RenderObject::SelectionInside: 173 startPos = 0; 174 endPos = textRenderer->textLength(); 175 break; 176 case RenderObject::SelectionStart: 177 textRenderer->selectionStartEnd(startPos, endPos); 178 endPos = textRenderer->textLength(); 179 break; 180 case RenderObject::SelectionEnd: 181 textRenderer->selectionStartEnd(startPos, endPos); 182 startPos = 0; 183 break; 184 case RenderObject::SelectionBoth: 185 textRenderer->selectionStartEnd(startPos, endPos); 186 break; 187 default: 188 ASSERT_NOT_REACHED(); 189 return; 190 } 191 Vector<FloatQuad> quads; 192 textRenderer->absoluteQuadsForRange(quads, startPos, endPos); 193 appendQuadsToSubtargetList(quads, textNode, subtargets); 194 } 129 195 } 130 196 … … 149 215 150 216 // Compiles a list of subtargets of all the relevant target nodes. 151 void compileSubtargetList(const NodeList& intersectedNodes, SubtargetGeometryList& subtargets, NodeFilter nodeFilter )217 void compileSubtargetList(const NodeList& intersectedNodes, SubtargetGeometryList& subtargets, NodeFilter nodeFilter, AppendSubtargetsForNode appendSubtargetsForNode) 152 218 { 153 219 // Find candidates responding to tap gesture events in O(n) time. … … 202 268 if (ancestorsToRespondersSet.contains(respondingNode)) 203 269 continue; 204 appendSubtargetsForNode ToList(candidate, subtargets);270 appendSubtargetsForNode(candidate, subtargets); 205 271 } 206 272 } … … 409 475 IntRect targetArea; 410 476 TouchAdjustment::SubtargetGeometryList subtargets; 411 TouchAdjustment::compileSubtargetList(nodeList, subtargets, TouchAdjustment::nodeRespondsToTapGesture );477 TouchAdjustment::compileSubtargetList(nodeList, subtargets, TouchAdjustment::nodeRespondsToTapGesture, TouchAdjustment::appendBasicSubtargetsForNode); 412 478 return TouchAdjustment::findNodeWithLowestDistanceMetric(targetNode, targetPoint, targetArea, touchHotspot, touchArea, subtargets, TouchAdjustment::hybridDistanceFunction); 413 479 } … … 417 483 IntRect targetArea; 418 484 TouchAdjustment::SubtargetGeometryList subtargets; 419 TouchAdjustment::compileSubtargetList(nodeList, subtargets, TouchAdjustment::providesContextMenuItems );485 TouchAdjustment::compileSubtargetList(nodeList, subtargets, TouchAdjustment::providesContextMenuItems, TouchAdjustment::appendContextSubtargetsForNode); 420 486 return TouchAdjustment::findNodeWithLowestDistanceMetric(targetNode, targetPoint, targetArea, touchHotspot, touchArea, subtargets, TouchAdjustment::hybridDistanceFunction); 421 487 }
Note: See TracChangeset
for help on using the changeset viewer.