Skip to content

Commit

Permalink
Make pinch-zoom work for OOP PDF
Browse files Browse the repository at this point in the history
There are two changes to make this work:
-Set the plugins width/height to 100%. We will soon be using this for the material layout as well.
-Allow MimeHandlerViewGuests to handle pinch gestures when they are full-page plugins.

BUG=453729

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

Cr-Commit-Position: refs/heads/master@{#314742}
  • Loading branch information
raymes authored and Commit bot committed Feb 5, 2015
1 parent 7208f4b commit f0db15c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 14 deletions.
2 changes: 2 additions & 0 deletions chrome/browser/resources/pdf/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ viewer-password-screen {
}

#plugin {
height: 100%;
position: fixed;
width: 100%;
z-index: 1;
}

Expand Down
18 changes: 5 additions & 13 deletions chrome/browser/resources/pdf/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ function PDFViewer(streamDetails) {
this.plugin_.type = 'application/x-google-chrome-pdf';
this.plugin_.addEventListener('message', this.handlePluginMessage_.bind(this),
false);
this.plugin_.style.height =
(window.innerHeight - this.toolbarHeight_) + 'px';
this.plugin_.style.width = window.innerWidth + 'px';

if (this.isMaterial_)
this.plugin_.setAttribute('is-material', '');
Expand Down Expand Up @@ -580,16 +577,6 @@ PDFViewer.prototype = {
* A callback that's called after the viewport changes.
*/
viewportChanged_: function() {
var hasScrollbars = this.viewport_.documentHasScrollbars();
var scrollbarWidth = this.viewport_.scrollbarWidth;
var verticalScrollbarWidth = hasScrollbars.vertical ? scrollbarWidth : 0;
var horizontalScrollbarWidth =
hasScrollbars.horizontal ? scrollbarWidth : 0;
this.plugin_.style.width =
(window.innerWidth - verticalScrollbarWidth) + 'px';
this.plugin_.style.height = (window.innerHeight -
horizontalScrollbarWidth - this.toolbarHeight_) + 'px';

if (!this.documentDimensions_)
return;

Expand All @@ -604,6 +591,11 @@ PDFViewer.prototype = {
}

// Offset the toolbar position so that it doesn't move if scrollbars appear.
var hasScrollbars = this.viewport_.documentHasScrollbars();
var scrollbarWidth = this.viewport_.scrollbarWidth;
var verticalScrollbarWidth = hasScrollbars.vertical ? scrollbarWidth : 0;
var horizontalScrollbarWidth =
hasScrollbars.horizontal ? scrollbarWidth : 0;
var toolbarRight = Math.max(PDFViewer.MIN_TOOLBAR_OFFSET, scrollbarWidth);
var toolbarBottom = Math.max(PDFViewer.MIN_TOOLBAR_OFFSET, scrollbarWidth);
toolbarRight -= verticalScrollbarWidth;
Expand Down
2 changes: 1 addition & 1 deletion extensions/browser/guest_view/guest_view_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ class GuestViewBase : public content::BrowserPluginGuestDelegate,
const content::FileChooserParams& params) override;
bool ShouldFocusPageAfterCrash() final;
bool PreHandleGestureEvent(content::WebContents* source,
const blink::WebGestureEvent& event) final;
const blink::WebGestureEvent& event) override;
void UpdatePreferredSize(content::WebContents* web_contents,
const gfx::Size& pref_size) final;
void UpdateTargetURL(content::WebContents* source, const GURL& url) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "extensions/strings/grit/extensions_strings.h"
#include "ipc/ipc_message_macros.h"
#include "net/base/url_util.h"
#include "third_party/WebKit/public/web/WebInputEvent.h"

using content::WebContents;

Expand Down Expand Up @@ -187,6 +188,19 @@ bool MimeHandlerViewGuest::HandleContextMenu(
return false;
}

bool MimeHandlerViewGuest::PreHandleGestureEvent(
content::WebContents* source,
const blink::WebGestureEvent& event) {
if (event.type == blink::WebGestureEvent::GesturePinchBegin ||
event.type == blink::WebGestureEvent::GesturePinchUpdate ||
event.type == blink::WebGestureEvent::GesturePinchEnd) {
// If we're an embedded plugin we drop pinch-gestures to avoid zooming the
// guest.
return !is_full_page_plugin();
}
return false;
}

void MimeHandlerViewGuest::FindReply(content::WebContents* web_contents,
int request_id,
int number_of_matches,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class MimeHandlerViewGuest : public GuestView<MimeHandlerViewGuest>,
content::WebContents* source,
const content::OpenURLParams& params) override;
bool HandleContextMenu(const content::ContextMenuParams& params) override;
bool PreHandleGestureEvent(content::WebContents* source,
const blink::WebGestureEvent& event) override;
void FindReply(content::WebContents* web_contents,
int request_id,
int number_of_matches,
Expand Down
1 change: 1 addition & 0 deletions pdf/out_of_process_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ OutOfProcessInstance::OutOfProcessInstance(PP_Instance instance)

RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_MOUSE);
RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD);
RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_TOUCH);
}

OutOfProcessInstance::~OutOfProcessInstance() {
Expand Down

0 comments on commit f0db15c

Please sign in to comment.