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

Side by Side Diff: third_party/WebKit/Source/web/WebViewImpl.cpp

Issue 2306643003: WebRange-ify WebWidget::compositionRange. (Closed)
Patch Set: Created 4 years, 3 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
« no previous file with comments | « third_party/WebKit/Source/web/WebViewImpl.h ('k') | third_party/WebKit/public/web/WebWidget.h » ('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) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 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 2369 matching lines...) Expand 10 before | Expand all | Expand 10 after
2380 LocalFrame* focused = focusedLocalFrameAvailableForIme(); 2380 LocalFrame* focused = focusedLocalFrameAvailableForIme();
2381 if (!focused) 2381 if (!focused)
2382 return false; 2382 return false;
2383 2383
2384 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused)) 2384 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused))
2385 return plugin->confirmComposition(text, selectionBehavior); 2385 return plugin->confirmComposition(text, selectionBehavior);
2386 2386
2387 return focused->inputMethodController().confirmCompositionOrInsertText(text, selectionBehavior == KeepSelection ? InputMethodController::KeepSelection : Inp utMethodController::DoNotKeepSelection); 2387 return focused->inputMethodController().confirmCompositionOrInsertText(text, selectionBehavior == KeepSelection ? InputMethodController::KeepSelection : Inp utMethodController::DoNotKeepSelection);
2388 } 2388 }
2389 2389
2390 bool WebViewImpl::compositionRange(size_t* location, size_t* length) 2390 WebRange WebViewImpl::compositionRange()
2391 { 2391 {
2392 LocalFrame* focused = focusedLocalFrameAvailableForIme(); 2392 LocalFrame* focused = focusedLocalFrameAvailableForIme();
2393 if (!focused) 2393 if (!focused)
2394 return false; 2394 return WebRange();
2395 2395
2396 const EphemeralRange range = focused->inputMethodController().compositionEph emeralRange(); 2396 const EphemeralRange range = focused->inputMethodController().compositionEph emeralRange();
2397 if (range.isNull()) 2397 if (range.isNull())
2398 return false; 2398 return WebRange();
2399 2399
2400 Element* editable = focused->selection().rootEditableElementOrDocumentElemen t(); 2400 Element* editable = focused->selection().rootEditableElementOrDocumentElemen t();
2401 DCHECK(editable); 2401 DCHECK(editable);
2402 PlainTextRange plainTextRange(PlainTextRange::create(*editable, range)); 2402 return PlainTextRange::create(*editable, range);
2403 if (plainTextRange.isNull())
2404 return false;
2405 *location = plainTextRange.start();
2406 *length = plainTextRange.length();
2407 return true;
2408 } 2403 }
2409 2404
2410 WebTextInputInfo WebViewImpl::textInputInfo() 2405 WebTextInputInfo WebViewImpl::textInputInfo()
2411 { 2406 {
2412 WebTextInputInfo info; 2407 WebTextInputInfo info;
2413 2408
2414 LocalFrame* focused = focusedLocalFrameInWidget(); 2409 LocalFrame* focused = focusedLocalFrameInWidget();
2415 if (!focused) 2410 if (!focused)
2416 return info; 2411 return info;
2417 2412
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
2805 } 2800 }
2806 2801
2807 void WebViewImpl::didChangeWindowResizerRect() 2802 void WebViewImpl::didChangeWindowResizerRect()
2808 { 2803 {
2809 if (mainFrameImpl()->frameView()) 2804 if (mainFrameImpl()->frameView())
2810 mainFrameImpl()->frameView()->windowResizerRectChanged(); 2805 mainFrameImpl()->frameView()->windowResizerRectChanged();
2811 } 2806 }
2812 2807
2813 bool WebViewImpl::getCompositionCharacterBounds(WebVector<WebRect>& bounds) 2808 bool WebViewImpl::getCompositionCharacterBounds(WebVector<WebRect>& bounds)
2814 { 2809 {
2815 size_t offset = 0; 2810 WebRange range = compositionRange();
2816 size_t characterCount = 0; 2811 if (range.isNull())
2817 if (!compositionRange(&offset, &characterCount))
2818 return false; 2812 return false;
2819 2813
2820 if (characterCount == 0) 2814 if (range.length() == 0)
esprehn 2016/09/02 21:24:34 isEmpty() would be idiomatic.
2821 return false; 2815 return false;
2822 2816
2823 WebLocalFrame* frame = focusedFrame(); 2817 WebLocalFrame* frame = focusedFrame();
2824 2818
2825 // Only consider frames whose local root is the main frame. For other 2819 // Only consider frames whose local root is the main frame. For other
2826 // local frames which have different local roots, the corresponding 2820 // local frames which have different local roots, the corresponding
2827 // WebFrameWidget will handle this task. 2821 // WebFrameWidget will handle this task.
2828 if (frame->localRoot() != mainFrameImpl()) 2822 if (frame->localRoot() != mainFrameImpl())
2829 return false; 2823 return false;
2830 2824
2825 size_t characterCount = range.length();
2826 size_t offset = range.startOffset();
2831 WebVector<WebRect> result(characterCount); 2827 WebVector<WebRect> result(characterCount);
2832 WebRect webrect; 2828 WebRect webrect;
2833 for (size_t i = 0; i < characterCount; ++i) { 2829 for (size_t i = 0; i < characterCount; ++i) {
2834 if (!frame->firstRectForCharacterRange(offset + i, 1, webrect)) { 2830 if (!frame->firstRectForCharacterRange(offset + i, 1, webrect)) {
2835 DLOG(ERROR) << "Could not retrieve character rectangle at " << i; 2831 DLOG(ERROR) << "Could not retrieve character rectangle at " << i;
2836 return false; 2832 return false;
2837 } 2833 }
2838 result[i] = webrect; 2834 result[i] = webrect;
2839 } 2835 }
2840 bounds.swap(result); 2836 bounds.swap(result);
(...skipping 1757 matching lines...) Expand 10 before | Expand all | Expand 10 after
4598 return nullptr; 4594 return nullptr;
4599 return focusedFrame; 4595 return focusedFrame;
4600 } 4596 }
4601 4597
4602 LocalFrame* WebViewImpl::focusedLocalFrameAvailableForIme() const 4598 LocalFrame* WebViewImpl::focusedLocalFrameAvailableForIme() const
4603 { 4599 {
4604 return m_imeAcceptEvents ? focusedLocalFrameInWidget() : nullptr; 4600 return m_imeAcceptEvents ? focusedLocalFrameInWidget() : nullptr;
4605 } 4601 }
4606 4602
4607 } // namespace blink 4603 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/WebViewImpl.h ('k') | third_party/WebKit/public/web/WebWidget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698