OLD | NEW |
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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 #include "third_party/WebKit/public/platform/scheduler/renderer/renderer_schedul
er.h" | 79 #include "third_party/WebKit/public/platform/scheduler/renderer/renderer_schedul
er.h" |
80 #include "third_party/WebKit/public/web/WebDeviceEmulationParams.h" | 80 #include "third_party/WebKit/public/web/WebDeviceEmulationParams.h" |
81 #include "third_party/WebKit/public/web/WebFrameWidget.h" | 81 #include "third_party/WebKit/public/web/WebFrameWidget.h" |
82 #include "third_party/WebKit/public/web/WebInputMethodController.h" | 82 #include "third_party/WebKit/public/web/WebInputMethodController.h" |
83 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 83 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
84 #include "third_party/WebKit/public/web/WebNode.h" | 84 #include "third_party/WebKit/public/web/WebNode.h" |
85 #include "third_party/WebKit/public/web/WebPagePopup.h" | 85 #include "third_party/WebKit/public/web/WebPagePopup.h" |
86 #include "third_party/WebKit/public/web/WebPopupMenuInfo.h" | 86 #include "third_party/WebKit/public/web/WebPopupMenuInfo.h" |
87 #include "third_party/WebKit/public/web/WebRange.h" | 87 #include "third_party/WebKit/public/web/WebRange.h" |
88 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 88 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
| 89 #include "third_party/WebKit/public/web/WebTextSuggestionController.h" |
89 #include "third_party/WebKit/public/web/WebView.h" | 90 #include "third_party/WebKit/public/web/WebView.h" |
90 #include "third_party/WebKit/public/web/WebWidget.h" | 91 #include "third_party/WebKit/public/web/WebWidget.h" |
91 #include "third_party/skia/include/core/SkShader.h" | 92 #include "third_party/skia/include/core/SkShader.h" |
92 #include "ui/base/clipboard/clipboard.h" | 93 #include "ui/base/clipboard/clipboard.h" |
93 #include "ui/base/ui_base_switches.h" | 94 #include "ui/base/ui_base_switches.h" |
94 #include "ui/events/base_event_utils.h" | 95 #include "ui/events/base_event_utils.h" |
95 #include "ui/gfx/geometry/point_conversions.h" | 96 #include "ui/gfx/geometry/point_conversions.h" |
96 #include "ui/gfx/geometry/rect_conversions.h" | 97 #include "ui/gfx/geometry/rect_conversions.h" |
97 #include "ui/gfx/geometry/size_conversions.h" | 98 #include "ui/gfx/geometry/size_conversions.h" |
98 #include "ui/gfx/skia_util.h" | 99 #include "ui/gfx/skia_util.h" |
(...skipping 1486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1585 WebVector<WebCompositionUnderline>(underlines), | 1586 WebVector<WebCompositionUnderline>(underlines), |
1586 replacement_range.IsValid() | 1587 replacement_range.IsValid() |
1587 ? WebRange(replacement_range.start(), replacement_range.length()) | 1588 ? WebRange(replacement_range.start(), replacement_range.length()) |
1588 : WebRange(), | 1589 : WebRange(), |
1589 selection_start, selection_end)) { | 1590 selection_start, selection_end)) { |
1590 // If we failed to set the composition text, then we need to let the browser | 1591 // If we failed to set the composition text, then we need to let the browser |
1591 // process to cancel the input method's ongoing composition session, to make | 1592 // process to cancel the input method's ongoing composition session, to make |
1592 // sure we are in a consistent state. | 1593 // sure we are in a consistent state. |
1593 Send(new InputHostMsg_ImeCancelComposition(routing_id())); | 1594 Send(new InputHostMsg_ImeCancelComposition(routing_id())); |
1594 } | 1595 } |
1595 UpdateCompositionInfo(false /* not an immediate request */); | 1596 updateCompositionInfo(false /* not an immediate request */); |
1596 } | 1597 } |
1597 | 1598 |
1598 void RenderWidget::OnImeCommitText( | 1599 void RenderWidget::OnImeCommitText( |
1599 const base::string16& text, | 1600 const base::string16& text, |
1600 const std::vector<WebCompositionUnderline>& underlines, | 1601 const std::vector<WebCompositionUnderline>& underlines, |
1601 const gfx::Range& replacement_range, | 1602 const gfx::Range& replacement_range, |
1602 int relative_cursor_pos) { | 1603 int relative_cursor_pos) { |
1603 if (!ShouldHandleImeEvents()) | 1604 if (!ShouldHandleImeEvents()) |
1604 return; | 1605 return; |
1605 | 1606 |
1606 #if BUILDFLAG(ENABLE_PLUGINS) | 1607 #if BUILDFLAG(ENABLE_PLUGINS) |
1607 if (focused_pepper_plugin_) { | 1608 if (focused_pepper_plugin_) { |
1608 focused_pepper_plugin_->render_frame()->OnImeCommitText( | 1609 focused_pepper_plugin_->render_frame()->OnImeCommitText( |
1609 text, replacement_range, relative_cursor_pos); | 1610 text, replacement_range, relative_cursor_pos); |
1610 return; | 1611 return; |
1611 } | 1612 } |
1612 #endif | 1613 #endif |
1613 ImeEventGuard guard(this); | 1614 ImeEventGuard guard(this); |
1614 input_handler_->set_handling_input_event(true); | 1615 input_handler_->set_handling_input_event(true); |
1615 if (auto* controller = GetInputMethodController()) { | 1616 if (auto* controller = GetInputMethodController()) { |
1616 controller->commitText( | 1617 controller->commitText( |
1617 WebString::fromUTF16(text), | 1618 WebString::fromUTF16(text), |
1618 WebVector<WebCompositionUnderline>(underlines), | 1619 WebVector<WebCompositionUnderline>(underlines), |
1619 replacement_range.IsValid() | 1620 replacement_range.IsValid() |
1620 ? WebRange(replacement_range.start(), replacement_range.length()) | 1621 ? WebRange(replacement_range.start(), replacement_range.length()) |
1621 : WebRange(), | 1622 : WebRange(), |
1622 relative_cursor_pos); | 1623 relative_cursor_pos); |
1623 } | 1624 } |
1624 input_handler_->set_handling_input_event(false); | 1625 input_handler_->set_handling_input_event(false); |
1625 UpdateCompositionInfo(false /* not an immediate request */); | 1626 updateCompositionInfo(false /* not an immediate request */); |
1626 } | 1627 } |
1627 | 1628 |
1628 void RenderWidget::OnImeFinishComposingText(bool keep_selection) { | 1629 void RenderWidget::OnImeFinishComposingText(bool keep_selection) { |
1629 if (!ShouldHandleImeEvents()) | 1630 if (!ShouldHandleImeEvents()) |
1630 return; | 1631 return; |
1631 | 1632 |
1632 #if BUILDFLAG(ENABLE_PLUGINS) | 1633 #if BUILDFLAG(ENABLE_PLUGINS) |
1633 if (focused_pepper_plugin_) { | 1634 if (focused_pepper_plugin_) { |
1634 focused_pepper_plugin_->render_frame()->OnImeFinishComposingText( | 1635 focused_pepper_plugin_->render_frame()->OnImeFinishComposingText( |
1635 keep_selection); | 1636 keep_selection); |
1636 return; | 1637 return; |
1637 } | 1638 } |
1638 #endif | 1639 #endif |
1639 | 1640 |
1640 if (!GetWebWidget()) | 1641 if (!GetWebWidget()) |
1641 return; | 1642 return; |
1642 ImeEventGuard guard(this); | 1643 ImeEventGuard guard(this); |
1643 input_handler_->set_handling_input_event(true); | 1644 input_handler_->set_handling_input_event(true); |
1644 if (auto* controller = GetInputMethodController()) { | 1645 if (auto* controller = GetInputMethodController()) { |
1645 controller->finishComposingText( | 1646 controller->finishComposingText( |
1646 keep_selection ? WebInputMethodController::KeepSelection | 1647 keep_selection ? WebInputMethodController::KeepSelection |
1647 : WebInputMethodController::DoNotKeepSelection); | 1648 : WebInputMethodController::DoNotKeepSelection); |
1648 } | 1649 } |
1649 input_handler_->set_handling_input_event(false); | 1650 input_handler_->set_handling_input_event(false); |
1650 UpdateCompositionInfo(false /* not an immediate request */); | 1651 updateCompositionInfo(false /* not an immediate request */); |
1651 } | 1652 } |
1652 | 1653 |
1653 void RenderWidget::OnDeviceScaleFactorChanged() { | 1654 void RenderWidget::OnDeviceScaleFactorChanged() { |
1654 if (!compositor_) | 1655 if (!compositor_) |
1655 return; | 1656 return; |
1656 if (IsUseZoomForDSFEnabled()) | 1657 if (IsUseZoomForDSFEnabled()) |
1657 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor()); | 1658 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor()); |
1658 else | 1659 else |
1659 compositor_->setDeviceScaleFactor(device_scale_factor_); | 1660 compositor_->setDeviceScaleFactor(device_scale_factor_); |
1660 } | 1661 } |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1810 ui::TextInputType RenderWidget::GetTextInputType() { | 1811 ui::TextInputType RenderWidget::GetTextInputType() { |
1811 #if BUILDFLAG(ENABLE_PLUGINS) | 1812 #if BUILDFLAG(ENABLE_PLUGINS) |
1812 if (focused_pepper_plugin_) | 1813 if (focused_pepper_plugin_) |
1813 return focused_pepper_plugin_->text_input_type(); | 1814 return focused_pepper_plugin_->text_input_type(); |
1814 #endif | 1815 #endif |
1815 if (auto* controller = GetInputMethodController()) | 1816 if (auto* controller = GetInputMethodController()) |
1816 return ConvertWebTextInputType(controller->textInputType()); | 1817 return ConvertWebTextInputType(controller->textInputType()); |
1817 return ui::TEXT_INPUT_TYPE_NONE; | 1818 return ui::TEXT_INPUT_TYPE_NONE; |
1818 } | 1819 } |
1819 | 1820 |
1820 void RenderWidget::UpdateCompositionInfo(bool immediate_request) { | 1821 void RenderWidget::updateCompositionInfo(bool immediate_request) { |
1821 if (!monitor_composition_info_ && !immediate_request) | 1822 if (!monitor_composition_info_ && !immediate_request) |
1822 return; // Do not calculate composition info if not requested. | 1823 return; // Do not calculate composition info if not requested. |
1823 | 1824 |
1824 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo"); | 1825 TRACE_EVENT0("renderer", "RenderWidget::updateCompositionInfo"); |
1825 gfx::Range range; | 1826 gfx::Range range; |
1826 std::vector<gfx::Rect> character_bounds; | 1827 std::vector<gfx::Rect> character_bounds; |
1827 | 1828 |
1828 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) { | 1829 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) { |
1829 // Composition information is only available on editable node. | 1830 // Composition information is only available on editable node. |
1830 range = gfx::Range::InvalidRange(); | 1831 range = gfx::Range::InvalidRange(); |
1831 } else { | 1832 } else { |
1832 GetCompositionRange(&range); | 1833 GetCompositionRange(&range); |
1833 GetCompositionCharacterBounds(&character_bounds); | 1834 GetCompositionCharacterBounds(&character_bounds); |
1834 } | 1835 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1872 UpdateSelectionBounds(); | 1873 UpdateSelectionBounds(); |
1873 UpdateTextInputStateInternal(false, true /* reply_to_request */); | 1874 UpdateTextInputStateInternal(false, true /* reply_to_request */); |
1874 } | 1875 } |
1875 #endif | 1876 #endif |
1876 | 1877 |
1877 void RenderWidget::OnRequestCompositionUpdates(bool immediate_request, | 1878 void RenderWidget::OnRequestCompositionUpdates(bool immediate_request, |
1878 bool monitor_updates) { | 1879 bool monitor_updates) { |
1879 monitor_composition_info_ = monitor_updates; | 1880 monitor_composition_info_ = monitor_updates; |
1880 if (!immediate_request) | 1881 if (!immediate_request) |
1881 return; | 1882 return; |
1882 UpdateCompositionInfo(true /* immediate request */); | 1883 updateCompositionInfo(true /* immediate request */); |
1883 } | 1884 } |
1884 | 1885 |
1885 void RenderWidget::OnSetDeviceScaleFactor(float device_scale_factor) { | 1886 void RenderWidget::OnSetDeviceScaleFactor(float device_scale_factor) { |
1886 if (device_scale_factor_ == device_scale_factor) | 1887 if (device_scale_factor_ == device_scale_factor) |
1887 return; | 1888 return; |
1888 | 1889 |
1889 device_scale_factor_ = device_scale_factor; | 1890 device_scale_factor_ = device_scale_factor; |
1890 OnDeviceScaleFactorChanged(); | 1891 OnDeviceScaleFactorChanged(); |
1891 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_); | 1892 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_); |
1892 } | 1893 } |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2009 selection_focus_rect_ != params.focus_rect) { | 2010 selection_focus_rect_ != params.focus_rect) { |
2010 selection_anchor_rect_ = params.anchor_rect; | 2011 selection_anchor_rect_ = params.anchor_rect; |
2011 selection_focus_rect_ = params.focus_rect; | 2012 selection_focus_rect_ = params.focus_rect; |
2012 GetWebWidget()->selectionTextDirection(params.focus_dir, | 2013 GetWebWidget()->selectionTextDirection(params.focus_dir, |
2013 params.anchor_dir); | 2014 params.anchor_dir); |
2014 params.is_anchor_first = GetWebWidget()->isSelectionAnchorFirst(); | 2015 params.is_anchor_first = GetWebWidget()->isSelectionAnchorFirst(); |
2015 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params)); | 2016 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params)); |
2016 } | 2017 } |
2017 } | 2018 } |
2018 | 2019 |
2019 UpdateCompositionInfo(false /* not an immediate request */); | 2020 updateCompositionInfo(false /* not an immediate request */); |
2020 } | 2021 } |
2021 | 2022 |
2022 void RenderWidget::DidAutoResize(const gfx::Size& new_size) { | 2023 void RenderWidget::DidAutoResize(const gfx::Size& new_size) { |
2023 WebRect new_size_in_window(0, 0, new_size.width(), new_size.height()); | 2024 WebRect new_size_in_window(0, 0, new_size.width(), new_size.height()); |
2024 convertViewportToWindow(&new_size_in_window); | 2025 convertViewportToWindow(&new_size_in_window); |
2025 if (size_.width() != new_size_in_window.width || | 2026 if (size_.width() != new_size_in_window.width || |
2026 size_.height() != new_size_in_window.height) { | 2027 size_.height() != new_size_in_window.height) { |
2027 size_ = gfx::Size(new_size_in_window.width, new_size_in_window.height); | 2028 size_ = gfx::Size(new_size_in_window.width, new_size_in_window.height); |
2028 | 2029 |
2029 if (resizing_mode_selector_->is_synchronous_mode()) { | 2030 if (resizing_mode_selector_->is_synchronous_mode()) { |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2316 // browser side (https://crbug.com/669219). | 2317 // browser side (https://crbug.com/669219). |
2317 // If there is no WebFrameWidget, then there will be no | 2318 // If there is no WebFrameWidget, then there will be no |
2318 // InputMethodControllers for a WebLocalFrame. | 2319 // InputMethodControllers for a WebLocalFrame. |
2319 return nullptr; | 2320 return nullptr; |
2320 } | 2321 } |
2321 return static_cast<blink::WebFrameWidget*>(GetWebWidget()) | 2322 return static_cast<blink::WebFrameWidget*>(GetWebWidget()) |
2322 ->getActiveWebInputMethodController(); | 2323 ->getActiveWebInputMethodController(); |
2323 } | 2324 } |
2324 | 2325 |
2325 } // namespace content | 2326 } // namespace content |
OLD | NEW |