| 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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 class RenderWidget::ScreenMetricsEmulator { | 241 class RenderWidget::ScreenMetricsEmulator { |
| 242 public: | 242 public: |
| 243 ScreenMetricsEmulator( | 243 ScreenMetricsEmulator( |
| 244 RenderWidget* widget, | 244 RenderWidget* widget, |
| 245 const WebDeviceEmulationParams& params); | 245 const WebDeviceEmulationParams& params); |
| 246 virtual ~ScreenMetricsEmulator(); | 246 virtual ~ScreenMetricsEmulator(); |
| 247 | 247 |
| 248 // Scale and offset used to convert between host coordinates | 248 // Scale and offset used to convert between host coordinates |
| 249 // and webwidget coordinates. | 249 // and webwidget coordinates. |
| 250 float scale() { return scale_; } | 250 float scale() { return scale_; } |
| 251 gfx::Point offset() { return offset_; } | 251 gfx::PointF offset() { return offset_; } |
| 252 gfx::Rect applied_widget_rect() const { return applied_widget_rect_; } | 252 gfx::Rect applied_widget_rect() const { return applied_widget_rect_; } |
| 253 gfx::Rect original_screen_rect() const { return original_view_screen_rect_; } | 253 gfx::Rect original_screen_rect() const { return original_view_screen_rect_; } |
| 254 const WebScreenInfo& original_screen_info() { return original_screen_info_; } | 254 const WebScreenInfo& original_screen_info() { return original_screen_info_; } |
| 255 | 255 |
| 256 void ChangeEmulationParams( | 256 void ChangeEmulationParams( |
| 257 const WebDeviceEmulationParams& params); | 257 const WebDeviceEmulationParams& params); |
| 258 | 258 |
| 259 // The following methods alter handlers' behavior for messages related to | 259 // The following methods alter handlers' behavior for messages related to |
| 260 // widget size and position. | 260 // widget size and position. |
| 261 void OnResizeMessage(const ViewMsg_Resize_Params& params); | 261 void OnResizeMessage(const ViewMsg_Resize_Params& params); |
| 262 void OnUpdateScreenRectsMessage(const gfx::Rect& view_screen_rect, | 262 void OnUpdateScreenRectsMessage(const gfx::Rect& view_screen_rect, |
| 263 const gfx::Rect& window_screen_rect); | 263 const gfx::Rect& window_screen_rect); |
| 264 void OnShowContextMenu(ContextMenuParams* params); | 264 void OnShowContextMenu(ContextMenuParams* params); |
| 265 gfx::Rect AdjustValidationMessageAnchor(const gfx::Rect& anchor); | 265 gfx::Rect AdjustValidationMessageAnchor(const gfx::Rect& anchor); |
| 266 | 266 |
| 267 private: | 267 private: |
| 268 void Reapply(); | 268 void Reapply(); |
| 269 void Apply(bool top_controls_shrink_blink_size, | 269 void Apply(bool top_controls_shrink_blink_size, |
| 270 float top_controls_height, | 270 float top_controls_height, |
| 271 gfx::Rect resizer_rect, | 271 gfx::Rect resizer_rect, |
| 272 bool is_fullscreen); | 272 bool is_fullscreen); |
| 273 | 273 |
| 274 RenderWidget* widget_; | 274 RenderWidget* widget_; |
| 275 | 275 |
| 276 // Parameters as passed by RenderWidget::EnableScreenMetricsEmulation. | 276 // Parameters as passed by RenderWidget::EnableScreenMetricsEmulation. |
| 277 WebDeviceEmulationParams params_; | 277 WebDeviceEmulationParams params_; |
| 278 | 278 |
| 279 // The computed scale and offset used to fit widget into browser window. | 279 // The computed scale and offset used to fit widget into browser window. |
| 280 float scale_; | 280 float scale_; |
| 281 gfx::Point offset_; | 281 gfx::PointF offset_; |
| 282 | 282 |
| 283 // Widget rect as passed to webwidget. | 283 // Widget rect as passed to webwidget. |
| 284 gfx::Rect applied_widget_rect_; | 284 gfx::Rect applied_widget_rect_; |
| 285 | 285 |
| 286 // Original values to restore back after emulation ends. | 286 // Original values to restore back after emulation ends. |
| 287 gfx::Size original_size_; | 287 gfx::Size original_size_; |
| 288 gfx::Size original_physical_backing_size_; | 288 gfx::Size original_physical_backing_size_; |
| 289 gfx::Size original_visible_viewport_size_; | 289 gfx::Size original_visible_viewport_size_; |
| 290 blink::WebScreenInfo original_screen_info_; | 290 blink::WebScreenInfo original_screen_info_; |
| 291 gfx::Rect original_view_screen_rect_; | 291 gfx::Rect original_view_screen_rect_; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 307 Apply(widget_->top_controls_shrink_blink_size_, | 307 Apply(widget_->top_controls_shrink_blink_size_, |
| 308 widget_->top_controls_height_, | 308 widget_->top_controls_height_, |
| 309 widget_->resizer_rect_, | 309 widget_->resizer_rect_, |
| 310 widget_->is_fullscreen_); | 310 widget_->is_fullscreen_); |
| 311 } | 311 } |
| 312 | 312 |
| 313 RenderWidget::ScreenMetricsEmulator::~ScreenMetricsEmulator() { | 313 RenderWidget::ScreenMetricsEmulator::~ScreenMetricsEmulator() { |
| 314 widget_->screen_info_ = original_screen_info_; | 314 widget_->screen_info_ = original_screen_info_; |
| 315 | 315 |
| 316 widget_->SetDeviceScaleFactor(original_screen_info_.deviceScaleFactor); | 316 widget_->SetDeviceScaleFactor(original_screen_info_.deviceScaleFactor); |
| 317 widget_->SetScreenMetricsEmulationParameters(0.f, gfx::Point(), 1.f); | 317 widget_->SetScreenMetricsEmulationParameters(false, params_); |
| 318 widget_->view_screen_rect_ = original_view_screen_rect_; | 318 widget_->view_screen_rect_ = original_view_screen_rect_; |
| 319 widget_->window_screen_rect_ = original_window_screen_rect_; | 319 widget_->window_screen_rect_ = original_window_screen_rect_; |
| 320 widget_->Resize(original_size_, | 320 widget_->Resize(original_size_, |
| 321 original_physical_backing_size_, | 321 original_physical_backing_size_, |
| 322 widget_->top_controls_shrink_blink_size_, | 322 widget_->top_controls_shrink_blink_size_, |
| 323 widget_->top_controls_height_, | 323 widget_->top_controls_height_, |
| 324 original_visible_viewport_size_, | 324 original_visible_viewport_size_, |
| 325 widget_->resizer_rect_, | 325 widget_->resizer_rect_, |
| 326 widget_->is_fullscreen_, | 326 widget_->is_fullscreen_, |
| 327 NO_RESIZE_ACK); | 327 NO_RESIZE_ACK); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 | 385 |
| 386 float applied_device_scale_factor = params_.deviceScaleFactor ? | 386 float applied_device_scale_factor = params_.deviceScaleFactor ? |
| 387 params_.deviceScaleFactor : original_screen_info_.deviceScaleFactor; | 387 params_.deviceScaleFactor : original_screen_info_.deviceScaleFactor; |
| 388 widget_->screen_info_.deviceScaleFactor = applied_device_scale_factor; | 388 widget_->screen_info_.deviceScaleFactor = applied_device_scale_factor; |
| 389 | 389 |
| 390 // Pass three emulation parameters to the blink side: | 390 // Pass three emulation parameters to the blink side: |
| 391 // - we keep the real device scale factor in compositor to produce sharp image | 391 // - we keep the real device scale factor in compositor to produce sharp image |
| 392 // even when emulating different scale factor; | 392 // even when emulating different scale factor; |
| 393 // - in order to fit into view, WebView applies offset and scale to the | 393 // - in order to fit into view, WebView applies offset and scale to the |
| 394 // root layer. | 394 // root layer. |
| 395 widget_->SetScreenMetricsEmulationParameters( | 395 blink::WebDeviceEmulationParams modified_params = params_; |
| 396 original_screen_info_.deviceScaleFactor, offset_, scale_); | 396 modified_params.deviceScaleFactor = original_screen_info_.deviceScaleFactor; |
| 397 modified_params.offset = blink::WebFloatPoint(offset_.x(), offset_.y()); |
| 398 modified_params.scale = scale_; |
| 399 widget_->SetScreenMetricsEmulationParameters(true, modified_params); |
| 397 | 400 |
| 398 widget_->SetDeviceScaleFactor(applied_device_scale_factor); | 401 widget_->SetDeviceScaleFactor(applied_device_scale_factor); |
| 399 widget_->view_screen_rect_ = applied_widget_rect_; | 402 widget_->view_screen_rect_ = applied_widget_rect_; |
| 400 | 403 |
| 401 gfx::Size physical_backing_size = gfx::ToCeiledSize(gfx::ScaleSize( | 404 gfx::Size physical_backing_size = gfx::ToCeiledSize(gfx::ScaleSize( |
| 402 original_size_, original_screen_info_.deviceScaleFactor)); | 405 original_size_, original_screen_info_.deviceScaleFactor)); |
| 403 widget_->Resize(applied_widget_rect_.size(), | 406 widget_->Resize(applied_widget_rect_.size(), |
| 404 physical_backing_size, | 407 physical_backing_size, |
| 405 top_controls_shrink_blink_size, | 408 top_controls_shrink_blink_size, |
| 406 top_controls_height, | 409 top_controls_height, |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 RenderProcess::current()->AddRefProcess(); | 652 RenderProcess::current()->AddRefProcess(); |
| 650 } | 653 } |
| 651 | 654 |
| 652 void RenderWidget::WasSwappedOut() { | 655 void RenderWidget::WasSwappedOut() { |
| 653 // If we have been swapped out and no one else is using this process, | 656 // If we have been swapped out and no one else is using this process, |
| 654 // it's safe to exit now. | 657 // it's safe to exit now. |
| 655 CHECK(is_swapped_out_); | 658 CHECK(is_swapped_out_); |
| 656 RenderProcess::current()->ReleaseProcess(); | 659 RenderProcess::current()->ReleaseProcess(); |
| 657 } | 660 } |
| 658 | 661 |
| 659 void RenderWidget::EnableScreenMetricsEmulation( | |
| 660 const WebDeviceEmulationParams& params) { | |
| 661 if (!screen_metrics_emulator_) | |
| 662 screen_metrics_emulator_.reset(new ScreenMetricsEmulator(this, params)); | |
| 663 else | |
| 664 screen_metrics_emulator_->ChangeEmulationParams(params); | |
| 665 } | |
| 666 | |
| 667 void RenderWidget::DisableScreenMetricsEmulation() { | |
| 668 screen_metrics_emulator_.reset(); | |
| 669 } | |
| 670 | |
| 671 void RenderWidget::SetPopupOriginAdjustmentsForEmulation( | 662 void RenderWidget::SetPopupOriginAdjustmentsForEmulation( |
| 672 ScreenMetricsEmulator* emulator) { | 663 ScreenMetricsEmulator* emulator) { |
| 673 popup_origin_scale_for_emulation_ = emulator->scale(); | 664 popup_origin_scale_for_emulation_ = emulator->scale(); |
| 674 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin(); | 665 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin(); |
| 675 popup_screen_origin_for_emulation_ = gfx::Point( | 666 popup_screen_origin_for_emulation_ = gfx::Point( |
| 676 emulator->original_screen_rect().origin().x() + emulator->offset().x(), | 667 emulator->original_screen_rect().origin().x() + emulator->offset().x(), |
| 677 emulator->original_screen_rect().origin().y() + emulator->offset().y()); | 668 emulator->original_screen_rect().origin().y() + emulator->offset().y()); |
| 678 screen_info_ = emulator->original_screen_info(); | 669 screen_info_ = emulator->original_screen_info(); |
| 679 device_scale_factor_ = screen_info_.deviceScaleFactor; | 670 device_scale_factor_ = screen_info_.deviceScaleFactor; |
| 680 } | 671 } |
| 681 | 672 |
| 682 gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) { | 673 gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) { |
| 683 if (screen_metrics_emulator_) | 674 if (screen_metrics_emulator_) |
| 684 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor); | 675 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor); |
| 685 return anchor; | 676 return anchor; |
| 686 } | 677 } |
| 687 | 678 |
| 688 void RenderWidget::SetScreenMetricsEmulationParameters( | 679 void RenderWidget::SetScreenMetricsEmulationParameters( |
| 689 float device_scale_factor, | 680 bool enabled, |
| 690 const gfx::Point& root_layer_offset, | 681 const blink::WebDeviceEmulationParams& params) { |
| 691 float root_layer_scale) { | |
| 692 // This is only supported in RenderView. | 682 // This is only supported in RenderView. |
| 693 NOTREACHED(); | 683 NOTREACHED(); |
| 694 } | 684 } |
| 695 | 685 |
| 696 #if defined(OS_MACOSX) || defined(OS_ANDROID) | 686 #if defined(OS_MACOSX) || defined(OS_ANDROID) |
| 697 void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation( | 687 void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation( |
| 698 ExternalPopupMenu* popup, ScreenMetricsEmulator* emulator) { | 688 ExternalPopupMenu* popup, ScreenMetricsEmulator* emulator) { |
| 699 popup->SetOriginScaleAndOffsetForEmulation( | 689 popup->SetOriginScaleAndOffsetForEmulation( |
| 700 emulator->scale(), emulator->offset()); | 690 emulator->scale(), emulator->offset()); |
| 701 } | 691 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 725 OnCursorVisibilityChange) | 715 OnCursorVisibilityChange) |
| 726 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition) | 716 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition) |
| 727 IPC_MESSAGE_HANDLER(InputMsg_ImeConfirmComposition, OnImeConfirmComposition) | 717 IPC_MESSAGE_HANDLER(InputMsg_ImeConfirmComposition, OnImeConfirmComposition) |
| 728 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost) | 718 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost) |
| 729 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus) | 719 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus) |
| 730 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted, | 720 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted, |
| 731 OnSyntheticGestureCompleted) | 721 OnSyntheticGestureCompleted) |
| 732 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose) | 722 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose) |
| 733 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck) | 723 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck) |
| 734 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize) | 724 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize) |
| 725 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation, |
| 726 OnEnableDeviceEmulation) |
| 727 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation, |
| 728 OnDisableDeviceEmulation) |
| 735 IPC_MESSAGE_HANDLER(ViewMsg_ColorProfile, OnColorProfile) | 729 IPC_MESSAGE_HANDLER(ViewMsg_ColorProfile, OnColorProfile) |
| 736 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect) | 730 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect) |
| 737 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden) | 731 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden) |
| 738 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown) | 732 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown) |
| 739 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive) | 733 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive) |
| 740 IPC_MESSAGE_HANDLER(ViewMsg_CandidateWindowShown, OnCandidateWindowShown) | 734 IPC_MESSAGE_HANDLER(ViewMsg_CandidateWindowShown, OnCandidateWindowShown) |
| 741 IPC_MESSAGE_HANDLER(ViewMsg_CandidateWindowUpdated, | 735 IPC_MESSAGE_HANDLER(ViewMsg_CandidateWindowUpdated, |
| 742 OnCandidateWindowUpdated) | 736 OnCandidateWindowUpdated) |
| 743 IPC_MESSAGE_HANDLER(ViewMsg_CandidateWindowHidden, OnCandidateWindowHidden) | 737 IPC_MESSAGE_HANDLER(ViewMsg_CandidateWindowHidden, OnCandidateWindowHidden) |
| 744 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint) | 738 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint) |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 908 params.top_controls_height, | 902 params.top_controls_height, |
| 909 params.visible_viewport_size, | 903 params.visible_viewport_size, |
| 910 params.resizer_rect, | 904 params.resizer_rect, |
| 911 params.is_fullscreen, | 905 params.is_fullscreen, |
| 912 params.needs_resize_ack ? SEND_RESIZE_ACK : NO_RESIZE_ACK); | 906 params.needs_resize_ack ? SEND_RESIZE_ACK : NO_RESIZE_ACK); |
| 913 | 907 |
| 914 if (orientation_changed) | 908 if (orientation_changed) |
| 915 OnOrientationChange(); | 909 OnOrientationChange(); |
| 916 } | 910 } |
| 917 | 911 |
| 912 void RenderWidget::OnEnableDeviceEmulation( |
| 913 const blink::WebDeviceEmulationParams& params) { |
| 914 if (!screen_metrics_emulator_) |
| 915 screen_metrics_emulator_.reset(new ScreenMetricsEmulator(this, params)); |
| 916 else |
| 917 screen_metrics_emulator_->ChangeEmulationParams(params); |
| 918 } |
| 919 |
| 920 void RenderWidget::OnDisableDeviceEmulation() { |
| 921 screen_metrics_emulator_.reset(); |
| 922 } |
| 923 |
| 918 void RenderWidget::OnColorProfile(const std::vector<char>& color_profile) { | 924 void RenderWidget::OnColorProfile(const std::vector<char>& color_profile) { |
| 919 SetDeviceColorProfile(color_profile); | 925 SetDeviceColorProfile(color_profile); |
| 920 } | 926 } |
| 921 | 927 |
| 922 void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) { | 928 void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) { |
| 923 if (resizer_rect_ == resizer_rect) | 929 if (resizer_rect_ == resizer_rect) |
| 924 return; | 930 return; |
| 925 resizer_rect_ = resizer_rect; | 931 resizer_rect_ = resizer_rect; |
| 926 if (webwidget_) | 932 if (webwidget_) |
| 927 webwidget_->didChangeWindowResizerRect(); | 933 webwidget_->didChangeWindowResizerRect(); |
| (...skipping 1489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2417 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { | 2423 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { |
| 2418 video_hole_frames_.AddObserver(frame); | 2424 video_hole_frames_.AddObserver(frame); |
| 2419 } | 2425 } |
| 2420 | 2426 |
| 2421 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { | 2427 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { |
| 2422 video_hole_frames_.RemoveObserver(frame); | 2428 video_hole_frames_.RemoveObserver(frame); |
| 2423 } | 2429 } |
| 2424 #endif // defined(VIDEO_HOLE) | 2430 #endif // defined(VIDEO_HOLE) |
| 2425 | 2431 |
| 2426 } // namespace content | 2432 } // namespace content |
| OLD | NEW |