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

Side by Side Diff: third_party/WebKit/Source/web/WebFrameWidgetImpl.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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 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 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 LocalFrame* focused = focusedLocalFrameAvailableForIme(); 562 LocalFrame* focused = focusedLocalFrameAvailableForIme();
563 if (!focused) 563 if (!focused)
564 return false; 564 return false;
565 565
566 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused)) 566 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused))
567 return plugin->confirmComposition(text, selectionBehavior); 567 return plugin->confirmComposition(text, selectionBehavior);
568 568
569 return focused->inputMethodController().confirmCompositionOrInsertText(text, selectionBehavior == KeepSelection ? InputMethodController::KeepSelection : Inp utMethodController::DoNotKeepSelection); 569 return focused->inputMethodController().confirmCompositionOrInsertText(text, selectionBehavior == KeepSelection ? InputMethodController::KeepSelection : Inp utMethodController::DoNotKeepSelection);
570 } 570 }
571 571
572 bool WebFrameWidgetImpl::compositionRange(size_t* location, size_t* length) 572 WebRange WebFrameWidgetImpl::compositionRange()
573 { 573 {
574 LocalFrame* focused = focusedLocalFrameAvailableForIme(); 574 LocalFrame* focused = focusedLocalFrameAvailableForIme();
575 if (!focused) 575 if (!focused)
576 return false; 576 return WebRange();
577 577
578 const EphemeralRange range = focused->inputMethodController().compositionEph emeralRange(); 578 const EphemeralRange range = focused->inputMethodController().compositionEph emeralRange();
579 if (range.isNull()) 579 if (range.isNull())
580 return false; 580 return WebRange();
581 581
582 Element* editable = focused->selection().rootEditableElementOrDocumentElemen t(); 582 Element* editable = focused->selection().rootEditableElementOrDocumentElemen t();
583 DCHECK(editable); 583 DCHECK(editable);
584 PlainTextRange plainTextRange(PlainTextRange::create(*editable, range)); 584 return PlainTextRange::create(*editable, range);
585 if (plainTextRange.isNull())
586 return false;
587 *location = plainTextRange.start();
588 *length = plainTextRange.length();
589 return true;
590 } 585 }
591 586
592 WebTextInputInfo WebFrameWidgetImpl::textInputInfo() 587 WebTextInputInfo WebFrameWidgetImpl::textInputInfo()
593 { 588 {
594 WebTextInputInfo info; 589 WebTextInputInfo info;
595 590
596 LocalFrame* focused = focusedLocalFrameInWidget(); 591 LocalFrame* focused = focusedLocalFrameInWidget();
597 if (!focused) 592 if (!focused)
598 return info; 593 return info;
599 594
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 page()->pointerLockController().didNotAcquirePointerLock(); 841 page()->pointerLockController().didNotAcquirePointerLock();
847 } 842 }
848 843
849 void WebFrameWidgetImpl::didLosePointerLock() 844 void WebFrameWidgetImpl::didLosePointerLock()
850 { 845 {
851 page()->pointerLockController().didLosePointerLock(); 846 page()->pointerLockController().didLosePointerLock();
852 } 847 }
853 848
854 bool WebFrameWidgetImpl::getCompositionCharacterBounds(WebVector<WebRect>& bound s) 849 bool WebFrameWidgetImpl::getCompositionCharacterBounds(WebVector<WebRect>& bound s)
855 { 850 {
856 size_t offset = 0; 851 WebRange range = compositionRange();
857 size_t characterCount = 0; 852 if (range.isNull())
858 if (!compositionRange(&offset, &characterCount))
859 return false; 853 return false;
860 854
861 if (characterCount == 0) 855 if (range.length() == 0)
862 return false; 856 return false;
863 857
864 LocalFrame* frame = focusedLocalFrameInWidget(); 858 LocalFrame* frame = focusedLocalFrameInWidget();
865 if (!frame) 859 if (!frame)
866 return false; 860 return false;
867 861
868 WebLocalFrameImpl* webLocalFrame = WebLocalFrameImpl::fromFrame(frame); 862 WebLocalFrameImpl* webLocalFrame = WebLocalFrameImpl::fromFrame(frame);
863 size_t characterCount = range.length();
864 size_t offset = range.startOffset();
869 WebVector<WebRect> result(characterCount); 865 WebVector<WebRect> result(characterCount);
870 WebRect webrect; 866 WebRect webrect;
871 for (size_t i = 0; i < characterCount; ++i) { 867 for (size_t i = 0; i < characterCount; ++i) {
872 if (!webLocalFrame->firstRectForCharacterRange(offset + i, 1, webrect)) { 868 if (!webLocalFrame->firstRectForCharacterRange(offset + i, 1, webrect)) {
873 DLOG(ERROR) << "Could not retrieve character rectangle at " << i; 869 DLOG(ERROR) << "Could not retrieve character rectangle at " << i;
874 return false; 870 return false;
875 } 871 }
876 result[i] = webrect; 872 result[i] = webrect;
877 } 873 }
874
878 bounds.swap(result); 875 bounds.swap(result);
879 return true; 876 return true;
880 } 877 }
881 878
882 void WebFrameWidgetImpl::applyReplacementRange(int start, int length) 879 void WebFrameWidgetImpl::applyReplacementRange(int start, int length)
883 { 880 {
884 if (LocalFrame* frame = focusedLocalFrameInWidget()) { 881 if (LocalFrame* frame = focusedLocalFrameInWidget()) {
885 // TODO(dglazkov): Going from LocalFrame to WebLocalFrameImpl seems 882 // TODO(dglazkov): Going from LocalFrame to WebLocalFrameImpl seems
886 // silly. What is going on here? 883 // silly. What is going on here?
887 WebLocalFrameImpl::fromFrame(frame)->selectRange(WebRange(start, length) ); 884 WebLocalFrameImpl::fromFrame(frame)->selectRange(WebRange(start, length) );
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
1438 } 1435 }
1439 1436
1440 LocalFrame* WebFrameWidgetImpl::focusedLocalFrameAvailableForIme() const 1437 LocalFrame* WebFrameWidgetImpl::focusedLocalFrameAvailableForIme() const
1441 { 1438 {
1442 if (!m_imeAcceptEvents) 1439 if (!m_imeAcceptEvents)
1443 return nullptr; 1440 return nullptr;
1444 return focusedLocalFrameInWidget(); 1441 return focusedLocalFrameInWidget();
1445 } 1442 }
1446 1443
1447 } // namespace blink 1444 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698