| 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 "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 gfx::Size new_widget_size = | 821 gfx::Size new_widget_size = |
| 822 IsUseZoomForDSFEnabled() ? physical_backing_size_ : size_; | 822 IsUseZoomForDSFEnabled() ? physical_backing_size_ : size_; |
| 823 // When resizing, we want to wait to paint before ACK'ing the resize. This | 823 // When resizing, we want to wait to paint before ACK'ing the resize. This |
| 824 // ensures that we only resize as fast as we can paint. We only need to | 824 // ensures that we only resize as fast as we can paint. We only need to |
| 825 // send an ACK if we are resized to a non-empty rect. | 825 // send an ACK if we are resized to a non-empty rect. |
| 826 webwidget_->resize(new_widget_size); | 826 webwidget_->resize(new_widget_size); |
| 827 } | 827 } |
| 828 WebSize visual_viewport_size; | 828 WebSize visual_viewport_size; |
| 829 | 829 |
| 830 if (IsUseZoomForDSFEnabled()) { | 830 if (IsUseZoomForDSFEnabled()) { |
| 831 gfx::SizeF scaled_visible_viewport_size = | 831 visual_viewport_size = |
| 832 gfx::ScaleSize(gfx::SizeF(visible_viewport_size), device_scale_factor_); | 832 gfx::ScaleToCeiledSize(visible_viewport_size, device_scale_factor_); |
| 833 visual_viewport_size = gfx::ToCeiledSize(scaled_visible_viewport_size); | |
| 834 } else { | 833 } else { |
| 835 visual_viewport_size = visible_viewport_size_; | 834 visual_viewport_size = visible_viewport_size_; |
| 836 } | 835 } |
| 837 | 836 |
| 838 webwidget()->resizeVisualViewport(visual_viewport_size); | 837 webwidget()->resizeVisualViewport(visual_viewport_size); |
| 839 | 838 |
| 840 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) { | 839 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) { |
| 841 // In this case there is no paint/composite and therefore no | 840 // In this case there is no paint/composite and therefore no |
| 842 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the | 841 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the |
| 843 // ack through a fake ViewHostMsg_UpdateRect or a different message. | 842 // ack through a fake ViewHostMsg_UpdateRect or a different message. |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1364 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_); | 1363 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_); |
| 1365 if (compositor_) | 1364 if (compositor_) |
| 1366 compositor_->setViewportSize(physical_backing_size_); | 1365 compositor_->setViewportSize(physical_backing_size_); |
| 1367 } | 1366 } |
| 1368 | 1367 |
| 1369 void RenderWidget::initializeLayerTreeView() { | 1368 void RenderWidget::initializeLayerTreeView() { |
| 1370 DCHECK(!host_closing_); | 1369 DCHECK(!host_closing_); |
| 1371 | 1370 |
| 1372 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_); | 1371 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_); |
| 1373 compositor_->setViewportSize(physical_backing_size_); | 1372 compositor_->setViewportSize(physical_backing_size_); |
| 1374 | 1373 OnDeviceScaleFactorChanged(); |
| 1375 // For background pages and certain tests, we don't want to trigger | 1374 // For background pages and certain tests, we don't want to trigger |
| 1376 // OutputSurface creation. | 1375 // OutputSurface creation. |
| 1377 if (compositor_never_visible_ || !RenderThreadImpl::current()) | 1376 if (compositor_never_visible_ || !RenderThreadImpl::current()) |
| 1378 compositor_->SetNeverVisible(); | 1377 compositor_->SetNeverVisible(); |
| 1379 | 1378 |
| 1380 StartCompositor(); | 1379 StartCompositor(); |
| 1381 } | 1380 } |
| 1382 | 1381 |
| 1383 void RenderWidget::WillCloseLayerTreeView() { | 1382 void RenderWidget::WillCloseLayerTreeView() { |
| 1384 if (host_closing_) | 1383 if (host_closing_) |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1620 return pending_window_rect_; | 1619 return pending_window_rect_; |
| 1621 | 1620 |
| 1622 return view_screen_rect_; | 1621 return view_screen_rect_; |
| 1623 } | 1622 } |
| 1624 | 1623 |
| 1625 void RenderWidget::setToolTipText(const blink::WebString& text, | 1624 void RenderWidget::setToolTipText(const blink::WebString& text, |
| 1626 WebTextDirection hint) { | 1625 WebTextDirection hint) { |
| 1627 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint)); | 1626 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint)); |
| 1628 } | 1627 } |
| 1629 | 1628 |
| 1630 void RenderWidget::setWindowRect(const WebRect& rect) { | 1629 void RenderWidget::setWindowRect(const WebRect& rect_in_screen) { |
| 1631 // TODO(oshima): Scale back to DIP coordinates. | 1630 WebRect window_rect = rect_in_screen; |
| 1632 WebRect window_rect = rect; | |
| 1633 if (popup_origin_scale_for_emulation_) { | 1631 if (popup_origin_scale_for_emulation_) { |
| 1634 float scale = popup_origin_scale_for_emulation_; | 1632 float scale = popup_origin_scale_for_emulation_; |
| 1635 window_rect.x = popup_screen_origin_for_emulation_.x() + | 1633 window_rect.x = popup_screen_origin_for_emulation_.x() + |
| 1636 (window_rect.x - popup_view_origin_for_emulation_.x()) * scale; | 1634 (window_rect.x - popup_view_origin_for_emulation_.x()) * scale; |
| 1637 window_rect.y = popup_screen_origin_for_emulation_.y() + | 1635 window_rect.y = popup_screen_origin_for_emulation_.y() + |
| 1638 (window_rect.y - popup_view_origin_for_emulation_.y()) * scale; | 1636 (window_rect.y - popup_view_origin_for_emulation_.y()) * scale; |
| 1639 } | 1637 } |
| 1640 | 1638 |
| 1641 if (!resizing_mode_selector_->is_synchronous_mode()) { | 1639 if (!resizing_mode_selector_->is_synchronous_mode()) { |
| 1642 if (did_show_) { | 1640 if (did_show_) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1700 if (text.length()) | 1698 if (text.length()) |
| 1701 webwidget_->confirmComposition(text); | 1699 webwidget_->confirmComposition(text); |
| 1702 else if (keep_selection) | 1700 else if (keep_selection) |
| 1703 webwidget_->confirmComposition(WebWidget::KeepSelection); | 1701 webwidget_->confirmComposition(WebWidget::KeepSelection); |
| 1704 else | 1702 else |
| 1705 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection); | 1703 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection); |
| 1706 handling_input_event_ = false; | 1704 handling_input_event_ = false; |
| 1707 UpdateCompositionInfo(true); | 1705 UpdateCompositionInfo(true); |
| 1708 } | 1706 } |
| 1709 | 1707 |
| 1708 void RenderWidget::OnDeviceScaleFactorChanged() { |
| 1709 DCHECK(compositor_); |
| 1710 if (IsUseZoomForDSFEnabled()) |
| 1711 compositor_->SetPaintedDeviceScaleFactor(device_scale_factor_); |
| 1712 else |
| 1713 compositor_->setDeviceScaleFactor(device_scale_factor_); |
| 1714 } |
| 1715 |
| 1710 void RenderWidget::OnRepaint(gfx::Size size_to_paint) { | 1716 void RenderWidget::OnRepaint(gfx::Size size_to_paint) { |
| 1711 // During shutdown we can just ignore this message. | 1717 // During shutdown we can just ignore this message. |
| 1712 if (!webwidget_) | 1718 if (!webwidget_) |
| 1713 return; | 1719 return; |
| 1714 | 1720 |
| 1715 // Even if the browser provides an empty damage rect, it's still expecting to | 1721 // Even if the browser provides an empty damage rect, it's still expecting to |
| 1716 // receive a repaint ack so just damage the entire widget bounds. | 1722 // receive a repaint ack so just damage the entire widget bounds. |
| 1717 if (size_to_paint.IsEmpty()) { | 1723 if (size_to_paint.IsEmpty()) { |
| 1718 size_to_paint = size_; | 1724 size_to_paint = size_; |
| 1719 } | 1725 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1750 | 1756 |
| 1751 void RenderWidget::OnSetSurfaceIdNamespace(uint32_t surface_id_namespace) { | 1757 void RenderWidget::OnSetSurfaceIdNamespace(uint32_t surface_id_namespace) { |
| 1752 if (compositor_) | 1758 if (compositor_) |
| 1753 compositor_->SetSurfaceIdNamespace(surface_id_namespace); | 1759 compositor_->SetSurfaceIdNamespace(surface_id_namespace); |
| 1754 } | 1760 } |
| 1755 | 1761 |
| 1756 void RenderWidget::showImeIfNeeded() { | 1762 void RenderWidget::showImeIfNeeded() { |
| 1757 OnShowImeIfNeeded(); | 1763 OnShowImeIfNeeded(); |
| 1758 } | 1764 } |
| 1759 | 1765 |
| 1766 void RenderWidget::convertViewportToScreen(blink::WebRect* rect) { |
| 1767 gfx::Rect screen_rect(*rect); |
| 1768 if (IsUseZoomForDSFEnabled()) { |
| 1769 // TODO(oshima): We may need to allow pixel precision here as the the |
| 1770 // anchor element can be placed at half pixel. |
| 1771 float reverse = 1 / device_scale_factor_; |
| 1772 screen_rect.set_origin( |
| 1773 gfx::ScaleToRoundedPoint(screen_rect.origin(), reverse)); |
| 1774 screen_rect.set_size(gfx::ScaleToRoundedSize(screen_rect.size(), reverse)); |
| 1775 } |
| 1776 |
| 1777 blink::WebRect window_rect = windowRect(); |
| 1778 screen_rect.Offset(window_rect.x, window_rect.y); |
| 1779 rect->x = screen_rect.x(); |
| 1780 rect->y = screen_rect.y(); |
| 1781 rect->width = screen_rect.width(); |
| 1782 rect->height = screen_rect.height(); |
| 1783 } |
| 1784 |
| 1760 void RenderWidget::OnShowImeIfNeeded() { | 1785 void RenderWidget::OnShowImeIfNeeded() { |
| 1761 #if defined(OS_ANDROID) || defined(USE_AURA) | 1786 #if defined(OS_ANDROID) || defined(USE_AURA) |
| 1762 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME); | 1787 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME); |
| 1763 #endif | 1788 #endif |
| 1764 | 1789 |
| 1765 // TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with | 1790 // TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with |
| 1766 // virtual keyboard. | 1791 // virtual keyboard. |
| 1767 #if !defined(OS_ANDROID) | 1792 #if !defined(OS_ANDROID) |
| 1768 FocusChangeComplete(); | 1793 FocusChangeComplete(); |
| 1769 #endif | 1794 #endif |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1816 | 1841 |
| 1817 void RenderWidget::IgnoreAckForMouseMoveFromDebugger() { | 1842 void RenderWidget::IgnoreAckForMouseMoveFromDebugger() { |
| 1818 ignore_ack_for_mouse_move_from_debugger_ = true; | 1843 ignore_ack_for_mouse_move_from_debugger_ = true; |
| 1819 } | 1844 } |
| 1820 | 1845 |
| 1821 void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) { | 1846 void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) { |
| 1822 if (device_scale_factor_ == device_scale_factor) | 1847 if (device_scale_factor_ == device_scale_factor) |
| 1823 return; | 1848 return; |
| 1824 | 1849 |
| 1825 device_scale_factor_ = device_scale_factor; | 1850 device_scale_factor_ = device_scale_factor; |
| 1851 |
| 1852 OnDeviceScaleFactorChanged(); |
| 1853 |
| 1826 ScheduleComposite(); | 1854 ScheduleComposite(); |
| 1827 } | 1855 } |
| 1828 | 1856 |
| 1829 bool RenderWidget::SetDeviceColorProfile( | 1857 bool RenderWidget::SetDeviceColorProfile( |
| 1830 const std::vector<char>& color_profile) { | 1858 const std::vector<char>& color_profile) { |
| 1831 if (device_color_profile_ == color_profile) | 1859 if (device_color_profile_ == color_profile) |
| 1832 return false; | 1860 return false; |
| 1833 | 1861 |
| 1834 device_color_profile_ = color_profile; | 1862 device_color_profile_ = color_profile; |
| 1835 return true; | 1863 return true; |
| (...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2441 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { | 2469 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { |
| 2442 video_hole_frames_.AddObserver(frame); | 2470 video_hole_frames_.AddObserver(frame); |
| 2443 } | 2471 } |
| 2444 | 2472 |
| 2445 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { | 2473 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { |
| 2446 video_hole_frames_.RemoveObserver(frame); | 2474 video_hole_frames_.RemoveObserver(frame); |
| 2447 } | 2475 } |
| 2448 #endif // defined(VIDEO_HOLE) | 2476 #endif // defined(VIDEO_HOLE) |
| 2449 | 2477 |
| 2450 } // namespace content | 2478 } // namespace content |
| OLD | NEW |