Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: third_party/WebKit/Source/core/frame/FrameView.cpp

Issue 2643903002: Fix viewport unit sizes when printing. (Closed)
Patch Set: Fix comment Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/web/tests/WebViewTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org> 2 * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
3 * 1999 Lars Knoll <knoll@kde.org> 3 * 1999 Lars Knoll <knoll@kde.org>
4 * 1999 Antti Koivisto <koivisto@kde.org> 4 * 1999 Antti Koivisto <koivisto@kde.org>
5 * 2000 Dirk Mueller <mueller@kde.org> 5 * 2000 Dirk Mueller <mueller@kde.org>
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
7 * (C) 2006 Graham Dennis (graham.dennis@gmail.com) 7 * (C) 2006 Graham Dennis (graham.dennis@gmail.com)
8 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) 8 * (C) 2006 Alexey Proskuryakov (ap@nypop.com)
9 * Copyright (C) 2009 Google Inc. All rights reserved. 9 * Copyright (C) 2009 Google Inc. All rights reserved.
10 * 10 *
(...skipping 1340 matching lines...) Expand 10 before | Expand all | Expand 10 after
1351 1351
1352 us.intersect(parentRect); 1352 us.intersect(parentRect);
1353 } 1353 }
1354 1354
1355 return us; 1355 return us;
1356 } 1356 }
1357 1357
1358 FloatSize FrameView::viewportSizeForViewportUnits() const { 1358 FloatSize FrameView::viewportSizeForViewportUnits() const {
1359 float zoom = frame().pageZoomFactor(); 1359 float zoom = frame().pageZoomFactor();
1360 1360
1361 if (m_frame->settings() && 1361 FloatSize layoutSize;
1362 !RuntimeEnabledFeatures::inertTopControlsEnabled()) {
1363 FloatSize viewportSize;
1364 1362
1365 LayoutViewItem layoutViewItem = this->layoutViewItem(); 1363 LayoutViewItem layoutViewItem = this->layoutViewItem();
1366 if (layoutViewItem.isNull()) 1364 if (layoutViewItem.isNull())
1367 return viewportSize; 1365 return layoutSize;
1368 1366
1369 viewportSize.setWidth(layoutViewItem.viewWidth(IncludeScrollbars) / zoom); 1367 layoutSize.setWidth(layoutViewItem.viewWidth(IncludeScrollbars) / zoom);
1370 viewportSize.setHeight(layoutViewItem.viewHeight(IncludeScrollbars) / zoom); 1368 layoutSize.setHeight(layoutViewItem.viewHeight(IncludeScrollbars) / zoom);
1371 return viewportSize; 1369
1370 if (RuntimeEnabledFeatures::inertTopControlsEnabled()) {
1371 // We use the layoutSize rather than frameRect to calculate viewport units
1372 // so that we get correct results on mobile where the page is laid out into
1373 // a rect that may be larger than the viewport (e.g. the 980px fallback
1374 // width for desktop pages). Since the layout height is statically set to
1375 // be the viewport with browser controls showing, we add the browser
1376 // controls height, compensating for page scale as well, since we want to
1377 // use the viewport with browser controls hidden for vh (to match Safari).
1378 BrowserControls& browserControls = m_frame->host()->browserControls();
1379 int viewportWidth = m_frame->host()->visualViewport().size().width();
1380 if (m_frame->isMainFrame() && layoutSize.width() && viewportWidth) {
1381 float pageScaleAtLayoutWidth = viewportWidth / layoutSize.width();
1382 layoutSize.expand(0, browserControls.height() / pageScaleAtLayoutWidth);
1383 }
1372 } 1384 }
1373 1385
1374 FloatSize size(layoutSize(IncludeScrollbars)); 1386 return layoutSize;
1375
1376 // We use the layoutSize rather than frameRect to calculate viewport units
1377 // so that we get correct results on mobile where the page is laid out into
1378 // a rect that may be larger than the viewport (e.g. the 980px fallback
1379 // width for desktop pages). Since the layout height is statically set to
1380 // be the viewport with browser controls showing, we add the browser controls
1381 // height, compensating for page scale as well, since we want to use the
1382 // viewport with browser controls hidden for vh (to match Safari).
1383 BrowserControls& browserControls = m_frame->host()->browserControls();
1384 int viewportWidth = m_frame->host()->visualViewport().size().width();
1385 if (m_frame->isMainFrame() && size.width() && viewportWidth) {
1386 float pageScaleAtLayoutWidth = viewportWidth / size.width();
1387 size.expand(0, browserControls.height() / pageScaleAtLayoutWidth);
1388 }
1389
1390 size.scale(1 / zoom);
1391 return size;
1392 } 1387 }
1393 1388
1394 DocumentLifecycle& FrameView::lifecycle() const { 1389 DocumentLifecycle& FrameView::lifecycle() const {
1395 DCHECK(m_frame); 1390 DCHECK(m_frame);
1396 DCHECK(m_frame->document()); 1391 DCHECK(m_frame->document());
1397 return m_frame->document()->lifecycle(); 1392 return m_frame->document()->lifecycle();
1398 } 1393 }
1399 1394
1400 LayoutReplaced* FrameView::embeddedReplacedContent() const { 1395 LayoutReplaced* FrameView::embeddedReplacedContent() const {
1401 LayoutViewItem layoutViewItem = this->layoutViewItem(); 1396 LayoutViewItem layoutViewItem = this->layoutViewItem();
(...skipping 3596 matching lines...) Expand 10 before | Expand all | Expand 10 after
4998 // This is the top-level frame, so no mapping necessary. 4993 // This is the top-level frame, so no mapping necessary.
4999 if (m_frame->isMainFrame()) 4994 if (m_frame->isMainFrame())
5000 return; 4995 return;
5001 4996
5002 LayoutRect viewportIntersectionRect(remoteViewportIntersection()); 4997 LayoutRect viewportIntersectionRect(remoteViewportIntersection());
5003 transformState.move( 4998 transformState.move(
5004 LayoutSize(-viewportIntersectionRect.x(), -viewportIntersectionRect.y())); 4999 LayoutSize(-viewportIntersectionRect.x(), -viewportIntersectionRect.y()));
5005 } 5000 }
5006 5001
5007 } // namespace blink 5002 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/web/tests/WebViewTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698