OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/guest_view/guest_view_base.h" | 5 #include "extensions/browser/guest_view/guest_view_base.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "components/ui/zoom/page_zoom.h" | 9 #include "components/ui/zoom/page_zoom.h" |
10 #include "components/ui/zoom/zoom_controller.h" | 10 #include "components/ui/zoom/zoom_controller.h" |
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 // The derived class did not create a WebContents so this class serves no | 710 // The derived class did not create a WebContents so this class serves no |
711 // purpose. Let's self-destruct. | 711 // purpose. Let's self-destruct. |
712 delete this; | 712 delete this; |
713 callback.Run(nullptr); | 713 callback.Run(nullptr); |
714 return; | 714 return; |
715 } | 715 } |
716 InitWithWebContents(*create_params, guest_web_contents); | 716 InitWithWebContents(*create_params, guest_web_contents); |
717 callback.Run(guest_web_contents); | 717 callback.Run(guest_web_contents); |
718 } | 718 } |
719 | 719 |
| 720 double GuestViewBase::GetEmbedderZoomFactor() { |
| 721 if (!embedder_web_contents()) |
| 722 return 1.0; |
| 723 |
| 724 auto zoom_controller = |
| 725 ui_zoom::ZoomController::FromWebContents(embedder_web_contents()); |
| 726 if (!zoom_controller) |
| 727 return 1.0; |
| 728 |
| 729 double zoom_factor = |
| 730 content::ZoomLevelToZoomFactor(zoom_controller->GetZoomLevel()); |
| 731 return zoom_factor; |
| 732 } |
| 733 |
| 734 int GuestViewBase::LogicalPixelsToPhysicalPixels(double logical_pixels) { |
| 735 DCHECK(logical_pixels >= 0); |
| 736 double zoom_factor = GetEmbedderZoomFactor(); |
| 737 return static_cast<int>(logical_pixels * zoom_factor + 0.5); |
| 738 } |
| 739 |
| 740 double GuestViewBase::PhysicalPixelsToLogicalPixels(int physical_pixels) { |
| 741 DCHECK(physical_pixels >= 0); |
| 742 double zoom_factor = GetEmbedderZoomFactor(); |
| 743 return physical_pixels * zoom_factor; |
| 744 } |
| 745 |
720 void GuestViewBase::SetUpSizing(const base::DictionaryValue& params) { | 746 void GuestViewBase::SetUpSizing(const base::DictionaryValue& params) { |
721 // Read the autosize parameters passed in from the embedder. | 747 // Read the autosize parameters passed in from the embedder. |
722 bool auto_size_enabled = false; | 748 bool auto_size_enabled = false; |
723 params.GetBoolean(guestview::kAttributeAutoSize, &auto_size_enabled); | 749 params.GetBoolean(guestview::kAttributeAutoSize, &auto_size_enabled); |
724 | 750 |
725 int max_height = 0; | 751 int max_height = 0; |
726 int max_width = 0; | 752 int max_width = 0; |
727 params.GetInteger(guestview::kAttributeMaxHeight, &max_height); | 753 params.GetInteger(guestview::kAttributeMaxHeight, &max_height); |
728 params.GetInteger(guestview::kAttributeMaxWidth, &max_width); | 754 params.GetInteger(guestview::kAttributeMaxWidth, &max_width); |
729 | 755 |
730 int min_height = 0; | 756 int min_height = 0; |
731 int min_width = 0; | 757 int min_width = 0; |
732 params.GetInteger(guestview::kAttributeMinHeight, &min_height); | 758 params.GetInteger(guestview::kAttributeMinHeight, &min_height); |
733 params.GetInteger(guestview::kAttributeMinWidth, &min_width); | 759 params.GetInteger(guestview::kAttributeMinWidth, &min_width); |
734 | 760 |
735 // Set the normal size to the element size so that the guestview will fit the | 761 // Set the normal size to the element size so that the guestview will fit the |
736 // element initially if autosize is disabled. | 762 // element initially if autosize is disabled. |
737 int normal_height = 0; | 763 double element_height = 0.0; |
738 int normal_width = 0; | 764 double element_width = 0.0; |
739 params.GetInteger(guestview::kElementHeight, &normal_height); | 765 params.GetDouble(guestview::kElementHeight, &element_height); |
740 params.GetInteger(guestview::kElementWidth, &normal_width); | 766 params.GetDouble(guestview::kElementWidth, &element_width); |
| 767 // Convert the element size from logical pixels to physical pixels. |
| 768 int normal_height = LogicalPixelsToPhysicalPixels(element_height); |
| 769 int normal_width = LogicalPixelsToPhysicalPixels(element_width); |
741 | 770 |
742 SetSizeParams set_size_params; | 771 SetSizeParams set_size_params; |
743 set_size_params.enable_auto_size.reset(new bool(auto_size_enabled)); | 772 set_size_params.enable_auto_size.reset(new bool(auto_size_enabled)); |
744 set_size_params.min_size.reset(new gfx::Size(min_width, min_height)); | 773 set_size_params.min_size.reset(new gfx::Size(min_width, min_height)); |
745 set_size_params.max_size.reset(new gfx::Size(max_width, max_height)); | 774 set_size_params.max_size.reset(new gfx::Size(max_width, max_height)); |
746 set_size_params.normal_size.reset(new gfx::Size(normal_width, normal_height)); | 775 set_size_params.normal_size.reset(new gfx::Size(normal_width, normal_height)); |
747 | 776 |
748 // Call SetSize to apply all the appropriate validation and clipping of | 777 // Call SetSize to apply all the appropriate validation and clipping of |
749 // values. | 778 // values. |
750 SetSize(set_size_params); | 779 SetSize(set_size_params); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 void GuestViewBase::RegisterGuestViewTypes() { | 811 void GuestViewBase::RegisterGuestViewTypes() { |
783 AppViewGuest::Register(); | 812 AppViewGuest::Register(); |
784 ExtensionOptionsGuest::Register(); | 813 ExtensionOptionsGuest::Register(); |
785 ExtensionViewGuest::Register(); | 814 ExtensionViewGuest::Register(); |
786 MimeHandlerViewGuest::Register(); | 815 MimeHandlerViewGuest::Register(); |
787 SurfaceWorkerGuest::Register(); | 816 SurfaceWorkerGuest::Register(); |
788 WebViewGuest::Register(); | 817 WebViewGuest::Register(); |
789 } | 818 } |
790 | 819 |
791 } // namespace extensions | 820 } // namespace extensions |
OLD | NEW |