Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 #include "Console.h" | 78 #include "Console.h" |
| 79 #include "DOMUtilitiesPrivate.h" | 79 #include "DOMUtilitiesPrivate.h" |
| 80 #include "DOMWindow.h" | 80 #include "DOMWindow.h" |
| 81 #include "Document.h" | 81 #include "Document.h" |
| 82 #include "DocumentFragment.h" // Only needed for ReplaceSelectionCommand.h :( | 82 #include "DocumentFragment.h" // Only needed for ReplaceSelectionCommand.h :( |
| 83 #include "DocumentLoader.h" | 83 #include "DocumentLoader.h" |
| 84 #include "DocumentMarker.h" | 84 #include "DocumentMarker.h" |
| 85 #include "DocumentMarkerController.h" | 85 #include "DocumentMarkerController.h" |
| 86 #include "Editor.h" | 86 #include "Editor.h" |
| 87 #include "EventHandler.h" | 87 #include "EventHandler.h" |
| 88 #include "FocusController.h" | |
| 88 #include "FormState.h" | 89 #include "FormState.h" |
| 89 #include "FrameLoadRequest.h" | 90 #include "FrameLoadRequest.h" |
| 90 #include "FrameLoader.h" | 91 #include "FrameLoader.h" |
| 91 #include "FrameTree.h" | 92 #include "FrameTree.h" |
| 92 #include "FrameView.h" | 93 #include "FrameView.h" |
| 93 #include "HTMLCollection.h" | 94 #include "HTMLCollection.h" |
| 94 #include "HTMLFormElement.h" | 95 #include "HTMLFormElement.h" |
| 95 #include "HTMLFrameOwnerElement.h" | 96 #include "HTMLFrameOwnerElement.h" |
| 96 #include "HTMLHeadElement.h" | 97 #include "HTMLHeadElement.h" |
| 97 #include "HTMLInputElement.h" | 98 #include "HTMLInputElement.h" |
| 98 #include "HTMLLinkElement.h" | 99 #include "HTMLLinkElement.h" |
| 99 #include "HTMLNames.h" | 100 #include "HTMLNames.h" |
| 100 #include "HistoryItem.h" | 101 #include "HistoryItem.h" |
| 102 #include "HitTestResult.h" | |
| 101 #include "InspectorController.h" | 103 #include "InspectorController.h" |
| 102 #include "Page.h" | 104 #include "Page.h" |
| 103 #include "painting/GraphicsContextBuilder.h" | 105 #include "painting/GraphicsContextBuilder.h" |
| 104 #include "Performance.h" | 106 #include "Performance.h" |
| 105 #include "PlatformBridge.h" | 107 #include "PlatformBridge.h" |
| 106 #include "PluginDocument.h" | 108 #include "PluginDocument.h" |
| 107 #include "PrintContext.h" | 109 #include "PrintContext.h" |
| 108 #include "RenderFrame.h" | 110 #include "RenderFrame.h" |
| 109 #include "RenderObject.h" | 111 #include "RenderObject.h" |
| 110 #include "RenderTreeAsText.h" | 112 #include "RenderTreeAsText.h" |
| (...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1105 if ((location + length < location) && (location + length)) | 1107 if ((location + length < location) && (location + length)) |
| 1106 length = 0; | 1108 length = 0; |
| 1107 | 1109 |
| 1108 Element* selectionRoot = frame()->selection()->rootEditableElement(); | 1110 Element* selectionRoot = frame()->selection()->rootEditableElement(); |
| 1109 Element* scope = selectionRoot ? selectionRoot : frame()->document()->docume ntElement(); | 1111 Element* scope = selectionRoot ? selectionRoot : frame()->document()->docume ntElement(); |
| 1110 RefPtr<Range> range = TextIterator::rangeFromLocationAndLength(scope, locati on, length); | 1112 RefPtr<Range> range = TextIterator::rangeFromLocationAndLength(scope, locati on, length); |
| 1111 if (!range) | 1113 if (!range) |
| 1112 return false; | 1114 return false; |
| 1113 IntRect intRect = frame()->editor()->firstRectForRange(range.get()); | 1115 IntRect intRect = frame()->editor()->firstRectForRange(range.get()); |
| 1114 rect = WebRect(intRect.x(), intRect.y(), intRect.width(), intRect.height()); | 1116 rect = WebRect(intRect.x(), intRect.y(), intRect.width(), intRect.height()); |
| 1117 // When inside an text control, don't adjust the range. | |
| 1118 if (!selectionRoot) | |
| 1119 rect = frame()->view()->contentsToWindow(rect); | |
|
James Su
2011/03/03 04:08:03
IMHO, we should return frame based position in Web
Robert Sesek
2011/03/18 21:33:36
Why? That seems unnecessary and makes this CL more
| |
| 1115 | 1120 |
| 1116 return true; | 1121 return true; |
| 1117 } | 1122 } |
| 1118 | 1123 |
| 1124 unsigned WebFrameImpl::characterIndexForPoint(const WebPoint& webPoint) const | |
| 1125 { | |
| 1126 if (!frame()) | |
| 1127 return notFound; | |
| 1128 | |
| 1129 IntPoint point = frame()->view()->windowToContents(webPoint); | |
|
James Su
2011/03/03 04:08:03
Same as above.
| |
| 1130 HitTestResult result = frame()->eventHandler()->hitTestResultAtPoint(point, false); | |
| 1131 Range* range = characterRangeAtPoint(result.point()); | |
| 1132 if (!range) | |
| 1133 return notFound; | |
| 1134 | |
| 1135 unsigned location, length; | |
| 1136 getLocationAndLengthFromRange(range, location, length); | |
| 1137 return location; | |
| 1138 } | |
| 1139 | |
| 1119 bool WebFrameImpl::executeCommand(const WebString& name) | 1140 bool WebFrameImpl::executeCommand(const WebString& name) |
| 1120 { | 1141 { |
| 1121 ASSERT(frame()); | 1142 ASSERT(frame()); |
| 1122 | 1143 |
| 1123 if (name.length() <= 2) | 1144 if (name.length() <= 2) |
| 1124 return false; | 1145 return false; |
| 1125 | 1146 |
| 1126 // Since we don't have NSControl, we will convert the format of command | 1147 // Since we don't have NSControl, we will convert the format of command |
| 1127 // string and call the function on Editor directly. | 1148 // string and call the function on Editor directly. |
| 1128 String command = name; | 1149 String command = name; |
| (...skipping 1138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2267 ScriptValue result = m_frame->script()->executeScript(script, true); | 2288 ScriptValue result = m_frame->script()->executeScript(script, true); |
| 2268 | 2289 |
| 2269 String scriptResult; | 2290 String scriptResult; |
| 2270 if (!result.getString(scriptResult)) | 2291 if (!result.getString(scriptResult)) |
| 2271 return; | 2292 return; |
| 2272 | 2293 |
| 2273 if (!m_frame->navigationScheduler()->locationChangePending()) | 2294 if (!m_frame->navigationScheduler()->locationChangePending()) |
| 2274 m_frame->document()->loader()->writer()->replaceDocument(scriptResult); | 2295 m_frame->document()->loader()->writer()->replaceDocument(scriptResult); |
| 2275 } | 2296 } |
| 2276 | 2297 |
| 2298 // This function is copied from /WebKit2/WebPage/mac/WebPageMac.mm. | |
| 2299 Range* WebFrameImpl::characterRangeAtPoint(const IntPoint& point) const | |
| 2300 { | |
| 2301 VisiblePosition position = frame()->visiblePositionForPoint(point); | |
| 2302 if (position.isNull()) | |
| 2303 return NULL; | |
| 2304 | |
| 2305 VisiblePosition previous = position.previous(); | |
| 2306 if (previous.isNotNull()) { | |
| 2307 Range* previousCharacterRange = makeRange(previous, position).get(); | |
| 2308 IntRect rect = frame()->editor()->firstRectForRange(previousCharacterRan ge); | |
| 2309 if (rect.contains(point)) | |
| 2310 return previousCharacterRange; | |
| 2311 } | |
| 2312 | |
| 2313 VisiblePosition next = position.next(); | |
| 2314 if (next.isNotNull()) { | |
| 2315 Range* nextCharacterRange = makeRange(position, next).get(); | |
| 2316 IntRect rect = frame()->editor()->firstRectForRange(nextCharacterRange); | |
| 2317 if (rect.contains(point)) | |
| 2318 return nextCharacterRange; | |
| 2319 } | |
| 2320 | |
| 2321 return NULL; | |
| 2322 } | |
| 2323 | |
| 2324 // This function is copied from /WebKit2/WebPage/WebPage.cpp. | |
| 2325 bool WebFrameImpl::getLocationAndLengthFromRange(Range* range, unsigned& locatio n, unsigned& length) const | |
| 2326 { | |
| 2327 location = notFound; | |
| 2328 length = 0; | |
| 2329 | |
| 2330 if (!range || !range->startContainer()) | |
| 2331 return false; | |
| 2332 | |
| 2333 Element* selectionRoot = range->ownerDocument()->frame()->selection()->rootE ditableElement(); | |
| 2334 Element* scope = selectionRoot ? selectionRoot : range->ownerDocument()->doc umentElement(); | |
| 2335 | |
| 2336 // Mouse events may cause TSM to attempt to create an NSRange for a portion of the view | |
| 2337 // that is not inside the current editable region. These checks ensure we d on't produce | |
| 2338 // potentially invalid data when responding to such requests. | |
| 2339 if (range->startContainer() != scope && !range->startContainer()->isDescenda ntOf(scope)) | |
| 2340 return false; | |
| 2341 if (range->endContainer() != scope && !range->endContainer()->isDescendantOf (scope)) | |
| 2342 return false; | |
| 2343 | |
| 2344 RefPtr<Range> testRange = Range::create(scope->document(), scope, 0, range-> startContainer(), range->startOffset()); | |
| 2345 ASSERT(testRange->startContainer() == scope); | |
| 2346 location = TextIterator::rangeLength(testRange.get()); | |
| 2347 | |
| 2348 ExceptionCode ec; | |
| 2349 testRange->setEnd(range->endContainer(), range->endOffset(), ec); | |
| 2350 ASSERT(testRange->startContainer() == scope); | |
| 2351 length = TextIterator::rangeLength(testRange.get()) - location; | |
| 2352 return true; | |
| 2353 } | |
| 2354 | |
| 2277 } // namespace WebKit | 2355 } // namespace WebKit |
| OLD | NEW |