Skip to content

Commit

Permalink
Fixed the incorrect PDF sizing on emulated devices in devtools.
Browse files Browse the repository at this point in the history
BUG=474191

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

Cr-Commit-Position: refs/heads/master@{#324753}
  • Loading branch information
paulmeyer90 authored and Commit bot committed Apr 11, 2015
1 parent 247624d commit cd7a39a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 37 deletions.
67 changes: 34 additions & 33 deletions extensions/browser/guest_view/guest_view_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,17 @@ void GuestViewBase::DispatchOnResizeEvent(const gfx::Size& old_size,
DispatchEventToGuestProxy(new Event(guestview::kEventResize, args.Pass()));
}

gfx::Size GuestViewBase::GetDefaultSize() const {
if (is_full_page_plugin()) {
// Full page plugins default to the size of the owner's viewport.
return owner_web_contents()
->GetRenderWidgetHostView()
->GetVisibleViewportSize();
} else {
return gfx::Size(guestview::kDefaultWidth, guestview::kDefaultHeight);
}
}

void GuestViewBase::SetSize(const SetSizeParams& params) {
bool enable_auto_size =
params.enable_auto_size ? *params.enable_auto_size : auto_size_enabled_;
Expand All @@ -321,17 +332,17 @@ void GuestViewBase::SetSize(const SetSizeParams& params) {
// Autosize is being disabled.
// Use default width/height if missing from partially defined normal size.
if (normal_size_.width() && !normal_size_.height())
normal_size_.set_height(guestview::kDefaultHeight);
normal_size_.set_height(GetDefaultSize().height());
if (!normal_size_.width() && normal_size_.height())
normal_size_.set_width(guestview::kDefaultWidth);
normal_size_.set_width(GetDefaultSize().width());

gfx::Size new_size;
if (!normal_size_.IsEmpty()) {
new_size = normal_size_;
} else if (!guest_size_.IsEmpty()) {
new_size = guest_size_;
} else {
new_size = gfx::Size(guestview::kDefaultWidth, guestview::kDefaultHeight);
new_size = GetDefaultSize();
}

if (auto_size_enabled_) {
Expand Down Expand Up @@ -546,13 +557,13 @@ void GuestViewBase::WillAttach(content::WebContents* embedder_web_contents,
WillAttachToEmbedder();
}

int GuestViewBase::LogicalPixelsToPhysicalPixels(double logical_pixels) {
int GuestViewBase::LogicalPixelsToPhysicalPixels(double logical_pixels) const {
DCHECK(logical_pixels >= 0);
double zoom_factor = GetEmbedderZoomFactor();
return lround(logical_pixels * zoom_factor);
}

double GuestViewBase::PhysicalPixelsToLogicalPixels(int physical_pixels) {
double GuestViewBase::PhysicalPixelsToLogicalPixels(int physical_pixels) const {
DCHECK(physical_pixels >= 0);
double zoom_factor = GetEmbedderZoomFactor();
return physical_pixels / zoom_factor;
Expand Down Expand Up @@ -784,7 +795,7 @@ void GuestViewBase::CompleteInit(
callback.Run(guest_web_contents);
}

double GuestViewBase::GetEmbedderZoomFactor() {
double GuestViewBase::GetEmbedderZoomFactor() const {
if (!embedder_web_contents())
return 1.0;

Expand All @@ -808,36 +819,26 @@ void GuestViewBase::SetUpSizing(const base::DictionaryValue& params) {
params.GetInteger(guestview::kAttributeMinHeight, &min_height);
params.GetInteger(guestview::kAttributeMinWidth, &min_width);

double element_height = 0.0;
double element_width = 0.0;
params.GetDouble(guestview::kElementHeight, &element_height);
params.GetDouble(guestview::kElementWidth, &element_width);

// Set the normal size to the element size so that the guestview will fit
// the element initially if autosize is disabled.
int normal_height = normal_size_.height();
int normal_width = normal_size_.width();
if (is_full_page_plugin()) {
// The initial size of a full page plugin should be set to fill the
// owner's visible viewport.
auto owner_size = owner_web_contents()->GetRenderWidgetHostView()->
GetVisibleViewportSize();
normal_height = owner_size.height();
normal_width = owner_size.width();
// If the element size was provided in logical units (versus physical), then
// it will be converted to physical units.
bool element_size_is_logical = false;
params.GetBoolean(guestview::kElementSizeIsLogical, &element_size_is_logical);
if (element_size_is_logical) {
// Convert the element size from logical pixels to physical pixels.
normal_height = LogicalPixelsToPhysicalPixels(element_height);
normal_width = LogicalPixelsToPhysicalPixels(element_width);
} else {
// Set the normal size to the element size so that the guestview will fit
// the element initially if autosize is disabled.
double element_height = 0.0;
double element_width = 0.0;
params.GetDouble(guestview::kElementHeight, &element_height);
params.GetDouble(guestview::kElementWidth, &element_width);

// If the element size was provided in logical units (versus physical), then
// it will be converted to physical units.
bool element_size_is_logical = false;
params.GetBoolean(guestview::kElementSizeIsLogical,
&element_size_is_logical);
if (element_size_is_logical) {
// Convert the element size from logical pixels to physical pixels.
normal_height = LogicalPixelsToPhysicalPixels(element_height);
normal_width = LogicalPixelsToPhysicalPixels(element_width);
} else {
normal_height = lround(element_height);
normal_width = lround(element_width);
}
normal_height = lround(element_height);
normal_width = lround(element_width);
}

SetSizeParams set_size_params;
Expand Down
11 changes: 7 additions & 4 deletions extensions/browser/guest_view/guest_view_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ class GuestViewBase : public content::BrowserPluginGuestDelegate,
const GURL& GetOwnerSiteURL() const;

// Whether the guest view is inside a plugin document.
bool is_full_page_plugin() { return is_full_page_plugin_; }
bool is_full_page_plugin() const { return is_full_page_plugin_; }

// Returns the routing ID of the guest proxy in the owner's renderer process.
// This value is only valid after attachment or first navigation.
Expand Down Expand Up @@ -321,14 +321,14 @@ class GuestViewBase : public content::BrowserPluginGuestDelegate,
// (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);
int LogicalPixelsToPhysicalPixels(double logical_pixels) const;

// 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);
double PhysicalPixelsToLogicalPixels(int physical_pixels) const;

// WebContentsObserver implementation.
void DidStopLoading() final;
Expand Down Expand Up @@ -382,8 +382,11 @@ class GuestViewBase : public content::BrowserPluginGuestDelegate,
void DispatchOnResizeEvent(const gfx::Size& old_size,
const gfx::Size& new_size);

// Returns the default size of the guestview.
gfx::Size GetDefaultSize() const;

// Get the zoom factor for the embedder's web contents.
double GetEmbedderZoomFactor();
double GetEmbedderZoomFactor() const;

void SetUpSizing(const base::DictionaryValue& params);

Expand Down

0 comments on commit cd7a39a

Please sign in to comment.