Commit d00a7978 authored by kinaba@chromium.org's avatar kinaba@chromium.org

Zoom level limits must be set before setting a zoom level.

The default zoom level upperbound of WebKit is 300%,
while content::kMaximumZoomFactor is 500%. The larger
limit must be set before restoring the host-URL zoom levels,
otherwise 400% or 500% zoom level is clipped to 300%.

BUG=139559

Review URL: https://chromiumcodereview.appspot.com/10828143

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150284 0039d316-1c4b-4281-b951-d872f2087c98
parent 11ead627
...@@ -1698,3 +1698,33 @@ TEST_F(RenderViewImplTest, GetCompositionCharacterBoundsTest) { ...@@ -1698,3 +1698,33 @@ TEST_F(RenderViewImplTest, GetCompositionCharacterBoundsTest) {
} }
view()->OnImeConfirmComposition(empty_string, ui::Range::InvalidRange()); view()->OnImeConfirmComposition(empty_string, ui::Range::InvalidRange());
} }
TEST_F(RenderViewImplTest, ZoomLimit) {
const double kMinZoomLevel =
WebKit::WebView::zoomFactorToZoomLevel(content::kMinimumZoomFactor);
const double kMaxZoomLevel =
WebKit::WebView::zoomFactorToZoomLevel(content::kMaximumZoomFactor);
ViewMsg_Navigate_Params params;
params.page_id = -1;
params.navigation_type = ViewMsg_Navigate_Type::NORMAL;
// Verifies navigation to a URL with preset zoom level indeed sets the level.
// Regression test for http://crbug.com/139559, where the level was not
// properly set when it is out of the default zoom limits of WebView.
params.url = GURL("data:text/html,min_zoomlimit_test");
view()->OnSetZoomLevelForLoadingURL(params.url, kMinZoomLevel);
view()->OnNavigate(params);
ProcessPendingMessages();
EXPECT_DOUBLE_EQ(kMinZoomLevel, view()->GetWebView()->zoomLevel());
// It should work even when the zoom limit is temporarily changed in the page.
view()->GetWebView()->zoomLimitsChanged(
WebKit::WebView::zoomFactorToZoomLevel(1.0),
WebKit::WebView::zoomFactorToZoomLevel(1.0));
params.url = GURL("data:text/html,max_zoomlimit_test");
view()->OnSetZoomLevelForLoadingURL(params.url, kMaxZoomLevel);
view()->OnNavigate(params);
ProcessPendingMessages();
EXPECT_DOUBLE_EQ(kMaxZoomLevel, view()->GetWebView()->zoomLevel());
}
...@@ -1416,6 +1416,13 @@ void RenderViewImpl::UpdateURL(WebFrame* frame) { ...@@ -1416,6 +1416,13 @@ void RenderViewImpl::UpdateURL(WebFrame* frame) {
if (!frame->parent()) { if (!frame->parent()) {
// Top-level navigation. // Top-level navigation.
// 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 WebContentsImpl.
webview()->zoomLimitsChanged(
WebView::zoomFactorToZoomLevel(content::kMinimumZoomFactor),
WebView::zoomFactorToZoomLevel(content::kMaximumZoomFactor));
// Set zoom level, but don't do it for full-page plugin since they don't use // Set zoom level, but don't do it for full-page plugin since they don't use
// the same zoom settings. // the same zoom settings.
HostZoomLevels::iterator host_zoom = HostZoomLevels::iterator host_zoom =
...@@ -1435,13 +1442,6 @@ void RenderViewImpl::UpdateURL(WebFrame* frame) { ...@@ -1435,13 +1442,6 @@ void RenderViewImpl::UpdateURL(WebFrame* frame) {
host_zoom_levels_.erase(host_zoom); 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 WebContentsImpl.
webview()->zoomLimitsChanged(
WebView::zoomFactorToZoomLevel(content::kMinimumZoomFactor),
WebView::zoomFactorToZoomLevel(content::kMaximumZoomFactor));
// Update contents MIME type for main frame. // Update contents MIME type for main frame.
params.contents_mime_type = ds->response().mimeType().utf8(); params.contents_mime_type = ds->response().mimeType().utf8();
......
...@@ -803,6 +803,7 @@ class RenderViewImpl : public RenderWidget, ...@@ -803,6 +803,7 @@ class RenderViewImpl : public RenderWidget,
FRIEND_TEST_ALL_PREFIXES(RenderViewTest, MacTestCmdUp); FRIEND_TEST_ALL_PREFIXES(RenderViewTest, MacTestCmdUp);
#endif #endif
FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, SetHistoryLengthAndPrune); FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, SetHistoryLengthAndPrune);
FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, ZoomLimit);
typedef std::map<GURL, double> HostZoomLevels; typedef std::map<GURL, double> HostZoomLevels;
...@@ -983,7 +984,8 @@ class RenderViewImpl : public RenderWidget, ...@@ -983,7 +984,8 @@ class RenderViewImpl : public RenderWidget,
void OnSetWindowVisibility(bool visible); void OnSetWindowVisibility(bool visible);
#endif #endif
void OnSetZoomLevel(double zoom_level); void OnSetZoomLevel(double zoom_level);
void OnSetZoomLevelForLoadingURL(const GURL& url, double zoom_level); CONTENT_EXPORT void OnSetZoomLevelForLoadingURL(const GURL& url,
double zoom_level);
void OnExitFullscreen(); void OnExitFullscreen();
void OnShouldClose(); void OnShouldClose();
void OnStop(); void OnStop();
......
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