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/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 // The following methods alter handlers' behavior for messages related to | 191 // The following methods alter handlers' behavior for messages related to |
192 // widget size and position. | 192 // widget size and position. |
193 void OnResizeMessage(const ViewMsg_Resize_Params& params); | 193 void OnResizeMessage(const ViewMsg_Resize_Params& params); |
194 void OnUpdateScreenRectsMessage(const gfx::Rect& view_screen_rect, | 194 void OnUpdateScreenRectsMessage(const gfx::Rect& view_screen_rect, |
195 const gfx::Rect& window_screen_rect); | 195 const gfx::Rect& window_screen_rect); |
196 void OnShowContextMenu(ContextMenuParams* params); | 196 void OnShowContextMenu(ContextMenuParams* params); |
197 gfx::Rect AdjustValidationMessageAnchor(const gfx::Rect& anchor); | 197 gfx::Rect AdjustValidationMessageAnchor(const gfx::Rect& anchor); |
198 | 198 |
199 private: | 199 private: |
200 void Reapply(); | 200 void Reapply(); |
201 void Apply(float top_controls_layout_height, | 201 void Apply(bool top_controls_shrink_blink_size, |
202 float top_controls_height, | |
202 gfx::Rect resizer_rect, | 203 gfx::Rect resizer_rect, |
203 bool is_fullscreen); | 204 bool is_fullscreen); |
204 | 205 |
205 RenderWidget* widget_; | 206 RenderWidget* widget_; |
206 | 207 |
207 // Parameters as passed by RenderWidget::EnableScreenMetricsEmulation. | 208 // Parameters as passed by RenderWidget::EnableScreenMetricsEmulation. |
208 WebDeviceEmulationParams params_; | 209 WebDeviceEmulationParams params_; |
209 | 210 |
210 // The computed scale and offset used to fit widget into browser window. | 211 // The computed scale and offset used to fit widget into browser window. |
211 float scale_; | 212 float scale_; |
(...skipping 16 matching lines...) Expand all Loading... | |
228 const WebDeviceEmulationParams& params) | 229 const WebDeviceEmulationParams& params) |
229 : widget_(widget), | 230 : widget_(widget), |
230 params_(params), | 231 params_(params), |
231 scale_(1.f) { | 232 scale_(1.f) { |
232 original_size_ = widget_->size_; | 233 original_size_ = widget_->size_; |
233 original_physical_backing_size_ = widget_->physical_backing_size_; | 234 original_physical_backing_size_ = widget_->physical_backing_size_; |
234 original_visible_viewport_size_ = widget_->visible_viewport_size_; | 235 original_visible_viewport_size_ = widget_->visible_viewport_size_; |
235 original_screen_info_ = widget_->screen_info_; | 236 original_screen_info_ = widget_->screen_info_; |
236 original_view_screen_rect_ = widget_->view_screen_rect_; | 237 original_view_screen_rect_ = widget_->view_screen_rect_; |
237 original_window_screen_rect_ = widget_->window_screen_rect_; | 238 original_window_screen_rect_ = widget_->window_screen_rect_; |
238 Apply(widget_->top_controls_layout_height_, widget_->resizer_rect_, | 239 Apply(widget_->top_controls_shrink_blink_size_, |
239 widget_->is_fullscreen_); | 240 widget_->top_controls_height_, |
241 widget_->resizer_rect_, | |
242 widget_->is_fullscreen_); | |
240 } | 243 } |
241 | 244 |
242 RenderWidget::ScreenMetricsEmulator::~ScreenMetricsEmulator() { | 245 RenderWidget::ScreenMetricsEmulator::~ScreenMetricsEmulator() { |
243 widget_->screen_info_ = original_screen_info_; | 246 widget_->screen_info_ = original_screen_info_; |
244 | 247 |
245 widget_->SetDeviceScaleFactor(original_screen_info_.deviceScaleFactor); | 248 widget_->SetDeviceScaleFactor(original_screen_info_.deviceScaleFactor); |
246 widget_->SetScreenMetricsEmulationParameters(0.f, gfx::Point(), 1.f); | 249 widget_->SetScreenMetricsEmulationParameters(0.f, gfx::Point(), 1.f); |
247 widget_->view_screen_rect_ = original_view_screen_rect_; | 250 widget_->view_screen_rect_ = original_view_screen_rect_; |
248 widget_->window_screen_rect_ = original_window_screen_rect_; | 251 widget_->window_screen_rect_ = original_window_screen_rect_; |
249 widget_->Resize(original_size_, | 252 widget_->Resize(original_size_, |
250 original_physical_backing_size_, | 253 original_physical_backing_size_, |
251 widget_->top_controls_layout_height_, | 254 widget_->top_controls_shrink_blink_size_, |
255 widget_->top_controls_height_, | |
252 original_visible_viewport_size_, | 256 original_visible_viewport_size_, |
253 widget_->resizer_rect_, | 257 widget_->resizer_rect_, |
254 widget_->is_fullscreen_, | 258 widget_->is_fullscreen_, |
255 NO_RESIZE_ACK); | 259 NO_RESIZE_ACK); |
256 } | 260 } |
257 | 261 |
258 void RenderWidget::ScreenMetricsEmulator::ChangeEmulationParams( | 262 void RenderWidget::ScreenMetricsEmulator::ChangeEmulationParams( |
259 const WebDeviceEmulationParams& params) { | 263 const WebDeviceEmulationParams& params) { |
260 params_ = params; | 264 params_ = params; |
261 Reapply(); | 265 Reapply(); |
262 } | 266 } |
263 | 267 |
264 void RenderWidget::ScreenMetricsEmulator::Reapply() { | 268 void RenderWidget::ScreenMetricsEmulator::Reapply() { |
265 Apply(widget_->top_controls_layout_height_, widget_->resizer_rect_, | 269 Apply(widget_->top_controls_shrink_blink_size_, |
266 widget_->is_fullscreen_); | 270 widget_->top_controls_height_, |
271 widget_->resizer_rect_, | |
272 widget_->is_fullscreen_); | |
267 } | 273 } |
268 | 274 |
269 void RenderWidget::ScreenMetricsEmulator::Apply( | 275 void RenderWidget::ScreenMetricsEmulator::Apply( |
270 float top_controls_layout_height, | 276 bool top_controls_shrink_blink_size, |
277 float top_controls_height, | |
271 gfx::Rect resizer_rect, | 278 gfx::Rect resizer_rect, |
272 bool is_fullscreen) { | 279 bool is_fullscreen) { |
273 applied_widget_rect_.set_size(gfx::Size(params_.viewSize)); | 280 applied_widget_rect_.set_size(gfx::Size(params_.viewSize)); |
274 if (!applied_widget_rect_.width()) | 281 if (!applied_widget_rect_.width()) |
275 applied_widget_rect_.set_width(original_size_.width()); | 282 applied_widget_rect_.set_width(original_size_.width()); |
276 if (!applied_widget_rect_.height()) | 283 if (!applied_widget_rect_.height()) |
277 applied_widget_rect_.set_height(original_size_.height()); | 284 applied_widget_rect_.set_height(original_size_.height()); |
278 | 285 |
279 if (params_.fitToView && !original_size_.IsEmpty()) { | 286 if (params_.fitToView && !original_size_.IsEmpty()) { |
280 int original_width = std::max(original_size_.width(), 1); | 287 int original_width = std::max(original_size_.width(), 1); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
318 // - in order to fit into view, WebView applies offset and scale to the | 325 // - in order to fit into view, WebView applies offset and scale to the |
319 // root layer. | 326 // root layer. |
320 widget_->SetScreenMetricsEmulationParameters( | 327 widget_->SetScreenMetricsEmulationParameters( |
321 original_screen_info_.deviceScaleFactor, offset_, scale_); | 328 original_screen_info_.deviceScaleFactor, offset_, scale_); |
322 | 329 |
323 widget_->SetDeviceScaleFactor(applied_device_scale_factor); | 330 widget_->SetDeviceScaleFactor(applied_device_scale_factor); |
324 widget_->view_screen_rect_ = applied_widget_rect_; | 331 widget_->view_screen_rect_ = applied_widget_rect_; |
325 | 332 |
326 gfx::Size physical_backing_size = gfx::ToCeiledSize(gfx::ScaleSize( | 333 gfx::Size physical_backing_size = gfx::ToCeiledSize(gfx::ScaleSize( |
327 original_size_, original_screen_info_.deviceScaleFactor)); | 334 original_size_, original_screen_info_.deviceScaleFactor)); |
328 widget_->Resize(applied_widget_rect_.size(), physical_backing_size, | 335 widget_->Resize(applied_widget_rect_.size(), |
329 top_controls_layout_height, applied_widget_rect_.size(), resizer_rect, | 336 physical_backing_size, |
330 is_fullscreen, NO_RESIZE_ACK); | 337 top_controls_shrink_blink_size, |
338 top_controls_height, | |
339 applied_widget_rect_.size(), | |
340 resizer_rect, | |
341 is_fullscreen, | |
342 NO_RESIZE_ACK); | |
331 } | 343 } |
332 | 344 |
333 void RenderWidget::ScreenMetricsEmulator::OnResizeMessage( | 345 void RenderWidget::ScreenMetricsEmulator::OnResizeMessage( |
334 const ViewMsg_Resize_Params& params) { | 346 const ViewMsg_Resize_Params& params) { |
335 bool need_ack = params.new_size != original_size_ && | 347 bool need_ack = params.new_size != original_size_ && |
336 !params.new_size.IsEmpty() && !params.physical_backing_size.IsEmpty(); | 348 !params.new_size.IsEmpty() && !params.physical_backing_size.IsEmpty(); |
337 original_size_ = params.new_size; | 349 original_size_ = params.new_size; |
338 original_physical_backing_size_ = params.physical_backing_size; | 350 original_physical_backing_size_ = params.physical_backing_size; |
339 original_screen_info_ = params.screen_info; | 351 original_screen_info_ = params.screen_info; |
340 original_visible_viewport_size_ = params.visible_viewport_size; | 352 original_visible_viewport_size_ = params.visible_viewport_size; |
341 Apply(params.top_controls_layout_height, params.resizer_rect, | 353 Apply(params.top_controls_shrink_blink_size, |
342 params.is_fullscreen); | 354 params.top_controls_height, |
355 params.resizer_rect, | |
356 params.is_fullscreen); | |
343 | 357 |
344 if (need_ack) { | 358 if (need_ack) { |
345 widget_->set_next_paint_is_resize_ack(); | 359 widget_->set_next_paint_is_resize_ack(); |
346 if (widget_->compositor_) | 360 if (widget_->compositor_) |
347 widget_->compositor_->SetNeedsRedrawRect(gfx::Rect(widget_->size_)); | 361 widget_->compositor_->SetNeedsRedrawRect(gfx::Rect(widget_->size_)); |
348 } | 362 } |
349 } | 363 } |
350 | 364 |
351 void RenderWidget::ScreenMetricsEmulator::OnUpdateScreenRectsMessage( | 365 void RenderWidget::ScreenMetricsEmulator::OnUpdateScreenRectsMessage( |
352 const gfx::Rect& view_screen_rect, | 366 const gfx::Rect& view_screen_rect, |
(...skipping 25 matching lines...) Expand all Loading... | |
378 RenderWidget::RenderWidget(blink::WebPopupType popup_type, | 392 RenderWidget::RenderWidget(blink::WebPopupType popup_type, |
379 const blink::WebScreenInfo& screen_info, | 393 const blink::WebScreenInfo& screen_info, |
380 bool swapped_out, | 394 bool swapped_out, |
381 bool hidden, | 395 bool hidden, |
382 bool never_visible) | 396 bool never_visible) |
383 : routing_id_(MSG_ROUTING_NONE), | 397 : routing_id_(MSG_ROUTING_NONE), |
384 surface_id_(0), | 398 surface_id_(0), |
385 webwidget_(NULL), | 399 webwidget_(NULL), |
386 opener_id_(MSG_ROUTING_NONE), | 400 opener_id_(MSG_ROUTING_NONE), |
387 init_complete_(false), | 401 init_complete_(false), |
388 top_controls_layout_height_(0.f), | 402 top_controls_shrink_blink_size_(false), |
403 top_controls_height_(0.f), | |
389 next_paint_flags_(0), | 404 next_paint_flags_(0), |
390 auto_resize_mode_(false), | 405 auto_resize_mode_(false), |
391 need_update_rect_for_auto_resize_(false), | 406 need_update_rect_for_auto_resize_(false), |
392 did_show_(false), | 407 did_show_(false), |
393 is_hidden_(hidden), | 408 is_hidden_(hidden), |
394 never_visible_(never_visible), | 409 never_visible_(never_visible), |
395 is_fullscreen_(false), | 410 is_fullscreen_(false), |
396 has_focus_(false), | 411 has_focus_(false), |
397 handling_input_event_(false), | 412 handling_input_event_(false), |
398 handling_ime_event_(false), | 413 handling_ime_event_(false), |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
644 | 659 |
645 // If given a messsage without a routing ID, then assign our routing ID. | 660 // If given a messsage without a routing ID, then assign our routing ID. |
646 if (message->routing_id() == MSG_ROUTING_NONE) | 661 if (message->routing_id() == MSG_ROUTING_NONE) |
647 message->set_routing_id(routing_id_); | 662 message->set_routing_id(routing_id_); |
648 | 663 |
649 return RenderThread::Get()->Send(message); | 664 return RenderThread::Get()->Send(message); |
650 } | 665 } |
651 | 666 |
652 void RenderWidget::Resize(const gfx::Size& new_size, | 667 void RenderWidget::Resize(const gfx::Size& new_size, |
653 const gfx::Size& physical_backing_size, | 668 const gfx::Size& physical_backing_size, |
654 float top_controls_layout_height, | 669 bool top_controls_shrink_blink_size, |
670 float top_controls_height, | |
655 const gfx::Size& visible_viewport_size, | 671 const gfx::Size& visible_viewport_size, |
656 const gfx::Rect& resizer_rect, | 672 const gfx::Rect& resizer_rect, |
657 bool is_fullscreen, | 673 bool is_fullscreen, |
658 ResizeAck resize_ack) { | 674 ResizeAck resize_ack) { |
659 if (resizing_mode_selector_->NeverUsesSynchronousResize()) { | 675 if (resizing_mode_selector_->NeverUsesSynchronousResize()) { |
660 // A resize ack shouldn't be requested if we have not ACK'd the previous | 676 // A resize ack shouldn't be requested if we have not ACK'd the previous |
661 // one. | 677 // one. |
662 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack()); | 678 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack()); |
663 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK); | 679 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK); |
664 } | 680 } |
665 | 681 |
666 // Ignore this during shutdown. | 682 // Ignore this during shutdown. |
667 if (!webwidget_) | 683 if (!webwidget_) |
668 return; | 684 return; |
669 | 685 |
670 if (compositor_) { | 686 if (compositor_) { |
671 compositor_->setViewportSize(new_size, physical_backing_size); | 687 compositor_->setViewportSize(new_size, physical_backing_size); |
672 compositor_->SetTopControlsLayoutHeight(top_controls_layout_height); | 688 compositor_->SetTopControlsShrinkBlinkSize(top_controls_shrink_blink_size); |
689 compositor_->SetTopControlsHeight(top_controls_height); | |
673 } | 690 } |
674 | 691 |
675 physical_backing_size_ = physical_backing_size; | 692 physical_backing_size_ = physical_backing_size; |
676 top_controls_layout_height_ = top_controls_layout_height; | 693 top_controls_shrink_blink_size_ = top_controls_shrink_blink_size; |
694 top_controls_height_ = top_controls_height; | |
677 visible_viewport_size_ = visible_viewport_size; | 695 visible_viewport_size_ = visible_viewport_size; |
678 resizer_rect_ = resizer_rect; | 696 resizer_rect_ = resizer_rect; |
679 | 697 |
680 // NOTE: We may have entered fullscreen mode without changing our size. | 698 // NOTE: We may have entered fullscreen mode without changing our size. |
681 bool fullscreen_change = is_fullscreen_ != is_fullscreen; | 699 bool fullscreen_change = is_fullscreen_ != is_fullscreen; |
682 if (fullscreen_change) | 700 if (fullscreen_change) |
683 WillToggleFullscreen(); | 701 WillToggleFullscreen(); |
684 is_fullscreen_ = is_fullscreen; | 702 is_fullscreen_ = is_fullscreen; |
685 | 703 |
686 webwidget_->setTopControlsLayoutHeight(top_controls_layout_height); | 704 webwidget_->setTopControlsLayoutHeight(top_controls_shrink_blink_size_ |
705 ? static_cast<float>(top_controls_height) : 0.f); | |
aelias_OOO_until_Jul13
2014/11/21 04:19:21
static_cast<float> seems to do nothing here?
David Trainor- moved to gerrit
2014/11/22 00:35:30
Done.
| |
687 | 706 |
688 if (size_ != new_size) { | 707 if (size_ != new_size) { |
689 size_ = new_size; | 708 size_ = new_size; |
690 | 709 |
691 // When resizing, we want to wait to paint before ACK'ing the resize. This | 710 // When resizing, we want to wait to paint before ACK'ing the resize. This |
692 // ensures that we only resize as fast as we can paint. We only need to | 711 // ensures that we only resize as fast as we can paint. We only need to |
693 // send an ACK if we are resized to a non-empty rect. | 712 // send an ACK if we are resized to a non-empty rect. |
694 webwidget_->resize(new_size); | 713 webwidget_->resize(new_size); |
695 } else if (!resizing_mode_selector_->is_synchronous_mode()) { | 714 } else if (!resizing_mode_selector_->is_synchronous_mode()) { |
696 resize_ack = NO_RESIZE_ACK; | 715 resize_ack = NO_RESIZE_ACK; |
(...skipping 19 matching lines...) Expand all Loading... | |
716 // If a resize ack is requested and it isn't set-up, then no more resizes will | 735 // If a resize ack is requested and it isn't set-up, then no more resizes will |
717 // come in and in general things will go wrong. | 736 // come in and in general things will go wrong. |
718 DCHECK(resize_ack != SEND_RESIZE_ACK || next_paint_is_resize_ack()); | 737 DCHECK(resize_ack != SEND_RESIZE_ACK || next_paint_is_resize_ack()); |
719 } | 738 } |
720 | 739 |
721 void RenderWidget::ResizeSynchronously( | 740 void RenderWidget::ResizeSynchronously( |
722 const gfx::Rect& new_position, | 741 const gfx::Rect& new_position, |
723 const gfx::Size& visible_viewport_size) { | 742 const gfx::Size& visible_viewport_size) { |
724 Resize(new_position.size(), | 743 Resize(new_position.size(), |
725 new_position.size(), | 744 new_position.size(), |
726 top_controls_layout_height_, | 745 top_controls_shrink_blink_size_, |
746 top_controls_height_, | |
727 visible_viewport_size, | 747 visible_viewport_size, |
728 gfx::Rect(), | 748 gfx::Rect(), |
729 is_fullscreen_, | 749 is_fullscreen_, |
730 NO_RESIZE_ACK); | 750 NO_RESIZE_ACK); |
731 view_screen_rect_ = new_position; | 751 view_screen_rect_ = new_position; |
732 window_screen_rect_ = new_position; | 752 window_screen_rect_ = new_position; |
733 if (!did_show_) | 753 if (!did_show_) |
734 initial_pos_ = new_position; | 754 initial_pos_ = new_position; |
735 } | 755 } |
736 | 756 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
772 if (screen_metrics_emulator_) { | 792 if (screen_metrics_emulator_) { |
773 screen_metrics_emulator_->OnResizeMessage(params); | 793 screen_metrics_emulator_->OnResizeMessage(params); |
774 return; | 794 return; |
775 } | 795 } |
776 | 796 |
777 bool orientation_changed = | 797 bool orientation_changed = |
778 screen_info_.orientationAngle != params.screen_info.orientationAngle; | 798 screen_info_.orientationAngle != params.screen_info.orientationAngle; |
779 | 799 |
780 screen_info_ = params.screen_info; | 800 screen_info_ = params.screen_info; |
781 SetDeviceScaleFactor(screen_info_.deviceScaleFactor); | 801 SetDeviceScaleFactor(screen_info_.deviceScaleFactor); |
782 Resize(params.new_size, params.physical_backing_size, | 802 Resize(params.new_size, |
783 params.top_controls_layout_height, | 803 params.physical_backing_size, |
784 params.visible_viewport_size, params.resizer_rect, | 804 params.top_controls_shrink_blink_size, |
785 params.is_fullscreen, SEND_RESIZE_ACK); | 805 params.top_controls_height, |
806 params.visible_viewport_size, | |
807 params.resizer_rect, | |
808 params.is_fullscreen, | |
809 SEND_RESIZE_ACK); | |
786 | 810 |
787 if (orientation_changed) | 811 if (orientation_changed) |
788 OnOrientationChange(); | 812 OnOrientationChange(); |
789 } | 813 } |
790 | 814 |
791 void RenderWidget::OnColorProfile(const std::vector<char>& color_profile) { | 815 void RenderWidget::OnColorProfile(const std::vector<char>& color_profile) { |
792 SetDeviceColorProfile(color_profile); | 816 SetDeviceColorProfile(color_profile); |
793 } | 817 } |
794 | 818 |
795 void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) { | 819 void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) { |
(...skipping 1456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2252 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { | 2276 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { |
2253 video_hole_frames_.AddObserver(frame); | 2277 video_hole_frames_.AddObserver(frame); |
2254 } | 2278 } |
2255 | 2279 |
2256 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { | 2280 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { |
2257 video_hole_frames_.RemoveObserver(frame); | 2281 video_hole_frames_.RemoveObserver(frame); |
2258 } | 2282 } |
2259 #endif // defined(VIDEO_HOLE) | 2283 #endif // defined(VIDEO_HOLE) |
2260 | 2284 |
2261 } // namespace content | 2285 } // namespace content |
OLD | NEW |