Commit f018aaad authored by paulmeyer's avatar paulmeyer Committed by Commit bot

Fixed a bug that caused extension options not to fit their overlays properly when zoomed.

The issue involved a discrepancy between sizes specified in logical versus physical pixels. See https://codereview.chromium.org/939443002/ for an explanation on a very similar bugfix, which this CL utilizes.

BUG=459266

Review URL: https://codereview.chromium.org/934303003

Cr-Commit-Position: refs/heads/master@{#317113}
parent 40e8ee4f
......@@ -127,8 +127,14 @@ cr.define('extensions', function() {
extensionoptions.onpreferredsizechanged = function(evt) {
var oldWidth = parseInt(overlayStyle.width, 10);
var oldHeight = parseInt(overlayStyle.height, 10);
var newWidth = Math.max(evt.width, minWidth);
var newHeight = Math.min(evt.height, maxHeight);
// The overlay must be slightly larger than the extension options to
// avoid creating scrollbars.
// TODO(paulmeyer): This shouldn't be necessary, but the preferred size
// (coming from Blink) seems to be too small for some zoom levels. The
// 2-pixel addition should be removed once this problem is investigated
// and corrected.
var newWidth = Math.max(evt.width + 2, minWidth);
var newHeight = Math.min(evt.height + 2, maxHeight);
// animationTime is the amount of time in ms that will be used to resize
// the overlay. It is calculated by multiplying the pythagorean distance
......
......@@ -162,8 +162,9 @@ bool ExtensionOptionsGuest::IsPreferredSizeModeEnabled() const {
void ExtensionOptionsGuest::OnPreferredSizeChanged(const gfx::Size& pref_size) {
extension_options_internal::PreferredSizeChangedOptions options;
options.width = pref_size.width();
options.height = pref_size.height();
// Convert the size from physical pixels to logical pixels.
options.width = PhysicalPixelsToLogicalPixels(pref_size.width());
options.height = PhysicalPixelsToLogicalPixels(pref_size.height());
DispatchEventToView(new GuestViewBase::Event(
extension_options_internal::OnPreferredSizeChanged::kEventName,
options.ToValue()));
......
......@@ -510,6 +510,18 @@ void GuestViewBase::WillAttach(content::WebContents* embedder_web_contents,
WillAttachToEmbedder();
}
int GuestViewBase::LogicalPixelsToPhysicalPixels(double logical_pixels) {
DCHECK(logical_pixels >= 0);
double zoom_factor = GetEmbedderZoomFactor();
return lround(logical_pixels * zoom_factor);
}
double GuestViewBase::PhysicalPixelsToLogicalPixels(int physical_pixels) {
DCHECK(physical_pixels >= 0);
double zoom_factor = GetEmbedderZoomFactor();
return physical_pixels / zoom_factor;
}
void GuestViewBase::DidStopLoading(content::RenderViewHost* render_view_host) {
if (IsPreferredSizeModeEnabled()) {
render_view_host->EnablePreferredSizeMode();
......@@ -731,18 +743,6 @@ double GuestViewBase::GetEmbedderZoomFactor() {
return zoom_factor;
}
int GuestViewBase::LogicalPixelsToPhysicalPixels(double logical_pixels) {
DCHECK(logical_pixels >= 0);
double zoom_factor = GetEmbedderZoomFactor();
return static_cast<int>(logical_pixels * zoom_factor + 0.5);
}
double GuestViewBase::PhysicalPixelsToLogicalPixels(int physical_pixels) {
DCHECK(physical_pixels >= 0);
double zoom_factor = GetEmbedderZoomFactor();
return physical_pixels * zoom_factor;
}
void GuestViewBase::SetUpSizing(const base::DictionaryValue& params) {
// Read the autosize parameters passed in from the embedder.
bool auto_size_enabled = false;
......
......@@ -293,6 +293,20 @@ class GuestViewBase : public content::BrowserPluginGuestDelegate,
~GuestViewBase() override;
// Convert sizes in pixels from logical to physical numbers of pixels.
// Note that a size can consist of a fractional number of logical pixels
// (hence |logical_pixels| is represented as a double), but will always
// consist of an integral number of physical pixels (hence the return value
// is represented as an int).
int LogicalPixelsToPhysicalPixels(double logical_pixels);
// Convert sizes in pixels from physical to logical numbers of pixels.
// Note that a size can consist of a fractional number of logical pixels
// (hence the return value is represented as a double), but will always
// consist of an integral number of physical pixels (hence |physical_pixels|
// is represented as an int).
double PhysicalPixelsToLogicalPixels(int physical_pixels);
// WebContentsObserver implementation.
void DidStopLoading(content::RenderViewHost* render_view_host) final;
void RenderViewReady() final;
......@@ -343,20 +357,6 @@ class GuestViewBase : public content::BrowserPluginGuestDelegate,
// Get the zoom factor for the embedder's web contents.
double GetEmbedderZoomFactor();
// Convert sizes in pixels from logical to physical numbers of pixels.
// Note that a size can consist of a fractional number of logical pixels
// (hence |logical_pixels| is represented as a double), but will always
// consist of an integral number of physical pixels (hence the return value
// is represented as an int).
int LogicalPixelsToPhysicalPixels(double logical_pixels);
// Convert sizes in pixels from physical to logical numbers of pixels.
// Note that a size can consist of a fractional number of logical pixels
// (hence the return value is represented as a double), but will always
// consist of an integral number of physical pixels (hence |physical_pixels|
// is represented as an int).
double PhysicalPixelsToLogicalPixels(int physical_pixels);
void SetUpSizing(const base::DictionaryValue& params);
void StartTrackingEmbedderZoomLevel();
......
......@@ -12,8 +12,8 @@ namespace extensionOptionsInternal {
};
dictionary PreferredSizeChangedOptions {
long width;
long height;
double width;
double height;
};
interface Events {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment