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

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

Issue 2674253004: [refactor] Remove WebWidget::applyReplacementRange (Closed)
Patch Set: more refactoring Created 3 years, 10 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_widget.h" 5 #include "content/renderer/render_widget.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 661
662 return RenderThread::Get()->Send(message); 662 return RenderThread::Get()->Send(message);
663 } 663 }
664 664
665 void RenderWidget::SendOrCrash(IPC::Message* message) { 665 void RenderWidget::SendOrCrash(IPC::Message* message) {
666 bool result = Send(message); 666 bool result = Send(message);
667 CHECK(closing_ || result) << "Failed to send message"; 667 CHECK(closing_ || result) << "Failed to send message";
668 } 668 }
669 669
670 bool RenderWidget::ShouldHandleImeEvents() const { 670 bool RenderWidget::ShouldHandleImeEvents() const {
671 return GetWebWidget()->isWebFrameWidget() && has_focus_; 671 return GetWebWidget() && GetWebWidget()->isWebFrameWidget() && has_focus_;
672 } 672 }
673 673
674 void RenderWidget::SetWindowRectSynchronously( 674 void RenderWidget::SetWindowRectSynchronously(
675 const gfx::Rect& new_window_rect) { 675 const gfx::Rect& new_window_rect) {
676 ResizeParams params; 676 ResizeParams params;
677 params.screen_info = screen_info_; 677 params.screen_info = screen_info_;
678 params.new_size = new_window_rect.size(); 678 params.new_size = new_window_rect.size();
679 params.physical_backing_size = 679 params.physical_backing_size =
680 gfx::ScaleToCeiledSize(new_window_rect.size(), device_scale_factor_); 680 gfx::ScaleToCeiledSize(new_window_rect.size(), device_scale_factor_);
681 params.visible_viewport_size = new_window_rect.size(); 681 params.visible_viewport_size = new_window_rect.size();
(...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after
1548 if (!ShouldHandleImeEvents()) 1548 if (!ShouldHandleImeEvents())
1549 return; 1549 return;
1550 1550
1551 #if BUILDFLAG(ENABLE_PLUGINS) 1551 #if BUILDFLAG(ENABLE_PLUGINS)
1552 if (focused_pepper_plugin_) { 1552 if (focused_pepper_plugin_) {
1553 focused_pepper_plugin_->render_frame()->OnImeSetComposition( 1553 focused_pepper_plugin_->render_frame()->OnImeSetComposition(
1554 text, underlines, selection_start, selection_end); 1554 text, underlines, selection_start, selection_end);
1555 return; 1555 return;
1556 } 1556 }
1557 #endif 1557 #endif
1558 if (replacement_range.IsValid()) {
1559 GetWebWidget()->applyReplacementRange(
1560 WebRange(replacement_range.start(), replacement_range.length()));
1561 }
1562
1563 if (!GetWebWidget())
1564 return;
1565 ImeEventGuard guard(this); 1558 ImeEventGuard guard(this);
1566 blink::WebInputMethodController* controller = GetInputMethodController(); 1559 blink::WebInputMethodController* controller = GetInputMethodController();
1567 if (!controller || 1560 if (!controller ||
1568 !controller->setComposition( 1561 !controller->setComposition(
1569 WebString::fromUTF16(text), 1562 WebString::fromUTF16(text),
1570 WebVector<WebCompositionUnderline>(underlines), selection_start, 1563 WebVector<WebCompositionUnderline>(underlines),
1571 selection_end)) { 1564 replacement_range.IsValid()
1565 ? WebRange(replacement_range.start(), replacement_range.length())
1566 : WebRange(),
1567 selection_start, selection_end)) {
1572 // If we failed to set the composition text, then we need to let the browser 1568 // If we failed to set the composition text, then we need to let the browser
1573 // process to cancel the input method's ongoing composition session, to make 1569 // process to cancel the input method's ongoing composition session, to make
1574 // sure we are in a consistent state. 1570 // sure we are in a consistent state.
1575 Send(new InputHostMsg_ImeCancelComposition(routing_id())); 1571 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
1576 } 1572 }
1577 UpdateCompositionInfo(false /* not an immediate request */); 1573 UpdateCompositionInfo(false /* not an immediate request */);
1578 } 1574 }
1579 1575
1580 void RenderWidget::OnImeCommitText( 1576 void RenderWidget::OnImeCommitText(
1581 const base::string16& text, 1577 const base::string16& text,
1582 const std::vector<WebCompositionUnderline>& underlines, 1578 const std::vector<WebCompositionUnderline>& underlines,
1583 const gfx::Range& replacement_range, 1579 const gfx::Range& replacement_range,
1584 int relative_cursor_pos) { 1580 int relative_cursor_pos) {
1585 if (!ShouldHandleImeEvents()) 1581 if (!ShouldHandleImeEvents())
1586 return; 1582 return;
1587 1583
1588 #if BUILDFLAG(ENABLE_PLUGINS) 1584 #if BUILDFLAG(ENABLE_PLUGINS)
1589 if (focused_pepper_plugin_) { 1585 if (focused_pepper_plugin_) {
1590 focused_pepper_plugin_->render_frame()->OnImeCommitText( 1586 focused_pepper_plugin_->render_frame()->OnImeCommitText(
1591 text, replacement_range, relative_cursor_pos); 1587 text, replacement_range, relative_cursor_pos);
1592 return; 1588 return;
1593 } 1589 }
1594 #endif 1590 #endif
1595 if (replacement_range.IsValid()) {
1596 GetWebWidget()->applyReplacementRange(
1597 WebRange(replacement_range.start(), replacement_range.length()));
1598 }
1599
1600 if (!GetWebWidget())
1601 return;
1602 ImeEventGuard guard(this); 1591 ImeEventGuard guard(this);
1603 input_handler_->set_handling_input_event(true); 1592 input_handler_->set_handling_input_event(true);
1604 if (auto* controller = GetInputMethodController()) 1593 if (auto* controller = GetInputMethodController())
1605 controller->commitText(WebString::fromUTF16(text), 1594 controller->commitText(
1606 WebVector<WebCompositionUnderline>(underlines), 1595 WebString::fromUTF16(text),
1607 relative_cursor_pos); 1596 WebVector<WebCompositionUnderline>(underlines),
1597 replacement_range.IsValid()
1598 ? WebRange(replacement_range.start(), replacement_range.length())
1599 : WebRange(),
1600 relative_cursor_pos);
1608 input_handler_->set_handling_input_event(false); 1601 input_handler_->set_handling_input_event(false);
1609 UpdateCompositionInfo(false /* not an immediate request */); 1602 UpdateCompositionInfo(false /* not an immediate request */);
1610 } 1603 }
1611 1604
1612 void RenderWidget::OnImeFinishComposingText(bool keep_selection) { 1605 void RenderWidget::OnImeFinishComposingText(bool keep_selection) {
1613 if (!ShouldHandleImeEvents()) 1606 if (!ShouldHandleImeEvents())
1614 return; 1607 return;
1615 1608
1616 #if BUILDFLAG(ENABLE_PLUGINS) 1609 #if BUILDFLAG(ENABLE_PLUGINS)
1617 if (focused_pepper_plugin_) { 1610 if (focused_pepper_plugin_) {
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after
2290 // browser side (https://crbug.com/669219). 2283 // browser side (https://crbug.com/669219).
2291 // If there is no WebFrameWidget, then there will be no 2284 // If there is no WebFrameWidget, then there will be no
2292 // InputMethodControllers for a WebLocalFrame. 2285 // InputMethodControllers for a WebLocalFrame.
2293 return nullptr; 2286 return nullptr;
2294 } 2287 }
2295 return static_cast<blink::WebFrameWidget*>(GetWebWidget()) 2288 return static_cast<blink::WebFrameWidget*>(GetWebWidget())
2296 ->getActiveWebInputMethodController(); 2289 ->getActiveWebInputMethodController();
2297 } 2290 }
2298 2291
2299 } // namespace content 2292 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698