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

Side by Side Diff: sky/engine/core/page/TouchAdjustment.cpp

Issue 640143004: Remove context menus. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « sky/engine/core/page/TouchAdjustment.h ('k') | sky/engine/core/testing/DummyPageHolder.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies) 2 * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 99
100 bool nodeIsZoomTarget(Node* node) 100 bool nodeIsZoomTarget(Node* node)
101 { 101 {
102 if (node->isTextNode() || node->isShadowRoot()) 102 if (node->isTextNode() || node->isShadowRoot())
103 return false; 103 return false;
104 104
105 ASSERT(node->renderer()); 105 ASSERT(node->renderer());
106 return node->renderer()->isBox(); 106 return node->renderer()->isBox();
107 } 107 }
108 108
109 bool providesContextMenuItems(Node* node)
110 {
111 // This function tries to match the nodes that receive special context-menu items in
112 // ContextMenuController::populate(), and should be kept uptodate with those .
113 ASSERT(node->renderer() || node->isShadowRoot());
114 if (!node->renderer())
115 return false;
116 if (node->isContentEditable())
117 return true;
118 if (node->isLink())
119 return true;
120 if (node->renderer()->isImage())
121 return true;
122 if (node->renderer()->isMedia())
123 return true;
124 if (node->renderer()->canBeSelectionLeaf()) {
125 // If the context menu gesture will trigger a selection all selectable n odes are valid targets.
126 if (node->renderer()->frame()->editor().behavior().shouldSelectOnContext ualMenuClick())
127 return true;
128 // Only the selected part of the renderer is a valid target, but this wi ll be corrected in
129 // appendContextSubtargetsForNode.
130 if (node->renderer()->selectionState() != RenderObject::SelectionNone)
131 return true;
132 }
133 return false;
134 }
135
136 static inline void appendQuadsToSubtargetList(Vector<FloatQuad>& quads, Node* no de, SubtargetGeometryList& subtargets) 109 static inline void appendQuadsToSubtargetList(Vector<FloatQuad>& quads, Node* no de, SubtargetGeometryList& subtargets)
137 { 110 {
138 Vector<FloatQuad>::const_iterator it = quads.begin(); 111 Vector<FloatQuad>::const_iterator it = quads.begin();
139 const Vector<FloatQuad>::const_iterator end = quads.end(); 112 const Vector<FloatQuad>::const_iterator end = quads.end();
140 for (; it != end; ++it) 113 for (; it != end; ++it)
141 subtargets.append(SubtargetGeometry(node, *it)); 114 subtargets.append(SubtargetGeometry(node, *it));
142 } 115 }
143 116
144 static inline void appendBasicSubtargetsForNode(Node* node, SubtargetGeometryLis t& subtargets) 117 static inline void appendBasicSubtargetsForNode(Node* node, SubtargetGeometryLis t& subtargets)
145 { 118 {
146 // Node guaranteed to have renderer due to check in node filter. 119 // Node guaranteed to have renderer due to check in node filter.
147 ASSERT(node->renderer()); 120 ASSERT(node->renderer());
148 121
149 Vector<FloatQuad> quads; 122 Vector<FloatQuad> quads;
150 node->renderer()->absoluteQuads(quads); 123 node->renderer()->absoluteQuads(quads);
151 124
152 appendQuadsToSubtargetList(quads, node, subtargets); 125 appendQuadsToSubtargetList(quads, node, subtargets);
153 } 126 }
154 127
155 static inline void appendContextSubtargetsForNode(Node* node, SubtargetGeometryL ist& subtargets)
156 {
157 // This is a variant of appendBasicSubtargetsForNode that adds special subta rgets for
158 // selected or auto-selectable parts of text nodes.
159 ASSERT(node->renderer());
160
161 if (!node->isTextNode())
162 return appendBasicSubtargetsForNode(node, subtargets);
163
164 Text* textNode = toText(node);
165 RenderText* textRenderer = textNode->renderer();
166
167 if (textRenderer->frame()->editor().behavior().shouldSelectOnContextualMenuC lick()) {
168 // Make subtargets out of every word.
169 String textValue = textNode->data();
170 TextBreakIterator* wordIterator = wordBreakIterator(textValue, 0, textVa lue.length());
171 int lastOffset = wordIterator->first();
172 if (lastOffset == -1)
173 return;
174 int offset;
175 while ((offset = wordIterator->next()) != -1) {
176 if (isWordTextBreak(wordIterator)) {
177 Vector<FloatQuad> quads;
178 textRenderer->absoluteQuadsForRange(quads, lastOffset, offset);
179 appendQuadsToSubtargetList(quads, textNode, subtargets);
180 }
181 lastOffset = offset;
182 }
183 } else {
184 if (textRenderer->selectionState() == RenderObject::SelectionNone)
185 return appendBasicSubtargetsForNode(node, subtargets);
186 // If selected, make subtargets out of only the selected part of the tex t.
187 int startPos, endPos;
188 switch (textRenderer->selectionState()) {
189 case RenderObject::SelectionInside:
190 startPos = 0;
191 endPos = textRenderer->textLength();
192 break;
193 case RenderObject::SelectionStart:
194 textRenderer->selectionStartEnd(startPos, endPos);
195 endPos = textRenderer->textLength();
196 break;
197 case RenderObject::SelectionEnd:
198 textRenderer->selectionStartEnd(startPos, endPos);
199 startPos = 0;
200 break;
201 case RenderObject::SelectionBoth:
202 textRenderer->selectionStartEnd(startPos, endPos);
203 break;
204 default:
205 ASSERT_NOT_REACHED();
206 return;
207 }
208 Vector<FloatQuad> quads;
209 textRenderer->absoluteQuadsForRange(quads, startPos, endPos);
210 appendQuadsToSubtargetList(quads, textNode, subtargets);
211 }
212 }
213
214 static inline void appendZoomableSubtargets(Node* node, SubtargetGeometryList& s ubtargets) 128 static inline void appendZoomableSubtargets(Node* node, SubtargetGeometryList& s ubtargets)
215 { 129 {
216 RenderBox* renderer = toRenderBox(node->renderer()); 130 RenderBox* renderer = toRenderBox(node->renderer());
217 ASSERT(renderer); 131 ASSERT(renderer);
218 132
219 Vector<FloatQuad> quads; 133 Vector<FloatQuad> quads;
220 FloatRect borderBoxRect = renderer->borderBoxRect(); 134 FloatRect borderBoxRect = renderer->borderBoxRect();
221 FloatRect contentBoxRect = renderer->contentBoxRect(); 135 FloatRect contentBoxRect = renderer->contentBoxRect();
222 quads.append(renderer->localToAbsoluteQuad(borderBoxRect)); 136 quads.append(renderer->localToAbsoluteQuad(borderBoxRect));
223 if (borderBoxRect != contentBoxRect) 137 if (borderBoxRect != contentBoxRect)
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 } // namespace TouchAdjustment 394 } // namespace TouchAdjustment
481 395
482 bool findBestClickableCandidate(Node*& targetNode, IntPoint& targetPoint, const IntPoint& touchHotspot, const IntRect& touchArea, const WillBeHeapVector<RefPtrW illBeMember<Node> >& nodes) 396 bool findBestClickableCandidate(Node*& targetNode, IntPoint& targetPoint, const IntPoint& touchHotspot, const IntRect& touchArea, const WillBeHeapVector<RefPtrW illBeMember<Node> >& nodes)
483 { 397 {
484 IntRect targetArea; 398 IntRect targetArea;
485 TouchAdjustment::SubtargetGeometryList subtargets; 399 TouchAdjustment::SubtargetGeometryList subtargets;
486 TouchAdjustment::compileSubtargetList(nodes, subtargets, TouchAdjustment::no deRespondsToTapGesture, TouchAdjustment::appendBasicSubtargetsForNode); 400 TouchAdjustment::compileSubtargetList(nodes, subtargets, TouchAdjustment::no deRespondsToTapGesture, TouchAdjustment::appendBasicSubtargetsForNode);
487 return TouchAdjustment::findNodeWithLowestDistanceMetric(targetNode, targetP oint, targetArea, touchHotspot, touchArea, subtargets, TouchAdjustment::hybridDi stanceFunction); 401 return TouchAdjustment::findNodeWithLowestDistanceMetric(targetNode, targetP oint, targetArea, touchHotspot, touchArea, subtargets, TouchAdjustment::hybridDi stanceFunction);
488 } 402 }
489 403
490 bool findBestContextMenuCandidate(Node*& targetNode, IntPoint& targetPoint, cons t IntPoint& touchHotspot, const IntRect& touchArea, const WillBeHeapVector<RefPt rWillBeMember<Node> >& nodes)
491 {
492 IntRect targetArea;
493 TouchAdjustment::SubtargetGeometryList subtargets;
494 TouchAdjustment::compileSubtargetList(nodes, subtargets, TouchAdjustment::pr ovidesContextMenuItems, TouchAdjustment::appendContextSubtargetsForNode);
495 return TouchAdjustment::findNodeWithLowestDistanceMetric(targetNode, targetP oint, targetArea, touchHotspot, touchArea, subtargets, TouchAdjustment::hybridDi stanceFunction);
496 }
497
498 bool findBestZoomableArea(Node*& targetNode, IntRect& targetArea, const IntPoint & touchHotspot, const IntRect& touchArea, const WillBeHeapVector<RefPtrWillBeMem ber<Node> >& nodes) 404 bool findBestZoomableArea(Node*& targetNode, IntRect& targetArea, const IntPoint & touchHotspot, const IntRect& touchArea, const WillBeHeapVector<RefPtrWillBeMem ber<Node> >& nodes)
499 { 405 {
500 IntPoint targetPoint; 406 IntPoint targetPoint;
501 TouchAdjustment::SubtargetGeometryList subtargets; 407 TouchAdjustment::SubtargetGeometryList subtargets;
502 TouchAdjustment::compileZoomableSubtargets(nodes, subtargets); 408 TouchAdjustment::compileZoomableSubtargets(nodes, subtargets);
503 return TouchAdjustment::findNodeWithLowestDistanceMetric(targetNode, targetP oint, targetArea, touchHotspot, touchArea, subtargets, TouchAdjustment::zoomable IntersectionQuotient); 409 return TouchAdjustment::findNodeWithLowestDistanceMetric(targetNode, targetP oint, targetArea, touchHotspot, touchArea, subtargets, TouchAdjustment::zoomable IntersectionQuotient);
504 } 410 }
505 411
506 } // namespace blink 412 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/page/TouchAdjustment.h ('k') | sky/engine/core/testing/DummyPageHolder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698