diff options
Diffstat (limited to 'chrome/renderer')
-rw-r--r-- | chrome/renderer/pepper_plugin_delegate_impl.cc | 24 | ||||
-rw-r--r-- | chrome/renderer/pepper_plugin_delegate_impl.h | 9 | ||||
-rw-r--r-- | chrome/renderer/render_thread.cc | 17 | ||||
-rw-r--r-- | chrome/renderer/render_thread.h | 2 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 116 | ||||
-rw-r--r-- | chrome/renderer/render_view.h | 6 |
6 files changed, 137 insertions, 37 deletions
diff --git a/chrome/renderer/pepper_plugin_delegate_impl.cc b/chrome/renderer/pepper_plugin_delegate_impl.cc index e633a64..426c15a 100644 --- a/chrome/renderer/pepper_plugin_delegate_impl.cc +++ b/chrome/renderer/pepper_plugin_delegate_impl.cc @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <cmath> + #include "chrome/renderer/pepper_plugin_delegate_impl.h" #include "app/l10n_util.h" @@ -25,6 +27,7 @@ #include "third_party/WebKit/WebKit/chromium/public/WebFileChooserCompletion.h" #include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h" #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h" +#include "third_party/WebKit/WebKit/chromium/public/WebView.h" #include "webkit/fileapi/file_system_callback_dispatcher.h" #include "webkit/glue/plugins/pepper_file_io.h" #include "webkit/glue/plugins/pepper_plugin_instance.h" @@ -35,6 +38,8 @@ #include "chrome/renderer/render_thread.h" #endif +using WebKit::WebView; + namespace { const int32 kDefaultCommandBufferSize = 1024 * 1024; @@ -612,14 +617,14 @@ PepperPluginDelegateImpl::CreateVideoDecoder( return decoder.release(); } -void PepperPluginDelegateImpl::DidChangeNumberOfFindResults(int identifier, - int total, - bool final_result) { +void PepperPluginDelegateImpl::NumberOfFindResultsChanged(int identifier, + int total, + bool final_result) { render_view_->reportFindInPageMatchCount(identifier, total, final_result); } -void PepperPluginDelegateImpl::DidChangeSelectedFindResult(int identifier, - int index) { +void PepperPluginDelegateImpl::SelectedFindResultChanged(int identifier, + int index) { render_view_->reportFindInPageSelection( identifier, index + 1, WebKit::WebRect()); } @@ -734,3 +739,12 @@ std::string PepperPluginDelegateImpl::GetDefaultEncoding() { // encoding here rather than using the global default for the UI language. return l10n_util::GetStringUTF8(IDS_DEFAULT_ENCODING); } + +void PepperPluginDelegateImpl::ZoomLimitsChanged(double minimum_factor, + double maximum_factor) { +#ifdef ZOOM_LEVEL_IS_DOUBLE + double minimum_level = WebView::zoomFactorToZoomLevel(minimum_factor); + double maximum_level = WebView::zoomFactorToZoomLevel(maximum_factor); + render_view_->webview()->zoomLimitsChanged(minimum_level, maximum_level); +#endif +} diff --git a/chrome/renderer/pepper_plugin_delegate_impl.h b/chrome/renderer/pepper_plugin_delegate_impl.h index b3b5b76..869daeb 100644 --- a/chrome/renderer/pepper_plugin_delegate_impl.h +++ b/chrome/renderer/pepper_plugin_delegate_impl.h @@ -75,10 +75,10 @@ class PepperPluginDelegateImpl virtual PlatformContext3D* CreateContext3D(); virtual PlatformVideoDecoder* CreateVideoDecoder( const PP_VideoDecoderConfig_Dev& decoder_config); - virtual void DidChangeNumberOfFindResults(int identifier, - int total, - bool final_result); - virtual void DidChangeSelectedFindResult(int identifier, int index); + virtual void NumberOfFindResultsChanged(int identifier, + int total, + bool final_result); + virtual void SelectedFindResultChanged(int identifier, int index); virtual bool RunFileChooser( const WebKit::WebFileChooserParams& params, WebKit::WebFileChooserCompletion* chooser_completion); @@ -103,6 +103,7 @@ class PepperPluginDelegateImpl virtual pepper::FullscreenContainer* CreateFullscreenContainer( pepper::PluginInstance* instance); virtual std::string GetDefaultEncoding(); + virtual void ZoomLimitsChanged(double minimum_factor, double maximum_factor); private: // Pointer to the RenderView that owns us. diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc index be4cac6..0c37652 100644 --- a/chrome/renderer/render_thread.cc +++ b/chrome/renderer/render_thread.cc @@ -78,6 +78,7 @@ #include "third_party/WebKit/WebKit/chromium/public/WebColor.h" #include "third_party/WebKit/WebKit/chromium/public/WebCrossOriginPreflightResultCache.h" #include "third_party/WebKit/WebKit/chromium/public/WebDatabase.h" +#include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" #include "third_party/WebKit/WebKit/chromium/public/WebFontCache.h" #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" #include "third_party/WebKit/WebKit/chromium/public/WebKit.h" @@ -188,21 +189,31 @@ class RenderViewContentSettingsSetter : public RenderViewVisitor { class RenderViewZoomer : public RenderViewVisitor { public: - RenderViewZoomer(const GURL& url, int zoom_level) + RenderViewZoomer(const GURL& url, double zoom_level) : zoom_level_(zoom_level) { host_ = net::GetHostOrSpecFromURL(url); } virtual bool Visit(RenderView* render_view) { WebView* webview = render_view->webview(); // Guaranteed non-NULL. + + // Don't set zoom level for full-page plugin since they don't use the same + // zoom settings. + if (webview->mainFrame()->document().isPluginDocument()) + return true; + if (net::GetHostOrSpecFromURL(GURL(webview->mainFrame()->url())) == host_) +#ifdef ZOOM_LEVEL_IS_DOUBLE webview->setZoomLevel(false, zoom_level_); +#else + webview->setZoomLevel(false, static_cast<int>(zoom_level_)); +#endif return true; } private: std::string host_; - int zoom_level_; + double zoom_level_; DISALLOW_COPY_AND_ASSIGN(RenderViewZoomer); }; @@ -506,7 +517,7 @@ void RenderThread::OnSetContentSettingsForCurrentURL( } void RenderThread::OnSetZoomLevelForCurrentURL(const GURL& url, - int zoom_level) { + double zoom_level) { RenderViewZoomer zoomer(url, zoom_level); RenderView::ForEach(&zoomer); } diff --git a/chrome/renderer/render_thread.h b/chrome/renderer/render_thread.h index 6c42b18..e4fd3ce 100644 --- a/chrome/renderer/render_thread.h +++ b/chrome/renderer/render_thread.h @@ -251,7 +251,7 @@ class RenderThread : public RenderThreadBase, void OnUpdateVisitedLinks(base::SharedMemoryHandle table); void OnAddVisitedLinks(const VisitedLinkSlave::Fingerprints& fingerprints); void OnResetVisitedLinks(); - void OnSetZoomLevelForCurrentURL(const GURL& url, int zoom_level); + void OnSetZoomLevelForCurrentURL(const GURL& url, double zoom_level); void OnSetContentSettingsForCurrentURL( const GURL& url, const ContentSettings& content_settings); void OnUpdateUserScripts(base::SharedMemoryHandle table); diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index e84fb89..3c0c57a 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -5,6 +5,7 @@ #include "chrome/renderer/render_view.h" #include <algorithm> +#include <cmath> #include <string> #include <vector> @@ -1385,17 +1386,40 @@ void RenderView::UpdateURL(WebFrame* frame) { } } - // Set zoom level. + // Set zoom level, but don't do it for full-page plugin since they don't use + // the same zoom settings. HostZoomLevels::iterator host_zoom = host_zoom_levels_.find(GURL(request.url())); + if (webview()->mainFrame()->document().isPluginDocument()) { + // Reset the zoom levels for plugins. +#ifdef ZOOM_LEVEL_IS_DOUBLE + webview()->setZoomLevel(false, 0); +#endif + } else { + if (host_zoom != host_zoom_levels_.end()) +#ifdef ZOOM_LEVEL_IS_DOUBLE + webview()->setZoomLevel(false, host_zoom->second); +#else + webview()->setZoomLevel(false, static_cast<int>(host_zoom->second)); +#endif + } + if (host_zoom != host_zoom_levels_.end()) { - webview()->setZoomLevel(false, host_zoom->second); // This zoom level was merely recorded transiently for this load. We can // erase it now. If at some point we reload this page, the browser will // send us a new, up-to-date zoom level. host_zoom_levels_.erase(host_zoom); } + // Reset the zoom limits in case a plugin had changed them previously. This + // will also call us back which will cause us to send a message to + // update TabContents. +#ifdef ZOOM_LEVEL_IS_DOUBLE + webview()->zoomLimitsChanged( + WebView::zoomFactorToZoomLevel(WebView::minTextSizeMultiplier), + WebView::zoomFactorToZoomLevel(WebView::maxTextSizeMultiplier)); +#endif + // Update contents MIME type for main frame. params.contents_mime_type = ds->response().mimeType().utf8(); @@ -3996,20 +4020,8 @@ WebPlugin* RenderView::CreatePepperPlugin(WebFrame* frame, const WebPluginParams& params, const FilePath& path, pepper::PluginModule* pepper_module) { - WebPlugin* plugin = new pepper::WebPluginImpl(pepper_module, params, - pepper_delegate_.AsWeakPtr()); - if (plugin && !frame->parent() && frame->document().isPluginDocument()) { - // If this is a full-page plugin hosting the internal PDF plugin, we want - // to notify the browser so that it can treat things like zooming - // differently. - // TODO(sanjeevr): Use a Pepper interface to determine this rather than - // hardcode this for the PDF plugin path. - FilePath pdf_path; - PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path); - if (path == pdf_path) - Send(new ViewHostMsg_SetDisplayingPDFContent(routing_id_)); - } - return plugin; + return new pepper::WebPluginImpl( + pepper_module, params, pepper_delegate_.AsWeakPtr()); } WebPlugin* RenderView::CreateNPAPIPlugin(WebFrame* frame, @@ -4066,13 +4078,36 @@ void RenderView::OnZoom(PageZoom::Function function) { webview()->hidePopups(); +#ifdef ZOOM_LEVEL_IS_DOUBLE + double old_zoom_level = webview()->zoomLevel(); + double zoom_level; + if (function == PageZoom::RESET) { + zoom_level = 0; + } else if (static_cast<int>(old_zoom_level) == old_zoom_level) { + // Previous zoom level is a whole number, so just increment/decrement. + zoom_level = old_zoom_level + function; + } else { + // Either the user hit the zoom factor limit and thus the zoom level is now + // not a whole number, or a plugin changed it to a custom value. We want + // to go to the next whole number so that the user can always get back to + // 100% with the keyboard/menu. + if ((old_zoom_level > 1 && function > 0) || + (old_zoom_level < 1 && function < 0)) { + zoom_level = abs(old_zoom_level + function); + } else { + // We're going towards 100%, so first go to the next whole number. + zoom_level = static_cast<int>(old_zoom_level); + } + } + + webview()->setZoomLevel(false, zoom_level); + zoomLevelChanged(); +#else int zoom_level = webview()->zoomLevel(); - int new_zoom_level = webview()->setZoomLevel(false, + webview()->setZoomLevel(false, (function == PageZoom::RESET) ? 0 : (zoom_level + function)); - - // Tell the browser which url got zoomed so it can update the saved values. - Send(new ViewHostMsg_DidZoomURL( - GURL(webview()->mainFrame()->url()), new_zoom_level)); + zoomLevelChanged(); +#endif } void RenderView::OnSetContentSettingsForLoadingURL( @@ -4082,7 +4117,7 @@ void RenderView::OnSetContentSettingsForLoadingURL( } void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url, - int zoom_level) { + double zoom_level) { host_zoom_levels_[url] = zoom_level; } @@ -5820,6 +5855,43 @@ WebKit::WebDeviceOrientationClient* RenderView::deviceOrientationClient() { return device_orientation_dispatcher_.get(); } +void RenderView::zoomLimitsChanged(double minimum_level, double maximum_level) { + // For now, don't remember plugin zoom values. We don't want to mix them with + // normal web content (i.e. a fixed layout plugin would usually want them + // different). + bool remember = !webview()->mainFrame()->document().isPluginDocument(); + +#ifdef ZOOM_LEVEL_IS_DOUBLE + int minimum_percent = static_cast<int>( + WebView::zoomLevelToZoomFactor(minimum_level) * 100); + int maximum_percent = static_cast<int>( + WebView::zoomLevelToZoomFactor(maximum_level) * 100); +#else + int minimum_percent = static_cast<int>(std::pow(1.2, minimum_level) * 100); + int maximum_percent = static_cast<int>(std::pow(1.2, minimum_level) * 100); +#endif + + Send(new ViewHostMsg_UpdateZoomLimits( + routing_id_, minimum_percent, maximum_percent, remember)); +} + +void RenderView::zoomLevelChanged() { + bool remember = !webview()->mainFrame()->document().isPluginDocument(); + + double zoom_level = webview()->zoomLevel(); +#ifndef ZOOM_LEVEL_IS_DOUBLE + // Clamp down since we just got an integer. + double minimum_level = log(0.5) / log(1.2); + double maximum_level = log(3.0) / log(1.2); + zoom_level = std::max(std::min(zoom_level, maximum_level), minimum_level); +#endif + + // Tell the browser which url got zoomed so it can update the menu and the + // saved values if necessary + Send(new ViewHostMsg_DidZoomURL( + routing_id_, zoom_level, remember, GURL(webview()->mainFrame()->url()))); +} + bool RenderView::IsNonLocalTopLevelNavigation( const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) { // Must be a top level frame. diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index 55fe218..2292a3c 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -437,6 +437,8 @@ class RenderView : public RenderWidget, virtual WebKit::WebSpeechInputController* speechInputController( WebKit::WebSpeechInputListener* listener); virtual WebKit::WebDeviceOrientationClient* deviceOrientationClient(); + virtual void zoomLimitsChanged(double minimum_level, double maximum_level); + virtual void zoomLevelChanged(); // WebKit::WebFrameClient implementation ------------------------------------- @@ -641,7 +643,7 @@ class RenderView : public RenderWidget, FRIEND_TEST_ALL_PREFIXES(RenderViewTest, UpdateTargetURLWithInvalidURL); typedef std::map<GURL, ContentSettings> HostContentSettings; - typedef std::map<GURL, int> HostZoomLevels; + typedef std::map<GURL, double> HostZoomLevels; enum ErrorPageType { DNS_ERROR, @@ -845,7 +847,7 @@ class RenderView : public RenderWidget, #if defined(OS_MACOSX) void OnSetWindowVisibility(bool visible); #endif - void OnSetZoomLevelForLoadingURL(const GURL& url, int zoom_level); + void OnSetZoomLevelForLoadingURL(const GURL& url, double zoom_level); void OnShouldClose(); void OnStop(); void OnStopFinding(const ViewMsg_StopFinding_Params& params); |