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 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
503 } | 503 } |
504 | 504 |
505 // Start tracking the new embedder's zoom level. | 505 // Start tracking the new embedder's zoom level. |
506 StartTrackingEmbedderZoomLevel(); | 506 StartTrackingEmbedderZoomLevel(); |
507 element_instance_id_ = element_instance_id; | 507 element_instance_id_ = element_instance_id; |
508 is_full_page_plugin_ = is_full_page_plugin; | 508 is_full_page_plugin_ = is_full_page_plugin; |
509 | 509 |
510 WillAttachToEmbedder(); | 510 WillAttachToEmbedder(); |
511 } | 511 } |
512 | 512 |
513 int GuestViewBase::LogicalPixelsToPhysicalPixels(double logical_pixels) { | |
514 DCHECK(logical_pixels >= 0); | |
515 double zoom_factor = GetEmbedderZoomFactor(); | |
516 return static_cast<int>(logical_pixels * zoom_factor + 0.5); | |
517 } | |
518 | |
519 double GuestViewBase::PhysicalPixelsToLogicalPixels(int physical_pixels) { | |
520 DCHECK(physical_pixels >= 0); | |
521 double zoom_factor = GetEmbedderZoomFactor(); | |
522 return static_cast<int>(physical_pixels / zoom_factor + 0.5); | |
Fady Samuel
2015/02/18 18:27:31
Why are you casting to int here and then returning
paulmeyer
2015/02/19 18:42:58
Done.
| |
523 } | |
524 | |
513 void GuestViewBase::DidStopLoading(content::RenderViewHost* render_view_host) { | 525 void GuestViewBase::DidStopLoading(content::RenderViewHost* render_view_host) { |
514 if (IsPreferredSizeModeEnabled()) { | 526 if (IsPreferredSizeModeEnabled()) { |
515 render_view_host->EnablePreferredSizeMode(); | 527 render_view_host->EnablePreferredSizeMode(); |
516 } | 528 } |
517 if (!IsDragAndDropEnabled()) { | 529 if (!IsDragAndDropEnabled()) { |
518 const char script[] = "window.addEventListener('dragstart', function() { " | 530 const char script[] = "window.addEventListener('dragstart', function() { " |
519 " window.event.preventDefault(); " | 531 " window.event.preventDefault(); " |
520 "});"; | 532 "});"; |
521 render_view_host->GetMainFrame()->ExecuteJavaScript( | 533 render_view_host->GetMainFrame()->ExecuteJavaScript( |
522 base::ASCIIToUTF16(script)); | 534 base::ASCIIToUTF16(script)); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
724 auto zoom_controller = | 736 auto zoom_controller = |
725 ui_zoom::ZoomController::FromWebContents(embedder_web_contents()); | 737 ui_zoom::ZoomController::FromWebContents(embedder_web_contents()); |
726 if (!zoom_controller) | 738 if (!zoom_controller) |
727 return 1.0; | 739 return 1.0; |
728 | 740 |
729 double zoom_factor = | 741 double zoom_factor = |
730 content::ZoomLevelToZoomFactor(zoom_controller->GetZoomLevel()); | 742 content::ZoomLevelToZoomFactor(zoom_controller->GetZoomLevel()); |
731 return zoom_factor; | 743 return zoom_factor; |
732 } | 744 } |
733 | 745 |
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 | |
746 void GuestViewBase::SetUpSizing(const base::DictionaryValue& params) { | 746 void GuestViewBase::SetUpSizing(const base::DictionaryValue& params) { |
747 // Read the autosize parameters passed in from the embedder. | 747 // Read the autosize parameters passed in from the embedder. |
748 bool auto_size_enabled = false; | 748 bool auto_size_enabled = false; |
749 params.GetBoolean(guestview::kAttributeAutoSize, &auto_size_enabled); | 749 params.GetBoolean(guestview::kAttributeAutoSize, &auto_size_enabled); |
750 | 750 |
751 int max_height = 0; | 751 int max_height = 0; |
752 int max_width = 0; | 752 int max_width = 0; |
753 params.GetInteger(guestview::kAttributeMaxHeight, &max_height); | 753 params.GetInteger(guestview::kAttributeMaxHeight, &max_height); |
754 params.GetInteger(guestview::kAttributeMaxWidth, &max_width); | 754 params.GetInteger(guestview::kAttributeMaxWidth, &max_width); |
755 | 755 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
811 void GuestViewBase::RegisterGuestViewTypes() { | 811 void GuestViewBase::RegisterGuestViewTypes() { |
812 AppViewGuest::Register(); | 812 AppViewGuest::Register(); |
813 ExtensionOptionsGuest::Register(); | 813 ExtensionOptionsGuest::Register(); |
814 ExtensionViewGuest::Register(); | 814 ExtensionViewGuest::Register(); |
815 MimeHandlerViewGuest::Register(); | 815 MimeHandlerViewGuest::Register(); |
816 SurfaceWorkerGuest::Register(); | 816 SurfaceWorkerGuest::Register(); |
817 WebViewGuest::Register(); | 817 WebViewGuest::Register(); |
818 } | 818 } |
819 | 819 |
820 } // namespace extensions | 820 } // namespace extensions |
OLD | NEW |