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

Side by Side Diff: content/renderer/render_frame_impl.cc

Issue 2199523002: Convert WebRange to be a simple pair of numbers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Forgot the exports. Created 4 years, 4 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 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/render_frame_impl.h" 5 #include "content/renderer/render_frame_impl.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 1862 matching lines...) Expand 10 before | Expand all | Expand 10 after
1873 return; 1873 return;
1874 } 1874 }
1875 1875
1876 // A negative adjust amount moves the selection towards the beginning of 1876 // A negative adjust amount moves the selection towards the beginning of
1877 // the document, a positive amount moves the selection towards the end of 1877 // the document, a positive amount moves the selection towards the end of
1878 // the document. 1878 // the document.
1879 start += start_adjust; 1879 start += start_adjust;
1880 length += end_adjust - start_adjust; 1880 length += end_adjust - start_adjust;
1881 1881
1882 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); 1882 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
1883 frame_->selectRange(WebRange::fromDocumentRange(frame_, start, length)); 1883 frame_->selectRange(WebRange(start, length));
1884 } 1884 }
1885 1885
1886 void RenderFrameImpl::OnUnselect() { 1886 void RenderFrameImpl::OnUnselect() {
1887 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); 1887 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
1888 frame_->executeCommand(WebString::fromUTF8("Unselect")); 1888 frame_->executeCommand(WebString::fromUTF8("Unselect"));
1889 } 1889 }
1890 1890
1891 void RenderFrameImpl::OnMoveRangeSelectionExtent(const gfx::Point& point) { 1891 void RenderFrameImpl::OnMoveRangeSelectionExtent(const gfx::Point& point) {
1892 // This IPC is dispatched by RenderWidgetHost, so use its routing id. 1892 // This IPC is dispatched by RenderWidgetHost, so use its routing id.
1893 Send(new InputHostMsg_MoveRangeSelectionExtent_ACK( 1893 Send(new InputHostMsg_MoveRangeSelectionExtent_ACK(
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
2241 : WebFrameLoadType::Reload); 2241 : WebFrameLoadType::Reload);
2242 } 2242 }
2243 2243
2244 void RenderFrameImpl::OnReloadLoFiImages() { 2244 void RenderFrameImpl::OnReloadLoFiImages() {
2245 is_using_lofi_ = false; 2245 is_using_lofi_ = false;
2246 GetWebFrame()->reloadLoFiImages(); 2246 GetWebFrame()->reloadLoFiImages();
2247 } 2247 }
2248 2248
2249 void RenderFrameImpl::OnTextSurroundingSelectionRequest(uint32_t max_length) { 2249 void RenderFrameImpl::OnTextSurroundingSelectionRequest(uint32_t max_length) {
2250 blink::WebSurroundingText surroundingText; 2250 blink::WebSurroundingText surroundingText;
2251 surroundingText.initialize(frame_->selectionRange(), max_length); 2251 surroundingText.initializeFromCurrentSelection(frame_, max_length);
2252 2252
2253 if (surroundingText.isNull()) { 2253 if (surroundingText.isNull()) {
2254 // |surroundingText| might not be correctly initialized, for example if 2254 // |surroundingText| might not be correctly initialized, for example if
2255 // |frame_->selectionRange().isNull()|, in other words, if there was no 2255 // |frame_->selectionRange().isNull()|, in other words, if there was no
2256 // selection. 2256 // selection.
2257 Send(new FrameHostMsg_TextSurroundingSelectionResponse( 2257 Send(new FrameHostMsg_TextSurroundingSelectionResponse(
2258 routing_id_, base::string16(), 0, 0)); 2258 routing_id_, base::string16(), 0, 0));
2259 return; 2259 return;
2260 } 2260 }
2261 2261
(...skipping 3410 matching lines...) Expand 10 before | Expand all | Expand 10 after
5672 if (GetRenderWidget()->webwidget()->textInputType() != 5672 if (GetRenderWidget()->webwidget()->textInputType() !=
5673 blink::WebTextInputTypeNone) { 5673 blink::WebTextInputTypeNone) {
5674 // If current focused element is editable, we will send 100 more chars 5674 // If current focused element is editable, we will send 100 more chars
5675 // before and after selection. It is for input method surrounding text 5675 // before and after selection. It is for input method surrounding text
5676 // feature. 5676 // feature.
5677 if (location > kExtraCharsBeforeAndAfterSelection) 5677 if (location > kExtraCharsBeforeAndAfterSelection)
5678 offset = location - kExtraCharsBeforeAndAfterSelection; 5678 offset = location - kExtraCharsBeforeAndAfterSelection;
5679 else 5679 else
5680 offset = 0; 5680 offset = 0;
5681 length = location + length - offset + kExtraCharsBeforeAndAfterSelection; 5681 length = location + length - offset + kExtraCharsBeforeAndAfterSelection;
5682 WebRange webrange = WebRange::fromDocumentRange(frame_, offset, length); 5682 text = frame_->rangeAsText(WebRange(offset, length));
5683 if (!webrange.isNull())
5684 text = webrange.toPlainText();
5685 } else { 5683 } else {
5686 offset = location; 5684 offset = location;
5687 text = frame_->selectionAsText(); 5685 text = frame_->selectionAsText();
5688 // http://crbug.com/101435 5686 // http://crbug.com/101435
5689 // In some case, frame->selectionAsText() returned text's length is not 5687 // In some case, frame->selectionAsText() returned text's length is not
5690 // equal to the length returned from webwidget()->caretOrSelectionRange(). 5688 // equal to the length returned from webwidget()->caretOrSelectionRange().
5691 // So we have to set the range according to text.length(). 5689 // So we have to set the range according to text.length().
5692 range.set_end(range.start() + text.length()); 5690 range.set_end(range.start() + text.length());
5693 } 5691 }
5694 } 5692 }
5695 5693
5694 // TODO(dglazkov): Investigate if and why this would be happening,
5695 // and resolve this. We shouldn't be carrying selection text here.
5696 // http://crbug.com/632920.
5696 // Sometimes we get repeated didChangeSelection calls from webkit when 5697 // Sometimes we get repeated didChangeSelection calls from webkit when
5697 // the selection hasn't actually changed. We don't want to report these 5698 // the selection hasn't actually changed. We don't want to report these
5698 // because it will cause us to continually claim the X clipboard. 5699 // because it will cause us to continually claim the X clipboard.
5699 if (selection_text_offset_ != offset || 5700 if (selection_text_offset_ != offset ||
5700 selection_range_ != range || 5701 selection_range_ != range ||
5701 selection_text_ != text) { 5702 selection_text_ != text) {
5702 selection_text_ = text; 5703 selection_text_ = text;
5703 selection_text_offset_ = offset; 5704 selection_text_offset_ = offset;
5704 selection_range_ = range; 5705 selection_range_ = range;
5705 SetSelectedText(text, offset, range); 5706 SetSelectedText(text, offset, range);
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
6330 // event target. Potentially a Pepper plugin will receive the event. 6331 // event target. Potentially a Pepper plugin will receive the event.
6331 // In order to tell whether a plugin gets the last mouse event and which it 6332 // In order to tell whether a plugin gets the last mouse event and which it
6332 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets 6333 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets
6333 // the event, it will notify us via DidReceiveMouseEvent() and set itself as 6334 // the event, it will notify us via DidReceiveMouseEvent() and set itself as
6334 // |pepper_last_mouse_event_target_|. 6335 // |pepper_last_mouse_event_target_|.
6335 pepper_last_mouse_event_target_ = nullptr; 6336 pepper_last_mouse_event_target_ = nullptr;
6336 #endif 6337 #endif
6337 } 6338 }
6338 6339
6339 } // namespace content 6340 } // namespace content
OLDNEW
« no previous file with comments | « components/printing/test/print_web_view_helper_browsertest.cc ('k') | content/renderer/render_view_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698